Consider two tasks created with the same priority in FreeRTOS. Each task prints a message and then delays for 100 ticks. What will be the output sequence?
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> void Task1(void *pvParameters) { while(1) { printf("Task 1 running\n"); vTaskDelay(100); } } void Task2(void *pvParameters) { while(1) { printf("Task 2 running\n"); vTaskDelay(100); } } int main(void) { xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL); xTaskCreate(Task2, "Task2", 1000, NULL, 1, NULL); vTaskStartScheduler(); return 0; }
Tasks with the same priority and equal delay times will share CPU time in a round-robin manner.
Since both tasks have the same priority and call vTaskDelay(100), the scheduler switches between them, resulting in alternating output.
In FreeRTOS, what is the correct function to create a new task that will run concurrently?
Look for the function starting with 'x' that creates tasks.
The function xTaskCreate() is the official FreeRTOS API to create a new task.
Examine the following task code. Why might it cause a stack overflow?
void Task(void *pvParameters) {
char buffer[1024];
while(1) {
// Do some work
vTaskDelay(10);
}
}
int main(void) {
xTaskCreate(Task, "Task", 100, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}Consider the size of local variables versus the stack size allocated.
The task stack size is set to 100 words, which is too small to hold the 1024-byte local buffer, causing stack overflow.
Which option contains the correct syntax to create a FreeRTOS task?
Check the parameter types and count for xTaskCreate.
The first parameter must be a function pointer, the second a string name, and the last parameter is a pointer to receive the task handle (can be NULL). Option D matches this.
You have two tasks that both read and write a shared variable. Which method ensures safe concurrent access?
Think about synchronization tools FreeRTOS provides.
A mutex ensures only one task accesses the shared variable at a time, preventing race conditions.