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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38481 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
#include <platform/openfirmware/openfirmware.h>
|
#include <platform/openfirmware/openfirmware.h>
|
||||||
|
|
||||||
|
|
||||||
int gRTC = OF_FAILED;
|
static int sHandle = OF_FAILED;
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
@@ -30,8 +30,8 @@ init_real_time_clock(void)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
gRTC = of_open(gKernelArgs.platform_args.rtc_path);
|
sHandle = of_open(gKernelArgs.platform_args.rtc_path);
|
||||||
if (gRTC == OF_FAILED) {
|
if (sHandle == OF_FAILED) {
|
||||||
printf("%s(): Could not open RTC device!\n", __func__);
|
printf("%s(): Could not open RTC device!\n", __func__);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -39,3 +39,19 @@ init_real_time_clock(void)
|
|||||||
return B_OK;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,9 +14,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int gRTC;
|
|
||||||
|
|
||||||
status_t init_real_time_clock(void);
|
status_t init_real_time_clock(void);
|
||||||
|
bigtime_t real_time_clock_usecs(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
||||||
* Copyright 2010, Andreas Färber <[email protected]>
|
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -9,27 +8,10 @@
|
|||||||
|
|
||||||
#include <platform/openfirmware/openfirmware.h>
|
#include <platform/openfirmware/openfirmware.h>
|
||||||
|
|
||||||
#include "real_time_clock.h"
|
|
||||||
|
|
||||||
|
|
||||||
bigtime_t
|
bigtime_t
|
||||||
system_time(void)
|
system_time(void)
|
||||||
{
|
{
|
||||||
int milliseconds = of_milliseconds();
|
int result = of_milliseconds();
|
||||||
if (milliseconds == OF_FAILED)
|
return (result == OF_FAILED ? 0 : bigtime_t(result) * 1000);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user