/*---------------------------------------------------------------------------- * Copyright (c) Fenda Technologies Co., Ltd. 2020. All rights reserved. * * Description: task_ancillary.c * * Author: saimen * * Create: 2024-7-11 *--------------------------------------------------------------------------*/ //lib #include #include #include //os #include "securec.h" #include "common_def.h" #include "debug_print.h" #include "soc_osal.h" #include "cmsis_os2.h" //sdk //drv //user #include "sys_typedef.h" #include "sys_config.h" #include "task_ancillary.h" /********************************************************************************************************************** * DEFINE */ #define ENABLE_STATIC_PRINT_INFO false #define ENABLE_STATIC_PRINT_WARN true #define ENABLE_STATIC_PRINT_ERROR true #if ENABLE_STATIC_PRINT_INFO #define static_print_debug(...) sys_common_printf(__VA_ARGS__) #else #define static_print_debug(...) #endif #if ENABLE_STATIC_PRINT_WARN #define static_print_warn(...) sys_common_printf(__VA_ARGS__) #else #define static_print_warn(...) #endif #if ENABLE_STATIC_PRINT_ERROR #define static_print_error(...) sys_common_printf(__VA_ARGS__) #else #define static_print_error(...) #endif #define QUEUE_ANCILLARY_COUNT 16 /********************************************************************************************************************** * VARIABLES */ static unsigned long g_queue_ancillary; static unsigned int *g_task_ancillary_handle; /********************************************************************************************************************** * PUBLIC FUNCTIONS */ unsigned int *tjd_task_ancillary_get_task_handle(void) { return g_task_ancillary_handle; } unsigned long tjd_task_ancillary_get_queue_id(void) { return g_queue_ancillary; } void tjd_task_ancillary_entry(void *param) { unused(param); int32_t ret = OSAL_FAILURE; queue_default_info_t msg_data; unsigned int msg_size = sizeof(queue_default_info_t); while (1) { (void)memset_s(&msg_data, sizeof(msg_data), 0, sizeof(msg_data)); ret = osal_msg_queue_read_copy(g_queue_ancillary, &msg_data, &msg_size, OSAL_MSGQ_WAIT_FOREVER); if (ret != OSAL_SUCCESS) { continue; } static_print_debug("queue_ancillary_default_info_t: service_node:0x%X-0x%X-%d\r\n", msg_data.param, msg_data.func_event_handler, msg_data.value); if(msg_data.func_event_handler) { ret = msg_data.func_event_handler(msg_data.param); } osal_kfree(msg_data.payload); } } void tjd_task_ancillary_init(unsigned short stack_depth, unsigned short priority) { osal_msg_queue_create("tjd_q_ancillary", QUEUE_ANCILLARY_COUNT, &g_queue_ancillary, 0, sizeof(queue_default_info_t)); #define APP_MAIN_STACK_SIZE 0xc00 #define TASK_PRIORITY_APP (osPriority_t)(17) osThreadAttr_t task_attr = { "tjd_t_ancillary", 0, NULL, 0, NULL, APP_MAIN_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }; if(stack_depth>APP_MAIN_STACK_SIZE){ task_attr.stack_size = stack_depth; } if(priority>TASK_PRIORITY_APP){ //task_attr.priority = priority; } task_attr.stack_mem = memalign(16, task_attr.stack_size);//add g_task_ancillary_handle = osThreadNew(tjd_task_ancillary_entry, NULL, &task_attr); static_print_warn("tjd_task_ancillary_init() END: task-0x%X queue-0x%X-%d\r\n", g_task_ancillary_handle, g_queue_ancillary, sizeof(queue_default_info_t)); } /********************************************************************************************************************** * TEST FUNCTIONS */ static unsigned long s_test_param; signed int tjd_task_ancillary_test_handle(void *param) { unsigned long *p_param = (unsigned long *)param; static_print_debug("tjd_task_ancillary_test_handle(): param=%d\r\n", *p_param); s_test_param++; return 0; //默认返回0,也可以自定义。 } void tjd_task_ancillary_test_send(void) { queue_default_info_t msg_data = { tjd_task_ancillary_test_handle, &s_test_param, NULL, NULL }; osal_msg_queue_write_copy(tjd_task_ancillary_get_queue_id(), (void *)&msg_data, sizeof(queue_default_info_t), 0); } #if 0 void task_ancillary_entry(void *pvParameters) { TaskMessage_t Msg = {0}; static_print_remind("\r\n%d task_ancillary_entry\r\n",xTaskGetTickCount()); button_api_init(); // adpt_aclock_config_load(); // adpt_ndisturb_config_load(); User_StopWatchInit(); // CountDownInit(); while(1) { if( xQueueReceive(g_ancillary_queue_handle, &Msg, portMAX_DELAY) != pdPASS ) { continue; } switch( Msg.uMessageID ) { case ANCILLARY_MSG_RTC_SECOND: // CountDownTimerCallback(); //计时器 break; case ANCILLARY_MSG_RTC_MINUTE: // static_print_remind("ANCILLARY_MSG_RTC_MINUTE==================================\n"); AlarmClockMinuteHandle(); //闹钟 break; case ANCILLARY_MSG_STOP_WATCH: //stop_watch - 秒表 User_StopWatchOperate(Msg.uData); break; case ANCILLARY_MSG_NO_DISTURB: //no_disturb - 勿扰模式 from UI // SetNoDisturbAllDay(Msg.uData); break; case ANCILLARY_MSG_COUNT_DOWN: { //计时器消息 from UI // CountDownOperateType type = (CountDownOperateType)(Msg.uData & 0xFF); // uint32_t startTime = Msg.uData >> 8; // CountDownOperate(type, startTime); } break; case ANCILLARY_MSG_RESTORE_FACTORY: //恢复出厂设置 system_restore_factory(); break; case ANCILLARY_MSG_RESTORE_FACTORY_TEST: //连接复位测试专用 system_restore_factory_test(); break; case ANCILLARY_MSG_REBOOT_CMD: // system_restart(); break; case ANCILLARY_MSG_POWER_ON: break; case ANCILLARY_MSG_POWER_OFF: system_enter_sleep_mode(); break; case ANCILLARY_MSG_LOG_BUF_FULL: //将日志已满的缓冲写入到文件 log_api_save_at_cache_full(); // DealDataLogBufFull(Msg.uData); break; default: break; } } } #endif