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 ..... transmit_fifo.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 |
|
|
LIBRARY IEEE;
|
43 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
44 |
|
|
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
|
45 |
|
|
USE WORK.ALL;
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
ENTITY transmit_fifo IS
|
49 |
|
|
GENERIC(
|
50 |
|
|
|
51 |
|
|
datawidth : NATURAL RANGE 8 TO 8192
|
52 |
|
|
);
|
53 |
|
|
PORT(
|
54 |
|
|
--== General Interface (Sync Rst, 50MHz Clock) ==--
|
55 |
|
|
|
56 |
|
|
rst : IN STD_LOGIC;
|
57 |
|
|
clk : IN STD_LOGIC;
|
58 |
|
|
|
59 |
|
|
--== SoCWire Interface ==--
|
60 |
|
|
|
61 |
|
|
state : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
|
62 |
|
|
|
63 |
|
|
--== Data Input Interface ==--
|
64 |
|
|
|
65 |
|
|
dat_full : OUT STD_LOGIC;
|
66 |
|
|
dat_nwrite : IN STD_LOGIC;
|
67 |
|
|
dat_din : IN STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
68 |
|
|
|
69 |
|
|
--== Data Output Interface ==--
|
70 |
|
|
|
71 |
|
|
dat_nread : IN STD_LOGIC;
|
72 |
|
|
dat_empty : OUT STD_LOGIC;
|
73 |
|
|
dat_dout : OUT STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
74 |
|
|
|
75 |
|
|
--== FCT Input Interface ==--
|
76 |
|
|
|
77 |
|
|
fct_full : OUT STD_LOGIC;
|
78 |
|
|
fct_nwrite : IN STD_LOGIC
|
79 |
|
|
);
|
80 |
|
|
END transmit_fifo;
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
ARCHITECTURE rtl OF transmit_fifo IS
|
85 |
|
|
|
86 |
|
|
---==========================---
|
87 |
|
|
--== Constants Declarations ==--
|
88 |
|
|
---==========================---
|
89 |
|
|
|
90 |
|
|
CONSTANT st_error_reset : STD_LOGIC_VECTOR(2 DOWNTO 0) := "000";
|
91 |
|
|
CONSTANT st_error_wait : STD_LOGIC_VECTOR(2 DOWNTO 0) := "001";
|
92 |
|
|
CONSTANT st_ready : STD_LOGIC_VECTOR(2 DOWNTO 0) := "010";
|
93 |
|
|
CONSTANT st_started : STD_LOGIC_VECTOR(2 DOWNTO 0) := "011";
|
94 |
|
|
CONSTANT st_connecting : STD_LOGIC_VECTOR(2 DOWNTO 0) := "100";
|
95 |
|
|
CONSTANT st_run : STD_LOGIC_VECTOR(2 DOWNTO 0) := "101";
|
96 |
|
|
CONSTANT st_unknown_1 : STD_LOGIC_VECTOR(2 DOWNTO 0) := "110";
|
97 |
|
|
CONSTANT st_unknown_2 : STD_LOGIC_VECTOR(2 DOWNTO 0) := "111";
|
98 |
|
|
|
99 |
|
|
---=======================---
|
100 |
|
|
--== Signal Declarations ==--
|
101 |
|
|
---=======================---
|
102 |
|
|
|
103 |
|
|
SIGNAL rst_fct : STD_LOGIC;
|
104 |
|
|
SIGNAL fct_full_d : STD_LOGIC;
|
105 |
|
|
SIGNAL fct_full_i : STD_LOGIC;
|
106 |
|
|
SIGNAL fct_en : STD_LOGIC;
|
107 |
|
|
SIGNAL dat_en : STD_LOGIC;
|
108 |
|
|
SIGNAL dat2_en : STD_LOGIC;
|
109 |
|
|
SIGNAL credit : STD_LOGIC_VECTOR(5 DOWNTO 0) := (OTHERS => '0');
|
110 |
|
|
SIGNAL credit_d : STD_LOGIC_VECTOR(5 DOWNTO 0);
|
111 |
|
|
SIGNAL credit_e : STD_LOGIC;
|
112 |
|
|
SIGNAL dat_full_d : STD_LOGIC;
|
113 |
|
|
SIGNAL dat_full_i : STD_LOGIC;
|
114 |
|
|
SIGNAL dat_empty_d : STD_LOGIC;
|
115 |
|
|
SIGNAL dat_empty_i : STD_LOGIC;
|
116 |
|
|
SIGNAL store_e : STD_LOGIC;
|
117 |
|
|
SIGNAL store : STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
118 |
|
|
SIGNAL got_eop : STD_LOGIC;
|
119 |
|
|
SIGNAL swallow_d : STD_LOGIC;
|
120 |
|
|
SIGNAL swallow : STD_LOGIC;
|
121 |
|
|
SIGNAL dat_dout_e : STD_LOGIC;
|
122 |
|
|
SIGNAL dat_dout_d : STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
BEGIN
|
126 |
|
|
|
127 |
|
|
---============================================---
|
128 |
|
|
--== Reset for non-Connecting & non-Run logic ==--
|
129 |
|
|
---============================================---
|
130 |
|
|
|
131 |
|
|
rst_fct <= '1' WHEN (rst = '1') OR NOT((state = st_connecting) OR (state = st_run)) ELSE '0';
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
---=====================---
|
135 |
|
|
--== Synchronous Logic ==--
|
136 |
|
|
---=====================---
|
137 |
|
|
|
138 |
|
|
PROCESS (clk)
|
139 |
|
|
BEGIN
|
140 |
|
|
IF RISING_EDGE(clk) THEN
|
141 |
|
|
IF rst_fct = '0' THEN
|
142 |
|
|
fct_full_i <= fct_full_d;
|
143 |
|
|
IF credit_e = '1' THEN
|
144 |
|
|
credit <= credit_d;
|
145 |
|
|
END IF;
|
146 |
|
|
ELSE
|
147 |
|
|
credit <= (others => '0');
|
148 |
|
|
fct_full_i <= '1';
|
149 |
|
|
END IF;
|
150 |
|
|
|
151 |
|
|
IF rst = '0' THEN
|
152 |
|
|
swallow <= swallow_d;
|
153 |
|
|
dat_full_i <= dat_full_d;
|
154 |
|
|
dat_empty_i <= dat_empty_d;
|
155 |
|
|
IF dat2_en = '1' THEN
|
156 |
|
|
got_eop <= dat_din(datawidth);
|
157 |
|
|
END IF;
|
158 |
|
|
IF store_e = '1' THEN
|
159 |
|
|
store <= dat_din;
|
160 |
|
|
END IF;
|
161 |
|
|
IF dat_dout_e = '1' THEN
|
162 |
|
|
dat_dout <= dat_dout_d;
|
163 |
|
|
END IF;
|
164 |
|
|
ELSE
|
165 |
|
|
got_eop <= '1';
|
166 |
|
|
swallow <= '1';
|
167 |
|
|
dat_full_i <= '1';
|
168 |
|
|
dat_empty_i <= '1';
|
169 |
|
|
store <= (others => '0');
|
170 |
|
|
dat_dout <= (others => '0');
|
171 |
|
|
END IF;
|
172 |
|
|
END IF;
|
173 |
|
|
END PROCESS;
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
---====================---
|
177 |
|
|
--== FCT Write Enable ==--
|
178 |
|
|
---====================---
|
179 |
|
|
|
180 |
|
|
fct_en <= NOT(fct_full_i) AND NOT(fct_nwrite);
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
---========================---
|
184 |
|
|
--== Data Out Read Enable ==--
|
185 |
|
|
---========================---
|
186 |
|
|
|
187 |
|
|
dat_en <= NOT(dat_empty_i) AND NOT(dat_nread);
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
---========================---
|
191 |
|
|
--== Data In Write Enable ==--
|
192 |
|
|
---========================---
|
193 |
|
|
|
194 |
|
|
dat2_en <= NOT(dat_full_i) AND NOT(dat_nwrite);
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
---===========================---
|
198 |
|
|
--== Transmit Credit Counter ==--
|
199 |
|
|
---===========================---
|
200 |
|
|
|
201 |
|
|
PROCESS(fct_en, dat_en, credit)
|
202 |
|
|
VARIABLE tmp : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
203 |
|
|
BEGIN
|
204 |
|
|
tmp := fct_en & dat_en;
|
205 |
|
|
CASE tmp IS
|
206 |
|
|
WHEN "11" => credit_d <= credit + 7;
|
207 |
|
|
WHEN "10" => credit_d <= credit + 8;
|
208 |
|
|
WHEN "01" => credit_d <= credit - 1;
|
209 |
|
|
WHEN OTHERS => credit_d <= credit;
|
210 |
|
|
END CASE;
|
211 |
|
|
END PROCESS;
|
212 |
|
|
|
213 |
|
|
credit_e <= fct_en OR dat_en;
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
---=======================---
|
217 |
|
|
--== FCT Handshake Logic ==--
|
218 |
|
|
---=======================---
|
219 |
|
|
|
220 |
|
|
PROCESS(credit, fct_en)
|
221 |
|
|
BEGIN
|
222 |
|
|
IF (credit <= '1' & NOT(fct_en) & fct_en & "000") THEN
|
223 |
|
|
fct_full_d <= '0';
|
224 |
|
|
ELSE
|
225 |
|
|
fct_full_d <= '1';
|
226 |
|
|
END IF;
|
227 |
|
|
END PROCESS;
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
---========================---
|
231 |
|
|
--== Packet swallow logic ==--
|
232 |
|
|
---========================---
|
233 |
|
|
|
234 |
|
|
PROCESS(state, swallow, dat_full_i, dat_nwrite, dat_din, got_eop)
|
235 |
|
|
BEGIN
|
236 |
|
|
IF (state /= st_Run) THEN
|
237 |
|
|
swallow_d <= '1';
|
238 |
|
|
ELSE
|
239 |
|
|
IF (swallow = '1') THEN
|
240 |
|
|
IF ((dat_full_i = '0') AND (dat_nwrite = '0') AND (dat_din(datawidth) = '1')) OR (got_eop = '1') THEN
|
241 |
|
|
swallow_d <= '0';
|
242 |
|
|
ELSE
|
243 |
|
|
swallow_d <= '1';
|
244 |
|
|
END IF;
|
245 |
|
|
ELSE
|
246 |
|
|
swallow_d <= '0';
|
247 |
|
|
END IF;
|
248 |
|
|
END IF;
|
249 |
|
|
END PROCESS;
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
---========================---
|
253 |
|
|
--== FIFO full flag logic ==--
|
254 |
|
|
---========================---
|
255 |
|
|
|
256 |
|
|
PROCESS(state, swallow, got_eop, dat_full_i, dat_nwrite, dat_din, credit, dat_en, dat_empty_i, dat_nread)
|
257 |
|
|
BEGIN
|
258 |
|
|
IF (state /= st_Run) THEN
|
259 |
|
|
dat_full_d <= '0';
|
260 |
|
|
ELSE
|
261 |
|
|
IF (swallow = '1') THEN
|
262 |
|
|
IF (got_eop = '1') AND (dat_full_i = '0') AND (dat_nwrite = '0') AND (dat_din(datawidth) = '0') THEN
|
263 |
|
|
dat_full_d <= '1';
|
264 |
|
|
ELSE
|
265 |
|
|
dat_full_d <= '0';
|
266 |
|
|
END IF;
|
267 |
|
|
ELSE
|
268 |
|
|
IF (credit(5 DOWNTO 1) = "000000") AND ((credit(0) = '0') OR (dat_en = '1')) THEN
|
269 |
|
|
dat_full_d <= dat_full_i OR NOT(dat_nwrite);
|
270 |
|
|
ELSE
|
271 |
|
|
dat_full_d <= NOT(dat_empty_i) AND dat_nread AND (dat_full_i OR NOT(dat_nwrite));
|
272 |
|
|
END IF;
|
273 |
|
|
END IF;
|
274 |
|
|
END IF;
|
275 |
|
|
END PROCESS;
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
---=========================---
|
279 |
|
|
--== FIFO empty flag logic ==--
|
280 |
|
|
---=========================---
|
281 |
|
|
|
282 |
|
|
PROCESS(state, swallow, credit, dat_en, dat_full_i, dat_nwrite, dat_empty_i, dat_nread)
|
283 |
|
|
BEGIN
|
284 |
|
|
IF (state /= st_Run) OR (swallow = '1') THEN
|
285 |
|
|
dat_empty_d <= '1';
|
286 |
|
|
ELSE
|
287 |
|
|
IF (credit(5 DOWNTO 1) = "000000") AND ((credit(0) = '0') OR (dat_en = '1')) THEN
|
288 |
|
|
dat_empty_d <= '1';
|
289 |
|
|
ELSE
|
290 |
|
|
dat_empty_d <= NOT(dat_full_i) AND dat_nwrite AND (dat_empty_i OR NOT(dat_nread));
|
291 |
|
|
END IF;
|
292 |
|
|
END IF;
|
293 |
|
|
END PROCESS;
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
---===============---
|
297 |
|
|
--== FIFO memory ==--
|
298 |
|
|
---===============---
|
299 |
|
|
|
300 |
|
|
store_e <= NOT(dat_full_i);
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
---=======================---
|
304 |
|
|
--== FIFO data out logic ==--
|
305 |
|
|
---=======================---
|
306 |
|
|
|
307 |
|
|
PROCESS(dat_full_i, dat_din, store)
|
308 |
|
|
BEGIN
|
309 |
|
|
CASE dat_full_i IS
|
310 |
|
|
WHEN '0' => dat_dout_d <= dat_din;
|
311 |
|
|
WHEN '1' => dat_dout_d <= store;
|
312 |
|
|
WHEN OTHERS => NULL;
|
313 |
|
|
END CASE;
|
314 |
|
|
END PROCESS;
|
315 |
|
|
|
316 |
|
|
dat_dout_e <= '1' WHEN (dat_empty_i = '1') OR (dat_nread = '0') ELSE '0';
|
317 |
|
|
|
318 |
|
|
---======================================---
|
319 |
|
|
--== Shared Internal & External Signals ==--
|
320 |
|
|
---======================================---
|
321 |
|
|
|
322 |
|
|
dat_full <= dat_full_i;
|
323 |
|
|
fct_full <= fct_full_i;
|
324 |
|
|
dat_empty <= dat_empty_i;
|
325 |
|
|
|
326 |
|
|
END rtl;
|