Skip to content

Instantly share code, notes, and snippets.

@good5dog5
Created March 28, 2015 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save good5dog5/3224d7b23a6779e8dd65 to your computer and use it in GitHub Desktop.
Save good5dog5/3224d7b23a6779e8dd65 to your computer and use it in GitHub Desktop.
// workspace/visualizer/main.c
void trace_task_switch(void *prev_task, unsigned int prev_tick, void *curr_task)
{
char buf[128];
int len = snprintf(buf, 128, "switch %d %d %d %d %d %d\n",
prev_task, curr_task,
xTaskGetTickCount(), get_reload(),
prev_tick, get_current());
write(logfile, buf, len);
}
// workspace/visuallizer/FreeRTOSConfig.h
// define an alias of trace_task_switch()
#define traceTASK_SWITCHED_IN() \
if (pxPreviousTCB != pxCurrentTCB) { \
trace_task_switch(pxPreviousTCB, \
previous_systick_current, \
pxCurrentTCB); \
}
// workspace/freertos-basic/freertos/libraries/FreeRTOS/task.c
// vTaskSwitchCountext()
/* Find the highest priority queue that contains ready tasks. */
while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) )
{
configASSERT( uxTopReadyPriority );
--uxTopReadyPriority;
}
/* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the tasks of the
same priority get an equal share of the processor time. */
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );
traceTASK_SWITCHED_IN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment