source: PlatformSupport/CustomPeripherals/pcores/radio_controller_axi_v3_01_a/src/max2829_pll_tune_val_gen.py

Last change on this file was 6317, checked in by murphpo, 3 years ago

Updated max2829_pll_tune_val_gen.py script to work with Py3 (Py3 map returns generator, wrapped in list so map output can be reused to print both reg3 and reg4 arrays)

File size: 3.9 KB
Line 
1# Python code to generate arrays of PLL tuning register values for MAX2829
2
3def calc_div_ratio_24(center_freq):
4    return (center_freq * 4.0/3.0) / 20.0
5
6def calc_div_ratio_5(center_freq):
7    return (center_freq * 4.0/5.0) / 20.0
8
9def calc_div_ratio_int(div_ratio):
10    return int(div_ratio)
11
12def calc_div_ratio_frac_as_int(div_ratio):
13    return int(div_ratio * 2**16)
14
15def calc_reg34_vals(div_ratio):
16    # Each divider ratio is represented as a UFix26_16 (10 integer bits, 16 fractional bits)
17    # reg3:
18    # [13:12]: 2LSB of fractional part of div ratio
19    # [11: 8]: Zeros
20    # [ 9: 0]: Integer part (UFix10_0) of div ratio
21    # reg4:
22    # [13: 0]: 14MSB of fractional part of div ratio
23
24    dr_i = calc_div_ratio_int(div_ratio)
25    df_fi = calc_div_ratio_frac_as_int(div_ratio)
26
27    reg3 = (dr_i & 0x3FF) | ((df_fi & 0x3) << 12)
28    reg4 = ((df_fi & 0xFFFC) >> 2)
29
30    return (reg3, reg4)
31
32center_freqs_24 = [2412,   2417,   2422,   2427,   2432,   2437,   2442,   2447,   2452,   2457,   2462,   2467,   2472,   2484]
33div_ratios_24 = list(map(calc_div_ratio_24, center_freqs_24))
34regs = list(map(calc_reg34_vals, div_ratios_24))
35
36c_l1 = 'static u16 rc_tuningParams_24GHz_freqs[{0}] = {{ {1} }};'.format(len(center_freqs_24), ', '.join(map(str, center_freqs_24)))
37c_l2 = 'static u16 rc_tuningParams_24GHz_reg3[{0}] = {{ {1} }};'.format(len(center_freqs_24), ', '.join(map(hex, [x[0] for x in regs])))
38c_l3 = 'static u16 rc_tuningParams_24GHz_reg4[{0}] = {{ {1} }};'.format(len(center_freqs_24), ', '.join(map(hex, [x[1] for x in regs])))
39
40print(c_l1 + '\n' + c_l2 + '\n' + c_l3 + '\n')
41
42center_freqs_5 = [  5180, 5190, 5200, 5220, 5230, 5240, 5260, 5270, 5280, 5300,
43                    5310, 5320, 5500, 5510, 5520, 5540, 5550, 5560, 5580, 5590,
44                    5600, 5620, 5630, 5640, 5660, 5670, 5680, 5700, 5710, 5720,
45                    5745, 5755, 5765, 5785, 5795, 5805, 5825, 5860, 5870, 5875,
46                    5880, 5885, 5890, 5865]
47
48div_ratios_5 = list(map(calc_div_ratio_5, center_freqs_5))
49regs = list(map(calc_reg34_vals, div_ratios_5))
50
51c_l1 = 'static u16 rc_tuningParams_5GHz_freqs[{0}] = {{ {1} }};'.format(len(center_freqs_5), ', '.join(map(str, center_freqs_5)))
52c_l2 = 'static u16 rc_tuningParams_5GHz_reg3[{0}] = {{ {1} }};'.format(len(center_freqs_5), ', '.join(map(hex, [x[0] for x in regs])))
53c_l3 = 'static u16 rc_tuningParams_5GHz_reg4[{0}] = {{ {1} }};'.format(len(center_freqs_5), ', '.join(map(hex, [x[1] for x in regs])))
54
55print(c_l1 + '\n' + c_l2 + '\n' + c_l3 + '\n')
56
57if 0:
58    # Print doxygen-style table of channel indexes and center frequencies
59    #  Can be copy/pasted into doxygen comment above radio_controller_setCenterFrequency
60
61    print('2.4GHz <br> Chan | Freq <br> (MHz) | | 5GHz <br> Chan | Freq <br> (MHz)')
62    print('--- | ----- | - | --- | -----')
63
64    # Want lines like:
65    # '  1 | 2412  |   |   1 | 5180'
66    # ' 14 | 2484  |   |  14 | 5510'
67    # '    |       |   |  22 | 5620'
68    for ii in range(len(center_freqs_5)):
69        if(ii < len(center_freqs_24)):
70            print('{0} | {1} |  | {0} | {2}'.format(ii+1, center_freqs_24[ii], center_freqs_5[ii]))
71        else:
72            print('- | - | | {0} | {1}'.format(ii+1, center_freqs_5[ii]))
73
74if 0:
75    # Print wiki-style table output, to be copy-pasted into warplab command doc string
76
77    # ||||=  2.4GHz  =||||=  5GHz  =||
78    # || Chan || Freq || Chan || Freq ||
79    # ||  1 ||    2412 ||  1 ||    5180 ||
80    # || || ||  12 ||   5560 ||
81
82    print('                    % ||||=  2.4GHz  =||||=  5GHz  =||')
83    print('                    % || Chan || Freq || Chan || Freq ||')
84
85    for ii in range(len(center_freqs_5)):
86        if(ii < len(center_freqs_24)):
87            print('                    % ||  {0} ||    {1} ||  {0} ||    {2} ||'.format(ii+1, center_freqs_24[ii], center_freqs_5[ii]))
88        else:
89            print('                    % || || ||  {0} ||    {1} ||'.format(ii+1, center_freqs_5[ii]))
90
Note: See TracBrowser for help on using the repository browser.