xref: /haiku/src/system/libroot/os/arch/arm/time.c (revision 57c324a753e3d6b54728b520588373184f7237c2)
1*57c324a7SJerome Duval /*
2*57c324a7SJerome Duval  * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3*57c324a7SJerome Duval  * Distributed under the terms of the MIT License.
4*57c324a7SJerome Duval  */
5*57c324a7SJerome Duval 
6*57c324a7SJerome Duval #include <OS.h>
7*57c324a7SJerome Duval 
8*57c324a7SJerome Duval #include <arch_cpu.h>
9*57c324a7SJerome Duval #include <libroot_private.h>
10*57c324a7SJerome Duval #include <real_time_data.h>
11*57c324a7SJerome Duval 
12*57c324a7SJerome Duval 
13*57c324a7SJerome Duval static struct arch_real_time_data *sRealTimeData;
14*57c324a7SJerome Duval 
15*57c324a7SJerome Duval void
16*57c324a7SJerome Duval __arch_init_time(struct real_time_data *data, bool setDefaults)
17*57c324a7SJerome Duval {
18*57c324a7SJerome Duval 	sRealTimeData = &data->arch_data;
19*57c324a7SJerome Duval 
20*57c324a7SJerome Duval 	if (setDefaults) {
21*57c324a7SJerome Duval 		sRealTimeData->data[0].system_time_offset = 0;
22*57c324a7SJerome Duval 		sRealTimeData->system_time_conversion_factor = 1000000000LL;
23*57c324a7SJerome Duval 		sRealTimeData->version = 0;
24*57c324a7SJerome Duval 	}
25*57c324a7SJerome Duval 
26*57c324a7SJerome Duval 	__arm_setup_system_time(&sRealTimeData->system_time_conversion_factor);
27*57c324a7SJerome Duval }
28*57c324a7SJerome Duval 
29*57c324a7SJerome Duval 
30*57c324a7SJerome Duval bigtime_t
31*57c324a7SJerome Duval __arch_get_system_time_offset(struct real_time_data *data)
32*57c324a7SJerome Duval {
33*57c324a7SJerome Duval 	int32 version;
34*57c324a7SJerome Duval 	bigtime_t offset;
35*57c324a7SJerome Duval 	do {
36*57c324a7SJerome Duval 		version = sRealTimeData->version;
37*57c324a7SJerome Duval 		offset = sRealTimeData->data[version % 2].system_time_offset;
38*57c324a7SJerome Duval 	} while (version != sRealTimeData->version);
39*57c324a7SJerome Duval 
40*57c324a7SJerome Duval 	return offset;
41*57c324a7SJerome Duval }
42*57c324a7SJerome Duval 
43