Livt packages

Livt.IO

Version 1.8.1

Memory, UART, I2C, SPI, and Ethernet input/output components for Livt hardware designs.

Published files (126)

tests/uart/RtsCtsBufferedUartSmokeTest.lvt

namespace Livt.IO.Tests

using Livt.IO

/**
 * Exercises RtsCtsBufferedUartSmoke with a shared fixture instance. Each scenario
 * establishes the inputs and state it needs.
 */
@Test
@Context(ClockFrequency = 100MHz)
component RtsCtsBufferedUartSmokeTest
{
	// Independent 100 MHz/1 Mbaud timing keeps behavioral regressions short.
	const TICKS_PER_BIT: int = 100

	// Shared fixture instances, signals, and observation state.
	uart: RtsCtsBufferedUart<64, 64, UartDataBits.Eight, UartParity.None, UartStopBits.One, 1MHz>

	// Shared fixture instances, signals, and observation state.
	loopback_line: logic = 0b1
	cts_n: logic = 0b1
	rts_n: logic

	/**
	 * Creates the shared fixture instances (RtsCtsBufferedUart). Tests initialize the state
	 * required by their scenario.
	 */
	new()
	{
		this.uart = new RtsCtsBufferedUart<64, 64, UartDataBits.Eight, UartParity.None, UartStopBits.One, 1MHz>(
			this.loopback_line,
			this.loopback_line,
			this.cts_n,
			this.rts_n)
	}

	/**
	 * Checks that Send waits for cts.
	 */
	@Test
	fn TestSendWaitsForCts()
	{
		var message = "Hi".Encode()
		assert this.uart.Send(message) == 2

		Simulation.Wait(100)
		assert this.uart.IsTransmitting() == false
		assert this.uart.GetReceiveCount() == 0

		this.cts_n = 0b0
		Simulation.Wait(TICKS_PER_BIT * 25)

		assert this.uart.GetReceiveCount() == 2
		var receivedByte1: byte
		assert this.uart.TryReceive(receivedByte1) == true
		assert receivedByte1 == 0x48
		var receivedByte2: byte
		assert this.uart.TryReceive(receivedByte2) == true
		assert receivedByte2 == 0x69
	}
}