amiro-os / modules / LightRing_1-0 / module.c @ 45fb0d6f
History | View | Annotate | Download (10.016 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 |
#include "module.h" |
20 |
|
21 |
#include <amiroos.h> |
22 |
|
23 |
/*===========================================================================*/
|
24 |
/**
|
25 |
* @name Module specific functions
|
26 |
* @{
|
27 |
*/
|
28 |
/*===========================================================================*/
|
29 |
|
30 |
|
31 |
/** @} */
|
32 |
|
33 |
/*===========================================================================*/
|
34 |
/**
|
35 |
* @name ChibiOS/HAL configuration
|
36 |
* @{
|
37 |
*/
|
38 |
/*===========================================================================*/
|
39 |
|
40 |
CANConfig moduleHalCanConfig = { |
41 |
/* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
42 |
/* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
43 |
}; |
44 |
|
45 |
I2CConfig moduleHalI2cEepromConfig = { |
46 |
/* I²C mode */ OPMODE_I2C,
|
47 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
48 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
49 |
}; |
50 |
|
51 |
SerialConfig moduleHalProgIfConfig = { |
52 |
/* bit rate */ 115200, |
53 |
/* CR1 */ 0, |
54 |
/* CR1 */ 0, |
55 |
/* CR1 */ 0, |
56 |
}; |
57 |
|
58 |
SPIConfig moduleHalSpiLightConfig = { |
59 |
/* circular buffer mode */ false, |
60 |
/* callback function pointer */ NULL, |
61 |
/* chip select line port */ GPIOC,
|
62 |
/* chip select line pad number */ GPIOC_LIGHT_XLAT,
|
63 |
/* CR1 */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
|
64 |
/* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
65 |
}; |
66 |
|
67 |
SPIConfig moduleHalSpiUWBConfig = { |
68 |
/* circular buffer mode */ false, |
69 |
/* callback function pointer */ NULL, |
70 |
/* chip select line port */ GPIOB,
|
71 |
/* chip select line pad number */ GPIOB_WL_SS_N,
|
72 |
/* CR1 */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
|
73 |
/* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
74 |
}; |
75 |
|
76 |
/*===========================================================================*/
|
77 |
/**
|
78 |
* @name GPIO definitions
|
79 |
* @{
|
80 |
*/
|
81 |
/*===========================================================================*/
|
82 |
|
83 |
/**
|
84 |
* @brief LIGHT_BANK output signal GPIO.
|
85 |
*/
|
86 |
static apalGpio_t _gpioLightBlank = {
|
87 |
/* port */ GPIOA,
|
88 |
/* pad */ GPIOA_LIGHT_BLANK,
|
89 |
}; |
90 |
apalControlGpio_t moduleGpioLightBlank = { |
91 |
/* GPIO */ &_gpioLightBlank,
|
92 |
/* meta */ {
|
93 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
94 |
/* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
95 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
96 |
}, |
97 |
}; |
98 |
|
99 |
/**
|
100 |
* @brief LASER_EN output signal GPIO.
|
101 |
*/
|
102 |
static apalGpio_t _gpioLaserEn = {
|
103 |
/* port */ GPIOB,
|
104 |
/* pad */ GPIOB_LASER_EN,
|
105 |
}; |
106 |
apalControlGpio_t moduleGpioLaserEn = { |
107 |
/* GPIO */ &_gpioLaserEn,
|
108 |
/* meta */ {
|
109 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
110 |
/* active state */ TPS2051B_LLD_ENABLE_ACTIVE_STATE,
|
111 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
112 |
}, |
113 |
}; |
114 |
|
115 |
/**
|
116 |
* @brief LASER_OC input signal GPIO.
|
117 |
*/
|
118 |
static apalGpio_t _gpioLaserOc = {
|
119 |
/* port */ GPIOB,
|
120 |
/* pad */ GPIOB_LASER_OC_N,
|
121 |
}; |
122 |
apalControlGpio_t moduleGpioLaserOc = { |
123 |
/* GPIO */ &_gpioLaserOc,
|
124 |
/* meta */ {
|
125 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
126 |
/* active state */ TPS2051B_LLD_OVERCURRENT_ACTIVE_STATE,
|
127 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
128 |
}, |
129 |
}; |
130 |
|
131 |
/**
|
132 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
133 |
*/
|
134 |
static apalGpio_t _gpioSysUartDn = {
|
135 |
/* port */ GPIOB,
|
136 |
/* pad */ GPIOB_SYS_UART_DN,
|
137 |
}; |
138 |
apalControlGpio_t moduleGpioSysUartDn = { |
139 |
/* GPIO */ &_gpioSysUartDn,
|
140 |
/* meta */ {
|
141 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
142 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
143 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
144 |
}, |
145 |
}; |
146 |
|
147 |
//INFO WL_GDO2,WL_GDO0 / -> UWB EXTI config.
|
148 |
|
149 |
/**
|
150 |
* @brief WL_GDO2 input signal GPIO.
|
151 |
*/
|
152 |
static apalGpio_t _gpioWlGdo2 = {
|
153 |
/* port */ GPIOB,
|
154 |
/* pad */ GPIOB_WL_GDO2,
|
155 |
}; |
156 |
apalControlGpio_t moduleGpioWlGdo2 = { |
157 |
/* GPIO */ &_gpioWlGdo2,
|
158 |
/* meta */ {
|
159 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
160 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
161 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
162 |
}, |
163 |
}; |
164 |
|
165 |
/**
|
166 |
* @brief WL_GDO0 input signal GPIO.
|
167 |
*/
|
168 |
static apalGpio_t _gpioWlGdo0= {
|
169 |
/* port */ GPIOB,
|
170 |
/* pad */ GPIOB_WL_GDO0,
|
171 |
}; |
172 |
apalControlGpio_t moduleGpioWlGdo0 = { |
173 |
/* GPIO */ &_gpioWlGdo0,
|
174 |
/* meta */ {
|
175 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
176 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
177 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
178 |
}, |
179 |
}; |
180 |
|
181 |
/**
|
182 |
* @brief LIGHT_XLAT output signal GPIO.
|
183 |
*/
|
184 |
static apalGpio_t _gpioLightXlat = {
|
185 |
/* port */ GPIOC,
|
186 |
/* pad */ GPIOC_LIGHT_XLAT,
|
187 |
}; |
188 |
apalControlGpio_t moduleGpioLightXlat = { |
189 |
/* GPIO */ &_gpioLightXlat,
|
190 |
/* meta */ {
|
191 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
192 |
/* active state */ TLC5947_LLD_XLAT_ACTIVE_STATE,
|
193 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
194 |
}, |
195 |
}; |
196 |
|
197 |
/**
|
198 |
* @brief SYS_PD bidirectional signal GPIO.
|
199 |
*/
|
200 |
static apalGpio_t _gpioSysPd = {
|
201 |
/* port */ GPIOC,
|
202 |
/* pad */ GPIOC_SYS_PD_N,
|
203 |
}; |
204 |
apalControlGpio_t moduleGpioSysPd = { |
205 |
/* GPIO */ &_gpioSysPd,
|
206 |
/* meta */ {
|
207 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
208 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
209 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
210 |
}, |
211 |
}; |
212 |
|
213 |
/**
|
214 |
* @brief SYS_SYNC bidirectional signal GPIO.
|
215 |
*/
|
216 |
static apalGpio_t _gpioSysSync = {
|
217 |
/* port */ GPIOD,
|
218 |
/* pad */ GPIOD_SYS_INT_N,
|
219 |
}; |
220 |
apalControlGpio_t moduleGpioSysSync = { |
221 |
/* GPIO */ &_gpioSysSync,
|
222 |
/* meta */ {
|
223 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
224 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
225 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
226 |
}, |
227 |
}; |
228 |
|
229 |
/** @} */
|
230 |
|
231 |
/*===========================================================================*/
|
232 |
/**
|
233 |
* @name AMiRo-OS core configurations
|
234 |
* @{
|
235 |
*/
|
236 |
/*===========================================================================*/
|
237 |
|
238 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
239 |
const char* moduleShellPrompt = "LightRing"; |
240 |
#endif
|
241 |
|
242 |
/** @} */
|
243 |
|
244 |
/*===========================================================================*/
|
245 |
/**
|
246 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
247 |
* @{
|
248 |
*/
|
249 |
/*===========================================================================*/
|
250 |
|
251 |
/** @} */
|
252 |
|
253 |
/*===========================================================================*/
|
254 |
/**
|
255 |
* @name Low-level drivers
|
256 |
* @{
|
257 |
*/
|
258 |
/*===========================================================================*/
|
259 |
|
260 |
AT24C01BNDriver moduleLldEeprom = { |
261 |
/* I2C driver */ &MODULE_HAL_I2C_EEPROM,
|
262 |
/* I2C address */ 0x00u, |
263 |
}; |
264 |
|
265 |
TLC5947Driver moduleLldLedPwm = { |
266 |
/* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
267 |
/* BLANK signal GPIO */ &moduleGpioLightBlank,
|
268 |
/* XLAT signal GPIO */ &moduleGpioLightXlat,
|
269 |
}; |
270 |
|
271 |
TPS2051BDriver moduleLldPowerSwitchLaser = { |
272 |
/* laser enable GPIO */ &moduleGpioLaserEn,
|
273 |
/* laser overcurrent GPIO */ &moduleGpioLaserOc,
|
274 |
}; |
275 |
|
276 |
|
277 |
DW1000Driver moduleLldDW1000 = { |
278 |
/* SPI driver */ &MODULE_HAL_SPI_UWB,
|
279 |
/* EXTI GPIO */ &_gpioWlGdo2,
|
280 |
/* RESET GPIO */ &_gpioWlGdo2,
|
281 |
|
282 |
}; |
283 |
|
284 |
/** @} */
|
285 |
|
286 |
/*===========================================================================*/
|
287 |
/**
|
288 |
* @name Unit tests (UT)
|
289 |
* @{
|
290 |
*/
|
291 |
/*===========================================================================*/
|
292 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
293 |
|
294 |
/* EEPROM (AT24C01BN) */
|
295 |
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
296 |
{ |
297 |
(void)argc;
|
298 |
(void)argv;
|
299 |
aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
300 |
return AOS_OK;
|
301 |
} |
302 |
static ut_at24c01bndata_t _utAt24c01bnData = {
|
303 |
/* driver */ &moduleLldEeprom,
|
304 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
305 |
}; |
306 |
aos_unittest_t moduleUtAlldAt24c01bn = { |
307 |
/* name */ "AT24C01BN-SH-B", |
308 |
/* info */ "1kbit EEPROM", |
309 |
/* test function */ utAlldAt24c01bnFunc,
|
310 |
/* shell command */ {
|
311 |
/* name */ "unittest:EEPROM", |
312 |
/* callback */ _utShellCmdCb_AlldAt24c01bn,
|
313 |
/* next */ NULL, |
314 |
}, |
315 |
/* data */ &_utAt24c01bnData,
|
316 |
}; |
317 |
|
318 |
/* LED PWM driver (TLD5947) */
|
319 |
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[]) |
320 |
{ |
321 |
(void)argc;
|
322 |
(void)argv;
|
323 |
aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
|
324 |
return AOS_OK;
|
325 |
} |
326 |
aos_unittest_t moduleUtAlldTlc5947 = { |
327 |
/* info */ "TLC5947", |
328 |
/* name */ "LED PWM driver", |
329 |
/* test function */ utAlldTlc5947Func,
|
330 |
/* shell command */ {
|
331 |
/* name */ "unittest:Lights", |
332 |
/* callback */ _utShellCmdCb_Tlc5947,
|
333 |
/* next */ NULL, |
334 |
}, |
335 |
/* data */ &moduleLldLedPwm,
|
336 |
}; |
337 |
|
338 |
/* power switch (Laser) */
|
339 |
static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[]) |
340 |
{ |
341 |
(void)argc;
|
342 |
(void)argv;
|
343 |
aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
|
344 |
return AOS_OK;
|
345 |
} |
346 |
aos_unittest_t moduleUtAlldTps2051bdbv = { |
347 |
/* info */ "TPS2051BDBV", |
348 |
/* name */ "current-limited power switch", |
349 |
/* test function */ utAlldTps2051bdbvFunc,
|
350 |
/* shell command */ {
|
351 |
/* name */ "unittest:PowerSwitch", |
352 |
/* callback */ _utShellCmdCb_Tps2051bdbv,
|
353 |
/* next */ NULL, |
354 |
}, |
355 |
/* data */ &moduleLldPowerSwitchLaser,
|
356 |
}; |
357 |
|
358 |
/* UWB Module */
|
359 |
static int _utShellCmdCb_Dw1000(BaseSequentialStream* stream, int argc, char* argv[]) |
360 |
{ |
361 |
(void)argc;
|
362 |
(void)argv;
|
363 |
aosUtRun(stream,&moduleUtAlldDw1000, NULL);
|
364 |
return AOS_OK;
|
365 |
} |
366 |
aos_unittest_t moduleUtAlldDw1000 = { |
367 |
/* info */ "DW1000", |
368 |
/* name */ "UWB Module", |
369 |
/* test function */ utAlldDw1000Func,
|
370 |
/* shell command */ {
|
371 |
/* name */ "unittest:UWB", |
372 |
/* callback */ _utShellCmdCb_Dw1000,
|
373 |
/* next */ NULL, |
374 |
}, |
375 |
/* data */ &moduleLldDW1000,
|
376 |
}; |
377 |
|
378 |
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
379 |
|
380 |
/** @} */
|