From 2f94b181a2f049ec342deba0927bed51f7174ab0 Mon Sep 17 00:00:00 2001 From: Boris van der Meer Date: Fri, 8 Sep 2023 01:20:13 +0200 Subject: [PATCH] Add Trace Hook Macros and function that returns the start of the stack. (#659) * Add Trace Hook Macros and function that returns the start of the stack. * Remove obsolete functions. --------- Co-authored-by: kar-rahul-aws <118818625+kar-rahul-aws@users.noreply.github.com> Co-authored-by: Rahul Kar Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> --- include/FreeRTOS.h | 20 ++++++++++++++++++++ portable/GCC/ARM_CM7/r0p1/port.c | 7 +++++++ portable/GCC/ARM_CM7/r0p1/portmacro.h | 7 +++++-- tasks.c | 4 ++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index 980c9d0f823..a2b84185f70 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -653,6 +653,14 @@ #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) #endif +#ifndef traceMOVED_TASK_TO_DELAYED_LIST + #define traceMOVED_TASK_TO_DELAYED_LIST() +#endif + +#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST + #define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() +#endif + #ifndef traceQUEUE_CREATE #define traceQUEUE_CREATE( pxNewQueue ) #endif @@ -901,6 +909,18 @@ #define traceTASK_NOTIFY_GIVE_FROM_ISR( uxIndexToNotify ) #endif +#ifndef traceISR_EXIT_TO_SCHEDULER + #define traceISR_EXIT_TO_SCHEDULER() +#endif + +#ifndef traceISR_EXIT + #define traceISR_EXIT() +#endif + +#ifndef traceISR_ENTER + #define traceISR_ENTER() +#endif + #ifndef traceSTREAM_BUFFER_CREATE_FAILED #define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) #endif diff --git a/portable/GCC/ARM_CM7/r0p1/port.c b/portable/GCC/ARM_CM7/r0p1/port.c index ccaaf884ec3..c22a3592b7b 100644 --- a/portable/GCC/ARM_CM7/r0p1/port.c +++ b/portable/GCC/ARM_CM7/r0p1/port.c @@ -511,14 +511,21 @@ void xPortSysTickHandler( void ) * save and then restore the interrupt mask value as its value is already * known. */ portDISABLE_INTERRUPTS(); + traceISR_ENTER(); { /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE ) { + traceISR_EXIT_TO_SCHEDULER(); + /* A context switch is required. Context switching is performed in * the PendSV interrupt. Pend the PendSV interrupt. */ portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } + else + { + traceISR_EXIT(); + } } portENABLE_INTERRUPTS(); } diff --git a/portable/GCC/ARM_CM7/r0p1/portmacro.h b/portable/GCC/ARM_CM7/r0p1/portmacro.h index 96d5e35798c..d32af2b753e 100644 --- a/portable/GCC/ARM_CM7/r0p1/portmacro.h +++ b/portable/GCC/ARM_CM7/r0p1/portmacro.h @@ -95,8 +95,11 @@ typedef unsigned long UBaseType_t; #define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) ) #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) -#define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired != pdFALSE ) portYIELD( ); } while( 0 ) -#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) +#define portEND_SWITCHING_ISR( xSwitchRequired ) \ + do { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } \ + else { traceISR_EXIT(); } \ + } while( 0 ) +#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) /*-----------------------------------------------------------*/ /* Critical section management. */ diff --git a/tasks.c b/tasks.c index 01f972ba0ff..eee6a8c7077 100644 --- a/tasks.c +++ b/tasks.c @@ -7577,12 +7577,14 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, { /* Wake time has overflowed. Place this item in the overflow * list. */ + traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); } else { /* The wake time has not overflowed, so the current block list * is used. */ + traceMOVED_TASK_TO_DELAYED_LIST(); vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); /* If the task entering the blocked state was placed at the @@ -7611,11 +7613,13 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, if( xTimeToWake < xConstTickCount ) { + traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); /* Wake time has overflowed. Place this item in the overflow list. */ vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); } else { + traceMOVED_TASK_TO_DELAYED_LIST(); /* The wake time has not overflowed, so the current block list is used. */ vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );