Index: Utilities.c =================================================================== diff -u -re8828d66e4a76e0590c3f06b7f6235f33df64e80 -raa1221efc98233c54a97a2cbbf7fb1a5a35d385d --- Utilities.c (.../Utilities.c) (revision e8828d66e4a76e0590c3f06b7f6235f33df64e80) +++ Utilities.c (.../Utilities.c) (revision aa1221efc98233c54a97a2cbbf7fb1a5a35d385d) @@ -8,7 +8,7 @@ * @file Utilities.c * * @author (last) Sean Nash -* @date (last) 23-Jul-2020 +* @date (last) 05-Aug-2020 * * @author (original) Sean * @date (original) 17-Feb-2020 @@ -103,8 +103,8 @@ * @details * Inputs : none * Outputs : none - * @param address : pointer to start address of memory range to calculate CRC for - * @param len : # of bytes in the memory range to calculate CRC for + * @param address pointer to start address of memory range to calculate CRC for + * @param len number of bytes in the memory range to calculate CRC for * @return CRC *************************************************************************/ U16 crc16( const U08 *address, U32 len ) @@ -127,8 +127,8 @@ * @details * Inputs : none * Outputs : none - * @param address : pointer to start address of memory range to calculate CRC for - * @param len : # of bytes in the memory range to calculate CRC for + * @param address pointer to start address of memory range to calculate CRC for + * @param len number of bytes in the memory range to calculate CRC for * @return CRC *************************************************************************/ U08 crc8( const U08 *address, U32 len ) @@ -150,9 +150,9 @@ * @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 + * @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 ) @@ -174,7 +174,23 @@ } else { - timeWindowedCountsInitialized[ cnt ] = FALSE; + if ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) + { + timeWindowedCountsInitialized[ cnt ] = FALSE; +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_INVALID_WIN_MAX_COUNT, maxCnt ) +#else + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_INVALID_WIN_MAX_COUNT, maxCnt ) +#endif + } + else + { +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_INVALID_WIN_COUNT, cnt ) +#else + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_INVALID_WIN_COUNT, cnt ) +#endif + } } } @@ -188,7 +204,7 @@ * @details * Inputs : timeWindowedCounts[][], timeWindowedCountIndexes[], timeWindowedCountCounts[] * Outputs : timeWindowedCounts[][], timeWindowedCountIndexes[], timeWindowedCountCounts[] - * @param cnt : ID of the time windowed count to add an instance to + * @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 *************************************************************************/ @@ -215,13 +231,99 @@ else { #ifdef _DG_ - SET_ALARM_WITH_1_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR ); + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR, cnt ); #else - SET_ALARM_WITH_1_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR ); + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR, cnt ); #endif } return result; +} + +/*********************************************************************//** + * @brief + * The getCriticalData function gets the value for a given critical data \n + * record. The integrity of the critical data is checked first. If the \n + * critical data record fails the integrity check, a fault is triggered. + * @details + * Inputs : none + * Outputs : given critical data record's value is retrieved. + * @param data Ptr to a critical data record + * @return The data from a critical data record + *************************************************************************/ +CRITICAL_DATAS_T getCriticalData( CRITICAL_DATA_T *data ) +{ + CRITICAL_DATAS_T result; + CRITICAL_DATA_T d; + + _disable_IRQ(); + d = *data; + _enable_IRQ(); + + result = d.data; + // verify data integrity + if ( ( ~d.data.uInt != d.comp ) || + ( TRUE != d.set ) || + ( data->typ >= NUM_OF_CRITICAL_DATA_TYPES ) ) + { + result.uInt = 0; +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_CRITICAL_DATA_ERROR, (U32)&data[0], 0 ) +#else + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_CRITICAL_DATA_ERROR, (U32)&data[0], 0 ) +#endif + } + + return result; +} + +/*********************************************************************//** + * @brief + * The setCriticalData function sets the value for a given critical data \n + * record. + * @details + * Inputs : none + * Outputs : given critical data record's value is set to given value + * @param data Ptr to a critical data record + * @param value a value to set + * @return none + *************************************************************************/ +void setCriticalData( CRITICAL_DATA_T *data, CRITICAL_DATAS_T value ) +{ + if ( data->typ < NUM_OF_CRITICAL_DATA_TYPES ) + { + _disable_IRQ(); + data->data = value; + data->comp = ~data->data.uInt; + data->set = TRUE; + _enable_IRQ(); + } + else + { +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_CRITICAL_DATA_ERROR, (U32)&data[0], 1 ) +#else + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_CRITICAL_DATA_ERROR, (U32)&data[0], 1 ) +#endif + } +} + +/*********************************************************************//** + * @brief + * The resetCriticalData function resets a critical data record. + * @details + * Inputs : none + * Outputs : Given critical data record is reset + * @param data Ptr to a critical data record + * @return none + *************************************************************************/ +void resetCriticalData( CRITICAL_DATA_T *data ) +{ + _disable_IRQ(); + data->set = FALSE; + data->data.uInt = 0; + data->comp = ~data->data.uInt; + _enable_IRQ(); } /**@}*/