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

Revision 692, 13.7 kB (checked in by sgupta, 12 months ago)

Doxygen documentation

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_adv.c
8 * \brief C code for advanced functions allowing for finer control.
9 *
10 * @version 1.09
11 * @author Siddharth Gupta
12 *
13 * This file contains controls the advanced functionality of the radio boards, such as
14 * DAC phase offsets, and all the various shutdown and standby states.
15 */
16
17
18/***************************** Include Files *******************************/
19
20#include "radio_controller_adv.h"
21
22/****************************** Functions **********************************/
23
24/**
25 * @brief Shuts down the radio.
26 *
27 * This function shuts down the radios specified. Forcibly turns off transmit and recieve modes as well as shuts down
28 * amplifiers.
29 * @param radios Refers to the radios in the slots that will be shut down.
30 */
31void WarpRadio_v1_SHDNEnable(unsigned int radios) {
32
33        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) & ~(radios & (RAD_RXEN_MASK | RAD_TXEN_MASK)))); // Disable Rx and Tx
34        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) | (radios & RAD_SHDN_MASK))); // Turn on Shdn
35}
36
37/**
38 * @brief Starts up the radio.
39 *
40 * This function starts up the radios specified to the standby state.
41 * Receive and transmit are still off.
42 *
43 * @param radios Refers to the radios in the slots that will be started up.
44 */
45void WarpRadio_v1_SHDNDisable(unsigned int radios) {
46
47        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) & ~(radios & RAD_SHDN_MASK))); // Disable SHDN
48}
49
50/**
51 * @brief SHDN control is thorugh software function calls.
52 *
53 * Enable SHDN software control. In this situation the SHDNEnable and Disable functions control the SHDN pin.
54 *
55 * @param radios Radios affected.
56 */
57void WarpRadio_v1_SHDNSoftControlEnable(unsigned int radios) {
58
59        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) & ~(radios & RAD_SHDN_CON_MASK))); // Enable software control
60}
61
62/**
63 * @brief SHDN control is thorugh hardware ports.
64 *
65 * Disable SHDN software control. In this situation the SHDN external port on the radio bridge must be used.
66 *
67 * @param radios Radios affected.
68 */
69void WarpRadio_v1_SHDNSoftControlDisable(unsigned int radios) {
70
71        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) | (radios & RAD_SHDN_CON_MASK))); // Disable software control
72}
73
74/**
75 * @brief Receive Enable control is thorugh software function calls.
76 *
77 * Enable Receive Enable software control. In this situation the RxEnable and Disable functions control the RxEn pin.
78 *
79 * @param radios Radios affected.
80 */
81void WarpRadio_v1_RxEnSoftControlEnable(unsigned int radios) {
82
83        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) & ~(radios & RAD_RXEN_CON_MASK))); // Enable software control
84}
85
86/**
87 * @brief Receive Enable control is thorugh hardware ports.
88 *
89 * Disable Receive Enable software control. In this situation the RxEn external port on the radio bridge must be used.
90 *
91 * @param radios Radios affected.
92 */
93void WarpRadio_v1_RxEnSoftControlDisable(unsigned int radios) {
94
95        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) | (radios & RAD_RXEN_CON_MASK))); // Disable software control
96}
97
98/**
99 * @brief Transmit Enable control is thorugh software function calls.
100 *
101 * Enable Transmit Enable software control. In this situation the TxEnable and Disable functions control the TxEn pin.
102 *
103 * @param radios Radios affected.
104 */
105void WarpRadio_v1_TxEnSoftControlEnable(unsigned int radios) {
106
107        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) & ~(radios & RAD_TXEN_CON_MASK))); // Enable software control
108}
109
110/**
111 * @brief Transmit Enable control is thorugh hardware ports.
112 *
113 * Disable Transmit Enable software control. In this situation the TxEn external port on the radio bridge must be used.
114 *
115 * @param radios Radios affected.
116 */
117void WarpRadio_v1_TxEnSoftControlDisable(unsigned int radios) {
118
119        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) | (radios & RAD_TXEN_CON_MASK))); // Disable software control
120}
121
122/**
123 * @brief RxHp control is thorugh software function calls.
124 *
125 * Enable RxHp software control. In this situation the RxHpEnable and Disable functions control the RxHp pin.
126 *
127 * @param radios Radios affected.
128 */
129void WarpRadio_v1_RxHpSoftControlEnable(unsigned int radios) {
130
131        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) & ~(radios & RAD_RXHP_CON_MASK))); // Enable software control
132}
133
134/**
135 * @brief RxHp control is thorugh hardware ports.
136 *
137 * Disable RxHp software control. In this situation the RxHp external port on the radio bridge must be used.
138 *
139 * @param radios Radios affected.
140 */
141void WarpRadio_v1_RxHpSoftControlDisable(unsigned int radios) {
142
143        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) | (radios & RAD_RXHP_CON_MASK))); // Disable software control
144}
145
146/**
147 * @brief Enable RxHp on radios.
148 *
149 * Enables the RxHp on the radios specified. Must be software control mode to work.
150 *
151 * @param radios Refers to the radios affected.
152 */
153void WarpRadio_v1_RxHpEnable(unsigned int radios) {
154
155        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) | (radios & RAD_RXHP_MASK))); // Turn on RxHP
156}
157
158/**
159 * @brief Disable RxHp on radios.
160 *
161 * Disables the RxHp bit in the radios specified.
162 *
163 * @param radios Refers to the radios affected.
164 */
165void WarpRadio_v1_RxHpDisable(unsigned int radios) {
166
167        RADIO_CONTROLLER_mWriteSlaveReg0((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg0((volatile)radio_controller_baseaddr) & ~(radios & RAD_RXHP_MASK))); // Turn off RxHP
168}
169
170/**
171 * @brief Enable or disable RSSI High Bandwidth.
172 * @param mode 0 disables high bandwidth, 1 enables high bandwidth.
173 * @param radios The radios that are affected.
174 * @return Returns INVALID_MODE if mode is incorrect, WARP_SUCCESS if successful change.
175 */
176char WarpRadio_v1_RssiHighBandwidth(char mode, unsigned int radios) {
177
178        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASK & radios));                    // Select Radios affected by this function
179
180        unsigned int modeon = 0x0800;
181        unsigned int modeoff = 0xF7FF;
182
183        if (mode == 0) {
184                if((radios & RAD1MASK) > 0) {           // Check to make sure if Radio 1 is being used
185                        unsigned int reg7 = REG_RAD1_LOWPASS_FILTER & modeoff;
186
187                        transRadio(0x0001, ((reg7<<4)+0x0007));
188
189                        REG_RAD1_LOWPASS_FILTER = (short)reg7;
190                }
191                if((radios & RAD2MASK) > 0) {           // Check to make sure if Radio 2 is being used
192                        unsigned int reg7 = REG_RAD2_LOWPASS_FILTER & modeoff;
193
194                        transRadio(0x0002, ((reg7<<4)+0x0007));
195
196                        REG_RAD2_LOWPASS_FILTER = (short)reg7;
197                }
198                if((radios & RAD3MASK) > 0) {           // Check to make sure if Radio 3 is being used
199                        unsigned int reg7 = REG_RAD3_LOWPASS_FILTER & modeoff;
200
201                        transRadio(0x0004, ((reg7<<4)+0x0007));
202
203                        REG_RAD3_LOWPASS_FILTER = (short)reg7;
204                }
205                if((radios & RAD4MASK) > 0) {           // Check to make sure if Radio 4 is being used
206                        unsigned int reg7 = REG_RAD4_LOWPASS_FILTER & modeoff;
207
208                        transRadio(0x0008, ((reg7<<4)+0x0007));
209
210                        REG_RAD4_LOWPASS_FILTER = (short)reg7;
211                }
212        }
213        else if (mode == 1) {
214                if((radios & RAD1MASK) > 0) {           // Check to make sure if Radio 1 is being used
215                        unsigned int reg7 = REG_RAD1_LOWPASS_FILTER | modeon;
216
217                        transRadio(0x0001, ((reg7<<4)+0x0007));
218
219                        REG_RAD1_LOWPASS_FILTER = (short)reg7;
220                }
221                if((radios & RAD2MASK) > 0) {           // Check to make sure if Radio 2 is being used
222                        unsigned int reg7 = REG_RAD2_LOWPASS_FILTER | modeon;
223
224                        transRadio(0x0002, ((reg7<<4)+0x0007));
225
226                        REG_RAD2_LOWPASS_FILTER = (short)reg7;
227                }
228                if((radios & RAD3MASK) > 0) {           // Check to make sure if Radio 3 is being used
229                        unsigned int reg7 = REG_RAD3_LOWPASS_FILTER | modeon;
230
231                        transRadio(0x0004, ((reg7<<4)+0x0007));
232
233                        REG_RAD3_LOWPASS_FILTER = (short)reg7;
234                }
235                if((radios & RAD4MASK) > 0) {           // Check to make sure if Radio 4 is being used
236                        unsigned int reg7 = REG_RAD4_LOWPASS_FILTER | modeon;
237
238                        transRadio(0x0008, ((reg7<<4)+0x0007));
239
240                        REG_RAD4_LOWPASS_FILTER = (short)reg7;
241                }
242        }
243        else {
244                return INVALID_MODE;
245        }
246        return WARP_SUCCESS;
247}
248
249/*
250// Returns the temp of the 'radio' specified.
251char WarpRadio_v1_RSSITemp(unsigned char radio) {
252
253        return 0;
254}
255*/
256
257/**
258 * @brief Sleep or un-sleep DAC.
259 *
260 * This function either puts the DAC on the specified radios to sleep or takes them out of sleep.
261 *
262 * @param mode 0 not in sleep, 1 enable sleep.
263 * @param radios The radios that are affected.
264 * @return Returns INVALID_MODE if mode is incorrect, WARP_SUCCESS if successful change.
265 */
266int WarpRadio_v1_DACSleep(char mode, unsigned int radios) {
267
268        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASKDAC & radios));         // Select the dacs that need to be affected
269
270        if (mode == 1) {                                                                        // Check if DACs need to put to sleep.
271                transmitdac(0x0014);                                    // Transmit the sleep bit = 1 for the required DACs
272        }
273        else if (mode == 0) {
274                transmitdac(0x0004);                                    // Remove the DACs specified from sleep mode.
275        }
276        else {
277                return INVALID_MODE;
278        }
279
280        return WARP_SUCCESS;
281}
282
283/**
284 * @brief Adjust output fine gain for DAC.
285 *
286 * Adjust the Fine Gain for output current on the I and Q channels of the DAC. The value must be
287 * 8 bits wide at most.
288 *
289 * @param chan ICHAN changes the I channel fine gain, QCHAN affects the fine gain of the Q channel.
290 * @param value The value is 8 bits wide and goes to the registers.
291 * @param radios The dacs of the radios affected.
292 * @return Returns INVALID_MODE if the mode is incorrect, WARP_SUCCESS if successful change.
293 */
294int WarpRadio_v1_DACFineGainAdj(char chan, unsigned char value, unsigned int radios) {
295
296        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASKDAC & radios));                 // Select the dacs that need to be affected
297
298        value = value & 0x00FF;                                                         // Use only the last 8 bits of the value
299
300        if (chan == ICHAN) {                                                            // If called on I channel send the values to register 5
301                transmitdac(0x0500 + value);
302        }
303        else if (chan == QCHAN) {                                                       // If called on Q channel send the values to register 9
304                transmitdac(0x0900 + value);
305        }
306        else {
307                return INVALID_MODE;
308        }
309        return WARP_SUCCESS;
310}
311
312/**
313 * @brief Adjust output coarse gain for DAC.
314 *
315 * Adjust the Coarse Gain for output current on the I and Q channels of the DAC. The value must be
316 * 8 bits wide at most.
317 *
318 * @param chan ICHAN changes the I channel fine gain, QCHAN affects the fine gain of the Q channel.
319 * @param value The value is 4 bits wide and goes to the registers.
320 * @param radios The dacs of the radios affected.
321 * @return Returns INVALID_MODE if the mode is incorrect, WARP_SUCCESS if successful change.
322 */
323int WarpRadio_v1_DACCoarseGainAdj(char chan, unsigned char value, unsigned int radios) {
324
325        RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, (SLAVEMASKDAC & radios));         // Select the dacs that need to be affected
326
327        value = value & 0x000F;                                                 // Use only last 4 bits
328
329        if (chan == ICHAN) {
330                transmitdac(0x0600 + value);
331        }
332        else if (chan == QCHAN) {
333                transmitdac(0x0A00 + value);
334        }
335        else {
336                return INVALID_MODE;
337        }
338        return WARP_SUCCESS;
339}
340
341/**
342 * @brief Power up/down the ADC on radio
343 *
344 * Controls power down and power up functionality of the two channels of the ADC. Both channels
345 * can be done by ORing the chan values together.
346 *
347 * @param chan ICHAN is for I channel QCHAN is for Q channel.
348 * @param value 0 is to power up 1 is to power down.
349 * @param radios ADCs on radios affected.
350 */
351void WarpRadio_v1_ADCPdwn(char chan, unsigned char value, unsigned int radios) {
352
353        if (chan == ICHAN) {
354                if (value == 0) {
355                        RADIO_CONTROLLER_mWriteSlaveReg2((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg2((volatile)radio_controller_baseaddr) & ~(radios & RAD_ADC_RX_PWDNA_MASK)));
356                }
357                else if (value == 1) {
358                        RADIO_CONTROLLER_mWriteSlaveReg2((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg2((volatile)radio_controller_baseaddr) | (radios & RAD_ADC_RX_PWDNA_MASK)));
359                }
360        }
361        else if (chan == QCHAN) {
362                if (value == 0) {
363                        RADIO_CONTROLLER_mWriteSlaveReg2((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg2((volatile)radio_controller_baseaddr) & ~(radios & RAD_ADC_RX_PWDNB_MASK)));
364                }
365                else if (value == 1) {
366                        RADIO_CONTROLLER_mWriteSlaveReg2((volatile)radio_controller_baseaddr, (RADIO_CONTROLLER_mReadSlaveReg2((volatile)radio_controller_baseaddr) | (radios & RAD_ADC_RX_PWDNB_MASK)));
367                }
368        }
369}
370
371/**
372 * @brief Adjusts the divider ratio for the spi interface of the radio.
373 *
374 * @param val New clock ratio value.
375 */
376void WarpRadio_v1_clkRatio(unsigned int val){
377        clkRatio = val;
378}
Note: See TracBrowser for help on using the browser.