Skip to content

Commit

Permalink
Add portTASK_SWITCH_HOOK (#867)
Browse files Browse the repository at this point in the history
This commit adds a portTASK_SWITCH_HOOK() macro which allows ports to inject
behavior immediately after a context switch. For example, this macro could be
used by ports that need to set an end of stack watchpoint after a context
swtich.

Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Soren Ptak <ptaksoren@gmail.com>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Tony Josi <tonyjosi@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
  • Loading branch information
6 people authored Dec 11, 2023
1 parent 30e6b8a commit bd0f87c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@
#define portSETUP_TCB( pxTCB ) ( void ) ( pxTCB )
#endif

#ifndef portTASK_SWITCH_HOOK
#define portTASK_SWITCH_HOOK( pxTCB ) ( void ) ( pxTCB )
#endif

#ifndef configQUEUE_REGISTRY_SIZE
#define configQUEUE_REGISTRY_SIZE 0U
#endif
Expand Down
10 changes: 10 additions & 0 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5153,6 +5153,11 @@ BaseType_t xTaskIncrementTick( void )
taskSELECT_HIGHEST_PRIORITY_TASK();
traceTASK_SWITCHED_IN();

/* Macro to inject port specific behaviour immediately after
* switching tasks, such as setting an end of stack watchpoint
* or reconfiguring the MPU. */
portTASK_SWITCH_HOOK( pxCurrentTCB );

/* After the new task is switched in, update the global errno. */
#if ( configUSE_POSIX_ERRNO == 1 )
{
Expand Down Expand Up @@ -5245,6 +5250,11 @@ BaseType_t xTaskIncrementTick( void )
taskSELECT_HIGHEST_PRIORITY_TASK( xCoreID );
traceTASK_SWITCHED_IN();

/* Macro to inject port specific behaviour immediately after
* switching tasks, such as setting an end of stack watchpoint
* or reconfiguring the MPU. */
portTASK_SWITCH_HOOK( pxCurrentTCBs[ portGET_CORE_ID() ] );

/* After the new task is switched in, update the global errno. */
#if ( configUSE_POSIX_ERRNO == 1 )
{
Expand Down

0 comments on commit bd0f87c

Please # to comment.