int LP PHY Calc RX IQ Comp ( u16 num_samps)
- Create a struct {u32 iq_prod; u32 i_pwr; u32 q_pwr} called iq_est
Read PHY Register 0x49E, mask with 0xFF00, right shift by 8, and save as c0_new
Read PHY Register 0x49E, mask with 0x00FF and save as c1_new
MaskSet PHY Register 0x49E with mask 0xFF00 and set with 0x00C0
MaskSet PHY Register 0x49E with mask 0x00FF and set with 0
Set value to LP PHY RX IQ Est with arguments ( num_samps, 32, &iq_est)
- If value is zero
- Goto cleanup
- Set iq to the iq_prod member of iq_est
- Set ii to the i_pwr member of iq_est
- Set qq to the q_pwr member of iq_est
If ii + qq < 2
- Set value to 0
- Goto cleanup
Use PHY Nbits to calculate the number of bits in iq, save as iq_nbits
Use PHY Nbits to calculate the number of bits in qq, save as qq_nbits
- Set crsh to iq_nbits - 20
If crsh >= 0
Set c to ((iq << (30 - iq_nbits)) + (ii >> (1 + crsh))) / (ii >> crsh)
- Otherwise
Set c to ((iq << (30 - iq_nbits)) + (ii << (-1 - crsh))) / (ii << -crsh)
- Set arsh to qq_nbits - 11
If arsh >= 0
Set a to (qq << (31 - qq_nbits)) / (ii >> arsh)
- Otherwise
Set a to (qq << (31 - qq_nbits)) / (ii << -arsh)
- Subtract c * c from a
- a = -int_sqrt(a)
Set c0_new to c >> 3
Set c1_new to a >> 4
cleanup:
MaskSet PHY Register 0x49E with mask 0xFF00 and set with c1_new
MaskSet PHY Register 0x49E with mask 0x00FF and set with c0_new << 8
- Return value