DescriptionTrace hook macros are a very powerful feature that permit you to collect data on how your embedded application is behaving.Key points of interest within the FreeRTOS source code contain empty macros that an application can re-define for the purpose of providing application specific trace facilities. The application need only implement those macros of particular interest - with unused macros remaining empty and therefore not impacting the application timing.
ExamplesFollowing are some examples of how these macros can be used:
Example 1The FreeRTOS task tag functionality provides a simple mechanism for setting up logging via digital or analogue outputs. For example, the tag value can be set to a voltage that is unique to that task. The traceSWITCHED_IN() macro can then be defined to simply set an analogue output to the value associated with the task being switched in. For example:/* First task sets its tag value to 1. */ void vTask1( void *pvParameters ) { /* This task is going to be represented by a voltage scale of 1. */ vTaskSetApplicationTaskTag( NULL, ( void * ) 1 ); for( ;; ) { /* Task code goes here. */ } } /*************************************************/ /* Second task sets its tag value to 2. */ void vTask2( void *pvParameters ) { /* This task is going to be represented by a voltage scale of 2. */ vTaskSetApplicationTaskTag( NULL, ( void * ) 2 ); for( ;; ) { /* Task code goes here. */ } } /*************************************************/ /* Define the traceTASK_SWITCHED_IN() macro to output the voltage associated with the task being selected to run on port 0. */ #define traceTASK_SWITCHED_IN() vSetAnalogueOutput( 0, (int)pxCurrentTCB->pxTaskTag )
Example 2API call logging can be used to record the reason a context switch occurred. RTOS kernel call logging can be used to record the sequence in which tasks execute. For example:/* traceBLOCKING_ON_QUEUE_RECEIVE() is just one of the macros that can be used to record why a context switch is about to occur. */ #define traceBLOCKING_ON_QUEUE_RECEIVE(xQueue) \ ulSwitchReason = reasonBLOCKING_ON_QUEUE_READ; /* log_event() is an application defined function that logs which tasks ran when, and why. */ #define traceTASK_SWITCHED_OUT() \ log_event( pxCurrentTCB, ulSwitchReason );
DefiningMacros that are called from within interrupts, particularly the tick interrupt, must execute quickly and not use much stack space. Setting variables, writing to trace registers, or outputting to ports are all acceptable. Attempting to fprintf() log data to a slow disk will not work!Macro definitions must occur before the inclusion of FreeRTOS.h. The easiest place to define trace macros is at the bottom of FreeRTOSConfig.h, or in a separate header file that is included from the bottom of FreeRTOSConfig.h. The table below describes the available macros. The macro parameters are used to indicate which task, queue, semaphore or mutex was associated with the event being recorded.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|
Latest News
NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS. Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019 Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed. View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS. Careers
FreeRTOS and other embedded software careers at AWS. FreeRTOS Partners
|