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
已解决! 转到解答。
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.
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.
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);
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...