Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.h @ 080149cf

History | View | Annotate | Download (13.208 KB)

1 9ae7c4f3 Thomas Schöpping
/*
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 ee884101 Thomas Schöpping
 * @brief   I2C driver to access the EEPROM, power monitor and the breakout header.
60 9ae7c4f3 Thomas Schöpping
 */
61 ee884101 Thomas Schöpping
#define MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT   I2CD2
62 9ae7c4f3 Thomas Schöpping
63
/**
64 ee884101 Thomas Schöpping
 * @brief   Configuration for the EEPROM, power monitor and breakout I2C driver.
65 9ae7c4f3 Thomas Schöpping
 */
66 ee884101 Thomas Schöpping
extern I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig;
67 9ae7c4f3 Thomas Schöpping
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   Configuration for the SPI interface driver to communicate with the LED driver.
85
 */
86
extern SPIConfig moduleHalSpiLightConfig;
87
88
/**
89
 * @brief   SPI interface driver for the breakout header.
90
 */
91
#define MODULE_HAL_SPI_BREAKOUT                 SPID2
92
93
/**
94
 * @brief   UART interface driver for the breakout header (alternative to serial).
95
 */
96
#define MODULE_HAL_UART_BREAKOUT                UARTD2
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   RS232_R_EN_N output signal GPIO.
119
 */
120
extern ROMCONST apalControlGpio_t moduleGpioRs232En;
121
122
/**
123
 * @brief   SW_V33_EN output signal GPIO.
124
 */
125
extern ROMCONST apalControlGpio_t moduleGpioSwV33En;
126
127
/**
128
 * @brief   SW_V42_EN output signal GPIO.
129
 */
130
extern ROMCONST apalControlGpio_t moduleGpioSwV42En;
131
132
/**
133
 * @brief   SW_V50_EN output signal GPIO.
134
 */
135
extern ROMCONST apalControlGpio_t moduleGpioSwV50En;
136
137
/**
138
 * @brief   IO_3 breakout signal GPIO.
139
 */
140
extern apalControlGpio_t moduleGpioBreakoutIo3;
141
142
/**
143
 * @brief   IO_5 breakout signal GPIO.
144
 */
145
extern apalControlGpio_t moduleGpioBreakoutIo5;
146
147
/**
148
 * @brief   IO_6 breakout signal GPIO.
149
 */
150
extern apalControlGpio_t moduleGpioBreakoutIo6;
151
152
/**
153
 * @brief   SYS_UART_DN bidirectional signal GPIO.
154
 */
155
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
156
157
/**
158
 * @brief   IO_7 breakout signal GPIO.
159
 */
160
extern apalControlGpio_t moduleGpioBreakoutIo7;
161
162
/**
163
 * @brief   IO_8 breakout signal GPIO.
164
 */
165
extern apalControlGpio_t moduleGpioBreakoutIo8;
166
167
/**
168
 * @brief   IO_4 breakout signal GPIO.
169
 */
170
extern apalControlGpio_t moduleGpioBreakoutIo4;
171
172
/**
173
 * @brief   IO_1 breakout signal GPIO.
174
 */
175
extern apalControlGpio_t moduleGpioBreakoutIo1;
176
177
/**
178
 * @brief   IO_2 breakout signal GPIO.
179
 */
180
extern apalControlGpio_t moduleGpioBreakoutIo2;
181
182
/**
183
 * @brief   LED output signal GPIO.
184
 */
185
extern ROMCONST apalControlGpio_t moduleGpioLed;
186
187
/**
188
 * @brief   SW_V18_EN output signal GPIO.
189
 */
190
extern ROMCONST apalControlGpio_t moduleGpioSwV18En;
191
192
/**
193
 * @brief   SW_VSYS_EN output signal GPIO.
194
 */
195
extern ROMCONST apalControlGpio_t moduleGpioSwVsysEn;
196
197
/**
198
 * @brief   SYS_UART_UP bidirectional signal GPIO.
199
 */
200
extern ROMCONST apalControlGpio_t moduleGpioSysUartUp;
201
202
/**
203
 * @brief   SYS_PD bidirectional signal GPIO.
204
 */
205
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
206
207
/**
208
 * @brief   SYS_SYNC bidirectional signal GPIO.
209
 */
210
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
211
212
/** @} */
213
214
/*===========================================================================*/
215
/**
216
 * @name AMiRo-OS core configurations
217
 * @{
218
 */
219
/*===========================================================================*/
220
221
/**
222
 * @brief   Event flag to be set on a IO_4 (breakout) interrupt.
223
 */
224 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO4      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_4))
225 9ae7c4f3 Thomas Schöpping
226
/**
227
 * @brief   Event flag to be set on a IO_1 (breakout) interrupt.
228
 */
229 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO1      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_1))
230 9ae7c4f3 Thomas Schöpping
231
/**
232
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
233
 */
234 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
235 9ae7c4f3 Thomas Schöpping
236
/**
237
 * @brief   Event flag to be set on a IO_3 (breakout) interrupt.
238
 */
239 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO3      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_3))
240 9ae7c4f3 Thomas Schöpping
241
/**
242
 * @brief   Event flag to be set on a IO_5 (breakout) interrupt.
243
 */
244 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO5      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_5))
245 9ae7c4f3 Thomas Schöpping
246
/**
247
 * @brief   Event flag to be set on a IO_6 (breakout) interrupt.
248
 */
249 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO6      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_6))
250 9ae7c4f3 Thomas Schöpping
251
/**
252
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
253
 */
254 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_DN))
255 9ae7c4f3 Thomas Schöpping
256
/**
257
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
258
 */
259 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTUP        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_UP))
260 9ae7c4f3 Thomas Schöpping
261
/**
262
 * @brief   Event flag to be set on a IO_7 (breakout) interrupt.
263
 */
264 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO7      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_7))
265 9ae7c4f3 Thomas Schöpping
266
/**
267
 * @brief   Event flag to be set on a IO_8 (breakout) interrupt.
268
 */
269 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO8      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_8))
270 9ae7c4f3 Thomas Schöpping
271
/**
272
 * @brief   Event flag to be set on a SYS_PD interrupt.
273
 */
274 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSPD            AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
275 9ae7c4f3 Thomas Schöpping
276
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
277
/**
278
 * @brief   Shell prompt text.
279
 */
280
extern ROMCONST char* moduleShellPrompt;
281
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
282
283
/**
284
 * @brief   Interrupt initialization macro.
285
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
286
 */
287
#define MODULE_INIT_INTERRUPTS() {                                            \
288
  /* breakout interrupts must be enabled explicitely */                       \
289
}
290
291
/**
292
 * @brief   Unit test initialization hook.
293
 */
294
#define MODULE_INIT_TESTS() {                                                 \
295
  /* add unit-test shell commands */                                          \
296
  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01b.shellcmd);             \
297 ee884101 Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleUtAlldIna219.shellcmd);               \
298
  aosShellAddCommand(&aos.shell, &moduleUtAlldLed.shellcmd);                  \
299
  aosShellAddCommand(&aos.shell, &moduleUtAlldMic9404x.shellcmd);             \
300 9ae7c4f3 Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleUtAlldTlc5947.shellcmd);              \
301
}
302
303
/**
304
 * @brief   Periphery communication interfaces initialization hook.
305
 */
306
#define MODULE_INIT_PERIPHERY_COMM() {                                        \
307
  /* serial driver */                                                         \
308
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
309
  /* I2C */                                                                   \
310 ee884101 Thomas Schöpping
  moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \
311
  moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \
312
  moduleHalI2cEepromPwrmtrBreakoutConfig.duty_cycle = (moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
313
  i2cStart(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT, &moduleHalI2cEepromPwrmtrBreakoutConfig);  \
314 9ae7c4f3 Thomas Schöpping
  /* SPI */                                                                   \
315
  spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig);                  \
316
}
317
318
/**
319
 * @brief   Periphery communication interface deinitialization hook.
320
 */
321
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
322
  /* SPI */                                                                   \
323
  spiStop(&MODULE_HAL_SPI_LIGHT);                                             \
324
  /* I2C */                                                                   \
325 ee884101 Thomas Schöpping
  i2cStop(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT);                            \
326 9ae7c4f3 Thomas Schöpping
  /* don't stop the serial driver so messages can still be printed */         \
327
}
328
329
/** @} */
330
331
/*===========================================================================*/
332
/**
333
 * @name Startup Shutdown Synchronization Protocol (SSSP)
334
 * @{
335
 */
336
/*===========================================================================*/
337
338
/**
339
 * @brief   PD signal GPIO.
340
 */
341
#define moduleSsspGpioPd                        moduleGpioSysPd
342
343
/**
344
 * @brief   SYNC signal GPIO.
345
 */
346
#define moduleSsspGpioSync                      moduleGpioSysSync
347
348
/**
349
 * @brief   UP signal GPIO.
350
 */
351
#define moduleSsspGpioUp                        moduleGpioSysUartUp
352
353
/**
354
 * @brief   DN signal GPIO.
355
 */
356
#define moduleSsspGpioDn                        moduleGpioSysUartDn
357
358
/**
359
 * @brief   Event flags for PD signal events.
360
 */
361
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
362
363
/**
364
 * @brief   Event flags for SYNC signal events.
365
 */
366
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
367
368
/**
369
 * @brief   Event flags for UP signal events.
370
 */
371
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
372
373
/**
374
 * @brief   Event flags for DN signal events.
375
 */
376
#define MODULE_SSSP_EVENTFLAGS_DN               MODULE_OS_IOEVENTFLAGS_SYSUARTDN
377
378
/** @} */
379
380
/*===========================================================================*/
381
/**
382
 * @name Low-level drivers
383
 * @{
384
 */
385
/*===========================================================================*/
386
#include <alld_AT24C01B.h>
387 ee884101 Thomas Schöpping
#include <alld_INA219.h>
388 9ae7c4f3 Thomas Schöpping
#include <alld_LED.h>
389 ee884101 Thomas Schöpping
#include <alld_MIC9404x.h>
390
//#include <alld_SNx5C3221E.h>
391 9ae7c4f3 Thomas Schöpping
#include <alld_TLC5947.h>
392
393
/**
394
 * @brief   EEPROM driver.
395
 */
396
extern AT24C01BDriver moduleLldEeprom;
397
398
/**
399 ee884101 Thomas Schöpping
 * @brief   Power monitor (VLED 4.2) driver.
400
 */
401
extern INA219Driver moduleLldPowerMonitorVled;
402
403
/**
404 9ae7c4f3 Thomas Schöpping
 * @brief   Status LED driver.
405
 */
406
extern LEDDriver moduleLldStatusLed;
407
408
/**
409 ee884101 Thomas Schöpping
 * @brief   Power switch driver (1.8V).
410
 */
411
extern MIC9404xDriver moduleLldPowerSwitchV18;
412
413
/**
414
 * @brief   Power switch driver (3.3V).
415
 */
416
extern MIC9404xDriver moduleLldPowerSwitchV33;
417
418
/**
419
 * @brief   Power switch driver (4.2V).
420
 */
421
extern MIC9404xDriver moduleLldPowerSwitchV42;
422
423
/**
424
 * @brief   Power switch driver (5.0V).
425
 */
426
extern MIC9404xDriver moduleLldPowerSwitchV50;
427
428
/**
429
 * @brief   Pseudo power switch driver (VSYS).
430
 * @details There is no actual MIC9040x device, but the swicthable circuit behaves analogous.
431
 */
432
extern MIC9404xDriver moduleLldPowerSwitchVsys;
433
434
/**
435 9ae7c4f3 Thomas Schöpping
 * @brief   LED PWM driver.
436
 */
437
extern TLC5947Driver moduleLldLedPwm;
438
439
/** @} */
440
441
/*===========================================================================*/
442
/**
443
 * @name Unit tests (UT)
444
 * @{
445
 */
446
/*===========================================================================*/
447
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
448
#include <ut_alld_AT24C01B_v1.h>
449 ee884101 Thomas Schöpping
#include <ut_alld_INA219_v1.h>
450
#include <ut_alld_LED_v1.h>
451
#include <ut_alld_MIC9404x_v1.h>
452
//#include <ut_alld_SNx5C3221E_v1.h>
453 9ae7c4f3 Thomas Schöpping
#include <ut_alld_TLC5947_v1.h>
454
455
/**
456
 * @brief   EEPROM unit test object.
457
 */
458
extern aos_unittest_t moduleUtAlldAt24c01b;
459
460
/**
461 ee884101 Thomas Schöpping
 * @brief   INA219 (power monitor) unit test object.
462
 */
463
extern aos_unittest_t moduleUtAlldIna219;
464
465
/**
466
 * @brief   Status LED unit test object.
467
 */
468
extern aos_unittest_t moduleUtAlldLed;
469
470
/**
471
 * @brief   Power switch unit test object.
472
 */
473
extern aos_unittest_t moduleUtAlldMic9404x;
474
475
/**
476 9ae7c4f3 Thomas Schöpping
 * @brief   LED PWM driver unit test object.
477
 */
478
extern aos_unittest_t moduleUtAlldTlc5947;
479
480
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
481
482
/** @} */
483
484
#endif /* AMIROOS_MODULE_H */
485
486
/** @} */