Challenge - 5 Problems
FreeRTOS Timer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this FreeRTOS timer creation code?
Consider the following code snippet using
xTimerCreate(). What will be the value of timerHandle after execution?FreeRTOS
TimerHandle_t timerHandle = xTimerCreate("MyTimer", pdMS_TO_TICKS(1000), pdTRUE, (void *)0, vTimerCallback); if(timerHandle == NULL) { printf("Timer creation failed\n"); } else { printf("Timer created successfully\n"); }
Attempts:
2 left
💡 Hint
Check if the timer period and callback function are valid.
✗ Incorrect
The timer is created with a valid period and a valid callback function pointer, so
xTimerCreate() returns a valid handle, not NULL.❓ Predict Output
intermediateWhat happens if the timer period is zero in xTimerCreate()?
Given this code snippet, what will be the output?
FreeRTOS
TimerHandle_t timerHandle = xTimerCreate("ZeroPeriodTimer", 0, pdFALSE, NULL, vTimerCallback); if(timerHandle == NULL) { printf("Timer creation failed\n"); } else { printf("Timer created successfully\n"); }
Attempts:
2 left
💡 Hint
Check the FreeRTOS documentation about timer periods.
✗ Incorrect
A timer period of zero is invalid and causes
xTimerCreate() to return NULL, indicating failure.🔧 Debug
advancedIdentify the error in this xTimerCreate() usage
What error will this code produce when compiled or run?
FreeRTOS
TimerHandle_t timerHandle = xTimerCreate("Timer", pdMS_TO_TICKS(500), pdTRUE, NULL, NULL); if(timerHandle == NULL) { printf("Timer creation failed\n"); } else { printf("Timer created successfully\n"); }
Attempts:
2 left
💡 Hint
Check if the callback function pointer can be NULL.
✗ Incorrect
Passing NULL as the callback function pointer causes
xTimerCreate() to fail and return NULL.🧠 Conceptual
advancedWhat does the auto-reload parameter control in xTimerCreate()?
In the function
xTimerCreate(), what is the effect of setting the uxAutoReload parameter to pdTRUE?Attempts:
2 left
💡 Hint
Think about what 'auto-reload' means in a timer context.
✗ Incorrect
Setting
uxAutoReload to pdTRUE makes the timer restart automatically after each expiration, creating a periodic timer.❓ Predict Output
expertWhat is the output count of active timers after these calls?
Given the following code, how many timers are active after execution?
FreeRTOS
TimerHandle_t t1 = xTimerCreate("T1", pdMS_TO_TICKS(1000), pdFALSE, NULL, vTimerCallback); TimerHandle_t t2 = xTimerCreate("T2", pdMS_TO_TICKS(0), pdTRUE, NULL, vTimerCallback); TimerHandle_t t3 = xTimerCreate("T3", pdMS_TO_TICKS(500), pdTRUE, NULL, vTimerCallback); int activeCount = 0; if(t1 != NULL) activeCount++; if(t2 != NULL) activeCount++; if(t3 != NULL) activeCount++; printf("Active timers: %d\n", activeCount);
Attempts:
2 left
💡 Hint
Remember which timer periods are valid and which cause creation failure.
✗ Incorrect
Timer t2 has zero period and fails creation (NULL). Timers t1 and t3 are created successfully, so activeCount is 2.
