Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 8cbe3240

History | View | Annotate | Download (9.556 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       */ PAL_PORT(LINE_LIGHT_XLAT),
67
  /* chip select line pad number */ PAL_PAD(LINE_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       */ PAL_PORT(LINE_WL_SS_N),
76
  /* chip select line pad number */ PAL_PAD(LINE_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
  /* line */ LINE_LIGHT_BLANK,
93
};
94
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
95
  /* 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

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

    
118
/**
119
 * @brief   LASER_OC input signal GPIO.
120
 */
121
static apalGpio_t _gpioLaserOc = {
122
  /* line */ LINE_LASER_OC_N,
123
};
124
ROMCONST apalControlGpio_t moduleGpioLaserOc = {
125
  /* GPIO */ &_gpioLaserOc,
126
  /* meta */ {
127
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
128
    /* active state   */ TPS20xxB_LLD_OVERCURRENT_ACTIVE_STATE,
129
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
130
  },
131
};
132

    
133
/**
134
 * @brief   SYS_UART_DN bidirectional signal GPIO.
135
 */
136
static apalGpio_t _gpioSysUartDn = {
137
  /* line */ LINE_SYS_UART_DN,
138
};
139
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
140
  /* 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

    
148
/**
149
 * @brief   WL_GDO2 input signal GPIO.
150
 */
151
static apalGpio_t _gpioWlGdo2 = {
152
  /* line */ LINE_WL_GDO2,
153
};
154
ROMCONST apalControlGpio_t moduleGpioWlGdo2 = {
155
  /* 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

    
163
/**
164
 * @brief   WL_GDO0 input signal GPIO.
165
 */
166
static apalGpio_t _gpioWlGdo0= {
167
  /* line */ LINE_WL_GDO0,
168
};
169
ROMCONST apalControlGpio_t moduleGpioWlGdo0 = {
170
  /* 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

    
178
/**
179
 * @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
 * @brief   SYS_PD bidirectional signal GPIO.
195
 */
196
static apalGpio_t _gpioSysPd = {
197
  /* line */ LINE_SYS_PD_N,
198
};
199
ROMCONST apalControlGpio_t moduleGpioSysPd = {
200
  /* 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

    
208
/**
209
 * @brief   SYS_SYNC bidirectional signal GPIO.
210
 */
211
static apalGpio_t _gpioSysSync = {
212
  /* line */ LINE_SYS_INT_N,
213
};
214
ROMCONST apalControlGpio_t moduleGpioSysSync = {
215
  /* 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

    
223
/** @} */
224

    
225
/*===========================================================================*/
226
/**
227
 * @name AMiRo-OS core configurations
228
 * @{
229
 */
230
/*===========================================================================*/
231

    
232
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
233
ROMCONST char* moduleShellPrompt = "LightRing";
234
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
235

    
236
/** @} */
237

    
238
/*===========================================================================*/
239
/**
240
 * @name Startup Shutdown Synchronization Protocol (SSSP)
241
 * @{
242
 */
243
/*===========================================================================*/
244

    
245
/** @} */
246

    
247
/*===========================================================================*/
248
/**
249
 * @name Low-level drivers
250
 * @{
251
 */
252
/*===========================================================================*/
253

    
254
AT24C01BDriver moduleLldEeprom = {
255
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM,
256
  /* I2C address  */ 0x00u,
257
};
258

    
259
TLC5947Driver moduleLldLedPwm = {
260
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
261
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
262
  /* XLAT signal GPIO   */ &moduleGpioLightXlat,
263
};
264

    
265
TPS20xxBDriver moduleLldPowerSwitchLaser = {
266
  /* laser enable GPIO      */ &moduleGpioLaserEn,
267
  /* laser overcurrent GPIO */ &moduleGpioLaserOc,
268
};
269

    
270
/** @} */
271

    
272
/*===========================================================================*/
273
/**
274
 * @name Unit tests (UT)
275
 * @{
276
 */
277
/*===========================================================================*/
278
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
279

    
280
/*
281
 * EEPROM (AT24C01B)
282
 */
283
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
284
{
285
  (void)argc;
286
  (void)argv;
287
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
288
  return AOS_OK;
289
}
290
static ut_at24c01bdata_t _utAlldAt24c01bData = {
291
  /* driver   */ &moduleLldEeprom,
292
  /* timeout  */ MICROSECONDS_PER_SECOND,
293
};
294
aos_unittest_t moduleUtAlldAt24c01b = {
295
  /* name           */ "AT24C01B",
296
  /* info           */ "1kbit EEPROM",
297
  /* test function  */ utAlldAt24c01bFunc,
298
  /* shell command  */ {
299
    /* name     */ "unittest:EEPROM",
300
    /* callback */ _utShellCmdCb_AlldAt24c01b,
301
    /* next     */ NULL,
302
  },
303
  /* data           */ &_utAlldAt24c01bData,
304
};
305

    
306
/*
307
 * LED PWM driver (TLC5947)
308
 */
309
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
/*
329
 * power switch (TPS2051BDBV)
330
 */
331
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
  /* test function  */ utAlldTps20xxbFunc,
342
  /* shell command  */ {
343
    /* name     */ "unittest:PowerSwitch",
344
    /* callback */ _utShellCmdCb_Tps2051bdbv,
345
    /* next     */ NULL,
346
  },
347
  /* data           */ &moduleLldPowerSwitchLaser,
348
};
349

    
350
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
351

    
352
/** @} */
353
/** @} */