Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 651cb6e6

History | View | Annotate | Download (9.617 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
/*===========================================================================*/
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
  /* circular buffer mode        */ false,
65
  /* 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
};
71

    
72
SPIConfig moduleHalSpiWlConfig = {
73
  /* 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
  /* CR1                         */ SPI_CR1_BR_0,
78
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
79
};
80

    
81
/*===========================================================================*/
82
/**
83
 * @name GPIO definitions
84
 * @{
85
 */
86
/*===========================================================================*/
87

    
88
/**
89
 * @brief   LIGHT_BANK output signal GPIO.
90
 */
91
static apalGpio_t _gpioLightBlank = {
92
  /* port */ GPIOA,
93
  /* pad  */ GPIOA_LIGHT_BLANK,
94
};
95
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
96
  /* 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

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

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

    
136
/**
137
 * @brief   SYS_UART_DN bidirectional signal GPIO.
138
 */
139
static apalGpio_t _gpioSysUartDn = {
140
  /* port */ GPIOB,
141
  /* pad  */ GPIOB_SYS_UART_DN,
142
};
143
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
144
  /* 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

    
152
/**
153
 * @brief   WL_GDO2 input signal GPIO.
154
 */
155
static apalGpio_t _gpioWlGdo2 = {
156
  /* port */ GPIOB,
157
  /* pad  */ GPIOB_WL_GDO2,
158
};
159
ROMCONST apalControlGpio_t moduleGpioWlGdo2 = {
160
  /* 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

    
168
/**
169
 * @brief   WL_GDO0 input signal GPIO.
170
 */
171
static apalGpio_t _gpioWlGdo0= {
172
  /* port */ GPIOB,
173
  /* pad  */ GPIOB_WL_GDO0,
174
};
175
ROMCONST apalControlGpio_t moduleGpioWlGdo0 = {
176
  /* 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

    
184
/**
185
 * @brief   LIGHT_XLAT output signal GPIO.
186
 */
187
static apalGpio_t _gpioLightXlat = {
188
  /* port */ GPIOC,
189
  /* pad  */ GPIOC_LIGHT_XLAT,
190
};
191
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
192
  /* 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

    
200
/**
201
 * @brief   SYS_PD bidirectional signal GPIO.
202
 */
203
static apalGpio_t _gpioSysPd = {
204
  /* port */ GPIOC,
205
  /* pad  */ GPIOC_SYS_PD_N,
206
};
207
ROMCONST apalControlGpio_t moduleGpioSysPd = {
208
  /* 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

    
216
/**
217
 * @brief   SYS_SYNC bidirectional signal GPIO.
218
 */
219
static apalGpio_t _gpioSysSync = {
220
  /* port */ GPIOD,
221
  /* pad  */ GPIOD_SYS_INT_N,
222
};
223
ROMCONST apalControlGpio_t moduleGpioSysSync = {
224
  /* 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

    
232
/** @} */
233

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

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

    
245
/** @} */
246

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

    
254
/** @} */
255

    
256
/*===========================================================================*/
257
/**
258
 * @name Low-level drivers
259
 * @{
260
 */
261
/*===========================================================================*/
262

    
263
AT24C01BDriver moduleLldEeprom = {
264
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM,
265
  /* I2C address  */ 0x00u,
266
};
267

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

    
274
TPS20xxBDriver moduleLldPowerSwitchLaser = {
275
  /* laser enable GPIO      */ &moduleGpioLaserEn,
276
  /* laser overcurrent GPIO */ &moduleGpioLaserOc,
277
};
278

    
279
/** @} */
280

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

    
289
/*
290
 * EEPROM (AT24C01B)
291
 */
292
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
293
{
294
  (void)argc;
295
  (void)argv;
296
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
297
  return AOS_OK;
298
}
299
static ut_at24c01bdata_t _utAlldAt24c01bData = {
300
  /* driver   */ &moduleLldEeprom,
301
  /* timeout  */ MICROSECONDS_PER_SECOND,
302
};
303
aos_unittest_t moduleUtAlldAt24c01b = {
304
  /* name           */ "AT24C01B",
305
  /* info           */ "1kbit EEPROM",
306
  /* test function  */ utAlldAt24c01bFunc,
307
  /* shell command  */ {
308
    /* name     */ "unittest:EEPROM",
309
    /* callback */ _utShellCmdCb_AlldAt24c01b,
310
    /* next     */ NULL,
311
  },
312
  /* data           */ &_utAlldAt24c01bData,
313
};
314

    
315
/*
316
 * LED PWM driver (TLC5947)
317
 */
318
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
/*
338
 * power switch (TPS2051BDBV)
339
 */
340
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
  /* test function  */ utAlldTps20xxbFunc,
351
  /* shell command  */ {
352
    /* name     */ "unittest:PowerSwitch",
353
    /* callback */ _utShellCmdCb_Tps2051bdbv,
354
    /* next     */ NULL,
355
  },
356
  /* data           */ &moduleLldPowerSwitchLaser,
357
};
358

    
359
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
360

    
361
/** @} */
362
/** @} */