Index: NVDataMgmt.c =================================================================== diff -u -r51178541e201275f227c8b3e8084a455bb78cf39 -rcfd81ad59f6a5ccece4a3e0dc24c9601f7a13259 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 51178541e201275f227c8b3e8084a455bb78cf39) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision cfd81ad59f6a5ccece4a3e0dc24c9601f7a13259) @@ -668,9 +668,13 @@ break; default: - +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, + NVDataMgmtSelfTestState ); +#else SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, NVDataMgmtSelfTestState ); +#endif NVDataMgmtSelfTestState = NVDATAMGMT_SELF_TEST_STATE_COMPLETE; NVDataMgmtSelfTestResult = SELF_TEST_STATUS_FAILED; break; @@ -766,8 +770,13 @@ default: +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, + NVDataMgmtExecState ); +#else SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, NVDataMgmtExecState ); +#endif NVDataMgmtExecState = NVDATAMGMT_EXEC_STATE_IDLE; break; } Index: RTC.c =================================================================== diff -u -rd2078bea465465a2d9dcd162276257eff747a65c -rcfd81ad59f6a5ccece4a3e0dc24c9601f7a13259 --- RTC.c (.../RTC.c) (revision d2078bea465465a2d9dcd162276257eff747a65c) +++ RTC.c (.../RTC.c) (revision cfd81ad59f6a5ccece4a3e0dc24c9601f7a13259) @@ -333,7 +333,11 @@ default: +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RTC_SELF_TEST_INVALID_STATE, RTCSelfTestState ); +#else SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_RTC_SELF_TEST_INVALID_STATE, RTCSelfTestState ); +#endif RTCSelfTestResult = SELF_TEST_STATUS_FAILED; RTCSelfTestState = RTC_SELF_TEST_STATE_COMPLETE; break; @@ -392,7 +396,11 @@ default: +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RTC_EXEC_INVALID_STATE, RTCExecState ); +#else SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_RTC_EXEC_INVALID_STATE, RTCExecState ); +#endif RTCExecState = RTC_EXEC_STATE_IDLE; break; } Index: TestSupport.h =================================================================== diff -u -r1640a914c7923f8fd8fb78801158e0979c0a5256 -rcfd81ad59f6a5ccece4a3e0dc24c9601f7a13259 --- TestSupport.h (.../TestSupport.h) (revision 1640a914c7923f8fd8fb78801158e0979c0a5256) +++ TestSupport.h (.../TestSupport.h) (revision cfd81ad59f6a5ccece4a3e0dc24c9601f7a13259) @@ -150,7 +150,7 @@ } \ else \ { \ - activateAlarmNoData( ALARM_ID_SOFTWARE_FAULT ); \ + activateAlarmNoData( ALARM_ID_HD_SOFTWARE_FAULT ); \ } \ return result; \ } Index: Utilities.c =================================================================== diff -u -r62f81f0f9649926feae18dc09da001690dbcd26e -rcfd81ad59f6a5ccece4a3e0dc24c9601f7a13259 --- Utilities.c (.../Utilities.c) (revision 62f81f0f9649926feae18dc09da001690dbcd26e) +++ Utilities.c (.../Utilities.c) (revision cfd81ad59f6a5ccece4a3e0dc24c9601f7a13259) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -16,15 +16,22 @@ **************************************************************************/ #include "Common.h" +#include "Timers.h" #include "Utilities.h" +/** + * @addtogroup Utilities + * @{ + */ + // ********** private definitions ********** -#define INITIAL_CRC16_VAL 0xFFFF -#define INITIAL_CRC08_VAL 0x00 +#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function. +#define INITIAL_CRC08_VAL 0x00 ///< Seed for 8-bit CRC function. // ********** private data ********** +/// CRC-16 look-up table. const U16 crc16_table[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, @@ -61,6 +68,7 @@ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 }; +/// CRC-8 look-up table. const U08 crc8_table[] = { 0, 49, 98, 83, 196, 245, 166, 151, 185, 136, 219, 234, 125, 76, 31, 46, 67, 114, 33, 16, 135, 182, 229, 212, 250, 203, 152, 169, 62, 15, 92, 109, @@ -80,8 +88,16 @@ 130, 179, 224, 209, 70, 119, 36, 21, 59, 10, 89, 104, 255, 206, 157, 172 }; -/************************************************************************* - * @brief crc16 +// variables for time windowed counts (counts # of instances in a specific window of time) +static BOOL timeWindowedCountsInitialized[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Initialized flags for time windowed counts. +static U32 timeWindowedCountsMaxCount[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Max. counts for time windowed counts. +static U32 timeWindowedCountsWindowMs[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Time windows (in ms) for time windowed counts. +static U32 timeWindowedCounts[ NUM_OF_TIME_WINDOWED_COUNTS ][ MAX_TIME_WINDOWED_COUNT ]; ///< Time stamps for instances for time windowed counts. +static U32 timeWindowedCountIndexes[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< List indexes for time windowed counts. +static U32 timeWindowedCountCounts[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Current counts for time windowed counts. + +/*********************************************************************//** + * @brief * The crc16 function calculates a 16-bit CRC for a given range of bytes \n * in memory. Poly = 0x1021. Not reflected. Initial value = 0xFFFF. * @details @@ -104,8 +120,8 @@ return crc; } -/************************************************************************* - * @brief crc8 +/*********************************************************************//** + * @brief * The crc8 function calculates a 8-bit CRC for a given range of bytes \n * in memory. * @details @@ -128,3 +144,69 @@ return crc; } +/*********************************************************************//** + * @brief + * The initTimeWindowedCount function initializes a given time windowed count. + * @details + * Inputs : none + * Outputs : all time windowed count variables for a given time windowed count are initialized. + * @param cnt : ID of the time windowed count to initialize + * @param maxCnt : maximum number of instances in the time window for this count + * @param winMs : number of ms in the time window for this count + * @return none + *************************************************************************/ +void initTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt, U32 maxCnt, U32 winMs ) +{ + if ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) + { + U32 i; + + // initialize a time windowed count + timeWindowedCountsMaxCount[ cnt ] = maxCnt; + timeWindowedCountsWindowMs[ cnt ] = winMs; + timeWindowedCountIndexes[ cnt ] = 0; + timeWindowedCountCounts[ cnt ] = 0; + for ( i = 0; i < MAX_TIME_WINDOWED_COUNT; i++ ) + { + timeWindowedCounts[ cnt ][ i ] = 0; + } + timeWindowedCountsInitialized[ cnt ] = TRUE; + } +} + +/*********************************************************************//** + * @brief + * The incTimeWindowedCount function adds a new instance to a given time \n + * windowed count. + * @details + * Inputs : timeWindowedCounts[][], timeWindowedCountIndexes[], timeWindowedCountCounts[] + * Outputs : timeWindowedCounts[][], timeWindowedCountIndexes[], timeWindowedCountCounts[] + * @param cnt : ID of the time windowed count to add an instance to + * @return TRUE if this instances brings the count to the maximum within \n + * this counts time window, otherwise FALSE + *************************************************************************/ +BOOL incTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt ) +{ + BOOL result = FALSE; + U32 timeInMS; + + if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( TRUE == timeWindowedCountsInitialized[ cnt ] ) ) + { + // replace oldest instance in list with this new one + timeWindowedCounts[ cnt ][ timeWindowedCountIndexes[ cnt ] ] = getMSTimerCount(); + // move index to next position (may wrap) + timeWindowedCountIndexes[ cnt ] = INC_WRAP( timeWindowedCountIndexes[ cnt ], 0, timeWindowedCountsMaxCount[ cnt ] - 1 ); + // update list count + timeWindowedCountCounts[ cnt ] = INC_CAP( timeWindowedCountCounts[ cnt ], timeWindowedCountsMaxCount[ cnt ] ); + // check if too many instances in window of time + timeInMS = calcTimeSince( timeWindowedCounts[ cnt ][ timeWindowedCountIndexes[ cnt ] ] ); + if ( ( timeWindowedCountCounts[ cnt ] >= timeWindowedCountsMaxCount[ cnt ] ) && ( timeInMS <= timeWindowedCountsWindowMs[ cnt ] ) ) + { + result = TRUE; + } + } + + return result; +} + +/**@}*/ Index: Utilities.h =================================================================== diff -u -r62f81f0f9649926feae18dc09da001690dbcd26e -rcfd81ad59f6a5ccece4a3e0dc24c9601f7a13259 --- Utilities.h (.../Utilities.h) (revision 62f81f0f9649926feae18dc09da001690dbcd26e) +++ Utilities.h (.../Utilities.h) (revision cfd81ad59f6a5ccece4a3e0dc24c9601f7a13259) @@ -17,12 +17,42 @@ #ifndef __UTILITIES_H__ #define __UTILITIES_H__ +/** + * @defgroup Utilities Utilities + * @brief Utilities module contains various utility functions. + * + * @addtogroup Utilities + * @{ + */ + // ********** public definitions ********** +#define MAX_TIME_WINDOWED_COUNT 5 ///< Maximum # of counts that a time windowed count can count to. +/// Enumeration of time-windowed counts. +typedef enum TimeWindowedCounts +{ + TIME_WINDOWED_COUNT_BAD_MSG_CRC = 0, ///< Bad message CRC. + TIME_WINDOWED_COUNT_CAN_WARNING, ///< CAN warning. + TIME_WINDOWED_COUNT_CAN_PASSIVE, ///< CAN passive mode. + TIME_WINDOWED_COUNT_CAN_OFF, ///< CAN off. + TIME_WINDOWED_COUNT_CAN_PARITY, ///< CAN parity error. + TIME_WINDOWED_COUNT_FPGA_UART_FRAME_ERROR, ///< FPGA UART frame error. + TIME_WINDOWED_COUNT_FPGA_UART_OVERRUN, ///< FPGA UART overrun error. +#ifdef _HD_ +#endif +#ifdef _DG_ +#endif + NUM_OF_TIME_WINDOWED_COUNTS ///< Number of pressure sensors. +} TIME_WINDOWED_COUNT_T; + // ********** public function prototypes ********** U16 crc16( const U08 *address, U32 len ); U08 crc8( const U08 *address, U32 len ); +void initTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt, U32 maxCnt, U32 winMs ); +BOOL incTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt ); +/**@}*/ + #endif