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.15 2005/06/27 21:25:50 bernie
21 *#* Modularize hardware access; Port to new timer interface.
23 *#* Revision 1.14 2005/04/11 19:10:27 bernie
24 *#* Include top-level headers from cfg/ subdir.
26 *#* Revision 1.13 2005/02/18 11:20:15 bernie
27 *#* Use mware/event.h; Update copyright info.
29 *#* Revision 1.12 2004/12/13 12:07:06 bernie
30 *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
32 *#* Revision 1.11 2004/12/08 09:11:53 bernie
33 *#* Rename time_t to mtime_t.
35 *#* Revision 1.10 2004/10/03 18:38:51 bernie
36 *#* Add missing AVR header; Fix header.
38 *#* Revision 1.9 2004/09/14 21:01:25 bernie
39 *#* Use new AVR port pin names.
43 #include <hw_buzzer.h>
44 #include <drv/buzzer.h>
46 #include <drv/timer.h>
49 #include <mware/event.h>
51 #include <cfg/debug.h>
55 static Timer buz_timer;
56 static bool buz_timer_running;
57 static mtime_t buz_repeat_interval;
58 static mtime_t buz_repeat_duration;
62 * Turn off buzzer, called by software timer
64 static void buz_softint(void)
69 if (buz_repeat_interval)
71 /* Wait for interval time */
72 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_interval));
73 timer_add(&buz_timer);
76 buz_timer_running = false;
78 else if (buz_repeat_interval)
80 /* Wait for beep time */
82 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_duration));
83 timer_add(&buz_timer);
86 buz_timer_running = false;
91 * Beep for the specified ms time
93 void buz_beep(mtime_t time)
96 IRQ_SAVE_DISABLE(flags);
98 /* Remove the software interrupt if it was already queued */
99 if (buz_timer_running)
100 timer_abort(&buz_timer);
105 /* Add software interrupt to turn the buzzer off later */
106 buz_timer_running = true;
107 timer_setDelay(&buz_timer, ms_to_ticks(time));
108 timer_add(&buz_timer);
115 * Start buzzer repetition
117 void buz_repeat_start(mtime_t duration, mtime_t interval)
119 buz_repeat_interval = interval;
120 buz_repeat_duration = duration;
126 * Stop buzzer repetition
128 void buz_repeat_stop(void)
131 IRQ_SAVE_DISABLE(flags);
133 /* Remove the software interrupt if it was already queued */
134 if (buz_timer_running)
136 timer_abort(&buz_timer);
137 buz_timer_running = false;
140 buz_repeat_interval = 0;
155 /* Inizializza software interrupt */
156 timer_set_event_softint(&buz_timer, (Hook)buz_softint, 0);