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.17 2006/02/10 12:30:18 bernie
21 *#* Push interrupt protection inside hw module.
23 *#* Revision 1.16 2005/11/04 16:19:33 bernie
24 *#* buz_init(): Restore IRQ protection as in project_bko.
26 *#* Revision 1.15 2005/06/27 21:25:50 bernie
27 *#* Modularize hardware access; Port to new timer interface.
29 *#* Revision 1.14 2005/04/11 19:10:27 bernie
30 *#* Include top-level headers from cfg/ subdir.
32 *#* Revision 1.13 2005/02/18 11:20:15 bernie
33 *#* Use mware/event.h; Update copyright info.
35 *#* Revision 1.12 2004/12/13 12:07:06 bernie
36 *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
38 *#* Revision 1.11 2004/12/08 09:11:53 bernie
39 *#* Rename time_t to mtime_t.
41 *#* Revision 1.10 2004/10/03 18:38:51 bernie
42 *#* Add missing AVR header; Fix header.
44 *#* Revision 1.9 2004/09/14 21:01:25 bernie
45 *#* Use new AVR port pin names.
50 #include <hw_buzzer.h>
51 #include <drv/timer.h>
53 #include <mware/event.h>
55 #include <cfg/debug.h>
59 static Timer buz_timer;
60 static bool buz_timer_running;
61 static mtime_t buz_repeat_interval;
62 static mtime_t buz_repeat_duration;
66 * Turn off buzzer, called by software timer
68 static void buz_softint(void)
73 if (buz_repeat_interval)
75 /* Wait for interval time */
76 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_interval));
77 timer_add(&buz_timer);
80 buz_timer_running = false;
82 else if (buz_repeat_interval)
84 /* Wait for beep time */
86 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_duration));
87 timer_add(&buz_timer);
90 buz_timer_running = false;
95 * Beep for the specified ms time
97 void buz_beep(mtime_t time)
100 IRQ_SAVE_DISABLE(flags);
102 /* Remove the software interrupt if it was already queued */
103 if (buz_timer_running)
104 timer_abort(&buz_timer);
109 /* Add software interrupt to turn the buzzer off later */
110 buz_timer_running = true;
111 timer_setDelay(&buz_timer, ms_to_ticks(time));
112 timer_add(&buz_timer);
119 * Start buzzer repetition
121 void buz_repeat_start(mtime_t duration, mtime_t interval)
123 buz_repeat_interval = interval;
124 buz_repeat_duration = duration;
130 * Stop buzzer repetition
132 void buz_repeat_stop(void)
135 IRQ_SAVE_DISABLE(flags);
137 /* Remove the software interrupt if it was already queued */
138 if (buz_timer_running)
140 timer_abort(&buz_timer);
141 buz_timer_running = false;
144 buz_repeat_interval = 0;
158 /* Init software interrupt. */
159 timer_set_event_softint(&buz_timer, (Hook)buz_softint, 0);