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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [axi_cmn/] [fm_raw_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_raw_fifo.v
7
//
8
// Abstract:
9
//   FIFO for AXI read-after-write
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_raw_fifo (
43
  clk_core,
44
  rst_x,
45
  i_check_address,
46
  o_hit,
47
  i_wstrobe,
48
  i_dt,
49
  o_full,
50
  i_renable,
51
  o_dt,
52
  o_empty,
53
  o_dnum
54
);
55
 
56
// set default parameters
57
parameter WIDTH = 32;
58
parameter RANGEE = 4;
59
localparam DEPTH = 1 << RANGEE;
60
////////////////////////////
61
// I/O definition
62
////////////////////////////
63
input         clk_core;            // system clock
64
input         rst_x;          // system reset
65
input  [WIDTH-1:0] i_check_address;
66
output        o_hit;
67
input         i_wstrobe;      // write strobe
68
input  [WIDTH-1:0] i_dt;      // write data
69
output        o_full;         // write data full
70
input         i_renable;      // read enable
71
output [WIDTH-1:0] o_dt;      // read data
72
output        o_empty;        // read data empty
73
output [RANGEE:0] o_dnum;      // written data number
74
 
75
/////////////////////////
76
//  Register definition
77
/////////////////////////
78
reg [RANGEE-1:0] rs_write_counter;
79
reg [RANGEE-1:0] rs_read_counter;
80
// data registers
81
reg [WIDTH-1:0] rs_data_buffer[0:DEPTH-1];
82
reg [DEPTH-1:0] rs_valid;
83
/////////////////////////
84
//  wire definition
85
/////////////////////////
86
wire             o_full;
87
wire             o_empty;
88
wire [WIDTH-1:0] o_dt;
89
wire [1:0]       w_status;
90
wire             w_we;
91
wire             w_re;
92
// address compare
93
wire [DEPTH-1:0] w_hit;
94
/////////////////////////
95
//  assign statement
96
/////////////////////////
97
assign o_full  = (&rs_valid);
98
assign o_empty = ~(|rs_valid);
99
assign o_dt = rs_data_buffer[rs_read_counter];
100
assign o_dnum = 'd0;
101
assign w_we = !o_full & i_wstrobe;
102
assign w_re = i_renable & !o_empty;
103
assign w_status = {w_re,w_we};
104
assign o_hit = |w_hit;
105
////////////////////////
106
// always statement
107
///////////////////////
108
  genvar i;
109
  generate for (i=0;i<DEPTH;i=i+1) begin : gen_loop
110
    assign w_hit[i] = rs_valid[i] ? (i_check_address == rs_data_buffer[i]) : 1'b0;
111
  end
112
  endgenerate
113
 
114
  // write side
115
  always @(posedge clk_core or negedge rst_x) begin
116
    if (~rst_x) begin
117
      rs_write_counter <= 'd0;
118
    end else begin
119
      if (w_we) begin
120
        rs_write_counter <= rs_write_counter + 1'b1;
121
      end
122
    end
123
  end
124
 
125
  always @(posedge clk_core) begin
126
    if (w_we) begin
127
      rs_data_buffer[rs_write_counter] <= i_dt;
128
    end
129
  end
130
 
131
  // read side
132
  always @(posedge clk_core or negedge rst_x) begin
133
    if (~rst_x) begin
134
      rs_read_counter <= 'd0;
135
    end else begin
136
      if (w_re) begin
137
        rs_read_counter <= rs_read_counter + 1'b1;
138
      end
139
    end
140
  end
141
  // data valid
142
  always @(posedge clk_core or negedge rst_x) begin
143
    if (~rst_x) begin
144
      rs_valid <= {DEPTH{1'b0}};
145
    end else begin
146
      case (w_status)
147
        2'b01: rs_valid[rs_write_counter] <= 1'b1; // write
148
        2'b10: rs_valid[rs_read_counter]  <= 1'b0; // read
149
        2'b11: begin
150
          rs_valid[rs_write_counter] <= 1'b1; // write
151
          rs_valid[rs_read_counter]  <= 1'b0; // read
152
        end
153
        default:  rs_valid <= rs_valid;      // 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.