FreeRTOS的任务优先级测试
在RAM文档DUI0553-Cortex-M4-Devices-Generic-User-Guide .pdf 中指出,一个比较低的数值表示一个比较高的优先级。
Reset -3, the highest
NMI -2 0x00000008
HardFault -1 0x0000000C
但是在FreeRTOS中,Priorities can be assigned from 0, which is the lowest priority, to (configMAX_PRIORITIES – 1), which is the highest priority.
采用一个S32K144的开发板,在S32DS开发环境下,通过创建两个任务,
第一个任务是死循环。
第二个任务是每隔1s闪一次灯。
只存在两个任务,第一个任务的优先级定义为1,第二个任务的优先级定义为2。
可见,灯能够正常闪动。
但是,如果将第一个任务的优先级定义高于2,则灯不能够闪动。
可见,该操作系统是能够支持优先级的。能够比较好的处理多任务的情况。
void endless_loop_test(void) { uint32_t dummy_cnt = 0; do { dummy_cnt++; } while(1u); }
void toogle_led( void *pvParameters ) { TickType_t xNextWakeTime; const unsigned long ulValueToSend = 100UL; /* Casting pvParameters to void because it is unused */ (void)pvParameters; /* Initialise xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); for( ;; ) { /* Place this task in the blocked state until it is time to run again. The block time is specified in ticks, the constant used converts ticks to ms. While in the Blocked state this task will not consume any CPU time. */ vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS ); PINS_DRV_TogglePins(LED_GPIO, (1 << LED2)); } }