w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
serport_xontx_tb.vhd
Go to the documentation of this file.
1-- $Id: serport_xontx_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_xontx_tb - sim
7-- Description: serial port: xon/xoff logic tx 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_xontx)
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_xontx_tb is -- serial port: xon/xoff logic tx 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_TXDATA : out slv8; -- uart data in
32 UART_TXENA : out slbit; -- uart data enable
33 UART_TXBUSY : in slbit; -- uart data busy
34 TXDATA : in slv8; -- user data in
35 TXENA : in slbit; -- user data enable
36 TXBUSY : out slbit; -- user data busy
37 RXOK : in slbit; -- rx channel ok
38 TXOK : in slbit -- tx channel ok
39 );
41
42
43architecture sim of serport_xontx_tb is
44
45 type regs_type is record
46 ibuf : slv8; -- input buffer
47 ival : slbit; -- ibuf has valid data
48 obuf : slv8; -- output buffer
49 oval : slbit; -- obuf has valid data
50 rxok : slbit; -- rx channel ok state
51 enaxon_1 : slbit; -- last enaxon
52 escpend : slbit; -- escape pending
53 end record regs_type;
54
55 constant regs_init : regs_type := (
56 (others=>'0'),'0', -- ibuf,ival
57 (others=>'0'),'0', -- obuf,oval
58 '1', -- rxok (startup default is ok !!)
59 '0', -- enaxon_1
60 '0' -- escpend
61 );
62
63 signal R_REGS : regs_type := regs_init; -- state registers
64 signal N_REGS : regs_type := regs_init; -- next value state regs
65
66begin
67
68 proc_regs: process (CLK)
69 begin
70
71 if rising_edge(CLK) then
72 if RESET = '1' then
74 else
75 R_REGS <= N_REGS;
76 end if;
77 end if;
78
79 end process proc_regs;
80
81 proc_next: process (R_REGS, ENAXON, ENAESC, UART_TXBUSY,
83
84 variable r : regs_type := regs_init;
85 variable n : regs_type := regs_init;
86
87 begin
88
89 r := R_REGS;
90 n := R_REGS;
91
92 if TXENA='1' and r.ival='0' then
93 n.ibuf := TXDATA;
94 n.ival := '1';
95 end if;
96
97 if r.oval = '0' then
98 if ENAXON='1' and r.rxok/=RXOK then
99 n.rxok := RXOK;
100 n.oval := '1';
101 if r.rxok = '0' then
102 n.obuf := c_serport_xon;
103 else
104 n.obuf := c_serport_xoff;
105 end if;
106 elsif TXOK = '1' then
107 if r.escpend = '1' then
108 n.obuf := not r.ibuf;
109 n.oval := '1';
110 n.escpend := '0';
111 n.ival := '0';
112 elsif r.ival = '1' then
113 if ENAESC='1' and (r.ibuf=c_serport_xon or
114 r.ibuf=c_serport_xoff or
115 r.ibuf=c_serport_xesc)
116 then
117 n.obuf := c_serport_xesc;
118 n.oval := '1';
119 n.escpend := '1';
120 else
121 n.obuf := r.ibuf;
122 n.oval := '1';
123 n.ival := '0';
124 end if;
125 end if;
126 end if;
127 end if;
128
129 if r.oval='1' and UART_TXBUSY='0' then
130 n.oval := '0';
131 end if;
132
133 -- FIXME: document this hack
134 n.enaxon_1 := ENAXON;
135 if ENAXON='1' and r.enaxon_1='0' then
136 n.rxok := not RXOK;
137 end if;
138
139 N_REGS <= n;
140
141 TXBUSY <= r.ival;
142 UART_TXDATA <= r.obuf;
143 UART_TXENA <= r.oval;
144
145 end process proc_next;
146
147end sim;
regs_type := regs_init N_REGS
regs_type := regs_init R_REGS
regs_type :=(( others => '0'), '0',( others => '0'), '0', '1', '0', '0') regs_init
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40