|
|
@@ -1483,79 +1483,10 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
|
// 当前段脉冲发送完毕,进入等待状态 |
|
|
|
g_plsr_route.run_state = PLSR_STATE_WAIT; |
|
|
|
|
|
|
|
// 检查等待条件是否满足 |
|
|
|
if (PLSR_Section_CheckWaitCondition(&g_plsr_route)) |
|
|
|
{ |
|
|
|
// 等待条件满足,切换到下一段 |
|
|
|
PLSR_SectionConfig_t* current_section = &g_plsr_route.section[g_plsr_route.current_section_num - 1]; |
|
|
|
|
|
|
|
// 更新prevPulseCount为当前段的累计脉冲数 |
|
|
|
if (g_plsr_route.mode == PLSR_MODE_RELATIVE) |
|
|
|
{ |
|
|
|
g_plsr_route.prevPulseCount = g_plsr_route.pulse_count; |
|
|
|
} |
|
|
|
|
|
|
|
// 切换到下一段 |
|
|
|
g_plsr_route.current_section_num = current_section->next_section; |
|
|
|
g_plsr_route.current_freq = g_plsr_route.target_freq; // 当前频率更新为上一段的目标频率 |
|
|
|
|
|
|
|
// 启动新段 |
|
|
|
PLSR_Section_StartNewSection(&g_plsr_route); |
|
|
|
|
|
|
|
// 计算新段需要发送的脉冲数 |
|
|
|
PLSR_SectionConfig_t* new_section = &g_plsr_route.section[g_plsr_route.current_section_num - 1]; |
|
|
|
uint32_t next_pulse_target; |
|
|
|
if (g_plsr_route.mode == PLSR_MODE_RELATIVE) |
|
|
|
{ |
|
|
|
// 相对模式:每段发送指定的脉冲数 |
|
|
|
next_pulse_target = new_section->target_pulse; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 绝对模式:发送到绝对位置所需的脉冲数 |
|
|
|
if (new_section->target_pulse > g_plsr_route.pulse_count) |
|
|
|
{ |
|
|
|
next_pulse_target = new_section->target_pulse - g_plsr_route.pulse_count; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 目标位置小于等于当前位置,该段不发送脉冲 |
|
|
|
next_pulse_target = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
// 处理脉冲数 |
|
|
|
if (next_pulse_target == 0) |
|
|
|
{ |
|
|
|
// 绝对模式下目标位置已达到,直接切换到下一段或结束 |
|
|
|
// 检查是否还有下一段 |
|
|
|
if (new_section->next_section == 0 && g_plsr_route.current_section_num >= g_plsr_route.section_num) |
|
|
|
{ |
|
|
|
// 没有下一段,路径结束 |
|
|
|
PLSR_Route_Stop(&g_plsr_route); |
|
|
|
return; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 该段无需发送脉冲,立即完成并检查下一段 |
|
|
|
// 这种情况下直接标记当前段完成,等待下次中断处理 |
|
|
|
g_plsr_route.run_state = PLSR_STATE_WAIT; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (next_pulse_target > 0 && next_pulse_target <= 0xFFFFFFFF) |
|
|
|
{ |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, next_pulse_target); |
|
|
|
// 重置TIM2计数器后再启动PWM |
|
|
|
__HAL_TIM_SET_COUNTER(&htim2, 0); |
|
|
|
PLSR_PWM_Start(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 脉冲数异常,停止路径 |
|
|
|
PLSR_Route_Stop(&g_plsr_route); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// TIM2中断只设置等待状态,段切换逻辑移到任务中处理 |
|
|
|
// 发送信号量,通知高优先级段切换任务立即处理 |
|
|
|
s_task_notification_flag = 1; |
|
|
|
PLSR_SectionSwitchSignal(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
@@ -1577,6 +1508,17 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
|
{ |
|
|
|
// 无匀速阶段,直接进入减速 |
|
|
|
g_plsr_route.run_state = PLSR_STATE_DECEL; |
|
|
|
// 设置减速目标频率:如果是最后一段则减速到0,否则减速到下一段的起始频率 |
|
|
|
if(g_plsr_route.current_section_num == g_plsr_route.section_num) |
|
|
|
{ |
|
|
|
// 最后一段,减速到0 |
|
|
|
g_plsr_route.target_freq = 0; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 不是最后一段,减速到下一段的起始频率(当前频率) |
|
|
|
g_plsr_route.target_freq = g_plsr_route.current_freq; |
|
|
|
} |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, g_plsr_route.decel_pulse_count); |
|
|
|
__HAL_TIM_SET_COUNTER(&htim2, 0); |
|
|
|
PLSR_PWM_Start(); |
|
|
@@ -1597,6 +1539,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
|
if(g_plsr_route.decel_pulse_count > 0) |
|
|
|
{ |
|
|
|
g_plsr_route.run_state = PLSR_STATE_DECEL; |
|
|
|
// 最后一段,减速到0 |
|
|
|
g_plsr_route.target_freq = 0; |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, g_plsr_route.decel_pulse_count); |
|
|
|
__HAL_TIM_SET_COUNTER(&htim2, 0); |
|
|
|
PLSR_PWM_Start(); |
|
|
@@ -1612,6 +1556,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
|
{ |
|
|
|
if(g_plsr_route.current_section_num == g_plsr_route.section_num) |
|
|
|
{ |
|
|
|
printf("路径完成:全部%lu脉冲发送完毕\n", AllPluse); |
|
|
|
// 减速阶段完成,清零减速脉冲计数 |
|
|
|
g_plsr_route.decel_pulse_count = 0; |
|
|
|
|
|
|
@@ -1626,56 +1571,9 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
|
|
|
|
|
// 进入等待状态,等待下一段开始 |
|
|
|
g_plsr_route.run_state = PLSR_STATE_WAIT; |
|
|
|
// 检查等待条件是否满足 |
|
|
|
if (PLSR_Section_CheckWaitCondition(&g_plsr_route)) |
|
|
|
{ |
|
|
|
// 等待条件满足,切换到下一段 |
|
|
|
PLSR_SectionConfig_t* current_section = &g_plsr_route.section[g_plsr_route.current_section_num - 1]; |
|
|
|
if (current_section->next_section == 0 && g_plsr_route.current_section_num >= g_plsr_route.section_num) |
|
|
|
{ |
|
|
|
// 当前段是最后一段同时跳转段为0,路径结束 |
|
|
|
PLSR_Route_Stop(&g_plsr_route); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 检查是否有下一段可执行 |
|
|
|
if (g_plsr_route.current_section_num < g_plsr_route.section_num) |
|
|
|
{ |
|
|
|
// 更新prevPulseCount为当前段的累计脉冲数 |
|
|
|
if (g_plsr_route.mode == PLSR_MODE_RELATIVE) |
|
|
|
{ |
|
|
|
g_plsr_route.prevPulseCount = g_plsr_route.pulse_count; |
|
|
|
} |
|
|
|
// 切换到下一段 |
|
|
|
PLSR_SectionConfig_t* next_section = &g_plsr_route.section[g_plsr_route.current_section_num]; |
|
|
|
g_plsr_route.current_section_num++; |
|
|
|
g_plsr_route.current_freq = next_section->target_freq; // 更新当前频率 |
|
|
|
|
|
|
|
// 启动新段 |
|
|
|
PLSR_Section_StartNewSection(&g_plsr_route); |
|
|
|
|
|
|
|
// 计算新段需要发送的脉冲数 |
|
|
|
uint32_t next_pulse_target = next_section->target_pulse; |
|
|
|
|
|
|
|
if (next_pulse_target > 0 && next_pulse_target <= 0xFFFFFFFF) |
|
|
|
{ |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, next_pulse_target); |
|
|
|
__HAL_TIM_SET_COUNTER(&htim2, 0); |
|
|
|
PLSR_PWM_Start(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 脉冲数异常,停止路径 |
|
|
|
PLSR_Route_Stop(&g_plsr_route); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 没有下一段,路径结束 |
|
|
|
PLSR_Route_Stop(&g_plsr_route); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// TIM2中断只设置等待状态,段切换逻辑移到任务中处理 |
|
|
|
// 设置任务通知标志,通知任务进行段切换处理 |
|
|
|
s_task_notification_flag = 1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@@ -1755,10 +1653,12 @@ void PLSR_Route_Init(PLSR_RouteConfig_t* route) |
|
|
|
route->direction = PLSR_DIR_FORWARD; // 运行方向:默认正向 |
|
|
|
|
|
|
|
// 初始化新增的加减速参数 |
|
|
|
route->default_accel_time_ms = 0; // 默认加速时间:清零 |
|
|
|
route->default_decel_time_ms = 0; // 默认减速时间:清零 |
|
|
|
route->accel_rate = 0; // 加速度:清零 |
|
|
|
route->decel_rate = 0; // 减速度:清零 |
|
|
|
route->default_freq = 1000; // 默认频率:1000Hz |
|
|
|
route->default_accel_time_ms = 1000; // 默认加速时间:1000ms |
|
|
|
route->default_decel_time_ms = 1000; // 默认减速时间:1000ms |
|
|
|
|
|
|
|
// 计算默认加减速度 |
|
|
|
PLSR_Accel_UpdateRates(route); |
|
|
|
|
|
|
|
// 初始化运行状态参数 - 清零所有运行时状态 |
|
|
|
route->run_state = PLSR_STATE_IDLE; // 运行状态:空闲 |
|
|
@@ -1942,6 +1842,62 @@ void PLSR_Section_StartNewSection(PLSR_RouteConfig_t* route) |
|
|
|
|
|
|
|
// 设置本段的目标频率到路径控制结构体中 |
|
|
|
route->target_freq = current_section->target_freq; |
|
|
|
|
|
|
|
// 根据等待条件决定运行状态和TIM2设置 |
|
|
|
if(current_section->wait_condition.wait_type == PLSR_WAIT_PLUSEEND) |
|
|
|
{ |
|
|
|
// 脉冲发送完成等待:计算当前段需要发送的脉冲数 |
|
|
|
uint32_t current_pulse_target; |
|
|
|
if (route->mode == PLSR_MODE_RELATIVE) |
|
|
|
{ |
|
|
|
// 相对模式:每段发送指定的脉冲数 |
|
|
|
current_pulse_target = current_section->target_pulse; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 绝对模式:发送到绝对位置所需的脉冲数 |
|
|
|
current_pulse_target = current_section->target_pulse - route->prevPulseCount; |
|
|
|
} |
|
|
|
|
|
|
|
// 设置TIM2自动重装值为当前段的目标脉冲数 |
|
|
|
if (current_pulse_target > 0 && current_pulse_target <= 0xFFFF) |
|
|
|
{ |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, current_pulse_target); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 脉冲数无效,设置为1避免除零错误 |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if(route->run_state == PLSR_STATE_ACCEL) |
|
|
|
{ |
|
|
|
// 如果是加速状态,设置TIM2自动重装值为加速脉冲数 |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, route->accel_pulse_count); |
|
|
|
} |
|
|
|
else if(route->run_state == PLSR_STATE_CONST) |
|
|
|
{ |
|
|
|
// 如果是匀速状态,设置TIM2自动重装值为匀速脉冲数 |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, route->const_pulse_count); |
|
|
|
} |
|
|
|
else if(route->run_state == PLSR_STATE_DECEL) |
|
|
|
{ |
|
|
|
// 如果是减速状态,设置TIM2自动重装值为减速脉冲数 |
|
|
|
__HAL_TIM_SetAutoreload(&htim2, route->decel_pulse_count); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 重置TIM2计数器 |
|
|
|
__HAL_TIM_SET_COUNTER(&htim2, 0); |
|
|
|
|
|
|
|
// 设置PWM频率为当前段的起始频率 |
|
|
|
if(route->current_freq > 0) |
|
|
|
{ |
|
|
|
PLSR_PWM_SetFrequency(route->current_freq); |
|
|
|
} |
|
|
|
|
|
|
|
//为等待时间计数赋值 |
|
|
|
PLSR_Wait_StartTimer(route); |
|
|
|
} |
|
|
@@ -2025,10 +1981,6 @@ void PLSR_Section_SwitchNext(PLSR_RouteConfig_t* route) |
|
|
|
* @retval None |
|
|
|
* @note 根据时间和频率差计算加减速所需的步数 |
|
|
|
*/ |
|
|
|
// 注意:PLSR_Accel_CalculateSteps函数已被删除 |
|
|
|
// 新的直线加减速算法不再需要复杂的步数计算 |
|
|
|
// 改为使用PLSR_Accel_Process函数在TIM6中断中直接处理加减速 |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 加减速处理函数 |
|
|
|
* @param route: 路径控制结构体指针 |
|
|
@@ -2044,10 +1996,22 @@ void PLSR_Accel_Process(PLSR_RouteConfig_t* route) |
|
|
|
uint32_t tim6_period_ms = s_tim6_update_freq_us / 1000; |
|
|
|
if (tim6_period_ms == 0) tim6_period_ms = 1; // 避免除零错误 |
|
|
|
uint8_t first_flag = (route->current_freq == 0); |
|
|
|
if ((route->run_state == PLSR_STATE_ACCEL && route->current_freq >= route->target_freq) || |
|
|
|
(route->run_state == PLSR_STATE_DECEL && route->current_freq <= route->target_freq)) |
|
|
|
|
|
|
|
// 加速完成检查 |
|
|
|
if (route->run_state == PLSR_STATE_ACCEL && route->current_freq >= route->target_freq) |
|
|
|
{ |
|
|
|
route->current_freq = route->target_freq; // 限制到目标频率 |
|
|
|
route->run_state = PLSR_STATE_CONST; |
|
|
|
PLSR_PWM_SetFrequency(route->current_freq); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 减速完成检查 - 只有当减速到目标频率且目标频率大于0时才切换到匀速 |
|
|
|
if (route->run_state == PLSR_STATE_DECEL && route->current_freq <= route->target_freq && route->target_freq > 0) |
|
|
|
{ |
|
|
|
route->current_freq = route->target_freq; // 限制到目标频率 |
|
|
|
route->run_state = PLSR_STATE_CONST; |
|
|
|
PLSR_PWM_SetFrequency(route->current_freq); |
|
|
|
return; |
|
|
|
} |
|
|
|
// ==================== 加速处理 ==================== |
|
|
@@ -2091,11 +2055,25 @@ void PLSR_Accel_Process(PLSR_RouteConfig_t* route) |
|
|
|
// 检查是否达到目标频率 |
|
|
|
if (route->current_freq <= route->target_freq) { |
|
|
|
route->current_freq = route->target_freq; // 限制到目标频率 |
|
|
|
route->run_state = PLSR_STATE_CONST; // 切换到匀速状态 |
|
|
|
|
|
|
|
// 如果目标频率为0,说明减速到停止 |
|
|
|
if (route->target_freq == 0) { |
|
|
|
route->run_state = PLSR_STATE_IDLE; // 切换到空闲状态 |
|
|
|
PLSR_PWM_Stop(); // 停止PWM输出 |
|
|
|
return; |
|
|
|
} else { |
|
|
|
route->run_state = PLSR_STATE_CONST; // 切换到匀速状态 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 更新PWM频率 |
|
|
|
PLSR_PWM_SetFrequency(route->current_freq); |
|
|
|
// 更新PWM频率或停止PWM |
|
|
|
if (route->current_freq > 0) { |
|
|
|
PLSR_PWM_SetFrequency(route->current_freq); |
|
|
|
} else { |
|
|
|
// 频率减速到0,停止PWM输出 |
|
|
|
route->run_state = PLSR_STATE_IDLE; |
|
|
|
PLSR_PWM_Stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@@ -2125,6 +2103,26 @@ void PLSR_Accel_UpdateRates(PLSR_RouteConfig_t* route) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 设置默认加减速参数 |
|
|
|
* @param route: 路径控制结构体指针 |
|
|
|
* @param accel_time_ms: 加速时间(毫秒) |
|
|
|
* @param decel_time_ms: 减速时间(毫秒) |
|
|
|
* @retval None |
|
|
|
* @note 设置默认加减速时间并自动计算加减速度 |
|
|
|
*/ |
|
|
|
void PLSR_Accel_SetDefaultParams(PLSR_RouteConfig_t* route, uint32_t accel_time_ms, uint32_t decel_time_ms) |
|
|
|
{ |
|
|
|
if (route == NULL) return; |
|
|
|
|
|
|
|
// 设置加减速时间 |
|
|
|
route->default_accel_time_ms = accel_time_ms; |
|
|
|
route->default_decel_time_ms = decel_time_ms; |
|
|
|
|
|
|
|
// 自动更新加减速度 |
|
|
|
PLSR_Accel_UpdateRates(route); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 匀速状态处理 |
|
|
@@ -2192,6 +2190,82 @@ uint8_t PLSR_Section_CheckPulseComplete(PLSR_RouteConfig_t* route) |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 获取任务通知标志 |
|
|
|
* @param None |
|
|
|
* @retval 任务通知标志状态 (1: 有通知, 0: 无通知) |
|
|
|
*/ |
|
|
|
uint8_t PLSR_GetTaskNotificationFlag(void) |
|
|
|
{ |
|
|
|
return s_task_notification_flag; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 清除任务通知标志 |
|
|
|
* @param None |
|
|
|
* @retval None |
|
|
|
*/ |
|
|
|
void PLSR_ClearTaskNotificationFlag(void) |
|
|
|
{ |
|
|
|
s_task_notification_flag = 0; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 任务中执行段切换逻辑 |
|
|
|
* @param route: 路径控制结构体指针 |
|
|
|
* @retval None |
|
|
|
* @note 此函数应在任务中调用,用于处理从TIM2中断转移过来的段切换逻辑 |
|
|
|
*/ |
|
|
|
void PLSR_TaskSectionSwitch(PLSR_RouteConfig_t* route) |
|
|
|
{ |
|
|
|
if (route == NULL) return; |
|
|
|
|
|
|
|
/* 检查是否处于等待状态且有任务通知 */ |
|
|
|
if (route->run_state == PLSR_STATE_WAIT && s_task_notification_flag) |
|
|
|
{ |
|
|
|
/* 清除任务通知标志 */ |
|
|
|
s_task_notification_flag = 0; |
|
|
|
|
|
|
|
/* 检查是否为最后一段 */ |
|
|
|
if (route->current_section_num >= route->section_num) |
|
|
|
{ |
|
|
|
/* 路径结束 */ |
|
|
|
route->route_state = PLSR_ROUTE_COMPLETED; |
|
|
|
PLSR_PWM_Stop(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
/* 获取当前段配置 */ |
|
|
|
PLSR_SectionConfig_t* current_section = &route->section[route->current_section_num - 1]; |
|
|
|
|
|
|
|
/* 检查等待条件 */ |
|
|
|
if (current_section->wait_condition.wait_type == PLSR_WAIT_PLUSEEND || |
|
|
|
current_section->wait_condition.wait_type == PLSR_WAIT_EXT_OR_END) |
|
|
|
{ |
|
|
|
/* 脉冲发送完成,直接切换到下一段 */ |
|
|
|
PLSR_Section_SwitchNext(route); |
|
|
|
/* 启动新段,设置新的脉冲参数和频率 */ |
|
|
|
PLSR_Section_StartNewSection(route); |
|
|
|
/* 启动PWM输出 */ |
|
|
|
PLSR_PWM_Start(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
/* 其他等待条件,检查是否满足 */ |
|
|
|
if (PLSR_Section_CheckWaitCondition(route)) |
|
|
|
{ |
|
|
|
/* 等待条件满足,切换到下一段 */ |
|
|
|
PLSR_Section_SwitchNext(route); |
|
|
|
/* 启动新段,设置新的脉冲参数和频率 */ |
|
|
|
PLSR_Section_StartNewSection(route); |
|
|
|
/* 启动PWM输出 */ |
|
|
|
PLSR_PWM_Start(); |
|
|
|
} |
|
|
|
/* 如果等待条件未满足,保持等待状态,等待下次检查 */ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 检查等待条件是否满足 |
|
|
|
* @param route: 路径控制结构体指针 |
|
|
@@ -2239,6 +2313,68 @@ uint8_t PLSR_Section_CheckWaitCondition(PLSR_RouteConfig_t* route) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ==================== PLSR实时段切换任务实现 ==================== |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 段切换信号量 |
|
|
|
*/ |
|
|
|
static OS_EVENT *s_section_switch_sem = NULL; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 段切换信号量初始化 |
|
|
|
* @param None |
|
|
|
* @retval None |
|
|
|
* @note 在系统初始化时调用,创建段切换信号量 |
|
|
|
*/ |
|
|
|
void PLSR_SectionSwitchInit(void) |
|
|
|
{ |
|
|
|
/* 创建段切换信号量,初始值为0 */ |
|
|
|
s_section_switch_sem = OSSemCreate(0); |
|
|
|
|
|
|
|
if (s_section_switch_sem == NULL) { |
|
|
|
/* 信号量创建失败处理 */ |
|
|
|
while(1); // 系统错误,停止运行 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 发送段切换信号量 |
|
|
|
* @param None |
|
|
|
* @retval None |
|
|
|
* @note 在TIM2中断中调用,通知段切换任务立即执行 |
|
|
|
*/ |
|
|
|
void PLSR_SectionSwitchSignal(void) |
|
|
|
{ |
|
|
|
if (s_section_switch_sem != NULL) { |
|
|
|
/* 发送信号量,唤醒段切换任务 */ |
|
|
|
OSSemPost(s_section_switch_sem); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 实时段切换任务函数 |
|
|
|
* @param p_arg: 任务参数指针 |
|
|
|
* @retval None |
|
|
|
* @note 高优先级任务,等待信号量后立即执行段切换逻辑 |
|
|
|
*/ |
|
|
|
void PLSR_SectionSwitchTask(void *p_arg) |
|
|
|
{ |
|
|
|
INT8U err; |
|
|
|
|
|
|
|
(void)p_arg; // 避免编译器警告 |
|
|
|
|
|
|
|
while (1) { |
|
|
|
/* 等待段切换信号量 */ |
|
|
|
OSSemPend(s_section_switch_sem, 0, &err); |
|
|
|
|
|
|
|
if (err == OS_ERR_NONE) { |
|
|
|
/* 信号量获取成功,执行段切换逻辑 */ |
|
|
|
PLSR_TaskSectionSwitch(&g_plsr_route); |
|
|
|
} |
|
|
|
/* 如果信号量获取失败,继续等待下一次信号 */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|