Skip to content

Commit d8ca0e1

Browse files
committed
Add Trace Hook Macros and function that returns the start of the stack.
1 parent aa987a3 commit d8ca0e1

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

include/FreeRTOS.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@
243243
#define INCLUDE_uxTaskGetStackHighWaterMark2 0
244244
#endif
245245

246+
#ifndef INCLUDE_pxTaskGetStackStart
247+
#define INCLUDE_pxTaskGetStackStart 0
248+
#endif
249+
246250
#ifndef INCLUDE_eTaskGetState
247251
#define INCLUDE_eTaskGetState 0
248252
#endif
@@ -511,6 +515,18 @@
511515
#define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )
512516
#endif
513517

518+
#ifndef traceMOVED_TASK_TO_DELAYED_LIST
519+
#define traceMOVED_TASK_TO_DELAYED_LIST()
520+
#endif
521+
522+
#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST
523+
#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST()
524+
#endif
525+
526+
#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST
527+
#define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB )
528+
#endif
529+
514530
#ifndef traceQUEUE_CREATE
515531
#define traceQUEUE_CREATE( pxNewQueue )
516532
#endif
@@ -759,6 +775,18 @@
759775
#define traceTASK_NOTIFY_GIVE_FROM_ISR( uxIndexToNotify )
760776
#endif
761777

778+
#ifndef traceISR_EXIT_TO_SCHEDULER
779+
#define traceISR_EXIT_TO_SCHEDULER()
780+
#endif
781+
782+
#ifndef traceISR_EXIT
783+
#define traceISR_EXIT()
784+
#endif
785+
786+
#ifndef traceISR_ENTER
787+
#define traceISR_ENTER()
788+
#endif
789+
762790
#ifndef traceSTREAM_BUFFER_CREATE_FAILED
763791
#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )
764792
#endif

include/task.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,27 @@ UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTIO
15971597
*/
15981598
configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
15991599

1600+
/**
1601+
* task.h
1602+
* @code{c}
1603+
* uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);
1604+
* @endcode
1605+
*
1606+
* INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for
1607+
* this function to be available.
1608+
*
1609+
* Returns the start of the stack associated with xTask. That is,
1610+
* the highest stack memory address on architectures where the stack grows down
1611+
* from high memory, and the lowest memory address on architectures where the
1612+
* stack grows up from low memory.
1613+
*
1614+
* @param xTask Handle of the task associated with the stack returned.
1615+
* Set xTask to NULL to return the stack of the calling task.
1616+
*
1617+
* @return A pointer to the start of the stack.
1618+
*/
1619+
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION;
1620+
16001621
/* When using trace macros it is sometimes necessary to include task.h before
16011622
* FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
16021623
* so the following two prototypes will cause a compilation error. This can be

portable/GCC/ARM_CM7/r0p1/port.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,20 @@ void xPortSysTickHandler( void )
525525
* save and then restore the interrupt mask value as its value is already
526526
* known. */
527527
portDISABLE_INTERRUPTS();
528+
traceISR_ENTER();
528529
{
529530
/* Increment the RTOS tick. */
530531
if( xTaskIncrementTick() != pdFALSE )
531532
{
533+
traceISR_EXIT_TO_SCHEDULER();
532534
/* A context switch is required. Context switching is performed in
533535
* the PendSV interrupt. Pend the PendSV interrupt. */
534536
portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
535537
}
538+
else
539+
{
540+
traceISR_EXIT();
541+
}
536542
}
537543
portENABLE_INTERRUPTS();
538544
}

portable/GCC/ARM_CM7/r0p1/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494

9595
#define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) )
9696
#define portNVIC_PENDSVSET_BIT ( 1UL << 28UL )
97-
#define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired != pdFALSE ) portYIELD(); } while( 0 )
97+
#define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else { traceISR_EXIT(); } } while( 0 )
9898
#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
9999
/*-----------------------------------------------------------*/
100100

tasks.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
17081708
mtCOVERAGE_TEST_MARKER();
17091709
}
17101710

1711+
traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB);
17111712
vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) );
17121713

17131714
#if ( configUSE_TASK_NOTIFICATIONS == 1 )
@@ -3988,6 +3989,21 @@ static void prvCheckTasksWaitingTermination( void )
39883989
#endif /* INCLUDE_uxTaskGetStackHighWaterMark */
39893990
/*-----------------------------------------------------------*/
39903991

3992+
#if (INCLUDE_pxTaskGetStackStart == 1)
3993+
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask)
3994+
{
3995+
TCB_t *pxTCB;
3996+
UBaseType_t uxReturn;
3997+
(void)uxReturn;
3998+
3999+
pxTCB = prvGetTCBFromHandle( xTask );
4000+
return ( uint8_t * ) pxTCB->pxStack;
4001+
}
4002+
4003+
#endif /* INCLUDE_pxTaskGetStackStart */
4004+
/*-----------------------------------------------------------*/
4005+
4006+
39914007
#if ( INCLUDE_vTaskDelete == 1 )
39924008

39934009
static void prvDeleteTCB( TCB_t * pxTCB )
@@ -5412,12 +5428,14 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
54125428
{
54135429
/* Wake time has overflowed. Place this item in the overflow
54145430
* list. */
5431+
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
54155432
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
54165433
}
54175434
else
54185435
{
54195436
/* The wake time has not overflowed, so the current block list
54205437
* is used. */
5438+
traceMOVED_TASK_TO_DELAYED_LIST();
54215439
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
54225440

54235441
/* If the task entering the blocked state was placed at the
@@ -5446,11 +5464,13 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
54465464

54475465
if( xTimeToWake < xConstTickCount )
54485466
{
5467+
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
54495468
/* Wake time has overflowed. Place this item in the overflow list. */
54505469
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
54515470
}
54525471
else
54535472
{
5473+
traceMOVED_TASK_TO_DELAYED_LIST();
54545474
/* The wake time has not overflowed, so the current block list is used. */
54555475
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
54565476

0 commit comments

Comments
 (0)