Skip to content

Commit a34345e

Browse files
committed
applet.interface.uart: add multiple interfaces test
1 parent 4b2eafa commit a34345e

File tree

1 file changed

+25
-2
lines changed
  • software/glasgow/applet/interface/uart

1 file changed

+25
-2
lines changed

software/glasgow/applet/interface/uart/test.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import logging
2+
13
from amaranth import *
24

3-
from ... import *
4-
from . import UARTApplet
5+
from glasgow.applet import GlasgowAppletV2TestCase, synthesis_test, applet_v2_simulation_test
6+
from glasgow.simulation.assembly import SimulationAssembly
7+
from . import UARTApplet, UARTInterface
58

9+
logger = logging.getLogger(__name__)
610

711
class UARTAppletTestCase(GlasgowAppletV2TestCase, applet=UARTApplet):
812
@synthesis_test
@@ -16,3 +20,22 @@ def prepare_loopback(self, assembly):
1620
async def test_loopback(self, applet, ctx):
1721
await applet.uart_iface.write(bytes([0xAA, 0x55]))
1822
self.assertEqual(await applet.uart_iface.read(2), bytes([0xAA, 0x55]))
23+
24+
def test_multiple_interfaces(self):
25+
assembly = SimulationAssembly()
26+
iface0 = UARTInterface(logger, assembly, rx="A0", tx="A1", parity="none")
27+
iface1 = UARTInterface(logger, assembly, rx="B0", tx="B1", parity="none")
28+
29+
assembly.connect_pins("A0", "B1")
30+
assembly.connect_pins("B0", "A1")
31+
32+
async def write_testbench(ctx):
33+
await iface0.set_baud(9600)
34+
await iface1.set_baud(9600)
35+
await iface0.write(b'Hello')
36+
37+
async def read_testbench(ctx):
38+
self.assertEqual(await iface1.read(5), b'Hello')
39+
40+
assembly.add_testbench(write_testbench)
41+
assembly.run(read_testbench, vcd_file="uart_multi.vcd")

0 commit comments

Comments
 (0)