/** * @file main_app.c * @author Alvin Young (impressionyang@outlook.com) * @brief * @version 0.1 * @date 2024-11-25 * * _ _ * (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _ * / / ' \/ _ \/ __/ -_|_-<(_- * Date Version Author Description * 2024-11-25 v1.0 Alvin Young 首次创建 * * */ /* Define to prevent recursive inclusion -------------------------------------*/ /* Includes ------------------------------------------------------------------*/ #include "main_app.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" #include "esp_chip_info.h" #include "sdkconfig.h" #include #include #include "esp_log.h" #include "main_common.h" #include "shell_port.h" #include "imp_msg_queue.h" #include "ext_trans_service.h" #include "display_service.h" #include "audio_service.h" #include #include "imp_out_port.h" /* define --------------------------------------------------------------------*/ /* typedef -------------------------------------------------------------------*/ /* variables -----------------------------------------------------------------*/ static uint8_t print_en = 0; static imp_msg_queue_t* msg_q_handle = NULL; char InfoBuffer[512] = { 0 }; /* Private function(only *.c) -----------------------------------------------*/ uint8_t _esp_print_all_task() { memset(InfoBuffer, 0, 512); // 信息缓冲区清零 vTaskList((char*)&InfoBuffer); ESP_LOGI("maint_task", "\r\n name status priority stack_left task_id core\r\n%s\r\n", InfoBuffer); ESP_LOGI("maint_task", "X:exec R:ready B:block S:hang\r\n"); return 0; } uint8_t _print_all_task(int argc, char** argv) { int idx = 0; int len = strlen(InfoBuffer); memset(InfoBuffer, 0, 512); // 信息缓冲区清零 vTaskList((char*)&InfoBuffer); cdc_printf("\r\n name status priority stack_left task_id core \r\n"); cdc_printf("%s", InfoBuffer); cdc_printf("\r\nX:exec R:ready B:block S:hang\r\n"); _esp_print_all_task(); return 0; } uint8_t _set_print_en(int argc, char** argv) { if (argc < 2) { cdc_printf("too few argv\r\n"); } int en_v = atoi(argv[1]); print_en = en_v; return 0; } uint8_t _set_send_msg_to(int argc, char** argv) { // send id value if (argc < 3) { cdc_printf("too few argv: cmd sendtoid value_num\r\n"); } uint16_t send_to_id = (uint16_t)atoi(argv[1]); int value_num = atoi(argv[2]); imp_msg_item_t msg_item = { 0 }; msg_item.msg_data = value_num; imp_msg_queue_send_msg(msg_q_handle, send_to_id, &msg_item); cdc_printf("send from %d to %d value %d ok\r\n", msg_item.send_id, msg_item.recv_id, msg_item.msg_data); return 0; } uint8_t _main_task_wake_up_services() { xTaskCreate(imp_ext_trans_service_task, imp_main_task_table[IMP_TASK_ID_EXT_TRANS_SERVICE_TASK], 2048, NULL, 10, NULL); xTaskCreate(imp_display_service_task, imp_main_task_table[IMP_TASK_ID_DISP_SERVICE_TASK], 8192, NULL, 11, NULL); xTaskCreate(imp_audio_service_task, imp_main_task_table[IMP_TASK_ID_AUDIO_SERVICE_TASK], 2048, NULL, 12, NULL); return 0; } /* Exported functions --------------------------------------------------------*/ void imp_main_app_task(void* param) { uint16_t i = 0; uint8_t msg_recv_ret = 0; msg_q_handle = imp_msg_queue_create_handle(IMP_TASK_ID_MAIN_TASK); imp_msg_item_t msg_item = { 0 }; _main_task_wake_up_services(); _esp_print_all_task(); while (1) { // 10 ticks = 100ms msg_recv_ret = imp_msg_queue_recv_msg(msg_q_handle, &msg_item, 10); if (!msg_recv_ret) { cdc_printf("get msg from %d OK\r\n", msg_item.send_id); switch (msg_item.msg_type) { } } if (print_en) { cdc_printf("hello %d\r\n", i); } if (i++ % 30 == 0) { msg_item.msg_data = i; imp_msg_queue_send_msg( msg_q_handle, IMP_TASK_ID_EXT_TRANS_SERVICE_TASK, &msg_item); } vTaskDelay(1000 / portTICK_PERIOD_MS); // ESP_LOGI("maint_task", "u8g2 init done"); } return; } SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), main_pe, _set_print_en, set print value); SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), main_msg_to, _set_send_msg_to, send msg to other task); SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), print_task, _print_all_task, print all task status); /* * EOF */