2 ** Copyright 2003, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <kernel/kernel.h>
6 #include <kernel/debug.h>
7 #include <kernel/time.h>
8 #include <kernel/arch/time.h>
11 // The 'rough' counter of system up time, accurate to the rate at
12 // which the timer interrupts run (see TICK_RATE in timer.c).
13 static bigtime_t sys_time
;
15 // The delta of usecs that needs to be added to sys_time to get real time
16 static bigtime_t real_time_delta
;
18 // Any additional delta that might need to be added to the above two values
19 // to get real time. (in case the RTC isn't in UTC)
20 static bigtime_t tz_delta
;
22 // The current name of the timezone, saved for all to see
23 static char tz_name
[SYS_MAX_NAME_LEN
];
25 int time_init(kernel_args
*ka
)
27 dprintf("time_init: entry\n");
32 strcpy(tz_name
, "UTC");
34 return arch_time_init(ka
);
37 int time_init2(kernel_args
*ka
)
39 real_time_delta
= arch_get_rtc_delta();
44 void time_tick(int tick_rate
)
46 sys_time
+= tick_rate
;
50 bigtime_t
system_time(void)
52 volatile bigtime_t
*st
= &sys_time
;
56 // read the system time, make sure we didn't get a partial read
61 // ask the architectural specific layer to give us a little better precision if it can
62 val
+= arch_get_time_delta();
67 bigtime_t
system_time_lores(void)
69 volatile bigtime_t
*st
= &sys_time
;
73 // read the system time, make sure we didn't get a partial read
81 bigtime_t
local_time(void)
83 return system_time() + real_time_delta
+ tz_delta
;