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.16 2005/11/04 16:19:33 bernie
21 *#* buz_init(): Restore IRQ protection as in project_bko.
23 *#* Revision 1.15 2005/06/27 21:25:50 bernie
24 *#* Modularize hardware access; Port to new timer interface.
26 *#* Revision 1.14 2005/04/11 19:10:27 bernie
27 *#* Include top-level headers from cfg/ subdir.
29 *#* Revision 1.13 2005/02/18 11:20:15 bernie
30 *#* Use mware/event.h; Update copyright info.
32 *#* Revision 1.12 2004/12/13 12:07:06 bernie
33 *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
35 *#* Revision 1.11 2004/12/08 09:11:53 bernie
36 *#* Rename time_t to mtime_t.
38 *#* Revision 1.10 2004/10/03 18:38:51 bernie
39 *#* Add missing AVR header; Fix header.
41 *#* Revision 1.9 2004/09/14 21:01:25 bernie
42 *#* Use new AVR port pin names.
46 #include <hw_buzzer.h>
47 #include <drv/buzzer.h>
49 #include <drv/timer.h>
52 #include <mware/event.h>
54 #include <cfg/debug.h>
58 static Timer buz_timer;
59 static bool buz_timer_running;
60 static mtime_t buz_repeat_interval;
61 static mtime_t buz_repeat_duration;
65 * Turn off buzzer, called by software timer
67 static void buz_softint(void)
72 if (buz_repeat_interval)
74 /* Wait for interval time */
75 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_interval));
76 timer_add(&buz_timer);
79 buz_timer_running = false;
81 else if (buz_repeat_interval)
83 /* Wait for beep time */
85 timer_setDelay(&buz_timer, ms_to_ticks(buz_repeat_duration));
86 timer_add(&buz_timer);
89 buz_timer_running = false;
94 * Beep for the specified ms time
96 void buz_beep(mtime_t time)
99 IRQ_SAVE_DISABLE(flags);
101 /* Remove the software interrupt if it was already queued */
102 if (buz_timer_running)
103 timer_abort(&buz_timer);
108 /* Add software interrupt to turn the buzzer off later */
109 buz_timer_running = true;
110 timer_setDelay(&buz_timer, ms_to_ticks(time));
111 timer_add(&buz_timer);
118 * Start buzzer repetition
120 void buz_repeat_start(mtime_t duration, mtime_t interval)
122 buz_repeat_interval = interval;
123 buz_repeat_duration = duration;
129 * Stop buzzer repetition
131 void buz_repeat_stop(void)
134 IRQ_SAVE_DISABLE(flags);
136 /* Remove the software interrupt if it was already queued */
137 if (buz_timer_running)
139 timer_abort(&buz_timer);
140 buz_timer_running = false;
143 buz_repeat_interval = 0;
156 IRQ_SAVE_DISABLE(flags);
162 /* Init software interrupt. */
163 timer_set_event_softint(&buz_timer, (Hook)buz_softint, 0);