amiro-os / modules / LightRing_1-0 / module.c @ b49ed442
History | View | Annotate | Download (9.556 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 | 3106e8cc | Thomas Schöpping | /* chip select line port */ PAL_PORT(LINE_LIGHT_XLAT),
|
67 | /* chip select line pad number */ PAL_PAD(LINE_LIGHT_XLAT),
|
||
68 | e545e620 | Thomas Schöpping | /* 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 | 3106e8cc | Thomas Schöpping | /* chip select line port */ PAL_PORT(LINE_WL_SS_N),
|
76 | /* chip select line pad number */ PAL_PAD(LINE_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 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LIGHT_BLANK,
|
93 | e545e620 | Thomas Schöpping | }; |
94 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLightBlank = { |
95 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLightBlank,
|
96 | /* meta */ {
|
||
97 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
98 | /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
||
99 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
100 | }, |
||
101 | }; |
||
102 | e545e620 | Thomas Schöpping | |
103 | 1e5f7648 | Thomas Schöpping | /**
|
104 | * @brief LASER_EN output signal GPIO.
|
||
105 | */
|
||
106 | static apalGpio_t _gpioLaserEn = {
|
||
107 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LASER_EN,
|
108 | e545e620 | Thomas Schöpping | }; |
109 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLaserEn = { |
110 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLaserEn,
|
111 | /* meta */ {
|
||
112 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
113 | ddf34c3d | Thomas Schöpping | /* active state */ TPS20xxB_LLD_ENABLE_ACTIVE_STATE,
|
114 | 1e5f7648 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
115 | }, |
||
116 | }; |
||
117 | e545e620 | Thomas Schöpping | |
118 | 1e5f7648 | Thomas Schöpping | /**
|
119 | * @brief LASER_OC input signal GPIO.
|
||
120 | */
|
||
121 | static apalGpio_t _gpioLaserOc = {
|
||
122 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LASER_OC_N,
|
123 | e545e620 | Thomas Schöpping | }; |
124 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLaserOc = { |
125 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLaserOc,
|
126 | /* meta */ {
|
||
127 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
128 | ddf34c3d | Thomas Schöpping | /* active state */ TPS20xxB_LLD_OVERCURRENT_ACTIVE_STATE,
|
129 | 1e5f7648 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
130 | }, |
||
131 | }; |
||
132 | e545e620 | Thomas Schöpping | |
133 | 1e5f7648 | Thomas Schöpping | /**
|
134 | * @brief SYS_UART_DN bidirectional signal GPIO.
|
||
135 | */
|
||
136 | static apalGpio_t _gpioSysUartDn = {
|
||
137 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_UART_DN,
|
138 | e545e620 | Thomas Schöpping | }; |
139 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartDn = { |
140 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysUartDn,
|
141 | /* meta */ {
|
||
142 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
143 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
144 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
145 | }, |
||
146 | }; |
||
147 | e545e620 | Thomas Schöpping | |
148 | 1e5f7648 | Thomas Schöpping | /**
|
149 | * @brief WL_GDO2 input signal GPIO.
|
||
150 | */
|
||
151 | static apalGpio_t _gpioWlGdo2 = {
|
||
152 | 3106e8cc | Thomas Schöpping | /* line */ LINE_WL_GDO2,
|
153 | e545e620 | Thomas Schöpping | }; |
154 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo2 = { |
155 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo2,
|
156 | /* meta */ {
|
||
157 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
158 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
159 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
160 | }, |
||
161 | }; |
||
162 | e545e620 | Thomas Schöpping | |
163 | 1e5f7648 | Thomas Schöpping | /**
|
164 | * @brief WL_GDO0 input signal GPIO.
|
||
165 | */
|
||
166 | static apalGpio_t _gpioWlGdo0= {
|
||
167 | 3106e8cc | Thomas Schöpping | /* line */ LINE_WL_GDO0,
|
168 | e545e620 | Thomas Schöpping | }; |
169 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo0 = { |
170 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo0,
|
171 | /* meta */ {
|
||
172 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
173 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
174 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
175 | }, |
||
176 | }; |
||
177 | e545e620 | Thomas Schöpping | |
178 | 1e5f7648 | Thomas Schöpping | /**
|
179 | c930aa01 | Thomas Schöpping | * @brief LIGHT_XLAT output signal GPIO.
|
180 | */
|
||
181 | static apalGpio_t _gpioLightXlat = {
|
||
182 | /* line */ LINE_LIGHT_XLAT,
|
||
183 | }; |
||
184 | ROMCONST apalControlGpio_t moduleGpioLightXlat = { |
||
185 | /* GPIO */ &_gpioLightXlat,
|
||
186 | /* meta */ {
|
||
187 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
188 | /* active state */ (TLC5947_LLD_XLAT_UPDATE_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
189 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
190 | }, |
||
191 | }; |
||
192 | |||
193 | /**
|
||
194 | 1e5f7648 | Thomas Schöpping | * @brief SYS_PD bidirectional signal GPIO.
|
195 | */
|
||
196 | static apalGpio_t _gpioSysPd = {
|
||
197 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_PD_N,
|
198 | e545e620 | Thomas Schöpping | }; |
199 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysPd = { |
200 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysPd,
|
201 | /* meta */ {
|
||
202 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
203 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
204 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
205 | }, |
||
206 | }; |
||
207 | e545e620 | Thomas Schöpping | |
208 | 1e5f7648 | Thomas Schöpping | /**
|
209 | * @brief SYS_SYNC bidirectional signal GPIO.
|
||
210 | */
|
||
211 | static apalGpio_t _gpioSysSync = {
|
||
212 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_INT_N,
|
213 | e545e620 | Thomas Schöpping | }; |
214 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysSync = { |
215 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysSync,
|
216 | /* meta */ {
|
||
217 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
218 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
219 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
220 | }, |
||
221 | }; |
||
222 | e545e620 | Thomas Schöpping | |
223 | /** @} */
|
||
224 | |||
225 | /*===========================================================================*/
|
||
226 | /**
|
||
227 | * @name AMiRo-OS core configurations
|
||
228 | * @{
|
||
229 | */
|
||
230 | /*===========================================================================*/
|
||
231 | |||
232 | 2dd2e257 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
233 | acc97cbf | Thomas Schöpping | ROMCONST char* moduleShellPrompt = "LightRing"; |
234 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
235 | 6b53f6bf | Thomas Schöpping | |
236 | /** @} */
|
||
237 | |||
238 | /*===========================================================================*/
|
||
239 | /**
|
||
240 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
241 | * @{
|
||
242 | */
|
||
243 | /*===========================================================================*/
|
||
244 | |||
245 | e545e620 | Thomas Schöpping | /** @} */
|
246 | |||
247 | /*===========================================================================*/
|
||
248 | /**
|
||
249 | * @name Low-level drivers
|
||
250 | * @{
|
||
251 | */
|
||
252 | /*===========================================================================*/
|
||
253 | |||
254 | ddf34c3d | Thomas Schöpping | AT24C01BDriver moduleLldEeprom = { |
255 | e545e620 | Thomas Schöpping | /* I2C driver */ &MODULE_HAL_I2C_EEPROM,
|
256 | /* I2C address */ 0x00u, |
||
257 | }; |
||
258 | |||
259 | TLC5947Driver moduleLldLedPwm = { |
||
260 | /* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
||
261 | 1e5f7648 | Thomas Schöpping | /* BLANK signal GPIO */ &moduleGpioLightBlank,
|
262 | c930aa01 | Thomas Schöpping | /* XLAT signal GPIO */ &moduleGpioLightXlat,
|
263 | e545e620 | Thomas Schöpping | }; |
264 | |||
265 | ddf34c3d | Thomas Schöpping | TPS20xxBDriver moduleLldPowerSwitchLaser = { |
266 | 1e5f7648 | Thomas Schöpping | /* laser enable GPIO */ &moduleGpioLaserEn,
|
267 | /* laser overcurrent GPIO */ &moduleGpioLaserOc,
|
||
268 | e545e620 | Thomas Schöpping | }; |
269 | |||
270 | /** @} */
|
||
271 | |||
272 | /*===========================================================================*/
|
||
273 | /**
|
||
274 | * @name Unit tests (UT)
|
||
275 | * @{
|
||
276 | */
|
||
277 | /*===========================================================================*/
|
||
278 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
279 | |||
280 | 8be006e0 | Thomas Schöpping | /*
|
281 | ddf34c3d | Thomas Schöpping | * EEPROM (AT24C01B)
|
282 | 8be006e0 | Thomas Schöpping | */
|
283 | ddf34c3d | Thomas Schöpping | static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[]) |
284 | e545e620 | Thomas Schöpping | { |
285 | (void)argc;
|
||
286 | (void)argv;
|
||
287 | ddf34c3d | Thomas Schöpping | aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
|
288 | e545e620 | Thomas Schöpping | return AOS_OK;
|
289 | } |
||
290 | ddf34c3d | Thomas Schöpping | static ut_at24c01bdata_t _utAlldAt24c01bData = {
|
291 | e545e620 | Thomas Schöpping | /* driver */ &moduleLldEeprom,
|
292 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
293 | }; |
||
294 | ddf34c3d | Thomas Schöpping | aos_unittest_t moduleUtAlldAt24c01b = { |
295 | /* name */ "AT24C01B", |
||
296 | e545e620 | Thomas Schöpping | /* info */ "1kbit EEPROM", |
297 | ddf34c3d | Thomas Schöpping | /* test function */ utAlldAt24c01bFunc,
|
298 | e545e620 | Thomas Schöpping | /* shell command */ {
|
299 | /* name */ "unittest:EEPROM", |
||
300 | ddf34c3d | Thomas Schöpping | /* callback */ _utShellCmdCb_AlldAt24c01b,
|
301 | e545e620 | Thomas Schöpping | /* next */ NULL, |
302 | }, |
||
303 | ddf34c3d | Thomas Schöpping | /* data */ &_utAlldAt24c01bData,
|
304 | e545e620 | Thomas Schöpping | }; |
305 | |||
306 | 8be006e0 | Thomas Schöpping | /*
|
307 | ddf34c3d | Thomas Schöpping | * LED PWM driver (TLC5947)
|
308 | 8be006e0 | Thomas Schöpping | */
|
309 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[]) |
310 | { |
||
311 | (void)argc;
|
||
312 | (void)argv;
|
||
313 | aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
|
||
314 | return AOS_OK;
|
||
315 | } |
||
316 | aos_unittest_t moduleUtAlldTlc5947 = { |
||
317 | /* info */ "TLC5947", |
||
318 | /* name */ "LED PWM driver", |
||
319 | /* test function */ utAlldTlc5947Func,
|
||
320 | /* shell command */ {
|
||
321 | /* name */ "unittest:Lights", |
||
322 | /* callback */ _utShellCmdCb_Tlc5947,
|
||
323 | /* next */ NULL, |
||
324 | }, |
||
325 | /* data */ &moduleLldLedPwm,
|
||
326 | }; |
||
327 | |||
328 | 8be006e0 | Thomas Schöpping | /*
|
329 | ddf34c3d | Thomas Schöpping | * power switch (TPS2051BDBV)
|
330 | 8be006e0 | Thomas Schöpping | */
|
331 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[]) |
332 | { |
||
333 | (void)argc;
|
||
334 | (void)argv;
|
||
335 | aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
|
||
336 | return AOS_OK;
|
||
337 | } |
||
338 | aos_unittest_t moduleUtAlldTps2051bdbv = { |
||
339 | /* info */ "TPS2051BDBV", |
||
340 | /* name */ "current-limited power switch", |
||
341 | ddf34c3d | Thomas Schöpping | /* test function */ utAlldTps20xxbFunc,
|
342 | e545e620 | Thomas Schöpping | /* shell command */ {
|
343 | /* name */ "unittest:PowerSwitch", |
||
344 | /* callback */ _utShellCmdCb_Tps2051bdbv,
|
||
345 | /* next */ NULL, |
||
346 | }, |
||
347 | /* data */ &moduleLldPowerSwitchLaser,
|
||
348 | }; |
||
349 | |||
350 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
351 | e545e620 | Thomas Schöpping | |
352 | /** @} */
|
||
353 | 3940ba8a | Thomas Schöpping | /** @} */ |