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

📄 os_probe.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                          uC/Probe Plug-ins
*
*                         (c) Copyright 2007-2008; 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.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                    PLUG-IN FOR MICRIUM uC/OS-II
*
* Filename      : os_probe.c
* Version       : V2.20
* Programmer(s) : BAN
*********************************************************************************************************
* Note(s)       : (1) This module calculates task CPU & stack usage statistics that can be displayed in
*                     uC/Probe.
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            INCLUDE FILES
*********************************************************************************************************
*/

#define   OS_PROBE_MODULE
#include <os_probe.h>


/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL 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


/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


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

void  OSProbe_Init (void)
{
#if (OS_PROBE_TASK > 0)
    OSProbe_SetDelay(100);
    OSProbe_SetCallback((void (*)(void))0);                     /* Clr terminal callback function.                      */

    OSProbe_InitOS();
#endif

#if (OS_PROBE_HOOKS_EN > 0)
    OSProbe_TmrInit();

    OSProbe_CyclesCtr   = 0;
    OSProbe_TmrCntsPrev = 0;
#endif
}


/*
*********************************************************************************************************
*                                        OSProbe_SetCallback()
*
* Description : Set the callback function which will be invoked in OSProbe_Task().
*
* Argument(s) : call_back   Pointer to the callback function.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

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


/*
*********************************************************************************************************
*                                         OSProbe_SetDelay()
*
* Description : Set the delay used in OSProbe_Task().
*
* Argument(s) : delay       Delay, in milliseconds.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

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


/*
*********************************************************************************************************
*                                       OSProbe_TimeGetCycles()
*
* Description : Get time as accurately as possible, stored in a 32-bit variable.
*
* Argument(s) : none.
*
* Return(s)   : A 32-bit representation of time.
*
* Caller(s)   : OSProbe_TaskSwHook(),
*               OSProbe_TaskCreateHook().
*
* Note(s)     : (1) Since the cycles count returned by this function will eventually overflow a 32-bit
*                   integer, it should only be used for comparative time lapse measurements (e.g., to
*                   determine a time lapse between two events which can be compared to similarly
*                   calculated time lapses).  In such a measurement, the difference between two cycle
*                   counts will be computed.  The application MUST guarantee that this difference does
*                   not overflow a 32-bit integer.  For example, if the underlying timer increments at a
*                   rate of 100MHz, then the maximum time lapse that can be measured is
*
*                                2^32 - 1
*                       tmax = ------------ s = 42.9497 s
*                               100 * 10^6
*
*               (2) When using a 16-bit timer, this function MUST be called with sufficient frequency
*                   that timer overflows do not occur.  If necessary, the timer should be configured with
*                   a sufficient prescaler in order to decrease the probability of timer overflows.
*
*                   For example, a 16-bit timer incrementing at 48-MHz with a prescaler of 128 will
*                   require that this function be called at
*
*                                   48 * 10^6
*                       freqmin = ------------- Hz = 5.72 Hz
*                                  128 * 65536
*
*                   A possible solution is that this would be called from the tick handler of the
*                   application's OS (assuming the tick rate is greater than 5.72 Hz).
*********************************************************************************************************
*/

#if (OS_PROBE_HOOKS_EN > 0)
INT32U  OSProbe_TimeGetCycles (void)
{
    INT32U     cycles;
#if (OS_PROBE_TMR_32_BITS > 0)
    INT32U     cnts32;
    INT32U     cnts32_delta;
#else
    INT16U     cnts16;
    INT16U     cnts16_delta;
#endif
#if (OS_CRITICAL_METHOD == 3)                                   /* Allocate storage for CPU status register.            */
    OS_CPU_SR  cpu_sr = 0;
#endif


    OS_ENTER_CRITICAL();
#if (OS_PROBE_TMR_32_BITS > 0)
    cnts32               = OSProbe_TmrRd();                     /* Read current counts of the free running counter.     */
    cnts32_delta         = cnts32 - OSProbe_TmrCntsPrev;
    OSProbe_TmrCntsPrev  = cnts32;                              /* Save current counts for next time.                   */
    OSProbe_CyclesCtr   += cnts32_delta;
#else
    cnts16               = (INT16U)OSProbe_TmrRd();             /* Read current counts of the free running counter.     */
    cnts16_delta         = cnts16 - OSProbe_TmrCntsPrev;
    OSProbe_TmrCntsPrev  = cnts16;                              /* Save current counts for next time.                   */
    OSProbe_CyclesCtr   += (INT32U)cnts16_delta;
#endif
    cycles               = OSProbe_CyclesCtr;
    OS_EXIT_CRITICAL();

    return (cycles);
}
#endif


/*
*********************************************************************************************************
*********************************************************************************************************
*                                             TASK HOOKS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                      OSProbe_TaskCreateHook()
*
* Description : This function is called when a task is created.
*

⌨️ 快捷键说明

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