📄 cpu_core.h
字号:
*
* (b) (1) However, if execution of code following calls to CPU_SW_EXCEPTION() is required
* (e.g. for automated testing); it is recommended that the last statement in
* developer-implemented versions be to return from the current function to prevent
* possible software exception(s) in the current function from triggering CPU &/or
* hardware exception(s).
*
* Example CPU_SW_EXCEPTION() :
*
* #define CPU_SW_EXCEPTION(err_rtn_val) do { \
* Log(__FILE__, __LINE__); \
* return err_rtn_val; \
* } while (0)
*
* (A) Note that 'err_rtn_val' in the return statement MUST NOT be enclosed in
* parentheses. This allows CPU_SW_EXCEPTION() to return from functions that
* return 'void', i.e. NO return type or value (see also Note #2b2A).
*$PAGE*
* (2) In order for CPU_SW_EXCEPTION() to return from functions with various return
* types/values, each caller function MUST pass an appropriate error return type
* & value to CPU_SW_EXCEPTION().
*
* (A) Note that CPU_SW_EXCEPTION() MUST NOT be passed any return type or value
* for functions that return 'void', i.e. NO return type or value; but SHOULD
* instead be passed a single semicolon. This prevents possible compiler
* warnings that CPU_SW_EXCEPTION() is passed too few arguments. However,
* the compiler may warn that CPU_SW_EXCEPTION() does NOT prevent creating
* null statements on lines with NO other code statements.
*
* Example CPU_SW_EXCEPTION() calls :
*
* void Fnct (CPU_ERR *p_err)
* {
* :
*
* if (p_err == (CPU_ERR *)0) {
* CPU_SW_EXCEPTION(;); Exception macro returns NO value
* } (see Note #2b2A)
*
* :
* }
*
* CPU_BOOLEAN Fnct (CPU_ERR *p_err)
* {
* :
*
* if (p_err == (CPU_ERR *)0) {
* CPU_SW_EXCEPTION(DEF_FAIL); Exception macro returns 'DEF_FAIL'
* }
*
* :
* }
*
* OBJ *Fnct (CPU_ERR *p_err)
* {
* :
*
* if (p_err == (CPU_ERR *)0) {
* CPU_SW_EXCEPTION((OBJ *)0); Exception macro returns NULL 'OBJ *'
* }
*
* :
* }
*
*********************************************************************************************************
*/
#ifndef CPU_SW_EXCEPTION /* See Note #2. */
#define CPU_SW_EXCEPTION(err_rtn_val) do { \
CPU_SW_Exception(); \
} while (0)
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_TYPE_CREATE()
*
* Description : Creates a generic type value.
*
* Argument(s) : char_1 1st ASCII character to create generic type value.
*
* char_2 2nd ASCII character to create generic type value.
*
* char_3 3rd ASCII character to create generic type value.
*
* char_4 4th ASCII character to create generic type value.
*
* Return(s) : 32-bit generic type value.
*
* Caller(s) : various.
*
* Note(s) : (1) (a) Generic type values should be #define'd with large, non-trivial values to trap
* & discard invalid/corrupted objects based on type value.
*
* In other words, by assigning large, non-trivial values to valid objects' type
* fields; the likelihood that an object with an unassigned &/or corrupted type
* field will contain a value is highly improbable & therefore the object itself
* will be trapped as invalid.
*
* (b) (1) CPU_TYPE_CREATE() creates a 32-bit type value from four values.
*
* (2) Ideally, generic type values SHOULD be created from 'CPU_CHAR' characters to
* represent ASCII string abbreviations of the specific object types. Memory
* displays of object type values will display the specific object types with
* their chosen ASCII names.
*
* Examples :
*
* #define FILE_TYPE CPU_TYPE_CREATE('F', 'I', 'L', 'E')
* #define BUF_TYPE CPU_TYPE_CREATE('B', 'U', 'F', ' ')
*********************************************************************************************************
*/
#if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
#define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1)) << (3u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_2)) << (2u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_3)) << (1u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_4)) << (0u * DEF_OCTET_NBR_BITS)))
#else
#if ((CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_64) || \
(CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32))
#define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1)) << (0u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_2)) << (1u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_3)) << (2u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_4)) << (3u * DEF_OCTET_NBR_BITS)))
#elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
#define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1)) << (2u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_2)) << (3u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_3)) << (0u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_4)) << (1u * DEF_OCTET_NBR_BITS)))
#else /* Dflt CPU_WORD_SIZE_08. */
#define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1)) << (3u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_2)) << (2u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_3)) << (1u * DEF_OCTET_NBR_BITS)) | \
((CPU_INT32U)((CPU_INT08U)(char_4)) << (0u * DEF_OCTET_NBR_BITS)))
#endif
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*
* Note(s) : (1) CPU interrupts disabled time measurement functions prototyped/defined only if
* CPU_CFG_INT_DIS_MEAS_EN #define'd in 'cpu_cfg.h'.
*
* (2) CPU_CntLeadZeros() prototyped/defined respectively in :
*
* (a) 'cpu.h'/'cpu_a.asm', if CPU_CFG_LEAD_ZEROS_ASM_PRESENT #define'd in 'cpu.h'/
* 'cpu_cfg.h' to enable assembly-version function
*
* (b) 'cpu_core.h'/'cpu_core.c', if CPU_CFG_LEAD_ZEROS_ASM_PRESENT NOT #define'd in 'cpu.h'/
* 'cpu_cfg.h' to enable C-source-version function otherwise
*********************************************************************************************************
*/
void CPU_Init (void);
void CPU_SW_Exception (void);
#if (CPU_CFG_NAME_EN == DEF_ENABLED) /* -------------- CPU NAME FNCTS -------------- */
void CPU_NameClr (void);
void CPU_NameGet (CPU_CHAR *p_name,
CPU_ERR *p_err);
void CPU_NameSet (CPU_CHAR *p_name,
CPU_ERR *p_err);
#endif
/* --------------- CPU TS FNCTS --------------- */
#if (CPU_CFG_TS_32_EN == DEF_ENABLED)
CPU_TS32 CPU_TS_Get32 (void);
#endif
#if (CPU_CFG_TS_64_EN == DEF_ENABLED)
CPU_TS64 CPU_TS_Get64 (void);
#endif
#if (CPU_CFG_TS_EN == DEF_ENABLED)
void CPU_TS_Update (void);
#endif
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED) /* ------------- CPU TS TMR FNCTS ------------- */
CPU_TS_TMR_FREQ CPU_TS_TmrFreqGet (CPU_ERR *p_err);
void CPU_TS_TmrFreqSet (CPU_TS_TMR_FREQ freq_hz);
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN /* -------- CPU INT DIS TIME MEAS FNCTS ------- */
/* See Note #1. */
CPU_TS_TMR CPU_IntDisMeasMaxCurReset(void);
CPU_TS_TMR CPU_IntDisMeasMaxCurGet (void);
CPU_TS_TMR CPU_IntDisMeasMaxGet (void);
void CPU_IntDisMeasStart (void);
void CPU_IntDisMeasStop (void);
#endif
#ifndef CPU_CFG_LEAD_ZEROS_ASM_PRESENT /* --------- CPU CNT LEAD ZEROS FNCTS --------- */
CPU_DATA CPU_CntLeadZeros (CPU_DATA val); /* See Note #2. */
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
* DEFINED IN PRODUCT'S BSP
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* CPU_TS_TmrInit()
*
* Description : Initialize & start CPU timestamp timer.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : CPU_TS_Init().
*
* This function is an INTERNAL CPU module function & MUST be implemented by application/
* BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
*
* Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
* if either of the following CPU features is enabled :
*
* (a) CPU timestamps
* (b) CPU interrupts disabled time measurements
*
* See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
* & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
*
* (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
* data type.
*
* (1) If timer has more bits, truncate timer values' higher-order bits greater
* than the configured 'CPU_TS_TMR' timestamp timer data type word size.
*
* (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
* timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
* configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
*
* In other words, if timer size is not a binary-multiple of 8-bit octets
* (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
* octet word size SHOULD be configured (e.g. to 16-bits). However, the
* minimum supported word size for CPU timestamp timers is 8-bits.
*
* See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
* & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
*
* (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
*
* (c) When applicable, 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_TS_TmrRd() Note #2'.
*********************************************************************************************************
*/
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
void CPU_TS_TmrInit(void);
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CPU_TS_TmrRd()
*
* Description : Get current CPU timestamp timer count value.
*
* Argument(s) : none.
*
* Return(s) : Timestamp timer count (see Notes #2a & #2b).
*
* Caller(s) : CPU_TS_Init(),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -