Skip to content

Commit

Permalink
wip: define transfer() method for local OBIInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelburgos committed May 4, 2024
1 parent 3c08d30 commit b780a45
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
25 changes: 16 additions & 9 deletions Gateware/glasgowcontrib/applet/open_beam_interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,15 @@ async def _synchronize(self):
print(str(list(data)))

async def readuntil(self, separator=b'\n', *, flush=True):
if flush and len(self._out_buffer) > 0:
def find_sep(buffer, separator=b'\n', offset=0):
if buffer._chunk is None:
if not buffer._queue:
raise IncompleteReadError
buffer._chunk = buffer._queue.popleft()
buffer._offset = 0
return buffer._chunk.obj.find(separator)

if flush and len(self.lower._out_buffer) > 0:
# Flush the buffer, so that everything written before the read reaches the device.
await self.lower.flush(wait=False)

Expand All @@ -1133,7 +1141,7 @@ async def readuntil(self, separator=b'\n', *, flush=True):

# Check if we now have enough data in the buffer for `separator` to fit.
if buflen >= seplen:
isep = self.find(self.lower._in_buffer, separator)
isep = find_sep(self.lower._in_buffer, separator)
if isep != -1:
print(f"found {isep=}")
# `separator` is in the buffer. `isep` will be used later
Expand All @@ -1156,13 +1164,12 @@ async def readuntil(self, separator=b'\n', *, flush=True):
result = memoryview(b"".join(chunks))
return result

def find(self, buffer, separator=b'\n', offset=0):
if buffer._chunk is None:
if not buffer._queue:
raise IncompleteReadError
buffer._chunk = buffer._queue.popleft()
buffer._offset = 0
return buffer._chunk.obj.find(separator)
async def transfer(self, seq): #CommandSequence
await self.lower.write(seq.message)
await self.lower.flush()
data = await self.lower.read(seq._response_length)
return seq.unpack(data)


class OBIApplet(GlasgowApplet):
required_revision = "C3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class DwellTime(int):
One DwellTime = 125 ns'''
pass

class DelayTime(int):
'''Delay time is measured in units of 48 MHz clock cycles.
One DelayTime = 20.833 ns'''
pass


class BaseCommand(metaclass=ABCMeta):
# def __init_subclass__(cls):
Expand Down Expand Up @@ -111,7 +116,7 @@ def message(self):


class DelayCommand(BaseCommand):
def __init__(self, delay):
def __init__(self, delay:DelayTime):
assert delay <= 65535
self._delay = delay

Expand Down
5 changes: 1 addition & 4 deletions Gateware/scripts/test.py → Gateware/scripts/raster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@
seq.add(RasterPixelsCommand(dwells = pixels))
seq.add(FlushCommand())

await iface.write(seq.message)
await iface.flush()
data = await iface.read(seq._response_length)
seq.unpack(data)
await conn.transfer(seq)

0 comments on commit b780a45

Please sign in to comment.