Index: Common.h =================================================================== diff -u -r98a3bed2b658adc37be874746ece9634a8460f56 -r6b11ea4a37a54cd47af543900dfa68dac27c8c7e --- Common.h (.../Common.h) (revision 98a3bed2b658adc37be874746ece9634a8460f56) +++ Common.h (.../Common.h) (revision 6b11ea4a37a54cd47af543900dfa68dac27c8c7e) @@ -7,8 +7,8 @@ * * @file Common.h * -* @author (last) Hung Nguyen -* @date (last) 04-Feb-2022 +* @author (last) Dara Navaei +* @date (last) 03-Aug-2022 * * @author (original) Sean * @date (original) 04-Feb-2020 @@ -86,7 +86,7 @@ // **** Common Definitions **** #define NEARLY_INFINITY 1.0E20 ///< Value that is nearly infinity. -#define NEARLY_ZERO 0.00000001 ///< Value that is nearly zero. Used for floating point zero comparisons (e.g. divide by zero checks) +#define NEARLY_ZERO 0.00000001F ///< Value that is nearly zero. Used for floating point zero comparisons (e.g. divide by zero checks) #define HEX_64_K 0x10000 ///< 64K (65536 in decimal) #define HEX_32_BIT_FULL_SCALE 0xFFFFFFFF ///< 32-bit full scale value #define MASK_OFF_MSB 0x00FF ///< Bits to mask off the most significant byte of a 2-byte word @@ -104,25 +104,27 @@ #define MAX_DOUBLE_DIGIT_DECIMAL 99U ///< Maximum value for a decimal byte #define MAX_SINGLE_DIGIT_DECIMAL 9U ///< Maximum value for a decimal nibble #define SHIFT_BITS_BY_4 4U ///< Number of bits to shift in order to shift a nibble -#define FLOAT_TO_INT_ROUNDUP_OFFSET 0.5 ///< Offset to add to a floating point value for rounding rounding when converting to integer +#define SHIFT_BITS_BY_31 31 ///< Shift bits by 31 +#define FLOAT_TO_INT_ROUNDUP_OFFSET 0.5F ///< Offset to add to a floating point value for rounding rounding when converting to integer #define ML_PER_LITER 1000 ///< Number of milliliters in a liter #define MA_PER_AMP 1000 ///< Number of milliamps in an amp #define MS_PER_SECOND 1000 ///< Number of milliseconds in a second #define US_PER_SECOND 1000000 ///< Number of microseconds in a millisecond #define SEC_PER_MIN 60 ///< Number of seconds in a minute -#define FRACTION_TO_PERCENT_FACTOR 100.0 ///< Percentage factor (100) +#define FRACTION_TO_PERCENT_FACTOR 100.0F ///< Percentage factor (100) #define MIN_PER_HOUR 60 ///< Number of minutes in an hour -#define PI 3.1415927 ///< PI +#define PI 3.1415927F ///< PI #define SECONDS_IN_A_DAY 86400 ///< Number of seconds in a day #define BITS_8_FULL_SCALE 256 ///< Full scale range for 8 bit ADC or DAC #define BITS_10_FULL_SCALE 1024 ///< Full scale range for 10 bit ADC or DAC #define BITS_12_FULL_SCALE 4096 ///< Full scale range for 12 bit ADC or DAC #define BITS_14_FULL_SCALE 16384 ///< Full scale range for 14 bit ADC or DAC #define BITS_16_FULL_SCALE 65536 ///< Full scale range for 16 bit ADC or DAC +#define HALF 0.5F ///< Half // **** Common Macros **** -#define FLOAT_TO_INT_WITH_ROUND(f) ((f) < 0.0 ? (S32)((f) - FLOAT_TO_INT_ROUNDUP_OFFSET) : (S32)((f) + FLOAT_TO_INT_ROUNDUP_OFFSET)) ///< Macro converts a floating point value to an integer +#define FLOAT_TO_INT_WITH_ROUND(f) ((f) < 0.0F ? (S32)((f) - FLOAT_TO_INT_ROUNDUP_OFFSET) : (S32)((f) + FLOAT_TO_INT_ROUNDUP_OFFSET)) ///< Macro converts a floating point value to an integer #define CAP(v, u) ((v) > (u) ? (u) : (v)) ///< Macro caps a value to a maximum #define RANGE(v, l, u) ((v) > (u) ? (u) : ((v) < (l) ? (l) : (v))) ///< Macro enforces a range on a value #define INC_WRAP(v, l, u) ((v) >= (u) ? (l) : ((v) + 1)) ///< Macro increments a value and wraps to a minimum when a maximum is reached @@ -138,7 +140,7 @@ #define MAKE_LONG_OF_WORDS(h, l) ((((U32)(h) << SHIFT_16_BITS_FOR_WORD_SHIFT) & MASK_OFF_LSW) | ((U32)(l) & MASK_OFF_MSW)) ///< Macro merges two 2-byte words into a 4-byte word #define GET_TOGGLE(v, l, h) ((v) == (l) ? (h) : (l)) ///< Macro toggles a value #define BIT_BY_POS(p) (1U << (p)) ///< Macro returns a bit mask for a bit of given position -#define RAD2DEG(r) ((r) * 180.0 / PI) ///< Macro converts radians to degrees +#define RAD2DEG(r) ((r) * 180.0F / PI) ///< Macro converts radians to degrees /// Macro to set a specific alarm with 1 piece of unsigned 32-bit alarm data. #define SET_ALARM_WITH_1_U32_DATA(a,d1) { \ @@ -205,10 +207,10 @@ /// Record structure for event data of any supported type. typedef union { - EVENT_DATA_U32_T uInt; ///< Event data of unsigned integer type. - EVENT_DATA_S32_T sInt; ///< Event data of signed integer type. - EVENT_DATA_F32_T flt; ///< Event data of floating point type. - EVENT_DATA_BOOL_T bln; ///< Event data of boolean type. + EVENT_DATA_U32_T uInt; ///< Event data of unsigned integer type. + EVENT_DATA_S32_T sInt; ///< Event data of signed integer type. + EVENT_DATA_F32_T flt; ///< Event data of floating point type. + EVENT_DATA_BOOL_T bln; ///< Event data of boolean type. } EVENT_DATAS_T; /// Event data types list.