📄 cpu_core.c
字号:
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_TS_Update()
*
* Description : Update current CPU timestamp(s).
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application/BSP periodic time handler (see Note #1).
*
* This function is a CPU timestamp BSP function & SHOULD be called only by appropriate
* application/BSP function(s).
*
* Note(s) : (1) (a) CPU timestamp(s) MUST be updated periodically by some application (or BSP) time
* handler in order to (adequately) maintain CPU timestamp(s)' time.
*
* (b) CPU timestamp(s) MUST be updated more frequently than the CPU timestamp timer
* overflows; otherwise, CPU timestamp(s) will lose time.
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c2'.
*********************************************************************************************************
*/
#if (CPU_CFG_TS_EN == DEF_ENABLED)
void CPU_TS_Update (void)
{
#if ((CPU_CFG_TS_32_EN == DEF_ENABLED) && \
(CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_32))
(void)CPU_TS_Get32();
#endif
#if ((CPU_CFG_TS_64_EN == DEF_ENABLED) && \
(CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_64))
(void)CPU_TS_Get64();
#endif
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_TS_TmrFreqGet()
*
* Description : Get CPU timestamp's timer frequency.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* CPU_ERR_NONE CPU timestamp's timer frequency successfully
* returned.
* CPU_ERR_TS_FREQ_INVALID CPU timestamp's timer frequency invalid &/or
* NOT yet configured.
*
* Return(s) : CPU timestamp's timer frequency (in Hertz), if NO error(s).
*
* 0, otherwise.
*
* Caller(s) : Application.
*
* This function is a CPU module application interface (API) function & MAY be called by
* application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
CPU_TS_TMR_FREQ CPU_TS_TmrFreqGet (CPU_ERR *p_err)
{
CPU_TS_TMR_FREQ freq_hz;
if (p_err == (CPU_ERR *)0) {
CPU_SW_EXCEPTION(;);
}
freq_hz = CPU_TS_TmrFreq_Hz;
*p_err = (freq_hz != 0u) ? CPU_ERR_NONE : CPU_ERR_TS_FREQ_INVALID;
return (freq_hz);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_TS_TmrFreqSet()
*
* Description : Set CPU timestamp's timer frequency.
*
* Argument(s) : freq_hz Frequency (in Hertz) to set for CPU timestamp's timer.
*
* Return(s) : none.
*
* Caller(s) : CPU_TS_TmrInit(),
* Application/BSP initialization function(s).
*
* This function is a CPU module BSP function & SHOULD be called only by appropriate
* application/BSP function(s) [see Note #1].
*
* Note(s) : (1) (a) (1) CPU timestamp timer frequency is NOT required for internal CPU timestamp
* operations but may OPTIONALLY be configured by CPU_TS_TmrInit() or other
* application/BSP initialization functions.
*
* (2) CPU timestamp timer frequency MAY be used with optional CPU_TSxx_to_uSec()
* to convert CPU timestamps from timer counts into microseconds.
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2a'.
*
* (b) CPU timestamp timer period SHOULD be less than the typical measured time but MUST
* be less than the maximum measured time; otherwise, timer resolution inadequate to
* measure desired times.
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2b'.
*********************************************************************************************************
*/
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
void CPU_TS_TmrFreqSet (CPU_TS_TMR_FREQ freq_hz)
{
CPU_TS_TmrFreq_Hz = freq_hz;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_IntDisMeasMaxCurReset()
*
* Description : Reset current maximum interrupts disabled time.
*
* Argument(s) : none.
*
* Return(s) : Maximum interrupts disabled time (in CPU timestamp timer counts) before resetting.
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c'
* & 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2'.
*
* Caller(s) : Application.
*
* This function is a CPU module application interface (API) function & MAY be called
* by application function(s).
*
* Note(s) : (1) After initialization, 'CPU_IntDisMeasMaxCur_cnts' MUST ALWAYS be accessed
* exclusively with interrupts disabled -- but NOT with critical sections.
*********************************************************************************************************
*/
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_TS_TMR CPU_IntDisMeasMaxCurReset (void)
{
CPU_TS_TMR time_max_cnts;
CPU_SR_ALLOC();
time_max_cnts = CPU_IntDisMeasMaxCurGet();
CPU_INT_DIS();
CPU_IntDisMeasMaxCur_cnts = 0u;
CPU_INT_EN();
return (time_max_cnts);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_IntDisMeasMaxCurGet()
*
* Description : Get current maximum interrupts disabled time.
*
* Argument(s) : none.
*
* Return(s) : Current maximum interrupts disabled time (in CPU timestamp timer counts).
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c'
* & 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2'.
*
* Caller(s) : CPU_IntDisMeasMaxCurReset(),
* Application.
*
* This function is a CPU module application interface (API) function & MAY be called
* by application function(s).
*
* Note(s) : (1) After initialization, 'CPU_IntDisMeasMaxCur_cnts' MUST ALWAYS be accessed
* exclusively with interrupts disabled -- but NOT with critical sections.
*********************************************************************************************************
*/
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_TS_TMR CPU_IntDisMeasMaxCurGet (void)
{
CPU_TS_TMR time_tot_cnts;
CPU_TS_TMR time_max_cnts;
CPU_SR_ALLOC();
CPU_INT_DIS();
time_tot_cnts = CPU_IntDisMeasMaxCur_cnts;
CPU_INT_EN();
time_max_cnts = CPU_IntDisMeasMaxCalc(time_tot_cnts);
return (time_max_cnts);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_IntDisMeasMaxGet()
*
* Description : Get (non-resetable) maximum interrupts disabled time.
*
* Argument(s) : none.
*
* Return(s) : (Non-resetable) maximum interrupts disabled time (in CPU timestamp timer counts).
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c'
* & 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2'.
*
* Caller(s) : CPU_IntDisMeasInit(),
* Application.
*
* This function is a CPU module application interface (API) function & MAY be called
* by application function(s).
*
* Note(s) : (1) After initialization, 'CPU_IntDisMeasMax_cnts' MUST ALWAYS be accessed
* exclusively with interrupts disabled -- but NOT with critical sections.
*********************************************************************************************************
*/
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_TS_TMR CPU_IntDisMeasMaxGet (void)
{
CPU_TS_TMR time_tot_cnts;
CPU_TS_TMR time_max_cnts;
CPU_SR_ALLOC();
CPU_INT_DIS();
time_tot_cnts = CPU_IntDisMeasMax_cnts;
CPU_INT_EN();
time_max_cnts = CPU_IntDisMeasMaxCalc(time_tot_cnts);
return (time_max_cnts);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_IntDisMeasStart()
*
* Description : Start interrupts disabled time measurement.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : CPU_CRITICAL_ENTER().
*
* This function is an INTERNAL CPU module function & MUST NOT be called by application
* function(s).
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -