source: PlatformSupport/CustomPeripherals/pcores/radio_controller_v1_30_a/src/radio_controller_5ghz.c

Last change on this file was 1427, checked in by sgupta, 14 years ago

fixed ancient radio controller driver bug that causes the pll of radios in slot 1 tuned to 5ghz to unlock

File size: 11.9 KB
Line 
1// Copyright (c) 2006 Rice University
2// All Rights Reserved
3// This code is covered by the Rice-WARP license
4// See http://warp.rice.edu/license/ for details
5
6/**
7 * \file radio_controller_5ghz.c
8 * \brief Contains the functions that utilize the 5GHz band functionality.
9 *
10 * @version 1.09
11 * @author Siddharth Gupta
12 *
13 * This file has the functions that play a role in the 5GHz functionality of the radio boards
14 * including center frequency and amplifiers.
15 */
16
17/***************************** Include Files *******************************/
18
19#include "radio_controller_5ghz.h"
20
21/****************************** Functions **********************************/
22
23/**
24 * @brief Enable the 5GHz power amplifier.
25 *
26 * Enable the 5GHz amplifier for the boards specified. The amplifier turns on during the
27 * transmit state machine's execution.
28 *
29 * @param radios Radio boards affected.
30 */
31void WarpRadio_v1_5AmpEnable(unsigned int radios) {
32
33    RADIO_CONTROLLER_mWriteSlaveReg1((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg1((volatile)radio_controller_baseaddr) | (radios & RAD_5PA_MASK))); // Enable 5GHz amp
34}
35
36/**
37 * @brief Disable the 5GHz power amplifier.
38 *
39 * Disable the 5GHz amplifier for the boards specified. Unless an amplifier is enabled, none
40 * will turn on during transmit.
41 *
42 * @param radios Radio boards affected.
43 */
44void WarpRadio_v1_5AmpDisable(unsigned int radios) {
45
46    RADIO_CONTROLLER_mWriteSlaveReg1((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg1((volatile)radio_controller_baseaddr) & ~(radios & RAD_5PA_MASK))); // Disable 5GHz amp
47}
48
49/**
50 * @brief Tune the radio to a frequency in the 5GHz band.
51 *
52 * Function used to shift the center frequency on the radio within the 5GHz band. Also enables the
53 * 5GHz amplifier for the transmit state machine.
54 *      -# 5180MHz
55 *      -# 5200MHz
56 *      -# 5220MHz
57 *      -# 5240MHz
58 *      -# 5260MHz
59 *      -# 5280MHz
60 *      -# 5300MHz
61 *      -# 5320MHz
62 *      -# 5500MHz
63 *      -# 5520MHz
64 *      -# 5540MHz
65 *      -# 5560MHz
66 *      -# 5580MHz
67 *      -# 5600MHz
68 *      -# 5620MHz
69 *      -# 5640MHz
70 *      -# 5660MHz
71 *      -# 5680MHz
72 *      -# 5700MHz
73 *      -# 5745MHz
74 *      -# 5765MHz
75 *      -# 5785MHz
76 *      -# 5805MHz
77 *
78 * @param freqset The frequency channel to use, selected from above list
79 * @param radios Defines which radios are affected by this function call.
80 * @return Returns INVALID_FREQ if given frequency set is not valid.
81 */
82int WarpRadio_v1_SetCenterFreq5GHz(char freqset, unsigned int radios) {
83
84    RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));            // Select Radios affected by this function
85
86    unsigned int reg3;
87    unsigned int reg4;
88    unsigned int reg5;
89    int band5;                          // Defines whether the frequency is in the upper 5GHz band or in the lower 5GHz band.
90    int retval;                         // Return value from the function
91    unsigned int mask5gl1 = 0x0001;
92    unsigned int mask5gl2 = 0xFFBF;
93    unsigned int mask5gh = 0x0041;
94
95    switch(freqset) {                   // Switch on the frequency set given as input.
96        case(1) : {
97            reg3 = 0x30CF3;             // Set a value of 0x30CF for Register 3
98            reg4 = 0x0CCC4;             // Set a value of 0x3333 for Register 4
99            retval = 5180;              // Set the return value to the frequency that has been set.
100            band5 = 1;                  // Set the band5 value that it is in the lower 5GHz band.
101            break;
102        }
103        case(2) : {
104            reg3 = 0x00D03;
105            reg4 = 0x00004;
106            retval = 5200;
107            band5 = 1;
108            break;
109        }
110        case(3) : {
111            reg3 = 0x00D03;
112            reg4 = 0x33334;
113            retval = 5220;
114            band5 = 1;
115            break;
116        }
117        case(4) : {
118            reg3 = 0x10D13;
119            reg4 = 0x26664;
120            retval = 5240;
121            band5 = 1;
122            break;
123        }
124        case(5) : {
125            reg3 = 0x20D23;
126            reg4 = 0x19994;
127            retval = 5260;
128            band5 = 1;
129            break;
130        }
131        case(6) : {
132            reg3 = 0x30D33;
133            reg4 = 0x0CCC4;
134            retval = 5280;
135            band5 = 1;
136            break;
137        }
138        case(7) : {
139            reg3 = 0x00D43;
140            reg4 = 0x00004;
141            retval = 5300;
142            band5 = 1;
143            break;
144        }
145        case(8) : {
146            reg3 = 0x00D43;
147            reg4 = 0x33334;
148            retval = 5320;
149            band5 = 1;
150            break;
151        }
152        case(9) : {
153            reg3 = 0x00DC3;
154            reg4 = 0x00004;
155            retval = 5500;
156            band5 = 2;
157            break;
158        }
159        case(10) : {
160            reg3 = 0x00DC3;
161            reg4 = 0x33334;
162            retval = 5520;
163            band5 = 2;
164            break;
165        }
166        case(11) : {
167            reg3 = 0x10DD3;
168            reg4 = 0x26664;
169            retval = 5540;
170            band5 = 2;
171            break;
172        }
173        case(12) : {
174            reg3 = 0x20DE3;
175            reg4 = 0x19994;
176            retval = 5560;
177            band5 = 2;
178            break;
179        }
180        case(13) : {
181            reg3 = 0x30DF3;
182            reg4 = 0x0CCC4;
183            retval = 5580;
184            band5 = 2;
185            break;
186        }
187        case(14) : {
188            reg3 = 0x00E03;
189            reg4 = 0x00004;
190            retval = 5600;
191            band5 = 2;
192            break;
193        }
194        case(15) : {
195            reg3 = 0x00E03;
196            reg4 = 0x33334;
197            retval = 5620;
198            band5 = 2;
199            break;
200        }
201        case(16) : {
202            reg3 = 0x10E13;
203            reg4 = 0x26664;
204            retval = 5640;
205            band5 = 2;
206            break;
207        }
208        case(17) : {
209            reg3 = 0x20E23;
210            reg4 = 0x19994;
211            retval = 5660;
212            band5 = 2;
213            break;
214        }
215        case(18) : {
216            reg3 = 0x30E33;
217            reg4 = 0x0CCC4;
218            retval = 5680;
219            band5 = 2;
220            break;
221        }
222        case(19) : {
223            reg3 = 0x00E43;
224            reg4 = 0x00004;
225            retval = 5700;
226            band5 = 2;
227            break;
228        }
229        case(20) : {
230            reg3 = 0x00E53;
231            reg4 = 0x33334;
232            retval = 5745;
233            band5 = 2;
234            break;
235        }
236        case(21) : {
237            reg3 = 0x10E63;
238            reg4 = 0x26664;
239            retval = 5765;
240            band5 = 2;
241            break;
242        }
243        case(22) : {
244            reg3 = 0x20E73;
245            reg4 = 0x19994;
246            retval = 5785;
247            band5 = 2;
248            break;
249        }
250        case(23) : {
251            reg3 = 0x30E83;
252            reg4 = 0x0CCC4;
253            retval = 5805;
254            band5 = 2;
255            break;
256        }
257        default : {
258            retval = INVALID_FREQ;
259        }
260    }
261
262    if(retval != -1) {                      // Check if an invalid freqency set has been provided and if so do not change freqency
263
264        transmit(reg3);         // Transmit register 3 value
265        transmit(reg4);         // Transmit register 4 value
266
267        reg3 = reg3>>4;
268        reg4 = reg4>>4;
269
270        if (band5 == 1) {                                   // Check if the freqency is in the lower 5GHz band
271            if((radios & RAD1MASK) > 0) {   // Check if the Slave is in use
272
273                reg5 = REG_RAD1_BAND_SELECT | mask5gl1;                         // Set the band in register 5 to 5GHz
274                reg5 = reg5 & mask5gl2;                                         // Set the band range in the register 5 to the lower 5GHz band
275
276                transRadio(0x0001, ((reg5<<4)+0x0005));             // Set the register 5 value
277                transRadio(0x0001, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
278                transRadio(0x0001, ((reg5<<4)+0x0005));             // Restore the value of register 5
279
280                REG_RAD1_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
281                REG_RAD1_INTEGER_DIVIDER_RATIO = (short)reg3;
282                REG_RAD1_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
283            }
284            if((radios & RAD2MASK) > 0) {   // Check if the Slave is in use
285
286                reg5 = REG_RAD2_BAND_SELECT | mask5gl1;                         // Set the band in register 5 to 5GHz
287                reg5 = reg5 & mask5gl2;                                         // Set the band range in the register 5 to the lower 5GHz band
288
289                transRadio(0x0002, ((reg5<<4)+0x0005));             // Set the register 5 value
290                transRadio(0x0002, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
291                transRadio(0x0002, ((reg5<<4)+0x0005));             // Restore the value of register 5
292
293                REG_RAD2_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
294                REG_RAD2_INTEGER_DIVIDER_RATIO = (short)reg3;
295                REG_RAD2_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
296            }
297            if((radios & RAD3MASK) > 0) {   // Check if the Slave is in use
298
299                reg5 = REG_RAD3_BAND_SELECT | mask5gl1;                         // Set the band in register 5 to 5GHz
300                reg5 = reg5 & mask5gl2;                                         // Set the band range in the register 5 to the lower 5GHz band
301
302                transRadio(0x0004, ((reg5<<4)+0x0005));             // Set the register 5 value
303                transRadio(0x0004, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
304                transRadio(0x0004, ((reg5<<4)+0x0005));             // Restore the value of register 5
305
306                REG_RAD3_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
307                REG_RAD3_INTEGER_DIVIDER_RATIO = (short)reg3;
308                REG_RAD3_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
309            }
310            if((radios & RAD4MASK) > 0) {   // Check if the Slave is in use
311
312                reg5 = REG_RAD4_BAND_SELECT | mask5gl1;                         // Set the band in register 5 to 5GHz
313                reg5 = reg5 & mask5gl2;                                         // Set the band range in the register 5 to the lower 5GHz band
314
315                transRadio(0x0008, ((reg5<<4)+0x0005));             // Set the register 5 value
316                transRadio(0x0008, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
317                transRadio(0x0008, ((reg5<<4)+0x0005));             // Restore the value of register 5
318
319                REG_RAD4_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
320                REG_RAD4_INTEGER_DIVIDER_RATIO = (short)reg3;
321                REG_RAD4_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
322            }
323        }
324
325        if (band5 == 2) {                                   // Check if the freqency is in the upper 5GHz band
326            if((radios & RAD1MASK) > 0) {   // Check if the Slave is in use
327
328                reg5 = REG_RAD1_BAND_SELECT | mask5gh;                          // Set the band in register 5 to 5GHz and upper 5GHz band
329
330                transRadio(0x0001, ((reg5<<4)+0x0005));             // Set the register 5 value
331                transRadio(0x0001, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
332                transRadio(0x0001, ((reg5<<4)+0x0005));             // Restore the value of register 5
333
334                REG_RAD1_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
335                REG_RAD1_INTEGER_DIVIDER_RATIO = (short)reg3;
336                REG_RAD1_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
337            }
338            if((radios & RAD2MASK) > 0) {   // Check if the Slave is in use
339
340                reg5 = REG_RAD2_BAND_SELECT | mask5gh;                          // Set the band in register 5 to 5GHz and upper 5GHz band
341
342                transRadio(0x0002, ((reg5<<4)+0x0005));             // Set the register 5 value
343                transRadio(0x0002, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
344                transRadio(0x0002, ((reg5<<4)+0x0005));             // Restore the value of register 5
345
346                REG_RAD2_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
347                REG_RAD2_INTEGER_DIVIDER_RATIO = (short)reg3;
348                REG_RAD2_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
349            }
350            if((radios & RAD3MASK) > 0) {   // Check if the Slave is in use
351
352                reg5 = REG_RAD3_BAND_SELECT | mask5gh;                          // Set the band in register 5 to 5GHz and upper 5GHz band
353
354                transRadio(0x0004, ((reg5<<4)+0x0005));             // Set the register 5 value
355                transRadio(0x0004, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
356                transRadio(0x0004, ((reg5<<4)+0x0005));             // Restore the value of register 5
357
358                REG_RAD3_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
359                REG_RAD3_INTEGER_DIVIDER_RATIO = (short)reg3;
360                REG_RAD3_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
361            }
362            if((radios & RAD4MASK) > 0) {   // Check if the Slave is in use
363
364                reg5 = REG_RAD4_BAND_SELECT | mask5gh;                          // Set the band in register 5 to 5GHz and upper 5GHz band
365
366                transRadio(0x0008, ((reg5<<4)+0x0005));             // Set the register 5 value
367                transRadio(0x0008, (((reg5 | 0x0080)<<4)+0x0005));  // Start auto band switch to the new value.
368                transRadio(0x0008, ((reg5<<4)+0x0005));             // Restore the value of register 5
369
370                REG_RAD4_BAND_SELECT = (short)reg5;                             // Store new values to the local copies
371                REG_RAD4_INTEGER_DIVIDER_RATIO = (short)reg3;
372                REG_RAD4_FRACTIONAL_DIVIDER_RATIO = (short)reg4;
373            }
374        }
375    }
376
377
378    RADIO_CONTROLLER_mWriteSlaveReg1((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg1((volatile)radio_controller_baseaddr) & ~(radios & RAD_24PA_MASK))); // Disable 2.4GHz amp
379
380    RADIO_CONTROLLER_mWriteSlaveReg1((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg1((volatile)radio_controller_baseaddr) | (radios & RAD_5PA_MASK))); // Enable 5GHz amp
381
382    return retval;      // Return either the new freqency that has been set or return -1 to indicate that the frequency set given was invalid
383}
384
Note: See TracBrowser for help on using the repository browser.