1 |
8 |
bjoerno |
---====================== Start Software License ========================---
|
2 |
|
|
--== ==--
|
3 |
|
|
--== This license governs the use of this software, and your use of ==--
|
4 |
|
|
--== this software constitutes acceptance of this license. Agreement ==--
|
5 |
|
|
--== with all points is required to use this software. ==--
|
6 |
|
|
--== ==--
|
7 |
|
|
--== 1. This source file may be used and distributed without ==--
|
8 |
|
|
--== restriction provided that this software license statement is not ==--
|
9 |
|
|
--== removed from the file and that any derivative work contains the ==--
|
10 |
|
|
--== original software license notice and the associated disclaimer. ==--
|
11 |
|
|
--== ==--
|
12 |
|
|
--== 2. This source file is free software; you can redistribute it ==--
|
13 |
|
|
--== and/or modify it under the restriction that UNDER NO CIRCUMTANCES ==--
|
14 |
|
|
--== this Software is to be used to CONSTRUCT a SPACEWIRE INTERFACE ==--
|
15 |
|
|
--== This implies modification and/or derivative work of this Software. ==--
|
16 |
|
|
--== ==--
|
17 |
|
|
--== 3. This source is distributed in the hope that it will be useful, ==--
|
18 |
|
|
--== but WITHOUT ANY WARRANTY; without even the implied warranty of ==--
|
19 |
|
|
--== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ==--
|
20 |
|
|
--== ==--
|
21 |
|
|
--== Your rights under this license are terminated immediately if you ==--
|
22 |
|
|
--== breach it in any way. ==--
|
23 |
|
|
--== ==--
|
24 |
|
|
---======================= End Software License =========================---
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
---====================== Start Copyright Notice ========================---
|
28 |
|
|
--== ==--
|
29 |
|
|
--== Filename ..... receiver.vhd ==--
|
30 |
|
|
--== Download ..... http://www.ida.ing.tu-bs.de ==--
|
31 |
|
|
--== Company ...... IDA TU Braunschweig, Prof. Dr.-Ing. Harald Michalik ==--
|
32 |
|
|
--== Authors ...... Björn Osterloh, Karel Kotarowski ==--
|
33 |
|
|
--== Contact ...... Björn Osterloh (b.osterloh@tu-bs.de) ==--
|
34 |
|
|
--== Copyright .... Copyright (c) 2008 IDA ==--
|
35 |
|
|
--== Project ...... SoCWire CODEC ==--
|
36 |
|
|
--== Version ...... 1.00 ==--
|
37 |
|
|
--== Conception ... 11 November 2008 ==--
|
38 |
|
|
--== Modified ..... N/A ==--
|
39 |
|
|
--== ==--
|
40 |
|
|
---======================= End Copyright Notice =========================---
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
LIBRARY IEEE;
|
44 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
45 |
|
|
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
|
46 |
|
|
USE WORK.ALL;
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
ENTITY receiver IS
|
50 |
|
|
GENERIC(
|
51 |
|
|
|
52 |
|
|
datawidth : NATURAL RANGE 8 TO 8192;
|
53 |
|
|
speed : NATURAL RANGE 1 TO 100;
|
54 |
|
|
disconnect_detection : NATURAL RANGE 1 TO 850
|
55 |
|
|
);
|
56 |
|
|
PORT(
|
57 |
|
|
--== General Interface (Sync Rst, 50MHz Clock) ==--
|
58 |
|
|
|
59 |
|
|
rst : IN STD_LOGIC;
|
60 |
|
|
clk : IN STD_LOGIC;
|
61 |
|
|
|
62 |
|
|
--== SoCWire Interface ==--
|
63 |
|
|
|
64 |
|
|
state : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
|
65 |
|
|
|
66 |
|
|
--== External Receive Interface ==--
|
67 |
|
|
|
68 |
|
|
rx : IN STD_LOGIC_VECTOR(datawidth+1 DOWNTO 0);
|
69 |
|
|
rx_valid : IN STD_LOGIC;
|
70 |
|
|
|
71 |
|
|
--== Character Interface ==--
|
72 |
|
|
|
73 |
|
|
got_null : OUT STD_LOGIC;
|
74 |
|
|
got_fct : OUT STD_LOGIC;
|
75 |
|
|
got_nchar : OUT STD_LOGIC;
|
76 |
|
|
|
77 |
|
|
--== Error Interface ==--
|
78 |
|
|
|
79 |
|
|
err_par : OUT STD_LOGIC;
|
80 |
|
|
err_esc : OUT STD_LOGIC;
|
81 |
|
|
err_dsc : OUT STD_LOGIC;
|
82 |
|
|
err_fct : OUT STD_LOGIC;
|
83 |
|
|
err_nchar : OUT STD_LOGIC;
|
84 |
|
|
|
85 |
|
|
--== Data Output Interface ==--
|
86 |
|
|
|
87 |
|
|
dat_nread : IN STD_LOGIC;
|
88 |
|
|
dat_empty : OUT STD_LOGIC;
|
89 |
|
|
dat_dout : OUT STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
90 |
|
|
|
91 |
|
|
--== FCT Output Interface ==--
|
92 |
|
|
|
93 |
|
|
fct_nread : IN STD_LOGIC;
|
94 |
|
|
fct_empty : OUT STD_LOGIC
|
95 |
|
|
);
|
96 |
|
|
END receiver;
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
ARCHITECTURE rtl OF receiver IS
|
100 |
|
|
|
101 |
|
|
---==========================---
|
102 |
|
|
--== Constants Declarations ==--
|
103 |
|
|
---==========================---
|
104 |
|
|
|
105 |
|
|
CONSTANT st_error_reset : STD_LOGIC_VECTOR(2 DOWNTO 0) := "000";
|
106 |
|
|
CONSTANT st_error_wait : STD_LOGIC_VECTOR(2 DOWNTO 0) := "001";
|
107 |
|
|
CONSTANT st_ready : STD_LOGIC_VECTOR(2 DOWNTO 0) := "010";
|
108 |
|
|
CONSTANT st_started : STD_LOGIC_VECTOR(2 DOWNTO 0) := "011";
|
109 |
|
|
CONSTANT st_connecting : STD_LOGIC_VECTOR(2 DOWNTO 0) := "100";
|
110 |
|
|
CONSTANT st_run : STD_LOGIC_VECTOR(2 DOWNTO 0) := "101";
|
111 |
|
|
CONSTANT st_unknown_1 : STD_LOGIC_VECTOR(2 DOWNTO 0) := "110";
|
112 |
|
|
CONSTANT st_unknown_2 : STD_LOGIC_VECTOR(2 DOWNTO 0) := "111";
|
113 |
|
|
CONSTANT zeros : STD_LOGIC_VECTOR(datawidth+1 downto 9) := (others => '0');
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
---=======================---
|
117 |
|
|
--== Signal Declarations ==--
|
118 |
|
|
---=======================---
|
119 |
|
|
|
120 |
|
|
SIGNAL rx_rst : STD_LOGIC;
|
121 |
|
|
SIGNAL dsc_count_d : STD_LOGIC_VECTOR(9 DOWNTO 0);
|
122 |
|
|
SIGNAL dsc_count : STD_LOGIC_VECTOR(9 DOWNTO 0);
|
123 |
|
|
SIGNAL bit_array : STD_LOGIC_VECTOR(datawidth+1 DOWNTO 0);
|
124 |
|
|
SIGNAL got_char : STD_LOGIC;
|
125 |
|
|
SIGNAL got_null_d : STD_LOGIC;
|
126 |
|
|
SIGNAL got_fct_d : STD_LOGIC;
|
127 |
|
|
SIGNAL got_eop_d : STD_LOGIC;
|
128 |
|
|
SIGNAL got_esc_d : STD_LOGIC;
|
129 |
|
|
SIGNAL got_data_d : STD_LOGIC;
|
130 |
|
|
SIGNAL got_nchar_d : STD_LOGIC;
|
131 |
|
|
SIGNAL err_par_d : STD_LOGIC;
|
132 |
|
|
SIGNAL err_esc_d : STD_LOGIC;
|
133 |
|
|
SIGNAL par_ok : STD_LOGIC;
|
134 |
|
|
SIGNAL got_null_i : STD_LOGIC;
|
135 |
|
|
SIGNAL got_esc_dd : STD_LOGIC;
|
136 |
|
|
SIGNAL got_esc : STD_LOGIC;
|
137 |
|
|
SIGNAL dat_empty_d : STD_LOGIC;
|
138 |
|
|
SIGNAL dat_empty_i : STD_LOGIC;
|
139 |
|
|
SIGNAL fct_empty_d : STD_LOGIC;
|
140 |
|
|
SIGNAL fct_empty_i : STD_LOGIC;
|
141 |
|
|
SIGNAL err_dsc_d : STD_LOGIC;
|
142 |
|
|
SIGNAL dat_dout_d : STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
143 |
|
|
SIGNAL x : STD_LOGIC;
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
BEGIN
|
148 |
|
|
|
149 |
|
|
---======================================================---
|
150 |
|
|
--== Generate Tx Reset Signal to hold Receiver in Reset ==--
|
151 |
|
|
---======================================================---
|
152 |
|
|
|
153 |
|
|
rx_rst <= '1' WHEN (rst = '1') OR (state = st_error_reset) ELSE '0';
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
---=====================---
|
157 |
|
|
--== Synchronous Logic ==--
|
158 |
|
|
---=====================---
|
159 |
|
|
|
160 |
|
|
PROCESS (clk)
|
161 |
|
|
VARIABLE par_temp : STD_LOGIC;
|
162 |
|
|
BEGIN
|
163 |
|
|
IF RISING_EDGE(clk) THEN
|
164 |
|
|
IF rx_rst = '0' THEN
|
165 |
|
|
par_temp := '0';
|
166 |
|
|
FOR i IN 2 TO datawidth+1 LOOP
|
167 |
|
|
par_temp := par_temp XOR bit_array(i);
|
168 |
|
|
END LOOP;
|
169 |
|
|
par_ok <= rx(0) XOR rx(1) XOR par_temp;
|
170 |
|
|
err_dsc <= err_dsc_d;
|
171 |
|
|
dsc_count <= dsc_count_d;
|
172 |
|
|
bit_array <= rx;
|
173 |
|
|
dat_dout <= dat_dout_d;
|
174 |
|
|
dat_empty_i <= dat_empty_d;
|
175 |
|
|
fct_empty_i <= fct_empty_d;
|
176 |
|
|
got_esc <= got_esc_dd;
|
177 |
|
|
err_par <= err_par_d;
|
178 |
|
|
err_esc <= err_esc_d;
|
179 |
|
|
got_fct <= got_fct_d;
|
180 |
|
|
got_nchar <= got_nchar_d;
|
181 |
|
|
ELSE
|
182 |
|
|
par_ok <= '0';
|
183 |
|
|
par_temp := '0';
|
184 |
|
|
err_dsc <= '0';
|
185 |
|
|
dsc_count <= (others => '0');
|
186 |
|
|
bit_array <= zeros & "000000001";
|
187 |
|
|
dat_dout <= (others => '0');
|
188 |
|
|
fct_empty_i <= '1';
|
189 |
|
|
dat_empty_i <= '1';
|
190 |
|
|
got_esc <= '0';
|
191 |
|
|
err_par <= '0';
|
192 |
|
|
err_esc <= '0';
|
193 |
|
|
got_fct <= '0';
|
194 |
|
|
got_nchar <= '0';
|
195 |
|
|
END IF;
|
196 |
|
|
END IF;
|
197 |
|
|
END PROCESS;
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
---===========================---
|
201 |
|
|
--== Rx Disconnect Detection ==--
|
202 |
|
|
---===========================---
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
err_dsc_d <= '1' WHEN (dsc_count = disconnect_detection / speed) ELSE '0';
|
206 |
|
|
|
207 |
|
|
PROCESS(rx_valid, dsc_count)
|
208 |
|
|
BEGIN
|
209 |
|
|
IF (rx_valid = '1') THEN
|
210 |
|
|
dsc_count_d <= "0000000001";
|
211 |
|
|
ELSIF (dsc_count /= "0000000000") THEN
|
212 |
|
|
dsc_count_d <= dsc_count + 1;
|
213 |
|
|
ELSE
|
214 |
|
|
dsc_count_d <= dsc_count; -- could be all 0's, if so add it to reset!!
|
215 |
|
|
END IF;
|
216 |
|
|
END PROCESS;
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
---===============================---
|
220 |
|
|
--== Rx Character Identification ==--
|
221 |
|
|
---===============================---
|
222 |
|
|
|
223 |
|
|
got_char <= '1' WHEN (rx_valid = '1') AND (rx /= zeros & "000101110")
|
224 |
|
|
AND (got_null_i = '1') ELSE '0';
|
225 |
|
|
|
226 |
|
|
got_null_d <= '1' WHEN (rx_valid = '1') AND (rx(9 downto 1) = "000010111") AND (rx(datawidth+1 downto 9) = zeros)
|
227 |
|
|
AND (par_ok = '1') ELSE '0';
|
228 |
|
|
|
229 |
|
|
got_fct_d <= '1' WHEN (got_char = '1') AND
|
230 |
|
|
(got_esc = '0') AND
|
231 |
|
|
(rx(9 downto 1) = "000000001") AND (rx(datawidth+1 downto 9) = zeros)
|
232 |
|
|
AND (par_ok = '1') ELSE '0';
|
233 |
|
|
|
234 |
|
|
got_eop_d <= '1' WHEN (got_char = '1') AND (rx(datawidth+1 downto 9) = zeros) AND
|
235 |
|
|
(got_esc = '0') AND
|
236 |
|
|
((rx(9 downto 1) = "000000011") OR
|
237 |
|
|
(rx(9 downto 1) = "000000101")) AND
|
238 |
|
|
(par_ok = '1') ELSE '0';
|
239 |
|
|
|
240 |
|
|
got_esc_d <= '1' WHEN (got_char = '1') AND (rx(datawidth+1 downto 9) = zeros) AND
|
241 |
|
|
(rx(9 downto 1) = "000000111") AND
|
242 |
|
|
(par_ok = '1') ELSE '0';
|
243 |
|
|
|
244 |
|
|
got_data_d <= '1' WHEN (got_char = '1') AND
|
245 |
|
|
(rx(1) = '0') AND
|
246 |
|
|
(got_esc = '0') AND
|
247 |
|
|
(par_ok = '1') ELSE '0';
|
248 |
|
|
|
249 |
|
|
err_esc_d <= got_esc AND got_char AND ((rx(3) OR rx(2)) AND rx(1));
|
250 |
|
|
|
251 |
|
|
err_par_d <= NOT par_ok AND rx_valid;
|
252 |
|
|
|
253 |
|
|
got_nchar_d <= got_eop_d OR got_data_d;
|
254 |
|
|
|
255 |
|
|
got_nchar_d <= got_eop_d OR got_data_d;
|
256 |
|
|
|
257 |
|
|
x <= got_null_d NOR got_null_i;
|
258 |
|
|
got_null_i <= rx_rst NOR x;
|
259 |
|
|
|
260 |
|
|
PROCESS(rx_valid, got_esc_d, got_char, got_esc)
|
261 |
|
|
BEGIN
|
262 |
|
|
IF (rx_valid = '1') AND (got_esc_d = '1') THEN
|
263 |
|
|
got_esc_dd <= '1';
|
264 |
|
|
ELSIF (got_char = '1') THEN
|
265 |
|
|
got_esc_dd <= '0';
|
266 |
|
|
ELSE
|
267 |
|
|
got_esc_dd <= got_esc;
|
268 |
|
|
END IF;
|
269 |
|
|
END PROCESS;
|
270 |
|
|
|
271 |
|
|
fct_empty_d <= NOT(got_fct_d);
|
272 |
|
|
dat_empty_d <= NOT(got_nchar_d);
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
PROCESS(rx, got_eop_d)
|
276 |
|
|
BEGIN
|
277 |
|
|
IF(got_eop_d = '1') THEN
|
278 |
|
|
dat_dout_d(datawidth) <= '1';
|
279 |
|
|
dat_dout_d(datawidth-1 downto 1) <= (others => '0');
|
280 |
|
|
dat_dout_d(0) <= rx(2);
|
281 |
|
|
ELSE
|
282 |
|
|
dat_dout_d(datawidth) <= '0';
|
283 |
|
|
FOR i IN 0 TO datawidth-1 LOOP
|
284 |
|
|
dat_dout_d(i) <= rx(i+2);
|
285 |
|
|
END LOOP;
|
286 |
|
|
END IF;
|
287 |
|
|
END PROCESS;
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
---===============================================---
|
291 |
|
|
--== Generate error for too much data comming in ==--
|
292 |
|
|
---===============================================---
|
293 |
|
|
|
294 |
|
|
err_nchar <= NOT(dat_empty_i) AND dat_nread;
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
---================================================---
|
298 |
|
|
--== Generate error for too many FCT's comming in ==--
|
299 |
|
|
---================================================---
|
300 |
|
|
|
301 |
|
|
err_fct <= NOT(fct_empty_i) AND fct_nread;
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
---======================================---
|
305 |
|
|
--== Shared Internal & External Signals ==--
|
306 |
|
|
---======================================---
|
307 |
|
|
|
308 |
|
|
got_null <= got_null_i;
|
309 |
|
|
dat_empty <= dat_empty_i;
|
310 |
|
|
fct_empty <= fct_empty_i;
|
311 |
|
|
|
312 |
|
|
END rtl;
|