Index: NVDataMgmt.c =================================================================== diff -u -rcd1dbf44ebce97f61ad4a757d47449562ec366f0 -r4b13eff164ec468e415fff197ed8af3b85504df0 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision cd1dbf44ebce97f61ad4a757d47449562ec366f0) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 4b13eff164ec468e415fff197ed8af3b85504df0) @@ -19,10 +19,13 @@ #include // For memcpy +#include "system.h" #include "F021.h" + +#include "MsgQueues.h" #include "NVDataMgmt.h" #include "RTC.h" -#include "system.h" +#include "SystemCommMessages.h" #include "Timers.h" #include "Utilities.h" @@ -81,6 +84,8 @@ #define COMMAND_TIME_OUT 500U // time in ms ///< Timeout for an EEPROM or RTC command in ms +#define ERASE_CALIBRATION_KEY 0xD2C3B4A5 ///< 32-bit key required for clearing calibration data. + /// NVDataMgmt self-test states enumeration. typedef enum NVDataMgmt_Self_Test_States { @@ -226,6 +231,9 @@ static BOOL calRecordIsValid = FALSE; ///< Flag indicates whether stored calibration record was found to be valid static volatile BOOL powerOffIsImminent = FALSE; ///< Power off warning has been signaled. Non-volatile memory operations should be completed ASAP and then ceased +// *** This declaration will cause a compiler error if CALIBRATION_DATA_T record size exceeds max message payload size. +U08 calRecordSizeAssertion[ ( sizeof( CALIBRATION_DATA_T ) <= MAX_MSG_PAYLOAD_SIZE ? 1 : -1 ) ]; + // Private functions static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestStart ( void ); @@ -367,7 +375,7 @@ /*********************************************************************//** * @brief - * The getCalibrationData returns the data in the structure that hold + * The getCalibrationData function returns the data in the structure that hold * calibration record to buffer that the caller has provided. * @details Inputs: calibrationRecord * @details Outputs: none @@ -389,6 +397,38 @@ /*********************************************************************//** * @brief + * The testResetCalibrationData function erases the calibration data. + * @details + * Inputs: calibrationRecord + * Outputs: none + * @param key a key is required to erase calibration data + * @return TRUE if calibration record valid + *************************************************************************/ +BOOL testResetCalibrationData( U32 key ) +{ + BOOL status = FALSE; + + // tester must be logged in + if ( TRUE == isTestingActivated() ) + { + // verify key + if ( ERASE_CALIBRATION_KEY == key ) + { + // erase calibration record + memset( (U08*)&calibrationRecord.calData, 0, sizeof(CALIBRATION_DATA_T) ); + // zero CRC so integrity check will fail unless calibration data set again + calibrationRecord.crc = 0; + // save erased calibration record + // queue job to re-store all non-volatile data records to memory bank 7, sector 0 (sector allocated for these records) from RAM + status = enqueueBank7Sector0Records(); + } + } + + return status; +} + +/*********************************************************************//** + * @brief * The setServiceDate updates the structure that holds the calibration data, * calls another function to calculate the CRC for the provided data if * there is enough queues available, it schedules a write to RTC RAM. Index: PersistentAlarm.c =================================================================== diff -u -r97f119050f52c01aa9346c80b706dfdbbda3ac9e -r4b13eff164ec468e415fff197ed8af3b85504df0 --- PersistentAlarm.c (.../PersistentAlarm.c) (revision 97f119050f52c01aa9346c80b706dfdbbda3ac9e) +++ PersistentAlarm.c (.../PersistentAlarm.c) (revision 4b13eff164ec468e415fff197ed8af3b85504df0) @@ -7,8 +7,8 @@ * * @file PersistentAlarm.c * -* @author (last) Quang Nguyen -* @date (last) 17-Aug-2020 +* @author (last) Sean Nash +* @date (last) 01-Oct-2020 * * @author (original) Quang Nguyen * @date (original) 17-Aug-2020 @@ -17,6 +17,7 @@ #include "AlarmMgmt.h" #include "PersistentAlarm.h" +#include "Timers.h" /** * @addtogroup PersistentAlarm @@ -31,11 +32,11 @@ ALARM_ID_T alarm; ///< Alarm id BOOL isClearable; ///< Flag if alarm can be cleared - U32 persistentClearCount; ///< Persistent count limit before clear alarm - U32 persistentTriggerCount; ///< Persistent count limit before trigger alarm + U32 persistentClearPeriod; ///< Persistent count limit before clear alarm + U32 persistentTriggerPeriod; ///< Persistent count limit before trigger alarm - U32 inRangeCounter; ///< Data in range persistent counter - U32 outOfRangeCounter; ///< Data out of range persistent counter + U32 inRangeStartTime; ///< Data in range persistent counter + U32 outOfRangeStartTime; ///< Data out of range persistent counter } PERSISTENT_ALARM_DATA_T; // ********** private data ********** @@ -48,27 +49,26 @@ * @brief * The initPersistentAlarm function initializes the PersistentAlarm module * when the alarm count lower than maximum persistent alarm allowed. - * @details - * Inputs : none - * Outputs : PersistentAlarm module initialized + * @details Inputs: none + * @details Outputs: PersistentAlarm module initialized * @param alarmIndex Persistent alarm index * @param alarm Alarm id * @param isClearable Flag to indicate alarm is clearable or not - * @param persistentClearCount Persistent count limit before clear alarm - * @param persistentTriggerCount Persistent count limit before trigger alarm + * @param persistentClearPeriod Persistent period limit before clear alarm + * @param persistentTriggerPeriod Persistent period limit before trigger alarm * @return none *************************************************************************/ void initPersistentAlarm( PERSISTENT_ALARM_T alarmIndex, ALARM_ID_T alarm, BOOL isClearable, - F32 persistentClearCount, F32 persistentTriggerCount ) + U32 persistentClearPeriod, U32 persistentTriggerPeriod ) { if ( alarmIndex < NUM_OF_PERSISTENT_ALARM ) { - persistentAlarms[ alarmIndex ].alarm = alarm; - persistentAlarms[ alarmIndex ].isClearable = isClearable; - persistentAlarms[ alarmIndex ].persistentClearCount = persistentClearCount; - persistentAlarms[ alarmIndex ].persistentTriggerCount = persistentTriggerCount; - persistentAlarms[ alarmIndex ].inRangeCounter = 0U; - persistentAlarms[ alarmIndex ].outOfRangeCounter = 0U; + persistentAlarms[ alarmIndex ].alarm = alarm; + persistentAlarms[ alarmIndex ].isClearable = isClearable; + persistentAlarms[ alarmIndex ].persistentClearPeriod = persistentClearPeriod; + persistentAlarms[ alarmIndex ].persistentTriggerPeriod = persistentTriggerPeriod; + persistentAlarms[ alarmIndex ].inRangeStartTime = 0U; + persistentAlarms[ alarmIndex ].outOfRangeStartTime = 0U; } else { @@ -85,9 +85,8 @@ * The checkPersistentAlarm function check whether data is out of range or * not. Then the function set or clear alarm once the persistent counter * exceeds the limit. - * @details - * Inputs : none - * Outputs : Checks for out of range data and set/clear alarm + * @details Inputs: none + * @details Outputs: Checks for out of range data and set/clear alarm * @param alarmIndex Persistent alarm index * @param isOutOfRange Flag indicates data out of range * @param data Data to be check for out of range @@ -100,18 +99,24 @@ { if ( isOutOfRange ) { - ++persistentAlarms[ alarmIndex ].outOfRangeCounter; - persistentAlarms[ alarmIndex ].inRangeCounter = 0; - if ( persistentAlarms[ alarmIndex ].outOfRangeCounter > persistentAlarms[ alarmIndex ].persistentTriggerCount ) + persistentAlarms[ alarmIndex ].inRangeStartTime = 0; + if ( persistentAlarms[ alarmIndex ].outOfRangeStartTime == 0 ) { + persistentAlarms[ alarmIndex ].outOfRangeStartTime = getMSTimerCount(); + } + if ( didTimeout( persistentAlarms[ alarmIndex ].outOfRangeStartTime, persistentAlarms[ alarmIndex ].persistentTriggerPeriod ) ) + { SET_ALARM_WITH_2_F32_DATA( persistentAlarms[ alarmIndex ].alarm, data, limit ); } } else { - ++persistentAlarms[ alarmIndex ].inRangeCounter; - persistentAlarms[ alarmIndex ].outOfRangeCounter = 0; - BOOL const isInRangePersistent = persistentAlarms[ alarmIndex ].inRangeCounter > persistentAlarms[ alarmIndex ].persistentClearCount; + persistentAlarms[ alarmIndex ].outOfRangeStartTime = 0; + if ( persistentAlarms[ alarmIndex ].inRangeStartTime == 0 ) + { + persistentAlarms[ alarmIndex ].inRangeStartTime = getMSTimerCount(); + } + BOOL const isInRangePersistent = didTimeout( persistentAlarms[ alarmIndex ].inRangeStartTime, persistentAlarms[ alarmIndex ].persistentClearPeriod ); if ( persistentAlarms[ alarmIndex ].isClearable && isInRangePersistent ) { clearAlarm( persistentAlarms[ alarmIndex ].alarm ); Index: PersistentAlarm.h =================================================================== diff -u -r97f119050f52c01aa9346c80b706dfdbbda3ac9e -r4b13eff164ec468e415fff197ed8af3b85504df0 --- PersistentAlarm.h (.../PersistentAlarm.h) (revision 97f119050f52c01aa9346c80b706dfdbbda3ac9e) +++ PersistentAlarm.h (.../PersistentAlarm.h) (revision 4b13eff164ec468e415fff197ed8af3b85504df0) @@ -8,7 +8,7 @@ * @file PersistentAlarm.h * * @author (last) Quang Nguyen -* @date (last) 17-Aug-2020 +* @date (last) 02-Sep-2020 * * @author (original) Quang Nguyen * @date (original) 17-Aug-2020 @@ -34,25 +34,35 @@ typedef enum PersistentAlarm { #ifdef _HD_ - PERSISTENT_ALARM_ARTERIAL_PRESSURE_LOW, ///< Arterial pressure too low during treatment - PERSISTENT_ALARM_ARTERIAL_PRESSURE_HIGH, ///< Arterial pressure too high during treatment - PERSISTENT_ALARM_VENOUS_PRESSURE_LOW, ///< Venous pressure too low during treatment - PERSISTENT_ALARM_VENOUS_PRESSURE_HIGH, ///< Venous pressure too high during treatment + PERSISTENT_ALARM_BLOOD_FLOW_SIGNAL_STRENGTH, ///< Blood flow signal strength too low + PERSISTENT_ALARM_DIALYSATE_FLOW_SIGNAL_STRENGTH, ///< Dialysate flow signal strength too low + PERSISTENT_ALARM_ARTERIAL_PRESSURE_LOW, ///< Arterial pressure too low during treatment + PERSISTENT_ALARM_ARTERIAL_PRESSURE_HIGH, ///< Arterial pressure too high during treatment + PERSISTENT_ALARM_VENOUS_PRESSURE_LOW, ///< Venous pressure too low during treatment + PERSISTENT_ALARM_VENOUS_PRESSURE_HIGH, ///< Venous pressure too high during treatment #endif #ifdef _DG_ - PERSISTENT_ALARM_INLET_WATER_HIGH_TEMPERATURE, ///< Inlet water high temperature persistent alarm - PERSISTENT_ALARM_INLET_WATER_LOW_TEMPERATURE, ///< Inlet water low temperature persistent alarm - PERSISTENT_ALARM_INLET_WATER_HIGH_CONDUCTIVITY, ///< Inlet water high conductivity persistent alarm - PERSISTENT_ALARM_INLET_WATER_LOW_CONDUCTIVITY, ///< Inlet water low conductivity persistent alarm - PERSISTENT_ALARM_RO_REJECTION_RATIO_OUT_OF_RANGE, ///< RO rejection ratio out of range persistent alarm + PERSISTENT_ALARM_INLET_WATER_HIGH_TEMPERATURE, ///< Inlet water high temperature persistent alarm + PERSISTENT_ALARM_INLET_WATER_LOW_TEMPERATURE, ///< Inlet water low temperature persistent alarm + PERSISTENT_ALARM_INLET_WATER_HIGH_CONDUCTIVITY, ///< Inlet water high conductivity persistent alarm + PERSISTENT_ALARM_INLET_WATER_LOW_CONDUCTIVITY, ///< Inlet water low conductivity persistent alarm + PERSISTENT_ALARM_RO_REJECTION_RATIO_OUT_OF_RANGE, ///< RO rejection ratio out of range persistent alarm + PERSISTENT_ALARM_INLET_WATER_LOW_PRESSURE, ///< Inlet water low pressure persistent alarm + PERSISTENT_ALARM_INLET_WATER_PRESSURE_FAULT, ///< Inlet water pressure fault persistent alarm + PERSISTENT_ALARM_POST_ACID_CONDUCTIVITY_OUT_OF_RANGE, ///< Post acid concentrate conductivity out of range + PERSISTENT_ALARM_POST_BICARB_CONDUCTIVITY_OUT_OF_RANGE, ///< Post bicarbonate concentrate conductivity out of range + PERSISTENT_ALARM_RO_PUMP_FLOW_RATE_OUT_OF_RANGE, ///< RO pump flow rate out of range + PERSISTENT_ALARM_CP1_SPEED_CONTROL_ERROR, ///< Concentrate pump CP1 speed control error + PERSISTENT_ALARM_CP2_SPEED_CONTROL_ERROR, ///< Concentrate pump CP2 speed control error #endif - NUM_OF_PERSISTENT_ALARM ///< Number of persistent alarms + NUM_OF_PERSISTENT_ALARM ///< Number of persistent alarms } PERSISTENT_ALARM_T; // ********** public function prototypes ********** +// Persistent period resolution is in ms void initPersistentAlarm( PERSISTENT_ALARM_T alarmIndex, ALARM_ID_T alarm, BOOL isClearable, - F32 persistentClearCount, F32 persistentTriggerCount ); + U32 persistentClearPeriod, U32 persistentTriggerPeriod ); void checkPersistentAlarm( PERSISTENT_ALARM_T const alarmIndex, BOOL const isOutOfRange, F32 const data, F32 const limit ); /**@}*/