From 509dc7c18d61e3994e47d87f4d4011aff0766559 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 30 Jul 1998 21:27:51 +0000 Subject: Added getRealTime() and setRealTime(). Reimplemented checkRealTime() to use RTEMS internal routine. --- c/src/lib/libbsp/shared/tod.c | 78 +++++++++++++++++++++++++++++++++++++------ c/src/lib/libbsp/shared/tod.h | 39 ++++++++++++++++++---- 2 files changed, 99 insertions(+), 18 deletions(-) (limited to 'c/src/lib/libbsp/shared') diff --git a/c/src/lib/libbsp/shared/tod.c b/c/src/lib/libbsp/shared/tod.c index c414e9e47b..b43c7c1c04 100644 --- a/c/src/lib/libbsp/shared/tod.c +++ b/c/src/lib/libbsp/shared/tod.c @@ -148,6 +148,62 @@ void setRealTimeFromRTEMS() 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 * * checkRealTime @@ -160,28 +216,28 @@ void setRealTimeFromRTEMS() * Output parameters: NONE * * Return values: - * int The differance between the real time clock and rtems time or - * 9999 in the event of an error. + * int The differance between the real time clock and rtems time. */ +/* XXX this routine should be part of the public RTEMS interface */ +unsigned32 _TOD_To_seconds( rtems_time_of_day *tod ); + int checkRealTime() { rtems_time_of_day rtems_tod; rtems_time_of_day rtc_tod; + unsigned32 rtems_time; + unsigned32 rtc_time; if (!RTC_Present) - return 0; + return -1; rtems_clock_get( RTEMS_CLOCK_GET_TOD, &rtems_tod ); RTC_Table[RTC_Minor].pDeviceFns->deviceGetTime(RTC_Minor, &rtc_tod); - if( rtems_tod.year == rtc_tod.year && - rtems_tod.month == rtc_tod.month && - rtems_tod.day == rtc_tod.day ) { - return ((rtems_tod.hour - rtc_tod.hour) * 3600) + - ((rtems_tod.minute - rtc_tod.minute) * 60) + - (rtems_tod.second - rtc_tod.second); - } - return 9999; + rtems_time = _TOD_To_seconds( &rtems_tod ); + rtc_time = _TOD_To_seconds( &rtc_tod ); + + return rtems_time - rtc_time; } diff --git a/c/src/lib/libbsp/shared/tod.h b/c/src/lib/libbsp/shared/tod.h index d51ceb23b9..725211e082 100644 --- a/c/src/lib/libbsp/shared/tod.h +++ b/c/src/lib/libbsp/shared/tod.h @@ -21,15 +21,40 @@ extern "C" { #endif -extern void setRealTimeToRTEMS(); -/* Read real time from RTC and set it to RTEMS' clock manager */ +/* + * Set the RTC. + */ + +int setRealTime( + rtems_time_of_day *tod +); -extern void setRealTimeFromRTEMS(); -/* Read time from RTEMS' clock manager and set it to RTC */ +/* + * Get the time from the RTC. + */ + +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. + */ -extern int checkRealTime(); -/* 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 } -- cgit v1.2.3