What will be the output of the following FreeRTOS tick count code snippet after 3 ticks?
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> TickType_t tickCount = 0; void vApplicationTickHook(void) { tickCount = xTaskGetTickCount(); } int main() { // Simulate 3 ticks for (int i = 0; i < 3; i++) { vApplicationTickHook(); } printf("Tick count: %u\n", (unsigned int)tickCount); return 0; }
Observe that the scheduler is not started in the code, so xTaskGetTickCount() returns 0.
The code attempts to simulate 3 ticks by calling vApplicationTickHook() in a loop. However, since vTaskStartScheduler() is never called, the FreeRTOS scheduler and tick interrupt are not running. Therefore, xTaskGetTickCount() always returns 0, and the output is 'Tick count: 0'.
What is the primary role of the tick timer in FreeRTOS?
Think about what triggers task switching and delays.
The tick timer generates periodic interrupts that allow the scheduler to switch tasks and manage delays/timeouts.
Given the following FreeRTOS configuration snippet, why does the scheduler never switch tasks?
#define configUSE_PREEMPTION 0
#define configTICK_RATE_HZ 1000
void vTask1(void *pvParameters) {
while(1) {
// Task code
}
}
void vTask2(void *pvParameters) {
while(1) {
// Task code
}
}
int main() {
xTaskCreate(vTask1, "Task1", 1000, NULL, 1, NULL);
xTaskCreate(vTask2, "Task2", 1000, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}Check the configUSE_PREEMPTION setting.
With preemption disabled, the scheduler switches tasks only when tasks yield or block. Without explicit yield, the first task runs forever.
Which option contains the correct syntax for implementing the FreeRTOS tick hook function?
Check the correct C function declaration syntax.
Option B correctly declares the tick hook function with void parameter and no return value.
Given a FreeRTOS tick rate of 1000 Hz and a 32-bit tick counter, how long in days will it take for the tick count to overflow?
Calculate total ticks before overflow and convert to time.
The 32-bit counter max value is 2^32 - 1 ticks. At 1000 ticks per second, overflow time = (2^32 / 1000) seconds ≈ 4294967 seconds ≈ 49.7 days.