-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdcmspi.v
142 lines (126 loc) · 3.12 KB
/
dcmspi.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
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
/////////////////////////////////////////////////////
// DCM SPI Controller
/////////////////////////////////////////////////////
`timescale 1ns / 1ps
module dcmspi (
input RST, //Synchronous Reset
input PROGCLK, //SPI clock
input PROGDONE, //DCM is ready to take next command
input DFSLCKD,
input [7:0] M, //DCM M value
input [7:0] D, //DCM D value
input GO, //Go programme the M and D value into DCM(1 cycle pulse)
output reg BUSY,
output reg PROGEN, //SlaveSelect,
output reg PROGDATA //CommandData
);
parameter TCQ = 1;
wire [9:0] mval = {M, 1'b1, 1'b1}; //M command: 11,M0-M7
wire [9:0] dval = {D, 1'b0, 1'b1}; //D command: 10,D0-D7
reg dfslckd_q;
reg dfslckd_rising;
always @ (posedge PROGCLK)
begin
dfslckd_q <=#TCQ DFSLCKD;
dfslckd_rising <=#TCQ !dfslckd_q & DFSLCKD;
end
always @ (posedge PROGCLK)
begin
if(RST || (PROGDONE & dfslckd_rising))
BUSY <=#TCQ 1'b0;
else if (GO)
BUSY <=#TCQ 1'b1;
end
reg [9:0] sndval;
reg sndm = 1'b0;
reg sndd = 1'b0;
wire ddone;
SRL16E VCNT (
.Q(ddone), // SRL data output
.A0(1'b1), // Select[0] input
.A1(1'b0), // Select[1] input
.A2(1'b0), // Select[2] input
.A3(1'b1), // Select[3] input
.CE(1'b1), //clock enable
.CLK(PROGCLK), // Clock input
.D(GO) // SRL data input
);
// The following defparam declaration
defparam VCNT.INIT = 16'h0;
always @ (posedge PROGCLK)
begin
if(RST || ddone)
sndd <=#TCQ 1'b0;
else if(GO)
sndd <=#TCQ 1'b1;
end
//V has been sent now it is M's turn
wire ldm;
SRL16E DMGAP (
.Q(ldm), // SRL data output
.A0(1'b0), // Select[0] input
.A1(1'b0), // Select[1] input
.A2(1'b1), // Select[2] input
.A3(1'b0), // Select[3] input
.CE(1'b1), //clock enable
.CLK(PROGCLK), // Clock input
.D(ddone) // SRL data input
);
// The following defparam declaration
defparam DMGAP.INIT = 16'h0;
wire mdone;
SRL16E MCNT (
.Q(mdone), // SRL data output
.A0(1'b1), // Select[0] input
.A1(1'b0), // Select[1] input
.A2(1'b0), // Select[2] input
.A3(1'b1), // Select[3] input
.CE(1'b1), //clock enable
.CLK(PROGCLK), // Clock input
.D(ldm) // SRL data input
);
// The following defparam declaration
defparam MCNT.INIT = 16'h0;
always @ (posedge PROGCLK)
begin
if(RST || mdone)
sndm <=#TCQ 1'b0;
else if(ldm)
sndm <=#TCQ 1'b1;
end
wire gocmd;
SRL16E GOGAP (
.Q(gocmd), // SRL data output
.A0(1'b0), // Select[0] input
.A1(1'b0), // Select[1] input
.A2(1'b1), // Select[2] input
.A3(1'b0), // Select[3] input
.CE(1'b1), //clock enable
.CLK(PROGCLK), // Clock input
.D(mdone) // SRL data input
);
// The following defparam declaration
defparam GOGAP.INIT = 16'h0;
always @ (posedge PROGCLK)
begin
if(RST)
sndval <=#TCQ 10'h0;
else if(GO) //send D first
sndval <=#TCQ dval;
else if(ldm)
sndval <=#TCQ mval;
else if(sndm || sndd)
sndval <=#TCQ sndval >> 1;
end
always @ (posedge PROGCLK)
begin
PROGEN <=#TCQ sndd | sndm | gocmd;
end
always @ (posedge PROGCLK)
begin
if(sndm || sndd)
PROGDATA <=#TCQ sndval[0];
else
PROGDATA <=#TCQ 1'b0;
end
endmodule