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

📄 os_probe.c

📁 UCOS在LPC2378开发板里面的原版移植程序.并且里面还包含了最新的UCPROBE,很强哦,另外还有UCOSVIEW和大量文档.
💻 C
字号:
/*
*********************************************************************************************************
*                                     uC/Probe uC/OS-II Plug-in
*
*                          (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                              uC/Probe
*
*                                         Plug-in for uC/OS-II
*
* Filename      : os_probe.c
* Version       : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

#define  OS_PROBE_GLOBALS
#include <includes.h>

#if uC_PROBE_OS_PLUGIN > 0

/*
*********************************************************************************************************
*                                               CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                           LOCAL VARIABLES
*********************************************************************************************************
*/

#if OS_PROBE_TASK > 0
static  OS_STK      OSProbe_TaskStk[OS_PROBE_TASK_STK_SIZE];
#endif


/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

#if OS_PROBE_TASK > 0
static  void        OSProbe_InitOS(void);
static  void        OSProbe_Task(void *p_arg);
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                       INITIALIZE uC/OS-View
*********************************************************************************************************
*/

void  OSProbe_Init (void)
{
#if OS_PROBE_TASK > 0
    OSProbe_SetDelay(100);
    OSProbe_SetCallback((void (*)(void))0);                     /* Force terminal callback function to 'nothing'            */

    (void)OSProbe_TaskCPUUsage;
    (void)OSProbe_TaskStkUsage;

    OSProbe_InitOS();
#endif

#if OS_VIEW_MODULE > 0
#if OS_VIEW_USE_OS_PROBE > 0
    OSView_Init(0);
#endif
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                             INITIALIZE THE uC/OS-View TASK AND OS OBJECTS
*********************************************************************************************************
*/

#if OS_PROBE_TASK > 0
static  void  OSProbe_InitOS (void)
{
#if OS_TASK_NAME_SIZE > 7 || OS_EVENT_NAME_SIZE > 7
    INT8U  err;
#endif


#if OS_TASK_CREATE_EXT_EN > 0
    #if OS_STK_GROWTH == 1
    (void)OSTaskCreateExt(OSProbe_Task,
                          (void *)0,                                    /* No arguments passed to OSProbe_Task()            */
                          &OSProbe_TaskStk[OS_PROBE_TASK_STK_SIZE - 1], /* Set Top-Of-Stack                                 */
                          OS_PROBE_TASK_PRIO,                           /* Lowest priority level                            */
                          OS_PROBE_TASK_ID,
                          &OSProbe_TaskStk[0],                          /* Set Bottom-Of-Stack                              */
                          OS_PROBE_TASK_STK_SIZE,
                          (void *)0,                                    /* No TCB extension                                 */
                          OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);   /* Enable stack checking + clear stack              */
    #else
    (void)OSTaskCreateExt(OSProbe_Task,
                          (void *)0,                                    /* No arguments passed to OSProbe_Task()            */
                          &OSProbe_TaskStk[0],                          /* Set Top-Of-Stack                                 */
                          OS_PROBE_TASK_PRIO,                           /* Lowest priority level                            */
                          OS_PROBE_TASK_ID,
                          &OSProbe_TaskStk[OS_PROBE_TASK_STK_SIZE - 1], /* Set Bottom-Of-Stack                              */
                          OS_PROBE_TASK_STK_SIZE,
                          (void *)0,                                    /* No TCB extension                                 */
                          OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);   /* Enable stack checking + clear stack              */
    #endif
#else
    #if OS_STK_GROWTH == 1
    (void)OSTaskCreate(OSProbe_Task,
                       (void *)0,
                       &OSProbe_TaskStk[OS_PROBE_TASK_STK_SIZE - 1],
                       OS_PROBE_TASK_PRIO);
    #else
    (void)OSTaskCreate(OSProbe_Task,
                       (void *)0,
                       &OSProbe_TaskStk[0],
                       OS_PROBE_TASK_PRIO);
    #endif
#endif

#if OS_TASK_NAME_SIZE > 19
    OSTaskNameSet(OS_PROBE_TASK_PRIO, (INT8U *)"uC/Probe OS Plug-In", &err);
#else
#if OS_TASK_NAME_SIZE > 11
    OSTaskNameSet(OS_PROBE_TASK_PRIO, (INT8U *)"uC/Probe OS", &err);
#endif
#endif
}
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                                           uC/OS-View TASK
*********************************************************************************************************
*/

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



    (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 ((CPU_INT32U)OSProbe_CallbackFnct != 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) {
            if (ptcb == NULL) {
                break;                                          /*  ... If ptcb is NULL, then last TCB reached ...          */
            }

                                                                /*  ... 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_STK_GROWTH == 1
                OSProbe_TaskStkUsage[i] = (CPU_FP32)(((CPU_INT32U)(ptcb->OSTCBStkBase) - (CPU_INT32U)(ptcb->OSTCBStkPtr)) * 100)
                                        / ((ptcb->OSTCBStkSize) * sizeof (OS_STK));
#else
                OSProbe_TaskStkUsage[i] = (CPU_FP32)(((CPU_INT32U)(ptcb->OSTCBStkPtr) - (CPU_INT32U)(ptcb->OSTCBStkBase)) * 100)
                                        / ((ptcb->OSTCBStkSize) * sizeof (OS_STK));
#endif
            }

            ptcb                    = ptcb->OSTCBPrev;

            i++;
        }
                                                                /*  ... For each task, calculate percent CPU usage.         */
        for (i = 0; i < OS_MAX_TASKS; i++) {
            OSProbe_TaskCPUUsage[i]   = (CPU_FP32)(cycles_dif[i] * 100) / cycles_tot;
        }
    }
}
#endif

/*
*********************************************************************************************************
*                                      Set Callback Function
*
* Description: This routine sets the callback function which will be invoked in OSProbe_Task()
*
* Argument(s): call_back    is a pointer to the callback function.
*
* Returns    : none.
*********************************************************************************************************
*/

#if OS_PROBE_TASK > 0
void    OSProbe_SetCallback(void (*call_back)(void))
{
    OSProbe_CallbackFnct = call_back;
}
#endif


/*
*********************************************************************************************************
*                                      Set Task Delay
*
* Description: This routine sets the delay used in OSProbe_Task()
*
* Argument(s): delay    is the delay, in milliseconds.
*
* Returns    : none.
*********************************************************************************************************
*/

#if OS_PROBE_TASK > 0
void    OSProbe_SetDelay (INT16U  delay)
{
    OSProbe_Delay       = delay;
}
#endif




#endif

⌨️ 快捷键说明

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