4 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
8 * \brief Hardware independent timer driver (implementation)
11 * \author Bernardo Innocenti <bernie@develer.com>
16 *#* Revision 1.2 2005/11/27 03:58:18 bernie
17 *#* Add POSIX timer emulator.
19 *#* Revision 1.1 2005/11/27 03:04:08 bernie
20 *#* Move test code to timer_test.c; Add OS_HOSTED support.
25 #include "mware/event.c"
26 #include "os/hptime.c"
28 static void timer_test_constants(void)
30 kprintf("TIMER_HW_HPTICKS_PER_SEC=%lu\n", TIMER_HW_HPTICKS_PER_SEC);
31 #ifdef TIMER_PRESCALER
32 kprintf("TIMER_PRESCALER=%d\n", TIMER_PRESCALER);
34 #ifdef TIMER1_OVF_COUNT
35 kprintf("TIMER1_OVF_COUNT=%d\n", (int)TIMER1_OVF_COUNT);
37 kprintf("TIMER_TICKS_PER_MSEC=%d\n", (int)TIMER_TICKS_PER_MSEC);
39 kprintf("ms_to_ticks(100)=%lu\n", ms_to_ticks(100));
40 kprintf("ms_to_ticks(10000)=%lu\n", ms_to_ticks(10000));
41 kprintf("us_to_ticks(100)=%lu\n", us_to_ticks(100));
42 kprintf("us_to_ticks(10000)=%lu\n", us_to_ticks(10000));
44 kprintf("ticks_to_ms(100)=%lu\n", ticks_to_ms(100));
45 kprintf("ticks_to_ms(10000)=%lu\n", ticks_to_ms(10000));
46 kprintf("ticks_to_us(100)=%lu\n", ticks_to_us(100));
47 kprintf("ticks_to_us(10000)=%lu\n", ticks_to_us(10000));
49 kprintf("hptime_to_us(100)=%lu\n", hptime_to_us(100));
50 kprintf("hptime_to_us(10000)=%lu\n", hptime_to_us(10000));
51 kprintf("us_to_hptime(100)=%lu\n", us_to_hptime(100));
52 kprintf("us_to_hptime(10000)=%lu\n", us_to_hptime(10000));
55 static void timer_test_delay(void)
59 kputs("Delay test\n");
60 for (i = 0; i < 1000; i += 100)
62 kprintf("delay %d...", i);
68 static void timer_test_hook(iptr_t _timer)
70 Timer *timer = (Timer *)(void *)_timer;
72 kprintf("Timer %ld expired\n", ticks_to_ms(timer->_delay));
76 static void timer_test_async(void)
78 static Timer test_timers[5];
79 static const mtime_t test_delays[5] = { 170, 50, 310, 1500, 310 };
82 for (i = 0; i < countof(test_timers); ++i)
84 Timer *timer = &test_timers[i];
85 timer_setDelay(timer, ms_to_ticks(test_delays[i]));
86 timer_set_event_softint(timer, timer_test_hook, (iptr_t)timer);
91 static void timer_test_poll(void)
94 mtime_t start_time = ticks_to_ms(timer_clock());
99 now = ticks_to_ms(timer_clock());
100 if (now - start_time >= 1000)
104 kprintf("seconds = %d, ticks=%ld\n", secs, now);
114 timer_test_constants();