From 587a5671882f303737ed50aca0d25dfaedac51b3 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 4 Mar 2023 14:29:31 -0500 Subject: [PATCH] tb: uart_rx: Export putchar This function is useful for other testbenches. Export it. Signed-off-by: Sean Anderson --- tb/uart_rx.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tb/uart_rx.py b/tb/uart_rx.py index f924251..3dd5473 100644 --- a/tb/uart_rx.py +++ b/tb/uart_rx.py @@ -17,6 +17,11 @@ def as_bits(c): yield c & 1 c >>= 1 +async def putchar(rx, c): + for bit in (0, *as_bits(c), 1): + rx.value = bit + await Timer(BIT_STEPS) + @cocotb.test(timeout_time=1, timeout_unit='ms') async def test_rx(uart): uart.clk.value = BinaryValue('Z') @@ -30,11 +35,6 @@ async def test_rx(uart): await cocotb.start(Clock(uart.clk, 8, units='ns').start()) await FallingEdge(uart.clk) - async def putchar(c): - for bit in (0, *as_bits(c), 1): - uart.rx.value = bit - await Timer(BIT_STEPS) - msg = b"Hell\0" signals = { 'clk': uart.clk, @@ -45,7 +45,7 @@ async def test_rx(uart): await cocotb.start(recv_packet(signals, msg)) for c in msg: - await putchar(c) + await putchar(uart.rx, c) overflows = 0 frame_errors = 0 @@ -69,8 +69,8 @@ async def test_rx(uart): assert frame_errors == 1 uart.ready.value = 0 - await putchar(0xFF) - await putchar(0) + await putchar(uart.rx, 0xFF) + await putchar(uart.rx, 0) assert overflows == 1