N PHY RSSI Calibrate
If PHY Revision >= 3
- Otherwise
- Call N PHY RSSI Calibrate Rev 2 with argument 2 (below)
- Call N PHY RSSI Calibrate Rev 2 with argument 0
- Call N PHY RSSI Calibrate Rev 2 with argument 1
N PHY RSSI Calibrate Rev 2 (u8 type)
- Establish a 2-element u16 array clip_state
- Establish a 2-element u16 array clip_off and preset with 0xFFFF in both elements
- Create a 4-element s32 array results_min and initialize to zero
- Create a 4-element u8 array vcm_final and initialize to zero
- Create a 4 x 4 s32 array called results and initialize to 0
- Create a 4 x 2 s32 array called miniq and initialize to zero
- If type is 2
- Set code to 0
- Set val to 6
- Else if type is 0 or 1
- Set code to 25
- Set val to 4
- Otherwise
- Return
Call N PHY Classifier with arguments 0, 0 and save as class
Call N PHY Classifier with arguments 7, 4
Call N PHY Clip Detection with arguments 0, clip_state
Call N PHY Clip Detection with arguments 1, clip_off
- If band is 5G
- Set override to 0x140
- Otherwise
- Set override to 0x110
- Save PHY Register 0x91
- Save Radio Register 0x17
- Write override to PHY Register 0x91
- Write val to Radio Register 0x17
- Save PHY Register 0x92
- Save Radio Register 0x1B
- Write override to PHY Register 0x92
- Write val to Radio Register 0x1B
- Read Radio Register 0x18, mask with 0x07 and save as state0
- Read Radio Register 0x1c, mask with 0x07 and save as state1
- Maskset Radio Register 0x18 with mask 0xF8 and set with 0
- Maskset Radio Register 0x1C with mask 0xF8 and set with 0
- Read Radio Register 0x03, mask with 0x07 and save as state2
- Read Radio Register 0x05, mask with 0x07 and save as state3
Call N PHY RSSI Select with arguments 5 and type
Call N PHY Scale Offset RSSI with arguments 0, 0, 5, 0, type
Call N PHY Scale Offset RSSI with arguments 0, 0, 5, 1, type
- Loop 4 times with index i
- Set all elements of a 4-element array tmp to the loop index
- If type is not 1
Call N PHY Set RSSI 2055 VCM with arguments type, tmp
Call N PHY Poll RSSI with type, &results[i][0], 8 as arguments
- If type is 0 or 1
- Loop 2 times with index j
- Set miniq[i][j] to the minimum of (results[i][2 * j], results[i][2 * j + 1])
- Loop 2 times with index j
- Loop 4 times with index i
- Set mind to 0x100000
- Set minvcm to 0
- Set minpoll to 249
- Loop 4 times with index j
- If type is 2
- Set current to abs(results[j][i] - code * 8)
- Otherwise
- Set current to abs(miniq[j][i / 2] - code * 8)
If current < mind
- Set mind to current
- Set minvcm to j
If results[j][i] < minpoll
- Set minpoll to results[j][i]
- If type is 2
- Set results_min[i] to minpoll
- Set vcm_final[i] to minvcm
- If type is not 1
Call N PHY Set RSSI 2055 VCM with arguments type, vcm_final
- Loop 4 times with index i
- Set offset[i] to (code * 8) - results[vcm_final[i]][i]
If offset[i] < 0
- Set offset[i] to -((abs(offset[i]) + 4) / 8)
- Otherwise
- Set offset to (offset + 4) / 8
- If results_min[i] equals 248
- Set offset[i] to code - 32
- If i % 2 is zero
- Set arg2 to 0
- Otherwise
- Set arg2 to 1
- If i / 2 is 0
- Set arg1 to 1
- Otherwise
- Set arg1 to 2
Call N PHY Scale Offset RSSI with arguments 0, offset[i], arg1, arg2, type
MaskSet Radio Register 0x18 with mask 0xF8 and set with state0
MaskSet Radio Register 0x1C with mask 0xF8 and set with state1
- If state2 is 1
Call N PHY RSSI Select with arguments 1, 2
- Else if state2 is 4
Call N PHY RSSI Select with arguments 1, 0
- Else if state2 is 2
Call N PHY RSSI Select with arguments 1, 1
- Otherwise
Call N PHY RSSI Select with arguments 1, 1
- If state3 is 1
Call N PHY RSSI Select with arguments 2, 2
- Else if state3 is 4
Call N PHY RSSI Select with arguments 2, 0
- Otherwise
Call N PHY RSSI Select with arguments 2, 1
Call N PHY RSSI Select with arguments 0, type
- Restore PHY Register 0x91
- Restore Radio Register 0x17
- Restore PHY Register 0x92
- Restore Radio Register 0x1B
Call N PHY Classifier with 7, class as arguments
Call N PHY Clip Detection with 1, clip_state as arguments