amiro-os / unittests / periphery-lld / src / ut_alld_dw1000.c @ 8a93b752
History | View | Annotate | Download (6.255 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 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 <ut_alld_dw1000.h> |
20 |
|
21 |
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_DW1000)) || defined(__DOXYGEN__) |
22 |
|
23 |
/******************************************************************************/
|
24 |
/* LOCAL DEFINITIONS */
|
25 |
/******************************************************************************/
|
26 |
|
27 |
/******************************************************************************/
|
28 |
/* EXPORTED VARIABLES */
|
29 |
/******************************************************************************/
|
30 |
|
31 |
/******************************************************************************/
|
32 |
/* LOCAL TYPES */
|
33 |
/******************************************************************************/
|
34 |
|
35 |
/******************************************************************************/
|
36 |
/* LOCAL VARIABLES */
|
37 |
/******************************************************************************/
|
38 |
|
39 |
/******************************************************************************/
|
40 |
/* LOCAL FUNCTIONS */
|
41 |
/******************************************************************************/
|
42 |
|
43 |
/******************************************************************************/
|
44 |
/* EXPORTED FUNCTIONS */
|
45 |
/******************************************************************************/
|
46 |
|
47 |
aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut) { |
48 |
|
49 |
aosDbgCheck(ut->data != NULL);
|
50 |
|
51 |
aos_utresult_t result = {0, 0}; |
52 |
|
53 |
chprintf(stream, "init DW1000...\n");
|
54 |
dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data); |
55 |
chprintf(stream, "device ID should be: 0xDECA0130\nget device ID...\n");
|
56 |
uint32_t actual_deviceId = dwt_readdevid(); |
57 |
chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId);
|
58 |
aosThdMSleep(1);
|
59 |
|
60 |
if (actual_deviceId == DWT_DEVICE_ID){
|
61 |
aosUtPassed(stream, &result); |
62 |
} else {
|
63 |
aosUtFailed(stream, &result); |
64 |
} |
65 |
|
66 |
/*chprintf(stream, "write-read test...\n");
|
67 |
uint32_t testvalue = 0x0A;
|
68 |
uint16_t panid = 0x00;
|
69 |
|
70 |
dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
|
71 |
chprintf(stream, "value PANADR register before write: %x\n", panid);
|
72 |
chprintf(stream, "write 0x%x to PANADR register...\n", testvalue);
|
73 |
dwt_setpanid(testvalue);
|
74 |
dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
|
75 |
|
76 |
chprintf(stream, "PANADR register is now: 0x%x\n", panid);
|
77 |
|
78 |
if (panid == testvalue){
|
79 |
aosUtPassed(stream, &result);
|
80 |
} else {
|
81 |
aosUtFailed(stream, &result);
|
82 |
}
|
83 |
*/
|
84 |
|
85 |
dwt_setleds(0x03);
|
86 |
|
87 |
// RUN DECA-DEMO
|
88 |
|
89 |
instanceConfig_t chConfig; |
90 |
chConfig.channelNumber = 2; // channel |
91 |
chConfig.preambleCode = 4; // preambleCode |
92 |
chConfig.pulseRepFreq = DWT_PRF_16M; // prf
|
93 |
chConfig.dataRate = DWT_BR_6M8; // datarate
|
94 |
chConfig.preambleLen = DWT_PLEN_128; // preambleLength
|
95 |
chConfig.pacSize = DWT_PAC8; // pacSize
|
96 |
chConfig.nsSFD = 0; // non-standard SFD |
97 |
chConfig.sfdTO = (129 + 8 - 8); // SFD timeout |
98 |
|
99 |
sfConfig_t sfConfig; |
100 |
sfConfig.slotDuration_ms = (10); //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time |
101 |
//e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
|
102 |
sfConfig.numSlots = (10); //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging), |
103 |
sfConfig.sfPeriod_ms = (10*10); //in ms => 100 ms frame means 10 Hz location rate |
104 |
sfConfig.tagPeriod_ms = (10*10); //tag period in ms (sleep time + ranging time) |
105 |
sfConfig.pollTxToFinalTxDly_us = (2500); //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames) |
106 |
|
107 |
//TODO Disable EXTI IRQ
|
108 |
//port_DisableEXT_IRQ();
|
109 |
|
110 |
// inittestapplication
|
111 |
// dwt_softreset(); // already done in instance_init()
|
112 |
|
113 |
// Set this instance mode (tag/anchor)
|
114 |
(void) instance_init(TAG, (DW1000Driver*) ut->data);
|
115 |
//int err = instance_init(TAG, (DW1000Driver*) ut->data);
|
116 |
(void) instance_readdeviceid();
|
117 |
//uint32_t deca_dev_id = instance_readdeviceid();
|
118 |
|
119 |
// TAG ID 0
|
120 |
instance_set_16bit_address(0);
|
121 |
// simulate DECA config Mode 2 (DIP 1100000)
|
122 |
instance_config(&chConfig, &sfConfig) ; |
123 |
|
124 |
//TODO Enable EXTI IRQ
|
125 |
//port_EnableEXT_IRQ();
|
126 |
|
127 |
// Start Ranging
|
128 |
|
129 |
chprintf(stream, "start ranging...\n");
|
130 |
|
131 |
|
132 |
while(1) { |
133 |
//int n = 0;
|
134 |
instance_data_t* inst = instance_get_local_structure_ptr(0);
|
135 |
|
136 |
int monitor_local = inst->monitor ;
|
137 |
int txdiff = (chVTGetSystemTimeX() - inst->timeofTx);
|
138 |
|
139 |
tag_run(); |
140 |
//if delayed TX scheduled but did not happen after expected time then it has failed... (has to be < slot period)
|
141 |
//if anchor just go into RX and wait for next message from tags/anchors
|
142 |
//if tag handle as a timeout
|
143 |
if( (monitor_local == 1) && ( txdiff > inst->slotDuration_ms) ) { |
144 |
inst->wait4ack = 0;
|
145 |
tag_process_rx_timeout(inst); |
146 |
inst->monitor = 0;
|
147 |
} |
148 |
} |
149 |
|
150 |
(void) instance_newrange();
|
151 |
//int rx = instance_newrange();
|
152 |
|
153 |
return result;
|
154 |
} |
155 |
|
156 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_DW1000) */ |