-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from strath-sdr/update_clocks
Update clocks
- Loading branch information
Showing
12 changed files
with
452 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
all: block_design bitstream clean | ||
all: bitstream clean | ||
|
||
block_design: | ||
vivado -mode batch -source make_block_design.tcl -notrace | ||
|
||
bitstream: | ||
$(MAKE) block_design | ||
vivado -mode batch -source make_bitstream.tcl -notrace | ||
|
||
clean: | ||
rm -rf block_design *.jou *.log NA .Xil | ||
rm -rf block_design *.jou *.log NA .Xil || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
all: block_design bitstream clean | ||
all: bitstream clean | ||
|
||
block_design: | ||
vivado -mode batch -source make_block_design.tcl -notrace | ||
|
||
bitstream: | ||
$(MAKE) block_design | ||
vivado -mode batch -source make_bitstream.tcl -notrace | ||
|
||
clean: | ||
rm -rf block_design *.jou *.log NA .Xil | ||
rm -rf block_design *.jou *.log NA .Xil || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import os | ||
import xrfclk | ||
|
||
def _get_lmclk_devices(): | ||
"""Populate LMK and LMX devices. | ||
""" | ||
|
||
# Search for devices if none exist | ||
if xrfclk.lmk_devices == [] and xrfclk.lmx_devices == []: | ||
xrfclk.xrfclk._find_devices() | ||
|
||
def _get_custom_lmclks(loc): | ||
"""Search for LMK and LMX clock files with a given address. | ||
""" | ||
|
||
# Check type and value | ||
if not isinstance(loc, str): | ||
raise TypeError('Address location must be a string.') | ||
if not os.path.isdir(loc): | ||
raise ValueError('Address location does not exist.') | ||
|
||
# Variables | ||
lmk_loc = '' | ||
lmx_loc = '' | ||
lmclk_loc = '' | ||
|
||
# Walk through directory and find .txt files | ||
for root, dirs, files in os.walk(loc): | ||
for d in dirs: | ||
for lmk in xrfclk.lmk_devices: | ||
if d == lmk['compatible']: | ||
lmclk_loc = os.path.join(root, d) | ||
break | ||
|
||
# Check variable is empty | ||
if lmclk_loc == '': | ||
raise RuntimeError('Could not find lmclk files.') | ||
|
||
# Use root directory to extract LMK and LMX locs | ||
for file in os.listdir(lmclk_loc): | ||
if file.endswith('.txt'): | ||
if 'LMK' in file: | ||
lmk_loc = os.path.join(lmclk_loc, file) | ||
elif 'LMX' in file: | ||
lmx_loc = os.path.join(lmclk_loc, file) | ||
|
||
# Check variables are empty | ||
if lmk_loc == '' or lmx_loc == '': | ||
raise RuntimeError('Could not find lmclk files.') | ||
|
||
return lmk_loc, lmx_loc | ||
|
||
def _get_custom_lmclk_props(lmk_loc, lmx_loc): | ||
"""Obtain the properties for LMK and LMX clocks using | ||
a set of address locations for clock files. | ||
""" | ||
|
||
# Check type, value, and file format | ||
if not isinstance(lmk_loc, str) or not isinstance(lmx_loc, str): | ||
raise TypeError('TICS files must be a string.') | ||
if not os.path.isfile(lmk_loc) or not os.path.isfile(lmx_loc): | ||
raise ValueError('TICS file paths do not exist.') | ||
if not lmk_loc[-4:] == '.txt' or not lmx_loc[-4:] == '.txt': | ||
raise ValueError('TICS files must be .txt files.') | ||
|
||
# Strip file name from arguments | ||
lmk_name = lmk_loc.split('/')[-1] | ||
lmx_name = lmx_loc.split('/')[-1] | ||
|
||
# Split file name into LMK and LMX chip and freq (strip .txt) | ||
lmk_split = lmk_name.strip('.txt').split('_') | ||
lmx_split = lmx_name.strip('.txt').split('_') | ||
|
||
# Obtain LMK and LMX chip and freq components and | ||
# check for errors in format | ||
if len(lmk_split) == 2 and len(lmx_split) == 2: | ||
lmk_chip, lmk_freq = lmk_split | ||
lmx_chip, lmx_freq = lmx_split | ||
else: | ||
raise ValueError('TICS file names have incorrect format.') | ||
|
||
# Open files and parse registers | ||
with open(lmk_loc, 'r') as file: | ||
reg = [line.rstrip("\n") for line in file] | ||
lmk_reg = [int(r.split('\t')[-1], 16) for r in reg] | ||
with open(lmx_loc, 'r') as file: | ||
reg = [line.rstrip("\n") for line in file] | ||
lmx_reg = [int(r.split('\t')[-1], 16) for r in reg] | ||
|
||
# Populate TICS file dictionary | ||
clk_props = { | ||
'lmk' : { | ||
'file' : lmk_name, | ||
'loc' : lmk_loc, | ||
'chip' : lmk_chip, | ||
'freq' : lmk_freq, | ||
'reg' : lmk_reg | ||
}, | ||
'lmx' : { | ||
'file' : lmx_name, | ||
'loc' : lmx_loc, | ||
'chip' : lmx_chip, | ||
'freq' : lmx_freq, | ||
'reg' : lmx_reg | ||
} | ||
} | ||
|
||
return clk_props | ||
|
||
def _program_custom_lmclks(clk_props): | ||
"""Program the LMK and LMX clocks using clock properties. | ||
""" | ||
|
||
# Program each device | ||
for lmk in xrfclk.lmk_devices: | ||
xrfclk.xrfclk._write_LMK_regs(clk_props['lmk']['reg'], lmk) | ||
for lmx in xrfclk.lmx_devices: | ||
xrfclk.xrfclk._write_LMX_regs(clk_props['lmx']['reg'], lmx) | ||
|
||
def set_custom_lmclks(): | ||
"""Populate LMK and LMX clocks. Search for clock files. | ||
Obtain the properties of the clock files. Program the | ||
LMK and LMX clocks with the properties of the files. | ||
""" | ||
|
||
# Ensure LMK and LMX devices are known | ||
_get_lmclk_devices() | ||
|
||
# Get custom ref clock locs | ||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
lmk_loc, lmx_loc = _get_custom_lmclks(cwd) | ||
|
||
# Get custom ref clock props | ||
clk_props = _get_custom_lmclk_props(lmk_loc, lmx_loc) | ||
|
||
# Program custom ref clocks | ||
_program_custom_lmclks(clk_props) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
R0 (INIT) 0x00160040 | ||
R0 0x00143200 | ||
R1 0x00143201 | ||
R2 0x00140322 | ||
R3 0xC0140023 | ||
R4 0x40140024 | ||
R5 0x80141E05 | ||
R6 0x01100006 | ||
R7 0x01100007 | ||
R8 0x06010008 | ||
R9 0x55555549 | ||
R10 0x9102410A | ||
R11 0x0401100B | ||
R12 0x1B0C006C | ||
R13 0x2302886D | ||
R14 0x0200000E | ||
R15 0x8000800F | ||
R16 0xC1550410 | ||
R24 0x00000058 | ||
R25 0x02C9C419 | ||
R26 0x8FA8001A | ||
R27 0x10001E1B | ||
R28 0x0021201C | ||
R29 0x0180033D | ||
R30 0x0200033E | ||
R31 0x003F001F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.