Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Description

This function is called by by OS_TaskReturn(). OS_TaskReturn() is  is called if the user accidentally returns from the task code. In other words, the task should either be implemented as an infinite loop and never return, or the task must call call OSTaskDel((OS_TCB *)0, &err) to  to delete itself to prevent it from exiting. Anchor10053311005331

OSTaskReturnHook() is  is part of the CPU port code and this function function must not be  be called by the application code. OSTaskReturnHook() is  is actually used by the µC/OS-III port developer.

Anchor10053321005332Note that after calling calling OSTaskReturnHook(), OS_TaskReturn() will  will actually delete the task by calling:anchor10053331005333

OSTaskDel((OS_TCB *)0,

...

          &err)

...

Files

os.h/os_cpu_c.c and os_app_hooks.c

Prototype

Code Block
void  OSTaskReturnHook (OS_TCB  *p_tcb)

Arguments

p_tcb

is a pointer to the TCB of the task that is not behaving as expected. Note that the OS_TCB is validated by OS_TaskReturn(), and is guaranteed to not be a NULL pointer when OSTaskReturnHook() is called.

...

Returned Value

anchorNone10053391005339 None Anchor10053401005340 Notes/Warnings Anchor10053411005341

Required Configuration

OS_CFG_APP_HOOKS_EN must be enabled in os_cfg.h. Refer to µC-OS-III Configuration Manual.

Callers

OS_TaskReturn().

Notes/Warnings

  1. Do not call this function from the application.

...

Example

...

Usage

The code below calls an application-specific hook that the application programmer can define. For this, the user can simply set the value of OS_AppTaskReturnHookPtr to point to the desired hook function as shown in the example. If a task returns and forgets to call OSTaskDel((OS_TCB *)0, &err) then µC/OS-III will call OSTaskReturnHook() which in turns calls App_OS_TaskReturnHook() through OS_AppTaskReturnHookPtr. When called, the application hook is passed the address of the OS_TCB of the task returning.anchor

Code Block

...

void { /* Your code goes here! */ }     void
         */
          {
              /* Your code goes here! */
          }
           
           
          void App_OS_SetAllHooks (void)                              /* os_app_hooks.c
*/ {
         */
          {
              CPU_SR_ALLOC();
 

           
              CPU_CRITICAL_ENTER();
: OS_AppTaskReturnHookPtr =

              :
              OS_AppTaskReturnHookPtr = App_OS_TaskReturnHook;
:

              :
              CPU_CRITICAL_EXIT();
}     void OSTaskReturnHook

          }
           
           
          void  OSTaskReturnHook (OS_TCB *p_tcb)                      /* os_cpu_c.c
*/ { #if
             */
          {
          #if OS_CFG_APP_HOOKS_EN >
0u if
 0u
              if (OS_AppTaskReturnHookPtr != (OS_APP_HOOK_TCB)0) {    /* Call application hook
*/
  */
                  (*OS_AppTaskReturnHookPtr)(p_tcb);
} #endif }tr

              }
          #endif
          }
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
rowspan4
Anchor
10053461005346
titleOSTaskReturnHook() example usage
          void  App_OS_TaskReturnHook (OS_TCB  *p_tcb)                /* os_app_hooks.c
*/
Anchor
10053471005347
Anchor
10053481005348
Anchor
10053491005349
Anchor
10053501005350
Anchor
10053511005351
Anchor
10053521005352
Anchor
10053531005353
Anchor
10053541005354
Anchor
10053551005355
Anchor
10053571005357
Anchor
10053581005358
Anchor
10053591005359
Anchor
10053601005360
Anchor
10053621005362
Anchor
10053631005363
Anchor
10053641005364
Anchor
10053651005365
Anchor
10053661005366
Anchor
10053671005367
Anchor
10053681005368
Anchor
10053691005369
Anchor
10053701005370
Anchor
10053711005371
Anchor
10053721005372
Anchor
10053731005373
Table Row (tr)
Table Row (tr)