| 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 ..... receive_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 receive_fifo IS
|
| 49 |
|
|
GENERIC(
|
| 50 |
19 |
bjoerno |
datawidth : NATURAL RANGE 8 TO 8192
|
| 51 |
8 |
bjoerno |
);
|
| 52 |
|
|
PORT(
|
| 53 |
|
|
--== General Interface (Sync Rst, 50MHz Clock) ==--
|
| 54 |
|
|
|
| 55 |
|
|
rst : IN STD_LOGIC;
|
| 56 |
|
|
clk : IN STD_LOGIC;
|
| 57 |
|
|
|
| 58 |
|
|
--== SoCWire Interface ==--
|
| 59 |
|
|
|
| 60 |
|
|
state : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
|
| 61 |
|
|
|
| 62 |
|
|
--== Data Input Interface ==--
|
| 63 |
|
|
|
| 64 |
|
|
dat_full : OUT STD_LOGIC;
|
| 65 |
|
|
dat_nwrite : IN STD_LOGIC;
|
| 66 |
|
|
dat_din : IN STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
| 67 |
|
|
|
| 68 |
|
|
--== Data Output Interface ==--
|
| 69 |
|
|
|
| 70 |
|
|
dat_nread : IN STD_LOGIC;
|
| 71 |
|
|
dat_empty : OUT STD_LOGIC;
|
| 72 |
|
|
dat_dout : OUT STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
| 73 |
|
|
|
| 74 |
|
|
--== FCT Output Interface ==--
|
| 75 |
|
|
|
| 76 |
|
|
fct_nread : IN STD_LOGIC;
|
| 77 |
|
|
fct_empty : OUT STD_LOGIC
|
| 78 |
|
|
);
|
| 79 |
|
|
END receive_fifo;
|
| 80 |
|
|
|
| 81 |
|
|
|
| 82 |
|
|
ARCHITECTURE rtl OF receive_fifo IS
|
| 83 |
|
|
|
| 84 |
|
|
---==========================---
|
| 85 |
|
|
--== Constants Declarations ==--
|
| 86 |
|
|
---==========================---
|
| 87 |
|
|
|
| 88 |
|
|
CONSTANT st_error_reset : STD_LOGIC_VECTOR(2 DOWNTO 0) := "000";
|
| 89 |
|
|
CONSTANT st_error_wait : STD_LOGIC_VECTOR(2 DOWNTO 0) := "001";
|
| 90 |
|
|
CONSTANT st_ready : STD_LOGIC_VECTOR(2 DOWNTO 0) := "010";
|
| 91 |
|
|
CONSTANT st_started : STD_LOGIC_VECTOR(2 DOWNTO 0) := "011";
|
| 92 |
|
|
CONSTANT st_connecting : STD_LOGIC_VECTOR(2 DOWNTO 0) := "100";
|
| 93 |
|
|
CONSTANT st_run : STD_LOGIC_VECTOR(2 DOWNTO 0) := "101";
|
| 94 |
|
|
CONSTANT st_unknown_1 : STD_LOGIC_VECTOR(2 DOWNTO 0) := "110";
|
| 95 |
|
|
CONSTANT st_unknown_2 : STD_LOGIC_VECTOR(2 DOWNTO 0) := "111";
|
| 96 |
|
|
CONSTANT zeros : STD_LOGIC_VECTOR(datawidth-1 DOWNTO 1) := (OTHERS => '0');
|
| 97 |
|
|
|
| 98 |
|
|
---=======================---
|
| 99 |
|
|
--== Signal Declarations ==--
|
| 100 |
|
|
---=======================---
|
| 101 |
|
|
|
| 102 |
|
|
SIGNAL rd_en : STD_LOGIC;
|
| 103 |
|
|
SIGNAL rd_addr : STD_LOGIC_VECTOR(9 DOWNTO 0) := (OTHERS => '0');
|
| 104 |
|
|
SIGNAL rd_empty_d : STD_LOGIC;
|
| 105 |
|
|
SIGNAL rd_empty : STD_LOGIC;
|
| 106 |
|
|
SIGNAL rd_addr_d : STD_LOGIC_VECTOR(9 DOWNTO 0);
|
| 107 |
|
|
SIGNAL wr_en : STD_LOGIC;
|
| 108 |
|
|
SIGNAL wr_addr : STD_LOGIC_VECTOR(9 DOWNTO 0) := (OTHERS => '0');
|
| 109 |
|
|
SIGNAL wr_full_d : STD_LOGIC;
|
| 110 |
|
|
SIGNAL wr_full : STD_LOGIC;
|
| 111 |
|
|
SIGNAL wr_din : STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
| 112 |
|
|
SIGNAL wr_addr_d : STD_LOGIC_VECTOR(9 DOWNTO 0);
|
| 113 |
|
|
SIGNAL empty_i : STD_LOGIC;
|
| 114 |
|
|
SIGNAL fct_empty_i_d : STD_LOGIC;
|
| 115 |
|
|
SIGNAL fct_empty_i : STD_LOGIC;
|
| 116 |
|
|
SIGNAL fct_en : STD_LOGIC;
|
| 117 |
|
|
SIGNAL credit : STD_LOGIC_VECTOR(5 DOWNTO 0) := (OTHERS => '0');
|
| 118 |
|
|
SIGNAL credit_d : STD_LOGIC_VECTOR(5 DOWNTO 0) := (OTHERS => '0');
|
| 119 |
|
|
SIGNAL credit_e : STD_LOGIC;
|
| 120 |
|
|
SIGNAL vfullness : STD_LOGIC_VECTOR(9 DOWNTO 0) := (OTHERS => '0');
|
| 121 |
|
|
SIGNAL vfullness_d : STD_LOGIC_VECTOR(9 DOWNTO 0) := (OTHERS => '0');
|
| 122 |
|
|
SIGNAL vfullness_e : STD_LOGIC;
|
| 123 |
|
|
SIGNAL fullness : STD_LOGIC_VECTOR(9 DOWNTO 0) := (OTHERS => '0');
|
| 124 |
|
|
SIGNAL fullness_d : STD_LOGIC_VECTOR(9 DOWNTO 0) := (OTHERS => '0');
|
| 125 |
|
|
SIGNAL fullness_e : STD_LOGIC;
|
| 126 |
|
|
SIGNAL got_eop : STD_LOGIC;
|
| 127 |
|
|
SIGNAL empty_i_d : STD_LOGIC;
|
| 128 |
|
|
SIGNAL rst_fct : STD_LOGIC;
|
| 129 |
|
|
SIGNAL wr_en_ext : STD_LOGIC;
|
| 130 |
|
|
|
| 131 |
|
|
|
| 132 |
|
|
|
| 133 |
|
|
---=============================================---
|
| 134 |
|
|
--== Component Instantiations for leaf modules ==--
|
| 135 |
|
|
---=============================================---
|
| 136 |
|
|
|
| 137 |
|
|
COMPONENT dp_ram
|
| 138 |
|
|
GENERIC(
|
| 139 |
|
|
datawidth : NATURAL RANGE 8 TO 8192
|
| 140 |
|
|
);
|
| 141 |
|
|
PORT(
|
| 142 |
|
|
--== General Interface ==--
|
| 143 |
|
|
|
| 144 |
|
|
rst : IN STD_LOGIC;
|
| 145 |
|
|
clk : IN STD_LOGIC;
|
| 146 |
|
|
|
| 147 |
|
|
--== Write Interface ==--
|
| 148 |
|
|
|
| 149 |
|
|
wr_en : IN STD_LOGIC;
|
| 150 |
|
|
wr_addr : IN STD_LOGIC_VECTOR(9 DOWNTO 0);
|
| 151 |
|
|
wr_din : IN STD_LOGIC_VECTOR(datawidth DOWNTO 0);
|
| 152 |
|
|
|
| 153 |
|
|
--== Read Interface ==--
|
| 154 |
|
|
|
| 155 |
|
|
rd_en : IN STD_LOGIC;
|
| 156 |
|
|
rd_addr : IN STD_LOGIC_VECTOR(9 DOWNTO 0);
|
| 157 |
|
|
rd_dout : OUT STD_LOGIC_VECTOR(datawidth DOWNTO 0)
|
| 158 |
|
|
);
|
| 159 |
|
|
END COMPONENT dp_ram;
|
| 160 |
|
|
|
| 161 |
|
|
|
| 162 |
|
|
BEGIN
|
| 163 |
|
|
|
| 164 |
|
|
---============================================---
|
| 165 |
|
|
--== Reset for non-Connecting & non-Run logic ==--
|
| 166 |
|
|
---============================================---
|
| 167 |
|
|
|
| 168 |
|
|
rst_fct <= '1' WHEN (rst = '1') OR NOT((state = st_connecting) OR (state = st_run)) ELSE '0';
|
| 169 |
|
|
|
| 170 |
|
|
|
| 171 |
|
|
---=====================---
|
| 172 |
|
|
--== Synchronous Logic ==--
|
| 173 |
|
|
---=====================---
|
| 174 |
|
|
|
| 175 |
|
|
PROCESS (clk)
|
| 176 |
|
|
BEGIN
|
| 177 |
|
|
IF RISING_EDGE(clk) THEN
|
| 178 |
|
|
IF rst_fct = '0' THEN
|
| 179 |
|
|
fct_empty_i <= fct_empty_i_d;
|
| 180 |
|
|
IF credit_e = '1' THEN
|
| 181 |
|
|
credit <= credit_d;
|
| 182 |
|
|
END IF;
|
| 183 |
|
|
ELSE
|
| 184 |
|
|
credit <= (others => '0');
|
| 185 |
|
|
fct_empty_i <= '1';
|
| 186 |
|
|
END IF;
|
| 187 |
|
|
|
| 188 |
|
|
IF rst = '0' THEN
|
| 189 |
|
|
wr_full <= wr_full_d;
|
| 190 |
|
|
rd_empty <= rd_empty_d;
|
| 191 |
|
|
empty_i <= empty_i_d;
|
| 192 |
|
|
|
| 193 |
|
|
IF wr_en = '1' THEN
|
| 194 |
|
|
got_eop <= wr_din(datawidth);
|
| 195 |
|
|
wr_addr <= wr_addr_d;
|
| 196 |
|
|
END IF;
|
| 197 |
|
|
IF rd_en = '1' THEN
|
| 198 |
|
|
rd_addr <= rd_addr_d;
|
| 199 |
|
|
END IF;
|
| 200 |
|
|
IF fullness_e = '1' THEN
|
| 201 |
|
|
fullness <= fullness_d;
|
| 202 |
|
|
END IF;
|
| 203 |
|
|
IF vfullness_e = '1' THEN
|
| 204 |
|
|
vfullness <= vfullness_d;
|
| 205 |
|
|
END IF;
|
| 206 |
|
|
|
| 207 |
|
|
ELSE
|
| 208 |
|
|
got_eop <= '1';
|
| 209 |
|
|
wr_addr <= (others => '0');
|
| 210 |
|
|
rd_addr <= (others => '0');
|
| 211 |
|
|
wr_full <= '1';
|
| 212 |
|
|
rd_empty <= '1';
|
| 213 |
|
|
fullness <= (others => '0');
|
| 214 |
|
|
empty_i <= '1';
|
| 215 |
|
|
vfullness <= (others => '0');
|
| 216 |
|
|
|
| 217 |
|
|
END IF;
|
| 218 |
|
|
END IF;
|
| 219 |
|
|
END PROCESS;
|
| 220 |
|
|
|
| 221 |
|
|
|
| 222 |
|
|
---=================---
|
| 223 |
|
|
--== EEP Generator ==--
|
| 224 |
|
|
---=================---
|
| 225 |
|
|
|
| 226 |
|
|
wr_din <= dat_din WHEN (dat_nwrite = '0') AND (wr_full = '0') ELSE '1' & zeros & '1';
|
| 227 |
|
|
|
| 228 |
|
|
|
| 229 |
|
|
---===========================================---
|
| 230 |
|
|
--== FIFO Write Enable & EEP Insertion Logic ==--
|
| 231 |
|
|
---===========================================---
|
| 232 |
|
|
|
| 233 |
|
|
wr_en <= '1' WHEN ((dat_nwrite = '0') AND (wr_full = '0')) OR ((got_eop = '0') AND (state /= st_connecting) AND (state /= st_run)) ELSE '0';
|
| 234 |
|
|
|
| 235 |
|
|
|
| 236 |
|
|
---======================---
|
| 237 |
|
|
--== FIFO Write Address ==--
|
| 238 |
|
|
---======================---
|
| 239 |
|
|
|
| 240 |
|
|
wr_addr_d <= wr_addr + 1;
|
| 241 |
|
|
|
| 242 |
|
|
|
| 243 |
|
|
---==================---
|
| 244 |
|
|
--== FIFO Full Flag ==--
|
| 245 |
|
|
---==================---
|
| 246 |
|
|
|
| 247 |
|
|
wr_full_d <= '1' WHEN ((credit(5 DOWNTO 1) = 0) AND ((credit(0) = '0') OR (wr_en_ext = '1')) AND
|
| 248 |
|
|
(fct_en = '0')) OR (state /= st_run) ELSE '0';
|
| 249 |
|
|
|
| 250 |
|
|
|
| 251 |
|
|
---===========================---
|
| 252 |
|
|
--== FIFO (Auto) Read Enable ==--
|
| 253 |
|
|
---===========================---
|
| 254 |
|
|
|
| 255 |
|
|
rd_en <= NOT(rd_empty) AND (empty_i OR NOT(dat_nread));
|
| 256 |
|
|
|
| 257 |
|
|
|
| 258 |
|
|
---=====================---
|
| 259 |
|
|
--== FIFO Read Address ==--
|
| 260 |
|
|
---=====================---
|
| 261 |
|
|
|
| 262 |
|
|
rd_addr_d <= rd_addr + 1;
|
| 263 |
|
|
|
| 264 |
|
|
|
| 265 |
|
|
---===================---
|
| 266 |
|
|
--== FIFO Empty Flag ==--
|
| 267 |
|
|
---===================---
|
| 268 |
|
|
|
| 269 |
|
|
rd_empty_d <= '1' WHEN (fullness(9 DOWNTO 1) = 0) AND (wr_en = '0') AND
|
| 270 |
|
|
((fullness(0) = '0') OR (rd_en = '1')) ELSE '0';
|
| 271 |
|
|
|
| 272 |
|
|
|
| 273 |
|
|
---==================================---
|
| 274 |
|
|
--== FIFO (Actual) Fullness Counter ==--
|
| 275 |
|
|
---==================================---
|
| 276 |
|
|
|
| 277 |
|
|
PROCESS(wr_en, rd_en, fullness)
|
| 278 |
|
|
BEGIN
|
| 279 |
|
|
IF (wr_en = '1') THEN
|
| 280 |
|
|
fullness_d <= fullness + 1;
|
| 281 |
|
|
ELSIF (rd_en = '1') THEN
|
| 282 |
|
|
fullness_d <= fullness - 1;
|
| 283 |
|
|
ELSE
|
| 284 |
|
|
fullness_d <= fullness;
|
| 285 |
|
|
END IF;
|
| 286 |
|
|
END PROCESS;
|
| 287 |
|
|
|
| 288 |
|
|
fullness_e <= rd_en XOR wr_en;
|
| 289 |
|
|
|
| 290 |
|
|
|
| 291 |
|
|
---===============================---
|
| 292 |
|
|
--== Data Output Handshake Logic ==--
|
| 293 |
|
|
---===============================---
|
| 294 |
|
|
|
| 295 |
|
|
empty_i_d <= rd_empty AND (empty_i OR NOT(dat_nread));
|
| 296 |
|
|
|
| 297 |
|
|
|
| 298 |
|
|
---===================================---
|
| 299 |
|
|
--== FIFO (Virtual) Fullness Counter ==--
|
| 300 |
|
|
---===================================---
|
| 301 |
|
|
|
| 302 |
|
|
PROCESS(vfullness, fct_en, rd_en, fullness_d)
|
| 303 |
|
|
VARIABLE tmp : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
| 304 |
|
|
BEGIN
|
| 305 |
|
|
tmp := fct_en & rd_en;
|
| 306 |
|
|
CASE tmp IS
|
| 307 |
|
|
WHEN "00" => vfullness_d <= fullness_d;
|
| 308 |
|
|
WHEN "01" => vfullness_d <= vfullness - 1;
|
| 309 |
|
|
WHEN "10" => vfullness_d <= vfullness + 8;
|
| 310 |
|
|
WHEN "11" => vfullness_d <= vfullness + 7;
|
| 311 |
|
|
WHEN OTHERS => NULL;
|
| 312 |
|
|
END CASE;
|
| 313 |
|
|
END PROCESS;
|
| 314 |
|
|
|
| 315 |
|
|
vfullness_e <= (fct_en OR rd_en) WHEN (state = st_connecting) OR (state = st_run) ELSE '1';
|
| 316 |
|
|
|
| 317 |
|
|
|
| 318 |
|
|
---===================---
|
| 319 |
|
|
--== FCT Read Enable ==--
|
| 320 |
|
|
---===================---
|
| 321 |
|
|
|
| 322 |
|
|
fct_en <= NOT(fct_nread) AND NOT(fct_empty_i);
|
| 323 |
|
|
|
| 324 |
|
|
|
| 325 |
|
|
---==========================---
|
| 326 |
|
|
--== Receive Credit Counter ==--
|
| 327 |
|
|
---==========================---
|
| 328 |
|
|
|
| 329 |
|
|
wr_en_ext <= '1' WHEN ((dat_nwrite = '0') AND (wr_full = '0')) ELSE '0';
|
| 330 |
|
|
|
| 331 |
|
|
PROCESS(credit, fct_en, wr_en_ext)
|
| 332 |
|
|
VARIABLE tmp : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
| 333 |
|
|
BEGIN
|
| 334 |
|
|
tmp := fct_en & wr_en_ext;
|
| 335 |
|
|
CASE tmp IS
|
| 336 |
|
|
WHEN "11" => credit_d <= credit + 7;
|
| 337 |
|
|
WHEN "10" => credit_d <= credit + 8;
|
| 338 |
|
|
WHEN OTHERS => credit_d <= credit - 1;
|
| 339 |
|
|
END CASE;
|
| 340 |
|
|
END PROCESS;
|
| 341 |
|
|
|
| 342 |
|
|
credit_e <= fct_en OR wr_en_ext;
|
| 343 |
|
|
|
| 344 |
|
|
---=======================---
|
| 345 |
|
|
--== FCT Handshake Logic ==--
|
| 346 |
|
|
---=======================---
|
| 347 |
|
|
|
| 348 |
|
|
PROCESS(fct_empty_i, fct_nread, credit, vfullness)
|
| 349 |
|
|
BEGIN
|
| 350 |
|
|
CASE fct_empty_i IS
|
| 351 |
|
|
WHEN '0' => IF (fct_nread = '0') THEN
|
| 352 |
|
|
fct_empty_i_d <= '1';
|
| 353 |
|
|
ELSE
|
| 354 |
|
|
fct_empty_i_d <= '0';
|
| 355 |
|
|
END IF;
|
| 356 |
|
|
WHEN '1' => IF (credit <= 48) AND (vfullness <= 1014) THEN
|
| 357 |
|
|
fct_empty_i_d <= '0';
|
| 358 |
|
|
ELSE
|
| 359 |
|
|
fct_empty_i_d <= '1';
|
| 360 |
|
|
END IF;
|
| 361 |
|
|
WHEN OTHERS => NULL;
|
| 362 |
|
|
END CASE;
|
| 363 |
|
|
END PROCESS;
|
| 364 |
|
|
|
| 365 |
|
|
|
| 366 |
|
|
---=================---
|
| 367 |
|
|
--== Dual Port RAM ==--
|
| 368 |
|
|
---=================---
|
| 369 |
|
|
|
| 370 |
|
|
dp_ram0 : dp_ram
|
| 371 |
|
|
GENERIC MAP
|
| 372 |
|
|
( datawidth => datawidth )
|
| 373 |
|
|
PORT MAP
|
| 374 |
|
|
(--== General Interface ==--
|
| 375 |
|
|
rst => rst,
|
| 376 |
|
|
clk => clk,
|
| 377 |
|
|
--== Write Interface ==--
|
| 378 |
|
|
wr_en => wr_en,
|
| 379 |
|
|
wr_addr => wr_addr,
|
| 380 |
|
|
wr_din => wr_din,
|
| 381 |
|
|
--== Read Interface ==--
|
| 382 |
|
|
rd_en => rd_en,
|
| 383 |
|
|
rd_addr => rd_addr,
|
| 384 |
|
|
rd_dout => dat_dout
|
| 385 |
|
|
);
|
| 386 |
|
|
|
| 387 |
|
|
|
| 388 |
|
|
---======================================---
|
| 389 |
|
|
--== Shared Internal & External Signals ==--
|
| 390 |
|
|
---======================================---
|
| 391 |
|
|
|
| 392 |
|
|
fct_empty <= fct_empty_i;
|
| 393 |
|
|
dat_empty <= empty_i;
|
| 394 |
|
|
dat_full <= wr_full;
|
| 395 |
|
|
END rtl;
|