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.

CC3200: use of mktime in CC3200

Part Number: CC3200

Hi there, 

Do you have any example using mktime function working. I tried calling the mktime from time.h but it is not working.

#define DAY     6
#define MONTH   1
#define YEAR    2016
#define HOUR    19
#define MINUTE  0
#define SECOND  0

#define YEARDIFF  1900
#define MONTHDIFF 1

#include <time.h>
#include <stdint.h>
static void setTime(void)
{
    struct tm startTime = {0};
    time_t ts;

    /* Set system clock on application microcontroller */
    startTime.tm_mday = DAY;
    startTime.tm_mon  = MONTH - MONTHDIFF;
    startTime.tm_year = YEAR - YEARDIFF;
    startTime.tm_hour = HOUR;
    startTime.tm_min  = MINUTE;
    startTime.tm_sec  = SECOND;
    startTime.tm_isdst = -1;
    ts = mktime(&startTime);
    UART_PRINT("seconds since the Epoch: %ld\n", (long) ts);
}

Thanks
Ganesh

  • Hi Ganesh,

    Are you trying to set the RTOS clock on the host MCU, or are you trying to set the NWP clock for networking uses?

    Best regards,

    Sarah

  • Hi Sarah,

    I am not trying to set in RTOS clock or in NWP clock

    #define YEARDIFF 1900
    #define MONTHDIFF 1
    
    static uint32_t setTime(uint16_t year, uint8_t month, uint8_t day, uint8_t h, uint8_t m, uint8_t s)
    {
    	struct tm startTime = { 0 };
    	time_t ts;
    
    	/* Set system clock on application microcontroller */
    	startTime.tm_mday = day;
    	startTime.tm_mon = month - MONTHDIFF;
    	startTime.tm_year = year - YEARDIFF;
    	startTime.tm_hour = h;
    	startTime.tm_min = m;
    	startTime.tm_sec = s;
    	startTime.tm_isdst = 0;
    	ts = mktime(&startTime);
    	//UART_PRINT("seconds since the Epoch: %ld\n", (long)ts);
    	return (uint32_t)ts;
    }

    After using mktime i was trying get the correct timestamp, thats all. But it return me incorrect data.

  • Hi Ganesh,

    Can you explain your result and what you expect instead?

    I believe the TI-RTOS Epoch is based on 1970, and you should use an unsigned long to print.

    Best regards,

    Sarah

  • Hi Sarah,

    Thanks works.

    Ganesh