]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/rtc/server/src/ux.c
update
[l4.git] / l4 / pkg / rtc / server / src / ux.c
1 /**
2  * \file    rtc/server/src/ux.c
3  * \brief   Get current time
4  *
5  * \date    09/26/2003
6  * \author  Adam Lackorzynski <adam@os.inf.tu-dresden.de> */
7
8 /*
9  * (c) 2003-2009 Author(s)
10  *     economic rights: Technische Universität Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  */
16
17 #include <l4/lxfuxlibc/lxfuxlc.h>
18
19 #include <l4/sys/thread.h>
20 #include <l4/re/env.h>
21 #include <l4/util/rdtsc.h>
22 #include <l4/util/kip.h>
23
24 #include <time.h>
25 #include <stdio.h>
26
27 #include "rtc.h"
28
29 static void printit(void)
30 {
31   time_t t = lx_time(NULL);
32   struct tm *r;
33
34   r = gmtime(&t);
35
36   printf("Date:%02d.%02d.%04d Time:%02d:%02d:%02d\n",
37          r->tm_mday, r->tm_mon + 1, r->tm_year + 1900,
38          r->tm_hour, r->tm_min, r->tm_sec);
39 }
40
41 static int
42 get_base_time_ux(void)
43 {
44   l4_uint32_t current_s, current_ns;
45
46   l4_tsc_to_s_and_ns(l4_rdtsc(), &current_s, &current_ns);
47   system_time_offs_rel_1970 = lx_time(NULL) - current_s;
48
49   printit();
50
51   return 0;
52 }
53
54 get_base_time_func_t init_ux(void)
55 {
56   if (l4util_kip_kernel_is_ux(l4re_kip()))
57     {
58       l4_thread_control_start();
59       l4_thread_control_ux_host_syscall(1);
60       l4_thread_control_commit(l4re_env()->main_thread);
61       return get_base_time_ux;
62     }
63
64   return NULL;
65 }