131 lines
4.0 KiB
C
131 lines
4.0 KiB
C
/**
|
|
* @file main_app.c
|
|
* @author Alvin Young (impressionyang@outlook.com)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2024-11-25
|
|
*
|
|
* _ _
|
|
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
|
|
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
|
|
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
|
|
* /_/ /___/ /___/
|
|
* @copyright Copyright (c) 2024 impressionyang
|
|
*
|
|
* @par 修改日志:
|
|
* <table>
|
|
* <tr><th>Date <th>Version <th>Author <th>Description
|
|
* <tr><td>2024-11-25 <td>v1.0 <td>Alvin Young <td>首次创建
|
|
* </table>
|
|
*
|
|
*/
|
|
/* 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 <inttypes.h>
|
|
#include <stdio.h>
|
|
#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"
|
|
|
|
/* define --------------------------------------------------------------------*/
|
|
/* typedef -------------------------------------------------------------------*/
|
|
/* variables -----------------------------------------------------------------*/
|
|
|
|
static uint8_t print_en = 0;
|
|
static imp_msg_queue_t* msg_q_handle = NULL;
|
|
|
|
/* Private function(only *.c) -----------------------------------------------*/
|
|
|
|
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], 2048, NULL,
|
|
11, 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();
|
|
|
|
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);
|
|
|
|
/*
|
|
* EOF
|
|
*/ |