1+ import logging
2+
13from 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
711class 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