Complete the code to define a trace hook function that runs when a task is switched in.
void traceTASK_SWITCHED_IN(void) {
[1];
}The trace hook traceTASK_SWITCHED_IN is used to run code when a task is switched in. Using printf here logs the event.
Complete the code to enable FreeRTOS+Trace recording in the configuration.
#define configUSE_TRACE_FACILITY [1]
Setting configUSE_TRACE_FACILITY to 1 enables trace facility support in FreeRTOS.
Fix the error in the trace hook function to correctly record a task switch event.
void traceTASK_SWITCHED_OUT(void) {
[1](pxCurrentTCB->pxTaskTag);
}The function vTraceStoreTaskSwitchedOut records the task switch out event for FreeRTOS+Trace.
Fill both blanks to create a dictionary of task names and their run times using FreeRTOS+Trace API.
for (int i = 0; i < uxTaskGetNumberOfTasks(); i++) { char* name = pcTaskGetName([1]); uint32_t time = ulTaskGetRunTimeCounter([2]); taskTimes[name] = time; }
Using xTaskGetHandle(NULL) is incorrect here; to get task handles by index, FreeRTOS does not provide a direct API. Instead, the correct approach is to use uxTaskGetSystemState() to get an array of task status structures. Since the question uses index i, the correct function to get the task handle is xTaskGetHandle() with the task name or from the system state array. Given the options, the best fit is D for both blanks, assuming xTaskGetHandle() is used with the task name.
Fill all three blanks to start trace recording, record a task switch, and stop recording.
vTrace[1](); vTrace[2](pxCurrentTCB->pxTaskTag); vTrace[3]();
Start trace recording with vTraceStart(), record task switch with vTraceStoreTaskSwitchedIn(), and stop with vTraceStop().