- Add PL031 RTC code for Versatile.
authorevb <evb@svn.reactos.org>
Thu, 4 Feb 2010 07:22:03 +0000 (07:22 +0000)
committerevb <evb@svn.reactos.org>
Thu, 4 Feb 2010 07:22:03 +0000 (07:22 +0000)
- Add RTC time to TimeInfo convert.
- Implement FirmWare GetTime function. Countdown in FreeLDR now working.

svn path=/trunk/; revision=45414

reactos/boot/armllb/armllb.rbuild
reactos/boot/armllb/fw.c
reactos/boot/armllb/hw/time.c [new file with mode: 0755]
reactos/boot/armllb/hw/versatile/hwinfo.c
reactos/boot/armllb/inc/fw.h
reactos/boot/armllb/inc/hw.h
reactos/boot/armllb/inc/precomp.h

index ea39a50..5e254c4 100644 (file)
@@ -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">
index 94350fa..6e9ead5 100644 (file)
@@ -171,12 +171,11 @@ LlbFwVideoSync(VOID)
     return;
 }
 
-VOID
+TIMEINFO*
 LlbFwGetTime(VOID)
 {
-    printf("%s is UNIMPLEMENTED", __FUNCTION__);
-    while (TRUE);
-    return;   
+    /* Call existing function */
+    return LlbGetTime();
 }
 
 /* EOF */
diff --git a/reactos/boot/armllb/hw/time.c b/reactos/boot/armllb/hw/time.c
new file mode 100755 (executable)
index 0000000..f37be24
--- /dev/null
@@ -0,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 */
index 5c2c0b8..667898f 100755 (executable)
@@ -8,6 +8,9 @@
 
 #include "precomp.h"
 
+#define PL031_RTC_DR                (LlbHwVersaRtcBase + 0x00)
+static const ULONG LlbHwVersaRtcBase = 0x101E8000;
+
 ULONG
 NTAPI
 LlbHwGetBoardType(VOID)
@@ -44,4 +47,10 @@ LlbHwBuildMemoryMap(IN PBIOS_MEMORY_MAP MemoryMap)
     LlbAllocateMemoryEntry(BiosMemoryReserved, 0x10000000, 128 * 1024 * 1024);
 }
 
+ULONG
+LlbHwRtcRead(VOID)
+{
+    /* Read RTC value */
+    return READ_REGISTER_ULONG(PL031_RTC_DR);
+}
 /* EOF */
index 3c44c2d..7bc86dd 100755 (executable)
@@ -6,6 +6,16 @@
  * PROGRAMMERS:     ReactOS Portable Systems Group
  */
 
+typedef struct _TIMEINFO
+{
+    USHORT Year;
+    USHORT Month;
+    USHORT Day;
+    USHORT Hour;
+    USHORT Minute;
+    USHORT Second;
+} TIMEINFO;
+
 VOID
 LlbFwPutChar(
     INT Ch
@@ -94,7 +104,7 @@ LlbFwVideoSync(
     VOID
 );
 
-VOID
+TIMEINFO*
 LlbFwGetTime(
     VOID
 );
index 1d8ad18..d82123f 100755 (executable)
@@ -104,6 +104,19 @@ LlbHwLoadOsLoaderFromRam(
     VOID
 );
 
+ULONG
+NTAPI
+LlbHwRtcRead(
+    VOID
+);
+
+//fix
+TIMEINFO*
+NTAPI
+LlbGetTime(
+    VOID
+);
+
 #ifdef _VERSATILE_
 #include "versa.h"
 #elif _OMAP3_
index bda644b..8bd44b7 100755 (executable)
@@ -11,8 +11,8 @@
 #include "ioaccess.h"
 #include "machtype.h"
 #include "osloader.h"
-#include "hw.h"
 #include "fw.h"
+#include "hw.h"
 #include "serial.h"
 #include "video.h"
 #include "keyboard.h"