Skip to content

Commit 83861f5

Browse files
authored
Add Trace Hook Macros to all API calls (#786)
This pull-request adds out-of-the-box support for different tracing tools. New trace hook macros have been added for all public API functions, one for each function entry and one for each exit. There are no functional changes, as the macros are by default empty. For more information see following forum post: https://forums.freertos.org/t/add-tracing-functionality-for-all-api-calls/18007.
1 parent 15e0364 commit 83861f5

File tree

8 files changed

+2357
-3
lines changed

8 files changed

+2357
-3
lines changed

croutine.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
BaseType_t xReturn;
108108
CRCB_t * pxCoRoutine;
109109

110+
traceENTER_xCoRoutineCreate( pxCoRoutineCode, uxPriority, uxIndex );
111+
110112
/* Allocate the memory that will store the co-routine control block. */
111113
pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) );
112114

@@ -156,6 +158,8 @@
156158
xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
157159
}
158160

161+
traceRETURN_xCoRoutineCreate( xReturn );
162+
159163
return xReturn;
160164
}
161165
/*-----------------------------------------------------------*/
@@ -165,6 +169,8 @@
165169
{
166170
TickType_t xTimeToWake;
167171

172+
traceENTER_vCoRoutineAddToDelayedList( xTicksToDelay, pxEventList );
173+
168174
/* Calculate the time to wake - this may overflow but this is
169175
* not a problem. */
170176
xTimeToWake = xCoRoutineTickCount + xTicksToDelay;
@@ -196,6 +202,8 @@
196202
* function must be called with interrupts disabled. */
197203
vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) );
198204
}
205+
206+
traceRETURN_vCoRoutineAddToDelayedList();
199207
}
200208
/*-----------------------------------------------------------*/
201209

@@ -283,6 +291,8 @@
283291

284292
void vCoRoutineSchedule( void )
285293
{
294+
traceENTER_vCoRoutineSchedule();
295+
286296
/* Only run a co-routine after prvInitialiseCoRoutineLists() has been
287297
* called. prvInitialiseCoRoutineLists() is called automatically when a
288298
* co-routine is created. */
@@ -313,6 +323,8 @@
313323
/* Call the co-routine. */
314324
( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex );
315325
}
326+
327+
traceRETURN_vCoRoutineSchedule();
316328
}
317329
/*-----------------------------------------------------------*/
318330

@@ -341,6 +353,8 @@
341353
CRCB_t * pxUnblockedCRCB;
342354
BaseType_t xReturn;
343355

356+
traceENTER_xCoRoutineRemoveFromEventList( pxEventList );
357+
344358
/* This function is called from within an interrupt. It can only access
345359
* event lists and the pending ready list. This function assumes that a
346360
* check has already been made to ensure pxEventList is not empty. */
@@ -357,6 +371,8 @@
357371
xReturn = pdFALSE;
358372
}
359373

374+
traceRETURN_xCoRoutineRemoveFromEventList( xReturn );
375+
360376
return xReturn;
361377
}
362378

event_groups.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
8282
{
8383
EventGroup_t * pxEventBits;
8484

85+
traceENTER_xEventGroupCreateStatic( pxEventGroupBuffer );
86+
8587
/* A StaticEventGroup_t object must be provided. */
8688
configASSERT( pxEventGroupBuffer );
8789

@@ -122,6 +124,8 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
122124
traceEVENT_GROUP_CREATE_FAILED();
123125
}
124126

127+
traceRETURN_xEventGroupCreateStatic( pxEventBits );
128+
125129
return pxEventBits;
126130
}
127131

@@ -134,6 +138,8 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
134138
{
135139
EventGroup_t * pxEventBits;
136140

141+
traceENTER_xEventGroupCreate();
142+
137143
/* Allocate the event group. Justification for MISRA deviation as
138144
* follows: pvPortMalloc() always ensures returned memory blocks are
139145
* aligned per the requirements of the MCU stack. In this case
@@ -170,6 +176,8 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
170176
traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */
171177
}
172178

179+
traceRETURN_xEventGroupCreate( pxEventBits );
180+
173181
return pxEventBits;
174182
}
175183

@@ -186,6 +194,8 @@ EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
186194
BaseType_t xAlreadyYielded;
187195
BaseType_t xTimeoutOccurred = pdFALSE;
188196

197+
traceENTER_xEventGroupSync( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTicksToWait );
198+
189199
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
190200
configASSERT( uxBitsToWaitFor != 0 );
191201
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
@@ -303,6 +313,8 @@ EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
303313
/* Prevent compiler warnings when trace macros are not used. */
304314
( void ) xTimeoutOccurred;
305315

316+
traceRETURN_xEventGroupSync( uxReturn );
317+
306318
return uxReturn;
307319
}
308320
/*-----------------------------------------------------------*/
@@ -318,6 +330,8 @@ EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
318330
BaseType_t xWaitConditionMet, xAlreadyYielded;
319331
BaseType_t xTimeoutOccurred = pdFALSE;
320332

333+
traceENTER_xEventGroupWaitBits( xEventGroup, uxBitsToWaitFor, xClearOnExit, xWaitForAllBits, xTicksToWait );
334+
321335
/* Check the user is not attempting to wait on the bits used by the kernel
322336
* itself, and that at least one bit is being requested. */
323337
configASSERT( xEventGroup );
@@ -467,6 +481,8 @@ EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
467481
/* Prevent compiler warnings when trace macros are not used. */
468482
( void ) xTimeoutOccurred;
469483

484+
traceRETURN_xEventGroupWaitBits( uxReturn );
485+
470486
return uxReturn;
471487
}
472488
/*-----------------------------------------------------------*/
@@ -477,6 +493,8 @@ EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
477493
EventGroup_t * pxEventBits = xEventGroup;
478494
EventBits_t uxReturn;
479495

496+
traceENTER_xEventGroupClearBits( xEventGroup, uxBitsToClear );
497+
480498
/* Check the user is not attempting to clear the bits used by the kernel
481499
* itself. */
482500
configASSERT( xEventGroup );
@@ -495,6 +513,8 @@ EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
495513
}
496514
taskEXIT_CRITICAL();
497515

516+
traceRETURN_xEventGroupClearBits( uxReturn );
517+
498518
return uxReturn;
499519
}
500520
/*-----------------------------------------------------------*/
@@ -506,9 +526,13 @@ EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
506526
{
507527
BaseType_t xReturn;
508528

529+
traceENTER_xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear );
530+
509531
traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
510532
xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
511533

534+
traceRETURN_xEventGroupClearBitsFromISR( xReturn );
535+
512536
return xReturn;
513537
}
514538

@@ -521,12 +545,16 @@ EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
521545
EventGroup_t const * const pxEventBits = xEventGroup;
522546
EventBits_t uxReturn;
523547

548+
traceENTER_xEventGroupGetBitsFromISR( xEventGroup );
549+
524550
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
525551
{
526552
uxReturn = pxEventBits->uxEventBits;
527553
}
528554
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
529555

556+
traceRETURN_xEventGroupGetBitsFromISR( uxReturn );
557+
530558
return uxReturn;
531559
} /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */
532560
/*-----------------------------------------------------------*/
@@ -542,6 +570,8 @@ EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
542570
EventGroup_t * pxEventBits = xEventGroup;
543571
BaseType_t xMatchFound = pdFALSE;
544572

573+
traceENTER_xEventGroupSetBits( xEventGroup, uxBitsToSet );
574+
545575
/* Check the user is not attempting to set the bits used by the kernel
546576
* itself. */
547577
configASSERT( xEventGroup );
@@ -623,6 +653,8 @@ EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
623653
}
624654
( void ) xTaskResumeAll();
625655

656+
traceRETURN_xEventGroupSetBits( pxEventBits->uxEventBits );
657+
626658
return pxEventBits->uxEventBits;
627659
}
628660
/*-----------------------------------------------------------*/
@@ -632,6 +664,8 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
632664
EventGroup_t * pxEventBits = xEventGroup;
633665
const List_t * pxTasksWaitingForBits;
634666

667+
traceENTER_vEventGroupDelete( xEventGroup );
668+
635669
configASSERT( pxEventBits );
636670

637671
pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
@@ -670,6 +704,8 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
670704
}
671705
}
672706
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
707+
708+
traceRETURN_vEventGroupDelete();
673709
}
674710
/*-----------------------------------------------------------*/
675711

@@ -680,6 +716,8 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
680716
BaseType_t xReturn;
681717
EventGroup_t * pxEventBits = xEventGroup;
682718

719+
traceENTER_xEventGroupGetStaticBuffer( xEventGroup, ppxEventGroupBuffer );
720+
683721
configASSERT( pxEventBits );
684722
configASSERT( ppxEventGroupBuffer );
685723

@@ -704,6 +742,8 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
704742
}
705743
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
706744

745+
traceRETURN_xEventGroupGetStaticBuffer( xReturn );
746+
707747
return xReturn;
708748
}
709749
#endif /* configSUPPORT_STATIC_ALLOCATION */
@@ -714,7 +754,11 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
714754
void vEventGroupSetBitsCallback( void * pvEventGroup,
715755
const uint32_t ulBitsToSet )
716756
{
757+
traceENTER_vEventGroupSetBitsCallback( pvEventGroup, ulBitsToSet );
758+
717759
( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
760+
761+
traceRETURN_vEventGroupSetBitsCallback();
718762
}
719763
/*-----------------------------------------------------------*/
720764

@@ -723,7 +767,11 @@ void vEventGroupSetBitsCallback( void * pvEventGroup,
723767
void vEventGroupClearBitsCallback( void * pvEventGroup,
724768
const uint32_t ulBitsToClear )
725769
{
770+
traceENTER_vEventGroupClearBitsCallback( pvEventGroup, ulBitsToClear );
771+
726772
( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
773+
774+
traceRETURN_vEventGroupClearBitsCallback();
727775
}
728776
/*-----------------------------------------------------------*/
729777

@@ -772,9 +820,13 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
772820
{
773821
BaseType_t xReturn;
774822

823+
traceENTER_xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken );
824+
775825
traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
776826
xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
777827

828+
traceRETURN_xEventGroupSetBitsFromISR( xReturn );
829+
778830
return xReturn;
779831
}
780832

@@ -788,6 +840,8 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
788840
UBaseType_t xReturn;
789841
EventGroup_t const * pxEventBits = ( EventGroup_t * ) xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
790842

843+
traceENTER_uxEventGroupGetNumber( xEventGroup );
844+
791845
if( xEventGroup == NULL )
792846
{
793847
xReturn = 0;
@@ -797,6 +851,8 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
797851
xReturn = pxEventBits->uxEventGroupNumber;
798852
}
799853

854+
traceRETURN_uxEventGroupGetNumber( xReturn );
855+
800856
return xReturn;
801857
}
802858

@@ -808,7 +864,11 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
808864
void vEventGroupSetNumber( void * xEventGroup,
809865
UBaseType_t uxEventGroupNumber )
810866
{
867+
traceENTER_vEventGroupSetNumber( xEventGroup, uxEventGroupNumber );
868+
811869
( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
870+
871+
traceRETURN_vEventGroupSetNumber();
812872
}
813873

814874
#endif /* configUSE_TRACE_FACILITY */

0 commit comments

Comments
 (0)