Revision 8588411e

View differences:

unittests/periphery-lld/inc/ut_alld_DW1000_v0.h
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
#ifndef AMIROOS_UT_ALLD_DW1000_V0_H
20
#define AMIROOS_UT_ALLD_DW1000_V0_H
21

  
22
#include <amiroos.h>
23

  
24
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0)) || defined(__DOXYGEN__)
25

  
26
#include <alld_DW1000.h>
27

  
28
/******************************************************************************/
29
/* CONSTANTS                                                                  */
30
/******************************************************************************/
31

  
32
/******************************************************************************/
33
/* SETTINGS                                                                   */
34
/******************************************************************************/
35

  
36
/******************************************************************************/
37
/* CHECKS                                                                     */
38
/******************************************************************************/
39

  
40
/******************************************************************************/
41
/* DATA STRUCTURES AND TYPES                                                  */
42
/******************************************************************************/
43

  
44
/******************************************************************************/
45
/* MACROS                                                                     */
46
/******************************************************************************/
47

  
48
/******************************************************************************/
49
/* EXTERN DECLARATIONS                                                        */
50
/******************************************************************************/
51

  
52
#if defined(__cplusplus)
53
extern "C" {
54
#endif /* defined(__cplusplus) */
55
  aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut);
56
#if defined(__cplusplus)
57
}
58
#endif /* defined(__cplusplus) */
59

  
60
/******************************************************************************/
61
/* INLINE FUNCTIONS                                                           */
62
/******************************************************************************/
63

  
64
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0) */
65

  
66
#endif /* AMIROOS_UT_ALLD_DW1000_V0_H */
unittests/periphery-lld/inc/ut_alld_DW1000_v1.h
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
#ifndef AMIROOS_UT_ALLD_DW1000_V1_H
20
#define AMIROOS_UT_ALLD_DW1000_V1_H
21

  
22
#include <amiroos.h>
23

  
24
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0)) || defined(__DOXYGEN__)
25

  
26
#include <alld_DW1000.h>
27

  
28
/******************************************************************************/
29
/* CONSTANTS                                                                  */
30
/******************************************************************************/
31

  
32
/******************************************************************************/
33
/* SETTINGS                                                                   */
34
/******************************************************************************/
35

  
36
/******************************************************************************/
37
/* CHECKS                                                                     */
38
/******************************************************************************/
39

  
40
/******************************************************************************/
41
/* DATA STRUCTURES AND TYPES                                                  */
42
/******************************************************************************/
43

  
44
/******************************************************************************/
45
/* MACROS                                                                     */
46
/******************************************************************************/
47

  
48
/******************************************************************************/
49
/* EXTERN DECLARATIONS                                                        */
50
/******************************************************************************/
51

  
52
#if defined(__cplusplus)
53
extern "C" {
54
#endif /* defined(__cplusplus) */
55
  aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut);
56
#if defined(__cplusplus)
57
}
58
#endif /* defined(__cplusplus) */
59

  
60
/******************************************************************************/
61
/* INLINE FUNCTIONS                                                           */
62
/******************************************************************************/
63

  
64
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0) */
65

  
66
#endif /* AMIROOS_UT_ALLD_DW1000_V1_H */
unittests/periphery-lld/src/ut_alld_DW1000_v0.c
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 <amiroos.h>
20
#include <ut_alld_DW1000_v0.h>
21

  
22
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0)) || defined(__DOXYGEN__)
23

  
24
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27

  
28
/******************************************************************************/
29
/* EXPORTED VARIABLES                                                         */
30
/******************************************************************************/
31

  
32
/******************************************************************************/
33
/* LOCAL TYPES                                                                */
34
/******************************************************************************/
35

  
36
/******************************************************************************/
37
/* LOCAL VARIABLES                                                            */
38
/******************************************************************************/
39

  
40
/******************************************************************************/
41
/* LOCAL FUNCTIONS                                                            */
42
/******************************************************************************/
43

  
44
/******************************************************************************/
45
/* EXPORTED FUNCTIONS                                                         */
46
/******************************************************************************/
47

  
48
aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut) {
49

  
50
    aosDbgCheck(ut->data != NULL);
51

  
52
    aos_utresult_t result = {0, 0};
53

  
54
    chprintf(stream, "init DW1000...\n");
55
    dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
56
    chprintf(stream, "device ID should be: 0xDECA0130\nget device ID...\n");
57
    uint32_t actual_deviceId = dwt_readdevid();
58
    chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId);
59
    aosThdMSleep(1);
60

  
61
    if (actual_deviceId == DWT_DEVICE_ID){
62
      aosUtPassed(stream, &result);
63
    } else {
64
      aosUtFailed(stream, &result);
65
    }
66

  
67
    /*chprintf(stream, "write-read test...\n");
68
    uint32_t testvalue = 0x0A;
69
    uint16_t panid = 0x00;
70

  
71
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
72
    chprintf(stream, "value PANADR register before write: %x\n", panid);
73
    chprintf(stream, "write 0x%x to PANADR register...\n", testvalue);
74
    dwt_setpanid(testvalue);
75
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
76

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

  
79
    if (panid == testvalue){
80
      aosUtPassed(stream, &result);
81
    } else {
82
      aosUtFailed(stream, &result);
83
    }
84
*/
85

  
86
    dwt_setleds(0x03);
87

  
88
    // RUN DECA-DEMO
89

  
90
    instanceConfig_t chConfig;
91
    chConfig.channelNumber = 2;            // channel
92
    chConfig.preambleCode = 4;             // preambleCode
93
    chConfig.pulseRepFreq = DWT_PRF_16M;   // prf
94
    chConfig.dataRate = DWT_BR_6M8;        // datarate
95
    chConfig.preambleLen = DWT_PLEN_128;   // preambleLength
96
    chConfig.pacSize = DWT_PAC8;           // pacSize
97
    chConfig.nsSFD = 0;                    // non-standard SFD
98
    chConfig.sfdTO = (129 + 8 - 8);        // SFD timeout
99

  
100
    sfConfig_t sfConfig;
101
    sfConfig.slotDuration_ms = (10);        //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
102
                                            //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
103
    sfConfig.numSlots = (10);               //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging),
104
    sfConfig.sfPeriod_ms = (10*10);         //in ms => 100 ms frame means 10 Hz location rate
105
    sfConfig.tagPeriod_ms = (10*10);        //tag period in ms (sleep time + ranging time)
106
    sfConfig.pollTxToFinalTxDly_us = (2500); //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
107

  
108
    //TODO Disable EXTI IRQ
109
    //port_DisableEXT_IRQ();
110

  
111
    // inittestapplication
112
    // dwt_softreset(); // already done in instance_init()
113

  
114
    // Set this instance mode (tag/anchor)
115
    (void) instance_init(TAG, (DW1000Driver*) ut->data);
116
    //int err = instance_init(TAG, (DW1000Driver*) ut->data);
117
    (void) instance_readdeviceid();
118
    //uint32_t deca_dev_id = instance_readdeviceid();
119

  
120
    // TAG ID 0
121
    instance_set_16bit_address(0);
122
    // simulate DECA config Mode 2 (DIP 1100000)
123
    instance_config(&chConfig, &sfConfig) ;
124

  
125
    //TODO Enable EXTI IRQ
126
    //port_EnableEXT_IRQ();
127

  
128
    // Start Ranging
129

  
130
    chprintf(stream, "start ranging...\n");
131

  
132

  
133
    while(1) {
134
        //int n = 0;
135
        instance_data_t* inst = instance_get_local_structure_ptr(0);
136

  
137
        int monitor_local = inst->monitor ;
138
        int txdiff = (chVTGetSystemTimeX() - inst->timeofTx);
139

  
140
        tag_run();
141
        //if delayed TX scheduled but did not happen after expected time then it has failed... (has to be < slot period)
142
        //if anchor just go into RX and wait for next message from tags/anchors
143
        //if tag handle as a timeout
144
        if( (monitor_local == 1) && ( txdiff > inst->slotDuration_ms) )  {
145
            inst->wait4ack = 0;
146
            tag_process_rx_timeout(inst);
147
            inst->monitor = 0;
148
        }
149
    }
150

  
151
    (void) instance_newrange();
152
    //int rx = instance_newrange();
153

  
154
    return result;
155
}
156

  
157
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0) */
unittests/periphery-lld/src/ut_alld_DW1000_v1.c
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 <amiroos.h>
20
#include <ut_alld_DW1000_v1.h>
21

  
22
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0)) || defined(__DOXYGEN__)
23

  
24
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27

  
28
/******************************************************************************/
29
/* EXPORTED VARIABLES                                                         */
30
/******************************************************************************/
31

  
32
/******************************************************************************/
33
/* LOCAL TYPES                                                                */
34
/******************************************************************************/
35

  
36
/******************************************************************************/
37
/* LOCAL VARIABLES                                                            */
38
/******************************************************************************/
39

  
40
/******************************************************************************/
41
/* LOCAL FUNCTIONS                                                            */
42
/******************************************************************************/
43

  
44
/******************************************************************************/
45
/* EXPORTED FUNCTIONS                                                         */
46
/******************************************************************************/
47

  
48
aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut) {
49

  
50
    aosDbgCheck(ut->data != NULL);
51

  
52
    aos_utresult_t result = {0, 0};
53

  
54
    chprintf(stream, "init DW1000...\n");
55
    dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
56
    chprintf(stream, "device ID should be: 0xDECA0130\nget device ID...\n");
57
    uint32_t actual_deviceId = dwt_readdevid();
58
    chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId);
59
    aosThdMSleep(1);
60

  
61
    if (actual_deviceId == DWT_DEVICE_ID){
62
      aosUtPassed(stream, &result);
63
    } else {
64
      aosUtFailed(stream, &result);
65
    }
66

  
67
    /*chprintf(stream, "write-read test...\n");
68
    uint32_t testvalue = 0x0A;
69
    uint16_t panid = 0x00;
70

  
71
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
72
    chprintf(stream, "value PANADR register before write: %x\n", panid);
73
    chprintf(stream, "write 0x%x to PANADR register...\n", testvalue);
74
    dwt_setpanid(testvalue);
75
    dwt_readfromdevice(PANADR_ID, PANADR_PAN_ID_OFFSET, 2, (uint8_t*) &panid);
76

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

  
79
    if (panid == testvalue){
80
      aosUtPassed(stream, &result);
81
    } else {
82
      aosUtFailed(stream, &result);
83
    }
84
*/
85

  
86
    dwt_setleds(0x03);
87

  
88
    // RUN DECA-DEMO
89

  
90
    instanceConfig_t chConfig;
91
    chConfig.channelNumber = 2;            // channel
92
    chConfig.preambleCode = 4;             // preambleCode
93
    chConfig.pulseRepFreq = DWT_PRF_16M;   // prf
94
    chConfig.dataRate = DWT_BR_6M8;        // datarate
95
    chConfig.preambleLen = DWT_PLEN_128;   // preambleLength
96
    chConfig.pacSize = DWT_PAC8;           // pacSize
97
    chConfig.nsSFD = 0;                    // non-standard SFD
98
    chConfig.sfdTO = (129 + 8 - 8);        // SFD timeout
99

  
100
    sfConfig_t sfConfig;
101
    sfConfig.slotDuration_ms = (10);        //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
102
                                            //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
103
    sfConfig.numSlots = (10);               //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging),
104
    sfConfig.sfPeriod_ms = (10*10);         //in ms => 100 ms frame means 10 Hz location rate
105
    sfConfig.tagPeriod_ms = (10*10);        //tag period in ms (sleep time + ranging time)
106
    sfConfig.pollTxToFinalTxDly_us = (2500); //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
107

  
108
    //TODO Disable EXTI IRQ
109
    //port_DisableEXT_IRQ();
110

  
111
    // inittestapplication
112
    // dwt_softreset(); // already done in instance_init()
113

  
114
    // Set this instance mode (tag/anchor)
115
    (void) instance_init(TAG, (DW1000Driver*) ut->data);
116
    //int err = instance_init(TAG, (DW1000Driver*) ut->data);
117
    (void) instance_readdeviceid();
118
    //uint32_t deca_dev_id = instance_readdeviceid();
119

  
120
    // TAG ID 0
121
    instance_set_16bit_address(0);
122
    // simulate DECA config Mode 2 (DIP 1100000)
123
    instance_config(&chConfig, &sfConfig) ;
124

  
125
    //TODO Enable EXTI IRQ
126
    //port_EnableEXT_IRQ();
127

  
128
    // Start Ranging
129

  
130
    chprintf(stream, "start ranging...\n");
131

  
132

  
133
    while(1) {
134
        //int n = 0;
135
        instance_data_t* inst = instance_get_local_structure_ptr(0);
136

  
137
        int monitor_local = inst->monitor ;
138
        int txdiff = (chVTGetSystemTimeX() - inst->timeofTx);
139

  
140
        tag_run();
141
        //if delayed TX scheduled but did not happen after expected time then it has failed... (has to be < slot period)
142
        //if anchor just go into RX and wait for next message from tags/anchors
143
        //if tag handle as a timeout
144
        if( (monitor_local == 1) && ( txdiff > inst->slotDuration_ms) )  {
145
            inst->wait4ack = 0;
146
            tag_process_rx_timeout(inst);
147
            inst->monitor = 0;
148
        }
149
    }
150

  
151
    (void) instance_newrange();
152
    //int rx = instance_newrange();
153

  
154
    return result;
155
}
156

  
157
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0) */

Also available in: Unified diff