Index: RTC.c =================================================================== diff -u -rcfa1142455dbcebceda091ae61e5d1f5e889fa6e -rf6f638e2d46b6b4581ac599e38fae339ea478750 --- RTC.c (.../RTC.c) (revision cfa1142455dbcebceda091ae61e5d1f5e889fa6e) +++ RTC.c (.../RTC.c) (revision f6f638e2d46b6b4581ac599e38fae339ea478750) @@ -48,6 +48,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_START_STOP_CLK_BIT_INDEX 5 ///< RTC start/stop bit index number + // 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 @@ -256,7 +258,7 @@ /*********************************************************************//** * @brief * The initRTC initializes the RTC module. - * @details Inputs: RTCSelfTestState, RTCSelfTestState + * @details Inputs: none * @details Outputs: RTCSelfTestState, RTCSelfTestState * @return none *************************************************************************/ @@ -1132,19 +1134,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 +1170,7 @@ *************************************************************************/ static RTC_EXEC_STATE_T handleExecWriteState( void ) { - if ( !isTimestampBufferReady ) + if ( FALSE == isTimestampBufferReady ) { txBuffer[ 0 ] = RTC_WRITE_TO_REG0; txBuffer[ 1 ] = 0x0000; @@ -1373,9 +1375,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 +1413,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 +1482,52 @@ 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() ) + { + // 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; + 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; +} + /**@}*/