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>
36 * \brief Buzzer driver (implementation)
39 * \author Bernie Innocenti <bernie@codewiz.org>
40 * \author Francesco Sacchi <batt@develer.com>
45 #include "hw/hw_buzzer.h"
46 #include <drv/timer.h>
48 #include <mware/event.h>
50 #include <cfg/debug.h>
51 #include <cfg/module.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;
157 /* Init software interrupt. */
158 timer_setSoftint(&buz_timer, (Hook)buz_softint, 0);