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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [scenario/] [3d/] [mfifo.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   mfifo.v
7
//
8
// Abstract:
9
//   fifo module for simulation
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, 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 mfifo (
43
  i_wstrobe,
44
  i_dt,
45
  o_full,
46
  i_renable,
47
  o_dt,
48
  o_empty,
49
  o_dnum,
50
  clk,
51
  rst_x
52
);
53
 
54
// set default parameters
55
parameter WIDTH = 32;
56
parameter RANGE = 2;
57
parameter DEPTH = 1 << RANGE;
58
////////////////////////////
59
// I/O definitions
60
////////////////////////////
61
input         i_wstrobe;      // write strobe
62
input  [WIDTH-1:0] i_dt;      // write data
63
output        o_full;         // write data full
64
input         i_renable;      // read enable
65
output [WIDTH-1:0] o_dt;      // read data
66
output        o_empty;        // read data empty
67
output [RANGE:0] o_dnum;      // written data number
68
input         clk;            // system clock
69
input         rst_x;          // system reset
70
 
71
/////////////////////////
72
//  Register definitions
73
/////////////////////////
74
reg [RANGE-1:0] rs_write_counter;
75
reg [RANGE-1:0] rs_read_counter;
76
// data registers
77
reg [WIDTH-1:0] rs_data_buffer[0:DEPTH-1];
78
reg [RANGE:0] rs_status;
79
/////////////////////////
80
//  wire definitions
81
/////////////////////////
82
wire             o_full;
83
wire             o_empty;
84
wire [WIDTH-1:0] o_dt;
85
wire [1:0]       w_status;
86
wire             w_we;
87
wire             w_re;
88
/////////////////////////
89
//  assign statements
90
/////////////////////////
91
assign o_full  = (rs_status == DEPTH);
92
assign o_empty = (rs_status == 0);
93
assign o_dt = rs_data_buffer[rs_read_counter];
94
assign o_dnum = rs_status;
95
assign w_we = !o_full & i_wstrobe;
96
assign w_re = i_renable & !o_empty;
97
assign w_status = {w_re,w_we};
98
////////////////////////
99
// Behaviour
100
///////////////////////
101
  // write side
102
  always @(posedge clk or negedge rst_x) begin
103
    if (~rst_x) begin
104
      rs_write_counter <= 'd0;
105
    end else begin
106
      if (w_we) begin
107
        rs_write_counter <= rs_write_counter + 1'b1;
108
      end
109
    end
110
  end
111
 
112
  always @(posedge clk) begin
113
    if (w_we) begin
114
      rs_data_buffer[rs_write_counter] <= i_dt;
115
    end
116
  end
117
 
118
  // read side
119
  always @(posedge clk or negedge rst_x) begin
120
    if (~rst_x) begin
121
      rs_read_counter <= 'd0;
122
    end else begin
123
      if (w_re) begin
124
        rs_read_counter <= rs_read_counter + 1'b1;
125
      end
126
    end
127
  end
128
  // status counter
129
  always @(posedge clk or negedge rst_x) begin
130
    if (~rst_x) begin
131
      rs_status <= 'd0;
132
    end else begin
133
      case (w_status)
134
        2'b01:  rs_status <= rs_status + 1'b1; // write
135
        2'b10:  rs_status <= rs_status - 1'b1; // read
136
        //default:  rs_status <= rs_status;      // nothing to do 
137
      endcase
138
    end
139
  end
140
 
141
endmodule
142
 
143
 

powered by: WebSVN 2.1.0

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