zoukankan      html  css  js  c++  java
  • UCOSIII钩子函数

    OSIdleTaskHook
    空闲任务调用这个函数,可以用来让CPU进入低功耗模式

    void  OSIdleTaskHook (void)
    {
    #if OS_CFG_APP_HOOKS_EN > 0u
        if (OS_AppIdleTaskHookPtr != (OS_APP_HOOK_VOID)0) {
            (*OS_AppIdleTaskHookPtr)();
        }
    #endif
    }

    OSInitHook
    系统初始化函数OSInit()调用此函数

    void  OSInitHook (void)
    {
        /* 8-byte align the ISR stack */    
        OS_CPU_ExceptStkBase = (CPU_STK *)(OSCfg_ISRStkBasePtr + OSCfg_ISRStkSize);
        OS_CPU_ExceptStkBase = (CPU_STK *)((CPU_STK)(OS_CPU_ExceptStkBase) & 0xFFFFFFF8);
    }

    OSStatTaskHook
    统计任务每秒中都会调用这个函数,此函数允许你向统计任务中添加自己的应用函数

    void  OSStatTaskHook (void)
    {
    #if OS_CFG_APP_HOOKS_EN > 0u
        if (OS_AppStatTaskHookPtr != (OS_APP_HOOK_VOID)0) {
            (*OS_AppStatTaskHookPtr)();
        }
    #endif
    }

    OSTaskCreateHook
    任务创建的钩子函数

    void  OSTaskCreateHook (OS_TCB  *p_tcb)
    {
    #if OS_CFG_APP_HOOKS_EN > 0u
        if (OS_AppTaskCreateHookPtr != (OS_APP_HOOK_TCB)0) {
            (*OS_AppTaskCreateHookPtr)(p_tcb);
        }
    #else
        (void)p_tcb; /* Prevent compiler warning */
    #endif
    }

    OSTaskDelHook
    任务删除的钩子函数

    void  OSTaskDelHook (OS_TCB  *p_tcb)
    {
    #if OS_CFG_APP_HOOKS_EN > 0u
        if (OS_AppTaskDelHookPtr != (OS_APP_HOOK_TCB)0) {
            (*OS_AppTaskDelHookPtr)(p_tcb);
        }
    #else
        (void)p_tcb; /* Prevent compiler warning */
    #endif
    }

    OSTaskReturnHook
    任务意外返回时调用的钩子函数,比如删除某个任务

    void  OSTaskReturnHook (OS_TCB  *p_tcb)
    {
    #if OS_CFG_APP_HOOKS_EN > 0u
        if (OS_AppTaskReturnHookPtr != (OS_APP_HOOK_TCB)0) {
            (*OS_AppTaskReturnHookPtr)(p_tcb);
        }
    #else
        (void)p_tcb; /* Prevent compiler warning */
    #endif
    }

    OSTaskSwHook
    任务切换时候调用的钩子函数

    void  OSTaskSwHook (void)
    {
    #if OS_CFG_TASK_PROFILE_EN > 0u
        CPU_TS  ts;
    #endif
    #ifdef  CPU_CFG_INT_DIS_MEAS_EN
        CPU_TS  int_dis_time;
    #endif
    
    
    #if (OS_CPU_ARM_FP_EN == DEF_ENABLED)
    //    if ((OSTCBCurPtr->Opt & OS_OPT_TASK_SAVE_FP) != (OS_OPT)0) {
    //        OS_CPU_FP_Reg_Push(OSTCBCurPtr->StkPtr);
    //    }
    
    //    if ((OSTCBHighRdyPtr->Opt & OS_OPT_TASK_SAVE_FP) != (OS_OPT)0) {
    //        OS_CPU_FP_Reg_Pop(OSTCBHighRdyPtr->StkPtr);
    //    }
    #endif
    
    #if OS_CFG_APP_HOOKS_EN > 0u
        if (OS_AppTaskSwHookPtr != (OS_APP_HOOK_VOID)0) {
            (*OS_AppTaskSwHookPtr)();
        }
    #endif
    
    #if (defined(TRACE_CFG_EN) && (TRACE_CFG_EN > 0u))
        TRACE_OS_TASK_SWITCHED_IN(OSTCBHighRdyPtr);             /* Record the event.                                      */
    #endif
    
    #if OS_CFG_TASK_PROFILE_EN > 0u
        ts = OS_TS_GET();
        if (OSTCBCurPtr != OSTCBHighRdyPtr) {
            OSTCBCurPtr->CyclesDelta  = ts - OSTCBCurPtr->CyclesStart;
            OSTCBCurPtr->CyclesTotal += (OS_CYCLES)OSTCBCurPtr->CyclesDelta;
        }
    
        OSTCBHighRdyPtr->CyclesStart = ts;
    #endif
    
    #ifdef  CPU_CFG_INT_DIS_MEAS_EN
        int_dis_time = CPU_IntDisMeasMaxCurReset(); /* Keep track of per-task interrupt disable time */
        if (OSTCBCurPtr->IntDisTimeMax < int_dis_time) {
            OSTCBCurPtr->IntDisTimeMax = int_dis_time;
        }
    #endif
    
    #if OS_CFG_SCHED_LOCK_TIME_MEAS_EN > 0u
        /* Keep track of per-task scheduler lock time */
        if (OSTCBCurPtr->SchedLockTimeMax < OSSchedLockTimeMaxCur) {
            OSTCBCurPtr->SchedLockTimeMax = OSSchedLockTimeMaxCur;
        }
        OSSchedLockTimeMaxCur = (CPU_TS)0; /* Reset the per-task value */
    #endif
    }

    OSTimeTickHook
    滴答定时器调用的钩子函数

    void  OSTimeTickHook (void)
    {
    #if OS_CFG_APP_HOOKS_EN > 0u
        if (OS_AppTimeTickHookPtr != (OS_APP_HOOK_VOID)0) {
            (*OS_AppTimeTickHookPtr)();
        }
    #endif
    }

    使用举例

    void  App_OS_SetAllHooks (void)
    {
    #if OS_CFG_APP_HOOKS_EN > 0u
        CPU_SR_ALLOC();
    
    
        CPU_CRITICAL_ENTER();
        OS_AppTaskCreateHookPtr = App_OS_TaskCreateHook;
        OS_AppTaskDelHookPtr    = App_OS_TaskDelHook;
        OS_AppTaskReturnHookPtr = App_OS_TaskReturnHook;
    
        OS_AppIdleTaskHookPtr   = App_OS_IdleTaskHook;
        OS_AppStatTaskHookPtr   = App_OS_StatTaskHook;
        OS_AppTaskSwHookPtr     = App_OS_TaskSwHook;
        OS_AppTimeTickHookPtr   = App_OS_TimeTickHook;
        CPU_CRITICAL_EXIT();
    #endif
    }
    
    void App_OS_IdleTaskHook (void)
    {
        static int num;
        num++;
        if(num%50000==0)
        {
            printf("Idle Task Running 50000 times!
    ");
        }
    }

    实验现象
    1

  • 相关阅读:
    Objective-C 关于锁的种类
    iOS多线程编程Part 1/3
    isa基础知识
    block学习笔记
    关于GCD使用
    iOS开发多线程篇—NSOperation基本操作
    iOS开发多线程篇—基础知识 NSOperation
    iOS开发多线程篇—单例模式(ARC)
    iOS开发多线程篇—GCD的常见用法
    OS开发多线程篇—线程间的通信
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709499.html
Copyright © 2011-2022 走看看