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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [fm_hvc/] [fm_hvc_dma.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_dma.v
7
//
8
// Abstract:
9
//   VGA LCD Controller DMAC
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_dma (
43
    clk_core,
44
    rst_x,
45
    i_color_mode,
46
    i_video_start,
47
    i_vsync,
48
    i_hsync,
49
    i_fb0_offset,
50
    i_fb1_offset,
51
    i_front_buffer,
52
    i_fifo_available,
53
    o_fifo_available_ack,
54
    o_vsync,
55
    o_vsync_edge,
56
    // dram if
57
    o_req,
58
    o_adrs,
59
    o_len,
60
    i_ack
61
);
62
 
63
////////////////////////////
64
// Parameter definition
65
////////////////////////////
66 4 specular
 parameter P_IB_ADDR_WIDTH ='d24;
67
 parameter P_IB_LEN_WIDTH = 'd6;
68 2 specular
 
69 4 specular
localparam P_IDLE   = 3'd0;
70
localparam P_REQ    = 3'd1;
71
localparam P_REQ_AA = 3'd2;
72
localparam P_WAIT_FIFO_AVL = 3'd3;
73
localparam P_WAIT_AVL_FALL = 3'd4;
74
 
75
`ifdef PP_BUSWIDTH_64
76
localparam P_BURST_SIZE = 6'd16;
77
localparam P_BURST_SIZE_H = 6'd8;
78
`else
79
localparam P_BURST_SIZE = 6'd32;
80
localparam P_BURST_SIZE_H = 6'd16;
81
`endif
82 2 specular
//////////////////////////////////
83
// I/O port definition
84
//////////////////////////////////
85
    input         clk_core;
86
    input         rst_x;
87
    input [1:0]   i_color_mode;
88
    input         i_video_start;
89
    input         i_vsync;
90
    input         i_hsync;
91 4 specular
`ifdef PP_BUSWIDTH_64
92
    input  [11:0] i_fb0_offset;
93
    input  [11:0] i_fb1_offset;
94
`else
95 2 specular
    input  [6:0]  i_fb0_offset;
96
    input  [6:0]  i_fb1_offset;
97 4 specular
`endif
98 2 specular
    input         i_front_buffer;
99
    input         i_fifo_available;
100
    output        o_fifo_available_ack;
101
    output        o_vsync;
102
    output        o_vsync_edge;
103
    // dram if
104
    output        o_req;
105 4 specular
    output [P_IB_ADDR_WIDTH-1:0]
106
                  o_adrs;
107
    output [P_IB_LEN_WIDTH-1:0]
108
                  o_len;  // 32 burst x 10
109 2 specular
    input         i_ack;
110
 
111
//////////////////////////////////
112
// reg
113
//////////////////////////////////
114
    reg    [2:0]   r_state;
115
    reg            r_req;
116 4 specular
`ifdef PP_BUSWIDTH_64
117
    reg    [13:0]  r_cur_adrs_l;
118
`else
119 2 specular
    reg    [12:0]  r_cur_adrs_l;
120 4 specular
`endif
121 2 specular
    reg    [3:0]   r_req_cnt;
122
    // syncro register
123
    reg            r_vsync_1z;
124
    reg            r_vsync_2z;
125
    reg            r_vsync_3z;
126
 
127
    reg            r_hsync_1z;
128
    reg            r_hsync_2z;
129
    reg            r_hsync_3z;
130
 
131
    reg            r_fifo_available_1z;
132
    reg            r_fifo_available_2z;
133
    reg            r_fifo_available_3z;
134
    reg            r_fifo_available_ack;
135
//////////////////////////////////
136
// wire
137
//////////////////////////////////
138
    wire           w_set_initial_adrs;
139
    wire           w_v_rise;
140
    wire           w_h_start;
141
    wire           w_adrs_inc;
142
    wire           w_line_end;
143
    wire           w_req_cnt_clear;
144
 
145 4 specular
`ifdef PP_BUSWIDTH_64
146
    wire    [11:0]  w_fb_offset;
147
    wire    [11:0]  w_offset;
148
`else
149 2 specular
    wire    [6:0]  w_fb_offset;
150
    wire    [6:0]  w_offset;
151 4 specular
`endif
152
    wire           w_hburst;
153 2 specular
//////////////////////////////////
154
// assign
155
//////////////////////////////////
156
    assign o_req = r_req;
157
    assign w_hburst = (i_color_mode == 2'd3)&(r_req_cnt == 4'd2);
158
    assign o_len = (w_hburst) ? P_BURST_SIZE_H : P_BURST_SIZE;
159
    assign o_fifo_available_ack = r_fifo_available_ack;
160
 
161
    assign w_set_initial_adrs = w_v_rise;
162 4 specular
    assign w_adrs_inc = (r_state == P_REQ) & i_ack;
163 2 specular
 
164
    assign w_h_start = i_video_start & r_hsync_2z & !r_hsync_3z;  // rise of hsync
165
    assign w_v_rise = r_vsync_2z & !r_vsync_3z;  // rising edge of vsync
166 4 specular
    assign w_line_end = (i_color_mode == 2'd3) ? (r_req_cnt == 4'd3)  :// 80 times,  32burstx2, 16burstx1
167
                        (i_color_mode == 2'd2) ? (r_req_cnt == 4'd5)  :// 160 times, 32burstx5
168
                                                 (r_req_cnt == 4'd10); // 320 times, 32burstx10
169
    // 80 times,  16burstx2, 8burstx1 (64)
170 2 specular
    assign w_req_cnt_clear = (w_line_end & !r_fifo_available_2z &
171 4 specular
                             (r_state == P_WAIT_AVL_FALL)) |
172
                             (w_line_end & (r_state == P_WAIT_FIFO_AVL) & (i_color_mode == 'd3));
173 2 specular
 
174 4 specular
`ifdef PP_BUSWIDTH_64
175
    assign o_adrs = {w_offset, r_cur_adrs_l,3'b0};
176
`else
177
    assign o_adrs = {w_offset, r_cur_adrs_l,4'b0};
178
`endif
179 2 specular
 
180
    assign w_fb_offset = (i_front_buffer) ? i_fb1_offset : i_fb0_offset;
181 4 specular
    assign w_offset = w_fb_offset;
182 2 specular
 
183
    assign o_vsync = r_vsync_2z;
184
    assign o_vsync_edge = !r_vsync_2z & r_vsync_3z;  // falling edge
185
 
186
//////////////////////////////////
187
// always
188
//////////////////////////////////
189
    // request state
190
    always @(posedge clk_core or negedge rst_x) begin
191
        if (~rst_x) begin
192
            r_state <= P_IDLE;
193
            r_req <= 1'b0;
194
            r_fifo_available_ack <= 1'b0;
195
        end else begin
196
            case (r_state)
197
                P_IDLE: begin
198
                    if (w_h_start) begin
199
                        r_req <= 1'b1;
200
                        r_state <= P_REQ;
201
                    end
202
                end
203
                P_REQ: begin
204
                    if (i_ack) begin
205 4 specular
                       r_req <= 1'b0;
206
                       r_state <= P_WAIT_FIFO_AVL;
207 2 specular
                    end
208
                end
209
                P_WAIT_FIFO_AVL: begin
210
                   if (r_req_cnt < 4'd4) begin
211 4 specular
                      if (w_line_end) begin
212 2 specular
                           r_state <= P_IDLE;
213 4 specular
                      end else begin
214 2 specular
                           r_req <= 1'b1;
215
                           r_state <= P_REQ;
216
                       end
217
                                                 end else begin
218
                       if (r_fifo_available_2z) begin
219
                           r_fifo_available_ack <= 1'b1;
220
                           r_state <= P_WAIT_AVL_FALL;
221
                       end
222
                   end
223
                end
224
                P_WAIT_AVL_FALL: begin
225
                    if (!r_fifo_available_2z) begin
226
                       r_fifo_available_ack <= 1'b0;
227
                        if (w_line_end) begin
228
                            r_state <= P_IDLE;
229
                        end else begin
230
                            r_req <= 1'b1;
231
                            r_state <= P_REQ;
232
                        end
233
                    end
234
                end
235
            endcase
236
        end
237
    end
238
 
239
    // current address
240
    always @(posedge clk_core or negedge rst_x) begin
241
        if (~rst_x) begin
242 4 specular
            r_cur_adrs_l <= 'h0; // for simulation
243 2 specular
        end else begin
244
            if (w_set_initial_adrs) begin
245 4 specular
                r_cur_adrs_l <= 'h0;
246 2 specular
            end else if (w_adrs_inc) begin
247
              if (w_hburst)
248
                r_cur_adrs_l <= r_cur_adrs_l + 1'b1;  // same as + 16
249 4 specular
              else
250 2 specular
                r_cur_adrs_l <= r_cur_adrs_l + 2'b10;  // same as + 32
251
            end
252
        end
253
    end
254
 
255
    always @(posedge clk_core or negedge rst_x) begin
256
        if (~rst_x) begin
257
            r_req_cnt <= 4'd0;
258
        end else begin
259
           if (w_req_cnt_clear) r_req_cnt <= 4'd0;
260
           else if (w_adrs_inc) r_req_cnt <= r_req_cnt + 1'b1;
261
        end
262
    end
263
 
264
    // syncro register
265
    always @(posedge clk_core or negedge rst_x) begin
266
        if (~rst_x) begin
267
            r_vsync_1z <= 1'b1;
268
            r_vsync_2z <= 1'b1;
269
            r_vsync_3z <= 1'b1;
270
            r_hsync_1z <= 1'b1;
271
            r_hsync_2z <= 1'b1;
272
            r_hsync_3z <= 1'b1;
273
            r_fifo_available_1z <= 1'b0;
274
            r_fifo_available_2z <= 1'b0;
275
        end else begin
276
            r_vsync_1z <= i_vsync;
277
            r_vsync_2z <= r_vsync_1z;
278
            r_vsync_3z <= r_vsync_2z;
279
            r_hsync_1z <= i_hsync;
280
            r_hsync_2z <= r_hsync_1z;
281
            r_hsync_3z <= r_hsync_2z;
282
            r_fifo_available_1z <= i_fifo_available;
283
            r_fifo_available_2z <= r_fifo_available_1z;
284
        end
285
    end
286
 
287
 
288
 
289
endmodule

powered by: WebSVN 2.1.0

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