Index: RTC.c =================================================================== diff -u -r984999b778476facdec04244b998f362a54f4c43 -ra89fd55052e2e467f9ae2fdc828e84272c142022 --- RTC.c (.../RTC.c) (revision 984999b778476facdec04244b998f362a54f4c43) +++ RTC.c (.../RTC.c) (revision a89fd55052e2e467f9ae2fdc828e84272c142022) @@ -8,7 +8,7 @@ * @file RTC.c * * @author (last) Dara Navaei -* @date (last) 31-Jul-2021 +* @date (last) 09-Nov-2021 * * @author (original) Dara Navaei * @date (original) 11-Jan-2020 @@ -17,6 +17,7 @@ #include "mibspi.h" #include "FPGA.h" +#include "MessageSupport.h" #include "OperationModes.h" #include "RTC.h" #include "SystemCommMessages.h" @@ -44,7 +45,7 @@ #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_START_STOP_CLK_BIT_INDEX 5 ///< RTC start/stop bit index number +#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 @@ -217,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 ); @@ -293,8 +294,8 @@ } else { - hasWriteToRTCRequested = TRUE; - isTimestampBufferReady = FALSE; + hasWriteToRTCRequested = TRUE; + isTimestampBufferReady = FALSE; RTCNewTimestampStruct.seconds = secs; RTCNewTimestampStruct.minutes = mins; RTCNewTimestampStruct.hours = hours; @@ -1229,6 +1230,8 @@ { if ( isRTCFunctional() ) { + RTC_DATA_T data; + updateReadTimestampStruct(); lastEpochTime = convertDateTime2Epoch( RTCTimestampStruct ); timeCounter = 1; @@ -1237,6 +1240,16 @@ #else broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&lastEpochTime, sizeof( U32 ) ); #endif + timeCounter = 1; + data.epochTime = lastEpochTime; + +#ifdef _DG_ + 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; @@ -1411,18 +1424,16 @@ if ( TRUE == isTestingActivated() ) { - // Get the first register - U16 stopClockRegister = rxBuffer[ RTC_REG_1_INDEX ] & MASK_OFF_MSB; - // Set the 5th bit which is the clock run to 1 to be stopped - stopClockRegister = ( 1 << RTC_START_STOP_CLK_BIT_INDEX ) | 1; // 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; - txBuffer[ 1 ] = stopClockRegister; + // 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 );