Index: Common.h =================================================================== diff -u -r36da170faf02387c47766be557b4b391cd55ae92 -r0f1d0c443daee3e30ae823711e85f3410bbf49fe --- Common.h (.../Common.h) (revision 36da170faf02387c47766be557b4b391cd55ae92) +++ Common.h (.../Common.h) (revision 0f1d0c443daee3e30ae823711e85f3410bbf49fe) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file Common.h * -* @author (last) Sean -* @date (last) 12-May-2020 +* @author (last) Dara Navaei +* @date (last) 02-Dec-2020 * * @author (original) Sean * @date (original) 04-Feb-2020 @@ -32,100 +32,108 @@ // **** Types **** -typedef float F32; ///< 32-bit floating point type. -typedef double F64; ///< 64-bit floating point type. -typedef unsigned int U32; ///< 32-bit unsigned integer type. -typedef int S32; ///< 32-bit signed integer type. -typedef unsigned short U16; ///< 16-bit unsigned integer type. -typedef short S16; ///< 16-bit signed integer type. -typedef unsigned char U08; ///< 8-bit unsigned integer type. -typedef unsigned int BOOL; ///< 32-bit boolean type. -typedef unsigned char BYTE; ///< 8-bit byte type. +typedef float F32; ///< 32-bit floating point type +typedef double F64; ///< 64-bit floating point type +typedef unsigned int U32; ///< 32-bit unsigned integer type +typedef int S32; ///< 32-bit signed integer type +typedef unsigned short U16; ///< 16-bit unsigned integer type +typedef short S16; ///< 16-bit signed integer type +typedef unsigned char U08; ///< 8-bit unsigned integer type +typedef unsigned int BOOL; ///< 32-bit boolean type +typedef unsigned char BYTE; ///< 8-bit byte type /// List of pin signal states. typedef enum Pin_Signal_States { - PIN_SIGNAL_LOW = 0, ///< Low signal level. - PIN_SIGNAL_HIGH, ///< High signal level. - NUM_OF_PIN_SIGNAL_STATES ///< # of pin signal states. + PIN_SIGNAL_LOW = 0, ///< Low signal level + PIN_SIGNAL_HIGH, ///< High signal level + NUM_OF_PIN_SIGNAL_STATES ///< Number of pin signal states } PIN_SIGNAL_STATE_T; -/// List of self test status. +/// List of self-test status. typedef enum Self_Test_Status { - SELF_TEST_STATUS_IN_PROGRESS = 0, ///< Self test is in progress. - SELF_TEST_STATUS_PASSED, ///< Self test has passed. - SELF_TEST_STATUS_FAILED, ///< Self test has failed. - NUM_OF_SELF_TEST_STATUS ///< # of self test status. + SELF_TEST_STATUS_IN_PROGRESS = 0, ///< Self test is in progress + SELF_TEST_STATUS_PASSED, ///< Self test has passed + SELF_TEST_STATUS_FAILED, ///< Self test has failed + NUM_OF_SELF_TEST_STATUS ///< Number of self-test status } SELF_TEST_STATUS_T; /// List of 2-way valve states. typedef enum Two_Way_States { - STATE_CLOSED = 0, ///< Valve is closed state. - STATE_OPEN, ///< Valve is open state. - NUM_OF_OPN_CLS_STATES ///< # of 2-way valve states. + STATE_CLOSED = 0, ///< Valve is closed state + STATE_OPEN, ///< Valve is open state + NUM_OF_OPN_CLS_STATES ///< Number of 2-way valve states } OPN_CLS_STATE_T; /// List of motor directions. typedef enum Motor_Directions { - MOTOR_DIR_FORWARD = 0, ///< Motor direction is forward. - MOTOR_DIR_REVERSE, ///< Motor direction is reverse. - NUM_OF_MOTOR_DIRECTIONS ///< # of motor directions. + MOTOR_DIR_FORWARD = 0, ///< Motor direction is forward + MOTOR_DIR_REVERSE, ///< Motor direction is reverse + NUM_OF_MOTOR_DIRECTIONS ///< Number of motor directions } MOTOR_DIR_T; /// List of pump control modes. typedef enum Pump_Control_Modes { - PUMP_CONTROL_MODE_CLOSED_LOOP = 0, ///< Pump controlled based on set point and feedback. - PUMP_CONTROL_MODE_OPEN_LOOP, ///< Pump controlled to set PWM duty cycle. - NUM_OF_PUMP_CONTROL_MODES ///< # of pump control modes. + PUMP_CONTROL_MODE_CLOSED_LOOP = 0, ///< Pump controlled based on set point and feedback + PUMP_CONTROL_MODE_OPEN_LOOP, ///< Pump controlled to set PWM duty cycle + NUM_OF_PUMP_CONTROL_MODES ///< Number of pump control modes } PUMP_CONTROL_MODE_T; +/// List of switch states. +typedef enum Switch_States +{ + TURN_OFF = 0, ///< Turn off + TURN_ON, ///< Turn on +} SWITCH_STATES_T; + // **** Common Definitions **** -#define NEARLY_ZERO 0.00000001 ///< 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 MASK_OFF_MSB 0x00FF ///< Bits to mask off the most significant byte of a 2-byte word. -#define MASK_OFF_LSB 0xFF00 ///< Bits to mask off the least significant byte of a 2-byte word. -#define MASK_OFF_MSW 0x0000FFFF ///< Bits to mask off the most significant 2-byte word of a 4-byte word. -#define MASK_OFF_LSW 0xFFFF0000 ///< Bits to mask off the least significant 2-byte word of a 4-byte word. -#define MASK_OFF_U32_MSB 0x00FFFFFF ///< Bits to mask off the most significant 2-byte word of a 4-byte word. -#define SHIFT_8_BITS_FOR_BYTE_SHIFT 8 ///< # of bits to shift in order to shift a byte. -#define SHIFT_16_BITS_FOR_WORD_SHIFT 16 ///< # of bits to shift in order to shift 2 bytes. -#define MASK_OFF_NIBBLE_LSB 0xF0 ///< Bits to mask off the least significant nibble of a byte. -#define MASK_OFF_NIBBLE_MSB 0x0F ///< Bits to mask off the most significant nibble of a byte. -#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 ///< # 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 ML_PER_LITER 1000 ///< # of milliliters in a liter. -#define MS_PER_SECOND 1000 ///< # of milliseconds in a second. -#define SEC_PER_MIN 60 ///< # of seconds in a minute. -#define FRACTION_TO_PERCENT_FACTOR 100.0 ///< Percentage factor (100). -#define MIN_PER_HOUR 60 ///< # of minutes in an hour. -#define PI 3.1415927 ///< PI. +#define NEARLY_ZERO 0.00000001 ///< 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 MASK_OFF_MSB 0x00FF ///< Bits to mask off the most significant byte of a 2-byte word +#define MASK_OFF_LSB 0xFF00 ///< Bits to mask off the least significant byte of a 2-byte word +#define MASK_OFF_MSW 0x0000FFFF ///< Bits to mask off the most significant 2-byte word of a 4-byte word +#define MASK_OFF_LSW 0xFFFF0000 ///< Bits to mask off the least significant 2-byte word of a 4-byte word +#define MASK_OFF_U32_MSB 0x00FFFFFF ///< Bits to mask off the most significant 3-byte word of a 4-byte word +#define SHIFT_8_BITS_FOR_BYTE_SHIFT 8 ///< Number of bits to shift in order to shift a byte +#define SHIFT_16_BITS_FOR_WORD_SHIFT 16 ///< Number of bits to shift in order to shift 2 bytes +#define MASK_OFF_NIBBLE_LSB 0xF0 ///< Bits to mask off the least significant nibble of a byte +#define MASK_OFF_NIBBLE_MSB 0x0F ///< Bits to mask off the most significant nibble of a byte +#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 ML_PER_LITER 1000 ///< Number of milliliters in a liter +#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 MIN_PER_HOUR 60 ///< Number of minutes in an hour +#define PI 3.1415927 ///< PI #define SECONDS_IN_A_DAY 86400 ///< Number of seconds in a day // **** 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 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. -#define DEC_WRAP(v, l, u) ((v) <= (l) ? (u) : ((v) - 1)) ///< Macro decrements a value and wraps to a maximum when a minimum is reached. -#define INC_CAP(v, u) ((v) >= (u) ? (u) : ((v) + 1)) ///< Macro increments a value but does not allow to exceed a maximum. -#define MAX(a, b) ((a) < (b) ? (b) : (a)) ///< Macro enforces a maximum on a value. -#define MIN(a, b) ((a) > (b) ? (b) : (a)) ///< Macro enforces a minimum on a value. -#define GET_LSB_OF_WORD(w) ((U08)((w) & MASK_OFF_MSB)) ///< Macro returns the least signficant byte of a 2-byte word. -#define GET_MSB_OF_WORD(w) ((U08)(((w) >> SHIFT_8_BITS_FOR_BYTE_SHIFT) & MASK_OFF_MSB)) ///< Macro returns the most signficant byte of a 2-byte word. -#define GET_LSW_OF_LONG(l) ((U16)((l) & MASK_OFF_MSW)) ///< Macro returns the least signficant 2-byte word of a 4-byte word. -#define GET_MSW_OF_LONG(l) ((U16)(((l) >> SHIFT_16_BITS_FOR_WORD_SHIFT) & MASK_OFF_MSW)) ///< Macro returns the most signficant 2-byte word of a 4-byte word. -#define MAKE_WORD_OF_BYTES(h, l) ((((U16)(h) << SHIFT_8_BITS_FOR_BYTE_SHIFT) & MASK_OFF_LSB) | ((U16)(l) & MASK_OFF_MSB)) ///< Macro merges two bytes into a 2-byte word. -#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 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 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 +#define DEC_WRAP(v, l, u) ((v) <= (l) ? (u) : ((v) - 1)) ///< Macro decrements a value and wraps to a maximum when a minimum is reached +#define INC_CAP(v, u) ((v) >= (u) ? (u) : ((v) + 1)) ///< Macro increments a value but does not allow to exceed a maximum +#define MAX(a, b) ((a) < (b) ? (b) : (a)) ///< Macro enforces a maximum on a value +#define MIN(a, b) ((a) > (b) ? (b) : (a)) ///< Macro enforces a minimum on a value +#define GET_LSB_OF_WORD(w) ((U08)((w) & MASK_OFF_MSB)) ///< Macro returns the least signficant byte of a 2-byte word +#define GET_MSB_OF_WORD(w) ((U08)(((w) >> SHIFT_8_BITS_FOR_BYTE_SHIFT) & MASK_OFF_MSB)) ///< Macro returns the most signficant byte of a 2-byte word +#define GET_LSW_OF_LONG(l) ((U16)((l) & MASK_OFF_MSW)) ///< Macro returns the least signficant 2-byte word of a 4-byte word +#define GET_MSW_OF_LONG(l) ((U16)(((l) >> SHIFT_16_BITS_FOR_WORD_SHIFT) & MASK_OFF_MSW)) ///< Macro returns the most signficant 2-byte word of a 4-byte word +#define MAKE_WORD_OF_BYTES(h, l) ((((U16)(h) << SHIFT_8_BITS_FOR_BYTE_SHIFT) & MASK_OFF_LSB) | ((U16)(l) & MASK_OFF_MSB)) ///< Macro merges two bytes into a 2-byte word +#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 /// Macro to set a specific alarm with 1 piece of unsigned 32-bit alarm data. @@ -137,7 +145,6 @@ } /// Macro to set a specific alarm with 1 piece of floating point alarm data. - #define SET_ALARM_WITH_1_F32_DATA(a,d1) { \ ALARM_DATA_T dat1; \ dat1.dataType = ALARM_DATA_TYPE_F32; \ @@ -167,8 +174,6 @@ activateAlarm2Data( a, dat1, dat2 ); \ } -/**@}*/ - // **** VectorCAST Definitions **** #ifdef _VECTORCAST_