Index: RTC.c =================================================================== diff -u -rf6f638e2d46b6b4581ac599e38fae339ea478750 -r383eddc9d7e0487233d3a774f7d425a71c19e29a --- RTC.c (.../RTC.c) (revision f6f638e2d46b6b4581ac599e38fae339ea478750) +++ RTC.c (.../RTC.c) (revision 383eddc9d7e0487233d3a774f7d425a71c19e29a) @@ -17,6 +17,7 @@ #include "mibspi.h" #include "FPGA.h" +#include "MessageSupport.h" #include "OperationModes.h" #include "RTC.h" #include "SystemCommMessages.h" @@ -48,7 +49,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 @@ -232,7 +233,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 ); #ifdef USE_LIBRARY_TIME_FUNCTIONS static U32 convertTime2Epoch( void ); @@ -312,8 +313,8 @@ } else { - hasWriteToRTCRequested = TRUE; - isTimestampBufferReady = FALSE; + hasWriteToRTCRequested = TRUE; + isTimestampBufferReady = FALSE; RTCNewTimestampStruct.seconds = secs; RTCNewTimestampStruct.minutes = mins; RTCNewTimestampStruct.hours = hours; @@ -1320,14 +1321,18 @@ { if ( isRTCFunctional() ) { + RTC_DATA_T data; + updateReadTimestampStruct(); #ifndef USE_LIBRARY_TIME_FUNCTIONS lastEpochTime = convertDateTime2Epoch( RTCTimestampStruct ); #else lastEpochTime = convertTime2Epoch(); #endif timeCounter = 1; - broadcastRTCEpoch( lastEpochTime ); + data.epochTime = lastEpochTime; + + broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( RTC_DATA_T ) ); } result = RTC_EXEC_STATE_IDLE; @@ -1502,18 +1507,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 );