N PHY Calc RX IQ Comp (u8 mask)
- Establish a struct nphy_iq_est named est
- Establist 2 struct nphy_iq_comp named old and new
- Set error to 0
- If mask is 0
- Return
Call N PHY RX IQ Coeffs with 0, &old as arguments
- Set new.a0, new.b0, new.a1, and new.b1 to 0
Call N PHY RX IQ Coeffs with 1, &new as arguments
Call N PHY RX IQ Est with &est, 0x4000, 32, 0 as arguments
- Set new to old
- Loop 2 times with i as index
If i is zero and (mask & 1) is not zero
- Set iq to est.iq0_prod
- Set ii to est.i0_pwr
- Set qq to est.q0_pwr
Else if i is 1 and (mask & 2) is not zero
- Set iq to est.iq1_prod
- Set ii to est.i1_pwr
- Set qq to est.q1_pwr
- Otherwise
- Continue
If ii + qq < 2
- Set error to -1
- Break from loop
Set iq_nbits to Number of bits in iq
Set qq_nbits to Number of bits in qq
- Set arsh to iq_nbits - 20
If arsh >= 0
Set a to -((iq << (30 - iq_nbits)) + (ii >> (1 + arsh)))
Set tmp to ii >> arsh
- If tmp is zero
- Set error to -1
- Break from loop
- Otherwise
Set a to -((iq << (30 - iq_nbits)) + (ii << (-1 - arsh)))
Set tmp to ii << -arsh
- If tmp is zero
- Set error to -1
- Break from loop
- Replace a by a / tmp
- Set brsh to qq_nbits - 11
If brsh >= 0
Set b to (qq << (31 - qq_nbits))
Set tmp to ii >> brsh
- If tmp is zero
- Set error to -1
- Break
- Otherwise
Set b to (qq << (31 - qq_nbits))
Set tmp to (ii << -brsh)
- If tmp is zero
- Set error to -1
- Break
Set b to sqrt (b / tmp - a * a) - (1 << 10)
If i is zero and (mask & 0x1) is not zero
If PHY Revision >= 3
Set new.a0 to a & 0x3FF
Set new.b0 to b & 0x3FF
- Otherwise
Set new.a0 to b & 0x3FF
Set new.b0 to a & 0x3FF
If i is 1 and mask & 0x2 is not zero
If PHY Revision >= 3
Set new.a1 to a & 0x3FF
Set new.b1 to b & 0x3FF
- Otherwise
Set new.a1 to b & 0x3FF
Set new.b1 to a & 0x3FF
- If error is not zero
- Set new to old
Call N PHY RX IQ Coeffs with 1, &new as arguments