This probably calculates the slope + intercept of the NRSSI function.
B Mode
Back up RadioRegisters 0x7A, 0x52, and 0x43
Back up PHYRegisters 0x30, 0x26, 0x15, 0x2A, 0x20, 0x5A, 0x59, 0x58
Back up MMIO offsets 0x3E2, 0x3E6 and 0x3F4
- If the PHY Revision is 5 or greater
Bitwise AND RadioRegister 0x7A with 0x7F
- Otherwise
Bitwise AND RadioRegister 0x7A with 0xF
Write 0xFF to PHYRegister 0x30
Write 0x7F7F to MMIO offset 0x3EC
Write 0 to PHYRegister 0x26
Bitwise OR PHYRegister 0x15 with 0x20
Write 0x8A3 to PHYRegister 0x2A
Bitwise OR RadioRegister 0x7A with 0x80
Save the value of PHYRegister 0x27
Bitwise AND RadioRegister 0x7A with 0x7F
If the Analog Core Revision is 2 or greater
Write 0x40 to MMIO offset 0x3E6
If the Analog Core Revision is 0
Write 0x122 to MMIO offset 0x3E6
- Otherwise
Bitwise AND MMIO offset 0x3F4 with 0x2000
Write 0x3F3F to PHYRegister 0x20
Write 0xF330 to PHYRegister 0x15
Write 0x60 to RadioRegister 0x5A
Bitwise AND RadioRegister 0x43 with 0xF0
Write 0x480 to PHYRegister 0x5A
Write 0x810 to PHYRegister 0x59
Write 0xD to PHYRegister 0x58
- Delay for 20 uSec
Save another copy of PHYRegister 0x27
Restore PHYRegister 0x30
Restore RadioRegister 0x7A
Restore MMIO offset 0x3E2
Restore PHYRegisters 0x26, 0x15, 0x2A
Synth PU Workaround with the current channel
If the Analog Core Revision isn't 0
Restore MMIO offset 0x3F4
Restore PHYRegisters 0x20, 0x5A, 0x59 and 0x58
Restore RadioRegisters 0x52 and 0x43
If the two saved values of PHYRegister 0x27 are equal
- The saved NRSSI slope value is 0x10000
- Otherwise,
Find the slope by taking the rise / run. The rise here is 0x400000 (a constant) and the run is the difference between the first saved value of PHYRegister 0x27 and the second saved value.
If the first saved value of PHYRegister 0x27 is less than or equal to -4
Save the first saved value of PHYRegister 0x27 as the first saved NRSSI value
Save the second saved value of PHYRegister 0x27 as the second saved NRSSI value
G Mode
If the RadioID Radio Revision is >= 9
- Return, there's nothing to do
If the RadioID Radio Revision is 8
Calculate the NRSSIOffset
Bitwise AND PHYRegister 0x429 with 0x7FFF
Bitwise AND PHYRegister 0x802 with 0xFFFC
Back up MMIO offset 0x3E2
Set bit 0x8000 in MMIO register 0x3E2
Back up RadioRegisters 0x7A, 0x52, and 0x43
Back up PHYRegisters 0x15, 0x5A, 0x59, 0x58
Back up MMIO offsets 0x3E6, and 0x3F4
- If the PHY Revision is 3 or higher
Back up PHYRegisters 0x2E, 0x2F, 0x80F, 0x810, 0x801, 0x60, 0x14 and 0x478
Write 0 to PHYRegister 0x2E
Write 0 to PHYRegister 0x810
- If the Phy Revision is 4,6 or 7
Bitwise OR PHYRegister 0x478 with 0x100
Bitwise OR PHYRegister 0x801 with 0x40
- If the PHY Revision is 3 or 5
Bitwise AND PHYRegister 0x801 with 0xFFBF
Bitwise OR PHYRegister 0x60 with 0x40
Bitwise OR PHYRegister 0x14 with 0x200
Bitwise OR RadioRegister 0x7A with 0x70
Set All Gains to 0, 8, 0
Bitwise AND RadioRegister 0x7A with 0xF7
- If the PHY Revision is 2 or higher
MaskSet PHYRegister 0x811 with mask 0xFFFFFFCF and set 0x30
MaskSet PHYRegister 0x812 with mask 0xFFFFFFCF and set 0x10
Bitwise OR RadioRegister 0x7A with 0x80
- Delay 20 uSec
Save the value of PHYRegister 0x47F, right shift by 8 and bitwise AND it with 0x3F
- If the value is 0x20 or higher, subtract 0x40 from it.
Bitwise AND RadioRegister 0x7A with 0x7F
If the Analog Core Revision is 2 or greater
MaskSet PHYRegister 0x3 with mask 0xFFFFFF9F and set 0x40
Bitwise OR MMIO offset 0x3F4 with 0x2000
Bitwise OR RadioRegister 0x7A with 0xF
Write 0xF330 to PHYRegister 0x15
If the PHY Revision is >= 2
MaskSet PHYRegister 0x812 with mask 0xFFFFFFCF and set 0x20
MaskSet PHYRegister 0x811 with mask 0xFFFFFFCF and set 0x20
Set All Gains to 3, 0, 1
If the RadioID Radio Revision is 8
Write 0x1F to RadioRegister 0x43
- Otherwise
MaskSet RadioRegister 0x52 with mask 0xFFFFFF0F and set 0x60
MaskSet RadioRegister 0x43 with mask 0xFFFFFFF0 and set 0x9
Write 0x480 to PHYRegister 0x5A
Write 0x810 to PHYRegister 0x59
Write 0xD to PHYRegister 0x58
- Delay 20 uSec
Retrieve the value again from PHYRegister 0x47F, right shift by 8 and bitwise AND it with 0x3F
- If this value is 0x20 or greater, subtract 0x40 from it.
If the first value saved from PHYRegister 0x47F equals the second
- The saved NRSSI Slope is 0x10000
- Otherwise
Find the difference between the first value and the second values saved from PHYRegister 0x47F
- The saved NRSSI slope is 0x400000 divided by the difference
- If the first value is -4 or more
- The second value is saved as the first saved NRSSI value
- The first value is saved as the second saved NRSSI value
- If the PHY Revision is 3 or higher
Restore the original values of PHYRegisters 0x2E, 0x2F, 0x80F and 0x810
- If the PHY Revision is 2 or higher
Mask PHYRegister 0x812 with mask 0xFFFFFFCF
Mask PHYRegister 0x811 with mask 0xFFFFFFCF
Restore the original values of RadioRegisters 0x7A, 0x52, 0x43
Restore the original values of MMIO offsets 0x3E2, 0x3E6, 0x3F4
Restore the original values of PHYRegisters 0x15, 0x5A, 0x59, 0x58
Synth PU Workaround using the current channel
Set bits 0x1 and 0x2 in PHYRegister 0x802
Set OriginalGains
Set bit 0x8000 in the PHYRegister 0x429
- If the PHY Revision is 3 or higher
Restore the original values of PHYRegisters 0x801, 0x60, 0x14 and 0x478
Update the "In Memory" NRSSILookupTable
Set NRSSIThreshold for a G PHY