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

Subversion Repositories vga_lcd

[/] [vga_lcd/] [trunk/] [rtl/] [verilog/] [vga_wb_slave.v] - Blame information for rev 62

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3 30 rherveille
////  WISHBONE rev.B2 compliant enhanced VGA/LCD Core            ////
4 23 rherveille
////  Wishbone slave interface                                   ////
5
////                                                             ////
6
////  Author: Richard Herveille                                  ////
7
////          richard@asics.ws                                   ////
8
////          www.asics.ws                                       ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/projects/vga_lcd ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14 30 rherveille
//// Copyright (C) 2001, 2002 Richard Herveille                  ////
15 23 rherveille
////                    richard@asics.ws                         ////
16
////                                                             ////
17
//// This source file may be used and distributed without        ////
18
//// restriction provided that this copyright statement is not   ////
19
//// removed from the file and that any derivative work contains ////
20
//// the original copyright notice and the associated disclaimer.////
21
////                                                             ////
22
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
23
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
24
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
25
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
26
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
27
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
28
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
29
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
30
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
31
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
32
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
33
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
34
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
35
////                                                             ////
36
/////////////////////////////////////////////////////////////////////
37
 
38
//  CVS Log
39 17 rherveille
//
40 53 rherveille
//  $Id: vga_wb_slave.v,v 1.12 2003-05-07 09:48:54 rherveille Exp $
41 17 rherveille
//
42 53 rherveille
//  $Date: 2003-05-07 09:48:54 $
43
//  $Revision: 1.12 $
44 23 rherveille
//  $Author: rherveille $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//               $Log: not supported by cvs2svn $
50 53 rherveille
//               Revision 1.11  2002/04/20 10:02:39  rherveille
51
//               Changed video timing generator.
52
//               Changed wishbone master vertical gate count code.
53
//               Fixed a potential bug in the wishbone slave (cursor color register readout).
54
//
55 39 rherveille
//               Revision 1.10  2002/03/28 04:59:25  rherveille
56
//               Fixed two small bugs that only showed up when the hardware cursors were disabled
57
//
58 36 rherveille
//               Revision 1.9  2002/03/04 16:05:52  rherveille
59
//               Added hardware cursor support to wishbone master.
60
//               Added provision to turn-off 3D cursors.
61
//               Fixed some minor bugs.
62
//
63 34 rherveille
//               Revision 1.8  2002/03/04 11:01:59  rherveille
64
//               Added 64x64pixels 4bpp hardware cursor support.
65
//
66 33 rherveille
//               Revision 1.7  2002/02/25 06:13:44  rherveille
67
//               Fixed dat_o incomplete sensitivity list.
68
//
69 32 rherveille
//               Revision 1.6  2002/02/07 05:42:10  rherveille
70
//               Fixed some bugs discovered by modified testbench
71
//               Removed / Changed some strange logic constructions
72
//               Started work on hardware cursor support (not finished yet)
73
//               Changed top-level name to vga_enh_top.v
74
//
75 17 rherveille
 
76 53 rherveille
//synopsys translate_off
77 17 rherveille
`include "timescale.v"
78 53 rherveille
//synopsys translate_on
79 30 rherveille
`include "vga_defines.v"
80 17 rherveille
 
81 53 rherveille
module vga_wb_slave(
82
        clk_i, rst_i, arst_i, adr_i, dat_i, dat_o, sel_i, we_i, stb_i, cyc_i, ack_o, rty_o, err_o, inta_o,
83
        wbm_busy, dvi_odf, bl, csl, vsl, hsl, pc, cd, vbl, cbsw, vbsw, ven, avmp, acmp,
84
        cursor0_res, cursor0_en, cursor0_xy, cursor0_ba, cursor0_ld, cc0_adr_i, cc0_dat_o,
85
        cursor1_res, cursor1_en, cursor1_xy, cursor1_ba, cursor1_ld, cc1_adr_i, cc1_dat_o,
86
        vbsint_in, cbsint_in, hint_in, vint_in, luint_in, sint_in,
87
        Thsync, Thgdel, Thgate, Thlen, Tvsync, Tvgdel, Tvgate, Tvlen, VBARa, VBARb,
88
        clut_acc, clut_ack, clut_q
89
        );
90 17 rherveille
 
91
        //
92
        // inputs & outputs
93
        //
94
 
95
        // wishbone slave interface
96 33 rherveille
        input         clk_i;
97
        input         rst_i;
98
        input         arst_i;
99
        input  [11:2] adr_i;
100
        input  [31:0] dat_i;
101
        output [31:0] dat_o;
102
        reg [31:0] dat_o;
103
        input  [ 3:0] sel_i;
104
        input         we_i;
105
        input         stb_i;
106
        input         cyc_i;
107
        output        ack_o;
108
        reg ack_o;
109 53 rherveille
        output        rty_o;
110
        reg rty_o;
111 33 rherveille
        output        err_o;
112
        reg err_o;
113
        output        inta_o;
114
        reg inta_o;
115 17 rherveille
 
116 53 rherveille
        // wishbone master controller feedback
117
        input  wbm_busy;             // data transfer in progress
118
 
119 17 rherveille
        // control register settings
120 53 rherveille
        output [1:0] dvi_odf;        // DVI output data format
121
        output bl;                   // blanking level
122
        output csl;                  // composite sync level
123
        output vsl;                  // vsync level
124
        output hsl;                  // hsync level
125
        output pc;                   // pseudo color
126
        output [1:0] cd;             // color depth
127
        output [1:0] vbl;            // video memory burst length
128
        output cbsw;                 // clut bank switch enable
129
        output vbsw;                 // video memory bank switch enable
130
        output ven;                  // video system enable
131 17 rherveille
 
132 30 rherveille
        // hardware cursor settings
133 33 rherveille
        output         cursor0_res;  // cursor0 resolution
134
        output         cursor0_en;   // cursor0 enable
135
        output [31: 0] cursor0_xy;   // cursor0 location
136 30 rherveille
        output [31:11] cursor0_ba;   // cursor0 base address
137
        output         cursor0_ld;   // reload cursor0 from video memory
138 33 rherveille
        input  [ 3: 0] cc0_adr_i;    // cursor0 color register address
139
        output [15: 0] cc0_dat_o;    // cursor0 color register data
140
        output         cursor1_res;  // cursor1 resolution
141
        output         cursor1_en;   // cursor1 enable
142
        output [31: 0] cursor1_xy;   // cursor1 location
143 30 rherveille
        output [31:11] cursor1_ba;   // cursor1 base address
144
        output         cursor1_ld;   // reload cursor1 from video memory
145 33 rherveille
        input  [ 3: 0] cc1_adr_i;    // cursor1 color register address
146
        output [15: 0] cc1_dat_o;    // cursor1 color register data
147 30 rherveille
 
148
        reg [31: 0] cursor0_xy;
149
        reg [31:11] cursor0_ba;
150
        reg         cursor0_ld;
151
        reg [31: 0] cursor1_xy;
152
        reg [31:11] cursor1_ba;
153
        reg         cursor1_ld;
154
 
155 17 rherveille
        // status register inputs
156 19 rherveille
        input avmp;          // active video memory page
157
        input acmp;          // active clut memory page
158
        input vbsint_in;     // bank switch interrupt request
159
        input cbsint_in;     // clut switch interrupt request
160
        input hint_in;       // hsync interrupt request
161
        input vint_in;       // vsync interrupt request
162
        input luint_in;      // line fifo underrun interrupt request
163
        input sint_in;       // system error interrupt request
164 17 rherveille
 
165
        // Horizontal Timing Register
166
        output [ 7:0] Thsync;
167
        output [ 7:0] Thgdel;
168
        output [15:0] Thgate;
169
        output [15:0] Thlen;
170
 
171
        // Vertical Timing Register
172
        output [ 7:0] Tvsync;
173
        output [ 7:0] Tvgdel;
174
        output [15:0] Tvgate;
175
        output [15:0] Tvlen;
176
 
177 19 rherveille
        // video base addresses
178 30 rherveille
        output [31:2] VBARa;
179
        reg [31:2] VBARa;
180
        output [31:2] VBARb;
181
        reg [31:2] VBARb;
182 17 rherveille
 
183 19 rherveille
        // color lookup table signals
184
        output        clut_acc;
185
        input         clut_ack;
186
        input  [23:0] clut_q;
187
 
188
 
189 17 rherveille
        //
190
        // variable declarations
191
        //
192 33 rherveille
        parameter REG_ADR_HIBIT = 7;
193 19 rherveille
 
194 33 rherveille
        wire [REG_ADR_HIBIT:0] REG_ADR  = adr_i[REG_ADR_HIBIT : 2];
195
        wire                   CLUT_ADR = adr_i[11];
196 17 rherveille
 
197 33 rherveille
        parameter [REG_ADR_HIBIT : 0] CTRL_ADR  = 6'b00_0000;
198
        parameter [REG_ADR_HIBIT : 0] STAT_ADR  = 6'b00_0001;
199
        parameter [REG_ADR_HIBIT : 0] HTIM_ADR  = 6'b00_0010;
200
        parameter [REG_ADR_HIBIT : 0] VTIM_ADR  = 6'b00_0011;
201
        parameter [REG_ADR_HIBIT : 0] HVLEN_ADR = 6'b00_0100;
202
        parameter [REG_ADR_HIBIT : 0] VBARA_ADR = 6'b00_0101;
203
        parameter [REG_ADR_HIBIT : 0] VBARB_ADR = 6'b00_0110;
204
        parameter [REG_ADR_HIBIT : 0] C0XY_ADR  = 6'b00_1100;
205
        parameter [REG_ADR_HIBIT : 0] C0BAR_ADR = 6'b00_1101;
206
        parameter [REG_ADR_HIBIT : 0] CCR0_ADR  = 6'b01_0???;
207
        parameter [REG_ADR_HIBIT : 0] C1XY_ADR  = 6'b01_1100;
208
        parameter [REG_ADR_HIBIT : 0] C1BAR_ADR = 6'b01_1101;
209
        parameter [REG_ADR_HIBIT : 0] CCR1_ADR  = 6'b10_0???;
210 17 rherveille
 
211 30 rherveille
 
212 17 rherveille
        reg [31:0] ctrl, stat, htim, vtim, hvlen;
213 19 rherveille
        wire hint, vint, vbsint, cbsint, luint, sint;
214
        wire hie, vie, vbsie, cbsie;
215
        wire acc, acc32, reg_acc, reg_wacc;
216 33 rherveille
        wire cc0_acc, cc1_acc;
217
        wire [31:0] ccr0_dat_o, ccr1_dat_o;
218 17 rherveille
 
219 19 rherveille
 
220
        reg [31:0] reg_dato; // data output from registers
221
 
222 17 rherveille
        //
223
        // Module body
224
        //
225
 
226 33 rherveille
        assign acc      =  cyc_i & stb_i;
227
        assign acc32    = (sel_i == 4'b1111);
228 19 rherveille
        assign clut_acc =  CLUT_ADR & acc & acc32;
229 53 rherveille
        assign reg_acc  = ~CLUT_ADR & acc & acc32;
230 33 rherveille
        assign reg_wacc =  reg_acc & we_i;
231 17 rherveille
 
232 53 rherveille
        assign cc0_acc  = (REG_ADR == CCR0_ADR) & acc & acc32;
233
        assign cc1_acc  = (REG_ADR == CCR1_ADR) & acc & acc32;
234 17 rherveille
 
235 53 rherveille
        always @(posedge clk_i)
236
          ack_o <= #1 ((reg_acc & acc32) | clut_ack) & ~(wbm_busy & REG_ADR == CTRL_ADR) & ~ack_o ;
237 19 rherveille
 
238 53 rherveille
        always @(posedge clk_i)
239
          rty_o <= #1 ((reg_acc & acc32) | clut_ack) & (wbm_busy & REG_ADR == CTRL_ADR) & ~rty_o ;
240 19 rherveille
 
241 53 rherveille
        always @(posedge clk_i)
242
          err_o <= #1 acc & ~acc32 & ~err_o;
243 33 rherveille
 
244 53 rherveille
 
245 17 rherveille
        // generate registers
246 53 rherveille
        always @(posedge clk_i or negedge arst_i)
247 17 rherveille
        begin : gen_regs
248 53 rherveille
          if (!arst_i)
249
            begin
250
                htim       <= #1 0;
251
                vtim       <= #1 0;
252
                hvlen      <= #1 0;
253
                VBARa      <= #1 0;
254
                VBARb      <= #1 0;
255
                cursor0_xy <= #1 0;
256
                cursor0_ba <= #1 0;
257
                cursor1_xy <= #1 0;
258
                cursor1_ba <= #1 0;
259
            end
260
          else if (rst_i)
261
            begin
262
                htim       <= #1 0;
263
                vtim       <= #1 0;
264
                hvlen      <= #1 0;
265
                VBARa      <= #1 0;
266
                VBARb      <= #1 0;
267
                cursor0_xy <= #1 0;
268
                cursor0_ba <= #1 0;
269
                cursor1_xy <= #1 0;
270
                cursor1_ba <= #1 0;
271
            end
272
          else if (reg_wacc)
273
            case (adr_i) // synopsis full_case parallel_case
274
                HTIM_ADR  : htim       <= #1 dat_i;
275
                VTIM_ADR  : vtim       <= #1 dat_i;
276
                HVLEN_ADR : hvlen      <= #1 dat_i;
277
                VBARA_ADR : VBARa      <= #1 dat_i[31: 2];
278
                VBARB_ADR : VBARb      <= #1 dat_i[31: 2];
279
                C0XY_ADR  : cursor0_xy <= #1 dat_i[31: 0];
280
                C0BAR_ADR : cursor0_ba <= #1 dat_i[31:11];
281
                C1XY_ADR  : cursor1_xy <= #1 dat_i[31: 0];
282
                C1BAR_ADR : cursor1_ba <= #1 dat_i[31:11];
283
            endcase
284 17 rherveille
        end
285
 
286 53 rherveille
        always @(posedge clk_i)
287
          begin
288
             cursor0_ld <= #1 reg_wacc && (adr_i == C0BAR_ADR);
289
             cursor1_ld <= #1 reg_wacc && (adr_i == C1BAR_ADR);
290
          end
291 17 rherveille
 
292
        // generate control register
293 53 rherveille
        always @(posedge clk_i or negedge arst_i)
294
          if (!arst_i)
295
            ctrl <= #1 0;
296
          else if (rst_i)
297
            ctrl <= #1 0;
298
          else if (reg_wacc & (REG_ADR == CTRL_ADR) & ~wbm_busy )
299
            ctrl <= #1 dat_i;
300
          else begin
301
            ctrl[6] <= #1 ctrl[6] & !cbsint_in;
302
            ctrl[5] <= #1 ctrl[5] & !vbsint_in;
303
          end
304 17 rherveille
 
305
 
306
        // generate status register
307 53 rherveille
        always @(posedge clk_i or negedge arst_i)
308
          if (!arst_i)
309
            stat <= #1 0;
310
          else if (rst_i)
311
            stat <= #1 0;
312
          else begin
313
            `ifdef VGA_HWC1
314
                stat[21] <= #1 1'b1;
315
            `else
316
                stat[21] <= #1 1'b0;
317
            `endif
318
            `ifdef VGA_HWC0
319
                stat[20] <= #1 1'b1;
320
            `else
321
                stat[20] <= #1 1'b0;
322
            `endif
323 30 rherveille
 
324 53 rherveille
            stat[17] <= #1 acmp;
325
            stat[16] <= #1 avmp;
326 30 rherveille
 
327 53 rherveille
            if (reg_wacc & (REG_ADR == STAT_ADR) )
328
              begin
329
                  stat[7] <= #1 cbsint_in | (stat[7] & !dat_i[7]);
330
                  stat[6] <= #1 vbsint_in | (stat[6] & !dat_i[6]);
331
                  stat[5] <= #1 hint_in   | (stat[5] & !dat_i[5]);
332
                  stat[4] <= #1 vint_in   | (stat[4] & !dat_i[4]);
333
                  stat[1] <= #1 luint_in  | (stat[3] & !dat_i[1]);
334
                  stat[0] <= #1 sint_in   | (stat[0] & !dat_i[0]);
335
              end
336
            else
337
              begin
338
                  stat[7] <= #1 stat[7] | cbsint_in;
339
                  stat[6] <= #1 stat[6] | vbsint_in;
340
                  stat[5] <= #1 stat[5] | hint_in;
341
                  stat[4] <= #1 stat[4] | vint_in;
342
                  stat[1] <= #1 stat[1] | luint_in;
343
                  stat[0] <= #1 stat[0] | sint_in;
344
              end
345
          end
346 17 rherveille
 
347
 
348
        // decode control register
349 53 rherveille
        assign dvi_odf     = ctrl[29:28];
350 33 rherveille
        assign cursor1_res = ctrl[25];
351
        assign cursor1_en  = ctrl[24];
352
        assign cursor0_res = ctrl[23];
353
        assign cursor0_en  = ctrl[20];
354
        assign bl          = ctrl[15];
355
        assign csl         = ctrl[14];
356
        assign vsl         = ctrl[13];
357
        assign hsl         = ctrl[12];
358
        assign pc          = ctrl[11];
359
        assign cd          = ctrl[10:9];
360
        assign vbl         = ctrl[8:7];
361
        assign cbsw        = ctrl[6];
362
        assign vbsw        = ctrl[5];
363
        assign cbsie       = ctrl[4];
364
        assign vbsie       = ctrl[3];
365
        assign hie         = ctrl[2];
366
        assign vie         = ctrl[1];
367
        assign ven         = ctrl[0];
368 17 rherveille
 
369
        // decode status register
370 19 rherveille
        assign cbsint = stat[7];
371
        assign vbsint = stat[6];
372
        assign hint   = stat[5];
373
        assign vint   = stat[4];
374
        assign luint  = stat[1];
375
        assign sint   = stat[0];
376 17 rherveille
 
377
        // decode Horizontal Timing Register
378
        assign Thsync = htim[31:24];
379
        assign Thgdel = htim[23:16];
380
        assign Thgate = htim[15:0];
381
        assign Thlen  = hvlen[31:16];
382
 
383
        // decode Vertical Timing Register
384
        assign Tvsync = vtim[31:24];
385
        assign Tvgdel = vtim[23:16];
386
        assign Tvgate = vtim[15:0];
387
        assign Tvlen  = hvlen[15:0];
388
 
389 33 rherveille
 
390
        `ifdef VGA_HWC0
391
                // hookup cursor0 color registers
392
                vga_cur_cregs cregs0(
393
                        .clk_i(clk_i),
394
                        .rst_i(rst_i),
395
                        .arst_i(arst_i),
396
                        .hsel_i(cc0_acc),
397
                        .hadr_i(adr_i[4:2]),
398
                        .hwe_i(we_i),
399
                        .hdat_i(dat_i),
400
                        .hdat_o(ccr0_dat_o), // host access
401
                        .hack_o(),
402
                        .cadr_i(cc0_adr_i),
403
                        .cdat_o(cc0_dat_o)   // cursor processor access
404
                );
405
        `else
406 36 rherveille
                assign ccr0_dat_o = 32'h0;
407 39 rherveille
                assign cc0_dat_o = 32'h0;
408 33 rherveille
        `endif
409
 
410
        `ifdef VGA_HWC1
411
                // hookup cursor1 color registers
412
                vga_cur_cregs cregs1(
413
                        .clk_i(clk_i),
414
                        .rst_i(rst_i),
415
                        .arst_i(arst_i),
416
                        .hsel_i(cc1_acc),
417
                        .hadr_i(adr_i[4:2]),
418
                        .hwe_i(we_i),
419
                        .hdat_i(dat_i),
420
                        .hdat_o(ccr1_dat_o), // host access
421
                        .hack_o(),
422
                        .cadr_i(cc1_adr_i),
423
                        .cdat_o(cc1_dat_o)   // cursor processor access
424
                );
425
        `else
426
                assign ccr1_dat_o = 32'h0;
427 39 rherveille
                assign cc1_dat_o = 32'h0;
428 33 rherveille
        `endif
429
 
430 53 rherveille
 
431 17 rherveille
        // assign output
432 53 rherveille
        always @(REG_ADR or ctrl or stat or htim or vtim or hvlen or VBARa or VBARb or acmp or
433 34 rherveille
                cursor0_xy or cursor0_ba or cursor1_xy or cursor1_ba or ccr0_dat_o or ccr1_dat_o)
434 53 rherveille
          casez (REG_ADR) // synopsis full_case parallel_case
435
              CTRL_ADR  : reg_dato = ctrl;
436
              STAT_ADR  : reg_dato = stat;
437
              HTIM_ADR  : reg_dato = htim;
438
              VTIM_ADR  : reg_dato = vtim;
439
              HVLEN_ADR : reg_dato = hvlen;
440
              VBARA_ADR : reg_dato = {VBARa, 2'b0};
441
              VBARB_ADR : reg_dato = {VBARb, 2'b0};
442
              C0XY_ADR  : reg_dato = cursor0_xy;
443
              C0BAR_ADR : reg_dato = {cursor0_ba, 11'h0};
444
              CCR0_ADR  : reg_dato = ccr0_dat_o;
445
              C1XY_ADR  : reg_dato = cursor1_xy;
446
              C1BAR_ADR : reg_dato = {cursor1_ba, 11'h0};
447
              CCR1_ADR  : reg_dato = ccr1_dat_o;
448
              default   : reg_dato = 32'h0000_0000;
449
          endcase
450 17 rherveille
 
451 53 rherveille
        always @(posedge clk_i)
452
          dat_o <= #1 reg_acc ? reg_dato : {8'h0, clut_q};
453 19 rherveille
 
454 17 rherveille
        // generate interrupt request signal
455 53 rherveille
        always @(posedge clk_i)
456
          inta_o <= #1 (hint & hie) | (vint & vie) | (vbsint & vbsie) | (cbsint & cbsie) | luint | sint;
457 17 rherveille
endmodule
458 19 rherveille
 
459 30 rherveille
 
460 36 rherveille
 

powered by: WebSVN 2.1.0

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