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