Created
December 7, 2018 14:05
-
-
Save ryos36/96f1f250a5f3d880faeeaa94969bd1bf to your computer and use it in GitHub Desktop.
This file contains 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
from polyphony import testbench, module, is_worker_running | |
from polyphony.io import Port | |
from polyphony.timing import wait_value | |
from polyphony.typing import bit | |
@module | |
class Blink: | |
def __init__(self, interval): | |
self.led = Port(bit, 'out') | |
self.interval = interval | |
self.append_worker(self.main) | |
def main(self): | |
led_bit:bit = 1 | |
while is_worker_running(): | |
self.led(led_bit) | |
led_bit = 1 - led_bit | |
self._wait() | |
def _wait(self): | |
for i in range(self.interval // 2): | |
pass | |
@testbench | |
def test(dut): | |
v = 0 | |
for i in range(4): | |
print("loop:", i) | |
wait_value(1, dut.led) | |
wait_value(0, dut.led) | |
print("finished") | |
blink = Blink(125 * 1000 * 1000) | |
test(blink) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment