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.4 2006/07/19 12:56:26 bernie
17 *#* Convert to new Doxygen style.
19 *#* Revision 1.3 2006/02/21 21:28:02 bernie
20 *#* New time handling based on TIMER_TICKS_PER_SEC to support slow timers with ticks longer than 1ms.
22 *#* Revision 1.2 2005/11/27 03:58:18 bernie
23 *#* Add POSIX timer emulator.
25 *#* Revision 1.1 2005/11/27 03:04:08 bernie
26 *#* Move test code to timer_test.c; Add OS_HOSTED support.
31 #include "mware/event.c"
32 #include "os/hptime.c"
34 static void timer_test_constants(void)
36 kprintf("TIMER_HW_HPTICKS_PER_SEC=%lu\n", TIMER_HW_HPTICKS_PER_SEC);
37 #ifdef TIMER_PRESCALER
38 kprintf("TIMER_PRESCALER=%d\n", TIMER_PRESCALER);
40 #ifdef TIMER1_OVF_COUNT
41 kprintf("TIMER1_OVF_COUNT=%d\n", (int)TIMER1_OVF_COUNT);
43 kprintf("TIMER_TICKS_PER_SEC=%d\n", (int)TIMER_TICKS_PER_SEC);
45 kprintf("ms_to_ticks(100)=%lu\n", ms_to_ticks(100));
46 kprintf("ms_to_ticks(10000)=%lu\n", ms_to_ticks(10000));
47 kprintf("us_to_ticks(100)=%lu\n", us_to_ticks(100));
48 kprintf("us_to_ticks(10000)=%lu\n", us_to_ticks(10000));
50 kprintf("ticks_to_ms(100)=%lu\n", ticks_to_ms(100));
51 kprintf("ticks_to_ms(10000)=%lu\n", ticks_to_ms(10000));
52 kprintf("ticks_to_us(100)=%lu\n", ticks_to_us(100));
53 kprintf("ticks_to_us(10000)=%lu\n", ticks_to_us(10000));
55 kprintf("hptime_to_us(100)=%lu\n", hptime_to_us(100));
56 kprintf("hptime_to_us(10000)=%lu\n", hptime_to_us(10000));
57 kprintf("us_to_hptime(100)=%lu\n", us_to_hptime(100));
58 kprintf("us_to_hptime(10000)=%lu\n", us_to_hptime(10000));
61 static void timer_test_delay(void)
65 kputs("Delay test\n");
66 for (i = 0; i < 1000; i += 100)
68 kprintf("delay %d...", i);
74 static void timer_test_hook(iptr_t _timer)
76 Timer *timer = (Timer *)(void *)_timer;
78 kprintf("Timer %ld expired\n", ticks_to_ms(timer->_delay));
82 static void timer_test_async(void)
84 static Timer test_timers[5];
85 static const mtime_t test_delays[5] = { 170, 50, 310, 1500, 310 };
88 for (i = 0; i < countof(test_timers); ++i)
90 Timer *timer = &test_timers[i];
91 timer_setDelay(timer, ms_to_ticks(test_delays[i]));
92 timer_set_event_softint(timer, timer_test_hook, (iptr_t)timer);
97 static void timer_test_poll(void)
100 mtime_t start_time = ticks_to_ms(timer_clock());
105 now = ticks_to_ms(timer_clock());
106 if (now - start_time >= 1000)
110 kprintf("seconds = %d, ticks=%ld\n", secs, now);
120 timer_test_constants();