int N PHY ACI Scan IQ Based
Copy nphy_aci.detect_repeat_ctr to repeat_ctr
Copy nphy_aci.detect_num_samples to nsamps
- Set count_thresh to nsamps / 5
- Set num_adc_ranges to 3
Set u32 array adc_pwrs to {nphy_aci.adcpwr_enter_thresh, 1400, 9000, 12000}
- Set s8 array valid_w2s[] to {23, 19, 10}
Set u32 adc_pwrs_rev3[] to {nphy_aci.adcpwr_enter_thresh, 7000, 13000, 15000}
- Set s8 valid_w2s_rev3[] to {15, 10, 5}
- Establish a 2-element u8 array named saved_pwr_index
- Set pwr to 0
- Set u16 array clip_off[] to {0xFFFF, 0xFFFF}
Copy pubpi.radio_chanspec to orig_chanspec
Set orig_channel to orig_chanspec & 0xFF
If PHY revision >= 3
Set adc_code_thresh to square root of nphy_aci.adcpwr_enter_thresh / 2
Call N PHY Classifier with 0, 0 as arguments and save result as classifier_state
Call N PHY Clip Detection with 0, clip_state as arguments
- Read PHY Register 0x1ED, mask with 0x7F00, shift the result right by 8 and save as saved_pwr_index[0]
- Read PHY Register 0x1EE, mask with 0x7F00, shift the result right by 8 and save as saved_pwr_index[1]
- Save [[802.11/PHY/Registers|PHY Registers] 0xCA, 0xC8, and 0xC9
- If the bandwidth is 40 MHz
- Set chan_delta to 6 and chan_skip to 5
- Otherwise
- Set chan_delta to 5 and chan_skip to 4
- Set start to orig_channel - chan_delta
If start < 1
- Set start to 1
- Set stop to orig_channel + chan_delta
If stop > 13
- Set stop to 13
- Loop from start to end (inclusive) with chan as loop index
If chan < (orig_channel - chan_skip) OR chan > (orig_channel + chan_skip)
If chan <= 14
- Set tmp to chan | 0x2B00
- Otherwise
- Set tmp to chan | 0x1B00
Call PHY Set Chanspec with tmp as argument
Call N PHY Classifier with 7, 4 as arguments
Call N PHY Clip Det with 1, clip_off as arguments
Call N PHY RF Ctrl Override with 0x1000, 0x213F, 3, 0 as arguments
Write 0xFFFF to PHY Registers 0xC8 and 0xC9
Call N PHY RSSI Sel with arguments 5, 1
Call N PHY Force Seq with argument 2
- Set pwr_ch to 0
- Set w2_ch to 32
- Loop 2 times with core as the index
- Write (6 + core) to PHY Register 0xCA
- Loop from repeat_ctr times with ctr as index
- Set avg_adcpwr to 0
- Set avgw2 to 0
- Set count to 0
- Loop nsamps times with samp as the index
- If core is 0
Read PHY Register 0x1C9 and save as gpio
- Otherwise
Read PHY Register 0x1CA and save as gpio
- Bitwise mask gpio with 0x3FF, left shift by 6, cast the result as s16, right shift by 8 and save as adc_code
- Right shift gpio by 10, mask with 0x3F, left shift by 2, cast as s8, right shift by 2 and save as w2 (These items are sign extended.)
If abs(adc_code) > adc_code_thresh
- Increment count
- Add adc_code * adc_code to avg_adcpwr
- Add w2 to avgw2
- If core is 0
If count > count_thresh
- Divide avg_adcpwr by count
If avg_adcpwr > pwr_ch
- Divide avgw2 by count
- Set adcpwr_val to 1
- Loop num_adc_ranges times with i as index
If avg_adcpwr >= adc_pwrs_rev3[i] AND avg_adcpwr < adc_pwrs_rev3[i + 1]
If avgw2 < valid_w2s_rev3[i]
- Set adcpwr_val to 0
- Break
- If adcpwr_val is 1
- Set pwr_ch to avg_adcpwr
- Set w2_ch to avgw2
- Delay 10 usec
If pwr < pwr_ch
- Set pwr to pwr_ch
Restore PHY Registers 0xCA, 0xC8, 0xC9
Call N PHY RSSI Sel with 0, 0 as arguments
Call N PHY Force RF Seq with 2 as the argument
Call N PHY RF Ctrl Override 0x1000, 0, 3, 1 as arguments
Call N PHY Force RF Seq with 2 as the argument
Call N PHY Clip Detection 1, clip_state as arguments
Call N PHY Classifier with 7, classifier_state as arguments
Call N PHY Force RF Seq with 2 as the argument
Call PHY Set Chanspec with argument orig_chanspec
Set nphy_txpwr_idx[0] and [1] from saved_pwr_idx[0] and [1]
Call N PHY TX Power Ctrl Enable with tx_pwr_ctrl_state as argument
If pwr > adc_pwrs_rev3[1]
- Return 3
- Return 0
- Otherwise
If aci_state & 2 is not zero
Set adc_pwrs_rev3[0] to nphy_aci.adcpwr_exit_thresh
Call N PHY Classifier with arguments (0, 0) and save in classifier_state
Call N PHY Clip Detection with arguments (0, clip_state)
Save PHY Registers 0xCA, 0xC8, 0xC9, 0x91 and 0x92
Save Radio Registers 0x66, 0x95, 0x71, and 0xA0
Read Radio Register 0x2B, add 20 and save in rccal_val
If 0x1F < rccal_val
- Set rccal_val to 0x1F
- Bitwise OR rccal_val with 0x20
- If the bandwidth is 40 MHz
- Set chan_delta to 6
- Set chan_skip to 5
- Otherwise
- Set chan_delta to 5
- Set chan_skip to 4
- Set start to orig_channel - chan_delta
If start < 1
- Set start to 1
- Set end to orig_channel + chan_delta
If end > 13
- Set end to 13
- Loop from start to end (inclusive) with chan as index
If chan < (orig_channel - chan_skip) OR chan > (orig_channel + chan_skip)
If channel <= 14
- Set tmp to channel | 0x2B00
- Otherwise
- Set tmp to channel | 0x1B00
Call PHY Set Chanspec with tmp as argument
Call N PHY Classifier with arguments 7, 4
Call N PHY Clip Detection with arguments 1, clip_off
Call N PHY RF Ctrl Override with 0x400, 0x62C, 3, 0 as arguments
Write 0x120 to PHY Registers 0x91 and 0x92
Clear bit 0x2 in Radio Register 0x66
Clear bit 0x2 in Radio Register 0x95
- Write rccal_val to Radio Registers 0x71 and 0xA0
Call N PHY RSSI Sel with 5, 1 as arguments
- Write 0xFFFF to PHY Registers 0xC8 and 0xC9
Call N PHY RF Seq with 2 as the argument
- Set pwr_ch to 0
- Set w2_ch to 32
- Loop 2 times with core as index
Write core + 6 to PHY Register 0xCA
- Loop repeat_ctr times with ctr as index
- Set avg_adcpwr, avgw2, and count to 0
- Loop nsamps times with samp as index
- If core is 0
Read PHY Register 0x1C9 and save in gpio
- Otherwise
Read PHY Register 0x1CA and save in gpio
- Mask gpio with 0x3FF, left shift by 6, cast to s16, right shift by 8, and save as adc_code
- Right shift gpio by 10, mask with 0x3F, left shift by 2, cast to s8, right shift by 2, and save as w2
If abs(adc_code) > adc_code_thresh
- Increment count
- Add adc_code * adc_code to avg_adcpwr
- Add w2 to avgw2
- If core is 0
If count > count_thresh
- Divide avg_adcpwr by count
If avg_adcpwr > pwr_ch
- Divide avgw2 by count
- Set adcpwr_val to 1
- Loop num_adc_ranges times with i as index
If avg_adcpwr >= adc_pwrs[i] AND avg_adcpwr < adc_pwrs[i + 1]
If avgw2 < valid_w2s[i]
- Set adcpwr_val to 0
- Break
- If adcpwr_val is not zero
- Set pwr_ch to avg_adcpwr
- Set w2_ch to avgw2
- Delay 10 usec
If pwr > pwr_ch
- Set pwr to pwr_ch
Restore PHY Registers 0xCA, 0xC8, and 0xC9
Call N PHY RSSI Sel with 0, 0 as arguments
Restore Radio Registers 0x71, 0xA0, 0x66, and 0x95
Restore PHY Registers 0x0x91 and 0x92
Call N PHY RF Ctrl Override with 0x0400, 0, 3, 1 as arguments
Call N PHY Force RF Seq with argument 2
Call N PHY Clip Detection 1, clip_state as arguments
Call N PHY Classifier with 7, classifier_state as arguments
Call N PHY RF Seq with 2 as the argument
Call PHY Set Chanspec with argument orig_chanspec
If pwr > adc_pwrs[2]
- Return 3
Else if pwr > adc_pwrs[1]
- Return 2
Else if pwr > adc_pwrs[0]
- Return 1
- Return 0