N PHY Cal TX Gain Control (int target, bool debug)
- Create a 2-element u32 array called power
Call N PHY TX Power Index with 1, nphy_cal_orig_pwr_index[0], 1 as arguments
Call N PHY TX Power Index with 1, nphy_cal_orig_pwr_index[1], 1 as arguments
If phyhang_avoid
Call N PHY Carrier Search with 1 as argument
Save value in phyhang_avoid
Set phyhang_avoid to 0
- Save PHY Registers 0x91, 0x92, 0xE7 and 0xEC
Call N PHY RF Control Intc Override with 2, 1, 3 as arguments
- If debug is 0
Call N PHY RF Control Intc Override with 1, 2, 1 as arguments
Call N PHY RF Control Intc Override with 1, 8, 2 as arguments
- Otherwise
Call N PHY RF Control Intc Override with 1, 1, 1 as arguments
Call N PHY RF Control Intc Override with 1, 7, 2 as arguments
- Save PHY Register 0x01
- Mask PHY Register 0x01 with mask 0xFFDA
- Write 0x3C57 to PHY Register 0x72
- Read PHY Register 0x73 and save as m1
- Loop 2 times with index i
Set index to nphy_cal_orig_pwr_idx[i]
- Loop 2 times with index j
Call N PHY TX Tone with 2500, 250, 0, 0 as arguments
- If i is 0
- Mask m1 with 0xFF00 and save as m2
- Otherwise
- Mask m1 with 0x00FF and save as m2
- Write 0x3C57 to PHY Register 0x72
- Write m2 to PHY Register 0x73
- Write 0x3C5F to PHY Register 0x72
- Write m2 to PHY Register 0x73
- Delay 50 usec
Call N PHY Estimate Tone Power with power, 128 as arguments
Set nphy_bb_mult_save to 0
Call N PHY Stop Playback
- Set diff to target * 4 - power[i]
- Reduce index by diff
- Clamp index between 0 and 127
Call N PHY TX Power Index with 1 << i, index, 1 as arguments
Set nphy_cal_orig_pwr_idx[i] to index
- If debug is 1
- Write 0x3C57 to PHY Register 0x72
- Read PHY Register 0x73 and save as tmp
Call N PHY TX Tone with 2500, 450, 0, 0 as arguments
- Write 0x3C57 to PHY Register 0x72
- Write tmp to PHY Register 0x73
- Write 0x3C5F to PHY Register 0x72
- Write tmp to PHY Register 0x73
- Delay 100 usec
Call N PHY Estimate Tone Power with power, 64 as arguments
- Write (0x1D10 + i) to PHY Register 0x72
- Read PHY Register 0x73 and save as gain
- Sleep for 4 seconds (??????)
Set nphy_bb_mult_save to 0
Call N PHY Stop Playback
Call N PHY TX Power Index with 1, nphy_txcal_pwr_idx[0], 1 as arguments
Call N PHY TX Power Index with 2, nphy_txcal_pwr_idx[1], 1 as arguments
- Write 0x3C57 to PHY Register 0x72
Read PHY Register 0x73 and save as nphy_txcal_bbmult
- Restore PHY Registers 0x01, 0x91, 0x92, 0xE7 and 0xEC
Restore original value of phyhang_avoid
If phyhang_avoid
Call N PHY Carrier Search with 0 as argument