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_ext.c |
---|
8 | * \brief Extended functionality of the radio boards, over the basic controller. |
---|
9 | * |
---|
10 | * @version 1.09 |
---|
11 | * @author Siddharth Gupta |
---|
12 | * |
---|
13 | * Drivers for more complex functions of the radio boards. This includes finer control of receive |
---|
14 | * and transmit gains, both in hardware and software, transmit state machine and control |
---|
15 | * of filter parameters. |
---|
16 | */ |
---|
17 | |
---|
18 | /***************************** Include Files *******************************/ |
---|
19 | |
---|
20 | #include "radio_controller_ext.h" |
---|
21 | |
---|
22 | /****************************** Functions **********************************/ |
---|
23 | |
---|
24 | /** |
---|
25 | * @brief Enable the 2.4GHz power amplifier. |
---|
26 | * |
---|
27 | * Enable the 2.4GHz amplifier for the boards specified. The amplifier turns on during the |
---|
28 | * transmit state machine's execution. |
---|
29 | * |
---|
30 | * @param radios Radio boards affected. |
---|
31 | */ |
---|
32 | void WarpRadio_v1_24AmpEnable(unsigned int radios) { |
---|
33 | |
---|
34 | RADIO_CONTROLLER_mWriteSlaveReg1((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg1((volatile)radio_controller_baseaddr) | (radios & RAD_24PA_MASK))); // Enable 2.4GHz amp |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * @brief Disable the 2.4GHz power amplifier. |
---|
39 | * |
---|
40 | * Disable the 2.4GHz amplifier for the boards specified. Unless an amplifier is enabled, none |
---|
41 | * will turn on during transmit. |
---|
42 | * |
---|
43 | * @param radios Radio boards affected. |
---|
44 | */ |
---|
45 | void WarpRadio_v1_24AmpDisable(unsigned int radios) { |
---|
46 | |
---|
47 | RADIO_CONTROLLER_mWriteSlaveReg1((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg1((volatile)radio_controller_baseaddr) & ~(radios & RAD_24PA_MASK))); // Disable 2.4GHz amp |
---|
48 | } |
---|
49 | |
---|
50 | /* |
---|
51 | // Select a configuration for the Antennas and Transmit and Receive paths. |
---|
52 | // Applies to 'radios' specified. |
---|
53 | // mode = 1: Antenna 1 for TX and RX |
---|
54 | // mode = 2: Antenna 2 for TX and RX |
---|
55 | // mode = 3: Antenna 1 for TX and Antenna 2 for RX |
---|
56 | // mode = 4: Antenna 1 for RX and Antenna 2 for TX |
---|
57 | char WarpRadio_v1_AntennaConfig(char mode, unsigned int radios); |
---|
58 | */ |
---|
59 | |
---|
60 | /** |
---|
61 | * @brief Read lock detect from the radio. |
---|
62 | * |
---|
63 | * Reads the LockDetect pin of the radios requested. Outputs lock detects as {LD4, LD3, LD2, LD1}. |
---|
64 | * Not requested radios have a zero on the output. |
---|
65 | * |
---|
66 | * @param radios Radios to read from |
---|
67 | * @return An output of 1 indicates that the radio is locked while 0 indicates that it is not. |
---|
68 | */ |
---|
69 | char WarpRadio_v1_LockDetect(unsigned int radios) { |
---|
70 | |
---|
71 | return (((RADIO_CONTROLLER_mReadSlaveReg1((volatile)radio_controller_baseaddr) & RAD_LD_MASK) >> 8) & radios); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief Control transmit gain in software/hardware. |
---|
76 | * |
---|
77 | * Enable or disable transmit VGA Gain programming using software. If in software, TxVGAGainControl |
---|
78 | * must be used to set gain value. If not, then the transmit state machine must be setup to use |
---|
79 | * gain values. |
---|
80 | * |
---|
81 | * @see WarpRadio_v1_TxVGAGainControl, WarpRadio_v1_setTxGainTiming |
---|
82 | * @param mode 0: Transmit VGA Gain programmed with external ports, 1: Transmit VGA Gain programmed with TxVGAGainControl function |
---|
83 | * @param radios Radios affected. |
---|
84 | * @return Returns INVALID_MODE if the mode is an invalid input, WARP_SUCCESS if successful. |
---|
85 | */ |
---|
86 | char WarpRadio_v1_SoftwareTxGainControl(short mode, unsigned int radios) { |
---|
87 | |
---|
88 | if (mode == 0 | mode == 1) { |
---|
89 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
90 | |
---|
91 | mode = mode & 0x0001; |
---|
92 | mode = mode << 10; |
---|
93 | int mask = 0xFBFF; |
---|
94 | |
---|
95 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
96 | unsigned int reg9 = REG_RAD1_TX_LINEARITY & mask; |
---|
97 | reg9 = reg9 + mode; |
---|
98 | transRadio(0x0001, ((reg9<<4)+0x0009)); |
---|
99 | |
---|
100 | REG_RAD1_TX_LINEARITY = (short)reg9; |
---|
101 | } |
---|
102 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
103 | unsigned int reg9 = REG_RAD2_TX_LINEARITY & mask; |
---|
104 | reg9 = reg9 + mode; |
---|
105 | transRadio(0x0002, ((reg9<<4)+0x0009)); |
---|
106 | |
---|
107 | REG_RAD2_TX_LINEARITY = (short)reg9; |
---|
108 | } |
---|
109 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
110 | unsigned int reg9 = REG_RAD3_TX_LINEARITY & mask; |
---|
111 | reg9 = reg9 + mode; |
---|
112 | transRadio(0x0004, ((reg9<<4)+0x0009)); |
---|
113 | |
---|
114 | REG_RAD3_TX_LINEARITY = (short)reg9; |
---|
115 | } |
---|
116 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
117 | unsigned int reg9 = REG_RAD4_TX_LINEARITY & mask; |
---|
118 | reg9 = reg9 + mode; |
---|
119 | transRadio(0x0008, ((reg9<<4)+0x0009)); |
---|
120 | |
---|
121 | REG_RAD4_TX_LINEARITY = (short)reg9; |
---|
122 | } |
---|
123 | } |
---|
124 | else { |
---|
125 | return INVALID_MODE; |
---|
126 | } |
---|
127 | |
---|
128 | return WARP_SUCCESS; |
---|
129 | } |
---|
130 | |
---|
131 | /** |
---|
132 | * @brief Set the transmit baseband gain. |
---|
133 | * |
---|
134 | * Set the transmit baseband gain. Always set by software. |
---|
135 | * Gains: |
---|
136 | * - 00: max baseband gain - 5db |
---|
137 | * - 01: max baseband gain - 3db |
---|
138 | * - 10: max baseband gain - 1.5db |
---|
139 | * - 11: max baseband gain |
---|
140 | * |
---|
141 | * @param value Value from the above list corresponding to the gain needed. |
---|
142 | * @param radios The radios affected. |
---|
143 | */ |
---|
144 | void WarpRadio_v1_BaseBandTxGain(char value, unsigned int radios) { |
---|
145 | |
---|
146 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
147 | |
---|
148 | value = value & 0x0003; |
---|
149 | int mask = 0xFFFC; |
---|
150 | |
---|
151 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
152 | unsigned int reg9 = REG_RAD1_TX_LINEARITY & mask; |
---|
153 | reg9 = reg9 + value; |
---|
154 | transRadio(0x0001, ((reg9<<4)+0x0009)); |
---|
155 | |
---|
156 | REG_RAD1_TX_LINEARITY = (short)reg9; |
---|
157 | } |
---|
158 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
159 | unsigned int reg9 = REG_RAD2_TX_LINEARITY & mask; |
---|
160 | reg9 = reg9 + value; |
---|
161 | transRadio(0x0002, ((reg9<<4)+0x0009)); |
---|
162 | |
---|
163 | REG_RAD2_TX_LINEARITY = (short)reg9; |
---|
164 | } |
---|
165 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
166 | unsigned int reg9 = REG_RAD3_TX_LINEARITY & mask; |
---|
167 | reg9 = reg9 + value; |
---|
168 | transRadio(0x0004, ((reg9<<4)+0x0009)); |
---|
169 | |
---|
170 | REG_RAD3_TX_LINEARITY = (short)reg9; |
---|
171 | } |
---|
172 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
173 | unsigned int reg9 = REG_RAD4_TX_LINEARITY & mask; |
---|
174 | reg9 = reg9 + value; |
---|
175 | transRadio(0x0008, ((reg9<<4)+0x0009)); |
---|
176 | |
---|
177 | REG_RAD4_TX_LINEARITY = (short)reg9; |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | /** |
---|
182 | * @brief Adjust total transmit gain. |
---|
183 | * |
---|
184 | * This function adjusts the total transmit gain when using software control. |
---|
185 | * The 6 bits of this function map to B6:B1 of the gain bus. 000000 is the lowest possible gain. |
---|
186 | * |
---|
187 | * @see WarpRadio_v1_SoftwareTxGainControl |
---|
188 | * @param value Gain value, 6 bits wide. |
---|
189 | * @param radios Radios affected. |
---|
190 | */ |
---|
191 | void WarpRadio_v1_TxVGAGainControl(char value, unsigned int radios) { |
---|
192 | |
---|
193 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
194 | |
---|
195 | value = value & 0x003F; |
---|
196 | int mask = 0xFFC0; |
---|
197 | |
---|
198 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
199 | unsigned int reg12 = REG_RAD1_TX_VGA_GAIN & mask; |
---|
200 | reg12 = reg12 + value; |
---|
201 | transRadio(0x0001, ((reg12<<4)+0x000C)); |
---|
202 | |
---|
203 | REG_RAD1_TX_VGA_GAIN = (short)reg12; |
---|
204 | } |
---|
205 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
206 | unsigned int reg12 = REG_RAD2_TX_VGA_GAIN & mask; |
---|
207 | reg12 = reg12 + value; |
---|
208 | transRadio(0x0002, ((reg12<<4)+0x000C)); |
---|
209 | |
---|
210 | REG_RAD2_TX_VGA_GAIN = (short)reg12; |
---|
211 | } |
---|
212 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
213 | unsigned int reg12 = REG_RAD3_TX_VGA_GAIN & mask; |
---|
214 | reg12 = reg12 + value; |
---|
215 | transRadio(0x0004, ((reg12<<4)+0x000C)); |
---|
216 | |
---|
217 | REG_RAD3_TX_VGA_GAIN = (short)reg12; |
---|
218 | } |
---|
219 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
220 | unsigned int reg12 = REG_RAD4_TX_VGA_GAIN & mask; |
---|
221 | reg12 = reg12 + value; |
---|
222 | transRadio(0x0008, ((reg12<<4)+0x000C)); |
---|
223 | |
---|
224 | REG_RAD4_TX_VGA_GAIN = (short)reg12; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | /** |
---|
230 | * @brief Control recieve gain in software/hardware. |
---|
231 | * |
---|
232 | * Enable or disable receive VGA/LNA Gain programming using software. If in software, RxVGAGainControl |
---|
233 | * and RxLNAGainControl must be used to set gain value. |
---|
234 | * |
---|
235 | * @see WarpRadio_v1_RxVGAGainControl, WarpRadio_v1_RxLNAGainControl |
---|
236 | * @param mode 0: Receive VGA/LNA Gain programmed with external ports, 1: programmed with functions mentioned above |
---|
237 | * @param radios Radios affected. |
---|
238 | * @return Returns INVALID_MODE if the mode is an invalid input, WARP_SUCCESS if successful. |
---|
239 | */ |
---|
240 | char WarpRadio_v1_SoftwareRxGainControl(short mode, unsigned int radios) { |
---|
241 | |
---|
242 | if (mode == 0 | mode == 1) { |
---|
243 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
244 | |
---|
245 | mode = mode & 0x0001; |
---|
246 | mode = mode << 12; |
---|
247 | int mask = 0xEFFF; |
---|
248 | |
---|
249 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
250 | unsigned int reg8 = REG_RAD1_RX_CONTROL & mask; |
---|
251 | reg8 = reg8 + mode; |
---|
252 | transRadio(0x0001, ((reg8<<4)+0x0008)); |
---|
253 | |
---|
254 | REG_RAD1_RX_CONTROL = (short)reg8; |
---|
255 | } |
---|
256 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
257 | unsigned int reg8 = REG_RAD2_RX_CONTROL & mask; |
---|
258 | reg8 = reg8 + mode; |
---|
259 | transRadio(0x0002, ((reg8<<4)+0x0008)); |
---|
260 | |
---|
261 | REG_RAD2_RX_CONTROL = (short)reg8; |
---|
262 | } |
---|
263 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
264 | unsigned int reg8 = REG_RAD3_RX_CONTROL & mask; |
---|
265 | reg8 = reg8 + mode; |
---|
266 | transRadio(0x0004, ((reg8<<4)+0x0008)); |
---|
267 | |
---|
268 | REG_RAD3_RX_CONTROL = (short)reg8; |
---|
269 | } |
---|
270 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
271 | unsigned int reg8 = REG_RAD4_RX_CONTROL & mask; |
---|
272 | reg8 = reg8 + mode; |
---|
273 | transRadio(0x0008, ((reg8<<4)+0x0008)); |
---|
274 | |
---|
275 | REG_RAD4_RX_CONTROL = (short)reg8; |
---|
276 | } |
---|
277 | } |
---|
278 | else { |
---|
279 | return INVALID_MODE; |
---|
280 | } |
---|
281 | |
---|
282 | return WARP_SUCCESS; |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | /** |
---|
287 | * @brief Adjust upper receive gain. |
---|
288 | * |
---|
289 | * This function combined with RxVGAGainControl adjusts the total recieve gain when using software |
---|
290 | * control. The 2 bits of this function map to B7:B6 of gain bus. 00 is the lowest possible gain. |
---|
291 | * |
---|
292 | * @see WarpRadio_v1_SoftwareRxGainControl, WarpRadio_v1_RxVGAGainControl |
---|
293 | * @param value Gain value, 2 bits wide. |
---|
294 | * @param radios Radios affected. |
---|
295 | */ |
---|
296 | void WarpRadio_v1_RxLNAGainControl(char value, unsigned int radios) { |
---|
297 | |
---|
298 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
299 | |
---|
300 | value = value & 0x0003; |
---|
301 | value = value << 5; |
---|
302 | int mask = 0xFF9F; |
---|
303 | |
---|
304 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
305 | unsigned int reg11 = REG_RAD1_RX_GAIN & mask; |
---|
306 | reg11 = reg11 + value; |
---|
307 | transRadio(0x0001, ((reg11<<4)+0x000B)); |
---|
308 | |
---|
309 | REG_RAD1_RX_GAIN = (short)reg11; |
---|
310 | } |
---|
311 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
312 | unsigned int reg11 = REG_RAD2_RX_GAIN & mask; |
---|
313 | reg11 = reg11 + value; |
---|
314 | transRadio(0x0002, ((reg11<<4)+0x000B)); |
---|
315 | |
---|
316 | REG_RAD2_RX_GAIN = (short)reg11; |
---|
317 | } |
---|
318 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
319 | unsigned int reg11 = REG_RAD3_RX_GAIN & mask; |
---|
320 | reg11 = reg11 + value; |
---|
321 | transRadio(0x0004, ((reg11<<4)+0x000B)); |
---|
322 | |
---|
323 | REG_RAD3_RX_GAIN = (short)reg11; |
---|
324 | } |
---|
325 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
326 | unsigned int reg11 = REG_RAD4_RX_GAIN & mask; |
---|
327 | reg11 = reg11 + value; |
---|
328 | transRadio(0x0008, ((reg11<<4)+0x000B)); |
---|
329 | |
---|
330 | REG_RAD4_RX_GAIN = (short)reg11; |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | /** |
---|
335 | * @brief Adjust lower receive gain. |
---|
336 | * |
---|
337 | * This function combined with RxLNAGainControl adjusts the total recieve gain when using software |
---|
338 | * control. The 5 bits of this function map to B5:B1 of gain bus. 00000 is the lowest possible gain. |
---|
339 | * |
---|
340 | * @see WarpRadio_v1_SoftwareRxGainControl, WarpRadio_v1_RxLNAGainControl |
---|
341 | * @param value Gain value, 5 bits wide. |
---|
342 | * @param radios Radios affected. |
---|
343 | */ |
---|
344 | void WarpRadio_v1_RxVGAGainControl(char value, unsigned int radios) { |
---|
345 | |
---|
346 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
347 | |
---|
348 | value = value & 0x001F; |
---|
349 | int mask = 0xFFE0; |
---|
350 | |
---|
351 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
352 | unsigned int reg11 = REG_RAD1_RX_GAIN & mask; |
---|
353 | reg11 = reg11 + value; |
---|
354 | transRadio(0x0001, ((reg11<<4)+0x000B)); |
---|
355 | |
---|
356 | REG_RAD1_RX_GAIN = (short)reg11; |
---|
357 | } |
---|
358 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
359 | unsigned int reg11 = REG_RAD2_RX_GAIN & mask; |
---|
360 | reg11 = reg11 + value; |
---|
361 | transRadio(0x0002, ((reg11<<4)+0x000B)); |
---|
362 | |
---|
363 | REG_RAD2_RX_GAIN = (short)reg11; |
---|
364 | } |
---|
365 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
366 | unsigned int reg11 = REG_RAD3_RX_GAIN & mask; |
---|
367 | reg11 = reg11 + value; |
---|
368 | transRadio(0x0004, ((reg11<<4)+0x000B)); |
---|
369 | |
---|
370 | REG_RAD3_RX_GAIN = (short)reg11; |
---|
371 | } |
---|
372 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
373 | unsigned int reg11 = REG_RAD4_RX_GAIN & mask; |
---|
374 | reg11 = reg11 + value; |
---|
375 | transRadio(0x0008, ((reg11<<4)+0x000B)); |
---|
376 | |
---|
377 | REG_RAD4_RX_GAIN = (short)reg11; |
---|
378 | } |
---|
379 | } |
---|
380 | |
---|
381 | |
---|
382 | /** |
---|
383 | * @brief Setup timing parameters for the transmit state machine. |
---|
384 | * |
---|
385 | * The transmit state machine gets triggered by the TxEnable function. When called, there is a delay |
---|
386 | * in turning on the TxEnable pin, the trigger for data transmission, the amplifier and the gain ramp |
---|
387 | * cycle (parameters set by WarpRadio_v1_SetTxGainTiming). All these paramenters are setup here. |
---|
388 | * For the gain parameters to be valid, must be in hardware gain control. Atleast one amplifier |
---|
389 | * must be enabled for the power amp enable to work. |
---|
390 | * |
---|
391 | * @see WarpRadio_v1_SetTxGainTiming |
---|
392 | * @param radios Radios affected by these settings. |
---|
393 | * @param dly_TxEn OPB clock cycles to wait before turning on transmit enable. dly_TxEn=0 enables TxEn forever; dly_TxEn=255 disables TxEn forever |
---|
394 | * @param dly_TxStart OPB clock cycles to wait before sending enabling data transmission model. dly_TxStart=0 enables TxStart forever; dly_TxStart=255 disables TxStart forever |
---|
395 | * @param dly_GainRampEn OPB clock cycles to wait before turning on gain ramp cycle. dly_GainRampEn=255 disables the gain ramp |
---|
396 | * @param dly_PowerAmpEn OPB clock cycles to wait before turning on amplifier. dly_PowerAmpEn=0 enables PowerAmpEn forever; dly_PowerAmpEn=255 disables PowerAmpEn forever |
---|
397 | */ |
---|
398 | void WarpRadio_v1_SetTxTiming(unsigned int radios, unsigned char dly_TxEn, unsigned short dly_TxStart, unsigned char dly_GainRampEn, unsigned char dly_PowerAmpEn) { |
---|
399 | |
---|
400 | //TxTiming values stored in two registers per radio: |
---|
401 | // GainRampEn - slv_reg{13,14,15,16}[0:7] |
---|
402 | // PowerAmpEn - slv_reg{13,14,15,16}[8:15] |
---|
403 | // TxEn - slv_reg{13,14,15,16}[16:23] |
---|
404 | // TxStart - slv_reg{09,10,11,12}[16:27] |
---|
405 | //Endian change swaps LSB/MSB in C<->Verilog |
---|
406 | |
---|
407 | unsigned int regValA, regValB; |
---|
408 | unsigned int regMaskA = 0xFFFFFF00; //mask[0:23] for regs13/14/15/16 |
---|
409 | unsigned int regMaskB = 0x0000FFF0; //mask[16:27] for regs09/10/11/12 |
---|
410 | |
---|
411 | //Mask the input parameters to their max sizes, then shift to their positions in each register |
---|
412 | regValA = ((dly_GainRampEn & 0xFF) << 24 ) | ((dly_PowerAmpEn & 0xFF) << 16 ) | ((dly_TxEn & 0xFF) << 8 ); |
---|
413 | regValB = ((dly_TxStart & 0xFFF) << 4); |
---|
414 | |
---|
415 | if(((SLAVEMASK & radios) & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
416 | RADIO_CONTROLLER_mWriteSlaveReg13((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg13((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
417 | RADIO_CONTROLLER_mWriteSlaveReg9((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg9((volatile)radio_controller_baseaddr) & ~regMaskB) | regValB ); |
---|
418 | } |
---|
419 | if(((SLAVEMASK & radios) & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
420 | RADIO_CONTROLLER_mWriteSlaveReg14((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg14((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
421 | RADIO_CONTROLLER_mWriteSlaveReg10((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg10((volatile)radio_controller_baseaddr) & ~regMaskB) | regValB ); |
---|
422 | } |
---|
423 | if(((SLAVEMASK & radios) & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
424 | RADIO_CONTROLLER_mWriteSlaveReg15((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg15((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
425 | RADIO_CONTROLLER_mWriteSlaveReg11((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg11((volatile)radio_controller_baseaddr) & ~regMaskB) | regValB ); |
---|
426 | } |
---|
427 | if(((SLAVEMASK & radios) & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
428 | RADIO_CONTROLLER_mWriteSlaveReg16((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg16((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
429 | RADIO_CONTROLLER_mWriteSlaveReg12((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg12((volatile)radio_controller_baseaddr) & ~regMaskB) | regValB ); |
---|
430 | } |
---|
431 | |
---|
432 | return; |
---|
433 | } |
---|
434 | |
---|
435 | /** |
---|
436 | * @brief Setup gain parameters for transmit state machine. |
---|
437 | * |
---|
438 | * The gain parameters are used when the gain ramp is triggered by WarpRadio_v1_SetTxTiming. |
---|
439 | * The gain ramping is automatic and for it to be valid, the gain settings for transmit must be |
---|
440 | * in hardware control as the ramping is done using the gain bus. |
---|
441 | * |
---|
442 | * @see WarpRadio_v1_SetTxTiming, WarpRadio_v1_SoftwareTxGainControl |
---|
443 | * @param radios Radios affected by these settings. |
---|
444 | * @param TxGainTarget Target transmit gain, x0 to x3F |
---|
445 | * @param TxGainStep Step with which to ramp to required gain |
---|
446 | * @param TxGainTimeStep Time paused on each gain step |
---|
447 | */ |
---|
448 | void WarpRadio_v1_SetTxGainTiming(unsigned int radios, unsigned char TxGainTarget, unsigned char TxGainStep, unsigned char TxGainTimeStep) { |
---|
449 | |
---|
450 | //TxTiming values stored in two registers per radio: |
---|
451 | // TxGainTarget - slv_reg{09,10,11,12}[0:5] |
---|
452 | // TxGainStep - slv_reg{09,10,11,12}[6:9] |
---|
453 | // TxGainTimeStep - slv_reg{09,10,11,12}[10:13] |
---|
454 | //Endian change swaps LSB/MSB in C<->Verilog |
---|
455 | |
---|
456 | unsigned int regValA; |
---|
457 | unsigned int regMaskA = 0xFFFC0000; //mask[0:13] for regs9/10/11/12 |
---|
458 | |
---|
459 | regValA = ((TxGainTarget & 0x3F) << 26) | ((TxGainStep & 0xF) << 22) | ((TxGainTimeStep & 0xF) << 18); |
---|
460 | |
---|
461 | if(((SLAVEMASK & radios) & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
462 | RADIO_CONTROLLER_mWriteSlaveReg9((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg9((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
463 | } |
---|
464 | if(((SLAVEMASK & radios) & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
465 | RADIO_CONTROLLER_mWriteSlaveReg10((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg10((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
466 | } |
---|
467 | if(((SLAVEMASK & radios) & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
468 | RADIO_CONTROLLER_mWriteSlaveReg11((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg11((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
469 | } |
---|
470 | if(((SLAVEMASK & radios) & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
471 | RADIO_CONTROLLER_mWriteSlaveReg12((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg12((volatile)radio_controller_baseaddr) & ~regMaskA) | regValA ); |
---|
472 | } |
---|
473 | |
---|
474 | return; |
---|
475 | } |
---|
476 | |
---|
477 | /** |
---|
478 | * @brief Set lowpass filter corner frequency on transmit (coarse adjustment). |
---|
479 | * |
---|
480 | * Set the Transmit Lowpass Filter Corner Frequency. This is the Coarse adjustment. |
---|
481 | * The values are chosen from the following list: |
---|
482 | * - 0: undefined |
---|
483 | * - 1: 12MHz (nominal mode) |
---|
484 | * - 2: 18MHz (turbo mode 1) |
---|
485 | * - 3: 24MHz (turbo mode 2) |
---|
486 | * |
---|
487 | * @param value Chosed from the above list. |
---|
488 | * @param radios Radios affected. |
---|
489 | * @return Returns OUT_OF_RANGE if value is out of range, WARP_SUCCESS if successful. |
---|
490 | */ |
---|
491 | void WarpRadio_v1_TxLpfCornFreqCoarseAdj(char value, unsigned int radios) { |
---|
492 | |
---|
493 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
494 | |
---|
495 | value = value & 0x0003; // Pick the last 2 bits of the value provided. |
---|
496 | value = value << 5; // Shift the bits to the right location. |
---|
497 | int mask = 0xFF9F; // Mask to empty the value currently in the register. |
---|
498 | |
---|
499 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
500 | unsigned int reg7 = REG_RAD1_LOWPASS_FILTER & mask; // Empty the two bits |
---|
501 | reg7 = reg7 + value; // Put the new value in |
---|
502 | transRadio(0x0001, ((reg7<<4)+0x0007)); // Transmit the new value |
---|
503 | |
---|
504 | REG_RAD1_LOWPASS_FILTER = (short)reg7; // Store to the local copies |
---|
505 | } |
---|
506 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
507 | unsigned int reg7 = REG_RAD2_LOWPASS_FILTER & mask; |
---|
508 | reg7 = reg7 + value; |
---|
509 | transRadio(0x0002, ((reg7<<4)+0x0007)); |
---|
510 | |
---|
511 | REG_RAD2_LOWPASS_FILTER = (short)reg7; |
---|
512 | } |
---|
513 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
514 | unsigned int reg7 = REG_RAD3_LOWPASS_FILTER & mask; |
---|
515 | reg7 = reg7 + value; |
---|
516 | transRadio(0x0004, ((reg7<<4)+0x0007)); |
---|
517 | |
---|
518 | REG_RAD3_LOWPASS_FILTER = (short)reg7; |
---|
519 | } |
---|
520 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
521 | unsigned int reg7 = REG_RAD4_LOWPASS_FILTER & mask; |
---|
522 | reg7 = reg7 + value; |
---|
523 | transRadio(0x0008, ((reg7<<4)+0x0007)); |
---|
524 | |
---|
525 | REG_RAD4_LOWPASS_FILTER = (short)reg7; |
---|
526 | } |
---|
527 | } |
---|
528 | |
---|
529 | /** |
---|
530 | * @brief Set lowpass filter corner frequency on receive (coarse adjustment). |
---|
531 | * |
---|
532 | * Set the Recieve Lowpass Filter Corner Frequency. This is the Coarse adjustment. |
---|
533 | * The values are chosen from the following list: |
---|
534 | * - 0: 7.5MHz |
---|
535 | * - 1: 9.5MHz (nominal mode) |
---|
536 | * - 2: 14MHz (turbo mode 1) |
---|
537 | * - 3: 18MHz (turbo mode 2) |
---|
538 | * |
---|
539 | * @param value Chosed from the above list. |
---|
540 | * @param radios Radios affected. |
---|
541 | * @return Returns OUT_OF_RANGE if value is out of range, WARP_SUCCESS if successful. |
---|
542 | */ |
---|
543 | void WarpRadio_v1_RxLpfCornFreqCoarseAdj(char value, unsigned int radios) { |
---|
544 | |
---|
545 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
546 | |
---|
547 | value = value & 0x0003; |
---|
548 | value = value << 3; |
---|
549 | int mask = 0xFFE7; |
---|
550 | |
---|
551 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
552 | unsigned int reg7 = REG_RAD1_LOWPASS_FILTER & mask; |
---|
553 | reg7 = reg7 + value; |
---|
554 | transRadio(0x0001, ((reg7<<4)+0x0007)); |
---|
555 | |
---|
556 | REG_RAD1_LOWPASS_FILTER = (short)reg7; |
---|
557 | } |
---|
558 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
559 | unsigned int reg7 = REG_RAD2_LOWPASS_FILTER & mask; |
---|
560 | reg7 = reg7 + value; |
---|
561 | transRadio(0x0002, ((reg7<<4)+0x0007)); |
---|
562 | |
---|
563 | REG_RAD2_LOWPASS_FILTER = (short)reg7; |
---|
564 | } |
---|
565 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
566 | unsigned int reg7 = REG_RAD3_LOWPASS_FILTER & mask; |
---|
567 | reg7 = reg7 + value; |
---|
568 | transRadio(0x0004, ((reg7<<4)+0x0007)); |
---|
569 | |
---|
570 | REG_RAD3_LOWPASS_FILTER = (short)reg7; |
---|
571 | } |
---|
572 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
573 | unsigned int reg7 = REG_RAD4_LOWPASS_FILTER & mask; |
---|
574 | reg7 = reg7 + value; |
---|
575 | transRadio(0x0008, ((reg7<<4)+0x0007)); |
---|
576 | |
---|
577 | REG_RAD4_LOWPASS_FILTER = (short)reg7; |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | /** |
---|
582 | * @brief Set lowpass filter corner frequency on receive (fine adjustment). |
---|
583 | * |
---|
584 | * Set the Recieve Lowpass Filter Corner Frequency. This is the Fine adjustment. |
---|
585 | * The values are chosen from the following list: |
---|
586 | * - 000: 90% |
---|
587 | * - 001: 95% |
---|
588 | * - 010: 100% |
---|
589 | * - 011: 105% |
---|
590 | * - 100: 110% |
---|
591 | * - 101-111: not applicable |
---|
592 | * |
---|
593 | * @param value Chosed from the above list. |
---|
594 | * @param radios Radios affected. |
---|
595 | * @return Returns OUT_OF_RANGE if value is out of range, WARP_SUCCESS if successful. |
---|
596 | */ |
---|
597 | char WarpRadio_v1_RxLpfCornFreqFineAdj(char value, unsigned int radios) { |
---|
598 | |
---|
599 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
600 | |
---|
601 | value = value & 0x0007; |
---|
602 | int mask = 0xFFF8; |
---|
603 | |
---|
604 | if (value == 5 || value == 6 || value == 7) { // Make sure the the value is not out of the specified range. |
---|
605 | return OUT_OF_RANGE; |
---|
606 | } |
---|
607 | |
---|
608 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
609 | unsigned int reg7 = REG_RAD1_LOWPASS_FILTER & mask; |
---|
610 | reg7 = reg7 + value; |
---|
611 | transRadio(0x0001, ((reg7<<4)+0x0007)); |
---|
612 | |
---|
613 | REG_RAD1_LOWPASS_FILTER = (short)reg7; |
---|
614 | } |
---|
615 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
616 | unsigned int reg7 = REG_RAD2_LOWPASS_FILTER & mask; |
---|
617 | reg7 = reg7 + value; |
---|
618 | transRadio(0x0002, ((reg7<<4)+0x0007)); |
---|
619 | |
---|
620 | REG_RAD2_LOWPASS_FILTER = (short)reg7; |
---|
621 | } |
---|
622 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
623 | unsigned int reg7 = REG_RAD3_LOWPASS_FILTER & mask; |
---|
624 | reg7 = reg7 + value; |
---|
625 | transRadio(0x0004, ((reg7<<4)+0x0007)); |
---|
626 | |
---|
627 | REG_RAD3_LOWPASS_FILTER = (short)reg7; |
---|
628 | } |
---|
629 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
630 | unsigned int reg7 = REG_RAD4_LOWPASS_FILTER & mask; |
---|
631 | reg7 = reg7 + value; |
---|
632 | transRadio(0x0008, ((reg7<<4)+0x0007)); |
---|
633 | |
---|
634 | REG_RAD4_LOWPASS_FILTER = (short)reg7; |
---|
635 | } |
---|
636 | return WARP_SUCCESS; |
---|
637 | } |
---|
638 | |
---|
639 | |
---|
640 | /** |
---|
641 | * @brief Set corner frequency for receive high pass filter. |
---|
642 | * |
---|
643 | * Set the Recieve Highpass Filter Corner Frequency when RXHP=0. |
---|
644 | * |
---|
645 | * @param value 0: 100Hz, 1: 30kHz |
---|
646 | * @param radios Radios affected by function. |
---|
647 | */ |
---|
648 | void WarpRadio_v1_RxHighPassCornerFreq(char value, unsigned int radios) { |
---|
649 | |
---|
650 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios)); // Select Radios affected by this function |
---|
651 | |
---|
652 | value = value & 0x0001; |
---|
653 | value = value << 2; |
---|
654 | int mask = 0xFFFB; |
---|
655 | |
---|
656 | if((radios & RAD1MASK) > 0) { // Check to make sure if Radio 1 is being used |
---|
657 | unsigned int reg8 = REG_RAD1_RX_CONTROL & mask; |
---|
658 | reg8 = reg8 + value; |
---|
659 | transRadio(0x0001, ((reg8<<4)+0x0008)); |
---|
660 | |
---|
661 | REG_RAD1_RX_CONTROL = (short)reg8; |
---|
662 | } |
---|
663 | if((radios & RAD2MASK) > 0) { // Check to make sure if Radio 2 is being used |
---|
664 | unsigned int reg8 = REG_RAD2_RX_CONTROL & mask; |
---|
665 | reg8 = reg8 + value; |
---|
666 | transRadio(0x0002, ((reg8<<4)+0x0008)); |
---|
667 | |
---|
668 | REG_RAD2_RX_CONTROL = (short)reg8; |
---|
669 | } |
---|
670 | if((radios & RAD3MASK) > 0) { // Check to make sure if Radio 3 is being used |
---|
671 | unsigned int reg8 = REG_RAD3_RX_CONTROL & mask; |
---|
672 | reg8 = reg8 + value; |
---|
673 | transRadio(0x0004, ((reg8<<4)+0x0008)); |
---|
674 | |
---|
675 | REG_RAD3_RX_CONTROL = (short)reg8; |
---|
676 | } |
---|
677 | if((radios & RAD4MASK) > 0) { // Check to make sure if Radio 4 is being used |
---|
678 | unsigned int reg8 = REG_RAD4_RX_CONTROL & mask; |
---|
679 | reg8 = reg8 + value; |
---|
680 | transRadio(0x0008, ((reg8<<4)+0x0008)); |
---|
681 | |
---|
682 | REG_RAD4_RX_CONTROL = (short)reg8; |
---|
683 | } |
---|
684 | } |
---|
685 | |
---|
686 | /** |
---|
687 | * @brief Read instantaneous RSSI. |
---|
688 | * |
---|
689 | * Reads the RSSI values for a single radio only. |
---|
690 | * |
---|
691 | * @param radios Radio from to read data. |
---|
692 | * @return RSSI data |
---|
693 | */ |
---|
694 | unsigned int WarpRadio_v1_RSSIData(unsigned int radios) { |
---|
695 | |
---|
696 | unsigned int rssi = 0; |
---|
697 | |
---|
698 | if(radios & RAD1MASK) |
---|
699 | rssi = RADIO_CONTROLLER_mReadSlaveReg3((volatile)radio_controller_baseaddr) & 0x3FF; |
---|
700 | |
---|
701 | else if(radios & RAD2MASK) |
---|
702 | rssi = (RADIO_CONTROLLER_mReadSlaveReg3((volatile)radio_controller_baseaddr) & 0x3FF0000)>>16; |
---|
703 | |
---|
704 | else if(radios & RAD3MASK) |
---|
705 | rssi = RADIO_CONTROLLER_mReadSlaveReg4((volatile)radio_controller_baseaddr) & 0x3FF; |
---|
706 | |
---|
707 | else if(radios & RAD4MASK) |
---|
708 | rssi = (RADIO_CONTROLLER_mReadSlaveReg4((volatile)radio_controller_baseaddr) & 0x3FF0000)>>16; |
---|
709 | |
---|
710 | return rssi; |
---|
711 | } |
---|
712 | |
---|