4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 1999, 2003 Bernardo Innocenti <bernie@develer.com>
36 * \brief Buzzer driver (implementation)
39 * \author Bernardo Innocenti <bernie@develer.com>
40 * \author Francesco Sacchi <batt@develer.com>
45 *#* Revision 1.19 2006/07/19 12:56:25 bernie
46 *#* Convert to new Doxygen style.
48 *#* Revision 1.18 2006/02/17 21:15:25 bernie
49 *#* Add MOD_CHECK() checks.
51 *#* Revision 1.17 2006/02/10 12:30:18 bernie
52 *#* Push interrupt protection inside hw module.
54 *#* Revision 1.16 2005/11/04 16:19:33 bernie
55 *#* buz_init(): Restore IRQ protection as in project_bko.
57 *#* Revision 1.15 2005/06/27 21:25:50 bernie
58 *#* Modularize hardware access; Port to new timer interface.
60 *#* Revision 1.14 2005/04/11 19:10:27 bernie
61 *#* Include top-level headers from cfg/ subdir.
63 *#* Revision 1.13 2005/02/18 11:20:15 bernie
64 *#* Use mware/event.h; Update copyright info.
66 *#* Revision 1.12 2004/12/13 12:07:06 bernie
67 *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
69 *#* Revision 1.11 2004/12/08 09:11:53 bernie
70 *#* Rename time_t to mtime_t.
72 *#* Revision 1.10 2004/10/03 18:38:51 bernie
73 *#* Add missing AVR header; Fix header.
75 *#* Revision 1.9 2004/09/14 21:01:25 bernie
76 *#* Use new AVR port pin names.
81 #include <hw_buzzer.h>
82 #include <drv/timer.h>
84 #include <mware/event.h>
86 #include <cfg/debug.h>
87 #include <cfg/module.h>
91 static Timer buz_timer;
92 static bool buz_timer_running;
93 static mtime_t buz_repeat_interval;
94 static mtime_t buz_repeat_duration;
98 * Turn off buzzer, called by software timer
100 static void buz_softint(void)
105 if (buz_repeat_interval)
107 /* Wait for interval time */
108 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_interval));
109 timer_add(&buz_timer);
112 buz_timer_running = false;
114 else if (buz_repeat_interval)
116 /* Wait for beep time */
118 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_duration));
119 timer_add(&buz_timer);
122 buz_timer_running = false;
127 * Beep for the specified ms time
129 void buz_beep(mtime_t time)
132 IRQ_SAVE_DISABLE(flags);
134 /* Remove the software interrupt if it was already queued */
135 if (buz_timer_running)
136 timer_abort(&buz_timer);
141 /* Add software interrupt to turn the buzzer off later */
142 buz_timer_running = true;
143 timer_setDelay(&buz_timer, ms_to_ticks(time));
144 timer_add(&buz_timer);
151 * Start buzzer repetition
153 void buz_repeat_start(mtime_t duration, mtime_t interval)
155 buz_repeat_interval = interval;
156 buz_repeat_duration = duration;
162 * Stop buzzer repetition
164 void buz_repeat_stop(void)
167 IRQ_SAVE_DISABLE(flags);
169 /* Remove the software interrupt if it was already queued */
170 if (buz_timer_running)
172 timer_abort(&buz_timer);
173 buz_timer_running = false;
176 buz_repeat_interval = 0;
193 /* Init software interrupt. */
194 timer_set_event_softint(&buz_timer, (Hook)buz_softint, 0);