Skip to content

Commit d678bb3

Browse files
committedNov 18, 2016
phaser: update sawg tests
1 parent 51f23fe commit d678bb3

File tree

5 files changed

+78
-51
lines changed

5 files changed

+78
-51
lines changed
 

‎artiq/gateware/dsp/sawg.py

+40-28
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ def __init__(self, widths, parallelism=1, a_delay=0):
3636

3737
self.comb += [
3838
xy_delay.i.eq(Cat(self.i.x, self.i.y)),
39-
z_delay.i.eq(Cat([zi[-widths.p:]
40-
for zi in accu.o.payload.flatten()])),
39+
z_delay.i.eq(Cat(zi[-widths.p:]
40+
for zi in accu.o.payload.flatten())),
4141
eqh(accu.i.p, self.i.p),
4242
accu.i.f.eq(self.i.f),
4343
accu.i.clr.eq(self.i.clr),
4444
accu.i.stb.eq(self.i.stb),
4545
self.i.ack.eq(accu.i.ack),
4646
accu.o.ack.eq(1),
4747
[Cat(c.xi, c.yi).eq(xy_delay.o) for c in cordic],
48-
Cat([c.zi for c in cordic]).eq(z_delay.o),
48+
Cat(c.zi for c in cordic).eq(z_delay.o),
4949
]
5050

5151

@@ -71,8 +71,15 @@ def __init__(self, widths, orders, **kwargs):
7171
f.o.ack.eq(self.ce),
7272
eqh(self.i.f, f.o.a0),
7373
eqh(self.i.p, p.o.a0),
74-
self.i.clr.eq(self.clr),
75-
self.i.stb.eq(p.o.stb & f.o.stb),
74+
self.i.stb.eq(p.o.stb | f.o.stb),
75+
]
76+
77+
assert p.latency == 1
78+
self.sync += [
79+
self.i.clr.eq(0),
80+
If(p.i.stb,
81+
self.i.clr.eq(self.clr),
82+
),
7683
]
7784

7885

@@ -94,20 +101,24 @@ def __init__(self, widths, orders, **kwargs):
94101

95102

96103
class Config(Module):
97-
def __init__(self):
98-
self.clr = Signal(4)
99-
self.iq_en = Signal(2)
100-
limit = [Signal((16, True)) for i in range(2*2)]
101-
self.limit = [limit[i:i + 2] for i in range(0, len(limit), 2)]
102-
self.i = Endpoint([("addr", bits_for(len(limit) + 2)), ("data", 16)])
104+
def __init__(self, width):
105+
self.clr = Signal(4, reset=0b1111)
106+
self.iq_en = Signal(2, reset=0b01)
107+
self.limit = [[Signal((width, True), reset=-(1 << width - 1)),
108+
Signal((width, True), reset=(1 << width - 1) - 1)]
109+
for i in range(2)]
110+
self.i = Endpoint([("addr", bits_for(4 + 2*len(self.limit))),
111+
("data", 16)])
103112
self.ce = Signal()
104113

105114
###
106115

107-
div = Signal(16)
116+
div = Signal(16, reset=0)
108117
n = Signal.like(div)
118+
pad = Signal()
109119

110-
reg = Array([Cat(self.clr, self.iq_en), Cat(div, n)] + self.limit)
120+
reg = Array([Cat(div, n), self.clr, self.iq_en, pad] +
121+
sum(self.limit, []))
111122

112123
self.comb += [
113124
self.i.ack.eq(1),
@@ -130,22 +141,22 @@ def __init__(self, width=16, parallelism=4, widths=None, orders=None):
130141
orders = _Orders(a=4, f=2, p=1)
131142
if widths is None:
132143
widths = _Widths(t=width, a=orders.a*width, p=orders.p*width,
133-
f=3*width + (orders.f - 1)*width)
144+
f=(orders.f + 2)*width)
134145

135-
cfg = Config()
136-
a1 = SplineParallelDDS(widths, orders)
137-
a2 = SplineParallelDDS(widths, orders)
138-
b = SplineParallelDUC(widths, orders, parallelism=parallelism,
139-
a_delay=-a1.latency)
146+
self.submodules.a1 = a1 = SplineParallelDDS(widths, orders)
147+
self.submodules.a2 = a2 = SplineParallelDDS(widths, orders)
148+
self.submodules.b = b = SplineParallelDUC(
149+
widths, orders, parallelism=parallelism, a_delay=-a1.latency)
150+
cfg = Config(widths.a)
140151
u = Spline(width=widths.a, order=orders.a)
141152
du = Delay(widths.a, a1.latency + b.latency - u.latency)
142-
self.submodules += cfg, a1, a2, b, u, du
143-
self.cfg = cfg.i
153+
self.submodules += cfg, u, du
144154
self.u = u.tri(widths.t)
145-
self.i = [self.cfg, self.u, a1.a, a1.f, a1.p, a2.a, a2.f, a2.p, b.f, b.p]
146-
self.y_in = [Signal((width, True)) for i in range(b.parallelism)]
147-
self.y_out = b.yo
148-
self.o = [Signal((width, True)) for i in range(b.parallelism)]
155+
self.i = [cfg.i, self.u, a1.a, a1.f, a1.p, a2.a, a2.f, a2.p, b.f, b.p]
156+
self.i_names = "cfg u a1 f1 p1 a2 f2 p2 f0 p0".split()
157+
self.i_named = dict(zip(self.i_names, self.i))
158+
self.y_in = [Signal((width, True)) for i in range(parallelism)]
159+
self.o = [Signal((width, True)) for i in range(parallelism)]
149160
self.widths = widths
150161
self.orders = orders
151162
self.parallelism = parallelism
@@ -167,10 +178,11 @@ def __init__(self, width=16, parallelism=4, widths=None, orders=None):
167178
# wire up outputs and q_{i,o} exchange
168179
for o, x, y in zip(self.o, b.xo, self.y_in):
169180
self.sync += [
170-
o.eq(self.sat_add([du.o,
181+
o.eq(self.sat_add([
182+
du.o,
171183
Mux(cfg.iq_en[0], x, 0),
172184
Mux(cfg.iq_en[1], y, 0)])),
173185
]
174186

175-
def connect_q_from(self, buddy):
176-
self.comb += Cat(self.y_in).eq(Cat(buddy.y_out))
187+
def connect_y(self, buddy):
188+
self.comb += Cat(buddy.y_in).eq(Cat(self.b.yo))

‎artiq/gateware/rtio/phy/sawg.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ def __init__(self, *args, **kwargs):
1616
_ChannelPHY.__init__(self, *args, **kwargs)
1717
self.phys = []
1818
for i in self.i:
19-
rl = rtlink.Interface(rtlink.OInterface(
20-
min(32, len(i.payload)))) # TODO: test/expand
19+
rl = rtlink.Interface(rtlink.OInterface(len(i.payload)))
2120
self.comb += [
2221
i.stb.eq(rl.o.stb),
2322
rl.o.busy.eq(~i.ack),
24-
Cat(i.payload.flatten()).eq(rl.o.data),
23+
i.payload.raw_bits().eq(rl.o.data),
2524
]
26-
# no probes, overrides
25+
# TODO probes, overrides
2726
self.phys.append(_Phy(rl, [], []))
28-
self.phys_names = dict(zip("cfg f0 p0 a1 f1 p1 a2 f2 p2".split(),
29-
self.phys))
27+
self.phys_named = dict(zip(self.i_names, self.phys))

‎artiq/test/gateware/test_sawg.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
from migen import *
44
from migen.fhdl.verilog import convert
55

6-
from artiq.gateware.dsp.sawg import DDSFast
6+
from artiq.gateware.dsp import sawg
77
from .tools import xfer
88

99

1010
def _test_gen_dds(dut, o):
1111
yield from xfer(dut,
12-
a=dict(a=10),
13-
p=dict(p=0),
14-
f=dict(f=1 << 8),
12+
a=dict(a0=10),
13+
p=dict(a0=0),
14+
f=dict(a0=1),
1515
)
1616
for i in range(256//dut.parallelism):
1717
yield
18-
o.append((yield from [(yield _) for _ in dut.o]))
18+
o.append((yield from [(yield _) for _ in dut.xo]))
1919

2020

2121
def _test_channel():
22-
dut = DDSFast(width=8, parallelism=2)
22+
widths = sawg._Widths(t=8, a=4*8, p=8, f=16)
23+
orders = sawg._Orders(a=4, p=1, f=2)
24+
dut = sawg.SplineParallelDDS(widths, orders, parallelism=2)
2325

2426
if False:
2527
print(convert(dut))

‎artiq/test/gateware/test_sawg_phy.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
import numpy as np
2+
from operator import or_
23

34
from migen import *
45
from migen.fhdl.verilog import convert
56

67
from artiq.gateware.rtio.phy.sawg import Channel
7-
from .tools import xfer, szip
8+
from .tools import rtio_xfer
89

910

10-
def rtio_xfer(dut, **kwargs):
11-
yield from szip(*(
12-
xfer(dut.phys_names[k].rtlink, o={"data": v})
13-
for k, v in kwargs.items()))
11+
def pack_tri(port, *v):
12+
r = 0
13+
w = 0
14+
for vi, p in zip(v, port.payload.flatten()):
15+
w += len(p)
16+
r |= int(vi*(1 << w))
17+
return r
1418

1519

1620
def gen_rtio(dut):
17-
width = dut.width
1821
yield
1922
yield from rtio_xfer(
20-
dut, a=int(.1 * (1 << width)),
21-
f=int(.01234567 * (1 << 2*width)),
22-
p=0)
23+
dut,
24+
a1=pack_tri(dut.a1.a, .1),
25+
f0=pack_tri(dut.b.f, .01234567),
26+
f1=pack_tri(dut.a1.f, .01234567),
27+
a2=pack_tri(dut.a1.a, .05),
28+
f2=pack_tri(dut.a1.f, .00534567),
29+
)
2330

2431

2532
def gen_log(dut, o, n):
@@ -28,10 +35,12 @@ def gen_log(dut, o, n):
2835
for i in range(n):
2936
yield
3037
o.append((yield from [(yield _) for _ in dut.o]))
38+
#o.append([(yield dut.a1.xo[0])])
3139

3240

3341
def _test_channel():
3442
width = 16
43+
3544
dut = ClockDomainsRenamer({"rio_phy": "sys"})(
3645
Channel(width=width, parallelism=4)
3746
)
@@ -43,8 +52,8 @@ def _test_channel():
4352
o = []
4453
run_simulation(
4554
dut,
46-
[gen_rtio(dut), gen_log(dut, o, 256 * 2)],
47-
) # vcd_name="dds.vcd")
55+
[gen_rtio(dut), gen_log(dut, o, 128)],
56+
vcd_name="dds.vcd")
4857
o = np.array(o)/(1 << (width - 1))
4958
o = o.ravel()
5059
np.savez_compressed("dds.npz", o=o)

‎artiq/test/gateware/tools.py

+6
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@ def szip(*iters):
4141
val = (yield None)
4242
for it in active:
4343
active[it] = val
44+
45+
46+
def rtio_xfer(dut, **kwargs):
47+
yield from szip(*(
48+
xfer(dut.phys_named[k].rtlink, o={"data": v})
49+
for k, v in kwargs.items()))

0 commit comments

Comments
 (0)
Please sign in to comment.