Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 4c72a54c

History | View | Annotate | Download (9.705 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
/*===========================================================================*/
84
/**
85
 * @name GPIO definitions
86
 * @{
87
 */
88
/*===========================================================================*/
89

    
90
/**
91
 * @brief   LIGHT_BANK output signal GPIO.
92
 */
93
static apalGpio_t _gpioLightBlank = {
94
  /* line */ LINE_LIGHT_BLANK,
95
};
96
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
97
  /* 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

    
105
/**
106
 * @brief   LASER_EN output signal GPIO.
107
 */
108
static apalGpio_t _gpioLaserEn = {
109
  /* line */ LINE_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
  /* line */ LINE_LASER_OC_N,
125
};
126
ROMCONST apalControlGpio_t moduleGpioLaserOc = {
127
  /* GPIO */ &_gpioLaserOc,
128
  /* meta */ {
129
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
130
    /* active state   */ TPS20xxB_LLD_OVERCURRENT_ACTIVE_STATE,
131
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
132
  },
133
};
134

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

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

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

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

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

    
225
/** @} */
226

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

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

    
238
/** @} */
239

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

    
247
/** @} */
248

    
249
/*===========================================================================*/
250
/**
251
 * @name Low-level drivers
252
 * @{
253
 */
254
/*===========================================================================*/
255

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

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

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

    
272
/** @} */
273

    
274
/*===========================================================================*/
275
/**
276
 * @name Tests
277
 * @{
278
 */
279
/*===========================================================================*/
280
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
281

    
282
/*
283
 * AT24C01BN-SH-B (EEPROM)
284
 */
285
#include <module_test_AT24C01B.h>
286
static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
287
{
288
  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
289
}
290
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
291

    
292
/*
293
 * TLC5947 (24 channel PWM LED driver)
294
 */
295
#include <module_test_TLC5947.h>
296
static int _testTlc5947ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
297
{
298
  return moduleTestTlc5947ShellCb(stream, argc, argv, NULL);
299
}
300
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

    
312
/*
313
 * entire module
314
 */
315
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
316
{
317
  (void)argc;
318
  (void)argv;
319

    
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
}
343
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
344

    
345
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
346

    
347
/** @} */
348
/** @} */