From 7e12290c751b4b7e07e1db2099e86b482303f88f Mon Sep 17 00:00:00 2001 From: rtel Date: Mon, 8 Oct 2018 15:10:18 +0000 Subject: [PATCH] Add xTaskGetApplicationTaskTagFromISR(), which is an interrupt safe version of xTaskGetApplicationTaskTagFrom(). git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2588 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo | Bin 56832 -> 56832 bytes .../WIN32-MingW/code_coverage_additions.c | 16 +++++++ FreeRTOS/Source/include/mpu_prototypes.h | 1 + FreeRTOS/Source/include/mpu_wrappers.h | 1 + FreeRTOS/Source/include/task.h | 13 +++++- .../Source/portable/Common/mpu_wrappers.c | 13 ++++++ FreeRTOS/Source/tasks.c | 40 +++++++++++++----- 7 files changed, 72 insertions(+), 12 deletions(-) diff --git a/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo b/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo index 138d3b80c5931bbe53fbc7bc6c1ff6b3c815347f..11cf75261bbdc5678c1a45f798db6cad9f36322d 100644 GIT binary patch delta 1828 zcmbtUZ)jUp6u=NjA6rg4)oY|U(tp_o6-+XgbLZrK-YO}3`s zw6(8m#W_3IzJvJZL&0ocM9?-DM4@Ofei*3G4}$2YxUc$QLW>(XpXa` z&%O8D^E>z4W2`!iRmVaEu4NU!%9xum=0N;mSr!V$SDx4@Db<%krOeUqco$4a(|jB@ zq*)$?Gmh7scjKO$@T=mR#sgLd&PevuCd7(jyQpUd3P{K#^-S| ziXgoXSa$l&X4#1*%Mw4hJ0&wQq;PsON&~zZ3PT~0a#3C=U$$XAVen^QBAIl_XlkvQ zoll{17H(`!LVC3WB9bBsYLdfH?|>O7@E2erFwMtcBan3Ya3^Jyyg4Zp24}WCrf@17 z${^WWo9bNT(%t{> zc}iQp;x6hg^v}tiyMPJ>fCG5wpom4vywn@#u0ga=U)dzwH*d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GxY3FJ87-0=x^@RRIb*xc|*EU1C*vyh* zEwZUMYpLhqw!ewd4qfPNKZDtJMd1ek_b*goK-NUEEf>s=gbLiqwilBfK@GSw4fgVJ zM1q}8eiceBM=sxJz7RajJW5i-&Ys$_YYLs=7R=jG zi+Z>tWdm|{ydyykDA%Z|1h`t>u0cj(KSl?g7&V$z;45rb3}g6IUPk9X=E*tvO)!CQ=zTgCt!=2=CcggV|asDj!>;f?Kcin(iD2g^i2x@Dad@ zfeA73#2CZ}Jte|(`i2@inh#qLM#o?q-Wn~#8#{CeV?VKTqy2I#pm*$&S$!J6AM0@h zq=2}3=CC7sE8Q7BEm^|(nOS`1l_8v-%fg!Ii_;*^U-;IQ-$w$|qjGVCxp-Y1lK**eaC!H4 Tx3}!B$$)^%>mb%Yg6cm3Tgo|# diff --git a/FreeRTOS/Demo/WIN32-MingW/code_coverage_additions.c b/FreeRTOS/Demo/WIN32-MingW/code_coverage_additions.c index 5aafe110b..1c4ec6714 100644 --- a/FreeRTOS/Demo/WIN32-MingW/code_coverage_additions.c +++ b/FreeRTOS/Demo/WIN32-MingW/code_coverage_additions.c @@ -508,12 +508,22 @@ TaskHandle_t xTask; } } + /* Try FromISR version too. */ + if( xTaskGetApplicationTaskTagFromISR( xTask ) != prvDummyTagFunction ) + { + xReturn = pdFAIL; + } + /* Now try with a NULL handle, so using this task. */ vTaskSetApplicationTaskTag( NULL, NULL ); if( xTaskGetApplicationTaskTag( NULL ) != NULL ) { xReturn = pdFAIL; } + if( xTaskGetApplicationTaskTagFromISR( NULL ) != NULL ) + { + xReturn = pdFAIL; + } vTaskSetApplicationTaskTag( NULL, prvDummyTagFunction ); if( xTaskGetApplicationTaskTag( NULL ) != prvDummyTagFunction ) @@ -532,6 +542,12 @@ TaskHandle_t xTask; } } + /* Try FromISR version too. */ + if( xTaskGetApplicationTaskTagFromISR( NULL ) != prvDummyTagFunction ) + { + xReturn = pdFAIL; + } + vTaskSetApplicationTaskTag( NULL, NULL ); if( xTaskGetApplicationTaskTag( NULL ) != NULL ) { diff --git a/FreeRTOS/Source/include/mpu_prototypes.h b/FreeRTOS/Source/include/mpu_prototypes.h index 9b9492231..55ee9a23e 100644 --- a/FreeRTOS/Source/include/mpu_prototypes.h +++ b/FreeRTOS/Source/include/mpu_prototypes.h @@ -64,6 +64,7 @@ UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask ); configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ); void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ); TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask ); +TaskHookFunction_t MPU_xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ); void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ); void * MPU_pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ); BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ); diff --git a/FreeRTOS/Source/include/mpu_wrappers.h b/FreeRTOS/Source/include/mpu_wrappers.h index 96e94ffe4..04348c614 100644 --- a/FreeRTOS/Source/include/mpu_wrappers.h +++ b/FreeRTOS/Source/include/mpu_wrappers.h @@ -70,6 +70,7 @@ only for ports that are using the MPU. */ #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2 #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag + #define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook diff --git a/FreeRTOS/Source/include/task.h b/FreeRTOS/Source/include/task.h index a03ff82a6..446f6fa88 100644 --- a/FreeRTOS/Source/include/task.h +++ b/FreeRTOS/Source/include/task.h @@ -1477,9 +1477,20 @@ constant. */ * task.h *
void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
* - * Returns the pxHookFunction value assigned to the task xTask. + * Returns the pxHookFunction value assigned to the task xTask. Do not + * call from an interrupt service routine - call + * xTaskGetApplicationTaskTagFromISR() instead. */ TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + + /** + * task.h + *
void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
+ * + * Returns the pxHookFunction value assigned to the task xTask. Can + * be called from an interrupt service routine. + */ + TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; #endif /* configUSE_APPLICATION_TASK_TAG ==1 */ #endif /* ifdef configUSE_APPLICATION_TASK_TAG */ diff --git a/FreeRTOS/Source/portable/Common/mpu_wrappers.c b/FreeRTOS/Source/portable/Common/mpu_wrappers.c index cb86b793e..ca490d6bf 100644 --- a/FreeRTOS/Source/portable/Common/mpu_wrappers.c +++ b/FreeRTOS/Source/portable/Common/mpu_wrappers.c @@ -357,6 +357,19 @@ BaseType_t xRunningPrivileged = xPortRaisePrivilege(); #endif /*-----------------------------------------------------------*/ +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + TaskHookFunction_t MPU_xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) + { + TaskHookFunction_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetApplicationTaskTagFromISR( xTask ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) { diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index e494bbcef..75fa4631c 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -2845,24 +2845,17 @@ BaseType_t xSwitchRequired = pdFALSE; TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) { - TCB_t *xTCB; + TCB_t *pxTCB; TaskHookFunction_t xReturn; - /* If xTask is NULL then we are setting our own task hook. */ - if( xTask == NULL ) - { - xTCB = ( TCB_t * ) pxCurrentTCB; - } - else - { - xTCB = xTask; - } + /* If xTask is NULL then set the calling task's hook. */ + pxTCB = prvGetTCBFromHandle( xTask ); /* Save the hook function in the TCB. A critical section is required as the value can be accessed from an interrupt. */ taskENTER_CRITICAL(); { - xReturn = xTCB->pxTaskTag; + xReturn = pxTCB->pxTaskTag; } taskEXIT_CRITICAL(); @@ -2872,6 +2865,31 @@ BaseType_t xSwitchRequired = pdFALSE; #endif /* configUSE_APPLICATION_TASK_TAG */ /*-----------------------------------------------------------*/ +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) + { + TCB_t *pxTCB; + TaskHookFunction_t xReturn; + UBaseType_t uxSavedInterruptStatus; + + /* If xTask is NULL then set the calling task's hook. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + /* Save the hook function in the TCB. A critical section is required as + the value can be accessed from an interrupt. */ + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + xReturn = pxTCB->pxTaskTag; + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) -- 2.39.5