Revision 10b520a8 unittests/periphery-lld/src/ut_alld_dw1000_v1.c
unittests/periphery-lld/src/ut_alld_dw1000_v1.c | ||
---|---|---|
41 | 41 |
#define SWS1_A1A_MODE 0x10 //anchor/tag address A1 |
42 | 42 |
#define SWS1_A2A_MODE 0x20 //anchor/tag address A2 |
43 | 43 |
#define SWS1_A3A_MODE 0x40 //anchor/tag address A3 |
44 |
#define SWS1_USB2SPI_MODE 0x78 //USB to SPI mode |
|
45 | 44 |
|
46 | 45 |
#define S1_SWITCH_ON (1) |
47 | 46 |
#define S1_SWITCH_OFF (0) |
... | ... | |
72 | 71 |
void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){ |
73 | 72 |
|
74 | 73 |
spiStop(drv->spid); |
75 |
// spiAcquireBus(&MODULE_HAL_SPI_UWB); |
|
76 | 74 |
|
77 | 75 |
if (speedValue == FALSE){ |
78 | 76 |
spiStart(drv->spid, &moduleHalSpiUwbLsConfig); // low speed spi configuration |
... | ... | |
82 | 80 |
} |
83 | 81 |
} |
84 | 82 |
|
83 |
/*! @brief entry point to the IRQn event in DW1000 module |
|
84 |
* |
|
85 |
* */ |
|
86 |
void process_deca_irq(void){ |
|
87 |
do{ |
|
88 |
dwt_isr(); |
|
89 |
//while IRS line active (ARM can only do edge sensitive interrupts) |
|
90 |
}while(port_CheckEXT_IRQ() == 1); |
|
91 |
} |
|
92 |
|
|
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 |
|
|
85 | 100 |
/*! @brief Manually set the chip select pin of the SPI */ |
86 | 101 |
void set_SPI_chip_select(void){ |
87 | 102 |
apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_HIGH); |
... | ... | |
107 | 122 |
aosThdMSleep(2); |
108 | 123 |
} |
109 | 124 |
|
110 |
|
|
111 | 125 |
/*! @brief Configure instance tag/anchor/etc... addresses */ |
112 | 126 |
void addressconfigure(uint8_t s1switch, uint8_t mode){ |
113 | 127 |
uint16_t instAddress ; |
... | ... | |
129 | 143 |
instancesetaddresses(instAddress); |
130 | 144 |
} |
131 | 145 |
|
132 |
|
|
133 | 146 |
/*! @brief returns the use case / operational mode */ |
134 | 147 |
int decarangingmode(uint8_t s1switch){ |
135 | 148 |
int mode = 0; |
... | ... | |
146 | 159 |
} |
147 | 160 |
|
148 | 161 |
/*! @brief Check connection setting and initialize DW1000 module */ |
149 |
uint32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){
|
|
162 |
int32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){ |
|
150 | 163 |
uint32_t devID ; |
151 | 164 |
int result; |
152 | 165 |
|
... | ... | |
174 | 187 |
instance_mode = ANCHOR; |
175 | 188 |
} |
176 | 189 |
|
177 |
result = instance_init(drv) ; // TODO |
|
178 |
// result = instance_init() ; |
|
190 |
result = instance_init(drv) ; |
|
179 | 191 |
|
180 | 192 |
if (0 > result){ |
181 | 193 |
return(-1) ; |
182 | 194 |
} |
183 | 195 |
|
184 |
setHighSpeed_SPI(TRUE, drv); // high speed spi max. ~ 20M
|
|
196 |
setHighSpeed_SPI(TRUE, drv); // high speed spi max. ~ 20M |
|
185 | 197 |
devID = instancereaddeviceid() ; |
186 | 198 |
|
187 | 199 |
if (DWT_DEVICE_ID != devID){ |
... | ... | |
199 | 211 |
chan = chConfig[dr_mode].channelNumber ; |
200 | 212 |
instance_config(&chConfig[dr_mode], &sfConfig[dr_mode], drv) ; |
201 | 213 |
|
202 |
return devID; |
|
214 |
return (int32_t)devID;
|
|
203 | 215 |
} |
204 | 216 |
|
205 |
|
|
206 | 217 |
/*! @brief Main Entry point to Initialization of UWB DW1000 configuration */ |
207 | 218 |
#pragma GCC optimize ("O3") |
208 | 219 |
int UWB_Init(DW1000Driver* drv){ |
... | ... | |
219 | 230 |
|
220 | 231 |
port_DisableEXT_IRQ(); //disable ScenSor IRQ until we configure the device |
221 | 232 |
|
222 |
if((s1switch & SWS1_USB2SPI_MODE) == SWS1_USB2SPI_MODE){
|
|
223 |
return 1;
|
|
233 |
if(inittestapplication(s1switch, drv) == -1) {
|
|
234 |
return (-1); //error
|
|
224 | 235 |
} |
225 |
else{ |
|
226 |
//run RTLS application |
|
227 |
if(inittestapplication(s1switch, drv) == (uint32_t)-1) { |
|
228 |
return 0; //error |
|
229 |
} |
|
230 | 236 |
|
231 |
aosThdMSleep(5); |
|
232 |
} |
|
237 |
aosThdMSleep(5); |
|
233 | 238 |
|
234 |
port_EnableEXT_IRQ(); //enable ScenSor IRQ before starting
|
|
239 |
port_EnableEXT_IRQ(); //enable DW1000 IRQ before starting
|
|
235 | 240 |
|
236 | 241 |
return 0; |
237 | 242 |
} |
... | ... | |
254 | 259 |
|
255 | 260 |
|
256 | 261 |
/*! Unit Test snippets for DW1000. |
257 |
* @Note: Passed all 4 unit tests. Event IRQ should be tested separately
|
|
262 |
* @Note: Event IRQ for DW1000 should be tested separately
|
|
258 | 263 |
*/ |
259 | 264 |
#ifdef UNIT_TEST_SNIPPETS_DW1000 |
260 | 265 |
|
... | ... | |
269 | 274 |
chprintf(stream, "actual read ID: 0x%x\n", actual_deviceId); |
270 | 275 |
aosThdMSleep(5); |
271 | 276 |
|
272 |
if(DWT_DEVICE_ID != actual_deviceId) //if the read of device ID fails, the DW1000 could be asleep |
|
273 |
{ |
|
274 |
port_SPIx_clear_chip_select(); //CS low |
|
275 |
aosThdMSleep(1); //200 us to wake up then waits 5ms for DW1000 XTAL to stabilise |
|
276 |
port_SPIx_set_chip_select(); //CS high |
|
277 |
//if the read of device ID fails, the DW1000 could be asleep |
|
278 |
if(DWT_DEVICE_ID != actual_deviceId){ |
|
279 |
|
|
280 |
clear_SPI_chip_select(); |
|
281 |
aosThdMSleep(1); |
|
282 |
set_SPI_chip_select(); |
|
277 | 283 |
aosThdMSleep(7); |
278 | 284 |
actual_deviceId = instancereaddeviceid() ; |
279 | 285 |
|
280 |
// SPI not working or Unsupported Device ID |
|
281 | 286 |
if(DWT_DEVICE_ID != actual_deviceId){ |
282 |
chprintf(stream, "SPI not working or Unsupported Device ID\n"); |
|
287 |
chprintf(stream, "SPI is not working or Unsupported Device ID\n");
|
|
283 | 288 |
chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId); |
284 | 289 |
chprintf(stream, "expected device ID: 0xDECA0130 \n"); |
285 | 290 |
aosThdMSleep(5); |
286 |
// return(-1) ; |
|
287 | 291 |
} |
288 | 292 |
|
289 | 293 |
//clear the sleep bit - so that after the hard reset below the DW does not go into sleep |
... | ... | |
296 | 300 |
} else { |
297 | 301 |
aosUtFailed(stream, &result); |
298 | 302 |
} |
299 |
reset_DW1000(); |
|
300 | 303 |
|
304 |
reset_DW1000(); |
|
301 | 305 |
|
302 |
chprintf(stream, " Initialise instance for DW1000 \n");
|
|
303 |
aosThdSleep(5);
|
|
306 |
chprintf(stream, "initialise instance for DW1000 \n");
|
|
307 |
aosThdSleep(1);
|
|
304 | 308 |
|
305 |
int x_init = instance_init((DW1000Driver*) ut->data) ; // TODO |
|
306 |
// int x_init = instance_init() ; |
|
309 |
int x_init = instance_init((DW1000Driver*) ut->data) ; |
|
307 | 310 |
|
308 | 311 |
if (0 != x_init){ |
309 |
chprintf(stream, "Init error with return value: %d \n", x_init);
|
|
310 |
aosThdSleep(5);
|
|
312 |
chprintf(stream, "init error with return value: %d \n", x_init);
|
|
313 |
aosThdSleep(1);
|
|
311 | 314 |
} |
312 | 315 |
else { |
313 |
chprintf(stream, "Init success with return value: %d \n", x_init);
|
|
314 |
aosThdSleep(5);
|
|
316 |
chprintf(stream, "init success with return value: %d \n", x_init);
|
|
317 |
aosThdSleep(1);
|
|
315 | 318 |
} |
316 | 319 |
|
317 |
|
|
318 | 320 |
/*! UT2: Initialization result*/ |
319 | 321 |
if (x_init == 0){ |
320 | 322 |
aosUtPassed(stream, &result); |
... | ... | |
322 | 324 |
aosUtFailed(stream, &result); |
323 | 325 |
} |
324 | 326 |
|
325 |
|
|
326 | 327 |
setHighSpeed_SPI(true, (DW1000Driver*) ut->data); |
327 | 328 |
|
328 | 329 |
chprintf(stream, "expected device ID (HS SPI): 0xDECA0130\n"); |
329 | 330 |
actual_deviceId = instancereaddeviceid(); |
330 | 331 |
chprintf(stream, "actual read ID: 0x%x\n", actual_deviceId); |
331 |
aosThdMSleep(5);
|
|
332 |
aosThdMSleep(1);
|
|
332 | 333 |
|
333 | 334 |
/*! UT3: High speed SPI result*/ |
334 | 335 |
if (actual_deviceId == DWT_DEVICE_ID){ |
... | ... | |
340 | 341 |
port_EnableEXT_IRQ(); |
341 | 342 |
reset_DW1000(); |
342 | 343 |
|
343 |
|
|
344 |
chprintf(stream, " Initialise the configuration for UWB application \n"); |
|
345 |
aosThdSleep(5); |
|
344 |
chprintf(stream, "initialise the configuration for UWB application \n"); |
|
345 |
aosThdSleep(1); |
|
346 | 346 |
|
347 | 347 |
int uwb_init = UWB_Init((DW1000Driver*) ut->data); |
348 | 348 |
|
349 | 349 |
if (0 != uwb_init){ |
350 | 350 |
chprintf(stream, "UWB config error with return value: %d \n", uwb_init); |
351 |
aosThdSleep(5);
|
|
351 |
aosThdSleep(1);
|
|
352 | 352 |
} |
353 | 353 |
else { |
354 | 354 |
chprintf(stream, "UWB config success with return value: %d \n", uwb_init); |
355 |
aosThdSleep(5);
|
|
355 |
aosThdSleep(1);
|
|
356 | 356 |
} |
357 | 357 |
|
358 | 358 |
/*! UT4: UWB configuration result |
... | ... | |
369 | 369 |
|
370 | 370 |
#else |
371 | 371 |
|
372 |
// RUN THE STATE MACHINE DEMO APP |
|
373 | 372 |
|
374 |
chprintf(stream, " Initialise the State Machine \n"); |
|
373 |
/*! RUN THE STATE MACHINE DEMO APP (RTLS) */ |
|
374 |
|
|
375 |
chprintf(stream, "initialise the State Machine \n"); |
|
375 | 376 |
aosThdSleep(2); |
376 | 377 |
|
377 | 378 |
/* Initialize UWB system with user defined configuration */ |
378 | 379 |
int uwb_init = UWB_Init((DW1000Driver*) ut->data); |
379 | 380 |
|
380 | 381 |
if (0 != uwb_init){ |
381 |
chprintf(stream, "UWB config error with return value: %d \n", uwb_init);
|
|
382 |
chprintf(stream, "error in UWB config with return value: %d \n", uwb_init);
|
|
382 | 383 |
} |
383 | 384 |
else { |
384 |
chprintf(stream, "UWB config success with return value: %d \n", uwb_init);
|
|
385 |
chprintf(stream, "succeed the init of UWB config \n");
|
|
385 | 386 |
} |
386 | 387 |
aosThdSleep(1); |
387 | 388 |
|
388 |
chprintf(stream, " Running the RTLS demo application \n");
|
|
389 |
chprintf(stream, "running the RTLS demo application ... \n");
|
|
389 | 390 |
aosThdSleep(1); |
390 | 391 |
|
391 |
|
|
392 |
/* Run the localization system demo app as a thread */ |
|
392 |
/*! Run the localization system demo app as a thread */ |
|
393 | 393 |
while(1){ |
394 | 394 |
instance_run(); |
395 | 395 |
// aosThdUSleep(10); |
Also available in: Unified diff