1 | /*! \file debugMac.c |
---|
2 | \brief Top-level debug "MAC" for testing PHY/MAC builds between reference design releases |
---|
3 | |
---|
4 | @version 10 |
---|
5 | @author Chris Hunter |
---|
6 | |
---|
7 | Doesn't actually implement a MAC, and traffic only flows one direction. This is used for testing/debugging low-level PHY and WARPMAC changes. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "warpmac.h" |
---|
11 | #include "warpphy.h" |
---|
12 | #include "debugMac.h" |
---|
13 | #include "xparameters.h" |
---|
14 | #include "string.h" |
---|
15 | #include "errno.h" |
---|
16 | #include "stdlib.h" |
---|
17 | #include "stdio.h" |
---|
18 | #include "warp_userioboard_util.h" |
---|
19 | |
---|
20 | //Lower level includes, for debug/development |
---|
21 | #include "ofdm_txrx_mimo_regMacros.h" |
---|
22 | #include "ofdm_agc_mimo_regMacros.h" |
---|
23 | #include "warp_timer_regMacros.h" |
---|
24 | #include "EEPROM.h" |
---|
25 | #include "radio_controller_basic.h" |
---|
26 | #include "radio_controller_ext.h" |
---|
27 | #include "radio_controller_adv.h" |
---|
28 | #include "radio_controller_5ghz.h" |
---|
29 | #include "ascii_characters.h" |
---|
30 | #include "xgpio.h" |
---|
31 | |
---|
32 | |
---|
33 | unsigned char chan; |
---|
34 | unsigned char dacGain_coarse; |
---|
35 | unsigned int dacGain_fine; |
---|
36 | unsigned char agcPrintMode; |
---|
37 | unsigned int pktCount; |
---|
38 | unsigned int agcGains; |
---|
39 | unsigned int pktFullRate; |
---|
40 | unsigned int pktCodeRate; |
---|
41 | unsigned char TxGainBB; |
---|
42 | unsigned char TxGainRF; |
---|
43 | unsigned char fftScaling_Rx_1; |
---|
44 | unsigned char fftScaling_Rx_2; |
---|
45 | unsigned char fftScaling_Rx_3; |
---|
46 | unsigned char fftScaling_Tx_1; |
---|
47 | unsigned char fftScaling_Tx_2; |
---|
48 | unsigned char fftScaling_Tx_3; |
---|
49 | unsigned char agc_coarseThresh_1; |
---|
50 | unsigned char agc_coarseThresh_2; |
---|
51 | unsigned char agc_coarseThresh_3; |
---|
52 | unsigned char updateFFTscaling; |
---|
53 | unsigned char updateAGCthresh; |
---|
54 | unsigned char userIOBoard_LEDs; |
---|
55 | unsigned char charsToPrint[16]; |
---|
56 | unsigned char pktDetMask; |
---|
57 | |
---|
58 | unsigned short radReg9; |
---|
59 | unsigned char updateRadReg9, txBBGain, txUpconvLin, txVGALin; |
---|
60 | |
---|
61 | unsigned int pktDet_rssi; |
---|
62 | |
---|
63 | unsigned int pktCount_good, pktCount_bad; |
---|
64 | |
---|
65 | unsigned int txScaling_preamble, txScaling_payload; |
---|
66 | unsigned int pktDet_thresh, cs_thresh; |
---|
67 | |
---|
68 | ///Buffer to hold received packet |
---|
69 | Macframe rxBuffer; |
---|
70 | |
---|
71 | void left(); |
---|
72 | void right(); |
---|
73 | void up(); |
---|
74 | void middle(); |
---|
75 | |
---|
76 | ///@brief Callback for the reception of Ethernet packets |
---|
77 | /// |
---|
78 | ///This function is called by the ethernet MAC drivers |
---|
79 | ///when a packet is available to send. This function fills |
---|
80 | ///the Macframe transmit buffer with the packet and sends |
---|
81 | ///it over the OFDM link |
---|
82 | ///@param length Length, in bytes, of received Ethernet frame |
---|
83 | ///@param payload address of first byte in Ethernet payload. |
---|
84 | void emacRx_callback(Xuint32 length, char* payload){ |
---|
85 | |
---|
86 | //Pseudocode for workshop users: |
---|
87 | //1) Instantiate a "Macframe" to hold a packet header |
---|
88 | //2) Copy the "length" of the received Ethernet frame (argument of this function) into the appropriate field of the "phyHeader" in the "Macframe" |
---|
89 | //3) Set the "fullRate" field of the "phyHeader" in the "Macframe" to "QPSK" |
---|
90 | //4) Copy the header over the packet buffer 1 using the "warpmac_prepPhyForXmit" function. |
---|
91 | //5) Send the contents of packet buffer 1 by using the "warpmac_startPhyXmit" function. |
---|
92 | //6) Wait for the PHY transmitter to finish and enable the receiver by using the "warpmac_finishPhyXmit" function. |
---|
93 | |
---|
94 | //Note: You may be wondering why the act of transmitting is broken up into three function calls (4,5,6 of pseudocode above). |
---|
95 | //In this simple exercise, it seems a bit unnecessary. However, the reason for this division will become clear in later labs. |
---|
96 | |
---|
97 | /**********************DELETE FOR WORKSHOP***************************/ |
---|
98 | //Buffer for holding a packet-to-xmit |
---|
99 | Macframe txBuffer; |
---|
100 | //Set the length field in the header |
---|
101 | txBuffer.header.length = length; |
---|
102 | //Set the modulation scheme for the packet's full-rate symbols |
---|
103 | txBuffer.header.fullRate = pktFullRate; |
---|
104 | txBuffer.header.codeRate = pktCodeRate; |
---|
105 | //Copy the header over to packet buffer 1 |
---|
106 | warpmac_prepPhyForXmit(&txBuffer,1); |
---|
107 | //Send packet buffer 1 |
---|
108 | warpmac_startPhyXmit(1); |
---|
109 | //Wait for it to finish and enable the receiver |
---|
110 | warpmac_finishPhyXmit(); |
---|
111 | /**********************DELETE FOR WORKSHOP***************************/ |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | ///@brief Callback for the reception of bad wireless headers |
---|
116 | /// |
---|
117 | ///@param packet Pointer to received Macframe |
---|
118 | void phyRx_badHeader_callback() { |
---|
119 | warpmac_incrementLEDLow(); |
---|
120 | pktCount++; |
---|
121 | // if(pktCount%250 == 0 & agcPrintMode) |
---|
122 | if(agcPrintMode) |
---|
123 | { |
---|
124 | agcGains = ofdm_AGC_GetGains(); |
---|
125 | pktDet_rssi = ofdm_txrx_mimo_ReadReg_Rx_PktDet_midPktRSSI_antA(); |
---|
126 | xil_printf("(bad)\tAGC Gains: %d %d\t%d %d\t", agcGains&0x3, (agcGains>>2)&0x1F, (agcGains>>8)&0x3, (agcGains>>10)&0x1F); |
---|
127 | xil_printf("AGC Thresholds: %d / %d / %d\t", (0xFFFFFF00 | agc_coarseThresh_1), (0xFFFFFF00 | agc_coarseThresh_2), (0xFFFFFF00 | agc_coarseThresh_3) ); |
---|
128 | xil_printf("RSSI (ant A): %d\r\n", pktDet_rssi); |
---|
129 | } |
---|
130 | |
---|
131 | userIOBoard_LEDs = userIOBoard_LEDs==0x80 ? 0x01 : (userIOBoard_LEDs << 1); |
---|
132 | warp_userioboard_set_leds(userIOBoard_LEDs); |
---|
133 | |
---|
134 | pktCount_bad++; |
---|
135 | } |
---|
136 | |
---|
137 | ///@brief Callback for the reception of good wireless headers |
---|
138 | /// |
---|
139 | ///This function then polls the PHY to determine if the entire packet passes checksum |
---|
140 | ///thereby triggering the transmission of the received data over Ethernet. |
---|
141 | ///@param packet Pointer to received Macframe |
---|
142 | void phyRx_goodHeader_callback(Macframe* packet){ |
---|
143 | |
---|
144 | /**********************DELETE FOR WORKSHOP***************************/ |
---|
145 | unsigned char state=INCOMPLETE; |
---|
146 | while(state==INCOMPLETE){ |
---|
147 | //Blocks until the PHY reports the received packet as either good or bad |
---|
148 | state = mimo_ofdmRx_getPayloadStatus(); |
---|
149 | } |
---|
150 | |
---|
151 | pktCount++; |
---|
152 | if(pktCount%250 == 0 & agcPrintMode) |
---|
153 | { |
---|
154 | agcGains = ofdm_AGC_GetGains(); |
---|
155 | pktDet_rssi = ofdm_txrx_mimo_ReadReg_Rx_PktDet_midPktRSSI_antA(); |
---|
156 | xil_printf("(good)\tAGC Gains: %d %d\t%d %d\t", agcGains&0x3, (agcGains>>2)&0x1F, (agcGains>>8)&0x3, (agcGains>>10)&0x1F); |
---|
157 | xil_printf("AGC Thresholds: %d / %d / %d\t", (0xFFFFFF00 | agc_coarseThresh_1), (0xFFFFFF00 | agc_coarseThresh_2), (0xFFFFFF00 | agc_coarseThresh_3) ); |
---|
158 | xil_printf("RSSI (ant A): %d\r\n", pktDet_rssi); |
---|
159 | } |
---|
160 | |
---|
161 | if(state&GOOD){ |
---|
162 | warpmac_incrementLEDHigh(); |
---|
163 | //Starts the DMA transfer of the payload into the EMAC |
---|
164 | // warpmac_prepEmacForXmit(packet); |
---|
165 | //Waits until the DMA transfer is complete, then starts the EMAC |
---|
166 | // warpmac_startEmacXmit(packet); |
---|
167 | |
---|
168 | userIOBoard_LEDs = userIOBoard_LEDs==0x01 ? 0x80 : (userIOBoard_LEDs >> 1); |
---|
169 | warp_userioboard_set_leds(userIOBoard_LEDs); |
---|
170 | |
---|
171 | pktCount_good++; |
---|
172 | } |
---|
173 | |
---|
174 | if(state&BAD){ |
---|
175 | //Bad packet, but good header |
---|
176 | warpmac_incrementLEDLow(); |
---|
177 | } |
---|
178 | /**********************DELETE FOR WORKSHOP***************************/ |
---|
179 | } |
---|
180 | void getByte(unsigned char uartByte) |
---|
181 | { |
---|
182 | if(uartByte != 0x0) |
---|
183 | { |
---|
184 | xil_printf("(%c)\t", uartByte); |
---|
185 | |
---|
186 | if(uartByte==ASCII_Z) { |
---|
187 | //Enable Alamouti mode |
---|
188 | mimo_ofdmRx_setOptions(mimo_ofdmRx_getOptions() & (~RX_SISO_MODE), DEFAULT_STATUSBITS); |
---|
189 | mimo_ofdmRx_setOptions(mimo_ofdmRx_getOptions() | RX_ALAMOUTI_MODE, DEFAULT_STATUSBITS); |
---|
190 | mimo_ofdmTx_setControlBits(mimo_ofdmTx_getOptions() & (~TX_SISO_MODE)); |
---|
191 | mimo_ofdmTx_setControlBits(mimo_ofdmTx_getOptions() | TX_ALAMOUTI_MODE); |
---|
192 | mimo_ofdmRx_setRxScaling(0x08000800); |
---|
193 | |
---|
194 | xil_printf("Enabled Alamouti\r\n"); |
---|
195 | } |
---|
196 | if(uartByte==ASCII_z) { |
---|
197 | //Disable Alamouti mode |
---|
198 | mimo_ofdmRx_setOptions(mimo_ofdmRx_getOptions() & (~RX_ALAMOUTI_MODE), DEFAULT_STATUSBITS); |
---|
199 | mimo_ofdmRx_setOptions(mimo_ofdmRx_getOptions() | RX_SISO_MODE, DEFAULT_STATUSBITS); |
---|
200 | mimo_ofdmTx_setControlBits(mimo_ofdmTx_getOptions() & (~TX_ALAMOUTI_MODE)); |
---|
201 | mimo_ofdmTx_setControlBits(mimo_ofdmTx_getOptions() | TX_SISO_MODE); |
---|
202 | mimo_ofdmRx_setRxScaling(0x10001000); |
---|
203 | |
---|
204 | xil_printf("Disabled Alamouti\r\n"); |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | if(uartByte==ASCII_T) {warpphy_set_B_KPPlus(0x20000);} |
---|
209 | if(uartByte==ASCII_t) {warpphy_set_B_KPMinus(0x20000);} |
---|
210 | if(uartByte==ASCII_G) {warpphy_set_B_KIPlus(0x100);} |
---|
211 | if(uartByte==ASCII_g) {warpphy_set_B_KIMinus(0x100);} |
---|
212 | |
---|
213 | if(uartByte==ASCII_P) {mimo_ofdmRx_setPNTrack_K(0x2700000); xil_printf("Enabled PN tracking\r\n");} |
---|
214 | if(uartByte==ASCII_p) {mimo_ofdmRx_setPNTrack_K(0); xil_printf("Disabled PN tracking\r\n");} |
---|
215 | |
---|
216 | if(uartByte==ASCII_C) {mimo_ofdmRx_setOptions(mimo_ofdmRx_getOptions() | COARSE_CFO_EN, DEFAULT_STATUSBITS); xil_printf("Enabled coarse CFO\r\n");} |
---|
217 | if(uartByte==ASCII_c) {mimo_ofdmRx_setOptions(mimo_ofdmRx_getOptions() & ~COARSE_CFO_EN, DEFAULT_STATUSBITS); xil_printf("Disabled coarse CFO\r\n");} |
---|
218 | |
---|
219 | if(uartByte==ASCII_A) warpphy_setTargetPlus(); |
---|
220 | if(uartByte==ASCII_a) warpphy_setTargetMinus(); |
---|
221 | |
---|
222 | if(uartByte==ASCII_N) warpphy_setNoiseTargetPlus(); |
---|
223 | if(uartByte==ASCII_n) warpphy_setNoiseTargetMinus(); |
---|
224 | |
---|
225 | if(uartByte==ASCII_s) {agcPrintMode = agcPrintMode^1; if(agcPrintMode) xil_printf("Enabled AGC print mode\r\n"); else xil_printf("Disabled AGC print mode\r\n");} |
---|
226 | |
---|
227 | if(uartByte==ASCII_u) {txUpconvLin = (txUpconvLin + 1)%4; updateRadReg9 = 1;} |
---|
228 | if(uartByte==ASCII_i) {txVGALin = (txVGALin + 1)%4; updateRadReg9 = 1;} |
---|
229 | if(uartByte==ASCII_o) {txBBGain = (txBBGain + 1)%4; updateRadReg9 = 1;} |
---|
230 | |
---|
231 | if(updateRadReg9) |
---|
232 | { |
---|
233 | radReg9 = (0x9) + (txBBGain << 4) + (txUpconvLin << 6) + (txVGALin << 10); |
---|
234 | transmit(radReg9); xil_printf("RadReg 9: bbG: %d, UpLin: %d, VGALin: %d\r\n", txBBGain, txUpconvLin, txVGALin); |
---|
235 | updateRadReg9 = 0; |
---|
236 | } |
---|
237 | |
---|
238 | if(uartByte==ASCII_m) {transmit(((0x0003<<4)+0x0009)); xil_printf("Set min Tx linearity\r\n");} |
---|
239 | if(uartByte==ASCII_M) {transmit(((0x03CF<<4)+0x0009)); xil_printf("Set max Tx linearity\r\n");} |
---|
240 | |
---|
241 | if(uartByte==ASCII_L) {WarpRadio_v1_RxLpfCornFreqCoarseAdj(1, FIRST_RADIO | SECOND_RADIO); xil_printf("RxLPF = 1\r\n");} |
---|
242 | if(uartByte==ASCII_l) {WarpRadio_v1_RxLpfCornFreqCoarseAdj(0, FIRST_RADIO | SECOND_RADIO); xil_printf("RxLPF = 0\r\n");} |
---|
243 | |
---|
244 | if(uartByte==ASCII_H) {WarpRadio_v1_RxHighPassCornerFreq(1, FIRST_RADIO | SECOND_RADIO); xil_printf("RxHPF = 1\r\n");} |
---|
245 | if(uartByte==ASCII_h) {WarpRadio_v1_RxHighPassCornerFreq(0, FIRST_RADIO | SECOND_RADIO); xil_printf("RxHPF = 0\r\n");} |
---|
246 | |
---|
247 | if(uartByte==ASCII_D) {RADIO_CONTROLLER_mWriteSlaveReg1(XPAR_RADIO_CONTROLLER_0_BASEADDR, (RADIO_CONTROLLER_mReadSlaveReg1(XPAR_RADIO_CONTROLLER_0_BASEADDR) | RAD_ADC_RX_DCS_MASK)); xil_printf("ADC DCS = 1\r\n");} |
---|
248 | if(uartByte==ASCII_d) {RADIO_CONTROLLER_mWriteSlaveReg1(XPAR_RADIO_CONTROLLER_0_BASEADDR, (RADIO_CONTROLLER_mReadSlaveReg1(XPAR_RADIO_CONTROLLER_0_BASEADDR) & ~RAD_ADC_RX_DCS_MASK)); xil_printf("ADC DCS = 0\r\n");} |
---|
249 | |
---|
250 | if(uartByte==ASCII_1) {fftScaling_Rx_1 = 0x3&(fftScaling_Rx_1+1); updateFFTscaling = 1;} |
---|
251 | if(uartByte==ASCII_2) {fftScaling_Rx_2 = 0x3&(fftScaling_Rx_2+1); updateFFTscaling = 1;} |
---|
252 | if(uartByte==ASCII_3) {fftScaling_Rx_3 = 0x3&(fftScaling_Rx_3+1); updateFFTscaling = 1;} |
---|
253 | |
---|
254 | if(uartByte==ASCII_7) {fftScaling_Tx_1 = 0x3&(fftScaling_Tx_1+1); updateFFTscaling = 1;} |
---|
255 | if(uartByte==ASCII_8) {fftScaling_Tx_2 = 0x3&(fftScaling_Tx_2+1); updateFFTscaling = 1;} |
---|
256 | if(uartByte==ASCII_9) {fftScaling_Tx_3 = 0x3&(fftScaling_Tx_3+1); updateFFTscaling = 1;} |
---|
257 | |
---|
258 | if(uartByte==ASCII_4) {agc_coarseThresh_1 = 0xFF&(agc_coarseThresh_1+1); updateAGCthresh = 1;} |
---|
259 | if(uartByte==ASCII_5) {agc_coarseThresh_2 = 0xFF&(agc_coarseThresh_2+1); updateAGCthresh = 1;} |
---|
260 | if(uartByte==ASCII_6) {agc_coarseThresh_3 = 0xFF&(agc_coarseThresh_3+1); updateAGCthresh = 1;} |
---|
261 | |
---|
262 | if(uartByte==ASCII_DOLLAR) {agc_coarseThresh_1 = 0xFF&(agc_coarseThresh_1-1); updateAGCthresh = 1;} |
---|
263 | if(uartByte==ASCII_PERCENT) {agc_coarseThresh_2 = 0xFF&(agc_coarseThresh_2-1); updateAGCthresh = 1;} |
---|
264 | if(uartByte==ASCII_CARROT) {agc_coarseThresh_3 = 0xFF&(agc_coarseThresh_3-1); updateAGCthresh = 1;} |
---|
265 | |
---|
266 | if(uartByte==ASCII_f) { if(chan>1) chan--; warpphy_setChannel(GHZ_2, chan); xil_printf("Channe: %d\r\n", chan);} |
---|
267 | if(uartByte==ASCII_F) { if(chan<14) chan++; warpphy_setChannel(GHZ_2, chan); xil_printf("Channe: %d\r\n", chan);} |
---|
268 | |
---|
269 | if(uartByte==ASCII_q) {pktDet_thresh = pktDet_thresh - 100; ofdm_txrx_mimo_WriteReg_Rx_PktDet_setThresh(pktDet_thresh); xil_printf("PktDet Thresh: %d\r\n", pktDet_thresh); } |
---|
270 | if(uartByte==ASCII_Q) {pktDet_thresh = pktDet_thresh + 100; ofdm_txrx_mimo_WriteReg_Rx_PktDet_setThresh(pktDet_thresh); xil_printf("PktDet Thresh: %d\r\n", pktDet_thresh); } |
---|
271 | |
---|
272 | if(uartByte==ASCII_V) { |
---|
273 | txScaling_preamble = txScaling_preamble + 100; //Add (0.05/4) |
---|
274 | txScaling_payload = txScaling_payload + 400; //Add 0.05 |
---|
275 | mimo_ofdmTx_setTxScaling(txScaling_preamble, txScaling_payload); |
---|
276 | xil_printf("TxScaling: Pre=%d Pay=%d\r\n", txScaling_preamble, txScaling_payload); |
---|
277 | } |
---|
278 | |
---|
279 | if(uartByte==ASCII_v) { |
---|
280 | txScaling_preamble = txScaling_preamble - 100; //Subtract (0.05/4) |
---|
281 | txScaling_payload = txScaling_payload - 400; //Subtract 0.05 |
---|
282 | mimo_ofdmTx_setTxScaling(txScaling_preamble, txScaling_payload); |
---|
283 | xil_printf("TxScaling: Pre=%d Pay=%d\r\n", txScaling_preamble, txScaling_payload); |
---|
284 | } |
---|
285 | |
---|
286 | if(uartByte==ASCII_k) {ofdm_txrx_mimo_WriteReg_Rx_PktDet_setMask((pktDetMask++)%4); xil_printf("pktDetMask: %d\r\n", pktDetMask);} |
---|
287 | |
---|
288 | if(uartByte==ASCII_r) {xil_printf("Rx scaling: %x\r\n", XIo_In32(XPAR_OFDM_TXRX_MIMO_PLBW_0_MEMMAP_RX_CONSTELLATION_SCALING_W));} |
---|
289 | |
---|
290 | if(updateFFTscaling) |
---|
291 | { |
---|
292 | mimo_ofdmTxRx_setFFTScaling((unsigned int)(((16*fftScaling_Rx_1 + 4*fftScaling_Rx_2 + 1*fftScaling_Rx_3)<<6 ) | (16*fftScaling_Tx_1 + 4*fftScaling_Tx_2 + 1*fftScaling_Tx_3))); |
---|
293 | xil_printf("FFT Tx Scaling: %d / %d / %d\r\n", fftScaling_Tx_1, fftScaling_Tx_2, fftScaling_Tx_3); |
---|
294 | xil_printf("FFT Rx Scaling: %d / %d / %d\r\n", fftScaling_Rx_1, fftScaling_Rx_2, fftScaling_Rx_3); |
---|
295 | updateFFTscaling = 0; |
---|
296 | } |
---|
297 | |
---|
298 | if(updateAGCthresh) |
---|
299 | { |
---|
300 | OFDM_AGC_MIMO_WriteReg_Thresholds(XPAR_OFDM_AGC_MIMO_OPBW_0_BASEADDR, ((agc_coarseThresh_1&0xFF)<<16) + ((agc_coarseThresh_2&0xFF)<<8) + (agc_coarseThresh_3&0xFF) ); |
---|
301 | xil_printf("AGC Thresholds: %d / %d / %d\r\n", (0xFFFFFF00 | agc_coarseThresh_1), (0xFFFFFF00 | agc_coarseThresh_2), (0xFFFFFF00 | agc_coarseThresh_3) ); |
---|
302 | updateAGCthresh = 0; |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | return; |
---|
307 | } |
---|
308 | |
---|
309 | ///@brief Main function |
---|
310 | /// |
---|
311 | ///This function configures MAC parameters, enables the underlying frameworks, and then loops forever. |
---|
312 | int main(){ |
---|
313 | xil_printf("DEBUGMAC\r\n"); |
---|
314 | |
---|
315 | updateFFTscaling = 0; |
---|
316 | updateAGCthresh = 0; |
---|
317 | pktCount = 0; |
---|
318 | chan = 9; |
---|
319 | dacGain_coarse = 0; |
---|
320 | dacGain_fine = 255; |
---|
321 | agcPrintMode = 0; |
---|
322 | pktDetMask = 1; |
---|
323 | |
---|
324 | pktFullRate = HDR_FULLRATE_QPSK; |
---|
325 | |
---|
326 | pktCodeRate = CODE_RATE_NONE; |
---|
327 | TxGainBB = 3; |
---|
328 | TxGainRF = 0x3F; |
---|
329 | userIOBoard_LEDs = 1; |
---|
330 | pktCount_good = 0; |
---|
331 | pktCount_bad = 0; |
---|
332 | |
---|
333 | fftScaling_Rx_1 = RX_FFT_SCALING_STAGE1; |
---|
334 | fftScaling_Rx_2 = RX_FFT_SCALING_STAGE2; |
---|
335 | fftScaling_Rx_3 = RX_FFT_SCALING_STAGE3; |
---|
336 | fftScaling_Tx_1 = TX_FFT_SCALING_STAGE1; |
---|
337 | fftScaling_Tx_2 = TX_FFT_SCALING_STAGE2; |
---|
338 | fftScaling_Tx_3 = TX_FFT_SCALING_STAGE3; |
---|
339 | |
---|
340 | agc_coarseThresh_1 = 0xE2; //-30 |
---|
341 | agc_coarseThresh_2 = 0xCB; //-53 |
---|
342 | agc_coarseThresh_3 = 0xA6; //-90 |
---|
343 | |
---|
344 | txScaling_preamble = 2080; |
---|
345 | txScaling_payload = 8192; |
---|
346 | |
---|
347 | radReg9 = 0x0003; |
---|
348 | updateRadReg9 = 0; |
---|
349 | txBBGain = 0x0; |
---|
350 | txUpconvLin = 0x0; |
---|
351 | txVGALin = 0x0; |
---|
352 | |
---|
353 | |
---|
354 | |
---|
355 | pktDet_thresh = 4000; |
---|
356 | cs_thresh = 6000; |
---|
357 | |
---|
358 | //Initialize the framework |
---|
359 | warpmac_init(); |
---|
360 | |
---|
361 | //Rx Buffer where the wireless PHY will write packets |
---|
362 | warpmac_setRxBuffer(&rxBuffer,0); |
---|
363 | //Tx buffer is where the EMAC will DMA payloads to |
---|
364 | warpmac_setTxBuffer(1); |
---|
365 | |
---|
366 | //Connect the various user-level callbacks |
---|
367 | warpmac_setBadHeaderCallback((void *)phyRx_badHeader_callback); |
---|
368 | warpmac_setGoodHeaderCallback((void *)phyRx_goodHeader_callback); |
---|
369 | warpmac_setEmacCallback((void *)emacRx_callback); |
---|
370 | warpmac_setUpButtonCallback((void *)up); |
---|
371 | warpmac_setMiddleButtonCallback((void *)middle); |
---|
372 | warpmac_setLeftButtonCallback((void *)left); |
---|
373 | warpmac_setRightButtonCallback((void *)right); |
---|
374 | warpmac_setUartRecvCallback((void *)getByte); |
---|
375 | |
---|
376 | |
---|
377 | ofdm_txrx_mimo_WriteReg_Rx_PktDet_setThresh(pktDet_thresh); |
---|
378 | ofdm_txrx_mimo_WriteReg_Rx_CSMA_setThresh(cs_thresh); |
---|
379 | |
---|
380 | //Set the default center frequency |
---|
381 | warpphy_setChannel(GHZ_2, chan); |
---|
382 | |
---|
383 | //Enable carrier sensing |
---|
384 | warpmac_enableCSMA(); |
---|
385 | |
---|
386 | //Enable Ethernet |
---|
387 | warpmac_enableEthernet(); |
---|
388 | |
---|
389 | //Set the modulation scheme use for base rate (header) symbols |
---|
390 | warpmac_setBaseRate(QPSK); |
---|
391 | |
---|
392 | OFDM_AGC_MIMO_WriteReg_Thresholds(XPAR_OFDM_AGC_MIMO_OPBW_0_BASEADDR, ((agc_coarseThresh_1&0xFF)<<16) + ((agc_coarseThresh_2&0xFF)<<8) + (agc_coarseThresh_3&0xFF) ); |
---|
393 | |
---|
394 | //Set initial Tx gains; controlled by push buttons below |
---|
395 | WarpRadio_v1_SetTxGainTiming(FIRST_RADIO | SECOND_RADIO, TxGainRF, 0xF, 1); |
---|
396 | WarpRadio_v1_BaseBandTxGain(TxGainBB, FIRST_RADIO | SECOND_RADIO); |
---|
397 | |
---|
398 | //Initialize the LCD for slot 1 (i.e. don't flip the image) and non-inverted colors |
---|
399 | warp_userioboard_lcd_init(1, 0); |
---|
400 | warp_userioboard_set_lcd_charbuf(1); |
---|
401 | |
---|
402 | snprintf(charsToPrint, 16, "Ref Design v12a"); |
---|
403 | warp_userio_lcd_printline(charsToPrint, 16, 1, 1); |
---|
404 | |
---|
405 | snprintf(charsToPrint, 16, " Rx Pkt Counts"); |
---|
406 | warp_userio_lcd_printline(charsToPrint, 16, 3, 1); |
---|
407 | |
---|
408 | warp_userioboard_set_leds(userIOBoard_LEDs); |
---|
409 | |
---|
410 | if(warpmac_getMyId()) |
---|
411 | { |
---|
412 | while(1){ |
---|
413 | warpmac_pollPeripherals(); |
---|
414 | } |
---|
415 | } |
---|
416 | else |
---|
417 | { |
---|
418 | xil_printf("Debug menu:\r\n"); |
---|
419 | |
---|
420 | while(1) |
---|
421 | { |
---|
422 | warpmac_pollPeripherals(); |
---|
423 | } |
---|
424 | } |
---|
425 | return; |
---|
426 | } |
---|
427 | |
---|
428 | |
---|
429 | |
---|
430 | ///@brief Callback for the depression of the left push button |
---|
431 | /// |
---|
432 | ///This button selects the left radio (slot 2) for Tx and Rx |
---|
433 | void left(){ |
---|
434 | |
---|
435 | switch(pktFullRate) |
---|
436 | { |
---|
437 | case HDR_FULLRATE_BPSK: |
---|
438 | pktFullRate = HDR_FULLRATE_BPSK; |
---|
439 | xil_printf("Tx: BPSK\r\n"); |
---|
440 | break; |
---|
441 | case HDR_FULLRATE_QPSK: |
---|
442 | pktFullRate = HDR_FULLRATE_BPSK; |
---|
443 | xil_printf("Tx: BPSK\r\n"); |
---|
444 | break; |
---|
445 | case HDR_FULLRATE_QAM_16: |
---|
446 | pktFullRate = HDR_FULLRATE_QPSK; |
---|
447 | xil_printf("Tx: QPSK\r\n"); |
---|
448 | break; |
---|
449 | case HDR_FULLRATE_QAM_64: |
---|
450 | pktFullRate = HDR_FULLRATE_QAM_16; |
---|
451 | xil_printf("Tx: 16-QAM\r\n"); |
---|
452 | break; |
---|
453 | default: |
---|
454 | pktFullRate = HDR_FULLRATE_QPSK; |
---|
455 | xil_printf("Tx: QPSK\r\n"); |
---|
456 | break; |
---|
457 | } |
---|
458 | |
---|
459 | } |
---|
460 | |
---|
461 | ///@brief Callback for the depression of the right push button |
---|
462 | /// |
---|
463 | ///This button selects the right radio (slot 3) for Tx and Rx |
---|
464 | void right(){ |
---|
465 | switch(pktFullRate) |
---|
466 | { |
---|
467 | case HDR_FULLRATE_BPSK: |
---|
468 | pktFullRate = HDR_FULLRATE_QPSK; |
---|
469 | xil_printf("Tx: QPSK\r\n"); |
---|
470 | break; |
---|
471 | case HDR_FULLRATE_QPSK: |
---|
472 | pktFullRate = HDR_FULLRATE_QAM_16; |
---|
473 | xil_printf("Tx: 16-QAM\r\n"); |
---|
474 | break; |
---|
475 | case HDR_FULLRATE_QAM_16: |
---|
476 | pktFullRate = HDR_FULLRATE_QAM_64; |
---|
477 | xil_printf("Tx: 64-QAM\r\n"); |
---|
478 | break; |
---|
479 | case HDR_FULLRATE_QAM_64: |
---|
480 | pktFullRate = HDR_FULLRATE_QAM_64; |
---|
481 | xil_printf("Tx: 64-QAM\r\n"); |
---|
482 | break; |
---|
483 | default: |
---|
484 | pktFullRate = HDR_FULLRATE_QPSK; |
---|
485 | xil_printf("Tx: QPSK\r\n"); |
---|
486 | break; |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | ///@brief Callback for the depression of the up push button |
---|
491 | /// |
---|
492 | ///This button increments the 2.4GHz channel being used |
---|
493 | void up(){ |
---|
494 | TxGainRF = (TxGainRF+1) & 0x3F; |
---|
495 | WarpRadio_v1_SetTxGainTiming(FIRST_RADIO | SECOND_RADIO, TxGainRF, 0xF, 1); |
---|
496 | WarpRadio_v1_TxVGAGainControl(TxGainRF, FIRST_RADIO | SECOND_RADIO); |
---|
497 | xil_printf("TxGainRF: %x\r\n", TxGainRF); |
---|
498 | } |
---|
499 | |
---|
500 | ///@brief Callback for the depression of the middle push button |
---|
501 | /// |
---|
502 | ///This button decrements the 2.4GHz channel being used |
---|
503 | void middle(){ |
---|
504 | TxGainRF = (TxGainRF-1) & 0x3F; |
---|
505 | WarpRadio_v1_SetTxGainTiming(FIRST_RADIO | SECOND_RADIO, TxGainRF, 0xF, 1); |
---|
506 | WarpRadio_v1_TxVGAGainControl(TxGainRF, FIRST_RADIO | SECOND_RADIO); |
---|
507 | xil_printf("TxGainRF: %x\r\n", TxGainRF); |
---|
508 | } |
---|
509 | |
---|
510 | |
---|
511 | /* |
---|
512 | |
---|
513 | ///@brief Callback for the depression of the left push button |
---|
514 | /// |
---|
515 | ///This button selects the left radio (slot 2) for Tx and Rx |
---|
516 | void left(){ |
---|
517 | warpphy_setTargetMinus(); |
---|
518 | } |
---|
519 | |
---|
520 | ///@brief Callback for the depression of the right push button |
---|
521 | /// |
---|
522 | ///This button selects the right radio (slot 3) for Tx and Rx |
---|
523 | void right(){ |
---|
524 | warpphy_setTargetPlus(); |
---|
525 | } |
---|
526 | |
---|
527 | #define DAC_COARSE 1 |
---|
528 | //#define DAC_FINE 1 |
---|
529 | |
---|
530 | ///@brief Callback for the depression of the up push button |
---|
531 | /// |
---|
532 | ///This button increments the 2.4GHz channel being used |
---|
533 | void up(){ |
---|
534 | RADIO_CONTROLLER_mWriteSlaveReg5((volatile)radio_controller_baseaddr, 0x3410); // Set the value of the Control Register to 0x00003410 for DACs |
---|
535 | RADIO_CONTROLLER_mWriteSlaveReg6((volatile)radio_controller_baseaddr, 1); // Set the value for the Divider Register to 0x00000001 |
---|
536 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASKDAC & (RADIO1_ADDR | RADIO2_ADDR | RADIO3_ADDR | RADIO4_ADDR))); // Select all DACs |
---|
537 | |
---|
538 | #ifdef DAC_COARSE |
---|
539 | dacGain_coarse++; |
---|
540 | if(dacGain_coarse > 15) |
---|
541 | dacGain_coarse = 0; |
---|
542 | |
---|
543 | WarpRadio_v1_DACCoarseGainAdj(ICHAN, dacGain_coarse, RADIO2_ADDR); |
---|
544 | WarpRadio_v1_DACCoarseGainAdj(QCHAN, dacGain_coarse, RADIO2_ADDR); |
---|
545 | xil_printf("Set DAC coarse gain = %d\r\n", dacGain_coarse); |
---|
546 | #endif |
---|
547 | |
---|
548 | #ifdef DAC_FINE |
---|
549 | dacGain_fine++; |
---|
550 | if(dacGain_fine > 255) |
---|
551 | dacGain_fine = 0; |
---|
552 | |
---|
553 | |
---|
554 | WarpRadio_v1_DACFineGainAdj(ICHAN, dacGain_fine, RADIO2_ADDR); |
---|
555 | WarpRadio_v1_DACFineGainAdj(QCHAN, dacGain_fine, RADIO2_ADDR); |
---|
556 | xil_printf("Set DAC fine gain = %d\r\n", dacGain_fine); |
---|
557 | #endif |
---|
558 | } |
---|
559 | |
---|
560 | ///@brief Callback for the depression of the middle push button |
---|
561 | /// |
---|
562 | ///This button decrements the 2.4GHz channel being used |
---|
563 | void middle(){ |
---|
564 | RADIO_CONTROLLER_mWriteSlaveReg5((volatile)radio_controller_baseaddr, 0x3410); // Set the value of the Control Register to 0x00003410 for DACs |
---|
565 | RADIO_CONTROLLER_mWriteSlaveReg6((volatile)radio_controller_baseaddr, 1); // Set the value for the Divider Register to 0x00000001 |
---|
566 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASKDAC & (RADIO1_ADDR | RADIO2_ADDR | RADIO3_ADDR | RADIO4_ADDR))); // Select all DACs |
---|
567 | |
---|
568 | #ifdef DAC_COARSE |
---|
569 | dacGain_coarse--; |
---|
570 | if(dacGain_coarse > 15) |
---|
571 | dacGain_coarse = 15; |
---|
572 | |
---|
573 | WarpRadio_v1_DACCoarseGainAdj(ICHAN, dacGain_coarse, RADIO2_ADDR); |
---|
574 | WarpRadio_v1_DACCoarseGainAdj(QCHAN, dacGain_coarse, RADIO2_ADDR); |
---|
575 | xil_printf("Set DAC coarse gain = %d\r\n", dacGain_coarse); |
---|
576 | #endif |
---|
577 | |
---|
578 | #ifdef DAC_FINE |
---|
579 | dacGain_fine--; |
---|
580 | if(dacGain_fine > 255) |
---|
581 | dacGain_fine = 255; |
---|
582 | |
---|
583 | |
---|
584 | WarpRadio_v1_DACFineGainAdj(ICHAN, dacGain_fine, RADIO2_ADDR); |
---|
585 | WarpRadio_v1_DACFineGainAdj(QCHAN, dacGain_fine, RADIO2_ADDR); |
---|
586 | xil_printf("Set DAC fine gain = %d\r\n", dacGain_fine); |
---|
587 | #endif |
---|
588 | } |
---|
589 | */ |
---|