amiro-os / modules / LightRing_1-0 / module.c @ f38aba21
History | View | Annotate | Download (9.705 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 | 4c72a54c | Thomas Schöpping | /** @} */
|
82 | |||
83 | e545e620 | Thomas Schöpping | /*===========================================================================*/
|
84 | /**
|
||
85 | * @name GPIO definitions
|
||
86 | * @{
|
||
87 | */
|
||
88 | /*===========================================================================*/
|
||
89 | |||
90 | 1e5f7648 | Thomas Schöpping | /**
|
91 | * @brief LIGHT_BANK output signal GPIO.
|
||
92 | */
|
||
93 | static apalGpio_t _gpioLightBlank = {
|
||
94 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LIGHT_BLANK,
|
95 | e545e620 | Thomas Schöpping | }; |
96 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLightBlank = { |
97 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLightBlank,
|
98 | /* meta */ {
|
||
99 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
100 | /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
||
101 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
102 | }, |
||
103 | }; |
||
104 | e545e620 | Thomas Schöpping | |
105 | 1e5f7648 | Thomas Schöpping | /**
|
106 | * @brief LASER_EN output signal GPIO.
|
||
107 | */
|
||
108 | static apalGpio_t _gpioLaserEn = {
|
||
109 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LASER_EN,
|
110 | e545e620 | Thomas Schöpping | }; |
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 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LASER_OC_N,
|
125 | e545e620 | Thomas Schöpping | }; |
126 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLaserOc = { |
127 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLaserOc,
|
128 | /* meta */ {
|
||
129 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
130 | ddf34c3d | Thomas Schöpping | /* active state */ TPS20xxB_LLD_OVERCURRENT_ACTIVE_STATE,
|
131 | 1e5f7648 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
132 | }, |
||
133 | }; |
||
134 | e545e620 | Thomas Schöpping | |
135 | 1e5f7648 | Thomas Schöpping | /**
|
136 | * @brief SYS_UART_DN bidirectional signal GPIO.
|
||
137 | */
|
||
138 | static apalGpio_t _gpioSysUartDn = {
|
||
139 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_UART_DN,
|
140 | e545e620 | Thomas Schöpping | }; |
141 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartDn = { |
142 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysUartDn,
|
143 | /* meta */ {
|
||
144 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
145 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
146 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
147 | }, |
||
148 | }; |
||
149 | e545e620 | Thomas Schöpping | |
150 | 1e5f7648 | Thomas Schöpping | /**
|
151 | * @brief WL_GDO2 input signal GPIO.
|
||
152 | */
|
||
153 | static apalGpio_t _gpioWlGdo2 = {
|
||
154 | 3106e8cc | Thomas Schöpping | /* line */ LINE_WL_GDO2,
|
155 | e545e620 | Thomas Schöpping | }; |
156 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo2 = { |
157 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo2,
|
158 | /* meta */ {
|
||
159 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
160 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
161 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
162 | }, |
||
163 | }; |
||
164 | e545e620 | Thomas Schöpping | |
165 | 1e5f7648 | Thomas Schöpping | /**
|
166 | * @brief WL_GDO0 input signal GPIO.
|
||
167 | */
|
||
168 | static apalGpio_t _gpioWlGdo0= {
|
||
169 | 3106e8cc | Thomas Schöpping | /* line */ LINE_WL_GDO0,
|
170 | e545e620 | Thomas Schöpping | }; |
171 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo0 = { |
172 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo0,
|
173 | /* meta */ {
|
||
174 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
175 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
176 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
177 | }, |
||
178 | }; |
||
179 | e545e620 | Thomas Schöpping | |
180 | 1e5f7648 | Thomas Schöpping | /**
|
181 | c930aa01 | Thomas Schöpping | * @brief LIGHT_XLAT output signal GPIO.
|
182 | */
|
||
183 | static apalGpio_t _gpioLightXlat = {
|
||
184 | /* line */ LINE_LIGHT_XLAT,
|
||
185 | }; |
||
186 | ROMCONST apalControlGpio_t moduleGpioLightXlat = { |
||
187 | /* GPIO */ &_gpioLightXlat,
|
||
188 | /* meta */ {
|
||
189 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
190 | /* active state */ (TLC5947_LLD_XLAT_UPDATE_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
191 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
192 | }, |
||
193 | }; |
||
194 | |||
195 | /**
|
||
196 | 1e5f7648 | Thomas Schöpping | * @brief SYS_PD bidirectional signal GPIO.
|
197 | */
|
||
198 | static apalGpio_t _gpioSysPd = {
|
||
199 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_PD_N,
|
200 | e545e620 | Thomas Schöpping | }; |
201 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysPd = { |
202 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysPd,
|
203 | /* meta */ {
|
||
204 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
205 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
206 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
207 | }, |
||
208 | }; |
||
209 | e545e620 | Thomas Schöpping | |
210 | 1e5f7648 | Thomas Schöpping | /**
|
211 | * @brief SYS_SYNC bidirectional signal GPIO.
|
||
212 | */
|
||
213 | static apalGpio_t _gpioSysSync = {
|
||
214 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_INT_N,
|
215 | e545e620 | Thomas Schöpping | }; |
216 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysSync = { |
217 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysSync,
|
218 | /* meta */ {
|
||
219 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
220 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
221 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
222 | }, |
||
223 | }; |
||
224 | e545e620 | Thomas Schöpping | |
225 | /** @} */
|
||
226 | |||
227 | /*===========================================================================*/
|
||
228 | /**
|
||
229 | * @name AMiRo-OS core configurations
|
||
230 | * @{
|
||
231 | */
|
||
232 | /*===========================================================================*/
|
||
233 | |||
234 | 2dd2e257 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
235 | acc97cbf | Thomas Schöpping | ROMCONST char* moduleShellPrompt = "LightRing"; |
236 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
237 | 6b53f6bf | Thomas Schöpping | |
238 | /** @} */
|
||
239 | |||
240 | /*===========================================================================*/
|
||
241 | /**
|
||
242 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
243 | * @{
|
||
244 | */
|
||
245 | /*===========================================================================*/
|
||
246 | |||
247 | e545e620 | Thomas Schöpping | /** @} */
|
248 | |||
249 | /*===========================================================================*/
|
||
250 | /**
|
||
251 | * @name Low-level drivers
|
||
252 | * @{
|
||
253 | */
|
||
254 | /*===========================================================================*/
|
||
255 | |||
256 | ddf34c3d | Thomas Schöpping | AT24C01BDriver moduleLldEeprom = { |
257 | e545e620 | Thomas Schöpping | /* I2C driver */ &MODULE_HAL_I2C_EEPROM,
|
258 | /* I2C address */ 0x00u, |
||
259 | }; |
||
260 | |||
261 | TLC5947Driver moduleLldLedPwm = { |
||
262 | /* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
||
263 | 1e5f7648 | Thomas Schöpping | /* BLANK signal GPIO */ &moduleGpioLightBlank,
|
264 | c930aa01 | Thomas Schöpping | /* XLAT signal GPIO */ &moduleGpioLightXlat,
|
265 | e545e620 | Thomas Schöpping | }; |
266 | |||
267 | ddf34c3d | Thomas Schöpping | TPS20xxBDriver moduleLldPowerSwitchLaser = { |
268 | 1e5f7648 | Thomas Schöpping | /* laser enable GPIO */ &moduleGpioLaserEn,
|
269 | /* laser overcurrent GPIO */ &moduleGpioLaserOc,
|
||
270 | e545e620 | Thomas Schöpping | }; |
271 | |||
272 | /** @} */
|
||
273 | |||
274 | /*===========================================================================*/
|
||
275 | /**
|
||
276 | 4c72a54c | Thomas Schöpping | * @name Tests
|
277 | e545e620 | Thomas Schöpping | * @{
|
278 | */
|
||
279 | /*===========================================================================*/
|
||
280 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
281 | |||
282 | 8be006e0 | Thomas Schöpping | /*
|
283 | 4c72a54c | Thomas Schöpping | * AT24C01BN-SH-B (EEPROM)
|
284 | 8be006e0 | Thomas Schöpping | */
|
285 | 4c72a54c | Thomas Schöpping | #include <module_test_AT24C01B.h> |
286 | static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
287 | e545e620 | Thomas Schöpping | { |
288 | 4c72a54c | Thomas Schöpping | return moduleTestAt24c01bShellCb(stream, argc, argv, NULL); |
289 | e545e620 | Thomas Schöpping | } |
290 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
|
291 | e545e620 | Thomas Schöpping | |
292 | 8be006e0 | Thomas Schöpping | /*
|
293 | 4c72a54c | Thomas Schöpping | * TLC5947 (24 channel PWM LED driver)
|
294 | 8be006e0 | Thomas Schöpping | */
|
295 | 4c72a54c | Thomas Schöpping | #include <module_test_TLC5947.h> |
296 | static int _testTlc5947ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
297 | e545e620 | Thomas Schöpping | { |
298 | 4c72a54c | Thomas Schöpping | return moduleTestTlc5947ShellCb(stream, argc, argv, NULL); |
299 | e545e620 | Thomas Schöpping | } |
300 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestTlc5947ShellCmd, "test:Lights", _testTlc5947ShellCmdCb);
|
301 | |||
302 | /*
|
||
303 | * TPS2051BDBV (Current-limited power switch)
|
||
304 | */
|
||
305 | #include <module_test_TPS20xxB.h> |
||
306 | static int _testTps2051bdbvShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
307 | { |
||
308 | return moduleTestTps20xxbShellCb(stream, argc, argv, NULL); |
||
309 | } |
||
310 | AOS_SHELL_COMMAND(moduleTestTps2051bdbvShellCmd, "test:PowerSwitch", _testTps2051bdbvShellCmdCb);
|
||
311 | e545e620 | Thomas Schöpping | |
312 | 8be006e0 | Thomas Schöpping | /*
|
313 | 4c72a54c | Thomas Schöpping | * entire module
|
314 | 8be006e0 | Thomas Schöpping | */
|
315 | 4c72a54c | Thomas Schöpping | static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
316 | e545e620 | Thomas Schöpping | { |
317 | (void)argc;
|
||
318 | (void)argv;
|
||
319 | 4c72a54c | Thomas Schöpping | |
320 | int status = AOS_OK;
|
||
321 | char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL}; |
||
322 | aos_testresult_t result_test = {0, 0}; |
||
323 | aos_testresult_t result_total = {0, 0}; |
||
324 | |||
325 | /* AT24C01B (EEPROM) */
|
||
326 | status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
|
||
327 | result_total = aosTestResultAdd(result_total, result_test); |
||
328 | |||
329 | /* TLC5947 (24 channel LED PWM driver) */
|
||
330 | status |= moduleTestTlc5947ShellCb(stream, 0, targv, &result_test);
|
||
331 | result_total = aosTestResultAdd(result_total, result_test); |
||
332 | |||
333 | /* TPS2051BDBV (Current-limited power switch) */
|
||
334 | status |= moduleTestTps20xxbShellCb(stream, 0, targv, &result_test);
|
||
335 | result_total = aosTestResultAdd(result_total, result_test); |
||
336 | |||
337 | // print total result
|
||
338 | chprintf(stream, "\n");
|
||
339 | aosTestResultPrintSummary(stream, &result_total, "entire module");
|
||
340 | |||
341 | return status;
|
||
342 | e545e620 | Thomas Schöpping | } |
343 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
|
344 | e545e620 | Thomas Schöpping | |
345 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
346 | e545e620 | Thomas Schöpping | |
347 | /** @} */
|
||
348 | 3940ba8a | Thomas Schöpping | /** @} */ |