📄 os_stat.c
字号:
/*
************************************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
*
* (c) Copyright 2009-2011; Micrium, Inc.; Weston, FL
* All rights reserved. Protected by international copyright laws.
*
* STATISTICS MODULE
*
* File : OS_STAT.C
* By : JJL
* Version : V3.02.00
*
* LICENSING TERMS:
* ---------------
* uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or
* for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/
* product then, you need to contact Micrium to properly license uC/OS-III for its use in your
* application/product. We provide ALL the source code for your convenience and to help you
* experience uC/OS-III. The fact that the source is provided does NOT mean that you can use
* it commercially without paying a licensing fee.
*
* 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.
*
* You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036.
************************************************************************************************************************
*/
#include <os.h>
#ifdef VSC_INCLUDE_SOURCE_FILE_NAMES
const CPU_CHAR *os_stat__c = "$Id: $";
#endif
#if OS_CFG_STAT_TASK_EN > 0u
/*
************************************************************************************************************************
* RESET STATISTICS
*
* Description: This function is called by your application to reset the statistics.
*
* Argument(s): p_err is a pointer to a variable that will contain an error code returned by this function.
*
* OS_ERR_NONE
*
* Returns : none
************************************************************************************************************************
*/
void OSStatReset (OS_ERR *p_err)
{
#if (OS_CFG_DBG_EN > 0u)
OS_TCB *p_tcb;
#if (OS_MSG_EN > 0u)
OS_MSG_Q *p_msg_q;
#endif
#if (OS_CFG_Q_EN > 0u)
OS_Q *p_q;
#endif
CPU_SR_ALLOC();
#endif
#ifdef OS_SAFETY_CRITICAL
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
#if OS_CFG_ISR_POST_DEFERRED_EN > 0u
OSIntQTaskTimeMax = (CPU_TS )0; /* Reset the task execution times */
OSIntQMaxNbrEntries = (OS_OBJ_QTY)0; /* Reset the queue maximum number of entries */
#endif
#if OS_CFG_STAT_TASK_EN > 0u
OSStatTaskTimeMax = (CPU_TS)0;
#endif
OSTickTaskTimeMax = (CPU_TS)0;
#if OS_CFG_TMR_EN > 0u
OSTmrTaskTimeMax = (CPU_TS)0;
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
OSIntDisTimeMax = (CPU_TS)0; /* Reset the maximum interrupt disable time */
#endif
#if OS_CFG_SCHED_LOCK_TIME_MEAS_EN > 0u
OSSchedLockTimeMax = (CPU_TS)0; /* Reset the maximum scheduler lock time */
#endif
#if OS_CFG_DBG_EN > 0u
p_tcb = OSTaskDbgListPtr;
while (p_tcb != (OS_TCB *)0) { /* Reset per-Task statistics */
CPU_CRITICAL_ENTER();
#ifdef CPU_CFG_INT_DIS_MEAS_EN
p_tcb->IntDisTimeMax = (CPU_TS )0;
#endif
#if OS_CFG_SCHED_LOCK_TIME_MEAS_EN > 0u
p_tcb->SchedLockTimeMax = (CPU_TS )0;
#endif
#if OS_CFG_TASK_PROFILE_EN > 0u
#if OS_CFG_TASK_Q_EN > 0u
p_tcb->MsgQPendTimeMax = (CPU_TS )0;
#endif
p_tcb->SemPendTimeMax = (CPU_TS )0;
p_tcb->CtxSwCtr = (OS_CTR )0;
p_tcb->CPUUsage = (OS_CPU_USAGE)0;
p_tcb->CyclesTotal = (OS_CYCLES )0;
p_tcb->CyclesTotalPrev = (OS_CYCLES )0;
p_tcb->CyclesStart = OS_TS_GET();
#endif
#if OS_CFG_TASK_Q_EN > 0u
p_msg_q = &p_tcb->MsgQ;
p_msg_q->NbrEntriesMax = (OS_MSG_QTY )0;
#endif
p_tcb = p_tcb->DbgNextPtr;
CPU_CRITICAL_EXIT();
}
#endif
OS_TickListResetPeak(); /* Reset tick wheel statistics */
#if OS_CFG_TMR_EN > 0u
OS_TmrResetPeak();
#endif
#if (OS_CFG_Q_EN > 0u) && (OS_CFG_DBG_EN > 0u)
p_q = OSQDbgListPtr;
while (p_q != (OS_Q *)0) { /* Reset message queues statistics */
CPU_CRITICAL_ENTER();
p_msg_q = &p_q->MsgQ;
p_msg_q->NbrEntriesMax = (OS_MSG_QTY)0;
p_q = p_q->DbgNextPtr;
CPU_CRITICAL_EXIT();
}
#endif
*p_err = OS_ERR_NONE;
}
/*$PAGE*/
/*
************************************************************************************************************************
* DETERMINE THE CPU CAPACITY
*
* Description: This function is called by your application to establish CPU usage by first determining how high a 32-bit
* counter would count to in 1/10 second if no other tasks were to execute during that time. CPU usage is
* then determined by a low priority task which keeps track of this 32-bit counter every second but this
* time, with other tasks running. CPU usage is determined by:
*
* OS_Stat_IdleCtr
* CPU Usage (%) = 100 * (1 - ------------------)
* OS_Stat_IdleCtrMax
*
* Argument(s): p_err is a pointer to a variable that will contain an error code returned by this function.
*
* OS_ERR_NONE
*
* Returns : none
************************************************************************************************************************
*/
void OSStatTaskCPUUsageInit (OS_ERR *p_err)
{
OS_ERR err;
OS_TICK dly;
CPU_SR_ALLOC();
#ifdef OS_SAFETY_CRITICAL
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
OSTimeDly((OS_TICK )2, /* Synchronize with clock tick */
(OS_OPT )OS_OPT_TIME_DLY,
(OS_ERR *)&err);
if (err != OS_ERR_NONE) {
*p_err = err;
return;
}
CPU_CRITICAL_ENTER();
OSStatTaskCtr = (OS_TICK)0; /* Clear idle counter */
CPU_CRITICAL_EXIT();
dly = (OS_TICK)0;
if (OSCfg_TickRate_Hz > OSCfg_StatTaskRate_Hz) {
dly = (OS_TICK)(OSCfg_TickRate_Hz / OSCfg_StatTaskRate_Hz);
}
if (dly == (OS_TICK)0) {
dly = (OS_TICK)(OSCfg_TickRate_Hz / (OS_RATE_HZ)10);
}
OSTimeDly(dly, /* Determine MAX. idle counter value */
OS_OPT_TIME_DLY,
&err);
CPU_CRITICAL_ENTER();
OSStatTaskTimeMax = (CPU_TS)0;
OSStatTaskCtrMax = OSStatTaskCtr; /* Store maximum idle counter count */
OSStatTaskRdy = OS_STATE_RDY;
CPU_CRITICAL_EXIT();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -