-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvgawritetest.v
117 lines (98 loc) · 2.15 KB
/
vgawritetest.v
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
`timescale 1ns / 1ps
module vgawritetest;
// Inputs
reg MainClkSrc;
reg Sclk;
reg Mosi;
reg CSel;
// Outputs
wire [18:0] MemAddr;
wire MemWE;
wire MemOE;
wire [5:0] ColorOut;
wire HsyncOut;
wire VsyncOut;
reg [8:0] Counter = 8'h00;
// Bidirs
wire [7:0] MemData;
assign MemData = Counter[8:1];
// Instantiate the Unit Under Test (UUT)
vga UUT (
.MainClkSrc(MainClkSrc),
.MemAddr(MemAddr),
.MemData(MemData),
.MemWE(MemWE),
.MemOE(MemOE),
.ColorOut(ColorOut),
.HsyncOut(HsyncOut),
.VsyncOut(VsyncOut),
.Sclk(Sclk),
.Mosi(Mosi),
.CSel(CSel)
);
task send_byte(input time PulseTime, input [7:0] Byte);
begin
CSel = 1'b0;
// for (j = 0; j < 8; j = j + 1)
#PulseTime;
send_pulse(PulseTime, (Byte>>7) & 1);
send_pulse(PulseTime, (Byte>>6) & 1);
send_pulse(PulseTime, (Byte>>5) & 1);
send_pulse(PulseTime, (Byte>>4) & 1);
send_pulse(PulseTime, (Byte>>3) & 1);
send_pulse(PulseTime, (Byte>>2) & 1);
send_pulse(PulseTime, (Byte>>1) & 1);
send_pulse(PulseTime, (Byte>>0) & 1);
Sclk = 1'b0;
#PulseTime;
CSel = 1'b1;
#PulseTime;
end
endtask
task send_pulse(input time PulseTime, input Data);
begin
Mosi = Data;
Sclk = 1'b0;
#PulseTime;
Sclk = 1'b1;
#PulseTime;
end
endtask
initial begin
// Initialize Clock
MainClkSrc = 0;
forever #5 MainClkSrc = ~MainClkSrc;
end
integer i;
initial begin
// Initialize Inputs
Sclk = 0;
Mosi = 0;
CSel = 0;
// Wait 100 ns for global reset to finish
#500;
// Add stimulus here
// Very fast SPI clock (100MHz)
send_byte(10, 8'h20);
send_byte(10, 8'b11000000);
send_byte(10, 8'h20);
send_byte(10, 8'b11000000);
send_byte(10, 8'h20);
send_byte(10, 8'b11000000);
for (i = 0; i < 640; i = i + 1) begin
// Small delay between next pixel write
#160;
send_byte(10, 8'h11);
send_byte(10, 8'h00);
send_byte(10, 8'h10);
// Another byte at next location
send_byte(10, 8'h20);
send_byte(10, i);
send_byte(10, 8'h20);
send_byte(10, i);
send_byte(10, 8'h20);
send_byte(10, i);
end
end
always @(posedge MainClkSrc) Counter <= Counter + 1'b1;
endmodule