Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (5.049 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
#include <aos_debug.h>
24
#include <chprintf.h>
25
#include <aos_thread.h>
26
// No unit testing! -> Contains the Deca Demo Application
27
#include <deca_instance.h>
28
#include <alld_dw1000.h>
29
#include <alld_dw1000_regs.h>
30
#include <math.h>
31
32
33
aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut) {
34
35
    aosDbgCheck(ut->data != NULL);
36
37
    aos_utresult_t result = {0, 0};
38
39
    chprintf(stream, "init DW1000...\n");
40
    dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
41
    chprintf(stream, "device ID should be: 0xDECA0130\nget device ID...\n");
42
    uint32_t actual_deviceId = dwt_readdevid();
43
    chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId);
44
    aosThdMSleep(1);
45
46
    if (actual_deviceId == DWT_DEVICE_ID){
47
      aosUtPassed(stream, &result);
48
    } else {
49
      aosUtFailed(stream, &result);
50
    }
51
52
    /*chprintf(stream, "write-read test...\n");
53
    uint32_t testvalue = 0x0A;
54
    uint16_t panid = 0x00;
55

56
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
57
    chprintf(stream, "value PANADR register before write: %x\n", panid);
58
    chprintf(stream, "write 0x%x to PANADR register...\n", testvalue);
59
    dwt_setpanid(testvalue);
60
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
61

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

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