MSP430F6736
My application needs to create a unix time stamp from available RTC data. This code yields wild answers (see values in comments).
I should think a long long would be more than sufficient to hold the result data. Perhaps this is simply not supported?
long long UnixTimeStamp(void)
{
struct tm t;
//time_t t_of_day;
long long t_of_day;
BCD2BIN = RTCYEAR;
unsigned long nYear=BCD2BIN;
BCD2BIN = RTCDAY;
unsigned char nDay=BCD2BIN;
BCD2BIN = RTCMON;
unsigned char nMonth=BCD2BIN;
BCD2BIN = RTCHOUR;
unsigned char nHour=BCD2BIN;
BCD2BIN = RTCMIN;
unsigned char nMin=BCD2BIN;
BCD2BIN = RTCSEC;
unsigned char nSec=BCD2BIN;
t.tm_year = nYear-1900;
t.tm_mon = nMonth; // Month, 0 - jan
t.tm_mday = nDay; // Day of the month
t.tm_hour = nHour;
t.tm_min = nMin;
t.tm_sec = nSec;
t.tm_isdst = -1; // Is DST on? 1 = yes, 0 = no, -1 = unknown
t_of_day = mktime(&t); // timestamp from RTC data. Result=3565814343
t.tm_year = 2011-1900;
t.tm_mon = 7; // Month, 0 - jan
t.tm_mday = 8; // Day of the month
t.tm_hour = 16;
t.tm_min = 11;
t.tm_sec = 42;
t.tm_isdst = -1;
t_of_day = mktime(&t); // timestamp from test data. Result=3521808702
return( t_of_day);
}