Author: evb Date: Thu Feb 4 08:22:03 2010 New Revision: 45414
URL: http://svn.reactos.org/svn/reactos?rev=45414&view=rev Log: - Add PL031 RTC code for Versatile. - Add RTC time to TimeInfo convert. - Implement FirmWare GetTime function. Countdown in FreeLDR now working.
Added: trunk/reactos/boot/armllb/hw/time.c (with props) Modified: trunk/reactos/boot/armllb/armllb.rbuild trunk/reactos/boot/armllb/fw.c trunk/reactos/boot/armllb/hw/versatile/hwinfo.c trunk/reactos/boot/armllb/inc/fw.h trunk/reactos/boot/armllb/inc/hw.h trunk/reactos/boot/armllb/inc/precomp.h
Modified: trunk/reactos/boot/armllb/armllb.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/armllb/armllb.rbuild?r... ============================================================================== --- trunk/reactos/boot/armllb/armllb.rbuild [iso-8859-1] (original) +++ trunk/reactos/boot/armllb/armllb.rbuild [iso-8859-1] Thu Feb 4 08:22:03 2010 @@ -26,6 +26,7 @@ <directory name="hw"> <file>keyboard.c</file> <file>serial.c</file> + <file>time.c</file> <file>video.c</file> <if property="SARCH" value="omap3"> <directory name="omap3">
Modified: trunk/reactos/boot/armllb/fw.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/armllb/fw.c?rev=45414&... ============================================================================== --- trunk/reactos/boot/armllb/fw.c [iso-8859-1] (original) +++ trunk/reactos/boot/armllb/fw.c [iso-8859-1] Thu Feb 4 08:22:03 2010 @@ -171,12 +171,11 @@ return; }
-VOID +TIMEINFO* LlbFwGetTime(VOID) { - printf("%s is UNIMPLEMENTED", __FUNCTION__); - while (TRUE); - return; + /* Call existing function */ + return LlbGetTime(); }
/* EOF */
Added: trunk/reactos/boot/armllb/hw/time.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/armllb/hw/time.c?rev=4... ============================================================================== --- trunk/reactos/boot/armllb/hw/time.c (added) +++ trunk/reactos/boot/armllb/hw/time.c [iso-8859-1] Thu Feb 4 08:22:03 2010 @@ -1,0 +1,91 @@ +/* + * PROJECT: ReactOS Boot Loader + * LICENSE: BSD - See COPYING.ARM in the top level directory + * FILE: boot/armllb/hw/time.c + * PURPOSE: LLB Time Routines + * PROGRAMMERS: ReactOS Portable Systems Group + */ + +#include "precomp.h" + +#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) + +UCHAR LlbDaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +TIMEINFO LlbTime; + +BOOLEAN +NTAPI +LlbIsLeapYear(IN ULONG Year) +{ + /* Every 4, 100, or 400 years */ + return (!(Year % 4) && (Year % 100)) || !(Year % 400); +} + +ULONG +NTAPI +LlbDayOfMonth(IN ULONG Month, + IN ULONG Year) +{ + /* Check how many days a month has, accounting for leap yearS */ + return LlbDaysInMonth[Month] + (LlbIsLeapYear(Year) && Month == 1); +} + +VOID +NTAPI +LlbConvertRtcTime(IN ULONG RtcTime, + OUT TIMEINFO* TimeInfo) +{ + ULONG Month, Year, Days, DaysLeft; + + /* Count the days, keep the minutes */ + Days = RtcTime / 86400; + RtcTime -= Days * 86400; + + /* Get the year, based on days since 1970 */ + Year = 1970 + Days / 365; + + /* Account for leap years which changed the number of days/year */ + Days -= (Year - 1970) * 365 + LEAPS_THRU_END_OF(Year - 1) - LEAPS_THRU_END_OF(1970 - 1); + if (Days < 0) + { + /* We hit a leap year, so fixup the math */ + Year--; + Days += 365 + LlbIsLeapYear(Year); + } + + /* Count months */ + for (Month = 0; Month < 11; Month++) + { + /* How many days in this month? */ + DaysLeft = Days - LlbDayOfMonth(Month, Year); + if (DaysLeft < 0) break; + + /* How many days left total? */ + Days = DaysLeft; + } + + /* Write the structure */ + TimeInfo->Year = Year; + TimeInfo->Day = Days + 1; + TimeInfo->Month = Month + 1; + TimeInfo->Hour = RtcTime / 3600; + RtcTime -= TimeInfo->Hour * 3600; + TimeInfo->Minute = RtcTime / 60; + TimeInfo->Second = RtcTime - TimeInfo->Minute * 60; +} + +TIMEINFO* +NTAPI +LlbGetTime(VOID) +{ + ULONG RtcTime; + + /* Read RTC time */ + RtcTime = LlbHwRtcRead(); + + /* Convert it */ + LlbConvertRtcTime(RtcTime, &LlbTime); + return &LlbTime; +} + +/* EOF */
Propchange: trunk/reactos/boot/armllb/hw/time.c ------------------------------------------------------------------------------ svn:eol-style = native
Propchange: trunk/reactos/boot/armllb/hw/time.c ------------------------------------------------------------------------------ svn:executable = *
Modified: trunk/reactos/boot/armllb/hw/versatile/hwinfo.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/armllb/hw/versatile/hw... ============================================================================== --- trunk/reactos/boot/armllb/hw/versatile/hwinfo.c [iso-8859-1] (original) +++ trunk/reactos/boot/armllb/hw/versatile/hwinfo.c [iso-8859-1] Thu Feb 4 08:22:03 2010 @@ -7,6 +7,9 @@ */
#include "precomp.h" + +#define PL031_RTC_DR (LlbHwVersaRtcBase + 0x00) +static const ULONG LlbHwVersaRtcBase = 0x101E8000;
ULONG NTAPI @@ -44,4 +47,10 @@ LlbAllocateMemoryEntry(BiosMemoryReserved, 0x10000000, 128 * 1024 * 1024); }
+ULONG +LlbHwRtcRead(VOID) +{ + /* Read RTC value */ + return READ_REGISTER_ULONG(PL031_RTC_DR); +} /* EOF */
Modified: trunk/reactos/boot/armllb/inc/fw.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/armllb/inc/fw.h?rev=45... ============================================================================== --- trunk/reactos/boot/armllb/inc/fw.h [iso-8859-1] (original) +++ trunk/reactos/boot/armllb/inc/fw.h [iso-8859-1] Thu Feb 4 08:22:03 2010 @@ -5,6 +5,16 @@ * PURPOSE: LLB Firmware Functions * PROGRAMMERS: ReactOS Portable Systems Group */ + +typedef struct _TIMEINFO +{ + USHORT Year; + USHORT Month; + USHORT Day; + USHORT Hour; + USHORT Minute; + USHORT Second; +} TIMEINFO;
VOID LlbFwPutChar( @@ -94,7 +104,7 @@ VOID );
-VOID +TIMEINFO* LlbFwGetTime( VOID );
Modified: trunk/reactos/boot/armllb/inc/hw.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/armllb/inc/hw.h?rev=45... ============================================================================== --- trunk/reactos/boot/armllb/inc/hw.h [iso-8859-1] (original) +++ trunk/reactos/boot/armllb/inc/hw.h [iso-8859-1] Thu Feb 4 08:22:03 2010 @@ -104,6 +104,19 @@ VOID );
+ULONG +NTAPI +LlbHwRtcRead( + VOID +); + +//fix +TIMEINFO* +NTAPI +LlbGetTime( + VOID +); + #ifdef _VERSATILE_ #include "versa.h" #elif _OMAP3_
Modified: trunk/reactos/boot/armllb/inc/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/armllb/inc/precomp.h?r... ============================================================================== --- trunk/reactos/boot/armllb/inc/precomp.h [iso-8859-1] (original) +++ trunk/reactos/boot/armllb/inc/precomp.h [iso-8859-1] Thu Feb 4 08:22:03 2010 @@ -11,8 +11,8 @@ #include "ioaccess.h" #include "machtype.h" #include "osloader.h" +#include "fw.h" #include "hw.h" -#include "fw.h" #include "serial.h" #include "video.h" #include "keyboard.h"