Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.h @ 1bb524af

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