1 /*
2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>,
4 * Frank Mehnert <fm3@os.inf.tu-dresden.de>,
5 * Michael Hohmuth <hohmuth@os.inf.tu-dresden.de>,
6 * Jork Löser <jork@os.inf.tu-dresden.de>,
7 * Lars Reuther <reuther@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 * This file is part of TUD:OS and distributed under the terms of the
10 * GNU Lesser General Public License 2.1.
11 * Please see the COPYING-LGPL-2.1 file for details.
12 */
13 /*
14 */
15
16 /*****************************************************************************
17 * libl4util/src/sleep.c *
18 * suspend thread *
19 *****************************************************************************/
20
21 #include <stdio.h>
22 #include <l4/sys/ipc.h>
23 #include <l4/sys/kdebug.h>
24 #include <l4/sys/kernel_object.h>
25 #include <l4/util/util.h>
26
l4_sleep(int ms)27 L4_CV void l4_sleep(int ms)
28 {
29 l4_timeout_t to;
30 l4_msgtag_t tag;
31 l4_utcb_t *u = l4_utcb();
32
33 if (ms != -1)
34 /* calculate timeout */
35 to = l4_timeout(L4_IPC_TIMEOUT_NEVER,l4util_micros2l4to(ms * 1000));
36 else
37 to = L4_IPC_NEVER;
38
39 tag = l4_ipc_receive(L4_INVALID_CAP, u, to);
40
41 if (l4_ipc_error(tag, u) != L4_IPC_RETIMEOUT)
42 printf("l4_sleep(): IPC error %02x\n", l4_ipc_error_code(u));
43 }
44
45
l4_usleep(int us)46 L4_CV void l4_usleep(int us)
47 {
48 l4_msgtag_t tag;
49 l4_timeout_t to;
50 l4_utcb_t *u = l4_utcb();
51
52 /* calculate timeout */
53 to = l4_timeout(L4_IPC_TIMEOUT_NEVER, l4util_micros2l4to(us));
54
55 tag = l4_ipc_sleep(to);
56
57 if (l4_ipc_error(tag, u) != L4_IPC_RETIMEOUT)
58 printf("l4_sleep(): IPC error %02x\n", l4_ipc_error_code(u));
59 }
60