Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
void  OSIdleTaskHook (void);

File

Called from

Code enabled by

os_cpu_c.c

OS_IdleTask() ONLY

N/A

Description

This function is called by by OS_IdleTask().

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

OSIdleTaskHook() runs  runs in the context of the idle task and thus it is important to make sure there is sufficient stack space in the idle task. OSIdleTaskHook() must not make any  make any OS???Pend() calls calls, call call OSTaskSuspend() or  or OSTimeDly???(). In other words, this function must never be allowed to make a blocking call.

Files

os.h/os_cpu_c.c and os_app_hooks.c

Prototype

Code Block
void  OSIdleTaskHook (void)

Arguments

None

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

OS_IdleTask().

Notes/Warnings

  1. Never make blocking calls from OSIdleTaskHook().
  2. Do not call this function from you 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_AppIdleTaskHookPtr to point to the desired hook function which in this case is assumed to be defined in os_app_hooks.c. The idle task calls OSIdleTaskHook() which in turns calls App_OS_IdleTaskHook() through OS_AppIdleTaskHookPtr.

This feature is very useful when there is a processor that can enter low-power mode. When µC/OS-III has no other task to run, the processor can be put to sleep waiting for an interrupt to wake it up.

Code Block
titleOSIdleTaskHook() example usage
          void  App_OS_IdleTaskHook (void)                           /* See os_app_hooks.c    */
          {
              /* Your code goes here! */
              /* Put the CPU in low power mode (optional) */
          }
           
           
          void App_OS_SetAllHooks (void)                             /* os_app_hooks.c        */
          {
              CPU_SR_ALLOC();
           
              CPU_CRITICAL_ENTER();
              :
              OS_AppIdleTaskHookPtr = App_OS_IdleTaskHook;
              :
              CPU_CRITICAL_EXIT();
          }
           
           
          void  OSIdleTaskHook (void)                                /* See os_cpu_c.c        */
          {
          #if OS_CFG_APP_HOOKS_EN > 0u
              if (OS_AppIdleTaskHookPtr != (OS_APP_HOOK_VOID)0) {    /* Call application hook */
                  (*OS_AppIdleTaskHookPtr)();
              }
          #endif
          }