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

powered by: WebSVN 2.1.0

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