1 |
2 |
jclaytons |
--------------------------------------------------------------------------
|
2 |
|
|
-- Package
|
3 |
|
|
--
|
4 |
|
|
|
5 |
|
|
library IEEE;
|
6 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
7 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
8 |
|
|
use IEEE.MATH_REAL.ALL;
|
9 |
|
|
|
10 |
|
|
package ascii_pack is
|
11 |
|
|
|
12 |
|
|
-- Component declarations not provided any more.
|
13 |
|
|
-- With VHDL '93 and newer, component declarations are allowed,
|
14 |
|
|
-- but not required.
|
15 |
|
|
--
|
16 |
|
|
-- Please to try direct instantiation instead, for example:
|
17 |
|
|
--
|
18 |
|
|
-- instance_name : entity work.entity_name(beh)
|
19 |
|
|
--
|
20 |
|
|
|
21 |
|
|
end ascii_pack;
|
22 |
|
|
|
23 |
|
|
-------------------------------------------------------------------------------
|
24 |
|
|
-- Parallel ASCII CRLF resolver
|
25 |
|
|
-------------------------------------------------------------------------------
|
26 |
|
|
--
|
27 |
|
|
-- Author: John Clayton
|
28 |
|
|
-- Date : Feb. 12, 2014 Conceived of this module, and began coding it.
|
29 |
|
|
-- Wrote description.
|
30 |
|
|
-- Feb. 13, 2014 Added synchronous reset input.
|
31 |
|
|
--
|
32 |
|
|
--
|
33 |
|
|
-- Description
|
34 |
|
|
-------------------------------------------------------------------------------
|
35 |
|
|
-- This module addresses the question of which character is to be expected at
|
36 |
|
|
-- the end of an ascii character command line. Is it to be '\n' or '\r'?
|
37 |
|
|
-- Perhaps both? A quick survey will reveal that the answer varies depending
|
38 |
|
|
-- on the details and importunate vagaries of the situation, including the
|
39 |
|
|
-- operating system at hand, program used &c. For instance, telnet uses
|
40 |
|
|
-- '\n' only by default, while a terminal emulator may use '\r'. In fact,
|
41 |
|
|
-- these programs can probably be configured to send both ('\r\n', or is it
|
42 |
|
|
-- '\n\r'?) So, when hardware is processing a stream of characters which
|
43 |
|
|
-- originate from a command line, it is unclear which character or set of
|
44 |
|
|
-- characters to expect at the end of the line. Moreover, sending both
|
45 |
|
|
-- characters is not a "clean" solution either, since the occurrence of the
|
46 |
|
|
-- second character can cause difficulties as, for example, the second
|
47 |
|
|
-- character may needlessly request access to a bus through a bus arbiter,
|
48 |
|
|
-- while the command is being executed due to the arrival of the first
|
49 |
|
|
-- character. It's just not "atomic," you understand?
|
50 |
|
|
--
|
51 |
|
|
-- So, in summary, it would be most agreeable if one could know for certain
|
52 |
|
|
-- which character to expect to use for initiating execution of an ASCII
|
53 |
|
|
-- command line, and also to know for certain that the expected character
|
54 |
|
|
-- will not be followed by any other "dangling" command line termination type
|
55 |
|
|
-- characters.
|
56 |
|
|
--
|
57 |
|
|
-- This module was conceived in order to address these challenges. But how,
|
58 |
|
|
-- you may ask? Gentle friend, read on, I pray, as an attempt will be made
|
59 |
|
|
-- at providing the answer to just such a question!
|
60 |
|
|
--
|
61 |
|
|
-- Quite simply, the module does a "consumptive substition with
|
62 |
|
|
-- acknowledgement."
|
63 |
|
|
--
|
64 |
|
|
-- In other words, it looks for any of the characters in the following
|
65 |
|
|
-- "substitution list":
|
66 |
|
|
--
|
67 |
|
|
-- <CR> (Carriage Return, which is 0x0D, sometimes written '\r')
|
68 |
|
|
-- <LF> (Line Feed, which is 0x0A, sometimes written '\n')
|
69 |
|
|
-- SUB_CHAR (generic, e.g. Null, which is 0x00, sometimes written '\0')
|
70 |
|
|
--
|
71 |
|
|
-- The generic setting "SUB_CRLF" controls whether or not <CR> and <LF>
|
72 |
|
|
-- are included in the substitution list.
|
73 |
|
|
--
|
74 |
|
|
-- When it finds one of these characters, it substitutes the chosen EMIT_CHAR
|
75 |
|
|
-- at char_o, in place of the one given at char_i, and then it enters its
|
76 |
|
|
-- "consumptive mode," wherein any and all immediately subsequent characters
|
77 |
|
|
-- which are also in the substitution list are "eaten up" without being
|
78 |
|
|
-- passed on. Consumptive mode is exited whenever a character is presented
|
79 |
|
|
-- for writing that is not in the substitution list.
|
80 |
|
|
--
|
81 |
|
|
-- The user is thus permitted to choose which character to expect at the end
|
82 |
|
|
-- of a command line, simply by setting EMIT_CHAR according to his (or her)
|
83 |
|
|
-- whims. Isn't that marvelous?!
|
84 |
|
|
--
|
85 |
|
|
-- Hopefully this descriptive explication makes sense. I've used what I at
|
86 |
|
|
-- the time considered to be fairly clear English, and my apologies are given
|
87 |
|
|
-- for those for whom this arrangement is in some way inconvenient or
|
88 |
|
|
-- incomprehensible.
|
89 |
|
|
--
|
90 |
|
|
-- The sys_rst_n input is an asynchronous reset.
|
91 |
|
|
|
92 |
|
|
library IEEE;
|
93 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
94 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
95 |
|
|
use IEEE.MATH_REAL.ALL;
|
96 |
|
|
|
97 |
|
|
entity parallel_ascii_crlf_resolver is
|
98 |
|
|
generic(
|
99 |
|
|
SUB_CRLF : integer := 1; -- Set nonzero to substitute for CR and LF.
|
100 |
|
|
SUB_CHAR : unsigned(7 downto 0) := "00000000"; -- character to be substituted
|
101 |
|
|
EMIT_CHAR : unsigned(7 downto 0) := "00001101" -- character which is emitted
|
102 |
|
|
);
|
103 |
|
|
port (
|
104 |
|
|
-- System Clock and Clock Enable
|
105 |
|
|
sys_rst_n : in std_logic;
|
106 |
|
|
sys_clk : in std_logic;
|
107 |
|
|
sys_clk_en : in std_logic;
|
108 |
|
|
|
109 |
|
|
-- Synchronous reset
|
110 |
|
|
clear_i : in std_logic;
|
111 |
|
|
|
112 |
|
|
-- Input Port
|
113 |
|
|
char_i : in unsigned(7 downto 0);
|
114 |
|
|
we_i : in std_logic;
|
115 |
|
|
ack_o : out std_logic;
|
116 |
|
|
|
117 |
|
|
-- Output Port
|
118 |
|
|
char_o : out unsigned(7 downto 0);
|
119 |
|
|
we_o : out std_logic;
|
120 |
|
|
ack_i : in std_logic
|
121 |
|
|
);
|
122 |
|
|
end parallel_ascii_crlf_resolver;
|
123 |
|
|
|
124 |
|
|
architecture beh of parallel_ascii_crlf_resolver is
|
125 |
|
|
|
126 |
|
|
-- Constants
|
127 |
|
|
constant VAL_CR : integer := 13; -- 0x0D
|
128 |
|
|
constant VAL_LF : integer := 10; -- 0x0A
|
129 |
|
|
|
130 |
|
|
-- Functions & associated types
|
131 |
|
|
|
132 |
|
|
-- Signal Declarations
|
133 |
|
|
signal hit_list : std_logic;
|
134 |
|
|
signal consumptive_mode : std_logic;
|
135 |
|
|
|
136 |
|
|
begin
|
137 |
|
|
|
138 |
|
|
hit_list <= '1' when (char_i=SUB_CHAR or (char_i=VAL_CR and SUB_CRLF/=0) or (char_i=VAL_LF and SUB_CRLF/=0)) else '0';
|
139 |
|
|
|
140 |
|
|
process (sys_clk, sys_clk_en, sys_rst_n)
|
141 |
|
|
begin
|
142 |
|
|
if (sys_rst_n='0') then
|
143 |
|
|
consumptive_mode <= '0';
|
144 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
145 |
|
|
if (sys_clk_en='1') then
|
146 |
|
|
-- Handle entering consumptive mode
|
147 |
|
|
if (consumptive_mode='0' and hit_list='1' and we_i='1' and ack_i='1') then
|
148 |
|
|
consumptive_mode <= '1';
|
149 |
|
|
end if;
|
150 |
|
|
-- Handle exiting consumptive mode
|
151 |
|
|
if (consumptive_mode='1' and hit_list='0' and we_i='1') or clear_i='1' then
|
152 |
|
|
consumptive_mode <= '0';
|
153 |
|
|
end if;
|
154 |
|
|
end if; -- sys_clk_en
|
155 |
|
|
end if; -- sys_clk
|
156 |
|
|
end process;
|
157 |
|
|
|
158 |
|
|
-- Reflect acknowledge at the input port.
|
159 |
|
|
ack_o <= ack_i when consumptive_mode='0' and hit_list='1' and we_i='1' else -- First character is emitted.
|
160 |
|
|
ack_i when consumptive_mode='1' and hit_list='0' and we_i='1' else
|
161 |
|
|
we_i when consumptive_mode='1' else
|
162 |
|
|
ack_i;
|
163 |
|
|
|
164 |
|
|
-- Provide output
|
165 |
|
|
char_o <= EMIT_CHAR when (hit_list='1' and we_i='1') else char_i;
|
166 |
|
|
we_o <= we_i when consumptive_mode='0' and hit_list='1' and we_i='1' else -- First character is emitted.
|
167 |
|
|
we_i when consumptive_mode='1' and hit_list='0' and we_i='1' else
|
168 |
|
|
'0' when consumptive_mode='1' else
|
169 |
|
|
we_i;
|
170 |
|
|
|
171 |
|
|
end beh;
|
172 |
|
|
|