Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelburgos committed May 17, 2024
1 parent 90c5026 commit f94913c
Show file tree
Hide file tree
Showing 11 changed files with 984 additions and 231 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Gateware/open_beam_interface.bin
*.png
*.pyc
*.tif
*.kicad_prl
*.kicad_prl
*.pdm-python
595 changes: 595 additions & 0 deletions Gateware/pdm.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def append_command(run_length):
for _ in range(self._length):
pixel_count += 1
total_dwell += self._dwell
if total_dwell >= max_latency:
if total_dwell >= latency:
append_command(pixel_count)
print(f"{len(commands)=}, {pixel_count=}, {total_dwell=}")
yield (commands, pixel_count)
Expand Down Expand Up @@ -589,18 +589,20 @@ def test_response(self):


class CommandSequence(BaseCommand):
_message = bytearray()
_response = bytearray()
def __init__(self, cookie: int=123, output: OutputMode=OutputMode.SixteenBit, raster:bool=False):
def __init__(self, sync:bool=True, cookie: int=123, output: OutputMode=OutputMode.SixteenBit, raster:bool=False):
self._message = bytearray()
self._response = bytearray()
self._output = output
self._raster = raster
self.add(SynchronizeCommand(cookie=cookie, output=output, raster=raster))
def add(self, other: BaseCommand):
print(f"adding {other!r}")
if sync:
self.add(SynchronizeCommand(cookie=cookie, output=output, raster=raster))
def add(self, other: BaseCommand, verbose:bool=False):
if verbose:
print(f"adding {other!r}")
try:
self._message.extend(other.message)
except TypeError:
raise TypeError("Command syntax error. Did your use 'command' instead of 'command()'?")
raise TypeError("Command syntax error. Did you use 'command' instead of 'command()'?")
#self._response.extend(other.response)

@property
Expand Down
38 changes: 2 additions & 36 deletions obi_applet/glasgowcontrib/applet/open_beam_interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from glasgow.support.logging import dump_hex
from glasgow.support.endpoint import ServerEndpoint
from base_commands import Command, CmdType, BeamType, RasterRegion, OutputMode, Transforms, DwellTime
from ....base_commands import Command, CmdType, BeamType, RasterRegion, OutputMode, Transforms, DwellTime

# Overview of (linear) processing pipeline:
# 1. PC software (in: user input, out: bytes)
Expand Down Expand Up @@ -1330,41 +1330,7 @@ async def run(self, device, args):
iface = await device.demultiplexer.claim_interface(self, self.mux_interface, args,
# read_buffer_size=131072*16, write_buffer_size=131072*16)
read_buffer_size=16384*16384, write_buffer_size=16384*16384)

if args.benchmark:
output_mode = 2 #no output
raster_mode = 0 #no raster
mode = int(output_mode<<1 | raster_mode)
sync_cmd = struct.pack('>BHB', 0, 123, mode)
flush_cmd = struct.pack('>B', 2)
await iface.write(sync_cmd)
await iface.write(flush_cmd)
await iface.flush()
await iface.read(4)
print(f"got cookie!")
commands = bytearray()
print("generating block of commands...")
for _ in range(131072*16):
commands.extend(struct.pack(">BHHH", 0x14, 0, 16383, 1))
commands.extend(struct.pack(">BHHH", 0x14, 16383, 0, 1))
length = len(commands)
print("writing commands...")
while True:
await device.write_register(self.__addr_stall_count_reset, 1)
await device.write_register(self.__addr_stall_count_reset, 0)
begin = time.time()
await iface.write(commands)
await iface.flush()
end = time.time()
out_stall_events = await device.read_register(self.__addr_out_stall_events)
out_stall_cycles = await device.read_register(self.__addr_out_stall_cycles, width=2)
self.logger.info("benchmark: %.2f MiB/s (%.2f Mb/s)",
(length / (end - begin)) / (1 << 20),
(length / (end - begin)) / (1 << 17))
self.logger.info(f"out stalls: {out_stall_events}, stalled cycles: {out_stall_cycles}")

else:
return iface
return iface

@classmethod
def add_interact_arguments(cls, parser):
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import Supersampler, RasterScanner, RasterRegion
from . import CommandParser, CommandExecutor, Command, BeamType, OutputMode, CmdType
from . import BusController, Flippenator
from base_commands import *
from ....base_commands import *


def put_dict(stream, signal):
Expand Down
37 changes: 0 additions & 37 deletions obi_applet/pyproject.toml

This file was deleted.

25 changes: 15 additions & 10 deletions obi_applet/scripts/blank_test.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from glasgowcontrib.applet.open_beam_interface.base_commands import *
from obi_applet.base_commands import *

dwell = 1
loops = 100

seq = CommandSequence(output=OutputMode.NoOutput, raster=False)
seq.add(BlankCommand())
seq.add(EnableExtCtrlCommand())
seq.add(SelectIbeamCommand())
seq.add(ExternalCtrlCommand(enable=True))
seq.add(BeamSelectCommand(beam_type=BeamType.Ion))

def dash_line(y):
seq.add(UnblankInlineCommand())
seq.add(BlankCommand(enable=False, inline=True))
for x in range(4096):
seq.add(VectorPixelCommand(x_coord = x, y_coord=y, dwell=dwell))
seq.add(BlankCommand())
for x in range(4096, 12288):
seq.add(VectorPixelCommand(x_coord = x, y_coord=y, dwell=dwell))
seq.add(UnblankInlineCommand())
seq.add(BlankCommand(enable=False, inline=True))
for x in range(12288,16383):
seq.add(VectorPixelCommand(x_coord = x, y_coord=y, dwell=dwell))
seq.add(BlankCommand())
Expand All @@ -25,11 +25,16 @@ def dash_line(y):
dash_line(12288)


seq.add(DisableExtCtrlCommand())
seq.add(ExternalCtrlCommand(enable=False))

for _ in range(loops):
await iface.write(seq.message)
await iface.flush()
# for _ in range(loops):
# await iface.write(seq.message)
# await iface.flush()

response = await iface.read()
print("writing")
await iface.write(SynchronizeCommand(cookie=123, raster=False, output=OutputMode.NoOutput).message)
print("wrote")
await iface.flush()
print("done")
#response = await iface.read()

29 changes: 15 additions & 14 deletions obi_applet/scripts/box.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
from glasgowcontrib.applet.open_beam_interface.base_commands import *
import sys
print(sys.path)
from obi_applet.base_commands import *

seq = CommandSequence(output=OutputMode.NoOutput, raster=False)
## seq.add(Command())
## ...
seq.add(BlankCommand())
seq.add(EnableExtCtrlCommand())
seq.add(ExternalCtrlCommand(enable=True))
seq.add(DelayCommand(5760))
seq.add(SelectIbeamCommand())
seq.add(UnblankInlineCommand())
seq.add(BeamSelectCommand(beam_type=BeamType.Ion))
seq.add(BlankCommand(enable=False, inline=True))


dwell = 65536


print("generating commands")
def box(x_start, y_start, x_width, y_height):
## start ______ x = x_start + x_width, y = y_start
## | |
## ------ x = x_start + x_width, y = y_start + y_height
for x in range(x_start, x_start+x_width):
seq.add(VectorPixelCommand(x_coord=x, y_coord = y_start, dwell = dwell))
print(f"{x=}")
#print(f"{x=}")
for y in range(y_start, y_start+y_height):
seq.add(VectorPixelCommand(x_coord=x_start+x_width, y_coord = y, dwell = dwell))
print(f"{y=}")
#print(f"{y=}")
for x in range(x_start+x_width, x_start, -1):
seq.add(VectorPixelCommand(x_coord=x, y_coord = y_start+y_height, dwell = dwell))
print(f"{x=}")
#print(f"{x=}")
for y in range(y_start+y_height, y_start, -1):
seq.add(VectorPixelCommand(x_coord=x_start, y_coord = y, dwell = dwell))
print(f"{y=}")
#print(f"{y=}")


box(5000, 5000, 5000, 5000)

seq.add(DisableExtCtrlCommand())


seq.add(ExternalCtrlCommand(enable=False))
print("commands generated")
print("writing")
await iface.write(seq.message)
await iface.flush()
print("done writing")
Loading

0 comments on commit f94913c

Please sign in to comment.