回想起当初学freertos的时候,某个中断优先级以下的任务是不能被freertos管理的(好像是全是抢占优先级,0子优先级的设置)。当初还不是非常了解。只知道管理不了
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock = 0U;
uint32_t uwPrescalerValue = 0U;
uint32_t pFLatency;
HAL_StatusTypeDef status;
/* Enable TIM11 clock */
__HAL_RCC_TIM11_CLK_ENABLE();
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* Compute TIM11 clock */
uwTimclock = HAL_RCC_GetPCLK2Freq();
/* Compute the prescaler value to have TIM11 counter clock equal to 1MHz */
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
/* Initialize TIM11 */
htim11.Instance = TIM11;
/* Initialize TIMx peripheral as follow:
+ Period = [(TIM11CLK/1000) - 1]. to have a (1/1000) s time base.
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
+ ClockDivision = 0
+ Counter direction = Up
*/
htim11.Init.Period = (1000000U / 1000U) - 1U;
htim11.Init.Prescaler = uwPrescalerValue;
htim11.Init.ClockDivision = 0;
htim11.Init.CounterMode = TIM_COUNTERMODE_UP;
htim11.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
status = HAL_TIM_Base_Init(&htim11);
if (status == HAL_OK)
{
/* Start the TIM time Base generation in interrupt mode */
status = HAL_TIM_Base_Start_IT(&htim11);
if (status == HAL_OK)
{
/* Enable the TIM11 global Interrupt */
HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);//如果启动成功,启用 TIM11 的全局中断
/* Configure the SysTick IRQ priority */
if (TickPriority < (1UL << __NVIC_PRIO_BITS))//TI Stellaris Cortex-M3 和 Cortex-M4 微控制器使用优先级配置寄存器的 3 个位,能提供 8 级优先级
{
/* Configure the TIM IRQ priority */
HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn, TickPriority, 0U);
uwTickPrio = TickPriority;
}
else
{
status = HAL_ERROR;
}
}
}
/* Return function status */
return status;
}
今天在看cubemx生成的代码里看到了这个配置
if (TickPriority < (1UL << __NVIC_PRIO_BITS))//TI Stellaris Cortex-M3 和 Cortex-M4 微控制器使用优先级配置寄存器的 3 个位,能提供 8 级优先级
{
/* Configure the TIM IRQ priority */
HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn, TickPriority, 0U);
uwTickPrio = TickPriority;
}
原因大致就是使用优先级 1<<3 = 0x1000 = 8 配置寄存器的 3 个位提供 8 级优先级
而这些详细的与freertos之间联系可以查阅下文
FreeRTOS 之七 Cortex-M 中的中断优先级设置_cortex中断优先级分组-CSDN博客