Statistics
| Branch: | Tag: | Revision:

amiro-os / os / modules / LightRing_1-0 / module.c @ bdf72fa0

History | View | Annotate | Download (10.094 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.source, (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
apalControlGpio_t moduleSsspPd = {
223
  /* GPIO */ &moduleGpioSysPd,
224
  /* meta */ {
225
    /* active state */ APAL_GPIO_ACTIVE_LOW,
226
    /* edge         */ APAL_GPIO_EDGE_FALLING,
227
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
228
  },
229
};
230

    
231
apalControlGpio_t moduleSsspSync = {
232
  /* GPIO */ &moduleGpioSysSync,
233
  /* meta */ {
234
    /* active state */ APAL_GPIO_ACTIVE_LOW,
235
    /* edge         */ APAL_GPIO_EDGE_FALLING,
236
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
237
  },
238
};
239

    
240
const char* moduleShellPrompt = "LightRing";
241

    
242
/** @} */
243

    
244
/*===========================================================================*/
245
/**
246
 * @name Low-level drivers
247
 * @{
248
 */
249
/*===========================================================================*/
250

    
251
AT24C01BNDriver moduleLldEeprom = {
252
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM,
253
  /* I2C address  */ 0x00u,
254
};
255

    
256
TLC5947Driver moduleLldLedPwm = {
257
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
258
  /* BLANK signal GPIO  */ {
259
    /* GPIO */ &moduleGpioLightBlank,
260
    /* meta */ {
261
      /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
262
      /* edge         */ APAL_GPIO_EDGE_NONE,
263
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
264
    },
265
  },
266
  /* XLAT signal GPIO   */ {
267
    /* GPIO */ &moduleGpioLightXlat,
268
    /* meta */ {
269
      /* active state */ TLC5947_LLD_XLAT_ACTIVE_STATE,
270
      /* edge         */ APAL_GPIO_EDGE_NONE,
271
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
272
    },
273
  },
274
};
275

    
276
TPS2051BDriver moduleLldPowerSwitchLaser = {
277
  /* laser enable gpio */ {
278
    /* GPIO */ &moduleGpioLaserEn,
279
    /* meta */ {
280
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
281
      /* edge         */ APAL_GPIO_EDGE_NONE,
282
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
283
    },
284
  },
285
  /* laser overcurrent gpio */ {
286
    /* GPIO         */ &moduleGpioLaserOc,
287
    /* meta */ {
288
      /* active state */ APAL_GPIO_ACTIVE_LOW,
289
      /* edge         */ APAL_GPIO_EDGE_NONE,
290
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
291
    },
292
  },
293
};
294

    
295
/** @} */
296

    
297
/*===========================================================================*/
298
/**
299
 * @name Unit tests (UT)
300
 * @{
301
 */
302
/*===========================================================================*/
303
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
304

    
305
/* EEPROM (AT24C01BN) */
306
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
307
{
308
  (void)argc;
309
  (void)argv;
310
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
311
  return AOS_OK;
312
}
313
static ut_at24c01bndata_t _utAt24c01bnData = {
314
  /* driver   */ &moduleLldEeprom,
315
  /* timeout  */ MICROSECONDS_PER_SECOND,
316
};
317
aos_unittest_t moduleUtAlldAt24c01bn = {
318
  /* name           */ "AT24C01BN-SH-B",
319
  /* info           */ "1kbit EEPROM",
320
  /* test function  */ utAlldAt24c01bnFunc,
321
  /* shell command  */ {
322
    /* name     */ "unittest:EEPROM",
323
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
324
    /* next     */ NULL,
325
  },
326
  /* data           */ &_utAt24c01bnData,
327
};
328

    
329
/* LED PWM driver (TLD5947) */
330
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
331
{
332
  (void)argc;
333
  (void)argv;
334
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
335
  return AOS_OK;
336
}
337
aos_unittest_t moduleUtAlldTlc5947 = {
338
  /* info           */ "TLC5947",
339
  /* name           */ "LED PWM driver",
340
  /* test function  */ utAlldTlc5947Func,
341
  /* shell command  */ {
342
    /* name     */ "unittest:Lights",
343
    /* callback */ _utShellCmdCb_Tlc5947,
344
    /* next     */ NULL,
345
  },
346
  /* data           */ &moduleLldLedPwm,
347
};
348

    
349
/* power switch (Laser) */
350
static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[])
351
{
352
  (void)argc;
353
  (void)argv;
354
  aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
355
  return AOS_OK;
356
}
357
aos_unittest_t moduleUtAlldTps2051bdbv = {
358
  /* info           */ "TPS2051BDBV",
359
  /* name           */ "current-limited power switch",
360
  /* test function  */ utAlldTps2051bdbvFunc,
361
  /* shell command  */ {
362
    /* name     */ "unittest:PowerSwitch",
363
    /* callback */ _utShellCmdCb_Tps2051bdbv,
364
    /* next     */ NULL,
365
  },
366
  /* data           */ &moduleLldPowerSwitchLaser,
367
};
368

    
369
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
370

    
371
/** @} */