📄 cpu_core.c
字号:
* Note(s) : none.
*********************************************************************************************************
*/
#ifdef CPU_CFG_INT_DIS_MEAS_EN
void CPU_IntDisMeasStart (void)
{
CPU_IntDisMeasCtr++;
if (CPU_IntDisNestCtr == 0u) { /* If ints NOT yet dis'd, ... */
CPU_IntDisMeasStart_cnts = CPU_TS_TmrRd(); /* ... get ints dis'd start time. */
}
CPU_IntDisNestCtr++;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_IntDisMeasStop()
*
* Description : Stop interrupts disabled time measurement.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : CPU_CRITICAL_EXIT().
*
* This function is an INTERNAL CPU module function & MUST NOT be called by application
* function(s).
*
* Note(s) : (1) (a) The total amount of time interrupts are disabled by system &/or application code
* during critical sections is calculated by the following equations :
*
* (1) When interrupts disabled time measurements are disabled :
*
*
* | CRITICAL | | CRITICAL |
* |<- SECTION ->| |<- SECTION ->|
* | ENTER | | EXIT |
*
* Disable Enable
* Interrupts Interrupts
*
* || || || ||
* || || || ||
* || | ||<------------------------->|| | ||
* || |<->|| | ||<----->| ||
* || | | || | || | | ||
* | | | | |
* interrupts time interrupts
* disabled interrupts |enabled
* | disabled |
* | (via application) |
* time time
* interrupts interrupts
* disabled ovrhd enabled ovrhd
*
*
* (A) time = [ time - time ] - time
* interrupts [ interrupts interrupts ] total
* disabled [ enabled disabled ] ovrhd
* (via application)
*
*
* (B) time = time + time
* total interrupts interrupts
* ovrhd enabled ovrhd disabled ovrhd
*
*
* where
*
* time time interrupts are disabled between
* interrupts first critical section enter &
* disabled last critical section exit (i.e.
* (via application) minus total overhead time)
*
* time time when interrupts are disabled
* interrupts
* disabled
*
* time time when interrupts are enabled
* interrupts
* enabled
*
*
* time total overhead time to disable/enable
* total interrupts during critical section
* ovrhd enter & exit
*
* time total overhead time to disable interrupts
* interrupts during critical section enter
* disabled ovrhd
*
* time total overhead time to enable interrupts
* interrupts during critical section exit
* enabled ovrhd
*
*$PAGE*
*
* (2) When interrupts disabled time measurements are enabled :
*
*
* | | | |
* |<----- CRITICAL SECTION ENTER ----->| |<------- CRITICAL SECTION EXIT ------->|
* | | | |
*
* Time Time
* Disable Measurement Measurement Enable
* Interrupts Start Stop Interrupts
*
* || | || || | ||
* || | || || | ||
* || | | ||<------------------------->|| | | ||
* || | | |<----------->|| | ||<------------->| | | ||
* || | | | | || | || | | | | ||
* | | | | | | |
* interrupts get | time | get interrupts
* disabled start time | interrupts | stop time enabled
* meas | disabled | meas
* time (via application) time
* start meas stop meas
* ovrhd ovrhd
*
*
* (A) time = [ time - time ] - time
* interrupts [ stop start ] total meas
* disabled [ meas meas ] ovrhd
* (via application)
*
*
* (B) time = time + time
* total meas start meas stop meas
* ovrhd ovrhd ovrhd
*
*
* where
*
* time time interrupts are disabled between first
* interrupts critical section enter & last critical
* disabled section exit (i.e. minus measurement
* (via application) overhead time; however, this does NOT
* include any overhead time to disable
* or enable interrupts during critical
* section enter & exit)
*
* time time of disable interrupts start time
* start measurement (in timer counts)
* meas
*
* time time of disable interrupts stop time
* stop measurement (in timer counts)
* meas
*
*
* time total overhead time to start/stop disabled
* total meas interrupts time measurements (in timer
* ovrhd counts)
*
* time total overhead time after getting start
* start meas time until end of start measurement
* ovrhd function (in timer counts)
*
* time total overhead time from beginning of stop
* stop meas measurement function until after getting
* ovrhd stop time (in timer counts)
*
*
*$PAGE*
* (b) (1) (A) In order to correctly handle unsigned subtraction overflows of start times
* from stop times, CPU timestamp timer count values MUST be returned via
* word-size-configurable 'CPU_TS_TMR' data type.
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2a'.
*
* (B) Since unsigned subtraction of start times from stop times assumes increasing
* values, timestamp timer count values MUST increase with each time count.
*
* See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2b'.
*
* (2) (A) To expedite & reduce interrupts disabled time measurement overhead; only the
* subtraction of start times from stop times is performed.
*
* (B) The final calculations to subtract the interrupts disabled time measurement
* overhead is performed asynchronously in appropriate API functions.
*
* See also 'CPU_IntDisMeasMaxCalc() Note #1b'.
*********************************************************************************************************
*/
#ifdef CPU_CFG_INT_DIS_MEAS_EN
void CPU_IntDisMeasStop (void)
{
CPU_TS_TMR time_ints_disd_cnts;
CPU_IntDisNestCtr--;
if (CPU_IntDisNestCtr == 0u) { /* If ints NO longer dis'd, ... */
CPU_IntDisMeasStop_cnts = CPU_TS_TmrRd(); /* ... get ints dis'd stop time & ... */
/* ... calc ints dis'd tot time (see Note #1b2A). */
time_ints_disd_cnts = CPU_IntDisMeasStop_cnts -
CPU_IntDisMeasStart_cnts;
/* Calc max ints dis'd times. */
if (CPU_IntDisMeasMaxCur_cnts < time_ints_disd_cnts) {
CPU_IntDisMeasMaxCur_cnts = time_ints_disd_cnts;
}
if (CPU_IntDisMeasMax_cnts < time_ints_disd_cnts) {
CPU_IntDisMeasMax_cnts = time_ints_disd_cnts;
}
}
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_CntLeadZeros()
*
* Description : Count the number of contiguous, most-significant, leading zero bits in a data value.
*
* Argument(s) : val Data value to count leading zero bits.
*
* Return(s) : Number of contiguous, most-significant, leading zero bits in 'val', if NO error(s).
*
* 0, otherwise.
*
* Caller(s) : Application.
*
* This function is an INTERNAL CPU module function but MAY be called by application function(s).
*
* Note(s) : (1) (a) Supports the following data value sizes :
*
* (1) 8-bits
* (2) 16-bits
* (3) 32-bits
* (4) 64-bits
*
* See also 'cpu_def.h CPU WORD CONFIGURATION Note #1'.
*
* (b) (1) For 8-bit values :
*
* b07 b06 b05 b04 b03 b02 b01 b00 # Leading Zeros
* --- --- --- --- --- --- --- --- ---------------
* 1 x x x x x x x 0
* 0 1 x x x x x x 1
* 0 0 1 x x x x x 2
* 0 0 0 1 x x x x 3
* 0 0 0 0 1 x x x 4
* 0 0 0 0 0 1 x x 5
* 0 0 0 0 0 0 1 x 6
* 0 0 0 0 0 0 0 1 7
* 0 0 0 0 0 0 0 0 8
*
*
* (2) For 16-bit values :
*
* b15 b14 b13 ... b04 b03 b02 b01 b00 # Leading Zeros
* --- --- --- --- --- --- --- --- ---------------
* 1 x x x x x x x 0
* 0 1 x x x x x x 1
* 0 0 1 x x x x x 2
* : : : : : : : : :
* : : : : : : : : :
* 0 0 0 1 x x x x 11
* 0 0 0 0 1 x x x 12
* 0 0 0 0 0 1 x x 13
* 0 0 0 0 0 0 1 x 14
* 0 0 0 0 0 0 0 1 15
* 0 0 0 0 0 0 0 0 16
*
*
* (3) For 32-bit values :
*
* b31 b30 b29 ... b04 b03 b02 b01 b00 # Leading Zeros
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -