N PHY RSSI Calibrate Rev 3
- Establish a 2-element u16 array clip_state
- Establish a 2-element u1s array clip_off and preset with 0xFFFF in both elements
- Create an 8 x 4 s32 array results and initialize to 0
- Create a 4-element s32 array results_min and initialize to 0
- Create a 4-element s32 array poll_result and initialize to zero
Call N PHY Classifier with arguments 0, 0 and save output as class
Call N PHY Classifier with arguments 7, 4
Call N PHY Clip Detection with 0, clip_state as arguments
Call N PHY Clip Detection with 1, clip_off as arguments
- Save PHY Registers 0x91, 0x92, 0x8F, 0xA5, 0xA6, 0xA7, 0xE7, 0xEC
If PHY Revision >= 7
- Save PHY Registers 0x342, 0x343, 0x346, 0x347
- Save PHY Registers 0xE5, 0xE6, 0x78, 0xF9, 0xFB
If PHY Revision >= 7
- Save PHY Registers 0x340, 0x341, 0x344, 0x345
- Save PHY Registers 0x7A, and 0x7D
Call N PHY RF Control Intc Override with arguments 0, 0, 7
Call N PHY RF Control Intc Override with arguments 1, 1, 7
If PHY Revision >= 7
Call N PHY RF Control Override One to Many with 0, 0, 0, 0 as arguments
Call N PHY RF Control Override One to Many with 1, 1, 0, 0 as arguments
Call N PHY RF Control Override Rev 7 with 0x80, 1, 0, 0, 0 as arguments
Call N PHY RF Control Override Rev 7 with 0x40, 1, 0, 0, 0 as arguments
- Otherwise
Call N PHY RF Control Override with arguments 1, 0, 0, 0
Call N PHY RF Control Override with arguments 2, 1, 0, 0
Call N PHY RF Control Override with arguments 0x80, 1, 0, 0
Call N PHY RF Control Override with arguments 0x40, 1, 0, 0
- If the current band is 5G
If PHY Revision >= 7
Call N PHY RF Control Override Rev 7 with arguments 0x20, 0, 0, 0, 0
Call N PHY RF Control Override Rev 7 with arguments 0x10, 1, 0, 0, 0
- Otherwise
Call N PHY RF Control Override with arguments 0x20, 0, 0, 0
Call N PHY RF Control Override with arguments 0x10, 1, 0, 0
- Otherwise
If PHY Revision >= 7
Call N PHY RF Control Override Rev 7 with arguments 0x10, 0, 0, 0, 0
Call N PHY RF Control Override Rev 7 with arguments 0x20, 1, 0, 0, 0
- Otherwise
Call N PHY RF Control Override with arguments 0x10, 0, 0, 0
Call N PHY RF Control Override with arguments 0x20, 1, 0, 0
Save the output of N PHY RX Core Get State
- Set max to 8
- Loop 2 times with index i (thru cores?)
If the saved core state & (1 << i) is zero
- Continue
Call N PHY Scale RSSI Offset with 0, 0, i+1, 0, 2 as arguments
Call N PHY Scale RSSI Offset with 0, 0, i+1, 1, 2 as arguments
- Loop 8 times with index j
If PHY Revision >= 7
- Set tmp to (i == 0) ? 0xB4 : 0x139
- Maskset Radio Register tmp with mask 0xF8 and set with j
- Otherwise
- Set tmp to (i == 0) ? 0x602B : 0x702B
MaskSet Radio Register tmp with mask 0xE3 and set with j << 2
Call N PHY Poll RSSI with 2, &results[j][0], 8 as arguments
- Loop 4 times with index j
- If j / 2 equals i and j % 2 equals 0
- Set mind to 0x100000
- Set minpoll to 249
- Set mink to 0
- Loop 8 times with index k
- Set current to results[k][j] * results[k][j] + results[k][j + 1] * results[k][j]
If current < mind
- Set mind to current
- Set mink to k
If results[k][j] < minpoll
- Set minpoll to results[k][j]
- Set final to mink
- Set results_min[j] to minpoll
- If j / 2 equals i and j % 2 equals 0
If PHY Revision >= 7
- Set tmp to (i == 0) ? 0xB4 : 0x139
- Maskset Radio Register tmp with mask 0xF8 and set with final
- Otherwise
- Set tmp to (i == 0) ? 0x602B : 0x702B
MaskSet Radio Register tmp with mask 0xE3 and set with final << 2
- Loop 4 times with index j
- If i equals j / 2
- Set offset[j] to -results[final][j]
If offset[j] < 0
- Set offset[j] to -((abs(offset[j]) + 4) / 8)
- Otherwise
- Set offset[j] to (offset[j] + 4) / 8
- If results_min[j] equals 248
- Set offset[j] to -32
Call N PHY Scale Offset RSSI with arguments 0, offset[j], (j/2==0) ? 1:2, (j%2==0) ? 0:1, 2 as arguments
- If i equals j / 2
- Loop 2 times with index i
If the saved core state & (1 << i) is zero
- Continue
- Loop 2 times with index j
Call N PHY Scale Offset RSSI with arguments 0, 0, i+1, 0, j
Call N PHY Scale Offset RSSI with arguments 0, 0, i+1, 1, j
Call N PHY Poll RSSI with j, poll_result, 8 as arguments
- Loop 4 times with index k
- If i equals k / 2
- Set offset[k] to 232 - poll_result[k]
If offset[k] < 0
- Set offset[k] to -((abs(offset[k] + 4) / 8)
- Otherwise
- Set offset[k] to (offset[k] + 4) / 8
Call N PHY Scale Offset RSSI with 0, offset[2 * i], i + 1, k % 2, type as arguments
- If i equals k / 2
- Restore PHY Registers 0x91 and 0x92
Call N PHY Force RF Seq with argument 2
MaskSet PHY Register 0xE7 with mask 0xFFFE and set with 0x0001
MaskSet PHY Register 0x78 with mask 0xFFFE and set with 0x0001
MaskSet PHY Register 0xE7 with mask 0xFFFE and set with 0
MaskSet PHY Register 0xEC with mask 0xFFFE and set with 1
MaskSet PHY Register 0x78 with mask 0xFFFD and set with 0x0002
MaskSet PHY Register 0xE7 with mask 0xFFFE and set with 0
- Restore saved values for PHY Registers 0x8F, 0xA5, 0xA6, 0xA7, 0xE7, 0xEC
If PHY Revision >= 7
- Restore saved values for PHY Registers 0x342, 0x343, 0x346, 0x347
- Restore saved values for PHY Registers 0xE5, 0xE6, 0x78, 0xF9, 0xFB
If PHY Revision >= 7
- Restore saved values for PHY Registers 0x340, 0x341, 0x344, 0x345
- Restore saved values for PHY Registers 0x7A, 0x7D
- If the band is 2 GHz
If PHY Revision >= 7
Save Radio Register 0xB4 to rssical_cache.rssical_radio_regs_2G[0]
Save Radio Register 0x139 to rssical_cache.rssical_radio_regs_2G[1]
- Otherwise
Save Radio Register 0x602B to rssical_cache.rssical_radio_regs_2G[0]
Save Radio Register 0x702B to rssical_cache.rssical_radio_regs_2G[1]
Save PHY Register 0x1A6 to rssical_cache.rssical_phyregs_2G[0]
Save PHY Register 0x1AC to rssical_cache.rssical_phyregs_2G[1]
Save PHY Register 0x1B2 to rssical_cache.rssical_phyregs_2G[2]
Save PHY Register 0x1B8 to rssical_cache.rssical_phyregs_2G[3]
Save PHY Register 0x1A4 to rssical_cache.rssical_phyregs_2G[4]
Save PHY Register 0x1AA to rssical_cache.rssical_phyregs_2G[5]
Save PHY Register 0x1B0 to rssical_cache.rssical_phyregs_2G[6]
Save PHY Register 0x1B6 to rssical_cache.rssical_phyregs_2G[7]
Save PHY Register 0x1A5 to rssical_cache.rssical_phyregs_2G[8]
Save PHY Register 0x1AB to rssical_cache.rssical_phyregs_2G[9]
Save PHY Register 0x1B1 to rssical_cache.rssical_phyregs_2G[10]
Save PHY Register 0x1B7 to rssical_cache.rssical_phyregs_2G[11]
Set nphy_rssical_chanspec_2G to the current chanspec
- Otherwise
If PHY Revision >= 7
Save Radio Register 0xB4 to rssical_cache.rssical_radio_regs_5G[0]
Save Radio Register 0x139 to rssical_cache.rssical_radio_regs_5G[1]
- Otherwise
Save Radio Register 0x602B to rssical_cache.rssical_radio_regs_5G[0]
Save Radio Register 0x702B to rssical_cache.rssical_radio_regs_5G[1]
Save PHY Register 0x1A6 to rssical_cache.rssical_phyregs_5G[0]
Save PHY Register 0x1AC to rssical_cache.rssical_phyregs_5G[1]
Save PHY Register 0x1B2 to rssical_cache.rssical_phyregs_5G[2]
Save PHY Register 0x1B8 to rssical_cache.rssical_phyregs_5G[3]
Save PHY Register 0x1A4 to rssical_cache.rssical_phyregs_5G[4]
Save PHY Register 0x1AA to rssical_cache.rssical_phyregs_5G[5]
Save PHY Register 0x1B0 to rssical_cache.rssical_phyregs_5G[6]
Save PHY Register 0x1B6 to rssical_cache.rssical_phyregs_5G[7]
Save PHY Register 0x1A5 to rssical_cache.rssical_phyregs_5G[8]
Save PHY Register 0x1AB to rssical_cache.rssical_phyregs_5G[9]
Save PHY Register 0x1B1 to rssical_cache.rssical_phyregs_5G[10]
Save PHY Register 0x1B7 to rssical_cache.rssical_phyregs_5G[11]
Set nphy_rssical_chanspec_5G to the current chanspec
Call N PHY Classifier with arguments 7, class
Call N PHY Clip Detection with 1, clip_state as arguments