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.

RTOS/TM4C1294KCPDT: Getting the Real time clock

Part Number: TM4C1294KCPDT

Tool/software: TI-RTOS

Hi Everyone,

I am developing an embedded application on TM4C1294KCPDT using TI-RTOS V2.16. Compiler CCS v6.2.

I am trying to get the current time from the system clock. I am using as RTC(Real time clock) to get and set the clock variables.

I am using Below code :: 

ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
		SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

HibernateEnableExpClk(ui32SysClock);
HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
HibernateRTCDisable();

HibernateRTCMatchSet(0,HibernateRTCGet()+1);
HibernateIntEnable(HIBERNATE_INT_RTC_MATCH_0);

HibernateCounterMode(HIBERNATE_COUNTER_24HR);

HibernateRTCSet(0); // this code is for time stamps
HibernateRTCEnable();


now = HibernateRTCGet(); //get the current value in seconds

System_printf("now = %ld \r HibernateRTCGet() %d\n", now, HibernateRTCGet());
System_flush();

SYSTEMTIME lt = {0};
GetLocalTime(&lt);     // This is for windows to get the local time But it is not working ccs

time_t t = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970);  // Here How to set the current time variable if we set the time here we can able to set the calendar and we may get the current time 
memcpy(&TimerStruct, localtime(&t), sizeof (struct tm));

HibernateCalendarSet(&TimerStruct);

HibernateCalendarGet(&TimerStruct);

System_printf("Date :: %d Day \t %d Month \t %d Year\n", TimerStruct.tm_mday, TimerStruct.tm_mon, TimerStruct.tm_year);
System_flush();

System_printf("TIME :: %d Hour \t %d Minute \t %d Sec\n", TimerStruct.tm_hour, TimerStruct.tm_min, TimerStruct.tm_sec);
System_flush();

I Mentioned the comments for the code please check that comments and give the solution. Right now i am getting Compilation errors.

  • Hello Prem,

    Can you post what the compilation errors are? It isn't apparent just based on your code snippet posted.

    Also are you actually using TI-RTOS for this? This looks like a TivaWave project as you call SysCtlClockFreqSet.
  • Hello Ralpha,

    struct tm TimerStruc;

    SYSTEMTIME lt = {0};
    GetLocalTime(&lt); // This is for windows to get the local time But it is not working ccs
    time_t t = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970); // Here How to set the current time variable if we set the time here we can able
    to set the calendar and we may get the current time
    memcpy(&TimerStruct, localtime(&t), sizeof (struct tm));

    These 3 API's are windows API's. That's why i am getting error.

    Instead of this how we can fill the TimerStruct from outside source.
  • prem kumar76 said:
    Instead of this how we can fill the TimerStruct from outside source.

    Hello,

    Perhaps call one of several HTTP national time servers (often *.edu) thus requires call to Time ports (TCP/UDP-37) query to fill your TimeStruct. 

    Perhaps modify the http.c or weather.c example projects to preform the http query. 

    Windows can also act as a time server to TCP/UDP time clients. 

  • Hello Prem,

    Windows API's don't just drop into MCU's like that. In some cases you would need to find if they have been ported for a specific MCU or architecture and then include files that leverage the MCU's capabilities to drive those API's, but for this that wouldn't even work.

    The Windows API's you are using depend on accessing the Windows system time, that is not something an MCU can just do, plus it would always have to be connected to Windows even if you did manage to find a way to do that.

    What BP101 is suggesting with getting the time from a server you can connect with via Ethernet is the proper way to handle this.