Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 3106e8cc

History | View | Annotate | Download (9.097 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   SYS_PD bidirectional signal GPIO.
180
 */
181
static apalGpio_t _gpioSysPd = {
182
  /* line */ LINE_SYS_PD_N,
183
};
184
ROMCONST apalControlGpio_t moduleGpioSysPd = {
185
  /* GPIO */ &_gpioSysPd,
186
  /* meta */ {
187
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
188
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
189
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
190
  },
191
};
192

    
193
/**
194
 * @brief   SYS_SYNC bidirectional signal GPIO.
195
 */
196
static apalGpio_t _gpioSysSync = {
197
  /* line */ LINE_SYS_INT_N,
198
};
199
ROMCONST apalControlGpio_t moduleGpioSysSync = {
200
  /* GPIO */ &_gpioSysSync,
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

    
210
/*===========================================================================*/
211
/**
212
 * @name AMiRo-OS core configurations
213
 * @{
214
 */
215
/*===========================================================================*/
216

    
217
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
218
ROMCONST char* moduleShellPrompt = "LightRing";
219
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
220

    
221
/** @} */
222

    
223
/*===========================================================================*/
224
/**
225
 * @name Startup Shutdown Synchronization Protocol (SSSP)
226
 * @{
227
 */
228
/*===========================================================================*/
229

    
230
/** @} */
231

    
232
/*===========================================================================*/
233
/**
234
 * @name Low-level drivers
235
 * @{
236
 */
237
/*===========================================================================*/
238

    
239
AT24C01BDriver moduleLldEeprom = {
240
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM,
241
  /* I2C address  */ 0x00u,
242
};
243

    
244
TLC5947Driver moduleLldLedPwm = {
245
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
246
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
247
  /* XLAT signal GPIO   */ NULL,
248
};
249

    
250
TPS20xxBDriver moduleLldPowerSwitchLaser = {
251
  /* laser enable GPIO      */ &moduleGpioLaserEn,
252
  /* laser overcurrent GPIO */ &moduleGpioLaserOc,
253
};
254

    
255
/** @} */
256

    
257
/*===========================================================================*/
258
/**
259
 * @name Unit tests (UT)
260
 * @{
261
 */
262
/*===========================================================================*/
263
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
264

    
265
/*
266
 * EEPROM (AT24C01B)
267
 */
268
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
269
{
270
  (void)argc;
271
  (void)argv;
272
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
273
  return AOS_OK;
274
}
275
static ut_at24c01bdata_t _utAlldAt24c01bData = {
276
  /* driver   */ &moduleLldEeprom,
277
  /* timeout  */ MICROSECONDS_PER_SECOND,
278
};
279
aos_unittest_t moduleUtAlldAt24c01b = {
280
  /* name           */ "AT24C01B",
281
  /* info           */ "1kbit EEPROM",
282
  /* test function  */ utAlldAt24c01bFunc,
283
  /* shell command  */ {
284
    /* name     */ "unittest:EEPROM",
285
    /* callback */ _utShellCmdCb_AlldAt24c01b,
286
    /* next     */ NULL,
287
  },
288
  /* data           */ &_utAlldAt24c01bData,
289
};
290

    
291
/*
292
 * LED PWM driver (TLC5947)
293
 */
294
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
295
{
296
  (void)argc;
297
  (void)argv;
298
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
299
  return AOS_OK;
300
}
301
aos_unittest_t moduleUtAlldTlc5947 = {
302
  /* info           */ "TLC5947",
303
  /* name           */ "LED PWM driver",
304
  /* test function  */ utAlldTlc5947Func,
305
  /* shell command  */ {
306
    /* name     */ "unittest:Lights",
307
    /* callback */ _utShellCmdCb_Tlc5947,
308
    /* next     */ NULL,
309
  },
310
  /* data           */ &moduleLldLedPwm,
311
};
312

    
313
/*
314
 * power switch (TPS2051BDBV)
315
 */
316
static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[])
317
{
318
  (void)argc;
319
  (void)argv;
320
  aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
321
  return AOS_OK;
322
}
323
aos_unittest_t moduleUtAlldTps2051bdbv = {
324
  /* info           */ "TPS2051BDBV",
325
  /* name           */ "current-limited power switch",
326
  /* test function  */ utAlldTps20xxbFunc,
327
  /* shell command  */ {
328
    /* name     */ "unittest:PowerSwitch",
329
    /* callback */ _utShellCmdCb_Tps2051bdbv,
330
    /* next     */ NULL,
331
  },
332
  /* data           */ &moduleLldPowerSwitchLaser,
333
};
334

    
335
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
336

    
337
/** @} */
338
/** @} */