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