-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathadf435xctl
executable file
·73 lines (61 loc) · 2.35 KB
/
adf435xctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
##
## This file is part of the pyadf435x project.
##
## Copyright (C) 2017 Joel Holdsworth <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
from collections import OrderedDict
import adf435x
import adf435x.interfaces
import argparse
import inspect
parser = argparse.ArgumentParser(description='Controls an ADF4350/1')
# Populate arguments
calculate_regs_spec = inspect.getfullargspec(adf435x.calculate_regs)
make_regs_spec = inspect.getfullargspec(adf435x.make_regs)
arg_dict = OrderedDict()
for arg, default in zip(calculate_regs_spec.args, calculate_regs_spec.defaults):
arg_dict[arg] = default
for arg, default in zip(make_regs_spec.args, make_regs_spec.defaults):
if arg not in arg_dict:
arg_dict[arg] = default
for arg in arg_dict.keys():
val=arg_dict[arg]
parser.add_argument('--' + arg.lower().replace('_', '-'),
default=val, type=type(val))
for r in range(6):
parser.add_argument('--r%d' % r, default=None, type=str)
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('--interface', default='FX2')
# Parse
args = vars(parser.parse_args())
# Generate register values
calculate_regs_kw = {arg : args[arg.lower()]
for arg in calculate_regs_spec.args}
kw = {arg : args[arg.lower()] for arg in make_regs_spec.args}
kw['INT'], kw['MOD'], kw['FRAC'], kw['output_divider'], \
kw['band_select_clock_divider'] = adf435x.calculate_regs(
**calculate_regs_kw)
regs = adf435x.make_regs(**kw)
for i in range(6):
r = args['r%d' % i]
if r != None:
regs[i] = int(r, 0)
if args['verbose']:
for r in range(6):
print('r%d = 0x%08x' % (r, regs[r]))
intf = getattr(adf435x.interfaces, args['interface'])()
intf.set_regs(regs[::-1])