bcm-v4

[Specification

int N PHY Cal RX IQ Rev 2 (struct nphy_txgains target, bool debug)

  1. Establish a 3-element u16 array called lna and preset to {3, 3, 1}
  2. Establish a 3-element u16 array called hpf1 and preset to {7, 2, 0}
  3. Establish a 3-element u16 array called hpf2 and preset to {2, 0, 0}
  4. Establish a 3-element u32 array called power
  5. Establish a 2-element u16 array called gain_save
  6. Establish a 2-element u16 array called cal_gain
  7. Establish a 2-element struct nphy_iqcal_params array named cal_params
  8. Establish a struct nphy_iq_est variable named est
  9. Initialize int ret to 0
  10. Initialize bool playtone to 1
  11. Initialized desired to 13
  12. Call N PHY Stay in Carrier Search with argument 1

  13. If PHY Revision < 2

    1. Call N PHY Reapply TX Cal Coeffs

  14. Read an N PHY Table with ID 7, length 2, offset 0x110, width 16, and data gain_save
  15. Loop 2 times with index i
    1. Call N PHY IQ Cal Gain Params with i, target, cal_params[i] as arguments

    2. Set cal_gain[i] to cal_params[i].cal_gain
  16. Write an N PHY Table with ID 7, length 2, offset 0x110, width 16, and data from cal_gain
  17. loop 2 times with index i
    1. Save PHY Register 0xA2 as tmp1
    2. Save PHY Register ((i == 0) ? 0xA6 : 0xA7) as tmp2
    3. Save PHY register 0xA5 as tmp3
    4. Save PHY Register ((i == 0) ? 0x91 : 0x92) as tmp4
    5. Save PHY Register ((i == 0) ? 0x92 : 0x91) as tmp5
    6. Maskset PHY Register 0xA2 with mask 0x0FFF and set with (1 - i) << 12

    7. Maskset PHY Register 0xA2 with mask 0xFFF0 and set with (1 - i)
    8. Set bits 0x0006 in PHY Register ((i == 0) ? 0xA6 : 0xA7)
    9. Set bits 0x0006 in PHY Register 0xA5
    10. If nphy_rxcalparams & 0xff000000 is not zero

      1. If the band if 5G
        1. Write 0x140 to PHY Register ((i == 0) ? 0x91 : 0x92)
      2. Otherwise
        1. Write 0x110 to PHY Register ((i == 0) ? 0x91 : 0x92)
    11. Otherwise
      1. If the band if 5G
        1. Write 0x180 to PHY Register ((i == 0) ? 0x91 : 0x92)
      2. Otherwise
        1. Write 0x120 to PHY Register ((i == 0) ? 0x91 : 0x92)
    12. If the band if 5G
      1. Write 0x148 to PHY Register ((i == 1) ? 0x91 : 0x92)
    13. Otherwise
      1. Write 0x114 to PHY Register ((i == 1) ? 0x91 : 0x92)
    14. If nphy_rxcalparams & 0x10000 is not 0

      1. Maskset Radio Register 0xD6 with mask 0xFC and set with (i + 1)
      2. Maskset Radio Register 0xE2 with mask 0xFC and set with (2 - i)
    15. Loop 4 times with index j
      1. If j < 3

        1. Set cur_lna to lna[j], cur_hpf1 to hpf1[j], and cur_hpf2 to hpf2[j]
      2. Otherwise
        1. If power[1] > 10000

          1. Set cur_lna to lna[2], cur_hpf1 to hpf1[2], and cur_hpf2 to hpf2[2]
          2. Set use to 1
          3. Set cur_hpf to cur_hpf1
          4. Set actual to number of bits in power[2]

        2. Otherwise
          1. If power[0] > 10000

            1. Set cur_lna to lna[1], cur_hpf1 to hpf1[1], and cur_hpf2 to hpf2[1]
            2. Set use to 1
            3. Set cur_hpf to cur_hpf1
            4. Set actual to number of bits in power[1]

          2. Otherwise
            1. Set cur_lna to lna[0], cur_hpf1 to hpf1[0], and cur_hpf2 to hpf2[0]
            2. Set use to 2
            3. Set cur_hpf to cur_hpf2
            4. Set actual to number of bits in power[0]

        3. Set change to desired - actual
        4. Add change to cur_hpf
        5. Clamp cur_hpf between 0 and 10
        6. If use is 1
          1. Set cur_hpf1 to cur_hpf
        7. Otherwise
          1. Set cur_hpf2 to cur_hpf
      3. Calculate tmp as ((cur_hpf2 << 8) | (cur_hpf1 << 4) | (cur_lna << 2))

      4. Call N PHY RF Ctrl Override with 0x400, tmp, 3, 0 as arguments

      5. Call N PHY Force RF Seq with 2 as argument

      6. Call N PHT Stop Playback

      7. If playtone is not zero
        1. Call N PHY TX Tone with 4000, (nphy_rxcalparams & 0xffff), 0, 0 as arguments and save result as ret

        2. Set playtone to 0
      8. Otherwise
        1. Call N PHY Run Samples with 160, 0xFFFF, 0, 0, 0 as arguments

      9. If ret is zero
        1. If j < 3

          1. Call N PHY RX IQ Est with &est, 1024, 32, 0 as arguments

          2. If i is 0
            1. Set real to (est.i0_pwr + 512) / 1024
            2. Set imag to (est.q0_pwr + 512) / 1024
          3. Otherwise
            1. Set real to (est.i1_pwr + 512) / 1024
            2. Set imag to (est.q1_pwr + 512) / 1024
          4. Set power[i] to real + imag
        2. Otherwise
          1. Call N PHY Calc RX IQ Comp with (1 << i) as argument

        3. Call N PHY Stop Playback

      10. If ret is not zero
        1. Break from loop
    16. Mask Radio Register 0xD6 with mask 0xFC
    17. Mask Radio Register 0xE2 with mask 0xFC
    18. Write tmp5 to PHY Register (i == 1) ? 0x91 : 0x92
    19. Write tmp4 to PHY Register (i == 0) ? 0x91 : 0x92
    20. Write tmp3 to PHY Register 0xA5
    21. Write tmp2 to PHY Register (i == 0) ? 0xA6 : 0xA7
    22. Write tmp1 to PHY Register 0xA2
    23. If ret is not zero
      1. Break from loop
  18. Call N PHY RF Ctrl Override with 0x400, 0, 3, 1 as arguments

  19. Call N PHY Force RF Seq with 2 as argument

  20. Write an N PHY Table with ID 7, length 2, offset 0x110, width 16, and data from gain_save
  21. Call N PHY Stay in Carrier Search with argument 0

  22. Return ret

Exported/Archived from the wiki to HTML on 2016-10-27