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.3 2006/02/21 21:28:02 bernie
17 *#* New time handling based on TIMER_TICKS_PER_SEC to support slow timers with ticks longer than 1ms.
19 *#* Revision 1.2 2005/11/27 03:58:18 bernie
20 *#* Add POSIX timer emulator.
22 *#* Revision 1.1 2005/11/27 03:04:08 bernie
23 *#* Move test code to timer_test.c; Add OS_HOSTED support.
28 #include "mware/event.c"
29 #include "os/hptime.c"
31 static void timer_test_constants(void)
33 kprintf("TIMER_HW_HPTICKS_PER_SEC=%lu\n", TIMER_HW_HPTICKS_PER_SEC);
34 #ifdef TIMER_PRESCALER
35 kprintf("TIMER_PRESCALER=%d\n", TIMER_PRESCALER);
37 #ifdef TIMER1_OVF_COUNT
38 kprintf("TIMER1_OVF_COUNT=%d\n", (int)TIMER1_OVF_COUNT);
40 kprintf("TIMER_TICKS_PER_SEC=%d\n", (int)TIMER_TICKS_PER_SEC);
42 kprintf("ms_to_ticks(100)=%lu\n", ms_to_ticks(100));
43 kprintf("ms_to_ticks(10000)=%lu\n", ms_to_ticks(10000));
44 kprintf("us_to_ticks(100)=%lu\n", us_to_ticks(100));
45 kprintf("us_to_ticks(10000)=%lu\n", us_to_ticks(10000));
47 kprintf("ticks_to_ms(100)=%lu\n", ticks_to_ms(100));
48 kprintf("ticks_to_ms(10000)=%lu\n", ticks_to_ms(10000));
49 kprintf("ticks_to_us(100)=%lu\n", ticks_to_us(100));
50 kprintf("ticks_to_us(10000)=%lu\n", ticks_to_us(10000));
52 kprintf("hptime_to_us(100)=%lu\n", hptime_to_us(100));
53 kprintf("hptime_to_us(10000)=%lu\n", hptime_to_us(10000));
54 kprintf("us_to_hptime(100)=%lu\n", us_to_hptime(100));
55 kprintf("us_to_hptime(10000)=%lu\n", us_to_hptime(10000));
58 static void timer_test_delay(void)
62 kputs("Delay test\n");
63 for (i = 0; i < 1000; i += 100)
65 kprintf("delay %d...", i);
71 static void timer_test_hook(iptr_t _timer)
73 Timer *timer = (Timer *)(void *)_timer;
75 kprintf("Timer %ld expired\n", ticks_to_ms(timer->_delay));
79 static void timer_test_async(void)
81 static Timer test_timers[5];
82 static const mtime_t test_delays[5] = { 170, 50, 310, 1500, 310 };
85 for (i = 0; i < countof(test_timers); ++i)
87 Timer *timer = &test_timers[i];
88 timer_setDelay(timer, ms_to_ticks(test_delays[i]));
89 timer_set_event_softint(timer, timer_test_hook, (iptr_t)timer);
94 static void timer_test_poll(void)
97 mtime_t start_time = ticks_to_ms(timer_clock());
102 now = ticks_to_ms(timer_clock());
103 if (now - start_time >= 1000)
107 kprintf("seconds = %d, ticks=%ld\n", secs, now);
117 timer_test_constants();