2002-10-05 21:07:03 +04:00
|
|
|
/*
|
2004-11-18 06:08:36 +03:00
|
|
|
* Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-10-05 21:07:03 +04:00
|
|
|
|
|
|
|
|
|
|
|
#include <OS.h>
|
2004-11-18 06:08:36 +03:00
|
|
|
|
2004-11-07 04:19:27 +03:00
|
|
|
#include <string.h>
|
2004-11-18 06:08:36 +03:00
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
#include <libroot_private.h>
|
|
|
|
#include <real_time_data.h>
|
|
|
|
#include <syscalls.h>
|
|
|
|
|
2002-10-05 21:07:03 +04:00
|
|
|
|
2004-11-18 06:08:36 +03:00
|
|
|
static struct real_time_data sRealTimeDefaults = {
|
|
|
|
0,
|
2004-11-23 03:20:30 +03:00
|
|
|
100000
|
2004-11-18 06:08:36 +03:00
|
|
|
};
|
|
|
|
static struct real_time_data *sRealTimeData;
|
2004-11-06 20:34:39 +03:00
|
|
|
|
2004-11-18 06:08:36 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
__init_time(void)
|
2004-11-06 20:34:39 +03:00
|
|
|
{
|
2004-11-10 01:45:48 +03:00
|
|
|
area_id dataArea;
|
2004-11-07 04:19:27 +03:00
|
|
|
area_info info;
|
2004-11-10 01:45:48 +03:00
|
|
|
|
|
|
|
dataArea = find_area("real time data userland");
|
2004-11-18 06:08:36 +03:00
|
|
|
if (dataArea < 0 || get_area_info(dataArea, &info) < B_OK) {
|
|
|
|
syslog(LOG_ERR, "error finding real time data area: %s\n", strerror(dataArea));
|
|
|
|
sRealTimeData = &sRealTimeDefaults;
|
|
|
|
} else
|
|
|
|
sRealTimeData = (struct real_time_data *)info.address;
|
|
|
|
|
|
|
|
__arch_init_time(sRealTimeData);
|
2004-11-06 20:34:39 +03:00
|
|
|
}
|
|
|
|
|
2002-10-05 21:07:03 +04:00
|
|
|
|
|
|
|
uint32
|
|
|
|
real_time_clock(void)
|
|
|
|
{
|
2004-11-23 03:20:30 +03:00
|
|
|
return (sRealTimeData->system_time_offset + system_time()) / 1000000;
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-18 06:08:36 +03:00
|
|
|
bigtime_t
|
|
|
|
real_time_clock_usecs(void)
|
2002-10-05 21:07:03 +04:00
|
|
|
{
|
2004-11-23 03:20:30 +03:00
|
|
|
return sRealTimeData->system_time_offset + system_time();
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-18 06:08:36 +03:00
|
|
|
void
|
|
|
|
set_real_time_clock(uint32 secs)
|
2002-10-05 21:07:03 +04:00
|
|
|
{
|
2004-11-18 06:08:36 +03:00
|
|
|
_kern_set_real_time_clock(secs);
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
set_timezone(char *timezone)
|
|
|
|
{
|
|
|
|
// ToDo: set_timezone()
|
2004-11-22 03:35:22 +03:00
|
|
|
status_t err;
|
|
|
|
struct tm *tm;
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
time(&t);
|
|
|
|
tm = localtime(&t);
|
|
|
|
|
|
|
|
if ((err = _kern_set_tzspecs(tm->tm_gmtoff, tm->tm_isdst))<B_OK)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return B_OK;
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bigtime_t
|
|
|
|
set_alarm(bigtime_t when, uint32 flags)
|
|
|
|
{
|
|
|
|
// ToDo: set_alarm()
|
|
|
|
return B_ERROR;
|
|
|
|
}
|