63 |
63 |
int chan, tagaddr, ancaddr;
|
64 |
64 |
int instance_mode = ANCHOR;
|
65 |
65 |
|
66 |
|
DW1000Driver* spiDrv;
|
67 |
|
|
68 |
66 |
|
69 |
67 |
/******************************************************************************/
|
70 |
68 |
/* LOCAL FUNCTIONS */
|
71 |
69 |
/******************************************************************************/
|
72 |
70 |
|
73 |
|
/*! @brief Change the SPI speed configuration on the fly */
|
74 |
|
void setHighSpeed_SPI(bool speedValue){
|
|
71 |
/*! @brief Change the SPI speed configuration on the fly */
|
|
72 |
void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){
|
75 |
73 |
|
76 |
|
spiStop(&MODULE_HAL_SPI_UWB);
|
|
74 |
spiStop(drv->spid);
|
77 |
75 |
// spiAcquireBus(&MODULE_HAL_SPI_UWB);
|
78 |
76 |
|
79 |
77 |
if (speedValue == FALSE){
|
80 |
|
spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig); // low speed spi configuration
|
|
78 |
spiStart(drv->spid, &moduleHalSpiUwbLsConfig); // low speed spi configuration
|
81 |
79 |
}
|
82 |
80 |
else{
|
83 |
|
spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbHsConfig); // high speed spi configuration
|
|
81 |
spiStart(drv->spid, &moduleHalSpiUwbHsConfig); // high speed spi configuration
|
84 |
82 |
}
|
85 |
83 |
}
|
86 |
|
/* void setHighSpeed_SPI(bool speedValue){
|
87 |
|
|
88 |
|
spiStop(spiDrv->spid);
|
89 |
|
// spiAcquireBus(&MODULE_HAL_SPI_UWB);
|
90 |
|
|
91 |
|
if (speedValue == FALSE){
|
92 |
|
spiStart(spiDrv->spid, &moduleHalSpiUwbLsConfig); // low speed spi configuration
|
93 |
|
}
|
94 |
|
else{
|
95 |
|
spiStart(spiDrv->spid, &moduleHalSpiUwbHsConfig); // high speed spi configuration
|
96 |
|
}
|
97 |
|
} */
|
98 |
84 |
|
99 |
85 |
/*! @brief Manually set the chip select pin of the SPI */
|
100 |
|
void port_SPIx_set_chip_select(void){
|
|
86 |
void set_SPI_chip_select(void){
|
101 |
87 |
apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_HIGH);
|
102 |
88 |
}
|
103 |
89 |
|
104 |
90 |
/*! @brief Manually reset the chip select pin of the SPI */
|
105 |
|
void port_SPIx_clear_chip_select(void){
|
|
91 |
void clear_SPI_chip_select(void){
|
106 |
92 |
apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW);
|
107 |
93 |
}
|
108 |
94 |
|
... | ... | |
122 |
108 |
}
|
123 |
109 |
|
124 |
110 |
|
125 |
|
/*! @brief Configure instance tag/anchor/etc... addresses
|
126 |
|
*
|
127 |
|
* */
|
|
111 |
/*! @brief Configure instance tag/anchor/etc... addresses */
|
128 |
112 |
void addressconfigure(uint8_t s1switch, uint8_t mode){
|
129 |
113 |
uint16_t instAddress ;
|
130 |
114 |
|
... | ... | |
146 |
130 |
}
|
147 |
131 |
|
148 |
132 |
|
149 |
|
/*! @brief returns the use case / operational mode
|
150 |
|
*
|
151 |
|
* */
|
|
133 |
/*! @brief returns the use case / operational mode */
|
152 |
134 |
int decarangingmode(uint8_t s1switch){
|
153 |
135 |
int mode = 0;
|
154 |
136 |
|
... | ... | |
163 |
145 |
return mode;
|
164 |
146 |
}
|
165 |
147 |
|
166 |
|
/*! @brief Check connection setting and initialize DW1000 module
|
167 |
|
*
|
168 |
|
**/
|
169 |
|
uint32_t inittestapplication(uint8_t s1switch){
|
|
148 |
/*! @brief Check connection setting and initialize DW1000 module */
|
|
149 |
uint32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){
|
170 |
150 |
uint32_t devID ;
|
171 |
151 |
int result;
|
172 |
152 |
|
173 |
|
setHighSpeed_SPI(FALSE); //low speed spi max. ~4M
|
|
153 |
setHighSpeed_SPI(FALSE, drv); //low speed spi max. ~4M
|
174 |
154 |
devID = instancereaddeviceid() ;
|
175 |
155 |
|
176 |
156 |
if(DWT_DEVICE_ID != devID) {
|
177 |
|
port_SPIx_clear_chip_select();
|
|
157 |
clear_SPI_chip_select();
|
178 |
158 |
Sleep(1);
|
179 |
|
port_SPIx_set_chip_select();
|
|
159 |
set_SPI_chip_select();
|
180 |
160 |
Sleep(7);
|
181 |
161 |
devID = instancereaddeviceid() ;
|
182 |
162 |
if(DWT_DEVICE_ID != devID){
|
183 |
|
return(-1) ; // SPI not working or Unsupported Device ID
|
|
163 |
return(-1) ;
|
184 |
164 |
}
|
185 |
|
dwt_softreset();//clear the sleep bit - so that after the hard reset below the DW does not go into sleep
|
|
165 |
dwt_softreset();
|
186 |
166 |
}
|
187 |
167 |
|
188 |
168 |
reset_DW1000(); //reset the DW1000 by driving the RSTn line low
|
... | ... | |
194 |
174 |
instance_mode = ANCHOR;
|
195 |
175 |
}
|
196 |
176 |
|
197 |
|
result = instance_init(spiDrv) ; // TODO
|
|
177 |
result = instance_init(drv) ; // TODO
|
198 |
178 |
// result = instance_init() ;
|
199 |
179 |
|
200 |
180 |
if (0 > result){
|
201 |
181 |
return(-1) ;
|
202 |
182 |
}
|
203 |
183 |
|
204 |
|
setHighSpeed_SPI(TRUE); // high speed spi max. ~ 20M
|
|
184 |
setHighSpeed_SPI(TRUE, drv); // high speed spi max. ~ 20M
|
205 |
185 |
devID = instancereaddeviceid() ;
|
206 |
186 |
|
207 |
187 |
if (DWT_DEVICE_ID != devID){
|
... | ... | |
217 |
197 |
instancesetrole(instance_mode) ; // Set this instance role
|
218 |
198 |
dr_mode = decarangingmode(s1switch);
|
219 |
199 |
chan = chConfig[dr_mode].channelNumber ;
|
220 |
|
instance_config(&chConfig[dr_mode], &sfConfig[dr_mode]) ;
|
|
200 |
instance_config(&chConfig[dr_mode], &sfConfig[dr_mode], drv) ;
|
221 |
201 |
|
222 |
202 |
return devID;
|
223 |
203 |
}
|
224 |
204 |
|
225 |
|
/*! @brief Main Entry point to Initialization of UWB DW1000 configuration
|
226 |
|
*
|
227 |
|
* */
|
|
205 |
|
|
206 |
/*! @brief Main Entry point to Initialization of UWB DW1000 configuration */
|
228 |
207 |
#pragma GCC optimize ("O3")
|
229 |
|
int UWB_Init(void){
|
|
208 |
int UWB_Init(DW1000Driver* drv){
|
230 |
209 |
|
231 |
210 |
/*! Software defined Configurartion for TAG, ANC, and other settings as needed */
|
232 |
|
s1switch = S1_SWITCH_OFF << 1 // is_switch_on(TA_SW1_2) << 2 // (on = 6.8 Mbps, off = 110 kbps)
|
233 |
|
| S1_SWITCH_OFF << 2 // (on = CH5, off = CH2)
|
234 |
|
| S1_SWITCH_OFF << 3 // (on = Anchor, off = TAG)
|
235 |
|
| S1_SWITCH_OFF << 4 // (configure Tag or anchor ID no.)
|
236 |
|
| S1_SWITCH_OFF << 5 // (configure Tag or anchor ID no.)
|
237 |
|
| S1_SWITCH_OFF << 6 // (configure Tag or anchor ID no.)
|
238 |
|
| S1_SWITCH_OFF << 7; // Not use in this demo
|
|
211 |
s1switch = S1_SWITCH_OFF << 1 // (on = 6.8 Mbps, off = 110 kbps)
|
|
212 |
| S1_SWITCH_OFF << 2 // (on = CH5, off = CH2)
|
|
213 |
| S1_SWITCH_OFF << 3 // (on = Anchor, off = TAG)
|
|
214 |
| S1_SWITCH_OFF << 4 // (configure Tag or anchor ID no.)
|
|
215 |
| S1_SWITCH_OFF << 5 // (configure Tag or anchor ID no.)
|
|
216 |
| S1_SWITCH_OFF << 6 // (configure Tag or anchor ID no.)
|
|
217 |
| S1_SWITCH_OFF << 7; // Not use in this demo
|
239 |
218 |
|
240 |
219 |
|
241 |
220 |
port_DisableEXT_IRQ(); //disable ScenSor IRQ until we configure the device
|
... | ... | |
245 |
224 |
}
|
246 |
225 |
else{
|
247 |
226 |
//run RTLS application
|
248 |
|
if(inittestapplication(s1switch) == (uint32_t)-1) {
|
|
227 |
if(inittestapplication(s1switch, drv) == (uint32_t)-1) {
|
249 |
228 |
return 0; //error
|
250 |
229 |
}
|
251 |
230 |
|
... | ... | |
269 |
248 |
|
270 |
249 |
aos_utresult_t result = {0, 0};
|
271 |
250 |
|
|
251 |
chprintf(stream, "init DW1000...\n");
|
|
252 |
dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
|
|
253 |
aosThdMSleep(5);
|
272 |
254 |
|
273 |
|
/*! Unit Test snippets for DW1000.
|
274 |
|
* @Note: Passed all 4 unit tests. Event IRQ should be tested separately
|
275 |
|
*/
|
|
255 |
|
|
256 |
/*! Unit Test snippets for DW1000.
|
|
257 |
* @Note: Passed all 4 unit tests. Event IRQ should be tested separately
|
|
258 |
*/
|
276 |
259 |
#ifdef UNIT_TEST_SNIPPETS_DW1000
|
277 |
260 |
|
278 |
261 |
uint32_t actual_deviceId;
|
279 |
262 |
|
280 |
|
chprintf(stream, "init DW1000...\n");
|
281 |
|
dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
|
282 |
|
aosThdMSleep(5);
|
283 |
|
|
284 |
263 |
port_DisableEXT_IRQ();
|
285 |
264 |
|
286 |
|
setHighSpeed_SPI(false);
|
|
265 |
setHighSpeed_SPI(false, (DW1000Driver*) ut->data);
|
287 |
266 |
chprintf(stream, "expected device ID (LS SPI): 0xDECA0130 \n");
|
288 |
267 |
aosThdMSleep(5);
|
289 |
268 |
actual_deviceId = instancereaddeviceid();
|
... | ... | |
311 |
290 |
dwt_softreset();
|
312 |
291 |
}
|
313 |
292 |
|
314 |
|
/*! Low speed SPI unit test result */
|
|
293 |
/*! UT1: Low speed SPI result */
|
315 |
294 |
if (actual_deviceId == DWT_DEVICE_ID){
|
316 |
295 |
aosUtPassed(stream, &result);
|
317 |
296 |
} else {
|
... | ... | |
336 |
315 |
}
|
337 |
316 |
|
338 |
317 |
|
339 |
|
/* Initialization unit test result */
|
|
318 |
/*! UT2: Initialization result*/
|
340 |
319 |
if (x_init == 0){
|
341 |
320 |
aosUtPassed(stream, &result);
|
342 |
321 |
} else {
|
... | ... | |
344 |
323 |
}
|
345 |
324 |
|
346 |
325 |
|
347 |
|
setHighSpeed_SPI(true);
|
|
326 |
setHighSpeed_SPI(true, (DW1000Driver*) ut->data);
|
348 |
327 |
|
349 |
328 |
chprintf(stream, "expected device ID (HS SPI): 0xDECA0130\n");
|
350 |
329 |
actual_deviceId = instancereaddeviceid();
|
351 |
330 |
chprintf(stream, "actual read ID: 0x%x\n", actual_deviceId);
|
352 |
331 |
aosThdMSleep(5);
|
353 |
332 |
|
354 |
|
/* High speed SPI unit test result */
|
|
333 |
/*! UT3: High speed SPI result*/
|
355 |
334 |
if (actual_deviceId == DWT_DEVICE_ID){
|
356 |
335 |
aosUtPassed(stream, &result);
|
357 |
336 |
} else {
|
... | ... | |
362 |
341 |
reset_DW1000();
|
363 |
342 |
|
364 |
343 |
|
365 |
|
|
366 |
344 |
chprintf(stream, " Initialise the configuration for UWB application \n");
|
367 |
345 |
aosThdSleep(5);
|
368 |
346 |
|
369 |
|
int uwb_init = UWB_Init();
|
|
347 |
int uwb_init = UWB_Init((DW1000Driver*) ut->data);
|
370 |
348 |
|
371 |
349 |
if (0 != uwb_init){
|
372 |
350 |
chprintf(stream, "UWB config error with return value: %d \n", uwb_init);
|
... | ... | |
377 |
355 |
aosThdSleep(5);
|
378 |
356 |
}
|
379 |
357 |
|
380 |
|
/* UWB configuration unit test.
|
|
358 |
/*! UT4: UWB configuration result
|
381 |
359 |
* If all the four unit tests are passed, the module is ready to run.
|
382 |
360 |
* Note that the interrupt IRQn should be tested separately.
|
383 |
361 |
*/
|
... | ... | |
396 |
374 |
chprintf(stream, " Initialise the State Machine \n");
|
397 |
375 |
aosThdSleep(2);
|
398 |
376 |
|
399 |
|
/* Initialize UWB system with the configuration provided in module_uwb_conf.c */
|
400 |
|
int uwb_init = UWB_Init();
|
|
377 |
/* Initialize UWB system with user defined configuration */
|
|
378 |
int uwb_init = UWB_Init((DW1000Driver*) ut->data);
|
401 |
379 |
|
402 |
380 |
if (0 != uwb_init){
|
403 |
381 |
chprintf(stream, "UWB config error with return value: %d \n", uwb_init);
|