amiro-os / modules / LightRing_1-0 / module.h @ a3ac2400
History | View | Annotate | Download (10.746 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file
|
21 |
* @brief Structures and constant for the LightRing module.
|
22 |
*
|
23 |
* @addtogroup lightring_module
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef AMIROOS_MODULE_H
|
28 |
#define AMIROOS_MODULE_H
|
29 |
|
30 |
#include <amiroos.h> |
31 |
|
32 |
/*===========================================================================*/
|
33 |
/**
|
34 |
* @name Module specific functions
|
35 |
* @{
|
36 |
*/
|
37 |
/*===========================================================================*/
|
38 |
|
39 |
/** @} */
|
40 |
|
41 |
/*===========================================================================*/
|
42 |
/**
|
43 |
* @name ChibiOS/HAL configuration
|
44 |
* @{
|
45 |
*/
|
46 |
/*===========================================================================*/
|
47 |
|
48 |
/**
|
49 |
* @brief CAN driver to use.
|
50 |
*/
|
51 |
#define MODULE_HAL_CAN CAND1
|
52 |
|
53 |
/**
|
54 |
* @brief Configuration for the CAN driver.
|
55 |
*/
|
56 |
extern CANConfig moduleHalCanConfig;
|
57 |
|
58 |
/**
|
59 |
* @brief I2C driver to access the EEPROM.
|
60 |
*/
|
61 |
#define MODULE_HAL_I2C_EEPROM I2CD2
|
62 |
|
63 |
/**
|
64 |
* @brief Configuration for the EEPROM I2C driver.
|
65 |
*/
|
66 |
extern I2CConfig moduleHalI2cEepromConfig;
|
67 |
|
68 |
/**
|
69 |
* @brief Serial driver of the programmer interface.
|
70 |
*/
|
71 |
#define MODULE_HAL_PROGIF SD1
|
72 |
|
73 |
/**
|
74 |
* @brief Configuration for the programmer serial interface driver.
|
75 |
*/
|
76 |
extern SerialConfig moduleHalProgIfConfig;
|
77 |
|
78 |
/**
|
79 |
* @brief SPI interface driver for the motion sensors (gyroscope and accelerometer).
|
80 |
*/
|
81 |
#define MODULE_HAL_SPI_LIGHT SPID1
|
82 |
|
83 |
/**
|
84 |
* @brief SPI interface driver for the wireless transceiver.
|
85 |
*/
|
86 |
#define MODULE_HAL_SPI_WL SPID2
|
87 |
|
88 |
/**
|
89 |
* @brief Configuration for the SPI interface driver to communicate with the LED driver.
|
90 |
*/
|
91 |
extern SPIConfig moduleHalSpiLightConfig;
|
92 |
|
93 |
/**
|
94 |
* @brief Configuration for the SPI interface driver to communicate with the wireless transceiver.
|
95 |
*/
|
96 |
extern SPIConfig moduleHalSpiWlConfig;
|
97 |
|
98 |
/**
|
99 |
* @brief Real-Time Clock driver.
|
100 |
*/
|
101 |
#define MODULE_HAL_RTC RTCD1
|
102 |
|
103 |
/** @} */
|
104 |
|
105 |
/*===========================================================================*/
|
106 |
/**
|
107 |
* @name GPIO definitions
|
108 |
* @{
|
109 |
*/
|
110 |
/*===========================================================================*/
|
111 |
|
112 |
/**
|
113 |
* @brief LIGHT_BANK output signal GPIO.
|
114 |
*/
|
115 |
extern ROMCONST apalControlGpio_t moduleGpioLightBlank;
|
116 |
|
117 |
/**
|
118 |
* @brief LASER_EN output signal GPIO.
|
119 |
*/
|
120 |
extern ROMCONST apalControlGpio_t moduleGpioLaserEn;
|
121 |
|
122 |
/**
|
123 |
* @brief LASER_OC input signal GPIO.
|
124 |
*/
|
125 |
extern ROMCONST apalControlGpio_t moduleGpioLaserOc;
|
126 |
|
127 |
/**
|
128 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
129 |
*/
|
130 |
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
|
131 |
|
132 |
/**
|
133 |
* @brief WL_GDO2 input signal GPIO.
|
134 |
*/
|
135 |
extern ROMCONST apalControlGpio_t moduleGpioWlGdo2;
|
136 |
|
137 |
/**
|
138 |
* @brief WL_GDO0 input signal GPIO.
|
139 |
*/
|
140 |
extern ROMCONST apalControlGpio_t moduleGpioWlGdo0;
|
141 |
|
142 |
/**
|
143 |
* @brief LIGHT_XLAT output signal.
|
144 |
*/
|
145 |
extern ROMCONST apalControlGpio_t moduleGpioLightXlat;
|
146 |
|
147 |
/**
|
148 |
* @brief SYS_PD bidirectional signal GPIO.
|
149 |
*/
|
150 |
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
|
151 |
|
152 |
/**
|
153 |
* @brief SYS_SYNC bidirectional signal GPIO.
|
154 |
*/
|
155 |
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
|
156 |
|
157 |
/** @} */
|
158 |
|
159 |
/*===========================================================================*/
|
160 |
/**
|
161 |
* @name AMiRo-OS core configurations
|
162 |
* @{
|
163 |
*/
|
164 |
/*===========================================================================*/
|
165 |
|
166 |
/**
|
167 |
* @brief Event flag to be set on a LASER_OC interrupt.
|
168 |
*/
|
169 |
#define MODULE_OS_IOEVENTFLAGS_LASEROC AOS_IOEVENT_FLAG(PAL_PAD(LINE_LASER_OC_N))
|
170 |
|
171 |
/**
|
172 |
* @brief Event flag to be set on a SYS_UART_DN interrupt.
|
173 |
*/
|
174 |
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_DN))
|
175 |
|
176 |
/**
|
177 |
* @brief Event flag to be set on a WL_GDO2 interrupt.
|
178 |
*/
|
179 |
#define MODULE_OS_IOEVENTFLAGS_WLGDO2 AOS_IOEVENT_FLAG(PAL_PAD(LINE_WL_GDO2))
|
180 |
|
181 |
/**
|
182 |
* @brief Event flag to be set on a WL_GDO0 interrupt.
|
183 |
*/
|
184 |
#define MODULE_OS_IOEVENTFLAGS_WLGDO0 AOS_IOEVENT_FLAG(PAL_PAD(LINE_WL_GDO0))
|
185 |
|
186 |
/**
|
187 |
* @brief Event flag to be set on a SYS_PD interrupt.
|
188 |
*/
|
189 |
#define MODULE_OS_IOEVENTFLAGS_SYSPD AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
|
190 |
|
191 |
/**
|
192 |
* @brief Event flag to be set on a SYS_SYNC interrupt.
|
193 |
*/
|
194 |
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
|
195 |
|
196 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
197 |
/**
|
198 |
* @brief Shell prompt text.
|
199 |
*/
|
200 |
extern ROMCONST char* moduleShellPrompt; |
201 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
202 |
|
203 |
/**
|
204 |
* @brief Interrupt initialization macro.
|
205 |
* @note SSSP related interrupt signals are already initialized in 'aos_system.c'.
|
206 |
*/
|
207 |
#define MODULE_INIT_INTERRUPTS() { \
|
208 |
/* LASER_OC */ \
|
209 |
palSetLineCallback(moduleGpioLaserOc.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioLaserOc.gpio->line); \ |
210 |
palEnableLineEvent(moduleGpioLaserOc.gpio->line, APAL2CH_EDGE(moduleGpioLaserOc.meta.edge)); \ |
211 |
/* WL_GDO2 */ \
|
212 |
palSetLineCallback(moduleGpioWlGdo2.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioWlGdo2.gpio->line); \ |
213 |
palEnableLineEvent(moduleGpioWlGdo2.gpio->line, APAL2CH_EDGE(moduleGpioWlGdo2.meta.edge)); \ |
214 |
/* WL_GDO0 */ \
|
215 |
palSetLineCallback(moduleGpioWlGdo0.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioWlGdo0.gpio->line); \ |
216 |
/*palEnableLineEvent(moduleGpioWlGdo0.gpio->line, APAL2CH_EDGE(moduleGpioWlGdo0.meta.edge)); // this is broken for some reason*/ \
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* @brief Test initialization hook.
|
221 |
*/
|
222 |
#define MODULE_INIT_TESTS() { \
|
223 |
/* initialize tests and add to shell */ \
|
224 |
aosShellAddCommand(&aos.shell, &moduleTestAt24c01bShellCmd); \ |
225 |
aosShellAddCommand(&aos.shell, &moduleTestTlc5947ShellCmd); \ |
226 |
aosShellAddCommand(&aos.shell, &moduleTestTps2051bdbvShellCmd); \ |
227 |
aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd); \ |
228 |
} |
229 |
|
230 |
/**
|
231 |
* @brief Periphery communication interfaces initialization hook.
|
232 |
*/
|
233 |
#define MODULE_INIT_PERIPHERY_IF() { \
|
234 |
/* serial driver */ \
|
235 |
sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \ |
236 |
/* I2C */ \
|
237 |
moduleHalI2cEepromConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromConfig.clock_speed; \ |
238 |
moduleHalI2cEepromConfig.duty_cycle = (moduleHalI2cEepromConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2; \
|
239 |
i2cStart(&MODULE_HAL_I2C_EEPROM, &moduleHalI2cEepromConfig); \ |
240 |
/* SPI */ \
|
241 |
spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig); \ |
242 |
spiStart(&MODULE_HAL_SPI_WL, &moduleHalSpiWlConfig); \ |
243 |
} |
244 |
|
245 |
/**
|
246 |
* @brief Periphery communication interface deinitialization hook.
|
247 |
*/
|
248 |
#define MODULE_SHUTDOWN_PERIPHERY_IF() { \
|
249 |
/* SPI */ \
|
250 |
spiStop(&MODULE_HAL_SPI_LIGHT); \ |
251 |
spiStop(&MODULE_HAL_SPI_WL); \ |
252 |
/* I2C */ \
|
253 |
i2cStop(&MODULE_HAL_I2C_EEPROM); \ |
254 |
/* don't stop the serial driver so messages can still be printed */ \
|
255 |
} |
256 |
|
257 |
/** @} */
|
258 |
|
259 |
/*===========================================================================*/
|
260 |
/**
|
261 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
262 |
* @{
|
263 |
*/
|
264 |
/*===========================================================================*/
|
265 |
|
266 |
/**
|
267 |
* @brief PD signal GPIO.
|
268 |
*/
|
269 |
#define moduleSsspGpioPd moduleGpioSysPd
|
270 |
|
271 |
/**
|
272 |
* @brief SYNC signal GPIO.
|
273 |
*/
|
274 |
#define moduleSsspGpioSync moduleGpioSysSync
|
275 |
|
276 |
/**
|
277 |
* @brief DN signal GPIO.
|
278 |
*/
|
279 |
#define moduleSsspGpioDn moduleGpioSysUartDn
|
280 |
|
281 |
/**
|
282 |
* @brief Event flags for PD signal events.
|
283 |
*/
|
284 |
#define MODULE_SSSP_EVENTFLAGS_PD MODULE_OS_IOEVENTFLAGS_SYSPD
|
285 |
|
286 |
/**
|
287 |
* @brief Event flags for SYNC signal events.
|
288 |
*/
|
289 |
#define MODULE_SSSP_EVENTFLAGS_SYNC MODULE_OS_IOEVENTFLAGS_SYSSYNC
|
290 |
|
291 |
/**
|
292 |
* @brief Event flags for DN signal events.
|
293 |
*/
|
294 |
#define MODULE_SSSP_EVENTFLAGS_DN MODULE_OS_IOEVENTFLAGS_SYSUARTDN
|
295 |
|
296 |
/** @} */
|
297 |
|
298 |
/*===========================================================================*/
|
299 |
/**
|
300 |
* @name Low-level drivers
|
301 |
* @{
|
302 |
*/
|
303 |
/*===========================================================================*/
|
304 |
#include <alld_AT24C01B.h> |
305 |
#include <alld_TLC5947.h> |
306 |
#include <alld_TPS20xxB.h> |
307 |
|
308 |
/**
|
309 |
* @brief EEPROM driver.
|
310 |
*/
|
311 |
extern AT24C01BDriver moduleLldEeprom;
|
312 |
|
313 |
/**
|
314 |
* @brief 24 channel PWM LED driver.
|
315 |
*/
|
316 |
extern TLC5947Driver moduleLldLedPwm;
|
317 |
|
318 |
/**
|
319 |
* @brief Power switch driver for the laser supply power.
|
320 |
*/
|
321 |
extern TPS20xxBDriver moduleLldPowerSwitchLaser;
|
322 |
|
323 |
/** @} */
|
324 |
|
325 |
/*===========================================================================*/
|
326 |
/**
|
327 |
* @name Tests
|
328 |
* @{
|
329 |
*/
|
330 |
/*===========================================================================*/
|
331 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
332 |
|
333 |
/**
|
334 |
* @brief AT24C01BN-SH-B (EEPROM) test command.
|
335 |
*/
|
336 |
extern aos_shellcommand_t moduleTestAt24c01bShellCmd;
|
337 |
|
338 |
/**
|
339 |
* @brief TLC5947 (24 channel PWM LED driver) test command
|
340 |
*/
|
341 |
extern aos_shellcommand_t moduleTestTlc5947ShellCmd;
|
342 |
|
343 |
/**
|
344 |
* @brief TPS2051BDBV (Current-limited power switch) test command
|
345 |
*/
|
346 |
extern aos_shellcommand_t moduleTestTps2051bdbvShellCmd;
|
347 |
|
348 |
/**
|
349 |
* @brief Entire module test command.
|
350 |
*/
|
351 |
extern aos_shellcommand_t moduleTestAllShellCmd;
|
352 |
|
353 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
354 |
|
355 |
/** @} */
|
356 |
|
357 |
#endif /* AMIROOS_MODULE_H */ |
358 |
|
359 |
/** @} */
|