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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [axi_cmn/] [fm_fifo.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_fifo.v
7
//
8
// Abstract:
9
//   FIFO with data clear
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 5 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2016, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
module fm_fifo (
43
  clk_core,
44
  rst_x,
45
  i_wstrobe,
46
  i_dt,
47
  o_full,
48
  i_renable,
49
  o_dt,
50
  o_empty,
51
  o_dnum
52
);
53
 
54
// set default parameters
55
parameter P_WIDTH = 32;
56
parameter P_RANGE = 2;
57
parameter P_DEPTH = 1 << P_RANGE;
58
parameter P_CLEAR = "FALSE";
59
 
60
////////////////////////////
61
// I/O definition
62
////////////////////////////
63
input         clk_core;            // system clock
64
input         rst_x;          // system reset
65
input         i_wstrobe;      // write strobe
66
input  [P_WIDTH-1:0] i_dt;      // write data
67
output        o_full;         // write data full
68
input         i_renable;      // read enable
69
output [P_WIDTH-1:0] o_dt;      // read data
70
output        o_empty;        // read data empty
71
output [P_RANGE:0] o_dnum;      // written data number
72
 
73
/////////////////////////
74
//  Register definition
75
/////////////////////////
76
reg [P_RANGE-1:0] rs_write_counter;
77
reg [P_RANGE-1:0] rs_read_counter;
78
// data registers
79
reg [P_WIDTH-1:0] rs_data_buffer[0:P_DEPTH-1];
80
reg [P_RANGE:0] rs_status;
81
/////////////////////////
82
//  wire definition
83
/////////////////////////
84
wire             o_full;
85
wire             o_empty;
86
wire [P_WIDTH-1:0] o_dt;
87
wire [1:0]       w_status;
88
wire             w_we;
89
wire             w_re;
90
/////////////////////////
91
//  assign statement
92
/////////////////////////
93
assign o_full  = (rs_status == P_DEPTH);
94
assign o_empty = (rs_status == 0);
95
assign o_dt = rs_data_buffer[rs_read_counter];
96
assign o_dnum = rs_status;
97
assign w_we = !o_full & i_wstrobe;
98
assign w_re = i_renable & !o_empty;
99
assign w_status = {w_re,w_we};
100
////////////////////////
101
// always statement
102
///////////////////////
103
  // write side
104
  always @(posedge clk_core or negedge rst_x) begin
105
    if (~rst_x) begin
106
      rs_write_counter <= 'd0;
107
    end else begin
108
      if (w_we) begin
109
        rs_write_counter <= rs_write_counter + 1'b1;
110
      end
111
    end
112
  end
113
 
114
generate
115
  if (P_CLEAR == "TRUE") begin
116
    integer i;
117
    always @(posedge clk_core or negedge rst_x) begin
118
      if (~rst_x) begin
119
        for(i=0;i<P_DEPTH;i=i+1) rs_data_buffer[i] <= 'd0;
120
      end else begin
121
        if (w_we) begin
122
          rs_data_buffer[rs_write_counter] <= i_dt;
123
        end
124
      end
125
    end
126
  end else begin
127
    always @(posedge clk_core) begin
128
      if (w_we) begin
129
        rs_data_buffer[rs_write_counter] <= i_dt;
130
      end
131
    end
132
  end
133
endgenerate
134
 
135
  // read side
136
  always @(posedge clk_core or negedge rst_x) begin
137
    if (~rst_x) begin
138
      rs_read_counter <= 'd0;
139
    end else begin
140
      if (w_re) begin
141
        rs_read_counter <= rs_read_counter + 1'b1;
142
      end
143
    end
144
  end
145
  // status counter
146
  always @(posedge clk_core or negedge rst_x) begin
147
    if (~rst_x) begin
148
      rs_status <= 'd0;
149
    end else begin
150
      case (w_status)
151
        2'b01:  rs_status <= rs_status + 1'b1; // write
152
        2'b10:  rs_status <= rs_status - 1'b1; // read
153
        default:  rs_status <= rs_status;      // nothing to do 
154
      endcase
155
    end
156
  end
157
 
158
endmodule
159
 
160
 

powered by: WebSVN 2.1.0

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