Local Oscillator Computed I and Q Table
The LO Computed I and Q table is a table of the computed I and Q values (LO Control Values) associated with the attenuation settings of the device. The I and Q values are kept for each possible attenuation value and are indexed by RF Attenuation and Baseband Attenuation. If the PAD Mixer is enabled, the value is considered different from the attenuation setting without the PAD Mixer and are stored as such. Additionally, entries may be marked as used or unused to help speed up calibration when the table isn't empty.
Building the Table
There are specific branches in the sections below that depend upon whether the table is empty or not. On init and after certain events, the table is cleared and then rebuilt.
Start
In this phase, registers are backed up and the LO is put into a known frequency to prepare for calibration.
If Hardware Power Control is enabled
Backup PHY Registers 0x80F, 0x801, 0x60, 0x14, 0x478
OR PHY Register 0x478 with 0x100
OR PHY Register 0x801 with 0x40
OR PHY Register 0x60 with 0x40
OR PHY Register 0x14 with 0x200
- If this isn't a GPHY
Return
Note older versions had B PHY Code too...
If the table isn't empty and Hardware Power Control is enabled
Read in the Power Vector from SHM offset 0x310 in 16 bit pieces, but clear the top 8 bits of each 16 bit value (Note that this introduces 8 bits of 0 between 8 bits of data read)
Clear the Power Vector at SHM offset 0x310 by writing 0's
If any Power Vector bits are set
Save a copy of the Power Vector
- Loop from 0 to 0x40
If the saved Power Vector has the bit corresponding to this loop position set
The RF Attenuation value corresponding to this position is found by dividing the list position by the length of the RF Attenuation List for this board and throwing away the remainder, this is the offset to use in the RF Attenuation List
The Baseband Attenuation value corresponding to this position is found by dividing the list position by the length of the RF Attenuation Values for this board and only keeping the remainder, this is the offset to use in the Baseband Attenuation List
- Mark as used the I and Q table entry corresponding to the Baseband and RF attenuation values found above
- If the PHY Revision is 2 or greater
Save PHY Registers 0x814, 0x815, 0x811, 0x812, 0x802, 0x3E, 0x429
AND PHY Register 0x802 with 0xFFFC
AND PHY Register 0x429 with 0x7FFF
OR PHY Register 0x814 with 3
AND PHY Register 0x815 with 0xFFFC
If PHY Revision is 7 or greater and the Board Flags indicate an External LNA
Write 0x933 to PHY Register 0x811
- Otherwise
Write 0x133 to PHY Register 0x811
Write 0 to PHY Register 0x3E
Back up Core Registers 0x3F4, 0x3E2
Back up Radio Registers 0x43, 0x7A
Back up PHY Registers 0x15, 0x2A, 0x35, 0x60
If TX Magnification isn't enabled
Back up Radio Register 0x52
- AND the backed up value with 0xF0
- Back up the current channel
OR Core Register 0x3E2 with 0x8000
AND Core Register 0x3F4 with 0xF000
Write 0x7F to PHY Register 0x80F
Write the backed up value of PHY Register 0x35 AND'd with 0xFF7F to PHY Register 0x35
Write the backed up value of Radio Register 0x7A AND'd with 0xFFF0 to Radio Register 0x7A
Write 0x8A3 to PHY Register 0x2A
Write 0x1003 to PHY Register 0x2B
- If the PHY Revision is 2 or greater
Perform a CCK Dummy Transmission
- Set the channel to 6
Perform a dummy read on Radio Register 0x51
- If this is a G PHY
Write 0 to PHY Register 0x2F
- If the table is empty
If Loopback Gain is disabled
The Loopback Gain value is 0
The TRSW_RX value is 2
The PGA value is 0
MaskSet the Power Control Radio Register (0x43) with mask 0xFFF0 and set with 6
- Otherwise, the values must be computed
The TRSW_RX value is 0
Take the saved Maximum Loopback Gain value and divide the result by 2, this is the Loopback Gain value (converted back to dB from hdB)
If the Loopback Gain value in hdB is greater than 10
Subtract 10 from the Loopback Gain value in hdB, then divide that by 6, this is the PGA Value
If the PGA Value is 0x10 or greater
Use 0xF as the PGA Value instead
MaskSet the Power Control Radio Register (0x43) with mask 0xFFF0 and set with 0
- Otherwise
The PGA value is 0
- If the PHY Revision is 2 or greater with a 0x2050 radio with revision 8
- The Loopback Gain Comparison value is 0xF
- Otherwise
- The Loopback Gain Comparison value is 0x9
- If the Loopback Gain in hdB is less than the Loopback Gain Comparison value multiplied by 4
- The Power Control value starts with the Loopback Gain Comparison value multiplied by 4
- Otherwise
- The Power Control value starts with the Loopback Gain value in dB
- If the Loopback Gain value in hdB is less than 0
- Add 6 to the Power Control value
- Otherwise
- Add 3 to the Power Control value
- Divide the Power Control value by 4
- If the Power Control value is less than the Loopback Gain Comparison value
MaskSet the Power Control Radio Register (0x43) with mask 0xFFF0 and set with the Power Control value
- Otherwise
MaskSet the Power Control Radio Register (0x43) with mask 0xFFF0 and set with the Loopback Gain Comparison value
- Set the Baseband Attenuation to 2
AND the TXCTL Radio Register from the TXCTL Register and Value Table with bitwise inverse of the value from the table
If TX Magnification is enabled
Loop over the TX Magnification Values
MaskSet Radio Register 0x52 with mask 0xFF0F and set with the current TX Magnification Value left shifted by 4
Loop over the TX Bias List
MaskSet Radio Register 0x52 with mask 0xFFF0 and set with the current TX Bias List value
Measure the Feedthrough using the TRSW_RX value and PGA value from above and an LNA value of 0
- If the result is less than the previous minimum (or it's the first time through the loop)
- Save the current TX Bias value and TX Magnification value
- If the saved TX Bias value is 0, break the loop
- Left shift the saved TX Magnification value by 4
- OR that value with the saved TX Bias value
Write the result to Radio Register 0x52
- Otherwise,
AND Radio Register 0x52 with 0xFFF0 (the TX Bias is 0)
- If the PHY Revision is 3 or greater
Write 0xC078 to the LO Control PHY Register (0x80F on G PHYs, 0x2E on B PHYs)
- Otherwise
Write 0x8078 to the LO Control PHY Register (0x80F on G PHYs, 0x2E on B PHYs)
LO Calibration
In this phase, different states are tried to find the state with the lowest LO leakage
Start with a LO Control Value with I = 0 and Q = 0
Loop over the RF Attenuation List for this board
If the table was empty and the PAD Mixer flag is not enabled for this RF Attenuation List value
- If this is the first iteration
Set the LO Control Value to I = 0 and Q = 0
- Otherwise,
If both the current and previous RF Attenuation List values are odd
Set the LO Control Value to the computed I and Q table value corresponding to the last RF Attenuation List value and a Baseband Attenuation value of 0
- Otherwise
Set the LO Control Value to the computed I and Q table value corresponding to the current RF Attenuation List value and a Baseband Attenuation value of 0
- If this is the first iteration
MaskSet Radio Register 0x43 with mask 0xFFF0 and set with the current RF Attenuation List value
MaskSet the Radio Register from the TXCTL Register and Value Table and mask with bitwise inverse of the Table Value and set with the Table Value if the PAD Mixer is enabled for this RF Attenuation List value
Loop over the Baseband Attenuation List: for this board
- If the table is not empty
If the I and Q value that corresponds to the current RF Attenuation List and Baseband Attenuation List values isn't marked as used
Skip this Baseband Attenuation List Value and move to the next one
Copy the I and Q value associated with the current RF Attenuation List and Baseband Attenuation List values to the Curent LO Control Pair
- Otherwise
Copy the I and Q value associated with the current RF Attenuation List and Baseband Attenuation List values as if the PAD Mixer wasn't enabled
Multiply the RF Attenuation List value by 2 and add to that the Baseband Attenuation List value divided by 2, this is the Maximum RX Gain
If the PAD Mixer is enabled for this RF Attenuation List value
Subtract the PAD Mixer Gain (found in the TXCTL Register and Value Table) from the Maximum RX Gain
- If Loopback Gain is enabled
- Add the Maximum Loopback Gain value (in hdB) to the Maximum RX Gain
Measure the Gains using the Maximum RX Gain found above (if the Loopback gain is enabled, the use of TRSW_RX is requested)
Set the Baseband Attenuation to the current Baseband Attenuation List value
Backup the current LO Control Value
Test the states using the Local Oscillator State Machine
- If this is a BPHY
Increment the I and Q values of the the current LO Control Value by 1
Save the LO Control Value into the I and Q value table associated with the current Baseband and RF attenuation values
- If the table is not empty
Finish
In this phase, registers are restored and the LO is configured for normal operation
Write the LO Control Value with the lowest Feedthrough to the LO Control PHY Register (0x80F on G PHYs, 0x2E on B PHYs)
- If the PHY Revision is 2 or greater
Write 0xE300 to PHY Register 0x15
Write the PGA value from the last time the Gain Values were measured, shifted up by 8 ORed with 0xA0 to PHY Register 0x812
- Delay 5 uSecs
Write the PGA value from the last time Gain Values were measured, shifted up by 8 ORed with 0xA2 to PHY Register 0x812
- Delay 2 uSecs
Write the PGA value from the last time Gain Values were measured, shifted up by 8 ORed with 0xA3 to PHY Register 0x812
- Otherwise
Bitwise OR the PGA value from the last time Gain Values were measured then with 0xEFA0 and write the result to PHY Register 0x15
- If this is a board with Hardware Power Control
- Initialize the GPHY DC Lookup Table
- Otherwise
- If the table was empty
Adjust the Local Oscillator using Radio Attenuation 3, Baseband Attenuation 2 and no TX Control flags set
- Otherwise
Adjust the Local Oscillator using the saved attenuation values
- If the table was empty
- If the PHY Revision is 3 or greater
Write 0xC078 to PHY Register 0x2E
- Otherwise
Write 0x8078 to PHY Register 0x2E
- If the PHY Revision is 2 or greater
Write 0x202 to PHY Register 0x2F
- Otherwise
Write 0x101 to PHY Register 0x2F
Restore Core Register 0x3F4
Restore PHY Registers 0x15, 0x2A, 0x35, 0x60
Restore Radio Registers 0x43, 0x7A
If TX Magnification isn't enabled
MaskSet Radio Register 0x52 with mask 0xFF0F and set with the backed up value of Radio Register 0x52
Restore Core Register 0x3E2
- If the PHY Revision is 2 or greater
Restore PHY Registers 0x814, 0x815, 0x802, 0x811, 0x812, 0x3E, 0x429
- If this board has Hardware Power Control
Restore PHY Register 0x80F, bitwise AND'd with 0xBFFF
Restore PHY Registers 0x801, 0x60, 0x14, 0x478
Set the channel back to the current channel (with the SynthPU Workaround)