OSTaskCreateHook

Description

This function is called by OSTaskCreate() after initializing the OS_TCB fields and setting up the stack frame for the task, just before adding the task to the ready list. When OSTaskCreateHook() is called, all of the OS_TCB fields are assumed to be initialized.

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

You can use this hook to initialize and store the contents of floating-point registers, MMU registers, or anything else that can be associated with a task. Typically, you would store this additional information in memory allocated by the application.

Files

os.h/os_cpu_c.c and os_app_hooks.c

Prototype

void  OSTaskCreateHook (OS_TCB  *p_tcb)

Arguments

p_tcb

is a pointer to the TCB of the task being created. Note that the OS_TCB has been validated by OSTaskCreate() and is guaranteed to not be a NULL pointer when OSTaskCreateHook() is called.

Returned Value

None

Required Configuration

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

Callers

OSTaskCreate().

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. The user can simply set the value of OS_AppTaskCreateHookPtr to point to the desired hook function as shown in the example. OSTaskCreate() calls OSTaskCreateHook() which in turns calls App_OS_TaskCreateHook() through OS_AppTaskCreateHookPtr. As can be seen, when called, the application hook is passed the address of the OS_TCB of the newly created task.

OSTaskCreateHook() example usage
          void  App_OS_TaskCreateHook (OS_TCB *p_tcb)                 /* os_app_hooks.c         */
          {
              /* Your code goes here! */
          }
           
           
          void App_OS_SetAllHooks (void)                              /* os_app_hooks.c         */
          {
              CPU_SR_ALLOC();
           
              CPU_CRITICAL_ENTER();
              :
              OS_AppTaskCreateHookPtr = App_OS_TaskCreateHook;
              :
              CPU_CRITICAL_EXIT();
          }
           
           
          void  OSTaskCreateHook (OS_TCB *p_tcb)                      /* os_cpu_c.c             */
          {
          #if OS_CFG_APP_HOOKS_EN > 0u
              if (OS_AppTaskCreateHookPtr != (OS_APP_HOOK_TCB)0) {    /* Call application hook  */
                  (*OS_AppTaskCreateHookPtr)(p_tcb);
              }
          #endif
          }