source: PlatformSupport/Deprecated/pcores/clock_board_config_v1_04_a/hdl/verilog/clock_board_config.v

Last change on this file was 901, checked in by murphpo, 16 years ago

updating clock config core parameters

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