buzzerled.c

Go to the documentation of this file.
00001 
00053 /*#*
00054  *#* $Log$
00055  *#* Revision 1.7  2006/07/19 12:56:25  bernie
00056  *#* Convert to new Doxygen style.
00057  *#*
00058  *#* Revision 1.6  2005/11/04 16:20:02  bernie
00059  *#* Fix reference to README.devlib in header.
00060  *#*
00061  *#* Revision 1.5  2004/12/08 09:43:41  bernie
00062  *#* Add a todo item.
00063  *#*
00064  *#* Revision 1.4  2004/08/25 14:12:08  rasky
00065  *#* Aggiornato il comment block dei log RCS
00066  *#*
00067  *#* Revision 1.3  2004/07/14 14:04:29  rasky
00068  *#* Merge da SC: spostata bld_set inline perché si ottimizza parecchio tramite propagazione di costanti
00069  *#*
00070  *#* Revision 1.2  2004/06/03 11:27:09  bernie
00071  *#* Add dual-license information.
00072  *#*
00073  *#* Revision 1.1  2004/05/23 18:36:05  bernie
00074  *#* Import buzzerled driver.
00075  *#*
00076  *#*/
00077 
00078 #include "buzzerled.h"
00079 #include "timer.h"
00080 
00081 static struct Timer timers[NUM_BLDS];
00082 static bool timer_go[NUM_BLDS];
00083 
00084 INLINE enum BLD_DEVICE hook_parm_to_device(void* parm)
00085 {
00086     struct Timer* t = (struct Timer*)parm;
00087     int num_bld = t - &timers[0];
00088 
00089     ASSERT(num_bld >= 0);
00090     ASSERT(num_bld < NUM_BLDS);
00091 
00092     return (enum BLD_DEVICE)num_bld;
00093 }
00094 
00095 static void hook_turn_off(void* parm)
00096 {
00097     enum BLD_DEVICE num_bld = hook_parm_to_device(parm);
00098     bld_set(num_bld, false);
00099 }
00100 
00101 void bld_init(void)
00102 {
00103     bld_hw_init();
00104 }
00105 
00106 void bld_beep(enum BLD_DEVICE device, uint16_t duration)
00107 {
00108     // \todo This is not reentrant for the same device. FIXME!
00109     struct Timer *t = &timers[device];
00110     timer_set_delay(t, duration);
00111     timer_set_event_softint(t, hook_turn_off, t);
00112     timer_add(t);
00113 
00114     bld_set(device, true);
00115 }
00116 
00117 void bld_beep_and_wait(enum BLD_DEVICE device, uint16_t duration)
00118 {
00119     bld_set(device, true);
00120     timer_delay(duration);
00121     bld_set(device, false);
00122 }
00123