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
|
|
|
|
2006-01-04 05:17:59 +03:00
|
|
|
static struct real_time_data sRealTimeDefaults;
|
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
|
|
|
{
|
2006-01-04 05:17:59 +03:00
|
|
|
bool setDefaults = false;
|
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;
|
2006-01-04 05:17:59 +03:00
|
|
|
setDefaults = true;
|
2004-11-18 06:08:36 +03:00
|
|
|
} else
|
|
|
|
sRealTimeData = (struct real_time_data *)info.address;
|
|
|
|
|
2006-01-04 05:17:59 +03:00
|
|
|
__arch_init_time(sRealTimeData, setDefaults);
|
2004-11-06 20:34:39 +03:00
|
|
|
}
|
|
|
|
|
2002-10-05 21:07:03 +04:00
|
|
|
|
|
|
|
uint32
|
|
|
|
real_time_clock(void)
|
|
|
|
{
|
2006-01-04 05:17:59 +03:00
|
|
|
return (__arch_get_system_time_offset(sRealTimeData) + 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
|
|
|
{
|
2006-01-04 05:17:59 +03:00
|
|
|
return __arch_get_system_time_offset(sRealTimeData) + 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);
|
|
|
|
|
2004-11-26 18:04:16 +03:00
|
|
|
if ((err = _kern_set_timezone(tm->tm_gmtoff, tm->tm_isdst)) < B_OK)
|
2004-11-22 03:35:22 +03:00
|
|
|
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;
|
|
|
|
}
|