Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 27286ba5

History | View | Annotate | Download (9.55 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

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
/**
20
 * @file
21
 * @brief   Structures and constant for the LightRing v1.0 module.
22
 *
23
 * @addtogroup lightring_module
24
 * @{
25
 */
26

    
27
#include "module.h"
28

    
29
#include <amiroos.h>
30

    
31
/*===========================================================================*/
32
/**
33
 * @name Module specific functions
34
 * @{
35
 */
36
/*===========================================================================*/
37

    
38
/** @} */
39

    
40
/*===========================================================================*/
41
/**
42
 * @name ChibiOS/HAL configuration
43
 * @{
44
 */
45
/*===========================================================================*/
46

    
47
CANConfig moduleHalCanConfig = {
48
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
49
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
50
};
51

    
52
I2CConfig moduleHalI2cEepromConfig = {
53
  /* I²C mode   */ OPMODE_I2C,
54
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
55
  /* duty cycle */ FAST_DUTY_CYCLE_2,
56
};
57

    
58
SerialConfig moduleHalProgIfConfig = {
59
  /* bit rate */ 115200,
60
  /* CR1      */ 0,
61
  /* CR1      */ 0,
62
  /* CR1      */ 0,
63
};
64

    
65
SPIConfig moduleHalSpiLightConfig = {
66
  /* circular buffer mode        */ false,
67
  /* callback function pointer   */ NULL,
68
  /* chip select line port       */ GPIOC,
69
  /* chip select line pad number */ GPIOC_LIGHT_XLAT,
70
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
71
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
72
};
73

    
74
SPIConfig moduleHalSpiWlConfig = {
75
  /* circular buffer mode        */ false,
76
  /* callback function pointer   */ NULL,
77
  /* chip select line port       */ GPIOB,
78
  /* chip select line pad number */ GPIOB_WL_SS_N,
79
  /* CR1                         */ SPI_CR1_BR_0,
80
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
81
};
82

    
83
/*===========================================================================*/
84
/**
85
 * @name GPIO definitions
86
 * @{
87
 */
88
/*===========================================================================*/
89

    
90
/**
91
 * @brief   LIGHT_BANK output signal GPIO.
92
 */
93
static apalGpio_t _gpioLightBlank = {
94
  /* port */ GPIOA,
95
  /* pad  */ GPIOA_LIGHT_BLANK,
96
};
97
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
98
  /* GPIO */ &_gpioLightBlank,
99
  /* meta */ {
100
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
101
    /* active state   */ TLC5947_LLD_BLANK_ACTIVE_STATE,
102
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
103
  },
104
};
105

    
106
/**
107
 * @brief   LASER_EN output signal GPIO.
108
 */
109
static apalGpio_t _gpioLaserEn = {
110
  /* port */ GPIOB,
111
  /* pad  */ GPIOB_LASER_EN,
112
};
113
ROMCONST apalControlGpio_t moduleGpioLaserEn = {
114
  /* GPIO */ &_gpioLaserEn,
115
  /* meta */ {
116
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
117
    /* active state   */ TPS2051B_LLD_ENABLE_ACTIVE_STATE,
118
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
119
  },
120
};
121

    
122
/**
123
 * @brief   LASER_OC input signal GPIO.
124
 */
125
static apalGpio_t _gpioLaserOc = {
126
  /* port */ GPIOB,
127
  /* pad  */ GPIOB_LASER_OC_N,
128
};
129
ROMCONST apalControlGpio_t moduleGpioLaserOc = {
130
  /* GPIO */ &_gpioLaserOc,
131
  /* meta */ {
132
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
133
    /* active state   */ TPS2051B_LLD_OVERCURRENT_ACTIVE_STATE,
134
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
135
  },
136
};
137

    
138
/**
139
 * @brief   SYS_UART_DN bidirectional signal GPIO.
140
 */
141
static apalGpio_t _gpioSysUartDn = {
142
  /* port */ GPIOB,
143
  /* pad  */ GPIOB_SYS_UART_DN,
144
};
145
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
146
  /* GPIO */ &_gpioSysUartDn,
147
  /* meta */ {
148
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
149
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
150
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
151
  },
152
};
153

    
154
/**
155
 * @brief   WL_GDO2 input signal GPIO.
156
 */
157
static apalGpio_t _gpioWlGdo2 = {
158
  /* port */ GPIOB,
159
  /* pad  */ GPIOB_WL_GDO2,
160
};
161
ROMCONST apalControlGpio_t moduleGpioWlGdo2 = {
162
  /* GPIO */ &_gpioWlGdo2,
163
  /* meta */ {
164
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
165
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
166
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
167
  },
168
};
169

    
170
/**
171
 * @brief   WL_GDO0 input signal GPIO.
172
 */
173
static apalGpio_t _gpioWlGdo0= {
174
  /* port */ GPIOB,
175
  /* pad  */ GPIOB_WL_GDO0,
176
};
177
ROMCONST apalControlGpio_t moduleGpioWlGdo0 = {
178
  /* GPIO */ &_gpioWlGdo0,
179
  /* meta */ {
180
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
181
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
182
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
183
  },
184
};
185

    
186
/**
187
 * @brief   LIGHT_XLAT output signal GPIO.
188
 */
189
static apalGpio_t _gpioLightXlat = {
190
  /* port */ GPIOC,
191
  /* pad  */ GPIOC_LIGHT_XLAT,
192
};
193
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
194
  /* GPIO */ &_gpioLightXlat,
195
  /* meta */ {
196
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
197
    /* active state   */ TLC5947_LLD_XLAT_ACTIVE_STATE,
198
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
199
  },
200
};
201

    
202
/**
203
 * @brief   SYS_PD bidirectional signal GPIO.
204
 */
205
static apalGpio_t _gpioSysPd = {
206
  /* port */ GPIOC,
207
  /* pad  */ GPIOC_SYS_PD_N,
208
};
209
ROMCONST apalControlGpio_t moduleGpioSysPd = {
210
  /* GPIO */ &_gpioSysPd,
211
  /* meta */ {
212
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
213
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
214
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
215
  },
216
};
217

    
218
/**
219
 * @brief   SYS_SYNC bidirectional signal GPIO.
220
 */
221
static apalGpio_t _gpioSysSync = {
222
  /* port */ GPIOD,
223
  /* pad  */ GPIOD_SYS_INT_N,
224
};
225
ROMCONST apalControlGpio_t moduleGpioSysSync = {
226
  /* GPIO */ &_gpioSysSync,
227
  /* meta */ {
228
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
229
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
230
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
231
  },
232
};
233

    
234
/** @} */
235

    
236
/*===========================================================================*/
237
/**
238
 * @name AMiRo-OS core configurations
239
 * @{
240
 */
241
/*===========================================================================*/
242

    
243
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
244
ROMCONST char* moduleShellPrompt = "LightRing";
245
#endif
246

    
247
/** @} */
248

    
249
/*===========================================================================*/
250
/**
251
 * @name Startup Shutdown Synchronization Protocol (SSSP)
252
 * @{
253
 */
254
/*===========================================================================*/
255

    
256
/** @} */
257

    
258
/*===========================================================================*/
259
/**
260
 * @name Low-level drivers
261
 * @{
262
 */
263
/*===========================================================================*/
264

    
265
AT24C01BNDriver moduleLldEeprom = {
266
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM,
267
  /* I2C address  */ 0x00u,
268
};
269

    
270
TLC5947Driver moduleLldLedPwm = {
271
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
272
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
273
  /* XLAT signal GPIO   */ &moduleGpioLightXlat,
274
};
275

    
276
TPS2051BDriver moduleLldPowerSwitchLaser = {
277
  /* laser enable GPIO      */ &moduleGpioLaserEn,
278
  /* laser overcurrent GPIO */ &moduleGpioLaserOc,
279
};
280

    
281
/** @} */
282

    
283
/*===========================================================================*/
284
/**
285
 * @name Unit tests (UT)
286
 * @{
287
 */
288
/*===========================================================================*/
289
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
290

    
291
/*
292
 * EEPROM (AT24C01BN)
293
 */
294
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
295
{
296
  (void)argc;
297
  (void)argv;
298
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
299
  return AOS_OK;
300
}
301
static ut_at24c01bndata_t _utAt24c01bnData = {
302
  /* driver   */ &moduleLldEeprom,
303
  /* timeout  */ MICROSECONDS_PER_SECOND,
304
};
305
aos_unittest_t moduleUtAlldAt24c01bn = {
306
  /* name           */ "AT24C01BN-SH-B",
307
  /* info           */ "1kbit EEPROM",
308
  /* test function  */ utAlldAt24c01bnFunc,
309
  /* shell command  */ {
310
    /* name     */ "unittest:EEPROM",
311
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
312
    /* next     */ NULL,
313
  },
314
  /* data           */ &_utAt24c01bnData,
315
};
316

    
317
/*
318
 * LED PWM driver (TLD5947)
319
 */
320
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
321
{
322
  (void)argc;
323
  (void)argv;
324
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
325
  return AOS_OK;
326
}
327
aos_unittest_t moduleUtAlldTlc5947 = {
328
  /* info           */ "TLC5947",
329
  /* name           */ "LED PWM driver",
330
  /* test function  */ utAlldTlc5947Func,
331
  /* shell command  */ {
332
    /* name     */ "unittest:Lights",
333
    /* callback */ _utShellCmdCb_Tlc5947,
334
    /* next     */ NULL,
335
  },
336
  /* data           */ &moduleLldLedPwm,
337
};
338

    
339
/*
340
 * power switch (Laser)
341
 */
342
static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[])
343
{
344
  (void)argc;
345
  (void)argv;
346
  aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
347
  return AOS_OK;
348
}
349
aos_unittest_t moduleUtAlldTps2051bdbv = {
350
  /* info           */ "TPS2051BDBV",
351
  /* name           */ "current-limited power switch",
352
  /* test function  */ utAlldTps2051bdbvFunc,
353
  /* shell command  */ {
354
    /* name     */ "unittest:PowerSwitch",
355
    /* callback */ _utShellCmdCb_Tps2051bdbv,
356
    /* next     */ NULL,
357
  },
358
  /* data           */ &moduleLldPowerSwitchLaser,
359
};
360

    
361
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
362

    
363
/** @} */