forked from Imagelibrary/rtems
Added getRealTime() and setRealTime().
Reimplemented checkRealTime() to use RTEMS internal routine.
This commit is contained in:
@@ -148,6 +148,62 @@ void setRealTimeFromRTEMS()
|
|||||||
RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, &rtems_tod);
|
RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, &rtems_tod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* getRealTime
|
||||||
|
*
|
||||||
|
* This routine reads the current time from the RTC.
|
||||||
|
*
|
||||||
|
* Input parameters: NONE
|
||||||
|
*
|
||||||
|
* Output parameters: NONE
|
||||||
|
*
|
||||||
|
* Return values: NONE
|
||||||
|
*/
|
||||||
|
|
||||||
|
void getRealTime(
|
||||||
|
rtems_time_of_day *tod
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!RTC_Present)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RTC_Table[RTC_Minor].pDeviceFns->deviceGetTime(RTC_Minor, tod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* setRealTime
|
||||||
|
*
|
||||||
|
* This routine sets the RTC.
|
||||||
|
*
|
||||||
|
* Input parameters: NONE
|
||||||
|
*
|
||||||
|
* Output parameters: NONE
|
||||||
|
*
|
||||||
|
* Return values: NONE
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* XXX this routine should be part of the public RTEMS interface */
|
||||||
|
rtems_boolean _TOD_Validate( rtems_time_of_day *tod );
|
||||||
|
|
||||||
|
int setRealTime(
|
||||||
|
rtems_time_of_day *tod
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!RTC_Present)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ( !_TOD_Validate(tod) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, tod);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*PAGE
|
/*PAGE
|
||||||
*
|
*
|
||||||
* checkRealTime
|
* checkRealTime
|
||||||
@@ -160,28 +216,28 @@ void setRealTimeFromRTEMS()
|
|||||||
* Output parameters: NONE
|
* Output parameters: NONE
|
||||||
*
|
*
|
||||||
* Return values:
|
* Return values:
|
||||||
* int The differance between the real time clock and rtems time or
|
* int The differance between the real time clock and rtems time.
|
||||||
* 9999 in the event of an error.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* XXX this routine should be part of the public RTEMS interface */
|
||||||
|
unsigned32 _TOD_To_seconds( rtems_time_of_day *tod );
|
||||||
|
|
||||||
int checkRealTime()
|
int checkRealTime()
|
||||||
{
|
{
|
||||||
rtems_time_of_day rtems_tod;
|
rtems_time_of_day rtems_tod;
|
||||||
rtems_time_of_day rtc_tod;
|
rtems_time_of_day rtc_tod;
|
||||||
|
unsigned32 rtems_time;
|
||||||
|
unsigned32 rtc_time;
|
||||||
|
|
||||||
if (!RTC_Present)
|
if (!RTC_Present)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
rtems_clock_get( RTEMS_CLOCK_GET_TOD, &rtems_tod );
|
rtems_clock_get( RTEMS_CLOCK_GET_TOD, &rtems_tod );
|
||||||
RTC_Table[RTC_Minor].pDeviceFns->deviceGetTime(RTC_Minor, &rtc_tod);
|
RTC_Table[RTC_Minor].pDeviceFns->deviceGetTime(RTC_Minor, &rtc_tod);
|
||||||
|
|
||||||
if( rtems_tod.year == rtc_tod.year &&
|
rtems_time = _TOD_To_seconds( &rtems_tod );
|
||||||
rtems_tod.month == rtc_tod.month &&
|
rtc_time = _TOD_To_seconds( &rtc_tod );
|
||||||
rtems_tod.day == rtc_tod.day ) {
|
|
||||||
return ((rtems_tod.hour - rtc_tod.hour) * 3600) +
|
return rtems_time - rtc_time;
|
||||||
((rtems_tod.minute - rtc_tod.minute) * 60) +
|
|
||||||
(rtems_tod.second - rtc_tod.second);
|
|
||||||
}
|
|
||||||
return 9999;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,15 +21,40 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void setRealTimeToRTEMS();
|
/*
|
||||||
/* Read real time from RTC and set it to RTEMS' clock manager */
|
* Set the RTC.
|
||||||
|
*/
|
||||||
|
|
||||||
extern void setRealTimeFromRTEMS();
|
int setRealTime(
|
||||||
/* Read time from RTEMS' clock manager and set it to RTC */
|
rtems_time_of_day *tod
|
||||||
|
);
|
||||||
|
|
||||||
extern int checkRealTime();
|
/*
|
||||||
/* Return the difference between RTC and RTEMS' clock manager time in minutes.
|
* Get the time from the RTC.
|
||||||
If the difference is greater than 1 day, this returns 9999. */
|
*/
|
||||||
|
|
||||||
|
void getRealTime(
|
||||||
|
rtems_time_of_day *tod
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read real time from RTC and set it to RTEMS' clock manager
|
||||||
|
*/
|
||||||
|
|
||||||
|
void setRealTimeToRTEMS();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read time from RTEMS' clock manager and set it to RTC
|
||||||
|
*/
|
||||||
|
|
||||||
|
void setRealTimeFromRTEMS();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the difference between RTC and RTEMS' clock manager time in minutes.
|
||||||
|
* If the difference is greater than 1 day, this returns 9999.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int checkRealTime();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user