Versions Compared

Key

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

...

os.h/os_cpu_c.c and os_app_hooks.c

Prototype

Code Block
void  OSTaskSwHook (void)

Arguments

None

Returned Values

...

The code below calls an application specific hook that the application programmer can define. The user can simply set the value of OS_AppTaskSwHookPtr to point to the desired hook function. When µC/OS-III performs a context switch, it calls OSTaskSwHook() which in turn calls App_OS_TaskSwHook() through OS_AppTaskSwHookPtr.

Code Block
titleOSTaskSwHook() example usage
          void  App_OS_TaskSwHook (void)                              /* os_app_hooks.c          */
          {
              /* Your code goes here! */
          }
           
           
          void App_OS_SetAllHooks (void)                              /* os_app_hooks.c          */
          {
              CPU_SR_ALLOC();
           
              CPU_CRITICAL_ENTER();
              :
              OS_AppTaskSwHookPtr = App_OS_TaskSwHook;
              :
              CPU_CRITICAL_EXIT();
          }
           
          void  OSTaskSwHook (void)                                   /* os_cpu_c.c              */
          {
          #if OS_CFG_TASK_PROFILE_EN > 0u
              CPU_TS     ts;
          #endif
          #ifdef  CPU_CFG_TIME_MEAS_INT_DIS_EN
              CPU_TS     int_dis_time;        
          #endif
           
 
          #if OS_CFG_APP_HOOKS_EN > 0u
              if (OS_AppTaskSwHookPtr != (OS_APP_HOOK_VOID)0) {
                  (*OS_AppTaskSwHookPtr)();
              }
          #endif
 
          #if OS_CFG_TASK_PROFILE_EN > 0u
              ts = OS_TS_GET();
              if (OSTCBCurPtr != OSTCBHighRdyPtr) {
                  OSTCBCurPtr->CyclesDelta  = ts - OSTCBCurPtr->CyclesStart;
                  OSTCBCurPtr->CyclesTotal += OSTCBCurPtr->CyclesDelta;
              }
              OSTCBHighRdyPtr->CyclesStart = ts;
          #endif
 
          #ifdef  CPU_CFG_INT_DIS_MEAS_EN        
              int_dis_time = CPU_IntDisMeasMaxCurReset();
              if (int_dis_time > OSTCBCurPtr->IntDisTimeMax) {
                  OSTCBCurPtr->IntDisTimeMax = int_dis_time;
              }
          #endif
 
          #if OS_CFG_SCHED_LOCK_TIME_MEAS_EN > 0u
              if (OSTCBCurPtr->SchedLockTimeMax < OSSchedLockTimeMaxCur) {
                  OSTCBCurPtr->SchedLockTimeMax = OSSchedLockTimeMaxCur;
              }
              OSSchedLockTimeMaxCur         = (CPU_TS)0;              
          #endif
 
          #if (OS_CFG_TASK_STK_REDZONE_EN == DEF_ENABLED)
              stk_status = OSTaskStkRedzoneChk(DEF_NULL);
              if (stk_status != DEF_OK) {
                  OSRedzoneHitHook(OSTCBCurPtr);
              }
          #endif
          }