-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_barraled_TX.cpp
198 lines (163 loc) · 5.47 KB
/
test_barraled_TX.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* File: main.cpp
* Author: Silvano
*
* Created on 2 marzo 2015, 18.53
*
*/
#include <cstdlib>
#include <cstdio>
#include <miosix.h>
#include <miosix/util/util.h>
#include "drivers/cc2520.h"
#include "drivers/frame.h"
#include "drivers/HW_mapping.h"
#include "drivers/SPI.h"
#include "drivers/BarraLed.h"
#include "drivers/fast_trigger.h"
#include "drivers/leds.h"
using namespace std;
// using namespace miosix;
typedef miosix::Gpio<GPIOB_BASE,0> rx_irq;
typedef miosix::Gpio<GPIOB_BASE,9> trigger_1;
/* control pins for transceiver 2 */
typedef miosix::Gpio<GPIOC_BASE,10> reset_2;
typedef miosix::Gpio<GPIOC_BASE,11> vreg_2;
typedef miosix::Gpio<GPIOA_BASE,12> trigger_2;
typedef miosix::Gpio<GPIOC_BASE,5> cs_2;
/* control pins for transceiver 3 */
typedef miosix::Gpio<GPIOC_BASE,0> reset_3;
typedef miosix::Gpio<GPIOC_BASE,1> vreg_3;
typedef miosix::Gpio<GPIOC_BASE,2> trigger_3;
typedef miosix::Gpio<GPIOC_BASE,3> cs_3;
template<typename T>
void sendBarraLed(Cc2520& cc2520_1, Cc2520& cc2520_2, Cc2520& cc2520_3,
unsigned char id, int skew, int power)
{
iprintf("skew=%d power=%d\n",skew,power);
for(int i=0;i<4;i++)
{
const unsigned char pkt[]={id,id,id,id};
cc2520_1.writeFrame(sizeof(pkt),pkt);
miosix::memDump(pkt,sizeof(pkt));
trigger_1::high();
miosix::Thread::sleep(1);
trigger_1::low();
while(!cc2520_1.isTxFrameDone()) ;
cc2520_1.isSFDRaised();
miosix::Thread::sleep(500);
}
T *pkt_1=new T;
T *pkt_2=new T;
T *pkt_i=new T;
pkt_1->encode(pkt_1->getPacketSize()-2); //The packets differ by 4 nibbles
pkt_2->encode(pkt_2->getPacketSize()+2);
pkt_i->encode(pkt_i->getPacketSize()/2);
for(int i=0;i<40;i++)
{
led1::high();
switch(power)
{
case 1:
cc2520_3.setTxPower(Cc2520::P_m18);
break;
case 2:
cc2520_3.setTxPower(Cc2520::P_m7);
break;
case 3:
cc2520_3.setTxPower(Cc2520::P_m2);
break;
}
cc2520_1.writeFrame(pkt_1->getPacketSize(),pkt_1->getPacket());
cc2520_2.writeFrame(pkt_2->getPacketSize(),pkt_2->getPacket());
if(power>0) cc2520_3.writeFrame(pkt_i->getPacketSize(),pkt_i->getPacket());
miosix::memDump(pkt_1->getPacket(), pkt_1->getPacketSize());
miosix::memDump(pkt_2->getPacket(), pkt_2->getPacketSize());
if(power>0) miosix::memDump(pkt_i->getPacket(), pkt_i->getPacketSize());
// skew : time skew in ns
// 0 : 83ns
// 1 : 166ns
// 2 : 333ns
// 3 : 624ns
if(skew == 0)
{
miosix::FastInterruptDisableLock lock;
trigger_80ns();
if(power>0) trigger_3::high();
} else {
miosix::FastInterruptDisableLock lock;
switch(skew){
case 1:
trigger_160ns();
break;
case 2:
trigger_320ns();
break;
case 3:
trigger_640ns();
break;
}
if(power>0) trigger_3::high();
}
miosix::Thread::sleep(1);
trigger_1::low();
trigger_2::low();
if(power>0) trigger_3::low();
if(power>0)
{
while(!cc2520_1.isTxFrameDone() || !cc2520_2.isTxFrameDone()
|| !cc2520_3.isTxFrameDone());
} else {
while(!cc2520_1.isTxFrameDone() || !cc2520_2.isTxFrameDone());
}
cc2520_1.isSFDRaised();
cc2520_2.isSFDRaised();
if(power>0) cc2520_3.isSFDRaised();
led1::low();
miosix::Thread::sleep(500);
}
delete pkt_1;
delete pkt_2;
delete pkt_i;
}
int main(int argc, char** argv)
{
led1::mode(miosix::Mode::OUTPUT);
led2::mode(miosix::Mode::OUTPUT);
trigger_1::mode(miosix::Mode::OUTPUT);
trigger_1::low();
trigger_2::mode(miosix::Mode::OUTPUT);
trigger_2::low();
trigger_3::mode(miosix::Mode::OUTPUT);
trigger_3::low();
SPI spi;
Cc2520 cc2520_1(spi, cc2520::cs::getPin(), cc2520::reset::getPin(), cc2520::vreg::getPin());
Cc2520 cc2520_2(spi, cs_2::getPin(), reset_2::getPin(), vreg_2::getPin());
Cc2520 cc2520_3(spi, cs_3::getPin(), reset_3::getPin(), vreg_3::getPin());
cc2520_1.setFrequency(2450);
cc2520_1.setMode(Cc2520::TX);
cc2520_1.setAutoFCS(false);
cc2520_2.setFrequency(2450);
cc2520_2.setMode(Cc2520::TX);
cc2520_2.setAutoFCS(false);
cc2520_3.setFrequency(2450);
cc2520_3.setMode(Cc2520::TX);
cc2520_3.setAutoFCS(false);
for(;;)
{
for(int j=0;j<4;j++)
{
for(int i=0;i<4;i++)
{
//meaning of id parameter to sendBarraLed
// 00000000
// |||||+++-- skew
// ||+++----- power of inteferer
// ++-------- 0=16 byte packets, 1=64 byte, 2=128 byte
sendBarraLed<packet16>(cc2520_1,cc2520_2,cc2520_3,0x00 | j<<3 | i,i,j);
sendBarraLed<packet64>(cc2520_1,cc2520_2,cc2520_3,0x40 | j<<3 | i,i,j);
sendBarraLed<packet127>(cc2520_1,cc2520_2,cc2520_3,0x80 | j<<3 | i,i,j);
}
}
}
}