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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [fm_hvc/] [fm_hvc_data.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_hvc_data.v
7
//
8
// Abstract:
9
//   LCD output color data construction
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_hvc_data (
43
    clk_core,
44
    clk_vi,
45
    rst_x,
46
    // sdram interface
47
    i_rstr,
48
    i_rd,
49
    // timing input
50
    i_h_active,
51
    i_first_line,
52
    i_hsync,
53
    i_vsync,
54
    o_fifo_available,
55
    i_fifo_available_ack,
56
    // configuration
57
    i_video_start,
58
    i_color_mode,
59
    // test color input
60
    i_test_r,
61
    i_test_g,
62
    i_test_b,
63
    // color out
64
    o_r,
65
    o_g,
66
    o_b,
67
    o_a
68
);
69
 
70
//////////////////////////////////
71
// I/O port definition
72
//////////////////////////////////
73
    input          clk_core;
74
    input          clk_vi;     // 25MHz
75
    input          rst_x;
76
    // sdram interface
77
    input          i_rstr;
78
    input  [31:0]  i_rd;
79
    // timing input
80
    input          i_h_active;
81
    input          i_first_line;
82
    input          i_hsync;
83
    input          i_vsync;
84
    output         o_fifo_available;
85
    input          i_fifo_available_ack;
86
    // configuration
87
    input          i_video_start;
88
    input  [1:0]   i_color_mode;
89
    // test color input
90
    input  [7:0]  i_test_r;
91
    input  [7:0]  i_test_g;
92
    input  [7:0]  i_test_b;
93
 
94
    output [7:0]   o_r;
95
    output [7:0]   o_g;
96
    output [7:0]   o_b;
97
    output [7:0]   o_a;
98
//////////////////////////////////
99
// reg
100
//////////////////////////////////
101
    reg    [9:0]   r_pix_cnt;
102
    reg            r_fifo_available;
103
 
104
    reg    [7:0]   r_r;
105
    reg    [7:0]   r_g;
106
    reg    [7:0]   r_b;
107
 
108
    reg    [7:0]   r_r_neg;
109
    reg    [7:0]   r_g_neg;
110
    reg    [7:0]   r_b_neg;
111
 
112
    reg            r_fifo_available_ack_1z;
113
    reg            r_fifo_available_ack_2z;
114
    reg            r_fifo_available_ack_3z;
115
 
116
//////////////////////////////////
117
// wire
118
//////////////////////////////////
119
    wire           w_rstr_base;
120
    wire           w_rstr_upper;
121
    wire   [15:0]  w_di;
122
    wire   [31:0]  w_do;
123
    wire   [31:0]  w_do_normal;
124
    wire   [7:0]   w_r_aa;
125
    wire   [7:0]   w_g_aa;
126
    wire   [7:0]   w_b_aa;
127
    wire   [7:0]   w_r_f;
128
    wire   [7:0]   w_g_f;
129
    wire   [7:0]   w_b_f;
130
 
131
    wire   [7:0]   w_r;
132
    wire   [7:0]   w_g;
133
    wire   [7:0]   w_b;
134
 
135
    wire           w_ren;
136
    wire           w_fifo_reset_x;
137
    wire           w_fifo_available_ack_rise;
138
    wire           w_pix_av_c0;
139
    wire           w_pix_av_c2;
140
    wire           w_pix_av_c3;
141
 
142
//////////////////////////////////
143
// assign
144
//////////////////////////////////
145
    assign w_fifo_available_ack_rise = r_fifo_available_ack_2z &
146
                                       !r_fifo_available_ack_3z;
147
    assign w_fifo_reset_x = i_vsync & rst_x;
148
    assign w_rstr_base = i_rstr;
149
    assign w_rstr_upper = i_rstr;
150
    assign w_ren = i_h_active;
151
 
152
    assign w_r_f = w_do_normal[31:24];
153
    assign w_g_f = w_do_normal[23:16];
154
    assign w_b_f = w_do_normal[15:8];
155
    assign w_do_normal = f_get_color(w_di,i_color_mode);
156
 
157
    assign w_b = (!i_video_start) ? i_test_b :
158
                 (i_h_active )?     w_b_f :
159
                                    8'h00;
160
    assign w_g = (!i_video_start) ? i_test_g :
161
                  (i_h_active )?    w_g_f :
162
                                    8'h00;
163
    assign w_r = (!i_video_start) ? i_test_r :
164
                  (i_h_active )?    w_r_f :
165
                                    8'h00;
166
    assign o_b = r_b;  //r_b_neg
167
    assign o_g = r_g;  // r_g_neg
168
    assign o_r = r_r;  // r_r_neg
169
 
170
    assign o_fifo_available = r_fifo_available;
171
 
172
    assign w_pix_av_c0 = ((i_color_mode == 'd0)&(r_pix_cnt == 'd63));
173
    assign w_pix_av_c2 = ((i_color_mode == 'd2)&(r_pix_cnt == 'd127));
174
    assign w_pix_av_c3 = ((i_color_mode == 'd3)&(r_pix_cnt == 'd255));
175
//////////////////////////////////
176
// always
177
//////////////////////////////////
178
 
179
    always @(posedge clk_vi or negedge rst_x) begin
180
        if (~rst_x) begin
181
            r_pix_cnt <= 10'd0;
182
        end else begin
183
            if (~i_hsync) r_pix_cnt <= 10'd0;
184
            else if (w_pix_av_c0|w_pix_av_c2|w_pix_av_c3)r_pix_cnt <= 10'd0;
185
            else if (w_ren) r_pix_cnt <= r_pix_cnt + 1'b1;
186
        end
187
    end
188
 
189
    always @(posedge clk_vi or negedge rst_x) begin
190
        if (~rst_x) begin
191
            r_fifo_available <= 1'b0;
192
        end else begin
193
            if (w_pix_av_c0|w_pix_av_c2|w_pix_av_c3) r_fifo_available <= 1'b1;  // 32 x 2
194
            else if (~i_hsync | w_fifo_available_ack_rise) r_fifo_available <= 1'b0;
195
        end
196
    end
197
 
198
 
199
    always @(posedge clk_vi or negedge rst_x) begin
200
        if (~rst_x) begin
201
            r_fifo_available_ack_1z <= 1'b0;
202
            r_fifo_available_ack_2z <= 1'b0;
203
            r_fifo_available_ack_3z <= 1'b0;
204
        end else begin
205
            r_fifo_available_ack_1z <= i_fifo_available_ack;
206
            r_fifo_available_ack_2z <= r_fifo_available_ack_1z;
207
            r_fifo_available_ack_3z <= r_fifo_available_ack_2z;
208
        end
209
    end
210
 
211
    always @(posedge clk_vi) begin
212
        r_r <= w_r;
213
        r_g <= w_g;
214
        r_b <= w_b;
215
    end
216
 
217
//////////////////////////////////
218
// function
219
//////////////////////////////////
220
    function [31:0] f_get_color;
221
        input [15:0] idata;
222
        input [1:0]  mode;
223
        reg [7:0] r;
224
        reg [7:0] g;
225
        reg [7:0] b;
226
        reg [7:0] a;
227
        begin
228
            case (mode)
229
                2'b00 : begin
230
                    // color mode 5:6:5
231
                    r = {idata[15:11],idata[15:13]};
232
                    g = {idata[10:5],idata[10:9]};
233
                    b = {idata[4:0],idata[4:2]};
234
                    a = 8'h0;
235
                end
236
                2'b01 : begin
237
                    // color mode 5:5:5:1
238
                    r = {idata[15:11],idata[15:13]};
239
                    g = {idata[10:6],idata[10:8]};
240
                    b = {idata[5:1],idata[5:3]};
241
                    a = {idata[0],7'b0};
242
                end
243
                2'b10 : begin
244
                    // color mode 2:3:3
245
                    r = {'d4{idata[7:6]}};
246
                    g = {idata[5:3],idata[5:3],idata[5:4]};
247
                    b = {idata[2:0],idata[2:0],idata[2:1]};
248
                    a = 8'h0;
249
                end
250
                default : begin
251
                    // color mode 1:2:2
252
                    r = {'d8{idata[3]}};
253
                    g = {'d4{idata[2:1]}};
254
                    b = {'d8{idata[0]}};
255
                    a = 8'h0;
256
                end
257
            endcase
258
            f_get_color = {r,g,b,a};
259
        end
260
    endfunction
261
 
262
 
263
//////////////////////////////////
264
// module instance
265
//////////////////////////////////
266
// 32bit x 128 entry fifo for current line
267
fm_afifo fm_afifo_c (
268
  .clk_core(clk_core),
269
  .clk_vi(clk_vi),
270
  .rst_x(w_fifo_reset_x),
271
  .i_color_mode(i_color_mode),
272
  .i_wstrobe(w_rstr_base),
273
  .i_dt(i_rd),
274
  .o_full(),
275
  .i_renable(w_ren),
276
  .o_dt(w_di),
277
  .o_empty(),
278
  .o_dnum()
279
);
280
 
281
 
282
endmodule

powered by: WebSVN 2.1.0

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