energia / cc13x2-core

Energia core for the CC13x2 family
1 stars 0 forks source link

Issue with time.h conversion functions #8

Closed rei-vilo closed 4 years ago

rei-vilo commented 4 years ago

High-level functions from ti/sysbios/hal/Seconds.h work fine as Seconds_set() and Seconds_get().

However, functions from standard time.h library throw errors and non-consistent results, especially when converting between epoch uint32_t and structure tm, as mktime(), asctime(), ctime() et al.

rei-vilo commented 4 years ago

The same sketch gives the following results with the RTC_Library.

=== LPSTK_CC1352_RTC.ino ENERGIA_CC1352R1_LAUNCHXL

--- Saturday 16 November 2019 20:40:21 Epoch= 1573936821

--- setTime(Epoch) getTime= 1573936821

--- ctime(Epoch)= Tue Jul 12 04:51:01 -2034068

--- tm=gmtime_r(Epoch) asctime(Epoch)= Tue Jul 12 04:51:01 -2034068 asctime(tm)= Thu Nov 23 13:23:01 3380

strftime(Epoch)= Tue Jul 12 04:51:01 -2034068 strftime(tm)= Thu Nov 23 13:23:01 3380

=== LPSTK_CC1352_RTC.ino ENERGIA_CC1350_LAUNCHXL

--- Saturday 16 November 2019 20:40:21 Epoch= 1573936821

--- setTime(Epoch) getTime= 1573936821

--- ctime(Epoch)= Sat Nov 16 20:40:21 2019

--- tm=gmtime_r(Epoch) asctime(Epoch)= Sat Nov 16 20:40:21 2019 asctime(tm)= Sat Nov 16 20:40:21 2019

strftime(Epoch)= Sat Nov 16 20:40:21 2019 strftime(tm)= Sat Nov 16 20:40:21 2019

// Core library for code-sense - IDE-based
// !!! Help: http://bit.ly/2AdU7cu
#if defined(ENERGIA) // LaunchPad specific
#include "Energia.h"
#else // error
#error Platform not defined
#endif // end IDE

// Include application, user and local libraries
#include "RTC_Library.h"

// Define variables and constants
DateTime myRTC;
time_t myEpochRTC;
tm myTimeRTC;

void setup()
{
    Serial.begin(115200);
    delay(500);
    Serial.println();
    Serial.println("=== "__FILE__);

#if defined(ENERGIA_CC1352R1_LAUNCHXL)
    Serial.println("ENERGIA_CC1352R1_LAUNCHXL");

#elif defined(ENERGIA_CC1350_LAUNCHXL)
    Serial.println("ENERGIA_CC1350_LAUNCHXL");

#else
    Serial.println("! Other board");
#endif

    myRTC.begin();
    myEpochRTC = (uint32_t)1573936821;

    Serial.println();
    Serial.println("--- Saturday 16 November 2019 20:40:21");
    Serial.print("Epoch= ");
    Serial.println(myEpochRTC);

    Serial.println();
    Serial.println("--- setTime(Epoch)");
    myRTC.setTime(myEpochRTC);
    Serial.print("getTime= ");
    myEpochRTC = myRTC.getTime();
    Serial.println(myEpochRTC);

    Serial.println();
    Serial.print("--- ctime(Epoch)= ");
    Serial.println(convertDateTime2String(myEpochRTC));

    Serial.println();
    Serial.println("--- tm=gmtime_r(Epoch)");
    convertEpoch2Structure(myEpochRTC, myTimeRTC);
    Serial.print("asctime(Epoch)= ");
    Serial.println(convertDateTime2String(myEpochRTC));
    Serial.print("asctime(tm)= ");
    Serial.println(convertDateTime2String(myTimeRTC));

    Serial.println();
    Serial.print("strftime(Epoch)= ");
    Serial.println(convertDateTime2String(myEpochRTC));
    Serial.print("strftime(tm)= ");
    Serial.println(convertDateTime2String(myTimeRTC));
}

void loop()
{
}
rei-vilo commented 4 years ago

@robertinant

I've used the same release of the compiler, arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437], against both boards.

Results are:

So the compiler is not the culprit.

rei-vilo commented 4 years ago

@robertinant

However, using the newer release of the compiler, arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027] against the CC1352 displays the correct results.

=== LPSTK_CC1352_RTC.ino
ENERGIA_CC1352R1_LAUNCHXL

--- Saturday 16 November 2019 20:40:21
Epoch= 1573936821

--- setTime(Epoch)
getTime= 1573936821

--- ctime(Epoch)= Sat Nov 16 20:40:21 2019

--- tm=gmtime_r(Epoch)
ctime(Epoch)= Sat Nov 16 20:40:21 2019
asctime(tm)= Sat Nov 16 20:40:21 2019

strftime(Epoch)= Sat Nov 16 20:40:21 2019
strftime(tm)= Sat Nov 16 20:40:21 2019