-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvcmdv1test.v
105 lines (86 loc) · 2.35 KB
/
vcmdv1test.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
`timescale 1ns/1ps
`include "spi.v"
`include "vcmdv1.v"
module vcmdv2test;
// SPI
// Inputs
reg Sclk;
reg Mosi;
reg CSel;
// Outputs
wire DataRecv;
wire [7:0] DataOut;
// Instantiate the Unit Under Test (UUT)
spi SPI (
.Sclk(Sclk),
.Mosi(Mosi),
.CSel(CSel),
.ByteRecv(DataRecv),
.ByteOut(DataOut)
);
task send_byte(input time PulseTime, input [7:0] Byte);
begin
CSel = 1'b0;
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);
CSel = 1'b1;
end
endtask
task send_pulse(input time PulseTime, input Data);
begin
Mosi = Data;
Sclk = 1'b1;
#PulseTime;
Sclk = 1'b0;
#PulseTime;
end
endtask
// VCMD
// Inputs
reg [1:0] DataIndex;
// Outputs
wire DataClkOut;
wire[17:0] CmdAddr;
wire CmdDataRdy;
// Instantiate the Unit Under Test (UUT)
vcmdv1 #(
.AWIDTH(18),
.DWIDTH(8)
) UUT (
.ByteClkIn(DataRecv),
.ByteIn(DataOut),
.DataModeEnable(1'b1),
.DataClkOut(DataClkOut),
.AddrOut(CmdAddr)
);
// frequency = 500 / SpiDelay MHz
localparam SpiDelay = 10; // ns
initial begin
// Initialize Inputs
Sclk = 0;
Mosi = 0;
CSel = 0;
DataIndex = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
// Very fast SPI clock (50MHz)
send_byte(SpiDelay, 8'b01000001);
send_byte(SpiDelay, 8'b11000000);
send_byte(SpiDelay, 8'b11000000);
send_byte(SpiDelay, 8'b11000000);
// Small delay between next pixel write
#160;
// Another byte at next location
send_byte(SpiDelay, 8'b01000001);
send_byte(SpiDelay, 8'b00000011);
send_byte(SpiDelay, 8'b00000011);
send_byte(SpiDelay, 8'b00000011);
end
endmodule