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 Bernie Innocenti <bernie@codewiz.org>
34 * \brief Buzzer driver (implementation)
36 * \author Bernie Innocenti <bernie@codewiz.org>
37 * \author Francesco Sacchi <batt@develer.com>
42 #include "hw/hw_buzzer.h"
43 #include <drv/timer.h>
45 #include <mware/event.h>
47 #include <cfg/debug.h>
48 #include <cfg/module.h>
52 static Timer buz_timer;
53 static bool buz_timer_running;
54 static mtime_t buz_repeat_interval;
55 static mtime_t buz_repeat_duration;
59 * Turn off buzzer, called by software timer
61 static void buz_softint(void)
66 if (buz_repeat_interval)
68 /* Wait for interval time */
69 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_interval));
70 timer_add(&buz_timer);
73 buz_timer_running = false;
75 else if (buz_repeat_interval)
77 /* Wait for beep time */
79 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_duration));
80 timer_add(&buz_timer);
83 buz_timer_running = false;
88 * Beep for the specified ms time
90 void buz_beep(mtime_t time)
93 IRQ_SAVE_DISABLE(flags);
95 /* Remove the software interrupt if it was already queued */
96 if (buz_timer_running)
97 timer_abort(&buz_timer);
102 /* Add software interrupt to turn the buzzer off later */
103 buz_timer_running = true;
104 timer_setDelay(&buz_timer, ms_to_ticks(time));
105 timer_add(&buz_timer);
112 * Start buzzer repetition
114 void buz_repeat_start(mtime_t duration, mtime_t interval)
116 buz_repeat_interval = interval;
117 buz_repeat_duration = duration;
123 * Stop buzzer repetition
125 void buz_repeat_stop(void)
128 IRQ_SAVE_DISABLE(flags);
130 /* Remove the software interrupt if it was already queued */
131 if (buz_timer_running)
133 timer_abort(&buz_timer);
134 buz_timer_running = false;
137 buz_repeat_interval = 0;
154 /* Init software interrupt. */
155 timer_setSoftint(&buz_timer, (Hook)buz_softint, 0);