Skip to content

Commit 28493e7

Browse files
authored
Merge pull request #44 from strath-sdr/update_clocks
Update clocks
2 parents 35733c2 + e0a0553 commit 28493e7

File tree

12 files changed

+452
-79
lines changed

12 files changed

+452
-79
lines changed

boards/RFSoC4x2/rfsoc_qpsk/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
all: block_design bitstream clean
1+
all: bitstream clean
22

33
block_design:
44
vivado -mode batch -source make_block_design.tcl -notrace
55

66
bitstream:
7+
$(MAKE) block_design
78
vivado -mode batch -source make_bitstream.tcl -notrace
89

910
clean:
10-
rm -rf block_design *.jou *.log NA .Xil
11+
rm -rf block_design *.jou *.log NA .Xil || true

boards/ZCU111/rfsoc_qpsk/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
all: block_design bitstream clean
1+
all: bitstream clean
22

33
block_design:
44
vivado -mode batch -source make_block_design.tcl -notrace
55

66
bitstream:
7+
$(MAKE) block_design
78
vivado -mode batch -source make_bitstream.tcl -notrace
89

910
clean:
10-
rm -rf block_design *.jou *.log NA .Xil
11+
rm -rf block_design *.jou *.log NA .Xil || true

rfsoc_qpsk/__main__.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ def install():
3838
logfile = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', 'install.txt'))
3939
with open(logfile, 'w') as f:
4040
f.write(dst)
41-
install_xrfclk_files()
42-
43-
def install_xrfclk_files():
44-
src = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', package_name, 'xrfclk'))
45-
if os.path.exists(src):
46-
dst = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', 'xrfclk'))
47-
for file in os.listdir(src):
48-
shutil.copyfile(os.path.join(src, file), os.path.join(dst, file))
49-
50-
def uninstall_xrfclk_files():
51-
src = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', package_name, 'xrfclk'))
52-
if os.path.exists(src):
53-
dst = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', 'xrfclk'))
54-
for file in os.listdir(src):
55-
os.remove(os.path.join(dst, file))
5641

5742
def uninstall():
5843
logfile = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', 'install.txt'))
@@ -64,7 +49,6 @@ def uninstall():
6449
raise RuntimeError('Package is not installed. Nothing has been removed.\r\n')
6550
shutil.rmtree(dst)
6651
os.remove(logfile)
67-
uninstall_xrfclk_files()
6852

6953
def clean():
7054
uninstall()

rfsoc_qpsk/clocks.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import os
2+
import xrfclk
3+
4+
def _get_lmclk_devices():
5+
"""Populate LMK and LMX devices.
6+
"""
7+
8+
# Search for devices if none exist
9+
if xrfclk.lmk_devices == [] and xrfclk.lmx_devices == []:
10+
xrfclk.xrfclk._find_devices()
11+
12+
def _get_custom_lmclks(loc):
13+
"""Search for LMK and LMX clock files with a given address.
14+
"""
15+
16+
# Check type and value
17+
if not isinstance(loc, str):
18+
raise TypeError('Address location must be a string.')
19+
if not os.path.isdir(loc):
20+
raise ValueError('Address location does not exist.')
21+
22+
# Variables
23+
lmk_loc = ''
24+
lmx_loc = ''
25+
lmclk_loc = ''
26+
27+
# Walk through directory and find .txt files
28+
for root, dirs, files in os.walk(loc):
29+
for d in dirs:
30+
for lmk in xrfclk.lmk_devices:
31+
if d == lmk['compatible']:
32+
lmclk_loc = os.path.join(root, d)
33+
break
34+
35+
# Check variable is empty
36+
if lmclk_loc == '':
37+
raise RuntimeError('Could not find lmclk files.')
38+
39+
# Use root directory to extract LMK and LMX locs
40+
for file in os.listdir(lmclk_loc):
41+
if file.endswith('.txt'):
42+
if 'LMK' in file:
43+
lmk_loc = os.path.join(lmclk_loc, file)
44+
elif 'LMX' in file:
45+
lmx_loc = os.path.join(lmclk_loc, file)
46+
47+
# Check variables are empty
48+
if lmk_loc == '' or lmx_loc == '':
49+
raise RuntimeError('Could not find lmclk files.')
50+
51+
return lmk_loc, lmx_loc
52+
53+
def _get_custom_lmclk_props(lmk_loc, lmx_loc):
54+
"""Obtain the properties for LMK and LMX clocks using
55+
a set of address locations for clock files.
56+
"""
57+
58+
# Check type, value, and file format
59+
if not isinstance(lmk_loc, str) or not isinstance(lmx_loc, str):
60+
raise TypeError('TICS files must be a string.')
61+
if not os.path.isfile(lmk_loc) or not os.path.isfile(lmx_loc):
62+
raise ValueError('TICS file paths do not exist.')
63+
if not lmk_loc[-4:] == '.txt' or not lmx_loc[-4:] == '.txt':
64+
raise ValueError('TICS files must be .txt files.')
65+
66+
# Strip file name from arguments
67+
lmk_name = lmk_loc.split('/')[-1]
68+
lmx_name = lmx_loc.split('/')[-1]
69+
70+
# Split file name into LMK and LMX chip and freq (strip .txt)
71+
lmk_split = lmk_name.strip('.txt').split('_')
72+
lmx_split = lmx_name.strip('.txt').split('_')
73+
74+
# Obtain LMK and LMX chip and freq components and
75+
# check for errors in format
76+
if len(lmk_split) == 2 and len(lmx_split) == 2:
77+
lmk_chip, lmk_freq = lmk_split
78+
lmx_chip, lmx_freq = lmx_split
79+
else:
80+
raise ValueError('TICS file names have incorrect format.')
81+
82+
# Open files and parse registers
83+
with open(lmk_loc, 'r') as file:
84+
reg = [line.rstrip("\n") for line in file]
85+
lmk_reg = [int(r.split('\t')[-1], 16) for r in reg]
86+
with open(lmx_loc, 'r') as file:
87+
reg = [line.rstrip("\n") for line in file]
88+
lmx_reg = [int(r.split('\t')[-1], 16) for r in reg]
89+
90+
# Populate TICS file dictionary
91+
clk_props = {
92+
'lmk' : {
93+
'file' : lmk_name,
94+
'loc' : lmk_loc,
95+
'chip' : lmk_chip,
96+
'freq' : lmk_freq,
97+
'reg' : lmk_reg
98+
},
99+
'lmx' : {
100+
'file' : lmx_name,
101+
'loc' : lmx_loc,
102+
'chip' : lmx_chip,
103+
'freq' : lmx_freq,
104+
'reg' : lmx_reg
105+
}
106+
}
107+
108+
return clk_props
109+
110+
def _program_custom_lmclks(clk_props):
111+
"""Program the LMK and LMX clocks using clock properties.
112+
"""
113+
114+
# Program each device
115+
for lmk in xrfclk.lmk_devices:
116+
xrfclk.xrfclk._write_LMK_regs(clk_props['lmk']['reg'], lmk)
117+
for lmx in xrfclk.lmx_devices:
118+
xrfclk.xrfclk._write_LMX_regs(clk_props['lmx']['reg'], lmx)
119+
120+
def set_custom_lmclks():
121+
"""Populate LMK and LMX clocks. Search for clock files.
122+
Obtain the properties of the clock files. Program the
123+
LMK and LMX clocks with the properties of the files.
124+
"""
125+
126+
# Ensure LMK and LMX devices are known
127+
_get_lmclk_devices()
128+
129+
# Get custom ref clock locs
130+
cwd = os.path.dirname(os.path.realpath(__file__))
131+
lmk_loc, lmx_loc = _get_custom_lmclks(cwd)
132+
133+
# Get custom ref clock props
134+
clk_props = _get_custom_lmclk_props(lmk_loc, lmx_loc)
135+
136+
# Program custom ref clocks
137+
_program_custom_lmclks(clk_props)
138+

rfsoc_qpsk/qpsk_overlay.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import ipywidgets as ipw
77
from time import sleep
88

9-
from rfsoc_qpsk import dma_timer, sdr_plots, qpsk_rx, qpsk_tx
9+
from rfsoc_qpsk import dma_timer, sdr_plots, qpsk_rx, qpsk_tx, clocks
1010

1111

1212
class TimerRegistry():
@@ -55,8 +55,6 @@ def __init__(self, bitfile_name=None, init_rf_clks=True, dark_theme=False, prese
5555
bigger font
5656
5757
"""
58-
GEN3 = ['RFSoC4x2', 'ZCU208', 'ZCU216']
59-
GEN1 = ['RFSoC2x2', 'ZCU111']
6058

6159
# Generate default bitfile name
6260
if bitfile_name is None:
@@ -96,14 +94,8 @@ def __init__(self, bitfile_name=None, init_rf_clks=True, dark_theme=False, prese
9694
# Create Overlay
9795
super().__init__(bitfile_name, **kwargs)
9896

99-
# Determine board and set PLL appropriately
97+
# Determine board
10098
board = os.environ['BOARD']
101-
if board in GEN3:
102-
lmk_clk = 245.76
103-
elif board in GEN1:
104-
lmk_clk = 122.88
105-
else:
106-
raise RuntimeError('Platform not supported.') # shouldn't get here
10799

108100
# Extact in-use dataconverter objects with friendly names
109101
self.rf = self.usp_rf_data_converter_0
@@ -132,7 +124,7 @@ def __init__(self, bitfile_name=None, init_rf_clks=True, dark_theme=False, prese
132124

133125
# Start up LMX clock
134126
if init_rf_clks:
135-
xrfclk.set_ref_clks(lmk_clk, 409.6)
127+
clocks.set_custom_lmclks()
136128

137129
# Set sane DAC defaults
138130
self.dac_tile.DynamicPLLConfig(1, 409.6, 1024)
@@ -175,28 +167,6 @@ def __init__(self, bitfile_name=None, init_rf_clks=True, dark_theme=False, prese
175167

176168
self.timers = TimerRegistry()
177169

178-
def init_i2c(self):
179-
"""Initialize the I2C control drivers on RFSoC2x2.
180-
This should happen after a bitstream is loaded since I2C reset
181-
is connected to PL pins. The I2C-related drivers are made loadable
182-
modules so they can be removed or inserted.
183-
"""
184-
module_list = ['i2c_dev', 'i2c_mux_pca954x', 'i2c_mux']
185-
for module in module_list:
186-
cmd = "if lsmod | grep {0}; then rmmod {0}; fi".format(module)
187-
ret = os.system(cmd)
188-
if ret:
189-
raise RuntimeError(
190-
'Removing kernel module {} failed.'.format(module))
191-
192-
module_list.reverse()
193-
for module in module_list:
194-
cmd = "modprobe {}".format(module)
195-
ret = os.system(cmd)
196-
if ret:
197-
raise RuntimeError(
198-
'Inserting kernel module {} failed.'.format(module))
199-
200170
def plot_group(self, group_name, domains, get_time_data, fs, get_freq_data=None, get_const_data=None):
201171
"""Create a group of plots for a given set of data generators.
202172
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
R0 (INIT) 0x00160040
2+
R0 0x00143200
3+
R1 0x00143201
4+
R2 0x00140322
5+
R3 0xC0140023
6+
R4 0x40140024
7+
R5 0x80141E05
8+
R6 0x01100006
9+
R7 0x01100007
10+
R8 0x06010008
11+
R9 0x55555549
12+
R10 0x9102410A
13+
R11 0x0401100B
14+
R12 0x1B0C006C
15+
R13 0x2302886D
16+
R14 0x0200000E
17+
R15 0x8000800F
18+
R16 0xC1550410
19+
R24 0x00000058
20+
R25 0x02C9C419
21+
R26 0x8FA8001A
22+
R27 0x10001E1B
23+
R28 0x0021201C
24+
R29 0x0180033D
25+
R30 0x0200033E
26+
R31 0x003F001F

boards/ZCU208/rfsoc_qpsk/xrfclk/LMX2594_409.6.txt renamed to rfsoc_qpsk/xrfclk/lmk04208/LMX2594_409.6.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ R82 0x521E00
3232
R81 0x510000
3333
R80 0x506666
3434
R79 0x4F0026
35-
R78 0x4E00E5
35+
R78 0x4E0003
3636
R77 0x4D0000
3737
R76 0x4C000C
3838
R75 0x4B0980
@@ -65,16 +65,16 @@ R49 0x314180
6565
R48 0x300300
6666
R47 0x2F0300
6767
R46 0x2E07FC
68-
R45 0x2DC0DF
69-
R44 0x2C1F20
68+
R45 0x2DC0CC
69+
R44 0x2C0C23
7070
R43 0x2B0000
7171
R42 0x2A0000
7272
R41 0x290000
7373
R40 0x280000
7474
R39 0x270001
7575
R38 0x260000
76-
R37 0x250104
77-
R36 0x240190
76+
R37 0x250304
77+
R36 0x240050
7878
R35 0x230004
7979
R34 0x220000
8080
R33 0x211E21
@@ -90,24 +90,24 @@ R24 0x18071A
9090
R23 0x17007C
9191
R22 0x160001
9292
R21 0x150401
93-
R20 0x14C848
93+
R20 0x14E048
9494
R19 0x1327B7
9595
R18 0x120064
96-
R17 0x110117
96+
R17 0x11012C
9797
R16 0x100080
9898
R15 0x0F064F
99-
R14 0x0E1E40
99+
R14 0x0E1E70
100100
R13 0x0D4000
101101
R12 0x0C5001
102-
R11 0x0B00A8
102+
R11 0x0B0018
103103
R10 0x0A10D8
104104
R9 0x090604
105105
R8 0x082000
106106
R7 0x0740B2
107107
R6 0x06C802
108108
R5 0x0500C8
109-
R4 0x040C43
109+
R4 0x040A43
110110
R3 0x030642
111111
R2 0x020500
112-
R1 0x010809
113-
R0 0x00241C
112+
R1 0x010808
113+
R0 0x00249C

0 commit comments

Comments
 (0)