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