235 lines
6.0 KiB
C
235 lines
6.0 KiB
C
/*----------------------------------------------------------------------------
|
||
* Copyright (c) Fenda Technologies Co., Ltd. 2020. All rights reserved.
|
||
*
|
||
* Description: task_manage.c
|
||
*
|
||
* Author: saimen
|
||
*
|
||
* Create: 2022-7-16
|
||
*--------------------------------------------------------------------------*/
|
||
//lib
|
||
//os
|
||
//sdk
|
||
//drv
|
||
#include "rtc_api.h"
|
||
#include "adc_api.h"
|
||
#include "motor_api.h"
|
||
#include "ppg_api.h"
|
||
#include "gsensor_api.h"
|
||
#include "pressure_api.h"
|
||
#include "airbag_api.h"
|
||
#include "display_api.h"
|
||
#include "tp_api.h"
|
||
#include "psram_api.h"
|
||
#include "flash_api.h"
|
||
#include "log_api.h"
|
||
#include "fs_api.h"
|
||
#include "fs_user_init.h"
|
||
#if (PRJ_FOR_FS_SPECIAL_TEST == ON)
|
||
#include "fs_test_server.h"
|
||
#endif
|
||
//user
|
||
#include "cm_backtrace.h"
|
||
#include "sys_config.h"
|
||
#include "sys_rtos.h"
|
||
#include "sys_restart.h"
|
||
#include "task_manage.h"
|
||
#include "task_watchdog.h"
|
||
#include "task_display.h"
|
||
#include "task_touchpad.h"
|
||
#include "task_ate.h"
|
||
#include "task_radio.h"
|
||
#include "task_rtc.h"
|
||
#include "task_charge.h"
|
||
#include "task_ui.h"
|
||
#include "task_ble.h"
|
||
#include "task_alg.h"
|
||
#include "task_fit.h"
|
||
#include "task_ancillary.h"
|
||
#include "user_adapter.h"
|
||
//#include "user_charge.h"
|
||
#include "charge_api.h"
|
||
//#include "user_dtm.h"
|
||
#include "ble_management_server.h"
|
||
#include "ble_file_trans.h"
|
||
#include "sql_message.h"
|
||
|
||
|
||
#define ENABLE_STATIC_PRINT false
|
||
extern uint32_t am_util_stdio_printf(const char *pcFmt, ...);
|
||
#define static_print_remind(...) am_util_stdio_printf(__VA_ARGS__)
|
||
#if ENABLE_STATIC_PRINT
|
||
#define static_print_info(...) am_util_stdio_printf(__VA_ARGS__)
|
||
#else
|
||
#define static_print_info(...)
|
||
#endif
|
||
|
||
extern void user_page_bootup_logo_refresh(void);
|
||
extern void user_gps_creat_mutex(void);
|
||
extern void user_ble_creat_send_data_mutex(void);
|
||
|
||
static void init_before_task(void)
|
||
{
|
||
|
||
#if 1
|
||
// 检查状态,是否需要跳转到DTM程序,初始化时间4ms
|
||
// user_check_dtm_data();
|
||
|
||
// 对cm_backtrace初始化 PRO_INFO_BASE_NAME --->ble_freertos_amota
|
||
cm_backtrace_init("ble_freertos_amota", PRO_INFO_DEVICE_MODEL, DEVICE_SOFT_VERSION);
|
||
|
||
// 对MCU一些相关内容进行初始化,初始化时间17ms
|
||
user_init_mcu_someth();
|
||
|
||
// PSRAM,初始化时间960ms
|
||
psram_api_init();
|
||
#ifdef EXTERNAL_MEMORY_XIPMM_MODE
|
||
psram_api_mapping();
|
||
#endif
|
||
|
||
// Set the default cache configuration
|
||
am_hal_cachectrl_config(&am_hal_cachectrl_defaults);
|
||
am_hal_cachectrl_enable();
|
||
|
||
// 外部flash
|
||
flash_api_init();
|
||
//flash_api_test();
|
||
|
||
// 文件系统及设备保存信息的初始化,初始化时间445ms
|
||
fs_user_init(false);
|
||
//fs_user_init(true);
|
||
|
||
// 对保存在MCU ROM的某些数据进行开机恢复,不操作外设。
|
||
sys_restart_data_recover();
|
||
|
||
// 充电IC
|
||
user_chg_chip_init();
|
||
|
||
// 按键GPIO口初始化
|
||
button_api_deinit();
|
||
|
||
// 马达GPIO口初始化
|
||
motor_api_deinit();
|
||
|
||
// A+G
|
||
gsensor_api_init();
|
||
|
||
// PPG
|
||
ppg_api_init();
|
||
|
||
// Pressure
|
||
pressure_api_init();
|
||
|
||
// GPS -- 因为cxd560x GPS芯片启动需要超过1秒,所以放到任务中启动GPS芯片并获取固件版本等信息.
|
||
// user_gps_init();
|
||
|
||
// TP
|
||
touchpad_api_init(touchpad_api_callback);
|
||
|
||
// 显示屏 -- init()内有open()的动作,初始化时间670ms(刷LOGO,显示LOGO,所以耗时)
|
||
display_api_open();
|
||
// user_page_bootup_logo_refresh(); // 刷LOGO,显示LOGO
|
||
|
||
// 掉电后恢复RTC时间
|
||
system_rtc_por_recover();
|
||
|
||
// 蓝牙传输文件与消息通知初始化,初始化时间1199ms
|
||
FileTransInit();
|
||
sql_message_init();
|
||
BleConifgInit();
|
||
|
||
#endif
|
||
}
|
||
|
||
// task最高优先级为:configMAX_PRIORITIES - 1 ;另2021-10-25统计当前所有任务的任务栈占用空间约为62KB(task) + QUEUE + 18Timers + other。
|
||
// 为方便堆栈及优先级管理,所有用户 task 全部在此创建。
|
||
static void user_task_init(void)
|
||
{
|
||
#if (PRJ_FOR_FS_SPECIAL_TEST == ON)
|
||
|
||
task_rtc_init(128, 1);
|
||
|
||
// This task used by ble stack.
|
||
task_radio_init((4 * 256), 4);
|
||
|
||
// 应用层蓝牙协议数据传输任务,ota use it
|
||
task_ble_init((8 * 256), 1);
|
||
|
||
// 文件系统测试任务
|
||
// CreateFsTestTask((64 * 256), 4);
|
||
|
||
task_ate_init((4 * 256), 1);
|
||
|
||
// MCU看门狗task
|
||
task_watchdog_init(128, 0);
|
||
|
||
#else
|
||
|
||
task_rtc_init(128, 1);
|
||
|
||
// This task used by ble stack.
|
||
task_radio_init((4 * 256), 4);
|
||
|
||
// 应用层蓝牙协议数据传输任务,ota use it
|
||
task_ble_init((8 * 256), 1);
|
||
|
||
// 充电IC、电源管理task
|
||
task_charge_init((2 * 256), 4);
|
||
|
||
// 算法task
|
||
task_alg_create((32 * 256), 5);
|
||
|
||
// 健康task
|
||
task_fit_create((10 * 256), 3);
|
||
|
||
// 显示任务
|
||
task_ui_init((10 * 256), 3);
|
||
task_display_init((2 * 256), 4);
|
||
task_touchpad_init((2 * 256), 4);
|
||
|
||
// system common task
|
||
task_ancillary_init((6 * 256), 2);
|
||
|
||
// ate产测task
|
||
task_ate_init((15 * 256), 1);
|
||
|
||
// MCU看门狗task
|
||
task_watchdog_init(128, 0);
|
||
#endif
|
||
}
|
||
|
||
//互斥锁创建
|
||
static void user_lock_init(void)
|
||
{
|
||
rtc_api_creat_lock();
|
||
user_ble_creat_send_data_mutex();
|
||
|
||
adc_api_mutex_handle_init();
|
||
charge_api_create_mutex();
|
||
display_port_ui_create_mutex();
|
||
touchpad_api_creat_mutex();
|
||
psram_api_create_mutex();
|
||
// gsensor_creat_mutex();
|
||
// ppg_creat_mutex();
|
||
//// user_gps_creat_mutex(); //gps驱动暂时用不到互斥锁
|
||
|
||
flash_api_create_lock();
|
||
fs_api_create_lock();
|
||
log_api_create_lock();
|
||
}
|
||
|
||
void user_run(void)
|
||
{
|
||
static_print_remind("name: %s version: %s\r\n", user_get_mcu_name(), user_get_mcu_sw_ver());
|
||
// user_update_bootup_stat(DEVICE_BOOTUPING);
|
||
|
||
// 以下三行代码必须位置顺序固定
|
||
init_before_task();
|
||
user_task_init();
|
||
user_lock_init();
|
||
|
||
// Start the scheduler.
|
||
vTaskStartScheduler();
|
||
}
|
||
|