Index: Common.h =================================================================== diff -u -rc9ead6cda7679735a3d891456d4871f7cf4f37e3 -rc0e7b9287da8b31bcb7d74c937f60ad263eeb710 --- Common.h (.../Common.h) (revision c9ead6cda7679735a3d891456d4871f7cf4f37e3) +++ Common.h (.../Common.h) (revision c0e7b9287da8b31bcb7d74c937f60ad263eeb710) @@ -1,17 +1,17 @@ /************************************************************************** * -* 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. * -* @file Common.h +* @file Common.h * -* @author (last) Sean Nash -* @date (last) 08-Sep-2020 +* @author (last) Dara Navaei +* @date (last) 18-Oct-2021 * -* @author (original) Sean -* @date (original) 04-Feb-2020 +* @author (original) Sean +* @date (original) 04-Feb-2020 * ***************************************************************************/ Index: MessageSupport.c =================================================================== diff -u -rdae0bc97eb180f6c1fd5a57b8e3ec4307d1a89af -rc0e7b9287da8b31bcb7d74c937f60ad263eeb710 --- MessageSupport.c (.../MessageSupport.c) (revision dae0bc97eb180f6c1fd5a57b8e3ec4307d1a89af) +++ MessageSupport.c (.../MessageSupport.c) (revision c0e7b9287da8b31bcb7d74c937f60ad263eeb710) @@ -1,21 +1,20 @@ /************************************************************************** * -* Copyright (c) 2021-2021 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. * -* @file MessageSupport.C +* @file MessageSupport.c * -* @author (last) Dara Navaei -* @date (last) 01-Oct-2021 +* @author (last) Dara Navaei +* @date (last) 10-Sep-2021 * -* @author (original) Dara Navaei -* @date (original) 01-Oct-2021 +* @author (original) Dara Navaei +* @date (original) 10-Sep-2021 * ***************************************************************************/ -#include "MessageSupport.h" #include "SystemCommMessages.h" #include "Utilities.h" Index: MessageSupport.h =================================================================== diff -u -rdae0bc97eb180f6c1fd5a57b8e3ec4307d1a89af -rc0e7b9287da8b31bcb7d74c937f60ad263eeb710 --- MessageSupport.h (.../MessageSupport.h) (revision dae0bc97eb180f6c1fd5a57b8e3ec4307d1a89af) +++ MessageSupport.h (.../MessageSupport.h) (revision c0e7b9287da8b31bcb7d74c937f60ad263eeb710) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2021-2021 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. * -* @file MessageSupport.h +* @file MessageSupport.h * -* @author (last) Dara Navaei -* @date (last) 01-Oct-2021 +* @author (last) Dara Navaei +* @date (last) 10-Sep-2021 * -* @author (original) Dara Navaei -* @date (original) 01-Oct-2021 +* @author (original) Dara Navaei +* @date (original) 10-Sep-2021 * ***************************************************************************/ Index: NVDataMgmt.c =================================================================== diff -u -r1fc3890ea60d20b923ab18934ef0741b72ee70a3 -rc0e7b9287da8b31bcb7d74c937f60ad263eeb710 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 1fc3890ea60d20b923ab18934ef0741b72ee70a3) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision c0e7b9287da8b31bcb7d74c937f60ad263eeb710) @@ -1,17 +1,17 @@ /************************************************************************** * -* 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. * -* @file NVDataMgmt.c +* @file NVDataMgmt.c * -* @author (last) Sean Nash -* @date (last) 24-Sep-2020 +* @author (last) Dara Navaei +* @date (last) 03-Nov-2021 * -* @author (original) Dara Navaei -* @date (original) 12-Feb-2020 +* @author (original) Dara Navaei +* @date (original) 12-Feb-2020 * ***************************************************************************/ @@ -78,6 +78,7 @@ #define DG_CONSUMED_WATER_ADDRESS 0x00000020 // 32 ///< DG water consumption start address in RTC RAM (32). #define SERVICE_RECORD_START_ADDRESS 0x00000030 // 48 ///< Service date record start address in RTC RAM (HD/DG) (48). #define DG_SCHEDULED_RUNS_START_ADDRESS (SERVICE_RECORD_START_ADDRESS + sizeof(DG_SERVICE_GROUP_T)) ///< DG scheduled runs start address in RTC RAM. +#define DG_HEATERS_INFO_START_ADDRESS (DG_SCHEDULED_RUNS_START_ADDRESS + sizeof(DG_HEATERS_INFO_GROUP_T))///< DG heaters info start address in RTC RAM. #define COMMAND_TIME_OUT 500U ///< Timeout for an EEPROM or RTC command in ms. /// EEPROM functions use the buffer length as the size of U32. So before send the length to any of FAPI functions, it should be divided by 4. @@ -134,6 +135,7 @@ NVDATAMGMT_SELF_TEST_STATE_READ_LOG_RECORD, ///< Self test read log record. NVDATAMGMT_SELF_TEST_STATE_READ_TREATMENT_TIME, ///< Self test read treatment time. TODO combine with water consumption NVDATAMGMT_SELF_TEST_STATE_READ_WATER_CONSUMPTION, ///< Self test read water consumption. TODO combine with tx time + NVDATAMGMT_SELF_TEST_STATE_READ_DG_HEATERS_INFO, ///< Self test read DG heaters information. NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC, ///< Self test check CRC. NVDATAMGMT_SELF_TEST_STATE_COMPLETE, ///< Self test complete. NUM_OF_NVDATAMGMT_SELF_TEST_STATES ///< Total number of self-test states. @@ -196,6 +198,7 @@ NVDATAMGMT_SERVICE_RECORD, ///< NVDATAMgmt process service record. #ifdef _DG_ NVDATAMGMT_SCHEDULED_RUNS_RECORD, ///< NVDataMgmt process scheduled runs record. + NVDATAMGMT_HEATERS_INFO_RECORD, ///< NVDataMgmt process heaters info record. #endif NUM_OF_NVDATMGMT_RECORDS_JOBS ///< Number of NVDataMgmt records jobs. } RECORD_JOBS_STATE_T; @@ -326,13 +329,23 @@ U16 crc; ///< CRC for the DG scheduled runs structure. } DG_SCHEDULED_RUNS_GROUP_T; +/// DG usage record structure typedef struct { DG_USAGE_INFO_RECORD_T dgUsageInfo; ///< DG usage info record. U08 padding[ RECORD_PADDING_LENGTH(DG_USAGE_INFO_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - RECORD_BYTE_SIZE(DG_USAGE_INFO_RECORD_T) ]; ///< DG scheduled run group padding. U16 crc; ///< CRC for the DG usage info structure. } DG_USAGE_INFO_GROUP_T; + +/// DG heaters record +typedef struct +{ + DG_HEATERS_RECORD_T dgHeatersInfo; ///< DG heaters info record. + U08 padding[ RECORD_PADDING_LENGTH(DG_HEATERS_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - + RECORD_BYTE_SIZE(DG_HEATERS_RECORD_T) ]; ///< DG heater info group padding. + U16 crc; ///< CRC for the DG heaters info structure. +} DG_HEATERS_INFO_GROUP_T; #endif #ifdef _HD_ @@ -394,12 +407,14 @@ static DG_SERVICE_GROUP_T dgServiceGroup; ///< DG service group structure (including padding and final CRC). static DG_SCHEDULED_RUNS_GROUP_T dgScheduledRunsGroup; ///< DG scheduled run structure (including padding and final CRC). static DG_USAGE_INFO_GROUP_T dgUsageInfoGroup; ///< DG usage info structure (including padding and final CRC). +static DG_HEATERS_INFO_GROUP_T dgHeatersInfoGroup; ///< DG heaters info structure (including padding and final CRC). // Process records specifications const PROCESS_RECORD_SPECS_T RECORDS_SPECS[ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_CALIBRATION_RECORD_T), (U08*)&dgCalibrationRecord, (U08*)&(dgCalibrationRecord.crc)}, // NVDATAMGMT_CALIBRATION_RECORD {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_SYSTEM_GROUP_T), (U08*)&dgSystemGroup, (U08*)&dgSystemGroup.crc}, // NVDATAMGMT_SYSTEM_RECORD {SERVICE_RECORD_START_ADDRESS, sizeof(DG_SERVICE_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgServiceGroup, (U08*)&dgServiceGroup.crc}, // NVDATAMGMT_SERVICE_RECORD - {DG_SCHEDULED_RUNS_START_ADDRESS, sizeof(DG_SCHEDULED_RUNS_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgScheduledRunsGroup, (U08*)&dgScheduledRunsGroup.crc} // NVDATAMGMT_SCHEDULER_RECORD + {DG_SCHEDULED_RUNS_START_ADDRESS, sizeof(DG_SCHEDULED_RUNS_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgScheduledRunsGroup, (U08*)&dgScheduledRunsGroup.crc} , // NVDATAMGMT_SCHEDULER_RECORD + {DG_HEATERS_INFO_START_ADDRESS, sizeof(DG_HEATERS_INFO_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgHeatersInfoGroup, (U08*)&dgHeatersInfoGroup.crc} // NVDATAMGMT_HEATERS_INFO_RECORD }; #endif @@ -463,6 +478,7 @@ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadHDTreatmentTime( void ); #endif #ifdef _DG_ +static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadDGHeatersInfo( void ); static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadDGWaterConsumption( void ); #endif static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadLogRecord( void ); @@ -697,6 +713,10 @@ case NVDATAMGMT_SELF_TEST_STATE_READ_WATER_CONSUMPTION: nvDataMgmtSelfTestState = handleSelfTestReadDGWaterConsumption(); break; + + case NVDATAMGMT_SELF_TEST_STATE_READ_DG_HEATERS_INFO: + nvDataMgmtSelfTestState = handleSelfTestReadDGHeatersInfo(); + break; #endif case NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC: @@ -1691,13 +1711,13 @@ { BOOL status = FALSE; dgUsageInfoGroup.dgUsageInfo.waterConsumption = liters; - dgUsageInfoGroup.crc = crc16 ( (U08*)&dgUsageInfoGroup.dgUsageInfo.waterConsumption, sizeof(U32) ); + dgUsageInfoGroup.crc = crc16 ( (U08*)&dgUsageInfoGroup.dgUsageInfo.waterConsumption, sizeof(U16) ); if ( !isQueueFull() ) { enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, DG_CONSUMED_WATER_ADDRESS, (U08*)&dgUsageInfoGroup, 0, sizeof(DG_USAGE_INFO_RECORD_T) ); - status = TRUE; + status = TRUE; //TODO this is not right use enqueueRecordJob function to schedule a write } return status; @@ -1714,6 +1734,45 @@ { return dgUsageInfoGroup.dgUsageInfo.waterConsumption; } + +/*********************************************************************//** + * @brief + * The getHeatersInfoReocrd returns the DG heaters info. + * @details Inputs: none + * @details Outputs: none + * @return DG heaters information record + ******************************************************************/ +DG_HEATERS_RECORD_T getHeatersInfoReocrd( void ) +{ + return dgHeatersInfoGroup.dgHeatersInfo; +} + +/*********************************************************************//** + * @brief + * The setHeatersInfoRecord sets a queue job to write the DG heaters info + * back to the RTC RAM. + * @details Inputs: none + * @details Outputs: dgHeatersInfoGroup + * @param addressPrt which is an address to the structure that is holding the + * heaters information. + * @return TRUE if queue is not full otherwise, FALSE + *************************************************************************/ +BOOL setHeatersInfoRecord( U08 *addressPtr ) +{ + BOOL status = FALSE; + memcpy( &dgHeatersInfoGroup.dgHeatersInfo, addressPtr, sizeof( DG_HEATERS_RECORD_T ) ); + // The crc is the DG heaters info and padding - the CRC U16 variable + dgHeatersInfoGroup.crc = crc16 ( (U08*)&dgHeatersInfoGroup.dgHeatersInfo, sizeof( dgHeatersInfoGroup ) - sizeof( U16 ) ); + + if ( FALSE == isQueueFull() ) + { + // Queue is not full, schedule a write to RTC RAM the write the heaters information record + enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, NVDATAMGMT_HEATERS_INFO_RECORD ); + status = TRUE; + } + + return status; +} #endif /*********************************************************************//** * @brief @@ -1855,15 +1914,15 @@ NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_SCHEDULED_RUNS_RECORD; BOOL timeoutStatus = didCommandTimeout( ALARM_ID_RTC_RAM_OPS_ERROR, (U08*)&state ); - if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE || timeoutStatus == TRUE ) + if ( ( RTC_RAM_STATUS_IDLE == getRTCRAMStatus() ) || ( TRUE == timeoutStatus ) ) { PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS[ NVDATAMGMT_SCHEDULED_RUNS_RECORD ]; U08* bufferAddress = specs.structAddressPtr; U32 maxBufferLength = specs.maxReadBufferSize; getDataFromRAM( bufferAddress, maxBufferLength ); - state = NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC; + state = NVDATAMGMT_SELF_TEST_STATE_READ_DG_HEATERS_INFO; } return state; @@ -1902,6 +1961,49 @@ #ifdef _DG_ /*********************************************************************//** * @brief + * The handleSelfTestReadDGHeatersInfo reads the DG heaters information + * from RTC RAM. + * @details Inputs: none + * @details Outputs: dgHeatersInfoGroup + * @return next state + *************************************************************************/ +static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadDGHeatersInfo( void ) +{ + NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_DG_HEATERS_INFO; + BOOL timeoutStatus = didCommandTimeout( ALARM_ID_RTC_RAM_OPS_ERROR, (U08*)&state ); + + if ( ( RTC_RAM_STATUS_IDLE == getRTCRAMStatus() ) || ( TRUE == timeoutStatus ) ) + { + PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS[ NVDATAMGMT_HEATERS_INFO_RECORD ]; + U08* bufferAddress = specs.structAddressPtr; + U32 maxBufferLength = specs.maxReadBufferSize; + + getDataFromRAM( bufferAddress, maxBufferLength ); + + // Calculate the CRC of the record + U16 calcCRC = crc16 ( specs.structAddressPtr, specs.sizeofJob - sizeof(U16) ); + U16 recordCRC = *(U16*)specs.structCRCPtr; + + // If the CRCs are not equal, set the average fill flow to 0.0 + // Otherwise, keep the data so it can be used + if ( calcCRC != recordCRC ) + { + dgHeatersInfoGroup.dgHeatersInfo.averageFillFlow = 0.0; + dgHeatersInfoGroup.crc = recordCRC; + } + else + { + memcpy( &dgHeatersInfoGroup, bufferAddress, sizeof( DG_HEATERS_INFO_GROUP_T ) ); + } + + state = NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC; + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleSelfTestReadDGWaterConsumption reads the DG water consumption * from RTC RAM. * @details Inputs: currentTime, waterConsumptionRecord @@ -2961,35 +3063,25 @@ *************************************************************************/ static BOOL areRecordsValid( void ) { - U32 i; - U16 calcCRC; - U16 recordCRC; - PROCESS_RECORD_SPECS_T spec; + ALARM_ID_T alarm; + BOOL status = TRUE; - BOOL isCheckRequired = TRUE; + PROCESS_RECORD_SPECS_T spec = RECORDS_SPECS [ NVDATAMGMT_CALIBRATION_RECORD ]; + U16 calcCRC = crc16 ( spec.structAddressPtr, spec.sizeofJob - sizeof(U16) ); + U16 recordCRC = *(U16*)spec.structCRCPtr; - for ( i = 0; i < NUM_OF_NVDATMGMT_RECORDS_JOBS; i++ ) + // If the CRCs do not match, break out of loop since POST will be failed + // regardless of the rest of the results + if ( calcCRC != recordCRC ) { #ifdef _DG_ - // Scheduled runs are not part this phase but it is part of the enums - // so they are ignored during checking - isCheckRequired = ( NVDATAMGMT_SCHEDULED_RUNS_RECORD == i ? FALSE : TRUE ); + alarm = ALARM_ID_DG_NVDATAMGMT_CAL_GROUP_RECORD_CRC_INVALID; #endif - if ( TRUE == isCheckRequired ) - { - spec = RECORDS_SPECS [ i ]; - calcCRC = crc16 ( spec.structAddressPtr, spec.sizeofJob - sizeof(U16) ); - recordCRC = *(U16*)spec.structCRCPtr; - - // If the CRCs do not match, break out of loop since POST will be failed - // regardless of the rest of the results - if ( calcCRC != recordCRC ) - { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_NVDATAMGMT_GROUP_RECORD_CRC_INVALID, i ); - status = FALSE; - } - } - +#ifdef _HD_ + alarm = ALARM_ID_HD_NVDATAMGMT_CAL_GROUP_RECORD_CRC_INVALID; +#endif + activateAlarmNoData( alarm ); + status = FALSE; } return status; Index: NVDataMgmtDGRecords.h =================================================================== diff -u -rd7bd26c00441b80ef68b716c80edd5b7f5adf917 -rc0e7b9287da8b31bcb7d74c937f60ad263eeb710 --- NVDataMgmtDGRecords.h (.../NVDataMgmtDGRecords.h) (revision d7bd26c00441b80ef68b716c80edd5b7f5adf917) +++ NVDataMgmtDGRecords.h (.../NVDataMgmtDGRecords.h) (revision c0e7b9287da8b31bcb7d74c937f60ad263eeb710) @@ -1,3 +1,19 @@ +/************************************************************************** +* +* 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. +* +* @file NVDataMgmtDGRecords.h +* +* @author (last) Dara Navaei +* @date (last) 03-Nov-2021 +* +* @author (original) Dara Navaei +* @date (original) 12-Feb-2021 +* +***************************************************************************/ #ifndef FWCOMMON_NVDATAMGMTDGRECORDS_H_ #define FWCOMMON_NVDATAMGMTDGRECORDS_H_ @@ -376,6 +392,12 @@ U32 waterConsumption; ///< Water consumption. U16 crc; ///< CRC for the DG usage info structure. } DG_USAGE_INFO_RECORD_T; + +/// DG heaters information structure +typedef struct +{ + F32 averageFillFlow; ///< Average fill flow rate. +} DG_HEATERS_RECORD_T; #pragma pack(pop) /**@}*/ Index: RTC.c =================================================================== diff -u -r7d81e8ddfd35cd917c7baaf031ca3ad3e1c6f466 -rc0e7b9287da8b31bcb7d74c937f60ad263eeb710 --- RTC.c (.../RTC.c) (revision 7d81e8ddfd35cd917c7baaf031ca3ad3e1c6f466) +++ RTC.c (.../RTC.c) (revision c0e7b9287da8b31bcb7d74c937f60ad263eeb710) @@ -1,22 +1,23 @@ /************************************************************************** * -* 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. * -* @file RTC.c +* @file RTC.c * -* @author (last) Sean Nash -* @date (last) 01-Oct-2020 +* @author (last) Dara Navaei +* @date (last) 09-Nov-2021 * -* @author (original) Dara Navaei -* @date (original) 11-Jan-2020 +* @author (original) Dara Navaei +* @date (original) 11-Jan-2020 * ***************************************************************************/ #include "mibspi.h" #include "FPGA.h" +#include "MessageSupport.h" #include "OperationModes.h" #include "RTC.h" #include "SystemCommMessages.h" @@ -44,6 +45,8 @@ #define RTC_REG_3_BF_MASK 0x0008 ///< Battery status interrupt flag (0x0008) #define RTC_REG_3_BLF_MASK 0x0004 ///< Battery status low flag (0x0004) +#define RTC_STOP_CLK_COMMAND 0x0020 ///< RTC stop clock command. + // Indices used to check values read from RTC #define RTC_REG_1_INDEX 1U ///< RTC control register 1 index #define RTC_REG_2_INDEX 2U ///< RTC control register 2 index @@ -215,7 +218,7 @@ static BOOL isRTCFunctional( void ); static U08 convertBCD2Decimal( U08 bcd ); static U08 convertDecimal2BCD( U08 decimal ); -static U32 convertDateTime2Epoch( RTC_TIMESTAMP_T dateTime ); +static U32 convertDateTime2Epoch( RTC_TIMESTAMP_T dateTime ); static BOOL convertEpoch2DateTime( U32 epoch ); static void updateReadTimestampStruct( void ); static BOOL setMibSPIBufferLength( U16 length ); @@ -237,7 +240,7 @@ /*********************************************************************//** * @brief * The initRTC initializes the RTC module. - * @details Inputs: RTCSelfTestState, RTCSelfTestState + * @details Inputs: none * @details Outputs: RTCSelfTestState, RTCSelfTestState * @return none *************************************************************************/ @@ -291,8 +294,8 @@ } else { - hasWriteToRTCRequested = TRUE; - isTimestampBufferReady = FALSE; + hasWriteToRTCRequested = TRUE; + isTimestampBufferReady = FALSE; RTCNewTimestampStruct.seconds = secs; RTCNewTimestampStruct.minutes = mins; RTCNewTimestampStruct.hours = hours; @@ -1041,19 +1044,19 @@ { RTC_EXEC_STATE_T result = RTC_EXEC_STATE_IDLE; - if ( hasWriteToRTCRequested ) + if ( TRUE == hasWriteToRTCRequested ) { result = RTC_EXEC_STATE_WRITE; } - else if ( hasWriteToRAMRequested ) + else if ( TRUE == hasWriteToRAMRequested ) { result = RTC_EXEC_STATE_PREP_RAM; } - else if ( hasReadFromRAMRequested ) + else if ( TRUE == hasReadFromRAMRequested ) { result = RTC_EXEC_STATE_PREP_RAM; } - else if ( timeCounter == TIMER_COUNTER_TO_REQUEST_READ ) + else if ( TIMER_COUNTER_TO_REQUEST_READ == timeCounter ) { prepBufferForReadCommand( RTC_GENERAL_BUFFER_LENGTH ); result = RTC_EXEC_STATE_READ; @@ -1077,7 +1080,7 @@ *************************************************************************/ static RTC_EXEC_STATE_T handleExecWriteState( void ) { - if ( !isTimestampBufferReady ) + if ( FALSE == isTimestampBufferReady ) { txBuffer[ 0 ] = RTC_WRITE_TO_REG0; txBuffer[ 1 ] = 0x0000; @@ -1227,14 +1230,20 @@ { if ( isRTCFunctional() ) { + RTC_DATA_T data; + updateReadTimestampStruct(); lastEpochTime = convertDateTime2Epoch( RTCTimestampStruct ); timeCounter = 1; + data.epochTime = lastEpochTime; + #ifdef _DG_ - broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&lastEpochTime, sizeof( U32 ) ); -#else - broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&lastEpochTime, sizeof( U32 ) ); + broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( RTC_DATA_T ) ); #endif + +#ifdef _HD_ + broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( RTC_DATA_T ) ); +#endif } result = RTC_EXEC_STATE_IDLE; @@ -1282,9 +1291,9 @@ RTC_SELF_TEST_STATE_T result = RTC_SELF_TEST_STATE_CHECK_CTRL_REGS; BOOL isStatusOk = serviceRTC( txBuffer, rxBuffer, RTC_GENERAL_BUFFER_LENGTH ); - if ( RTCServiceState == RTC_SERVICE_COMPLETE && isStatusOk ) + if ( ( RTC_SERVICE_COMPLETE == RTCServiceState ) && ( TRUE == isStatusOk ) ) { - if ( isRTCFunctional() ) + if ( TRUE == isRTCFunctional() ) { U32 RTCCurrentSecond = rxBuffer[ RTC_SECONDS_INDEX ]; RTCPreviousSecond = RTCCurrentSecond; @@ -1320,9 +1329,9 @@ RTC_SELF_TEST_STATE_T result = RTC_SELF_TEST_STATE_WAIT_FOR_FIRST_SECOND; BOOL isStatusOk = serviceRTC( txBuffer, rxBuffer, RTC_GENERAL_BUFFER_LENGTH ); - if ( ( RTCServiceState == RTC_SERVICE_COMPLETE ) && ( TRUE == isStatusOk ) ) + if ( ( RTC_SERVICE_COMPLETE == RTCServiceState ) && ( TRUE == isStatusOk ) ) { - if ( isRTCFunctional() ) + if ( TRUE == isRTCFunctional() ) { U32 RTCCurrentSecond = rxBuffer[ RTC_SECONDS_INDEX ]; @@ -1389,4 +1398,50 @@ return result; } + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetStopRTC sets the 5th bit of the first control register and + * sets its bit to 1 to stop the RTC clock. + * @details Inputs: none + * @details Outputs: hasWriteToRTCRequested, isTimestampBufferReady, txBuffer + * @return TRUE if the set was successful otherwise, FALSE + *************************************************************************/ +BOOL testSetStopRTC( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + // Set write request so the exec state machine will set it + hasWriteToRTCRequested = TRUE; + isTimestampBufferReady = TRUE; + + // Set the latest time stamp to be written to the RTC since the stop command must be written + // to RTC anyways + txBuffer[ 0 ] = RTC_WRITE_TO_REG0; + // Read the RX buffer and get the first register. Mask off the MSB and or it with 0x0020 to set the + // start stop RTC bit to a 1 to stop the RTC clock. + txBuffer[ 1 ] = ( rxBuffer[ RTC_REG_1_INDEX ] & MASK_OFF_MSB ) | RTC_STOP_CLK_COMMAND; + txBuffer[ 2 ] = 0x0000; + txBuffer[ 3 ] = 0x0000; + txBuffer[ 4 ] = convertDecimal2BCD( RTCNewTimestampStruct.seconds ); + txBuffer[ 5 ] = convertDecimal2BCD( RTCNewTimestampStruct.minutes ); + txBuffer[ 6 ] = convertDecimal2BCD( RTCNewTimestampStruct.hours ); + txBuffer[ 7 ] = convertDecimal2BCD( RTCNewTimestampStruct.days ); + txBuffer[ 8 ] = convertDecimal2BCD( RTCNewTimestampStruct.weekdays ); // Weekdays will not be used + txBuffer[ 9 ] = convertDecimal2BCD( RTCNewTimestampStruct.months ); + txBuffer[ 10 ] = convertDecimal2BCD( ( RTCNewTimestampStruct.years - YEAR_2000 ) ); + + result = TRUE; + } + + return result; +} + /**@}*/