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.19 2006/07/19 12:56:25 bernie
21 *#* Convert to new Doxygen style.
23 *#* Revision 1.18 2006/02/17 21:15:25 bernie
24 *#* Add MOD_CHECK() checks.
26 *#* Revision 1.17 2006/02/10 12:30:18 bernie
27 *#* Push interrupt protection inside hw module.
29 *#* Revision 1.16 2005/11/04 16:19:33 bernie
30 *#* buz_init(): Restore IRQ protection as in project_bko.
32 *#* Revision 1.15 2005/06/27 21:25:50 bernie
33 *#* Modularize hardware access; Port to new timer interface.
35 *#* Revision 1.14 2005/04/11 19:10:27 bernie
36 *#* Include top-level headers from cfg/ subdir.
38 *#* Revision 1.13 2005/02/18 11:20:15 bernie
39 *#* Use mware/event.h; Update copyright info.
41 *#* Revision 1.12 2004/12/13 12:07:06 bernie
42 *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
44 *#* Revision 1.11 2004/12/08 09:11:53 bernie
45 *#* Rename time_t to mtime_t.
47 *#* Revision 1.10 2004/10/03 18:38:51 bernie
48 *#* Add missing AVR header; Fix header.
50 *#* Revision 1.9 2004/09/14 21:01:25 bernie
51 *#* Use new AVR port pin names.
56 #include <hw_buzzer.h>
57 #include <drv/timer.h>
59 #include <mware/event.h>
61 #include <cfg/debug.h>
62 #include <cfg/module.h>
66 static Timer buz_timer;
67 static bool buz_timer_running;
68 static mtime_t buz_repeat_interval;
69 static mtime_t buz_repeat_duration;
73 * Turn off buzzer, called by software timer
75 static void buz_softint(void)
80 if (buz_repeat_interval)
82 /* Wait for interval time */
83 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_interval));
84 timer_add(&buz_timer);
87 buz_timer_running = false;
89 else if (buz_repeat_interval)
91 /* Wait for beep time */
93 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_duration));
94 timer_add(&buz_timer);
97 buz_timer_running = false;
102 * Beep for the specified ms time
104 void buz_beep(mtime_t time)
107 IRQ_SAVE_DISABLE(flags);
109 /* Remove the software interrupt if it was already queued */
110 if (buz_timer_running)
111 timer_abort(&buz_timer);
116 /* Add software interrupt to turn the buzzer off later */
117 buz_timer_running = true;
118 timer_setDelay(&buz_timer, ms_to_ticks(time));
119 timer_add(&buz_timer);
126 * Start buzzer repetition
128 void buz_repeat_start(mtime_t duration, mtime_t interval)
130 buz_repeat_interval = interval;
131 buz_repeat_duration = duration;
137 * Stop buzzer repetition
139 void buz_repeat_stop(void)
142 IRQ_SAVE_DISABLE(flags);
144 /* Remove the software interrupt if it was already queued */
145 if (buz_timer_running)
147 timer_abort(&buz_timer);
148 buz_timer_running = false;
151 buz_repeat_interval = 0;
168 /* Init software interrupt. */
169 timer_set_event_softint(&buz_timer, (Hook)buz_softint, 0);