amiro-os / modules / LightRing_1-0 / module.h @ 27e4a312
History | View | Annotate | Download (11.424 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 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 |
#ifndef _AMIROOS_MODULE_H_
|
20 |
#define _AMIROOS_MODULE_H_
|
21 |
|
22 |
/*===========================================================================*/
|
23 |
/**
|
24 |
* @name Module specific functions
|
25 |
* @{
|
26 |
*/
|
27 |
/*===========================================================================*/
|
28 |
|
29 |
static void _alld_dw1000_callback(void* args); |
30 |
|
31 |
/** @} */
|
32 |
|
33 |
/*===========================================================================*/
|
34 |
/**
|
35 |
* @name ChibiOS/HAL configuration
|
36 |
* @{
|
37 |
*/
|
38 |
/*===========================================================================*/
|
39 |
#include <hal.h> |
40 |
|
41 |
/**
|
42 |
* @brief CAN driver to use.
|
43 |
*/
|
44 |
#define MODULE_HAL_CAN CAND1
|
45 |
|
46 |
/**
|
47 |
* @brief Configuration for the CAN driver.
|
48 |
*/
|
49 |
extern CANConfig moduleHalCanConfig;
|
50 |
|
51 |
/**
|
52 |
* @brief I2C driver to access the EEPROM.
|
53 |
*/
|
54 |
#define MODULE_HAL_I2C_EEPROM I2CD2
|
55 |
|
56 |
/**
|
57 |
* @brief Configuration for the EEPROM I2C driver.
|
58 |
*/
|
59 |
extern I2CConfig moduleHalI2cEepromConfig;
|
60 |
|
61 |
/**
|
62 |
* @brief Serial driver of the programmer interface.
|
63 |
*/
|
64 |
#define MODULE_HAL_PROGIF SD1
|
65 |
|
66 |
/**
|
67 |
* @brief Configuration for the programmer serial interface driver.
|
68 |
*/
|
69 |
extern SerialConfig moduleHalProgIfConfig;
|
70 |
|
71 |
/**
|
72 |
* @brief SPI interface driver for the motion sensors (gyroscope and accelerometer).
|
73 |
*/
|
74 |
#define MODULE_HAL_SPI_LIGHT SPID1
|
75 |
|
76 |
/**
|
77 |
* @brief SPI interface driver for UWB Module.
|
78 |
*/
|
79 |
#define MODULE_HAL_SPI_UWB SPID2
|
80 |
|
81 |
/**
|
82 |
* @brief Configuration for the SPI interface driver to communicate with the LED driver.
|
83 |
*/
|
84 |
extern SPIConfig moduleHalSpiLightConfig;
|
85 |
|
86 |
/**
|
87 |
* @brief Configuration for the SPI interface driver to communicate with the LED driver.
|
88 |
*/
|
89 |
extern SPIConfig moduleHalSpiUWBConfig;
|
90 |
|
91 |
/**
|
92 |
* @brief Real-Time Clock driver.
|
93 |
*/
|
94 |
#define MODULE_HAL_RTC RTCD1
|
95 |
|
96 |
/** @} */
|
97 |
|
98 |
/*===========================================================================*/
|
99 |
/**
|
100 |
* @name GPIO definitions
|
101 |
* @{
|
102 |
*/
|
103 |
/*===========================================================================*/
|
104 |
#include <amiro-lld.h> |
105 |
|
106 |
/**
|
107 |
* @brief LIGHT_BANK output signal GPIO.
|
108 |
*/
|
109 |
extern apalControlGpio_t moduleGpioLightBlank;
|
110 |
|
111 |
/**
|
112 |
* @brief LASER_EN output signal GPIO.
|
113 |
*/
|
114 |
extern apalControlGpio_t moduleGpioLaserEn;
|
115 |
|
116 |
/**
|
117 |
* @brief LASER_OC input signal GPIO.
|
118 |
*/
|
119 |
extern apalControlGpio_t moduleGpioLaserOc;
|
120 |
|
121 |
/**
|
122 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
123 |
*/
|
124 |
extern apalControlGpio_t moduleGpioSysUartDn;
|
125 |
|
126 |
/**
|
127 |
* @brief WL_GDO2 input signal GPIO.
|
128 |
*/
|
129 |
extern apalControlGpio_t moduleGpioWlGdo2;
|
130 |
|
131 |
/**
|
132 |
* @brief WL_GDO0 input signal GPIO.
|
133 |
*/
|
134 |
extern apalControlGpio_t moduleGpioWlGdo0;
|
135 |
|
136 |
/**
|
137 |
* @brief LIGHT_XLAT output signal GPIO.
|
138 |
*/
|
139 |
extern apalControlGpio_t moduleGpioLightXlat;
|
140 |
|
141 |
/**
|
142 |
* @brief SYS_PD bidirectional signal GPIO.
|
143 |
*/
|
144 |
extern apalControlGpio_t moduleGpioSysPd;
|
145 |
|
146 |
/**
|
147 |
* @brief SYS_SYNC bidirectional signal GPIO.
|
148 |
*/
|
149 |
extern apalControlGpio_t moduleGpioSysSync;
|
150 |
|
151 |
/** @} */
|
152 |
|
153 |
/*===========================================================================*/
|
154 |
/**
|
155 |
* @name AMiRo-OS core configurations
|
156 |
* @{
|
157 |
*/
|
158 |
/*===========================================================================*/
|
159 |
|
160 |
/**
|
161 |
* @brief Event flag to be set on a LASER_OC interrupt.
|
162 |
*/
|
163 |
#define MODULE_OS_IOEVENTFLAGS_LASEROC ((eventflags_t)1 << GPIOB_LASER_OC_N) |
164 |
|
165 |
/**
|
166 |
* @brief Event flag to be set on a SYS_UART_DN interrupt.
|
167 |
*/
|
168 |
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN ((eventflags_t)1 << GPIOB_SYS_UART_DN) |
169 |
|
170 |
/**
|
171 |
* @brief Event flag to be set on a WL_GDO2 interrupt.
|
172 |
*/
|
173 |
#define MODULE_OS_IOEVENTFLAGS_WLGDO2 ((eventflags_t)1 << GPIOB_WL_GDO2) |
174 |
|
175 |
/**
|
176 |
* @brief Event flag to be set on a WL_GDO0 interrupt.
|
177 |
*/
|
178 |
#define MODULE_OS_IOEVENTFLAGS_WLGDO0 ((eventflags_t)1 << GPIOB_WL_GDO0) |
179 |
|
180 |
/**
|
181 |
* @brief Event flag to be set on a SYS_PD interrupt.
|
182 |
*/
|
183 |
#define MODULE_OS_IOEVENTFLAGS_SYSPD ((eventflags_t)1 << GPIOC_SYS_PD_N) |
184 |
|
185 |
/**
|
186 |
* @brief Event flag to be set on a SYS_SYNC interrupt.
|
187 |
*/
|
188 |
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC ((eventflags_t)1 << GPIOD_SYS_INT_N) |
189 |
|
190 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
191 |
/**
|
192 |
* @brief Shell prompt text.
|
193 |
*/
|
194 |
extern const char* moduleShellPrompt; |
195 |
#endif
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
/**
|
201 |
* @brief Interrupt initialization macro.
|
202 |
* @note SSSP related interrupt signals are already initialized in 'aos_system.c'.
|
203 |
*/
|
204 |
#define MODULE_INIT_INTERRUPTS() { \
|
205 |
/* LASER_OC */ \
|
206 |
palSetPadCallback(moduleGpioLaserOc.gpio->port, moduleGpioLaserOc.gpio->pad, _intCallback, &moduleGpioLaserOc.gpio->pad); \ |
207 |
palEnablePadEvent(moduleGpioLaserOc.gpio->port, moduleGpioLaserOc.gpio->pad, APAL2CH_EDGE(moduleGpioLaserOc.meta.edge)); \ |
208 |
/* WL_GDO2 */ \
|
209 |
palSetPadCallback(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, _alld_dw1000_callback, &moduleGpioWlGdo2.gpio->pad); \ |
210 |
palEnablePadEvent(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo2.meta.edge)); \ |
211 |
/* WL_GDO0 */ \
|
212 |
palSetPadCallback(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, _alld_dw1000_callback, &moduleGpioWlGdo0.gpio->pad); \ |
213 |
/*palEnablePadEvent(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo0.meta.edge)); // this is broken for some reason*/ \
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* @brief Unit test initialization hook.
|
218 |
*/
|
219 |
#define MODULE_INIT_TESTS() { \
|
220 |
/* add unit-test shell commands */ \
|
221 |
aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01bn.shellcmd); \ |
222 |
aosShellAddCommand(&aos.shell, &moduleUtAlldTlc5947.shellcmd); \ |
223 |
aosShellAddCommand(&aos.shell, &moduleUtAlldTps2051bdbv.shellcmd); \ |
224 |
aosShellAddCommand(&aos.shell, &moduleUtAlldDw1000.shellcmd); \ |
225 |
} |
226 |
|
227 |
/**
|
228 |
* @brief Periphery communication interfaces initialization hook.
|
229 |
*/
|
230 |
#define MODULE_INIT_PERIPHERY_COMM() { \
|
231 |
/* serial driver */ \
|
232 |
sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \ |
233 |
/* I2C */ \
|
234 |
moduleHalI2cEepromConfig.clock_speed = (AT24C01BN_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromConfig.clock_speed) ? AT24C01BN_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromConfig.clock_speed; \ |
235 |
moduleHalI2cEepromConfig.duty_cycle = (moduleHalI2cEepromConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2; \
|
236 |
i2cStart(&MODULE_HAL_I2C_EEPROM, &moduleHalI2cEepromConfig); \ |
237 |
/* SPI */ \
|
238 |
spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig); \ |
239 |
spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUWBConfig); \ |
240 |
} |
241 |
|
242 |
/**
|
243 |
* @brief Periphery communication interface deinitialization hook.
|
244 |
*/
|
245 |
#define MODULE_SHUTDOWN_PERIPHERY_COMM() { \
|
246 |
/* SPI */ \
|
247 |
spiStop(&MODULE_HAL_SPI_LIGHT); \ |
248 |
spiStop(&MODULE_HAL_SPI_UWB); \ |
249 |
/* I2C */ \
|
250 |
i2cStop(&MODULE_HAL_I2C_EEPROM); \ |
251 |
/* don't stop the serial driver so messages can still be printed */ \
|
252 |
} |
253 |
|
254 |
/** @} */
|
255 |
|
256 |
/*===========================================================================*/
|
257 |
/**
|
258 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
259 |
* @{
|
260 |
*/
|
261 |
/*===========================================================================*/
|
262 |
|
263 |
/**
|
264 |
* @brief PD signal GPIO.
|
265 |
*/
|
266 |
#define moduleSsspGpioPd moduleGpioSysPd
|
267 |
|
268 |
/**
|
269 |
* @brief SYNC signal GPIO.
|
270 |
*/
|
271 |
#define moduleSsspGpioSync moduleGpioSysSync
|
272 |
|
273 |
/**
|
274 |
* @brief DN signal GPIO.
|
275 |
*/
|
276 |
#define moduleSsspGpioDn moduleGpioSysUartDn
|
277 |
|
278 |
/**
|
279 |
* @brief Event flags for PD signal events.
|
280 |
*/
|
281 |
#define MODULE_SSSP_EVENTFLAGS_PD MODULE_OS_IOEVENTFLAGS_SYSPD
|
282 |
|
283 |
/**
|
284 |
* @brief Event flags for SYNC signal events.
|
285 |
*/
|
286 |
#define MODULE_SSSP_EVENTFLAGS_SYNC MODULE_OS_IOEVENTFLAGS_SYSSYNC
|
287 |
|
288 |
/**
|
289 |
* @brief Event flags for DN signal events.
|
290 |
*/
|
291 |
#define MODULE_SSSP_EVENTFLAGS_DN MODULE_OS_IOEVENTFLAGS_SYSUARTDN
|
292 |
|
293 |
/** @} */
|
294 |
|
295 |
/*===========================================================================*/
|
296 |
/**
|
297 |
* @name Low-level drivers
|
298 |
* @{
|
299 |
*/
|
300 |
/*===========================================================================*/
|
301 |
#include <alld_at24c01bn-sh-b.h> |
302 |
#include <alld_tlc5947.h> |
303 |
#include <alld_tps2051bdbv.h> |
304 |
#include <alld_dw1000.h> |
305 |
|
306 |
/**
|
307 |
* @brief EEPROM driver.
|
308 |
*/
|
309 |
extern AT24C01BNDriver moduleLldEeprom;
|
310 |
|
311 |
/**
|
312 |
* @brief LED PWM driver.
|
313 |
*/
|
314 |
extern TLC5947Driver moduleLldLedPwm;
|
315 |
|
316 |
/**
|
317 |
* @brief Power switch driver for the laser supply power.
|
318 |
*/
|
319 |
extern TPS2051BDriver moduleLldPowerSwitchLaser;
|
320 |
|
321 |
/**
|
322 |
* @brief DW1000 driver for UWB.
|
323 |
*/
|
324 |
extern DW1000Driver moduleLldDW1000;
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
/*! ------------------------------------------------------------------------------------------------------------------
|
330 |
* Function: _alld_dw1000_callback()
|
331 |
*
|
332 |
* Low level abstract function to handle 'reset' adn 'irq' interrupt from DW1000
|
333 |
* Expects arg to be of iopadid_t* type, used to distinguish between irq or reset signal
|
334 |
*/
|
335 |
static void _alld_dw1000_callback(void* args) { |
336 |
|
337 |
aosDbgCheck(true);
|
338 |
|
339 |
|
340 |
chSysLockFromISR(); |
341 |
if ((*(iopadid_t*) args) == moduleLldDW1000.gpio_reset->pad)
|
342 |
{ |
343 |
// dw1000 external indicate reset done
|
344 |
} |
345 |
else if ((*(iopadid_t*) args) == moduleLldDW1000.gpio_exti->pad) |
346 |
{ |
347 |
dwt_isr(); |
348 |
} |
349 |
else
|
350 |
{ |
351 |
return;
|
352 |
} |
353 |
chSysUnlockFromISR(); |
354 |
|
355 |
} |
356 |
|
357 |
|
358 |
/** @} */
|
359 |
|
360 |
/*===========================================================================*/
|
361 |
/**
|
362 |
* @name Unit tests (UT)
|
363 |
* @{
|
364 |
*/
|
365 |
/*===========================================================================*/
|
366 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
367 |
#include <ut_alld_at24c01bn-sh-b.h> |
368 |
#include <ut_alld_tlc5947.h> |
369 |
#include <ut_alld_tps2051bdbv.h> |
370 |
#include <ut_alld_dw1000.h> |
371 |
|
372 |
/**
|
373 |
* @brief EEPROM unit test object.
|
374 |
*/
|
375 |
extern aos_unittest_t moduleUtAlldAt24c01bn;
|
376 |
|
377 |
/**
|
378 |
* @brief LED PWM driver unit test object.
|
379 |
*/
|
380 |
extern aos_unittest_t moduleUtAlldTlc5947;
|
381 |
|
382 |
/**
|
383 |
* @brief Current-limited power switch (Laser output)
|
384 |
*/
|
385 |
extern aos_unittest_t moduleUtAlldTps2051bdbv;
|
386 |
|
387 |
/**
|
388 |
* @brief DW1000 unit test object.
|
389 |
*/
|
390 |
extern aos_unittest_t moduleUtAlldDw1000;
|
391 |
|
392 |
|
393 |
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
394 |
|
395 |
/** @} */
|
396 |
|
397 |
#endif /* _AMIROOS_MODULE_H_ */ |