Index: RTC.c =================================================================== diff -u -rcfa1142455dbcebceda091ae61e5d1f5e889fa6e -r343d278eb0278c79e00dee6151fb9ef21d2fda9c --- RTC.c (.../RTC.c) (revision cfa1142455dbcebceda091ae61e5d1f5e889fa6e) +++ RTC.c (.../RTC.c) (revision 343d278eb0278c79e00dee6151fb9ef21d2fda9c) @@ -23,10 +23,6 @@ #include "Timers.h" #include "Utilities.h" -#ifdef USE_LIBRARY_TIME_FUNCTIONS -#include // For epoch conversion functions mktime and gmtime -#endif - /** * @addtogroup RTC * @{ @@ -118,19 +114,8 @@ #define MAX_ALLOWED_RTC_RAM_ADDRESS 512U ///< Max allowed RTC RAM legal address (512) #define TEN 10U ///< Ten #define YEAR_2000 2000U ///< Year 2000 -#ifndef USE_LIBRARY_TIME_FUNCTIONS - #define EPOCH_BASE_YEAR 1970U ///< Reference year to calculate epoch (1970) -#else - #define EPOCH_BASE_YEAR 1900U ///< Reference year to calculate epoch (1900) - #define YEAR_1900_TO_1970_SECONDS_DIFF 2208988800U ///< Difference in seconds from 1/1/1900 to 1/1/1970 (2208988800) - /// Six hour offset is needed because TI library works in CST. - #define OFFSET_6_HRS (6 * MIN_PER_HOUR * SEC_PER_MIN) +#define EPOCH_BASE_YEAR 1970U ///< Reference year to calculate epoch (1970) - #ifdef _VECTORCAST_ - #define LOCAL_TO_GTM_TIME_CONVERSION 8U ///< Local time to GTM conversion for VectorCAST - #endif -#endif - #define SECS_IN_HOUR 3600 ///< Number of seconds in an hour. #define MONTHS_IN_YEAR 12 ///< Number of months in a year. #define LEAP_YEAR_MONTH ( 2 - 1 ) ///< Leap year month is February. Subtract 1 month for zero-based months. @@ -232,10 +217,6 @@ static U08 convertDecimal2BCD( U08 decimal ); static U32 convertDateTime2Epoch( RTC_TIMESTAMP_T dateTime ); static BOOL convertEpoch2DateTime( U32 epoch ); -#ifdef USE_LIBRARY_TIME_FUNCTIONS -static U32 convertTime2Epoch( void ); -static void convertEpoch2Time( U32 epoch ); -#endif static void updateReadTimestampStruct( void ); static BOOL setMibSPIBufferLength( U16 length ); static void prepBufferForReadCommand( U08 length ); // Puts the read command @@ -336,11 +317,7 @@ { BOOL result; -#ifndef USE_LIBRARY_TIME_FUNCTIONS result = convertEpoch2DateTime( epoch ); -#else - convertEpoch2Time( epoch ); -#endif result = setRTCTimestamp( RTCNewTimestampStruct.seconds, RTCNewTimestampStruct.minutes, RTCNewTimestampStruct.hours, @@ -918,76 +895,8 @@ return result; } -#ifdef USE_LIBRARY_TIME_FUNCTIONS /*********************************************************************//** * @brief - * The convertTime2Epoch converts the time into epoch (seconds from Jan 1 1970). - * @details Inputs: RTCTimestampStruct - * @details Outputs: none - * @return time in epoch as a U32 - *************************************************************************/ -static U32 convertTime2Epoch( void ) -{ - struct tm t; - time_t epochTime; - t.tm_sec = RTCTimestampStruct.seconds; - t.tm_min = RTCTimestampStruct.minutes; - t.tm_hour = RTCTimestampStruct.hours; - t.tm_mday = RTCTimestampStruct.days; - // In epoch conversion, the months are 0-11 - // so the months is decremented - t.tm_mon = RTCTimestampStruct.months - 1; - t.tm_year = RTCTimestampStruct.years + YEAR_2000 - EPOCH_BASE_YEAR; - // Disabled daylight saving - // If daylight saving is not disabled, MinGW in VectorCAST - // may or may not calculate the value right - t.tm_isdst= 0; - -#ifdef _VECTORCAST_ - // MinGW in VectorCAST assumes the time is local while - // the time is in GMT so 8 hours is subtracted from the hour - // to simulate GMT for VectorCAST - t.tm_hour = t.tm_hour - LOCAL_TO_GTM_TIME_CONVERSION; - epochTime = mktime(&t); -#else - epochTime = mktime(&t); - epochTime = epochTime - YEAR_1900_TO_1970_SECONDS_DIFF; -#endif - - return (U32)epochTime; -} -#endif - -#ifdef USE_LIBRARY_TIME_FUNCTIONS -/*********************************************************************//** - * @brief - * The convertEpoch2Time converts a given epoch date/time to a date/time - * structure that can be used to set the clock. - * @details Inputs: none - * @details Outputs: RTCNewTimestampStruct - * @param epoch epoch time stamp (seconds since 1/1/1970) - * @return none - *************************************************************************/ -static void convertEpoch2Time( U32 epoch ) -{ - struct tm *ptm; - - // Convert epoch to date/time structure - epoch += YEAR_1900_TO_1970_SECONDS_DIFF; - epoch -= OFFSET_6_HRS; // For some reason, TI works in CST time zone instead of GMT - ptm = gmtime( &epoch ); - // Copy date/time stamp to our structure - RTCNewTimestampStruct.years = ptm->tm_year + EPOCH_BASE_YEAR; // epoch is seconds from 1/1/1900. - RTCNewTimestampStruct.months = ptm->tm_mon + 1; // months from gmtime() are 0..11 - convert to 1..12. - RTCNewTimestampStruct.days = ptm->tm_mday; - RTCNewTimestampStruct.hours = ptm->tm_hour; - RTCNewTimestampStruct.minutes = ptm->tm_min; - RTCNewTimestampStruct.seconds = ptm->tm_sec; -} -#endif - -/*********************************************************************//** - * @brief * The updateReadTimestampStruct function updates the time structure * after every read. * @details Inputs: RTCTimestampStruct @@ -1319,13 +1228,13 @@ if ( isRTCFunctional() ) { updateReadTimestampStruct(); -#ifndef USE_LIBRARY_TIME_FUNCTIONS lastEpochTime = convertDateTime2Epoch( RTCTimestampStruct ); + timeCounter = 1; +#ifdef _DG_ + broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&lastEpochTime, sizeof( U32 ) ); #else - lastEpochTime = convertTime2Epoch(); + broadcastData( MSG_ID_RTC_EPOCH, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&lastEpochTime, sizeof( U32 ) ); #endif - timeCounter = 1; - broadcastRTCEpoch( lastEpochTime ); } result = RTC_EXEC_STATE_IDLE;