4 * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999, 2003 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See README.devlib for information.
11 * \brief Buzzer driver (implementation)
14 * \author Bernardo Innocenti <bernie@develer.com>
15 * \author Francesco Sacchi <batt@develer.com>
20 *#* Revision 1.18 2006/02/17 21:15:25 bernie
21 *#* Add MOD_CHECK() checks.
23 *#* Revision 1.17 2006/02/10 12:30:18 bernie
24 *#* Push interrupt protection inside hw module.
26 *#* Revision 1.16 2005/11/04 16:19:33 bernie
27 *#* buz_init(): Restore IRQ protection as in project_bko.
29 *#* Revision 1.15 2005/06/27 21:25:50 bernie
30 *#* Modularize hardware access; Port to new timer interface.
32 *#* Revision 1.14 2005/04/11 19:10:27 bernie
33 *#* Include top-level headers from cfg/ subdir.
35 *#* Revision 1.13 2005/02/18 11:20:15 bernie
36 *#* Use mware/event.h; Update copyright info.
38 *#* Revision 1.12 2004/12/13 12:07:06 bernie
39 *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
41 *#* Revision 1.11 2004/12/08 09:11:53 bernie
42 *#* Rename time_t to mtime_t.
44 *#* Revision 1.10 2004/10/03 18:38:51 bernie
45 *#* Add missing AVR header; Fix header.
47 *#* Revision 1.9 2004/09/14 21:01:25 bernie
48 *#* Use new AVR port pin names.
53 #include <hw_buzzer.h>
54 #include <drv/timer.h>
56 #include <mware/event.h>
58 #include <cfg/debug.h>
59 #include <cfg/module.h>
63 static Timer buz_timer;
64 static bool buz_timer_running;
65 static mtime_t buz_repeat_interval;
66 static mtime_t buz_repeat_duration;
70 * Turn off buzzer, called by software timer
72 static void buz_softint(void)
77 if (buz_repeat_interval)
79 /* Wait for interval time */
80 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_interval));
81 timer_add(&buz_timer);
84 buz_timer_running = false;
86 else if (buz_repeat_interval)
88 /* Wait for beep time */
90 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_duration));
91 timer_add(&buz_timer);
94 buz_timer_running = false;
99 * Beep for the specified ms time
101 void buz_beep(mtime_t time)
104 IRQ_SAVE_DISABLE(flags);
106 /* Remove the software interrupt if it was already queued */
107 if (buz_timer_running)
108 timer_abort(&buz_timer);
113 /* Add software interrupt to turn the buzzer off later */
114 buz_timer_running = true;
115 timer_setDelay(&buz_timer, ms_to_ticks(time));
116 timer_add(&buz_timer);
123 * Start buzzer repetition
125 void buz_repeat_start(mtime_t duration, mtime_t interval)
127 buz_repeat_interval = interval;
128 buz_repeat_duration = duration;
134 * Stop buzzer repetition
136 void buz_repeat_stop(void)
139 IRQ_SAVE_DISABLE(flags);
141 /* Remove the software interrupt if it was already queued */
142 if (buz_timer_running)
144 timer_abort(&buz_timer);
145 buz_timer_running = false;
148 buz_repeat_interval = 0;
165 /* Init software interrupt. */
166 timer_set_event_softint(&buz_timer, (Hook)buz_softint, 0);