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

Last change on this file was 684, checked in by sgupta, 17 years ago

Doxygen documentation

File size: 8.6 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/***************************** Include Files *******************************/
7
8#include "radio_controller_cal.h"
9
10/****************************** Functions **********************************/
11
12// Put the radio into transmit calibration mode. 'radios' refers to the radios that will be put into
13// calibration. Forcibly removed from receive calibration mode.
14void WarpRadio_v1_TxCalibration(unsigned int radios) {
15
16    RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));            // Select Radios affected by this function
17
18    unsigned int calreg = 0x04026;             
19
20    transmit(calreg);                       
21
22    calreg = calreg>>4;                             
23
24    if((radios & RAD1MASK) > 0) {       // Check to make sure if Radio 1 is being used
25        REG_RAD1_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
26    }
27    if((radios & RAD2MASK) > 0) {       // Check to make sure if Radio 2 is being used
28        REG_RAD2_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
29    }
30    if((radios & RAD3MASK) > 0) {       // Check to make sure if Radio 3 is being used
31        REG_RAD3_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
32    }
33    if((radios & RAD4MASK) > 0) {       // Check to make sure if Radio 4 is being used
34        REG_RAD4_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
35    }
36}
37
38// Put the radio into receive calibration mode. 'radios' refers to the radios that will be put into
39// calibration. Forcibly removed from receive calibration mode.
40void WarpRadio_v1_RxCalibration(unsigned int radios) {
41
42    RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));            // Select Radios affected by this function
43
44    unsigned calreg = 0x1C016;
45
46    transmit(calreg);
47
48    calreg = calreg>>4;
49
50    if((radios & RAD1MASK) > 0) {       // Check to make sure if Radio 1 is being used
51        REG_RAD1_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
52    }
53    if((radios & RAD2MASK) > 0) {       // Check to make sure if Radio 2 is being used
54        REG_RAD2_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
55    }
56    if((radios & RAD3MASK) > 0) {       // Check to make sure if Radio 3 is being used
57        REG_RAD3_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
58    }
59    if((radios & RAD4MASK) > 0) {       // Check to make sure if Radio 4 is being used
60        REG_RAD4_CALIBRATION = (short)calreg;       // Depending on if the radio is used, store the value to the local copies
61    }
62}
63
64// Takes the specified radios out of transmit and recieve calibration mode. 'radios' refers the Radios in the
65// slots that will be affected.
66void WarpRadio_v1_NoCalibration(unsigned int radios) {
67
68    RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));            // Select Radios affected by this function
69
70    unsigned calreg = 0x1C006;
71
72    transmit(calreg);
73
74    calreg = calreg>>4;
75
76    if((radios & RAD1MASK) > 0) {       // Check to make sure if Radio 1 is being used
77        REG_RAD1_CALIBRATION = (short)calreg;
78    }
79    if((radios & RAD2MASK) > 0) {       // Check to make sure if Radio 2 is being used
80        REG_RAD2_CALIBRATION = (short)calreg;
81    }
82    if((radios & RAD3MASK) > 0) {       // Check to make sure if Radio 3 is being used
83        REG_RAD3_CALIBRATION = (short)calreg;
84    }
85    if((radios & RAD4MASK) > 0) {       // Check to make sure if Radio 4 is being used
86        REG_RAD4_CALIBRATION = (short)calreg;
87    }
88}
89
90// Sets the gain for Transmitter I/Q Calibration.
91// Returns NOT_IN_CALIBRATION if any of the radios for which the gain is being set in not
92// in calibration mode. Returns INVALID_GAIN if the gain set value given is not valid. Returns
93// WARP_SUCCESS if value changed successfully. To be in calibration mode set
94// TxCalibration.
95// gain = 0 -> 8db
96// gain = 1 -> 18db
97// gain = 2 -> 24db
98// gain = 3 -> 34db
99char WarpRadio_v1_TxCalGain(char gain, unsigned int radios) {
100
101    RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));            // Select Radios affected by this function
102
103    unsigned int mask = 0x0002;
104
105    if((radios & RAD1MASK) > 0) {       // Check to make sure if Radio 1 is being used
106        if ((REG_RAD1_CALIBRATION & mask) == 0x0) {     // If the transmit calibration bit is 0 then return NOT_IN_CALIBRATION
107            return NOT_IN_CALIBRATION;
108        }
109    }
110    if((radios & RAD2MASK) > 0) {       // Check to make sure if Radio 2 is being used
111        if ((REG_RAD2_CALIBRATION & mask) == 0x0) {     // If the transmit calibration bit is 0 then return NOT_IN_CALIBRATION
112            return NOT_IN_CALIBRATION;
113        }
114    }
115    if((radios & RAD3MASK) > 0) {       // Check to make sure if Radio 3 is being used
116        if ((REG_RAD3_CALIBRATION & mask) == 0x0) {     // If the transmit calibration bit is 0 then return NOT_IN_CALIBRATION
117            return NOT_IN_CALIBRATION;
118        }
119    }
120    if((radios & RAD4MASK) > 0) {       // Check to make sure if Radio 4 is being used
121        if ((REG_RAD4_CALIBRATION & mask) == 0x0) {     // If the transmit calibration bit is 0 then return NOT_IN_CALIBRATION
122            return NOT_IN_CALIBRATION;
123        }
124    }
125
126    unsigned int calreg;
127
128    switch(gain) {                     
129        case(0) : {                     
130            calreg = 0x04026;
131            break;
132        }
133        case(1) : {
134            calreg = 0x0C026;
135            break;
136        }
137        case(2) : {
138            calreg = 0x14026;
139            break;
140        }
141        case(3) : {
142            calreg = 0x1C026;
143            break;
144        }
145        default : {
146            return OUT_OF_RANGE;
147        }
148    }
149
150    transmit(calreg);                   
151    calreg = calreg>>4;
152
153    if((radios & RAD1MASK) > 0) {       // Check to make sure if Radio 1 is being used
154        REG_RAD1_CALIBRATION = (short)calreg;
155    }
156    if((radios & RAD2MASK) > 0) {       // Check to make sure if Radio 2 is being used
157        REG_RAD2_CALIBRATION = (short)calreg;
158    }
159    if((radios & RAD3MASK) > 0) {       // Check to make sure if Radio 3 is being used
160        REG_RAD3_CALIBRATION = (short)calreg;
161    }
162    if((radios & RAD4MASK) > 0) {       // Check to make sure if Radio 4 is being used
163        REG_RAD4_CALIBRATION = (short)calreg;
164    }
165
166    return WARP_SUCCESS;
167}
168
169// Enable or disable the Rx baseband section of the reciever. Mode = 0 disables the value while mode = 1
170// enables the value. Returns INVALID_MODE if the mode is invalid. Returns WARP_SUCCESS if successfully manage
171// to change the value.
172char WarpRadio_v1_TxCalRxEnable(char mode, unsigned int radios) {
173
174    RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));            // Select Radios affected by this function
175
176        unsigned int modeon = 0x0040;
177        unsigned int modeoff = 0xFFBF;
178
179        if (mode == 0) {
180            if((radios & RAD1MASK) > 0) {       // Check to make sure if Radio 1 is being used
181                unsigned int reg2 = REG_RAD1_STANDBY & modeoff;         
182
183                transRadio(0x0001, ((reg2<<4)+0x0002));     
184
185                REG_RAD1_STANDBY = (short)reg2;
186            }
187            if((radios & RAD2MASK) > 0) {       // Check to make sure if Radio 2 is being used
188                unsigned int reg2 = REG_RAD2_STANDBY & modeoff;
189
190                transRadio(0x0002, ((reg2<<4)+0x0002));
191
192                REG_RAD2_STANDBY = (short)reg2;
193            }
194            if((radios & RAD3MASK) > 0) {       // Check to make sure if Radio 3 is being used
195                unsigned int reg2 = REG_RAD3_STANDBY & modeoff;
196
197                transRadio(0x0004, ((reg2<<4)+0x0002));
198
199                REG_RAD3_STANDBY = (short)reg2;
200            }
201            if((radios & RAD4MASK) > 0) {       // Check to make sure if Radio 4 is being used
202                unsigned int reg2 = REG_RAD4_STANDBY & modeoff;
203
204                transRadio(0x0008, ((reg2<<4)+0x0002));
205
206                REG_RAD4_STANDBY = (short)reg2;
207            }
208        }
209        else if (mode == 1) {
210            if((radios & RAD1MASK) > 0) {       // Check to make sure if Radio 1 is being used
211                unsigned int reg2 = REG_RAD1_STANDBY | modeon;         
212
213                transRadio(0x0001, ((reg2<<4)+0x0002));     
214
215                REG_RAD1_STANDBY = (short)reg2;
216            }
217            if((radios & RAD2MASK) > 0) {       // Check to make sure if Radio 2 is being used
218                unsigned int reg2 = REG_RAD2_STANDBY | modeon;
219
220                transRadio(0x0002, ((reg2<<4)+0x0002));
221
222                REG_RAD2_STANDBY = (short)reg2;
223            }
224            if((radios & RAD3MASK) > 0) {       // Check to make sure if Radio 3 is being used
225                unsigned int reg2 = REG_RAD3_STANDBY | modeon;
226
227                transRadio(0x0004, ((reg2<<4)+0x0002));
228
229                REG_RAD3_STANDBY = (short)reg2;
230            }
231            if((radios & RAD4MASK) > 0) {       // Check to make sure if Radio 4 is being used
232                unsigned int reg2 = REG_RAD4_STANDBY | modeon;
233
234                transRadio(0x0008, ((reg2<<4)+0x0002));
235
236                REG_RAD4_STANDBY = (short)reg2;
237            }
238        }
239        else {
240            return INVALID_MODE;
241        }
242    return WARP_SUCCESS;
243}
244
245
246
Note: See TracBrowser for help on using the repository browser.