Other Parts Discussed in Thread: CC3220SF
Tool/software: TI C/C++ Compiler
I set the internal RTC of CC3220SF to 1st January 2000, then I try to readback its value:
time_t GetEpoch(void) { _i16 ret; _u8 pConfigOpt = SL_DEVICE_GENERAL_DATE_TIME; _u16 pConfigLen = sizeof(SlDateTime_t); SlDateTime_t dateTime = {0}; ret = sl_DeviceGet(SL_DEVICE_GENERAL, &pConfigOpt, &pConfigLen, (unsigned char *) &dateTime); ASSERT_ON_ERROR(ret); struct tm t; time_t t_of_day; t.tm_year = dateTime.tm_year - 1900; t.tm_mon = dateTime.tm_mon - 1; t.tm_mday = dateTime.tm_day; t.tm_hour = dateTime.tm_hour; t.tm_min = dateTime.tm_min; t.tm_sec = dateTime.tm_sec; t.tm_isdst = -1; t_of_day = mktime(&t); UART_PRINT("SlDateTime_t: %d/%d/%d %d:%d:%d\r\n", dateTime.tm_year, dateTime.tm_mon, dateTime.tm_day, dateTime.tm_hour, dateTime.tm_min, dateTime.tm_sec); UART_PRINT("struct tm: %d/%d/%d %d:%d:%d\r\n", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); UART_PRINT("time_t : %lld\r\n", t_of_day); return t_of_day; }
Here the output:
SlDateTime_t: 2000/1/1 0:0:0 struct tm: 100/0/1 0:0:0 time_t : 2305849197122252192
Please note I'm using 64-bit time functions.
Both SlDateTime and tm structs are correct - why the time_t value is wrong? Is there any mistake in my code?