Which statement best describes what an RTOS (Real-Time Operating System) is?
Think about systems that need to respond quickly and predictably.
An RTOS is built to manage tasks so they complete within specific time limits, ensuring predictable behavior.
Consider this FreeRTOS code snippet that creates two tasks with different priorities. What will be the output?
void Task1(void *pvParameters) {
for(;;) {
printf("Task1 running\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void Task2(void *pvParameters) {
for(;;) {
printf("Task2 running\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
int main() {
xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL);
xTaskCreate(Task2, "Task2", 1000, NULL, 2, NULL);
vTaskStartScheduler();
return 0;
}Higher priority tasks run more often and can preempt lower priority tasks.
Task2 has higher priority and runs more frequently, so its messages appear more often than Task1's.
What error will this FreeRTOS code cause?
SemaphoreHandle_t xSemaphore;
void TaskA(void *pvParameters) {
xSemaphoreTake(xSemaphore, portMAX_DELAY);
// Critical section
xSemaphoreTake(xSemaphore, portMAX_DELAY);
xSemaphoreGive(xSemaphore);
xSemaphoreGive(xSemaphore);
vTaskDelete(NULL);
}
void TaskB(void *pvParameters) {
xSemaphoreTake(xSemaphore, portMAX_DELAY);
// Critical section
xSemaphoreGive(xSemaphore);
vTaskDelete(NULL);
}
int main() {
xSemaphore = xSemaphoreCreateMutex();
xTaskCreate(TaskA, "TaskA", 1000, NULL, 1, NULL);
xTaskCreate(TaskB, "TaskB", 1000, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}Think about what happens when a task tries to take a mutex it already holds.
TaskA tries to take the mutex twice without releasing it first, causing a deadlock waiting on itself.
Which option shows the correct syntax to create a FreeRTOS task that runs a function named MyTask?
Remember that the task function name is passed as a pointer without parentheses.
The function name is passed directly without parentheses or address operator. Option A is correct.
You are designing a system that must respond to sensor input within 5 milliseconds consistently. Which RTOS feature is most important to ensure this?
Think about how to make sure the most important task runs immediately when needed.
Priority-based preemptive scheduling allows the RTOS to run high-priority tasks immediately, meeting strict timing needs.