source: PlatformSupport/CustomPeripherals/pcores/clock_board_config_v1_05_a/hdl/verilog/clock_board_config.v

Last change on this file was 1483, checked in by murphpo, 14 years ago
File size: 30.3 KB
Line 
1// The two clocks fed to the FPGA over the clock board
2// header orginate in the AD9510 that supplied A/D and
3// D/A (logic) clocks.  OUT5 supplies the two series
4// terminated CMOS outputs, while OUT4 supplies the LVDS
5// outputs that are (should be) parallel terminated at
6// the inputs of the FPGA.
7//
8// To support various operating modes, a variable is
9// defined to specify the operating modes for OUT4 and
10// OUT5.
11//
12// OUT 5 supplies + and - CMOS outputs (test mode) : 16'h1EFF
13// OUT 5 supplies + CMOS output only (normal mode) : 16'h0EFF
14// OUT 5 powered down                              : 16'h0FFF
15
16`define fpga_clk_out5_reg 16'h0EFF
17
18// OUT 4 supplies + and - CMOS outputs (test mode) : 16'h1EFF
19// OUT 4 powered down (normal mode)                : 16'h07FF
20// OUT 4 supplies LVDS outputs                     : 16'h06FF
21
22`define fpga_clk_out4_reg 16'h07FF
23
24module clock_board_config (
25    sys_clk,
26    sys_rst,
27
28    cfg_radio_dat_out,
29    cfg_radio_csb_out,
30    cfg_radio_en_out,
31    cfg_radio_clk_out,
32
33    cfg_logic_dat_out,
34    cfg_logic_csb_out,
35    cfg_logic_en_out,
36    cfg_logic_clk_out,
37   
38    radio_clk_src_sel,
39    logic_clk_src_sel,
40   
41    config_invalid
42);
43
44parameter sys_clk_freq_hz = 120000000;
45
46// Select whether to use ports or parameters to select the clock sources
47//  0: Use parameter (fpga_radio_clk_source or fpga_logic_clk_source)
48//  1: Use port (radio_clk_src_sel or logic_clk_src_sel)
49parameter radio_clk_source_sel_mode = 1'b0;
50parameter logic_clk_source_sel_mode = 1'b0;
51
52// Select the input source for the radio clocks.
53//  CLK source for radio distribution = oscillator    : 0; //16'h1AFF
54//  CLK source for radio distribution = external coax : 1; //16'h1DFF
55//parameter fpga_radio_clk_source = 16'h1Aff;
56parameter fpga_radio_clk_source = 1'b0;
57
58// Select the input source for the logic (A/D and D/A) clocks.
59//  CLK source for logic distribution = oscillator    : 0; //16'h1AFF
60//  CLK source for logic distribution = external coax : 1; //16'h1DFF
61//parameter fpga_logic_clk_source = 16'h1Aff;
62parameter fpga_logic_clk_source = 1'b0;
63
64// Parameters controlling en/disable on radio reference clk outputs
65//  0x01ff disables the corresponding output
66//  0x1eff enables the corresponding ouptput
67// By default, outputs for slots 2 and 3 are enabled, matching
68//  the hardware config for a WARP MIMO kit
69parameter radio_clk_out4_mode = 16'h01ff; //J12
70parameter radio_clk_out5_mode = 16'h1eff; //J11 (usually radio in slot 3)
71parameter radio_clk_out6_mode = 16'h1eff; //J10 (usually radio in slot 2)
72parameter radio_clk_out7_mode = 16'h01ff; //J6
73
74// Parameter controlling whether to enable the off-board output of
75//  the radio reference clock (used for dasiy-chaining clocks)
76// 0x0BFF is disabled; 0x08FF is enabled
77parameter radio_clk_forward_out_mode = 16'h0BFF;
78
79// Parameters controlling en/disable on radio sampling clk outputs
80//  0x02ff disables the corresponding output
81//  0x04ff enables the corresponding output with min (340mV) drive
82//  0x08ff enables the corresponding output with max (810mV) drive
83// By default, outputs for slots 2 and 3 are enabled, matching
84//  the hardware config for a WARP MIMO kit
85parameter logic_clk_out0_mode = 16'h02ff; //J8
86parameter logic_clk_out1_mode = 16'h02ff; //J7
87parameter logic_clk_out2_mode = 16'h08ff; //J9 (usually radio in slot 3)
88parameter logic_clk_out3_mode = 16'h08ff; //J13 (usually radio in slot 2)
89
90// Parameter controlling whether to enable the off-board output of
91//  the radio sampling clock (used for dasiy-chaining clocks)
92// 0xh1FFF is disabled; 0xh1EFF is enabled
93parameter logic_clk_forward_out_mode = 16'h1FFF;
94
95input  sys_clk;
96input  sys_rst;
97
98output cfg_radio_dat_out; reg cfg_radio_dat_out = 1'b1;
99output cfg_radio_csb_out; reg cfg_radio_csb_out = 1'b1;
100output cfg_radio_en_out;  reg cfg_radio_en_out  = 1'b1;
101output cfg_radio_clk_out; reg cfg_radio_clk_out = 1'b1;
102
103output cfg_logic_dat_out; reg cfg_logic_dat_out = 1'b1;
104output cfg_logic_csb_out; reg cfg_logic_csb_out = 1'b1;
105output cfg_logic_en_out;  reg cfg_logic_en_out  = 1'b1;
106output cfg_logic_clk_out; reg cfg_logic_clk_out = 1'b1;
107
108input radio_clk_src_sel;
109input logic_clk_src_sel;
110
111wire srl11_radio_src_sel_ext_Q;
112wire srl11_radio_src_sel_osc_Q;
113wire srl11_logic_src_sel_ext_Q;
114wire srl11_logic_src_sel_osc_Q;
115wire srl11_radio_Q;
116wire srl11_logic_Q;
117
118output config_invalid;
119
120// SCP_CNT [7:0] increments throughout each clock period
121// of the AD9510 serial control port (SCP).  The absolute
122// maximum clock frequency for the SCP is 25 MHz, but I'm
123// limiting it to 12.5 MHz to be conservative.  If the
124// system clock operates at exactly 87.5 MHz, then the
125// minimum SCP clock period would equal exactly seven
126// SYS_CLK periods.  In this case, SCP_CNT cycles through
127// seven values -- 0, 1, 2, ..., 6 -- durin each SCP clock
128// period.  The result is an SCP clock period of 80 nsec
129// (12.5 MHz)..
130//
131// SCP_CYC_START and SCP_CYC_MID detect the start and middle
132// of each SCP cycle, respectively.  The assertion of
133// SCP_CYC_START, when appropriate, causes the SCP clock
134// to go low.  In this state, the assertion of SCP_CYC_MID
135// causes the SCP clock to return to its high state.
136
137parameter scp_min_freq_hz = 2500000;
138
139// a : How many SYS_CLK cycles per SCP cycle -- CEIL(X/Y)?
140// b : Impose a minimum of 2 SYS_CLK cycles per SCP cycle.
141
142parameter scp_cyc_leng_a = ((sys_clk_freq_hz + scp_min_freq_hz - 1) / scp_min_freq_hz);
143parameter scp_cyc_leng_b = (scp_cyc_leng_a < 2) ? 2 : scp_cyc_leng_a;
144parameter scp_cyc_leng   = scp_cyc_leng_b;
145
146reg [3:0] scp_cnt_en     = 4'b0000;     // enable used for graceful power-up
147reg [7:0] scp_cnt        = 8'b00000000; // SCP cycle counter
148reg       scp_cnt_tc     = 1'b0;        // pulses HIGH during last SCP cycle to reset counter
149reg       scp_cyc_start  = 1'b0;        // pulses high to denote start  of each SCP clock period
150reg       scp_cyc_mid    = 1'b0;        // pulses high to denote middle of each SCP clock period
151
152always @ (posedge sys_clk)
153begin
154    scp_cnt_en [3:0] <= {1'b1,scp_cnt_en [3:1]};
155
156    if (~scp_cnt_en [0])
157    begin
158        scp_cnt       [7:0] <= 8'b00000000;
159        scp_cnt_tc          <= 1'b0;
160        scp_cyc_start       <= 1'b0;
161        scp_cyc_mid         <= 1'b0;
162    end
163
164    else
165    begin
166        if   (~scp_cnt_tc) scp_cnt [7:0] <= scp_cnt [7:0] + 1;
167        else               scp_cnt [7:0] <= 8'b00000000;
168
169        scp_cnt_tc     <= (scp_cnt [7:0] == ((scp_cyc_leng + 0) - 2));
170        scp_cyc_start  <= (scp_cnt [7:0] ==                       0 );
171        scp_cyc_mid    <= (scp_cnt [7:0] == ((scp_cyc_leng + 1) / 2));
172    end
173
174end
175
176
177
178reg [3:0] sys_rst_lock = 4'b1111;
179reg [2:0] sys_rst_sync = 3'b111;
180
181always @ (posedge sys_clk or posedge sys_rst)
182begin
183    if   (sys_rst) sys_rst_lock [3] <= 1'b1;
184    else           sys_rst_lock [3] <= 1'b0;
185end
186
187always @ (posedge sys_clk or posedge sys_rst_lock [3])
188begin
189    if   (sys_rst_lock [3]) sys_rst_lock [2:0] <= 3'b111;
190    else                    sys_rst_lock [2:0] <= {1'b0,sys_rst_lock [2:1]};
191end
192
193always @ (posedge sys_clk)
194begin
195    sys_rst_sync [2:0] <= {sys_rst_lock [0],sys_rst_sync [2:1]};
196end
197
198
199
200// CFG_CYC [9:0] increments by 1 following each assertion
201// of SCP_CYC_MID, until it finally "rolls over" to 0.
202// Coincident with this roll-over is the assertion of
203// CFG_CYC_DONE, thereby preventing any further increments
204// to CFG_CYC.  The net result?...  SCP_CYC_START and
205// SCP_CYC_MID each pulse high 1024 times while
206// CFG_CYC_DONE is deasserted (low).  After this,
207// CFG_CYC_START and CFG_CYC_MID continue to pulse, but
208// CFG_CYC_DONE is asserted to mask of any "events" that
209// depend upon the START and MID pulses.
210//
211// EXAMPLE : SCP_CYC_LENG = 6...
212//
213// SYS_CLK         : \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/       \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
214// SCP_CYC_START   : 0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|1|  ... |0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|1|
215// SCP_CYC_MID     : 0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|  ... |1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|
216// CFG_CYC         :                 0        |     1     |     2  ...   |    1023   |        0
217// CFG_DONE        : 0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|  ... |0|0|0|0|0|0|0|1|1|1|1|1|1|1|1|1|
218//
219// EXAMPLE : SCP_CYC_LENG = 2...
220//
221// Same as in the previous example, except that
222// SCP_CYC_START and SCP_CYC_MID are alternately pulsing
223// high and low 180 degrees out of phase with respect to
224// one another.
225
226reg [9:0] cfg_cyc      = 10'b0000000000;
227reg       cfg_cyc_done =  1'b1;
228reg       cfg_restart  =  1'b0;
229reg       cfg_clk_low  =  1'b0;
230reg       cfg_clk_high =  1'b0;
231
232reg       cfg_cyc_done_d1 = 1'b1;
233
234always @ (posedge sys_clk)
235begin
236    cfg_cyc_done_d1 <= cfg_cyc_done;
237end
238
239
240
241always @ (posedge sys_clk)
242begin
243
244    if (~scp_cyc_mid)
245    begin
246        cfg_cyc      [9:0] <= cfg_cyc [9:0];
247        cfg_cyc_done       <= cfg_cyc_done;
248    end
249
250    else
251    begin
252        if (cfg_cyc_done)
253        begin
254            cfg_cyc      [9:0] <= 10'b0000000000;
255            cfg_cyc_done       <= ~cfg_restart;
256        end
257
258        else
259        begin
260            cfg_cyc      [9:0] <= cfg_cyc [9:0] + 1;
261            cfg_cyc_done       <= (cfg_cyc [9:0] == 10'b1111111111);
262        end
263    end
264
265   cfg_restart  <= ~cfg_restart & cfg_cyc_done & (sys_rst_sync [1:0] == 2'b01)
266                 |  cfg_restart & cfg_cyc_done & ~scp_cyc_mid;
267
268   cfg_clk_low  <= ~cfg_cyc_done & scp_cyc_start;
269   cfg_clk_high <= ~cfg_cyc_done & scp_cyc_mid;
270end
271
272
273
274// For a given sequence generation register (chain of
275// SRLs), the SRL having index 0 delivers its data
276// first, followed by the SRL having index 1.  The SRL
277// having index 63 delivers its data last.  Hence the
278// input of SRL N is fed by the output of SRL N + 1.
279// The last SRL in each chain is fed with the output
280// of the first SRL in he chain so that the configuration
281// may be repeated on demand.
282//
283// Two sequence generators are defined, one for the
284// AD9510 that clocks the radio ICs for up- and down-
285// conversion, and another that clocks the FPGA and
286// the radio boards' converters.
287
288wire        srl_shift;
289
290wire [63:0] srl_radio_d;
291wire [63:0] srl_radio_q;
292
293wire [63:0] srl_logic_d;
294wire [63:0] srl_logic_q;
295
296assign srl_shift          = cfg_clk_low;
297//assign srl_radio_d [63:0] = {srl_radio_q [0],srl_radio_q [63:1]};
298//assign srl_logic_d [63:0] = {srl_logic_q [0],srl_logic_q [63:1]};
299assign srl_radio_d [63:0] = {srl_radio_q[0], srl_radio_q[63:12], srl11_radio_Q, srl_radio_q[10:1]};
300assign srl_logic_d [63:0] = {srl_logic_q[0], srl_logic_q[63:12], srl11_logic_Q, srl_logic_q[10:1]};
301
302//Select which srl will provide the clock source register value
303// if:
304//  param x_clk_source_sel_mode==1 AND port x_clk_src_sel==1, select srl for external source
305//  param x_clk_source_sel_mode==0 AND parameter fpga_x_clk_source==1, select srl for external source
306// else:
307//  select srl for on-board oscillator
308assign srl11_radio_Q = ( (radio_clk_source_sel_mode & radio_clk_src_sel) | (~radio_clk_source_sel_mode & fpga_radio_clk_source) ) ? srl11_radio_src_sel_ext_Q : srl11_radio_src_sel_osc_Q;
309assign srl11_logic_Q = ( (logic_clk_source_sel_mode & logic_clk_src_sel) | (~logic_clk_source_sel_mode & fpga_logic_clk_source) ) ? srl11_logic_src_sel_ext_Q : srl11_logic_src_sel_osc_Q;
310
311reg    config_invalid = 1'b1;
312
313always @(posedge sys_clk)
314begin
315    if(cfg_cyc_done & ~cfg_cyc_done_d1)
316        config_invalid <= 1'b0;
317    else if(cfg_restart)
318        config_invalid <= 1'b1;
319end
320
321// ALL SRLs in this module are configured for a static
322// shift length of 16.  For a given 16-bit SRL INIT
323// value, the high order bit will be shifted out first,
324// while the low order bit will be shifted out last.
325// It is, therefore, VERY convenient to operate the
326// AD9510s in MSB first mode.  Pros : This is the
327// default operating mode for the AD9510, and requires
328// no additional hocus pocus.  Cons : Addresses are
329// decremented as data is written into each device.
330// This requires an extra control access to address
331// 5A in order to force the update -- not rocket science,
332// but very important to remember.  See the AD9510 data
333// sheet, revision A, pages 42 and 43 for details.
334
335genvar ii;
336generate
337    for (ii = 0 ; ii < 64 ; ii = ii + 1)
338    begin : gen_srls
339
340        SRL16E srl_radio (
341            .Q   (srl_radio_q [ii]),
342            .A0  (1'b1            ),
343            .A1  (1'b1            ),
344            .A2  (1'b1            ),
345            .A3  (1'b1            ),
346            .CE  (srl_shift       ),
347            .CLK (sys_clk         ),
348            .D   (srl_radio_d [ii])
349        );
350
351        SRL16E srl_logic (
352            .Q   (srl_logic_q [ii]),
353            .A0  (1'b1            ),
354            .A1  (1'b1            ),
355            .A2  (1'b1            ),
356            .A3  (1'b1            ),
357            .CE  (srl_shift       ),
358            .CLK (sys_clk         ),
359            .D   (srl_logic_d [ii])
360        );
361
362    end
363endgenerate
364
365SRL16E srl11_radio_src_sel_ext (
366    .Q   (srl11_radio_src_sel_ext_Q),
367    .A0  (1'b1            ),
368    .A1  (1'b1            ),
369    .A2  (1'b1            ),
370    .A3  (1'b1            ),
371    .CE  (srl_shift       ),
372    .CLK (sys_clk         ),
373    .D   (srl_radio_d [11])
374);
375
376SRL16E srl11_radio_src_sel_osc (
377    .Q   (srl11_radio_src_sel_osc_Q),
378    .A0  (1'b1            ),
379    .A1  (1'b1            ),
380    .A2  (1'b1            ),
381    .A3  (1'b1            ),
382    .CE  (srl_shift       ),
383    .CLK (sys_clk         ),
384    .D   (srl_radio_d [11])
385);
386
387SRL16E srl11_logic_src_sel_ext (
388    .Q   (srl11_logic_src_sel_ext_Q),
389    .A0  (1'b1            ),
390    .A1  (1'b1            ),
391    .A2  (1'b1            ),
392    .A3  (1'b1            ),
393    .CE  (srl_shift       ),
394    .CLK (sys_clk         ),
395    .D   (srl_logic_d [11])
396);
397
398SRL16E srl11_logic_src_sel_osc (
399    .Q   (srl11_logic_src_sel_osc_Q),
400    .A0  (1'b1            ),
401    .A1  (1'b1            ),
402    .A2  (1'b1            ),
403    .A3  (1'b1            ),
404    .CE  (srl_shift       ),
405    .CLK (sys_clk         ),
406    .D   (srl_logic_d [11])
407);
408
409defparam srl11_logic_src_sel_osc.INIT = 16'h1AFF;
410defparam srl11_logic_src_sel_ext.INIT = 16'h1DFF;
411defparam srl11_radio_src_sel_osc.INIT = 16'h1AFF;
412defparam srl11_radio_src_sel_ext.INIT = 16'h1DFF;
413
414// Here's where we define the register contents
415// Each "defparam gen_srls" corresponds to one 16 bit SPI transaction
416
417// Register contents for the radio reference generator
418
419// Leave some emtpy clock cycles at boot to let things settle
420defparam gen_srls[ 0].srl_radio.INIT = 16'hFFFF; // CYCLES    0 -   15
421defparam gen_srls[ 1].srl_radio.INIT = 16'hFFFF; // CYCLES   16 -   31
422defparam gen_srls[ 2].srl_radio.INIT = 16'hFFFF; // CYCLES   32 -   47
423defparam gen_srls[ 3].srl_radio.INIT = 16'hFFFF; // CYCLES   48 -   63
424defparam gen_srls[ 4].srl_radio.INIT = 16'hFFFF; // CYCLES   64 -   79
425defparam gen_srls[ 5].srl_radio.INIT = 16'hFFFF; // CYCLES   80 -   95
426
427// Issue soft-reset; does *not* require write to 5A to take effect
428// reg[0] <= 30, then 10 (assert, then de-assert reset bit)
429defparam gen_srls[ 6].srl_radio.INIT = 16'h0000; // CYCLES   96 -  111
430defparam gen_srls[ 7].srl_radio.INIT = 16'h30FF; // CYCLES  112 -  127
431
432defparam gen_srls[ 8].srl_radio.INIT = 16'h0000; // CYCLES  128 -  143
433defparam gen_srls[ 9].srl_radio.INIT = 16'h10FF; // CYCLES  144 -  159
434
435// Switch clock input to CLK2; power-down CLK1 and PLL input
436// reg[45] <= 1A
437defparam gen_srls[10].srl_radio.INIT = 16'h0045;               // CYCLES  160 -  175
438defparam gen_srls[11].srl_radio.INIT = fpga_radio_clk_source; // CYCLES  176 -  191
439
440// Bypass dividers on all clocks
441// reg[49,4B,4D,4F,51,53,55,57] <= 80
442
443defparam gen_srls[12].srl_radio.INIT = 16'h0049; // CYCLES  192 -  207
444defparam gen_srls[13].srl_radio.INIT = 16'h80FF; // CYCLES  208 -  223
445
446defparam gen_srls[14].srl_radio.INIT = 16'h004B; // CYCLES  224 -  239
447defparam gen_srls[15].srl_radio.INIT = 16'h80FF; // CYCLES  240 -  255
448
449defparam gen_srls[16].srl_radio.INIT = 16'h004D; // CYCLES  256 -  271
450defparam gen_srls[17].srl_radio.INIT = 16'h80FF; // CYCLES  272 -  287
451
452defparam gen_srls[18].srl_radio.INIT = 16'h004F; // CYCLES  288 -  303
453defparam gen_srls[19].srl_radio.INIT = 16'h80FF; // CYCLES  304 -  319
454
455defparam gen_srls[20].srl_radio.INIT = 16'h0051; // CYCLES  320 -  335
456defparam gen_srls[21].srl_radio.INIT = 16'h80FF; // CYCLES  336 -  351
457
458defparam gen_srls[22].srl_radio.INIT = 16'h0053; // CYCLES  352 -  367
459defparam gen_srls[23].srl_radio.INIT = 16'h80FF; // CYCLES  368 -  383
460
461defparam gen_srls[24].srl_radio.INIT = 16'h0055; // CYCLES  384 -  399
462defparam gen_srls[25].srl_radio.INIT = 16'h80FF; // CYCLES  400 -  415
463
464defparam gen_srls[26].srl_radio.INIT = 16'h0057; // CYCLES  416 -  431
465defparam gen_srls[27].srl_radio.INIT = 16'h80FF; // CYCLES  432 -  447
466
467// Configure the output properties on the CMOS clock outputs.
468// Enabled outputs require CMOS (not LVDS), invertered output enabled
469// reg[40,41,42,43] <= 1E means output is enabled
470// reg[40,41,42,43] <= 01 means output is disabled
471defparam gen_srls[28].srl_radio.INIT = 16'h0040; // CYCLES  448 -  463
472defparam gen_srls[29].srl_radio.INIT = radio_clk_out4_mode; // CYCLES  464 -  479
473
474defparam gen_srls[30].srl_radio.INIT = 16'h0041; // CYCLES  480 -  495
475defparam gen_srls[31].srl_radio.INIT = radio_clk_out5_mode; // CYCLES  496 -  511
476
477defparam gen_srls[32].srl_radio.INIT = 16'h0042; // CYCLES  512 -  527
478defparam gen_srls[33].srl_radio.INIT = radio_clk_out6_mode; // CYCLES  528 -  543
479
480defparam gen_srls[34].srl_radio.INIT = 16'h0043; // CYCLES  544 -  559
481defparam gen_srls[35].srl_radio.INIT = radio_clk_out7_mode; // CYCLES  560 -  575
482
483// Configure the output properties on the PECL clock outputs
484// OUT0 enabled, 810mV drive; OUT1/2/3 disabled
485// reg[3C] <= 08; reg[3D,3E,3F] <= 0B
486defparam gen_srls[36].srl_radio.INIT = 16'h003C; // CYCLES  576 -  591
487//defparam gen_srls[37].srl_radio.INIT = 16'h08FF; // CYCLES  592 -  607
488defparam gen_srls[37].srl_radio.INIT = radio_clk_forward_out_mode; // CYCLES  592 -  607
489
490defparam gen_srls[38].srl_radio.INIT = 16'h003D; // CYCLES  608 -  623
491defparam gen_srls[39].srl_radio.INIT = 16'h0BFF; // CYCLES  624 -  639
492
493defparam gen_srls[40].srl_radio.INIT = 16'h003E; // CYCLES  640 -  655
494defparam gen_srls[41].srl_radio.INIT = 16'h0BFF; // CYCLES  656 -  671
495
496defparam gen_srls[42].srl_radio.INIT = 16'h003F; // CYCLES  672 -  687
497defparam gen_srls[43].srl_radio.INIT = 16'h0BFF; // CYCLES  688 -  703
498
499
500// Latch the loaded values into the actual config registers
501// reg[5A] <= FF
502defparam gen_srls[44].srl_radio.INIT = 16'h005A; // CYCLES  704 -  719
503defparam gen_srls[45].srl_radio.INIT = 16'hFFFF; // CYCLES  720 -  735
504
505// unused cycles
506defparam gen_srls[46].srl_radio.INIT = 16'hFFFF; // CYCLES  736 -  751
507defparam gen_srls[47].srl_radio.INIT = 16'hFFFF; // CYCLES  752 -  767
508defparam gen_srls[48].srl_radio.INIT = 16'hFFFF; // CYCLES  768 -  783
509defparam gen_srls[49].srl_radio.INIT = 16'hFFFF; // CYCLES  784 -  799
510defparam gen_srls[50].srl_radio.INIT = 16'hFFFF; // CYCLES  800 -  815
511defparam gen_srls[51].srl_radio.INIT = 16'hFFFF; // CYCLES  816 -  831
512defparam gen_srls[52].srl_radio.INIT = 16'hFFFF; // CYCLES  832 -  847
513defparam gen_srls[53].srl_radio.INIT = 16'hFFFF; // CYCLES  848 -  863
514defparam gen_srls[54].srl_radio.INIT = 16'hFFFF; // CYCLES  864 -  879
515defparam gen_srls[55].srl_radio.INIT = 16'hFFFF; // CYCLES  880 -  895
516defparam gen_srls[56].srl_radio.INIT = 16'hFFFF; // CYCLES  896 -  911
517defparam gen_srls[57].srl_radio.INIT = 16'hFFFF; // CYCLES  912 -  927
518defparam gen_srls[58].srl_radio.INIT = 16'hFFFF; // CYCLES  928 -  943
519defparam gen_srls[59].srl_radio.INIT = 16'hFFFF; // CYCLES  944 -  959
520defparam gen_srls[60].srl_radio.INIT = 16'hFFFF; // CYCLES  960 -  975
521defparam gen_srls[61].srl_radio.INIT = 16'hFFFF; // CYCLES  976 -  991
522defparam gen_srls[62].srl_radio.INIT = 16'hFFFF; // CYCLES  992 - 1007
523defparam gen_srls[63].srl_radio.INIT = 16'hFFFF; // CYCLES 1008 - 1023
524
525// Here's some m-code that will help generate these vectors:
526// csb_low =  96   + 32*[0:15];sprintf('cfg_cyc == %d | ',csb_low)
527// csb_high = 96-8 + 32*[1:16];sprintf('cfg_cyc == %d | ',csb_high)
528
529`define RADIO_CSB_LOW_DECODE  ((cfg_cyc ==  96) | (cfg_cyc == 128) | (cfg_cyc == 160) | (cfg_cyc == 192) | (cfg_cyc == 224) | (cfg_cyc == 256) | (cfg_cyc == 288) | (cfg_cyc == 320) | (cfg_cyc == 352) | (cfg_cyc == 384) | (cfg_cyc == 416) | (cfg_cyc == 448) | (cfg_cyc == 480) | (cfg_cyc == 512) | (cfg_cyc == 544) | (cfg_cyc == 576) | (cfg_cyc == 608) | (cfg_cyc == 640) | (cfg_cyc == 672) | (cfg_cyc == 704))
530`define RADIO_CSB_HIGH_DECODE ((cfg_cyc == 120) | (cfg_cyc == 152) | (cfg_cyc == 184) | (cfg_cyc == 216) | (cfg_cyc == 248) | (cfg_cyc == 280) | (cfg_cyc == 312) | (cfg_cyc == 344) | (cfg_cyc == 376) | (cfg_cyc == 408) | (cfg_cyc == 440) | (cfg_cyc == 472) | (cfg_cyc == 504) | (cfg_cyc == 536) | (cfg_cyc == 568) | (cfg_cyc == 600) | (cfg_cyc == 632) | (cfg_cyc == 664) | (cfg_cyc == 696) | (cfg_cyc == 728))
531`define RADIO_EN_LOW_DECODE   ( cfg_cyc ==   0)
532`define RADIO_EN_HIGH_DECODE    ( cfg_cyc ==   4)
533
534//Register contents for the converter clock generator
535
536// Leave some emtpy clock cycles at boot to let things settle
537defparam gen_srls[ 0].srl_logic.INIT = 16'hFFFF; // CYCLES    0 -   15
538defparam gen_srls[ 1].srl_logic.INIT = 16'hFFFF; // CYCLES   16 -   31
539defparam gen_srls[ 2].srl_logic.INIT = 16'hFFFF; // CYCLES   32 -   47
540defparam gen_srls[ 3].srl_logic.INIT = 16'hFFFF; // CYCLES   48 -   63
541defparam gen_srls[ 4].srl_logic.INIT = 16'hFFFF; // CYCLES   64 -   79
542defparam gen_srls[ 5].srl_logic.INIT = 16'hFFFF; // CYCLES   80 -   95
543
544// Issue soft-reset; does *not* require write to 5A to take effect
545// reg[0] <= 30, then 10 (assert, then de-assert reset bit)
546defparam gen_srls[ 6].srl_logic.INIT = 16'h0000; // CYCLES   96 -  111
547defparam gen_srls[ 7].srl_logic.INIT = 16'h30FF; // CYCLES  112 -  127
548
549defparam gen_srls[ 8].srl_logic.INIT = 16'h0000; // CYCLES  128 -  143
550defparam gen_srls[ 9].srl_logic.INIT = 16'h10FF; // CYCLES  144 -  159
551
552// Switch clock input to CLK2; power-down CLK1 and PLL input
553// reg[45] <= 1A
554// defparam gen_srls[10].srl_logic.INIT = 16'h0045; // CYCLES  160 -  175
555// defparam gen_srls[11].srl_logic.INIT = 16'h1AFF; // CYCLES  176 -  191
556
557// For now, switch clock input to CLK1; power-down CLK2 and PLL input
558// reg[45] <= 1D
559defparam gen_srls[10].srl_logic.INIT = 16'h0045;               // CYCLES  160 -  175
560defparam gen_srls[11].srl_logic.INIT = fpga_logic_clk_source; // CYCLES  176 -  191
561
562// Bypass dividers on all clocks
563// reg[49,4B,4D,4F,51,53,55,57] <= 80
564
565defparam gen_srls[12].srl_logic.INIT = 16'h0049; // CYCLES  192 -  207
566defparam gen_srls[13].srl_logic.INIT = 16'h80FF; // CYCLES  208 -  223
567
568defparam gen_srls[14].srl_logic.INIT = 16'h004B; // CYCLES  224 -  239
569defparam gen_srls[15].srl_logic.INIT = 16'h80FF; // CYCLES  240 -  255
570
571defparam gen_srls[16].srl_logic.INIT = 16'h004D; // CYCLES  256 -  271
572defparam gen_srls[17].srl_logic.INIT = 16'h80FF; // CYCLES  272 -  287
573
574defparam gen_srls[18].srl_logic.INIT = 16'h004F; // CYCLES  288 -  303
575defparam gen_srls[19].srl_logic.INIT = 16'h80FF; // CYCLES  304 -  319
576
577defparam gen_srls[20].srl_logic.INIT = 16'h0051; // CYCLES  320 -  335
578defparam gen_srls[21].srl_logic.INIT = 16'h80FF; // CYCLES  336 -  351
579
580defparam gen_srls[22].srl_logic.INIT = 16'h0053; // CYCLES  352 -  367
581defparam gen_srls[23].srl_logic.INIT = 16'h80FF; // CYCLES  368 -  383
582
583defparam gen_srls[24].srl_logic.INIT = 16'h0055; // CYCLES  384 -  399
584defparam gen_srls[25].srl_logic.INIT = 16'h80FF; // CYCLES  400 -  415
585
586defparam gen_srls[26].srl_logic.INIT = 16'h0057; // CYCLES  416 -  431
587defparam gen_srls[27].srl_logic.INIT = 16'h80FF; // CYCLES  432 -  447
588
589// Configure the output properties on the PECL clock outputs
590// OUT0-OUT3 enabled, 810mV drive;
591// reg[3C,3D,3E,3F] <= 08; enables outputs with max (810mV) drive
592// reg[3C,3D,3E,3F] <= 04; enables outputs with min (340mV) drive
593// reg[3C,3D,3E,3F] <= 02; disables outputs
594
595defparam gen_srls[28].srl_logic.INIT = 16'h003C; // CYCLES  448 -  463
596defparam gen_srls[29].srl_logic.INIT = logic_clk_out0_mode; // CYCLES  464 -  479
597
598defparam gen_srls[30].srl_logic.INIT = 16'h003D; // CYCLES  480 -  495
599defparam gen_srls[31].srl_logic.INIT = logic_clk_out1_mode; // CYCLES  496 -  511
600
601defparam gen_srls[32].srl_logic.INIT = 16'h003E; // CYCLES  512 -  527
602defparam gen_srls[33].srl_logic.INIT = logic_clk_out2_mode; // CYCLES  528 -  543
603
604defparam gen_srls[34].srl_logic.INIT = 16'h003F; // CYCLES  544 -  559
605defparam gen_srls[35].srl_logic.INIT = logic_clk_out3_mode; // CYCLES  560 -  575
606
607// Configure the output properties for the forwarded clock (OUT7)
608// CMOS (not LVDS), inverted output enabled, maximum drive current
609// reg[43] <= 1E;
610defparam gen_srls[36].srl_logic.INIT = 16'h0043; // CYCLES  576 -  591
611//defparam gen_srls[37].srl_logic.INIT = 16'h1EFF; // CYCLES  592 -  607
612defparam gen_srls[37].srl_logic.INIT = logic_clk_forward_out_mode; // CYCLES  592 -  607
613
614// Power down CMOS OUT6
615// reg[42] <= 1F;
616defparam gen_srls[38].srl_logic.INIT = 16'h0042; // CYCLES  608 -  623
617defparam gen_srls[39].srl_logic.INIT = 16'h1FFF; // CYCLES  624 -  639
618
619// OUT5 : See comments at the top of this file
620defparam gen_srls[40].srl_logic.INIT = 16'h0041;           // CYCLES  640 -  655
621defparam gen_srls[41].srl_logic.INIT = `fpga_clk_out5_reg; // CYCLES  656 -  671
622
623// OUT4 : See comments at the top of this file
624defparam gen_srls[42].srl_logic.INIT = 16'h0040;           // CYCLES  672 -  687
625defparam gen_srls[43].srl_logic.INIT = `fpga_clk_out4_reg; // CYCLES  688 -  703
626
627// Latch the loaded values into the actual config registers
628// reg[5A] <= FF
629
630defparam gen_srls[44].srl_logic.INIT = 16'h005A; // CYCLES  704 -  719
631defparam gen_srls[45].srl_logic.INIT = 16'hFFFF; // CYCLES  720 -  735
632
633// unused cycles
634defparam gen_srls[46].srl_logic.INIT = 16'h0000; // CYCLES  736 -  751
635defparam gen_srls[47].srl_logic.INIT = 16'h0000; // CYCLES  752 -  767
636defparam gen_srls[48].srl_logic.INIT = 16'h0000; // CYCLES  768 -  783
637defparam gen_srls[49].srl_logic.INIT = 16'h0000; // CYCLES  784 -  799
638defparam gen_srls[50].srl_logic.INIT = 16'h0000; // CYCLES  800 -  815
639defparam gen_srls[51].srl_logic.INIT = 16'h0000; // CYCLES  816 -  831
640defparam gen_srls[52].srl_logic.INIT = 16'h0000; // CYCLES  832 -  847
641defparam gen_srls[53].srl_logic.INIT = 16'h0000; // CYCLES  848 -  863
642defparam gen_srls[54].srl_logic.INIT = 16'h0000; // CYCLES  864 -  879
643defparam gen_srls[55].srl_logic.INIT = 16'h0000; // CYCLES  880 -  895
644defparam gen_srls[56].srl_logic.INIT = 16'h0000; // CYCLES  896 -  911
645defparam gen_srls[57].srl_logic.INIT = 16'h0000; // CYCLES  912 -  927
646defparam gen_srls[58].srl_logic.INIT = 16'h0000; // CYCLES  928 -  943
647defparam gen_srls[59].srl_logic.INIT = 16'h0000; // CYCLES  944 -  959
648defparam gen_srls[60].srl_logic.INIT = 16'h0000; // CYCLES  960 -  975
649defparam gen_srls[61].srl_logic.INIT = 16'h0000; // CYCLES  976 -  991
650defparam gen_srls[62].srl_logic.INIT = 16'h0000; // CYCLES  992 - 1007
651defparam gen_srls[63].srl_logic.INIT = 16'h0000; // CYCLES 1008 - 1023
652
653`define LOGIC_CSB_LOW_DECODE  ((cfg_cyc ==  96) | (cfg_cyc == 128) | (cfg_cyc == 160) | (cfg_cyc == 192) | (cfg_cyc == 224) | (cfg_cyc == 256) | (cfg_cyc == 288) | (cfg_cyc == 320) | (cfg_cyc == 352) | (cfg_cyc == 384) | (cfg_cyc == 416) | (cfg_cyc == 448) | (cfg_cyc == 480) | (cfg_cyc == 512) | (cfg_cyc == 544) | (cfg_cyc == 576) | (cfg_cyc == 608) | (cfg_cyc == 640) | (cfg_cyc == 672) | (cfg_cyc == 704))
654`define LOGIC_CSB_HIGH_DECODE ((cfg_cyc == 120) | (cfg_cyc == 152) | (cfg_cyc == 184) | (cfg_cyc == 216) | (cfg_cyc == 248) | (cfg_cyc == 280) | (cfg_cyc == 312) | (cfg_cyc == 344) | (cfg_cyc == 376) | (cfg_cyc == 408) | (cfg_cyc == 440) | (cfg_cyc == 472) | (cfg_cyc == 504) | (cfg_cyc == 536) | (cfg_cyc == 568) | (cfg_cyc == 600) | (cfg_cyc == 632) | (cfg_cyc == 664) | (cfg_cyc == 696) | (cfg_cyc == 728))
655`define LOGIC_EN_LOW_DECODE   (cfg_cyc ==  0)
656`define LOGIC_EN_HIGH_DECODE  (cfg_cyc ==  4)
657
658// Decode various values of CFG_CYC to assert and deassert
659// control signals at various bit positions within the
660// configuration sequences.  CFG_RADIO_CSB_LOW, for example,
661// should decode the value of CFG_CYC corresponding to the
662// first bit of an SCP command.  CFG_RADIO_CSB_HIGH should
663// likewise decode the value corresponding to the first
664// bit FOLLOWING a streaming register access.
665
666reg       cfg_radio_csb_low  = 1'b0;
667reg       cfg_radio_csb_high = 1'b0;
668reg       cfg_radio_en_low   = 1'b0;
669reg       cfg_radio_en_high  = 1'b0;
670
671reg       cfg_logic_csb_low  = 1'b0;
672reg       cfg_logic_csb_high = 1'b0;
673reg       cfg_logic_en_low   = 1'b0;
674reg       cfg_logic_en_high  = 1'b0;
675
676always @ (posedge sys_clk)
677begin
678    if (~scp_cyc_start)
679    begin
680        cfg_radio_csb_low   <=  1'b0;
681        cfg_radio_csb_high  <=  1'b0;
682        cfg_radio_en_low    <=  1'b0;
683        cfg_radio_en_high   <=  1'b0;
684
685        cfg_logic_csb_low   <=  1'b0;
686        cfg_logic_csb_high  <=  1'b0;
687        cfg_logic_en_low    <=  1'b0;
688        cfg_logic_en_high   <=  1'b0;
689    end
690
691    else
692    begin
693        if (cfg_cyc_done)
694        begin
695            cfg_radio_csb_low   <=  1'b0;
696            cfg_radio_csb_high  <=  1'b1;
697            cfg_radio_en_low    <=  1'b0;
698            cfg_radio_en_high   <=  1'b1;
699
700            cfg_logic_csb_low   <=  1'b0;
701            cfg_logic_csb_high  <=  1'b1;
702            cfg_logic_en_low    <=  1'b0;
703            cfg_logic_en_high   <=  1'b1;
704        end
705        else
706        begin
707            cfg_radio_csb_low   <= `RADIO_CSB_LOW_DECODE;
708            cfg_radio_csb_high  <= `RADIO_CSB_HIGH_DECODE;
709            cfg_radio_en_low    <= `RADIO_EN_LOW_DECODE;
710            cfg_radio_en_high   <= `RADIO_EN_HIGH_DECODE;
711
712            cfg_logic_csb_low   <= `LOGIC_CSB_LOW_DECODE;
713            cfg_logic_csb_high  <= `LOGIC_CSB_HIGH_DECODE;
714            cfg_logic_en_low    <= `LOGIC_EN_LOW_DECODE;
715            cfg_logic_en_high   <= `LOGIC_EN_HIGH_DECODE;
716        end
717
718    end
719
720end
721
722
723
724always @ (posedge sys_clk)
725begin
726    if   (srl_shift) cfg_radio_dat_out <=  srl_radio_q [0];
727    else             cfg_radio_dat_out <=  cfg_radio_dat_out; 
728
729    cfg_radio_csb_out <=  cfg_radio_csb_out & ~cfg_radio_csb_low
730                      | ~cfg_radio_csb_out &  cfg_radio_csb_high;
731    cfg_radio_en_out  <=  cfg_radio_en_out  & ~cfg_radio_en_low
732                      | ~cfg_radio_en_out  &  cfg_radio_en_high;
733    cfg_radio_clk_out <=  cfg_radio_clk_out & ~cfg_clk_low
734                      | ~cfg_radio_clk_out &  cfg_clk_high;
735
736    if   (srl_shift) cfg_logic_dat_out <=  srl_logic_q [0];
737    else             cfg_logic_dat_out <=  cfg_logic_dat_out;
738
739    cfg_logic_csb_out <=  cfg_logic_csb_out & ~cfg_logic_csb_low
740                      | ~cfg_logic_csb_out &  cfg_logic_csb_high;
741    cfg_logic_en_out  <=  cfg_logic_en_out  & ~cfg_logic_en_low
742                      | ~cfg_logic_en_out  &  cfg_logic_en_high;
743    cfg_logic_clk_out <=  cfg_logic_clk_out & ~cfg_clk_low
744                      | ~cfg_logic_clk_out &  cfg_clk_high;
745end
746
747endmodule
Note: See TracBrowser for help on using the repository browser.