- 新增完整的CMSIS解决方案配置,包含AC6/GCC/IAR/CLANG编译器支持 - 添加项目配置文件,定义了设备层、系统层、应用层的模块结构 - 配置ARM::CMSIS和GigaDevice::GD32E50x_DFP软件包依赖 - 创建多层代码架构:应用入口(main)、系统层(sys)、设备层(device) - 实现任务管理系统,包含任务调度器和任务执行器分离设计 - 集成ADC、CANFD、定时器、串口、温度采样等核心功能模块 - 添加详细的README文档说明项目结构和代码组织方式 - 配置AC6链接脚本和运行时环境文件 - 设置Git忽略规则以排除编译产物和临时文件
69 lines
1.7 KiB
C++
69 lines
1.7 KiB
C++
/**
|
|
* @file task_manager.cpp
|
|
* @brief 任务调度管理器实现。
|
|
*/
|
|
|
|
#include "main.h"
|
|
#include "sys/task_manager.h"
|
|
#include "sys/config.h"
|
|
|
|
task_scheduler_t g_scheduler = {0};
|
|
|
|
void TaskManager::init()
|
|
{
|
|
g_scheduler.task_flags = 0U;
|
|
g_scheduler.tick_100us = 0U;
|
|
g_scheduler.tick_1ms = 0U;
|
|
g_scheduler.tick_10ms = 0U;
|
|
g_scheduler.tick_100ms = 0U;
|
|
g_scheduler.tick_1s = 0U;
|
|
}
|
|
|
|
void TaskManager::set(uint32_t taskMask)
|
|
{
|
|
g_scheduler.task_flags |= taskMask;
|
|
}
|
|
|
|
uint32_t TaskManager::takePending()
|
|
{
|
|
uint32_t pending;
|
|
__disable_irq();
|
|
pending = g_scheduler.task_flags;
|
|
g_scheduler.task_flags &= ~pending;
|
|
__enable_irq();
|
|
return pending;
|
|
}
|
|
|
|
void TaskManager::tick100us()
|
|
{
|
|
g_scheduler.tick_100us++;
|
|
|
|
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_VREF_SAMPLE_TICKS) == 0U) {
|
|
set(1UL << TASK_ADC_VREF_SAMPLE);
|
|
}
|
|
|
|
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_TEMP_SAMPLE_TICKS) == 0U) {
|
|
g_scheduler.tick_1ms++;
|
|
set((1UL << TASK_ADC_TEMP_SAMPLE) | (1UL << TASK_ADC_PROCESS));
|
|
}
|
|
|
|
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_CAN_RX_TICKS) == 0U) {
|
|
g_scheduler.tick_10ms++;
|
|
set((1UL << TASK_CAN_RX_POLL) | (1UL << TASK_CAN_RX_PARSE));
|
|
}
|
|
|
|
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_CAN_TX_TICKS) == 0U) {
|
|
g_scheduler.tick_100ms++;
|
|
set((1UL << TASK_CAN_TX_PREPARE) | (1UL << TASK_CAN_TX_SEND) | (1UL << TASK_STATUS_LED));
|
|
}
|
|
|
|
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_HEARTBEAT_TICKS) == 0U) {
|
|
g_scheduler.tick_1s++;
|
|
set((1UL << TASK_HEARTBEAT) | (1UL << TASK_DIAGNOSTIC_PRINT));
|
|
}
|
|
}
|
|
|
|
task_scheduler_t &TaskManager::state()
|
|
{
|
|
return g_scheduler;
|
|
} |