📄 lib_def.h
字号:
/*
*********************************************************************************************************
* 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*/
/*
*********************************************************************************************************
* 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.
*********************************************************************************************************
*/
#define DEF_CHK_VAL_MIN(val, val_min) (((!(((val) >= 0) && ((val_min) < 0))) && \
((((val_min) >= 0) && ((val) < 0)) || \
((val) < (val_min)))) ? DEF_FAIL : DEF_OK)
/*$PAGE*/
/*
*********************************************************************************************************
* DEF_CHK_VAL_MAX()
*
* Description : Validate a value as less than or equal to a specified maximum value.
*
* Argument(s) : val Value to validate.
*
* val_max Maximum value to test.
*
* Return(s) : DEF_OK, Value is less than or equal to maximum value.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) DEF_CHK_VAL_MAX() 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.
*********************************************************************************************************
*/
#define DEF_CHK_VAL_MAX(val, val_max) (((!(((val_max) >= 0) && ((val) < 0))) && \
((((val) >= 0) && ((val_max) < 0)) || \
((val) > (val_max)))) ? DEF_FAIL : DEF_OK)
/*$PAGE*/
/*
*********************************************************************************************************
* DEF_CHK_VAL()
*
* Description : Validate a value as greater than or equal to a specified minimum value & less than or
* equal to a specified maximum value.
*
* Argument(s) : val Value to validate.
*
* val_min Minimum value to test.
*
* val_max Maximum value to test.
*
* Return(s) : DEF_OK, Value is greater than or equal to minimum value AND
* less than or equal to maximum value.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) DEF_CHK_VAL() 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) DEF_CHK_VAL() does NOT validate that the maximum value ('val_max') is greater than
* or equal to the minimum value ('val_min').
*********************************************************************************************************
*/
#define DEF_CHK_VAL(val, val_min, val_max) (((DEF_CHK_VAL_MIN(val, val_min) == DEF_FAIL) || \
(DEF_CHK_VAL_MAX(val, val_max) == DEF_FAIL)) ? DEF_FAIL : DEF_OK)
/*$PAGE*/
/*
*********************************************************************************************************
* MATH MACRO'S
*
* Note(s) : (1) Ideally, ALL mathematical macro's & functions SHOULD be defined in the custom mathematics
* library ('lib_math.*'). #### However, to maintain backwards compatibility with previously-
* released modules, mathematical macro & function definitions should only be moved to the
* custom mathematics library once all previously-released modules are updated to include the
* custom mathematics library.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEF_MIN()
*
* Description : Determine the minimum of two values.
*
* Argument(s) : a First value.
*
* b Second value.
*
* Return(s) : Minimum of the two values.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
#define DEF_MIN(a, b) (((a) < (b)) ? (a) : (b))
/*
*********************************************************************************************************
* DEF_MAX()
*
* Description : Determine the maximum of two values.
*
* Argument(s) : a First value.
*
* b Second value.
*
* Return(s) : Maximum of the two values.
*
* Note(s) : none.
*********************************************************************************************************
*/
#define DEF_MAX(a, b) (((a) > (b)) ? (a) : (b))
/*$PAGE*/
/*
*********************************************************************************************************
* DEF_ABS()
*
* Description : Determine the absolute value of a value.
*
* Argument(s) : a Value to calculate absolute value.
*
* Return(s) : Absolute value of the value.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
#define DEF_ABS(a) (((a) < 0) ? (-(a)) : (a))
/*$PAGE*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif /* End of lib def module include. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -