1 |
11 |
ashwin_men |
library ieee;
|
2 |
|
|
use ieee.std_logic_1164.all;
|
3 |
|
|
use ieee.std_logic_arith.all;
|
4 |
|
|
use ieee.std_logic_unsigned.all;
|
5 |
|
|
|
6 |
|
|
-------------------------------------------------------------------------------
|
7 |
|
|
-- ENTITY: npi
|
8 |
|
|
-- AUTHOR: Andy Schmidt
|
9 |
|
|
-- DATE: 12/20/2008
|
10 |
|
|
-- Version: 2.0
|
11 |
|
|
-- PURPOSE: Native Port Interface (NPI) to Multi-Ported Memory Control (MPMC)
|
12 |
|
|
-- Provides Read / Write functionality to Off-Chip Memory (typically)
|
13 |
|
|
-- DDR2 is the target, but any memory using a MPMC wrapper around
|
14 |
|
|
-- the memory interface (say SDRAM_MEMORY_CONTROLLER) should work.
|
15 |
|
|
--
|
16 |
|
|
-- This assumes a memory interface of 64 Bits (Double Words).
|
17 |
|
|
--
|
18 |
|
|
-- Requests can be issued for upto 4 GB of memory per a single
|
19 |
|
|
-- Sequential Request. Read and Write requests can be made in
|
20 |
|
|
-- parallel. Read Requests have a higher priority as they take
|
21 |
|
|
-- longer to return and are typically more time sensitive.
|
22 |
|
|
--
|
23 |
|
|
-- The HW Core implementing this interface is assumed to have a
|
24 |
|
|
-- FIFO-like interface with Read and Write Enables along with
|
25 |
|
|
-- Read Valid signals. This is to simplify the design and allow
|
26 |
|
|
-- crossing between the common HW Core's 100 MHz boundry to the MPMC
|
27 |
|
|
-- 200 MHz Boundry.
|
28 |
|
|
--
|
29 |
|
|
-- * This new verion allows for overlapping read and write requests
|
30 |
|
|
-- to provide higher bandwidth
|
31 |
|
|
--
|
32 |
|
|
-- Future Work: Add Stride Support and Byte Addressing Support
|
33 |
|
|
-- Add Read Request Burst Improvement for the last burst
|
34 |
|
|
-- currently a 15 Double Work Request is broken down to
|
35 |
|
|
-- a burst of 8, 4, 2, 1 (worst case) when it should be
|
36 |
|
|
-- a burst of 16 ignoring the 16th word (much faster).
|
37 |
|
|
-- Add Write FIFO Flush Support
|
38 |
|
|
-- Add Read FIFO Flush Support
|
39 |
|
|
-- Add Coherency Support with RdModRwr
|
40 |
|
|
--
|
41 |
|
|
-- PORTS:
|
42 |
|
|
-- npi_ila_control - ChipScope Integrated Logic Analyzer Control
|
43 |
|
|
-- MPMC_Clk - MPMC Clock Source (current designs are 200 Mhz)
|
44 |
|
|
-- NPI_Reset - Reset Signal for SW Resets from HW Core
|
45 |
|
|
-- core_rfd - Core is Reay for Data (OK to issue Rd Req)
|
46 |
|
|
-- data_to_mem - Data from HW Core to be written to Memory
|
47 |
|
|
-- data_to_mem_we - Write Enable asserted when data_to_mem is valid
|
48 |
|
|
-- data_to_mem_re - Read Enable asserted by NPI when ready for data
|
49 |
|
|
-- data_to_core - Data from Memory to HW Core (Read Request)
|
50 |
|
|
-- data_to_core_we - Write Enable asserted when data_to_core is valid
|
51 |
|
|
-- num_rd_bytes - Number of Sequential Bytes Requested by HW Core
|
52 |
|
|
-- num_wr_bytes - Number of Sequential Bytes Requested by HW Core
|
53 |
|
|
-- init_rd_addr - Initial Read Address from HW Core to Memory
|
54 |
|
|
-- init_wr_addr - Initial Write Address from HW Core to Memory
|
55 |
|
|
-- rd_req_start - HW Core Asserts to Start Read Request
|
56 |
|
|
-- rd_req_done - NPI Asserts when Read Request is Complete
|
57 |
|
|
-- wr_req_start - HW Core Asserts to Start Write Request
|
58 |
|
|
-- wr_req_done - NPI Asserts when Write Request is Complete
|
59 |
|
|
-- NPI_* - Input/Output Signals on the NPI Bus to MPMC
|
60 |
|
|
-- There are a variety of these signals which
|
61 |
|
|
-- are pretty obvious with the documentation, I am
|
62 |
|
|
-- just describing my NPI interface signals above
|
63 |
|
|
-------------------------------------------------------------------------------
|
64 |
|
|
entity npi is
|
65 |
|
|
generic (
|
66 |
|
|
CHIPSCOPE : boolean := false;
|
67 |
|
|
END_SWAP : boolean := true
|
68 |
|
|
);
|
69 |
|
|
port
|
70 |
|
|
(
|
71 |
|
|
npi_ila_control : in std_logic_vector(35 downto 0);
|
72 |
|
|
MPMC_Clk : in std_logic;
|
73 |
|
|
NPI_Reset : in std_logic;
|
74 |
|
|
core_rfd : in std_logic;
|
75 |
|
|
data_to_mem : in std_logic_vector(0 to 63);
|
76 |
|
|
data_to_mem_we : in std_logic;
|
77 |
|
|
data_to_mem_re : out std_logic;
|
78 |
|
|
data_to_core : out std_logic_vector(0 to 63);
|
79 |
|
|
data_to_core_we : out std_logic;
|
80 |
|
|
num_rd_bytes : in std_logic_vector(0 to 31);
|
81 |
|
|
num_wr_bytes : in std_logic_vector(0 to 31);
|
82 |
|
|
init_rd_addr : in std_logic_vector(0 to 31);
|
83 |
|
|
init_wr_addr : in std_logic_vector(0 to 31);
|
84 |
|
|
rd_req_start : in std_logic;
|
85 |
|
|
rd_req_done : out std_logic;
|
86 |
|
|
wr_req_start : in std_logic;
|
87 |
|
|
wr_req_done : out std_logic;
|
88 |
|
|
NPI_AddrAck : in std_logic;
|
89 |
|
|
NPI_WrFIFO_AlmostFull : in std_logic;
|
90 |
|
|
NPI_RdFIFO_Empty : in std_logic;
|
91 |
|
|
NPI_InitDone : in std_logic;
|
92 |
|
|
NPI_WrFIFO_Empty : in std_logic;
|
93 |
|
|
NPI_RdFIFO_Latency : in std_logic_vector(1 downto 0);
|
94 |
|
|
NPI_RdFIFO_RdWdAddr : in std_logic_vector(3 downto 0);
|
95 |
|
|
NPI_RdFIFO_Data : in std_logic_vector(63 downto 0);
|
96 |
|
|
NPI_AddrReq : out std_logic;
|
97 |
|
|
NPI_RNW : out std_logic;
|
98 |
|
|
NPI_WrFIFO_Push : out std_logic;
|
99 |
|
|
NPI_RdFIFO_Pop : out std_logic;
|
100 |
|
|
NPI_RdModWr : out std_logic;
|
101 |
|
|
NPI_WrFIFO_Flush : out std_logic;
|
102 |
|
|
NPI_RdFIFO_Flush : out std_logic;
|
103 |
|
|
NPI_Size : out std_logic_vector(3 downto 0);
|
104 |
|
|
NPI_WrFIFO_BE : out std_logic_vector(7 downto 0);
|
105 |
|
|
NPI_Addr : out std_logic_vector(31 downto 0);
|
106 |
|
|
NPI_WrFIFO_Data : out std_logic_vector(63 downto 0)
|
107 |
|
|
);
|
108 |
|
|
end entity npi;
|
109 |
|
|
|
110 |
|
|
-------------------------------------------------------------------------------
|
111 |
|
|
-- ARCHITECTURE
|
112 |
|
|
-------------------------------------------------------------------------------
|
113 |
|
|
architecture IMP of npi is
|
114 |
|
|
-----------------------------------------------------------------------------
|
115 |
|
|
-- CONSTANTS
|
116 |
|
|
-----------------------------------------------------------------------------
|
117 |
|
|
constant BYTES_PER_READ : integer := 8;
|
118 |
|
|
constant BYTES_PER_WRITE : integer := 8;
|
119 |
|
|
|
120 |
|
|
-----------------------------------------------------------------------------
|
121 |
|
|
-- Internal NPI Output Signals
|
122 |
|
|
-----------------------------------------------------------------------------
|
123 |
|
|
signal my_NPI_RdFIFO_Flush : std_logic;
|
124 |
|
|
signal my_NPI_RdFIFO_Flush_next : std_logic;
|
125 |
|
|
signal my_NPI_AddrReq : std_logic := '0';
|
126 |
|
|
signal my_NPI_AddrReq_next : std_logic := '0';
|
127 |
|
|
signal wr_fifo_push : std_logic := '0';
|
128 |
|
|
signal my_NPI_RdFIFO_Pop : std_logic := '0';
|
129 |
|
|
signal my_NPI_RNW : std_logic := '0';
|
130 |
|
|
signal my_NPI_RNW_next : std_logic := '0';
|
131 |
|
|
signal req_type : std_logic := '0';
|
132 |
|
|
signal req_type_next : std_logic := '0';
|
133 |
|
|
signal data_to_mem_re_next : std_logic := '0';
|
134 |
|
|
signal data_to_mem_re_out : std_logic := '0';
|
135 |
|
|
signal xfer_size : std_logic_vector(2 downto 0) := (others => '0');
|
136 |
|
|
signal xfer_size_next : std_logic_vector(2 downto 0) := (others => '0');
|
137 |
|
|
signal wr_fifo_be : std_logic_vector(7 downto 0) := (others => '0');
|
138 |
|
|
signal my_NPI_Addr : std_logic_vector(31 downto 0) := (others => '0');
|
139 |
|
|
signal my_NPI_Addr_next : std_logic_vector(31 downto 0) := (others => '0');
|
140 |
|
|
signal wr_fifo_data : std_logic_vector(63 downto 0) := (others => '0');
|
141 |
|
|
|
142 |
|
|
-----------------------------------------------------------------------------
|
143 |
|
|
-- NPI Output Finite State Machine
|
144 |
|
|
-----------------------------------------------------------------------------
|
145 |
|
|
type NPI_FSM_TYPE is (idle, wait_for_addr_ack);
|
146 |
|
|
signal npi_fsm_cs, npi_fsm_ns : NPI_FSM_TYPE := idle;
|
147 |
|
|
|
148 |
|
|
-----------------------------------------------------------------------------
|
149 |
|
|
-- Data from Memory Write Enable Signals and Finite State Machine
|
150 |
|
|
-----------------------------------------------------------------------------
|
151 |
|
|
signal data_from_mem_we : std_logic;
|
152 |
|
|
signal data_from_mem_we_next : std_logic;
|
153 |
|
|
signal data_from_mem : std_logic_vector(0 to 63) ;
|
154 |
|
|
-- WE FSM
|
155 |
|
|
type WE_FSM_TYPE is ( idle, wait_one, we_high, last_pop );
|
156 |
|
|
signal we_fsm_cs, we_fsm_ns : WE_FSM_TYPE := idle;
|
157 |
|
|
|
158 |
|
|
-----------------------------------------------------------------------------
|
159 |
|
|
-- Read Request Signals and FSM
|
160 |
|
|
-----------------------------------------------------------------------------
|
161 |
|
|
signal rd_xfer_size : std_logic_vector(2 downto 0) := (others => '0');
|
162 |
|
|
signal rd_burst_size : std_logic_vector(0 to 7) := (others => '0');
|
163 |
|
|
signal actual_rd_bytes : std_logic_vector(0 to 31) := (others => '0');
|
164 |
|
|
signal rd_bytes_issued : std_logic_vector(0 to 31) := (others => '0');
|
165 |
|
|
signal rd_bytes_issued_next : std_logic_vector(0 to 31) := (others => '0');
|
166 |
|
|
signal num_rd_bytes_left : std_logic_vector(0 to 31) := (others => '0');
|
167 |
|
|
signal rd_addr : std_logic_vector(0 to 31) := (others => '0');
|
168 |
|
|
signal rd_addr_next : std_logic_vector(0 to 31) := (others => '0');
|
169 |
|
|
signal rd_req_done_out : std_logic := '0';
|
170 |
|
|
signal rd_req_done_next : std_logic := '0';
|
171 |
|
|
-- Read Request FSM
|
172 |
|
|
type RD_FSM_TYPE is (idle, issue_req, wait_for_addr_ack, check_req_complete,
|
173 |
|
|
wait_for_xfers, req_complete );
|
174 |
|
|
signal rd_fsm_cs, rd_fsm_ns : RD_FSM_TYPE := idle;
|
175 |
|
|
signal rd_fsm_value : std_logic_vector(0 to 3);
|
176 |
|
|
|
177 |
|
|
-----------------------------------------------------------------------------
|
178 |
|
|
-- Write Request Signals and FSM
|
179 |
|
|
-----------------------------------------------------------------------------
|
180 |
|
|
signal wr_xfer_size : std_logic_vector(2 downto 0) := (others => '0');
|
181 |
|
|
signal wr_counter : std_logic_vector(0 to 7) := (others => '0');
|
182 |
|
|
signal wr_counter_next : std_logic_vector(0 to 7) := (others => '0');
|
183 |
|
|
signal wr_burst_size : std_logic_vector(0 to 7) := (others => '0');
|
184 |
|
|
signal wr_bytes_issued : std_logic_vector(0 to 31) := (others => '0');
|
185 |
|
|
signal wr_bytes_issued_next : std_logic_vector(0 to 31) := (others => '0');
|
186 |
|
|
signal num_wr_bytes_left : std_logic_vector(0 to 31) := (others => '0');
|
187 |
|
|
signal wr_addr : std_logic_vector(0 to 31) := (others => '0');
|
188 |
|
|
signal wr_addr_next : std_logic_vector(0 to 31) := (others => '0');
|
189 |
|
|
signal wr_req_done_out : std_logic := '0';
|
190 |
|
|
signal wr_req_done_next : std_logic := '0';
|
191 |
|
|
signal wr_burst_counter_minus_two : std_logic_vector(0 to 7);
|
192 |
|
|
signal wr_burst_counter_minus_two_next : std_logic_vector(0 to 7);
|
193 |
|
|
|
194 |
|
|
signal num_rd_bytes_minus_one : std_logic_vector(0 to 31) := (others => '0');
|
195 |
|
|
signal num_rd_bytes_minus_one_next : std_logic_vector(0 to 31) := (others => '0');
|
196 |
|
|
-- Read Request FSM
|
197 |
|
|
type WR_FSM_TYPE is (idle, issue_req, write_one, check_valid, fill_wr_fifo,
|
198 |
|
|
fill_wr_fifo_last, fill_wr_fifo_last_stall,
|
199 |
|
|
wait_for_addr_ack, check_req_complete, req_complete );
|
200 |
|
|
signal wr_fsm_cs, wr_fsm_ns : WR_FSM_TYPE := idle;
|
201 |
|
|
signal wr_fsm_value : std_logic_vector(0 to 3);
|
202 |
|
|
|
203 |
|
|
-----------------------------------------------------------------------------
|
204 |
|
|
-- ChipScope ILA
|
205 |
|
|
-----------------------------------------------------------------------------
|
206 |
|
|
component npi_ila
|
207 |
|
|
port (
|
208 |
|
|
control : in std_logic_vector(35 downto 0);
|
209 |
|
|
clk : in std_logic;
|
210 |
|
|
trig0 : in std_logic_vector(63 downto 0);
|
211 |
|
|
trig1 : in std_logic_vector(63 downto 0);
|
212 |
|
|
trig2 : in std_logic_vector(31 downto 0);
|
213 |
|
|
trig3 : in std_logic_vector(31 downto 0);
|
214 |
|
|
trig4 : in std_logic_vector(7 downto 0);
|
215 |
|
|
trig5 : in std_logic_vector(7 downto 0);
|
216 |
|
|
trig6 : in std_logic_vector(3 downto 0);
|
217 |
|
|
trig7 : in std_logic_vector(3 downto 0);
|
218 |
|
|
trig8 : in std_logic_vector(1 downto 0);
|
219 |
|
|
trig9 : in std_logic_vector(31 downto 0));
|
220 |
|
|
end component;
|
221 |
|
|
|
222 |
|
|
-------------------------------------------------------------------------------
|
223 |
|
|
-- BEGIN
|
224 |
|
|
-------------------------------------------------------------------------------
|
225 |
|
|
begin
|
226 |
|
|
-----------------------------------------------------------------------------
|
227 |
|
|
-- Assert Pop signal when Read FIFO is not empty
|
228 |
|
|
-----------------------------------------------------------------------------
|
229 |
|
|
my_NPI_RdFIFO_Pop <= not(NPI_RdFIFO_Empty);
|
230 |
|
|
|
231 |
|
|
-- AGS: TODO - Only Assert Push when in either the fill_wr_fifo or
|
232 |
|
|
-- wait_for_addr_ack states
|
233 |
|
|
wr_fifo_push <= data_to_mem_we;
|
234 |
|
|
|
235 |
|
|
-- Register Write Counter to Maintain 200 MHz Operation
|
236 |
|
|
wr_burst_counter_minus_two_next <= wr_burst_size - (BYTES_PER_WRITE*2);
|
237 |
|
|
num_rd_bytes_minus_one_next <= num_rd_bytes - BYTES_PER_READ;
|
238 |
|
|
|
239 |
|
|
ENDIAN_SWAP: if (END_SWAP) generate
|
240 |
|
|
---------------------------------------------------------------------------
|
241 |
|
|
-- Process: INPUT_ENDIAN_SWAP_PROC
|
242 |
|
|
-- Purpose: MPMC uses Little Endian and PPC (we) use Big Endian
|
243 |
|
|
---------------------------------------------------------------------------
|
244 |
|
|
INPUT_ENDIAN_SWAP_PROC : process ( NPI_RdFIFO_Data ) is
|
245 |
|
|
begin
|
246 |
|
|
data_from_mem(0 to 7) <= NPI_RdFIFO_Data(7 downto 0);
|
247 |
|
|
data_from_mem(8 to 15) <= NPI_RdFIFO_Data(15 downto 8);
|
248 |
|
|
data_from_mem(16 to 23) <= NPI_RdFIFO_Data(23 downto 16);
|
249 |
|
|
data_from_mem(24 to 31) <= NPI_RdFIFO_Data(31 downto 24);
|
250 |
|
|
data_from_mem(32 to 39) <= NPI_RdFIFO_Data(39 downto 32);
|
251 |
|
|
data_from_mem(40 to 47) <= NPI_RdFIFO_Data(47 downto 40);
|
252 |
|
|
data_from_mem(48 to 55) <= NPI_RdFIFO_Data(55 downto 48);
|
253 |
|
|
data_from_mem(56 to 63) <= NPI_RdFIFO_Data(63 downto 56);
|
254 |
|
|
end process INPUT_ENDIAN_SWAP_PROC;
|
255 |
|
|
|
256 |
|
|
---------------------------------------------------------------------------
|
257 |
|
|
-- Process: OUTPUT_ENDIAN_SWAP_PROC
|
258 |
|
|
-- Purpose: MPMC uses Little Endian and PPC (we) use Big Endian
|
259 |
|
|
---------------------------------------------------------------------------
|
260 |
|
|
OUTPUT_ENDIAN_SWAP_PROC : process ( data_to_mem ) is
|
261 |
|
|
begin
|
262 |
|
|
wr_fifo_data(7 downto 0) <= data_to_mem(0 to 7);
|
263 |
|
|
wr_fifo_data(15 downto 8) <= data_to_mem(8 to 15);
|
264 |
|
|
wr_fifo_data(23 downto 16) <= data_to_mem(16 to 23);
|
265 |
|
|
wr_fifo_data(31 downto 24) <= data_to_mem(24 to 31);
|
266 |
|
|
wr_fifo_data(39 downto 32) <= data_to_mem(32 to 39);
|
267 |
|
|
wr_fifo_data(47 downto 40) <= data_to_mem(40 to 47);
|
268 |
|
|
wr_fifo_data(55 downto 48) <= data_to_mem(48 to 55);
|
269 |
|
|
wr_fifo_data(63 downto 56) <= data_to_mem(56 to 63);
|
270 |
|
|
end process OUTPUT_ENDIAN_SWAP_PROC;
|
271 |
|
|
end generate ENDIAN_SWAP;
|
272 |
|
|
|
273 |
|
|
NO_ENDIAN_SWAP: if not(END_SWAP) generate
|
274 |
|
|
data_from_mem <= NPI_RdFIFO_Data;
|
275 |
|
|
wr_fifo_data <= data_to_mem;
|
276 |
|
|
end generate NO_ENDIAN_SWAP;
|
277 |
|
|
|
278 |
|
|
-----------------------------------------------------------------------------
|
279 |
|
|
-- Process: NUM_BYTES_LEFT_PROC
|
280 |
|
|
-- Purpose: Count Number of Remaining Read / Write Bytes to be Completed
|
281 |
|
|
-----------------------------------------------------------------------------
|
282 |
|
|
NUM_BYTES_LEFT_PROC : process ( MPMC_Clk )
|
283 |
|
|
begin
|
284 |
|
|
if ((MPMC_Clk'event) and (MPMC_Clk = '1')) then
|
285 |
|
|
-- Num Read Transfers Left
|
286 |
|
|
if (NPI_Reset = '1') then
|
287 |
|
|
num_rd_bytes_left <= (others => '0');
|
288 |
|
|
elsif (rd_fsm_cs = idle) then
|
289 |
|
|
num_rd_bytes_left <= num_rd_bytes;
|
290 |
|
|
elsif ((rd_fsm_cs = wait_for_addr_ack) and (NPI_AddrAck = '1') and
|
291 |
|
|
(req_type = '1')) then
|
292 |
|
|
num_rd_bytes_left <= num_rd_bytes_left - rd_burst_size;
|
293 |
|
|
end if;
|
294 |
|
|
-- Num Write Transfers Left
|
295 |
|
|
if (NPI_Reset = '1') then
|
296 |
|
|
num_wr_bytes_left <= (others => '0');
|
297 |
|
|
elsif (wr_fsm_cs = idle) then
|
298 |
|
|
num_wr_bytes_left <= num_wr_bytes;
|
299 |
|
|
elsif ((wr_fsm_cs = wait_for_addr_ack) and (NPI_AddrAck = '1') and
|
300 |
|
|
(req_type = '0')) then
|
301 |
|
|
num_wr_bytes_left <= num_wr_bytes_left - wr_burst_size;
|
302 |
|
|
end if;
|
303 |
|
|
end if;
|
304 |
|
|
end process NUM_BYTES_LEFT_PROC;
|
305 |
|
|
|
306 |
|
|
-----------------------------------------------------------------------
|
307 |
|
|
-- Process: SET_BURST_AND_XFER_SIZE_PROC
|
308 |
|
|
-- Purpose: Based on the Number of Bytes left in the transaction
|
309 |
|
|
-- set the xfer_size and burst_size
|
310 |
|
|
-- xfer_size: NPI Specific 4 bit vector to designate xfer
|
311 |
|
|
-- "000" = 1 Double Word
|
312 |
|
|
-- "001" = 2 Double Word
|
313 |
|
|
-- "010" = 4 Double Word
|
314 |
|
|
-- "011" = 8 Double Word
|
315 |
|
|
-- "100" = 16 Double Word
|
316 |
|
|
-- "101" = 32 Double Word (Only With SLR)
|
317 |
|
|
-- burst_size: The Number of Bytes in the Burst
|
318 |
|
|
-- A burst of 16 = 16 Double Words = 128 Bytes
|
319 |
|
|
-- A burst of 8 = 8 Double Words = 64 Bytes
|
320 |
|
|
-- Round up for more efficient transfers
|
321 |
|
|
-----------------------------------------------------------------------
|
322 |
|
|
SET_BURST_AND_XFER_SIZE_PROC : process (MPMC_CLk) is
|
323 |
|
|
begin
|
324 |
|
|
if ((MPMC_Clk'event) and (MPMC_Clk = '1')) then
|
325 |
|
|
if (NPI_Reset = '1') then
|
326 |
|
|
rd_xfer_size <= (others => '0');
|
327 |
|
|
rd_burst_size <= (others => '0');
|
328 |
|
|
wr_xfer_size <= (others => '0');
|
329 |
|
|
wr_burst_size <= (others => '0');
|
330 |
|
|
else
|
331 |
|
|
-- Read Burst and Xfer Size
|
332 |
|
|
if (num_rd_bytes_left >= 65) then
|
333 |
|
|
rd_xfer_size <= "100";
|
334 |
|
|
rd_burst_size <= x"80";
|
335 |
|
|
elsif (num_rd_bytes_left >= 33) then
|
336 |
|
|
rd_xfer_size <= "011";
|
337 |
|
|
rd_burst_size <= x"40";
|
338 |
|
|
elsif (num_rd_bytes_left >= 17) then
|
339 |
|
|
rd_xfer_size <= "010";
|
340 |
|
|
rd_burst_size <= x"20";
|
341 |
|
|
elsif (num_rd_bytes_left >= 9) then
|
342 |
|
|
rd_xfer_size <= "001";
|
343 |
|
|
rd_burst_size <= x"10";
|
344 |
|
|
else
|
345 |
|
|
rd_xfer_size <= "000";
|
346 |
|
|
rd_burst_size <= x"08";
|
347 |
|
|
end if;
|
348 |
|
|
-- Write Burst and Xfer Size
|
349 |
|
|
if (num_wr_bytes_left >= 128) then
|
350 |
|
|
wr_xfer_size <= "100";
|
351 |
|
|
wr_burst_size <= x"80";
|
352 |
|
|
elsif (num_wr_bytes_left >= 64) then
|
353 |
|
|
wr_xfer_size <= "011";
|
354 |
|
|
wr_burst_size <= x"40";
|
355 |
|
|
elsif (num_wr_bytes_left >= 32) then
|
356 |
|
|
wr_xfer_size <= "010";
|
357 |
|
|
wr_burst_size <= x"20";
|
358 |
|
|
elsif (num_wr_bytes_left >=16) then
|
359 |
|
|
wr_xfer_size <= "001";
|
360 |
|
|
wr_burst_size <= x"10";
|
361 |
|
|
else
|
362 |
|
|
wr_xfer_size <= "000";
|
363 |
|
|
wr_burst_size <= x"08";
|
364 |
|
|
end if;
|
365 |
|
|
end if;
|
366 |
|
|
end if;
|
367 |
|
|
end process SET_BURST_AND_XFER_SIZE_PROC;
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
-----------------------------------------------------------------------------
|
371 |
|
|
-- Process: SET_WR_FIFO_BE_PROC
|
372 |
|
|
-- Purpose: Set the Write FIFO Byte Enable Signal based on the number
|
373 |
|
|
-- of remaining bytes to be written to Memory
|
374 |
|
|
-----------------------------------------------------------------------------
|
375 |
|
|
SET_WR_FIFO_BE_PROC : process (MPMC_CLk) is
|
376 |
|
|
begin
|
377 |
|
|
if ((MPMC_Clk'event) and (MPMC_Clk = '1')) then
|
378 |
|
|
if (NPI_Reset = '1') then
|
379 |
|
|
wr_fifo_be <= (others => '0');
|
380 |
|
|
elsif (num_wr_bytes_left >= 8) then
|
381 |
|
|
wr_fifo_be <= x"FF";
|
382 |
|
|
elsif (num_wr_bytes_left = 7) then
|
383 |
|
|
wr_fifo_be <= x"7F";
|
384 |
|
|
elsif (num_wr_bytes_left = 6) then
|
385 |
|
|
wr_fifo_be <= x"3F";
|
386 |
|
|
elsif (num_wr_bytes_left = 5) then
|
387 |
|
|
wr_fifo_be <= x"1F";
|
388 |
|
|
elsif (num_wr_bytes_left = 4) then
|
389 |
|
|
wr_fifo_be <= x"0F";
|
390 |
|
|
elsif (num_wr_bytes_left = 3) then
|
391 |
|
|
wr_fifo_be <= x"07";
|
392 |
|
|
elsif (num_wr_bytes_left = 2) then
|
393 |
|
|
wr_fifo_be <= x"03";
|
394 |
|
|
elsif (num_wr_bytes_left = 1) then
|
395 |
|
|
wr_fifo_be <= x"01";
|
396 |
|
|
else
|
397 |
|
|
wr_fifo_be <= (others => '0');
|
398 |
|
|
end if;
|
399 |
|
|
end if;
|
400 |
|
|
end process SET_WR_FIFO_BE_PROC;
|
401 |
|
|
|
402 |
|
|
-----------------------------------------------------------------------
|
403 |
|
|
-- Process: ACTUAL_BYTES_COUNTER_PROC
|
404 |
|
|
-- Purpose: Count Actual Number of Bytes Read from MPMC
|
405 |
|
|
-----------------------------------------------------------------------
|
406 |
|
|
ACTUAL_BYTES_COUNTER_PROC : process( MPMC_Clk ) is
|
407 |
|
|
begin
|
408 |
|
|
if ((MPMC_Clk'event) and (MPMC_Clk='1')) then
|
409 |
|
|
if ((NPI_Reset = '1') or (rd_fsm_cs = idle)) then
|
410 |
|
|
actual_rd_bytes <= (others => '0');
|
411 |
|
|
elsif (data_from_mem_we = '1') then
|
412 |
|
|
actual_rd_bytes <= actual_rd_bytes + BYTES_PER_READ;
|
413 |
|
|
end if;
|
414 |
|
|
end if;
|
415 |
|
|
end process ACTUAL_BYTES_COUNTER_PROC;
|
416 |
|
|
|
417 |
|
|
-----------------------------------------------------------------------
|
418 |
|
|
-- Process: REGISTERED_200_MHZ_PROC
|
419 |
|
|
-- Purpose: Register Signals at 200 MHz MPMC Clock
|
420 |
|
|
-----------------------------------------------------------------------
|
421 |
|
|
REGISTERED_200_MHZ_PROC: process ( MPMC_Clk ) is
|
422 |
|
|
begin
|
423 |
|
|
if ( (MPMC_Clk'event) and (MPMC_Clk = '1') ) then
|
424 |
|
|
if (NPI_Reset = '1') then
|
425 |
|
|
npi_fsm_cs <= idle;
|
426 |
|
|
we_fsm_cs <= idle;
|
427 |
|
|
wr_fsm_cs <= idle;
|
428 |
|
|
my_NPI_Addr <= (others => '0');
|
429 |
|
|
my_NPI_AddrReq <= '0';
|
430 |
|
|
my_NPI_RNW <= '0';
|
431 |
|
|
xfer_size <= (others => '0');
|
432 |
|
|
req_type <= '0';
|
433 |
|
|
wr_req_done_out <= '0';
|
434 |
|
|
data_to_mem_re_out <= '0';
|
435 |
|
|
data_from_mem_we <= '0';
|
436 |
|
|
rd_fsm_cs <= idle;
|
437 |
|
|
rd_bytes_issued <= (others => '0');
|
438 |
|
|
rd_addr <= (others => '0');
|
439 |
|
|
rd_req_done_out <= '0';
|
440 |
|
|
my_NPI_RdFIFO_Flush <= '0';
|
441 |
|
|
wr_addr <= (others => '0');
|
442 |
|
|
wr_bytes_issued <= (others => '0');
|
443 |
|
|
wr_counter <= (others => '0');
|
444 |
|
|
wr_burst_counter_minus_two <= (others => '0');
|
445 |
|
|
num_rd_bytes_minus_one <= (others => '0');
|
446 |
|
|
else
|
447 |
|
|
npi_fsm_cs <= npi_fsm_ns;
|
448 |
|
|
we_fsm_cs <= we_fsm_ns;
|
449 |
|
|
wr_fsm_cs <= wr_fsm_ns;
|
450 |
|
|
my_NPI_Addr <= my_NPI_Addr_next;
|
451 |
|
|
my_NPI_RNW <= my_NPI_RNW_next;
|
452 |
|
|
xfer_size <= xfer_size_next;
|
453 |
|
|
req_type <= req_type_next;
|
454 |
|
|
wr_req_done_out <= wr_req_done_next;
|
455 |
|
|
data_to_mem_re_out <= data_to_mem_re_next;
|
456 |
|
|
data_from_mem_we <= data_from_mem_we_next;
|
457 |
|
|
rd_fsm_cs <= rd_fsm_ns;
|
458 |
|
|
rd_bytes_issued <= rd_bytes_issued_next;
|
459 |
|
|
rd_req_done_out <= rd_req_done_next;
|
460 |
|
|
rd_addr <= rd_addr_next;
|
461 |
|
|
my_NPI_RdFIFO_Flush <= my_NPI_RdFIFO_Flush_next;
|
462 |
|
|
wr_addr <= wr_addr_next;
|
463 |
|
|
wr_bytes_issued <= wr_bytes_issued_next;
|
464 |
|
|
wr_counter <= wr_counter_next;
|
465 |
|
|
wr_burst_counter_minus_two <= wr_burst_counter_minus_two_next;
|
466 |
|
|
num_rd_bytes_minus_one <= num_rd_bytes_minus_one_next;
|
467 |
|
|
if ( NPI_AddrAck = '1' ) then
|
468 |
|
|
my_NPI_AddrReq <= '0';
|
469 |
|
|
else
|
470 |
|
|
my_NPI_AddrReq <= my_NPI_AddrReq_next;
|
471 |
|
|
end if;
|
472 |
|
|
end if;
|
473 |
|
|
end if;
|
474 |
|
|
end process REGISTERED_200_MHZ_PROC;
|
475 |
|
|
|
476 |
|
|
-----------------------------------------------------------------------------
|
477 |
|
|
-- Process: DATA_FROM_MEM_WE_LOGIC_PROC
|
478 |
|
|
-- Purpose: During Read Requests this Process will Assert WE signal
|
479 |
|
|
-- when data is valid in data_out register
|
480 |
|
|
-----------------------------------------------------------------------------
|
481 |
|
|
DATA_FROM_MEM_WE_LOGIC_PROC : process ( we_fsm_cs, my_NPI_RdFIFO_Pop,
|
482 |
|
|
data_from_mem_we, actual_rd_bytes,
|
483 |
|
|
num_rd_bytes_minus_one ) is
|
484 |
|
|
begin
|
485 |
|
|
data_from_mem_we_next <= data_from_mem_we;
|
486 |
|
|
we_fsm_ns <= we_fsm_cs;
|
487 |
|
|
|
488 |
|
|
case (we_fsm_cs) is
|
489 |
|
|
-------------------------------------------------------------------------
|
490 |
|
|
-- IDLE State: 0 - Sit in Idle State Until Pop is asserted
|
491 |
|
|
-------------------------------------------------------------------------
|
492 |
|
|
when idle =>
|
493 |
|
|
data_from_mem_we_next <= '0';
|
494 |
|
|
if ( my_NPI_RdFIFO_Pop = '1' ) then
|
495 |
|
|
we_fsm_ns <= wait_one;
|
496 |
|
|
end if;
|
497 |
|
|
|
498 |
|
|
-------------------------------------------------------------------------
|
499 |
|
|
-- WAIT ONE State: 1 - Wait 1 Clock Cycle
|
500 |
|
|
-------------------------------------------------------------------------
|
501 |
|
|
when wait_one =>
|
502 |
|
|
data_from_mem_we_next <= '1';
|
503 |
|
|
if ( my_NPI_RdFIFO_Pop = '0' ) then
|
504 |
|
|
we_fsm_ns <= last_pop;
|
505 |
|
|
else
|
506 |
|
|
we_fsm_ns <= we_high;
|
507 |
|
|
end if;
|
508 |
|
|
|
509 |
|
|
-------------------------------------------------------------------------
|
510 |
|
|
-- WE HIGH State: 2 - Assert WE signal
|
511 |
|
|
-------------------------------------------------------------------------
|
512 |
|
|
when we_high =>
|
513 |
|
|
if (actual_rd_bytes >= num_rd_bytes_minus_one) then
|
514 |
|
|
data_from_mem_we_next <= '0';
|
515 |
|
|
we_fsm_ns <= idle;
|
516 |
|
|
elsif ( my_NPI_RdFIFO_Pop = '0' ) then
|
517 |
|
|
data_from_mem_we_next <= '1';
|
518 |
|
|
we_fsm_ns <= last_pop;
|
519 |
|
|
else
|
520 |
|
|
data_from_mem_we_next <= '1';
|
521 |
|
|
we_fsm_ns <= we_high;
|
522 |
|
|
end if;
|
523 |
|
|
|
524 |
|
|
-------------------------------------------------------------------------
|
525 |
|
|
-- LAST POP State: 3 - Keep WE high for 1 last clock cycle
|
526 |
|
|
-- before returning to Idle
|
527 |
|
|
-- If doing back to back transfers only wait 1 clock cycle for 1st
|
528 |
|
|
-- data on second transfer
|
529 |
|
|
-------------------------------------------------------------------------
|
530 |
|
|
when last_pop =>
|
531 |
|
|
if ( my_NPI_RdFIFO_Pop = '1' ) then
|
532 |
|
|
data_from_mem_we_next <= '0';
|
533 |
|
|
we_fsm_ns <= wait_one;
|
534 |
|
|
else
|
535 |
|
|
data_from_mem_we_next <= '0';
|
536 |
|
|
we_fsm_ns <= idle;
|
537 |
|
|
end if;
|
538 |
|
|
|
539 |
|
|
when others => we_fsm_ns <= idle;
|
540 |
|
|
end case;
|
541 |
|
|
end process DATA_FROM_MEM_WE_LOGIC_PROC;
|
542 |
|
|
|
543 |
|
|
-----------------------------------------------------------------------------
|
544 |
|
|
-- PROCESS: NPI_FSM_LOGIC_PROC
|
545 |
|
|
-- PURPOSE: Logic Process to issue Read or Write Request because the NPI
|
546 |
|
|
-- while it is possible to queue Requests, there can only be
|
547 |
|
|
-- one single NPI Read or Write Request issued at a time
|
548 |
|
|
-----------------------------------------------------------------------------
|
549 |
|
|
NPI_FSM_LOGIC_PROC : process (npi_fsm_cs, req_type, my_NPI_Addr, xfer_size,
|
550 |
|
|
my_NPI_RNW, my_NPI_AddrReq, rd_fsm_cs,
|
551 |
|
|
wr_fsm_cs, rd_addr, rd_xfer_size, wr_addr,
|
552 |
|
|
wr_xfer_size, NPI_AddrAck
|
553 |
|
|
) is
|
554 |
|
|
begin
|
555 |
|
|
my_NPI_Addr_next <= my_NPI_Addr;
|
556 |
|
|
my_NPI_RNW_next <= my_NPI_RNW;
|
557 |
|
|
my_NPI_AddrReq_next <= my_NPI_AddrReq;
|
558 |
|
|
xfer_size_next <= xfer_size;
|
559 |
|
|
req_type_next <= req_type;
|
560 |
|
|
npi_fsm_ns <= npi_fsm_cs;
|
561 |
|
|
case (npi_fsm_cs) is
|
562 |
|
|
-------------------------------------------------------------------------
|
563 |
|
|
-- Idle State: 0 - Wait for Read or Write Request
|
564 |
|
|
-------------------------------------------------------------------------
|
565 |
|
|
when idle =>
|
566 |
|
|
-- Read Requests have a Higher Priority in this Scheme
|
567 |
|
|
if (rd_fsm_cs = wait_for_addr_ack) then
|
568 |
|
|
my_NPI_Addr_next <= rd_addr;
|
569 |
|
|
my_NPI_RNW_next <= '1';
|
570 |
|
|
my_NPI_AddrReq_next <= '1';
|
571 |
|
|
req_type_next <= '1';
|
572 |
|
|
xfer_size_next <= rd_xfer_size;
|
573 |
|
|
npi_fsm_ns <= wait_for_addr_ack;
|
574 |
|
|
elsif (wr_fsm_cs = wait_for_addr_ack) then
|
575 |
|
|
my_NPI_Addr_next <= wr_addr;
|
576 |
|
|
my_NPI_RNW_next <= '0';
|
577 |
|
|
my_NPI_AddrReq_next <= '1';
|
578 |
|
|
req_type_next <= '0';
|
579 |
|
|
xfer_size_next <= wr_xfer_size;
|
580 |
|
|
npi_fsm_ns <= wait_for_addr_ack;
|
581 |
|
|
else
|
582 |
|
|
my_NPI_Addr_next <= (others => '0');
|
583 |
|
|
my_NPI_RNW_next <= '0';
|
584 |
|
|
my_NPI_AddrReq_next <= '0';
|
585 |
|
|
req_type_next <= '0';
|
586 |
|
|
xfer_size_next <= (others => '0');
|
587 |
|
|
npi_fsm_ns <= idle;
|
588 |
|
|
end if;
|
589 |
|
|
|
590 |
|
|
-------------------------------------------------------------------------
|
591 |
|
|
-- Wait For Addr Ack State: 1 - Wait For NPI_AddrACK
|
592 |
|
|
-------------------------------------------------------------------------
|
593 |
|
|
when wait_for_addr_ack =>
|
594 |
|
|
if (NPI_AddrAck = '1') then
|
595 |
|
|
my_NPI_Addr_next <= (others => '0');
|
596 |
|
|
my_NPI_RNW_next <= '0';
|
597 |
|
|
my_NPI_AddrReq_next <= '0';
|
598 |
|
|
npi_fsm_ns <= idle;
|
599 |
|
|
end if;
|
600 |
|
|
when others => npi_fsm_ns <= idle;
|
601 |
|
|
end case;
|
602 |
|
|
end process NPI_FSM_LOGIC_PROC;
|
603 |
|
|
|
604 |
|
|
-----------------------------------------------------------------------
|
605 |
|
|
-- Process: WR_FSM_VALUE_PROC
|
606 |
|
|
-- Purpose: Read FSM State Indicator for ChipScope
|
607 |
|
|
-----------------------------------------------------------------------
|
608 |
|
|
WR_FSM_VALUE_PROC: process (wr_fsm_cs) is
|
609 |
|
|
begin
|
610 |
|
|
case (wr_fsm_cs) is
|
611 |
|
|
when idle => wr_fsm_value <= x"0";
|
612 |
|
|
when issue_req => wr_fsm_value <= x"1";
|
613 |
|
|
when write_one => wr_fsm_value <= x"2";
|
614 |
|
|
when check_valid => wr_fsm_value <= x"3";
|
615 |
|
|
when fill_wr_fifo => wr_fsm_value <= x"4";
|
616 |
|
|
when fill_wr_fifo_last => wr_fsm_value <= x"5";
|
617 |
|
|
when fill_wr_fifo_last_stall => wr_fsm_value <= x"6";
|
618 |
|
|
when wait_for_addr_ack => wr_fsm_value <= x"7";
|
619 |
|
|
when check_req_complete => wr_fsm_value <= x"8";
|
620 |
|
|
when req_complete => wr_fsm_value <= x"9";
|
621 |
|
|
when others => wr_fsm_value <= x"A";
|
622 |
|
|
end case;
|
623 |
|
|
end process WR_FSM_VALUE_PROC;
|
624 |
|
|
|
625 |
|
|
-----------------------------------------------------------------------
|
626 |
|
|
-- Process: WR_FSM_LOGIC_PROC
|
627 |
|
|
-- Purpose: Write Request Logic Process to perform functionality
|
628 |
|
|
-----------------------------------------------------------------------
|
629 |
|
|
WR_FSM_LOGIC_PROC : process( MPMC_Clk, wr_fsm_cs, wr_req_done_out,
|
630 |
|
|
wr_bytes_issued, wr_addr, num_wr_bytes_left,
|
631 |
|
|
wr_req_start, wr_burst_size, req_type,
|
632 |
|
|
init_wr_addr, num_wr_bytes, NPI_AddrAck,
|
633 |
|
|
data_to_mem_we, wr_counter,
|
634 |
|
|
NPI_WrFIFO_AlmostFull, data_to_mem_re_out,
|
635 |
|
|
wr_burst_counter_minus_two,
|
636 |
|
|
NPI_WrFIFO_Empty
|
637 |
|
|
) is
|
638 |
|
|
begin
|
639 |
|
|
wr_bytes_issued_next <= wr_bytes_issued;
|
640 |
|
|
wr_addr_next <= wr_addr;
|
641 |
|
|
wr_req_done_next <= wr_req_done_out;
|
642 |
|
|
wr_counter_next <= wr_counter;
|
643 |
|
|
data_to_mem_re_next <= data_to_mem_re_out;
|
644 |
|
|
wr_fsm_ns <= wr_fsm_cs;
|
645 |
|
|
|
646 |
|
|
case wr_fsm_cs is
|
647 |
|
|
-------------------------------------------------------------------------
|
648 |
|
|
-- Idle State: 0 - Wait for Read Request
|
649 |
|
|
-------------------------------------------------------------------------
|
650 |
|
|
when idle =>
|
651 |
|
|
if (wr_req_start = '1') then
|
652 |
|
|
wr_addr_next <= init_wr_addr;
|
653 |
|
|
wr_fsm_ns <= issue_req;
|
654 |
|
|
else
|
655 |
|
|
wr_bytes_issued_next <= (others => '0');
|
656 |
|
|
wr_addr_next <= (others => '0');
|
657 |
|
|
wr_counter_next <= (others => '0');
|
658 |
|
|
wr_req_done_next <= '0';
|
659 |
|
|
data_to_mem_re_next <= '0';
|
660 |
|
|
wr_fsm_ns <= idle;
|
661 |
|
|
end if;
|
662 |
|
|
|
663 |
|
|
-------------------------------------------------------------------------
|
664 |
|
|
-- Issue Request State: 1 - Start Write Request (wait on AddrReq FSM)
|
665 |
|
|
-------------------------------------------------------------------------
|
666 |
|
|
when issue_req =>
|
667 |
|
|
data_to_mem_re_next <= '1';
|
668 |
|
|
wr_counter_next <= (others => '0');
|
669 |
|
|
-- AGS: Added WrFIFO_Empty to see if BE aligns with FIFO
|
670 |
|
|
-- AGS: This causes an error because if it < F but the fifo is not
|
671 |
|
|
-- empty it will think it needs to write more than 1 word of data
|
672 |
|
|
--if ((NPI_WrFIFO_Empty = '1') and (num_wr_bytes_left <= x"0000000F")) then
|
673 |
|
|
if (num_wr_bytes_left <= x"0000000F") then
|
674 |
|
|
wr_fsm_ns <= write_one;
|
675 |
|
|
else
|
676 |
|
|
wr_fsm_ns <= fill_wr_fifo;
|
677 |
|
|
end if;
|
678 |
|
|
|
679 |
|
|
-------------------------------------------------------------------------
|
680 |
|
|
-- Write One State: 2 - Write a single Double Word - Check Valid because
|
681 |
|
|
-- The WE is asserted 1 Clock Cycle after RE Assert
|
682 |
|
|
-------------------------------------------------------------------------
|
683 |
|
|
when write_one =>
|
684 |
|
|
data_to_mem_re_next <= '0';
|
685 |
|
|
if (data_to_mem_we = '1') then
|
686 |
|
|
wr_fsm_ns <= wait_for_addr_ack;
|
687 |
|
|
else
|
688 |
|
|
wr_fsm_ns <= check_valid;
|
689 |
|
|
end if;
|
690 |
|
|
|
691 |
|
|
-------------------------------------------------------------------------
|
692 |
|
|
-- Check Valid State: 3 - Check if the Asserted RE triggered a WE
|
693 |
|
|
-------------------------------------------------------------------------
|
694 |
|
|
when check_valid =>
|
695 |
|
|
if (data_to_mem_we = '1') then
|
696 |
|
|
wr_fsm_ns <= wait_for_addr_ack;
|
697 |
|
|
else
|
698 |
|
|
data_to_mem_re_next <= '1';
|
699 |
|
|
wr_fsm_ns <= write_one;
|
700 |
|
|
end if;
|
701 |
|
|
|
702 |
|
|
-------------------------------------------------------------------------
|
703 |
|
|
-- Fill_Wr_FIFO State: 4 - Write data into Write FIFO
|
704 |
|
|
-------------------------------------------------------------------------
|
705 |
|
|
when fill_wr_fifo =>
|
706 |
|
|
if ((data_to_mem_we = '1') and (wr_counter >= wr_burst_counter_minus_two)) then
|
707 |
|
|
-- De-Assert RE and wait for last data
|
708 |
|
|
data_to_mem_re_next <= '0';
|
709 |
|
|
wr_counter_next <= wr_counter + BYTES_PER_WRITE;
|
710 |
|
|
wr_fsm_ns <= fill_wr_fifo_last;
|
711 |
|
|
elsif ((data_to_mem_we = '1') and (wr_counter < wr_burst_size)) then
|
712 |
|
|
data_to_mem_re_next <= '1';
|
713 |
|
|
wr_counter_next <= wr_counter + BYTES_PER_WRITE;
|
714 |
|
|
wr_fsm_ns <= fill_wr_fifo;
|
715 |
|
|
end if;
|
716 |
|
|
|
717 |
|
|
-- Verify this works! AGS
|
718 |
|
|
when fill_wr_fifo_last =>
|
719 |
|
|
if (data_to_mem_we = '1') then
|
720 |
|
|
data_to_mem_re_next <= '0';
|
721 |
|
|
wr_counter_next <= wr_counter + BYTES_PER_WRITE;
|
722 |
|
|
wr_fsm_ns <= wait_for_addr_ack;
|
723 |
|
|
else
|
724 |
|
|
-- Try Reading again
|
725 |
|
|
data_to_mem_re_next <= '1';
|
726 |
|
|
wr_fsm_ns <= fill_wr_fifo_last_stall;
|
727 |
|
|
end if;
|
728 |
|
|
|
729 |
|
|
when fill_wr_fifo_last_stall =>
|
730 |
|
|
data_to_mem_re_next <= '0';
|
731 |
|
|
if (data_to_mem_we = '1') then
|
732 |
|
|
wr_counter_next <= wr_counter + BYTES_PER_WRITE;
|
733 |
|
|
wr_fsm_ns <= wait_for_addr_ack;
|
734 |
|
|
else
|
735 |
|
|
wr_fsm_ns <= fill_wr_fifo_last;
|
736 |
|
|
end if;
|
737 |
|
|
|
738 |
|
|
-------------------------------------------------------------------------
|
739 |
|
|
-- Wait_For_Addr_Ack State: 7 - Wait for Addr ACK from MPMC
|
740 |
|
|
-------------------------------------------------------------------------
|
741 |
|
|
when wait_for_addr_ack =>
|
742 |
|
|
if ((NPI_AddrAck = '1') and (req_type = '0')) then
|
743 |
|
|
wr_addr_next <= wr_addr + wr_burst_size;
|
744 |
|
|
wr_bytes_issued_next <= wr_bytes_issued + wr_burst_size;
|
745 |
|
|
wr_fsm_ns <= check_req_complete;
|
746 |
|
|
end if;
|
747 |
|
|
|
748 |
|
|
-------------------------------------------------------------------------
|
749 |
|
|
-- Check_Req_Complete State: 8 - Check if all Write Requests Issued
|
750 |
|
|
-------------------------------------------------------------------------
|
751 |
|
|
when check_req_complete =>
|
752 |
|
|
if (wr_bytes_issued >= num_wr_bytes) then
|
753 |
|
|
wr_req_done_next <= '1';
|
754 |
|
|
wr_fsm_ns <= req_complete;
|
755 |
|
|
else
|
756 |
|
|
wr_fsm_ns <= issue_req;
|
757 |
|
|
end if;
|
758 |
|
|
|
759 |
|
|
-------------------------------------------------------------------------
|
760 |
|
|
-- Req_Complete State: 9 - Wait for HW Core to de-assert Start Signal
|
761 |
|
|
-------------------------------------------------------------------------
|
762 |
|
|
when req_complete =>
|
763 |
|
|
if (wr_req_start = '0') then
|
764 |
|
|
wr_req_done_next <= '0';
|
765 |
|
|
wr_fsm_ns <= idle;
|
766 |
|
|
end if;
|
767 |
|
|
|
768 |
|
|
when others => wr_fsm_ns <= idle;
|
769 |
|
|
end case;
|
770 |
|
|
end process WR_FSM_LOGIC_PROC;
|
771 |
|
|
|
772 |
|
|
-----------------------------------------------------------------------
|
773 |
|
|
-- Process: RD_FSM_VALUE_PROC
|
774 |
|
|
-- Purpose: Read FSM State Indicator for ChipScope
|
775 |
|
|
-----------------------------------------------------------------------
|
776 |
|
|
RD_FSM_VALUE_PROC: process (rd_fsm_cs) is
|
777 |
|
|
begin
|
778 |
|
|
case (rd_fsm_cs) is
|
779 |
|
|
when idle => rd_fsm_value <= x"0";
|
780 |
|
|
when issue_req => rd_fsm_value <= x"1";
|
781 |
|
|
when wait_for_addr_ack => rd_fsm_value <= x"2";
|
782 |
|
|
when check_req_complete => rd_fsm_value <= x"3";
|
783 |
|
|
when wait_for_xfers => rd_fsm_value <= x"4";
|
784 |
|
|
when req_complete => rd_fsm_value <= x"5";
|
785 |
|
|
when others => rd_fsm_value <= x"6";
|
786 |
|
|
end case;
|
787 |
|
|
end process RD_FSM_VALUE_PROC;
|
788 |
|
|
|
789 |
|
|
-----------------------------------------------------------------------
|
790 |
|
|
-- Process: RD_FSM_LOGIC_PROC
|
791 |
|
|
-- Purpose: Read Request Logic Process to perform functionality
|
792 |
|
|
-----------------------------------------------------------------------
|
793 |
|
|
RD_FSM_LOGIC_PROC : process( MPMC_Clk, rd_fsm_cs, rd_req_done_out,
|
794 |
|
|
rd_bytes_issued, num_rd_bytes, rd_addr,
|
795 |
|
|
rd_req_start, rd_burst_size, req_type,
|
796 |
|
|
init_rd_addr, NPI_RdFIFO_Empty,
|
797 |
|
|
NPI_AddrAck, actual_rd_bytes, core_rfd,
|
798 |
|
|
my_NPI_RdFIFO_Flush
|
799 |
|
|
) is
|
800 |
|
|
begin
|
801 |
|
|
rd_bytes_issued_next <= rd_bytes_issued;
|
802 |
|
|
rd_addr_next <= rd_addr;
|
803 |
|
|
rd_req_done_next <= rd_req_done_out;
|
804 |
|
|
my_NPI_RdFIFO_Flush_next <= my_NPI_RdFIFO_Flush;
|
805 |
|
|
rd_fsm_ns <= rd_fsm_cs;
|
806 |
|
|
|
807 |
|
|
case rd_fsm_cs is
|
808 |
|
|
-------------------------------------------------------------------------
|
809 |
|
|
-- Idle State: 0 - Wait for Read Request
|
810 |
|
|
-------------------------------------------------------------------------
|
811 |
|
|
when idle =>
|
812 |
|
|
rd_bytes_issued_next <= (others => '0');
|
813 |
|
|
rd_addr_next <= (others => '0');
|
814 |
|
|
rd_req_done_next <= '0';
|
815 |
|
|
my_NPI_RdFIFO_Flush_next <= '0';
|
816 |
|
|
if (rd_req_start = '1') then
|
817 |
|
|
rd_addr_next <= init_rd_addr;
|
818 |
|
|
rd_fsm_ns <= wait_for_addr_ack;
|
819 |
|
|
end if;
|
820 |
|
|
|
821 |
|
|
-------------------------------------------------------------------------
|
822 |
|
|
-- Issue Request State: 1 - Start Read Request (wait on AddrReq FSM)
|
823 |
|
|
-------------------------------------------------------------------------
|
824 |
|
|
when issue_req =>
|
825 |
|
|
if ((NPI_RdFIFO_Empty = '1') and (core_rfd = '1')) then
|
826 |
|
|
rd_fsm_ns <= wait_for_addr_ack;
|
827 |
|
|
end if;
|
828 |
|
|
|
829 |
|
|
-------------------------------------------------------------------------
|
830 |
|
|
-- Wait_For_Addr_Ack State: 2 - Wait for Addr ACK from MPMC
|
831 |
|
|
-------------------------------------------------------------------------
|
832 |
|
|
when wait_for_addr_ack =>
|
833 |
|
|
if ((NPI_AddrAck = '1') and (req_type = '1')) then
|
834 |
|
|
rd_addr_next <= rd_addr + rd_burst_size;
|
835 |
|
|
rd_bytes_issued_next <= rd_bytes_issued + rd_burst_size;
|
836 |
|
|
rd_fsm_ns <= check_req_complete;
|
837 |
|
|
end if;
|
838 |
|
|
|
839 |
|
|
-------------------------------------------------------------------------
|
840 |
|
|
-- Check_Req_Complete State: 3 - Check if all read Requests issued
|
841 |
|
|
-------------------------------------------------------------------------
|
842 |
|
|
when check_req_complete =>
|
843 |
|
|
if ( rd_bytes_issued >= num_rd_bytes ) then
|
844 |
|
|
rd_fsm_ns <= wait_for_xfers;
|
845 |
|
|
else
|
846 |
|
|
rd_fsm_ns <= issue_req;
|
847 |
|
|
end if;
|
848 |
|
|
|
849 |
|
|
-------------------------------------------------------------------------
|
850 |
|
|
-- Wait_For_Xfers State: 4 - Stay in this state until all data has been
|
851 |
|
|
-- Read from Memory and written to HW Core
|
852 |
|
|
-- TODO: Maybe I don't want to stay here and instead return to Idle
|
853 |
|
|
-- to allow another Transfer to occur in Parallel with the Return?
|
854 |
|
|
-------------------------------------------------------------------------
|
855 |
|
|
when wait_for_xfers =>
|
856 |
|
|
if (actual_rd_bytes >= num_rd_bytes) then
|
857 |
|
|
my_NPI_RdFIFO_Flush_next <= '1';
|
858 |
|
|
rd_req_done_next <= '1';
|
859 |
|
|
rd_fsm_ns <= req_complete;
|
860 |
|
|
end if;
|
861 |
|
|
|
862 |
|
|
-------------------------------------------------------------------------
|
863 |
|
|
-- Req_Complete State: 5 - Wait for HW Core to de-assert Start Signal
|
864 |
|
|
-- TODO: I would also Remove this state if I ditch State 4
|
865 |
|
|
-------------------------------------------------------------------------
|
866 |
|
|
when req_complete =>
|
867 |
|
|
if (rd_req_start = '0') then
|
868 |
|
|
my_NPI_RdFIFO_Flush_next <= '0';
|
869 |
|
|
rd_req_done_next <= '0';
|
870 |
|
|
rd_fsm_ns <= idle;
|
871 |
|
|
end if;
|
872 |
|
|
|
873 |
|
|
when others => rd_fsm_ns <= idle;
|
874 |
|
|
end case;
|
875 |
|
|
end process RD_FSM_LOGIC_PROC;
|
876 |
|
|
|
877 |
|
|
-----------------------------------------------------------------------------
|
878 |
|
|
-- NPI Output Signals to MPMC
|
879 |
|
|
-----------------------------------------------------------------------------
|
880 |
|
|
NPI_Addr <= my_NPI_Addr;
|
881 |
|
|
NPI_AddrReq <= my_NPI_AddrReq;
|
882 |
|
|
NPI_RNW <= my_NPI_RNW;
|
883 |
|
|
NPI_Size <= ('0' & xfer_size); -- '0' is to eliminate a latch
|
884 |
|
|
NPI_RdFIFO_Pop <= my_NPI_RdFIFO_Pop;
|
885 |
|
|
NPI_WrFIFO_Data <= wr_fifo_data;
|
886 |
|
|
NPI_WrFIFO_Push <= wr_fifo_push;
|
887 |
|
|
NPI_WrFIFO_BE <= wr_fifo_be;
|
888 |
|
|
NPI_WrFIFO_Flush <= '0'; -- TODO: Add Write FIFO Flush Support
|
889 |
|
|
-- AGS: I might be 1 Clock Cycle Late on asserting RdFIFO_Flush
|
890 |
|
|
NPI_RdFIFO_Flush <= my_NPI_RdFIFO_Flush;
|
891 |
|
|
NPI_RdModWr <= '0'; -- TODO: Consider Coherency Support
|
892 |
|
|
|
893 |
|
|
-----------------------------------------------------------------------------
|
894 |
|
|
-- NPI Output to HW Core
|
895 |
|
|
-----------------------------------------------------------------------------
|
896 |
|
|
-- Output Data Read Enable to HW Core to Read Next Element from FIFO
|
897 |
|
|
data_to_mem_re <= data_to_mem_re_out;
|
898 |
|
|
|
899 |
|
|
-- Read Request Signals to Core
|
900 |
|
|
data_to_core <= data_from_mem;
|
901 |
|
|
data_to_core_we <= data_from_mem_we;
|
902 |
|
|
|
903 |
|
|
-- To signal Core Request has Finished
|
904 |
|
|
rd_req_done <= rd_req_done_out;
|
905 |
|
|
wr_req_done <= wr_req_done_out;
|
906 |
|
|
|
907 |
|
|
-----------------------------------------------------------------------------
|
908 |
|
|
-- ChipScope ILA
|
909 |
|
|
-----------------------------------------------------------------------------
|
910 |
|
|
CHIPSCOPE_ILA_GEN: if (CHIPSCOPE) generate
|
911 |
|
|
npi_ila_i : npi_ila
|
912 |
|
|
port map (
|
913 |
|
|
control => npi_ila_control,
|
914 |
|
|
clk => mpmc_clk,
|
915 |
|
|
trig0 => data_from_mem,
|
916 |
|
|
trig1 => data_to_mem,
|
917 |
|
|
trig2 => my_NPI_Addr,
|
918 |
|
|
trig3 => num_wr_bytes_left,
|
919 |
|
|
trig4 => wr_counter,
|
920 |
|
|
trig5 => wr_burst_size,
|
921 |
|
|
trig6 => rd_fsm_value,
|
922 |
|
|
trig7 => wr_fsm_value,
|
923 |
|
|
trig8 => NPI_RdFIFO_Latency,
|
924 |
|
|
trig9(0) => data_to_mem_we,
|
925 |
|
|
trig9(1) => rd_req_start,
|
926 |
|
|
trig9(2) => wr_req_start,
|
927 |
|
|
trig9(3) => NPI_AddrAck,
|
928 |
|
|
trig9(4) => NPI_WrFIFO_AlmostFull,
|
929 |
|
|
trig9(5) => NPI_RdFIFO_Empty,
|
930 |
|
|
trig9(6) => NPI_InitDone,
|
931 |
|
|
trig9(7) => NPI_WrFIFO_Empty,
|
932 |
|
|
trig9(8) => my_NPI_AddrReq,
|
933 |
|
|
trig9(9) => wr_fifo_push,
|
934 |
|
|
trig9(10) => my_NPI_RdFIFO_Pop,
|
935 |
|
|
trig9(11) => my_NPI_RNW,
|
936 |
|
|
trig9(12) => req_type,
|
937 |
|
|
trig9(13) => rd_req_done_out,
|
938 |
|
|
trig9(14) => wr_req_done_out,
|
939 |
|
|
trig9(15) => my_NPI_RdFIFO_Flush,
|
940 |
|
|
trig9(16) => data_from_mem_we,
|
941 |
|
|
trig9(17) => core_rfd,
|
942 |
|
|
trig9(18) => '0',
|
943 |
|
|
trig9(19) => '0',
|
944 |
|
|
trig9(20) => '0',
|
945 |
|
|
trig9(21) => '0',
|
946 |
|
|
trig9(22) => '0',
|
947 |
|
|
trig9(23) => '0',
|
948 |
|
|
trig9(24) => '0',
|
949 |
|
|
trig9(25) => '0',
|
950 |
|
|
trig9(26) => '0',
|
951 |
|
|
trig9(27) => '0',
|
952 |
|
|
trig9(28) => '0',
|
953 |
|
|
trig9(29) => '0',
|
954 |
|
|
trig9(30) => '0',
|
955 |
|
|
trig9(31) => '0'
|
956 |
|
|
);
|
957 |
|
|
end generate CHIPSCOPE_ILA_GEN;
|
958 |
|
|
|
959 |
|
|
end IMP;
|