Use of xTaskGetApplicationTaskTag within an interrupt handler

laugenslug wrote on Friday, October 05, 2018:

I am using the Coretex-M4 port of FreeRTOS, version 10.1.1, and I get a configASSERT when I use the function xTaskGetApplicationTaskTag within the traceTASK_SWITCHED_IN handler. This topic has already been discussed at:

https://www.freertos.org/FreeRTOS_Support_Forum_Archive/March_2016/freertos_Use_of_xTaskGetApplicationTaskTag_within_an_interrupt_handler_045d9b72j.html

However, no solution was supplied, other than a suggestion to comment out the offending configASSERT. Is there a plan to make a xTaskGetApplicationTaskTagFromISR function to solve this problem properly?

I would also like to point out that accessing pxCurrentTCB directly is no solution, as this pointer is statically defined in tasks.c. This is good data hiding practice, but does not help me in this instance.

Thank you

rtel wrote on Friday, October 05, 2018:

Which assert are you hitting? I can’t see one in that function -
although there is one in taskENTER_CRITICAL() which is called from that
function - but that will only get hit if interrupt priorities are invalid.

rtel wrote on Friday, October 05, 2018:

Sorry - look properly - the assert in ENTER_CRITICAL() is checking if it
is being called from an interrupt - so that probably is the problem.

One answer would be to provide a FromISR() version of
xTaskGetApplicationTaskTag() - would that be helpful for you?

laugenslug wrote on Monday, October 08, 2018:

@Richard Barry. Yes, I think a FromISR() version of xTaskGetApplicationTaskTag() would be helpful for me.

It is as you wrote in your second reply. The assert in taskENTER_CRITICAL() is being hit, because the OS is already in a critical section / in the ISR.

rtel wrote on Monday, October 08, 2018:

Try checking out the latest head revision from SVN - xTaskGetApplicationTaskTagFromISR() is implemented on line 2870 (or thereabouts) of https://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Source/tasks.c

laugenslug wrote on Wednesday, October 10, 2018:

@Richard Barry. Thank you!! It works!!

I made the following tests

  • My test environment is an LPC4088 Quick Start Board from Embedded Artists. This is a Cortex M4 processor
  • I am running FreeRTOS version 10.1.1, using the ARM_CM4F port, patched with tasks.c and tasks.h from svn revieion r2588
  • I have defined the macros traceTASK_SWITCHED_IN and traceTASK_SWITCHED_OUT in FreeRTOSConfig.h
  • I call the new function xTaskGetApplicationTaskTagFromISR from within the traceTASK_SWITCHED_IN function
  • The function returned the expected value (originally set from vTaskSetApplicationTaskTag)

Once again, thank you for the excellent support
Peter