Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 738a28c8

History | View | Annotate | Download (8.97 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
/*===========================================================================*/
67
/**
68
 * @name GPIO definitions
69
 * @{
70
 */
71
/*===========================================================================*/
72

    
73
/**
74
 * @brief   LIGHT_BANK output signal GPIO.
75
 */
76
static apalGpio_t _gpioLightBlank = {
77
  /* port */ GPIOA,
78
  /* pad  */ GPIOA_LIGHT_BLANK,
79
};
80
apalControlGpio_t moduleGpioLightBlank = {
81
  /* GPIO */ &_gpioLightBlank,
82
  /* meta */ {
83
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
84
    /* active state   */ TLC5947_LLD_BLANK_ACTIVE_STATE,
85
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
86
  },
87
};
88

    
89
/**
90
 * @brief   LASER_EN output signal GPIO.
91
 */
92
static apalGpio_t _gpioLaserEn = {
93
  /* port */ GPIOB,
94
  /* pad  */ GPIOB_LASER_EN,
95
};
96
apalControlGpio_t moduleGpioLaserEn = {
97
  /* GPIO */ &_gpioLaserEn,
98
  /* meta */ {
99
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
100
    /* active state   */ TPS2051B_LLD_ENABLE_ACTIVE_STATE,
101
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
102
  },
103
};
104

    
105
/**
106
 * @brief   LASER_OC input signal GPIO.
107
 */
108
static apalGpio_t _gpioLaserOc = {
109
  /* port */ GPIOB,
110
  /* pad  */ GPIOB_LASER_OC_N,
111
};
112
apalControlGpio_t moduleGpioLaserOc = {
113
  /* GPIO */ &_gpioLaserOc,
114
  /* meta */ {
115
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
116
    /* active state   */ TPS2051B_LLD_OVERCURRENT_ACTIVE_STATE,
117
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
118
  },
119
};
120

    
121
/**
122
 * @brief   SYS_UART_DN bidirectional signal GPIO.
123
 */
124
static apalGpio_t _gpioSysUartDn = {
125
  /* port */ GPIOB,
126
  /* pad  */ GPIOB_SYS_UART_DN,
127
};
128
apalControlGpio_t moduleGpioSysUartDn = {
129
  /* GPIO */ &_gpioSysUartDn,
130
  /* meta */ {
131
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
132
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
133
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
134
  },
135
};
136

    
137
/**
138
 * @brief   WL_GDO2 input signal GPIO.
139
 */
140
static apalGpio_t _gpioWlGdo2 = {
141
  /* port */ GPIOB,
142
  /* pad  */ GPIOB_WL_GDO2,
143
};
144
apalControlGpio_t moduleGpioWlGdo2 = {
145
  /* GPIO */ &_gpioWlGdo2,
146
  /* meta */ {
147
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
148
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
149
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
150
  },
151
};
152

    
153
/**
154
 * @brief   WL_GDO0 input signal GPIO.
155
 */
156
static apalGpio_t _gpioWlGdo0= {
157
  /* port */ GPIOB,
158
  /* pad  */ GPIOB_WL_GDO0,
159
};
160
apalControlGpio_t moduleGpioWlGdo0 = {
161
  /* GPIO */ &_gpioWlGdo0,
162
  /* meta */ {
163
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
164
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
165
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
166
  },
167
};
168

    
169
/**
170
 * @brief   LIGHT_XLAT output signal GPIO.
171
 */
172
static apalGpio_t _gpioLightXlat = {
173
  /* port */ GPIOC,
174
  /* pad  */ GPIOC_LIGHT_XLAT,
175
};
176
apalControlGpio_t moduleGpioLightXlat = {
177
  /* GPIO */ &_gpioLightXlat,
178
  /* meta */ {
179
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
180
    /* active state   */ TLC5947_LLD_XLAT_ACTIVE_STATE,
181
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
182
  },
183
};
184

    
185
/**
186
 * @brief   SYS_PD bidirectional signal GPIO.
187
 */
188
static apalGpio_t _gpioSysPd = {
189
  /* port */ GPIOC,
190
  /* pad  */ GPIOC_SYS_PD_N,
191
};
192
apalControlGpio_t moduleGpioSysPd = {
193
  /* GPIO */ &_gpioSysPd,
194
  /* meta */ {
195
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
196
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
197
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
198
  },
199
};
200

    
201
/**
202
 * @brief   SYS_SYNC bidirectional signal GPIO.
203
 */
204
static apalGpio_t _gpioSysSync = {
205
  /* port */ GPIOD,
206
  /* pad  */ GPIOD_SYS_INT_N,
207
};
208
apalControlGpio_t moduleGpioSysSync = {
209
  /* GPIO */ &_gpioSysSync,
210
  /* meta */ {
211
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
212
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
213
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
214
  },
215
};
216

    
217
/** @} */
218

    
219
/*===========================================================================*/
220
/**
221
 * @name AMiRo-OS core configurations
222
 * @{
223
 */
224
/*===========================================================================*/
225

    
226
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
227
const char* moduleShellPrompt = "LightRing";
228
#endif
229

    
230
/** @} */
231

    
232
/*===========================================================================*/
233
/**
234
 * @name Startup Shutdown Synchronization Protocol (SSSP)
235
 * @{
236
 */
237
/*===========================================================================*/
238

    
239
/** @} */
240

    
241
/*===========================================================================*/
242
/**
243
 * @name Low-level drivers
244
 * @{
245
 */
246
/*===========================================================================*/
247

    
248
AT24C01BNDriver moduleLldEeprom = {
249
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM,
250
  /* I2C address  */ 0x00u,
251
};
252

    
253
TLC5947Driver moduleLldLedPwm = {
254
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
255
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
256
  /* XLAT signal GPIO   */ &moduleGpioLightXlat,
257
};
258

    
259
TPS2051BDriver moduleLldPowerSwitchLaser = {
260
  /* laser enable GPIO      */ &moduleGpioLaserEn,
261
  /* laser overcurrent GPIO */ &moduleGpioLaserOc,
262
};
263

    
264
/** @} */
265

    
266
/*===========================================================================*/
267
/**
268
 * @name Unit tests (UT)
269
 * @{
270
 */
271
/*===========================================================================*/
272
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
273

    
274
/* EEPROM (AT24C01BN) */
275
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
276
{
277
  (void)argc;
278
  (void)argv;
279
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
280
  return AOS_OK;
281
}
282
static ut_at24c01bndata_t _utAt24c01bnData = {
283
  /* driver   */ &moduleLldEeprom,
284
  /* timeout  */ MICROSECONDS_PER_SECOND,
285
};
286
aos_unittest_t moduleUtAlldAt24c01bn = {
287
  /* name           */ "AT24C01BN-SH-B",
288
  /* info           */ "1kbit EEPROM",
289
  /* test function  */ utAlldAt24c01bnFunc,
290
  /* shell command  */ {
291
    /* name     */ "unittest:EEPROM",
292
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
293
    /* next     */ NULL,
294
  },
295
  /* data           */ &_utAt24c01bnData,
296
};
297

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

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

    
338
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
339

    
340
/** @} */