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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [fm_hvc/] [fm_afifo.v] - Blame information for rev 4

Go to most recent revision | 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
//   fm_afifo.v
7
//
8
// Abstract:
9
//   Asynchronus FIFO
10
//
11
// Author:
12 4 specular
//   Kenji Ishimaru (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 fm_afifo (
43
  clk_core,
44
  clk_vi,
45
  rst_x,
46
  i_color_mode,
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 P_RANGE = 7;
58
parameter P_DEPTH = 1 << P_RANGE;  // 128
59 4 specular
`ifdef PP_BUSWIDTH_64
60
localparam P_IB_DATA_WIDTH = 'd64;
61
`else
62
localparam P_IB_DATA_WIDTH = 'd32;
63
`endif
64 2 specular
////////////////////////////
65
// I/O definition
66
////////////////////////////
67
input         clk_core;       // system clock
68
input         clk_vi;
69
input         rst_x;          // system reset
70
input  [1:0]  i_color_mode;
71
input         i_wstrobe;      // write strobe
72 4 specular
input  [P_IB_DATA_WIDTH-1:0]
73
              i_dt;           // write data
74 2 specular
output        o_full;         // write data full
75
input         i_renable;      // read enable
76
output [15:0] o_dt;           // read data
77
output        o_empty;        // read data empty
78
output [P_RANGE:0] o_dnum;     // written data number
79
 
80
/////////////////////////
81
//  Register definition
82
/////////////////////////
83
reg [P_RANGE-1:0] r_write_counter;
84
reg [P_RANGE-1:0] r_read_counter;
85
// data registers
86 4 specular
`ifdef PP_BUSWIDTH_64
87
reg [3:0]         r_select_hw;
88
`else
89 2 specular
reg [2:0]         r_select_hw;
90 4 specular
`endif
91 2 specular
/////////////////////////
92
//  wire definition
93
/////////////////////////
94
wire             o_full;
95
wire             o_empty;
96
wire [15:0]      o_dt;
97
wire             w_we;
98
wire             w_re;
99 4 specular
wire [P_IB_DATA_WIDTH-1:0]
100
                 w_dt;
101 2 specular
wire [P_RANGE-1:0] w_read_counter_inc;
102
wire [P_RANGE-1:0] w_read_counter;
103
wire [15:0] w_dt16;
104
wire [7:0] w_dt8;
105
wire [3:0] w_dt4;
106
// /////////////////////////
107
//  assign statement
108
/////////////////////////
109 4 specular
`ifdef PP_BUSWIDTH_64
110
assign w_dt16 = (r_select_hw[1:0] == 'd3) ? w_dt[63:48] :
111
                (r_select_hw[1:0] == 'd2) ? w_dt[47:32] :
112
                (r_select_hw[1:0] == 'd1) ? w_dt[31:16] :
113
                                            w_dt[15:0];
114
 
115
assign w_dt8 = (r_select_hw[2:0] == 'd7) ? w_dt[63:56] :
116
               (r_select_hw[2:0] == 'd6) ? w_dt[55:48] :
117
               (r_select_hw[2:0] == 'd5) ? w_dt[47:40] :
118
               (r_select_hw[2:0] == 'd4) ? w_dt[39:32] :
119
               (r_select_hw[2:0] == 'd3) ? w_dt[31:24] :
120
               (r_select_hw[2:0] == 'd2) ? w_dt[23:16] :
121
               (r_select_hw[2:0] == 'd1) ? w_dt[15:8] :
122
                                           w_dt[7:0];
123
 
124
assign w_dt4 = (r_select_hw[3:0] == 'd15) ? w_dt[63:60] :
125
               (r_select_hw[3:0] == 'd14) ? w_dt[59:56] :
126
               (r_select_hw[3:0] == 'd13) ? w_dt[55:52] :
127
               (r_select_hw[3:0] == 'd12) ? w_dt[51:48] :
128
               (r_select_hw[3:0] == 'd11) ? w_dt[47:44] :
129
               (r_select_hw[3:0] == 'd10) ? w_dt[43:40] :
130
               (r_select_hw[3:0] == 'd9) ? w_dt[39:36] :
131
               (r_select_hw[3:0] == 'd8) ? w_dt[35:32] :
132
               (r_select_hw[3:0] == 'd7) ? w_dt[31:28] :
133
               (r_select_hw[3:0] == 'd6) ? w_dt[27:24] :
134
               (r_select_hw[3:0] == 'd5) ? w_dt[23:20] :
135
               (r_select_hw[3:0] == 'd4) ? w_dt[19:16] :
136
               (r_select_hw[3:0] == 'd3) ? w_dt[15:12] :
137
               (r_select_hw[3:0] == 'd2) ? w_dt[11:8] :
138
               (r_select_hw[3:0] == 'd1) ? w_dt[7:4] :
139
                                           w_dt[3:0];
140
 
141
assign w_re = i_renable & ((i_color_mode == 'd3) ? (r_select_hw[3:0] == 'd15) :
142
                           (i_color_mode == 'd2) ? (r_select_hw[2:0] == 'd7) :
143
                                                   (r_select_hw[1:0] == 'd3)
144
                           );
145
`else
146
assign w_dt16 = (r_select_hw[0]) ? w_dt[31:16] : w_dt[15:0];
147
assign w_dt8 = (r_select_hw[1:0] == 'd3) ? w_dt[31:24] :
148
               (r_select_hw[1:0] == 'd2) ? w_dt[23:16] :
149
               (r_select_hw[1:0] == 'd1) ? w_dt[15:8] :
150
                                           w_dt[7:0];
151 2 specular
 
152 4 specular
assign w_dt4 = (r_select_hw[2:0] == 'd7) ? w_dt[31:28] :
153
               (r_select_hw[2:0] == 'd6) ? w_dt[27:24] :
154
               (r_select_hw[2:0] == 'd5) ? w_dt[23:20] :
155
               (r_select_hw[2:0] == 'd4) ? w_dt[19:16] :
156
               (r_select_hw[2:0] == 'd3) ? w_dt[15:12] :
157
               (r_select_hw[2:0] == 'd2) ? w_dt[11:8] :
158
               (r_select_hw[2:0] == 'd1) ? w_dt[7:4] :
159
                                           w_dt[3:0];
160
 
161
assign w_re = i_renable & ((i_color_mode == 'd3) ? (r_select_hw == 'd7) :
162
                           (i_color_mode == 'd2) ? (r_select_hw[1:0] == 'd3) :
163
                                                   (r_select_hw[0] == 'd1)
164
                           );
165
`endif
166 2 specular
assign o_dt = (i_color_mode == 'd3) ? {12'd0,w_dt4} :
167
              (i_color_mode == 'd2) ? {8'd0,w_dt8} :
168
                                      w_dt16 ;
169
assign o_dnum = 0;
170
assign o_full = 1'b0;
171
assign o_empty = 1'b0;
172
assign w_we = i_wstrobe;
173
assign w_read_counter_inc = r_read_counter + 1'b1;
174
assign w_read_counter = (w_re) ? w_read_counter_inc : r_read_counter;
175
 
176
////////////////////////
177
// always 
178
///////////////////////
179
  // write side (clk_core)
180
  always @(posedge clk_core or negedge rst_x) begin
181
    if (~rst_x) begin
182
      r_write_counter <= 'd0;
183
    end else begin
184
      if (w_we) begin
185
        r_write_counter <= r_write_counter + 1'b1;
186
      end
187
    end
188
  end
189
 
190
  // read side (clk_vi)
191
  always @(posedge clk_vi or negedge rst_x) begin
192
    if (~rst_x) begin
193
      r_read_counter <= 'd0;
194
    end else begin
195
      if (w_re) begin
196
        r_read_counter <= w_read_counter_inc;
197
      end
198
    end
199
  end
200
 
201
  // select half word
202
  always @(posedge clk_vi or negedge rst_x) begin
203
    if (~rst_x) begin
204 4 specular
      r_select_hw <= 'd0;
205 2 specular
    end else begin
206
        if (i_renable) r_select_hw <= r_select_hw + 1'b1;
207
    end
208
  end
209
 
210
///////////////////
211
// module instance
212
///////////////////
213 4 specular
`ifdef PP_BUSWIDTH_64
214
    fm_cmn_ram #(.P_RAM_TYPE("TYPE_A"),.P_WIDTH(64),.P_RANGE( P_RANGE)) ram_00 (
215
`else
216 2 specular
    fm_cmn_ram #(.P_RAM_TYPE("TYPE_A"),.P_WIDTH(32),.P_RANGE( P_RANGE)) ram_00 (
217 4 specular
`endif
218 2 specular
        .clka(clk_core),
219
        .clkb(clk_vi),
220
        .wea(w_we),
221
        .addra(r_write_counter),
222
        .addrb(w_read_counter),
223
        .dia(i_dt),
224
        .doa(),
225 4 specular
        .dob(w_dt)
226 2 specular
    );
227
 
228
endmodule
229
 
230
 

powered by: WebSVN 2.1.0

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