/**********************************************************************//** * * Copyright (c) 2019-2020 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 * * @date 19-Sep-2019 * @author S. Nash * * @brief Header file for common definitions, types and macros. * **************************************************************************/ #ifndef __COMMON_H__ #define __COMMON_H__ #include "hal_stdtypes.h" /** * @defgroup CommonHeader CommonHeader * @brief Provides commonly used definitions and macros. * * @addtogroup CommonHeader * @{ */ // ********** public definitions ********** // **** 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. /// 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_STATE_T; /// 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_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. } 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_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_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 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 signficiant 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. // **** Common Macros **** #define ABS(v) ((v) < 0 ? (v) * -1 : (v)) #define FABS(v) ((v) < 0.0 ? (v) * -1.0 : (v)) #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. /**@}*/ /// Macro to set a specific alarm with 1 piece of unsigned 32-bit alarm data. #define SET_ALARM_WITH_1_U32_DATA(a,d1) { \ ALARM_DATA_T dat1; \ dat1.dataType = ALARM_DATA_TYPE_U32; \ dat1.data.uInt.data = (U32)(d1); \ activateAlarm1Data( a, dat1 ); \ } /// 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; \ dat1.data.flt.data = (F32)(d1); \ activateAlarm1Data( a, dat1 ); \ } /// Macro to set a specific alarm with 2 pieces of unsigned 32-bit alarm data. #define SET_ALARM_WITH_2_U32_DATA(a,d1,d2) { \ ALARM_DATA_T dat1; \ ALARM_DATA_T dat2; \ dat1.dataType = ALARM_DATA_TYPE_U32; \ dat1.data.uInt.data = (U32)(d1); \ dat2.dataType = ALARM_DATA_TYPE_U32; \ dat2.data.uInt.data = (U32)(d2); \ activateAlarm2Data( a, dat1, dat2 ); \ } /// Macro to set a specific alarm with 2 pieces of floating point alarm data. #define SET_ALARM_WITH_2_F32_DATA(a,d1,d2) { \ ALARM_DATA_T dat1; \ ALARM_DATA_T dat2; \ dat1.dataType = ALARM_DATA_TYPE_F32; \ dat1.data.flt.data = (F32)(d1); \ dat2.dataType = ALARM_DATA_TYPE_F32; \ dat2.data.flt.data = (F32)(d2); \ activateAlarm2Data( a, dat1, dat2 ); \ } // **** VectorCAST Definitions **** #ifdef _VECTORCAST_ #define _enable_IRQ() #define _disable_IRQ() #define _enable_FIQ() #define _disable_FIQ() #define fabs(v) ((v) < 0.0 ? ((v) * -1.0) : (v)) #endif // include alarm mgmt header so any module can trigger an alarm #include "AlarmMgmt.h" // include Message definitions header for access to system message IDs #include "MsgDefs.h" // include test support definitions and macros #include "TestSupport.h" #endif