⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_probe.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 2 页
字号:
* Argument(s) : ptcb        Pointer to the task control block of the task being created.
*
* Return(s)   : none.
*
* Caller(s)   : App_TaskCreateHook().
*
* Note(s)     : (1) Interrupts are disabled during this call.
*
*               (2) This MUST be called from applications's task create hook function App_TaskCreateHook().
*********************************************************************************************************
*/

#if (OS_PROBE_HOOKS_EN > 0)
void  OSProbe_TaskCreateHook (OS_TCB *ptcb)
{
    ptcb->OSTCBCyclesStart = OSProbe_TimeGetCycles();           /* Get the current start time for this task.            */
    ptcb->OSTCBCyclesTot   = 0;                                 /* Update the task's total execution time.              */
}
#endif


/*
*********************************************************************************************************
*                                        OSProbe_TaskSwHook()
*
* Description : This function is called when a task switch is performed.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : App_TaskSwHook().
*
* Note(s)     : (1) Interrupts are disabled during this call.
*
*               (2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
*                   will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
*                   task being switched out (i.e. the preempted task).
*
*               (3) This MUST be called from application's task switch hook function App_TaskSwHook().
*********************************************************************************************************
*/

#if (OS_PROBE_HOOKS_EN > 0)
void  OSProbe_TaskSwHook (void)
{
    INT32U  cycles;


    cycles                         = OSProbe_TimeGetCycles();   /* This task is done.                                   */
    OSTCBCur->OSTCBCyclesTot      += cycles - OSTCBCur->OSTCBCyclesStart;
    OSTCBHighRdy->OSTCBCyclesStart = cycles;                    /* Save absolute #cycles at task activation.            */
}
#endif


/*
*********************************************************************************************************
*                                         OSProbe_TickHook()
*
* Description : This function is called every tick.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : App_TimeTickHook().
*
* Note(s)     : (1) Interrupts may or may not be ENABLED during this call.
*
*               (2) This MUST be called from user's time tick hook function App_TimeTickHook().
*********************************************************************************************************
*/

#if (OS_PROBE_HOOKS_EN > 0)
void  OSProbe_TickHook (void)
{
    (void)OSProbe_TimeGetCycles();
}
#endif


/*
*********************************************************************************************************
*********************************************************************************************************
*                                           LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          OSProbe_InitOS()
*
* Description : Create the task for the Probe Plug-In for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : OSProbe_Init().
*
* Note(s)     : none.
*********************************************************************************************************
*/

#if (OS_PROBE_TASK > 0)
static  void  OSProbe_InitOS (void)
{
    INT8U  err;


#if (OS_TASK_CREATE_EXT_EN > 0)
    #if (OS_STK_GROWTH == 1)
    err = OSTaskCreateExt((void (*)(void *)) OSProbe_Task,
                          (void          * ) 0,
                          (OS_STK        * )&OSProbe_TaskStk[OS_PROBE_TASK_STK_SIZE - 1],
                          (INT8U           ) OS_PROBE_TASK_PRIO,
                          (INT16U          ) OS_PROBE_TASK_PRIO,
                          (OS_STK        * )&OSProbe_TaskStk[0],
                          (INT32U          ) OS_PROBE_TASK_STK_SIZE,
                          (void          * ) 0,
                          (INT16U          )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
    #else
    err = OSTaskCreateExt((void (*)(void *)) OSProbe_Task,
                          (void          * ) 0,
                          (OS_STK        * )&OSProbe_TaskStk[0],
                          (INT8U           ) OS_PROBE_TASK_PRIO,
                          (INT16U          ) OS_PROBE_TASK_PRIO,
                          (OS_STK        * )&OSProbe_TaskStk[OS_PROBE_TASK_STK_SIZE - 1],
                          (INT32U          ) OS_PROBE_TASK_STK_SIZE,
                          (void          * ) 0,
                          (INT16U          )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
    #endif
#else
    #if (OS_STK_GROWTH == 1)
    err = OSTaskCreate((void (*)(void *)) OSProbe_Task,
                       (void          * ) 0,
                       (OS_STK        * )&OSProbe_TaskStk[OS_PROBE_TASK_STK_SIZE - 1],
                       (INT8U           ) OS_PROBE_TASK_PRIO);
    #else
    err = OSTaskCreate((void (*)(void *)) OSProbe_Task,
                       (void          * ) 0,
                       (OS_STK        * )&OSProbe_TaskStk[0],
                       (INT8U           ) OS_PROBE_TASK_PRIO);
    #endif
#endif

#if (OS_TASK_NAME_SIZE > 15)
    OSTaskNameSet(OS_PROBE_TASK_PRIO, (INT8U *)"Probe OS PlugIn", &err);
#endif

    (void)&err;
}
#endif


/*
*********************************************************************************************************
*                                           OSProbe_Task()
*
* Description : Updates task CPU usage and task stack usage statistics and calls a user-specified
*               callback functions, if the user sets this function.
*
* Argument(s) : p_arg       Argument passed to OSProbe_Task() by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/

#if (OS_PROBE_TASK > 0)
static  void  OSProbe_Task (void *p_arg)
{
            OS_TCB  *ptcb;
            INT16U   i;
            INT32U   cycles_tot;
    static  INT32U   cycles_dif[OS_MAX_TASKS];
    static  INT32U   cycles_tot_last[OS_MAX_TASKS];
#if (OS_PROBE_USE_FP == 0)
            INT32U   max;
#endif


    (void)p_arg;

                                                                /* Initialize stored CyclesTot values.                  */
    for (i = 0; i < OS_MAX_TASKS; i++) {
        cycles_tot_last[i]      = 0;
        OSProbe_TaskStkUsage[i] = 0;
        OSProbe_TaskCPUUsage[i] = 0;
    }

    while (1) {
        OSTimeDlyHMSM(0, 0, 0, OSProbe_Delay);
        if (OSProbe_CallbackFnct != (void (*)(void))0) {
            OSProbe_CallbackFnct();
        }

                                                                /* Update task CPU usage                                */
        i          = 0;
        cycles_tot = 0;
        ptcb       = &OSTCBTbl[0];                              /*  ... Get pointer to first TCB ...                    */

        while ((i    < OS_MAX_TASKS) &&
               (ptcb != (OS_TCB *)0) &&
               (ptcb != (OS_TCB *)1)) {
                                                                /*  ... Calculate new CyclesDif, the number of cycles   */
                                                                /*  ... used by the task since the last reading.  Half  */
                                                                /*  ... the previous value is added to provide some     */
                                                                /*  ... hysteresis, thereby reducing the natural        */
                                                                /*  ... "jitter" in the data.                           */
            cycles_dif[i]       = (ptcb->OSTCBCyclesTot - cycles_tot_last[i]) / 2 + (cycles_dif[i] / 2);
            cycles_tot_last[i]  = ptcb->OSTCBCyclesTot;
            cycles_tot         += cycles_dif[i];

            if (ptcb->OSTCBStkSize == 0) {
                OSProbe_TaskStkUsage[i] = 0;
            } else {
#if (OS_PROBE_USE_FP > 0)
#if (OS_STK_GROWTH == 1)
                OSProbe_TaskStkUsage[i] = (FP32)(((INT32U)(ptcb->OSTCBStkBase) - (INT32U)(ptcb->OSTCBStkPtr))  * 100)
                                        / ((ptcb->OSTCBStkSize) * sizeof (OS_STK));
#else
                OSProbe_TaskStkUsage[i] = (FP32)(((INT32U)(ptcb->OSTCBStkPtr)  - (INT32U)(ptcb->OSTCBStkBase)) * 100)
                                        / ((ptcb->OSTCBStkSize) * sizeof (OS_STK));
#endif
#else
                max = ((ptcb->OSTCBStkSize) * sizeof (OS_STK)) / 100L;

#if (OS_STK_GROWTH == 1)
                OSProbe_TaskStkUsage[i] = (INT16U)(((INT32U)(ptcb->OSTCBStkBase) - (INT32U)(ptcb->OSTCBStkPtr))  / max);
#else
                OSProbe_TaskStkUsage[i] = (INT16U)(((INT32U)(ptcb->OSTCBStkPtr)  - (INT32U)(ptcb->OSTCBStkBase)) / max);
#endif
#endif
            }

            ptcb = ptcb->OSTCBPrev;

            i++;
        }

#if (OS_PROBE_USE_FP == 0)
        max = cycles_tot / 100L;
#endif
                                                                /*  ... For each task, calculate percent CPU usage.     */
        for (i = 0; i < OS_MAX_TASKS; i++) {
#if (OS_PROBE_USE_FP > 0)
            OSProbe_TaskCPUUsage[i] = (FP32)(cycles_dif[i] * 100) / cycles_tot;
#else
            OSProbe_TaskCPUUsage[i] = (INT16U)(cycles_dif[i] / max);
#endif
        }
    }
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -