forked from greatscottgadgets/hackrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlollipop_logic.py
executable file
·201 lines (173 loc) · 5.18 KB
/
lollipop_logic.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Jared Boone
#
# This file is part of HackRF.
#
# This is a free hardware design; 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, or (at your option)
# any later version.
#
# This design 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 design; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
# This program is used to verify the logic on the Lollipop board, to
# make sure control of the various RF paths is correct.
class Component(object):
def __init__(self, **kwargs):
self.state = kwargs
def __repr__(self):
state_key = ''.join(
map(str,
map(int,
(self.state[input] for input in self.inputs)
)
)
)
if state_key not in self.states:
return 'Invalid'
else:
return self.functions[self.states[state_key]]
class SKY13317(Component):
inputs = (
'V1',
'V2',
'V3',
)
states = {
# V1, V2, V3
'100': 'RFC to RF1',
'010': 'RFC to RF2',
'001': 'RFC to RF3',
}
class SKY13351(Component):
inputs = (
'VCTL1',
'VCTL2',
)
states = {
# VCTL1, VCTL2
'01': 'INPUT to OUTPUT1',
'10': 'INPUT to OUTPUT2',
}
class U2_4(SKY13351):
name = 'U2/4'
functions = {
'INPUT to OUTPUT1': 'tx bandpass',
'INPUT to OUTPUT2': 'tx mixer'
}
class U6_9(SKY13351):
name = 'U6/9'
functions = {
'INPUT to OUTPUT1': 'tx lowpass',
'INPUT to OUTPUT2': 'tx highpass',
}
class U3(SKY13317):
name = 'U3'
functions = {
'RFC to RF1': 'tx highpass',
'RFC to RF2': 'tx lowpass',
'RFC to RF3': 'tx bandpass',
}
class U7(SKY13351):
name = 'U7'
functions = {
'INPUT to OUTPUT1': 'rx switch',
'INPUT to OUTPUT2': 'tx path',
}
class U10(SKY13351):
name = 'U10'
functions = {
'INPUT to OUTPUT1': 'tx/rx switch',
'INPUT to OUTPUT2': 'rx antenna',
}
class U15(SKY13317):
name = 'U15'
functions = {
'RFC to RF1': 'rx bandpass',
'RFC to RF2': 'rx highpass',
'RFC to RF3': 'rx lowpass',
}
class U12_14(SKY13351):
name = 'U12/14'
functions = {
'INPUT to OUTPUT1': 'rx lowpass',
'INPUT to OUTPUT2': 'rx highpass',
}
class U16_18(SKY13351):
name = 'U16/18'
functions = {
'INPUT to OUTPUT1': 'rx mixer',
'INPUT to OUTPUT2': 'rx bandpass',
}
def compute_logic(**inputs):
outputs = dict(inputs)
outputs['swtxb2'] = not inputs['swtxb1']
outputs['swrxb2'] = not inputs['swrxb1']
outputs['swtxa2'] = not inputs['swtxa1']
outputs['swrxa2'] = not inputs['swrxa1']
outputs['swd2'] = not inputs['swd1']
outputs['swrxv2'] = outputs['swrxb2'] and outputs['swrxa1']
outputs['swrxv3'] = outputs['swrxb2'] and outputs['swrxa2']
outputs['swtxv1'] = outputs['swtxa1'] and outputs['swtxb1']
outputs['swtxv2'] = outputs['swtxa2'] and outputs['swtxb1']
# Force boolean True/False (result of "not" operator) to 1 or 0.
for key in outputs:
outputs[key] = int(outputs[key])
return outputs
def print_signals(signals):
print(', '.join(('%s=%s' % (name, signals[name]) for name in sorted(signals))))
def print_circuit_state(signals):
components = (
U2_4(VCTL1=signals['swtxb1'], VCTL2=signals['swtxb2']),
U6_9(VCTL1=signals['swtxa1'], VCTL2=signals['swtxa2']),
U3(V1=signals['swtxv1'], V2=signals['swtxv2'], V3=signals['swtxb2']),
U7(VCTL1=signals['swd2'], VCTL2=signals['swd1']),
U10(VCTL1=signals['swd2'], VCTL2=signals['swd1']),
U15(V1=signals['swrxb1'], V2=signals['swrxv2'], V3=signals['swrxv3']),
U12_14(VCTL1=signals['swrxa1'], VCTL2=signals['swrxa2']),
U16_18(VCTL1=signals['swrxb1'], VCTL2=signals['swrxb2'])
)
for component in components:
print('%s: %s' % (component.name, component))
def make_bits_from_numbers(i, bit_count):
return [int(c) for c in bin(i)[2:].zfill(bit_count)]
print('Transmit')
print('========')
print
for i in range(4):
inputs = {
'swtxb1': (i >> 1) & 1,
'swtxa1': (i >> 0) & 1,
'swrxa1': 0,
'swrxb1': 0,
'swd1': 0,
}
outputs = compute_logic(**inputs)
print_signals(outputs)
print_circuit_state(outputs)
print
print('Receive')
print('========')
print
for i in range(4):
inputs = {
'swtxb1': 0,
'swtxa1': 0,
'swrxa1': (i >> 1) & 1,
'swrxb1': (i >> 0) & 1,
'swd1': 0,
}
outputs = compute_logic(**inputs)
print_signals(outputs)
print_circuit_state(outputs)
print