-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmmcm_drp.v
619 lines (512 loc) · 24 KB
/
mmcm_drp.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
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
///////////////////////////////////////////////////////////////////////////////
//
// Company: Xilinx
// Engineer: Karl Kurbjun
// Date: 12/7/2009
// Design Name: MMCM DRP
// Module Name: mmcm_drp.v
// Version: 1.2
// Target Devices: Virtex 6 Family
// Tool versions: L.50 (lin)
// Description: This calls the DRP register calculation functions and
// provides a state machine to perform MMCM reconfiguration
// based on the calulated values stored in a initialized
// ROM.
//
// Disclaimer: XILINX IS PROVIDING THIS DESIGN, CODE, OR
// INFORMATION "AS IS" SOLELY FOR USE IN DEVELOPING
// PROGRAMS AND SOLUTIONS FOR XILINX DEVICES. BY
// PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
// ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
// APPLICATION OR STANDARD, XILINX IS MAKING NO
// REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
// FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE
// RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY
// REQUIRE FOR YOUR IMPLEMENTATION. XILINX
// EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH
// RESPECT TO THE ADEQUACY OF THE IMPLEMENTATION,
// INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
// REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
// FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
//
// (c) Copyright 2009-2010 Xilinx, Inc.
// All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////
`timescale 1ps/1ps
module mmcm_drp
#(
//***********************************************************************
// State 1 Parameters - These are for the first reconfiguration state.
//***********************************************************************
// These parameters have an effect on the feedback path. A change on
// these parameters will effect all of the clock outputs.
//
// The paramaters are composed of:
// _MULT: This can be from 5 to 64. It has an effect on the VCO
// frequency which consequently, effects all of the clock
// outputs.
// _PHASE: This is the phase multiplied by 1000. For example if
// a phase of 24.567 deg was desired the input value would be
// 24567. The range for the phase is from -360000 to 360000.
parameter S1_CLKFBOUT_MULT = 5,
parameter S1_CLKFBOUT_PHASE = 0,
// The bandwidth parameter effects the phase error and the jitter filter
// capability of the MMCM. For more information on this parameter see the
// Device user guide.
parameter S1_BANDWIDTH = "LOW",
// The divclk parameter allows th einput clock to be divided before it
// reaches the phase and frequency comparitor. This can be set between
// 1 and 128.
parameter S1_DIVCLK_DIVIDE = 1,
// The following parameters describe the configuration that each clock
// output should have once the reconfiguration for state one has
// completed.
//
// The parameters are composed of:
// _DIVIDE: This can be from 1 to 128
// _PHASE: This is the phase multiplied by 1000. For example if
// a phase of 24.567 deg was desired the input value would be
// 24567. The range for the phase is from -360000 to 360000.
// _DUTY: This is the duty cycle multiplied by 100,000. For example if
// a duty cycle of .24567 was desired the input would be
// 24567.
parameter S1_CLKOUT0_DIVIDE = 1,
parameter S1_CLKOUT0_PHASE = 0,
parameter S1_CLKOUT0_DUTY = 50000,
parameter S1_CLKOUT1_DIVIDE = 1,
parameter S1_CLKOUT1_PHASE = 0,
parameter S1_CLKOUT1_DUTY = 50000,
parameter S1_CLKOUT2_DIVIDE = 1,
parameter S1_CLKOUT2_PHASE = 0,
parameter S1_CLKOUT2_DUTY = 50000,
parameter S1_CLKOUT3_DIVIDE = 1,
parameter S1_CLKOUT3_PHASE = 0,
parameter S1_CLKOUT3_DUTY = 50000,
parameter S1_CLKOUT4_DIVIDE = 1,
parameter S1_CLKOUT4_PHASE = 0,
parameter S1_CLKOUT4_DUTY = 50000,
parameter S1_CLKOUT5_DIVIDE = 1,
parameter S1_CLKOUT5_PHASE = 0,
parameter S1_CLKOUT5_DUTY = 50000,
parameter S1_CLKOUT6_DIVIDE = 1,
parameter S1_CLKOUT6_PHASE = 0,
parameter S1_CLKOUT6_DUTY = 50000,
//***********************************************************************
// State 2 Parameters - These are for the second reconfiguration state.
//***********************************************************************
// These parameters have an effect on the feedback path. A change on
// these parameters will effect all of the clock outputs.
//
// The paramaters are composed of:
// _MULT: This can be from 5 to 64. It has an effect on the VCO
// frequency which consequently, effects all of the clock
// outputs.
// _PHASE: This is the phase multiplied by 1000. For example if
// a phase of 24.567 deg was desired the input value would be
// 24567. The range for the phase is from -360000 to 360000.
parameter S2_CLKFBOUT_MULT = 5,
parameter S2_CLKFBOUT_PHASE = 0,
// The bandwidth parameter effects the phase error and the jitter filter
// capability of the MMCM. For more information on this parameter see the
// Device user guide.
parameter S2_BANDWIDTH = "LOW",
// The divclk parameter allows th einput clock to be divided before it
// reaches the phase and frequency comparitor. This can be set between
// 1 and 128.
parameter S2_DIVCLK_DIVIDE = 1,
// The following parameters describe the configuration that each clock
// output should have once the reconfiguration for state one has
// completed.
//
// The parameters are composed of:
// _DIVIDE: This can be from 1 to 128
// _PHASE: This is the phase multiplied by 1000. For example if
// a phase of 24.567 deg was desired the input value would be
// 24567. The range for the phase is from -360000 to 360000
// _DUTY: This is the duty cycle multiplied by 100,000. For example if
// a duty cycle of .24567 was desired the input would be
// 24567.
parameter S2_CLKOUT0_DIVIDE = 1,
parameter S2_CLKOUT0_PHASE = 0,
parameter S2_CLKOUT0_DUTY = 50000,
parameter S2_CLKOUT1_DIVIDE = 1,
parameter S2_CLKOUT1_PHASE = 0,
parameter S2_CLKOUT1_DUTY = 50000,
parameter S2_CLKOUT2_DIVIDE = 1,
parameter S2_CLKOUT2_PHASE = 0,
parameter S2_CLKOUT2_DUTY = 50000,
parameter S2_CLKOUT3_DIVIDE = 1,
parameter S2_CLKOUT3_PHASE = 0,
parameter S2_CLKOUT3_DUTY = 50000,
parameter S2_CLKOUT4_DIVIDE = 1,
parameter S2_CLKOUT4_PHASE = 0,
parameter S2_CLKOUT4_DUTY = 50000,
parameter S2_CLKOUT5_DIVIDE = 1,
parameter S2_CLKOUT5_PHASE = 0,
parameter S2_CLKOUT5_DUTY = 50000,
parameter S2_CLKOUT6_DIVIDE = 1,
parameter S2_CLKOUT6_PHASE = 0,
parameter S2_CLKOUT6_DUTY = 50000
) (
// These signals are controlled by user logic interface and are covered
// in more detail within the XAPP.
input SADDR,
input SEN,
input SCLK,
input RST,
output reg SRDY,
// These signals are to be connected to the MMCM_ADV by port name.
// Their use matches the MMCM port description in the Device User Guide.
input [15:0] DO,
input DRDY,
input LOCKED,
output reg DWE,
output reg DEN,
output reg [6:0] DADDR,
output reg [15:0] DI,
output DCLK,
output reg RST_MMCM
);
// 100 ps delay for behavioral simulations
localparam TCQ = 100;
// Make sure the memory is implemented as distributed
(* rom_style = "distributed" *)
reg [38:0] rom [63:0]; // 39 bit word 64 words deep
reg [5:0] rom_addr;
reg [38:0] rom_do;
reg next_srdy;
reg [5:0] next_rom_addr;
reg [6:0] next_daddr;
reg next_dwe;
reg next_den;
reg next_rst_mmcm;
reg [15:0] next_di;
// Integer used to initialize remainder of unused ROM
integer ii;
// Pass SCLK to DCLK for the MMCM
assign DCLK = SCLK;
// Include the MMCM reconfiguration functions. This contains the constant
// functions that are used in the calculations below. This file is
// required.
`include "mmcm_drp_func.h"
//**************************************************************************
// State 1 Calculations
//**************************************************************************
// Please see header for infor
localparam [37:0] S1_CLKFBOUT =
mmcm_count_calc(S1_CLKFBOUT_MULT, S1_CLKFBOUT_PHASE, 50000);
localparam [9:0] S1_DIGITAL_FILT =
mmcm_filter_lookup(S1_CLKFBOUT_MULT, S1_BANDWIDTH);
localparam [39:0] S1_LOCK =
mmcm_lock_lookup(S1_CLKFBOUT_MULT);
localparam [37:0] S1_DIVCLK =
mmcm_count_calc(S1_DIVCLK_DIVIDE, 0, 50000);
localparam [37:0] S1_CLKOUT0 =
mmcm_count_calc(S1_CLKOUT0_DIVIDE, S1_CLKOUT0_PHASE, S1_CLKOUT0_DUTY);
localparam [37:0] S1_CLKOUT1 =
mmcm_count_calc(S1_CLKOUT1_DIVIDE, S1_CLKOUT1_PHASE, S1_CLKOUT1_DUTY);
localparam [37:0] S1_CLKOUT2 =
mmcm_count_calc(S1_CLKOUT2_DIVIDE, S1_CLKOUT2_PHASE, S1_CLKOUT2_DUTY);
localparam [37:0] S1_CLKOUT3 =
mmcm_count_calc(S1_CLKOUT3_DIVIDE, S1_CLKOUT3_PHASE, S1_CLKOUT3_DUTY);
localparam [37:0] S1_CLKOUT4 =
mmcm_count_calc(S1_CLKOUT4_DIVIDE, S1_CLKOUT4_PHASE, S1_CLKOUT4_DUTY);
localparam [37:0] S1_CLKOUT5 =
mmcm_count_calc(S1_CLKOUT5_DIVIDE, S1_CLKOUT5_PHASE, S1_CLKOUT5_DUTY);
localparam [37:0] S1_CLKOUT6 =
mmcm_count_calc(S1_CLKOUT6_DIVIDE, S1_CLKOUT6_PHASE, S1_CLKOUT6_DUTY);
//**************************************************************************
// State 2 Calculations
//**************************************************************************
localparam [37:0] S2_CLKFBOUT =
mmcm_count_calc(S2_CLKFBOUT_MULT, S2_CLKFBOUT_PHASE, 50000);
localparam [9:0] S2_DIGITAL_FILT =
mmcm_filter_lookup(S2_CLKFBOUT_MULT, S2_BANDWIDTH);
localparam [39:0] S2_LOCK =
mmcm_lock_lookup(S2_CLKFBOUT_MULT);
localparam [37:0] S2_DIVCLK =
mmcm_count_calc(S2_DIVCLK_DIVIDE, 0, 50000);
localparam [37:0] S2_CLKOUT0 =
mmcm_count_calc(S2_CLKOUT0_DIVIDE, S2_CLKOUT0_PHASE, S2_CLKOUT0_DUTY);
localparam [37:0] S2_CLKOUT1 =
mmcm_count_calc(S2_CLKOUT1_DIVIDE, S2_CLKOUT1_PHASE, S2_CLKOUT1_DUTY);
localparam [37:0] S2_CLKOUT2 =
mmcm_count_calc(S2_CLKOUT2_DIVIDE, S2_CLKOUT2_PHASE, S2_CLKOUT2_DUTY);
localparam [37:0] S2_CLKOUT3 =
mmcm_count_calc(S2_CLKOUT3_DIVIDE, S2_CLKOUT3_PHASE, S2_CLKOUT3_DUTY);
localparam [37:0] S2_CLKOUT4 =
mmcm_count_calc(S2_CLKOUT4_DIVIDE, S2_CLKOUT4_PHASE, S2_CLKOUT4_DUTY);
localparam [37:0] S2_CLKOUT5 =
mmcm_count_calc(S2_CLKOUT5_DIVIDE, S2_CLKOUT5_PHASE, S2_CLKOUT5_DUTY);
localparam [37:0] S2_CLKOUT6 =
mmcm_count_calc(S2_CLKOUT6_DIVIDE, S2_CLKOUT6_PHASE, S2_CLKOUT6_DUTY);
initial begin
// rom entries contain (in order) the address, a bitmask, and a bitset
//***********************************************************************
// State 1 Initialization
//***********************************************************************
// Store the power bits
rom[0] = {7'h28, 16'h0000, 16'hFFFF};
// Store CLKOUT0 divide and phase
rom[1] = {7'h08, 16'h1000, S1_CLKOUT0[15:0]};
rom[2] = {7'h09, 16'hFC00, S1_CLKOUT0[31:16]};
// Store CLKOUT1 divide and phase
rom[3] = {7'h0A, 16'h1000, S1_CLKOUT1[15:0]};
rom[4] = {7'h0B, 16'hFC00, S1_CLKOUT1[31:16]};
// Store CLKOUT2 divide and phase
rom[5] = {7'h0C, 16'h1000, S1_CLKOUT2[15:0]};
rom[6] = {7'h0D, 16'hFC00, S1_CLKOUT2[31:16]};
// Store CLKOUT3 divide and phase
rom[7] = {7'h0E, 16'h1000, S1_CLKOUT3[15:0]};
rom[8] = {7'h0F, 16'hFC00, S1_CLKOUT3[31:16]};
// Store CLKOUT4 divide and phase
rom[9] = {7'h10, 16'h1000, S1_CLKOUT4[15:0]};
rom[10] = {7'h11, 16'hFC00, S1_CLKOUT4[31:16]};
// Store CLKOUT5 divide and phase
rom[11] = {7'h06, 16'h1000, S1_CLKOUT5[15:0]};
rom[12] = {7'h07, 16'hFC00, S1_CLKOUT5[31:16]};
// Store CLKOUT6 divide and phase
rom[13] = {7'h12, 16'h1000, S1_CLKOUT6[15:0]};
rom[14] = {7'h13, 16'hFC00, S1_CLKOUT6[31:16]};
// Store the input divider
rom[15] = {7'h16, 16'hC000, {2'h0, S1_DIVCLK[23:22], S1_DIVCLK[11:0]} };
// Store the feedback divide and phase
rom[16] = {7'h14, 16'h1000, S1_CLKFBOUT[15:0]};
rom[17] = {7'h15, 16'hFC00, S1_CLKFBOUT[31:16]};
// Store the lock settings
rom[18] = {7'h18, 16'hFC00, {6'h00, S1_LOCK[29:20]} };
rom[19] = {7'h19, 16'h8000, {1'b0 , S1_LOCK[34:30], S1_LOCK[9:0]} };
rom[20] = {7'h1A, 16'h8000, {1'b0 , S1_LOCK[39:35], S1_LOCK[19:10]} };
// Store the filter settings
rom[21] = {7'h4E, 16'h66FF,
S1_DIGITAL_FILT[9], 2'h0, S1_DIGITAL_FILT[8:7], 2'h0,
S1_DIGITAL_FILT[6], 8'h00 };
rom[22] = {7'h4F, 16'h666F,
S1_DIGITAL_FILT[5], 2'h0, S1_DIGITAL_FILT[4:3], 2'h0,
S1_DIGITAL_FILT[2:1], 2'h0, S1_DIGITAL_FILT[0], 4'h0 };
//***********************************************************************
// State 2 Initialization
//***********************************************************************
// Store the power bits
rom[23] = {7'h28, 16'h0000, 16'hFFFF};
// Store CLKOUT0 divide and phase
rom[24] = {7'h08, 16'h1000, S2_CLKOUT0[15:0]};
rom[25] = {7'h09, 16'hFC00, S2_CLKOUT0[31:16]};
// Store CLKOUT1 divide and phase
rom[26] = {7'h0A, 16'h1000, S2_CLKOUT1[15:0]};
rom[27] = {7'h0B, 16'hFC00, S2_CLKOUT1[31:16]};
// Store CLKOUT2 divide and phase
rom[28] = {7'h0C, 16'h1000, S2_CLKOUT2[15:0]};
rom[29] = {7'h0D, 16'hFC00, S2_CLKOUT2[31:16]};
// Store CLKOUT3 divide and phase
rom[30] = {7'h0E, 16'h1000, S2_CLKOUT3[15:0]};
rom[31] = {7'h0F, 16'hFC00, S2_CLKOUT3[31:16]};
// Store CLKOUT4 divide and phase
rom[32] = {7'h10, 16'h1000, S2_CLKOUT4[15:0]};
rom[33] = {7'h11, 16'hFC00, S2_CLKOUT4[31:16]};
// Store CLKOUT5 divide and phase
rom[34] = {7'h06, 16'h1000, S2_CLKOUT5[15:0]};
rom[35] = {7'h07, 16'hFC00, S2_CLKOUT5[31:16]};
// Store CLKOUT6 divide and phase
rom[36] = {7'h12, 16'h1000, S2_CLKOUT6[15:0]};
rom[37] = {7'h13, 16'hFC00, S2_CLKOUT6[31:16]};
// Store the input divider
rom[38] = {7'h16, 16'hC000, {2'h0, S2_DIVCLK[23:22], S2_DIVCLK[11:0]} };
// Store the feedback divide and phase
rom[39] = {7'h14, 16'h1000, S2_CLKFBOUT[15:0]};
rom[40] = {7'h15, 16'hFC00, S2_CLKFBOUT[31:16]};
// Store the lock settings
rom[41] = {7'h18, 16'hFC00, {6'h00, S2_LOCK[29:20]} };
rom[42] = {7'h19, 16'h8000, {1'b0 , S2_LOCK[34:30], S2_LOCK[9:0]} };
rom[43] = {7'h1A, 16'h8000, {1'b0 , S2_LOCK[39:35], S2_LOCK[19:10]} };
// Store the filter settings
rom[44] = {7'h4E, 16'h66FF,
S2_DIGITAL_FILT[9], 2'h0, S2_DIGITAL_FILT[8:7], 2'h0,
S2_DIGITAL_FILT[6], 8'h00 };
rom[45] = {7'h4F, 16'h666F,
S2_DIGITAL_FILT[5], 2'h0, S2_DIGITAL_FILT[4:3], 2'h0,
S2_DIGITAL_FILT[2:1], 2'h0, S2_DIGITAL_FILT[0], 4'h0 };
// Initialize the rest of the ROM
for(ii = 46; ii < 64; ii = ii +1) begin
rom[ii] = 0;
end
end
// Output the initialized rom value based on rom_addr each clock cycle
always @(posedge SCLK) begin
rom_do<= #TCQ rom[rom_addr];
end
//**************************************************************************
// Everything below is associated whith the state machine that is used to
// Read/Modify/Write to the MMCM.
//**************************************************************************
// State Definitions
localparam RESTART = 4'h1;
localparam WAIT_LOCK = 4'h2;
localparam WAIT_SEN = 4'h3;
localparam ADDRESS = 4'h4;
localparam WAIT_A_DRDY = 4'h5;
localparam BITMASK = 4'h6;
localparam BITSET = 4'h7;
localparam WRITE = 4'h8;
localparam WAIT_DRDY = 4'h9;
// State sync
reg [3:0] current_state = RESTART;
reg [3:0] next_state = RESTART;
// These variables are used to keep track of the number of iterations that
// each state takes to reconfigure.
// STATE_COUNT_CONST is used to reset the counters and should match the
// number of registers necessary to reconfigure each state.
localparam STATE_COUNT_CONST = 23;
reg [4:0] state_count = STATE_COUNT_CONST;
reg [4:0] next_state_count = STATE_COUNT_CONST;
// This block assigns the next register value from the state machine below
always @(posedge SCLK) begin
DADDR <= #TCQ next_daddr;
DWE <= #TCQ next_dwe;
DEN <= #TCQ next_den;
RST_MMCM <= #TCQ next_rst_mmcm;
DI <= #TCQ next_di;
SRDY <= #TCQ next_srdy;
rom_addr <= #TCQ next_rom_addr;
state_count <= #TCQ next_state_count;
end
// This block assigns the next state, reset is syncronous.
always @(posedge SCLK) begin
if(RST) begin
current_state <= #TCQ RESTART;
end else begin
current_state <= #TCQ next_state;
end
end
always @* begin
// Setup the default values
next_srdy = 1'b0;
next_daddr = DADDR;
next_dwe = 1'b0;
next_den = 1'b0;
next_rst_mmcm = RST_MMCM;
next_di = DI;
next_rom_addr = rom_addr;
next_state_count = state_count;
case (current_state)
// If RST is asserted reset the machine
RESTART: begin
next_daddr = 7'h00;
next_di = 16'h0000;
next_rom_addr = 6'h00;
next_rst_mmcm = 1'b1;
next_state = WAIT_LOCK;
end
// Waits for the MMCM to assert LOCKED - once it does asserts SRDY
WAIT_LOCK: begin
// Make sure reset is de-asserted
next_rst_mmcm = 1'b0;
// Reset the number of registers left to write for the next
// reconfiguration event.
next_state_count = STATE_COUNT_CONST;
if(LOCKED) begin
// MMCM is locked, go on to wait for the SEN signal
next_state = WAIT_SEN;
// Assert SRDY to indicate that the reconfiguration module is
// ready
next_srdy = 1'b1;
end else begin
// Keep waiting, locked has not asserted yet
next_state = WAIT_LOCK;
end
end
// Wait for the next SEN pulse and set the ROM addr appropriately
// based on SADDR
WAIT_SEN: begin
if (!SADDR) begin
// Reconfigure with the first (0) state
next_rom_addr = 8'h00;
end else begin
// Reconfigure with the second (1) state
next_rom_addr = STATE_COUNT_CONST;
end
if (SEN) begin
// SEN was asserted
// Go on to address the MMCM
next_state = ADDRESS;
end else begin
// Keep waiting for SEN to be asserted
next_state = WAIT_SEN;
end
end
// Set the address on the MMCM and assert DEN to read the value
ADDRESS: begin
// Reset the DCM through the reconfiguration
next_rst_mmcm = 1'b1;
// Enable a read from the MMCM and set the MMCM address
next_den = 1'b1;
next_daddr = rom_do[38:32];
// Wait for the data to be ready
next_state = WAIT_A_DRDY;
end
// Wait for DRDY to assert after addressing the MMCM
WAIT_A_DRDY: begin
if (DRDY) begin
// Data is ready, mask out the bits to save
next_state = BITMASK;
end else begin
// Keep waiting till data is ready
next_state = WAIT_A_DRDY;
end
end
// Zero out the bits that are not set in the mask stored in rom
BITMASK: begin
// Do the mask
next_di = rom_do[31:16] & DO;
// Go on to set the bits
next_state = BITSET;
end
// After the input is masked, OR the bits with calculated value in rom
BITSET: begin
// Set the bits that need to be assigned
next_di = rom_do[15:0] | DI;
// Set the next address to read from ROM
next_rom_addr = rom_addr + 1'b1;
// Go on to write the data to the MMCM
next_state = WRITE;
end
// DI is setup so assert DWE, DEN, and RST_MMCM. Subtract one from the
// state count and go to wait for DRDY.
WRITE: begin
// Set WE and EN on MMCM
next_dwe = 1'b1;
next_den = 1'b1;
// Decrement the number of registers left to write
next_state_count = state_count - 1'b1;
// Wait for the write to complete
next_state = WAIT_DRDY;
end
// Wait for DRDY to assert from the MMCM. If the state count is not 0
// jump to ADDRESS (continue reconfiguration). If state count is
// 0 wait for lock.
WAIT_DRDY: begin
if(DRDY) begin
// Write is complete
if(state_count > 0) begin
// If there are more registers to write keep going
next_state = ADDRESS;
end else begin
// There are no more registers to write so wait for the MMCM
// to lock
next_state = WAIT_LOCK;
end
end else begin
// Keep waiting for write to complete
next_state = WAIT_DRDY;
end
end
// If in an unknown state reset the machine
default: begin
next_state = RESTART;
end
endcase
end
endmodule