[haiku-commits] r38481 - haiku/trunk/src/system/boot/platform/openfirmware

  • From: andreas.faerber@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 31 Aug 2010 20:42:57 +0200 (CEST)

Author: andreasf
Date: 2010-08-31 20:42:57 +0200 (Tue, 31 Aug 2010)
New Revision: 38481
Changeset: http://dev.haiku-os.org/changeset/38481

Modified:
   haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.cpp
   haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.h
   haiku/trunk/src/system/boot/platform/openfirmware/support.cpp
Log:
boot_loader_openfirmware: Implement real_time_clock_usecs()

Partially revert r38465 and move the code from system_time() into a new
real_time_clock_usecs() function. The system_time() implementation was correct
in relying on of_milliseconds(), as pointed out by Axel. Add the correct
function for the desired functionality.


Modified: haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.cpp
===================================================================
--- haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.cpp       
2010-08-31 17:39:06 UTC (rev 38480)
+++ haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.cpp       
2010-08-31 18:42:57 UTC (rev 38481)
@@ -15,7 +15,7 @@
 #include <platform/openfirmware/openfirmware.h>
 
 
-int gRTC = OF_FAILED;
+static int sHandle = OF_FAILED;
 
 
 status_t
@@ -30,8 +30,8 @@
                return B_ERROR;
        }
 
-       gRTC = of_open(gKernelArgs.platform_args.rtc_path);
-       if (gRTC == OF_FAILED) {
+       sHandle = of_open(gKernelArgs.platform_args.rtc_path);
+       if (sHandle == OF_FAILED) {
                printf("%s(): Could not open RTC device!\n", __func__);
                return B_ERROR;
        }
@@ -39,3 +39,19 @@
        return B_OK;
 }
 
+
+bigtime_t
+real_time_clock_usecs(void)
+{
+       if (sHandle == OF_FAILED)
+               return OF_FAILED;
+       int second, minute, hour, day, month, year;
+       if (of_call_method(sHandle, "get-time", 0, 6, &year, &month, &day,
+                       &hour, &minute, &second) == OF_FAILED)
+               return OF_FAILED;
+       int days = day;
+               // TODO: Apply algorithm from kernel
+               // to assure monotonically increasing date.
+       return (((days * 24 + hour) * 60ULL + minute) * 60ULL + second)
+               * 1000000ULL;
+}

Modified: haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.h
===================================================================
--- haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.h 
2010-08-31 17:39:06 UTC (rev 38480)
+++ haiku/trunk/src/system/boot/platform/openfirmware/real_time_clock.h 
2010-08-31 18:42:57 UTC (rev 38481)
@@ -14,9 +14,8 @@
 extern "C" {
 #endif
 
-extern int gRTC;
-
 status_t init_real_time_clock(void);
+bigtime_t real_time_clock_usecs(void);
 
 #ifdef __cplusplus
 }   // extern "C"

Modified: haiku/trunk/src/system/boot/platform/openfirmware/support.cpp
===================================================================
--- haiku/trunk/src/system/boot/platform/openfirmware/support.cpp       
2010-08-31 17:39:06 UTC (rev 38480)
+++ haiku/trunk/src/system/boot/platform/openfirmware/support.cpp       
2010-08-31 18:42:57 UTC (rev 38481)
@@ -1,6 +1,5 @@
 /*
  * Copyright 2005, Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>.
- * Copyright 2010, Andreas Färber <andreas.faerber@xxxxxx>
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 
@@ -9,27 +8,10 @@
 
 #include <platform/openfirmware/openfirmware.h>
 
-#include "real_time_clock.h"
 
-
 bigtime_t
 system_time(void)
 {
-       int milliseconds = of_milliseconds();
-       if (milliseconds == OF_FAILED)
-               milliseconds = 0;
-       bigtime_t result = milliseconds;
-       int second, minute, hour, day, month, year;
-       if (gRTC != OF_FAILED) {
-               if (of_call_method(gRTC, "get-time", 0, 6, &year, &month, &day,
-                               &hour, &minute, &second) != OF_FAILED) {
-                       result %= 1000;
-                       int days = day;
-                               // TODO: Apply algorithm from kernel
-                               // to assure monotonically increasing date.
-                       result += (((days * 24 + hour) * 60ULL + minute) * 
60ULL + second)
-                               * 1000ULL;
-               }
-       }
-       return result * 1000;
+       int result = of_milliseconds();
+       return (result == OF_FAILED ? 0 : bigtime_t(result) * 1000);
 }


Other related posts:

  • » [haiku-commits] r38481 - haiku/trunk/src/system/boot/platform/openfirmware - andreas . faerber