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.

TM4C1294NCPDT: RTC capabilities in calendar mode of HibernateModule

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL

Hi,

It is a pretty simple question about the RTC on the hibernate module. I'm already using it to keep track of time using the RTC. It's working ok and all, but I couldn't find the year range of the internal RTC.

Since the datasheet mentions that uses a 32 bit timer I was assuming that the RTC would overflow on 2038. Is that the case?

If that matters, I'm using the tivaware library and it returns me a "struct tm" that uses 1900 as reference.

  • Hi,
    I will not doubt your calculation. There are 60x60x24x365=31536000 seconds in one year. If you divide 2^32 by 31536000 is equal to 136 years. If you start with 1900 then it can overflow at 2036. But for new development you don't need to start at 1900, right?
  • I did not choose to start from 1900, that's how the function "HibernateCalendarGet" return the "struct tm" using TivaWare. But if you take a look on the tm4c1294 datasheet the RTC module doesn't seem to be restrict to start on 1900. That's why I got confused and could not reach a conclusion on which is the constrain of time range on the internal RTC.

  • Hi,
    Yes, you can start at different date/time/year if you want.
  • Hi Charles,

    It is great to know that you can start at an arbitrary date, but that does not answer my fundamental question: What time range can I expect of the RTC? Can I go up to year 2100 and beyond? The leap years will still be correct up to when?
  • HI,
    I thought i calculated earlier that the 32bit counter will not expire in 136 years with the RTC clock at 32kHz. According to the datasheet the leap year compensation is handled within the calendar function. The number of days in February are adjusted to 29 whenever the year is divisible by four.
  • Hi Charles,
    Yes, you are right.
    Just one last question: which files/functions should I modify so I can start count the years on 2000 rather than 1900? I'm assuming I shouldn't mess with the "time.h". I was wondering if I could just assume the "struct tm" provided on TivaWare function is starting from 2000 but then I realized doing this would probably mess with the mktime and localtime functions that I rely to convert from "struct tm" to "seconds since".

    I'm already adding and subtracting 70 years to make a compatible "linux epoch" timestamp.

    Another though is that moving the reference year around shouldn't mess with the leap year calculation as long the base year change is divisible by 4, is that correct?

  • Hi,

     I wonder if you have a chance to run the TivaWare hibernate example under <TivaWare_Installation>/examples/boards/EK-TM4C1294XL/hibernate. If you run this example, it shows how you can set the DD/MM/YYYY via the terminal window using the date command. When the proper the DD/MM/YYYY is entered it will call the DateTimeSet() function which will then load the sTime structure with the entered day/month/year and then call the HibernateCalendarSet() API.  See below.

    In hibernate_command.c 

    /*****************************************************************************
    //
    // Command: date
    //
    // Set the current system date.  Use format "DD/MM/YYYY"
    //
    //*****************************************************************************
    int
    CMD_date(int argc, char **argv)
    {
        const char *pcNext;
    
        //
        // Check the argument count and return errors for too many or too few.
        //
        if(argc == 1)
        {
            return(CMDLINE_TOO_FEW_ARGS);
        }
        if(argc > 2)
        {
            return(CMDLINE_TOO_MANY_ARGS);
        }
    
        //
        // Convert the date to unsigned long
        //
        g_ui32DayIdx = ustrtoul(argv[1], &pcNext, 10);
        g_ui32MonthIdx = ustrtoul(pcNext+1, &pcNext, 10) - 1;
        g_ui32YearIdx = (ustrtoul(pcNext+1, NULL, 10) - 2000);
    
        //
        // Perform the conversions to a time struct and store in the hibernate
        // module after doing a minimal amount of validation.
        //
        if((g_ui32DayIdx > 31) || (g_ui32MonthIdx > 11))
        {
            return(CMDLINE_INVALID_ARG);
        }
    
        DateTimeSet();
    
        return(0);
    }

    In hibernate.c file.

    //*****************************************************************************
    //
    // This function writes the requested date and time to the calendar logic of
    // hibernation module.
    //
    //*****************************************************************************
    void
    DateTimeSet(void)
    {
        struct tm sTime;
    
        //
        // Get the latest date and time.  This is done here so that unchanged
        // parts of date and time can be written back as is.
        //
        HibernateCalendarGet(&sTime);
    
        //
        // Set the date and time values that are to be updated.
        //
        sTime.tm_hour = g_ui32HourIdx;
        sTime.tm_min = g_ui32MinIdx;
        sTime.tm_mon = g_ui32MonthIdx;
        sTime.tm_mday = g_ui32DayIdx;
        sTime.tm_year = 100 + g_ui32YearIdx;
    
        //
        // Update the calendar logic of hibernation module with the requested data.
        //
        HibernateCalendarSet(&sTime);

  • Hi Daniolpp,
    I have not heard back from you. I assume you are able to resolve the issue. I will close the thread for now. If you have new questions you can open a new thread or reply back to this thread with some comments if the issue persists