Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 9a7e49d4

History | View | Annotate | Download (9.383 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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
#include "module.h"
20

    
21
#include <amiroos.h>
22

    
23
/*===========================================================================*/
24
/**
25
 * @name Module specific functions
26
 * @{
27
 */
28
/*===========================================================================*/
29

    
30
/** @} */
31

    
32
/*===========================================================================*/
33
/**
34
 * @name ChibiOS/HAL configuration
35
 * @{
36
 */
37
/*===========================================================================*/
38

    
39
CANConfig moduleHalCanConfig = {
40
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
41
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
42
};
43

    
44
I2CConfig moduleHalI2cEepromConfig = {
45
  /* I²C mode   */ OPMODE_I2C,
46
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
47
  /* duty cycle */ FAST_DUTY_CYCLE_2,
48
};
49

    
50
SerialConfig moduleHalProgIfConfig = {
51
  /* bit rate */ 115200,
52
  /* CR1      */ 0,
53
  /* CR1      */ 0,
54
  /* CR1      */ 0,
55
};
56

    
57
SPIConfig moduleHalSpiLightConfig = {
58
  /* circular buffer mode        */ false,
59
  /* callback function pointer   */ NULL,
60
  /* chip select line port       */ GPIOC,
61
  /* chip select line pad number */ GPIOC_LIGHT_XLAT,
62
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
63
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
64
};
65

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

    
75
/*===========================================================================*/
76
/**
77
 * @name GPIO definitions
78
 * @{
79
 */
80
/*===========================================================================*/
81

    
82
/**
83
 * @brief   LIGHT_BANK output signal GPIO.
84
 */
85
static apalGpio_t _gpioLightBlank = {
86
  /* port */ GPIOA,
87
  /* pad  */ GPIOA_LIGHT_BLANK,
88
};
89
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
90
  /* GPIO */ &_gpioLightBlank,
91
  /* meta */ {
92
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
93
    /* active state   */ TLC5947_LLD_BLANK_ACTIVE_STATE,
94
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
95
  },
96
};
97

    
98
/**
99
 * @brief   LASER_EN output signal GPIO.
100
 */
101
static apalGpio_t _gpioLaserEn = {
102
  /* port */ GPIOB,
103
  /* pad  */ GPIOB_LASER_EN,
104
};
105
ROMCONST apalControlGpio_t moduleGpioLaserEn = {
106
  /* GPIO */ &_gpioLaserEn,
107
  /* meta */ {
108
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
109
    /* active state   */ TPS2051B_LLD_ENABLE_ACTIVE_STATE,
110
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
111
  },
112
};
113

    
114
/**
115
 * @brief   LASER_OC input signal GPIO.
116
 */
117
static apalGpio_t _gpioLaserOc = {
118
  /* port */ GPIOB,
119
  /* pad  */ GPIOB_LASER_OC_N,
120
};
121
ROMCONST apalControlGpio_t moduleGpioLaserOc = {
122
  /* GPIO */ &_gpioLaserOc,
123
  /* meta */ {
124
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
125
    /* active state   */ TPS2051B_LLD_OVERCURRENT_ACTIVE_STATE,
126
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
127
  },
128
};
129

    
130
/**
131
 * @brief   SYS_UART_DN bidirectional signal GPIO.
132
 */
133
static apalGpio_t _gpioSysUartDn = {
134
  /* port */ GPIOB,
135
  /* pad  */ GPIOB_SYS_UART_DN,
136
};
137
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
138
  /* GPIO */ &_gpioSysUartDn,
139
  /* meta */ {
140
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
141
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
142
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
143
  },
144
};
145

    
146
/**
147
 * @brief   WL_GDO2 input signal GPIO.
148
 */
149
static apalGpio_t _gpioWlGdo2 = {
150
  /* port */ GPIOB,
151
  /* pad  */ GPIOB_WL_GDO2,
152
};
153
ROMCONST apalControlGpio_t moduleGpioWlGdo2 = {
154
  /* GPIO */ &_gpioWlGdo2,
155
  /* meta */ {
156
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
157
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
158
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
159
  },
160
};
161

    
162
/**
163
 * @brief   WL_GDO0 input signal GPIO.
164
 */
165
static apalGpio_t _gpioWlGdo0= {
166
  /* port */ GPIOB,
167
  /* pad  */ GPIOB_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
  /* port */ GPIOC,
183
  /* pad  */ GPIOC_LIGHT_XLAT,
184
};
185
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
186
  /* GPIO */ &_gpioLightXlat,
187
  /* meta */ {
188
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
189
    /* active state   */ TLC5947_LLD_XLAT_ACTIVE_STATE,
190
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
191
  },
192
};
193

    
194
/**
195
 * @brief   SYS_PD bidirectional signal GPIO.
196
 */
197
static apalGpio_t _gpioSysPd = {
198
  /* port */ GPIOC,
199
  /* pad  */ GPIOC_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
  /* port */ GPIOD,
215
  /* pad  */ GPIOD_SYS_INT_N,
216
};
217
ROMCONST apalControlGpio_t moduleGpioSysSync = {
218
  /* GPIO */ &_gpioSysSync,
219
  /* meta */ {
220
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
221
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
222
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
223
  },
224
};
225

    
226
/** @} */
227

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

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

    
239
/** @} */
240

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

    
248
/** @} */
249

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

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

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

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

    
273
/** @} */
274

    
275
/*===========================================================================*/
276
/**
277
 * @name Unit tests (UT)
278
 * @{
279
 */
280
/*===========================================================================*/
281
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
282

    
283
/* EEPROM (AT24C01BN) */
284
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
285
{
286
  (void)argc;
287
  (void)argv;
288
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
289
  return AOS_OK;
290
}
291
static ut_at24c01bndata_t _utAt24c01bnData = {
292
  /* driver   */ &moduleLldEeprom,
293
  /* timeout  */ MICROSECONDS_PER_SECOND,
294
};
295
aos_unittest_t moduleUtAlldAt24c01bn = {
296
  /* name           */ "AT24C01BN-SH-B",
297
  /* info           */ "1kbit EEPROM",
298
  /* test function  */ utAlldAt24c01bnFunc,
299
  /* shell command  */ {
300
    /* name     */ "unittest:EEPROM",
301
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
302
    /* next     */ NULL,
303
  },
304
  /* data           */ &_utAt24c01bnData,
305
};
306

    
307
/* LED PWM driver (TLD5947) */
308
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
309
{
310
  (void)argc;
311
  (void)argv;
312
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
313
  return AOS_OK;
314
}
315
aos_unittest_t moduleUtAlldTlc5947 = {
316
  /* info           */ "TLC5947",
317
  /* name           */ "LED PWM driver",
318
  /* test function  */ utAlldTlc5947Func,
319
  /* shell command  */ {
320
    /* name     */ "unittest:Lights",
321
    /* callback */ _utShellCmdCb_Tlc5947,
322
    /* next     */ NULL,
323
  },
324
  /* data           */ &moduleLldLedPwm,
325
};
326

    
327
/* power switch (Laser) */
328
static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[])
329
{
330
  (void)argc;
331
  (void)argv;
332
  aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
333
  return AOS_OK;
334
}
335
aos_unittest_t moduleUtAlldTps2051bdbv = {
336
  /* info           */ "TPS2051BDBV",
337
  /* name           */ "current-limited power switch",
338
  /* test function  */ utAlldTps2051bdbvFunc,
339
  /* shell command  */ {
340
    /* name     */ "unittest:PowerSwitch",
341
    /* callback */ _utShellCmdCb_Tps2051bdbv,
342
    /* next     */ NULL,
343
  },
344
  /* data           */ &moduleLldPowerSwitchLaser,
345
};
346

    
347
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
348

    
349
/** @} */