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

Subversion Repositories rtfbitmapcontroller

[/] [rtfbitmapcontroller/] [trunk/] [rtl/] [verilog/] [rtfBitmapController1364x768.v] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 robfinch
// ============================================================================
2
//  Bitmap Controller (1364h x 768v x 8bpp):
3
//  - Displays a bitmap from memory.
4
//  - the video mode timing to be 1366x768
5
//
6
//
7
//      (C) 2008-2012  Robert Finch
8
//      robfinch<remove>@opencores.org
9
//
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
//
25
//  The default base screen address is:
26
//              $200000 - the second 2MiB of RAM
27
//
28
//
29
//      Verilog 1995
30
//
31
// ============================================================================
32
 
33
module rtfBitmapController1364x768(
34
        rst_i, clk_i, bte_o, cti_o, bl_o, cyc_o, stb_o, ack_i, we_o, sel_o, adr_o, dat_i, dat_o,
35
        vclk, eol, eof, blank, rgbo, page
36
);
37
parameter BM_BASE_ADDR1 = 32'h0020_0000;
38
parameter BM_BASE_ADDR2 = 32'h0040_0000;
39
 
40
// SYSCON
41
input rst_i;                            // system reset
42
input clk_i;                            // system bus interface clock
43
 
44
// Video Master Port
45
// Used to read memory via burst access
46
output [1:0] bte_o;
47
output [2:0] cti_o;
48
output [5:0] bl_o;
49
output cyc_o;                   // video burst request
50
output stb_o;
51
input  ack_i;                   // vid_acknowledge from memory
52
output we_o;
53
output [ 3:0] sel_o;
54
output [31:0] adr_o;     // address for memory access
55
input  [31:0] dat_i;     // memory data input
56
output [31:0] dat_o;
57
 
58
// Video
59
input vclk;                             // Video clock 73.529 MHz
60
input eol;                              // end of scan line
61
input eof;                              // end of frame
62
input blank;                    // blank the output
63
output [7:0] rgbo;               // 8-bit RGB output
64
reg [7:0] rgbo;
65
 
66
input page;                             // which page to display
67
 
68
 
69
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70
// IO registers
71
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72
reg [1:0] bte_o;
73
reg [2:0] cti_o;
74
reg [5:0] bl_o;
75
reg sync_o;
76
reg cyc_o;
77
reg stb_o;
78
reg we_o;
79
reg [3:0] sel_o;
80
reg [31:0] adr_o;
81
reg [31:0] dat_o;
82
 
83
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
85
wire [11:0] hctr;                // horizontal reference counter
86
wire [11:0] hctr1 = hctr - 12'd434;
87
wire [11:0] vctr;                // vertical reference counter
88
wire [11:0] vctr1 = vctr - 12'd27;
89
reg [31:0] baseAddr;     // base address register
90
wire [7:0] rgbo1;
91
reg [11:0] pixelRow;
92
reg [11:0] pixelCol;
93
 
94
always @(page)
95
        baseAddr = page ? BM_BASE_ADDR2 : BM_BASE_ADDR1;
96
 
97
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98
// Horizontal and Vertical timing reference counters
99
// - The memory fetch address is determined from these counters.
100
// - The counters are setup with negative values so that the zero
101
//   point coincides with the top left of the display.
102
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103
 
104
counter #(12) u1 (.rst(1'b0), .clk(vclk), .ce(1'b1), .ld(eol), .d(12'h1), .q(hctr));
105
counter #(12) u2 (.rst(1'b0), .clk(vclk), .ce(eol),  .ld(eof), .d(12'h1), .q(vctr));
106
 
107
// Pixel row and column are derived from the horizontal and vertical counts.
108
 
109
always @(vctr1)
110
        pixelRow = vctr1[11:0];
111
always @(hctr1)
112
        pixelCol = hctr1[11:0];
113
 
114
 
115
wire vFetch = vctr1 < 12'd768;
116
 
117
// Video Request Block
118
// 1364x768
119
// There are 1800 clock available on a scan line. For simplicity we
120
// use only 1364 of 1366 pixel on the display. 1364 is a multiple
121
// of four bytes, which is the unit being burst fetched.
122
// - 1364 =21*64+20 bytes
123
// 22 burst accesses are required, with the last burst being only for
124
//  5 data words (20 bytes). This means we have a budget of about 80
125
// pixel clock cycles per burst. (1800/22) This works out to about 31
126
// system clocks. The pixel to system clock ratio is about 2.58:1.
127
// Burst length is set to 16. The burst controller should be able
128
// to fetch a word (32 bits) every clock cycle, plus some overhead
129
// for memory latency. The memory clock is much faster than the system
130
// clock. 
131
// - 
132
// - Issue a request for access to memory every 80 clock cycles
133
// - Reset the request flag once an access has been initiated.
134
// - 1364 bytes (pixels) are read per scan line
135
// - It takes about ___ clock cycles @ 33 MHz to access 64 bytes of data
136
//   through the memory contoller.
137
 
138
reg [5:0] vreq;
139
 
140
// Must be vclk. vid_req will be active for numerous clock cycles as
141
// a burst type fetch is used. The ftch and vFetch may only be
142
// active for a single video clock cycle. vclk must be used so these
143
// signals are not missed due to a clock domain crossing. We luck
144
// out here because of the length of time vid_req is active.
145
//
146
always @(posedge vclk)
147
begin
148
        if (vFetch) begin
149
                if (hctr==12'd16 ) vreq <= 6'b100000;
150
                if (hctr==12'd96 ) vreq <= 6'b100001;
151
                if (hctr==12'd176) vreq <= 6'b100010;
152
                if (hctr==12'd256) vreq <= 6'b100011;
153
                if (hctr==12'd336) vreq <= 6'b100100;
154
                if (hctr==12'd416) vreq <= 6'b100101;
155
                if (hctr==12'd496) vreq <= 6'b100110;
156
                if (hctr==12'd576) vreq <= 6'b100111;
157
                if (hctr==12'd656) vreq <= 6'b101000;
158
                if (hctr==12'd736) vreq <= 6'b101001;
159
                if (hctr==12'd816) vreq <= 6'b101010;
160
                if (hctr==12'd896) vreq <= 6'b101011;
161
                if (hctr==12'd976) vreq <= 6'b101100;
162
                if (hctr==12'd1056) vreq <= 6'b101101;
163
                if (hctr==12'd1136) vreq <= 6'b101110;
164
                if (hctr==12'd1216) vreq <= 6'b101111;
165
                if (hctr==12'd1296) vreq <= 6'b110000;
166
                if (hctr==12'd1376) vreq <= 6'b110001;
167
                if (hctr==12'd1456) vreq <= 6'b110010;
168
                if (hctr==12'd1536) vreq <= 6'b110011;
169
                if (hctr==12'd1616) vreq <= 6'b110100;
170
                if (hctr==12'd1696) vreq <= 6'b110101;
171
        end
172
        if (cyc_o) vreq <= 6'b000000;
173
end
174
 
175
// Cross the clock domain with the request signal
176
reg do_cyc;
177
always @(posedge clk_i)
178
        do_cyc <= vreq[5];
179
 
180
wire[23:0] rowOffset = pixelRow * 11'd1364;
181
reg [11:0] fetchCol;
182
 
183
// - read from assigned video memory address, using burst mode reads
184
// - 64 pixels at a time are read
185
// - video data is fetched one pixel row in advance
186
//
187
reg [4:0] bcnt;
188
always @(posedge clk_i)
189
if (rst_i) begin
190
        bte_o <= 2'b00;         // linear burst
191
        cti_o <= 3'b000;        // classic cycle
192
        bl_o <= 6'd0;
193
        cyc_o <= 1'b0;
194
        stb_o <= 1'b0;
195
        sel_o <= 4'b0000;
196
        we_o <= 1'b0;
197
        adr_o <= 32'h0000_0000;
198
        dat_o <= 32'h0000_0000;
199
        fetchCol <= 9'd0;
200
        bcnt <= 4'd0;
201
end
202
else begin
203
        if (do_cyc & !cyc_o) begin
204
                cti_o <= 3'b010;        // incrementing burst cycle
205
                cyc_o <= 1'b1;
206
                stb_o <= 1'b1;
207
                sel_o <= 4'b1111;
208
                bcnt <= 5'd0;
209
                bl_o <= vreq==6'b110101 ? 6'd5: 6'd16;
210
                fetchCol <= {vreq[4:0],6'h00};
211
                adr_o <= baseAddr + rowOffset + 12'd1364 + {vreq[4:0],6'h00};
212
        end
213
        if (cyc_o & ack_i) begin
214
                fetchCol <= fetchCol + 12'd4;
215
                bcnt <= bcnt + 5'd1;
216
                if (bl_o==6'd5 ? bcnt==5'd3 : bcnt==5'd14)
217
                        cti_o <= 3'b111;        // end of burst
218
                if (bl_o==6'd5 ? bcnt==5'd4 : bcnt==5'd15) begin
219
                        cti_o <= 3'b000;        // classic cycles again
220
                        bl_o <= 6'd0;
221
                        cyc_o <= 1'b0;
222
                        stb_o <= 1'b0;
223
                        sel_o <= 4'b0000;
224
                        adr_o <= 32'h0000_0000;
225
                end
226
        end
227
end
228
 
229
 
230
always @(posedge vclk)
231
        rgbo <= rgbo1;
232
 
233
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234
// Video Line Buffer
235
// - gets written in bursts, but read continuously
236
// - buffer is used as two halves - one half is displayed (read) while
237
//   the other is fetched (write).
238
// - only the lower eleven bits of the address are used as an index,
239
//   these bits will match with the addresses generated by the burst
240
//   controller above.
241
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
242
 
243
// Storage for 2048x8 bit pixels (2048x8 data)
244
rtfBitmapLineBuffer u3
245
(
246
  .clka(clk_i), // input clka
247
  .ena(cyc_o), // input ena
248
  .wea(ack_i), // input [0 : 0] wea
249
  .addra({~pixelRow[0],fetchCol[10:2]}), // input [9 : 0] addra
250
  .dina(dat_i), // input [31 : 0] dina
251
 
252
  .clkb(vclk), // input clkb
253
  .addrb({pixelRow[0],pixelCol[10:2],~pixelCol[1:0]}), // input [11 : 0] addrb
254
  .doutb(rgbo1) // output [7 : 0] doutb
255
);
256
 
257
endmodule

powered by: WebSVN 2.1.0

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