Index: Common.h =================================================================== diff -u -rf4ee38d0f7a18e47e6e4980360a7eac9220d244a -r0f1d0c443daee3e30ae823711e85f3410bbf49fe --- Common.h (.../Common.h) (revision f4ee38d0f7a18e47e6e4980360a7eac9220d244a) +++ Common.h (.../Common.h) (revision 0f1d0c443daee3e30ae823711e85f3410bbf49fe) @@ -1,42 +1,25 @@ -/**********************************************************************//** +/************************************************************************** * -* 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. +* 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 +* @file Common.h * -* @date 19-Sep-2019 -* @author S. Nash +* @author (last) Dara Navaei +* @date (last) 02-Dec-2020 * -* @brief Header file for common definitions, types and macros. +* @author (original) Sean +* @date (original) 04-Feb-2020 * -**************************************************************************/ +***************************************************************************/ #ifndef __COMMON_H__ #define __COMMON_H__ #include "hal_stdtypes.h" -// ********** build switches ********** - -#ifndef _VECTORCAST_ -// #define RM46_EVAL_BOARD_TARGET 1 -// #define SIMULATE_UI 1 - #define DEBUG_ENABLED 1 -// #define ACK_NOT_IMPLEMENTED 1 - #define UF_TEST_ENABLED 1 - #define DISABLE_CRC_ERROR 1 - #define DISABLE_MOTOR_CURRENT_ERRORS 1 - #define SHOW_RAW_FLOW_VALUES 1 - - #ifdef DEBUG_ENABLED - #include - #include - #endif -#endif - /** * @defgroup CommonHeader CommonHeader * @brief Provides commonly used definitions and macros. @@ -49,99 +32,110 @@ // **** 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 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. +#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. #define SET_ALARM_WITH_1_U32_DATA(a,d1) { \ ALARM_DATA_T dat1; \ @@ -150,7 +144,7 @@ activateAlarm1Data( a, dat1 ); \ } -/// Macro to set a specific alarm with 1 piece of unsigned floating point alarm data. +/// 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; \ @@ -169,27 +163,35 @@ 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() - #ifndef _MINGW_ - #pragma WEAK(can1LowLevelInterrupt) - void can1LowLevelInterrupt(void) {} - #pragma WEAK(can1HighLevelInterrupt) - void can1HighLevelInterrupt(void) {} - #endif - #define fabs(v) ((v) < 0.0 ? ((v) * -1.0) : (v)) - #endif -// include alarm mgmt header +// 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