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.

TM4C123GH6PGE: TM4C123GH6PGE hibernate module

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

Hello,

I got the below code from one of the previous answer in the forum.Now i want to set the starting time from today like 11 october 2017 and start the time from present time like 18:05:26, anyone please tell me how to set above values in my below  code  

// Global data to be used by this example
//
//*****************************************************************************
time_t calendar_write;
time_t calendar_read;
struct tm tm1 = {50,59,23,5,6,2014-1900,5,0,0}; // to compute seconds since epoch
struct tm tm2 = {0}; // to read back the calendar
uint8_t buf_er[] = "Wrong initialization structure!\n";
uint8_t buf_rz[48];

void UARTSend(uint8_t *pui8Buffer, uint32_t ui32Count);
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// Hibernate handler
//
//*****************************************************************************
void HibernateHandler(void)
{
// reset interrupt flag
uint32_t ui32Status = HibernateIntStatus(1);
ROM_HibernateIntClear(ui32Status);
//
calendar_read = HibernateRTCGet();
ulocaltime(calendar_read, &tm2);
// format the output for uart
strftime((char *)buf_rz, 32, "%c\r\n", &tm2);
UARTSend((uint8_t *)buf_rz, 32);
// Keep the interrupt hapening
HibernateRTCMatchSet(0,HibernateRTCGet()+5);
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPut(UART0_BASE, *pui8Buffer++);
}
}

int main(void) {
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPUEnable();
ROM_FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Enable the GPIO port that is used for the on-board LED.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

//
// Enable the GPIO pins for the LED (PF2).
//
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO A0 and A1 as UART pins.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//
// Configure the hibernation module
//
ROM_HibernateEnableExpClk(0);
ROM_HibernateRTCEnable();
HibernateClockConfig(HIBERNATE_OSC_HIGHDRIVE);
//
HibernateIntRegister(HibernateHandler);
HibernateIntEnable(HIBERNATE_INT_RTC_MATCH_0);
HibernateWakeSet(HIBERNATE_WAKE_RTC);

//Set up counter mode for RTC
HibernateCounterMode(HIBERNATE_COUNTER_RTC);
//
// Calculate the calendar data to be written
//
calendar_write = umktime(&tm1);
if (calendar_write == (uint32_t)(-1)){
UARTSend((uint8_t *)buf_er, sizeof(buf_er));
while(1);
}
else {
HibernateRTCSet(calendar_write);
//Set an interrupt for the RTC after one second.
HibernateRTCMatchSet(0,HibernateRTCGet()+5);
}

while(1){
//do nothing - safety
}
// return 0;
}

Thanks in advance.

  • Hi Srinu,
    Please refer to the TivaWare Peripheral Driver Library user's guide for details on using HibernateCalendarSet() API to set the time and date.
  • I want to set my time and date in below structure.Please suggest me how can i write the values for time 11:08:25 and 12 october 2017

    struct tm tm1 = {50,59,23,5,6,2014-1900,5,0,0}; // to compute seconds since epoch

    abve structure like below

    struct tm
    {
    int tm_sec; /* seconds after the minute - [0,59] */
    int tm_min; /* minutes after the hour - [0,59] */
    int tm_hour; /* hours after the midnight - [0,23] */
    int tm_mday; /* day of the month - [1,31] */
    int tm_mon; /* months since January - [0,11] */
    int tm_year; /* years since 1900 */
    int tm_wday; /* days since Sunday - [0,6] */
    int tm_yday; /* days since Jan 1st - [0,365] */
    int tm_isdst; /* Daylight Savings Time flag */
    #if _AEABI_PORTABILITY_CHECK
    int __extra_1, __extra_2; /* ABI-required extra fields */
    #endif

    };

    Please suggest me


    Thanks in advance
  • //*****************************************************************************
    //
    // 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);
    }
    
    //*****************************************************************************
    //
    // This function sets the time to the default system time.
    //
    //*****************************************************************************
    void
    DateTimeDefaultSet(void)
    {
        g_ui32MonthIdx = 7;
        g_ui32DayIdx = 29;
        g_ui32YearIdx = 13;
        g_ui32HourIdx = 8;
        g_ui32MinIdx = 30;
    
    }

    Hi,

     Why don't you refer to the TivaWare hibernate.c example under <TivaWare_Installation>/examples/boards/ek-tm4c1294xl/hibernate.c? Below is the snippet.

  • Snippet appears (above) - some would say...
  • Hi cb1,

    Thanks. I missed it.

    //*****************************************************************************
    //
    // 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);
    }
    
    //*****************************************************************************
    //
    // This function sets the time to the default system time.
    //
    //*****************************************************************************
    void
    DateTimeDefaultSet(void)
    {
        g_ui32MonthIdx = 7;
        g_ui32DayIdx = 29;
        g_ui32YearIdx = 13;
        g_ui32HourIdx = 8;
        g_ui32MinIdx = 30;
    
    }

  • Thank you so much sir.