4 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
10 * \author Bernardo Innocenti <bernie@develer.com>
12 * \brief Low-level timer module for Qt emulator (implementation).
17 *#* Revision 1.5 2006/02/21 21:28:02 bernie
18 *#* New time handling based on TIMER_TICKS_PER_SEC to support slow timers with ticks longer than 1ms.
20 *#* Revision 1.4 2006/02/17 22:24:21 bernie
21 *#* Update POSIX timer emulator.
23 *#* Revision 1.3 2006/02/10 12:34:52 bernie
24 *#* Remove spurious EXTERN_C.
26 *#* Revision 1.2 2006/01/16 03:30:21 bernie
27 *#* Make header C++ friendly.
29 *#* Revision 1.1 2005/11/27 03:58:18 bernie
30 *#* Add POSIX timer emulator.
32 *#* Revision 1.1 2005/11/27 03:06:36 bernie
33 *#* Qt timer emulation.
37 #include <cfg/compiler.h> // hptime.t
38 #include <os/hptime.h>
40 #include <signal.h> // sigaction()
41 #include <sys/time.h> // setitimer()
42 #include <string.h> // memset()
45 // Forward declaration for the user interrupt server routine.
48 /// HW dependent timer initialization.
49 static void timer_hw_init(void)
52 memset(&sa, 0, sizeof(sa));
54 // Setup interrupt callback
55 sa.sa_handler = timer_isr;
56 sigemptyset(&sa.sa_mask);
57 sigaddset(&sa.sa_mask, SIGALRM);
58 sa.sa_flags = SA_RESTART;
59 sigaction(SIGALRM, &sa, NULL);
61 // Setup POSIX realtime timer to interrupt every 1/TIMER_TICKS_PER_SEC.
62 static struct itimerval itv =
64 { 0, 1000000 / TIMER_TICKS_PER_SEC }, /* it_interval */
65 { 0, 1000000 / TIMER_TICKS_PER_SEC } /* it_value */
67 setitimer(ITIMER_REAL, &itv, NULL);
70 INLINE hptime_t timer_hw_hpread(void)