From f451df004ba8ee6baff4017895abb5ba5071d540 Mon Sep 17 00:00:00 2001 From: ipason Date: Tue, 6 May 2025 10:42:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EFreeRTOS=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E6=B5=8B=E8=AF=95=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E6=A0=88=E7=A9=BA=E9=97=B4=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/FluxTime/FluxTime.c | 33 +++++++++++++++++++++++++++++++++ components/FluxTime/FluxTime.h | 26 ++++++++++++++++++++++++-- main/main.cpp | 5 +++++ sdkconfig | 4 ++-- 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/components/FluxTime/FluxTime.c b/components/FluxTime/FluxTime.c index 2af62ed..4fd63f8 100644 --- a/components/FluxTime/FluxTime.c +++ b/components/FluxTime/FluxTime.c @@ -95,3 +95,36 @@ char* get_time_str(void) return strftime_buf; } +#if SYSTEM_TIME_TEST_ENABLE +static void soft_timer_callback_func(void) +{ + //printf("soft timer callback\n"); + + /* 向SD卡写入时间戳 */ + WRITE_LOG_TO_SD("soft timer callback"); +} + +/** + * @brief 软件定时器精度测试任务 + * + * 验证使用FreeRTOS软件定时器可以保证气阀开启周期为 0.2s (开启0.2s后再关闭) + * + * @note cpu利用率拉升至100%,同时定义执行五次,周期为0.2s的定时器(调度器周期为1ms) + * ,使用GPIO输出模拟气阀切换,每次切换向SD卡中写入当前时间戳,持续运行读取当前日志。 + * + * @param[in] arg not used + */ +void soft_timer_task(void* arg) +{ + /* 定时器初始化 */ + TimerHandle_t soft_timer = xTimerCreate("soft_timer_cb", pdMS_TO_TICKS(10), pdTRUE, NULL, &soft_timer_callback_func); + + /* 立即启动定时器 */ + xTimerStart(soft_timer, 0); + while (1) + { + /* 延时1s */ + vTaskDelay(1000); + } +} +#endif \ No newline at end of file diff --git a/components/FluxTime/FluxTime.h b/components/FluxTime/FluxTime.h index c7ca111..dc59128 100644 --- a/components/FluxTime/FluxTime.h +++ b/components/FluxTime/FluxTime.h @@ -19,12 +19,34 @@ extern "C" { #endif /* 每隔多久进行一次时间数据更新*/ -#define SYSTEM_TIME_UPDATE_INTERVAL_SEC 1 +#define SYSTEM_TIME_UPDATE_INTERVAL_SEC (1) +/* 选择是否进行软件定时器精度测试 */ +#define SYSTEM_TIME_TEST_ENABLE (0) -/*时间同步任务*/ +/** + * @brief 时间同步函数 + * + * 用于时间同步操作,无网络环境无法使用。 + * + * @param[in] arg not used + */ void time_synic_task(void *arg); +#if SYSTEM_TIME_TEST_ENABLE +/** + * @brief 软件定时器精度测试任务 + * + * 验证使用FreeRTOS软件定时器可以保证气阀开启周期为 0.2s (开启0.2s后再关闭) + * + * @note cpu利用率拉升至100%,同时定义执行五次,周期为0.2s的定时器(调度器周期为1ms) + * ,使用GPIO输出模拟气阀切换,每次切换向SD卡中写入当前时间戳,持续运行读取当前日志。 + * + * @param[in] arg not used + */ +void soft_timer_task(void* arg); +#endif + /*获取当前时间*/ char* get_time_str(void); diff --git a/main/main.cpp b/main/main.cpp index 4335f39..8867a2a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -147,6 +147,11 @@ extern "C" void app_main(void) vTaskDelay(PROGRESS_DELAY_TIME/portTICK_PERIOD_MS); #endif +#if SYSTEM_TIME_TEST_ENABLE + /* 创建软件定时器任务 */ + xTaskCreate(soft_timer_task, "soft_timer_task", 1024, NULL, 2, NULL); +#endif + lv_scr_load_anim(ui_pageHome, LV_SCR_LOAD_ANIM_OUT_TOP, 800, 0, false); /*电源开启*/ diff --git a/sdkconfig b/sdkconfig index 4f41a9e..62213d2 100644 --- a/sdkconfig +++ b/sdkconfig @@ -1343,7 +1343,7 @@ CONFIG_FREERTOS_TIMER_SERVICE_TASK_NAME="Tmr Svc" CONFIG_FREERTOS_TIMER_TASK_NO_AFFINITY=y CONFIG_FREERTOS_TIMER_SERVICE_TASK_CORE_AFFINITY=0x7FFFFFFF CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 -CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048 +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=16416 CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1 @@ -2531,7 +2531,7 @@ CONFIG_WPA_MBEDTLS_TLS_CLIENT=y # CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y CONFIG_TIMER_TASK_PRIORITY=1 -CONFIG_TIMER_TASK_STACK_DEPTH=2048 +CONFIG_TIMER_TASK_STACK_DEPTH=16416 CONFIG_TIMER_QUEUE_LENGTH=10 # CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK is not set # CONFIG_HAL_ASSERTION_SILIENT is not set