Skip to content

Commit 3527704

Browse files
committed
hmm
1 parent da54bf9 commit 3527704

File tree

2 files changed

+44
-33
lines changed

2 files changed

+44
-33
lines changed

software/glasgow/applet/interface/gpib_controller/__init__.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def elaborate(self, platform):
183183
]
184184

185185
# settle_delay = math.ceil(platform.default_clk_frequency * 1e-6)
186-
settle_delay = 1000
186+
settle_delay = 5
187187
timer = Signal(range(1 + settle_delay))
188188

189189
m.d.comb += [
@@ -208,7 +208,11 @@ def elaborate(self, platform):
208208

209209
with m.FSM():
210210
with m.State("Control: Begin"):
211-
m.d.sync += self.status.eq(GPIBStatus.Idle)
211+
m.d.comb += Print("Control")
212+
m.d.sync += [
213+
self.status.eq(GPIBStatus.Idle),
214+
self.dav_o.eq(0),
215+
]
212216
m.d.comb += self.i_stream.ready.eq(1)
213217
with m.If(self.i_stream.valid):
214218
m.d.sync += l_control.eq(self.i_stream.payload)
@@ -254,10 +258,12 @@ def elaborate(self, platform):
254258
# resistor configuration from changing
255259
# mid-transaction.
256260
m.d.comb += [
257-
self.o_stream.valid.eq(1),
258261
self.o_stream.payload.eq(GPIBMessage._Acknowledge),
262+
self.o_stream.valid.eq(1),
263+
Print("awaiting acknowledge ready")
259264
]
260265
with m.If(self.o_stream.ready):
266+
m.d.comb += Print("acknowledge ready")
261267
m.next = "Control: Begin"
262268

263269
with m.State("Talk: Begin"):
@@ -316,11 +322,12 @@ def elaborate(self, platform):
316322
]
317323
with m.If(self.o_stream.ready):
318324
m.d.sync += self.nrfd_o.eq(0)
319-
m.next = "Listen: DAV unassert"
325+
m.next = "Listen: DAV assert"
320326

321-
with m.State("Listen: DAV unassert"):
327+
with m.State("Listen: DAV assert"):
322328
with m.If(self.dav_i):
323329
m.d.sync += self.ndac_o.eq(0)
330+
m.d.sync += self.nrfd_o.eq(0)
324331
m.next = "Control: Begin"
325332

326333
return m
@@ -361,10 +368,13 @@ async def write(self, message: GPIBMessage, data=bytes([0])):
361368

362369
for b in data:
363370
await self._pipe.send(bytes([message.value]))
371+
print("sent:", message)
364372
await self._pipe.send(bytes([b]))
365-
await self._pipe.flush()
366-
ack = (await self._pipe.recv(1))[0]
367-
assert GPIBMessage(ack) == GPIBMessage._Acknowledge
373+
print("sent:", b)
374+
375+
ack = await self._pipe.recv(1)
376+
print(ack)
377+
assert GPIBMessage(ack[0]) == GPIBMessage._Acknowledge
368378

369379
async def read(self, *, to_eoi=True):
370380
self.assembly.use_pulls({
@@ -380,14 +390,14 @@ async def read(self, *, to_eoi=True):
380390
eoi = False
381391
while not eoi:
382392
await self._pipe.send(bytes([GPIBMessage.Listen.value]))
383-
await self._pipe.flush()
384393

385394
eoi = bool((await self._pipe.recv(1))[0] & 2)
386395
if not to_eoi:
387396
eoi = True
388397

389398
yield (await self._pipe.recv(1))
390399

400+
391401
async def send_to(self, address, data):
392402
await self.cmd_talk(address)
393403
await self.write(GPIBMessage.Data, data)
Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import logging
22
import asyncio
3-
import time
43

54
from amaranth import *
65

76
from ... import *
87

98
from glasgow.simulation.assembly import SimulationAssembly
109
from glasgow.gateware.ports import PortGroup
11-
from . import GPIBControllerApplet, GPIBControllerInterface
10+
from . import GPIBControllerApplet, GPIBControllerInterface, GPIBStatus, GPIBMessage
11+
1212

1313
logger = logging.getLogger(__name__)
1414

@@ -17,39 +17,40 @@ class GPIBControllerAppletTestCase(GlasgowAppletV2TestCase, applet=GPIBControlle
1717
def test_build(self):
1818
self.assertBuilds()
1919

20-
21-
# def talk_and_listen(self, iface):
22-
# async def testbench(ctx):
23-
# print(ctx)
24-
# await iface.send_to(10, b'*IDN?')
25-
# await iface.read_from(10)
26-
# return testbench
27-
28-
def listen_and_reply(self, iface):
20+
def send_a_message(self, iface):
2921
async def testbench(ctx):
30-
time.sleep(0.5)
31-
print(await iface.read_from(10))
32-
await iface.send_to(10, b'GLASGOW DIGITAL INTERFACE EXPLORER')
22+
print("hello from testbench")
23+
# await iface.send_to(10, b'I')
24+
await iface.write(GPIBMessage.Data, b'I')
25+
# await iface.write(GPIBMessage.Data, b'O')
26+
print("message sent")
3327
return testbench
3428

35-
36-
3729
def test_two_can_talk(self):
3830
assembly = SimulationAssembly()
3931
iface0 = GPIBControllerInterface(logger, assembly,
40-
dio="A0:7", eoi="A8", dav="A9", nrfd="A10", ndac="A11", srq="A12", ifc="A13", atn="A14", ren="A15")
41-
32+
dio="A0:7", eoi="A8", dav="A9", nrfd="A10", ndac="A11", srq="A12", ifc="A13", atn="A14", ren="A15")
4233
iface1 = GPIBControllerInterface(logger, assembly,
43-
dio="B0:7", eoi="B8", dav="B9", nrfd="B10", ndac="B11", srq="B12", ifc="B13", atn="B14", ren="B15")
34+
dio="B0:7", eoi="B8", dav="B9", nrfd="B10", ndac="B11", srq="B12", ifc="B13", atn="B14", ren="B15")
4435

45-
for pin in range(0,16):
36+
# We skip IFC, ATN and REN, since they're always under the
37+
# control of the controller, and we're pretending one of the
38+
# controller isn't a controller....
39+
for pin in range(0,13):
4640
assembly.connect_pins("A%i" % pin, "B%i" % pin)
4741

48-
# assembly.add_testbench(self.talk_and_listen(iface0))
49-
assembly.add_testbench(self.listen_and_reply(iface1))
42+
assembly.add_testbench(self.send_a_message(iface0))
5043

5144
async def do_it(ctx):
52-
await iface0.send_to(10, b'*IDN?')
53-
await iface0.read_from(10)
45+
import time
46+
time.sleep(0.1)
47+
while True:
48+
response = b''
49+
async for data in iface1.read(to_eoi=True):
50+
response += data
51+
# print(data)
52+
# print("Talker:", GPIBStatus(await iface0._status.get()))
53+
# print("Listener:", GPIBStatus(await iface1._status.get()))
54+
5455

5556
assembly.run(do_it, vcd_file="test.vcd")

0 commit comments

Comments
 (0)