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 2

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
//   Kenji Ishimaru (kenji.ishimaru@prtissimo.com)
13
//
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
////////////////////////////
60
// I/O definition
61
////////////////////////////
62
input         clk_core;       // system clock
63
input         clk_vi;
64
input         rst_x;          // system reset
65
input  [1:0]  i_color_mode;
66
input         i_wstrobe;      // write strobe
67
input  [31:0] i_dt;           // write data
68
output        o_full;         // write data full
69
input         i_renable;      // read enable
70
output [15:0] o_dt;           // read data
71
output        o_empty;        // read data empty
72
output [P_RANGE:0] o_dnum;     // written data number
73
 
74
/////////////////////////
75
//  Register definition
76
/////////////////////////
77
reg [P_RANGE-1:0] r_write_counter;
78
reg [P_RANGE-1:0] r_read_counter;
79
// data registers
80
reg [2:0]         r_select_hw;
81
/////////////////////////
82
//  wire definition
83
/////////////////////////
84
wire             o_full;
85
wire             o_empty;
86
wire [15:0]      o_dt;
87
wire             w_we;
88
wire             w_re;
89
wire [31:0]      w_dt32;
90
wire [P_RANGE-1:0] w_read_counter_inc;
91
wire [P_RANGE-1:0] w_read_counter;
92
wire [15:0] w_dt16;
93
wire [7:0] w_dt8;
94
wire [3:0] w_dt4;
95
// /////////////////////////
96
//  assign statement
97
/////////////////////////
98
assign w_dt16 = (r_select_hw[0]) ? w_dt32[31:16] : w_dt32[15:0];
99
assign w_dt8 = (r_select_hw[1:0] == 'd3) ? w_dt32[31:24] :
100
               (r_select_hw[1:0] == 'd2) ? w_dt32[23:16] :
101
               (r_select_hw[1:0] == 'd1) ? w_dt32[15:8] :
102
                                           w_dt32[7:0];
103
 
104
assign w_dt4 = (r_select_hw[2:0] == 'd7) ? w_dt32[31:28] :
105
               (r_select_hw[2:0] == 'd6) ? w_dt32[27:24] :
106
               (r_select_hw[2:0] == 'd5) ? w_dt32[23:20] :
107
               (r_select_hw[2:0] == 'd4) ? w_dt32[19:16] :
108
               (r_select_hw[2:0] == 'd3) ? w_dt32[15:12] :
109
               (r_select_hw[2:0] == 'd2) ? w_dt32[11:8] :
110
               (r_select_hw[2:0] == 'd1) ? w_dt32[7:4] :
111
                                           w_dt32[3:0];
112
 
113
assign o_dt = (i_color_mode == 'd3) ? {12'd0,w_dt4} :
114
              (i_color_mode == 'd2) ? {8'd0,w_dt8} :
115
                                      w_dt16 ;
116
assign o_dnum = 0;
117
assign o_full = 1'b0;
118
assign o_empty = 1'b0;
119
assign w_we = i_wstrobe;
120
assign w_re = i_renable & ((i_color_mode == 'd3) ? (r_select_hw == 'd7) :
121
                           (i_color_mode == 'd2) ? (r_select_hw[1:0] == 'd3) :
122
                                                   (r_select_hw[0] == 'd1)
123
                           );
124
assign w_read_counter_inc = r_read_counter + 1'b1;
125
assign w_read_counter = (w_re) ? w_read_counter_inc : r_read_counter;
126
 
127
////////////////////////
128
// always 
129
///////////////////////
130
  // write side (clk_core)
131
  always @(posedge clk_core or negedge rst_x) begin
132
    if (~rst_x) begin
133
      r_write_counter <= 'd0;
134
    end else begin
135
      if (w_we) begin
136
        r_write_counter <= r_write_counter + 1'b1;
137
      end
138
    end
139
  end
140
 
141
  // read side (clk_vi)
142
  always @(posedge clk_vi or negedge rst_x) begin
143
    if (~rst_x) begin
144
      r_read_counter <= 'd0;
145
    end else begin
146
      if (w_re) begin
147
        r_read_counter <= w_read_counter_inc;
148
      end
149
    end
150
  end
151
 
152
  // select half word
153
  always @(posedge clk_vi or negedge rst_x) begin
154
    if (~rst_x) begin
155
      r_select_hw <= 3'b0;
156
    end else begin
157
        if (i_renable) r_select_hw <= r_select_hw + 1'b1;
158
    end
159
  end
160
 
161
///////////////////
162
// module instance
163
///////////////////
164
    fm_cmn_ram #(.P_RAM_TYPE("TYPE_A"),.P_WIDTH(32),.P_RANGE( P_RANGE)) ram_00 (
165
        .clka(clk_core),
166
        .clkb(clk_vi),
167
        .wea(w_we),
168
        .addra(r_write_counter),
169
        .addrb(w_read_counter),
170
        .dia(i_dt),
171
        .doa(),
172
        .dob(w_dt32)
173
    );
174
 
175
endmodule
176
 
177
 

powered by: WebSVN 2.1.0

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