Created
November 30, 2019 08:32
-
-
Save Vbitz/22a8e30951190e051e180e38beb5e004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from glasgow.applet import * | |
from nmigen.compat import * | |
from nmigen.build.plat import ResourceError | |
import logging | |
import asyncio | |
""" | |
Based on: https://github.com/GlasgowEmbedded/glasgow/blob/b28a6d7d918091e7425cd3e26d0f346d30966195/software/glasgow/applet/internal/selftest/__init__.py | |
""" | |
class BlinkSubtarget(Module): | |
def __init__(self, applet, target): | |
try: | |
leds = [target.platform.request("led", n) for n in range(5)] | |
except ResourceError: | |
leds = [] | |
reg_led, applet.addr_led = target.registers.add_rw(5) | |
target.comb += [Cat(leds).eq(reg_led)] | |
class BlinkApplet(GlasgowApplet, name="blink"): | |
logger = logging.getLogger(__name__) | |
help = "Just a blinky. Also a test of out-of-tree applets" | |
@classmethod | |
def add_build_arguments(cls, parser, access): | |
return super().add_build_arguments(parser, access) | |
def build(self, target, args): | |
target.submodules += BlinkSubtarget(applet=self, target=target) | |
@classmethod | |
def add_run_arguments(cls, parser, access): | |
return super().add_run_arguments(parser, access) | |
async def run(self, device, args): | |
while (True): | |
await asyncio.sleep(1) | |
device.write_register(self.addr_led, 0b10101) | |
await asyncio.sleep(0.5) | |
device.write_register(self.addr_led, 0b01010) | |
# ------------------------------------------------------------------------------------------------- | |
class BlinkAppletTestCase(GlasgowAppletTestCase, applet=BlinkApplet): | |
@synthesis_test | |
def test_build(self): | |
self.assertBuilds() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment