📄 lib_def.h
字号:
#elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_32)
#define DEF_BIT_SET(val, mask) ((sizeof(val) == CPU_WORD_SIZE_08) ? DEF_BIT_SET_08(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_16) ? DEF_BIT_SET_16(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_32) ? DEF_BIT_SET_32(val, mask) : 0)))
#elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_64)
#define DEF_BIT_SET(val, mask) ((sizeof(val) == CPU_WORD_SIZE_08) ? DEF_BIT_SET_08(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_16) ? DEF_BIT_SET_16(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_32) ? DEF_BIT_SET_32(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_64) ? DEF_BIT_SET_64(val, mask) : 0))))
#else
#error "CPU_CFG_DATA_SIZE_MAX illegally #defined in 'cpu.h' "
#error " [See 'cpu.h CONFIGURATION ERRORS']"
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* DEF_BIT_CLR_xx()
*
* Description : Clear specified bit(s) in a value of specified bit size.
*
* Argument(s) : val Value to modify by clearing specified bit(s).
*
* mask Mask of bits to clear.
*
* Return(s) : Modified value with specified bit(s) clear.
*
* Caller(s) : Application.
*
* Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
*********************************************************************************************************
*/
#define DEF_BIT_CLR_08(val, mask) ((val) = (CPU_INT08U)(((CPU_INT08U)(val)) & ((CPU_INT08U)~(mask))))
#define DEF_BIT_CLR_16(val, mask) ((val) = (CPU_INT16U)(((CPU_INT16U)(val)) & ((CPU_INT16U)~(mask))))
#define DEF_BIT_CLR_32(val, mask) ((val) = (CPU_INT32U)(((CPU_INT32U)(val)) & ((CPU_INT32U)~(mask))))
#define DEF_BIT_CLR_64(val, mask) ((val) = (CPU_INT64U)(((CPU_INT64U)(val)) & ((CPU_INT64U)~(mask))))
/*
*********************************************************************************************************
* DEF_BIT_CLR()
*
* Description : Clear specified bit(s) in a value.
*
* Argument(s) : val Value to modify by clearing specified bit(s).
*
* mask Mask of bits to clear.
*
* Return(s) : Modified value with specified bit(s) clear.
*
* Caller(s) : Application.
*
* Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
*********************************************************************************************************
*/
#if (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_08)
#define DEF_BIT_CLR(val, mask) ((sizeof(val) == CPU_WORD_SIZE_08) ? DEF_BIT_CLR_08(val, mask) : 0)
#elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_16)
#define DEF_BIT_CLR(val, mask) ((sizeof(val) == CPU_WORD_SIZE_08) ? DEF_BIT_CLR_08(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_16) ? DEF_BIT_CLR_16(val, mask) : 0))
#elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_32)
#define DEF_BIT_CLR(val, mask) ((sizeof(val) == CPU_WORD_SIZE_08) ? DEF_BIT_CLR_08(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_16) ? DEF_BIT_CLR_16(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_32) ? DEF_BIT_CLR_32(val, mask) : 0)))
#elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_64)
#define DEF_BIT_CLR(val, mask) ((sizeof(val) == CPU_WORD_SIZE_08) ? DEF_BIT_CLR_08(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_16) ? DEF_BIT_CLR_16(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_32) ? DEF_BIT_CLR_32(val, mask) : \
((sizeof(val) == CPU_WORD_SIZE_64) ? DEF_BIT_CLR_64(val, mask) : 0))))
#else
#error "CPU_CFG_DATA_SIZE_MAX illegally #defined in 'cpu.h' "
#error " [See 'cpu.h CONFIGURATION ERRORS']"
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* DEF_BIT_IS_SET()
*
* Description : Determine if specified bit(s) in a value are set.
*
* Argument(s) : val Value to check for specified bit(s) set.
*
* mask Mask of bits to check if set (see Note #2).
*
* Return(s) : DEF_YES, if ALL specified bit(s) are set in value.
*
* DEF_NO, if ALL specified bit(s) are NOT set in value.
*
* Caller(s) : Application.
*
* Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
*
* (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
*********************************************************************************************************
*/
#define DEF_BIT_IS_SET(val, mask) ((((mask) != 0u) && \
(((val) & (mask)) == (mask))) ? (DEF_YES) : (DEF_NO ))
/*
*********************************************************************************************************
* DEF_BIT_IS_CLR()
*
* Description : Determine if specified bit(s) in a value are clear.
*
* Argument(s) : val Value to check for specified bit(s) clear.
*
* mask Mask of bits to check if clear (see Note #2).
*
* Return(s) : DEF_YES, if ALL specified bit(s) are clear in value.
*
* DEF_NO, if ALL specified bit(s) are NOT clear in value.
*
* Caller(s) : Application.
*
* Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
*
* (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
*********************************************************************************************************
*/
#define DEF_BIT_IS_CLR(val, mask) ((((mask) != 0u) && \
(((val) & (mask)) == 0u)) ? (DEF_YES) : (DEF_NO ))
/*$PAGE*/
/*
*********************************************************************************************************
* DEF_BIT_IS_SET_ANY()
*
* Description : Determine if any specified bit(s) in a value are set.
*
* Argument(s) : val Value to check for specified bit(s) set.
*
* mask Mask of bits to check if set (see Note #2).
*
* Return(s) : DEF_YES, if ANY specified bit(s) are set in value.
*
* DEF_NO, if ALL specified bit(s) are NOT set in value.
*
* Caller(s) : Application.
*
* Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
*
* (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
*********************************************************************************************************
*/
#define DEF_BIT_IS_SET_ANY(val, mask) ((((val) & (mask)) == 0u) ? (DEF_NO ) : (DEF_YES))
/*
*********************************************************************************************************
* DEF_BIT_IS_CLR_ANY()
*
* Description : Determine if any specified bit(s) in a value are clear.
*
* Argument(s) : val Value to check for specified bit(s) clear.
*
* mask Mask of bits to check if clear (see Note #2).
*
* Return(s) : DEF_YES, if ANY specified bit(s) are clear in value.
*
* DEF_NO, if ALL specified bit(s) are NOT clear in value.
*
* Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
*
* (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
*********************************************************************************************************
*/
#define DEF_BIT_IS_CLR_ANY(val, mask) ((((val) & (mask)) == (mask)) ? (DEF_NO ) : (DEF_YES))
/*$PAGE*/
/*
*********************************************************************************************************
* VALUE MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEF_CHK_VAL_MIN()
*
* Description : Validate a value as greater than or equal to a specified minimum value.
*
* Argument(s) : val Value to validate.
*
* val_min Minimum value to test.
*
* Return(s) : DEF_OK, Value is greater than or equal to minimum value.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) DEF_CHK_VAL_MIN() avoids directly comparing any two values if only one of the values
* is negative since the negative value might be incorrectly promoted to an arbitrary
* unsigned value if the other value to compare is unsigned.
*
* (2) Validation of values is limited to the range supported by the compiler &/or target
* environment. All other values that underflow/overflow the supported range will
* modulo/wrap into the supported range as arbitrary signed or unsigned values.
*
* Therefore, any values that underflow the most negative signed value or overflow
* the most positive unsigned value supported by the compiler &/or target environment
* cannot be validated :
*
* ( N-1 N ]
* ( -(2 ) , 2 - 1 ]
* ( ]
*
* where
* N Number of data word bits supported by the compiler
* &/or target environment
*
* (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
* range since many compilers do NOT always correctly handle this value.
*
* (3) 'val' and 'val_min' are compared to 1 instead of 0 to avoid warning generated for
* unsigned numbers.
*********************************************************************************************************
*/
#define DEF_CHK_VAL_MIN(val, val_min) (((!(((val) >= 1) && ((val_min) < 1))) && \
((((val_min) >= 1) && ((val) < 1)) || \
((val) < (val_min)))) ? DEF_FAIL : DEF_OK)
/*$PAGE*/
/*
*********************************************************************************************************
* DEF_CHK_VAL_MAX()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -