Contents
B PHY
This might be a state machine like the G PHY version below
Back up PHYRegister 0x15
Back up RadioRegister 0x52 and mask with 0xFFF0
- If the Radio ID for this radio is 0x2050
Back up PHYRegisters 0xA, 0x2A, 0x35, 0x3, 0x1, 0x30
Back up RadioRegisters 0x43, 0x7A
Back up MMIO offset 0x3EC
Back up RadioRegister 0x52 again and mask with 0xF0
Write 0xFF to PHYRegister 0x30
Write 0x3F3F to MMIO offset 0x3EC
Write back the saved value of PHYRegister 0x35 masked with 0xFF7F
Write back the saved value of RadioRegister 0x7A masked with 0xFFF0
Write 0xB000 to PHYRegister 0x15
- If the Radio ID for this radio is 0x2050
Write 0x203 to PHYRegister 0x2B
Write 0x8A3 to PHYRegister 0x2A
- Otherwise
Write 0x1402 to PHYRegister 0x2B
- Minimum of the first measurement is 0xFFFF (unsigned 16 bit value)
- Loop 4 times, from 0 to 3
Write the first saved value of RadioRegister 0x52 bitwise OR'd with the number of times through this loop to RadioRegister 0x52
Perform Reg15Loop (return value is ignored)
- Loop 10 times from 0 to 9
Write the first saved value of RadioRegister 0x52 bitwise OR'd with the number of times through this loop to RadioRegister 0x52
Perform Reg15Loop
- Divide the result by 10
- If this value is less than the minimum of the first measurement
- This is the new minimum, save it along with the position in the loop that this minimum occured at.
Write the first saved value of RadioRegister 0x52 bitwise OR'd with the position in the loop the minimum value occured at to RadioRegister 0x52.
- Minimum of the second measurement is 0xFFFF (unsigned 16 bit value)
- Loop 5 times from -4 to 4, incrementing by 2's
- Loop 5 times from -4 to 4, incrementing by 2's
- If the current position in the inner loop is less than 0
- Find (0x100 * the position in outer loop) + the position in the inner loop + 0x100, this is the index value
- Otherwise
- Find (0x100 * the position in the outer loop) + the position in the inner loop, this is the index value
Write the index value to PHYRegister 0x2F
Perform Reg15Loop
- Divide the result by 10
- If this value is less than the minimum of the second measurement
- This is the new second minimum, save this value and the index value of this loop
- If the current position in the inner loop is less than 0
- Loop 5 times from -4 to 4, incrementing by 2's
- Increment the index value of the second minimum by 0x101
Write the index value of the second minimum to PHYRegister 0x2F
- If the Radio ID for this radio is 0x2050
Restore PHYRegisters 0xA, 0x2A, 0x35, 0x3, 0x1, 0x30
Restore RadioRegisters 0x43, 0x7A
MaskSet RadioRegister 0x52 with mask 0xF and set with the second saved value
Restore MMIO offset 0x3EC
Restore PHYRegister 0x15
Perform a Synth PU Workaround
G PHYs
Measuring the LO is done from two different contexts, initialization and normal operation. When performed after initialization, only iterate over the LO Pairs that have been marked as used.
Setup
If this board has HardwarePowerControl
Back up PHYRegisters 0x80F, 0x801, 0x60, 0x14 and 0x478
- If the PHY revision is 6, 7 or 8
Bitwise OR PHYRegister 0x478 with 0x100
Bitwise OR PHYRegister 0x801 with 0x40
Bitwise OR PHYRegister 0x60 with 0x40
Bitwise OR PHYRegister 0x14 with 0x200
If this is a BPHY with Radio Version 0x2050 and Radio Revision < 6
Write 0x410 to PHYRegister 0x16
Write 0x820 to PHYRegister 0x17
If this isn't during initialization and this is a board with HardwarePowerControl
Read in the Used LO Control Bitmap from SHM offset 0x89C in 16 bit chunks, but clear the top 8 bits of each 16 bit value read in
Clear the Used LO Control Bitmap at SHM offset 0x89C by writing 0's
If any bits are set in Used LO Control Bitmap that were just read in, save a copy of the Used LO Control Bitmap
- Loop from 0 to 0x40
If the saved Used LO Control Bitmap has the bit corresponding to this loop position set, mark the LO Control array value corresponding to the position in this loop (see Loop To Attenuation for details) as used
If PHYConnected is set
Save PHYRegisters 0x814, 0x815, 0x811, 0x812, 0x802, 0x3E, 0x429
Mask PHYRegister 0x429 with mask 0x7FFF
Mask PHYRegister 0x802 with mask 0xFFFC
Bitwise OR PHYRegister 0x814 with 3
Mask PHYRegister 0x815 with mask 0xFFFC
- If this is a G PHY
With PHY Revision >= 7 and BoardFlags indicate an External LNA
Write 0x933 to PHYRegister 0x811
- Otherwise
Write 0x133 to PHYRegister 0x811
- Otherwise
Write 0 to PHYRegister 0x811
Write 0 to PHYRegister 0x3E
Save the 16 bit MMIO offset 0x3E2
Save the 16 bit MMIO offset 0x3F4
Save PHYRegisters 0x15, 0x2A, 0x35 and 0x60
Save RadioRegisters 0x43, 0x7A
- If this isn't a 0x2050 Radio with Radio Revision 8
Save RadioRegister 0x52 bitwise AND'd with 0xF0
- If this is a BPHY
Save PHYRegisters 0x30, 0x6
Write 0xFF to PHYRegister 0x30
Write 0x3F3F to PHYRegister 0x6
- Otherwise
Set bit 0x8000 in MMIO offset 0x3E2
Bitwise AND MMIO offset 0x3F4 with 0xF000
Write 0x7F to the LO Mask Register (PHYRegister 0x80F on GPHYs and 0x2E on BPHYs)
Bitwise AND PHYRegister 0x35 with 0xFF7F
Bitwise AND RadioRegister 0x7A with 0xFFF0
Write 0x8A3 to PHYRegister 0x2A
- IF this is a GPHY or a BPHY with a 0x2050 Radio and Radio Revision 6 or greater
Write 0x1003 to PHYRegister 0x2B
- Otherwise
Write 0x802 to PHYRegister 0x2B
If PHYConnected is set
Perform a DummyTransmission
- Switch to channel 6
Perform a dummy read on RadioRegister 0x51
- If this is a GPHY
Write 0 to PHYRegister 0x2F
- If this is during initialization
If this isn't a PHY Revision 2 or greater OR PHYConnected isn't set
Set RadioRegister 0x43 below with 6
- The three values used when measuring the single subvalue below are 0x20, 0 and 0
- Otherwise
Take the first saved Loopback Gain value, bitwise AND the signed 16 bit value with 0xFFFE
If the 0xA - result * 2 < 0
Set RadioRegister 0x43 below with 0
- Find the absolute value of 0xA - (result * 2), then divide by 6
- Cap the result to 0xF
- The three values used when measuring the single subvalue below are 0, 0 and the result
- Otherwise
- The three values used when measuring the single subvalue below are 0, 0 and 0
- Find 0xA - the result * 2
- If this is less than 0x24 (0x3C if this is a GPHY with PHY Revision 2 or greater and Radio Revision 8)
- Use 0xA - the result * 2
- Otherwise
- Use 0x24 (0x3C if this is a GPHY with PHY Revision 2 or greater and Radio Revision 8)
- If the result of the last operation is less than -3
- Add 6 to the result
- Otherwise
- Add 3 to the result
- If the result / 4 is greater than or equal to 0x9 (0xF if this is a GPHY with PHY Revision 2 or greater and Radio Revision 8)
Set RadioRegister 0x43 below with 0x9 (0xF if this is a GPHY with PHY Revision 2 or greater and Radio Revision 8)
- Otherwise
Set RadioRegister 0x43 below with the result / 4
MaskSet RadioRegister 0x43 with mask 0xFFF0 and set with the value found above
Set the Baseband Attenuation to 2 (see AttenuationControl)
Mask the RadioRegister from the TXCTL Register and Value Table and mask with the value from the table
- If this is a GPHY with an 0x2050 Radio with Radio Revision 8
- Loop 2 times
MaskSet RadioRegister 0x52 with mask 0xFF0F and set with 0x70 the first time and 0x40 the second (These are TXCTL1 Values)
Loop over the TXCTL2 Values
MaskSet RadioRegister 0x52 with mask 0xFFF0 and set with the current TXCTL2 Value
- Measure a single subvalue as shown below, using the control values specified above
- If the result is less than the previous minimum
- Save the current TXCTL1 Attenuation Value and TXCTL2 Attenuation Value
- If the saved TXCTL2 value is 0, break the loop
Write the saved TXCTL2 attenuation value OR'd with the saved TXCTL1 attenuation value left shifted by 4 to RadioRegister 0x52
- Loop 2 times
- Otherwise,
Mask RadioRegister 0x52 with mask 0xFFF0
- If this is a GPHY with PHY Revision 3 or greater
Write 0xC078 to PHYRegister 0x80F (the LO Control Register Mask)
- Otherwise
Write 0x8078 to the appropriate LO Control Register Mask PHYRegister 0x2E for BPHYs or 0x80F for GPHYs
Measuring the LO Control Values
In the following, you'll always be measuring values in search of a minimum. One idea as to what it's measuring is a deviation value, so the spec is written accordingly, even if deviation doesn't make too much sense since it looks like the minimum can be negative.
- Start with a LO Control Pair of (0,0)
Loop over the RF Attenuation List for this board
If this is during initialization and the flag is not set for this RF Attenuation List value
- If this is the first iteration
- Set the LO Control Pair to (0,0)
- Otherwise,
If both the current and previous RF Attenuation List values are odd
Set the LO Control Pair to the saved LO Control Value at Row RF Attenuation List value corresponding to the loop position - 1 + the Maximum RF Attenuation List value if the flag is set for that value and Column 0
- Otherwise
Set the LO Control Pair to the Saved LO Control Value located at Row RF Attenuation List value corresponding to the loop position
- If this is the first iteration
MaskSet RadioRegister 0x43 with mask 0xFFF0 and set with the current RF Attenuation List value
MaskSet the RadioRegister from the TXCTL Register and Value Table and mask with bitwise inverse of the Table Value, set with the Table Value if the flag is set for this RF Attenuation List value
Loop over the Baseband Attenuation List for this board
- If this isn't being performed during initialization
If the Used Attenuation Value that corresponds to the current RF Attenuation List and Baseband Attenuation List values isn't used
Skip this Baseband Attenuation List Value and move to the next one
Copy the LO Pair from the TX Power LO Control Array value associated with the current RF Attenuation List and Baseband Attenuation List values (if the flag is set adjust as needed) to the Cuurent LO Control Pair
- Otherwise
Copy the LO Pair from the TX Power LO Control Array value associated with the current RF Attenuation List and Baseband Attenuation List values, ignoring the flag
Multiply the RF Attenuation List value by 2, add to that the Baseband Attenuation List value divided by 2
If the flag is set for this RF Attenuation List value
- Subract the Flag Value (found in the table below) from the previous result
If the PHYConnected flag is set and the PHY Revision is 2 or more
Add the first Loopback Gain value masked with 0xFFFE to the previous result
Measure the LO Gain Values using the value found above
Set the Baseband Attenuation to the current Baseband Attenuation List value
- Backup the current LO Control Pair
- Measure the deviation as explained below
Save the Current LO Control Pair to the TX Power Lo Control Array as specified in LocalOscillator
- If this is a BPHY
- Increment each of the saved LO control Pair values by 1
- If this isn't being performed during initialization
Restoration
Write the current LO Control Value to the LO Control PHYRegister (0x810 for G PHYs, 0x2F for B PHYs)
If PHYConnected is set
- Write 0xE300 to PHY Register 0x15
Write the fourth gain value (from the last time LO Gain Values was measured) shifted up by 8 ORed with 0xA0 to PHY Register 0x812
- Delay 5 uSecs
Write the fourth gain value (from the last time LO Gain Values was measured) shifted up by 8 ORed with 0xA2 to PHY Register 0x812
- Delay 2 uSecs
Write the fourth gain value (from the last time LO Gain Values was measured) shifted up by 8 ORed with 0xA3 to PHY Register 0x812
- Otherwise
Bitwise AND the fourth gain value (from the last time LO Gain Values was measured) with 0xFFFF, then bitwise OR the result with 0xEFA0
Write the result to PHYRegister 0x15
If this is a board with HardwarePowerControl
Initialize the GPHY DC Lookup Table
- Otherwise
- If this is during initialization
Adjust the LO using Radio Attenuation 3, Baseband Attenuation 2 and TXCTL1 0
- Otherwise
Adjust the LO using the saved attenuation values (see SetTXPower).
- If this is during initialization
- If this is a GPHY
- If the PHY Revision is 3 or greater
Write 0xC078 to PHYRegister 0x2E
- Otherwise
Write 0x8078 to PHYRegister 0x2E
- If the PHY Revision is 2 or greater
Write 0x202 to PHYRegister 0x2F
- Otherwise
Write 0x101 to PHYRegister 0x2F
- If the PHY Revision is 3 or greater
Restore MMIO offset 0x3F4
Restore PHYRegisters 0x15, 0x2A, 0x35, 0x60
Restore RadioRegisters 0x43, 0x7A
- If this isn't a 0x2050 Radio with Radio Revision 8
MaskSet RadioRegister 0x52 with mask 0xFF0F and set with the backed up value of RadioRegister 0x52
Restore MMIO offset 0x3E2
- If this is a BPHY with an 0x2050 Radio and Radio Revision 5 or less
Restore PHYRegisters 0x30, 0x6
If PHYConnected
RestorePHYRegisters 0x814, 0x815, 0x802, 0x811, 0x812, 0x3E, 0x429
If this board has HardwarePowerControl
Restore PHYRegister 0x80F, bitwise AND'd with 0xBFFF
Restore PHYRegisters 0x801, 0x60, 0x14, 0x478
Set the channel back to the current channel (with Synth PU Workaround)
Deviation Measuring State Machine
Again, we're using "deviation" here, even though we're not sure that this is what is actually being measured. What it does look like is that the state machine proceeds until it finds the smallest "deviation" for this set of RF Attenuation List and Baseband Attenuation List values.
A state diagram of the state machine's steps is available here: statemachine.pdf.
State Value Multipliers
Criteria |
Value |
During initialization and PHY Revision is 2 or greater and PHYConnected is set |
3 |
Otherwise |
1 |
Measuring a Single Deviation Value
Each transition of the state machine modifies the current control value pair depending on the target state of that transition. The table of control pair modifiers is given below. Note that under certain circumstances the value given here is multiplied by the State Value Multiplier given in the table above.
1. +1 / +1 2. +1 / 0 3. +1 / -1 4. 0 / -1 5. -1 / -1 6. -1 / 0 7. -1 / 1 8. 0 / 1
If the absolute value of either value in the control pair would cause it to be greater than 16, the transition may not be taken. Otherwise, a deviation value is measured for the all possible new control pairs (write the control pair to 0x810/0x2F again before measuring the deviation value), and the transition that generates the smallest new deviation is taken. This repeats up to 24 times or until no transition yields a smaller deviation than the current value.
The new control pair is returned.
Measuring the Deviation Value
- Start the Measured Subvalues Counter at 0
If the PHY Revision is 2 or greater and the PHYConnected value is set and none of the entries in the TX Power LO Control Array are marked as used, perform the procedure below 4 times, otherwise, perform the procedure below only once
Write the current LO Control Value to the LO Control PHYRegister (0x810 for G PHYs, 0x2F for B PHYs)
Measure a single subvalue as shown below, using the first gain value, the third gain value and the fourth gain value (gain values are from the last time LO Gain Values was measured)
- If this is during initialization OR the subvalue measured is 0x258 or higher
- If the subvalue measured is 0x12C or higher and this is not during initialization
Add 6 to the value used to measure the LO Gain Values
- Otherwise, if the subvalue measured is below 0x12C
Add 0xC to the value used to measure the LO Gain Values
Measure a single subvalue as shown below, using the first gain value, the third gain value and the fourth gain value (gain values are from the last time LO Gain Values was measured)
- If the subvalue measured is 0x12C or higher and this is not during initialization
- While the Measured Subvalues Counter is less than 24
- Loop over the each possible value in this state
- Multiply the state values by the state value multiplier, then add the result to each of the values of the Last LO Pair
- If the value of either of the LO Control Pairs isn't equal to the previous value of either of the LO control pairs and the absolute value of each of the LO Pair values are 16 or below
- Write the LO Control Pair to the LO Control register
Measure a single subvalue as shown below, using the first gain value, the third gain value and the fourth gain value (gain values are from the last time LO Gain Values was measured)
- If the single subvalue is lower than previous results, we've found a new minimum
- Save the single subvalue to compare against the next time through the loop
- Save the loop position this occured at, this is the next state
Unless the PHY has revision 2 or greater and the PHYConnected is set and the single subvalue is 1500 or greater
- Backup this LO Pair as the Last LO Pair
- Break from the "possible state value loop"
- If the Current LO Control Pair is equal to the Last LO Control Pair
- We've found the minimum, and we're finished with measuring this deviation value (break from the measured subvalues while loop)
- Otherwise
- Copy the current LO control Pair to the last LO Control Pair
- Increment the Measured Subvalues Counter
- Loop over the each possible value in this state
Measuring Subvalues
There are three values passed in that comprise the control value. The value written to the PHYRegisters depends upon the state of PHYConnected.
When PHY Connected is Set
Find the Control Value
When PHYConnected is set, the control value is comprised of three values passed in:
- Left shift the first value passed in by 12
- Left shift the second value passed in by 8
- Bitwise OR the previous two values and the third value passed in
- Btiwsie OR 0x10 with the result
If BoardFlags BFL_EXTLNA is set and the PHY Revision is 7 or greater
- Bitwise OR the result with 0x8000
Measure the Subvalue
Write 0xE300 to PHYRegister 0x15
Write the control value to PHYRegister 0x812
- Delay 10 uSec
Write the control value ORed with 0x2 to PHYRegister 0x812
- Delay 10 uSec
Write the control value ORed with 0x3 to PHYRegister 0x812
- Delay 10 uSec
Write 0xF300 to PHYRegister 0x15
- Delay 21 uSec
Return the value of PHYRegister 0x2D
When PHY Connected isn't Set
Measure the Subvalue
Write the third value passed in ORed with 0xEFA0 to PHYRegister 0x15
- Delay 10 uSec
Write the third value passed in ORed with 0xEFE0 to PHYRegister 0x15
- Delay 10 uSec
Write the third value passed in ORed with 0xFFE0 to PHYRegister 0x15
- Delay 21 uSec
Return the value of PHYRegister 0x2D
TXCTL Register and Value Table
G PHY
PHY Revision |
Radio Revision |
TXCTL Register |
TXCTL Value |
Flag Value |
2 or greater |
8 |
0x43 |
0x10 |
2 |
Otherwise |
Any |
0x52 |
0x30 |
5 |
B PHY
Radio Revision |
TXCTL Register |
TXCTL Value |
Flag Value |
5 or less |
0x43 |
0x30 |
0 |
Otherwise |
0x52 |
0x30 |
5 |