Revision 88449987

View differences:

modules/LightRing_1-2/alldconf.h
74 74
#define AMIROLLD_CFG_TLC5947                    1
75 75
#define TLC5947_LLD_CHAINED                     3
76 76

  
77
/**
78
 * @brief   Enable flag for the DW1000 UWB transmitter.
79
 * @note    Uncomment this if the device is attached.
80
 */
81
#define AMIROLLD_CFG_DW1000                     1
82

  
77 83
#endif /* ALLDCONF_H */
78 84

  
79 85
/** @} */
modules/LightRing_1-2/aosconf.h
84 84
 * @note    Any mandatory events (e.g. for SSSP) are enabled implicitely despite this configuration.
85 85
 */
86 86
#if !defined(OS_CFG_MAIN_LOOP_IOEVENT_MASK)
87
  #define AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK    0
87
  #define AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK    MODULE_OS_IOEVENTFLAGS_DW1000
88 88
#else /* !defined(OS_CFG_MAIN_LOOP_IOEVENT_MASK) */
89 89
  #define AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK    OS_CFG_MAIN_LOOP_IOEVENT_MASK
90 90
#endif /* !defined(OS_CFG_MAIN_LOOP_IOEVENT_MASK) */
modules/LightRing_1-2/module.c
69 69
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
70 70
};
71 71

  
72
#if defined(AMIROLLD_CFG_DW1000)
73

  
74
/*! SPI (high speed) configuration for DW1000 */
75
SPIConfig moduleHalSpiUwbHsConfig = {
76
  /* circular buffer mode        */ false,
77
  /* callback function pointer   */ NULL,
78
  /* chip select line port       */ PAL_PORT(LINE_SPI_SS_N),
79
  /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
80
  /* CR1                         */ 0,                                  // 36/2 Mbps
81
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,  // 0
82
};
83
/*! SPI (low speed) configuration for DW1000 */
84
SPIConfig moduleHalSpiUwbLsConfig = {
85
  /* circular buffer mode        */ false,
86
  /* callback function pointer   */ NULL,
87
  /* chip select line port       */ PAL_PORT(LINE_SPI_SS_N),
88
  /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
89
  /* CR1                         */ SPI_CR1_BR_1 | SPI_CR1_BR_0,        // 36/16 Mbps
90
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,  // 0
91
};
92

  
93
#endif /* defined(AMIROLLD_CFG_DW1000) */
94

  
72 95

  
73 96
/*===========================================================================*/
74 97
/**
......
212 235
  },
213 236
};
214 237

  
238
#if defined (AMIROLLD_CFG_DW1000)
215 239
/**
216
 * @brief   IO_7 breakout signal GPIO.
240
 * @brief   DW1000 interrrupt input signal GPIO.
217 241
 */
218
static apalGpio_t _gpioBreakoutIo7 = {
242
static apalGpio_t _gpioDw1000Irqn = {
243
  /* line */  LINE_IO_8,            // (GPIOB, GPIOB_IO_8),
244
};
245
ROMCONST apalControlGpio_t moduleGpioDw1000Irqn = {
246
  /* GPIO */ &_gpioDw1000Irqn,
247
  /* meta */ {
248
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
249
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
250
    /* interrupt edge */ APAL_GPIO_EDGE_RISING,
251
  },
252
};
253

  
254
/**
255
 * @brief   DW1000 reset output signal GPIO.
256
 */
257
static apalGpio_t _gpioDw1000Reset = {
219 258
  /* line */ LINE_IO_7,
220 259
};
221
apalControlGpio_t moduleGpioBreakoutIo7 = {
222
  /* GPIO */ &_gpioBreakoutIo7,
260
ROMCONST apalControlGpio_t moduleGpioDw1000Reset = {
261
  /* GPIO */ &_gpioDw1000Reset,
223 262
  /* meta */ {
224
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
263
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
225 264
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
226 265
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
227 266
  },
228 267
};
229 268

  
230 269
/**
270
 * @brief   IO_2 breakout signal GPIO.
271
 */
272
static apalGpio_t _gpioDw1000WakeUp = {
273
  /* line */ LINE_IO_2,
274
};
275
ROMCONST apalControlGpio_t moduleGpioDw1000WakeUp = {
276
  /* GPIO */ &_gpioDw1000WakeUp,
277
  /* meta */ {
278
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
279
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
280
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
281
  },
282
};
283

  
284
/**
285
 * @brief   DW1000 SPI chip select output signal GPIO.
286
 */
287
static apalGpio_t _gpioSpiChipSelect = {
288
  /* line */ LINE_SPI_SS_N,
289
};
290
ROMCONST apalControlGpio_t moduleGpioSpiChipSelect = {
291
  /* GPIO */ &_gpioSpiChipSelect,
292
  /* meta */ {
293
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
294
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
295
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
296
  },
297
};
298
#else
299
/**
231 300
 * @brief   IO_8 breakout signal GPIO.
232 301
 */
233 302
static apalGpio_t _gpioBreakoutIo8 = {
......
243 312
};
244 313

  
245 314
/**
246
 * @brief   IO_4 breakout signal GPIO.
315
 * @brief   IO_7 breakout signal GPIO.
247 316
 */
248
static apalGpio_t _gpioBreakoutIo4 = {
249
  /* line */ LINE_IO_4,
317
static apalGpio_t _gpioBreakoutIo7 = {
318
  /* line */ LINE_IO_7,
250 319
};
251
apalControlGpio_t moduleGpioBreakoutIo4 = {
252
  /* GPIO */ &_gpioBreakoutIo4,
320
apalControlGpio_t moduleGpioBreakoutIo7 = {
321
  /* GPIO */ &_gpioBreakoutIo7,
253 322
  /* meta */ {
254 323
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
255 324
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
......
258 327
};
259 328

  
260 329
/**
261
 * @brief   IO_1 breakout signal GPIO.
330
 * @brief   IO_2 breakout signal GPIO.
262 331
 */
263
static apalGpio_t _gpioBreakoutIo1 = {
264
  /* line */ LINE_IO_1,
332
static apalGpio_t _gpioBreakoutIo2 = {
333
  /* line */ LINE_IO_2,
265 334
};
266
apalControlGpio_t moduleGpioBreakoutIo1 = {
267
  /* GPIO */ &_gpioBreakoutIo1,
335
apalControlGpio_t moduleGpioBreakoutIo2 = {
336
  /* GPIO */ &_gpioBreakoutIo2,
268 337
  /* meta */ {
269 338
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
270 339
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
271 340
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
272 341
  },
273 342
};
343
#endif  /* defined (AMIROLLD_CFG_DW1000) */
274 344

  
275 345
/**
276
 * @brief   IO_2 breakout signal GPIO.
346
 * @brief   IO_4 breakout signal GPIO.
277 347
 */
278
static apalGpio_t _gpioBreakoutIo2 = {
279
  /* line */ LINE_IO_2,
348
static apalGpio_t _gpioBreakoutIo4 = {
349
  /* line */ LINE_IO_4,
280 350
};
281
apalControlGpio_t moduleGpioBreakoutIo2 = {
282
  /* GPIO */ &_gpioBreakoutIo2,
351
apalControlGpio_t moduleGpioBreakoutIo4 = {
352
  /* GPIO */ &_gpioBreakoutIo4,
353
  /* meta */ {
354
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
355
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
356
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
357
  },
358
};
359

  
360
/**
361
 * @brief   IO_1 breakout signal GPIO.
362
 */
363
static apalGpio_t _gpioBreakoutIo1 = {
364
  /* line */ LINE_IO_1,
365
};
366
apalControlGpio_t moduleGpioBreakoutIo1 = {
367
  /* GPIO */ &_gpioBreakoutIo1,
283 368
  /* meta */ {
284 369
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
285 370
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
......
450 535
  /* XLAT signal GPIO   */ NULL,
451 536
};
452 537

  
538
#if defined(AMIROLLD_CFG_DW1000)
539
DW1000Driver moduleLldDw1000 = {
540
  /* SPI driver         */ &MODULE_HAL_SPI_UWB,
541
  /* ext interrupt      */ &moduleGpioDw1000Irqn,
542
  /* RESET DW1000       */ &moduleGpioDw1000Reset,
543
};
544
#endif /* defined(AMIROLLD_CFG_DW1000) */
545

  
453 546
/** @} */
454 547

  
455 548
/*===========================================================================*/
......
624 717
  /* data           */ &moduleLldLedPwm,
625 718
};
626 719

  
720
#if defined(AMIROLLD_CFG_DW1000)
721
/*
722
 * UwB Driver (DW1000)
723
 */
724
static int _utShellCmdCb_Dw1000(BaseSequentialStream* stream, int argc, char* argv[])
725
{
726
  (void)argc;
727
  (void)argv;
728

  
729
  // Set the 3.3 V supply for powering the DW1000 module
730
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->mic9404xd = &moduleLldPowerSwitchV33;
731
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->dw1000d = NULL;
732
  aosUtRun(stream, &moduleUtAlldDw1000, NULL);
733
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->mic9404xd = NULL;
734

  
735
  // Set the 1.8 V supply
736
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->mic9404xd = &moduleLldPowerSwitchV18;
737
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->dw1000d = NULL;
738
   aosUtRun(stream, &moduleUtAlldDw1000, NULL);
739
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->mic9404xd = NULL;
740

  
741
  // Run the DW1000 module
742
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->dw1000d = &moduleLldDw1000;
743
  ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->mic9404xd = NULL;
744
  aosUtRun(stream, &moduleUtAlldDw1000, NULL);
745
  return AOS_OK;
746
}
747
static ut_dw1000data_t _utAlldDw1000Data = {
748
  /* driver DW1000    */ NULL,
749
  /* driver MIC9404x  */ NULL,
750
};
751
aos_unittest_t moduleUtAlldDw1000 = {
752
  /* info           */ "DW1000",
753
  /* name           */ "UWB System",
754
  /* test function  */ utAlldDw1000Func,
755
  /* shell command  */ {
756
    /* name     */ "unittest:Uwb",
757
    /* callback */ _utShellCmdCb_Dw1000,
758
    /* next     */ NULL,
759
  },
760
  /* data           */ &_utAlldDw1000Data,
761
};
762
#endif /* defined(AMIROLLD_CFG_DW1000) */
763

  
627 764
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
628 765

  
629 766
/** @} */
modules/LightRing_1-2/module.h
85 85
 */
86 86
extern SPIConfig moduleHalSpiLightConfig;
87 87

  
88
#if defined(AMIROLLD_CFG_DW1000)
89
/**
90
 * @brief   SPI interface driver for UWB DW1000 module.
91
 */
92
#define MODULE_HAL_SPI_UWB                      SPID2
93

  
94
/**
95
 * @brief   Configuration for the high-speed SPI interface driver of DW1000 module.
96
 */
97
extern SPIConfig moduleHalSpiUwbHsConfig;
98

  
99
/**
100
 * @brief   Configuration for the low-speed SPI interface driver of DW1000 module.
101
 */
102
extern SPIConfig moduleHalSpiUwbLsConfig;
103

  
104
#else
105

  
88 106
/**
89 107
 * @brief   SPI interface driver for the breakout header.
90 108
 */
91 109
#define MODULE_HAL_SPI_BREAKOUT                 SPID2
92 110

  
111
#endif /* defined(AMIROLLD_CFG_DW1000) */
112

  
93 113
/**
94 114
 * @brief   UART interface driver for the breakout header (alternative to serial).
95 115
 */
......
155 175
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
156 176

  
157 177
/**
158
 * @brief   IO_7 breakout signal GPIO.
159
 */
160
extern apalControlGpio_t moduleGpioBreakoutIo7;
161

  
162
/**
163
 * @brief   IO_8 breakout signal GPIO.
164
 */
165
extern apalControlGpio_t moduleGpioBreakoutIo8;
166

  
167
/**
168 178
 * @brief   IO_4 breakout signal GPIO.
169 179
 */
170 180
extern apalControlGpio_t moduleGpioBreakoutIo4;
......
175 185
extern apalControlGpio_t moduleGpioBreakoutIo1;
176 186

  
177 187
/**
178
 * @brief   IO_2 breakout signal GPIO.
179
 */
180
extern apalControlGpio_t moduleGpioBreakoutIo2;
181

  
182
/**
183 188
 * @brief   LED output signal GPIO.
184 189
 */
185 190
extern ROMCONST apalControlGpio_t moduleGpioLed;
......
209 214
 */
210 215
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
211 216

  
217
#if defined(AMIROLLD_CFG_DW1000)
218

  
219
/**
220
 * @brief   DW1000 reset output signal
221
 * @note    the reset pin should be drived as low by MCU to activate.
222
 *          Then, put back the reset pin as input to MCU (tri-state float on the air
223
 *          is not supported in AMiRo)
224
 */
225
extern ROMCONST apalControlGpio_t moduleGpioDw1000Reset;
226

  
227
/**
228
 * @brief   DW1000 wakeup signal
229
 */
230
extern ROMCONST apalControlGpio_t moduleGpioDw1000WakeUp;
231

  
232
/**
233
 * @brief   DW1000 interrupt IRQn input signal.
234
 */
235
extern ROMCONST apalControlGpio_t moduleGpioDw1000Irqn;
236

  
237
/**
238
 * @brief   DW1000 SPI chip select  output signal.
239
 */
240
extern ROMCONST apalControlGpio_t moduleGpioSpiChipSelect ;
241

  
242
#else
243
/**
244
 * @brief   IO_2 breakout signal GPIO.
245
 */
246
extern apalControlGpio_t moduleGpioBreakoutIo2;
247

  
248
/**
249
 * @brief   IO_7 breakout signal GPIO.
250
 */
251
extern apalControlGpio_t moduleGpioBreakoutIo7;
252

  
253
/**
254
 * @brief   IO_8 breakout signal GPIO.
255
 */
256
extern apalControlGpio_t moduleGpioBreakoutIo8;
257

  
258
#endif /* defined(AMIROLLD_CFG_DW1000) */
259

  
212 260
/** @} */
213 261

  
214 262
/*===========================================================================*/
......
263 311
 */
264 312
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO7      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_7))
265 313

  
314
#if defined(AMIROLLD_CFG_DW1000)
315
/**
316
 * @brief   Event flag to be call dwt_isr() interrupt.
317
 */
318
#define MODULE_OS_IOEVENTFLAGS_DW1000      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_8))
319
#else
266 320
/**
267 321
 * @brief   Event flag to be set on a IO_8 (breakout) interrupt.
268 322
 */
269 323
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO8      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_8))
324
#endif  /* defined(AMIROLLD_CFG_DW1000) */
270 325

  
271 326
/**
272 327
 * @brief   Event flag to be set on a SYS_PD interrupt.
......
286 341
 */
287 342
#define MODULE_INIT_INTERRUPTS() {                                            \
288 343
  /* breakout interrupts must be enabled explicitely */                       \
344
  MODULE_INIT_INTERRUPTS_DW1000();                                            \
289 345
}
346
#if defined(AMIROLLD_CFG_DW1000)
347
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
348
    palSetLineCallback(moduleGpioDw1000Irqn.gpio->line, aosSysGetStdIntCallback(), &moduleGpioDw1000Irqn.gpio->line); \
349
    palEnableLineEvent(moduleGpioDw1000Irqn.gpio->line, APAL2CH_EDGE(moduleGpioDw1000Irqn.meta.edge));                \
350
  }
351
#else /* defined(AMIROLLD_CFG_DW1000) */
352
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
353
  }
354
#endif /* defined(AMIROLLD_CFG_DW1000) */
290 355

  
291 356
/**
292 357
 * @brief   Unit test initialization hook.
......
298 363
  aosShellAddCommand(&aos.shell, &moduleUtAlldLed.shellcmd);                  \
299 364
  aosShellAddCommand(&aos.shell, &moduleUtAlldMic9404x.shellcmd);             \
300 365
  aosShellAddCommand(&aos.shell, &moduleUtAlldTlc5947.shellcmd);              \
366
  MODULE_INIT_TESTS_DW1000();                                                 \
301 367
}
368
#if defined(AMIROLLD_CFG_DW1000)
369
  #define MODULE_INIT_TESTS_DW1000() {                                        \
370
    aosShellAddCommand(&aos.shell, &moduleUtAlldDw1000.shellcmd);             \
371
  }
372
#else /* defined(AMIROLLD_CFG_DW1000) */
373
  #define MODULE_INIT_TESTS_DW1000() {                                        \
374
  }
375
#endif /* defined(AMIROLLD_CFG_DW1000) */
302 376

  
303 377
/**
304 378
 * @brief   Periphery communication interfaces initialization hook.
......
313 387
  i2cStart(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT, &moduleHalI2cEepromPwrmtrBreakoutConfig);  \
314 388
  /* SPI */                                                                   \
315 389
  spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig);                  \
390
  MODULE_INIT_PERIPHERY_COMM_DW1000();                                        \
316 391
}
392
#if defined(AMIROLLD_CFG_DW1000)
393
  #define MODULE_INIT_PERIPHERY_COMM_DW1000() {                               \
394
  spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig);                    \
395
  }
396
#else /* defined(AMIROLLD_CFG_DW1000) */
397
  #define MODULE_INIT_PERIPHERY_COMM_DW1000() {                               \
398
  }
399
#endif /* defined(AMIROLLD_CFG_DW1000) */
317 400

  
318 401
/**
319 402
 * @brief   Periphery communication interface deinitialization hook.
......
323 406
  spiStop(&MODULE_HAL_SPI_LIGHT);                                             \
324 407
  /* I2C */                                                                   \
325 408
  i2cStop(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT);                            \
409
  MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000();                                    \
326 410
  /* don't stop the serial driver so messages can still be printed */         \
327 411
}
412
#if defined(AMIROLLD_CFG_DW1000)
413
#define MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000() {                             \
414
  /* SPI */                                                                   \
415
  spiStop(&MODULE_HAL_SPI_UWB);                                               \
416
}
417
#else /* defined(AMIROLLD_CFG_DW1000) */
418
  #define MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000() {                           \
419
  }
420
#endif /* defined(AMIROLLD_CFG_DW1000) */
421

  
422
/**
423
 * @brief   HOOK to call process_deca_irq() func when the dw1000 interrupt pin is activated.
424
 */
425
#define MODULE_MAIN_LOOP_IO_EVENT(eventflags) {                               \
426
  MODULE_MAIN_LOOP_IO_EVENT_DW1000();                                         \
427
}
428
#if defined(AMIROLLD_CFG_DW1000)
429
  #define MODULE_MAIN_LOOP_IO_EVENT_DW1000() {                                \
430
    if(eventflags & MODULE_OS_IOEVENTFLAGS_DW1000) {                          \
431
      process_deca_irq();                                                     \
432
    }                                                                         \
433
  }
434
#else /* defined(AMIROLLD_CFG_DW1000) */
435
  #define MODULE_MAIN_LOOP_IO_EVENT_DW1000() {                                \
436
  }
437
#endif /* defined(AMIROLLD_CFG_DW1000) */
328 438

  
329 439
/** @} */
330 440

  
......
390 500
//#include <alld_SNx5C3221E.h>
391 501
#include <alld_TLC5947.h>
392 502

  
503
#if defined(AMIROLLD_CFG_DW1000)
504
#include <alld_DW1000.h>
505

  
506
extern DW1000Driver moduleLldDw1000;
507

  
508
#endif /* defined(AMIROLLD_CFG_DW1000) */
509

  
393 510
/**
394 511
 * @brief   EEPROM driver.
395 512
 */
......
452 569
//#include <ut_alld_SNx5C3221E_v1.h>
453 570
#include <ut_alld_TLC5947_v1.h>
454 571

  
572
#if defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)
573
#include <ut_alld_DW1000_v1.h>
574

  
575
/**
576
 * @brief   DW1000 unit test object.
577
 */
578
extern aos_unittest_t moduleUtAlldDw1000;
579

  
580
#endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */
581

  
455 582
/**
456 583
 * @brief   EEPROM unit test object.
457 584
 */
unittests/periphery-lld/inc/ut_alld_DW1000_v1.h
42 42
/* DATA STRUCTURES AND TYPES                                                  */
43 43
/******************************************************************************/
44 44

  
45
/**
46
 * @brief   Custom data structure for the unit test.
47
 */
48

  
49
#if defined (AMIROLLD_CFG_MIC9404x)
50
typedef struct {
51
  /**
52
   * @brief   DW1000 driver to use.
53
   */
54
  DW1000Driver *dw1000d;
55

  
56
  /**
57
   * @brief MIC9404x driver to use.
58
  */
59
  MIC9404xDriver  *mic9404xd;
60

  
61
} ut_dw1000data_t;
62

  
63
#else
64
typedef struct {
65
  /**
66
   * @brief   DW1000 driver to use.
67
   */
68
  DW1000Driver *dw1000d;
69

  
70
} ut_dw1000data_t;
71

  
72
#endif
73

  
74

  
45 75
/******************************************************************************/
46 76
/* MACROS                                                                     */
47 77
/******************************************************************************/
......
69 99
  void clear_SPI_chip_select(void);
70 100
  void reset_DW1000(void);
71 101
  void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv);
72
  apalGpioState_t port_CheckEXT_IRQ(void) ;
73 102
  void process_deca_irq(void);
103
  void wakeup_DW1000(void);
74 104

  
75 105
#if defined(__cplusplus)
76 106
}
unittests/periphery-lld/src/ut_alld_DW1000_v1.c
27 27
#include <module.h>
28 28
#include <alld_DW1000.h>
29 29
#include <v1/deca_instance_v1.h>
30
#include <v1/alld_dw1000_regs_v1.h>
31
#include <string.h>
30 32

  
31 33

  
32 34
/******************************************************************************/
......
69 71

  
70 72
/*! @brief Change the SPI speed configuration on the fly */
71 73
void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){
72

  
73 74
  spiStop(drv->spid);
74

  
75 75
  if (speedValue == FALSE){
76 76
    spiStart(drv->spid, &moduleHalSpiUwbLsConfig);  // low speed spi configuration
77 77
  }
......
80 80
  }
81 81
}
82 82

  
83
/*! @brief entry point to the IRQn event in DW1000 module
84
 *
85
 * */
83
/*! @brief entry point to the IRQn event in DW1000 module */
86 84
void process_deca_irq(void){
87 85
  do{
88 86
    dwt_isr();
......
90 88
  }while(port_CheckEXT_IRQ() == 1);
91 89
}
92 90

  
93
/*! @brief Check the current value of GPIO pin and return the value */
94
apalGpioState_t port_CheckEXT_IRQ(void) {
95
  apalGpioState_t  val;
96
  apalGpioRead(moduleGpioDw1000Irqn.gpio, &val);
97
  return val;
98
}
99

  
100 91
/*! @brief Manually set the chip select pin of the SPI */
101 92
void set_SPI_chip_select(void){
102 93
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_HIGH);
......
109 100

  
110 101
/*! @brief Manually reset the DW1000 module  */
111 102
void reset_DW1000(void){
112

  
113 103
  // Set the pin as output
114 104
  palSetLineMode(moduleGpioDw1000Reset.gpio->line, APAL_GPIO_DIRECTION_OUTPUT);
115

  
116 105
  //drive the RSTn pin low
117 106
  apalGpioWrite(moduleGpioDw1000Reset.gpio, APAL_GPIO_LOW);
118

  
119 107
  //put the pin back to tri-state ... as input
120 108
//  palSetLineMode(moduleGpioDw1000Reset.gpio->line, APAL_GPIO_DIRECTION_INPUT); // TODO:
109
  aosThdMSleep(7);
110
}
121 111

  
122
  aosThdMSleep(2);
112
/*! @brief waking up the DW1000 module using Chip Select pin */
113
void wakeup_DW1000(void){
114
  clear_SPI_chip_select();
115
  aosThdMSleep(1);
116
  set_SPI_chip_select();
117
  aosThdMSleep(7);  // wait for XTAL to stabilize
118

  
119
  // set wakeup pin directly high
120
//   apalGpioWrite(moduleGpioDw1000WakeUp.gpio, APAL_GPIO_HIGH);
121
   aosThdMSleep(10);
123 122
}
124 123

  
125 124
/*! @brief Configure instance tag/anchor/etc... addresses */
126 125
void addressconfigure(uint8_t s1switch, uint8_t mode){
127 126
  uint16_t instAddress ;
128

  
129 127
  instance_anchaddr = (((s1switch & SWS1_A1A_MODE) << 2) + (s1switch & SWS1_A2A_MODE) + ((s1switch & SWS1_A3A_MODE) >> 2)) >> 4;
130

  
131 128
  if(mode == ANCHOR) {
132 129
    if(instance_anchaddr > 3) {
133 130
      instAddress = GATEWAY_ANCHOR_ADDR | 0x4 ; //listener
......
139 136
  else{
140 137
    instAddress = (uint16_t)instance_anchaddr;
141 138
  }
142

  
143 139
  instancesetaddresses(instAddress);
144 140
}
145 141

  
146 142
/*! @brief returns the use case / operational mode */
147 143
int decarangingmode(uint8_t s1switch){
148 144
  int mode = 0;
149

  
150 145
  if(s1switch & SWS1_SHF_MODE)  {
151 146
    mode = 1;
152 147
  }
153

  
154 148
  if(s1switch & SWS1_CH5_MODE) {
155 149
    mode = mode + 2;
156 150
  }
157

  
158 151
  return mode;
159 152
}
160 153

  
......
177 170
    }    
178 171
    dwt_softreset();
179 172
  }
180

  
181 173
    reset_DW1000();  //reset the DW1000 by driving the RSTn line low
182

  
183 174
  if((s1switch & SWS1_ANC_MODE) == 0){
184 175
    instance_mode = TAG;
185 176
  }
186 177
  else{
187 178
    instance_mode = ANCHOR;
188 179
  }
189

  
190
  result = instance_init(drv) ;
191

  
180
  result = instance_init(drv);
192 181
  if (0 > result){
193 182
    return(-1) ;
194 183
  }
195

  
196 184
  setHighSpeed_SPI(TRUE, drv);       // high speed spi max. ~ 20M
197 185
  devID = instancereaddeviceid() ;
198

  
199 186
  if (DWT_DEVICE_ID != devID){
200 187
    return(-1) ;
201 188
  }
202

  
203 189
  addressconfigure(s1switch, (uint8_t)instance_mode) ;
204

  
205 190
  if((instance_mode == ANCHOR) && (instance_anchaddr > 0x3)){
206 191
    instance_mode = LISTENER;
207 192
  }
208

  
209 193
  instancesetrole(instance_mode) ;       // Set this instance role
210 194
  dr_mode = decarangingmode(s1switch);
211 195
  chan = chConfig[dr_mode].channelNumber ;
......
227 211
           | S1_SWITCH_OFF << 6  // (configure Tag or anchor ID no.)
228 212
           | S1_SWITCH_OFF << 7; // Not use in this demo
229 213

  
230

  
231 214
  port_DisableEXT_IRQ();           //disable ScenSor IRQ until we configure the device
232

  
233 215
  if(inittestapplication(s1switch, drv) == -1) {
234 216
    return (-1); //error
235 217
  }
236

  
237 218
  aosThdMSleep(5);
238

  
239 219
  port_EnableEXT_IRQ();  //enable DW1000 IRQ before starting
240 220

  
241 221
  return 0;
......
245 225
/******************************************************************************/
246 226
/* EXPORTED FUNCTIONS                                                         */
247 227
/******************************************************************************/
248

  
249

  
250 228
aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut) {
251 229

  
252 230
  aosDbgCheck(ut->data != NULL);
253

  
254 231
  aos_utresult_t result = {0, 0};
255 232

  
233
#if defined (AMIROLLD_CFG_MIC9404x)
234
  // Enable 3.3 and 1.8 supply voltages for powering up the DW1000 module in AMiRo Light Ring
235
  if ((ut->data != NULL) && (((ut_dw1000data_t*)(ut->data))->mic9404xd != NULL)){
236
    mic9404x_lld_state_t state;
237
    uint32_t status = APAL_STATUS_OK;
238

  
239
    chprintf(stream, "reading current status of the Power..\n");
240
    status = mic9404x_lld_get(((ut_dw1000data_t*)(ut->data))->mic9404xd, &state);
241
    if (status == APAL_STATUS_OK) {
242
      aosUtPassedMsg(stream, &result, "power %s\n", (state == MIC9404x_LLD_STATE_ON) ? "enabled" : "disabled");
243
    } else {
244
      aosUtFailed(stream, &result);
245
    }
246
    if (state == MIC9404x_LLD_STATE_OFF) {
247
      chprintf(stream, "enabling the power ...\n");
248
      status = mic9404x_lld_set(((ut_dw1000data_t*)(ut->data))->mic9404xd, MIC9404x_LLD_STATE_ON);
249
      status |= mic9404x_lld_get(((ut_dw1000data_t*)(ut->data))->mic9404xd, &state);
250
      if (state == MIC9404x_LLD_STATE_ON) {
251
        aosThdSSleep(2);
252
        status |= mic9404x_lld_get(((ut_dw1000data_t*)(ut->data))->mic9404xd, &state);
253
      }
254
      if ((status == APAL_STATUS_OK) && (state == MIC9404x_LLD_STATE_ON)) {
255
        aosUtPassed(stream, &result);
256
      } else {
257
        aosUtFailed(stream, &result);
258
      }
259
    }
260
    aosThdSleep(1);
261
    return result;
262
  }
263
#endif  /* defined (AMIROLLD_CFG_MIC9404x) */
264

  
265

  
266
  // Start the DW1000 module UT after powering up
256 267
  chprintf(stream, "init DW1000...\n");
257
  dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
258
  aosThdMSleep(5);
268
  aosThdSleep(1);
269
  ut_dw1000data_t* h_dw1000data = NULL;
270
  if((ut->data != NULL) && (((ut_dw1000data_t*)(ut->data))->dw1000d != NULL)){
271
    h_dw1000data = ut->data;
272
    chprintf(stream, "assign handle for DW1000Driver struct \n");
273
  }
274
  else {
275
    chprintf(stream, "unsupported data type \n");
276
    return result;
277
  }
278
  aosThdSleep(1);
259 279

  
280
  reset_DW1000();     // hard reset
281
//  wakeup_DW1000();
282
  aosThdMSleep(5);
283
  int init = dwt_initialise(DWT_LOADUCODE, h_dw1000data->dw1000d);
284
  if (init == 0){
285
    chprintf(stream, "DW1000 is initialized \n");
286
  }
287
  else {
288
    chprintf(stream, "init error with return value: %d \n", init);
289
  }
290
  aosThdMSleep(5);
260 291

  
261 292
/*! Unit Test snippets for DW1000.
262 293
 * @Note: Event IRQ for DW1000 should be tested separately
263 294
 */
264 295
#if defined(UNIT_TEST_SNIPPETS_DW1000)
265

  
266
  uint32_t actual_deviceId;
267

  
296
  uint32_t actual_devID;
268 297
  port_DisableEXT_IRQ();
269 298

  
270
  setHighSpeed_SPI(false, (DW1000Driver*) ut->data);
271
  chprintf(stream, "expected device ID (LS SPI): 0xDECA0130 \n");
299
  /*! UT1: Low speed SPI result */
300
  setHighSpeed_SPI(false, h_dw1000data->dw1000d);
301
  chprintf(stream, "expected ID (LS SPI): 0xDECA0130 \n");
272 302
  aosThdMSleep(5);
273
  actual_deviceId = instancereaddeviceid();
274
  chprintf(stream, "actual read ID: 0x%x\n", actual_deviceId);
303
  actual_devID = instancereaddeviceid();
304
  chprintf(stream, "read ID (LS SPI): 0x%x\n", actual_devID);
275 305
  aosThdMSleep(5);
276 306

  
277 307
  //if the read of device ID fails, the DW1000 could be asleep
278
  if(DWT_DEVICE_ID != actual_deviceId){
279

  
308
  if(DWT_DEVICE_ID != actual_devID){
280 309
    clear_SPI_chip_select();
281 310
    aosThdMSleep(1);
282 311
    set_SPI_chip_select();
283 312
    aosThdMSleep(7);
284
    actual_deviceId = instancereaddeviceid() ;
285

  
286
    if(DWT_DEVICE_ID != actual_deviceId){
313
    actual_devID = instancereaddeviceid() ;
314
    if(DWT_DEVICE_ID != actual_devID){
287 315
      chprintf(stream, "SPI is not working or Unsupported Device ID\n");
288
      chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId);
316
      chprintf(stream, "actual device ID is: 0x%x\n", actual_devID);
289 317
      chprintf(stream, "expected device ID: 0xDECA0130 \n");
290 318
      aosThdMSleep(5);
291
    }
292

  
293
    //clear the sleep bit - so that after the hard reset below the DW does not go into sleep
319
    }   
294 320
    dwt_softreset();
295 321
  }
296 322

  
297
  /*! UT1: Low speed SPI result */
298
  if (actual_deviceId == DWT_DEVICE_ID){
323
  if (actual_devID == DWT_DEVICE_ID){
299 324
    aosUtPassed(stream, &result);
300 325
  } else {
301 326
    aosUtFailed(stream, &result);
302 327
  }
303 328

  
304
  reset_DW1000();
305

  
306
  chprintf(stream, "initialise instance for DW1000 \n");
307
  aosThdSleep(1);
308

  
309
  int x_init = instance_init((DW1000Driver*) ut->data) ;
329
  /*! Blinking TX and RX LED simultenously for 5 times */
330
  chprintf(stream, "blinking TX and RX LEDs simultenously for 5 times \n");
331
  for(int i =0; i< 5; i++){
332
    uint8_t mode = 3;
333
    uint32_t reg ;
334

  
335
    // Set up for LED output.
336
    reg = dwt_read32bitoffsetreg(GPIO_CTRL_ID, GPIO_MODE_OFFSET); // Hardcoded = 0xDE001400
337
    reg &= ~(GPIO_MSGP2_MASK | GPIO_MSGP3_MASK);
338
    reg |= (GPIO_PIN2_RXLED | GPIO_PIN3_TXLED);
339
    dwt_write32bitoffsetreg(GPIO_CTRL_ID, GPIO_MODE_OFFSET, reg);
340

  
341
    // Enable LP Oscillator to run from counter and turn on de-bounce clock.
342
    reg = dwt_read32bitoffsetreg(PMSC_ID, PMSC_CTRL0_OFFSET);      // hard-coded = 0xF0B40200
343
    reg |= (PMSC_CTRL0_GPDCE | PMSC_CTRL0_KHZCLEN);
344
    dwt_write32bitoffsetreg(PMSC_ID, PMSC_CTRL0_OFFSET, reg);
345

  
346
    // Enable LEDs to blink and set default blink time.
347
    reg = PMSC_LEDC_BLNKEN | PMSC_LEDC_BLINK_TIME_DEF;
348
    // Make LEDs blink once if requested.
349
    if (mode & DWT_LEDS_INIT_BLINK)
350
    {
351
      reg |= PMSC_LEDC_BLINK_NOW_ALL;
352
    }
353
    dwt_write32bitoffsetreg(PMSC_ID, PMSC_LEDC_OFFSET, reg);
354
    // Clear force blink bits if needed.
355
    if(mode & DWT_LEDS_INIT_BLINK)
356
    {
357
      reg &= ~PMSC_LEDC_BLINK_NOW_ALL;
358
      dwt_write32bitoffsetreg(PMSC_ID, PMSC_LEDC_OFFSET, reg);
359
    }
360
    aosThdMSleep(500);
361
  }
310 362

  
311
  if (0 != x_init){
363
  /*! UT2: Initialization  of the DW1000 module */
364
  reset_DW1000();
365
  chprintf(stream, "initialise the instance for DW1000 \n");
366
  aosThdMSleep(100);
367
  int x_init = instance_init(h_dw1000data->dw1000d) ;
368
  if (x_init != 0){
312 369
    chprintf(stream, "init error with return value: %d \n", x_init);
313
    aosThdSleep(1);
314 370
  }
315 371
  else {
316
    chprintf(stream, "init success with return value: %d \n", x_init);
317
    aosThdSleep(1);
372
    chprintf(stream, "succeed init! \n");
318 373
  }
319

  
320
  /*! UT2: Initialization  result*/
374
  aosThdMSleep(100);
321 375
  if (x_init == 0){
322 376
    aosUtPassed(stream, &result);
323 377
  } else {
324 378
    aosUtFailed(stream, &result);
325 379
  }
326 380

  
327
  setHighSpeed_SPI(true, (DW1000Driver*) ut->data);
328

  
329
  chprintf(stream, "expected device ID (HS SPI): 0xDECA0130\n");
330
  actual_deviceId = instancereaddeviceid();
331
  chprintf(stream, "actual read ID: 0x%x\n", actual_deviceId);
332
  aosThdMSleep(1);
333

  
334
  /*! UT3: High speed SPI result*/
335
  if (actual_deviceId == DWT_DEVICE_ID){
381
  /*! UT3: High speed SPI Testing */
382
  setHighSpeed_SPI(true, h_dw1000data->dw1000d);
383
  chprintf(stream, "expected ID (HS SPI): 0xDECA0130\n");
384
  actual_devID = instancereaddeviceid();
385
  chprintf(stream, "Read ID (HS SPI): 0x%x\n", actual_devID);
386
  aosThdMSleep(100);
387
  if (actual_devID == DWT_DEVICE_ID){
336 388
    aosUtPassed(stream, &result);
337 389
  } else {
338 390
    aosUtFailed(stream, &result);
339 391
  }
340 392

  
393
  /*! UT4: Configuration of UWB module
394
   * If all the five unit tests are passed, the module is ready to run.
395
   * Note that the interrupt IRQn should be tested separately.
396
   */
341 397
  port_EnableEXT_IRQ();
342 398
  reset_DW1000();
343

  
344 399
  chprintf(stream, "initialise the configuration for UWB application \n");
345 400
  aosThdSleep(1);
346

  
347
  int uwb_init = UWB_Init((DW1000Driver*) ut->data);
348

  
349
  if (0 != uwb_init){
401
  int uwb_init = UWB_Init(h_dw1000data->dw1000d);
402
  if (uwb_init != 0){
350 403
    chprintf(stream, "UWB config error with return value: %d \n", uwb_init);
351
    aosThdSleep(1);
352 404
  }
353 405
  else {
354
    chprintf(stream, "UWB config success with return value: %d \n", uwb_init);
355
    aosThdSleep(1);
406
    chprintf(stream, "succeed UWB config process \n", uwb_init);
356 407
  }
357

  
358
  /*! UT4: UWB configuration result
359
   * If all the four unit tests are passed, the module is ready to run.
360
   * Note that the interrupt IRQn should be tested separately.
361
   */
362 408
  if (uwb_init == 0){
363 409
    aosUtPassed(stream, &result);
364 410
  } else {
365 411
    aosUtFailed(stream, &result);
366 412
  }
367 413

  
368
  /************** End of UNIT_TEST_SNIPPETS_DW1000*****************/
414
  /************** End of UNIT_TEST_SNIPPETS_DW1000 *****************/
369 415

  
370 416
#else /* defined(UNIT_TEST_SNIPPETS_DW1000) */
371 417

  
372

  
373 418
  /*! RUN THE STATE MACHINE DEMO APP (RTLS) */
374

  
375 419
  chprintf(stream, "initialise the State Machine \n");
376 420
  aosThdSleep(2);
377 421

  
378 422
  /* Initialize UWB system with user defined configuration  */
379
  int uwb_init = UWB_Init((DW1000Driver*) ut->data);
423
  int uwb_init = UWB_Init(h_dw1000data->dw1000d);
380 424

  
381
  if (0 != uwb_init){
425
  if (uwb_init != 0){
382 426
    chprintf(stream, "error in UWB config with return value: %d \n", uwb_init);
383 427
  }
384 428
  else {
385 429
    chprintf(stream, "succeed the init of UWB config \n");
386 430
  }
387 431
  aosThdSleep(1);
388

  
389 432
  chprintf(stream, "running the RTLS demo application ... \n");
390
  aosThdSleep(1);
391 433

  
392 434
  /*! Run the localization system demo app as a thread */
393 435
  while(1){
394 436
    instance_run();
395 437
//    aosThdUSleep(10);
438
//    aosThdMSleep(1);
396 439
  }
397 440

  
398 441
#endif  /* defined(UNIT_TEST_SNIPPETS_DW1000) */

Also available in: Unified diff