Architecture is based on just a single process.
An assertion has also been added to check that generics are assigned supported values.
Definition at line 49 of file uart_emu.vhd.
Decode uart_input
signal and write it to OUTPUT_FILE
.
Assuming the line is in the rest value ('1') when we are outside of the process, when we enter the process it should be because the line changed to the start bit ('0'). From that point, get all the data values and the parity, performing some sanity checks. Please note that this process does not check for signal stability (we will not raise any errors if the signals change a bit sooner or later than BIT_DURATION
), we just measure the signal at half the bit time, as a real UART receiver would do.
Definition at line 79 of file uart_emu.vhd.
get_values:
process 86 -- A transaction start when the line goes to a strong low level 89 report "uart_emu: uart transaction begin";
92 -- Offset half a bit so we measure at the center of each bit 95 -- Raise an error if we are not in the start bit 97 report "uart_emu: wrong value for start bit: expected: '0', actual: " & 'image(uart_input) severity failure;
105 report "uart_emu: sampled bit " & 'image(i) & ", got value: " & 'image(uart_input);
109 -- Print received data. If DATA_BITS = 8, print it also in ASCII 111 report "uart_emu: received data: " & slv2string(rxdata) & " (bin), " & slv2hexstring(rxdata) & " (hex), " & ascii(to_integer((rxdata))) & " (ASCII)";
113 report "uart_emu: received data: " & slv2string(rxdata) & " (bin), " & slv2hexstring(rxdata) & " (hex)";
116 -- If DATA_BITS = 8, write received data to output file. Data is always 117 -- prepared to be written to the output file, no matter if we have parity 120 -- We write the received char into the line variable, and not directly 121 -- into the file, unless we got a newline char (line feed, \n). Only when 122 -- we receive a newline char, we commit the line to the file. 124 -- This would probably be more convenient if we wrote to a pipe instead 125 -- of writing to a file, but I am not sure if that would work on Windows. 127 -- Since the file output seems to be buffered, normally it would not be 128 -- actually written to the log until we close the file, which should 129 -- happen automatically at the end of the simulation. But in that case 130 -- we would get all the text at the same time, instead of line by line as 131 -- the simulation progresses. So we will open and close the file each 132 -- time we have a complete line. 134 if rxdata /= LINE_FEED then 135 write (l, ascii(to_integer((rxdata))));
137 file_open(f, OUTPUT_FILE, append_mode);
143 -- If parity is even or odd, get parity bit 149 -- Calculate expected parity 151 expectedparity <= xor_reduce(rxdata);
153 expectedparity <= xnor_reduce(rxdata);
155 expectedparity <= '-';
158 -- Check if received parity matches expected, report an error if not 160 if rxparity /= expectedparity then 161 report "uart_emu: parity error! received parity bit: " & 'image(rxparity) & " expected: " & 'image(expectedparity) 166 -- Wait for stop bits, and raise errors if the value is incorrect. 167 -- We always will have at least one stop bit 170 report "uart_emu: wrong value for stop bit: expected: '1', actual: " & 'image(uart_input) severity failure;
173 -- But sometimes we will have a second stop bit 177 report "uart_emu: wrong value for second stop bit: expected: '1', actual: " & 'image(uart_input) severity failure;
181 -- We could do a last half-bit shift before we exit the process, but since 182 -- we will wait for an event on uart_input when we enter the process again, 183 -- that half-bit wait will be performed nevertheless. 184 -- Also, by not manualy waiting for a half-bit, we avoid missing the start 185 -- bit event on uart_input in the case of receiving a new transaction just 186 -- after the last stop bit. 189 report "uart_emu: uart transaction end";
193 in uart_inputstd_logic
Connect here the TX signal from your design.
PARITYstring := "none"
Can be either "even", "odd", or "none".
STOP_BITSinteger := 1
Can be either 1 or 2.
DATA_BITSinteger := 8
Number of data bits in the UART word.
VERBOSEboolean := false
Log beginning and end of transactions, as well as individual bit values.
BIT_DURATIONtime := 104 us
Duration of each bit, depends on baudrate (it is actually 1 second / baudrate)
The documentation for this class was generated from the following file: