Consider two FreeRTOS tasks with different priorities. Task A has higher priority than Task B. Task B starts first and then Task A is created. What will be the output sequence of the print statements?
void TaskA(void *pvParameters) {
for (;;) {
printf("A\n");
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void TaskB(void *pvParameters) {
printf("B\n");
vTaskDelay(pdMS_TO_TICKS(50));
xTaskCreate(TaskA, "TaskA", 1000, NULL, 2, NULL);
for (;;) {
printf("B\n");
vTaskDelay(pdMS_TO_TICKS(100));
}
}
int main() {
xTaskCreate(TaskB, "TaskB", 1000, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}Remember that higher priority tasks preempt lower priority ones immediately.
Task B starts first and prints "B". When Task A is created with higher priority, it preempts Task B and prints "A". Then Task B resumes after Task A delays, so the output alternates.
Which scheduling policy in FreeRTOS best ensures that high priority tasks meet their deadlines?
Think about which policy allows immediate switching to important tasks.
Preemptive priority-based scheduling allows the highest priority task to run immediately, ensuring real-time deadlines are met.
A FreeRTOS system has a high priority task that sometimes misses its deadline. The code snippet below shows the task creation and delay. What scheduling issue is causing the missed deadline?
xTaskCreate(HighPriorityTask, "High", 1000, NULL, 3, NULL); void HighPriorityTask(void *pvParameters) { for (;;) { // Critical work vTaskDelay(pdMS_TO_TICKS(200)); } } xTaskCreate(LowPriorityTask, "Low", 1000, NULL, 1, NULL); void LowPriorityTask(void *pvParameters) { for (;;) { // Long blocking operation vTaskDelay(pdMS_TO_TICKS(500)); } }
Consider how scheduling works when preemption is disabled or cooperative.
If the system uses cooperative scheduling, the low priority task can block the CPU and prevent the high priority task from running, causing missed deadlines.
Which option contains a syntax error that will prevent the FreeRTOS scheduler from starting?
void main() {
xTaskCreate(Task1, "Task1", 1000, NULL, 2, NULL);
xTaskCreate(Task2, "Task2", 1000, NULL, 1, NULL);
vTaskStartScheduler()
}
void Task1(void *pvParameters) {
for (;;) {
// Task code
}
}
void Task2(void *pvParameters) {
for (;;) {
// Task code
}
}Check for missing punctuation that causes compilation failure.
Missing semicolon after vTaskStartScheduler() causes a syntax error preventing compilation and scheduler start.
You have three tasks: SensorRead (high priority), DataProcessing (medium priority), and Logging (low priority). SensorRead must respond within 10ms. DataProcessing can be delayed up to 100ms. Logging is non-critical. Which scheduling approach best guarantees SensorRead meets its deadline?
Think about how priority and preemption affect response time.
Assigning SensorRead the highest priority with preemptive scheduling ensures it runs immediately when ready, meeting the 10ms deadline.