0
0
FreeRTOSprogramming~20 mins

Tick timer and scheduler in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tick Timer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Tick Count Increment Behavior

What will be the output of the following FreeRTOS tick count code snippet after 3 ticks?

FreeRTOS
#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;
}
ATick count: 1
BTick count: 3
CTick count: 0
DTick count: 2
Attempts:
2 left
💡 Hint

Observe that the scheduler is not started in the code, so xTaskGetTickCount() returns 0.

🧠 Conceptual
intermediate
1:30remaining
Role of the Tick Timer in FreeRTOS

What is the primary role of the tick timer in FreeRTOS?

ATo provide a periodic interrupt that drives the scheduler and time-related functions
BTo handle all hardware interrupts in the system
CTo manage memory allocation for tasks
DTo initialize the CPU clock frequency
Attempts:
2 left
💡 Hint

Think about what triggers task switching and delays.

🔧 Debug
advanced
2:30remaining
Why Does the Scheduler Not Switch Tasks?

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;
}
ABecause preemption is disabled, so tasks only switch on yield or blocking calls
BBecause the tick rate is too high causing scheduler overload
CBecause tasks have the same priority and scheduler cannot decide
DBecause tasks are missing calls to vTaskDelay()
Attempts:
2 left
💡 Hint

Check the configUSE_PREEMPTION setting.

📝 Syntax
advanced
1:30remaining
Identify the Syntax Error in Tick Hook Implementation

Which option contains the correct syntax for implementing the FreeRTOS tick hook function?

Avoid vApplicationTickHook() { /* user code */ }
Bvoid vApplicationTickHook(void) { /* user code */ }
Cvoid vApplicationTickHook(void) -> void { /* user code */ }
Dvoid vApplicationTickHook(void); { /* user code */ }
Attempts:
2 left
💡 Hint

Check the correct C function declaration syntax.

🚀 Application
expert
3:00remaining
Calculating Tick Overflow Time

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?

AApproximately 24 hours
BApproximately 365 days
CApproximately 100 days
DApproximately 49.7 days
Attempts:
2 left
💡 Hint

Calculate total ticks before overflow and convert to time.