What would be the easiest way to adjust time?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What would be the easiest way to adjust time?

Jump to solution
2,709 Views
MQXuser
Contributor III

I am using MQX_time and RTC_time in order to manage time for my system.

I am retrieving the time from a time server and I must adjust that time for my time zone, for which I must substract a few hours from the time retrieved.

I have seen _time_add function but that function is working with tick_time, thus I still looking for the ideal way of making this substraction.

 

Example:

 

Time =  5/February/2010  01:00 hrs

TimeZone = -0700

TimeAdjusted = 4/February/2010 18:00 hrs

 

Thanks

 

0 Kudos
Reply
1 Solution
996 Views
CarlFST60L
Senior Contributor II

Would this work for you? (I havnt tested it, but the concept seems right to me)

 

 

void RTC_TimeZoneUpdate(DATE_STRUCT date, int_32 Adjustment){ TIME_STRUCT time; RTC_TIME_STRUCT time_rtc;  _time_from_date(&date, &time);    //Get the MQX time from the date i.e. convert current date to seconds elapsed since 1971        time.SECONDS += Adjustment; //Timezone offset now in seconds
 _rtc_time_from_mqx_time(&time,&time_rtc); //Convert to RTC time format _rtc_set_time (&time_rtc);     //Update RTC}

 Then, you can just get your date and time, convert the timezone to seconds (Hours * 60) and call this unction and your RTC will update to the adjusted time.

 

With my application I need to reboot my processor to sync MQX time to the RTC (I think). If you need a function to reboot MQX, let me know.

 

View solution in original post

0 Kudos
Reply
5 Replies
996 Views
MQXuser
Contributor III

I am still looking for a way to adjust the time. Is there any MQX function that allows to do that?

0 Kudos
Reply
997 Views
CarlFST60L
Senior Contributor II

Would this work for you? (I havnt tested it, but the concept seems right to me)

 

 

void RTC_TimeZoneUpdate(DATE_STRUCT date, int_32 Adjustment){ TIME_STRUCT time; RTC_TIME_STRUCT time_rtc;  _time_from_date(&date, &time);    //Get the MQX time from the date i.e. convert current date to seconds elapsed since 1971        time.SECONDS += Adjustment; //Timezone offset now in seconds
 _rtc_time_from_mqx_time(&time,&time_rtc); //Convert to RTC time format _rtc_set_time (&time_rtc);     //Update RTC}

 Then, you can just get your date and time, convert the timezone to seconds (Hours * 60) and call this unction and your RTC will update to the adjusted time.

 

With my application I need to reboot my processor to sync MQX time to the RTC (I think). If you need a function to reboot MQX, let me know.

 

0 Kudos
Reply
996 Views
MQXuser
Contributor III

Thank you for your answer, I will test it soon.

In order to reset I am using the following Macro:

   #define MCF_RCM_RCR (*(vuint_8 *)(0x40110000))

   #define RESET    MCF_RCM_RCR = 0x80

Is there another way?

There is a function in order to synchronize MQX time and RTC time but I had trouble with that function(everything stoped working after using it). Have you tried it?

_rtc_sync_with_mqx(FALSE);

 

 

0 Kudos
Reply
996 Views
CarlFST60L
Senior Contributor II

I think your reset macro is a little better!

 

    VMCF5225_STRUCT_PTR reg_ptr = (VMCF5225_STRUCT_PTR)BSP_IPSBAR;    //Pointer to data
    reg_ptr->CCM.RCR |= MCF5225_CCM_RCR_SOFTRST;                      //Cause software reset

 

As for updating time, I dont think I can use this sync function between MQX and RTC during runtime as I have quite a few relative timers that are programmable/configurable and in multipule threads. Looking back, I should have written my code differently, but its no problem for us to reset...



0 Kudos
Reply
996 Views
MQXuser
Contributor III

Tested and working. Thanks.

0 Kudos
Reply