Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_dw1000.c @ f3ac1c96

History | View | Annotate | Download (6.48 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
#include <ut_alld_dw1000.h>
20
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_DW1000)) || defined(__DOXYGEN__)
22
23 f3ac1c96 Thomas Schöpping
/******************************************************************************/
24
/* LOCAL DEFINITIONS                                                          */
25
/******************************************************************************/
26 e05848a6 Robin Ewers
#include <aos_debug.h>
27
#include <chprintf.h>
28
#include <aos_thread.h>
29
// No unit testing! -> Contains the Deca Demo Application
30
#include <deca_instance.h>
31
#include <alld_dw1000.h>
32
#include <alld_dw1000_regs.h>
33
#include <math.h>
34
35 f3ac1c96 Thomas Schöpping
/******************************************************************************/
36
/* EXPORTED VARIABLES                                                         */
37
/******************************************************************************/
38
39
/******************************************************************************/
40
/* LOCAL TYPES                                                                */
41
/******************************************************************************/
42
43
/******************************************************************************/
44
/* LOCAL VARIABLES                                                            */
45
/******************************************************************************/
46
47
/******************************************************************************/
48
/* LOCAL FUNCTIONS                                                            */
49
/******************************************************************************/
50
51
/******************************************************************************/
52
/* EXPORTED FUNCTIONS                                                         */
53
/******************************************************************************/
54 e05848a6 Robin Ewers
55
aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut) {
56
57
    aosDbgCheck(ut->data != NULL);
58
59
    aos_utresult_t result = {0, 0};
60
61
    chprintf(stream, "init DW1000...\n");
62
    dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
63
    chprintf(stream, "device ID should be: 0xDECA0130\nget device ID...\n");
64
    uint32_t actual_deviceId = dwt_readdevid();
65
    chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId);
66
    aosThdMSleep(1);
67
68
    if (actual_deviceId == DWT_DEVICE_ID){
69
      aosUtPassed(stream, &result);
70
    } else {
71
      aosUtFailed(stream, &result);
72
    }
73
74
    /*chprintf(stream, "write-read test...\n");
75
    uint32_t testvalue = 0x0A;
76
    uint16_t panid = 0x00;
77

78
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
79
    chprintf(stream, "value PANADR register before write: %x\n", panid);
80
    chprintf(stream, "write 0x%x to PANADR register...\n", testvalue);
81
    dwt_setpanid(testvalue);
82
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
83

84
    chprintf(stream, "PANADR register is now: 0x%x\n", panid);
85

86
    if (panid == testvalue){
87
      aosUtPassed(stream, &result);
88
    } else {
89
      aosUtFailed(stream, &result);
90
    }
91
*/
92
93
    dwt_setleds(0x03);
94
95
    // RUN DECA-DEMO
96
97
    instanceConfig_t chConfig;
98
    chConfig.channelNumber = 2;            // channel
99
    chConfig.preambleCode = 4;             // preambleCode
100
    chConfig.pulseRepFreq = DWT_PRF_16M;   // prf
101
    chConfig.dataRate = DWT_BR_6M8;        // datarate
102
    chConfig.preambleLen = DWT_PLEN_128;   // preambleLength
103
    chConfig.pacSize = DWT_PAC8;           // pacSize
104
    chConfig.nsSFD = 0;                    // non-standard SFD
105
    chConfig.sfdTO = (129 + 8 - 8);        // SFD timeout
106
107
    sfConfig_t sfConfig;
108
    sfConfig.slotDuration_ms = (10);        //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
109
                                            //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
110
    sfConfig.numSlots = (10);               //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging),
111
    sfConfig.sfPeriod_ms = (10*10);         //in ms => 100 ms frame means 10 Hz location rate
112
    sfConfig.tagPeriod_ms = (10*10);        //tag period in ms (sleep time + ranging time)
113
    sfConfig.pollTxToFinalTxDly_us = (2500); //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
114
115
    //TODO Disable EXTI IRQ
116
    //port_DisableEXT_IRQ();
117
118
    // inittestapplication
119
    // dwt_softreset(); // already done in instance_init()
120
121
    // Set this instance mode (tag/anchor)
122
    (void) instance_init(TAG, (DW1000Driver*) ut->data);
123
    //int err = instance_init(TAG, (DW1000Driver*) ut->data);
124
    (void) instance_readdeviceid();
125
    //uint32_t deca_dev_id = instance_readdeviceid();
126
127
    // TAG ID 0
128
    instance_set_16bit_address(0);
129
    // simulate DECA config Mode 2 (DIP 1100000)
130
    instance_config(&chConfig, &sfConfig) ;
131
132
    //TODO Enable EXTI IRQ
133
    //port_EnableEXT_IRQ();
134
135
    // Start Ranging
136
137
    chprintf(stream, "start ranging...\n");
138
139
140
    while(1) {
141
        //int n = 0;
142
        instance_data_t* inst = instance_get_local_structure_ptr(0);
143
144
        int monitor_local = inst->monitor ;
145
        int txdiff = (chVTGetSystemTimeX() - inst->timeofTx);
146
147
        tag_run();
148
        //if delayed TX scheduled but did not happen after expected time then it has failed... (has to be < slot period)
149
        //if anchor just go into RX and wait for next message from tags/anchors
150
        //if tag handle as a timeout
151
        if( (monitor_local == 1) && ( txdiff > inst->slotDuration_ms) )  {
152
            inst->wait4ack = 0;
153
            tag_process_rx_timeout(inst);
154
            inst->monitor = 0;
155
        }
156
    }
157
158
    (void) instance_newrange();
159
    //int rx = instance_newrange();
160
161
    return result;
162
}
163
164
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_DW1000) */