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