Index: RTC.c =================================================================== diff -u -rcfa1142455dbcebceda091ae61e5d1f5e889fa6e -r0e642b49f26ac199454ce387c53e3804b5ba47d6 --- RTC.c (.../RTC.c) (revision cfa1142455dbcebceda091ae61e5d1f5e889fa6e) +++ RTC.c (.../RTC.c) (revision 0e642b49f26ac199454ce387c53e3804b5ba47d6) @@ -17,6 +17,7 @@ #include "mibspi.h" #include "FPGA.h" +#include "MessageSupport.h" #include "OperationModes.h" #include "RTC.h" #include "SystemCommMessages.h" @@ -48,6 +49,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 @@ -230,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 ); @@ -256,7 +259,7 @@ /*********************************************************************//** * @brief * The initRTC initializes the RTC module. - * @details Inputs: RTCSelfTestState, RTCSelfTestState + * @details Inputs: none * @details Outputs: RTCSelfTestState, RTCSelfTestState * @return none *************************************************************************/ @@ -310,8 +313,8 @@ } else { - hasWriteToRTCRequested = TRUE; - isTimestampBufferReady = FALSE; + hasWriteToRTCRequested = TRUE; + isTimestampBufferReady = FALSE; RTCNewTimestampStruct.seconds = secs; RTCNewTimestampStruct.minutes = mins; RTCNewTimestampStruct.hours = hours; @@ -1132,19 +1135,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; @@ -1168,7 +1171,7 @@ *************************************************************************/ static RTC_EXEC_STATE_T handleExecWriteState( void ) { - if ( !isTimestampBufferReady ) + if ( FALSE == isTimestampBufferReady ) { txBuffer[ 0 ] = RTC_WRITE_TO_REG0; txBuffer[ 1 ] = 0x0000; @@ -1318,14 +1321,24 @@ { 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; + +#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; @@ -1373,9 +1386,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; @@ -1411,9 +1424,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 ]; @@ -1480,4 +1493,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; +} + /**@}*/