Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.c @ 933df08e

History | View | Annotate | Download (10.6 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
/*===========================================================================*/
22
/**
23
 * @name Module specific functions
24
 * @{
25
 */
26
/*===========================================================================*/
27
#include <amiroos.h>
28

    
29
/**
30
 * @brief   Interrupt service routine callback for I/O interrupt signals.
31
 *
32
 * @param   extp      EXT driver to handle the ISR.
33
 * @param   channel   Channel on which the interrupt was encountered.
34
 */
35
static void _moduleIsrCallback(EXTDriver* extp, expchannel_t channel) {
36
  (void)extp;
37

    
38
  chSysLockFromISR();
39
  chEvtBroadcastFlagsI(&aos.events.io, (1 << channel));
40
  chSysUnlockFromISR();
41

    
42
  return;
43
}
44

    
45
/** @} */
46

    
47
/*===========================================================================*/
48
/**
49
 * @name ChibiOS/HAL configuration
50
 * @{
51
 */
52
/*===========================================================================*/
53

    
54
CANConfig moduleHalCanConfig = {
55
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
56
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
57
};
58

    
59
EXTConfig moduleHalExtConfig = {
60
  /* channel configrations */ {
61
    /* channel  0 */ {
62
      /* mode     */ EXT_CH_MODE_DISABLED,
63
      /* callback */ NULL,
64
    },
65
    /* channel  1 */ {
66
      /* mode     */ EXT_CH_MODE_DISABLED,
67
      /* callback */ NULL,
68
    },
69
    /* channel  2 */ { // SYS_SYNC_N: automatic interrupt on event
70
      /* mode     */ EXT_MODE_GPIOD | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
71
      /* callback */ _moduleIsrCallback
72
    },
73
    /* channel  3 */ {
74
      /* mode     */ EXT_CH_MODE_DISABLED,
75
      /* callback */ NULL,
76
    },
77
    /* channel  4 */ {
78
      /* mode     */ EXT_CH_MODE_DISABLED,
79
      /* callback */ NULL,
80
    },
81
    /* channel  5 */ { // LASER_OC_N: must be enabled explicitely
82
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_FALLING_EDGE,
83
      /* callback */ _moduleIsrCallback,
84
    },
85
    /* channel  6 */ { // SYS_UART_DN: automatic interrupt on event
86
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
87
      /* callback */ _moduleIsrCallback,
88
    },
89
    /* channel  7 */ {
90
      /* mode     */ EXT_CH_MODE_DISABLED,
91
      /* callback */ NULL,
92
    },
93
    /* channel  8 */ { // WL_GDO0: must be enabled explicitely
94
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_BOTH_EDGES,
95
      /* callback */ _moduleIsrCallback,
96
    },
97
    /* channel  9 */ { // WL_GDO2: must be enabled explicitely
98
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_BOTH_EDGES,
99
      /* callback */ _moduleIsrCallback,
100
    },
101
    /* channel 10 */ {
102
      /* mode     */ EXT_CH_MODE_DISABLED,
103
      /* callback */ NULL,
104
    },
105
    /* channel 11 */ {
106
      /* mode     */ EXT_CH_MODE_DISABLED,
107
      /* callback */ NULL,
108
    },
109
    /* channel 12 */ {
110
      /* mode     */ EXT_CH_MODE_DISABLED,
111
      /* callback */ NULL,
112
    },
113
    /* channel 13 */ {
114
      /* mode     */ EXT_CH_MODE_DISABLED,
115
      /* callback */ NULL,
116
    },
117
    /* channel 14 */ { // SYS_PD_N: automatic interrupt when activated
118
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
119
      /* callback */ _moduleIsrCallback
120
    },
121
    /* channel 15 */ {
122
      /* mode     */ EXT_CH_MODE_DISABLED,
123
      /* callback */ NULL,
124
    },
125
    /* channel 16 */ {
126
      /* mode     */ EXT_CH_MODE_DISABLED,
127
      /* callback */ NULL,
128
    },
129
    /* channel 17 */ {
130
      /* mode     */ EXT_CH_MODE_DISABLED,
131
      /* callback */ NULL,
132
    },
133
    /* channel 18 */ {
134
      /* mode     */ EXT_CH_MODE_DISABLED,
135
      /* callback */ NULL,
136
    },
137
  }
138
};
139

    
140
I2CConfig moduleHalI2cEepromConfig = {
141
  /* I²C mode   */ OPMODE_I2C,
142
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
143
  /* duty cycle */ FAST_DUTY_CYCLE_2,
144
};
145

    
146
SerialConfig moduleHalProgIfConfig = {
147
  /* bit rate */ 115200,
148
  /* CR1      */ 0,
149
  /* CR1      */ 0,
150
  /* CR1      */ 0,
151
};
152

    
153
SPIConfig moduleHalSpiLightConfig = {
154
  /* callback function pointer   */ NULL,
155
  /* chip select line port       */ GPIOC,
156
  /* chip select line pad number */ GPIOC_LIGHT_XLAT,
157
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
158
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
159
};
160

    
161
/*===========================================================================*/
162
/**
163
 * @name GPIO definitions
164
 * @{
165
 */
166
/*===========================================================================*/
167

    
168
apalGpio_t moduleGpioLightBlank = {
169
  /* port */ GPIOA,
170
  /* pad  */ GPIOA_LIGHT_BLANK,
171
};
172

    
173
apalGpio_t moduleGpioLaserEn = {
174
  /* port */ GPIOB,
175
  /* pad  */ GPIOB_LASER_EN,
176
};
177

    
178
apalGpio_t moduleGpioLaserOc = {
179
  /* port */ GPIOB,
180
  /* pad  */ GPIOB_LASER_OC_N,
181
};
182

    
183
apalGpio_t moduleGpioSysUartDn = {
184
  /* port */ GPIOB,
185
  /* pad  */ GPIOB_SYS_UART_DN,
186
};
187

    
188
apalGpio_t moduleGpioWlGdo2 = {
189
  /* port */ GPIOB,
190
  /* pad  */ GPIOB_WL_GDO2,
191
};
192

    
193
apalGpio_t moduleGpioWlGdo0= {
194
  /* port */ GPIOB,
195
  /* pad  */ GPIOB_WL_GDO0,
196
};
197

    
198
apalGpio_t moduleGpioLightXlat = {
199
  /* port */ GPIOC,
200
  /* pad  */ GPIOC_LIGHT_XLAT,
201
};
202

    
203
apalGpio_t moduleGpioSysPd = {
204
  /* port */ GPIOC,
205
  /* pad  */ GPIOC_SYS_PD_N,
206
};
207

    
208
apalGpio_t moduleGpioSysSync = {
209
  /* port */ GPIOD,
210
  /* pad  */ GPIOD_SYS_INT_N,
211
};
212

    
213
/** @} */
214

    
215
/*===========================================================================*/
216
/**
217
 * @name AMiRo-OS core configurations
218
 * @{
219
 */
220
/*===========================================================================*/
221

    
222
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
223
const char* moduleShellPrompt = "LightRing";
224
#endif
225

    
226
/** @} */
227

    
228
/*===========================================================================*/
229
/**
230
 * @name Startup Shutdown Synchronization Protocol (SSSP)
231
 * @{
232
 */
233
/*===========================================================================*/
234

    
235
apalControlGpio_t moduleSsspGpioPd = {
236
  /* GPIO */ &moduleGpioSysPd,
237
  /* meta */ {
238
    /* active state */ APAL_GPIO_ACTIVE_LOW,
239
    /* edge         */ APAL_GPIO_EDGE_FALLING,
240
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
241
  },
242
};
243

    
244
apalControlGpio_t moduleSsspGpioSync = {
245
  /* GPIO */ &moduleGpioSysSync,
246
  /* meta */ {
247
    /* active state */ APAL_GPIO_ACTIVE_LOW,
248
    /* edge         */ APAL_GPIO_EDGE_FALLING,
249
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
250
  },
251
};
252

    
253
apalControlGpio_t moduleSsspGpioDn = {
254
  /* GPIO */ &moduleGpioSysUartDn,
255
  /* meta */ {
256
    /* active state */ APAL_GPIO_ACTIVE_LOW,
257
    /* edge         */ APAL_GPIO_EDGE_FALLING,
258
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
259
  },
260
};
261

    
262
/** @} */
263

    
264
/*===========================================================================*/
265
/**
266
 * @name Low-level drivers
267
 * @{
268
 */
269
/*===========================================================================*/
270

    
271
AT24C01BNDriver moduleLldEeprom = {
272
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM,
273
  /* I2C address  */ 0x00u,
274
};
275

    
276
TLC5947Driver moduleLldLedPwm = {
277
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
278
  /* BLANK signal GPIO  */ {
279
    /* GPIO */ &moduleGpioLightBlank,
280
    /* meta */ {
281
      /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
282
      /* edge         */ APAL_GPIO_EDGE_NONE,
283
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
284
    },
285
  },
286
  /* XLAT signal GPIO   */ {
287
    /* GPIO */ &moduleGpioLightXlat,
288
    /* meta */ {
289
      /* active state */ TLC5947_LLD_XLAT_ACTIVE_STATE,
290
      /* edge         */ APAL_GPIO_EDGE_NONE,
291
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
292
    },
293
  },
294
};
295

    
296
TPS2051BDriver moduleLldPowerSwitchLaser = {
297
  /* laser enable gpio */ {
298
    /* GPIO */ &moduleGpioLaserEn,
299
    /* meta */ {
300
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
301
      /* edge         */ APAL_GPIO_EDGE_NONE,
302
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
303
    },
304
  },
305
  /* laser overcurrent gpio */ {
306
    /* GPIO         */ &moduleGpioLaserOc,
307
    /* meta */ {
308
      /* active state */ APAL_GPIO_ACTIVE_LOW,
309
      /* edge         */ APAL_GPIO_EDGE_NONE,
310
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
311
    },
312
  },
313
};
314

    
315
/** @} */
316

    
317
/*===========================================================================*/
318
/**
319
 * @name Unit tests (UT)
320
 * @{
321
 */
322
/*===========================================================================*/
323
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
324

    
325
/* EEPROM (AT24C01BN) */
326
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
327
{
328
  (void)argc;
329
  (void)argv;
330
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
331
  return AOS_OK;
332
}
333
static ut_at24c01bndata_t _utAt24c01bnData = {
334
  /* driver   */ &moduleLldEeprom,
335
  /* timeout  */ MICROSECONDS_PER_SECOND,
336
};
337
aos_unittest_t moduleUtAlldAt24c01bn = {
338
  /* name           */ "AT24C01BN-SH-B",
339
  /* info           */ "1kbit EEPROM",
340
  /* test function  */ utAlldAt24c01bnFunc,
341
  /* shell command  */ {
342
    /* name     */ "unittest:EEPROM",
343
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
344
    /* next     */ NULL,
345
  },
346
  /* data           */ &_utAt24c01bnData,
347
};
348

    
349
/* LED PWM driver (TLD5947) */
350
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
351
{
352
  (void)argc;
353
  (void)argv;
354
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
355
  return AOS_OK;
356
}
357
aos_unittest_t moduleUtAlldTlc5947 = {
358
  /* info           */ "TLC5947",
359
  /* name           */ "LED PWM driver",
360
  /* test function  */ utAlldTlc5947Func,
361
  /* shell command  */ {
362
    /* name     */ "unittest:Lights",
363
    /* callback */ _utShellCmdCb_Tlc5947,
364
    /* next     */ NULL,
365
  },
366
  /* data           */ &moduleLldLedPwm,
367
};
368

    
369
/* power switch (Laser) */
370
static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[])
371
{
372
  (void)argc;
373
  (void)argv;
374
  aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
375
  return AOS_OK;
376
}
377
aos_unittest_t moduleUtAlldTps2051bdbv = {
378
  /* info           */ "TPS2051BDBV",
379
  /* name           */ "current-limited power switch",
380
  /* test function  */ utAlldTps2051bdbvFunc,
381
  /* shell command  */ {
382
    /* name     */ "unittest:PowerSwitch",
383
    /* callback */ _utShellCmdCb_Tps2051bdbv,
384
    /* next     */ NULL,
385
  },
386
  /* data           */ &moduleLldPowerSwitchLaser,
387
};
388

    
389
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
390

    
391
/** @} */