w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
fx2_2fifo_core.vhd
Go to the documentation of this file.
1-- $Id: fx2_2fifo_core.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2013-2016 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: fx2_2fifo_core - sim
7-- Description: Cypress EZ-USB FX2 (2 fifo core model)
8--
9-- Dependencies: memlib/fifo_2c_dram
10-- Test bench: -
11-- Target Devices: generic
12-- Tool versions: xst 13.3-14.7; ghdl 0.29-0.33
13-- Revision History:
14-- Date Rev Version Comment
15-- 2016-09-02 805 1.0.1 proc_ifclk: remove clock stop (not needed anymore)
16-- 2013-01-04 469 1.0 Initial version
17------------------------------------------------------------------------------
18
19library ieee;
20use ieee.std_logic_1164.all;
21use ieee.numeric_std.all;
22use ieee.std_logic_textio.all;
23use std.textio.all;
24
25use work.slvtypes.all;
26use work.simbus.all;
27use work.fx2lib.all;
28use work.memlib.all;
29
30entity fx2_2fifo_core is -- EZ-USB FX2 (2 fifo core model)
31 port (
32 CLK : in slbit; -- uplink clock
33 RESET : in slbit; -- reset
34 RXDATA : in slv8; -- rx data (ext->fx2)
35 RXENA : in slbit; -- rx enable
36 RXBUSY : out slbit; -- rx busy
37 TXDATA : out slv8; -- tx data (fx2->ext)
38 TXVAL : out slbit; -- tx valid
39 IFCLK : out slbit; -- fx2 interface clock
40 FIFO : in slv2; -- fx2 fifo address
41 FLAG : out slv4; -- fx2 fifo flags
42 SLRD_N : in slbit; -- fx2 read enable (act.low)
43 SLWR_N : in slbit; -- fx2 write enable (act.low)
44 SLOE_N : in slbit; -- fx2 output enable (act.low)
45 PKTEND_N : in slbit; -- fx2 packet end (act.low)
46 DATA : inout slv8 -- fx2 data lines
47 );
49
50
51architecture sim of fx2_2fifo_core is
52
53 constant c_rxfifo : slv2 := c_fifo_ep4;
54 constant c_txfifo : slv2 := c_fifo_ep6;
55
56 constant c_flag_prog : integer := 0;
57 constant c_flag_tx_ff : integer := 1;
58 constant c_flag_rx_ef : integer := 2;
59 constant c_flag_tx2_ff : integer := 3;
60
61 constant bufsize : positive := 1024;
62 constant datzero : slv(DATA'range) := (others=>'0');
63 type buf_type is array (0 to bufsize-1) of slv(DATA'range);
64
65 signal CLK30 : slbit := '0';
66
67 signal RXFIFO_DO : slv8 := (others=>'0');
68 signal RXFIFO_VAL : slbit := '0';
69 signal RXFIFO_HOLD : slbit := '0';
70 signal TXFIFO_DI : slv8 := (others=>'0');
71 signal TXFIFO_ENA : slbit := '0';
72 signal TXFIFO_BUSY : slbit := '0';
73
74 signal R_FLAG : slv4 := (others=>'0');
75 signal R_DATA : slv8 := (others=>'0');
76
77 -- added for debug purposes
78 signal R_rxbuf_rind : natural := 0;
79 signal R_rxbuf_wind : natural := 0;
80 signal R_rxbuf_nbyt : natural := 0;
81 signal R_txbuf_rind : natural := 0;
82 signal R_txbuf_wind : natural := 0;
83 signal R_txbuf_nbyt : natural := 0;
84
85begin
86
87 RXFIFO : fifo_2c_dram
88 generic map (
89 AWIDTH => 5,
90 DWIDTH => 8)
91 port map (
92 CLKW => CLK,
93 CLKR => CLK30,
94 RESETW => '0',
95 RESETR => '0',
96 DI => RXDATA,
97 ENA => RXENA,
98 BUSY => RXBUSY,
99 DO => RXFIFO_DO,
100 VAL => RXFIFO_VAL,
101 HOLD => RXFIFO_HOLD,
102 SIZEW => open,
103 SIZER => open
104 );
105
106 TXFIFO : fifo_2c_dram
107 generic map (
108 AWIDTH => 5,
109 DWIDTH => 8)
110 port map (
111 CLKW => CLK30,
112 CLKR => CLK,
113 RESETW => '0',
114 RESETR => '0',
115 DI => TXFIFO_DI,
116 ENA => TXFIFO_ENA,
117 BUSY => TXFIFO_BUSY,
118 DO => TXDATA,
119 VAL => TXVAL,
120 HOLD => '0',
121 SIZEW => open,
122 SIZER => open
123 );
124
125 proc_ifclk: process
126 constant offset : Delay_length := 200 ns;
127 constant halfperiod_7: Delay_length := 16700 ps;
128 constant halfperiod_6: Delay_length := 16600 ps;
129 begin
130
131 CLK30 <= '0';
132 wait for offset;
133
134 loop
135 CLK30 <= '1';
136 wait for halfperiod_7;
137 CLK30 <= '0';
138 wait for halfperiod_7;
139 CLK30 <= '1';
140 wait for halfperiod_6;
141 CLK30 <= '0';
142 wait for halfperiod_7;
143 CLK30 <= '1';
144 wait for halfperiod_7;
145 CLK30 <= '0';
146 wait for halfperiod_6;
147 end loop;
148
149 end process proc_ifclk;
150
151 proc_state: process (CLK30)
152 variable rxbuf : buf_type := (others=>datzero);
153 variable rxbuf_rind : natural := 0;
154 variable rxbuf_wind : natural := 0;
155 variable rxbuf_nbyt : natural := 0;
156
157 variable txbuf : buf_type := (others=>datzero);
158 variable txbuf_rind : natural := 0;
159 variable txbuf_wind : natural := 0;
160 variable txbuf_nbyt : natural := 0;
161
162 variable oline : line;
163
164 begin
165
166 if rising_edge(CLK30) then
167
168 RXFIFO_HOLD <= '0';
169 TXFIFO_ENA <= '0';
170
171 -- rxfifo -> rxbuf
172 if RXFIFO_VAL = '1' then
173 if rxbuf_nbyt < bufsize then
174 rxbuf(rxbuf_wind) := RXFIFO_DO;
175 rxbuf_wind := (rxbuf_wind + 1) mod bufsize;
176 rxbuf_nbyt := rxbuf_nbyt + 1;
177 else
178 RXFIFO_HOLD <= '1';
179 end if;
180 end if;
181
182 -- txbuf -> txfifo
183 if txbuf_nbyt>0 and TXFIFO_BUSY='0' then
184 TXFIFO_DI <= txbuf(txbuf_rind);
185 TXFIFO_ENA <= '1';
186 txbuf_rind := (txbuf_rind + 1) mod bufsize;
187 txbuf_nbyt := txbuf_nbyt - 1;
188 end if;
189
190 -- slrd cycle: rxbuf -> data
191 if SLRD_N = '0' then
192 if rxbuf_nbyt > 0 then
193 rxbuf_rind := (rxbuf_rind + 1) mod bufsize;
194 rxbuf_nbyt := rxbuf_nbyt - 1;
195 else
196 write(oline, string'("fx2_2fifo_core: SLRD_N=0 when rxbuf empty"));
197 writeline(output, oline);
198 end if;
199 end if;
200 R_DATA <= rxbuf(rxbuf_rind);
201
202 -- slwr cycle: data -> txbuf
203 if SLWR_N = '0' then
204 if txbuf_nbyt < bufsize then
205 txbuf(txbuf_wind) := DATA;
206 txbuf_wind := (txbuf_wind + 1) mod bufsize;
207 txbuf_nbyt := txbuf_nbyt + 1;
208 else
209 write(oline, string'("fx2_2fifo_core: SLWR_N=0 when txbuf full"));
210 writeline(output, oline);
211 end if;
212 end if;
213
214 -- prepare flags (note that FLAGs are act.low!)
215 R_FLAG <= (others=>'1');
216 -- FLAGA = indexed, PF
217 -- rx endpoint -> PF 'almost empty' at 3 bytes to go
218 if FIFO = c_rxfifo then
219 if rxbuf_nbyt < 4 then
220 R_FLAG(0) <= '0';
221 end if;
222 -- tx endpoint -> PF 'almost full' at 3 bytes to go
223 elsif FIFO = c_txfifo then
224 if txbuf_nbyt > bufsize-4 then
225 R_FLAG(0) <= '0';
226 end if;
227 end if;
228
229 -- FLAGB = EP6 FF
230 if txbuf_nbyt = bufsize then
231 R_FLAG(1) <= '0';
232 end if;
233
234 -- FLAGC = EP4 EF
235 if rxbuf_nbyt = 0 then
236 R_FLAG(2) <= '0';
237 end if;
238
239 -- FLAGD = EP8 FF
240 R_FLAG(3) <= '1';
241
242 -- added for debug purposes
243 R_rxbuf_rind <= rxbuf_rind;
244 R_rxbuf_wind <= rxbuf_wind;
245 R_rxbuf_nbyt <= rxbuf_nbyt;
246 R_txbuf_rind <= txbuf_rind;
247 R_txbuf_wind <= txbuf_wind;
248 R_txbuf_nbyt <= txbuf_nbyt;
249
250 end if;
251
252 end process proc_state;
253
254 IFCLK <= CLK30;
255 FLAG <= R_FLAG;
256
257 proc_data: process (SLOE_N, R_DATA)
258 begin
259 if SLOE_N = '1' then
260 DATA <= (others=>'Z');
261 else
262 DATA <= R_DATA;
263 end if;
264 end process proc_data;
265
266end sim;
in ENA slbit
out DO slv( DWIDTH- 1 downto 0)
in DI slv( DWIDTH- 1 downto 0)
out BUSY slbit
in HOLD slbit
in CLKW slbit
AWIDTH positive := 5
in CLKR slbit
out SIZER slv( AWIDTH- 1 downto 0)
out VAL slbit
in RESETR slbit
out SIZEW slv( AWIDTH- 1 downto 0)
DWIDTH positive := 16
in RESETW slbit
natural := 0 R_txbuf_nbyt
natural := 0 R_txbuf_wind
slv8 :=( others => '0') TXFIFO_DI
slv2 := c_fifo_ep4 c_rxfifo
integer := 1 c_flag_tx_ff
natural := 0 R_rxbuf_rind
integer := 3 c_flag_tx2_ff
positive := 1024 bufsize
slbit := '0' TXFIFO_ENA
slbit := '0' RXFIFO_HOLD
slbit := '0' TXFIFO_BUSY
slv8 :=( others => '0') R_DATA
slbit := '0' RXFIFO_VAL
integer := 0 c_flag_prog
natural := 0 R_rxbuf_wind
slv(DATA) :=( others => '0') datzero
slbit := '0' CLK30
slv8 :=( others => '0') RXFIFO_DO
slv2 := c_fifo_ep6 c_txfifo
( 0 to bufsize- 1) slv(DATA) buf_type
integer := 2 c_flag_rx_ef
slv4 :=( others => '0') R_FLAG
natural := 0 R_rxbuf_nbyt
natural := 0 R_txbuf_rind
inout DATA slv8
in SLRD_N slbit
out RXBUSY slbit
out IFCLK slbit
out TXVAL slbit
out TXDATA slv8
in SLWR_N slbit
in SLOE_N slbit
in PKTEND_N slbit
std_logic_vector( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40
std_logic_vector( 1 downto 0) slv2
Definition: slvtypes.vhd:34
std_logic_vector slv
Definition: slvtypes.vhd:31