amiro-os / modules / LightRing_1-0 / module.c @ 908b6fb4
History | View | Annotate | Download (9.097 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 | * @brief SYS_PD bidirectional signal GPIO.
|
||
180 | */
|
||
181 | static apalGpio_t _gpioSysPd = {
|
||
182 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_PD_N,
|
183 | e545e620 | Thomas Schöpping | }; |
184 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysPd = { |
185 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysPd,
|
186 | /* meta */ {
|
||
187 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
188 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
189 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
190 | }, |
||
191 | }; |
||
192 | e545e620 | Thomas Schöpping | |
193 | 1e5f7648 | Thomas Schöpping | /**
|
194 | * @brief SYS_SYNC bidirectional signal GPIO.
|
||
195 | */
|
||
196 | static apalGpio_t _gpioSysSync = {
|
||
197 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_INT_N,
|
198 | e545e620 | Thomas Schöpping | }; |
199 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysSync = { |
200 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysSync,
|
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 | /** @} */
|
||
209 | |||
210 | /*===========================================================================*/
|
||
211 | /**
|
||
212 | * @name AMiRo-OS core configurations
|
||
213 | * @{
|
||
214 | */
|
||
215 | /*===========================================================================*/
|
||
216 | |||
217 | 2dd2e257 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
218 | acc97cbf | Thomas Schöpping | ROMCONST char* moduleShellPrompt = "LightRing"; |
219 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
220 | 6b53f6bf | Thomas Schöpping | |
221 | /** @} */
|
||
222 | |||
223 | /*===========================================================================*/
|
||
224 | /**
|
||
225 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
226 | * @{
|
||
227 | */
|
||
228 | /*===========================================================================*/
|
||
229 | |||
230 | e545e620 | Thomas Schöpping | /** @} */
|
231 | |||
232 | /*===========================================================================*/
|
||
233 | /**
|
||
234 | * @name Low-level drivers
|
||
235 | * @{
|
||
236 | */
|
||
237 | /*===========================================================================*/
|
||
238 | |||
239 | ddf34c3d | Thomas Schöpping | AT24C01BDriver moduleLldEeprom = { |
240 | e545e620 | Thomas Schöpping | /* I2C driver */ &MODULE_HAL_I2C_EEPROM,
|
241 | /* I2C address */ 0x00u, |
||
242 | }; |
||
243 | |||
244 | TLC5947Driver moduleLldLedPwm = { |
||
245 | /* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
||
246 | 1e5f7648 | Thomas Schöpping | /* BLANK signal GPIO */ &moduleGpioLightBlank,
|
247 | 3106e8cc | Thomas Schöpping | /* XLAT signal GPIO */ NULL, |
248 | e545e620 | Thomas Schöpping | }; |
249 | |||
250 | ddf34c3d | Thomas Schöpping | TPS20xxBDriver moduleLldPowerSwitchLaser = { |
251 | 1e5f7648 | Thomas Schöpping | /* laser enable GPIO */ &moduleGpioLaserEn,
|
252 | /* laser overcurrent GPIO */ &moduleGpioLaserOc,
|
||
253 | e545e620 | Thomas Schöpping | }; |
254 | |||
255 | /** @} */
|
||
256 | |||
257 | /*===========================================================================*/
|
||
258 | /**
|
||
259 | * @name Unit tests (UT)
|
||
260 | * @{
|
||
261 | */
|
||
262 | /*===========================================================================*/
|
||
263 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
264 | |||
265 | 8be006e0 | Thomas Schöpping | /*
|
266 | ddf34c3d | Thomas Schöpping | * EEPROM (AT24C01B)
|
267 | 8be006e0 | Thomas Schöpping | */
|
268 | ddf34c3d | Thomas Schöpping | static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[]) |
269 | e545e620 | Thomas Schöpping | { |
270 | (void)argc;
|
||
271 | (void)argv;
|
||
272 | ddf34c3d | Thomas Schöpping | aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
|
273 | e545e620 | Thomas Schöpping | return AOS_OK;
|
274 | } |
||
275 | ddf34c3d | Thomas Schöpping | static ut_at24c01bdata_t _utAlldAt24c01bData = {
|
276 | e545e620 | Thomas Schöpping | /* driver */ &moduleLldEeprom,
|
277 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
278 | }; |
||
279 | ddf34c3d | Thomas Schöpping | aos_unittest_t moduleUtAlldAt24c01b = { |
280 | /* name */ "AT24C01B", |
||
281 | e545e620 | Thomas Schöpping | /* info */ "1kbit EEPROM", |
282 | ddf34c3d | Thomas Schöpping | /* test function */ utAlldAt24c01bFunc,
|
283 | e545e620 | Thomas Schöpping | /* shell command */ {
|
284 | /* name */ "unittest:EEPROM", |
||
285 | ddf34c3d | Thomas Schöpping | /* callback */ _utShellCmdCb_AlldAt24c01b,
|
286 | e545e620 | Thomas Schöpping | /* next */ NULL, |
287 | }, |
||
288 | ddf34c3d | Thomas Schöpping | /* data */ &_utAlldAt24c01bData,
|
289 | e545e620 | Thomas Schöpping | }; |
290 | |||
291 | 8be006e0 | Thomas Schöpping | /*
|
292 | ddf34c3d | Thomas Schöpping | * LED PWM driver (TLC5947)
|
293 | 8be006e0 | Thomas Schöpping | */
|
294 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[]) |
295 | { |
||
296 | (void)argc;
|
||
297 | (void)argv;
|
||
298 | aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
|
||
299 | return AOS_OK;
|
||
300 | } |
||
301 | aos_unittest_t moduleUtAlldTlc5947 = { |
||
302 | /* info */ "TLC5947", |
||
303 | /* name */ "LED PWM driver", |
||
304 | /* test function */ utAlldTlc5947Func,
|
||
305 | /* shell command */ {
|
||
306 | /* name */ "unittest:Lights", |
||
307 | /* callback */ _utShellCmdCb_Tlc5947,
|
||
308 | /* next */ NULL, |
||
309 | }, |
||
310 | /* data */ &moduleLldLedPwm,
|
||
311 | }; |
||
312 | |||
313 | 8be006e0 | Thomas Schöpping | /*
|
314 | ddf34c3d | Thomas Schöpping | * power switch (TPS2051BDBV)
|
315 | 8be006e0 | Thomas Schöpping | */
|
316 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[]) |
317 | { |
||
318 | (void)argc;
|
||
319 | (void)argv;
|
||
320 | aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
|
||
321 | return AOS_OK;
|
||
322 | } |
||
323 | aos_unittest_t moduleUtAlldTps2051bdbv = { |
||
324 | /* info */ "TPS2051BDBV", |
||
325 | /* name */ "current-limited power switch", |
||
326 | ddf34c3d | Thomas Schöpping | /* test function */ utAlldTps20xxbFunc,
|
327 | e545e620 | Thomas Schöpping | /* shell command */ {
|
328 | /* name */ "unittest:PowerSwitch", |
||
329 | /* callback */ _utShellCmdCb_Tps2051bdbv,
|
||
330 | /* next */ NULL, |
||
331 | }, |
||
332 | /* data */ &moduleLldPowerSwitchLaser,
|
||
333 | }; |
||
334 | |||
335 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
336 | e545e620 | Thomas Schöpping | |
337 | /** @} */
|
||
338 | 3940ba8a | Thomas Schöpping | /** @} */ |