w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
serport_xonrx_tb.vhd
Go to the documentation of this file.
1-- $Id: serport_xonrx_tb.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2011-2016 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: serport_xonrx_tb - sim
7-- Description: serial port: xon/xoff logic rx path (SIM only!)
8--
9-- Dependencies: -
10-- Test bench: -
11-- Target Devices: generic
12-- Tool versions: ghdl 0.29-0.31
13-- Revision History:
14-- Date Rev Version Comment
15-- 2016-01-03 724 1.0 Initial version (copied from serport_xonrx)
16------------------------------------------------------------------------------
17
18library ieee;
19use ieee.std_logic_1164.all;
20use ieee.numeric_std.all;
21
22use work.slvtypes.all;
23use work.serportlib_tb.all;
24
25entity serport_xonrx_tb is -- serial port: xon/xoff logic rx path
26 port (
27 CLK : in slbit; -- clock
28 RESET : in slbit; -- reset
29 ENAXON : in slbit; -- enable xon/xoff handling
30 ENAESC : in slbit; -- enable xon/xoff escaping
31 UART_RXDATA : in slv8; -- uart data out
32 UART_RXVAL : in slbit; -- uart data valid
33 RXDATA : out slv8; -- user data out
34 RXVAL : out slbit; -- user data valid
35 RXHOLD : in slbit; -- user data hold
36 RXOVR : out slbit; -- user data overrun
37 TXOK : out slbit -- tx channel ok
38 );
40
41
42architecture sim of serport_xonrx_tb is
43
44 type regs_type is record
45 txok : slbit; -- tx channel ok state
46 escseen : slbit; -- escape seen
47 rxdata : slv8; -- user rxdata
48 rxval : slbit; -- user rxval
49 rxovr : slbit; -- user rxovr
50 end record regs_type;
51
52 constant regs_init : regs_type := (
53 '1', -- txok (startup default is ok !!)
54 '0', -- escseen
55 (others=>'0'), -- rxdata
56 '0','0' -- rxval,rxovr
57 );
58
59 signal R_REGS : regs_type := regs_init; -- state registers
60 signal N_REGS : regs_type := regs_init; -- next value state regs
61
62begin
63
64 proc_regs: process (CLK)
65 begin
66
67 if rising_edge(CLK) then
68 if RESET = '1' then
70 else
71 R_REGS <= N_REGS;
72 end if;
73 end if;
74
75 end process proc_regs;
76
77 proc_next: process (R_REGS, ENAXON, ENAESC, UART_RXDATA, UART_RXVAL, RXHOLD)
78
79 variable r : regs_type := regs_init;
80 variable n : regs_type := regs_init;
81
82 begin
83
84 r := R_REGS;
85 n := R_REGS;
86
87 if ENAXON = '0' then
88 n.txok := '1';
89 end if;
90 if ENAESC = '0' then
91 n.escseen := '0';
92 end if;
93
94 n.rxovr := '0'; -- ensure single clock pulse
95
96 if UART_RXVAL = '1' then
97 if ENAXON='1' and UART_RXDATA=c_serport_xon then
98 n.txok := '1';
99 elsif ENAXON='1' and UART_RXDATA=c_serport_xoff then
100 n.txok := '0';
101 elsif ENAESC='1' and UART_RXDATA=c_serport_xesc then
102 n.escseen := '1';
103
104 else
105 if r.escseen = '1' then
106 n.escseen := '0';
107 end if;
108
109 if r.rxval = '0' then
110 n.rxval := '1';
111 if r.escseen = '1' then
112 n.rxdata := not UART_RXDATA;
113 else
114 n.rxdata := UART_RXDATA;
115 end if;
116 else
117 n.rxovr := '1';
118 end if;
119 end if;
120 end if;
121
122 if r.rxval='1' and RXHOLD='0' then
123 n.rxval := '0';
124 end if;
125
126 N_REGS <= n;
127
128 RXDATA <= r.rxdata;
129 RXVAL <= r.rxval;
130 RXOVR <= r.rxovr;
131 TXOK <= r.txok;
132
133 end process proc_next;
134
135end sim;
regs_type := regs_init N_REGS
regs_type := regs_init R_REGS
regs_type :=( '1', '0',( others => '0'), '0', '0') regs_init
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40