Hoe to get the Task Number?

2014-03-15
2014-03-16
  • Alain Mouette

    Alain Mouette - 2014-03-15

    Inside vApplicationStackOverflowHook(), I need to get the Task number for error report.
    How can I get it from the xTaskHandle?

    Thanks, Alain

     
  • Real Time Engineers ltd.

    You can use the function:

    UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask );

    I'm not sure if that is documented as it is intended for internal and tracing use really. configUSE_TRACE_FACILITY must be set to 1 in FreeRTOSConfig.h.

    Note if the stack has overflowed then you may find the task handle passed into the hook function is corrupt. In which case you can use the pxCurrentTCB variable to get the handle instead, but you will have to declare it as an extern inside your hook function to make it available.

    Finally you could also keep a track of the number of the task that is currently running by defining a trace macro (assuming you are not using the trace macros for anything else). To do that declare a variable in your main.c (or somewhere else suitable) as per:

    
    UBaseType_t uxCurrentTaskNumber = 0;
    

    Then at the bottom of FreeRTOSConfig.h add:

    
    extern UBaseType_t uxCurrentTaskNumber;
    #define traceTASK_SWITCHED_IN() uxCurrentTaskNumber = pxCurrentTCB->uxTaskNumber;
    

    then in your hook you can just look at the uxCurrentTaskNumber variable.

    Regards.

     
    Last edit: Real Time Engineers ltd. 2014-03-15
    • Alain Mouette

      Alain Mouette - 2014-03-16

      Hi, thanks for the promp reply :)

      the third option is probably the simplest... BUT...

      IT ONLY WORKS with pxCurrentTCB->uxTCBNumber !!!
      uxTaskNumber doesn't seem to be updated and uxTCBNumber is what I get in
      pxTaskStatusArray (which serves as reference anyway...)

      I has to change UBaseType -> portBASE_TYPE -> long
      I am using 7.6.0 version because I expect trouble with LWIP. And also
      because portBASE_TYPE is defined inside portmacro.h wich is not known to
      my main.c

      NOTE: It's unfortunate that tskTaskControlBlock is defined only inside
      tasks.c, it would be much easier to use in tasks.h. Maybe not safe...
      the world isn't perfect...

      thanks,
      Alain

      Em 15-03-2014 11:54, Real Time Engineers ltd. escreveu:

      You can use the function:

      UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask );

      I'm not sure if that is documented as it is intended for internal and
      tracing use really. configUSE_TRACE_FACILITY must be set to 1 in
      FreeRTOSConfig.h.

      Note if the stack has overflowed then you may find the task handle
      passed into the hook function is corrupt. In which case you can use
      the pxCurrentTCB variable to get the handle instead, but you will have
      to declare it as an extern inside your hook function to make it available.

      Finally you could also keep a track of the number of the task that is
      currently running by defining a trace macro (assuming you are not
      using the trace macros for anything else). To do that declare a
      variable in your main.c (or somewhere else suitable) as per:

      ||

      UBaseType_t uxCurrentTaskNumber = 0;

      Then at the bottom of FreeRTOSConfig.h add:

      ||

      extern UBaseType_t uxCurrentTaskNumber;

      define traceTASK_SWITCHED_IN() uxCurrentTaskNumber =
      pxCurrentTCB->uxTaskNumber;

      then in your hook you can just look at the uxCurrentTaskNumber variable.

      Regards.


      Hoe to get the Task Number?
      https://sourceforge.net/p/freertos/discussion/382005/thread/77ed94e2/?limit=25#b2fe


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/freertos/discussion/382005/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks