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
38 * \author Giovanni Bajo <rasky@develer.com>
43 *#* Revision 1.7 2006/07/19 12:56:25 bernie
44 *#* Convert to new Doxygen style.
46 *#* Revision 1.6 2005/11/04 16:20:02 bernie
47 *#* Fix reference to README.devlib in header.
49 *#* Revision 1.5 2005/04/11 19:10:27 bernie
50 *#* Include top-level headers from cfg/ subdir.
52 *#* Revision 1.4 2004/11/16 21:54:43 bernie
53 *#* Changes for SC Monoboard support.
55 *#* Revision 1.3 2004/08/25 14:12:08 rasky
56 *#* Aggiornato il comment block dei log RCS
58 *#* Revision 1.2 2004/06/03 11:27:09 bernie
59 *#* Add dual-license information.
61 *#* Revision 1.1 2004/05/23 18:36:05 bernie
62 *#* Import buzzerled driver.
66 #ifndef DRV_BUZZERLED_DSP56K_H
67 #define DRV_BUZZERLED_DSP56K_H
69 #include <cfg/compiler.h>
76 * \name Connection of the leds to the DSP:
79 * ---------------------------
86 INLINE bool bld_is_inverted_intensity(enum BLD_DEVICE device)
88 return (device == BLD_GREEN_LED
89 || device == BLD_YELLOW_LED
90 || device == BLD_RED_LED);
93 INLINE bool bld_is_pwm(enum BLD_DEVICE device)
95 // Only the buzzer is connected to a PWM
96 return (device == BLD_BUZZER || device == BLD_READY_LED);
99 INLINE bool bld_is_timer(enum BLD_DEVICE device)
101 // LEDs are connected to timers
102 return (device == BLD_GREEN_LED || device == BLD_YELLOW_LED || device == BLD_RED_LED);
105 INLINE uint16_t bld_get_pwm(enum BLD_DEVICE device)
110 case BLD_BUZZER: return 5; // PWMA5
111 case BLD_READY_LED: return 9; // PWMB3
116 INLINE struct REG_TIMER_STRUCT* bld_get_timer(enum BLD_DEVICE device)
121 case BLD_GREEN_LED: return ®_TIMER_B[2];
122 case BLD_RED_LED: return ®_TIMER_B[1];
123 case BLD_YELLOW_LED: return ®_TIMER_B[3];
127 INLINE void bld_hw_init(void)
131 INLINE void bld_hw_set(enum BLD_DEVICE device, bool enable)
133 if (bld_is_inverted_intensity(device))
136 // Handle a BLD connected to a PWM
137 if (bld_is_pwm(device))
139 struct PWM* pwm = pwm_get_handle(bld_get_pwm(device));
141 pwm_set_enable(pwm, false);
142 pwm_set_dutycycle_percent(pwm, (enable ? 50 : 0));
143 pwm_set_enable(pwm, true);
145 else if (bld_is_timer(device))
147 struct REG_TIMER_STRUCT* timer = bld_get_timer(device);
149 // Check that the timer is currently stopped, and the OFLAG is not
150 // controlled by another timer. Otherwise, the led is already
151 // controlled by the timer, and we cannot correctly set it
152 // on/off without reprogramming the timer.
153 ASSERT((timer->CTRL & REG_TIMER_CTRL_MODE_MASK) == REG_TIMER_CTRL_MODE_STOP);
154 ASSERT(!(timer->SCR & REG_TIMER_SCR_EEOF));
156 // Check also that polarity is correct
157 ASSERT(!(timer->SCR & REG_TIMER_SCR_OPS));
159 // Without programming the timer, we have a way to manually force a certain
160 // value on the external pin. We also need to enable the output pin.
161 timer->SCR &= ~REG_TIMER_SCR_VAL_1;
162 timer->SCR |= REG_TIMER_SCR_OEN |
163 REG_TIMER_SCR_FORCE |
164 (!enable ? REG_TIMER_SCR_VAL_0 : REG_TIMER_SCR_VAL_1);
172 // We do not need inline functions here, because constant propagation is not big deal here
173 void bld_hw_init(void);
174 void bld_hw_set(enum BLD_DEVICE device, bool enable);
178 #endif /* DRV_BUZZERLED_DSP56K_H */