Ticket #6061: 0004-system_time-Use-get-time-on-rtc-device.patch

File 0004-system_time-Use-get-time-on-rtc-device.patch, 1.5 KB (added by andreasf, 14 years ago)

proposed patch: Use get-time on rtc device

  • src/system/boot/platform/openfirmware/support.cpp

    From 23c8e2d9b45a682045c13d73c47bfa33af9b7d6b Mon Sep 17 00:00:00 2001
    From: Andreas Faerber <andreas.faerber@web.de>
    Date: Sun, 23 May 2010 15:05:20 +0200
    Subject: [PATCH 4/4] system_time: Use get-time on rtc device
    
    ---
     src/system/boot/platform/openfirmware/support.cpp |   18 +++++++++++++++++-
     1 files changed, 17 insertions(+), 1 deletions(-)
    
    diff --git a/src/system/boot/platform/openfirmware/support.cpp b/src/system/boot/platform/openfirmware/support.cpp
    index 1f8b95e..80b6c10 100644
    a b  
    11/*
    22 * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
     3 * Copyright 2010, Andreas Faerber <andreas.faerber@web.de>
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56
    system_time(void)  
    1415    if (milliseconds == OF_FAILED) {
    1516        milliseconds = of_get_msecs();
    1617    }
    17     return (milliseconds == OF_FAILED ? 0 : bigtime_t(milliseconds) * 1000);
     18    if (milliseconds == OF_FAILED) {
     19        milliseconds = 0;
     20    }
     21    bigtime_t result = milliseconds;
     22    int second, minute, hour, day, month, year;
     23    int handle = of_open("rtc");
     24    if (handle != OF_FAILED) {
     25        if (of_call_method(handle, "get-time", 0, 6, &year, &month, &day,
     26                &hour, &minute, &second) != OF_FAILED) {
     27            result %= 1000;
     28            int days = day; // sufficient for now
     29            result += (((days * 24 + hour) * 60ULL + minute) * 60ULL + second) * 1000ULL;
     30        }
     31        of_close(handle);
     32    }
     33    return result * 1000ULL;
    1834}