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.1 2005/11/27 03:04:08 bernie
17 *#* Move test code to timer_test.c; Add OS_HOSTED support.
22 #include "mware/event.c"
24 static void timer_test_constants(void)
26 kprintf("TIMER_HW_HPTICKS_PER_SEC=%lu\n", TIMER_HW_HPTICKS_PER_SEC);
27 #ifdef TIMER_PRESCALER
28 kprintf("TIMER_PRESCALER=%d\n", TIMER_PRESCALER);
30 #ifdef TIMER1_OVF_COUNT
31 kprintf("TIMER1_OVF_COUNT=%d\n", (int)TIMER1_OVF_COUNT);
33 kprintf("TIMER_TICKS_PER_MSEC=%d\n", (int)TIMER_TICKS_PER_MSEC);
35 kprintf("ms_to_ticks(100)=%lu\n", ms_to_ticks(100));
36 kprintf("ms_to_ticks(10000)=%lu\n", ms_to_ticks(10000));
37 kprintf("us_to_ticks(100)=%lu\n", us_to_ticks(100));
38 kprintf("us_to_ticks(10000)=%lu\n", us_to_ticks(10000));
40 kprintf("ticks_to_ms(100)=%lu\n", ticks_to_ms(100));
41 kprintf("ticks_to_ms(10000)=%lu\n", ticks_to_ms(10000));
42 kprintf("ticks_to_us(100)=%lu\n", ticks_to_us(100));
43 kprintf("ticks_to_us(10000)=%lu\n", ticks_to_us(10000));
45 kprintf("hptime_to_us(100)=%lu\n", hptime_to_us(100));
46 kprintf("hptime_to_us(10000)=%lu\n", hptime_to_us(10000));
47 kprintf("us_to_hptime(100)=%lu\n", us_to_hptime(100));
48 kprintf("us_to_hptime(10000)=%lu\n", us_to_hptime(10000));
51 static void timer_test_delay(void)
55 kputs("Delay test\n");
56 for (i = 0; i < 1000; i += 100)
58 kprintf("delay %d...", i);
64 static void timer_test_hook(iptr_t _timer)
66 Timer *timer = (Timer *)(void *)_timer;
68 kprintf("Timer %ld expired\n", ticks_to_ms(timer->_delay));
72 static void timer_test_async(void)
74 static Timer test_timers[5];
75 static const mtime_t test_delays[5] = { 170, 50, 310, 1500, 310 };
78 for (i = 0; i < countof(test_timers); ++i)
80 Timer *timer = &test_timers[i];
81 timer_setDelay(timer, ms_to_ticks(test_delays[i]));
82 timer_set_event_softint(timer, timer_test_hook, (iptr_t)timer);
87 static void timer_test_poll(void)
90 mtime_t start_time = ticks_to_ms(timer_clock());
95 now = ticks_to_ms(timer_clock());
96 if (now - start_time >= 1000)
100 kprintf("seconds = %d, ticks=%ld\n", secs, now);
110 timer_test_constants();