w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
serport_xontx.vhd
Go to the documentation of this file.
1-- $Id: serport_xontx.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 - syn
7-- Description: serial port: xon/xoff logic tx path
8--
9-- Dependencies: -
10-- Test bench: -
11-- Target Devices: generic
12-- Tool versions: ise 13.1-14.7; viv 2014.4; ghdl 0.29-0.31
13-- Revision History:
14-- Date Rev Version Comment
15-- 2011-11-13 425 1.0 Initial version
16-- 2011-10-22 417 0.5 First draft
17------------------------------------------------------------------------------
18-- Note: for test bench usage a copy of all serport_* entities, with _tb
19-- appended to the name, has been created in the /tb sub folder.
20-- Ensure to update the copy when this file is changed !!
21
22library ieee;
23use ieee.std_logic_1164.all;
24use ieee.numeric_std.all;
25
26use work.slvtypes.all;
27use work.serportlib.all;
28
29entity serport_xontx is -- serial port: xon/xoff logic tx path
30 port (
31 CLK : in slbit; -- clock
32 RESET : in slbit; -- reset
33 ENAXON : in slbit; -- enable xon/xoff handling
34 ENAESC : in slbit; -- enable xon/xoff escaping
35 UART_TXDATA : out slv8; -- uart data in
36 UART_TXENA : out slbit; -- uart data enable
37 UART_TXBUSY : in slbit; -- uart data busy
38 TXDATA : in slv8; -- user data in
39 TXENA : in slbit; -- user data enable
40 TXBUSY : out slbit; -- user data busy
41 RXOK : in slbit; -- rx channel ok
42 TXOK : in slbit -- tx channel ok
43 );
45
46
47architecture syn of serport_xontx is
48
49 type regs_type is record
50 ibuf : slv8; -- input buffer
51 ival : slbit; -- ibuf has valid data
52 obuf : slv8; -- output buffer
53 oval : slbit; -- obuf has valid data
54 rxok : slbit; -- rx channel ok state
55 enaxon_1 : slbit; -- last enaxon
56 escpend : slbit; -- escape pending
57 end record regs_type;
58
59 constant regs_init : regs_type := (
60 (others=>'0'),'0', -- ibuf,ival
61 (others=>'0'),'0', -- obuf,oval
62 '1', -- rxok (startup default is ok !!)
63 '0', -- enaxon_1
64 '0' -- escpend
65 );
66
67 signal R_REGS : regs_type := regs_init; -- state registers
68 signal N_REGS : regs_type := regs_init; -- next value state regs
69
70begin
71
72 proc_regs: process (CLK)
73 begin
74
75 if rising_edge(CLK) then
76 if RESET = '1' then
78 else
79 R_REGS <= N_REGS;
80 end if;
81 end if;
82
83 end process proc_regs;
84
85 proc_next: process (R_REGS, ENAXON, ENAESC, UART_TXBUSY,
87
88 variable r : regs_type := regs_init;
89 variable n : regs_type := regs_init;
90
91 begin
92
93 r := R_REGS;
94 n := R_REGS;
95
96 if TXENA='1' and r.ival='0' then
97 n.ibuf := TXDATA;
98 n.ival := '1';
99 end if;
100
101 if r.oval = '0' then
102 if ENAXON='1' and r.rxok/=RXOK then
103 n.rxok := RXOK;
104 n.oval := '1';
105 if r.rxok = '0' then
106 n.obuf := c_serport_xon;
107 else
108 n.obuf := c_serport_xoff;
109 end if;
110 elsif TXOK = '1' then
111 if r.escpend = '1' then
112 n.obuf := not r.ibuf;
113 n.oval := '1';
114 n.escpend := '0';
115 n.ival := '0';
116 elsif r.ival = '1' then
117 if ENAESC='1' and (r.ibuf=c_serport_xon or
118 r.ibuf=c_serport_xoff or
119 r.ibuf=c_serport_xesc)
120 then
121 n.obuf := c_serport_xesc;
122 n.oval := '1';
123 n.escpend := '1';
124 else
125 n.obuf := r.ibuf;
126 n.oval := '1';
127 n.ival := '0';
128 end if;
129 end if;
130 end if;
131 end if;
132
133 if r.oval='1' and UART_TXBUSY='0' then
134 n.oval := '0';
135 end if;
136
137 -- FIXME: document this hack
138 n.enaxon_1 := ENAXON;
139 if ENAXON='1' and r.enaxon_1='0' then
140 n.rxok := not RXOK;
141 end if;
142
143 N_REGS <= n;
144
145 TXBUSY <= r.ival;
146 UART_TXDATA <= r.obuf;
147 UART_TXENA <= r.oval;
148
149 end process proc_next;
150
151end syn;
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
in RESET slbit
in TXENA slbit
out UART_TXENA slbit
in TXOK slbit
in ENAESC slbit
in ENAXON slbit
in TXDATA slv8
in CLK slbit
out UART_TXDATA slv8
in RXOK slbit
out TXBUSY slbit
in UART_TXBUSY slbit
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40