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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [axi_cmn/] [fm_cmn_bfifo.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_cmn_bfifo.v
7
//
8
// Abstract:
9
//   Block RAM FIFO
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_cmn_bfifo (
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 = 8;
57
parameter P_DEPTH = 1 << P_RANGE;
58
////////////////////////////
59
// I/O definition
60
////////////////////////////
61
input         clk_core;       // system clock
62
input         rst_x;          // system reset
63
input         i_wstrobe;      // write strobe
64
input  [P_WIDTH-1:0] i_dt;      // write data
65
output        o_full;         // write data full
66
input         i_renable;      // read enable
67
output [P_WIDTH-1:0] o_dt;      // read data
68
output        o_empty;        // read data empty
69
output [P_RANGE:0] o_dnum;      // written data number
70
 
71
/////////////////////////
72
//  Register definition
73
/////////////////////////
74
reg [P_RANGE-1:0] r_write_counter;
75
reg [P_RANGE-1:0] r_read_counter;
76
reg [P_RANGE:0]   r_status;
77
reg               r_sel;
78
/////////////////////////
79
//  wire definition
80
/////////////////////////
81
wire             o_full;
82
wire [P_WIDTH-1:0] o_dt;
83
wire [P_WIDTH-1:0] w_dto;
84
wire [P_WIDTH-1:0] w_dto_th;
85
wire [1:0]       w_status;
86
wire             w_we;
87
wire             w_re;
88
wire [P_RANGE-1:0] w_read_counter_inc;
89
wire [P_RANGE-1:0] w_read_counter;
90
/////////////////////////
91
//  assign statement
92
/////////////////////////
93
assign o_full  = (r_status == P_DEPTH);
94
assign o_empty = (r_status == 0);
95
assign o_dnum = r_status;
96
assign o_dt = (r_sel) ? w_dto_th : w_dto;
97
 
98
assign w_read_counter_inc = r_read_counter + 1'b1;
99
assign w_read_counter = (w_re) ? w_read_counter_inc : r_read_counter;
100
assign w_we = !o_full & i_wstrobe;
101
assign w_re = i_renable & !o_empty;
102
assign w_status = {w_re,w_we};
103
////////////////////////
104
// always statement
105
///////////////////////
106
  // write side
107
  always @(posedge clk_core or negedge rst_x) begin
108
    if (~rst_x) begin
109
      r_write_counter <= 'd0;
110
    end else begin
111
      if (w_we) begin
112
        r_write_counter <= r_write_counter + 1'b1;
113
      end
114
    end
115
  end
116
 
117
  // read side
118
  always @(posedge clk_core or negedge rst_x) begin
119
    if (~rst_x) begin
120
      r_read_counter <= 'd0;
121
    end else begin
122
      if (w_re) begin
123
        r_read_counter <= w_read_counter_inc;
124
      end
125
    end
126
  end
127
 
128
  // ram output select
129
  always @(posedge clk_core or negedge rst_x) begin
130
    if (~rst_x) begin
131
        r_sel <= 1'b0;
132
    end else begin
133
        r_sel <= (r_write_counter == w_read_counter) ? 1'b1 : 1'b0;
134
    end
135
  end
136
 
137
  // status counter
138
  always @(posedge clk_core or negedge rst_x) begin
139
    if (~rst_x) begin
140
      r_status <= 'd0;
141
    end else begin
142
      case (w_status)
143
        2'b01:  r_status <= r_status + 1'b1; // write
144
        2'b10:  r_status <= r_status - 1'b1; // read
145
        default:  r_status <= r_status;      // nothing to do 
146
      endcase
147
    end
148
  end
149
 
150
///////////////////
151
// module instance
152
///////////////////
153
    fm_cmn_bram_01 #(P_WIDTH, P_RANGE) bram_00 (
154
        .clk(clk_core),
155
        .we(w_we),
156
        .a(r_write_counter),
157
        .dpra(w_read_counter),
158
        .di(i_dt),
159
        .spo(w_dto_th),
160
        .dpo(w_dto)
161
    );
162
endmodule
163
 
164
 

powered by: WebSVN 2.1.0

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