OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [rtl/] [bplib/] [fx2lib/] [tb/] [fx2_2fifo_core.vhd] - Blame information for rev 26

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.