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 2004 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 2004 Giovanni Bajo
34 * \brief Hardware support for buzzers and leds in DSP56K-based boards
37 * \author Giovanni Bajo <rasky@develer.com>
42 *#* Revision 1.7 2006/07/19 12:56:25 bernie
43 *#* Convert to new Doxygen style.
45 *#* Revision 1.6 2005/11/04 16:20:02 bernie
46 *#* Fix reference to README.devlib in header.
48 *#* Revision 1.5 2005/04/11 19:10:27 bernie
49 *#* Include top-level headers from cfg/ subdir.
51 *#* Revision 1.4 2004/11/16 21:54:43 bernie
52 *#* Changes for SC Monoboard support.
54 *#* Revision 1.3 2004/08/25 14:12:08 rasky
55 *#* Aggiornato il comment block dei log RCS
57 *#* Revision 1.2 2004/06/03 11:27:09 bernie
58 *#* Add dual-license information.
60 *#* Revision 1.1 2004/05/23 18:36:05 bernie
61 *#* Import buzzerled driver.
65 #ifndef DRV_BUZZERLED_DSP56K_H
66 #define DRV_BUZZERLED_DSP56K_H
68 #include <cfg/compiler.h>
75 * \name Connection of the leds to the DSP:
78 * ---------------------------
85 INLINE bool bld_is_inverted_intensity(enum BLD_DEVICE device)
87 return (device == BLD_GREEN_LED
88 || device == BLD_YELLOW_LED
89 || device == BLD_RED_LED);
92 INLINE bool bld_is_pwm(enum BLD_DEVICE device)
94 // Only the buzzer is connected to a PWM
95 return (device == BLD_BUZZER || device == BLD_READY_LED);
98 INLINE bool bld_is_timer(enum BLD_DEVICE device)
100 // LEDs are connected to timers
101 return (device == BLD_GREEN_LED || device == BLD_YELLOW_LED || device == BLD_RED_LED);
104 INLINE uint16_t bld_get_pwm(enum BLD_DEVICE device)
109 case BLD_BUZZER: return 5; // PWMA5
110 case BLD_READY_LED: return 9; // PWMB3
115 INLINE struct REG_TIMER_STRUCT* bld_get_timer(enum BLD_DEVICE device)
120 case BLD_GREEN_LED: return ®_TIMER_B[2];
121 case BLD_RED_LED: return ®_TIMER_B[1];
122 case BLD_YELLOW_LED: return ®_TIMER_B[3];
126 INLINE void bld_hw_init(void)
130 INLINE void bld_hw_set(enum BLD_DEVICE device, bool enable)
132 if (bld_is_inverted_intensity(device))
135 // Handle a BLD connected to a PWM
136 if (bld_is_pwm(device))
138 struct PWM* pwm = pwm_get_handle(bld_get_pwm(device));
140 pwm_set_enable(pwm, false);
141 pwm_set_dutycycle_percent(pwm, (enable ? 50 : 0));
142 pwm_set_enable(pwm, true);
144 else if (bld_is_timer(device))
146 struct REG_TIMER_STRUCT* timer = bld_get_timer(device);
148 // Check that the timer is currently stopped, and the OFLAG is not
149 // controlled by another timer. Otherwise, the led is already
150 // controlled by the timer, and we cannot correctly set it
151 // on/off without reprogramming the timer.
152 ASSERT((timer->CTRL & REG_TIMER_CTRL_MODE_MASK) == REG_TIMER_CTRL_MODE_STOP);
153 ASSERT(!(timer->SCR & REG_TIMER_SCR_EEOF));
155 // Check also that polarity is correct
156 ASSERT(!(timer->SCR & REG_TIMER_SCR_OPS));
158 // Without programming the timer, we have a way to manually force a certain
159 // value on the external pin. We also need to enable the output pin.
160 timer->SCR &= ~REG_TIMER_SCR_VAL_1;
161 timer->SCR |= REG_TIMER_SCR_OEN |
162 REG_TIMER_SCR_FORCE |
163 (!enable ? REG_TIMER_SCR_VAL_0 : REG_TIMER_SCR_VAL_1);
171 // We do not need inline functions here, because constant propagation is not big deal here
172 void bld_hw_init(void);
173 void bld_hw_set(enum BLD_DEVICE device, bool enable);
177 #endif /* DRV_BUZZERLED_DSP56K_H */