Consider two FreeRTOS tasks with the same priority. Each task toggles an LED and then calls vTaskDelay(1). What is the expected behavior of the LED toggling?
void Task1(void *pvParameters) {
for (;;) {
ToggleLED1();
vTaskDelay(1);
}
}
void Task2(void *pvParameters) {
for (;;) {
ToggleLED2();
vTaskDelay(1);
}
}
int main(void) {
xTaskCreate(Task1, "Task1", 1000, NULL, 2, NULL);
xTaskCreate(Task2, "Task2", 1000, NULL, 2, NULL);
vTaskStartScheduler();
for(;;);
}Think about how FreeRTOS scheduler switches between tasks of equal priority when they call vTaskDelay().
When two tasks have the same priority and both call vTaskDelay(1), the scheduler time-slices between them. This causes the LEDs to toggle alternately with roughly equal frequency.
In FreeRTOS, if two tasks have the same priority and preemption is enabled, what happens when one task becomes ready while the other is running?
Consider how FreeRTOS handles tasks of equal priority with preemption enabled.
With preemption enabled, FreeRTOS does not preempt a running task for another task of the same priority immediately. The running task continues until it blocks, yields, or its time slice expires.
Two tasks with equal priority are created. Task1 runs an infinite loop without any blocking calls. Task2 never runs. What is the cause?
void Task1(void *pvParameters) {
for (;;) {
// No blocking or yielding
}
}
void Task2(void *pvParameters) {
for (;;) {
ToggleLED();
vTaskDelay(10);
}
}
int main(void) {
xTaskCreate(Task1, "Task1", 1000, NULL, 3, NULL);
xTaskCreate(Task2, "Task2", 1000, NULL, 3, NULL);
vTaskStartScheduler();
for(;;);
}Think about how FreeRTOS schedules tasks that never block or yield.
Task1 never blocks or yields, so it keeps running continuously. This prevents Task2 from running despite equal priority, causing starvation.
Which option contains a syntax error in creating two equal priority tasks for time-slicing?
Check the number of parameters required by xTaskCreate.
xTaskCreate requires 6 parameters. Option D calls it with only 5 parameters in the first call, causing a syntax error.
In FreeRTOS, two tasks have equal priority and the tick rate is set to 1000 Hz. If each task runs for one tick before switching, how much CPU time (in milliseconds) does each task get per time slice?
Consider the tick rate and how it relates to time slice duration.
With a tick rate of 1000 Hz, each tick is 1 millisecond. If tasks switch every tick, each gets 1 millisecond per time slice.