refactor(device): 移除备份配置文件并完善ADC模块注释
移除不再需要的 .cproject.yml.bak_dma 和 README.md 备份文件, 同时为 ADC.cpp 添加完整的 Doxygen 风格函数注释,提升代码可读性。
This commit is contained in:
@@ -9,6 +9,13 @@
|
||||
|
||||
task_scheduler_t g_scheduler = {0};
|
||||
|
||||
/**
|
||||
* @brief 初始化任务调度器内部状态。
|
||||
* @param[in] 无。
|
||||
* @param[out] 无。
|
||||
* @retval 无返回值。
|
||||
* @note 清零待执行任务位图以及所有分频节拍计数器。
|
||||
*/
|
||||
void TaskManager::init()
|
||||
{
|
||||
g_scheduler.task_flags = 0U;
|
||||
@@ -17,13 +24,32 @@ void TaskManager::init()
|
||||
g_scheduler.tick_10ms = 0U;
|
||||
g_scheduler.tick_100ms = 0U;
|
||||
g_scheduler.tick_1s = 0U;
|
||||
g_scheduler.div_vref_sample = 0U;
|
||||
g_scheduler.div_temp_sample = 0U;
|
||||
g_scheduler.div_can_rx = 0U;
|
||||
g_scheduler.div_can_tx = 0U;
|
||||
g_scheduler.div_heartbeat = 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 置位一个或多个待执行任务标志。
|
||||
* @param[in] taskMask 待置位的任务位图掩码。
|
||||
* @param[out] 无。
|
||||
* @retval 无返回值。
|
||||
* @note 该操作不清除其他已存在的任务位。
|
||||
*/
|
||||
void TaskManager::set(uint32_t taskMask)
|
||||
{
|
||||
g_scheduler.task_flags |= taskMask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 原子地取出当前所有待执行任务位图并清零。
|
||||
* @param[in] 无。
|
||||
* @param[out] 无。
|
||||
* @retval uint32_t 返回当前待执行任务位图。
|
||||
* @note 内部通过关中断实现对 `task_flags` 的原子交换。
|
||||
*/
|
||||
uint32_t TaskManager::takePending()
|
||||
{
|
||||
uint32_t pending;
|
||||
@@ -34,35 +60,54 @@ uint32_t TaskManager::takePending()
|
||||
return pending;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 推进一次 100us 调度节拍。
|
||||
* @param[in] 无。
|
||||
* @param[out] 无。
|
||||
* @retval 无返回值。
|
||||
* @note 按预设周期置位 ADC、CAN 接收、状态灯、心跳与诊断打印等任务。
|
||||
*/
|
||||
void TaskManager::tick100us()
|
||||
{
|
||||
g_scheduler.tick_100us++;
|
||||
|
||||
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_VREF_SAMPLE_TICKS) == 0U) {
|
||||
if(++g_scheduler.div_vref_sample >= CONFIG_TASK_PERIOD_VREF_SAMPLE_TICKS) {
|
||||
g_scheduler.div_vref_sample = 0U;
|
||||
set(1UL << TASK_ADC_VREF_SAMPLE);
|
||||
}
|
||||
|
||||
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_TEMP_SAMPLE_TICKS) == 0U) {
|
||||
if(++g_scheduler.div_temp_sample >= CONFIG_TASK_PERIOD_TEMP_SAMPLE_TICKS) {
|
||||
g_scheduler.div_temp_sample = 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) {
|
||||
if(++g_scheduler.div_can_rx >= CONFIG_TASK_PERIOD_CAN_RX_TICKS) {
|
||||
g_scheduler.div_can_rx = 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) {
|
||||
if(++g_scheduler.div_can_tx >= CONFIG_TASK_PERIOD_CAN_TX_TICKS) {
|
||||
g_scheduler.div_can_tx = 0U;
|
||||
g_scheduler.tick_100ms++;
|
||||
set((1UL << TASK_CAN_TX_PREPARE) | (1UL << TASK_CAN_TX_SEND) | (1UL << TASK_STATUS_LED));
|
||||
set(1UL << TASK_STATUS_LED);
|
||||
}
|
||||
|
||||
if((g_scheduler.tick_100us % CONFIG_TASK_PERIOD_HEARTBEAT_TICKS) == 0U) {
|
||||
if(++g_scheduler.div_heartbeat >= CONFIG_TASK_PERIOD_HEARTBEAT_TICKS) {
|
||||
g_scheduler.div_heartbeat = 0U;
|
||||
g_scheduler.tick_1s++;
|
||||
set((1UL << TASK_HEARTBEAT) | (1UL << TASK_DIAGNOSTIC_PRINT));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取全局调度器状态对象引用。
|
||||
* @param[in] 无。
|
||||
* @param[out] 无。
|
||||
* @retval task_scheduler_t& 返回全局调度器状态对象引用。
|
||||
* @note 供调试或其他模块观察当前节拍与任务位图。
|
||||
*/
|
||||
task_scheduler_t &TaskManager::state()
|
||||
{
|
||||
return g_scheduler;
|
||||
|
||||
Reference in New Issue
Block a user