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