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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [lib/] [fasm/] [fasm_fifo.v] - Blame information for rev 195

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 195 sybreon
/* $Id: fasm_fifo.v,v 1.2 2008/06/05 21:07:13 sybreon Exp $
2
**
3
** FASM MEMORY LIBRARY
4
** Copyright (C) 2004-2008 Shawn Tan <shawn.tan@aeste.net>
5
** All rights reserved.
6
**
7
** FASM is free software: you can redistribute it and/or modify it
8
** under the terms of the GNU Lesser General Public License as
9
** published by the Free Software Foundation, either version 3 of the
10
** License, or (at your option) any later version.
11
**
12
** FASM is distributed in the hope that it will be useful, but WITHOUT
13
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
15
** Public License for more details.
16
**
17
** You should have received a copy of the GNU Lesser General Public
18
** License along with FASM. If not, see <http:**www.gnu.org/licenses/>.
19
*/
20
/*
21
 * SMALL INTERNAL BUFFER (FIFO)
22
 * Synthesis proven on:
23
 * - Xilinx ISE
24
 * - Altera Quartus (>=8.0)
25
 */
26
 
27
module fasm_fifo (/*AUTOARG*/
28
   // Outputs
29
   dat_o, rok_o, wok_o,
30
   // Inputs
31
   dat_i, rde_i, wre_i, clr_i, rst_i, ena_i, clk_i
32
   );
33
   parameter AW = 4; // fifo depth
34
   parameter DW = 32; // fifo width
35
 
36
   output [DW-1:0] dat_o;
37
   output          rok_o, // empty signal
38
                   wok_o; // full signal
39
 
40
   input [DW-1:0]  dat_i;
41
   input           rde_i,
42
                   wre_i;
43
 
44
   input           clr_i,
45
                   rst_i,
46
                   ena_i,
47
                   clk_i; // global clock
48
 
49
   /*AUTOREG*/
50
   // Beginning of automatic regs (for this module's undeclared outputs)
51
   reg                  rok_o;
52
   reg                  wok_o;
53
   // End of automatics
54
 
55
   reg [AW:1]   rRADR,
56
                        rWADR;
57
 
58
   wire                 wWRE = wre_i & wok_o;
59
   wire                 wRDE = rde_i & rok_o;
60
 
61
   //wire [AW:1]                wRNXT = {~^rRADR[2:1],rRADR[AW:2]};
62
   //wire [AW:1]                wWNXT = {~^rWADR[2:1],rWADR[AW:2]};
63
   wire [AW:1]          wRNXT = rRADR + 1;
64
   wire [AW:1]          wWNXT = rWADR + 1;
65
 
66
   always @(posedge clk_i)
67
     if (rst_i | clr_i) begin
68
        rok_o <= 1'b0;
69
        wok_o <= 1'b1;
70
        /*AUTORESET*/
71
        // Beginning of autoreset for uninitialized flops
72
        rRADR <= {(1+(AW)-(1)){1'b0}};
73
        rWADR <= {(1+(AW)-(1)){1'b0}};
74
        // End of automatics
75
     end else if (ena_i) begin
76
 
77
        if (wWRE) rWADR <= #1 wWNXT;
78
        if (wRDE) rRADR <= #1 wRNXT;
79
 
80
        if (wWRE ^ wRDE) begin
81
           if (wWRE) begin
82
              wok_o <= #1 (wWNXT != rRADR); // FIXME: use XOR      
83
              rok_o <= #1 1'b1;
84
           end else begin
85
              wok_o <= #1 1'b1;
86
              rok_o <= #1 (wRNXT != rWADR);
87
           end
88
        end
89
 
90
     end // if (ena_i)
91
 
92
   /* fasm_tparam AUTO_TEMPLATE
93
    (
94
    .AW(AW),
95
    .DW(DW),
96
 
97
    .clk_i(clk_i),
98
    .rst_i(),
99
    .stb_i(),
100
    .wre_i(),
101
    .dat_i(),
102
    .adr_i(rRADR),
103
    .dat_o(dat_o),
104
 
105
    .xclk_i(clk_i),
106
    .xrst_i(),
107
    .xstb_i(),
108
    .xwre_i(wWRE),
109
    .xadr_i(rWADR),
110
    .xdat_i(dat_i),
111
    .xdat_o(),
112
    ); */
113
 
114
   fasm_tparam
115
     #(/*AUTOINSTPARAM*/
116
       // Parameters
117
       .AW                              (AW),                    // Templated
118
       .DW                              (DW))                    // Templated
119
   fiforam0
120
     (/*AUTOINST*/
121
      // Outputs
122
      .dat_o                            (dat_o),                 // Templated
123
      .xdat_o                           (),                      // Templated
124
      // Inputs
125
      .dat_i                            (),                      // Templated
126
      .adr_i                            (rRADR),                 // Templated
127
      .wre_i                            (),                      // Templated
128
      .stb_i                            (),                      // Templated
129
      .rst_i                            (),                      // Templated
130
      .clk_i                            (clk_i),                 // Templated
131
      .xdat_i                           (dat_i),                 // Templated
132
      .xadr_i                           (rWADR),                 // Templated
133
      .xwre_i                           (wWRE),                  // Templated
134
      .xstb_i                           (),                      // Templated
135
      .xrst_i                           (),                      // Templated
136
      .xclk_i                           (clk_i));                // Templated
137
 
138
   // ### SIMULATION ONLY ###
139
   // synopsys translate_on
140
   initial begin
141
      // This depends on target technology. All regular FPGAs have a
142
      // 16x1 dual port asynchronous RAM block.
143
      if (AW > 4) $display("Warning: FIFO too large!");
144
      if (AW < 2) $display("Warning: FIFO too small!");
145
   end
146
   // synopsys translate_off
147
 
148
endmodule // fasm_fifo

powered by: WebSVN 2.1.0

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