root/PlatformSupport/CustomPeripherals/drivers/radio_controller_v1_09_a/src/radio_controller_ext.c

Revision 705, 25.1 kB (checked in by sgupta, 12 months ago)

docs

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_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 */
32void 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 */
45void 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
57char 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 */
69char 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 */
86char 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 */
144void 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 */
191void 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 */
240char 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 */
296void 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 */
344void 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
394 * @param dly_TxStart OPB clock cycles to wait before sending enabling data transmission model
395 * @param dly_GainRampEn OPB clock cycles to wait before turning on gain ramp cycle
396 * @param dly_PowerAmpEn OPB clock cycles to wait before turning on amplifier
397 */
398void WarpRadio_v1_SetTxTiming(unsigned int radios, unsigned char dly_TxEn, unsigned char dly_TxStart, unsigned char dly_GainRampEn, unsigned char dly_PowerAmpEn) {
399
400        //GainRampEn - slv_reg_N[0:7]
401        //PowerAmpEn - slv_reg_N[8:15]
402        //TxEn - slv_reg_N[16:23]
403        //TxStart - slv_reg_N[24:31]
404
405        if(((SLAVEMASK & radios) & RAD1MASK) > 0) {             // Check to make sure if Radio 1 is being used
406                RADIO_CONTROLLER_mWriteSlaveReg13((volatile)radio_controller_baseaddr,(unsigned int)( (dly_GainRampEn << 24) + (dly_PowerAmpEn << 16) + (dly_TxEn << 8) + dly_TxStart ));
407        }
408        if(((SLAVEMASK & radios) & RAD2MASK) > 0) {             // Check to make sure if Radio 2 is being used
409                RADIO_CONTROLLER_mWriteSlaveReg14((volatile)radio_controller_baseaddr,(unsigned int)( (dly_GainRampEn << 24) + (dly_PowerAmpEn << 16) + (dly_TxEn << 8) + dly_TxStart ));
410        }
411        if(((SLAVEMASK & radios) & RAD3MASK) > 0) {             // Check to make sure if Radio 3 is being used
412                RADIO_CONTROLLER_mWriteSlaveReg15((volatile)radio_controller_baseaddr,(unsigned int)( (dly_GainRampEn << 24) + (dly_PowerAmpEn << 16) + (dly_TxEn << 8) + dly_TxStart ));
413        }
414        if(((SLAVEMASK & radios) & RAD4MASK) > 0) {             // Check to make sure if Radio 4 is being used
415                RADIO_CONTROLLER_mWriteSlaveReg16((volatile)radio_controller_baseaddr,(unsigned int)( (dly_GainRampEn << 24) + (dly_PowerAmpEn << 16) + (dly_TxEn << 8) + dly_TxStart ));
416        }
417
418        return;
419}
420
421/**
422 * @brief Setup gain parameters for transmit state machine.
423 *
424 * The gain parameters are used when the gain ramp is triggered by WarpRadio_v1_SetTxTiming.
425 * The gain ramping is automatic and for it to be valid, the gain settings for transmit must be
426 * in hardware control as the ramping is done using the gain bus.
427 *
428 * @see WarpRadio_v1_SetTxTiming, WarpRadio_v1_SoftwareTxGainControl
429 * @param radios Radios affected by these settings.
430 * @param TxGainTarget Target transmit gain, x0 to x3F
431 * @param TxGainStep Step with which to ramp to required gain
432 * @param TxGainTimeStep Time paused on each gain step
433 */
434void WarpRadio_v1_SetTxGainTiming(unsigned int radios, unsigned char TxGainTarget, unsigned char TxGainStep, unsigned char TxGainTimeStep) {
435
436        //TxGainTarget is a 6-bit value in the MSB of the register (slv_reg_N[0:5])
437        //TxGainStep is a 4-bit value (slv_reg_N[6:9])
438        //TxGainTimeStep is a 4-bit value (slv_reg_N[10:13])
439
440        if(((SLAVEMASK & radios) & RAD1MASK) > 0) {             // Check to make sure if Radio 1 is being used
441                RADIO_CONTROLLER_mWriteSlaveReg9((volatile)radio_controller_baseaddr,(unsigned int)( ((0x3f & TxGainTarget) << 26) | ((0xf & TxGainStep) << 22) | ((0xf & TxGainTimeStep) << 18)));
442        }
443        if(((SLAVEMASK & radios) & RAD2MASK) > 0) {             // Check to make sure if Radio 2 is being used
444                RADIO_CONTROLLER_mWriteSlaveReg10((volatile)radio_controller_baseaddr,(unsigned int)( ((0x3f & TxGainTarget) << 26) | ((0xf & TxGainStep) << 22) | ((0xf & TxGainTimeStep) << 18)));
445        }
446        if(((SLAVEMASK & radios) & RAD3MASK) > 0) {             // Check to make sure if Radio 3 is being used
447                RADIO_CONTROLLER_mWriteSlaveReg11((volatile)radio_controller_baseaddr,(unsigned int)( ((0x3f & TxGainTarget) << 26) | ((0xf & TxGainStep) << 22) | ((0xf & TxGainTimeStep) << 18)));
448        }
449        if(((SLAVEMASK & radios) & RAD4MASK) > 0) {             // Check to make sure if Radio 4 is being used
450                RADIO_CONTROLLER_mWriteSlaveReg12((volatile)radio_controller_baseaddr,(unsigned int)( ((0x3f & TxGainTarget) << 26) | ((0xf & TxGainStep) << 22) | ((0xf & TxGainTimeStep) << 18)));
451        }
452
453        return;
454}
455
456/**
457 * @brief Set lowpass filter corner frequency on transmit (coarse adjustment).
458 *
459 * Set the Transmit Lowpass Filter Corner Frequency. This is the Coarse adjustment.
460 * The values are chosen from the following list:
461 *              - 00: undefined
462 *              - 01: 12MHz (nominal mode)
463 *              - 10: 18MHz (turbo mode 1)
464 *              - 11: 24MHz (turbo mode 2)
465 *
466 * @param value Chosed from the above list.
467 * @param radios Radios affected.
468 * @return Returns OUT_OF_RANGE if value is out of range, WARP_SUCCESS if successful.
469 */
470void WarpRadio_v1_TxLpfCornFreqCoarseAdj(char value, unsigned int radios) {
471
472        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));                    // Select Radios affected by this function
473
474        value = value & 0x0003;                                         // Pick the last 2 bits of the value provided.
475        value = value << 5;                                                     // Shift the bits to the right location.
476        int mask = 0xFF9F;                                                      // Mask to empty the value currently in the register.
477
478        if((radios & RAD1MASK) > 0) {           // Check to make sure if Radio 1 is being used
479                unsigned int reg7 = REG_RAD1_LOWPASS_FILTER & mask;             // Empty the two bits
480                reg7 = reg7 + value;                                                                    // Put the new value in
481                transRadio(0x0001, ((reg7<<4)+0x0007));         // Transmit the new value
482
483                REG_RAD1_LOWPASS_FILTER = (short)reg7;                                  // Store to the local copies
484        }
485        if((radios & RAD2MASK) > 0) {           // Check to make sure if Radio 2 is being used
486                unsigned int reg7 = REG_RAD2_LOWPASS_FILTER & mask;
487                reg7 = reg7 + value;
488                transRadio(0x0002, ((reg7<<4)+0x0007));
489
490                REG_RAD2_LOWPASS_FILTER = (short)reg7;
491        }
492        if((radios & RAD3MASK) > 0) {           // Check to make sure if Radio 3 is being used
493                unsigned int reg7 = REG_RAD3_LOWPASS_FILTER & mask;
494                reg7 = reg7 + value;
495                transRadio(0x0004, ((reg7<<4)+0x0007));
496
497                REG_RAD3_LOWPASS_FILTER = (short)reg7;
498        }
499        if((radios & RAD4MASK) > 0) {           // Check to make sure if Radio 4 is being used
500                unsigned int reg7 = REG_RAD4_LOWPASS_FILTER & mask;
501                reg7 = reg7 + value;
502                transRadio(0x0008, ((reg7<<4)+0x0007));
503
504                REG_RAD4_LOWPASS_FILTER = (short)reg7;
505        }
506}
507
508/**
509 * @brief Set lowpass filter corner frequency on receive (coarse adjustment).
510 *
511 * Set the Recieve Lowpass Filter Corner Frequency. This is the Coarse adjustment.
512 * The values are chosen from the following list:
513 *              - 00: 7.5MHz
514 *              - 01: 9.5MHz (nominal mode)
515 *              - 10: 14MHz (turbo mode 1)
516 *              - 11: 18MHz (turbo mode 2)
517 *
518 * @param value Chosed from the above list.
519 * @param radios Radios affected.
520 * @return Returns OUT_OF_RANGE if value is out of range, WARP_SUCCESS if successful.
521 */
522void WarpRadio_v1_RxLpfCornFreqCoarseAdj(char value, unsigned int radios) {
523
524        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));                    // Select Radios affected by this function
525
526        value = value & 0x0003;
527        value = value << 3;
528        int mask = 0xFFE7;
529
530        if((radios & RAD1MASK) > 0) {           // Check to make sure if Radio 1 is being used
531                unsigned int reg7 = REG_RAD1_LOWPASS_FILTER & mask;
532                reg7 = reg7 + value;
533                transRadio(0x0001, ((reg7<<4)+0x0007));
534
535                REG_RAD1_LOWPASS_FILTER = (short)reg7;
536        }
537        if((radios & RAD2MASK) > 0) {           // Check to make sure if Radio 2 is being used
538                unsigned int reg7 = REG_RAD2_LOWPASS_FILTER & mask;
539                reg7 = reg7 + value;
540                transRadio(0x0002, ((reg7<<4)+0x0007));
541
542                REG_RAD2_LOWPASS_FILTER = (short)reg7;
543        }
544        if((radios & RAD3MASK) > 0) {           // Check to make sure if Radio 3 is being used
545                unsigned int reg7 = REG_RAD3_LOWPASS_FILTER & mask;
546                reg7 = reg7 + value;
547                transRadio(0x0004, ((reg7<<4)+0x0007));
548
549                REG_RAD3_LOWPASS_FILTER = (short)reg7;
550        }
551        if((radios & RAD4MASK) > 0) {           // Check to make sure if Radio 4 is being used
552                unsigned int reg7 = REG_RAD4_LOWPASS_FILTER & mask;
553                reg7 = reg7 + value;
554                transRadio(0x0008, ((reg7<<4)+0x0007));
555
556                REG_RAD4_LOWPASS_FILTER = (short)reg7;
557        }
558}
559
560/**
561 * @brief Set lowpass filter corner frequency on receive (fine adjustment).
562 *
563 * Set the Recieve Lowpass Filter Corner Frequency. This is the Fine adjustment.
564 * The values are chosen from the following list:
565 *              - 000: 90%
566 *              - 001: 95%
567 *              - 010: 100%
568 *              - 011: 105%
569 *              - 100: 110%
570 *              - 101-111: not applicable
571 *
572 * @param value Chosed from the above list.
573 * @param radios Radios affected.
574 * @return Returns OUT_OF_RANGE if value is out of range, WARP_SUCCESS if successful.
575 */
576char WarpRadio_v1_RxLpfCornFreqFineAdj(char value, unsigned int radios) {
577
578        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));                    // Select Radios affected by this function
579
580        value = value & 0x0007;
581        int mask = 0xFFF8;
582
583        if (value == 5 || value == 6 || value == 7) {                           // Make sure the the value is not out of the specified range.
584                return OUT_OF_RANGE;
585        }
586
587        if((radios & RAD1MASK) > 0) {           // Check to make sure if Radio 1 is being used
588                unsigned int reg7 = REG_RAD1_LOWPASS_FILTER & mask;
589                reg7 = reg7 + value;
590                transRadio(0x0001, ((reg7<<4)+0x0007));
591
592                REG_RAD1_LOWPASS_FILTER = (short)reg7;
593        }
594        if((radios & RAD2MASK) > 0) {           // Check to make sure if Radio 2 is being used
595                unsigned int reg7 = REG_RAD2_LOWPASS_FILTER & mask;
596                reg7 = reg7 + value;
597                transRadio(0x0002, ((reg7<<4)+0x0007));
598
599                REG_RAD2_LOWPASS_FILTER = (short)reg7;
600        }
601        if((radios & RAD3MASK) > 0) {           // Check to make sure if Radio 3 is being used
602                unsigned int reg7 = REG_RAD3_LOWPASS_FILTER & mask;
603                reg7 = reg7 + value;
604                transRadio(0x0004, ((reg7<<4)+0x0007));
605
606                REG_RAD3_LOWPASS_FILTER = (short)reg7;
607        }
608        if((radios & RAD4MASK) > 0) {           // Check to make sure if Radio 4 is being used
609                unsigned int reg7 = REG_RAD4_LOWPASS_FILTER & mask;
610                reg7 = reg7 + value;
611                transRadio(0x0008, ((reg7<<4)+0x0007));
612
613                REG_RAD4_LOWPASS_FILTER = (short)reg7;
614        }
615        return WARP_SUCCESS;
616}
617
618
619/**
620 * @brief Set corner frequency for receive high pass filter.
621 *
622 * Set the Recieve Highpass Filter Corner Frequency when RXHP=0.
623 *
624 * @param value 0: 100Hz, 1: 30kHz
625 * @param radios Radios affected by function.
626 */
627void WarpRadio_v1_RxHighPassCornerFreq(char value, unsigned int radios) {
628
629        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));                    // Select Radios affected by this function
630
631        value = value & 0x0001;
632        value = value << 2;
633        int mask = 0xFFFB;
634
635        if((radios & RAD1MASK) > 0) {           // Check to make sure if Radio 1 is being used
636                unsigned int reg8 = REG_RAD1_RX_CONTROL & mask;
637                reg8 = reg8 + value;
638                transRadio(0x0001, ((reg8<<4)+0x0008));
639
640                REG_RAD1_RX_CONTROL = (short)reg8;
641        }
642        if((radios & RAD2MASK) > 0) {           // Check to make sure if Radio 2 is being used
643                unsigned int reg8 = REG_RAD2_RX_CONTROL & mask;
644                reg8 = reg8 + value;
645                transRadio(0x0002, ((reg8<<4)+0x0008));
646
647                REG_RAD2_RX_CONTROL = (short)reg8;
648        }
649        if((radios & RAD3MASK) > 0) {           // Check to make sure if Radio 3 is being used
650                unsigned int reg8 = REG_RAD3_RX_CONTROL & mask;
651                reg8 = reg8 + value;
652                transRadio(0x0004, ((reg8<<4)+0x0008));
653
654                REG_RAD3_RX_CONTROL = (short)reg8;
655        }
656        if((radios & RAD4MASK) > 0) {           // Check to make sure if Radio 4 is being used
657                unsigned int reg8 = REG_RAD4_RX_CONTROL & mask;
658                reg8 = reg8 + value;
659                transRadio(0x0008, ((reg8<<4)+0x0008));
660
661                REG_RAD4_RX_CONTROL = (short)reg8;
662        }
663}
664
665/**
666 * @brief Read instantaneous RSSI.
667 *
668 * Reads the RSSI values for a single radio only.
669 *
670 * @param radios Radio from to read data.
671 * @return RSSI data
672 */
673unsigned int WarpRadio_v1_RSSIData(unsigned int radios) {
674       
675        unsigned int rssi = 0;
676
677        if(radios & RAD1MASK)
678                rssi = RADIO_CONTROLLER_mReadSlaveReg3((volatile)radio_controller_baseaddr) & 0x3FF;
679
680        else if(radios & RAD2MASK)
681                rssi = (RADIO_CONTROLLER_mReadSlaveReg3((volatile)radio_controller_baseaddr) & 0x3FF0000)>>16;
682
683        else if(radios & RAD3MASK)
684                rssi = RADIO_CONTROLLER_mReadSlaveReg4((volatile)radio_controller_baseaddr) & 0x3FF;
685
686        else if(radios & RAD4MASK)
687                rssi = (RADIO_CONTROLLER_mReadSlaveReg4((volatile)radio_controller_baseaddr) & 0x3FF0000)>>16;
688
689        return rssi;
690}
Note: See TracBrowser for help on using the browser.