vi_controller.v
19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
// Module instances modified by /home/rws/workarea/rf/sw/bbplayer/tools/necprimfix
//
// 9 instances of dfntnb changed to j_dfntnb.
//
/************************************************************************\
| |
| Copyright (C) 1994, Silicon Graphics, Inc. |
| |
| These coded instructions, statements, and computer programs contain |
| unpublished proprietary information of Silicon Graphics, Inc., and |
| are protected by Federal copyright law. They may not be disclosed |
| to third parties or cosied or duplicated in any form, in whole or |
| in part, without the prior written consent of Silicon Graphics, Inc. |
| |
\************************************************************************/
// $Id: vi_controller.v,v 1.13 2003/05/15 01:32:36 whs Exp $
////////////////////////////////////////////////////////////////////////
//
// Project Reality
//
// module: vi_controller
// description: DMA request FSM for video interface.
//
// designer: Phil Gossett
// date: 5/29/95
//
////////////////////////////////////////////////////////////////////////
module vi_controller(clk, reset_l,
dma_grant, dma_start, dma_last,
reg_write_data, reg_address, reg_write_enable, v_current,
block_address, block_length, block_word, bank_sel,
block_start, block_count, read_addr, pre_int,
horizontal_flag, di, dout_a, dout_b,
block_partial, wen_a, wen_b, addr_a, addr_b, do,
dma_address, dma_length, dma_request, block_grant, reg_read_data,
vbus_clock_enable_l, ctrl, origin, width, v_int,
hsync_width, burst_width, vsync_width, burst_start,
v_sync_period, h_sync_period, leap_pattern,
hsync_leap_b, hsync_leap_a, h_video_end, h_video_start,
v_video_end, v_video_start, v_burst_end, v_burst_start,
x_scale, y_scale, x_offset, y_offset, vi_int);
`include "vi.vh"
input clk; // system clock
input reset_l; // system reset_l
input dma_grant; // grant the DMA operation
input dma_start; // start the DMA operation
input dma_last; // end the DMA operation
input [31:0] reg_write_data; // register write data from cbus
input [VI_REG_ADDRESS_SIZE-1:0] reg_address; // register read/write address
input reg_write_enable; // register write enable
input [9:0] v_current; // lines read only reg
input [DRAM_ADDRESS_SIZE-1:0] block_address;
input [DMA_LENGTH_SIZE-1:0] block_length;
input [3:0] block_word; // location in span buffers
input bank_sel; // buffer bank select
input block_start; // treat as consecutive req's
input [1:0] block_count; // number of consec req's - 1
input [3:0] read_addr; // buffer read address
input pre_int; // for synchronization
input horizontal_flag; // for refresh strobe
input [EBUS_DATA_SIZE+DBUS_DATA_SIZE-1:0] di;
input [EBUS_DATA_SIZE+DBUS_DATA_SIZE-1:0] dout_a;
input [EBUS_DATA_SIZE+DBUS_DATA_SIZE-1:0] dout_b;
output block_partial; // some partially covered
output wen_a; // buffer write enable
output wen_b; // buffer write enable
output [3:0] addr_a; //write port address
output [3:0] addr_b; //read port address
output [EBUS_DATA_SIZE+DBUS_DATA_SIZE-1:0] do;
output [DRAM_ADDRESS_SIZE-1:0] dma_address;
output [DMA_LENGTH_SIZE-1:0] dma_length;
output dma_request; // request a DMA read cycle
output block_grant;
output [31:0] reg_read_data; // read data to cbus
output vbus_clock_enable_l;
output [16:0] ctrl; // bits
output [23:0] origin; // bytes
output [11:0] width; // pixels
output [9:0] v_int; // half lines
output [7:0] hsync_width; // pixels
output [7:0] burst_width; // pixels
output [3:0] vsync_width; // pixels
output [9:0] burst_start; // pixels
output [9:0] v_sync_period; // half lines
output [11:0] h_sync_period; // clocks
output [4:0] leap_pattern; // fields
output [11:0] hsync_leap_b; // clocks
output [11:0] hsync_leap_a; // clocks
output [9:0] h_video_end; // pixels
output [9:0] h_video_start; // pixels
output [9:0] v_video_end; // half lines
output [9:0] v_video_start; // half lines
output [9:0] v_burst_end; // half lines
output [9:0] v_burst_start; // half lines
output [11:0] x_scale; // 2.10
output [11:0] y_scale; // 2.10
output [11:0] x_offset; // 2.10
output [11:0] y_offset; // 2.10
output vi_int; // synchronized interrupt
// output registers
reg block_partial;
reg dma_request;
reg block_grant;
reg [16:0] ctrl; // bits
reg [23:0] origin; // bytes
reg [11:0] width; // pixels
reg [9:0] v_int; // half lines
reg [7:0] hsync_width; // pixels
reg [7:0] burst_width; // pixels
reg [3:0] vsync_width; // pixels
reg [9:0] burst_start; // pixels
reg [9:0] v_sync_period; // half lines
reg [11:0] h_sync_period; // clocks
reg [4:0] leap_pattern; // fields
reg [11:0] hsync_leap_b; // clocks
reg [11:0] hsync_leap_a; // clocks
reg [9:0] h_video_end; // pixels
reg [9:0] h_video_start; // pixels
reg [9:0] v_video_end; // half lines
reg [9:0] v_video_start; // half lines
reg [9:0] v_burst_end; // half lines
reg [9:0] v_burst_start; // half lines
reg [11:0] x_scale; // 2.10
reg [11:0] y_scale; // 2.10
reg [11:0] x_offset; // 2.10
reg [11:0] y_offset; // 2.10
reg vi_int;
reg refresh_strobe;
wire block_start_1d; // instanciated synchronizer delay
wire block_start_2d;
wire block_start_3d;
wire pre_int_1d;
wire pre_int_2d;
wire pre_int_3d;
wire horizontal_flag_1d;
wire horizontal_flag_2d;
wire horizontal_flag_3d;
reg refresh_strobe_0d;
reg refresh_strobe_1d;
reg refresh_strobe_2d;
reg refresh_strobe_3d;
reg refresh_strobe_4d;
reg refresh_strobe_5d;
reg block_start_4d; // for edge detectors
reg block_start_4e;
reg pre_int_4d;
reg horizontal_flag_4d;
reg dma_grant_1d; // to widen strobe for other clock domain
reg block_grant_1d; // ditto, for block_grant--rws
reg dma_start_1d; // delay line
reg dma_start_2d;
reg dma_start_3d;
reg dma_start_4d;
reg dma_last_1d;
reg dma_last_2d;
reg dma_last_3d;
reg dma_last_4d;
reg dma_last_5d;
reg [3:0] block_word_1d;
reg [3:0] block_word_2d;
reg [3:0] block_length_1d;
reg [3:0] block_length_2d;
reg [3:0] span_addr; // address for spanbuf read
reg [1:0] span_count; // number of remaining consecutive spans
reg [1:0] dma_count; // number of remaining consecutive dma's
reg [9:0] v_current_safe; // synchronized sample of current line
reg [6:0] test_addr; // spanbuf diagnostic address override
reg [EBUS_DATA_SIZE+DBUS_DATA_SIZE-1:0] staged_data; // diagnostic write data
reg pre_wen_a;
reg pre_wen_b;
reg [3:0] span_length;
reg split_last;
reg granted;
wire split;
wire [DRAM_ADDRESS_SIZE-1:0] block_end;
wire [DRAM_ADDRESS_SIZE-1:0] split_addr;
wire [3:0] paddr_a;
wire [3:0] paddr_b;
wire [31:0] test_data;
wire partial;
assign block_end = block_address + block_length;
assign split_addr = block_end & 24'hFFF800;
assign split = block_address[11] ^ block_end[11];
assign dma_address = (split && split_last) ? split_addr :
block_address;
assign dma_length = split ? (split_last ?
(block_end - split_addr) :
(split_addr - block_address - 1)) :
block_length;
assign partial = (!ctrl[0] && ((di[56:54] != 3'b111) || // 16 bit 5/5/5/3
(di[38:36] != 3'b111) ||
(di[20:18] != 3'b111) ||
(di[2:0] != 3'b111))) ||
( ctrl[0] && ((di[45:43] != 3'b111) || // 32 bit 8/8/8/8
(di[9:7] != 3'b111)));
assign wen_a = !ctrl[7] ? pre_wen_a : ((test_addr[1:0] == 3) &&
!test_addr[6] &&
(reg_address == 15) &&
reg_write_enable);
assign wen_b = !ctrl[7] ? pre_wen_b : ((test_addr[1:0] == 3) &&
test_addr[6] &&
(reg_address == 15) &&
reg_write_enable);
assign paddr_a = span_addr;
assign paddr_b = read_addr;
assign addr_a = !ctrl[7] ? paddr_a : test_addr[5:2];
assign addr_b = !ctrl[7] ? paddr_b : test_addr[5:2];
assign do = !ctrl[7] ? di : staged_data;
assign test_data =
!test_addr[6] ?
(!test_addr[1] ?
(!test_addr[0] ?
{dout_a[ 71: 56], dout_a[ 53: 38]} :
{dout_a[ 35: 20], dout_a[ 17: 2]} ) :
(!test_addr[0] ?
{dout_a[ 55: 54], dout_a[ 37: 36],
dout_a[ 19: 18], dout_a[ 1: 0]} :
0 )) :
(!test_addr[1] ?
(!test_addr[0] ?
{dout_b[ 71: 56], dout_b[ 53: 38]} :
{dout_b[ 35: 20], dout_b[ 17: 2]} ) :
(!test_addr[0] ?
{dout_b[ 55: 54], dout_b[ 37: 36],
dout_b[ 19: 18], dout_b[ 1: 0]} :
0 )) ;
// instanciated synchronizer flops
j_dfntnb bbsy1 (.cp(clk), .d(block_start), .q(block_start_1d));
j_dfntnb bbsy2 (.cp(clk), .d(block_start_1d), .q(block_start_2d));
j_dfntnb bbsy3 (.cp(clk), .d(block_start_2d), .q(block_start_3d));
j_dfntnb hfsy1 (.cp(clk), .d(horizontal_flag), .q(horizontal_flag_1d));
j_dfntnb hfsy2 (.cp(clk), .d(horizontal_flag_1d), .q(horizontal_flag_2d));
j_dfntnb hfsy3 (.cp(clk), .d(horizontal_flag_2d), .q(horizontal_flag_3d));
j_dfntnb pisy1 (.cp(clk), .d(pre_int), .q(pre_int_1d));
j_dfntnb pisy2 (.cp(clk), .d(pre_int_1d), .q(pre_int_2d));
j_dfntnb pisy3 (.cp(clk), .d(pre_int_2d), .q(pre_int_3d));
// state machine
reg [1:0] state;
parameter
STATE_IDLE = 0,
STATE_READ_REQ = 1,
STATE_READ_WAIT = 2,
STATE_READ = 3;
always @(posedge clk)
begin
if (reset_l == 1'b0)
begin
// resetable registers
dma_request <= 0;
block_partial <= 0;
split_last <= 0;
granted <= 0;
pre_wen_a <= 0;
pre_wen_b <= 0;
pre_int_4d <= 0;
block_start_4d <= 0;
block_start_4e <= 0;
ctrl <= 0; // blank video (incl syncs)
hsync_width <= 8'd1; // for refresh
h_sync_period <= 12'd2047; // for refresh
v_int <= 'h3FF;
vi_int <= 0;
refresh_strobe_0d <= 0;
refresh_strobe_1d <= 0;
refresh_strobe_2d <= 0;
refresh_strobe_3d <= 0;
refresh_strobe_4d <= 0;
refresh_strobe_5d <= 0;
refresh_strobe <= 0;
state <= STATE_IDLE;
block_grant <= 0;
block_grant_1d <= 0;
origin <= 0;
width <= 0;
burst_width <= 0;
vsync_width <= 0;
burst_start <= 0;
v_sync_period <= 0;
leap_pattern <= 0;
hsync_leap_b <= 0;
hsync_leap_a <= 0;
h_video_end <= 0;
h_video_start <= 0;
v_video_end <= 0;
v_video_start <= 0;
v_burst_end <= 0;
v_burst_start <= 0;
x_scale <= 0;
y_scale <= 0;
x_offset <= 0;
y_offset <= 0;
horizontal_flag_4d <= 0;
dma_grant_1d <= 0;
dma_start_1d <= 0;
dma_start_2d <= 0;
dma_start_3d <= 0;
dma_start_4d <= 0;
dma_last_1d <= 0;
dma_last_2d <= 0;
dma_last_3d <= 0;
dma_last_4d <= 0;
dma_last_5d <= 0;
block_word_1d <= 0;
block_word_2d <= 0;
block_length_1d <= 0;
block_length_2d <= 0;
span_addr <= 0;
span_count <= 0;
dma_count <= 0;
v_current_safe <= 0;
test_addr <= 0;
staged_data <= 0;
span_length <= 0;
end
else
begin
horizontal_flag_4d <= horizontal_flag_3d;
refresh_strobe_0d <= horizontal_flag_3d && !horizontal_flag_4d;
refresh_strobe_1d <= refresh_strobe_0d;
refresh_strobe_2d <= refresh_strobe_1d;
refresh_strobe_3d <= refresh_strobe_2d;
refresh_strobe_4d <= refresh_strobe_3d;
refresh_strobe_5d <= refresh_strobe_4d;
refresh_strobe <= refresh_strobe_5d;
dma_grant_1d <= dma_grant;
block_grant_1d <= (dma_grant || dma_grant_1d) && (!split || split_last);
block_grant <= block_grant_1d || ((dma_grant || dma_grant_1d) && (!split || split_last));
if (dma_grant)
begin
granted <= 1;
end
else
begin
if (dma_start)
begin
granted <= 0;
end
end
dma_start_1d <= dma_start && granted;
dma_start_2d <= dma_start_1d;
dma_start_3d <= dma_start_2d;
dma_start_4d <= dma_start_3d;
dma_last_1d <= dma_last;
dma_last_2d <= dma_last_1d;
dma_last_3d <= dma_last_2d;
dma_last_4d <= dma_last_3d;
dma_last_5d <= dma_last_4d;
case (state)
STATE_IDLE :
begin
if (block_start_3d && !block_start_4e)
begin
block_start_4e <= 1;
block_partial <= 0;
span_count <= block_count;
state <= STATE_READ_REQ;
end
else
begin
block_start_4e <= block_start_4e && block_start_3d;
end
end
STATE_READ_REQ :
begin
block_start_4e <= block_start_4e && block_start_3d;
if (dma_grant || granted)
begin
state <= STATE_READ_WAIT;
end
end
STATE_READ_WAIT :
begin
block_start_4e <= block_start_4e && block_start_3d;
if (dma_start_4d)
begin
if (!bank_sel)
begin
pre_wen_a <= !ctrl[11];
end
else
begin
pre_wen_b <= !ctrl[11];
end
span_addr <= block_word_2d;
span_length <= block_length_2d;
state <= STATE_READ;
end
end
STATE_READ :
begin
block_start_4e <= block_start_4e && block_start_3d;
span_addr <= span_addr + 1;
span_length <= span_length - 1;
if (partial)
begin
block_partial <= 1;
end
if (dma_last_5d)
begin
pre_wen_a <= 0;
pre_wen_b <= 0;
if (span_length != 0)
begin
state <= STATE_READ_WAIT;
end
else
begin
if (span_count != 0)
begin
span_count <= span_count - 1;
state <= STATE_READ_WAIT;
end
else
begin
state <= STATE_IDLE;
end
end
end
end
endcase
if (dma_grant)
begin
block_word_1d <= block_word + dma_address[6:3] - block_address[6:3];
block_length_1d <= split_last ? (block_end[6:3] - split_addr[6:3]) :
block_length[6:3];
block_start_4d <= block_start_4d && block_start_3d;
if (!split || split_last)
begin
if (dma_count != 0)
begin
dma_count <= dma_count - 1;
end
else
begin
dma_request <= 0;
end
end
end
else
begin
if (block_start_3d && !block_start_4d)
begin
block_start_4d <= 1;
dma_request <= 1;
dma_count <= block_count;
end
else
begin
block_start_4d <= block_start_4d && block_start_3d;
end
end
if (dma_grant_1d)
begin
if (split)
begin
split_last <= !split_last;
end
else
begin
split_last <= 0;
end
end
if (dma_start)
begin
block_word_2d <= block_word_1d;
block_length_2d <= block_length_1d;
end
if (refresh_strobe)
begin
v_current_safe <= v_current;
end
if (reg_write_enable && (reg_address == 4))
begin
vi_int <= 0;
end
else
begin
pre_int_4d <= pre_int_3d;
if (pre_int_3d && !pre_int_4d)
begin
vi_int <= 1;
end
end
if (reg_write_enable)
begin
case (reg_address)
0 : begin
ctrl[16:0] <= reg_write_data[16:0];
end
1 : begin
origin[23:0] <= reg_write_data[23:0];
end
2 : begin
width[11:0] <= reg_write_data[11:0];
end
3 : begin
v_int[9:0] <= reg_write_data[9:0];
end
4 : begin
end
5 : begin
burst_start[9:0] <= reg_write_data[29:20];
vsync_width[3:0] <= reg_write_data[19:16];
burst_width[7:0] <= reg_write_data[15:8];
hsync_width[7:0] <= reg_write_data[7:0];
end
6 : begin
v_sync_period[9:0] <= reg_write_data[9:0];
end
7 : begin
h_sync_period[11:0] <= reg_write_data[11:0];
leap_pattern[4:0] <= reg_write_data[20:16];
end
8 : begin
hsync_leap_b[11:0] <= reg_write_data[11:0];
hsync_leap_a[11:0] <= reg_write_data[27:16];
end
9 : begin
h_video_end[9:0] <= reg_write_data[9:0];
h_video_start[9:0] <= reg_write_data[25:16];
end
10 : begin
v_video_end[9:0] <= reg_write_data[9:0];
v_video_start[9:0] <= reg_write_data[25:16];
end
11 : begin
v_burst_end[9:0] <= reg_write_data[9:0];
v_burst_start[9:0] <= reg_write_data[25:16];
end
12 : begin
x_scale[11:0] <= reg_write_data[11:0];
x_offset[11:0] <= reg_write_data[27:16];
end
13 : begin
y_scale[11:0] <= reg_write_data[11:0];
y_offset[11:0] <= reg_write_data[27:16];
end
14: begin
test_addr <= reg_write_data[6:0];
end
15 : begin
case (test_addr[1:0])
0: begin
{staged_data[ 71: 56],
staged_data[ 53: 38]} <=
reg_write_data;
end
1: begin
{staged_data[ 35: 20],
staged_data[ 17: 2]} <=
reg_write_data;
end
2: begin
{staged_data[ 55: 54],
staged_data[ 37: 36],
staged_data[ 19: 18],
staged_data[ 1: 0]} <=
reg_write_data[7:0];
end
endcase
end
endcase
end
end
end
// register read mux
assign reg_read_data =
reg_address[3] ?
(reg_address[2] ?
(reg_address[1] ?
(reg_address[0] ?
test_data :
test_addr) :
(reg_address[0] ?
{y_offset[11:0],4'b0,
y_scale} :
{x_offset[11:0],4'b0,
x_scale[11:0]})) :
(reg_address[1] ?
(reg_address[0] ?
{v_burst_start[9:0],6'b0,
v_burst_end[9:0]} :
{v_video_start[9:0],6'b0,
v_video_end[9:0]}) :
(reg_address[0] ?
{h_video_start[9:0],6'b0,
h_video_end[9:0]} :
{hsync_leap_a[11:0],4'b0,
hsync_leap_b[11:0]}))) :
(reg_address[2] ?
(reg_address[1] ?
(reg_address[0] ?
{leap_pattern[4:0],4'b0,
h_sync_period[11:0]} :
v_sync_period) :
(reg_address[0] ?
{burst_start[9:0],
vsync_width[3:0],
burst_width[7:0],
hsync_width[7:0]} :
v_current_safe)) :
(reg_address[1] ?
(reg_address[0] ?
v_int :
width) :
(reg_address[0] ?
origin :
ctrl)));
assign vbus_clock_enable_l = ~ctrl[5];
endmodule // vi_controller.v