2002-10-05 21:07:03 +04:00
|
|
|
/*
|
2003-10-28 16:29:29 +03:00
|
|
|
** Copyright 2002-2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
2002-10-05 21:07:03 +04:00
|
|
|
** Distributed under the terms of the OpenBeOS License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <OS.h>
|
2004-11-07 04:19:27 +03:00
|
|
|
#include <string.h>
|
2002-10-05 21:07:03 +04:00
|
|
|
#include "syscalls.h"
|
2004-11-09 15:51:59 +03:00
|
|
|
#include "real_time_data.h"
|
2002-10-05 21:07:03 +04:00
|
|
|
|
2004-11-06 20:34:39 +03:00
|
|
|
static volatile bigtime_t *sBootTime = NULL;
|
|
|
|
|
2004-11-09 15:51:59 +03:00
|
|
|
static status_t
|
|
|
|
setup_rtc_boottime()
|
2004-11-06 20:34:39 +03:00
|
|
|
{
|
2004-11-09 15:51:59 +03:00
|
|
|
area_id dataArea = find_area("real time data userland");
|
2004-11-07 04:19:27 +03:00
|
|
|
area_info info;
|
|
|
|
status_t err;
|
|
|
|
|
2004-11-09 15:51:59 +03:00
|
|
|
if (dataArea < 0) {
|
|
|
|
printf("setup_rtc_boottime: error finding real time data area %s\n",
|
|
|
|
strerror(dataArea));
|
|
|
|
return dataArea;
|
2004-11-06 20:34:39 +03:00
|
|
|
}
|
2004-11-07 04:19:27 +03:00
|
|
|
|
2004-11-09 15:51:59 +03:00
|
|
|
err = get_area_info(dataArea, &info);
|
2004-11-07 04:19:27 +03:00
|
|
|
if (err < B_OK) {
|
2004-11-09 15:51:59 +03:00
|
|
|
printf("setup_rtc_boottime: error getting real time data info\n");
|
2004-11-07 04:19:27 +03:00
|
|
|
return err;
|
2004-11-06 20:34:39 +03:00
|
|
|
}
|
2004-11-09 15:51:59 +03:00
|
|
|
sBootTime = &((struct real_time_data *)info.address)->boot_time;
|
2004-11-06 20:34:39 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
2002-10-05 21:07:03 +04:00
|
|
|
|
|
|
|
uint32
|
|
|
|
real_time_clock(void)
|
|
|
|
{
|
2004-11-09 15:51:59 +03:00
|
|
|
if (!sBootTime && (setup_rtc_boottime()!=B_OK))
|
2004-11-07 04:19:27 +03:00
|
|
|
return 0;
|
|
|
|
return (*sBootTime + system_time()) / 1000000;
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2003-10-28 16:13:35 +03:00
|
|
|
set_real_time_clock(uint32 secs)
|
2002-10-05 21:07:03 +04:00
|
|
|
{
|
2003-10-28 16:29:29 +03:00
|
|
|
_kern_set_real_time_clock(secs);
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bigtime_t
|
|
|
|
real_time_clock_usecs(void)
|
|
|
|
{
|
2004-11-09 15:51:59 +03:00
|
|
|
if (!sBootTime && (setup_rtc_boottime() != B_OK))
|
2004-11-07 04:19:27 +03:00
|
|
|
return 0;
|
|
|
|
return *sBootTime + system_time();
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
set_timezone(char *timezone)
|
|
|
|
{
|
|
|
|
// ToDo: set_timezone()
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-17 23:30:59 +04:00
|
|
|
/*
|
|
|
|
// ToDo: currently defined in atomic.S - but should be in its own file time.S
|
2002-10-05 21:07:03 +04:00
|
|
|
bigtime_t
|
|
|
|
system_time(void)
|
|
|
|
{
|
2002-10-17 23:30:59 +04:00
|
|
|
// time since booting in microseconds
|
2002-10-05 21:07:03 +04:00
|
|
|
return sys_system_time();
|
|
|
|
}
|
2002-10-17 23:30:59 +04:00
|
|
|
*/
|
2002-10-05 21:07:03 +04:00
|
|
|
|
|
|
|
|
|
|
|
bigtime_t
|
|
|
|
set_alarm(bigtime_t when, uint32 flags)
|
|
|
|
{
|
|
|
|
// ToDo: set_alarm()
|
|
|
|
return B_ERROR;
|
|
|
|
}
|