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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [axi_cmn/] [fm_ififo.v] - Blame information for rev 8

Go to most recent revision | 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_ififo.v
7
//
8
// Abstract:
9
//   FIFO for Memory Interconnect
10
//
11
// Author:
12
//   Kenji Ishimaru (info.wf3d@gmail.com)
13
//
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_ififo (
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
);
52
 
53
// set default parameters
54
parameter WIDTH = 32;
55
////////////////////////////
56
// I/O definitions
57
////////////////////////////
58
input         i_wstrobe;      // write strobe
59
input  [WIDTH-1:0] i_dt;      // write data
60
output        o_full;         // write data full
61
input         i_renable;      // read enable
62
output [WIDTH-1:0] o_dt;      // read data
63
output        o_empty;        // read data empty
64
input         clk_core;        // system clock
65
input         rst_x;          // system reset
66
 
67
/////////////////////////
68
//  Register definitions
69
/////////////////////////
70
reg [2:0] rs_write_counter;
71
reg [2:0] rs_read_counter;
72
// data registers
73
reg [WIDTH-1:0] rs_data_buffer[0:4];  // only 5 data
74
reg [2:0] rs_status;
75
/////////////////////////
76
//  wire definitions
77
/////////////////////////
78
wire             o_full;
79
wire             o_empty;
80
wire [WIDTH-1:0] o_dt;
81
wire [1:0]       w_status;
82
wire             w_we;
83
wire             w_re;
84
reg [2:0] w_next_write_counter;
85
reg [2:0] w_next_read_counter;
86
/////////////////////////
87
//  assign statements
88
/////////////////////////
89
assign o_full  = (rs_status == 5);
90
assign o_empty = (rs_status == 0);
91
assign o_dt = rs_data_buffer[rs_read_counter];
92
assign w_we = !o_full & i_wstrobe;
93
assign w_re = i_renable & !o_empty;
94
assign w_status = {w_re,w_we};
95
 
96
always @(*) begin
97
  if (rs_write_counter == 3'd4) w_next_write_counter = 3'd0;
98
  else w_next_write_counter = rs_write_counter +1'b1;
99
end
100
 
101
always @(*) begin
102
 if (rs_read_counter == 3'd4) w_next_read_counter = 3'd0;
103
 else w_next_read_counter = rs_read_counter +1'b1;
104
end
105
 
106
////////////////////////
107
// Behaviour
108
///////////////////////
109
  // write side
110
  always @(posedge clk_core or negedge rst_x) begin
111
    if (~rst_x) begin
112
      rs_write_counter <= 'd0;
113
    end else begin
114
      if (w_we) begin
115
        rs_write_counter <= w_next_write_counter;
116
      end
117
    end
118
  end
119
  integer i;
120
 
121
  always @(posedge clk_core or negedge rst_x) begin
122
    if (~rst_x) begin
123
      for (i = 0; i < 5; i = i + 1) begin
124
        rs_data_buffer[i] <= 0;
125
      end
126
    end else begin
127
      if (w_we) begin
128
        rs_data_buffer[rs_write_counter] <= i_dt;
129
      end
130
    end
131
  end
132
 
133
  // read side
134
  always @(posedge clk_core or negedge rst_x) begin
135
    if (~rst_x) begin
136
      rs_read_counter <= 'd0;
137
    end else begin
138
      if (w_re) begin
139
        rs_read_counter <= w_next_read_counter;
140
      end
141
    end
142
  end
143
  // status counter
144
  always @(posedge clk_core or negedge rst_x) begin
145
    if (~rst_x) begin
146
      rs_status <= 'd0;
147
    end else begin
148
      case (w_status)
149
        2'b01:  rs_status <= rs_status + 1'b1; // write
150
        2'b10:  rs_status <= rs_status - 1'b1; // read
151
        default:  rs_status <= rs_status;      // nothing to do 
152
      endcase
153
    end
154
  end
155
 
156
endmodule
157
 
158
 

powered by: WebSVN 2.1.0

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