Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 431f985c71e4
Choose a base ref
...
head repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c47a734e10e7
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 28, 2019

  1. Copy the full SHA
    1979b66 View commit details
  2. Copy the full SHA
    76e7e29 View commit details
  3. cli: await all tasks, not just the ones that are done.

    When we cancel run_applet(), it continues to run, because it needs
    to wait for the USB transfers to get (asynchronously) cancelled.
    Restructure the logic so that, when any of the main tasks quits,
    they all get cancelled, and then awaited, ignoring the (expected)
    cancellation error.
    whitequark committed Aug 28, 2019
    Copy the full SHA
    c47a734 View commit details
Showing with 21 additions and 5 deletions.
  1. +7 −5 software/glasgow/cli.py
  2. +14 −0 software/glasgow/device/hardware.py
12 changes: 7 additions & 5 deletions software/glasgow/cli.py
Original file line number Diff line number Diff line change
@@ -574,15 +574,14 @@ async def run_applet():
if do_trace:
await device.write_register(target.analyzer.addr_done, 1)

async def wait_for_sigint(task):
async def wait_for_sigint():
await wait_for_signal(signal.SIGINT)
logger.debug("Ctrl+C pressed, terminating")
task.cancel()

if do_trace:
analyzer_task = asyncio.ensure_future(run_analyzer())
applet_task = asyncio.ensure_future(run_applet())
sigint_task = asyncio.ensure_future(wait_for_sigint(applet_task))
sigint_task = asyncio.ensure_future(wait_for_sigint())

if do_trace:
tasks = [analyzer_task, applet_task, sigint_task]
@@ -591,8 +590,11 @@ async def wait_for_sigint(task):
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
for task in pending:
task.cancel()
for task in done:
await task
for task in tasks:
try:
await task
except asyncio.CancelledError:
pass

if args.action == "tool":
tool = GlasgowApplet.all_applets[args.applet].tool_cls()
14 changes: 14 additions & 0 deletions software/glasgow/device/hardware.py
Original file line number Diff line number Diff line change
@@ -152,11 +152,25 @@ async def _do_transfer(self, is_read, setup):
setup(transfer)

def usb_callback(transfer):
if self.usb_poller.done:
return # shutting down
if transfer.isSubmitted():
return # transfer not completed

status = transfer.getStatus()
if status == usb1.TRANSFER_CANCELLED:
usb_transfer_type = transfer.getType()
if usb_transfer_type == usb1.TRANSFER_TYPE_CONTROL:
transfer_type = "CONTROL"
if usb_transfer_type == usb1.TRANSFER_TYPE_BULK:
transfer_type = "BULK"
endpoint = transfer.getEndpoint()
if endpoint & usb1.ENDPOINT_DIR_MASK == usb1.ENDPOINT_IN:
endpoint_dir = "IN"
if endpoint & usb1.ENDPOINT_DIR_MASK == usb1.ENDPOINT_OUT:
endpoint_dir = "OUT"
logger.trace("USB: %s EP%d %s (cancelled)",
transfer_type, endpoint & 0x7f, endpoint_dir)
cancel_future.set_result(None)
elif result_future.cancelled():
pass