This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CC2642R: The mktime() function and __TI_TIME_USES_64 build

Part Number: CC2642R

Tool/software: Code Composer Studio

Hi Sir,

 We are developping product with CC2652 under SDK "simplelink_cc13x2_26x2_sdk_4_10_00_78" .  The IDE is CCS V10.   We need time translate funtions like mktime to get number of seconds since an "epoch".

 However, according to https://processors.wiki.ti.com/index.php/Time_and_clock_RTS_Functions ,TI version of time function uses a different epoch: midnight UTC-6 Jan 1, 1900. What we want is  Jan 1, 1970 UTC-0000  baed one.  So according to the guide, I just define the "__TI_TIME_USES_64=1"  macro to support the  _time64_t epoch .

  When do the whole project rebuild, it reports error 

  "package/cfg/simple_peripheral_app_pem4f.c", line 2494: error #249: function "time" has already been defined

#if defined(__clang__) && defined(__TI_TIME_USES_64) && __TI_TIME_USES_64

that means __clang__ should also be defined?  Can we just define it ? It's OK for CCS build env?

  • Hi Daniel,

    The page you are referring to is not for the toolchain used for CC2642, you could not apply the same steps to the TI-ARM compiler and expect the same result. Could you try out the following define for your project: 

    __TI_TIME32_USES_POSIX_EPOCH = 1

    __TI_TIME32_USES_POSIX_EPOCH
  • Hi M-W;

       After added "__TI_TIME32_USES_POSIX_EPOCH=1" to predefined symbols and rebuild whole project including libs, it seems there is no effect. The mktime() function still returns  negative value and the time_t type is still  4 bytes width.

  • Hi Daniel,

    So what you get is compiler specific. The TI ARM does not give you a 64 bit implementation that link to the RTC like the case for 32-bits (as far as I can figure out). If you used the clang compiler, there seems to be one.

    Either way, you want the function to be bound to the RTC clock of the device (the "Seconds" HAL of TI-RTOS interface with this which is why the 32-bit version uses this). To this you manually want to add the offset to get the epoch right (you could see that the 32-bit version should be doing this if "__ti__" is defined.

    I took an generic example from the 4.20 SDK and ran a test with __TI_TIME_USES_64=1 set in the project to get the time() to redirect to the 64-bit version. But as I'm using TI ARM, I get redirected to a HOST version which is not what you want. In that case you could override the function yourself and fill in the logic needed to get the result you need from the clock source you want:

    /*
     *  ======== time ========
     */
    __time64_t __attribute__ ((used)) __time64(time_t *tout)
    {
        uint32_t t;
    
        /* Get time using fro example Seconds_get() */
    
    #if defined(__ti__)
        /*
         *  TI time() function returns seconds since 1900, so add the number
         *  of seconds from 1900 to 1970 (2208988800).
         */
        t += 2208988800;
    #endif
    
        if (tout) {
            *tout = t;
        }
    
        return (t);
    }