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_prototypes.c |
---|
8 | * \brief Initializes the registers to their default values. |
---|
9 | * |
---|
10 | * @version 1.09 |
---|
11 | * @author Siddharth Gupta |
---|
12 | * |
---|
13 | */ |
---|
14 | |
---|
15 | // This file initializes the local copies of the radio registers. |
---|
16 | |
---|
17 | /***************************** Include Files *******************************/ |
---|
18 | |
---|
19 | #include "radio_prototypes.h" |
---|
20 | |
---|
21 | /************************ Variable Initializations *************************/ |
---|
22 | |
---|
23 | // These are local copies of the registers in the chip on WARP Radio Board |
---|
24 | // daughtercard. These are modified on every command sent to the radio by |
---|
25 | // all the radio libraries. |
---|
26 | |
---|
27 | // RADIO 1 |
---|
28 | unsigned short REG_RAD1_REGISTER_0 = 0x1140; |
---|
29 | unsigned short REG_RAD1_REGISTER_1 = 0x00CA; |
---|
30 | unsigned short REG_RAD1_STANDBY = 0x1007; |
---|
31 | unsigned short REG_RAD1_INTEGER_DIVIDER_RATIO = 0x30A2; |
---|
32 | unsigned short REG_RAD1_FRACTIONAL_DIVIDER_RATIO = 0x1DDD; |
---|
33 | unsigned short REG_RAD1_BAND_SELECT = 0x1824; |
---|
34 | unsigned short REG_RAD1_CALIBRATION = 0x1C00; |
---|
35 | unsigned short REG_RAD1_LOWPASS_FILTER = 0x002A; |
---|
36 | unsigned short REG_RAD1_RX_CONTROL = 0x0025; |
---|
37 | unsigned short REG_RAD1_TX_LINEARITY = 0x03CF; |
---|
38 | unsigned short REG_RAD1_PA_BIAS_DAC = 0x03C0; |
---|
39 | unsigned short REG_RAD1_RX_GAIN = 0x007F; |
---|
40 | unsigned short REG_RAD1_TX_VGA_GAIN = 0x0000; |
---|
41 | |
---|
42 | // RADIO 2 |
---|
43 | unsigned short REG_RAD2_REGISTER_0 = 0x1140; |
---|
44 | unsigned short REG_RAD2_REGISTER_1 = 0x00CA; |
---|
45 | unsigned short REG_RAD2_STANDBY = 0x1007; |
---|
46 | unsigned short REG_RAD2_INTEGER_DIVIDER_RATIO = 0x30A2; |
---|
47 | unsigned short REG_RAD2_FRACTIONAL_DIVIDER_RATIO = 0x1DDD; |
---|
48 | unsigned short REG_RAD2_BAND_SELECT = 0x1824; |
---|
49 | unsigned short REG_RAD2_CALIBRATION = 0x1C00; |
---|
50 | unsigned short REG_RAD2_LOWPASS_FILTER = 0x002A; |
---|
51 | unsigned short REG_RAD2_RX_CONTROL = 0x0025; |
---|
52 | unsigned short REG_RAD2_TX_LINEARITY = 0x03CF; |
---|
53 | unsigned short REG_RAD2_PA_BIAS_DAC = 0x03C0; |
---|
54 | unsigned short REG_RAD2_RX_GAIN = 0x007F; |
---|
55 | unsigned short REG_RAD2_TX_VGA_GAIN = 0x0000; |
---|
56 | |
---|
57 | // RADIO 3 |
---|
58 | unsigned short REG_RAD3_REGISTER_0 = 0x1140; |
---|
59 | unsigned short REG_RAD3_REGISTER_1 = 0x00CA; |
---|
60 | unsigned short REG_RAD3_STANDBY = 0x1007; |
---|
61 | unsigned short REG_RAD3_INTEGER_DIVIDER_RATIO = 0x30A2; |
---|
62 | unsigned short REG_RAD3_FRACTIONAL_DIVIDER_RATIO = 0x1DDD; |
---|
63 | unsigned short REG_RAD3_BAND_SELECT = 0x1824; |
---|
64 | unsigned short REG_RAD3_CALIBRATION = 0x1C00; |
---|
65 | unsigned short REG_RAD3_LOWPASS_FILTER = 0x002A; |
---|
66 | unsigned short REG_RAD3_RX_CONTROL = 0x0025; |
---|
67 | unsigned short REG_RAD3_TX_LINEARITY = 0x03CF; |
---|
68 | unsigned short REG_RAD3_PA_BIAS_DAC = 0x03C0; |
---|
69 | unsigned short REG_RAD3_RX_GAIN = 0x007F; |
---|
70 | unsigned short REG_RAD3_TX_VGA_GAIN = 0x0000; |
---|
71 | |
---|
72 | // RADIO 4 |
---|
73 | unsigned short REG_RAD4_REGISTER_0 = 0x1140; |
---|
74 | unsigned short REG_RAD4_REGISTER_1 = 0x00CA; |
---|
75 | unsigned short REG_RAD4_STANDBY = 0x1007; |
---|
76 | unsigned short REG_RAD4_INTEGER_DIVIDER_RATIO = 0x30A2; |
---|
77 | unsigned short REG_RAD4_FRACTIONAL_DIVIDER_RATIO = 0x1DDD; |
---|
78 | unsigned short REG_RAD4_BAND_SELECT = 0x1824; |
---|
79 | unsigned short REG_RAD4_CALIBRATION = 0x1C00; |
---|
80 | unsigned short REG_RAD4_LOWPASS_FILTER = 0x002A; |
---|
81 | unsigned short REG_RAD4_RX_CONTROL = 0x0025; |
---|
82 | unsigned short REG_RAD4_TX_LINEARITY = 0x03CF; |
---|
83 | unsigned short REG_RAD4_PA_BIAS_DAC = 0x03C0; |
---|
84 | unsigned short REG_RAD4_RX_GAIN = 0x007F; |
---|
85 | unsigned short REG_RAD4_TX_VGA_GAIN = 0x0000; |
---|
86 | |
---|
87 | |
---|
88 | /***************************** Functions ******************************/ |
---|
89 | |
---|
90 | // slv_reg8 is the transmit register where the value to be transmitted is to be stored. |
---|
91 | // The last 4 bits of the transmitted value should be the register that needs to be set while |
---|
92 | // the first 14 bits are the numbers that need to be set in that register. |
---|
93 | // slv_reg5 is the Control Register. 0x00003412 is the startup value to be set for the system. |
---|
94 | // 0x00003512 lets the core know to transmit the value in the transmit register. |
---|
95 | // slv_reg6 is the Divider Register. The startup value that needs to be set is 0x00000000. |
---|
96 | // slv_reg7 is the Slave Select Register. This decides which of the radios recieve the transmitted |
---|
97 | // value. Daughtercard slot 1 is 0x00000001. Slot 2 is 0x00000002. Slot 3 is 0x00000004. |
---|
98 | // Slot 4 is 0x00000008. Multiple slots can also be selected at the same time. |
---|
99 | |
---|
100 | /** |
---|
101 | * @brief Send information via SPI interface. |
---|
102 | * |
---|
103 | * Function used to send values to the radio. Waits until the controller is done transmitting |
---|
104 | * before it returning. Slave select must be correctly set before being used. |
---|
105 | * |
---|
106 | * @param val Value to be sent to the radio. |
---|
107 | */ |
---|
108 | void transmit(int val) { |
---|
109 | |
---|
110 | RADIO_CONTROLLER_mWriteSlaveReg8((volatile)radio_controller_baseaddr, val); // Set the transmit register to the value that should be transmitted. |
---|
111 | |
---|
112 | RADIO_CONTROLLER_mWriteSlaveReg5((volatile)radio_controller_baseaddr, 0x3512); // Sets the GO_BSY to high so it starts transmitting. |
---|
113 | |
---|
114 | while(RADIO_CONTROLLER_mReadSlaveReg5((volatile)radio_controller_baseaddr) == 0x3512) { // Wait for the controller to finish transmitting. |
---|
115 | } |
---|
116 | |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | /** |
---|
121 | * @brief Send data to a subset of radios via SPI |
---|
122 | * |
---|
123 | * Using transmit() it sends data to radio but also allows for temporarily changing the slave select |
---|
124 | * to apply to some of the radios and not all. |
---|
125 | * |
---|
126 | * @param ssval Slave select input |
---|
127 | * @param val Value to be sent |
---|
128 | */ |
---|
129 | void transRadio(int ssval, unsigned int val) { |
---|
130 | |
---|
131 | unsigned int temp = RADIO_CONTROLLER_mReadSlaveReg7((volatile)radio_controller_baseaddr); // Store the current value of the Slave Select. Needed as this function is |
---|
132 | // used when calling the function for a single radio but still using more |
---|
133 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, ssval); // Set the Slave Select to the new value. |
---|
134 | transmit(val); // Transmit the new value |
---|
135 | RADIO_CONTROLLER_mWriteSlaveReg7((volatile)radio_controller_baseaddr, temp); // Return the Slave Select to its initial value. |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * @brief Send information to the DAC registers. |
---|
141 | * |
---|
142 | * Use to send information to DAC registers. Waits until the controller is done transmitting |
---|
143 | * before it returning. Slave select must be correctly set before being used. |
---|
144 | * |
---|
145 | * @param val Value to be sent. 16 bits wide, first 8 register number, last 8 data for that register. |
---|
146 | */ |
---|
147 | void transmitdac(int val) { |
---|
148 | |
---|
149 | RADIO_CONTROLLER_mWriteSlaveReg8((volatile)radio_controller_baseaddr, val); |
---|
150 | |
---|
151 | RADIO_CONTROLLER_mWriteSlaveReg5((volatile)radio_controller_baseaddr, 0x3510); |
---|
152 | |
---|
153 | while(RADIO_CONTROLLER_mReadSlaveReg5((volatile)radio_controller_baseaddr) == 0x3510) { |
---|
154 | } |
---|
155 | |
---|
156 | } |
---|
157 | |
---|