OpenCores
URL https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [libcycloneii/] [src/] [cycloneii_atoms.vhd] - Blame information for rev 185

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 123 rkastl
-- Copyright (C) 1991-2010 Altera Corporation
2
-- Your use of Altera Corporation's design tools, logic functions 
3
-- and other software and tools, and its AMPP partner logic 
4
-- functions, and any output files from any of the foregoing 
5
-- (including device programming or simulation files), and any 
6
-- associated documentation or information are expressly subject 
7
-- to the terms and conditions of the Altera Program License 
8
-- Subscription Agreement, Altera MegaCore Function License 
9
-- Agreement, or other applicable license agreement, including, 
10
-- without limitation, that your use is for the sole purpose of 
11
-- programming logic devices manufactured by Altera and sold by 
12
-- Altera or its authorized distributors.  Please refer to the 
13
-- applicable agreement for further details.
14
-- Quartus II 9.1 Build 350 10/07/2009
15
 
16
library IEEE;
17
use IEEE.std_logic_1164.all;
18
use IEEE.VITAL_Timing.all;
19
use IEEE.VITAL_Primitives.all;
20
 
21
package cycloneii_atom_pack is
22
 
23
function str_to_bin (lut_mask : string ) return std_logic_vector;
24
 
25
function product(list : std_logic_vector) return std_logic ;
26
 
27
function alt_conv_integer(arg : in std_logic_vector) return integer;
28
 
29
 
30
-- default generic values
31
    CONSTANT DefWireDelay        : VitalDelayType01      := (0 ns, 0 ns);
32
    CONSTANT DefPropDelay01      : VitalDelayType01      := (0 ns, 0 ns);
33
    CONSTANT DefPropDelay01Z     : VitalDelayType01Z     := (OTHERS => 0 ns);
34
    CONSTANT DefSetupHoldCnst    : TIME := 0 ns;
35
    CONSTANT DefPulseWdthCnst    : TIME := 0 ns;
36
-- default control options
37
--    CONSTANT DefGlitchMode       : VitalGlitchKindType   := OnEvent;
38
-- change default delay type to Transport : for spr 68748
39
    CONSTANT DefGlitchMode       : VitalGlitchKindType   := VitalTransport;
40
    CONSTANT DefGlitchMsgOn      : BOOLEAN       := FALSE;
41
    CONSTANT DefGlitchXOn        : BOOLEAN       := FALSE;
42
    CONSTANT DefMsgOnChecks      : BOOLEAN       := TRUE;
43
    CONSTANT DefXOnChecks        : BOOLEAN       := TRUE;
44
-- output strength mapping
45
                                                --  UX01ZWHL-
46
    CONSTANT PullUp      : VitalOutputMapType    := "UX01HX01X";
47
    CONSTANT NoPullUpZ   : VitalOutputMapType    := "UX01ZX01X";
48
    CONSTANT PullDown    : VitalOutputMapType    := "UX01LX01X";
49
-- primitive result strength mapping
50
    CONSTANT wiredOR     : VitalResultMapType    := ( 'U', 'X', 'L', '1' );
51
    CONSTANT wiredAND    : VitalResultMapType    := ( 'U', 'X', '0', 'H' );
52
    CONSTANT L : VitalTableSymbolType := '0';
53
    CONSTANT H : VitalTableSymbolType := '1';
54
    CONSTANT x : VitalTableSymbolType := '-';
55
    CONSTANT S : VitalTableSymbolType := 'S';
56
    CONSTANT R : VitalTableSymbolType := '/';
57
    CONSTANT U : VitalTableSymbolType := 'X';
58
    CONSTANT V : VitalTableSymbolType := 'B'; -- valid clock signal (non-rising)
59
 
60
-- Declare array types for CAM_SLICE
61
    TYPE cycloneii_mem_data IS ARRAY (0 to 31) of STD_LOGIC_VECTOR (31 downto 0);
62
 
63
function int2str( value : integer ) return string;
64
 
65
function map_x_to_0 (value : std_logic) return std_logic;
66
 
67
function SelectDelay (CONSTANT Paths: IN  VitalPathArray01Type) return TIME;
68
 
69
function int2bit (arg : boolean) return std_logic;
70
function int2bit (arg : integer) return std_logic;
71
function bin2int (s : std_logic_vector) return integer;
72
function bin2int (s : std_logic) return integer;
73
function int2bin (arg : integer; size : integer) return std_logic_vector;
74
function int2bin (arg : boolean; size : integer) return std_logic_vector;
75
function calc_sum_len( widtha : integer; widthb : integer) return integer;
76
 
77
end cycloneii_atom_pack;
78
 
79
library IEEE;
80
use IEEE.std_logic_1164.all;
81
 
82
package body cycloneii_atom_pack is
83
 
84
type masklength is array (4 downto 1) of std_logic_vector(3 downto 0);
85
function str_to_bin (lut_mask : string) return std_logic_vector is
86
variable slice : masklength := (OTHERS => "0000");
87
variable mask : std_logic_vector(15 downto 0);
88
 
89
 
90
begin
91
 
92
    for i in 1 to lut_mask'length loop
93
        case lut_mask(i) is
94
            when '0' => slice(i) := "0000";
95
            when '1' => slice(i) := "0001";
96
            when '2' => slice(i) := "0010";
97
            when '3' => slice(i) := "0011";
98
            when '4' => slice(i) := "0100";
99
            when '5' => slice(i) := "0101";
100
            when '6' => slice(i) := "0110";
101
            when '7' => slice(i) := "0111";
102
            when '8' => slice(i) := "1000";
103
            when '9' => slice(i) := "1001";
104
            when 'a' => slice(i) := "1010";
105
            when 'A' => slice(i) := "1010";
106
            when 'b' => slice(i) := "1011";
107
            when 'B' => slice(i) := "1011";
108
            when 'c' => slice(i) := "1100";
109
            when 'C' => slice(i) := "1100";
110
            when 'd' => slice(i) := "1101";
111
            when 'D' => slice(i) := "1101";
112
            when 'e' => slice(i) := "1110";
113
            when 'E' => slice(i) := "1110";
114
            when others => slice(i) := "1111";
115
        end case;
116
    end loop;
117
 
118
 
119
    mask := (slice(1) & slice(2) & slice(3) & slice(4));
120
    return (mask);
121
 
122
end str_to_bin;
123
 
124
function product (list: std_logic_vector) return std_logic is
125
begin
126
 
127
    for i in 0 to 31 loop
128
        if list(i) = '0' then
129
            return ('0');
130
        end if;
131
    end loop;
132
    return ('1');
133
 
134
end product;
135
 
136
function alt_conv_integer(arg : in std_logic_vector) return integer is
137
variable result : integer;
138
begin
139
    result := 0;
140
    for i in arg'range loop
141
        if arg(i) = '1' then
142
            result := result + 2**i;
143
        end if;
144
    end loop;
145
    return result;
146
end alt_conv_integer;
147
 
148
function int2str( value : integer ) return string is
149
variable ivalue,index : integer;
150
variable digit : integer;
151
variable line_no: string(8 downto 1) := "        ";
152
begin
153
    ivalue := value;
154
    index := 1;
155
    if (ivalue = 0) then
156
        line_no := "       0";
157
    end if;
158
    while (ivalue > 0) loop
159
        digit := ivalue MOD 10;
160
        ivalue := ivalue/10;
161
        case digit is
162
            when 0 =>
163
                    line_no(index) := '0';
164
            when 1 =>
165
                    line_no(index) := '1';
166
            when 2 =>
167
                    line_no(index) := '2';
168
            when 3 =>
169
                    line_no(index) := '3';
170
            when 4 =>
171
                    line_no(index) := '4';
172
            when 5 =>
173
                    line_no(index) := '5';
174
            when 6 =>
175
                    line_no(index) := '6';
176
            when 7 =>
177
                    line_no(index) := '7';
178
            when 8 =>
179
                    line_no(index) := '8';
180
            when 9 =>
181
                    line_no(index) := '9';
182
            when others =>
183
                    ASSERT FALSE
184
                    REPORT "Illegal number!"
185
                    SEVERITY ERROR;
186
        end case;
187
        index := index + 1;
188
    end loop;
189
    return line_no;
190
end;
191
 
192
function map_x_to_0 (value : std_logic) return std_logic is
193
begin
194
    if (Is_X (value) = TRUE) then
195
        return '0';
196
    else
197
        return value;
198
    end if;
199
end;
200
 
201
function SelectDelay (CONSTANT Paths : IN  VitalPathArray01Type) return TIME IS
202
 
203
variable Temp  : TIME;
204
variable TransitionTime  : TIME := TIME'HIGH;
205
variable PathDelay : TIME := TIME'HIGH;
206
 
207
begin
208
 
209
    for i IN Paths'RANGE loop
210
        next when not Paths(i).PathCondition;
211
 
212
        next when Paths(i).InputChangeTime > TransitionTime;
213
 
214
        Temp := Paths(i).PathDelay(tr01);
215
 
216
        if Paths(i).InputChangeTime < TransitionTime then
217
            PathDelay := Temp;
218
        else
219
            if Temp < PathDelay then
220
                PathDelay := Temp;
221
            end if;
222
        end if;
223
        TransitionTime := Paths(i).InputChangeTime;
224
    end loop;
225
 
226
    return PathDelay;
227
 
228
end;
229
 
230
function int2bit (arg : integer) return std_logic is
231
    variable int_val : integer := arg;
232
    variable result : std_logic;
233
    begin
234
 
235
            if (int_val  = 0) then
236
                result := '0';
237
            else
238
                result := '1';
239
            end if;
240
 
241
        return result;
242
end int2bit;
243
 
244
function int2bit (arg : boolean) return std_logic is
245
    variable int_val : boolean := arg;
246
    variable result : std_logic;
247
    begin
248
 
249
            if (int_val ) then
250
                result := '1';
251
            else
252
                result := '0';
253
            end if;
254
 
255
        return result;
256
end int2bit;
257
 
258
function bin2int (s : std_logic_vector) return integer is
259
 
260
      constant temp      : std_logic_vector(s'high-s'low DOWNTO 0) := s;
261
      variable result      : integer := 0;
262
   begin
263
      for i in temp'range loop
264
         if (temp(i) = '1') then
265
            result := result + (2**i);
266
         end if;
267
      end loop;
268
      return(result);
269
   end bin2int;
270
 
271
function bin2int (s : std_logic) return integer is
272
      constant temp      : std_logic := s;
273
      variable result      : integer := 0;
274
   begin
275
         if (temp = '1') then
276
            result := 1;
277
         else
278
                result := 0;
279
         end if;
280
      return(result);
281
        end bin2int;
282
 
283
        function int2bin (arg : integer; size : integer) return std_logic_vector is
284
    variable int_val : integer := arg;
285
    variable result : std_logic_vector(size-1 downto 0);
286
    begin
287
        for i in 0 to result'left loop
288
            if ((int_val mod 2) = 0) then
289
                result(i) := '0';
290
            else
291
                result(i) := '1';
292
            end if;
293
            int_val := int_val/2;
294
        end loop;
295
        return result;
296
    end int2bin;
297
 
298
function int2bin (arg : boolean; size : integer) return std_logic_vector is
299
    variable result : std_logic_vector(size-1 downto 0);
300
    begin
301
                if(arg)then
302
                        result := (OTHERS => '1');
303
                else
304
                        result := (OTHERS => '0');
305
                end if;
306
        return result;
307
    end int2bin;
308
 
309
function calc_sum_len( widtha : integer; widthb : integer) return integer is
310
variable result: integer;
311
begin
312
        if(widtha >= widthb) then
313
                result := widtha + 1;
314
        else
315
                result := widthb + 1;
316
        end if;
317
        return result;
318
end calc_sum_len;
319
 
320
end cycloneii_atom_pack;
321
 
322
Library ieee;
323
use ieee.std_logic_1164.all;
324
 
325
Package cycloneii_pllpack is
326
 
327
 
328
    procedure find_simple_integer_fraction( numerator   : in integer;
329
                                            denominator : in integer;
330
                                            max_denom   : in integer;
331
                                            fraction_num : out integer;
332
                                            fraction_div : out integer);
333
 
334
    procedure find_m_and_n_4_manual_phase ( inclock_period : in integer;
335
                                            vco_phase_shift_step : in integer;
336
                                            clk0_mult: in integer; clk1_mult: in integer;
337
                                            clk2_mult: in integer; clk3_mult: in integer;
338
                                            clk4_mult: in integer; clk5_mult: in integer;
339
                                            clk6_mult: in integer; clk7_mult: in integer;
340
                                            clk8_mult: in integer; clk9_mult: in integer;
341
                                            clk0_div : in integer; clk1_div : in integer;
342
                                            clk2_div : in integer; clk3_div : in integer;
343
                                            clk4_div : in integer; clk5_div : in integer;
344
                                            clk6_div : in integer; clk7_div : in integer;
345
                                            clk8_div : in integer; clk9_div : in integer;
346
                                            clk0_used : in string; clk1_used : in string;
347
                                            clk2_used : in string; clk3_used : in string;
348
                                            clk4_used : in string; clk5_used : in string;
349
                                            clk6_used : in string; clk7_used : in string;
350
                                            clk8_used : in string; clk9_used : in string;
351
                                            m : out integer;
352
                                            n : out integer );
353
 
354
    function gcd (X: integer; Y: integer) return integer;
355
 
356
    function count_digit (X: integer) return integer;
357
 
358
    function scale_num (X: integer; Y: integer) return integer;
359
 
360
    function lcm (A1: integer; A2: integer; A3: integer; A4: integer;
361
                A5: integer; A6: integer; A7: integer;
362
                A8: integer; A9: integer; A10: integer; P: integer) return integer;
363
 
364
    function output_counter_value (clk_divide: integer; clk_mult : integer ;
365
            M: integer; N: integer ) return integer;
366
 
367
    function counter_mode (duty_cycle: integer; output_counter_value: integer) return string;
368
 
369
    function counter_high (output_counter_value: integer := 1; duty_cycle: integer)
370
                        return integer;
371
 
372
    function counter_low (output_counter_value: integer; duty_cycle: integer)
373
                        return integer;
374
 
375
    function mintimedelay (t1: integer; t2: integer; t3: integer; t4: integer;
376
                        t5: integer; t6: integer; t7: integer; t8: integer;
377
                        t9: integer; t10: integer) return integer;
378
 
379
    function maxnegabs (t1: integer; t2: integer; t3: integer; t4: integer;
380
                        t5: integer; t6: integer; t7: integer; t8: integer;
381
                        t9: integer; t10: integer) return integer;
382
 
383
    function counter_time_delay ( clk_time_delay: integer;
384
                        m_time_delay: integer; n_time_delay: integer)
385
                        return integer;
386
 
387
    function get_phase_degree (phase_shift: integer; clk_period: integer) return integer;
388
 
389
    function counter_initial (tap_phase: integer; m: integer; n: integer)
390
                        return integer;
391
 
392
    function counter_ph (tap_phase: integer; m : integer; n: integer) return integer;
393
 
394
    function ph_adjust (tap_phase: integer; ph_base : integer) return integer;
395
 
396
    function translate_string (mode : string) return string;
397
 
398
    function str2int (s : string) return integer;
399
 
400
    function dqs_str2int (s : string) return integer;
401
 
402
end cycloneii_pllpack;
403
 
404
package body cycloneii_pllpack is
405
 
406
 
407
-- finds the closest integer fraction of a given pair of numerator and denominator. 
408
procedure find_simple_integer_fraction( numerator   : in integer;
409
                                        denominator : in integer;
410
                                        max_denom   : in integer;
411
                                        fraction_num : out integer;
412
                                        fraction_div : out integer) is
413
    constant MAX_ITER : integer := 20;
414
    type INT_ARRAY is array ((MAX_ITER-1) downto 0) of integer;
415
 
416
    variable quotient_array : INT_ARRAY;
417
    variable int_loop_iter : integer;
418
    variable int_quot  : integer;
419
    variable m_value   : integer;
420
    variable d_value   : integer;
421
    variable old_m_value : integer;
422
    variable swap  : integer;
423
    variable loop_iter : integer;
424
    variable num   : integer;
425
    variable den   : integer;
426
    variable i_max_iter : integer;
427
 
428
begin
429
    loop_iter := 0;
430
 
431
    if (numerator = 0) then
432
        num := 1;
433
    else
434
        num := numerator;
435
    end if;
436
 
437
    if (denominator = 0) then
438
        den := 1;
439
    else
440
        den := denominator;
441
    end if;
442
 
443
    i_max_iter := max_iter;
444
 
445
    while (loop_iter < i_max_iter) loop
446
        int_quot := num / den;
447
        quotient_array(loop_iter) := int_quot;
448
        num := num - (den*int_quot);
449
        loop_iter := loop_iter+1;
450
 
451
        if ((num = 0) or (max_denom /= -1) or (loop_iter = i_max_iter)) then
452
            -- calculate the numerator and denominator if there is a restriction on the
453
            -- max denom value or if the loop is ending
454
            m_value := 0;
455
            d_value := 1;
456
            -- get the rounded value at this stage for the remaining fraction
457
            if (den /= 0) then
458
                m_value := (2*num/den);
459
            end if;
460
            -- calculate the fraction numerator and denominator at this stage
461
            for int_loop_iter in (loop_iter-1) downto 0 loop
462
                if (m_value = 0) then
463
                    m_value := quotient_array(int_loop_iter);
464
                    d_value := 1;
465
                else
466
                    old_m_value := m_value;
467
                    m_value := (quotient_array(int_loop_iter)*m_value) + d_value;
468
                    d_value := old_m_value;
469
                end if;
470
            end loop;
471
            -- if the denominator is less than the maximum denom_value or if there is no restriction save it
472
            if ((d_value <= max_denom) or (max_denom = -1)) then
473
                if ((m_value = 0) or (d_value = 0)) then
474
                    fraction_num := numerator;
475
                    fraction_div := denominator;
476
                else
477
                    fraction_num := m_value;
478
                    fraction_div := d_value;
479
                end if;
480
            end if;
481
            -- end the loop if the denomitor has overflown or the numerator is zero (no remainder during this round)
482
            if (((d_value > max_denom) and (max_denom /= -1)) or (num = 0)) then
483
                i_max_iter := loop_iter;
484
            end if;
485
        end if;
486
        -- swap the numerator and denominator for the next round
487
        swap := den;
488
        den := num;
489
        num := swap;
490
    end loop;
491
end find_simple_integer_fraction;
492
 
493
-- find the M and N values for Manual phase based on the following 5 criterias:
494
-- 1. The PFD frequency (i.e. Fin / N) must be in the range 5 MHz to 720 MHz
495
-- 2. The VCO frequency (i.e. Fin * M / N) must be in the range 300 MHz to 1300 MHz
496
-- 3. M is less than 512
497
-- 4. N is less than 512
498
-- 5. It's the smallest M/N which satisfies all the above constraints, and is within 2ps
499
--    of the desired vco-phase-shift-step
500
procedure find_m_and_n_4_manual_phase ( inclock_period : in integer;
501
                                        vco_phase_shift_step : in integer;
502
                                        clk0_mult: in integer; clk1_mult: in integer;
503
                                        clk2_mult: in integer; clk3_mult: in integer;
504
                                        clk4_mult: in integer; clk5_mult: in integer;
505
                                        clk6_mult: in integer; clk7_mult: in integer;
506
                                        clk8_mult: in integer; clk9_mult: in integer;
507
                                        clk0_div : in integer; clk1_div : in integer;
508
                                        clk2_div : in integer; clk3_div : in integer;
509
                                        clk4_div : in integer; clk5_div : in integer;
510
                                        clk6_div : in integer; clk7_div : in integer;
511
                                        clk8_div : in integer; clk9_div : in integer;
512
                                        clk0_used : in string; clk1_used : in string;
513
                                        clk2_used : in string; clk3_used : in string;
514
                                        clk4_used : in string; clk5_used : in string;
515
                                        clk6_used : in string; clk7_used : in string;
516
                                        clk8_used : in string; clk9_used : in string;
517
                                        m : out integer;
518
                                        n : out integer ) is
519
        constant MAX_M : integer := 511;
520
        constant MAX_N : integer := 511;
521
        constant MAX_PFD : integer := 720;
522
        constant MIN_PFD : integer := 5;
523
        constant MAX_VCO : integer := 1600; -- max vco frequency. (in mHz)
524
        constant MIN_VCO : integer := 300;  -- min vco frequency. (in mHz)
525
        constant MAX_OFFSET : real := 0.004;
526
 
527
        variable vco_period : integer;
528
        variable pfd_freq : integer;
529
        variable vco_freq : integer;
530
        variable vco_ps_step_value : integer;
531
 
532
        variable i_m : integer;
533
        variable i_n : integer;
534
 
535
        variable i_pre_m : integer;
536
        variable i_pre_n : integer;
537
 
538
        variable closest_vco_step_value : integer;
539
 
540
        variable i_max_iter : integer;
541
        variable loop_iter : integer;
542
 
543
        variable clk0_div_factor_real : real;
544
        variable clk1_div_factor_real : real;
545
        variable clk2_div_factor_real : real;
546
        variable clk3_div_factor_real : real;
547
        variable clk4_div_factor_real : real;
548
        variable clk5_div_factor_real : real;
549
        variable clk6_div_factor_real : real;
550
        variable clk7_div_factor_real : real;
551
        variable clk8_div_factor_real : real;
552
        variable clk9_div_factor_real : real;
553
        variable clk0_div_factor_int : integer;
554
        variable clk1_div_factor_int : integer;
555
        variable clk2_div_factor_int : integer;
556
        variable clk3_div_factor_int : integer;
557
        variable clk4_div_factor_int : integer;
558
        variable clk5_div_factor_int : integer;
559
        variable clk6_div_factor_int : integer;
560
        variable clk7_div_factor_int : integer;
561
        variable clk8_div_factor_int : integer;
562
        variable clk9_div_factor_int : integer;
563
begin
564
    vco_period := vco_phase_shift_step * 8;
565
    i_pre_m := 0;
566
    i_pre_n := 0;
567
    closest_vco_step_value := 0;
568
 
569
    LOOP_1 :   for i_n_out in 1 to MAX_N loop
570
        for i_m_out in 1 to MAX_M loop
571
 
572
            clk0_div_factor_real := real(clk0_div * i_m_out) / real(clk0_mult * i_n_out);
573
            clk1_div_factor_real := real(clk1_div * i_m_out) / real(clk1_mult * i_n_out);
574
            clk2_div_factor_real := real(clk2_div * i_m_out) / real(clk2_mult * i_n_out);
575
            clk3_div_factor_real := real(clk3_div * i_m_out) / real(clk3_mult * i_n_out);
576
            clk4_div_factor_real := real(clk4_div * i_m_out) / real(clk4_mult * i_n_out);
577
            clk5_div_factor_real := real(clk5_div * i_m_out) / real(clk5_mult * i_n_out);
578
            clk6_div_factor_real := real(clk6_div * i_m_out) / real(clk6_mult * i_n_out);
579
            clk7_div_factor_real := real(clk7_div * i_m_out) / real(clk7_mult * i_n_out);
580
            clk8_div_factor_real := real(clk8_div * i_m_out) / real(clk8_mult * i_n_out);
581
            clk9_div_factor_real := real(clk9_div * i_m_out) / real(clk9_mult * i_n_out);
582
 
583
            clk0_div_factor_int := integer(clk0_div_factor_real);
584
            clk1_div_factor_int := integer(clk1_div_factor_real);
585
            clk2_div_factor_int := integer(clk2_div_factor_real);
586
            clk3_div_factor_int := integer(clk3_div_factor_real);
587
            clk4_div_factor_int := integer(clk4_div_factor_real);
588
            clk5_div_factor_int := integer(clk5_div_factor_real);
589
            clk6_div_factor_int := integer(clk6_div_factor_real);
590
            clk7_div_factor_int := integer(clk7_div_factor_real);
591
            clk8_div_factor_int := integer(clk8_div_factor_real);
592
            clk9_div_factor_int := integer(clk9_div_factor_real);
593
 
594
            if (((abs(clk0_div_factor_real - real(clk0_div_factor_int)) < MAX_OFFSET) or (clk0_used = "unused")) and
595
                ((abs(clk1_div_factor_real - real(clk1_div_factor_int)) < MAX_OFFSET) or (clk1_used = "unused")) and
596
                ((abs(clk2_div_factor_real - real(clk2_div_factor_int)) < MAX_OFFSET) or (clk2_used = "unused")) and
597
                ((abs(clk3_div_factor_real - real(clk3_div_factor_int)) < MAX_OFFSET) or (clk3_used = "unused")) and
598
                ((abs(clk4_div_factor_real - real(clk4_div_factor_int)) < MAX_OFFSET) or (clk4_used = "unused")) and
599
                ((abs(clk5_div_factor_real - real(clk5_div_factor_int)) < MAX_OFFSET) or (clk5_used = "unused")) and
600
                ((abs(clk6_div_factor_real - real(clk6_div_factor_int)) < MAX_OFFSET) or (clk6_used = "unused")) and
601
                ((abs(clk7_div_factor_real - real(clk7_div_factor_int)) < MAX_OFFSET) or (clk7_used = "unused")) and
602
                ((abs(clk8_div_factor_real - real(clk8_div_factor_int)) < MAX_OFFSET) or (clk8_used = "unused")) and
603
                ((abs(clk9_div_factor_real - real(clk9_div_factor_int)) < MAX_OFFSET) or (clk9_used = "unused")) )
604
            then
605
                if ((i_m_out /= 0) and (i_n_out /= 0))
606
                then
607
                    pfd_freq := 1000000 / (inclock_period * i_n_out);
608
                    vco_freq := (1000000 * i_m_out) / (inclock_period * i_n_out);
609
                    vco_ps_step_value := (inclock_period * i_n_out) / (8 * i_m_out);
610
 
611
                    if ( (i_m_out < max_m) and (i_n_out < max_n) and (pfd_freq >= min_pfd) and (pfd_freq <= max_pfd) and
612
                        (vco_freq >= min_vco) and (vco_freq <= max_vco) )
613
                    then
614
                        if (abs(vco_ps_step_value - vco_phase_shift_step) <= 2)
615
                        then
616
                            i_pre_m := i_m_out;
617
                            i_pre_n := i_n_out;
618
                            exit LOOP_1;
619
                        else
620
                            if ((closest_vco_step_value = 0) or (abs(vco_ps_step_value - vco_phase_shift_step) < abs(closest_vco_step_value - vco_phase_shift_step)))
621
                            then
622
                                i_pre_m := i_m_out;
623
                                i_pre_n := i_n_out;
624
                                closest_vco_step_value := vco_ps_step_value;
625
                            end if;
626
                        end if;
627
                    end if;
628
                end if;
629
            end if;
630
        end loop;
631
    end loop;
632
 
633
    if ((i_pre_m /= 0) and (i_pre_n /= 0))
634
    then
635
        find_simple_integer_fraction(i_pre_m, i_pre_n,
636
                    MAX_N, m, n);
637
    else
638
        n := 1;
639
        m := lcm  (clk0_mult, clk1_mult, clk2_mult, clk3_mult,
640
                clk4_mult, clk5_mult, clk6_mult,
641
                clk7_mult, clk8_mult, clk9_mult, inclock_period);
642
    end if;
643
end find_m_and_n_4_manual_phase;
644
 
645
-- find the greatest common denominator of X and Y
646
function gcd (X: integer; Y: integer) return integer is
647
variable L, S, R, G : integer := 1;
648
begin
649
    if (X < Y) then -- find which is smaller.
650
        S := X;
651
        L := Y;
652
    else
653
        S := Y;
654
        L := X;
655
    end if;
656
 
657
    R := S;
658
    while ( R > 1) loop
659
        S := L;
660
        L := R;
661
        R := S rem L;   -- divide bigger number by smaller.
662
                        -- remainder becomes smaller number.
663
    end loop;
664
    if (R = 0) then  -- if evenly divisible then L is gcd else it is 1.
665
        G := L;
666
    else
667
        G := R;
668
    end if;
669
 
670
    return G;
671
end gcd;
672
 
673
-- count the number of digits in the given integer
674
function count_digit (X: integer)
675
        return integer is
676
variable count, result: integer := 0;
677
begin
678
    result := X;
679
    while (result /= 0) loop
680
        result := (result / 10);
681
        count := count + 1;
682
    end loop;
683
 
684
    return count;
685
end count_digit;
686
 
687
-- reduce the given huge number to Y significant digits
688
function scale_num (X: integer; Y: integer)
689
        return integer is
690
variable count : integer := 0;
691
variable lc, fac_ten, result: integer := 1;
692
begin
693
    count := count_digit(X);
694
 
695
    for lc in 1 to (count-Y) loop
696
        fac_ten := fac_ten * 10;
697
    end loop;
698
 
699
    result := (X / fac_ten);
700
 
701
    return result;
702
end scale_num;
703
 
704
-- find the least common multiple of A1 to A10
705
function lcm (A1: integer; A2: integer; A3: integer; A4: integer;
706
            A5: integer; A6: integer; A7: integer;
707
            A8: integer; A9: integer; A10: integer; P: integer)
708
        return integer is
709
variable M1, M2, M3, M4, M5 , M6, M7, M8, M9, R: integer := 1;
710
begin
711
    M1 := (A1 * A2)/gcd(A1, A2);
712
    M2 := (M1 * A3)/gcd(M1, A3);
713
    M3 := (M2 * A4)/gcd(M2, A4);
714
    M4 := (M3 * A5)/gcd(M3, A5);
715
    M5 := (M4 * A6)/gcd(M4, A6);
716
    M6 := (M5 * A7)/gcd(M5, A7);
717
    M7 := (M6 * A8)/gcd(M6, A8);
718
    M8 := (M7 * A9)/gcd(M7, A9);
719
    M9 := (M8 * A10)/gcd(M8, A10);
720
    if (M9 < 3) then
721
        R := 10;
722
    elsif (M9 = 3) then
723
        R := 9;
724
    elsif ((M9 <= 10) and (M9 > 3)) then
725
        R := 4 * M9;
726
    elsif (M9 > 1000) then
727
        R := scale_num(M9,3);
728
    else
729
        R := M9 ;
730
    end if;
731
 
732
    return R;
733
end lcm;
734
 
735
-- find the factor of division of the output clock frequency compared to the VCO
736
function output_counter_value (clk_divide: integer; clk_mult: integer ;
737
                                M: integer; N: integer ) return integer is
738
variable r_real : real := 1.0;
739
variable r: integer := 1;
740
begin
741
    r_real := real(clk_divide * M)/ real(clk_mult * N);
742
    r := integer(r_real);
743
 
744
    return R;
745
end output_counter_value;
746
 
747
-- find the mode of each PLL counter - bypass, even or odd
748
function counter_mode (duty_cycle: integer; output_counter_value: integer)
749
        return string is
750
variable R: string (1 to 6) := "      ";
751
variable counter_value: integer := 1;
752
begin
753
    counter_value := (2*duty_cycle*output_counter_value)/100;
754
    if output_counter_value = 1 then
755
        R := "bypass";
756
    elsif (counter_value REM 2) = 0 then
757
        R := "  even";
758
    else
759
        R := "   odd";
760
    end if;
761
 
762
    return R;
763
end counter_mode;
764
 
765
-- find the number of VCO clock cycles to hold the output clock high
766
function counter_high (output_counter_value: integer := 1; duty_cycle: integer)
767
        return integer is
768
variable R: integer := 1;
769
variable half_cycle_high : integer := 1;
770
begin
771
    half_cycle_high := (duty_cycle * output_counter_value *2)/100 ;
772
    if (half_cycle_high REM 2 = 0) then
773
        R := half_cycle_high/2 ;
774
    else
775
        R := (half_cycle_high/2) + 1;
776
    end if;
777
 
778
    return R;
779
end;
780
 
781
-- find the number of VCO clock cycles to hold the output clock low
782
function counter_low (output_counter_value: integer; duty_cycle: integer)
783
        return integer is
784
variable R, R1: integer := 1;
785
variable half_cycle_high : integer := 1;
786
begin
787
    half_cycle_high := (duty_cycle * output_counter_value*2)/100 ;
788
    if (half_cycle_high REM 2 = 0) then
789
        R1 := half_cycle_high/2 ;
790
    else
791
        R1 := (half_cycle_high/2) + 1;
792
    end if;
793
 
794
    R := output_counter_value - R1;
795
 
796
    if (R = 0) then
797
        R := 1;
798
    end if;
799
 
800
    return R;
801
end;
802
 
803
-- find the smallest time delay amongst t1 to t10
804
function mintimedelay (t1: integer; t2: integer; t3: integer; t4: integer;
805
                        t5: integer; t6: integer; t7: integer; t8: integer;
806
                        t9: integer; t10: integer) return integer is
807
variable m1,m2,m3,m4,m5,m6,m7,m8,m9 : integer := 0;
808
begin
809
    if (t1 < t2) then m1 := t1; else m1 := t2; end if;
810
    if (m1 < t3) then m2 := m1; else m2 := t3; end if;
811
    if (m2 < t4) then m3 := m2; else m3 := t4; end if;
812
    if (m3 < t5) then m4 := m3; else m4 := t5; end if;
813
    if (m4 < t6) then m5 := m4; else m5 := t6; end if;
814
    if (m5 < t7) then m6 := m5; else m6 := t7; end if;
815
    if (m6 < t8) then m7 := m6; else m7 := t8; end if;
816
    if (m7 < t9) then m8 := m7; else m8 := t9; end if;
817
    if (m8 < t10) then m9 := m8; else m9 := t10; end if;
818
    if (m9 > 0) then return m9; else return 0; end if;
819
end;
820
 
821
-- find the numerically largest negative number, and return its absolute value
822
function maxnegabs (t1: integer; t2: integer; t3: integer; t4: integer;
823
                    t5: integer; t6: integer; t7: integer; t8: integer;
824
                    t9: integer; t10: integer) return integer is
825
variable m1,m2,m3,m4,m5,m6,m7,m8,m9 : integer := 0;
826
begin
827
    if (t1 < t2) then m1 := t1; else m1 := t2; end if;
828
    if (m1 < t3) then m2 := m1; else m2 := t3; end if;
829
    if (m2 < t4) then m3 := m2; else m3 := t4; end if;
830
    if (m3 < t5) then m4 := m3; else m4 := t5; end if;
831
    if (m4 < t6) then m5 := m4; else m5 := t6; end if;
832
    if (m5 < t7) then m6 := m5; else m6 := t7; end if;
833
    if (m6 < t8) then m7 := m6; else m7 := t8; end if;
834
    if (m7 < t9) then m8 := m7; else m8 := t9; end if;
835
    if (m8 < t10) then m9 := m8; else m9 := t10; end if;
836
    if (m9 < 0) then return (0 - m9); else return 0; end if;
837
end;
838
 
839
-- adjust the phase (tap_phase) with the largest negative number (ph_base)
840
function ph_adjust (tap_phase: integer; ph_base : integer) return integer is
841
begin
842
    return (tap_phase + ph_base);
843
end;
844
 
845
-- find the time delay for each PLL counter
846
function counter_time_delay (clk_time_delay: integer;
847
                            m_time_delay: integer; n_time_delay: integer)
848
        return integer is
849
variable R: integer := 0;
850
begin
851
    R := clk_time_delay + m_time_delay - n_time_delay;
852
 
853
    return R;
854
end;
855
 
856
-- calculate the given phase shift (in ps) in terms of degrees
857
function get_phase_degree (phase_shift: integer; clk_period: integer)
858
        return integer is
859
variable result: integer := 0;
860
begin
861
    result := ( phase_shift * 360 ) / clk_period;
862
    -- to round up the calculation result
863
    if (result > 0) then
864
        result := result + 1;
865
    elsif (result < 0) then
866
        result := result - 1;
867
    else
868
        result := 0;
869
    end if;
870
 
871
    return result;
872
end;
873
 
874
-- find the number of VCO clock cycles to wait initially before the first rising
875
-- edge of the output clock
876
function counter_initial (tap_phase: integer; m: integer; n: integer)
877
        return integer is
878
variable R: integer;
879
variable R1: real;
880
begin
881
    R1 := (real(abs(tap_phase)) * real(m))/(360.0 * real(n)) + 0.6;
882
    -- Note NCSim VHDL had problem in rounding up for 0.5 - 0.99. 
883
    -- This checking will ensure that the rounding up is done.
884
    if (R1 >= 0.5) and (R1 <= 1.0) then
885
        R1 := 1.0;
886
    end if;
887
 
888
    R := integer(R1);
889
 
890
    return R;
891
end;
892
 
893
-- find which VCO phase tap (0 to 7) to align the rising edge of the output clock to
894
function counter_ph (tap_phase: integer; m: integer; n: integer) return integer is
895
variable R: integer := 0;
896
begin
897
    -- 0.5 is added for proper rounding of the tap_phase.
898
    R := integer(real(integer(real(tap_phase * m / n)+ 0.5) REM 360)/45.0) rem 8;
899
 
900
    return R;
901
end;
902
 
903
-- convert given string to length 6 by padding with spaces
904
function translate_string (mode : string) return string is
905
variable new_mode : string (1 to 6) := "      ";
906
begin
907
    if (mode = "bypass") then
908
        new_mode := "bypass";
909
    elsif (mode = "even") then
910
        new_mode := "  even";
911
    elsif (mode = "odd") then
912
        new_mode := "   odd";
913
    end if;
914
 
915
    return new_mode;
916
end;
917
 
918
function str2int (s : string) return integer is
919
variable len : integer := s'length;
920
variable newdigit : integer := 0;
921
variable sign : integer := 1;
922
variable digit : integer := 0;
923
begin
924
    for i in 1 to len loop
925
        case s(i) is
926
            when '-' =>
927
                if i = 1 then
928
                    sign := -1;
929
                else
930
                    ASSERT FALSE
931
                    REPORT "Illegal Character "&  s(i) & "i n string parameter! "
932
                    SEVERITY ERROR;
933
                end if;
934
            when '0' =>
935
                digit := 0;
936
            when '1' =>
937
                digit := 1;
938
            when '2' =>
939
                digit := 2;
940
            when '3' =>
941
                digit := 3;
942
            when '4' =>
943
                digit := 4;
944
            when '5' =>
945
                digit := 5;
946
            when '6' =>
947
                digit := 6;
948
            when '7' =>
949
                digit := 7;
950
            when '8' =>
951
                digit := 8;
952
            when '9' =>
953
                digit := 9;
954
            when others =>
955
                ASSERT FALSE
956
                REPORT "Illegal Character "&  s(i) & "in string parameter! "
957
                SEVERITY ERROR;
958
        end case;
959
        newdigit := newdigit * 10 + digit;
960
    end loop;
961
 
962
    return (sign*newdigit);
963
end;
964
 
965
function dqs_str2int (s : string) return integer is
966
variable len : integer := s'length;
967
variable newdigit : integer := 0;
968
variable sign : integer := 1;
969
variable digit : integer := 0;
970
variable err : boolean := false;
971
begin
972
    for i in 1 to len loop
973
        case s(i) is
974
            when '-' =>
975
                if i = 1 then
976
                    sign := -1;
977
                else
978
                    ASSERT FALSE
979
                    REPORT "Illegal Character "&  s(i) & " in string parameter! "
980
                    SEVERITY ERROR;
981
                    err := true;
982
                end if;
983
            when '0' =>
984
                digit := 0;
985
            when '1' =>
986
                digit := 1;
987
            when '2' =>
988
                digit := 2;
989
            when '3' =>
990
                digit := 3;
991
            when '4' =>
992
                digit := 4;
993
            when '5' =>
994
                digit := 5;
995
            when '6' =>
996
                digit := 6;
997
            when '7' =>
998
                digit := 7;
999
            when '8' =>
1000
                digit := 8;
1001
            when '9' =>
1002
                digit := 9;
1003
            when others =>
1004
                -- set error flag
1005
                err := true;
1006
        end case;
1007
        if (err) then
1008
            err := false;
1009
        else
1010
            newdigit := newdigit * 10 + digit;
1011
        end if;
1012
    end loop;
1013
 
1014
    return (sign*newdigit);
1015
end;
1016
 
1017
end cycloneii_pllpack;
1018
 
1019
--
1020
--
1021
--  DFFE Model
1022
--
1023
--
1024
 
1025
LIBRARY IEEE;
1026
use IEEE.STD_LOGIC_1164.all;
1027
use IEEE.VITAL_Timing.all;
1028
use IEEE.VITAL_Primitives.all;
1029
use work.cycloneii_atom_pack.all;
1030
 
1031
entity cycloneii_dffe is
1032
    generic(
1033
        TimingChecksOn: Boolean := True;
1034
        XOn: Boolean := DefGlitchXOn;
1035
        MsgOn: Boolean := DefGlitchMsgOn;
1036
        MsgOnChecks: Boolean := DefMsgOnChecks;
1037
        XOnChecks: Boolean := DefXOnChecks;
1038
        InstancePath: STRING := "*";
1039
        tpd_PRN_Q_negedge              :  VitalDelayType01 := DefPropDelay01;
1040
        tpd_CLRN_Q_negedge             :  VitalDelayType01 := DefPropDelay01;
1041
        tpd_CLK_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
1042
        tpd_ENA_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
1043
        tsetup_D_CLK_noedge_posedge    :  VitalDelayType := DefSetupHoldCnst;
1044
        tsetup_D_CLK_noedge_negedge    :  VitalDelayType := DefSetupHoldCnst;
1045
        tsetup_ENA_CLK_noedge_posedge  :  VitalDelayType := DefSetupHoldCnst;
1046
        thold_D_CLK_noedge_posedge     :   VitalDelayType := DefSetupHoldCnst;
1047
        thold_D_CLK_noedge_negedge     :   VitalDelayType := DefSetupHoldCnst;
1048
        thold_ENA_CLK_noedge_posedge   :   VitalDelayType := DefSetupHoldCnst;
1049
        tipd_D                         :  VitalDelayType01 := DefPropDelay01;
1050
        tipd_CLRN                      :  VitalDelayType01 := DefPropDelay01;
1051
        tipd_PRN                       :  VitalDelayType01 := DefPropDelay01;
1052
        tipd_CLK                       :  VitalDelayType01 := DefPropDelay01;
1053
        tipd_ENA                       :  VitalDelayType01 := DefPropDelay01);
1054
 
1055
    port(
1056
        Q                              :  out   STD_LOGIC := '0';
1057
        D                              :  in    STD_LOGIC;
1058
        CLRN                           :  in    STD_LOGIC;
1059
        PRN                            :  in    STD_LOGIC;
1060
        CLK                            :  in    STD_LOGIC;
1061
        ENA                            :  in    STD_LOGIC);
1062
    attribute VITAL_LEVEL0 of cycloneii_dffe : entity is TRUE;
1063
end cycloneii_dffe;
1064
 
1065
-- architecture body --
1066
 
1067
architecture behave of cycloneii_dffe is
1068
    attribute VITAL_LEVEL0 of behave : architecture is TRUE;
1069
 
1070
    signal D_ipd  : STD_ULOGIC := 'U';
1071
    signal CLRN_ipd       : STD_ULOGIC := 'U';
1072
    signal PRN_ipd        : STD_ULOGIC := 'U';
1073
    signal CLK_ipd        : STD_ULOGIC := 'U';
1074
    signal ENA_ipd        : STD_ULOGIC := 'U';
1075
 
1076
begin
1077
 
1078
    ---------------------
1079
    --  INPUT PATH DELAYs
1080
    ---------------------
1081
    WireDelay : block
1082
    begin
1083
        VitalWireDelay (D_ipd, D, tipd_D);
1084
        VitalWireDelay (CLRN_ipd, CLRN, tipd_CLRN);
1085
        VitalWireDelay (PRN_ipd, PRN, tipd_PRN);
1086
        VitalWireDelay (CLK_ipd, CLK, tipd_CLK);
1087
        VitalWireDelay (ENA_ipd, ENA, tipd_ENA);
1088
    end block;
1089
    --------------------
1090
    --  BEHAVIOR SECTION
1091
    --------------------
1092
    VITALBehavior : process (D_ipd, CLRN_ipd, PRN_ipd, CLK_ipd, ENA_ipd)
1093
 
1094
    -- timing check results
1095
    VARIABLE Tviol_D_CLK : STD_ULOGIC := '0';
1096
    VARIABLE Tviol_ENA_CLK       : STD_ULOGIC := '0';
1097
    VARIABLE TimingData_D_CLK : VitalTimingDataType := VitalTimingDataInit;
1098
    VARIABLE TimingData_ENA_CLK : VitalTimingDataType := VitalTimingDataInit;
1099
 
1100
    -- functionality results
1101
    VARIABLE Violation : STD_ULOGIC := '0';
1102
    VARIABLE PrevData_Q : STD_LOGIC_VECTOR(0 to 7);
1103
    VARIABLE D_delayed : STD_ULOGIC := 'U';
1104
    VARIABLE CLK_delayed : STD_ULOGIC := 'U';
1105
    VARIABLE ENA_delayed : STD_ULOGIC := 'U';
1106
    VARIABLE Results : STD_LOGIC_VECTOR(1 to 1) := (others => '0');
1107
 
1108
    -- output glitch detection variables
1109
    VARIABLE Q_VitalGlitchData   : VitalGlitchDataType;
1110
 
1111
 
1112
    CONSTANT dffe_Q_tab : VitalStateTableType := (
1113
        ( L,  L,  x,  x,  x,  x,  x,  x,  x,  L ),
1114
        ( L,  H,  L,  H,  H,  x,  x,  H,  x,  H ),
1115
        ( L,  H,  L,  H,  x,  L,  x,  H,  x,  H ),
1116
        ( L,  H,  L,  x,  H,  H,  x,  H,  x,  H ),
1117
        ( L,  H,  H,  x,  x,  x,  H,  x,  x,  S ),
1118
        ( L,  H,  x,  x,  x,  x,  L,  x,  x,  H ),
1119
        ( L,  H,  x,  x,  x,  x,  H,  L,  x,  S ),
1120
        ( L,  x,  L,  L,  L,  x,  H,  H,  x,  L ),
1121
        ( L,  x,  L,  L,  x,  L,  H,  H,  x,  L ),
1122
        ( L,  x,  L,  x,  L,  H,  H,  H,  x,  L ),
1123
        ( L,  x,  x,  x,  x,  x,  x,  x,  x,  S ));
1124
    begin
1125
 
1126
        ------------------------
1127
        --  Timing Check Section
1128
        ------------------------
1129
        if (TimingChecksOn) then
1130
            VitalSetupHoldCheck (
1131
                Violation       => Tviol_D_CLK,
1132
                TimingData      => TimingData_D_CLK,
1133
                TestSignal      => D_ipd,
1134
                TestSignalName  => "D",
1135
                RefSignal       => CLK_ipd,
1136
                RefSignalName   => "CLK",
1137
                SetupHigh       => tsetup_D_CLK_noedge_posedge,
1138
                SetupLow        => tsetup_D_CLK_noedge_posedge,
1139
                HoldHigh        => thold_D_CLK_noedge_posedge,
1140
                HoldLow         => thold_D_CLK_noedge_posedge,
1141
                CheckEnabled    => TO_X01(( (NOT PRN_ipd) ) OR ( (NOT CLRN_ipd) ) OR ( (NOT ENA_ipd) )) /= '1',
1142
                RefTransition   => '/',
1143
                HeaderMsg       => InstancePath & "/DFFE",
1144
                XOn             => XOnChecks,
1145
                MsgOn           => MsgOnChecks );
1146
 
1147
            VitalSetupHoldCheck (
1148
                Violation       => Tviol_ENA_CLK,
1149
                TimingData      => TimingData_ENA_CLK,
1150
                TestSignal      => ENA_ipd,
1151
                TestSignalName  => "ENA",
1152
                RefSignal       => CLK_ipd,
1153
                RefSignalName   => "CLK",
1154
                SetupHigh       => tsetup_ENA_CLK_noedge_posedge,
1155
                SetupLow        => tsetup_ENA_CLK_noedge_posedge,
1156
                HoldHigh        => thold_ENA_CLK_noedge_posedge,
1157
                HoldLow         => thold_ENA_CLK_noedge_posedge,
1158
                CheckEnabled    => TO_X01(( (NOT PRN_ipd) ) OR ( (NOT CLRN_ipd) ) ) /= '1',
1159
                RefTransition   => '/',
1160
                HeaderMsg       => InstancePath & "/DFFE",
1161
                XOn             => XOnChecks,
1162
                MsgOn           => MsgOnChecks );
1163
        end if;
1164
 
1165
        -------------------------
1166
        --  Functionality Section
1167
        -------------------------
1168
        Violation := Tviol_D_CLK or Tviol_ENA_CLK;
1169
        VitalStateTable(
1170
        StateTable => dffe_Q_tab,
1171
        DataIn => (
1172
                Violation, CLRN_ipd, CLK_delayed, Results(1), D_delayed, ENA_delayed, PRN_ipd, CLK_ipd),
1173
        Result => Results,
1174
        NumStates => 1,
1175
        PreviousDataIn => PrevData_Q);
1176
        D_delayed := D_ipd;
1177
        CLK_delayed := CLK_ipd;
1178
        ENA_delayed := ENA_ipd;
1179
 
1180
        ----------------------
1181
        --  Path Delay Section
1182
        ----------------------
1183
        VitalPathDelay01 (
1184
        OutSignal => Q,
1185
        OutSignalName => "Q",
1186
        OutTemp => Results(1),
1187
        Paths => (  0 => (PRN_ipd'last_event, tpd_PRN_Q_negedge, TRUE),
1188
                    1 => (CLRN_ipd'last_event, tpd_CLRN_Q_negedge, TRUE),
1189
                    2 => (CLK_ipd'last_event, tpd_CLK_Q_posedge, TRUE)),
1190
        GlitchData => Q_VitalGlitchData,
1191
        Mode => DefGlitchMode,
1192
        XOn  => XOn,
1193
        MsgOn        => MsgOn );
1194
 
1195
    end process;
1196
 
1197
end behave;
1198
 
1199
--
1200
--
1201
--  cycloneii_mux21 Model
1202
--
1203
--
1204
 
1205
LIBRARY IEEE;
1206
use ieee.std_logic_1164.all;
1207
use IEEE.VITAL_Timing.all;
1208
use work.cycloneii_atom_pack.all;
1209
 
1210
entity cycloneii_mux21 is
1211
    generic(
1212
        TimingChecksOn: Boolean := True;
1213
        MsgOn: Boolean := DefGlitchMsgOn;
1214
        XOn: Boolean := DefGlitchXOn;
1215
        InstancePath: STRING := "*";
1216
        tpd_A_MO                      :   VitalDelayType01 := DefPropDelay01;
1217
        tpd_B_MO                      :   VitalDelayType01 := DefPropDelay01;
1218
        tpd_S_MO                      :   VitalDelayType01 := DefPropDelay01;
1219
        tipd_A                       :    VitalDelayType01 := DefPropDelay01;
1220
        tipd_B                       :    VitalDelayType01 := DefPropDelay01;
1221
        tipd_S                       :    VitalDelayType01 := DefPropDelay01);
1222
    port (
1223
        A : in std_logic := '0';
1224
        B : in std_logic := '0';
1225
        S : in std_logic := '0';
1226
        MO : out std_logic);
1227
    attribute VITAL_LEVEL0 of cycloneii_mux21 : entity is TRUE;
1228
end cycloneii_mux21;
1229
 
1230
architecture AltVITAL of cycloneii_mux21 is
1231
    attribute VITAL_LEVEL0 of AltVITAL : architecture is TRUE;
1232
 
1233
    signal A_ipd, B_ipd, S_ipd  : std_logic;
1234
 
1235
begin
1236
 
1237
    ---------------------
1238
    --  INPUT PATH DELAYs
1239
    ---------------------
1240
    WireDelay : block
1241
    begin
1242
        VitalWireDelay (A_ipd, A, tipd_A);
1243
        VitalWireDelay (B_ipd, B, tipd_B);
1244
        VitalWireDelay (S_ipd, S, tipd_S);
1245
    end block;
1246
 
1247
    --------------------
1248
    --  BEHAVIOR SECTION
1249
    --------------------
1250
    VITALBehavior : process (A_ipd, B_ipd, S_ipd)
1251
 
1252
    -- output glitch detection variables
1253
    VARIABLE MO_GlitchData       : VitalGlitchDataType;
1254
 
1255
    variable tmp_MO : std_logic;
1256
    begin
1257
        -------------------------
1258
        --  Functionality Section
1259
        -------------------------
1260
        if (S_ipd = '1') then
1261
            tmp_MO := B_ipd;
1262
        else
1263
            tmp_MO := A_ipd;
1264
        end if;
1265
 
1266
        ----------------------
1267
        --  Path Delay Section
1268
        ----------------------
1269
        VitalPathDelay01 (
1270
        OutSignal => MO,
1271
        OutSignalName => "MO",
1272
        OutTemp => tmp_MO,
1273
        Paths => (  0 => (A_ipd'last_event, tpd_A_MO, TRUE),
1274
                    1 => (B_ipd'last_event, tpd_B_MO, TRUE),
1275
                    2 => (S_ipd'last_event, tpd_S_MO, TRUE)),
1276
        GlitchData => MO_GlitchData,
1277
        Mode => DefGlitchMode,
1278
        XOn  => XOn,
1279
        MsgOn        => MsgOn );
1280
 
1281
    end process;
1282
end AltVITAL;
1283
 
1284
--
1285
--
1286
--  cycloneii_mux41 Model
1287
--
1288
--
1289
 
1290
LIBRARY IEEE;
1291
use ieee.std_logic_1164.all;
1292
use IEEE.VITAL_Timing.all;
1293
use work.cycloneii_atom_pack.all;
1294
 
1295
entity cycloneii_mux41 is
1296
    generic(
1297
            TimingChecksOn: Boolean := True;
1298
            MsgOn: Boolean := DefGlitchMsgOn;
1299
            XOn: Boolean := DefGlitchXOn;
1300
            InstancePath: STRING := "*";
1301
            tpd_IN0_MO : VitalDelayType01 := DefPropDelay01;
1302
            tpd_IN1_MO : VitalDelayType01 := DefPropDelay01;
1303
            tpd_IN2_MO : VitalDelayType01 := DefPropDelay01;
1304
            tpd_IN3_MO : VitalDelayType01 := DefPropDelay01;
1305
            tpd_S_MO : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01);
1306
            tipd_IN0 : VitalDelayType01 := DefPropDelay01;
1307
            tipd_IN1 : VitalDelayType01 := DefPropDelay01;
1308
            tipd_IN2 : VitalDelayType01 := DefPropDelay01;
1309
            tipd_IN3 : VitalDelayType01 := DefPropDelay01;
1310
            tipd_S : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01)
1311
        );
1312
    port (
1313
            IN0 : in std_logic := '0';
1314
            IN1 : in std_logic := '0';
1315
            IN2 : in std_logic := '0';
1316
            IN3 : in std_logic := '0';
1317
            S : in std_logic_vector(1 downto 0) := (OTHERS => '0');
1318
            MO : out std_logic
1319
        );
1320
    attribute VITAL_LEVEL0 of cycloneii_mux41 : entity is TRUE;
1321
end cycloneii_mux41;
1322
 
1323
architecture AltVITAL of cycloneii_mux41 is
1324
    attribute VITAL_LEVEL0 of AltVITAL : architecture is TRUE;
1325
 
1326
    signal IN0_ipd, IN1_ipd, IN2_ipd, IN3_ipd  : std_logic;
1327
    signal S_ipd : std_logic_vector(1 downto 0);
1328
 
1329
begin
1330
 
1331
    ---------------------
1332
    --  INPUT PATH DELAYs
1333
    ---------------------
1334
    WireDelay : block
1335
    begin
1336
        VitalWireDelay (IN0_ipd, IN0, tipd_IN0);
1337
        VitalWireDelay (IN1_ipd, IN1, tipd_IN1);
1338
        VitalWireDelay (IN2_ipd, IN2, tipd_IN2);
1339
        VitalWireDelay (IN3_ipd, IN3, tipd_IN3);
1340
        VitalWireDelay (S_ipd(0), S(0), tipd_S(0));
1341
        VitalWireDelay (S_ipd(1), S(1), tipd_S(1));
1342
    end block;
1343
 
1344
    --------------------
1345
    --  BEHAVIOR SECTION
1346
    --------------------
1347
    VITALBehavior : process (IN0_ipd, IN1_ipd, IN2_ipd, IN3_ipd, S_ipd(0), S_ipd(1))
1348
 
1349
    -- output glitch detection variables
1350
    VARIABLE MO_GlitchData       : VitalGlitchDataType;
1351
 
1352
    variable tmp_MO : std_logic;
1353
    begin
1354
        -------------------------
1355
        --  Functionality Section
1356
        -------------------------
1357
        if ((S_ipd(1) = '1') AND (S_ipd(0) = '1')) then
1358
            tmp_MO := IN3_ipd;
1359
        elsif ((S_ipd(1) = '1') AND (S_ipd(0) = '0')) then
1360
            tmp_MO := IN2_ipd;
1361
        elsif ((S_ipd(1) = '0') AND (S_ipd(0) = '1')) then
1362
            tmp_MO := IN1_ipd;
1363
        else
1364
            tmp_MO := IN0_ipd;
1365
        end if;
1366
 
1367
        ----------------------
1368
        --  Path Delay Section
1369
        ----------------------
1370
        VitalPathDelay01 (
1371
                        OutSignal => MO,
1372
                        OutSignalName => "MO",
1373
                        OutTemp => tmp_MO,
1374
                        Paths => (  0 => (IN0_ipd'last_event, tpd_IN0_MO, TRUE),
1375
                                    1 => (IN1_ipd'last_event, tpd_IN1_MO, TRUE),
1376
                                    2 => (IN2_ipd'last_event, tpd_IN2_MO, TRUE),
1377
                                    3 => (IN3_ipd'last_event, tpd_IN3_MO, TRUE),
1378
                                    4 => (S_ipd(0)'last_event, tpd_S_MO(0), TRUE),
1379
                                    5 => (S_ipd(1)'last_event, tpd_S_MO(1), TRUE)),
1380
                        GlitchData => MO_GlitchData,
1381
                        Mode => DefGlitchMode,
1382
                        XOn  => XOn,
1383
                        MsgOn => MsgOn );
1384
 
1385
    end process;
1386
end AltVITAL;
1387
 
1388
--
1389
--
1390
--  cycloneii_and1 Model
1391
--
1392
--
1393
LIBRARY IEEE;
1394
use IEEE.STD_LOGIC_1164.all;
1395
use IEEE.VITAL_Timing.all;
1396
use work.cycloneii_atom_pack.all;
1397
 
1398
-- entity declaration --
1399
entity cycloneii_and1 is
1400
    generic(
1401
        TimingChecksOn: Boolean := True;
1402
        MsgOn: Boolean := DefGlitchMsgOn;
1403
        XOn: Boolean := DefGlitchXOn;
1404
        InstancePath: STRING := "*";
1405
        tpd_IN1_Y                      :  VitalDelayType01 := DefPropDelay01;
1406
        tipd_IN1                       :  VitalDelayType01 := DefPropDelay01);
1407
 
1408
    port(
1409
        Y                              :  out   STD_LOGIC;
1410
        IN1                            :  in    STD_LOGIC);
1411
    attribute VITAL_LEVEL0 of cycloneii_and1 : entity is TRUE;
1412
end cycloneii_and1;
1413
 
1414
-- architecture body --
1415
 
1416
architecture AltVITAL of cycloneii_and1 is
1417
    attribute VITAL_LEVEL0 of AltVITAL : architecture is TRUE;
1418
 
1419
    SIGNAL IN1_ipd    : STD_ULOGIC := 'U';
1420
 
1421
begin
1422
 
1423
    ---------------------
1424
    --  INPUT PATH DELAYs
1425
    ---------------------
1426
    WireDelay : block
1427
    begin
1428
    VitalWireDelay (IN1_ipd, IN1, tipd_IN1);
1429
    end block;
1430
    --------------------
1431
    --  BEHAVIOR SECTION
1432
    --------------------
1433
    VITALBehavior : process (IN1_ipd)
1434
 
1435
 
1436
    -- functionality results
1437
    VARIABLE Results : STD_LOGIC_VECTOR(1 to 1) := (others => 'X');
1438
    ALIAS Y_zd : STD_ULOGIC is Results(1);
1439
 
1440
    -- output glitch detection variables
1441
    VARIABLE Y_GlitchData    : VitalGlitchDataType;
1442
 
1443
    begin
1444
 
1445
        -------------------------
1446
        --  Functionality Section
1447
        -------------------------
1448
        Y_zd := TO_X01(IN1_ipd);
1449
 
1450
        ----------------------
1451
        --  Path Delay Section
1452
        ----------------------
1453
        VitalPathDelay01 (
1454
            OutSignal => Y,
1455
            OutSignalName => "Y",
1456
            OutTemp => Y_zd,
1457
            Paths => (0 => (IN1_ipd'last_event, tpd_IN1_Y, TRUE)),
1458
            GlitchData => Y_GlitchData,
1459
            Mode => DefGlitchMode,
1460
            XOn  => XOn,
1461
            MsgOn        => MsgOn );
1462
 
1463
    end process;
1464
end AltVITAL;
1465
----------------------------------------------------------------------------
1466
-- Module Name     : cycloneii_ram_register
1467
-- Description     : Register module for RAM inputs/outputs
1468
----------------------------------------------------------------------------
1469
 
1470
LIBRARY IEEE;
1471
USE IEEE.STD_LOGIC_1164.ALL;
1472
USE IEEE.VITAL_Timing.all;
1473
USE IEEE.VITAL_Primitives.all;
1474
USE work.cycloneii_atom_pack.all;
1475
 
1476
ENTITY cycloneii_ram_register IS
1477
 
1478
GENERIC (
1479
    width   : INTEGER := 1;
1480
    preset  : STD_LOGIC := '0';
1481
    tipd_d  : VitalDelayArrayType01(143 DOWNTO 0) := (OTHERS => DefPropDelay01);
1482
    tipd_clk        : VitalDelayType01 := DefPropDelay01;
1483
    tipd_ena        : VitalDelayType01 := DefPropDelay01;
1484
    tipd_stall      : VitalDelayType01 := DefPropDelay01;
1485
    tipd_aclr       : VitalDelayType01 := DefPropDelay01;
1486
    tpw_ena_posedge : VitalDelayType   := DefPulseWdthCnst;
1487
    tpd_clk_q_posedge        : VitalDelayType01 := DefPropDelay01;
1488
    tpd_aclr_q_posedge       : VitalDelayType01 := DefPropDelay01;
1489
    tsetup_d_clk_noedge_posedge    : VitalDelayType := DefSetupHoldCnst;
1490
    thold_d_clk_noedge_posedge     : VitalDelayType := DefSetupHoldCnst;
1491
    tsetup_ena_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
1492
    thold_ena_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
1493
    tsetup_stall_clk_noedge_posedge  : VitalDelayType   := DefSetupHoldCnst;
1494
    thold_stall_clk_noedge_posedge   : VitalDelayType   := DefSetupHoldCnst;
1495
    tsetup_aclr_clk_noedge_posedge : VitalDelayType   := DefSetupHoldCnst;
1496
    thold_aclr_clk_noedge_posedge  : VitalDelayType   := DefSetupHoldCnst
1497
    );
1498
 
1499
PORT (
1500
    d       : IN STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1501
    clk     : IN STD_LOGIC;
1502
    ena     : IN STD_LOGIC;
1503
    stall : IN STD_LOGIC;
1504
    aclr    : IN STD_LOGIC;
1505
    devclrn : IN STD_LOGIC;
1506
    devpor  : IN STD_LOGIC;
1507
    q       : OUT STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1508
    aclrout : OUT STD_LOGIC
1509
    );
1510
 
1511
END cycloneii_ram_register;
1512
 
1513
ARCHITECTURE reg_arch OF cycloneii_ram_register IS
1514
 
1515
SIGNAL d_ipd : STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1516
SIGNAL clk_ipd  : STD_LOGIC;
1517
SIGNAL ena_ipd  : STD_LOGIC;
1518
SIGNAL aclr_ipd : STD_LOGIC;
1519
SIGNAL stall_ipd : STD_LOGIC;
1520
 
1521
BEGIN
1522
 
1523
WireDelay : BLOCK
1524
BEGIN
1525
    loopbits : FOR i in d'RANGE GENERATE
1526
        VitalWireDelay (d_ipd(i), d(i), tipd_d(i));
1527
    END GENERATE;
1528
    VitalWireDelay (clk_ipd, clk, tipd_clk);
1529
    VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
1530
    VitalWireDelay (ena_ipd, ena, tipd_ena);
1531
    VitalWireDelay (stall_ipd, stall, tipd_stall);
1532
END BLOCK;
1533
 
1534
   PROCESS (d_ipd,ena_ipd,stall_ipd,clk_ipd,aclr_ipd,devclrn,devpor)
1535
VARIABLE Tviol_clk_ena        : STD_ULOGIC := '0';
1536
VARIABLE Tviol_clk_aclr       : STD_ULOGIC := '0';
1537
VARIABLE Tviol_data_clk       : STD_ULOGIC := '0';
1538
VARIABLE TimingData_clk_ena   : VitalTimingDataType := VitalTimingDataInit;
1539
VARIABLE TimingData_clk_stall   : VitalTimingDataType := VitalTimingDataInit;
1540
VARIABLE TimingData_clk_aclr  : VitalTimingDataType := VitalTimingDataInit;
1541
VARIABLE TimingData_data_clk  : VitalTimingDataType := VitalTimingDataInit;
1542
VARIABLE Tviol_ena            : STD_ULOGIC := '0';
1543
VARIABLE PeriodData_ena       : VitalPeriodDataType := VitalPeriodDataInit;
1544
VARIABLE q_VitalGlitchDataArray : VitalGlitchDataArrayType(143 downto 0);
1545
VARIABLE CQDelay  : TIME := 0 ns;
1546
VARIABLE q_reg    : STD_LOGIC_VECTOR(width - 1 DOWNTO 0) := (OTHERS => preset);
1547
BEGIN
1548
 
1549
    IF (aclr_ipd = '1' OR devclrn = '0' OR devpor = '0') THEN
1550
        q_reg := (OTHERS => preset);
1551
       ELSIF (clk_ipd = '1' AND clk_ipd'EVENT AND ena_ipd = '1' AND stall_ipd = '0') THEN
1552
        q_reg := d_ipd;
1553
    END IF;
1554
 
1555
    -- Timing checks
1556
    VitalSetupHoldCheck (
1557
        Violation       => Tviol_clk_ena,
1558
        TimingData      => TimingData_clk_ena,
1559
        TestSignal      => ena_ipd,
1560
        TestSignalName  => "ena",
1561
        RefSignal       => clk_ipd,
1562
        RefSignalName   => "clk",
1563
        SetupHigh       => tsetup_ena_clk_noedge_posedge,
1564
        SetupLow        => tsetup_ena_clk_noedge_posedge,
1565
        HoldHigh        => thold_ena_clk_noedge_posedge,
1566
        HoldLow         => thold_ena_clk_noedge_posedge,
1567
        CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1568
        RefTransition   => '/',
1569
        HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1570
        XOn           => DefXOnChecks,
1571
        MsgOn         => DefMsgOnChecks );
1572
 
1573
  VitalSetupHoldCheck (
1574
      Violation       => Tviol_clk_ena,
1575
      TimingData      => TimingData_clk_stall,
1576
      TestSignal      => stall_ipd,
1577
      TestSignalName  => "stall",
1578
      RefSignal       => clk_ipd,
1579
      RefSignalName   => "clk",
1580
      SetupHigh       => tsetup_stall_clk_noedge_posedge,
1581
      SetupLow        => tsetup_stall_clk_noedge_posedge,
1582
      HoldHigh        => thold_stall_clk_noedge_posedge,
1583
      HoldLow         => thold_stall_clk_noedge_posedge,
1584
      CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1585
      RefTransition   => '/',
1586
      HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1587
      XOn           => DefXOnChecks,
1588
      MsgOn         => DefMsgOnChecks );
1589
 
1590
    VitalSetupHoldCheck (
1591
        Violation       => Tviol_clk_aclr,
1592
        TimingData      => TimingData_clk_aclr,
1593
        TestSignal      => aclr_ipd,
1594
        TestSignalName  => "aclr",
1595
        RefSignal       => clk_ipd,
1596
        RefSignalName   => "clk",
1597
        SetupHigh       => tsetup_aclr_clk_noedge_posedge,
1598
        SetupLow        => tsetup_aclr_clk_noedge_posedge,
1599
        HoldHigh        => thold_aclr_clk_noedge_posedge,
1600
        HoldLow         => thold_aclr_clk_noedge_posedge,
1601
        CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1602
        RefTransition   => '/',
1603
        HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1604
        XOn           => DefXOnChecks,
1605
        MsgOn         => DefMsgOnChecks );
1606
 
1607
    VitalSetupHoldCheck (
1608
        Violation       => Tviol_data_clk,
1609
        TimingData      => TimingData_data_clk,
1610
        TestSignal      => d_ipd,
1611
        TestSignalName  => "data",
1612
        RefSignal       => clk_ipd,
1613
        RefSignalName   => "clk",
1614
        SetupHigh       => tsetup_d_clk_noedge_posedge,
1615
        SetupLow        => tsetup_d_clk_noedge_posedge,
1616
        HoldHigh        => thold_d_clk_noedge_posedge,
1617
        HoldLow         => thold_d_clk_noedge_posedge,
1618
        CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1619
        RefTransition   => '/',
1620
        HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1621
        XOn           => DefXOnChecks,
1622
        MsgOn         => DefMsgOnChecks );
1623
 
1624
    VitalPeriodPulseCheck (
1625
        Violation       => Tviol_ena,
1626
        PeriodData      => PeriodData_ena,
1627
        TestSignal      => ena_ipd,
1628
        TestSignalName  => "ena",
1629
        PulseWidthHigh  => tpw_ena_posedge,
1630
        HeaderMsg       => "/RAM Register VitalPeriodPulseCheck",
1631
        XOn           => DefXOnChecks,
1632
        MsgOn         => DefMsgOnChecks );
1633
 
1634
    -- Path Delay Selection
1635
    CQDelay := SelectDelay (
1636
                   Paths => (
1637
                       (0 => (clk_ipd'LAST_EVENT,tpd_clk_q_posedge,TRUE),
1638
                        1 => (aclr_ipd'LAST_EVENT,tpd_aclr_q_posedge,TRUE))
1639
                   )
1640
               );
1641
    q <= TRANSPORT q_reg AFTER CQDelay;
1642
 
1643
END PROCESS;
1644
 
1645
aclrout <= aclr_ipd;
1646
 
1647
END reg_arch;
1648
 
1649
----------------------------------------------------------------------------
1650
-- Module Name     : cycloneii_ram_pulse_generator
1651
-- Description     : Generate pulse to initiate memory read/write operations
1652
----------------------------------------------------------------------------
1653
 
1654
LIBRARY IEEE;
1655
USE IEEE.STD_LOGIC_1164.ALL;
1656
USE IEEE.VITAL_Timing.all;
1657
USE IEEE.VITAL_Primitives.all;
1658
USE work.cycloneii_atom_pack.all;
1659
 
1660
ENTITY cycloneii_ram_pulse_generator IS
1661
GENERIC (
1662
    tipd_clk : VitalDelayType01 := (0.5 ns,0.5 ns);
1663
    tipd_ena : VitalDelayType01 := DefPropDelay01;
1664
    tpd_clk_pulse_posedge : VitalDelayType01 := DefPropDelay01
1665
    );
1666
PORT (
1667
    clk,ena : IN STD_LOGIC;
1668
    pulse,cycle : OUT STD_LOGIC
1669
    );
1670
ATTRIBUTE VITAL_Level0 OF cycloneii_ram_pulse_generator:ENTITY IS TRUE;
1671
END cycloneii_ram_pulse_generator;
1672
 
1673
ARCHITECTURE pgen_arch OF cycloneii_ram_pulse_generator IS
1674
SIGNAL clk_ipd,ena_ipd : STD_LOGIC;
1675
SIGNAL state : STD_LOGIC;
1676
ATTRIBUTE VITAL_Level0 OF pgen_arch:ARCHITECTURE IS TRUE;
1677
BEGIN
1678
 
1679
WireDelay : BLOCK
1680
BEGIN
1681
    VitalWireDelay (clk_ipd, clk, tipd_clk);
1682
    VitalWireDelay (ena_ipd, ena, tipd_ena);
1683
END BLOCK;
1684
 
1685
PROCESS (clk_ipd,state)
1686
BEGIN
1687
    IF (state = '1' AND state'EVENT) THEN
1688
        state <= '0';
1689
    ELSIF (clk_ipd = '1' AND clk_ipd'EVENT AND ena_ipd = '1') THEN
1690
        state <= '1';
1691
    END IF;
1692
END PROCESS;
1693
 
1694
PathDelay : PROCESS
1695
VARIABLE pulse_VitalGlitchData : VitalGlitchDataType;
1696
BEGIN
1697
    WAIT UNTIL state'EVENT;
1698
    VitalPathDelay01 (
1699
        OutSignal     => pulse,
1700
        OutSignalName => "pulse",
1701
        OutTemp       => state,
1702
        Paths         => (0 => (clk_ipd'LAST_EVENT,tpd_clk_pulse_posedge,TRUE)),
1703
        GlitchData    => pulse_VitalGlitchData,
1704
        Mode          => DefGlitchMode,
1705
        XOn           => DefXOnChecks,
1706
        MsgOn         => DefMsgOnChecks
1707
    );
1708
END PROCESS;
1709
 
1710
cycle <= clk_ipd;
1711
 
1712
END pgen_arch;
1713
 
1714
LIBRARY IEEE;
1715
USE IEEE.STD_LOGIC_1164.ALL;
1716
USE IEEE.VITAL_Timing.all;
1717
USE IEEE.VITAL_Primitives.all;
1718
USE work.cycloneii_atom_pack.all;
1719
USE work.cycloneii_ram_register;
1720
USE work.cycloneii_ram_pulse_generator;
1721
 
1722
ENTITY cycloneii_ram_block IS
1723
    GENERIC (
1724
        -- -------- GLOBAL PARAMETERS ---------
1725
        operation_mode                 :  STRING := "single_port";
1726
        mixed_port_feed_through_mode   :  STRING := "dont_care";
1727
        ram_block_type                 :  STRING := "auto";
1728
        logical_ram_name               :  STRING := "ram_name";
1729
        init_file                      :  STRING := "init_file.hex";
1730
        init_file_layout               :  STRING := "none";
1731
        data_interleave_width_in_bits  :  INTEGER := 1;
1732
        data_interleave_offset_in_bits :  INTEGER := 1;
1733
        port_a_logical_ram_depth       :  INTEGER := 0;
1734
        port_a_logical_ram_width       :  INTEGER := 0;
1735
        port_a_first_address           :  INTEGER := 0;
1736
        port_a_last_address            :  INTEGER := 0;
1737
        port_a_first_bit_number        :  INTEGER := 0;
1738
        port_a_data_in_clear           :  STRING := "none";
1739
        port_a_address_clear           :  STRING := "none";
1740
        port_a_write_enable_clear      :  STRING := "none";
1741
        port_a_data_out_clear          :  STRING := "none";
1742
        port_a_byte_enable_clear       :  STRING := "none";
1743
        port_a_data_in_clock           :  STRING := "clock0";
1744
        port_a_address_clock           :  STRING := "clock0";
1745
        port_a_write_enable_clock      :  STRING := "clock0";
1746
        port_a_byte_enable_clock       :  STRING := "clock0";
1747
        port_a_data_out_clock          :  STRING := "none";
1748
        port_a_data_width              :  INTEGER := 1;
1749
        port_a_address_width           :  INTEGER := 1;
1750
        port_a_byte_enable_mask_width  :  INTEGER := 1;
1751
        port_b_logical_ram_depth       :  INTEGER := 0;
1752
        port_b_logical_ram_width       :  INTEGER := 0;
1753
        port_b_first_address           :  INTEGER := 0;
1754
        port_b_last_address            :  INTEGER := 0;
1755
        port_b_first_bit_number        :  INTEGER := 0;
1756
        port_b_data_in_clear           :  STRING := "none";
1757
        port_b_address_clear           :  STRING := "none";
1758
        port_b_read_enable_write_enable_clear: STRING := "none";
1759
        port_b_byte_enable_clear       :  STRING := "none";
1760
        port_b_data_out_clear          :  STRING := "none";
1761
        port_b_data_in_clock           :  STRING := "clock1";
1762
        port_b_address_clock           :  STRING := "clock1";
1763
        port_b_read_enable_write_enable_clock: STRING := "clock1";
1764
        port_b_byte_enable_clock       :  STRING := "clock1";
1765
        port_b_data_out_clock          :  STRING := "none";
1766
        port_b_data_width              :  INTEGER := 1;
1767
        port_b_address_width           :  INTEGER := 1;
1768
        port_b_byte_enable_mask_width  :  INTEGER := 1;
1769
 
1770
        power_up_uninitialized         :  STRING := "false";
1771
        port_b_disable_ce_on_output_registers : STRING := "off";
1772
        port_b_disable_ce_on_input_registers : STRING := "off";
1773
        port_b_byte_size : INTEGER := 0;
1774
        port_a_disable_ce_on_output_registers : STRING := "off";
1775
        port_a_disable_ce_on_input_registers : STRING := "off";
1776
        port_a_byte_size : INTEGER := 0;
1777
        safe_write : STRING := "err_on_2clk";
1778
        init_file_restructured : STRING := "unused";
1779
        lpm_type                  : string := "cycloneii_ram_block";
1780
        lpm_hint                  : string := "true";
1781
        mem_init0 : BIT_VECTOR  := X"0";
1782
        mem_init1 : BIT_VECTOR  := X"0";
1783
        connectivity_checking     : string := "off"
1784
        );
1785
    -- -------- PORT DECLARATIONS ---------
1786
    PORT (
1787
        portadatain             : IN STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0)    := (OTHERS => '0');
1788
        portaaddr               : IN STD_LOGIC_VECTOR(port_a_address_width - 1 DOWNTO 0) := (OTHERS => '0');
1789
        portawe                 : IN STD_LOGIC := '0';
1790
        portbdatain             : IN STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0)    := (OTHERS => '0');
1791
        portbaddr               : IN STD_LOGIC_VECTOR(port_b_address_width - 1 DOWNTO 0) := (OTHERS => '0');
1792
        portbrewe               : IN STD_LOGIC := '0';
1793
        clk0                    : IN STD_LOGIC := '0';
1794
        clk1                    : IN STD_LOGIC := '0';
1795
        ena0                    : IN STD_LOGIC := '1';
1796
        ena1                    : IN STD_LOGIC := '1';
1797
        clr0                    : IN STD_LOGIC := '0';
1798
        clr1                    : IN STD_LOGIC := '0';
1799
        portabyteenamasks       : IN STD_LOGIC_VECTOR(port_a_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '1');
1800
        portbbyteenamasks       : IN STD_LOGIC_VECTOR(port_b_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '1');
1801
        devclrn                 : IN STD_LOGIC := '1';
1802
        devpor                  : IN STD_LOGIC := '1';
1803
         portaaddrstall : IN STD_LOGIC := '0';
1804
         portbaddrstall : IN STD_LOGIC := '0';
1805
        portadataout            : OUT STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1806
        portbdataout            : OUT STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0)
1807
        );
1808
 
1809
END cycloneii_ram_block;
1810
 
1811
ARCHITECTURE block_arch OF cycloneii_ram_block IS
1812
 
1813
COMPONENT cycloneii_ram_pulse_generator
1814
    PORT (
1815
          clk                     : IN  STD_LOGIC;
1816
          ena                     : IN  STD_LOGIC;
1817
          pulse                   : OUT STD_LOGIC;
1818
          cycle                   : OUT STD_LOGIC
1819
    );
1820
END COMPONENT;
1821
 
1822
COMPONENT cycloneii_ram_register
1823
    GENERIC (
1824
        preset                    :  STD_LOGIC := '0';
1825
        width                     :  integer := 1
1826
    );
1827
    PORT    (
1828
        d                       : IN  STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1829
        clk                     : IN  STD_LOGIC;
1830
        aclr                    : IN  STD_LOGIC;
1831
        devclrn                 : IN  STD_LOGIC;
1832
        devpor                  : IN  STD_LOGIC;
1833
        ena                     : IN  STD_LOGIC;
1834
        stall                     : IN  STD_LOGIC;
1835
        q                       : OUT STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1836
        aclrout                 : OUT STD_LOGIC
1837
     );
1838
END COMPONENT;
1839
 
1840
FUNCTION cond (condition : BOOLEAN;CONSTANT a,b : INTEGER) RETURN INTEGER IS
1841
VARIABLE c: INTEGER;
1842
BEGIN
1843
    IF (condition) THEN c := a; ELSE c := b; END IF;
1844
    RETURN c;
1845
END;
1846
 
1847
SUBTYPE port_type IS BOOLEAN;
1848
 
1849
CONSTANT primary   : port_type := TRUE;
1850
CONSTANT secondary : port_type := FALSE;
1851
 
1852
CONSTANT primary_port_is_a : BOOLEAN := (port_b_data_width <= port_a_data_width);
1853
CONSTANT primary_port_is_b : BOOLEAN := NOT primary_port_is_a;
1854
 
1855
CONSTANT mode_is_rom : BOOLEAN := (operation_mode = "rom");
1856
CONSTANT mode_is_sp  : BOOLEAN := (operation_mode = "single_port");
1857
CONSTANT mode_is_dp  : BOOLEAN := (operation_mode = "dual_port");
1858
CONSTANT mode_is_bdp : BOOLEAN := (operation_mode = "bidir_dual_port");
1859
 
1860
CONSTANT wired_mode : BOOLEAN := (port_a_address_width = port_b_address_width) AND (port_a_address_width = 1)
1861
                                  AND (port_a_data_width /= port_b_data_width);
1862
CONSTANT num_cols : INTEGER := cond(mode_is_rom OR mode_is_sp,1,
1863
                                    cond(wired_mode,2,2 ** (ABS(port_b_address_width - port_a_address_width))));
1864
CONSTANT data_width      : INTEGER := cond(primary_port_is_a,port_a_data_width,port_b_data_width);
1865
CONSTANT data_unit_width : INTEGER := cond(mode_is_rom OR mode_is_sp OR primary_port_is_b,port_a_data_width,port_b_data_width);
1866
 
1867
CONSTANT address_unit_width : INTEGER := cond(mode_is_rom OR mode_is_sp OR primary_port_is_a,port_a_address_width,port_b_address_width);
1868
CONSTANT address_width      : INTEGER := cond(mode_is_rom OR mode_is_sp OR primary_port_is_b,port_a_address_width,port_b_address_width);
1869
 
1870
CONSTANT byte_size_a : INTEGER := port_a_data_width / port_a_byte_enable_mask_width;
1871
CONSTANT byte_size_b : INTEGER := port_b_data_width / port_b_byte_enable_mask_width;
1872
 
1873
CONSTANT out_a_is_reg : BOOLEAN := (port_a_data_out_clock /= "none" AND port_a_data_out_clock /= "UNUSED");
1874
CONSTANT out_b_is_reg : BOOLEAN := (port_b_data_out_clock /= "none" AND port_b_data_out_clock /= "UNUSED");
1875
 
1876
CONSTANT bytes_a_disabled : STD_LOGIC_VECTOR(port_a_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '0');
1877
CONSTANT bytes_b_disabled : STD_LOGIC_VECTOR(port_b_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '0');
1878
 
1879
CONSTANT ram_type : BOOLEAN := (ram_block_type = "M-RAM" OR ram_block_type = "m-ram" OR ram_block_type = "MegaRAM" OR
1880
                               (ram_block_type = "auto"  AND mixed_port_feed_through_mode = "dont_care" AND port_b_read_enable_write_enable_clock = "clock0"));
1881
 
1882
TYPE bool_to_std_logic_map IS ARRAY(TRUE DOWNTO FALSE) OF STD_LOGIC;
1883
CONSTANT bool_to_std_logic : bool_to_std_logic_map := ('1','0');
1884
 
1885
 
1886
 
1887
-- -------- internal signals ---------
1888
-- clock / clock enable
1889
SIGNAL clk_a_in,clk_b_in : STD_LOGIC;
1890
SIGNAL clk_a_byteena,clk_b_byteena : STD_LOGIC;
1891
SIGNAL clk_a_out,clk_b_out : STD_LOGIC;
1892
SIGNAL clkena_a_out,clkena_b_out : STD_LOGIC;
1893
SIGNAL write_cycle_a,write_cycle_b : STD_LOGIC;
1894
 
1895
 
1896
 
1897
SUBTYPE one_bit_bus_type IS STD_LOGIC_VECTOR(0 DOWNTO 0);
1898
 
1899
-- asynch clear
1900
TYPE   clear_mode_type IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF BOOLEAN;
1901
TYPE   clear_vec_type  IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF STD_LOGIC;
1902
SIGNAL datain_a_clr,datain_b_clr   :  STD_LOGIC;
1903
SIGNAL dataout_a_clr,dataout_b_clr :  STD_LOGIC;
1904
 
1905
 
1906
SIGNAL addr_a_clr,addr_b_clr       :  STD_LOGIC;
1907
SIGNAL byteena_a_clr,byteena_b_clr :  STD_LOGIC;
1908
SIGNAL we_a_clr,rewe_b_clr         :  STD_LOGIC;
1909
SIGNAL datain_a_clr_in,datain_b_clr_in :  STD_LOGIC;
1910
SIGNAL addr_a_clr_in,addr_b_clr_in     :  STD_LOGIC;
1911
SIGNAL byteena_a_clr_in,byteena_b_clr_in  :  STD_LOGIC;
1912
SIGNAL we_a_clr_in,rewe_b_clr_in          :  STD_LOGIC;
1913
SIGNAL mem_invalidate,mem_invalidate_loc,read_latch_invalidate : clear_mode_type;
1914
SIGNAL clear_asserted_during_write :  clear_vec_type;
1915
 
1916
 
1917
-- port A registers
1918
SIGNAL we_a_reg                 :  STD_LOGIC;
1919
SIGNAL we_a_reg_in,we_a_reg_out :  one_bit_bus_type;
1920
SIGNAL addr_a_reg               :  STD_LOGIC_VECTOR(port_a_address_width - 1 DOWNTO 0);
1921
SIGNAL datain_a_reg             :  STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1922
SIGNAL dataout_a_reg            :  STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1923
SIGNAL dataout_a                :  STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1924
SIGNAL byteena_a_reg            :  STD_LOGIC_VECTOR(port_a_byte_enable_mask_width- 1 DOWNTO 0);
1925
-- port B registers
1926
SIGNAL rewe_b_reg               :  STD_LOGIC;
1927
SIGNAL rewe_b_reg_in,rewe_b_reg_out :  one_bit_bus_type;
1928
SIGNAL addr_b_reg               :  STD_LOGIC_VECTOR(port_b_address_width - 1 DOWNTO 0);
1929
SIGNAL datain_b_reg             :  STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0);
1930
SIGNAL dataout_b_reg            :  STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0);
1931
SIGNAL dataout_b                :  STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0);
1932
SIGNAL byteena_b_reg            :  STD_LOGIC_VECTOR(port_b_byte_enable_mask_width- 1 DOWNTO 0);
1933
-- pulses
1934
TYPE   pulse_vec IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF STD_LOGIC;
1935
SIGNAL write_pulse,read_pulse,read_pulse_feedthru : pulse_vec;
1936
SIGNAL wpgen_a_clk,wpgen_a_clkena,wpgen_b_clk,wpgen_b_clkena : STD_LOGIC;
1937
SIGNAL rpgen_a_clkena,rpgen_b_clkena : STD_LOGIC;
1938
SIGNAL ftpgen_a_clkena,ftpgen_b_clkena : STD_LOGIC;
1939
-- registered address
1940
SIGNAL addr_prime_reg,addr_sec_reg :  INTEGER;
1941
-- input/output
1942
SIGNAL datain_prime_reg,dataout_prime     :  STD_LOGIC_VECTOR(data_width - 1 DOWNTO 0);
1943
SIGNAL datain_sec_reg,dataout_sec         :  STD_LOGIC_VECTOR(data_unit_width - 1 DOWNTO 0);
1944
--  overlapping location write
1945
SIGNAL dual_write : BOOLEAN;
1946
-- memory core
1947
SUBTYPE  mem_word_type IS STD_LOGIC_VECTOR (data_width - 1 DOWNTO 0);
1948
SUBTYPE  mem_col_type  IS STD_LOGIC_VECTOR (data_unit_width - 1 DOWNTO 0);
1949
TYPE     mem_row_type  IS ARRAY (num_cols - 1 DOWNTO 0) OF mem_col_type;
1950
TYPE     mem_type IS ARRAY ((2 ** address_unit_width) - 1 DOWNTO 0) OF mem_row_type;
1951
SIGNAL   mem : mem_type;
1952
SIGNAL   init_mem : BOOLEAN := FALSE;
1953
CONSTANT mem_x : mem_type     := (OTHERS => (OTHERS => (OTHERS => 'X')));
1954
CONSTANT row_x : mem_row_type := (OTHERS => (OTHERS => 'X'));
1955
CONSTANT col_x : mem_col_type := (OTHERS => 'X');
1956
SIGNAL   mem_data : mem_row_type;
1957
SIGNAL   old_mem_data : mem_row_type;
1958
SIGNAL   mem_unit_data : mem_col_type;
1959
 
1960
-- latches
1961
TYPE   read_latch_rec IS RECORD
1962
       prime : mem_row_type;
1963
       sec   : mem_col_type;
1964
END RECORD;
1965
SIGNAL read_latch      :  read_latch_rec;
1966
-- (row,column) coordinates
1967
SIGNAL row_sec,col_sec  : INTEGER;
1968
-- byte enable
1969
TYPE   mask_type IS (normal,inverse);
1970
TYPE   mask_prime_type IS ARRAY(mask_type'HIGH DOWNTO mask_type'LOW) OF mem_word_type;
1971
TYPE   mask_sec_type   IS ARRAY(mask_type'HIGH DOWNTO mask_type'LOW) OF mem_col_type;
1972
TYPE   mask_rec IS RECORD
1973
       prime : mask_prime_type;
1974
       sec   : mask_sec_type;
1975
END RECORD;
1976
SIGNAL mask_vector : mask_rec;
1977
SIGNAL mask_vector_common : mem_col_type;
1978
 
1979
FUNCTION get_mask(
1980
    b_ena : IN STD_LOGIC_VECTOR;
1981
    mode  : port_type;
1982
    CONSTANT b_ena_width ,byte_size: INTEGER
1983
) RETURN mask_rec IS
1984
 
1985
VARIABLE l : INTEGER;
1986
VARIABLE mask : mask_rec := (
1987
                                (normal => (OTHERS => '0'),inverse => (OTHERS => 'X')),
1988
                                (normal => (OTHERS => '0'),inverse => (OTHERS => 'X'))
1989
                            );
1990
BEGIN
1991
    FOR l in 0 TO b_ena_width - 1  LOOP
1992
        IF (b_ena(l) = '0') THEN
1993
            IF (mode = primary) THEN
1994
                mask.prime(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
1995
                mask.prime(inverse)((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => '0');
1996
            ELSE
1997
                mask.sec(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
1998
                mask.sec(inverse)((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => '0');
1999
            END IF;
2000
        ELSIF (b_ena(l) = 'X' OR b_ena(l) = 'U') THEN
2001
            IF (mode = primary) THEN
2002
                mask.prime(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
2003
            ELSE
2004
                mask.sec(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
2005
            END IF;
2006
        END IF;
2007
    END LOOP;
2008
    RETURN mask;
2009
END get_mask;
2010
-- port active for read/write
2011
SIGNAL active_a_in_vec,active_b_in_vec,active_a_out,active_b_out : one_bit_bus_type;
2012
SIGNAL active_a_in,active_b_in   : STD_LOGIC;
2013
SIGNAL active_a,active_b : BOOLEAN;
2014
SIGNAL active_write_a :  BOOLEAN;
2015
SIGNAL active_write_b :  BOOLEAN;
2016
SIGNAL wire_vcc : STD_LOGIC := '1';
2017
SIGNAL wire_gnd : STD_LOGIC := '0';
2018
 
2019
 
2020
 
2021
 
2022
 
2023
 
2024
BEGIN
2025
    -- memory initialization
2026
    init_mem <= TRUE;
2027
 
2028
    -- -------- core logic ---------------
2029
    clk_a_in      <= clk0;
2030
 
2031
    clk_a_byteena <= '0'   WHEN (port_a_byte_enable_clock = "none" OR port_a_byte_enable_clock = "UNUSED") ELSE clk_a_in;
2032
    clk_a_out     <= '0'   WHEN (port_a_data_out_clock = "none" OR port_a_data_out_clock = "UNUSED")    ELSE
2033
                      clk0 WHEN (port_a_data_out_clock = "clock0")  ELSE clk1;
2034
 
2035
    clk_b_in      <=  clk0 WHEN (port_b_read_enable_write_enable_clock = "clock0") ELSE clk1;
2036
    clk_b_byteena <=  '0'  WHEN (port_b_byte_enable_clock = "none" OR port_b_byte_enable_clock = "UNUSED") ELSE
2037
                      clk0 WHEN (port_b_byte_enable_clock = "clock0") ELSE clk1;
2038
    clk_b_out     <=  '0'  WHEN (port_b_data_out_clock = "none" OR port_b_data_out_clock = "UNUSED")    ELSE
2039
                      clk0 WHEN (port_b_data_out_clock = "clock0")  ELSE clk1;
2040
 
2041
    addr_a_clr_in <=  '0'  WHEN (port_a_address_clear = "none" OR port_a_address_clear = "UNUSED") ELSE clr0;
2042
    addr_b_clr_in <=  '0'  WHEN (port_b_address_clear = "none" OR port_b_address_clear = "UNUSED") ELSE
2043
                      clr0 WHEN (port_b_address_clear = "clear0") ELSE clr1;
2044
 
2045
    datain_a_clr_in <= '0' WHEN (port_a_data_in_clear = "none" OR port_a_data_in_clear = "UNUSED") ELSE clr0;
2046
    datain_b_clr_in <= '0' WHEN (port_b_data_in_clear = "none" OR port_b_data_in_clear = "UNUSED") ELSE
2047
                       clr0 WHEN (port_b_data_in_clear = "clear0") ELSE clr1;
2048
 
2049
    dataout_a_clr   <= '0' WHEN (port_a_data_out_clear = "none" OR port_a_data_out_clear = "UNUSED")   ELSE
2050
                     clr0 WHEN (port_a_data_out_clear = "clear0") ELSE clr1;
2051
 
2052
    dataout_b_clr   <= '0' WHEN (port_b_data_out_clear = "none" OR port_b_data_out_clear = "UNUSED")   ELSE
2053
                     clr0 WHEN (port_b_data_out_clear = "clear0") ELSE clr1;
2054
 
2055
    byteena_a_clr_in <= '0' WHEN (port_a_byte_enable_clear = "none" OR port_a_byte_enable_clear = "UNUSED") ELSE clr0;
2056
    byteena_b_clr_in <= '0' WHEN (port_b_byte_enable_clear = "none" OR port_b_byte_enable_clear = "UNUSED") ELSE
2057
                        clr0 WHEN (port_b_byte_enable_clear = "clear0") ELSE clr1;
2058
    we_a_clr_in      <= '0' WHEN (port_a_write_enable_clear = "none" OR port_a_write_enable_clear = "UNUSED") ELSE clr0;
2059
    rewe_b_clr_in    <= '0' WHEN (port_b_read_enable_write_enable_clear = "none" OR port_b_read_enable_write_enable_clear = "UNUSED")   ELSE
2060
                        clr0 WHEN (port_b_read_enable_write_enable_clear = "clear0") ELSE clr1;
2061
 
2062
        active_a_in <= '1'  WHEN (port_a_disable_ce_on_input_registers = "on") ELSE ena0;
2063
 
2064
 
2065
        active_b_in <= '1'  WHEN (port_b_disable_ce_on_input_registers = "on") ELSE
2066
                       ena0 WHEN (port_b_read_enable_write_enable_clock = "clock0") ELSE ena1;
2067
 
2068
    -- Store clock enable value for SEAB/MEAB
2069
    -- A port active 
2070
    active_a_in_vec(0) <= active_a_in;
2071
    active_port_a : cycloneii_ram_register
2072
        GENERIC MAP ( width => 1 )
2073
        PORT MAP (
2074
            d => active_a_in_vec,
2075
            clk => clk_a_in,
2076
            aclr => wire_gnd,
2077
            devclrn => wire_vcc,devpor => wire_vcc,
2078
            ena => wire_vcc,
2079
            stall => wire_gnd,
2080
            q => active_a_out
2081
        );
2082
    active_a <= (active_a_out(0) = '1');
2083
    active_write_a <= active_a AND (byteena_a_reg /= bytes_a_disabled);
2084
 
2085
    -- B port active
2086
    active_b_in_vec(0) <= active_b_in;
2087
    active_port_b : cycloneii_ram_register
2088
        GENERIC MAP ( width => 1 )
2089
        PORT MAP (
2090
            d => active_b_in_vec,
2091
            clk => clk_b_in,
2092
            aclr => wire_gnd,
2093
            devclrn => wire_vcc,devpor => wire_vcc,
2094
            stall => wire_gnd,
2095
            ena => wire_vcc,
2096
            q => active_b_out
2097
        );
2098
    active_b <= (active_b_out(0) = '1');
2099
    active_write_b <= active_b AND (byteena_b_reg /= bytes_b_disabled);
2100
 
2101
 
2102
 
2103
 
2104
 
2105
    -- ------ A input registers
2106
    -- write enable
2107
    we_a_reg_in(0) <= '0' WHEN mode_is_rom ELSE portawe;
2108
    we_a_register : cycloneii_ram_register
2109
        GENERIC MAP ( width => 1 )
2110
        PORT MAP (
2111
            d => we_a_reg_in,
2112
            clk => clk_a_in,
2113
            aclr => we_a_clr_in,
2114
            devclrn => devclrn,
2115
            devpor => devpor,
2116
            stall => wire_gnd,
2117
             ena => active_a_in,
2118
            q   => we_a_reg_out,
2119
            aclrout => we_a_clr
2120
        );
2121
    we_a_reg <= we_a_reg_out(0);
2122
 
2123
    -- address
2124
    addr_a_register : cycloneii_ram_register
2125
        GENERIC MAP ( width => port_a_address_width )
2126
        PORT MAP (
2127
            d => portaaddr,
2128
            clk => clk_a_in,
2129
            aclr => addr_a_clr_in,
2130
            devclrn => devclrn,
2131
            devpor => devpor,
2132
            stall => portaaddrstall,
2133
            ena => active_a_in,
2134
            q   => addr_a_reg,
2135
            aclrout => addr_a_clr
2136
        );
2137
    -- data
2138
    datain_a_register : cycloneii_ram_register
2139
        GENERIC MAP ( width => port_a_data_width )
2140
        PORT MAP (
2141
            d => portadatain,
2142
            clk => clk_a_in,
2143
            aclr => datain_a_clr_in,
2144
            devclrn => devclrn,
2145
            devpor => devpor,
2146
            stall => wire_gnd,
2147
            ena => active_a_in,
2148
            q   => datain_a_reg,
2149
            aclrout => datain_a_clr
2150
        );
2151
    -- byte enable
2152
    byteena_a_register : cycloneii_ram_register
2153
        GENERIC MAP (
2154
            width  => port_a_byte_enable_mask_width,
2155
            preset => '1'
2156
        )
2157
        PORT MAP (
2158
            d => portabyteenamasks,
2159
            clk => clk_a_byteena,
2160
            aclr => byteena_a_clr_in,
2161
            devclrn => devclrn,
2162
            devpor => devpor,
2163
            stall => wire_gnd,
2164
            ena => active_a_in,
2165
            q   => byteena_a_reg,
2166
            aclrout => byteena_a_clr
2167
        );
2168
    -- ------ B input registers 
2169
    -- read/write enable
2170
    rewe_b_reg_in(0) <= portbrewe;
2171
    rewe_b_register : cycloneii_ram_register
2172
        GENERIC MAP (
2173
            width  => 1,
2174
            preset => bool_to_std_logic(mode_is_dp)
2175
        )
2176
        PORT MAP (
2177
            d => rewe_b_reg_in,
2178
            clk => clk_b_in,
2179
            aclr => rewe_b_clr_in,
2180
            devclrn => devclrn,
2181
            devpor => devpor,
2182
            stall => wire_gnd,
2183
            ena => active_b_in,
2184
            q   => rewe_b_reg_out,
2185
            aclrout => rewe_b_clr
2186
        );
2187
    rewe_b_reg <= rewe_b_reg_out(0);
2188
 
2189
 
2190
 
2191
    -- address
2192
    addr_b_register : cycloneii_ram_register
2193
        GENERIC MAP ( width  => port_b_address_width )
2194
        PORT MAP (
2195
            d => portbaddr,
2196
            clk => clk_b_in,
2197
            aclr => addr_b_clr_in,
2198
            devclrn => devclrn,
2199
            devpor => devpor,
2200
            stall => portbaddrstall,
2201
            ena => active_b_in,
2202
            q   => addr_b_reg,
2203
            aclrout => addr_b_clr
2204
        );
2205
    -- data
2206
    datain_b_register : cycloneii_ram_register
2207
        GENERIC MAP ( width  => port_b_data_width )
2208
        PORT MAP (
2209
            d => portbdatain,
2210
            clk => clk_b_in,
2211
            aclr => datain_b_clr_in,
2212
            devclrn => devclrn,
2213
            devpor => devpor,
2214
            stall => wire_gnd,
2215
            ena => active_b_in,
2216
            q   => datain_b_reg,
2217
            aclrout => datain_b_clr
2218
        );
2219
    -- byte enable
2220
    byteena_b_register : cycloneii_ram_register
2221
        GENERIC MAP (
2222
            width  => port_b_byte_enable_mask_width,
2223
            preset => '1'
2224
        )
2225
        PORT MAP (
2226
            d => portbbyteenamasks,
2227
            clk => clk_b_byteena,
2228
            aclr => byteena_b_clr_in,
2229
            devclrn => devclrn,
2230
            devpor => devpor,
2231
            stall => wire_gnd,
2232
            ena => active_b_in,
2233
            q   => byteena_b_reg,
2234
            aclrout => byteena_b_clr
2235
        );
2236
 
2237
    datain_prime_reg <= datain_a_reg WHEN primary_port_is_a ELSE datain_b_reg;
2238
    addr_prime_reg   <= alt_conv_integer(addr_a_reg)   WHEN primary_port_is_a ELSE alt_conv_integer(addr_b_reg);
2239
 
2240
    datain_sec_reg   <= (OTHERS => 'U') WHEN (mode_is_rom OR mode_is_sp) ELSE
2241
                        datain_b_reg    WHEN primary_port_is_a           ELSE datain_a_reg;
2242
    addr_sec_reg     <= alt_conv_integer(addr_b_reg)   WHEN primary_port_is_a ELSE alt_conv_integer(addr_a_reg);
2243
 
2244
    -- Write pulse generation
2245
    wpgen_a_clk <= clk_a_in WHEN ram_type ELSE (NOT clk_a_in);
2246
      wpgen_a_clkena <= '1' WHEN (active_write_a AND (we_a_reg = '1')) ELSE '0';
2247
 
2248
    wpgen_a : cycloneii_ram_pulse_generator
2249
        PORT MAP (
2250
            clk => wpgen_a_clk,
2251
            ena => wpgen_a_clkena,
2252
            pulse => write_pulse(primary_port_is_a),
2253
            cycle => write_cycle_a
2254
        );
2255
 
2256
    wpgen_b_clk <= clk_b_in WHEN ram_type ELSE (NOT clk_b_in);
2257
      wpgen_b_clkena <= '1' WHEN (active_write_b AND mode_is_bdp AND (rewe_b_reg = '1')) ELSE '0';
2258
 
2259
 
2260
    wpgen_b : cycloneii_ram_pulse_generator
2261
        PORT MAP (
2262
            clk => wpgen_b_clk,
2263
            ena => wpgen_b_clkena,
2264
            pulse => write_pulse(primary_port_is_b),
2265
            cycle => write_cycle_b
2266
            );
2267
 
2268
    -- Read  pulse generation
2269
    rpgen_a_clkena <= '1' WHEN (active_a AND (we_a_reg = '0')) ELSE '0';
2270
 
2271
    rpgen_a : cycloneii_ram_pulse_generator
2272
        PORT MAP (
2273
            clk => clk_a_in,
2274
            ena => rpgen_a_clkena,
2275
            pulse => read_pulse(primary_port_is_a)
2276
        );
2277
    rpgen_b_clkena <= '1' WHEN (active_b AND mode_is_dp  AND (rewe_b_reg = '1')) OR
2278
                               (active_b AND mode_is_bdp AND (rewe_b_reg = '0'))
2279
                         ELSE '0';
2280
    rpgen_b : cycloneii_ram_pulse_generator
2281
        PORT MAP (
2282
            clk => clk_b_in,
2283
            ena => rpgen_b_clkena,
2284
            pulse => read_pulse(primary_port_is_b)
2285
        );
2286
 
2287
 
2288
 
2289
    -- Create internal masks for byte enable processing
2290
    mask_create : PROCESS (byteena_a_reg,byteena_b_reg)
2291
    VARIABLE mask : mask_rec;
2292
    BEGIN
2293
        IF (byteena_a_reg'EVENT) THEN
2294
            mask := get_mask(byteena_a_reg,primary_port_is_a,port_a_byte_enable_mask_width,byte_size_a);
2295
            IF (primary_port_is_a) THEN
2296
                mask_vector.prime <= mask.prime;
2297
            ELSE
2298
                mask_vector.sec   <= mask.sec;
2299
            END IF;
2300
        END IF;
2301
        IF (byteena_b_reg'EVENT) THEN
2302
            mask := get_mask(byteena_b_reg,primary_port_is_b,port_b_byte_enable_mask_width,byte_size_b);
2303
            IF (primary_port_is_b) THEN
2304
                mask_vector.prime <= mask.prime;
2305
            ELSE
2306
                mask_vector.sec   <= mask.sec;
2307
            END IF;
2308
        END IF;
2309
    END PROCESS mask_create;
2310
 
2311
    -- (row,col) coordinates
2312
    row_sec <= addr_sec_reg / num_cols;
2313
    col_sec <= addr_sec_reg mod num_cols;
2314
 
2315
 
2316
 
2317
 
2318
    mem_rw : PROCESS (init_mem,
2319
                      write_pulse,read_pulse,read_pulse_feedthru,
2320
                      mem_invalidate,mem_invalidate_loc,read_latch_invalidate)
2321
    -- mem init
2322
    TYPE rw_type IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF BOOLEAN;
2323
    VARIABLE addr_range_init,row,col,index :  INTEGER;
2324
    VARIABLE mem_init_std :  STD_LOGIC_VECTOR((port_a_last_address - port_a_first_address + 1)*port_a_data_width - 1 DOWNTO 0);
2325
   VARIABLE mem_init  :  bit_vector(mem_init1'length + mem_init0'length - 1 DOWNTO 0);
2326
 
2327
    VARIABLE mem_val : mem_type;
2328
    -- read/write
2329
    VARIABLE mem_data_p : mem_row_type;
2330
    VARIABLE old_mem_data_p : mem_row_type;
2331
    VARIABLE row_prime,col_prime  : INTEGER;
2332
    VARIABLE access_same_location : BOOLEAN;
2333
    VARIABLE read_during_write    : rw_type;
2334
    BEGIN
2335
 
2336
        read_during_write := (FALSE,FALSE);
2337
        -- Memory initialization
2338
        IF (init_mem'EVENT) THEN
2339
            -- Initialize output latches to 0
2340
            IF (primary_port_is_a) THEN
2341
                dataout_prime <= (OTHERS => '0');
2342
                IF (mode_is_dp OR mode_is_bdp) THEN dataout_sec <= (OTHERS => '0'); END IF;
2343
            ELSE
2344
                dataout_sec   <= (OTHERS => '0');
2345
                IF (mode_is_dp OR mode_is_bdp) THEN dataout_prime <= (OTHERS => '0'); END IF;
2346
            END IF;
2347
            mem_val := (OTHERS => (OTHERS => (OTHERS => '0')));
2348
            IF (primary_port_is_a) THEN
2349
                addr_range_init := port_a_last_address - port_a_first_address + 1;
2350
            ELSE
2351
                addr_range_init := port_b_last_address - port_b_first_address + 1;
2352
            END IF;
2353
            IF (init_file_layout = "port_a" OR init_file_layout = "port_b") THEN
2354
                mem_init := mem_init1 & mem_init0;
2355
                mem_init_std := to_stdlogicvector(mem_init) ((port_a_last_address - port_a_first_address + 1)*port_a_data_width - 1 DOWNTO 0);
2356
                FOR row IN 0 TO addr_range_init - 1 LOOP
2357
                    FOR col IN 0 to num_cols - 1 LOOP
2358
                        index := row * data_width;
2359
                        mem_val(row)(col) := mem_init_std(index + (col+1)*data_unit_width -1 DOWNTO
2360
                                                          index +  col*data_unit_width);
2361
                    END LOOP;
2362
                END LOOP;
2363
            END IF;
2364
            mem <= mem_val;
2365
        END IF;
2366
        access_same_location := (mode_is_dp OR mode_is_bdp) AND (addr_prime_reg = row_sec);
2367
 
2368
        -- Write stage 1 : X to buffer
2369
        -- Write stage 2 : actual data to memory
2370
        IF (write_pulse(primary)'EVENT) THEN
2371
            IF (write_pulse(primary) = '1') THEN
2372
                old_mem_data_p := mem(addr_prime_reg);
2373
                mem_data_p := mem(addr_prime_reg);
2374
                FOR i IN 0 TO num_cols - 1 LOOP
2375
                    mem_data_p(i) := mem_data_p(i) XOR
2376
                                     mask_vector.prime(inverse)((i + 1)*data_unit_width - 1 DOWNTO i*data_unit_width);
2377
                END LOOP;
2378
                read_during_write(secondary) := (access_same_location AND read_pulse(secondary)'EVENT AND read_pulse(secondary) = '1');
2379
                IF (read_during_write(secondary)) THEN
2380
                    read_latch.sec <= old_mem_data_p(col_sec);
2381
                ELSE
2382
                    mem_data <= mem_data_p;
2383
                END IF;
2384
            ELSIF (clear_asserted_during_write(primary) /= '1') THEN
2385
                FOR i IN 0 TO data_width - 1 LOOP
2386
                    IF (mask_vector.prime(normal)(i) = '0') THEN
2387
                        mem(addr_prime_reg)(i / data_unit_width)(i mod data_unit_width) <= datain_prime_reg(i);
2388
                    ELSIF (mask_vector.prime(inverse)(i) = 'X') THEN
2389
                        mem(addr_prime_reg)(i / data_unit_width)(i mod data_unit_width) <= 'X';
2390
                    END IF;
2391
                END LOOP;
2392
            END IF;
2393
        END IF;
2394
 
2395
        IF (write_pulse(secondary)'EVENT) THEN
2396
            IF (write_pulse(secondary) = '1') THEN
2397
                read_during_write(primary) := (access_same_location AND read_pulse(primary)'EVENT AND read_pulse(primary) = '1');
2398
                IF (read_during_write(primary)) THEN
2399
                    read_latch.prime <= mem(addr_prime_reg);
2400
                    read_latch.prime(col_sec) <= mem(row_sec)(col_sec) XOR mask_vector.sec(inverse);
2401
                ELSE
2402
                    mem_unit_data <= mem(row_sec)(col_sec) XOR mask_vector.sec(inverse);
2403
                END IF;
2404
 
2405
                IF (access_same_location AND write_pulse(primary)'EVENT AND write_pulse(primary) = '1') THEN
2406
                    mask_vector_common <=
2407
                       mask_vector.prime(inverse)(((col_sec + 1)* data_unit_width - 1) DOWNTO col_sec*data_unit_width) AND
2408
                       mask_vector.sec(inverse);
2409
                    dual_write <= TRUE;
2410
                END IF;
2411
            ELSIF (clear_asserted_during_write(secondary) /= '1') THEN
2412
                FOR i IN 0 TO data_unit_width - 1 LOOP
2413
                    IF (mask_vector.sec(normal)(i) = '0') THEN
2414
                        mem(row_sec)(col_sec)(i) <= datain_sec_reg(i);
2415
                    ELSIF (mask_vector.sec(inverse)(i) = 'X') THEN
2416
                        mem(row_sec)(col_sec)(i) <= 'X';
2417
                    END IF;
2418
                END LOOP;
2419
            END IF;
2420
        END IF;
2421
        -- Simultaneous write
2422
        IF (dual_write AND write_pulse = "00") THEN
2423
           mem(row_sec)(col_sec) <= mem(row_sec)(col_sec) XOR mask_vector_common;
2424
           dual_write <= FALSE;
2425
        END IF;
2426
        -- Read stage 1 : read data 
2427
        -- Read stage 2 : send data to output
2428
        IF ((NOT read_during_write(primary)) AND read_pulse(primary)'EVENT) THEN
2429
            IF (read_pulse(primary) = '1') THEN
2430
                read_latch.prime <= mem(addr_prime_reg);
2431
                IF (access_same_location AND write_pulse(secondary) = '1') THEN
2432
                    read_latch.prime(col_sec) <= mem_unit_data;
2433
                END IF;
2434
            ELSE
2435
                FOR i IN 0 TO data_width - 1 LOOP
2436
                    row_prime := i / data_unit_width; col_prime := i mod data_unit_width;
2437
                    dataout_prime(i) <= read_latch.prime(row_prime)(col_prime);
2438
                END LOOP;
2439
            END IF;
2440
        END IF;
2441
 
2442
        IF ((NOT read_during_write(secondary)) AND read_pulse(secondary)'EVENT) THEN
2443
            IF (read_pulse(secondary) = '1') THEN
2444
                IF (access_same_location AND write_pulse(primary) = '1') THEN
2445
                    read_latch.sec <= mem_data(col_sec);
2446
                ELSE
2447
                    read_latch.sec <= mem(row_sec)(col_sec);
2448
                END IF;
2449
            ELSE
2450
                dataout_sec <= read_latch.sec;
2451
            END IF;
2452
        END IF;
2453
        -- Same port feed thru
2454
           IF (read_pulse_feedthru(primary)'EVENT AND read_pulse_feedthru(primary) = '0') THEN
2455
            dataout_prime <= datain_prime_reg XOR mask_vector.prime(normal);
2456
        END IF;
2457
 
2458
        IF (read_pulse_feedthru(secondary)'EVENT AND read_pulse_feedthru(secondary) = '0') THEN
2459
           dataout_sec <= datain_sec_reg XOR mask_vector.sec(normal);
2460
        END IF;
2461
        -- Async clear
2462
        IF (mem_invalidate'EVENT) THEN
2463
            IF (mem_invalidate(primary) = TRUE OR mem_invalidate(secondary) = TRUE) THEN
2464
                mem <= mem_x;
2465
            END IF;
2466
        END IF;
2467
        IF (mem_invalidate_loc'EVENT) THEN
2468
            IF (mem_invalidate_loc(primary))   THEN mem(addr_prime_reg)   <= row_x;  END IF;
2469
            IF (mem_invalidate_loc(secondary)) THEN mem(row_sec)(col_sec) <= col_x;  END IF;
2470
        END IF;
2471
        IF (read_latch_invalidate'EVENT) THEN
2472
            IF (read_latch_invalidate(primary)) THEN
2473
                read_latch.prime <= row_x;
2474
            END IF;
2475
            IF (read_latch_invalidate(secondary)) THEN
2476
                read_latch.sec   <= col_x;
2477
            END IF;
2478
        END IF;
2479
 
2480
    END PROCESS mem_rw;
2481
 
2482
    -- Same port feed through
2483
   ftpgen_a_clkena <= '1' WHEN (active_a AND (NOT mode_is_dp) AND (we_a_reg = '1')) ELSE '0';
2484
    ftpgen_a : cycloneii_ram_pulse_generator
2485
        PORT MAP (
2486
            clk => clk_a_in,
2487
            ena => ftpgen_a_clkena,
2488
            pulse => read_pulse_feedthru(primary_port_is_a)
2489
        );
2490
   ftpgen_b_clkena <= '1' WHEN (active_b AND mode_is_bdp AND (rewe_b_reg = '1')) ELSE '0';
2491
 
2492
    ftpgen_b : cycloneii_ram_pulse_generator
2493
        PORT MAP (
2494
            clk => clk_b_in,
2495
            ena => ftpgen_b_clkena,
2496
            pulse => read_pulse_feedthru(primary_port_is_b)
2497
        );
2498
 
2499
 
2500
 
2501
 
2502
 
2503
    -- Asynch clear events    
2504
    clear_a : PROCESS(addr_a_clr,we_a_clr,datain_a_clr)
2505
    BEGIN
2506
        IF (addr_a_clr'EVENT AND addr_a_clr = '1') THEN
2507
            clear_asserted_during_write(primary_port_is_a) <= write_pulse(primary_port_is_a);
2508
            IF (active_write_a AND (write_cycle_a = '1') AND (we_a_reg = '1')) THEN
2509
                mem_invalidate(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2510
           ELSIF (active_a AND we_a_reg = '0') THEN
2511
                read_latch_invalidate(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2512
            END IF;
2513
        END IF;
2514
        IF ((we_a_clr'EVENT AND we_a_clr = '1') OR (datain_a_clr'EVENT AND datain_a_clr = '1')) THEN
2515
            clear_asserted_during_write(primary_port_is_a) <= write_pulse(primary_port_is_a);
2516
            IF (active_write_a AND (write_cycle_a = '1') AND (we_a_reg = '1')) THEN
2517
                mem_invalidate_loc(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2518
                read_latch_invalidate(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2519
            END IF;
2520
        END IF;
2521
    END PROCESS clear_a;
2522
 
2523
   clear_b : PROCESS(addr_b_clr,rewe_b_clr,datain_b_clr)
2524
    BEGIN
2525
        IF (addr_b_clr'EVENT AND addr_b_clr = '1') THEN
2526
            clear_asserted_during_write(primary_port_is_b) <= write_pulse(primary_port_is_b);
2527
           IF (mode_is_bdp AND active_write_b AND (write_cycle_b = '1') AND (rewe_b_reg = '1')) THEN
2528
                mem_invalidate(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2529
           ELSIF (active_b AND ((mode_is_dp AND rewe_b_reg = '1') OR (mode_is_bdp AND rewe_b_reg = '0'))) THEN
2530
                read_latch_invalidate(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2531
            END IF;
2532
        END IF;
2533
       IF ((rewe_b_clr'EVENT AND rewe_b_clr = '1') OR (datain_b_clr'EVENT AND datain_b_clr = '1')) THEN
2534
            clear_asserted_during_write(primary_port_is_b) <= write_pulse(primary_port_is_b);
2535
           IF (mode_is_bdp AND active_write_b AND (write_cycle_b = '1') AND (rewe_b_reg = '1')) THEN
2536
                mem_invalidate_loc(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2537
                read_latch_invalidate(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2538
            END IF;
2539
        END IF;
2540
    END PROCESS clear_b;
2541
 
2542
 
2543
 
2544
 
2545
    -- ------ Output registers
2546
       clkena_a_out <= '1'  WHEN (port_a_disable_ce_on_output_registers = "on") ELSE
2547
                       ena0 WHEN (port_a_data_out_clock = "clock0") ELSE ena1;
2548
 
2549
      clkena_b_out <= '1'  WHEN (port_b_disable_ce_on_output_registers = "on") ELSE
2550
                       ena0 WHEN (port_b_data_out_clock = "clock0") ELSE ena1;
2551
 
2552
 
2553
    dataout_a <= dataout_prime WHEN primary_port_is_a ELSE dataout_sec;
2554
    dataout_b <= (OTHERS => 'U') WHEN (mode_is_rom OR mode_is_sp) ELSE
2555
                 dataout_prime   WHEN primary_port_is_b ELSE dataout_sec;
2556
 
2557
    dataout_a_register : cycloneii_ram_register
2558
        GENERIC MAP ( width => port_a_data_width )
2559
        PORT MAP (
2560
            d => dataout_a,
2561
            clk => clk_a_out,
2562
                     aclr => dataout_a_clr,
2563
            devclrn => devclrn,
2564
            devpor => devpor,
2565
            stall => wire_gnd,
2566
            ena => clkena_a_out,
2567
            q => dataout_a_reg
2568
        );
2569
 
2570
    dataout_b_register : cycloneii_ram_register
2571
        GENERIC MAP ( width => port_b_data_width )
2572
        PORT MAP (
2573
            d => dataout_b,
2574
            clk => clk_b_out,
2575
                     aclr => dataout_b_clr,
2576
            devclrn => devclrn,
2577
            devpor => devpor,
2578
            stall => wire_gnd,
2579
            ena => clkena_b_out,
2580
            q => dataout_b_reg
2581
        );
2582
 
2583
   portadataout <= dataout_a_reg WHEN out_a_is_reg ELSE dataout_a;
2584
   portbdataout <= dataout_b_reg WHEN out_b_is_reg ELSE dataout_b;
2585
 
2586
 
2587
END block_arch;
2588
 
2589
 
2590
-------------------------------------------------------------------
2591
--
2592
-- Entity Name : cycloneii_jtag
2593
--
2594
-- Description : CycloneII JTAG VHDL Simulation model
2595
--
2596
-------------------------------------------------------------------
2597
LIBRARY IEEE;
2598
use IEEE.std_logic_1164.all;
2599
use work.cycloneii_atom_pack.all;
2600
 
2601
entity  cycloneii_jtag is
2602
    generic (
2603
        lpm_type : string := "cycloneii_jtag"
2604
        );
2605
    port (
2606
        tms : in std_logic := '0';
2607
        tck : in std_logic := '0';
2608
        tdi : in std_logic := '0';
2609
        ntrst : in std_logic := '0';
2610
        tdoutap : in std_logic := '0';
2611
        tdouser : in std_logic := '0';
2612
        tdo: out std_logic;
2613
        tmsutap: out std_logic;
2614
        tckutap: out std_logic;
2615
        tdiutap: out std_logic;
2616
        shiftuser: out std_logic;
2617
        clkdruser: out std_logic;
2618
        updateuser: out std_logic;
2619
        runidleuser: out std_logic;
2620
        usr1user: out std_logic
2621
        );
2622
end cycloneii_jtag;
2623
 
2624
architecture architecture_jtag of cycloneii_jtag is
2625
begin
2626
 
2627
end architecture_jtag;
2628
 
2629
-------------------------------------------------------------------
2630
--
2631
-- Entity Name : cycloneii_crcblock
2632
--
2633
-- Description : CycloneII CRCBLOCK VHDL Simulation model
2634
--
2635
-------------------------------------------------------------------
2636
LIBRARY IEEE;
2637
use IEEE.std_logic_1164.all;
2638
use work.cycloneii_atom_pack.all;
2639
 
2640
entity  cycloneii_crcblock is
2641
    generic  (
2642
        oscillator_divider : integer := 1;
2643
 
2644
        lpm_type : string := "cycloneii_crcblock"
2645
        );
2646
    port (
2647
        clk : in std_logic := '0';
2648
        shiftnld : in std_logic := '0';
2649
           ldsrc : in std_logic := '0';
2650
        crcerror : out std_logic;
2651
        regout : out std_logic
2652
        );
2653
end cycloneii_crcblock;
2654
 
2655
architecture architecture_crcblock of cycloneii_crcblock is
2656
begin
2657
 
2658
end architecture_crcblock;
2659
-------------------------------------------------------------------
2660
--
2661
-- Entity Name : cycloneii_asmiblock
2662
--
2663
-- Description : CycloneII ASMIBLOCK VHDL Simulation model
2664
--
2665
-------------------------------------------------------------------
2666
LIBRARY IEEE;
2667
use IEEE.std_logic_1164.all;
2668
use work.cycloneii_atom_pack.all;
2669
 
2670
entity  cycloneii_asmiblock is
2671
         generic (
2672
                                        lpm_type        : string := "cycloneii_asmiblock"
2673
                                );
2674
    port (dclkin : in std_logic;
2675
                 scein : in std_logic;
2676
                 sdoin : in std_logic;
2677
                 oe : in std_logic;
2678
          data0out: out std_logic);
2679
end cycloneii_asmiblock;
2680
 
2681
architecture architecture_asmiblock of cycloneii_asmiblock is
2682
begin
2683
 
2684
process(dclkin, scein, sdoin, oe)
2685
begin
2686
 
2687
end process;
2688
 
2689
end architecture_asmiblock;  -- end of cycloneii_asmiblock
2690
--///////////////////////////////////////////////////////////////////////////
2691
--
2692
-- Entity Name : cycloneii_m_cntr
2693
--
2694
-- Description : Timing simulation model for the M counter. M is the loop 
2695
--               feedback counter of the CycloneII PLL.
2696
--
2697
--///////////////////////////////////////////////////////////////////////////
2698
 
2699
LIBRARY IEEE;
2700
USE IEEE.std_logic_1164.all;
2701
USE IEEE.VITAL_Timing.all;
2702
USE IEEE.VITAL_Primitives.all;
2703
 
2704
ENTITY cycloneii_m_cntr is
2705
    PORT(  clk           : IN std_logic;
2706
            reset         : IN std_logic := '0';
2707
            cout          : OUT std_logic;
2708
            initial_value : IN integer := 1;
2709
            modulus       : IN integer := 1;
2710
            time_delay    : IN integer := 0
2711
        );
2712
END cycloneii_m_cntr;
2713
 
2714
ARCHITECTURE behave of cycloneii_m_cntr is
2715
begin
2716
 
2717
    process (clk, reset)
2718
    variable count : integer := 1;
2719
    variable first_rising_edge : boolean := true;
2720
    variable tmp_cout : std_logic;
2721
    begin
2722
        if (reset = '1') then
2723
            count := 1;
2724
            tmp_cout := '0';
2725
            first_rising_edge := true;
2726
        elsif (clk'event) then
2727
            if (clk = '1' and first_rising_edge) then
2728
                first_rising_edge := false;
2729
                tmp_cout := clk;
2730
            elsif (not first_rising_edge) then
2731
                if (count < modulus) then
2732
                    count := count + 1;
2733
                else
2734
                    count := 1;
2735
                    tmp_cout := not tmp_cout;
2736
                end if;
2737
            end if;
2738
        end if;
2739
        cout <= transport tmp_cout after time_delay * 1 ps;
2740
    end process;
2741
end behave;
2742
 
2743
--///////////////////////////////////////////////////////////////////////////
2744
--
2745
-- Entity Name : cycloneii_n_cntr
2746
--
2747
-- Description : Timing simulation model for the N counter. N is the
2748
--               input counter of the CycloneII PLL.
2749
--
2750
--///////////////////////////////////////////////////////////////////////////
2751
 
2752
LIBRARY IEEE;
2753
USE IEEE.std_logic_1164.all;
2754
USE IEEE.VITAL_Timing.all;
2755
USE IEEE.VITAL_Primitives.all;
2756
 
2757
ENTITY cycloneii_n_cntr is
2758
    PORT(  clk           : IN std_logic;
2759
            reset         : IN std_logic := '0';
2760
            cout          : OUT std_logic;
2761
            initial_value : IN integer := 1;
2762
            modulus       : IN integer := 1;
2763
            time_delay    : IN integer := 0
2764
        );
2765
END cycloneii_n_cntr;
2766
 
2767
ARCHITECTURE behave of cycloneii_n_cntr is
2768
begin
2769
 
2770
    process (clk, reset)
2771
    variable count : integer := 1;
2772
    variable first_rising_edge : boolean := true;
2773
    variable tmp_cout : std_logic;
2774
    variable clk_last_valid_value : std_logic;
2775
    begin
2776
        if (reset = '1') then
2777
            count := 1;
2778
            tmp_cout := '0';
2779
            first_rising_edge := true;
2780
        elsif (clk'event) then
2781
            if (clk = 'X') then
2782
                ASSERT FALSE REPORT "Invalid transition to 'X' detected on PLL input clk. This edge will be ignored." severity warning;
2783
            elsif (clk = '1' and first_rising_edge) then
2784
                first_rising_edge := false;
2785
                tmp_cout := clk;
2786
            elsif (not first_rising_edge) then
2787
                if (count < modulus) then
2788
                    count := count + 1;
2789
                else
2790
                    count := 1;
2791
                    tmp_cout := not tmp_cout;
2792
                end if;
2793
            end if;
2794
        end if;
2795
        if (clk /= 'X') then
2796
            clk_last_valid_value := clk;
2797
        end if;
2798
        cout <= transport tmp_cout after time_delay * 1 ps;
2799
    end process;
2800
end behave;
2801
 
2802
--/////////////////////////////////////////////////////////////////////////////
2803
--
2804
-- Entity Name : cycloneii_scale_cntr
2805
--
2806
-- Description : Timing simulation model for the output scale-down counters.
2807
--               This is a common model for the C0, C1, C2, C3, C4 and C5
2808
--               output counters of the CycloneII PLL.
2809
--
2810
--/////////////////////////////////////////////////////////////////////////////
2811
 
2812
LIBRARY IEEE;
2813
USE IEEE.std_logic_1164.all;
2814
USE IEEE.VITAL_Timing.all;
2815
USE IEEE.VITAL_Primitives.all;
2816
 
2817
ENTITY cycloneii_scale_cntr is
2818
    PORT(   clk            : IN std_logic;
2819
            reset          : IN std_logic := '0';
2820
            initial        : IN integer := 1;
2821
            high           : IN integer := 1;
2822
            low            : IN integer := 1;
2823
            mode           : IN string := "bypass";
2824
            ph_tap         : IN integer := 0;
2825
            cout           : OUT std_logic
2826
        );
2827
END cycloneii_scale_cntr;
2828
 
2829
ARCHITECTURE behave of cycloneii_scale_cntr is
2830
begin
2831
    process (clk, reset)
2832
    variable tmp_cout : std_logic := '0';
2833
    variable count : integer := 1;
2834
    variable output_shift_count : integer := 1;
2835
    variable first_rising_edge : boolean := false;
2836
    begin
2837
        if (reset = '1') then
2838
            count := 1;
2839
            output_shift_count := 1;
2840
            tmp_cout := '0';
2841
            first_rising_edge := false;
2842
        elsif (clk'event) then
2843
            if (mode = "   off") then
2844
                tmp_cout := '0';
2845
            elsif (mode = "bypass") then
2846
                tmp_cout := clk;
2847
                first_rising_edge := true;
2848
            elsif (not first_rising_edge) then
2849
                if (clk = '1') then
2850
                    if (output_shift_count = initial) then
2851
                        tmp_cout := clk;
2852
                        first_rising_edge := true;
2853
                    else
2854
                        output_shift_count := output_shift_count + 1;
2855
                    end if;
2856
                end if;
2857
            elsif (output_shift_count < initial) then
2858
                if (clk = '1') then
2859
                    output_shift_count := output_shift_count + 1;
2860
                end if;
2861
            else
2862
                count := count + 1;
2863
                if (mode = "  even" and (count = (high*2) + 1)) then
2864
                    tmp_cout := '0';
2865
                elsif (mode = "   odd" and (count = high*2)) then
2866
                    tmp_cout := '0';
2867
                elsif (count = (high + low)*2 + 1) then
2868
                    tmp_cout := '1';
2869
                    count := 1;  -- reset count
2870
                end if;
2871
            end if;
2872
        end if;
2873
        cout <= transport tmp_cout;
2874
    end process;
2875
 
2876
end behave;
2877
 
2878
--/////////////////////////////////////////////////////////////////////////////
2879
--
2880
-- Entity Name : cycloneii_pll_reg
2881
--
2882
-- Description : Simulation model for a simple DFF.
2883
--               This is required for the generation of the bit slip-signals.
2884
--               No timing, powers upto 0.
2885
--
2886
--/////////////////////////////////////////////////////////////////////////////
2887
LIBRARY IEEE;
2888
USE IEEE.std_logic_1164.all;
2889
 
2890
ENTITY cycloneii_pll_reg is
2891
    PORT(   clk : in std_logic;
2892
            ena : in std_logic := '1';
2893
            d : in std_logic;
2894
            clrn : in std_logic := '1';
2895
            prn : in std_logic := '1';
2896
            q : out std_logic
2897
        );
2898
end cycloneii_pll_reg;
2899
 
2900
ARCHITECTURE behave of cycloneii_pll_reg is
2901
begin
2902
    process (clk, prn, clrn)
2903
    variable q_reg : std_logic := '0';
2904
    begin
2905
        if (prn = '0') then
2906
            q_reg := '1';
2907
        elsif (clrn = '0') then
2908
            q_reg := '0';
2909
        elsif (clk'event and clk = '1' and (ena = '1')) then
2910
            q_reg := D;
2911
        end if;
2912
 
2913
        Q <= q_reg;
2914
    end process;
2915
end behave;
2916
--///////////////////////////////////////////////////////////////////////////
2917
--
2918
-- Entity Name : cycloneii_pll
2919
--
2920
-- Description : Timing simulation model for the CycloneII PLL.
2921
--               In the functional mode, it is also the model for the altpll
2922
--               megafunction.
2923
--
2924
-- Limitations : Does not support Spread Spectrum and Bandwidth.
2925
--
2926
-- Outputs     : Up to 6 output clocks, each defined by its own set of
2927
--               parameters. Locked output (active high) indicates when the
2928
--               PLL locks. clkbad, clkloss and activeclock are used for
2929
--               clock switchover to indicate which input clock has gone
2930
--               bad, when the clock switchover initiates and which input
2931
--               clock is being used as the reference, respectively.
2932
--               scandataout is the data output of the serial scan chain.
2933
--
2934
--///////////////////////////////////////////////////////////////////////////
2935
LIBRARY IEEE, std;
2936
USE IEEE.std_logic_1164.all;
2937
USE IEEE.VITAL_Timing.all;
2938
USE IEEE.VITAL_Primitives.all;
2939
USE STD.TEXTIO.all;
2940
USE work.cycloneii_atom_pack.all;
2941
USE work.cycloneii_pllpack.all;
2942
USE work.cycloneii_m_cntr;
2943
USE work.cycloneii_n_cntr;
2944
USE work.cycloneii_scale_cntr;
2945
USE work.cycloneii_dffe;
2946
USE work.cycloneii_pll_reg;
2947
 
2948
ENTITY cycloneii_pll is
2949
    GENERIC (
2950
        operation_mode              : string := "normal";
2951
        pll_type                    : string := "auto";  -- EGPP/FAST/AUTO
2952
        compensate_clock            : string := "clk0";
2953
        feedback_source             : string := "clk0";
2954
        qualify_conf_done           : string := "off";
2955
 
2956
        test_input_comp_delay       : integer := 0;
2957
        test_feedback_comp_delay    : integer := 0;
2958
 
2959
        inclk0_input_frequency      : integer := 10000;
2960
        inclk1_input_frequency      : integer := 10000;
2961
 
2962
        gate_lock_signal            : string := "no";
2963
        gate_lock_counter           : integer := 1;
2964
        self_reset_on_gated_loss_lock : string := "off";
2965
        valid_lock_multiplier       : integer := 1;
2966
        invalid_lock_multiplier     : integer := 5;
2967
        sim_gate_lock_device_behavior : string := "off";
2968
 
2969
        switch_over_type            : string := "manual";
2970
        switch_over_on_lossclk      : string := "off";
2971
        switch_over_on_gated_lock   : string := "off";
2972
        switch_over_counter         : integer := 1;
2973
        enable_switch_over_counter  : string := "on";
2974
 
2975
        bandwidth                   : integer := 0;
2976
        bandwidth_type              : string := "auto";
2977
        down_spread                 : string := "0.0";
2978
        spread_frequency            : integer := 0;
2979
 
2980
        clk0_output_frequency       : integer := 0;
2981
        clk0_multiply_by            : integer := 1;
2982
        clk0_divide_by              : integer := 1;
2983
        clk0_phase_shift            : string := "0";
2984
        clk0_duty_cycle             : integer := 50;
2985
 
2986
        clk1_output_frequency       : integer := 0;
2987
        clk1_multiply_by            : integer := 1;
2988
        clk1_divide_by              : integer := 1;
2989
        clk1_phase_shift            : string := "0";
2990
        clk1_duty_cycle             : integer := 50;
2991
 
2992
        clk2_output_frequency       : integer := 0;
2993
        clk2_multiply_by            : integer := 1;
2994
        clk2_divide_by              : integer := 1;
2995
        clk2_phase_shift            : string := "0";
2996
        clk2_duty_cycle             : integer := 50;
2997
 
2998
        clk3_output_frequency       : integer := 0;
2999
        clk3_multiply_by            : integer := 1;
3000
        clk3_divide_by              : integer := 1;
3001
        clk3_phase_shift            : string := "0";
3002
        clk3_duty_cycle             : integer := 50;
3003
 
3004
        clk4_output_frequency       : integer := 0;
3005
        clk4_multiply_by            : integer := 1;
3006
        clk4_divide_by              : integer := 1;
3007
        clk4_phase_shift            : string := "0";
3008
        clk4_duty_cycle             : integer := 50;
3009
 
3010
        clk5_output_frequency       : integer := 0;
3011
        clk5_multiply_by            : integer := 1;
3012
        clk5_divide_by              : integer := 1;
3013
        clk5_phase_shift            : string := "0";
3014
        clk5_duty_cycle             : integer := 50;
3015
 
3016
        pfd_min                     : integer := 0;
3017
        pfd_max                     : integer := 0;
3018
        vco_min                     : integer := 0;
3019
        vco_max                     : integer := 0;
3020
        vco_center                  : integer := 0;
3021
 
3022
        -- ADVANCED USER PARAMETERS
3023
        m_initial                   : integer := 1;
3024
        m                           : integer := 0;
3025
        n                           : integer := 1;
3026
        m2                          : integer := 1;
3027
        n2                          : integer := 1;
3028
        ss                          : integer := 0;
3029
 
3030
        c0_high                     : integer := 1;
3031
        c0_low                      : integer := 1;
3032
        c0_initial                  : integer := 1;
3033
        c0_mode                     : string := "bypass";
3034
        c0_ph                       : integer := 0;
3035
 
3036
        c1_high                     : integer := 1;
3037
        c1_low                      : integer := 1;
3038
        c1_initial                  : integer := 1;
3039
        c1_mode                     : string := "bypass";
3040
        c1_ph                       : integer := 0;
3041
 
3042
        c2_high                     : integer := 1;
3043
        c2_low                      : integer := 1;
3044
        c2_initial                  : integer := 1;
3045
        c2_mode                     : string := "bypass";
3046
        c2_ph                       : integer := 0;
3047
 
3048
        c3_high                     : integer := 1;
3049
        c3_low                      : integer := 1;
3050
        c3_initial                  : integer := 1;
3051
        c3_mode                     : string := "bypass";
3052
        c3_ph                       : integer := 0;
3053
 
3054
        c4_high                     : integer := 1;
3055
        c4_low                      : integer := 1;
3056
        c4_initial                  : integer := 1;
3057
        c4_mode                     : string := "bypass";
3058
        c4_ph                       : integer := 0;
3059
 
3060
        c5_high                     : integer := 1;
3061
        c5_low                      : integer := 1;
3062
        c5_initial                  : integer := 1;
3063
        c5_mode                     : string := "bypass";
3064
        c5_ph                       : integer := 0;
3065
 
3066
        m_ph                        : integer := 0;
3067
 
3068
        clk0_counter                : string := "c0";
3069
        clk1_counter                : string := "c1";
3070
        clk2_counter                : string := "c2";
3071
        clk3_counter                : string := "c3";
3072
        clk4_counter                : string := "c4";
3073
        clk5_counter                : string := "c5";
3074
 
3075
        c1_use_casc_in              : string := "off";
3076
        c2_use_casc_in              : string := "off";
3077
        c3_use_casc_in              : string := "off";
3078
        c4_use_casc_in              : string := "off";
3079
        c5_use_casc_in              : string := "off";
3080
 
3081
        m_test_source               : integer := 5;
3082
        c0_test_source              : integer := 5;
3083
        c1_test_source              : integer := 5;
3084
        c2_test_source              : integer := 5;
3085
        c3_test_source              : integer := 5;
3086
        c4_test_source              : integer := 5;
3087
        c5_test_source              : integer := 5;
3088
 
3089
        -- LVDS mode parameters
3090
        enable0_counter             : string := "c0";
3091
        enable1_counter             : string := "c1";
3092
        sclkout0_phase_shift        : string := "0";
3093
        sclkout1_phase_shift        : string := "0";
3094
 
3095
        charge_pump_current         : integer := 52;
3096
        loop_filter_r               : string := " 1.000000";
3097
        loop_filter_c               : integer := 16;
3098
        use_vco_bypass              : string := "false";
3099
        use_dc_coupling             : string := "false";
3100
 
3101
        pll_compensation_delay      : integer := 0;
3102
        simulation_type             : string := "functional";
3103
        lpm_type                    : string := "cycloneii_pll";
3104
 
3105
        -- Simulation only generics
3106
        family_name                 : string  := "CycloneII";
3107
 
3108
        clk0_use_even_counter_mode  : string := "off";
3109
        clk1_use_even_counter_mode  : string := "off";
3110
        clk2_use_even_counter_mode  : string := "off";
3111
        clk3_use_even_counter_mode  : string := "off";
3112
        clk4_use_even_counter_mode  : string := "off";
3113
        clk5_use_even_counter_mode  : string := "off";
3114
 
3115
        clk0_use_even_counter_value : string := "off";
3116
        clk1_use_even_counter_value : string := "off";
3117
        clk2_use_even_counter_value : string := "off";
3118
        clk3_use_even_counter_value : string := "off";
3119
        clk4_use_even_counter_value : string := "off";
3120
        clk5_use_even_counter_value : string := "off";
3121
 
3122
        vco_multiply_by             : integer := 0;
3123
        vco_divide_by               : integer := 0;
3124
        vco_post_scale              : integer := 1;
3125
 
3126
        -- VITAL generics
3127
        XOn                         : Boolean := DefGlitchXOn;
3128
        MsgOn                       : Boolean := DefGlitchMsgOn;
3129
        MsgOnChecks                 : Boolean := DefMsgOnChecks;
3130
        XOnChecks                   : Boolean := DefXOnChecks;
3131
        TimingChecksOn              : Boolean := true;
3132
        InstancePath                : STRING := "*";
3133
        tipd_inclk                  : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01);
3134
        tipd_ena                    : VitalDelayType01 := DefPropDelay01;
3135
        tipd_pfdena                 : VitalDelayType01 := DefPropDelay01;
3136
        tipd_areset                 : VitalDelayType01 := DefPropDelay01;
3137
        tipd_clkswitch              : VitalDelayType01 := DefPropDelay01
3138
    );
3139
 
3140
    PORT
3141
    (
3142
        inclk                       : in std_logic_vector(1 downto 0);
3143
        ena                         : in std_logic := '1';
3144
        clkswitch                   : in std_logic := '0';
3145
        areset                      : in std_logic := '0';
3146
        pfdena                      : in std_logic := '1';
3147
        testclearlock               : in std_logic := '0';
3148
        sbdin                       : in std_logic := '0';
3149
        clk                         : out std_logic_vector(2 downto 0);
3150
        locked                      : out std_logic;
3151
        testupout                   : out std_logic;
3152
        testdownout                 : out std_logic;
3153
        sbdout                      : out std_logic
3154
    );
3155
END cycloneii_pll;
3156
 
3157
ARCHITECTURE vital_pll of cycloneii_pll is
3158
 
3159
TYPE int_array is ARRAY(NATURAL RANGE <>) of integer;
3160
TYPE str_array is ARRAY(NATURAL RANGE <>) of string(1 to 6);
3161
TYPE str_array1 is ARRAY(NATURAL RANGE <>) of string(1 to 9);
3162
TYPE std_logic_array is ARRAY(NATURAL RANGE <>) of std_logic;
3163
 
3164
-- internal advanced parameter signals
3165
signal   i_vco_min      : integer;
3166
signal   i_vco_max      : integer;
3167
signal   i_vco_center   : integer;
3168
signal   i_pfd_min      : integer;
3169
signal   i_pfd_max      : integer;
3170
signal   c_ph_val       : int_array(0 to 5) := (OTHERS => 0);
3171
signal   c_high_val     : int_array(0 to 5) := (OTHERS => 1);
3172
signal   c_low_val      : int_array(0 to 5) := (OTHERS => 1);
3173
signal   c_initial_val  : int_array(0 to 5) := (OTHERS => 1);
3174
signal   c_mode_val     : str_array(0 to 5);
3175
 
3176
-- old values
3177
signal   c_high_val_old : int_array(0 to 5) := (OTHERS => 1);
3178
signal   c_low_val_old  : int_array(0 to 5) := (OTHERS => 1);
3179
signal   c_ph_val_old   : int_array(0 to 5) := (OTHERS => 0);
3180
signal   c_mode_val_old : str_array(0 to 5);
3181
 
3182
-- hold registers
3183
signal   c_high_val_hold : int_array(0 to 5) := (OTHERS => 1);
3184
signal   c_low_val_hold  : int_array(0 to 5) := (OTHERS => 1);
3185
signal   c_ph_val_hold   : int_array(0 to 5) := (OTHERS => 0);
3186
signal   c_mode_val_hold : str_array(0 to 5);
3187
 
3188
-- temp registers
3189
signal   sig_c_ph_val_tmp   : int_array(0 to 5) := (OTHERS => 0);
3190
signal   sig_c_low_val_tmp  : int_array(0 to 5) := (OTHERS => 1);
3191
signal   sig_c_hi_val_tmp  : int_array(0 to 5) := (OTHERS => 1);
3192
signal   c_ph_val_orig  : int_array(0 to 5) := (OTHERS => 0);
3193
 
3194
--signal   i_clk5_counter         : string(1 to 2) := "c5";
3195
--signal   i_clk4_counter         : string(1 to 2) := "c4";
3196
--signal   i_clk3_counter         : string(1 to 2) := "c3";
3197
--signal   i_clk2_counter         : string(1 to 2) := "c2";
3198
--signal   i_clk1_counter         : string(1 to 2) := "c1";
3199
--signal   i_clk0_counter         : string(1 to 2) := "c0";
3200
 
3201
signal   i_clk5_counter         : integer := 5;
3202
signal   i_clk4_counter         : integer := 4;
3203
signal   i_clk3_counter         : integer := 3;
3204
signal   i_clk2_counter         : integer := 2;
3205
signal   i_clk1_counter         : integer := 1;
3206
signal   i_clk0_counter         : integer := 0;
3207
signal   i_charge_pump_current  : integer;
3208
signal   i_loop_filter_r        : integer;
3209
 
3210
-- end internal advanced parameter signals
3211
 
3212
-- CONSTANTS
3213
CONSTANT GPP_SCAN_CHAIN : integer := 174;
3214
CONSTANT FAST_SCAN_CHAIN : integer := 75;
3215
CONSTANT GATE_LOCK_CYCLES : integer := 7;
3216
 
3217
CONSTANT cntrs : str_array(5 downto 0) := ("    C5", "    C4", "    C3", "    C2", "    C1", "    C0");
3218
CONSTANT ss_cntrs : str_array(0 to 3) := ("     M", "    M2", "     N", "    N2");
3219
 
3220
CONSTANT loop_filter_c_arr : int_array(0 to 3) := (57, 16, 36, 5);
3221
CONSTANT fpll_loop_filter_c_arr : int_array(0 to 3) := (18, 13, 8, 2);
3222
CONSTANT charge_pump_curr_arr : int_array(0 to 15) := (6, 12, 30, 36, 52, 57, 72, 77, 92, 96, 110, 114, 127, 131, 144, 148);
3223
CONSTANT loop_filter_r_arr : str_array1(0 to 39) := (" 1.000000", " 1.500000", " 2.000000", " 2.500000", " 3.000000", " 3.500000", " 4.000000", " 4.500000", " 5.000000", " 5.500000", " 6.000000", " 6.500000", " 7.000000", " 7.500000", " 8.000000", " 8.500000", " 9.000000", " 9.500000", "10.000000", "10.500000", "11.000000", "11.500000", "12.000000", "12.500000", "13.000000", "13.500000", "14.000000", "14.500000", "15.000000", "15.500000", "16.000000", "16.500000", "17.000000", "17.500000", "18.000000", "18.500000", "19.000000", "19.500000", "20.000000", "20.500000");
3224
 
3225
-- signals
3226
 
3227
signal vcc : std_logic := '1';
3228
 
3229
signal fbclk       : std_logic;
3230
signal refclk      : std_logic;
3231
 
3232
signal c_clk : std_logic_array(0 to 5);
3233
signal vco_out : std_logic_vector(7 downto 0) := (OTHERS => '0');
3234
signal vco_tap : std_logic_vector(7 downto 0) := (OTHERS => '0');
3235
signal vco_out_last_value : std_logic_vector(7 downto 0);
3236
signal vco_tap_last_value : std_logic_vector(7 downto 0);
3237
 
3238
-- signals to assign values to counter params
3239
signal m_val : int_array(0 to 1) := (OTHERS => 1);
3240
signal n_val : int_array(0 to 1) := (OTHERS => 1);
3241
signal m_ph_val : integer := 0;
3242
signal m_initial_val : integer := m_initial;
3243
 
3244
signal m_mode_val : str_array(0 to 1) := (OTHERS => "      ");
3245
signal n_mode_val : str_array(0 to 1) := (OTHERS => "      ");
3246
signal lfc_val : integer := 0;
3247
signal cp_curr_val : integer := 0;
3248
signal lfr_val : string(1 to 9) := "         ";
3249
 
3250
-- old values
3251
signal m_val_old : int_array(0 to 1) := (OTHERS => 1);
3252
signal n_val_old : int_array(0 to 1) := (OTHERS => 1);
3253
signal m_mode_val_old : str_array(0 to 1) := (OTHERS => "      ");
3254
signal n_mode_val_old : str_array(0 to 1) := (OTHERS => "      ");
3255
signal m_ph_val_old : integer := 0;
3256
signal lfc_old : integer := 0;
3257
signal cp_curr_old : integer := 0;
3258
signal lfr_old : string(1 to 9) := "         ";
3259
signal num_output_cntrs : integer := 6;
3260
 
3261
signal scan_data : std_logic_vector(173 downto 0) := (OTHERS => '0');
3262
 
3263
signal clk0_tmp : std_logic;
3264
signal clk1_tmp : std_logic;
3265
signal clk2_tmp : std_logic;
3266
signal clk3_tmp : std_logic;
3267
signal clk4_tmp : std_logic;
3268
signal clk5_tmp : std_logic;
3269
signal sclkout0_tmp : std_logic;
3270
signal sclkout1_tmp : std_logic;
3271
 
3272
signal clkin : std_logic := '0';
3273
signal gate_locked : std_logic := '0';
3274
signal lock : std_logic := '0';
3275
signal about_to_lock : boolean := false;
3276
signal reconfig_err : boolean := false;
3277
 
3278
signal inclk_c0 : std_logic;
3279
signal inclk_c1 : std_logic;
3280
signal inclk_c2 : std_logic;
3281
signal inclk_c3 : std_logic;
3282
signal inclk_c4 : std_logic;
3283
signal inclk_c5 : std_logic;
3284
signal inclk_m : std_logic;
3285
signal devpor : std_logic;
3286
signal devclrn : std_logic;
3287
 
3288
signal inclk0_ipd : std_logic;
3289
signal inclk1_ipd : std_logic;
3290
signal ena_ipd : std_logic;
3291
signal pfdena_ipd : std_logic;
3292
signal areset_ipd : std_logic;
3293
signal fbin_ipd : std_logic;
3294
signal scanclk_ipd : std_logic;
3295
signal scanread_ipd : std_logic;
3296
signal scanwrite_ipd : std_logic;
3297
signal scandata_ipd : std_logic;
3298
signal clkswitch_ipd : std_logic;
3299
-- registered signals
3300
signal scanread_reg : std_logic := '0';
3301
signal scanwrite_reg : std_logic := '0';
3302
signal scanwrite_enabled : std_logic := '0';
3303
signal gated_scanclk : std_logic := '1';
3304
 
3305
signal inclk_c0_dly1 : std_logic := '0';
3306
signal inclk_c0_dly2 : std_logic := '0';
3307
signal inclk_c0_dly3 : std_logic := '0';
3308
signal inclk_c0_dly4 : std_logic := '0';
3309
signal inclk_c0_dly5 : std_logic := '0';
3310
signal inclk_c0_dly6 : std_logic := '0';
3311
signal inclk_c1_dly1 : std_logic := '0';
3312
signal inclk_c1_dly2 : std_logic := '0';
3313
signal inclk_c1_dly3 : std_logic := '0';
3314
signal inclk_c1_dly4 : std_logic := '0';
3315
signal inclk_c1_dly5 : std_logic := '0';
3316
signal inclk_c1_dly6 : std_logic := '0';
3317
 
3318
 
3319
signal sig_offset : time := 0 ps;
3320
signal sig_refclk_time : time := 0 ps;
3321
signal sig_fbclk_period : time := 0 ps;
3322
signal sig_vco_period_was_phase_adjusted : boolean := false;
3323
signal sig_phase_adjust_was_scheduled : boolean := false;
3324
signal sig_stop_vco : std_logic := '0';
3325
signal sig_m_times_vco_period : time := 0 ps;
3326
signal sig_new_m_times_vco_period : time := 0 ps;
3327
signal sig_got_refclk_posedge : boolean := false;
3328
signal sig_got_fbclk_posedge : boolean := false;
3329
signal sig_got_second_refclk : boolean := false;
3330
 
3331
signal m_delay : integer := 0;
3332
signal n_delay : integer := 0;
3333
 
3334
signal inclk1_tmp : std_logic := '0';
3335
 
3336
signal ext_fbk_cntr_high : integer := 0;
3337
signal ext_fbk_cntr_low : integer := 0;
3338
signal ext_fbk_cntr_ph : integer := 0;
3339
signal ext_fbk_cntr_initial : integer := 1;
3340
signal ext_fbk_cntr     : string(1 to 2) := "c0";
3341
signal ext_fbk_cntr_mode : string(1 to 6) := "bypass";
3342
signal ext_fbk_cntr_index : integer := 0;
3343
 
3344
signal enable0_tmp : std_logic := '0';
3345
signal enable1_tmp : std_logic := '0';
3346
signal reset_low : std_logic := '0';
3347
 
3348
signal scandataout_tmp : std_logic := '0';
3349
signal scandone_tmp : std_logic := '0';
3350
 
3351
signal sig_refclk_period : time := (inclk0_input_frequency * 1 ps) * n;
3352
 
3353
signal schedule_vco : std_logic := '0';
3354
 
3355
signal areset_ena_sig : std_logic := '0';
3356
signal pll_in_test_mode : boolean := false;
3357
 
3358
signal inclk_c_from_vco : std_logic_array(0 to 5);
3359
 
3360
signal inclk_m_from_vco : std_logic;
3361
signal inclk_sclkout0_from_vco : std_logic;
3362
signal inclk_sclkout1_from_vco : std_logic;
3363
 
3364
--signal tap0_is_active : boolean := true;
3365
    signal sig_quiet_time : time := 0 ps;
3366
    signal sig_slowest_clk_old : time := 0 ps;
3367
    signal sig_slowest_clk_new : time := 0 ps;
3368
    signal sig_m_val_tmp : int_array(0 to 1) := (OTHERS => 1);
3369
 
3370
COMPONENT cycloneii_m_cntr
3371
    PORT (
3372
        clk           : IN std_logic;
3373
        reset         : IN std_logic := '0';
3374
        cout          : OUT std_logic;
3375
        initial_value : IN integer := 1;
3376
        modulus       : IN integer := 1;
3377
        time_delay    : IN integer := 0
3378
    );
3379
END COMPONENT;
3380
 
3381
COMPONENT cycloneii_n_cntr
3382
    PORT (
3383
        clk           : IN std_logic;
3384
        reset         : IN std_logic := '0';
3385
        cout          : OUT std_logic;
3386
        initial_value : IN integer := 1;
3387
        modulus       : IN integer := 1;
3388
        time_delay    : IN integer := 0
3389
    );
3390
END COMPONENT;
3391
 
3392
COMPONENT cycloneii_scale_cntr
3393
    PORT (
3394
        clk            : IN std_logic;
3395
        reset          : IN std_logic := '0';
3396
        cout           : OUT std_logic;
3397
        initial        : IN integer := 1;
3398
        high           : IN integer := 1;
3399
        low            : IN integer := 1;
3400
        mode           : IN string := "bypass";
3401
        ph_tap         : IN integer := 0
3402
    );
3403
END COMPONENT;
3404
 
3405
COMPONENT cycloneii_dffe
3406
    GENERIC(
3407
      TimingChecksOn: Boolean := true;
3408
      InstancePath: STRING := "*";
3409
      XOn: Boolean := DefGlitchXOn;
3410
      MsgOn: Boolean := DefGlitchMsgOn;
3411
      MsgOnChecks: Boolean := DefMsgOnChecks;
3412
      XOnChecks: Boolean := DefXOnChecks;
3413
      tpd_PRN_Q_negedge              :  VitalDelayType01 := DefPropDelay01;
3414
      tpd_CLRN_Q_negedge             :  VitalDelayType01 := DefPropDelay01;
3415
      tpd_CLK_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
3416
      tpd_ENA_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
3417
      tsetup_D_CLK_noedge_posedge    :  VitalDelayType := DefSetupHoldCnst;
3418
      tsetup_D_CLK_noedge_negedge    :  VitalDelayType := DefSetupHoldCnst;
3419
      tsetup_ENA_CLK_noedge_posedge  :  VitalDelayType := DefSetupHoldCnst;
3420
      thold_D_CLK_noedge_posedge     :  VitalDelayType := DefSetupHoldCnst;
3421
      thold_D_CLK_noedge_negedge     :  VitalDelayType := DefSetupHoldCnst;
3422
      thold_ENA_CLK_noedge_posedge   :  VitalDelayType := DefSetupHoldCnst;
3423
      tipd_D                         :  VitalDelayType01 := DefPropDelay01;
3424
      tipd_CLRN                      :  VitalDelayType01 := DefPropDelay01;
3425
      tipd_PRN                       :  VitalDelayType01 := DefPropDelay01;
3426
      tipd_CLK                       :  VitalDelayType01 := DefPropDelay01;
3427
      tipd_ENA                       :  VitalDelayType01 := DefPropDelay01);
3428
 
3429
    PORT(
3430
        Q                              :  out   STD_LOGIC := '0';
3431
        D                              :  in    STD_LOGIC := '1';
3432
        CLRN                           :  in    STD_LOGIC := '1';
3433
        PRN                            :  in    STD_LOGIC := '1';
3434
        CLK                            :  in    STD_LOGIC := '0';
3435
        ENA                            :  in    STD_LOGIC := '1');
3436
END COMPONENT;
3437
 
3438
COMPONENT cycloneii_pll_reg
3439
    PORT(
3440
        Q                              :  out   STD_LOGIC := '0';
3441
        D                              :  in    STD_LOGIC := '1';
3442
        CLRN                           :  in    STD_LOGIC := '1';
3443
        PRN                            :  in    STD_LOGIC := '1';
3444
        CLK                            :  in    STD_LOGIC := '0';
3445
        ENA                            :  in    STD_LOGIC := '1');
3446
END COMPONENT;
3447
 
3448
begin
3449
 
3450
    ----------------------
3451
    --  INPUT PATH DELAYs
3452
    ----------------------
3453
    WireDelay : block
3454
    begin
3455
        VitalWireDelay (inclk0_ipd, inclk(0), tipd_inclk(0));
3456
        VitalWireDelay (inclk1_ipd, inclk(1), tipd_inclk(1));
3457
        VitalWireDelay (areset_ipd, areset, tipd_areset);
3458
        VitalWireDelay (ena_ipd, ena, tipd_ena);
3459
        VitalWireDelay (pfdena_ipd, pfdena, tipd_pfdena);
3460
        VitalWireDelay (clkswitch_ipd, clkswitch, tipd_clkswitch);
3461
    end block;
3462
        fbin_ipd <= '0';
3463
        scanclk_ipd <= '0';
3464
        scanread_ipd <= '0';
3465
        scandata_ipd <= '0';
3466
        scanwrite_ipd <= '0';
3467
 
3468
 
3469
    inclk_m <=  refclk when m_test_source = 1 else
3470
                '0'    when m_test_source = 2 else
3471
                '0'    when m_test_source = 3 else
3472
                clk0_tmp when operation_mode = "external_feedback" and feedback_source = "clk0" else
3473
                clk1_tmp when operation_mode = "external_feedback" and feedback_source = "clk1" else
3474
                clk2_tmp when operation_mode = "external_feedback" and feedback_source = "clk2" else
3475
                clk3_tmp when operation_mode = "external_feedback" and feedback_source = "clk3" else
3476
                clk4_tmp when operation_mode = "external_feedback" and feedback_source = "clk4" else
3477
                clk5_tmp when operation_mode = "external_feedback" and feedback_source = "clk5" else
3478
                inclk_m_from_vco;
3479
 
3480
    ext_fbk_cntr_high <= c_high_val(ext_fbk_cntr_index);
3481
    ext_fbk_cntr_low  <= c_low_val(ext_fbk_cntr_index);
3482
    ext_fbk_cntr_ph   <= c_ph_val(ext_fbk_cntr_index);
3483
    ext_fbk_cntr_initial <= c_initial_val(ext_fbk_cntr_index);
3484
    ext_fbk_cntr_mode <= c_mode_val(ext_fbk_cntr_index);
3485
 
3486
    areset_ena_sig <= areset_ipd or (not ena_ipd) or sig_stop_vco;
3487
 
3488
 
3489
    pll_in_test_mode <= true when   m_test_source = 1 or c0_test_source = 1 or
3490
                                    c0_test_source = 2 or c1_test_source = 1 or
3491
                                    c1_test_source = 2 or c2_test_source = 1 or
3492
                                    c2_test_source = 2 else
3493
                        false;
3494
 
3495
    m1 : cycloneii_m_cntr
3496
        port map (  clk           => inclk_m,
3497
                    reset         => areset_ena_sig,
3498
                    cout          => fbclk,
3499
                    initial_value => m_initial_val,
3500
                    modulus       => m_val(0),
3501
                    time_delay    => m_delay
3502
                );
3503
 
3504
    -- add delta delay to inclk1 to ensure inclk0 and inclk1 are processed
3505
    -- in different simulation deltas.
3506
    inclk1_tmp <= inclk1_ipd;
3507
 
3508
    process (inclk0_ipd, inclk1_tmp, clkswitch_ipd)
3509
    variable input_value : std_logic := '0';
3510
    variable current_clock : integer := 0;
3511
    variable clk0_count, clk1_count : integer := 0;
3512
    variable clk0_is_bad, clk1_is_bad : std_logic := '0';
3513
    variable primary_clk_is_bad : boolean := false;
3514
    variable current_clk_is_bad : boolean := false;
3515
    variable got_curr_clk_falling_edge_after_clkswitch : boolean := false;
3516
    variable switch_over_count : integer := 0;
3517
    variable active_clock : std_logic := '0';
3518
    variable external_switch : boolean := false;
3519
    begin
3520
        if (now = 0 ps) then
3521
            if (switch_over_type = "manual" and clkswitch_ipd = '1') then
3522
                current_clock := 1;
3523
                active_clock := '1';
3524
            end if;
3525
        end if;
3526
        if (clkswitch_ipd'event and clkswitch_ipd = '1' and switch_over_type = "auto") then
3527
            external_switch := true;
3528
        elsif (switch_over_type = "manual") then
3529
            if (clkswitch_ipd'event and clkswitch_ipd = '1') then
3530
                current_clock := 1;
3531
                active_clock := '1';
3532
                clkin <= transport inclk1_tmp;
3533
            elsif (clkswitch_ipd'event and clkswitch_ipd = '0') then
3534
                current_clock := 0;
3535
                active_clock := '0';
3536
                clkin <= transport inclk0_ipd;
3537
            end if;
3538
        end if;
3539
        -- save the current inclk event value
3540
        if (inclk0_ipd'event) then
3541
            input_value := inclk0_ipd;
3542
        elsif (inclk1_tmp'event) then
3543
            input_value := inclk1_tmp;
3544
        end if;
3545
 
3546
        -- check if either input clk is bad
3547
        if (inclk0_ipd'event and inclk0_ipd = '1') then
3548
            clk0_count := clk0_count + 1;
3549
            clk0_is_bad := '0';
3550
            clk1_count := 0;
3551
            if (clk0_count > 2) then
3552
                -- no event on other clk for 2 cycles
3553
                clk1_is_bad := '1';
3554
                if (current_clock = 1) then
3555
                    current_clk_is_bad := true;
3556
                end if;
3557
            end if;
3558
        end if;
3559
        if (inclk1_tmp'event and inclk1_tmp = '1') then
3560
            clk1_count := clk1_count + 1;
3561
            clk1_is_bad := '0';
3562
            clk0_count := 0;
3563
            if (clk1_count > 2) then
3564
                -- no event on other clk for 2 cycles
3565
                clk0_is_bad := '1';
3566
                if (current_clock = 0) then
3567
                    current_clk_is_bad := true;
3568
                end if;
3569
            end if;
3570
        end if;
3571
 
3572
        -- check if the bad clk is the primary clock
3573
        if (clk0_is_bad = '1') then
3574
            primary_clk_is_bad := true;
3575
        else
3576
            primary_clk_is_bad := false;
3577
        end if;
3578
 
3579
        -- actual switching
3580
        if (inclk0_ipd'event and current_clock = 0) then
3581
            if (external_switch) then
3582
                if (not got_curr_clk_falling_edge_after_clkswitch) then
3583
                    if (inclk0_ipd = '0') then
3584
                        got_curr_clk_falling_edge_after_clkswitch := true;
3585
                    end if;
3586
                    clkin <= transport inclk0_ipd;
3587
                end if;
3588
            else
3589
                clkin <= transport inclk0_ipd;
3590
            end if;
3591
        elsif (inclk1_tmp'event and current_clock = 1) then
3592
            if (external_switch) then
3593
                if (not got_curr_clk_falling_edge_after_clkswitch) then
3594
                    if (inclk1_tmp = '0') then
3595
                        got_curr_clk_falling_edge_after_clkswitch := true;
3596
                    end if;
3597
                    clkin <= transport inclk1_tmp;
3598
                end if;
3599
            else
3600
                clkin <= transport inclk1_tmp;
3601
            end if;
3602
        else
3603
            if (input_value = '1' and switch_over_on_lossclk = "on"  and enable_switch_over_counter = "on" and primary_clk_is_bad) then
3604
                switch_over_count := switch_over_count + 1;
3605
            end if;
3606
            if (input_value = '0') then
3607
                if (external_switch and (got_curr_clk_falling_edge_after_clkswitch or current_clk_is_bad)) or (switch_over_on_lossclk = "on" and primary_clk_is_bad and clkswitch_ipd /= '1' and (enable_switch_over_counter = "off" or switch_over_count = switch_over_counter)) then
3608
                    got_curr_clk_falling_edge_after_clkswitch := false;
3609
                    if (current_clock = 0) then
3610
                        current_clock := 1;
3611
                    else
3612
                        current_clock := 0;
3613
                    end if;
3614
                    active_clock := not active_clock;
3615
                    switch_over_count := 0;
3616
                    external_switch := false;
3617
                    current_clk_is_bad := false;
3618
                end if;
3619
 
3620
            end if;
3621
        end if;
3622
 
3623
        -- schedule outputs
3624
        if (switch_over_on_lossclk = "on" and clkswitch_ipd /= '1') then
3625
            if (primary_clk_is_bad) then
3626
                -- assert clkloss
3627
            else
3628
            end if;
3629
        else
3630
        end if;
3631
 
3632
    end process;
3633
 
3634
    process (inclk_sclkout0_from_vco)
3635
    begin
3636
        sclkout0_tmp <= inclk_sclkout0_from_vco;
3637
    end process;
3638
 
3639
    process (inclk_sclkout1_from_vco)
3640
    begin
3641
        sclkout1_tmp <= inclk_sclkout1_from_vco;
3642
    end process;
3643
 
3644
    n1 : cycloneii_n_cntr
3645
        port map (
3646
                clk           => clkin,
3647
                reset         => areset_ipd,
3648
                cout          => refclk,
3649
                initial_value => n_val(0),
3650
                modulus       => n_val(0));
3651
 
3652
    inclk_c0 <= refclk when c0_test_source = 1 else
3653
                fbclk   when c0_test_source = 2 else
3654
                '0'     when c0_test_source = 3 else
3655
                inclk_c_from_vco(0);
3656
 
3657
    c0 : cycloneii_scale_cntr
3658
        port map (
3659
                clk            => inclk_c0,
3660
                reset          => areset_ena_sig,
3661
                cout           => c_clk(0),
3662
                initial        => c_initial_val(0),
3663
                high           => c_high_val(0),
3664
                low            => c_low_val(0),
3665
                mode           => c_mode_val(0),
3666
                ph_tap         => c_ph_val(0));
3667
 
3668
    inclk_c1 <= refclk when c1_test_source = 1 else
3669
                fbclk  when c1_test_source = 2 else
3670
                '0'    when c1_test_source = 3 else
3671
                c_clk(0) when c1_use_casc_in = "on" else
3672
                inclk_c_from_vco(1);
3673
 
3674
    c1 : cycloneii_scale_cntr
3675
        port map (
3676
                clk            => inclk_c1,
3677
                reset          => areset_ena_sig,
3678
                cout           => c_clk(1),
3679
                initial        => c_initial_val(1),
3680
                high           => c_high_val(1),
3681
                low            => c_low_val(1),
3682
                mode           => c_mode_val(1),
3683
                ph_tap         => c_ph_val(1));
3684
 
3685
    inclk_c2 <= refclk when c2_test_source = 1 else
3686
                fbclk  when c2_test_source = 2 else
3687
                '0'    when c2_test_source = 3 else
3688
                c_clk(1) when c2_use_casc_in = "on" else
3689
                inclk_c_from_vco(2);
3690
 
3691
    c2 : cycloneii_scale_cntr
3692
        port map (
3693
                clk            => inclk_c2,
3694
                reset          => areset_ena_sig,
3695
                cout           => c_clk(2),
3696
                initial        => c_initial_val(2),
3697
                high           => c_high_val(2),
3698
                low            => c_low_val(2),
3699
                mode           => c_mode_val(2),
3700
                ph_tap         => c_ph_val(2));
3701
 
3702
 
3703
    inclk_c3 <= clkin when c3_test_source = 0 else
3704
                c_clk(2) when c3_use_casc_in = "on" else
3705
                inclk_c_from_vco(3);
3706
    c3 : cycloneii_scale_cntr
3707
        port map (
3708
                clk            => inclk_c3,
3709
                reset          => areset_ena_sig,
3710
                cout           => c_clk(3),
3711
                initial        => c_initial_val(3),
3712
                high           => c_high_val(3),
3713
                low            => c_low_val(3),
3714
                mode           => c_mode_val(3),
3715
                ph_tap         => c_ph_val(3));
3716
 
3717
    inclk_c4 <= '0' when (pll_type = "fast") else
3718
                clkin when (c4_test_source = 0) else
3719
                c_clk(3) when (c4_use_casc_in = "on") else
3720
                inclk_c_from_vco(4);
3721
    c4 : cycloneii_scale_cntr
3722
        port map (
3723
                clk            => inclk_c4,
3724
                reset          => areset_ena_sig,
3725
                cout           => c_clk(4),
3726
                initial        => c_initial_val(4),
3727
                high           => c_high_val(4),
3728
                low            => c_low_val(4),
3729
                mode           => c_mode_val(4),
3730
                ph_tap         => c_ph_val(4));
3731
 
3732
    inclk_c5 <= '0' when (pll_type = "fast") else
3733
                clkin when c5_test_source = 0 else
3734
                c_clk(4) when c5_use_casc_in = "on" else
3735
                inclk_c_from_vco(5);
3736
    c5 : cycloneii_scale_cntr
3737
        port map (
3738
                clk            => inclk_c5,
3739
                reset          => areset_ena_sig,
3740
                cout           => c_clk(5),
3741
                initial        => c_initial_val(5),
3742
                high           => c_high_val(5),
3743
                low            => c_low_val(5),
3744
                mode           => c_mode_val(5),
3745
                ph_tap         => c_ph_val(5));
3746
 
3747
    inclk_c0_dly1 <= inclk_c0 when (pll_type = "fast" or pll_type = "lvds")
3748
                    else '0';
3749
    inclk_c0_dly2 <= inclk_c0_dly1;
3750
    inclk_c0_dly3 <= inclk_c0_dly2;
3751
    inclk_c0_dly4 <= inclk_c0_dly3;
3752
    inclk_c0_dly5 <= inclk_c0_dly4;
3753
    inclk_c0_dly6 <= inclk_c0_dly5;
3754
 
3755
    inclk_c1_dly1 <= inclk_c1 when (pll_type = "fast" or pll_type = "lvds")
3756
                    else '0';
3757
    inclk_c1_dly2 <= inclk_c1_dly1;
3758
    inclk_c1_dly3 <= inclk_c1_dly2;
3759
    inclk_c1_dly4 <= inclk_c1_dly3;
3760
    inclk_c1_dly5 <= inclk_c1_dly4;
3761
    inclk_c1_dly6 <= inclk_c1_dly5;
3762
 
3763
    process(inclk_c0_dly6, inclk_c1_dly6, areset_ipd, ena_ipd, sig_stop_vco)
3764
    variable c0_got_first_rising_edge : boolean := false;
3765
    variable c0_count : integer := 2;
3766
    variable c0_initial_count : integer := 1;
3767
    variable c0_tmp, c1_tmp : std_logic := '0';
3768
    variable c1_got_first_rising_edge : boolean := false;
3769
    variable c1_count : integer := 2;
3770
    variable c1_initial_count : integer := 1;
3771
    begin
3772
        if (areset_ipd = '1' or ena_ipd = '0' or sig_stop_vco = '1') then
3773
            c0_count := 2;
3774
            c1_count := 2;
3775
            c0_initial_count := 1;
3776
            c1_initial_count := 1;
3777
            c0_got_first_rising_edge := false;
3778
            c1_got_first_rising_edge := false;
3779
        else
3780
            if (not c0_got_first_rising_edge) then
3781
                if (inclk_c0_dly6'event and inclk_c0_dly6 = '1') then
3782
                    if (c0_initial_count = c_initial_val(0)) then
3783
                        c0_got_first_rising_edge := true;
3784
                    else
3785
                        c0_initial_count := c0_initial_count + 1;
3786
                    end if;
3787
                end if;
3788
            elsif (inclk_c0_dly6'event) then
3789
                c0_count := c0_count + 1;
3790
                if (c0_count = (c_high_val(0) + c_low_val(0)) * 2) then
3791
                    c0_count := 1;
3792
                end if;
3793
            end if;
3794
            if (inclk_c0_dly6'event and inclk_c0_dly6 = '0') then
3795
                if (c0_count = 1) then
3796
                    c0_tmp := '1';
3797
                    c0_got_first_rising_edge := false;
3798
                else
3799
                    c0_tmp := '0';
3800
                end if;
3801
            end if;
3802
 
3803
            if (not c1_got_first_rising_edge) then
3804
                if (inclk_c1_dly6'event and inclk_c1_dly6 = '1') then
3805
                    if (c1_initial_count = c_initial_val(1)) then
3806
                        c1_got_first_rising_edge := true;
3807
                    else
3808
                        c1_initial_count := c1_initial_count + 1;
3809
                    end if;
3810
                end if;
3811
            elsif (inclk_c1_dly6'event) then
3812
                c1_count := c1_count + 1;
3813
                if (c1_count = (c_high_val(1) + c_low_val(1)) * 2) then
3814
                    c1_count := 1;
3815
                end if;
3816
            end if;
3817
            if (inclk_c1_dly6'event and inclk_c1_dly6 = '0') then
3818
                if (c1_count = 1) then
3819
                    c1_tmp := '1';
3820
                    c1_got_first_rising_edge := false;
3821
                else
3822
                    c1_tmp := '0';
3823
                end if;
3824
            end if;
3825
        end if;
3826
 
3827
        if (enable0_counter = "c0") then
3828
            enable0_tmp <= c0_tmp;
3829
        elsif (enable0_counter = "c1") then
3830
            enable0_tmp <= c1_tmp;
3831
        else
3832
            enable0_tmp <= '0';
3833
        end if;
3834
 
3835
        if (enable1_counter = "c0") then
3836
            enable1_tmp <= c0_tmp;
3837
        elsif (enable1_counter = "c1") then
3838
            enable1_tmp <= c1_tmp;
3839
        else
3840
            enable1_tmp <= '0';
3841
        end if;
3842
 
3843
    end process;
3844
 
3845
    glocked_cntr : process(clkin, ena_ipd, areset_ipd)
3846
    variable count : integer := 0;
3847
    variable output : std_logic := '0';
3848
    begin
3849
        if (areset_ipd = '1') then
3850
            count := 0;
3851
            output := '0';
3852
        elsif (clkin'event and clkin = '1') then
3853
            if (ena_ipd = '1') then
3854
                count := count + 1;
3855
                if (sim_gate_lock_device_behavior = "on") then
3856
                    if (count = gate_lock_counter) then
3857
                        output := '1';
3858
                    end if;
3859
                elsif (count = GATE_LOCK_CYCLES) then
3860
                    output := '1';
3861
                end if;
3862
            end if;
3863
        end if;
3864
        gate_locked <= output;
3865
    end process;
3866
 
3867
    locked <=   gate_locked and lock when gate_lock_signal = "yes" else
3868
                lock;
3869
 
3870
 
3871
    process (scandone_tmp)
3872
    variable buf : line;
3873
    begin
3874
        if (scandone_tmp'event and scandone_tmp = '1') then
3875
            if (reconfig_err = false) then
3876
                ASSERT false REPORT family_name & " PLL Reprogramming completed with the following values (Values in parantheses indicate values before reprogramming) :" severity note;
3877
                write (buf, string'("    N modulus = "));
3878
                write (buf, n_val(0));
3879
                write (buf, string'(" ( "));
3880
                write (buf, n_val_old(0));
3881
                write (buf, string'(" )"));
3882
                writeline (output, buf);
3883
 
3884
                write (buf, string'("    M modulus = "));
3885
                write (buf, m_val(0));
3886
                write (buf, string'(" ( "));
3887
                write (buf, m_val_old(0));
3888
                write (buf, string'(" )"));
3889
                writeline (output, buf);
3890
 
3891
                write (buf, string'("    M ph_tap = "));
3892
                write (buf, m_ph_val);
3893
                write (buf, string'(" ( "));
3894
                write (buf, m_ph_val_old);
3895
                write (buf, string'(" )"));
3896
                writeline (output, buf);
3897
 
3898
                if (ss > 0) then
3899
                    write (buf, string'("    M2 modulus = "));
3900
                    write (buf, m_val(1));
3901
                    write (buf, string'(" ( "));
3902
                    write (buf, m_val_old(1));
3903
                    write (buf, string'(" )"));
3904
                    writeline (output, buf);
3905
 
3906
                    write (buf, string'("    N2 modulus = "));
3907
                    write (buf, n_val(1));
3908
                    write (buf, string'(" ( "));
3909
                    write (buf, n_val_old(1));
3910
                    write (buf, string'(" )"));
3911
                    writeline (output, buf);
3912
                end if;
3913
 
3914
                for i in 0 to (num_output_cntrs-1) loop
3915
                    write (buf, cntrs(i));
3916
                    write (buf, string'(" :   high = "));
3917
                    write (buf, c_high_val(i));
3918
                    write (buf, string'(" ("));
3919
                    write (buf, c_high_val_old(i));
3920
                    write (buf, string'(") "));
3921
                    write (buf, string'(" ,   low = "));
3922
                    write (buf, sig_c_low_val_tmp(i));
3923
                    write (buf, string'(" ("));
3924
                    write (buf, c_low_val_old(i));
3925
                    write (buf, string'(") "));
3926
                    write (buf, string'(" ,   mode = "));
3927
                    write (buf, c_mode_val(i));
3928
                    write (buf, string'(" ("));
3929
                    write (buf, c_mode_val_old(i));
3930
                    write (buf, string'(") "));
3931
                    write (buf, string'(" ,   phase tap = "));
3932
                    write (buf, c_ph_val(i));
3933
                    write (buf, string'(" ("));
3934
                    write (buf, c_ph_val_old(i));
3935
                    write (buf, string'(") "));
3936
                    writeline(output, buf);
3937
                end loop;
3938
 
3939
                write (buf, string'("    Charge Pump Current (uA) = "));
3940
                write (buf, cp_curr_val);
3941
                write (buf, string'(" ( "));
3942
                write (buf, cp_curr_old);
3943
                write (buf, string'(" ) "));
3944
                writeline (output, buf);
3945
 
3946
                write (buf, string'("    Loop Filter Capacitor (pF) = "));
3947
                write (buf, lfc_val);
3948
                write (buf, string'(" ( "));
3949
                write (buf, lfc_old);
3950
                write (buf, string'(" ) "));
3951
                writeline (output, buf);
3952
 
3953
                write (buf, string'("    Loop Filter Resistor (Kohm) = "));
3954
                write (buf, lfr_val);
3955
                write (buf, string'(" ( "));
3956
                write (buf, lfr_old);
3957
                write (buf, string'(" ) "));
3958
                writeline (output, buf);
3959
 
3960
            else ASSERT false REPORT "Errors were encountered during PLL reprogramming. Please refer to error/warning messages above." severity warning;
3961
            end if;
3962
        end if;
3963
    end process;
3964
 
3965
    process (scanwrite_enabled, c_clk(0), c_clk(1), c_clk(2), c_clk(3), c_clk(4), c_clk(5), vco_tap, fbclk, scanclk_ipd, gated_scanclk)
3966
    variable init : boolean := true;
3967
    variable low, high : std_logic_vector(7 downto 0);
3968
    variable low_fast, high_fast : std_logic_vector(3 downto 0);
3969
    variable mode : string(1 to 6) := "bypass";
3970
    variable is_error : boolean := false;
3971
    variable m_tmp, n_tmp : std_logic_vector(8 downto 0);
3972
    variable n_fast : std_logic_vector(1 downto 0);
3973
    variable c_high_val_tmp : int_array(0 to 5) := (OTHERS => 1);
3974
    variable c_low_val_tmp  : int_array(0 to 5) := (OTHERS => 1);
3975
    variable c_ph_val_tmp   : int_array(0 to 5) := (OTHERS => 0);
3976
    variable c_mode_val_tmp : str_array(0 to 5);
3977
    variable m_ph_val_tmp   : integer := 0;
3978
    variable m_val_tmp      : int_array(0 to 1) := (OTHERS => 1);
3979
    variable c0_rising_edge_transfer_done : boolean := false;
3980
    variable c1_rising_edge_transfer_done : boolean := false;
3981
    variable c2_rising_edge_transfer_done : boolean := false;
3982
    variable c3_rising_edge_transfer_done : boolean := false;
3983
    variable c4_rising_edge_transfer_done : boolean := false;
3984
    variable c5_rising_edge_transfer_done : boolean := false;
3985
 
3986
    -- variables for scaling of multiply_by and divide_by values
3987
    variable i_clk0_mult_by    : integer := 1;
3988
    variable i_clk0_div_by     : integer := 1;
3989
    variable i_clk1_mult_by    : integer := 1;
3990
    variable i_clk1_div_by     : integer := 1;
3991
    variable i_clk2_mult_by    : integer := 1;
3992
    variable i_clk2_div_by     : integer := 1;
3993
    variable i_clk3_mult_by    : integer := 1;
3994
    variable i_clk3_div_by     : integer := 1;
3995
    variable i_clk4_mult_by    : integer := 1;
3996
    variable i_clk4_div_by     : integer := 1;
3997
    variable i_clk5_mult_by    : integer := 1;
3998
    variable i_clk5_div_by     : integer := 1;
3999
    variable max_d_value       : integer := 1;
4000
    variable new_multiplier    : integer := 1;
4001
 
4002
    -- internal variables for storing the phase shift number.(used in lvds mode only)
4003
    variable i_clk0_phase_shift : integer := 1;
4004
    variable i_clk1_phase_shift : integer := 1;
4005
    variable i_clk2_phase_shift : integer := 1;
4006
 
4007
    -- user to advanced variables
4008
 
4009
    variable   max_neg_abs    : integer := 0;
4010
    variable   i_m_initial    : integer;
4011
    variable   i_m            : integer := 1;
4012
    variable   i_n            : integer := 1;
4013
    variable   i_m2           : integer;
4014
    variable   i_n2           : integer;
4015
    variable   i_ss           : integer;
4016
    variable   i_c_high       : int_array(0 to 5);
4017
    variable   i_c_low        : int_array(0 to 5);
4018
    variable   i_c_initial    : int_array(0 to 5);
4019
    variable   i_c_ph         : int_array(0 to 5);
4020
    variable   i_c_mode       : str_array(0 to 5);
4021
    variable   i_m_ph         : integer;
4022
    variable   output_count   : integer;
4023
    variable   new_divisor    : integer;
4024
 
4025
    variable clk0_cntr : string(1 to 2) := "c0";
4026
    variable clk1_cntr : string(1 to 2) := "c1";
4027
    variable clk2_cntr : string(1 to 2) := "c2";
4028
    variable clk3_cntr : string(1 to 2) := "c3";
4029
    variable clk4_cntr : string(1 to 2) := "c4";
4030
    variable clk5_cntr : string(1 to 2) := "c5";
4031
 
4032
    variable fbk_cntr : string(1 to 2);
4033
    variable fbk_cntr_index : integer;
4034
    variable start_bit : integer;
4035
    variable quiet_time : time := 0 ps;
4036
    variable slowest_clk_old : time := 0 ps;
4037
    variable slowest_clk_new : time := 0 ps;
4038
    variable tmp_scan_data : std_logic_vector(173 downto 0) := (OTHERS => '0');
4039
    variable m_lo, m_hi : std_logic_vector(4 downto 0);
4040
 
4041
    variable j : integer := 0;
4042
    variable scanread_active_edge : time := 0 ps;
4043
    variable got_first_scanclk : boolean := false;
4044
    variable got_first_gated_scanclk : boolean := false;
4045
    variable scanclk_last_rising_edge : time := 0 ps;
4046
    variable scanclk_period : time := 0 ps;
4047
    variable current_scan_data : std_logic_vector(173 downto 0) := (OTHERS => '0');
4048
    variable index : integer := 0;
4049
    variable Tviol_scandata_scanclk : std_ulogic := '0';
4050
    variable Tviol_scanread_scanclk : std_ulogic := '0';
4051
    variable Tviol_scanwrite_scanclk : std_ulogic := '0';
4052
    variable TimingData_scandata_scanclk : VitalTimingDataType := VitalTimingDataInit;
4053
    variable TimingData_scanread_scanclk : VitalTimingDataType := VitalTimingDataInit;
4054
    variable TimingData_scanwrite_scanclk : VitalTimingDataType := VitalTimingDataInit;
4055
    variable scan_chain_length : integer := GPP_SCAN_CHAIN;
4056
    variable tmp_rem : integer := 0;
4057
    variable scanclk_cycles : integer := 0;
4058
    variable lfc_tmp : std_logic_vector(1 downto 0);
4059
    variable lfr_tmp : std_logic_vector(5 downto 0);
4060
    variable lfr_int : integer := 0;
4061
 
4062
    function slowest_clk (
4063
            C0 : integer; C0_mode : string(1 to 6);
4064
            C1 : integer; C1_mode : string(1 to 6);
4065
            C2 : integer; C2_mode : string(1 to 6);
4066
            C3 : integer; C3_mode : string(1 to 6);
4067
            C4 : integer; C4_mode : string(1 to 6);
4068
            C5 : integer; C5_mode : string(1 to 6);
4069
            refclk : time; m_mod : integer) return time is
4070
    variable max_modulus : integer := 1;
4071
    variable q_period : time := 0 ps;
4072
    variable refclk_int : integer := 0;
4073
    begin
4074
        if (C0_mode /= "bypass" and C0_mode /= "   off") then
4075
            max_modulus := C0;
4076
        end if;
4077
        if (C1 > max_modulus and C1_mode /= "bypass" and C1_mode /= "   off") then
4078
            max_modulus := C1;
4079
        end if;
4080
        if (C2 > max_modulus and C2_mode /= "bypass" and C2_mode /= "   off") then
4081
            max_modulus := C2;
4082
        end if;
4083
        if (C3 > max_modulus and C3_mode /= "bypass" and C3_mode /= "   off") then
4084
            max_modulus := C3;
4085
        end if;
4086
        if (C4 > max_modulus and C4_mode /= "bypass" and C4_mode /= "   off") then
4087
            max_modulus := C4;
4088
        end if;
4089
        if (C5 > max_modulus and C5_mode /= "bypass" and C5_mode /= "   off") then
4090
            max_modulus := C5;
4091
        end if;
4092
 
4093
        refclk_int := refclk / 1 ps;
4094
        if (m_mod /= 0) then
4095
            if (refclk_int > (refclk_int * max_modulus / m_mod)) then
4096
                q_period := refclk_int * 1 ps;
4097
            else
4098
                q_period := (refclk_int * max_modulus / m_mod) * 1 ps;
4099
            end if;
4100
        end if;
4101
        return (2*q_period);
4102
    end slowest_clk;
4103
 
4104
    function int2bin (arg : integer; size : integer) return std_logic_vector is
4105
    variable int_val : integer := arg;
4106
    variable result : std_logic_vector(size-1 downto 0);
4107
    begin
4108
        for i in 0 to result'left loop
4109
            if ((int_val mod 2) = 0) then
4110
                result(i) := '0';
4111
            else
4112
                result(i) := '1';
4113
            end if;
4114
            int_val := int_val/2;
4115
        end loop;
4116
        return result;
4117
    end int2bin;
4118
 
4119
    function extract_cntr_index (arg:string) return integer is
4120
    variable index : integer := 0;
4121
    begin
4122
        if (arg(2) = '0') then
4123
            index := 0;
4124
        elsif (arg(2) = '1') then
4125
            index := 1;
4126
        elsif (arg(2) = '2') then
4127
            index := 2;
4128
        elsif (arg(2) = '3') then
4129
            index := 3;
4130
        elsif (arg(2) = '4') then
4131
            index := 4;
4132
        else index := 5;
4133
        end if;
4134
 
4135
        return index;
4136
    end extract_cntr_index;
4137
 
4138
    begin
4139
        if (init) then
4140
            if (m = 0) then
4141
                clk5_cntr  := "c5";
4142
                clk4_cntr  := "c4";
4143
                clk3_cntr  := "c3";
4144
                clk2_cntr  := "c2";
4145
                clk1_cntr  := "c1";
4146
                clk0_cntr  := "c0";
4147
            else
4148
                clk5_cntr  := clk5_counter;
4149
                clk4_cntr  := clk4_counter;
4150
                clk3_cntr  := clk3_counter;
4151
                clk2_cntr  := clk2_counter;
4152
                clk1_cntr  := clk1_counter;
4153
                clk0_cntr  := clk0_counter;
4154
            end if;
4155
 
4156
            if (operation_mode = "external_feedback") then
4157
                if (feedback_source = "clk0") then
4158
                    fbk_cntr := clk0_cntr;
4159
                elsif (feedback_source = "clk1") then
4160
                    fbk_cntr := clk1_cntr;
4161
                elsif (feedback_source = "clk2") then
4162
                    fbk_cntr := clk2_cntr;
4163
                elsif (feedback_source = "clk3") then
4164
                    fbk_cntr := clk3_cntr;
4165
                elsif (feedback_source = "clk4") then
4166
                    fbk_cntr := clk4_cntr;
4167
                elsif (feedback_source = "clk5") then
4168
                    fbk_cntr := clk5_cntr;
4169
                else
4170
                    fbk_cntr := "c0";
4171
                end if;
4172
 
4173
                if (fbk_cntr = "c0") then
4174
                    fbk_cntr_index := 0;
4175
                elsif (fbk_cntr = "c1") then
4176
                    fbk_cntr_index := 1;
4177
                elsif (fbk_cntr = "c2") then
4178
                    fbk_cntr_index := 2;
4179
                elsif (fbk_cntr = "c3") then
4180
                    fbk_cntr_index := 3;
4181
                elsif (fbk_cntr = "c4") then
4182
                    fbk_cntr_index := 4;
4183
                elsif (fbk_cntr = "c5") then
4184
                    fbk_cntr_index := 5;
4185
                end if;
4186
 
4187
                ext_fbk_cntr <= fbk_cntr;
4188
                ext_fbk_cntr_index <= fbk_cntr_index;
4189
            end if;
4190
            i_clk0_counter <= extract_cntr_index(clk0_cntr);
4191
            i_clk1_counter <= extract_cntr_index(clk1_cntr);
4192
            i_clk2_counter <= extract_cntr_index(clk2_cntr);
4193
            i_clk3_counter <= extract_cntr_index(clk3_cntr);
4194
            i_clk4_counter <= extract_cntr_index(clk4_cntr);
4195
            i_clk5_counter <= extract_cntr_index(clk5_cntr);
4196
 
4197
 
4198
            if (m = 0) then  -- convert user parameters to advanced
4199
                -- set the limit of the divide_by value that can be returned by
4200
                -- the following function.
4201
                max_d_value := 500;
4202
 
4203
                -- scale down the multiply_by and divide_by values provided by the design
4204
                -- before attempting to use them in the calculations below
4205
                find_simple_integer_fraction(clk0_multiply_by, clk0_divide_by,
4206
                                max_d_value, i_clk0_mult_by, i_clk0_div_by);
4207
                find_simple_integer_fraction(clk1_multiply_by, clk1_divide_by,
4208
                                max_d_value, i_clk1_mult_by, i_clk1_div_by);
4209
                find_simple_integer_fraction(clk2_multiply_by, clk2_divide_by,
4210
                                max_d_value, i_clk2_mult_by, i_clk2_div_by);
4211
                find_simple_integer_fraction(clk3_multiply_by, clk3_divide_by,
4212
                                max_d_value, i_clk3_mult_by, i_clk3_div_by);
4213
                find_simple_integer_fraction(clk4_multiply_by, clk4_divide_by,
4214
                                max_d_value, i_clk4_mult_by, i_clk4_div_by);
4215
                find_simple_integer_fraction(clk5_multiply_by, clk5_divide_by,
4216
                                max_d_value, i_clk5_mult_by, i_clk5_div_by);
4217
 
4218
                if (((pll_type = "fast") or (pll_type = "lvds")) and ((vco_multiply_by /= 0) and (vco_divide_by /= 0))) then
4219
                    i_n := vco_divide_by;
4220
                    i_m := vco_multiply_by;
4221
                else
4222
                    i_n := 1;
4223
                    i_m := lcm (i_clk0_mult_by, i_clk1_mult_by,
4224
                                i_clk2_mult_by, i_clk3_mult_by,
4225
                                i_clk4_mult_by, i_clk5_mult_by,
4226
                                1, 1, 1, 1, inclk0_input_frequency);
4227
                end if;
4228
 
4229
                if (pll_type = "flvds") then
4230
                    -- Need to readjust phase shift values when the clock multiply value has been readjusted.
4231
                    new_multiplier := clk0_multiply_by / i_clk0_mult_by;
4232
                    i_clk0_phase_shift := str2int(clk0_phase_shift) * new_multiplier;
4233
                    i_clk1_phase_shift := str2int(clk1_phase_shift) * new_multiplier;
4234
                    i_clk2_phase_shift := str2int(clk2_phase_shift) * new_multiplier;
4235
                else
4236
                    i_clk0_phase_shift := str2int(clk0_phase_shift);
4237
                    i_clk1_phase_shift := str2int(clk1_phase_shift);
4238
                    i_clk2_phase_shift := str2int(clk2_phase_shift);
4239
                end if;
4240
 
4241
                max_neg_abs := maxnegabs(i_clk0_phase_shift,
4242
                                        i_clk1_phase_shift,
4243
                                        i_clk2_phase_shift,
4244
                                        str2int(clk3_phase_shift),
4245
                                        str2int(clk4_phase_shift),
4246
                                        str2int(clk5_phase_shift),
4247
                                        0, 0, 0, 0);
4248
                i_m_ph  := counter_ph(get_phase_degree(max_neg_abs,inclk0_input_frequency), i_m, i_n);
4249
 
4250
                i_c_ph(0) := counter_ph(get_phase_degree(ph_adjust(i_clk0_phase_shift,max_neg_abs),inclk0_input_frequency), i_m, i_n);
4251
                i_c_ph(1) := counter_ph(get_phase_degree(ph_adjust(i_clk1_phase_shift,max_neg_abs),inclk0_input_frequency), i_m, i_n);
4252
                i_c_ph(2) := counter_ph(get_phase_degree(ph_adjust(i_clk2_phase_shift,max_neg_abs),inclk0_input_frequency), i_m, i_n);
4253
                i_c_ph(3) := counter_ph(get_phase_degree(ph_adjust(str2int(clk3_phase_shift),max_neg_abs),inclk0_input_frequency), i_m, i_n);
4254
                i_c_ph(4) := counter_ph(get_phase_degree(ph_adjust(str2int(clk4_phase_shift),max_neg_abs),inclk0_input_frequency), i_m, i_n);
4255
                i_c_ph(5) := counter_ph(get_phase_degree(ph_adjust(str2int(clk5_phase_shift),max_neg_abs),inclk0_input_frequency), i_m, i_n);
4256
                i_c_high(0) := counter_high(output_counter_value(i_clk0_div_by,
4257
                                i_clk0_mult_by, i_m, i_n), clk0_duty_cycle);
4258
                i_c_high(1) := counter_high(output_counter_value(i_clk1_div_by,
4259
                                i_clk1_mult_by, i_m, i_n), clk1_duty_cycle);
4260
                i_c_high(2) := counter_high(output_counter_value(i_clk2_div_by,
4261
                                i_clk2_mult_by, i_m, i_n), clk2_duty_cycle);
4262
                i_c_high(3) := counter_high(output_counter_value(i_clk3_div_by,
4263
                                i_clk3_mult_by, i_m, i_n), clk3_duty_cycle);
4264
                i_c_high(4) := counter_high(output_counter_value(i_clk4_div_by,
4265
                                i_clk4_mult_by,  i_m, i_n), clk4_duty_cycle);
4266
                i_c_high(5) := counter_high(output_counter_value(i_clk5_div_by,
4267
                                i_clk5_mult_by,  i_m, i_n), clk5_duty_cycle);
4268
                i_c_low(0)  := counter_low(output_counter_value(i_clk0_div_by,
4269
                                i_clk0_mult_by,  i_m, i_n), clk0_duty_cycle);
4270
                i_c_low(1)  := counter_low(output_counter_value(i_clk1_div_by,
4271
                                i_clk1_mult_by,  i_m, i_n), clk1_duty_cycle);
4272
                i_c_low(2)  := counter_low(output_counter_value(i_clk2_div_by,
4273
                                i_clk2_mult_by,  i_m, i_n), clk2_duty_cycle);
4274
                i_c_low(3)  := counter_low(output_counter_value(i_clk3_div_by,
4275
                                i_clk3_mult_by,  i_m, i_n), clk3_duty_cycle);
4276
                i_c_low(4)  := counter_low(output_counter_value(i_clk4_div_by,
4277
                                i_clk4_mult_by,  i_m, i_n), clk4_duty_cycle);
4278
                i_c_low(5)  := counter_low(output_counter_value(i_clk5_div_by,
4279
                                i_clk5_mult_by,  i_m, i_n), clk5_duty_cycle);
4280
                i_m_initial  := counter_initial(get_phase_degree(max_neg_abs, inclk0_input_frequency), i_m,i_n);
4281
 
4282
                i_c_initial(0) := counter_initial(get_phase_degree(ph_adjust(i_clk0_phase_shift, max_neg_abs), inclk0_input_frequency), i_m, i_n);
4283
                i_c_initial(1) := counter_initial(get_phase_degree(ph_adjust(i_clk1_phase_shift, max_neg_abs), inclk0_input_frequency), i_m, i_n);
4284
                i_c_initial(2) := counter_initial(get_phase_degree(ph_adjust(i_clk2_phase_shift, max_neg_abs), inclk0_input_frequency), i_m, i_n);
4285
                i_c_initial(3) := counter_initial(get_phase_degree(ph_adjust(str2int(clk3_phase_shift), max_neg_abs), inclk0_input_frequency), i_m, i_n);
4286
                i_c_initial(4) := counter_initial(get_phase_degree(ph_adjust(str2int(clk4_phase_shift), max_neg_abs), inclk0_input_frequency), i_m, i_n);
4287
                i_c_initial(5) := counter_initial(get_phase_degree(ph_adjust(str2int(clk5_phase_shift), max_neg_abs), inclk0_input_frequency), i_m, i_n);
4288
                i_c_mode(0) := counter_mode(clk0_duty_cycle, output_counter_value(i_clk0_div_by, i_clk0_mult_by,  i_m, i_n));
4289
                i_c_mode(1) := counter_mode(clk1_duty_cycle, output_counter_value(i_clk1_div_by, i_clk1_mult_by,  i_m, i_n));
4290
                i_c_mode(2) := counter_mode(clk2_duty_cycle, output_counter_value(i_clk2_div_by, i_clk2_mult_by,  i_m, i_n));
4291
                i_c_mode(3) := counter_mode(clk3_duty_cycle, output_counter_value(i_clk3_div_by, i_clk3_mult_by,  i_m, i_n));
4292
                i_c_mode(4) := counter_mode(clk4_duty_cycle, output_counter_value(i_clk4_div_by, i_clk4_mult_by,  i_m, i_n));
4293
                i_c_mode(5) := counter_mode(clk5_duty_cycle, output_counter_value(i_clk5_div_by, i_clk5_mult_by,  i_m, i_n));
4294
 
4295
                -- in external feedback mode, need to adjust M value to take
4296
                -- into consideration the external feedback counter value
4297
                if(operation_mode = "external_feedback") then
4298
                    -- if there is a negative phase shift, m_initial can
4299
                    -- only be 1
4300
                    if (max_neg_abs > 0) then
4301
                        i_m_initial := 1;
4302
                    end if;
4303
 
4304
                    -- calculate the feedback counter multiplier
4305
                    if (i_c_mode(fbk_cntr_index) = "bypass") then
4306
                        output_count := 1;
4307
                    else
4308
                        output_count := i_c_high(fbk_cntr_index) + i_c_low(fbk_cntr_index);
4309
                    end if;
4310
 
4311
                    new_divisor := gcd(i_m, output_count);
4312
                    i_m := i_m / new_divisor;
4313
                    i_n := output_count / new_divisor;
4314
                end if;
4315
 
4316
            else -- m /= 0
4317
 
4318
                i_n             := n;
4319
                i_m             := m;
4320
                i_m_initial     := m_initial;
4321
                i_m_ph          := m_ph;
4322
                i_c_ph(0)         := c0_ph;
4323
                i_c_ph(1)         := c1_ph;
4324
                i_c_ph(2)         := c2_ph;
4325
                i_c_ph(3)         := c3_ph;
4326
                i_c_ph(4)         := c4_ph;
4327
                i_c_ph(5)         := c5_ph;
4328
                i_c_high(0)       := c0_high;
4329
                i_c_high(1)       := c1_high;
4330
                i_c_high(2)       := c2_high;
4331
                i_c_high(3)       := c3_high;
4332
                i_c_high(4)       := c4_high;
4333
                i_c_high(5)       := c5_high;
4334
                i_c_low(0)        := c0_low;
4335
                i_c_low(1)        := c1_low;
4336
                i_c_low(2)        := c2_low;
4337
                i_c_low(3)        := c3_low;
4338
                i_c_low(4)        := c4_low;
4339
                i_c_low(5)        := c5_low;
4340
                i_c_initial(0)    := c0_initial;
4341
                i_c_initial(1)    := c1_initial;
4342
                i_c_initial(2)    := c2_initial;
4343
                i_c_initial(3)    := c3_initial;
4344
                i_c_initial(4)    := c4_initial;
4345
                i_c_initial(5)    := c5_initial;
4346
                i_c_mode(0)       := translate_string(c0_mode);
4347
                i_c_mode(1)       := translate_string(c1_mode);
4348
                i_c_mode(2)       := translate_string(c2_mode);
4349
                i_c_mode(3)       := translate_string(c3_mode);
4350
                i_c_mode(4)       := translate_string(c4_mode);
4351
                i_c_mode(5)       := translate_string(c5_mode);
4352
 
4353
            end if; -- user to advanced conversion.
4354
 
4355
            m_initial_val <= i_m_initial;
4356
            n_val(0) <= i_n;
4357
            m_val(0) <= i_m;
4358
            m_val(1) <= m2;
4359
            n_val(1) <= n2;
4360
 
4361
            if (i_m = 1) then
4362
                m_mode_val(0) <= "bypass";
4363
            else
4364
                m_mode_val(0) <= "      ";
4365
            end if;
4366
            if (m2 = 1) then
4367
                m_mode_val(1) <= "bypass";
4368
            end if;
4369
            if (i_n = 1) then
4370
                n_mode_val(0) <= "bypass";
4371
            end if;
4372
            if (n2 = 1) then
4373
                n_mode_val(1) <= "bypass";
4374
            end if;
4375
 
4376
            m_ph_val  <= i_m_ph;
4377
            m_ph_val_tmp := i_m_ph;
4378
            m_val_tmp := m_val;
4379
 
4380
            for i in 0 to 5 loop
4381
                if (i_c_mode(i) = "bypass") then
4382
                    if (pll_type = "fast" or pll_type = "lvds") then
4383
                        i_c_high(i) := 16;
4384
                        i_c_low(i) := 16;
4385
                    else
4386
                        i_c_high(i) := 256;
4387
                        i_c_low(i) := 256;
4388
                    end if;
4389
                end if;
4390
                c_ph_val(i)         <= i_c_ph(i);
4391
                c_initial_val(i)    <= i_c_initial(i);
4392
                c_high_val(i)       <= i_c_high(i);
4393
                c_low_val(i)        <= i_c_low(i);
4394
                c_mode_val(i)       <= i_c_mode(i);
4395
                c_high_val_tmp(i)   := i_c_high(i);
4396
                c_low_val_tmp(i)    := i_c_low(i);
4397
                c_mode_val_tmp(i)   := i_c_mode(i);
4398
                c_ph_val_tmp(i)     := i_c_ph(i);
4399
                c_ph_val_orig(i)    <= i_c_ph(i);
4400
                c_high_val_hold(i)  <= i_c_high(i);
4401
                c_low_val_hold(i)   <= i_c_low(i);
4402
                c_mode_val_hold(i)  <= i_c_mode(i);
4403
            end loop;
4404
 
4405
            lfc_val <= loop_filter_c;
4406
            lfr_val <= loop_filter_r;
4407
            cp_curr_val <= charge_pump_current;
4408
 
4409
            if (pll_type = "fast") then
4410
                scan_chain_length := FAST_SCAN_CHAIN;
4411
            end if;
4412
            -- initialize the scan_chain contents
4413
            -- CP/LF bits
4414
            scan_data(11 downto 0) <= "000000000000";
4415
            for i in 0 to 3 loop
4416
                if (pll_type = "fast" or pll_type = "lvds") then
4417
                    if (fpll_loop_filter_c_arr(i) = loop_filter_c) then
4418
                        scan_data(11 downto 10) <= int2bin(i, 2);
4419
                    end if;
4420
                else
4421
                    if (loop_filter_c_arr(i) = loop_filter_c) then
4422
                        scan_data(11 downto 10) <= int2bin(i, 2);
4423
                    end if;
4424
                end if;
4425
            end loop;
4426
            for i in 0 to 15 loop
4427
                if (charge_pump_curr_arr(i) = charge_pump_current) then
4428
                    scan_data(3 downto 0) <= int2bin(i, 4);
4429
                end if;
4430
            end loop;
4431
            for i in 0 to 39 loop
4432
                if (loop_filter_r_arr(i) = loop_filter_r) then
4433
                    if (i >= 16 and i <= 23) then
4434
                        scan_data(9 downto 4) <= int2bin((i+8), 6);
4435
                    elsif (i >= 24 and i <= 31) then
4436
                        scan_data(9 downto 4) <= int2bin((i+16), 6);
4437
                    elsif (i >= 32) then
4438
                        scan_data(9 downto 4) <= int2bin((i+24), 6);
4439
                    else
4440
                        scan_data(9 downto 4) <= int2bin(i, 6);
4441
                    end if;
4442
                end if;
4443
            end loop;
4444
 
4445
            if (pll_type = "fast" or pll_type = "lvds") then
4446
                scan_data(21 downto 12) <= "0000000000"; -- M, C3-C0 ph
4447
                -- C0-C3 high
4448
                scan_data(25 downto 22) <= int2bin(i_c_high(0), 4);
4449
                scan_data(35 downto 32) <= int2bin(i_c_high(1), 4);
4450
                scan_data(45 downto 42) <= int2bin(i_c_high(2), 4);
4451
                scan_data(55 downto 52) <= int2bin(i_c_high(3), 4);
4452
                -- C0-C3 low
4453
                scan_data(30 downto 27) <= int2bin(i_c_low(0), 4);
4454
                scan_data(40 downto 37) <= int2bin(i_c_low(1), 4);
4455
                scan_data(50 downto 47) <= int2bin(i_c_low(2), 4);
4456
                scan_data(60 downto 57) <= int2bin(i_c_low(3), 4);
4457
                -- C0-C3 mode
4458
                for i in 0 to 3 loop
4459
                    if (i_c_mode(i) = "   off" or i_c_mode(i) = "bypass") then
4460
                        scan_data(26 + (10*i)) <= '1';
4461
                        if (i_c_mode(i) = "   off") then
4462
                            scan_data(31 + (10*i)) <= '1';
4463
                        else
4464
                            scan_data(31 + (10*i)) <= '0';
4465
                        end if;
4466
                    else
4467
                        scan_data(26 + (10*i)) <= '0';
4468
                        if (i_c_mode(i) = "   odd") then
4469
                            scan_data(31 + (10*i)) <= '1';
4470
                        else
4471
                            scan_data(31 + (10*i)) <= '0';
4472
                        end if;
4473
                    end if;
4474
                end loop;
4475
                -- M
4476
                if (i_m = 1) then
4477
                    scan_data(66) <= '1';
4478
                    scan_data(71) <= '0';
4479
                    scan_data(65 downto 62) <= "0000";
4480
                    scan_data(70 downto 67) <= "0000";
4481
                else
4482
                    scan_data(66) <= '0';       -- set BYPASS bit to 0
4483
                    scan_data(70 downto 67) <= int2bin(i_m/2, 4);   -- set M low
4484
                    if (i_m rem 2 = 0) then
4485
                        -- M is an even no. : set M high = low,
4486
                        -- set odd/even bit to 0
4487
                        scan_data(65 downto 62) <= int2bin(i_m/2, 4);
4488
                        scan_data(71) <= '0';
4489
                    else       -- M is odd : M high = low + 1
4490
                        scan_data(65 downto 62) <= int2bin((i_m/2) + 1, 4);
4491
                        scan_data(71) <= '1';
4492
                    end if;
4493
                end if;
4494
                -- N
4495
                scan_data(73 downto 72) <= int2bin(i_n, 2);
4496
                if (i_n = 1) then
4497
                    scan_data(74) <= '1';
4498
                    scan_data(73 downto 72) <= "00";
4499
                end if;
4500
            else          -- PLL type is auto or enhanced
4501
                scan_data(25 downto 12) <= "00000000000000"; -- M, C5-C0 ph
4502
                -- C0-C5 high
4503
                scan_data(123 downto 116) <= int2bin(i_c_high(0), 8);
4504
                scan_data(105 downto 98) <= int2bin(i_c_high(1), 8);
4505
                scan_data(87 downto 80) <= int2bin(i_c_high(2), 8);
4506
                scan_data(69 downto 62) <= int2bin(i_c_high(3), 8);
4507
                scan_data(51 downto 44) <= int2bin(i_c_high(4), 8);
4508
                scan_data(33 downto 26) <= int2bin(i_c_high(5), 8);
4509
                -- C0-C5 low
4510
                scan_data(132 downto 125) <= int2bin(i_c_low(0), 8);
4511
                scan_data(114 downto 107) <= int2bin(i_c_low(1), 8);
4512
                scan_data(96 downto 89) <= int2bin(i_c_low(2), 8);
4513
                scan_data(78 downto 71) <= int2bin(i_c_low(3), 8);
4514
                scan_data(60 downto 53) <= int2bin(i_c_low(4), 8);
4515
                scan_data(42 downto 35) <= int2bin(i_c_low(5), 8);
4516
                -- C0-C5 mode
4517
                for i in 0 to 5 loop
4518
                    if (i_c_mode(i) = "   off" or i_c_mode(i) = "bypass") then
4519
                        scan_data(124 - (18*i)) <= '1';
4520
                        if (i_c_mode(i) = "   off") then
4521
                            scan_data(133 - (18*i)) <= '1';
4522
                        else
4523
                            scan_data(133 - (18*i)) <= '0';
4524
                        end if;
4525
                    else
4526
                        scan_data(124 - (18*i)) <= '0';
4527
                        if (i_c_mode(i) = "   odd") then
4528
                            scan_data(133 - (18*i)) <= '1';
4529
                        else
4530
                            scan_data(133 - (18*i)) <= '0';
4531
                        end if;
4532
                    end if;
4533
                end loop;
4534
 
4535
                -- M/M2
4536
                scan_data(142 downto 134) <= int2bin(i_m, 9);
4537
                scan_data(143) <= '0';
4538
                scan_data(152 downto 144) <= int2bin(m2, 9);
4539
                scan_data(153) <= '0';
4540
                if (i_m = 1) then
4541
                    scan_data(143) <= '1';
4542
                    scan_data(142 downto 134) <= "000000000";
4543
                end if;
4544
                if (m2 = 1) then
4545
                    scan_data(153) <= '1';
4546
                    scan_data(152 downto 144) <= "000000000";
4547
                end if;
4548
 
4549
                -- N/N2
4550
                scan_data(162 downto 154) <= int2bin(i_n, 9);
4551
                scan_data(172 downto 164) <= int2bin(n2, 9);
4552
                if (i_n = 1) then
4553
                    scan_data(163) <= '1';
4554
                    scan_data(162 downto 154) <= "000000000";
4555
                end if;
4556
                if (n2 = 1) then
4557
                    scan_data(173) <= '1';
4558
                    scan_data(172 downto 164) <= "000000000";
4559
                end if;
4560
 
4561
            end if;
4562
            if (pll_type = "fast" or pll_type = "lvds") then
4563
                num_output_cntrs <= 4;
4564
            else
4565
                num_output_cntrs <= 6;
4566
            end if;
4567
 
4568
            init := false;
4569
        elsif (scanwrite_enabled'event and scanwrite_enabled = '0') then
4570
            -- falling edge : deassert scandone
4571
            scandone_tmp <= transport '0' after (1.5 * scanclk_period);
4572
            c0_rising_edge_transfer_done := false;
4573
            c1_rising_edge_transfer_done := false;
4574
            c2_rising_edge_transfer_done := false;
4575
            c3_rising_edge_transfer_done := false;
4576
            c4_rising_edge_transfer_done := false;
4577
            c5_rising_edge_transfer_done := false;
4578
        elsif (scanwrite_enabled'event and scanwrite_enabled = '1') then
4579
            ASSERT false REPORT "PLL Reprogramming Initiated" severity note;
4580
 
4581
            reconfig_err <= false;
4582
 
4583
            -- make temporary copy of scan_data for processing
4584
            tmp_scan_data := scan_data;
4585
 
4586
            -- save old values
4587
            lfc_old <= lfc_val;
4588
            lfr_old <= lfr_val;
4589
            cp_curr_old <= cp_curr_val;
4590
 
4591
            -- CP
4592
            -- Bits 0-3 : all values are legal
4593
            cp_curr_val <= charge_pump_curr_arr(alt_conv_integer(scan_data(3 downto 0)));
4594
 
4595
            -- LF Resistance : bits 4-9
4596
            -- values from 010000 - 010111, 100000 - 100111,
4597
            --             110000 - 110111 are illegal
4598
            lfr_tmp := tmp_scan_data(9 downto 4);
4599
            lfr_int := alt_conv_integer(lfr_tmp);
4600
            if (((lfr_int >= 16) and (lfr_int <= 23)) or
4601
                ((lfr_int >= 32) and (lfr_int <= 39)) or
4602
                ((lfr_int >= 48) and (lfr_int <= 55))) then
4603
                reconfig_err <= true;
4604
                ASSERT false REPORT "Illegal bit settings for Loop Filter Resistance. Legal bit values range from 000000-001111, 011000-011111, 101000-101111 and 111000-111111. Reconfiguration may not work." severity warning;
4605
            else
4606
                if (lfr_int >= 56) then
4607
                    lfr_int := lfr_int - 24;
4608
                elsif ((lfr_int >= 40) and (lfr_int <= 47)) then
4609
                    lfr_int := lfr_int - 16;
4610
                elsif ((lfr_int >= 24) and (lfr_int <= 31)) then
4611
                    lfr_int := lfr_int - 8;
4612
                end if;
4613
                lfr_val <= loop_filter_r_arr(lfr_int);
4614
            end if;
4615
 
4616
            -- LF Capacitance : bits 10,11 : all values are legal
4617
            lfc_tmp := scan_data(11 downto 10);
4618
            if (pll_type = "fast" or pll_type = "lvds") then
4619
                lfc_val <= fpll_loop_filter_c_arr(alt_conv_integer(lfc_tmp));
4620
            else
4621
                lfc_val <= loop_filter_c_arr(alt_conv_integer(lfc_tmp));
4622
            end if;
4623
 
4624
            -- cntrs c0-c5
4625
            -- save old values for display info.
4626
            m_val_old <= m_val;
4627
            n_val_old <= n_val;
4628
            m_mode_val_old <= m_mode_val;
4629
            n_mode_val_old <= n_mode_val;
4630
            m_ph_val_old <= m_ph_val;
4631
            c_high_val_old <= c_high_val;
4632
            c_low_val_old <= c_low_val;
4633
            c_ph_val_old <= c_ph_val;
4634
            c_mode_val_old <= c_mode_val;
4635
 
4636
            -- first the M counter phase : bit order same for fast and GPP
4637
            if (scan_data(12) = '0') then
4638
                -- do nothing
4639
            elsif (scan_data(12) = '1' and scan_data(13) = '1') then
4640
                m_ph_val_tmp := m_ph_val_tmp + 1;
4641
                if (m_ph_val_tmp > 7) then
4642
                    m_ph_val_tmp := 0;
4643
                end if;
4644
            elsif (scan_data(12) = '1' and scan_data(13) = '0') then
4645
                m_ph_val_tmp := m_ph_val_tmp - 1;
4646
                if (m_ph_val_tmp < 0) then
4647
                    m_ph_val_tmp := 7;
4648
                end if;
4649
            else
4650
                reconfig_err <= true;
4651
                ASSERT false REPORT "Illegal values for M counter phase tap. Reconfiguration may not work." severity warning;
4652
            end if;
4653
 
4654
            -- read the fast PLL bits
4655
            if (pll_type = "fast" or pll_type = "lvds") then
4656
                -- C3-C0 phase bits
4657
                for i in 3 downto 0 loop
4658
                    start_bit := 14 + ((3-i)*2);
4659
                    if (tmp_scan_data(start_bit) = '0') then
4660
                        -- do nothing
4661
                    elsif (tmp_scan_data(start_bit) = '1') then
4662
                        if (tmp_scan_data(start_bit + 1) = '1') then
4663
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) + 1;
4664
                            if (c_ph_val_tmp(i) > 7) then
4665
                                c_ph_val_tmp(i) := 0;
4666
                            end if;
4667
                        elsif (tmp_scan_data(start_bit + 1) = '0') then
4668
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) - 1;
4669
                            if (c_ph_val_tmp(i) < 0) then
4670
                                c_ph_val_tmp(i) := 7;
4671
                            end if;
4672
                        end if;
4673
                    end if;
4674
                end loop;
4675
                -- C0-C3 counter moduli
4676
                for i in 0 to 3 loop
4677
                    start_bit := 22 + (i*10);
4678
                    if (tmp_scan_data(start_bit + 4) = '1') then
4679
                        c_mode_val_tmp(i) := "bypass";
4680
                        if (tmp_scan_data(start_bit + 9) = '1') then
4681
                            c_mode_val_tmp(i) := "   off";
4682
                            ASSERT false REPORT "The specified bit settings will turn OFF the " &cntrs(i)& "counter. It cannot be turned on unless the part is re-initialized." severity warning;
4683
                        end if;
4684
                    elsif (tmp_scan_data(start_bit + 9) = '1') then
4685
                        c_mode_val_tmp(i) := "   odd";
4686
                    else
4687
                        c_mode_val_tmp(i) := "  even";
4688
                    end if;
4689
                    high_fast := tmp_scan_data(start_bit+3 downto start_bit);
4690
                    low_fast := tmp_scan_data(start_bit+8 downto start_bit+5);
4691
                    if (tmp_scan_data(start_bit+3 downto start_bit) = "0000") then
4692
                        c_high_val_tmp(i) := 16;
4693
                    else
4694
                        c_high_val_tmp(i) := alt_conv_integer(high_fast);
4695
                    end if;
4696
                    if (tmp_scan_data(start_bit+8 downto start_bit+5) = "0000") then
4697
                        c_low_val_tmp(i) := 16;
4698
                    else
4699
                        c_low_val_tmp(i) := alt_conv_integer(low_fast);
4700
                    end if;
4701
                end loop;
4702
                sig_c_ph_val_tmp <= c_ph_val_tmp;
4703
                sig_c_low_val_tmp <= c_low_val_tmp;
4704
                sig_c_hi_val_tmp <= c_high_val_tmp;
4705
                -- M
4706
                -- some temporary storage
4707
                if (tmp_scan_data(65 downto 62) = "0000") then
4708
                    m_hi := "10000";
4709
                else
4710
                    m_hi := "0" & tmp_scan_data(65 downto 62);
4711
                end if;
4712
                if (tmp_scan_data(70 downto 67) = "0000") then
4713
                    m_lo := "10000";
4714
                else
4715
                    m_lo := "0" & tmp_scan_data(70 downto 67);
4716
                end if;
4717
                m_val_tmp(0) := alt_conv_integer(m_hi) + alt_conv_integer(m_lo);
4718
                if (tmp_scan_data(66) = '1') then
4719
                    if (tmp_scan_data(71) = '1') then
4720
                        -- this will turn off the M counter : error
4721
                        reconfig_err <= true;
4722
                        is_error := true;
4723
                        ASSERT false REPORT "The specified bit settings will turn OFF the M counter. This is illegal. Reconfiguration may not work." severity warning;
4724
                    else -- M counter is being bypassed
4725
                        if (m_mode_val(0) /= "bypass") then
4726
                            -- mode is switched : give warning
4727
                            ASSERT false REPORT "M counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
4728
                        end if;
4729
                        m_val_tmp(0) := 1;
4730
                        m_mode_val(0) <= "bypass";
4731
                    end if;
4732
                else
4733
                    if (m_mode_val(0) = "bypass") then
4734
                        -- mode is switched : give warning
4735
                        ASSERT false REPORT "M counter switched BYPASS mode to enabled. PLL may lose lock." severity warning;
4736
                    end if;
4737
                    m_mode_val(0) <= "      ";
4738
                    if (tmp_scan_data(71) = '1') then
4739
                        -- odd : check for duty cycle, if not 50% -- error
4740
                        if (alt_conv_integer(m_hi) - alt_conv_integer(m_lo) /= 1) then
4741
                            reconfig_err <= true;
4742
                            ASSERT FALSE REPORT "The M counter of the " & family_name & " FAST PLL can be configured for 50% duty cycle only. In this case, the HIGH and LOW moduli programmed will result in a duty cycle other than 50%, which is illegal. Reconfiguration may not work." severity warning;
4743
                        end if;
4744
                    else -- even
4745
                        if (alt_conv_integer(m_hi) /= alt_conv_integer(m_lo)) then
4746
                            reconfig_err <= true;
4747
                            ASSERT FALSE REPORT "The M counter of the " & family_name & " FAST PLL can be configured for 50% duty cycle only. In this case, the HIGH and LOW moduli programmed will result in a duty cycle other than 50%, which is illegal. Reconfiguration may not work." severity warning;
4748
                        end if;
4749
                    end if;
4750
                end if;
4751
 
4752
                -- N
4753
                is_error := false;
4754
                n_fast := tmp_scan_data(73 downto 72);
4755
                n_val(0) <= alt_conv_integer(n_fast);
4756
                if (tmp_scan_data(74) /= '1') then
4757
                    if (alt_conv_integer(n_fast) = 1) then
4758
                        is_error := true;
4759
                        reconfig_err <= true;
4760
                        -- cntr value is illegal : give warning
4761
                        ASSERT false REPORT "Illegal 1 value for N counter. Instead the counter should be BYPASSED. Reconfiguration may not work." severity warning;
4762
                    elsif (alt_conv_integer(n_fast) = 0) then
4763
                        n_val(0) <= 4;
4764
                        ASSERT FALSE REPORT "N Modulus = " &int2str(4)& " " severity note;
4765
                    end if;
4766
                    if (not is_error) then
4767
                        if (n_mode_val(0) = "bypass") then
4768
                            ASSERT false REPORT "N Counter switched from BYPASS mode to enabled (N modulus = " &int2str(alt_conv_integer(n_fast))& "). PLL may lose lock." severity warning;
4769
                        else
4770
                            ASSERT FALSE REPORT "N modulus = " &int2str(alt_conv_integer(n_fast))& " "severity note;
4771
                        end if;
4772
                        n_mode_val(0) <= "      ";
4773
                    end if;
4774
                elsif (tmp_scan_data(74) = '1') then
4775
                    if (tmp_scan_data(72) /= '0') then
4776
                        is_error := true;
4777
                        reconfig_err <= true;
4778
                        ASSERT false report "Illegal value for N counter in BYPASS mode. The LSB of the counter should be set to 0 in order to operate the counter in BYPASS mode. Reconfiguration may not work." severity warning;
4779
                    else
4780
                        if (n_mode_val(0) /= "bypass") then
4781
                            ASSERT false REPORT "N Counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
4782
                        end if;
4783
                        n_val(0) <= 1;
4784
                        n_mode_val(0) <= "bypass";
4785
                    end if;
4786
                end if;
4787
            else   -- GENERAL PURPOSE PLL
4788
                for i in 0 to 5 loop
4789
                    start_bit := 116 - (i*18);
4790
                    if (tmp_scan_data(start_bit + 8) = '1') then
4791
                        c_mode_val_tmp(i) := "bypass";
4792
                        if (tmp_scan_data(start_bit + 17) = '1') then
4793
                            c_mode_val_tmp(i) := "   off";
4794
                            ASSERT false REPORT "The specified bit settings will turn OFF the " &cntrs(i)& "counter. It cannot be turned on unless the part is re-initialized." severity warning;
4795
                        end if;
4796
                    elsif (tmp_scan_data(start_bit + 17) = '1') then
4797
                        c_mode_val_tmp(i) := "   odd";
4798
                    else
4799
                        c_mode_val_tmp(i) := "  even";
4800
                    end if;
4801
                    high := tmp_scan_data(start_bit + 7 downto start_bit);
4802
                    low := tmp_scan_data(start_bit+16 downto start_bit+9);
4803
                    if (tmp_scan_data(start_bit+7 downto start_bit) = "00000000") then
4804
                        c_high_val_tmp(i) := 256;
4805
                    else
4806
                        c_high_val_tmp(i) := alt_conv_integer(high);
4807
                    end if;
4808
                    if (tmp_scan_data(start_bit+16 downto start_bit+9) = "00000000") then
4809
                        c_low_val_tmp(i) := 256;
4810
                    else
4811
                        c_low_val_tmp(i) := alt_conv_integer(low);
4812
                    end if;
4813
                end loop;
4814
                -- the phase taps
4815
                for i in 0 to 5 loop
4816
                    start_bit := 14 + (i*2);
4817
                    if (tmp_scan_data(start_bit) = '0') then
4818
                        -- do nothing
4819
                    elsif (tmp_scan_data(start_bit) = '1') then
4820
                        if (tmp_scan_data(start_bit + 1) = '1') then
4821
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) + 1;
4822
                            if (c_ph_val_tmp(i) > 7) then
4823
                                c_ph_val_tmp(i) := 0;
4824
                            end if;
4825
                        elsif (tmp_scan_data(start_bit + 1) = '0') then
4826
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) - 1;
4827
                            if (c_ph_val_tmp(i) < 0) then
4828
                                c_ph_val_tmp(i) := 7;
4829
                            end if;
4830
                        end if;
4831
                    end if;
4832
                end loop;
4833
                sig_c_ph_val_tmp <= c_ph_val_tmp;
4834
                sig_c_low_val_tmp <= c_low_val_tmp;
4835
                sig_c_hi_val_tmp <= c_high_val_tmp;
4836
 
4837
                -- cntrs M/M2
4838
                for i in 0 to 1 loop
4839
                    start_bit := 134 + (i*10);
4840
                    if ( i = 0 or (i = 1 and ss > 0) ) then
4841
                        is_error := false;
4842
                        m_tmp := tmp_scan_data(start_bit+8 downto start_bit);
4843
                        m_val_tmp(i) := alt_conv_integer(m_tmp);
4844
                        if (tmp_scan_data(start_bit+9) /= '1') then
4845
                            if (alt_conv_integer(m_tmp) = 1) then
4846
                                is_error := true;
4847
                                reconfig_err <= true;
4848
                                -- cntr value is illegal : give warning
4849
                                ASSERT false REPORT "Illegal 1 value for " &ss_cntrs(i)& "counter. Instead " &ss_cntrs(i)& "should be BYPASSED. Reconfiguration may not work." severity warning;
4850
                            elsif (tmp_scan_data(start_bit+8 downto start_bit) = "000000000") then
4851
                                m_val_tmp(i) := 512;
4852
                            end if;
4853
                            if (not is_error) then
4854
                                if (m_mode_val(i) = "bypass") then
4855
                                    -- Mode is switched : give warning
4856
                                    ASSERT false REPORT "M Counter switched from BYPASS mode to enabled (M modulus = " &int2str(alt_conv_integer(m_tmp))& "). PLL may lose lock." severity warning;
4857
                                else
4858
                                end if;
4859
                                m_mode_val(i) <= "      ";
4860
                            end if;
4861
                        elsif (tmp_scan_data(start_bit+9) = '1') then
4862
                            if (tmp_scan_data(start_bit) /= '0') then
4863
                                is_error := true;
4864
                                reconfig_err <= true;
4865
                                ASSERT false report "Illegal value for counter " &ss_cntrs(i)& "in BYPASS mode. The LSB of the counter should be set to 0 in order to operate the counter in BYPASS mode. Reconfiguration may not work." severity warning;
4866
                            else
4867
                                if (m_mode_val(i) /= "bypass") then
4868
                                    -- Mode is switched : give warning
4869
                                    ASSERT false REPORT "M Counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
4870
                                end if;
4871
                                m_val_tmp(i) := 1;
4872
                                m_mode_val(i) <= "bypass";
4873
                            end if;
4874
                        end if;
4875
                    end if;
4876
                end loop;
4877
                if (ss > 0) then
4878
                    if (m_mode_val(0) /= m_mode_val(1)) then
4879
                        reconfig_err <= true;
4880
                        is_error := true;
4881
                        ASSERT false REPORT "Incompatible modes for M/M2 counters. Either both should be BYPASSED or both NON-BYPASSED. Reconfiguration may not work." severity warning;
4882
                    end if;
4883
                end if;
4884
                sig_m_val_tmp <= m_val_tmp;
4885
                -- cntrs N/N2
4886
                for i in 0 to 1 loop
4887
                    start_bit := 154 + i*10;
4888
                    if ( i = 0 or (i = 1 and ss > 0) ) then
4889
                        is_error := false;
4890
                        n_tmp := tmp_scan_data(start_bit+8 downto start_bit);
4891
                        n_val(i) <= alt_conv_integer(n_tmp);
4892
                        if (tmp_scan_data(start_bit+9) /= '1') then
4893
                            if (alt_conv_integer(n_tmp) = 1) then
4894
                                is_error := true;
4895
                                reconfig_err <= true;
4896
                                -- cntr value is illegal : give warning
4897
                                ASSERT false REPORT "Illegal 1 value for " &ss_cntrs(2+i)& "counter. Instead " &ss_cntrs(2+i)& "should be BYPASSED. Reconfiguration may not work." severity warning;
4898
                            elsif (alt_conv_integer(n_tmp) = 0) then
4899
                                n_val(i) <= 512;
4900
                            end if;
4901
                            if (not is_error) then
4902
                                if (n_mode_val(i) = "bypass") then
4903
                                    ASSERT false REPORT "N Counter switched from BYPASS mode to enabled (N modulus = " &int2str(alt_conv_integer(n_tmp))& "). PLL may lose lock." severity warning;
4904
                                else
4905
                                end if;
4906
                                n_mode_val(i) <= "      ";
4907
                            end if;
4908
                        elsif (tmp_scan_data(start_bit+9) = '1') then
4909
                            if (tmp_scan_data(start_bit) /= '0') then
4910
                                is_error := true;
4911
                                reconfig_err <= true;
4912
                                ASSERT false report "Illegal value for counter " &ss_cntrs(2+i)& "in BYPASS mode. The LSB of the counter should be set to 0 in order to operate the counter in BYPASS mode. Reconfiguration may not work." severity warning;
4913
                            else
4914
                                if (n_mode_val(i) /= "bypass") then
4915
                                    ASSERT false REPORT "N Counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
4916
                                end if;
4917
                                n_val(i) <= 1;
4918
                                n_mode_val(i) <= "bypass";
4919
                            end if;
4920
                        end if;
4921
                    end if;
4922
                end loop;
4923
                if (ss > 0) then
4924
                    if (n_mode_val(0) /= n_mode_val(1)) then
4925
                        reconfig_err <= true;
4926
                        is_error := true;
4927
                        ASSERT false REPORT "Incompatible modes for N/N2 counters. Either both should be BYPASSED or both NON-BYPASSED. Reconfiguration may not work." severity warning;
4928
                    end if;
4929
                end if;
4930
            end if;
4931
 
4932
            slowest_clk_old := slowest_clk(c_high_val(0)+c_low_val(0), c_mode_val(0),
4933
                                    c_high_val(1)+c_low_val(1), c_mode_val(1),
4934
                                    c_high_val(2)+c_low_val(2), c_mode_val(2),
4935
                                    c_high_val(3)+c_low_val(3), c_mode_val(3),
4936
                                    c_high_val(4)+c_low_val(4), c_mode_val(4),
4937
                                    c_high_val(5)+c_low_val(5), c_mode_val(5),
4938
                                    sig_refclk_period, m_val(0));
4939
 
4940
            slowest_clk_new := slowest_clk(c_high_val_tmp(0)+c_low_val_tmp(0), c_mode_val_tmp(0),
4941
                                    c_high_val_tmp(1)+c_low_val_tmp(1), c_mode_val_tmp(1),
4942
                                    c_high_val_tmp(2)+c_low_val_tmp(2), c_mode_val_tmp(2),
4943
                                    c_high_val_tmp(3)+c_low_val_tmp(3), c_mode_val_tmp(3),
4944
                                    c_high_val_tmp(4)+c_low_val_tmp(4), c_mode_val_tmp(4),
4945
                                    c_high_val_tmp(5)+c_low_val_tmp(5), c_mode_val_tmp(5),
4946
                                    sig_refclk_period, m_val_tmp(0));
4947
 
4948
            if (slowest_clk_new > slowest_clk_old) then
4949
                quiet_time := slowest_clk_new;
4950
            else
4951
                quiet_time := slowest_clk_old;
4952
            end if;
4953
            sig_quiet_time <= quiet_time;
4954
            sig_slowest_clk_old <= slowest_clk_old;
4955
            sig_slowest_clk_new <= slowest_clk_new;
4956
            tmp_rem := (quiet_time/1 ps) rem (scanclk_period/ 1 ps);
4957
            scanclk_cycles := (quiet_time/1 ps) / (scanclk_period/1 ps);
4958
            if (tmp_rem /= 0) then
4959
                scanclk_cycles := scanclk_cycles + 1;
4960
            end if;
4961
            scandone_tmp <= transport '1' after ((scanclk_cycles+1)*scanclk_period - (scanclk_period/2));
4962
        end if;
4963
 
4964
        if (scanwrite_enabled = '1') then
4965
            if (fbclk'event and fbclk = '1') then
4966
                m_val <= m_val_tmp;
4967
            end if;
4968
 
4969
            if (c_clk(0)'event and c_clk(0) = '1') then
4970
                c_high_val(0) <= c_high_val_tmp(0);
4971
                c_mode_val(0) <= c_mode_val_tmp(0);
4972
                c0_rising_edge_transfer_done := true;
4973
            end if;
4974
            if (c_clk(1)'event and c_clk(1) = '1') then
4975
                c_high_val(1) <= c_high_val_tmp(1);
4976
                c_mode_val(1) <= c_mode_val_tmp(1);
4977
                c1_rising_edge_transfer_done := true;
4978
            end if;
4979
            if (c_clk(2)'event and c_clk(2) = '1') then
4980
                c_high_val(2) <= c_high_val_tmp(2);
4981
                c_mode_val(2) <= c_mode_val_tmp(2);
4982
                c2_rising_edge_transfer_done := true;
4983
            end if;
4984
            if (c_clk(3)'event and c_clk(3) = '1') then
4985
                c_high_val(3) <= c_high_val_tmp(3);
4986
                c_mode_val(3) <= c_mode_val_tmp(3);
4987
                c3_rising_edge_transfer_done := true;
4988
            end if;
4989
            if (c_clk(4)'event and c_clk(4) = '1') then
4990
                c_high_val(4) <= c_high_val_tmp(4);
4991
                c_mode_val(4) <= c_mode_val_tmp(4);
4992
                c4_rising_edge_transfer_done := true;
4993
            end if;
4994
            if (c_clk(5)'event and c_clk(5) = '1') then
4995
                c_high_val(5) <= c_high_val_tmp(5);
4996
                c_mode_val(5) <= c_mode_val_tmp(5);
4997
                c5_rising_edge_transfer_done := true;
4998
            end if;
4999
        end if;
5000
 
5001
        if (c_clk(0)'event and c_clk(0) = '0' and c0_rising_edge_transfer_done) then
5002
            c_low_val(0) <= c_low_val_tmp(0);
5003
        end if;
5004
        if (c_clk(1)'event and c_clk(1) = '0' and c1_rising_edge_transfer_done) then
5005
            c_low_val(1) <= c_low_val_tmp(1);
5006
        end if;
5007
        if (c_clk(2)'event and c_clk(2) = '0' and c2_rising_edge_transfer_done) then
5008
            c_low_val(2) <= c_low_val_tmp(2);
5009
        end if;
5010
        if (c_clk(3)'event and c_clk(3) = '0' and c3_rising_edge_transfer_done) then
5011
            c_low_val(3) <= c_low_val_tmp(3);
5012
        end if;
5013
        if (c_clk(4)'event and c_clk(4) = '0' and c4_rising_edge_transfer_done) then
5014
            c_low_val(4) <= c_low_val_tmp(4);
5015
        end if;
5016
        if (c_clk(5)'event and c_clk(5) = '0' and c5_rising_edge_transfer_done) then
5017
            c_low_val(5) <= c_low_val_tmp(5);
5018
        end if;
5019
 
5020
        if (scanwrite_enabled = '1') then
5021
            for x in 0 to 7 loop
5022
                if (vco_tap(x) /= vco_tap_last_value(x) and vco_tap(x) = '0') then
5023
                    -- TAP X has event
5024
                    for i in 0 to 5 loop
5025
                        if (c_ph_val(i) = x) then
5026
                            c_ph_val(i) <= c_ph_val_tmp(i);
5027
                        end if;
5028
                    end loop;
5029
                    if (m_ph_val = x) then
5030
                        m_ph_val <= m_ph_val_tmp;
5031
                    end if;
5032
                end if;
5033
            end loop;
5034
        end if;
5035
 
5036
        -- revert counter phase tap values to POF programmed values
5037
        -- if PLL is reset
5038
 
5039
        if (areset_ipd = '1') then
5040
            c_ph_val <= i_c_ph;
5041
            c_ph_val_tmp := i_c_ph;
5042
            m_ph_val <= i_m_ph;
5043
            m_ph_val_tmp := i_m_ph;
5044
        end if;
5045
 
5046
        for x in 0 to 7 loop
5047
            if (vco_tap(x) /= vco_tap_last_value(x)) then
5048
                -- TAP X has event
5049
                for i in 0 to 5 loop
5050
                    if (c_ph_val(i) = x) then
5051
                        inclk_c_from_vco(i) <= vco_tap(x);
5052
                        if (i = 0 and enable0_counter = "c0") then
5053
                            inclk_sclkout0_from_vco <= vco_tap(x);
5054
                        end if;
5055
                        if (i = 0 and enable1_counter = "c0") then
5056
                            inclk_sclkout1_from_vco <= vco_tap(x);
5057
                        end if;
5058
                        if (i = 1 and enable0_counter = "c1") then
5059
                            inclk_sclkout0_from_vco <= vco_tap(x);
5060
                        end if;
5061
                        if (i = 1 and enable1_counter = "c1") then
5062
                            inclk_sclkout1_from_vco <= vco_tap(x);
5063
                        end if;
5064
                    end if;
5065
                end loop;
5066
 
5067
                if (m_ph_val = x) then
5068
                    inclk_m_from_vco <= vco_tap(x);
5069
                end if;
5070
 
5071
                vco_tap_last_value(x) <= vco_tap(x);
5072
            end if;
5073
        end loop;
5074
 
5075
 
5076
 
5077
        if (scanclk_ipd'event and scanclk_ipd = '0') then
5078
            -- enable scanwrite on falling edge
5079
            scanwrite_enabled <= scanwrite_reg;
5080
        end if;
5081
 
5082
        if (scanread_reg = '1') then
5083
            gated_scanclk <= transport scanclk_ipd and scanread_reg;
5084
        else
5085
            gated_scanclk <= transport '1';
5086
        end if;
5087
 
5088
        if (scanclk_ipd'event and scanclk_ipd = '1') then
5089
            -- register scanread and scanwrite
5090
            scanread_reg <= scanread_ipd;
5091
            scanwrite_reg <= scanwrite_ipd;
5092
 
5093
            if (got_first_scanclk) then
5094
                scanclk_period := now - scanclk_last_rising_edge;
5095
            else
5096
                got_first_scanclk := true;
5097
            end if;
5098
            -- reset got_first_scanclk on falling edge of scanread_reg
5099
            if (scanread_ipd = '0' and scanread_reg = '1') then
5100
                got_first_scanclk := false;
5101
                got_first_gated_scanclk := false;
5102
            end if;
5103
 
5104
            scanclk_last_rising_edge := now;
5105
        end if;
5106
 
5107
        if (gated_scanclk'event and gated_scanclk = '1' and now > 0 ps) then
5108
            if (not got_first_gated_scanclk) then
5109
                got_first_gated_scanclk := true;
5110
            end if;
5111
            for j in scan_chain_length - 1 downto 1 loop
5112
                scan_data(j) <= scan_data(j-1);
5113
            end loop;
5114
            scan_data(0) <= scandata_ipd;
5115
        end if;
5116
    end process;
5117
 
5118
    scandataout_tmp <= scan_data(FAST_SCAN_CHAIN-1) when (pll_type = "fast" or pll_type = "lvds") else scan_data(GPP_SCAN_CHAIN-1);
5119
 
5120
 
5121
    SCHEDULE : process (schedule_vco, areset_ipd, ena_ipd, pfdena_ipd, refclk, fbclk, vco_out)
5122
    variable sched_time : time := 0 ps;
5123
 
5124
    TYPE time_array is ARRAY (0 to 7) of time;
5125
    variable init : boolean := true;
5126
    variable refclk_period : time;
5127
    variable m_times_vco_period : time;
5128
    variable new_m_times_vco_period : time;
5129
 
5130
    variable phase_shift : time_array := (OTHERS => 0 ps);
5131
    variable last_phase_shift : time_array := (OTHERS => 0 ps);
5132
 
5133
    variable l_index : integer := 1;
5134
    variable cycle_to_adjust : integer := 0;
5135
 
5136
    variable stop_vco : boolean := false;
5137
 
5138
    variable locked_tmp : std_logic := '0';
5139
    variable pll_is_locked : boolean := false;
5140
    variable pll_about_to_lock : boolean := false;
5141
    variable cycles_to_lock : integer := 0;
5142
    variable cycles_to_unlock : integer := 0;
5143
 
5144
    variable got_first_refclk : boolean := false;
5145
    variable got_second_refclk : boolean := false;
5146
    variable got_first_fbclk : boolean := false;
5147
 
5148
    variable refclk_time : time := 0 ps;
5149
    variable fbclk_time : time := 0 ps;
5150
    variable first_fbclk_time : time := 0 ps;
5151
 
5152
    variable fbclk_period : time := 0 ps;
5153
 
5154
    variable first_schedule : boolean := true;
5155
 
5156
    variable vco_val : std_logic := '0';
5157
    variable vco_period_was_phase_adjusted : boolean := false;
5158
    variable phase_adjust_was_scheduled : boolean := false;
5159
 
5160
    variable loop_xplier : integer;
5161
    variable loop_initial : integer := 0;
5162
    variable loop_ph : integer := 0;
5163
    variable loop_time_delay : integer := 0;
5164
 
5165
    variable initial_delay : time := 0 ps;
5166
    variable vco_per : time;
5167
    variable tmp_rem : integer;
5168
    variable my_rem : integer;
5169
    variable fbk_phase : integer := 0;
5170
 
5171
    variable pull_back_M : integer := 0;
5172
    variable total_pull_back : integer := 0;
5173
    variable fbk_delay : integer := 0;
5174
 
5175
    variable offset : time := 0 ps;
5176
 
5177
    variable tmp_vco_per : integer := 0;
5178
    variable high_time : time;
5179
    variable low_time : time;
5180
 
5181
    variable got_refclk_posedge : boolean := false;
5182
    variable got_fbclk_posedge : boolean := false;
5183
    variable inclk_out_of_range : boolean := false;
5184
    variable no_warn : boolean := false;
5185
 
5186
    variable ext_fbk_cntr_modulus : integer := 1;
5187
    variable init_clks : boolean := true;
5188
    variable pll_is_in_reset : boolean := false;
5189
    variable pll_is_disabled : boolean := false;
5190
    variable next_vco_sched_time : time  := 0 ps;
5191
    variable tap0_is_active : boolean := true;
5192
 
5193
    begin
5194
        if (init) then
5195
 
5196
            -- jump-start the VCO
5197
            -- add 1 ps delay to ensure all signals are updated to initial
5198
            -- values
5199
            schedule_vco <= transport not schedule_vco after 1 ps;
5200
 
5201
            init := false;
5202
        end if;
5203
 
5204
        if (schedule_vco'event) then
5205
            if (init_clks) then
5206
                refclk_period := inclk0_input_frequency * n_val(0) * 1 ps;
5207
 
5208
                m_times_vco_period := refclk_period;
5209
                new_m_times_vco_period := refclk_period;
5210
                init_clks := false;
5211
            end if;
5212
            sched_time := 0 ps;
5213
            for i in 0 to 7 loop
5214
                last_phase_shift(i) := phase_shift(i);
5215
            end loop;
5216
            cycle_to_adjust := 0;
5217
            l_index := 1;
5218
            m_times_vco_period := new_m_times_vco_period;
5219
        end if;
5220
 
5221
        -- areset was asserted
5222
        if (areset_ipd'event and areset_ipd = '1') then
5223
            assert false report family_name & " PLL was reset" severity note;
5224
            -- reset lock parameters
5225
            locked_tmp := '0';
5226
            pll_is_locked := false;
5227
            pll_about_to_lock := false;
5228
            cycles_to_lock := 0;
5229
            cycles_to_unlock := 0;
5230
            pll_is_in_reset := true;
5231
            tap0_is_active := false;
5232
            for x in 0 to 7 loop
5233
                vco_tap(x) <= '0';
5234
            end loop;
5235
        end if;
5236
 
5237
        -- note areset deassert time
5238
        -- note it as refclk_time to prevent false triggering
5239
        -- of stop_vco after areset
5240
        if (areset_ipd'event and areset_ipd = '0' and pll_is_in_reset) then
5241
            refclk_time := now;
5242
            pll_is_in_reset := false;
5243
            if (ena_ipd = '1' and not stop_vco and next_vco_sched_time <= now) then
5244
                schedule_vco <= not schedule_vco;
5245
            end if;
5246
        end if;
5247
 
5248
        -- ena was deasserted
5249
        if (ena_ipd'event and ena_ipd = '0') then
5250
            assert false report family_name & " PLL was disabled" severity note;
5251
            pll_is_disabled := true;
5252
            tap0_is_active := false;
5253
            for x in 0 to 7 loop
5254
                vco_tap(x) <= '0';
5255
            end loop;
5256
        end if;
5257
 
5258
        if (ena_ipd'event and ena_ipd = '1') then
5259
            assert false report family_name & " PLL is enabled" severity note;
5260
            pll_is_disabled := false;
5261
            if (areset_ipd /= '1' and not stop_vco and next_vco_sched_time < now) then
5262
                schedule_vco <= not schedule_vco;
5263
            end if;
5264
        end if;
5265
 
5266
        -- illegal value on areset_ipd
5267
        if (areset_ipd'event and areset_ipd = 'X') then
5268
            assert false report "Illegal value 'X' detected on ARESET input" severity warning;
5269
        end if;
5270
 
5271
        if (areset_ipd = '1' or ena_ipd = '0' or stop_vco) then
5272
 
5273
            -- reset lock parameters
5274
            locked_tmp := '0';
5275
            pll_is_locked := false;
5276
            pll_about_to_lock := false;
5277
            cycles_to_lock := 0;
5278
            cycles_to_unlock := 0;
5279
 
5280
            got_first_refclk := false;
5281
            got_second_refclk := false;
5282
            refclk_time := 0 ps;
5283
            got_first_fbclk := false;
5284
            fbclk_time := 0 ps;
5285
            first_fbclk_time := 0 ps;
5286
            fbclk_period := 0 ps;
5287
 
5288
--            first_schedule := true;
5289
--            vco_val := '0';
5290
            vco_period_was_phase_adjusted := false;
5291
            phase_adjust_was_scheduled := false;
5292
 
5293
            -- reset all counter phase taps to POF programmed values
5294
        end if;
5295
 
5296
        if (schedule_vco'event and areset_ipd /= '1' and ena_ipd /= '0' and (not stop_vco) and now > 0 ps) then
5297
 
5298
 
5299
            -- calculate loop_xplier : this will be different from m_val
5300
            -- in external_feedback_mode
5301
            loop_xplier := m_val(0);
5302
            loop_initial := m_initial_val - 1;
5303
            loop_ph := m_ph_val;
5304
 
5305
            if (operation_mode = "external_feedback") then
5306
                if (ext_fbk_cntr_mode = "bypass") then
5307
                    ext_fbk_cntr_modulus := 1;
5308
                else
5309
                    ext_fbk_cntr_modulus := ext_fbk_cntr_high + ext_fbk_cntr_low;
5310
                end if;
5311
                loop_xplier := m_val(0) * (ext_fbk_cntr_modulus);
5312
                loop_ph := ext_fbk_cntr_ph;
5313
                loop_initial := ext_fbk_cntr_initial - 1 + ((m_initial_val - 1) * ext_fbk_cntr_modulus);
5314
            end if;
5315
 
5316
            -- convert initial value to delay
5317
            initial_delay := (loop_initial * m_times_vco_period)/loop_xplier;
5318
 
5319
            -- convert loop ph_tap to delay
5320
            my_rem := (m_times_vco_period/1 ps) rem loop_xplier;
5321
            tmp_vco_per := (m_times_vco_period/1 ps) / loop_xplier;
5322
            if (my_rem /= 0) then
5323
                tmp_vco_per := tmp_vco_per + 1;
5324
            end if;
5325
            fbk_phase := (loop_ph * tmp_vco_per)/8;
5326
 
5327
            if (operation_mode = "external_feedback") then
5328
                pull_back_M :=  (m_initial_val - 1) * ext_fbk_cntr_modulus * ((refclk_period/loop_xplier)/1 ps);
5329
                while (pull_back_M > refclk_period/1 ps) loop
5330
                    pull_back_M := pull_back_M - refclk_period/ 1 ps;
5331
                end loop;
5332
            else
5333
                pull_back_M := initial_delay/1 ps + fbk_phase;
5334
            end if;
5335
 
5336
            total_pull_back := pull_back_M;
5337
 
5338
            if (simulation_type = "timing") then
5339
                total_pull_back := total_pull_back + pll_compensation_delay;
5340
            end if;
5341
            while (total_pull_back > refclk_period/1 ps) loop
5342
                total_pull_back := total_pull_back - refclk_period/1 ps;
5343
            end loop;
5344
 
5345
            if (total_pull_back > 0) then
5346
                offset := refclk_period - (total_pull_back * 1 ps);
5347
            end if;
5348
            if (operation_mode = "external_feedback") then
5349
                fbk_delay := pull_back_M;
5350
                if (simulation_type = "timing") then
5351
                    fbk_delay := fbk_delay + pll_compensation_delay;
5352
                end if;
5353
            else
5354
                fbk_delay := total_pull_back - fbk_phase;
5355
                if (fbk_delay < 0) then
5356
                    offset := offset - (fbk_phase * 1 ps);
5357
                    fbk_delay := total_pull_back;
5358
                end if;
5359
            end if;
5360
 
5361
            -- assign m_delay
5362
            m_delay <= transport fbk_delay after 1 ps;
5363
 
5364
            my_rem := (m_times_vco_period/1 ps) rem loop_xplier;
5365
            for i in 1 to loop_xplier loop
5366
                -- adjust cycles
5367
                tmp_vco_per := (m_times_vco_period/1 ps)/loop_xplier;
5368
                if (my_rem /= 0 and l_index <= my_rem) then
5369
                    tmp_rem := (loop_xplier * l_index) rem my_rem;
5370
                    cycle_to_adjust := (loop_xplier * l_index) / my_rem;
5371
                    if (tmp_rem /= 0) then
5372
                        cycle_to_adjust := cycle_to_adjust + 1;
5373
                    end if;
5374
                end if;
5375
                if (cycle_to_adjust = i) then
5376
                    tmp_vco_per := tmp_vco_per + 1;
5377
                    l_index := l_index + 1;
5378
                end if;
5379
 
5380
                -- calculate high and low periods
5381
                vco_per := tmp_vco_per * 1 ps;
5382
                high_time := (tmp_vco_per/2) * 1 ps;
5383
                if (tmp_vco_per rem 2 /= 0) then
5384
                    high_time := high_time + 1 ps;
5385
                end if;
5386
                low_time := vco_per - high_time;
5387
 
5388
                -- schedule the rising and falling edges
5389
                for j in 1 to 2 loop
5390
                    vco_val := not vco_val;
5391
                    if (vco_val = '0') then
5392
                        sched_time := sched_time + high_time;
5393
                    elsif (vco_val = '1') then
5394
                        sched_time := sched_time + low_time;
5395
                    end if;
5396
 
5397
                    -- schedule tap0
5398
                    vco_out(0) <= transport vco_val after sched_time;
5399
                end loop;
5400
            end loop;
5401
 
5402
            -- schedule once more
5403
            if (first_schedule) then
5404
                vco_val := not vco_val;
5405
                if (vco_val = '0') then
5406
                    sched_time := sched_time + high_time;
5407
                elsif (vco_val = '1') then
5408
                    sched_time := sched_time + low_time;
5409
                end if;
5410
                -- schedule tap 0
5411
                vco_out(0) <= transport vco_val after sched_time;
5412
 
5413
                first_schedule := false;
5414
            end if;
5415
 
5416
            schedule_vco <= transport not schedule_vco after sched_time;
5417
            next_vco_sched_time := now + sched_time;
5418
 
5419
            if (vco_period_was_phase_adjusted) then
5420
                m_times_vco_period := refclk_period;
5421
                new_m_times_vco_period := refclk_period;
5422
                vco_period_was_phase_adjusted := false;
5423
                phase_adjust_was_scheduled := true;
5424
 
5425
                vco_per := m_times_vco_period/loop_xplier;
5426
                for k in 0 to 7 loop
5427
                    phase_shift(k) := (k * vco_per)/8;
5428
                end loop;
5429
            end if;
5430
        end if;
5431
 
5432
        -- now schedule the other taps with the appropriate phase-shift
5433
        if (vco_out(0)'event) then
5434
            for k in 1 to 7 loop
5435
                phase_shift(k) := (k * vco_per)/8;
5436
                vco_out(k) <= transport vco_out(0) after phase_shift(k);
5437
            end loop;
5438
        end if;
5439
 
5440
        if (refclk'event and refclk = '1' and areset_ipd = '0') then
5441
            got_refclk_posedge := true;
5442
            if (not got_first_refclk) then
5443
                got_first_refclk := true;
5444
            else
5445
                got_second_refclk := true;
5446
                refclk_period := now - refclk_time;
5447
 
5448
                -- check if incoming freq. will cause VCO range to be
5449
                -- exceeded
5450
                if ( (vco_max /= 0 and vco_min /= 0 and pfdena_ipd = '1') and
5451
                    (((refclk_period/1 ps)/loop_xplier > vco_max) or
5452
                    ((refclk_period/1 ps)/loop_xplier < vco_min)) ) then
5453
                    if (pll_is_locked) then
5454
                        assert false report " Input clock freq. is not within VCO range : " & family_name & " PLL may lose lock" severity warning;
5455
                        if (inclk_out_of_range) then
5456
                            pll_is_locked := false;
5457
                            locked_tmp := '0';
5458
                            pll_about_to_lock := false;
5459
                            cycles_to_lock := 0;
5460
                            vco_period_was_phase_adjusted := false;
5461
                            phase_adjust_was_scheduled := false;
5462
                            assert false report family_name & " PLL lost lock." severity note;
5463
                        end if;
5464
                    elsif (not no_warn) then
5465
                        assert false report " Input clock freq. is not within VCO range : " & family_name & " PLL may not lock. Please use the correct frequency." severity warning;
5466
                        no_warn := true;
5467
                    end if;
5468
                    inclk_out_of_range := true;
5469
                else
5470
                    inclk_out_of_range := false;
5471
                end if;
5472
            end if;
5473
 
5474
            if (stop_vco) then
5475
                stop_vco := false;
5476
                schedule_vco <= not schedule_vco;
5477
            end if;
5478
 
5479
            refclk_time := now;
5480
        else
5481
            got_refclk_posedge := false;
5482
        end if;
5483
 
5484
        if (fbclk'event and fbclk = '1') then
5485
            got_fbclk_posedge := true;
5486
            if (not got_first_fbclk) then
5487
                got_first_fbclk := true;
5488
            else
5489
                fbclk_period := now - fbclk_time;
5490
            end if;
5491
 
5492
            -- need refclk_period here, so initialized to proper value above
5493
            if ( ( (now - refclk_time > 1.5 * refclk_period) and pfdena_ipd = '1' and pll_is_locked) or ( (now - refclk_time > 5 * refclk_period) and pfdena_ipd = '1') ) then
5494
                stop_vco := true;
5495
                -- reset
5496
                got_first_refclk := false;
5497
                got_first_fbclk := false;
5498
                got_second_refclk := false;
5499
                if (pll_is_locked) then
5500
                    pll_is_locked := false;
5501
                    locked_tmp := '0';
5502
                    assert false report family_name & " PLL lost lock due to loss of input clock" severity note;
5503
                end if;
5504
                pll_about_to_lock := false;
5505
                cycles_to_lock := 0;
5506
                cycles_to_unlock := 0;
5507
                first_schedule := true;
5508
                vco_period_was_phase_adjusted := false;
5509
                phase_adjust_was_scheduled := false;
5510
                tap0_is_active := false;
5511
                for x in 0 to 7 loop
5512
                    vco_tap(x) <= '0';
5513
                end loop;
5514
            end if;
5515
            fbclk_time := now;
5516
        else
5517
            got_fbclk_posedge := false;
5518
        end if;
5519
 
5520
        if ((got_refclk_posedge or got_fbclk_posedge) and got_second_refclk and pfdena_ipd = '1' and (not inclk_out_of_range)) then
5521
 
5522
            -- now we know actual incoming period
5523
            if ( abs(fbclk_time - refclk_time) <= 5 ps or
5524
                (got_first_fbclk and abs(refclk_period - abs(fbclk_time - refclk_time)) <= 5 ps)) then
5525
                -- considered in phase
5526
                if (cycles_to_lock = valid_lock_multiplier - 1) then
5527
                    pll_about_to_lock := true;
5528
                end if;
5529
                if (cycles_to_lock = valid_lock_multiplier) then
5530
                    if (not pll_is_locked) then
5531
                        assert false report family_name & " PLL locked to incoming clock" severity note;
5532
                    end if;
5533
                    pll_is_locked := true;
5534
                    locked_tmp := '1';
5535
                    cycles_to_unlock := 0;
5536
                end if;
5537
                -- increment lock counter only if second part of above
5538
                -- time check is NOT true
5539
                if (not(abs(refclk_period - abs(fbclk_time - refclk_time)) <= 5 ps)) then
5540
                    cycles_to_lock := cycles_to_lock + 1;
5541
                end if;
5542
 
5543
                -- adjust m_times_vco_period
5544
                new_m_times_vco_period := refclk_period;
5545
            else
5546
                -- if locked, begin unlock
5547
                if (pll_is_locked) then
5548
                    cycles_to_unlock := cycles_to_unlock + 1;
5549
                    if (cycles_to_unlock = invalid_lock_multiplier) then
5550
                        pll_is_locked := false;
5551
                        locked_tmp := '0';
5552
                        pll_about_to_lock := false;
5553
                        cycles_to_lock := 0;
5554
                        vco_period_was_phase_adjusted := false;
5555
                        phase_adjust_was_scheduled := false;
5556
                        assert false report family_name & " PLL lost lock." severity note;
5557
                    end if;
5558
                end if;
5559
                if ( abs(refclk_period - fbclk_period) <= 2 ps ) then
5560
                    -- frequency is still good
5561
                    if (now = fbclk_time and (not phase_adjust_was_scheduled)) then
5562
                        if ( abs(fbclk_time - refclk_time) > refclk_period/2) then
5563
                            if ( abs(fbclk_time - refclk_time) > 1.5 * refclk_period) then
5564
                                -- input clock may have stopped : do nothing
5565
                            else
5566
                            new_m_times_vco_period := m_times_vco_period + (refclk_period - abs(fbclk_time - refclk_time));
5567
                            vco_period_was_phase_adjusted := true;
5568
                            end if;
5569
                        else
5570
                            new_m_times_vco_period := m_times_vco_period - abs(fbclk_time - refclk_time);
5571
                            vco_period_was_phase_adjusted := true;
5572
                        end if;
5573
 
5574
                    end if;
5575
                else
5576
                    phase_adjust_was_scheduled := false;
5577
                    new_m_times_vco_period := refclk_period;
5578
                end if;
5579
 
5580
            end if;
5581
        end if;
5582
 
5583
        -- check which vco_tap has event
5584
        for x in 0 to 7 loop
5585
            if (vco_out(x) /= vco_out_last_value(x)) then
5586
                -- TAP X has event
5587
                if (x = 0 and areset_ipd = '0' and ena_ipd = '1' and sig_stop_vco = '0') then
5588
                    if (vco_out(0) = '1') then
5589
                        tap0_is_active := true;
5590
                    end if;
5591
                    if (tap0_is_active) then
5592
                        vco_tap(0) <= vco_out(0);
5593
                    end if;
5594
                elsif (tap0_is_active) then
5595
                        vco_tap(x) <= vco_out(x);
5596
                end if;
5597
                if (sig_stop_vco = '1') then
5598
                    vco_tap(x) <= '0';
5599
                end if;
5600
                vco_out_last_value(x) <= vco_out(x);
5601
            end if;
5602
        end loop;
5603
 
5604
        if (pfdena_ipd = '0') then
5605
            if (pll_is_locked) then
5606
                locked_tmp := 'X';
5607
            end if;
5608
            pll_is_locked := false;
5609
            cycles_to_lock := 0;
5610
        end if;
5611
 
5612
        -- give message only at time of deassertion
5613
        if (pfdena_ipd'event and pfdena_ipd = '0') then
5614
            assert false report "PFDENA deasserted." severity note;
5615
        elsif (pfdena_ipd'event and pfdena_ipd = '1') then
5616
            got_first_refclk := false;
5617
            got_second_refclk := false;
5618
            refclk_time := now;
5619
        end if;
5620
 
5621
        if (reconfig_err) then
5622
            lock <= '0';
5623
        else
5624
            lock <= locked_tmp;
5625
        end if;
5626
        about_to_lock <= pll_about_to_lock after 1 ps;
5627
 
5628
        -- signal to calculate quiet_time
5629
        sig_refclk_period <= refclk_period;
5630
 
5631
        if (stop_vco = true) then
5632
            sig_stop_vco <= '1';
5633
        else
5634
            sig_stop_vco <= '0';
5635
        end if;
5636
    end process SCHEDULE;
5637
 
5638
    clk0_tmp <= c_clk(i_clk0_counter);
5639
    clk(0)   <= clk0_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
5640
                'X';
5641
 
5642
    clk1_tmp <= c_clk(i_clk1_counter);
5643
    clk(1)   <= clk1_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
5644
                'X';
5645
 
5646
    clk2_tmp <= c_clk(i_clk2_counter);
5647
    clk(2)   <= clk2_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
5648
                'X';
5649
 
5650
    clk3_tmp <= c_clk(i_clk3_counter);
5651
 
5652
    clk4_tmp <= c_clk(i_clk4_counter);
5653
 
5654
    clk5_tmp <= c_clk(i_clk5_counter);
5655
 
5656
 
5657
 
5658
 
5659
 
5660
end vital_pll;
5661
-- END ARCHITECTURE VITAL_PLL
5662
 
5663
---------------------------------------------------------------------
5664
--
5665
-- Entity Name :  cycloneii_routing_wire
5666
--
5667
-- Description :  CycloneII Routing Wire VHDL simulation model
5668
--
5669
--
5670
---------------------------------------------------------------------
5671
 
5672
LIBRARY IEEE;
5673
use IEEE.std_logic_1164.all;
5674
use IEEE.VITAL_Timing.all;
5675
use IEEE.VITAL_Primitives.all;
5676
use work.cycloneii_atom_pack.all;
5677
 
5678
ENTITY cycloneii_routing_wire is
5679
    generic (
5680
             MsgOn : Boolean := DefGlitchMsgOn;
5681
             XOn : Boolean := DefGlitchXOn;
5682
             tpd_datain_dataout : VitalDelayType01 := DefPropDelay01;
5683
             tpd_datainglitch_dataout : VitalDelayType01 := DefPropDelay01;
5684
             tipd_datain : VitalDelayType01 := DefPropDelay01
5685
            );
5686
    PORT (
5687
          datain : in std_logic;
5688
          dataout : out std_logic
5689
         );
5690
   attribute VITAL_LEVEL0 of cycloneii_routing_wire : entity is TRUE;
5691
end cycloneii_routing_wire;
5692
 
5693
ARCHITECTURE behave of cycloneii_routing_wire is
5694
attribute VITAL_LEVEL0 of behave : architecture is TRUE;
5695
signal datain_ipd : std_logic;
5696
signal datainglitch_inert : std_logic;
5697
begin
5698
    ---------------------
5699
    --  INPUT PATH DELAYs
5700
    ---------------------
5701
    WireDelay : block
5702
    begin
5703
        VitalWireDelay (datain_ipd, datain, tipd_datain);
5704
    end block;
5705
 
5706
    VITAL: process(datain_ipd, datainglitch_inert)
5707
    variable datain_inert_VitalGlitchData : VitalGlitchDataType;
5708
    variable dataout_VitalGlitchData : VitalGlitchDataType;
5709
 
5710
    begin
5711
        ----------------------
5712
        --  Path Delay Section
5713
        ----------------------
5714
        VitalPathDelay01 (
5715
            OutSignal => datainglitch_inert,
5716
            OutSignalName => "datainglitch_inert",
5717
            OutTemp => datain_ipd,
5718
            Paths => (1 => (datain_ipd'last_event, tpd_datainglitch_dataout, TRUE)),
5719
            GlitchData => datain_inert_VitalGlitchData,
5720
            Mode => VitalInertial,
5721
            XOn  => XOn,
5722
            MsgOn  => MsgOn );
5723
 
5724
        VitalPathDelay01 (
5725
            OutSignal => dataout,
5726
            OutSignalName => "dataout",
5727
            OutTemp => datainglitch_inert,
5728
            Paths => (1 => (datain_ipd'last_event, tpd_datain_dataout, TRUE)),
5729
            GlitchData => dataout_VitalGlitchData,
5730
            Mode => DefGlitchMode,
5731
            XOn  => XOn,
5732
            MsgOn  => MsgOn );
5733
 
5734
    end process;
5735
 
5736
end behave;
5737
---------------------------------------------------------------------
5738
--
5739
-- Entity Name :  cycloneii_lcell_ff
5740
-- 
5741
-- Description :  Cyclone II LCELL_FF VHDL simulation model
5742
--  
5743
--
5744
---------------------------------------------------------------------
5745
 
5746
LIBRARY IEEE;
5747
use IEEE.std_logic_1164.all;
5748
use IEEE.VITAL_Timing.all;
5749
use IEEE.VITAL_Primitives.all;
5750
use work.cycloneii_atom_pack.all;
5751
use work.cycloneii_and1;
5752
 
5753
entity cycloneii_lcell_ff is
5754
    generic (
5755
             x_on_violation : string := "on";
5756
             lpm_type : string := "cycloneii_lcell_ff";
5757
             tsetup_datain_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
5758
             tsetup_sdata_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
5759
             tsetup_sclr_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
5760
             tsetup_sload_clk_noedge_posedge    : VitalDelayType := DefSetupHoldCnst;
5761
             tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
5762
             thold_datain_clk_noedge_posedge    : VitalDelayType := DefSetupHoldCnst;
5763
             thold_sdata_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
5764
             thold_sclr_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
5765
             thold_sload_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
5766
             thold_ena_clk_noedge_posedge       : VitalDelayType := DefSetupHoldCnst;
5767
             tpd_clk_regout_posedge : VitalDelayType01 := DefPropDelay01;
5768
             tpd_aclr_regout_posedge : VitalDelayType01 := DefPropDelay01;
5769
             tpd_sdata_regout: VitalDelayType01 := DefPropDelay01;
5770
             tipd_clk : VitalDelayType01 := DefPropDelay01;
5771
             tipd_datain : VitalDelayType01 := DefPropDelay01;
5772
             tipd_sdata : VitalDelayType01 := DefPropDelay01;
5773
             tipd_sclr : VitalDelayType01 := DefPropDelay01;
5774
             tipd_sload : VitalDelayType01 := DefPropDelay01;
5775
             tipd_aclr : VitalDelayType01 := DefPropDelay01;
5776
             tipd_ena : VitalDelayType01 := DefPropDelay01;
5777
             TimingChecksOn: Boolean := True;
5778
             MsgOn: Boolean := DefGlitchMsgOn;
5779
             XOn: Boolean := DefGlitchXOn;
5780
             MsgOnChecks: Boolean := DefMsgOnChecks;
5781
             XOnChecks: Boolean := DefXOnChecks;
5782
             InstancePath: STRING := "*"
5783
            );
5784
 
5785
    port (
5786
          datain : in std_logic := '0';
5787
          clk : in std_logic := '0';
5788
          aclr : in std_logic := '0';
5789
          sclr : in std_logic := '0';
5790
          sload : in std_logic := '0';
5791
          ena : in std_logic := '1';
5792
          sdata : in std_logic := '0';
5793
          devclrn : in std_logic := '1';
5794
          devpor : in std_logic := '1';
5795
          regout : out std_logic
5796
         );
5797
   attribute VITAL_LEVEL0 of cycloneii_lcell_ff : entity is TRUE;
5798
end cycloneii_lcell_ff;
5799
 
5800
architecture vital_lcell_ff of cycloneii_lcell_ff is
5801
   attribute VITAL_LEVEL0 of vital_lcell_ff : architecture is TRUE;
5802
   signal clk_ipd : std_logic;
5803
   signal datain_ipd : std_logic;
5804
   signal datain_dly : std_logic;
5805
   signal sdata_ipd : std_logic;
5806
   signal sdata_dly : std_logic;
5807
   signal sdata_dly1 : std_logic;
5808
   signal sclr_ipd : std_logic;
5809
   signal sload_ipd : std_logic;
5810
   signal aclr_ipd : std_logic;
5811
   signal ena_ipd : std_logic;
5812
 
5813
component cycloneii_and1
5814
    generic (XOn                  : Boolean := DefGlitchXOn;
5815
             MsgOn                : Boolean := DefGlitchMsgOn;
5816
             tpd_IN1_Y            : VitalDelayType01 := DefPropDelay01;
5817
             tipd_IN1             : VitalDelayType01 := DefPropDelay01
5818
            );
5819
 
5820
    port    (Y                    :  out   STD_LOGIC;
5821
             IN1                  :  in    STD_LOGIC
5822
            );
5823
end component;
5824
 
5825
begin
5826
 
5827
dataindelaybuffer: cycloneii_and1
5828
                   port map(IN1 => datain_ipd,
5829
                            Y => datain_dly);
5830
 
5831
sdatadelaybuffer: cycloneii_and1
5832
                   port map(IN1 => sdata_ipd,
5833
                            Y => sdata_dly);
5834
 
5835
sdatadelaybuffer1: cycloneii_and1
5836
                   port map(IN1 => sdata_dly,
5837
                            Y => sdata_dly1);
5838
 
5839
 
5840
    ---------------------
5841
    --  INPUT PATH DELAYs
5842
    ---------------------
5843
    WireDelay : block
5844
    begin
5845
        VitalWireDelay (clk_ipd, clk, tipd_clk);
5846
        VitalWireDelay (datain_ipd, datain, tipd_datain);
5847
        VitalWireDelay (sdata_ipd, sdata, tipd_sdata);
5848
        VitalWireDelay (sclr_ipd, sclr, tipd_sclr);
5849
        VitalWireDelay (sload_ipd, sload, tipd_sload);
5850
        VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
5851
        VitalWireDelay (ena_ipd, ena, tipd_ena);
5852
    end block;
5853
 
5854
    VITALtiming : process (clk_ipd, datain_dly, sdata_dly1,
5855
                           sclr_ipd, sload_ipd, aclr_ipd,
5856
                           ena_ipd, devclrn, devpor)
5857
 
5858
    variable Tviol_datain_clk : std_ulogic := '0';
5859
    variable Tviol_sdata_clk : std_ulogic := '0';
5860
    variable Tviol_sclr_clk : std_ulogic := '0';
5861
    variable Tviol_sload_clk : std_ulogic := '0';
5862
    variable Tviol_ena_clk : std_ulogic := '0';
5863
    variable TimingData_datain_clk : VitalTimingDataType := VitalTimingDataInit;
5864
    variable TimingData_sdata_clk : VitalTimingDataType := VitalTimingDataInit;
5865
    variable TimingData_sclr_clk : VitalTimingDataType := VitalTimingDataInit;
5866
    variable TimingData_sload_clk : VitalTimingDataType := VitalTimingDataInit;
5867
    variable TimingData_ena_clk : VitalTimingDataType := VitalTimingDataInit;
5868
    variable regout_VitalGlitchData : VitalGlitchDataType;
5869
 
5870
    variable iregout : std_logic := '0';
5871
    variable idata: std_logic := '0';
5872
 
5873
    -- variables for 'X' generation
5874
    variable violation : std_logic := '0';
5875
 
5876
    begin
5877
 
5878
        ------------------------
5879
        --  Timing Check Section
5880
        ------------------------
5881
        if (TimingChecksOn) then
5882
 
5883
            VitalSetupHoldCheck (
5884
                Violation       => Tviol_datain_clk,
5885
                TimingData      => TimingData_datain_clk,
5886
                TestSignal      => datain,
5887
                TestSignalName  => "DATAIN",
5888
                RefSignal       => clk_ipd,
5889
                RefSignalName   => "CLK",
5890
                SetupHigh       => tsetup_datain_clk_noedge_posedge,
5891
                SetupLow        => tsetup_datain_clk_noedge_posedge,
5892
                HoldHigh        => thold_datain_clk_noedge_posedge,
5893
                HoldLow         => thold_datain_clk_noedge_posedge,
5894
                CheckEnabled    => TO_X01((aclr_ipd) OR
5895
                                          (sload_ipd) OR
5896
                                          (sclr_ipd) OR
5897
                                          (NOT devpor) OR
5898
                                          (NOT devclrn) OR
5899
                                          (NOT ena_ipd)) /= '1',
5900
                RefTransition   => '/',
5901
                HeaderMsg       => InstancePath & "/LCELL_FF",
5902
                XOn             => XOnChecks,
5903
                MsgOn           => MsgOnChecks );
5904
 
5905
            VitalSetupHoldCheck (
5906
                Violation       => Tviol_sdata_clk,
5907
                TimingData      => TimingData_sdata_clk,
5908
                TestSignal      => sdata_ipd,
5909
                TestSignalName  => "SDATA",
5910
                RefSignal       => clk_ipd,
5911
                RefSignalName   => "CLK",
5912
                SetupHigh       => tsetup_sdata_clk_noedge_posedge,
5913
                SetupLow        => tsetup_sdata_clk_noedge_posedge,
5914
                HoldHigh        => thold_sdata_clk_noedge_posedge,
5915
                HoldLow         => thold_sdata_clk_noedge_posedge,
5916
                CheckEnabled    => TO_X01((aclr_ipd) OR
5917
                                          (NOT sload_ipd) OR
5918
                                          (NOT devpor) OR
5919
                                          (NOT devclrn) OR
5920
                                          (NOT ena_ipd)) /= '1',
5921
                RefTransition   => '/',
5922
                HeaderMsg       => InstancePath & "/LCELL_FF",
5923
                XOn             => XOnChecks,
5924
                MsgOn           => MsgOnChecks );
5925
 
5926
            VitalSetupHoldCheck (
5927
                Violation       => Tviol_sclr_clk,
5928
                TimingData      => TimingData_sclr_clk,
5929
                TestSignal      => sclr_ipd,
5930
                TestSignalName  => "SCLR",
5931
                RefSignal       => clk_ipd,
5932
                RefSignalName   => "CLK",
5933
                SetupHigh       => tsetup_sclr_clk_noedge_posedge,
5934
                SetupLow        => tsetup_sclr_clk_noedge_posedge,
5935
                HoldHigh        => thold_sclr_clk_noedge_posedge,
5936
                HoldLow         => thold_sclr_clk_noedge_posedge,
5937
                CheckEnabled    => TO_X01((aclr_ipd) OR
5938
                                          (NOT devpor) OR
5939
                                          (NOT devclrn) OR
5940
                                          (NOT ena_ipd)) /= '1',
5941
                RefTransition   => '/',
5942
                HeaderMsg       => InstancePath & "/LCELL_FF",
5943
                XOn             => XOnChecks,
5944
                MsgOn           => MsgOnChecks );
5945
 
5946
            VitalSetupHoldCheck (
5947
                Violation       => Tviol_sload_clk,
5948
                TimingData      => TimingData_sload_clk,
5949
                TestSignal      => sload_ipd,
5950
                TestSignalName  => "SLOAD",
5951
                RefSignal       => clk_ipd,
5952
                RefSignalName   => "CLK",
5953
                SetupHigh       => tsetup_sload_clk_noedge_posedge,
5954
                SetupLow        => tsetup_sload_clk_noedge_posedge,
5955
                HoldHigh        => thold_sload_clk_noedge_posedge,
5956
                HoldLow         => thold_sload_clk_noedge_posedge,
5957
                CheckEnabled    => TO_X01((aclr_ipd) OR
5958
                                          (NOT devpor) OR
5959
                                          (NOT devclrn) OR
5960
                                          (NOT ena_ipd)) /= '1',
5961
                RefTransition   => '/',
5962
                HeaderMsg       => InstancePath & "/LCELL_FF",
5963
                XOn             => XOnChecks,
5964
                MsgOn           => MsgOnChecks );
5965
 
5966
            VitalSetupHoldCheck (
5967
                Violation       => Tviol_ena_clk,
5968
                TimingData      => TimingData_ena_clk,
5969
                TestSignal      => ena_ipd,
5970
                TestSignalName  => "ENA",
5971
                RefSignal       => clk_ipd,
5972
                RefSignalName   => "CLK",
5973
                SetupHigh       => tsetup_ena_clk_noedge_posedge,
5974
                SetupLow        => tsetup_ena_clk_noedge_posedge,
5975
                HoldHigh        => thold_ena_clk_noedge_posedge,
5976
                HoldLow         => thold_ena_clk_noedge_posedge,
5977
                CheckEnabled    => TO_X01((aclr_ipd) OR
5978
                                          (NOT devpor) OR
5979
                                          (NOT devclrn) ) /= '1',
5980
                RefTransition   => '/',
5981
                HeaderMsg       => InstancePath & "/LCELL_FF",
5982
                XOn             => XOnChecks,
5983
                MsgOn           => MsgOnChecks );
5984
 
5985
        end if;
5986
 
5987
        violation := Tviol_datain_clk or Tviol_sdata_clk or
5988
                     Tviol_sclr_clk or Tviol_sload_clk or Tviol_ena_clk;
5989
 
5990
 
5991
        if ((devpor = '0') or (devclrn = '0') or (aclr_ipd = '1'))  then
5992
            iregout := '0';
5993
        elsif (violation = 'X' and x_on_violation = "on") then
5994
            iregout := 'X';
5995
        elsif clk_ipd'event and clk_ipd = '1' and clk_ipd'last_value = '0' then
5996
            if (ena_ipd = '1') then
5997
                if (sclr_ipd = '1') then
5998
                    iregout := '0';
5999
                elsif (sload_ipd = '1') then
6000
                    iregout := sdata_dly1;
6001
                else
6002
                    iregout := datain_dly;
6003
                end if;
6004
            end if;
6005
        end if;
6006
 
6007
        ----------------------
6008
        --  Path Delay Section
6009
        ----------------------
6010
        VitalPathDelay01 (
6011
            OutSignal => regout,
6012
            OutSignalName => "REGOUT",
6013
            OutTemp => iregout,
6014
            Paths => (0 => (aclr_ipd'last_event, tpd_aclr_regout_posedge, TRUE),
6015
                      1 => (sdata_ipd'last_event, tpd_sdata_regout, TRUE),
6016
                      2 => (clk_ipd'last_event, tpd_clk_regout_posedge, TRUE)),
6017
            GlitchData => regout_VitalGlitchData,
6018
            Mode => DefGlitchMode,
6019
            XOn  => XOn,
6020
            MsgOn  => MsgOn );
6021
 
6022
    end process;
6023
 
6024
end vital_lcell_ff;
6025
 
6026
---------------------------------------------------------------------
6027
--
6028
-- Entity Name :  cycloneii_lcell_comb
6029
-- 
6030
-- Description :  Cyclone II LCELL_COMB VHDL simulation model
6031
--  
6032
--
6033
---------------------------------------------------------------------
6034
 
6035
LIBRARY IEEE;
6036
use IEEE.std_logic_1164.all;
6037
use IEEE.VITAL_Timing.all;
6038
use IEEE.VITAL_Primitives.all;
6039
use work.cycloneii_atom_pack.all;
6040
 
6041
entity cycloneii_lcell_comb is
6042
    generic (
6043
             lut_mask : std_logic_vector(15 downto 0) := (OTHERS => '1');
6044
             sum_lutc_input : string := "datac";
6045
             lpm_type : string := "cycloneii_lcell_comb";
6046
             TimingChecksOn: Boolean := True;
6047
             MsgOn: Boolean := DefGlitchMsgOn;
6048
             XOn: Boolean := DefGlitchXOn;
6049
             MsgOnChecks: Boolean := DefMsgOnChecks;
6050
             XOnChecks: Boolean := DefXOnChecks;
6051
             InstancePath: STRING := "*";
6052
             tpd_dataa_combout : VitalDelayType01 := DefPropDelay01;
6053
             tpd_datab_combout : VitalDelayType01 := DefPropDelay01;
6054
             tpd_datac_combout : VitalDelayType01 := DefPropDelay01;
6055
             tpd_datad_combout : VitalDelayType01 := DefPropDelay01;
6056
             tpd_cin_combout : VitalDelayType01 := DefPropDelay01;
6057
             tpd_dataa_cout : VitalDelayType01 := DefPropDelay01;
6058
             tpd_datab_cout : VitalDelayType01 := DefPropDelay01;
6059
             tpd_datac_cout : VitalDelayType01 := DefPropDelay01;
6060
             tpd_datad_cout : VitalDelayType01 := DefPropDelay01;
6061
             tpd_cin_cout : VitalDelayType01 := DefPropDelay01;
6062
             tipd_dataa : VitalDelayType01 := DefPropDelay01;
6063
             tipd_datab : VitalDelayType01 := DefPropDelay01;
6064
             tipd_datac : VitalDelayType01 := DefPropDelay01;
6065
             tipd_datad : VitalDelayType01 := DefPropDelay01;
6066
             tipd_cin : VitalDelayType01 := DefPropDelay01
6067
            );
6068
 
6069
    port (
6070
          dataa : in std_logic := '1';
6071
          datab : in std_logic := '1';
6072
          datac : in std_logic := '1';
6073
          datad : in std_logic := '1';
6074
          cin : in std_logic := '0';
6075
          combout : out std_logic;
6076
          cout : out std_logic
6077
         );
6078
   attribute VITAL_LEVEL0 of cycloneii_lcell_comb : entity is TRUE;
6079
end cycloneii_lcell_comb;
6080
 
6081
architecture vital_lcell_comb of cycloneii_lcell_comb is
6082
    attribute VITAL_LEVEL0 of vital_lcell_comb : architecture is TRUE;
6083
    signal dataa_ipd : std_logic;
6084
    signal datab_ipd : std_logic;
6085
    signal datac_ipd : std_logic;
6086
    signal datad_ipd : std_logic;
6087
    signal cin_ipd : std_logic;
6088
begin
6089
 
6090
    ---------------------
6091
    --  INPUT PATH DELAYs
6092
    ---------------------
6093
    WireDelay : block
6094
    begin
6095
        VitalWireDelay (dataa_ipd, dataa, tipd_dataa);
6096
        VitalWireDelay (datab_ipd, datab, tipd_datab);
6097
        VitalWireDelay (datac_ipd, datac, tipd_datac);
6098
        VitalWireDelay (datad_ipd, datad, tipd_datad);
6099
        VitalWireDelay (cin_ipd, cin, tipd_cin);
6100
    end block;
6101
 
6102
VITALtiming : process(dataa_ipd, datab_ipd, datac_ipd, datad_ipd,
6103
                      cin_ipd)
6104
 
6105
variable combout_VitalGlitchData : VitalGlitchDataType;
6106
variable cout_VitalGlitchData : VitalGlitchDataType;
6107
-- output variables
6108
variable combout_tmp : std_logic;
6109
variable cout_tmp : std_logic;
6110
 
6111
begin
6112
 
6113
    -- lut_mask_var := lut_mask;
6114
 
6115
    ------------------------
6116
    --  Timing Check Section
6117
    ------------------------
6118
 
6119
    if (sum_lutc_input = "datac") then
6120
        -- combout 
6121
        combout_tmp := VitalMUX(data => lut_mask,
6122
                                dselect => (datad_ipd,
6123
                                            datac_ipd,
6124
                                            datab_ipd,
6125
                                            dataa_ipd));
6126
    elsif (sum_lutc_input = "cin") then
6127
        -- combout 
6128
        combout_tmp := VitalMUX(data => lut_mask,
6129
                                dselect => (datad_ipd,
6130
                                            cin_ipd,
6131
                                            datab_ipd,
6132
                                            dataa_ipd));
6133
    end if;
6134
 
6135
    -- cout 
6136
    cout_tmp := VitalMUX(data => lut_mask,
6137
                         dselect => ('0',
6138
                                     cin_ipd,
6139
                                     datab_ipd,
6140
                                     dataa_ipd));
6141
 
6142
    ----------------------
6143
    --  Path Delay Section
6144
    ----------------------
6145
 
6146
    VitalPathDelay01 (
6147
        OutSignal => combout,
6148
        OutSignalName => "COMBOUT",
6149
        OutTemp => combout_tmp,
6150
        Paths => (0 => (dataa_ipd'last_event, tpd_dataa_combout, TRUE),
6151
                  1 => (datab_ipd'last_event, tpd_datab_combout, TRUE),
6152
                  2 => (datac_ipd'last_event, tpd_datac_combout, TRUE),
6153
                  3 => (datad_ipd'last_event, tpd_datad_combout, TRUE),
6154
                  4 => (cin_ipd'last_event, tpd_cin_combout, TRUE)),
6155
        GlitchData => combout_VitalGlitchData,
6156
        Mode => DefGlitchMode,
6157
        XOn  => XOn,
6158
        MsgOn => MsgOn );
6159
 
6160
    VitalPathDelay01 (
6161
        OutSignal => cout,
6162
        OutSignalName => "COUT",
6163
        OutTemp => cout_tmp,
6164
        Paths => (0 => (dataa_ipd'last_event, tpd_dataa_cout, TRUE),
6165
                  1 => (datab_ipd'last_event, tpd_datab_cout, TRUE),
6166
                  2 => (datac_ipd'last_event, tpd_datac_cout, TRUE),
6167
                  3 => (datad_ipd'last_event, tpd_datad_cout, TRUE),
6168
                  4 => (cin_ipd'last_event, tpd_cin_cout, TRUE)),
6169
        GlitchData => cout_VitalGlitchData,
6170
        Mode => DefGlitchMode,
6171
        XOn  => XOn,
6172
        MsgOn => MsgOn );
6173
 
6174
end process;
6175
 
6176
end vital_lcell_comb;
6177
 
6178
--
6179
--
6180
--  CYCLONEII_ASYNCH_IO Model
6181
--
6182
--
6183
LIBRARY IEEE;
6184
use IEEE.std_logic_1164.all;
6185
use IEEE.std_logic_arith.all;
6186
use IEEE.VITAL_Timing.all;
6187
use IEEE.VITAL_Primitives.all;
6188
use work.cycloneii_atom_pack.all;
6189
 
6190
entity cycloneii_asynch_io is
6191
        generic(
6192
                operation_mode  : STRING := "input";
6193
                open_drain_output : STRING := "false";
6194
                bus_hold : STRING := "false";
6195
                use_differential_input : STRING := "false";
6196
 
6197
                XOn: Boolean := DefGlitchXOn;
6198
                MsgOn: Boolean := DefGlitchMsgOn;
6199
 
6200
                tpd_padio_differentialout    : VitalDelayType01 := DefPropDelay01;
6201
                tpd_differentialin_combout   : VitalDelayType01 := DefPropDelay01;
6202
 
6203
                tpd_datain_padio        : VitalDelayType01 := DefPropDelay01;
6204
                tpd_oe_padio_posedge       : VitalDelayType01 := DefPropDelay01;
6205
                tpd_oe_padio_negedge       : VitalDelayType01 := DefPropDelay01;
6206
                tpd_padio_combout   : VitalDelayType01 := DefPropDelay01;
6207
                tpd_regin_regout   : VitalDelayType01 := DefPropDelay01;
6208
 
6209
                tipd_differentialin : VitalDelayType01 := DefPropDelay01;
6210
 
6211
                tipd_datain         : VitalDelayType01 := DefPropDelay01;
6212
                tipd_oe             : VitalDelayType01 := DefPropDelay01;
6213
                tipd_padio          : VitalDelayType01 := DefPropDelay01);
6214
        port(
6215
                datain  : in  STD_LOGIC := '0';
6216
                oe      : in  STD_LOGIC := '1';
6217
                regin  : in STD_LOGIC;
6218
                differentialin  : in STD_LOGIC;
6219
                differentialout : out STD_LOGIC;
6220
                padio   : inout STD_LOGIC;
6221
                combout : out STD_LOGIC;
6222
                regout : out STD_LOGIC);
6223
 
6224
        attribute VITAL_LEVEL0 of cycloneii_asynch_io : entity is TRUE;
6225
end cycloneii_asynch_io;
6226
 
6227
architecture behave of cycloneii_asynch_io is
6228
attribute VITAL_LEVEL0 of behave : architecture is TRUE;
6229
 
6230
signal datain_ipd, oe_ipd, padio_ipd: std_logic;
6231
 
6232
signal differentialin_ipd: std_logic;
6233
 
6234
begin
6235
    ---------------------
6236
    --  INPUT PATH DELAYs
6237
    ---------------------
6238
    WireDelay : block
6239
    begin
6240
        VitalWireDelay (datain_ipd, datain, tipd_datain);
6241
        VitalWireDelay (differentialin_ipd, differentialin, tipd_differentialin);
6242
 
6243
        VitalWireDelay (oe_ipd, oe, tipd_oe);
6244
        VitalWireDelay (padio_ipd, padio, tipd_padio);
6245
    end block;
6246
 
6247
    VITAL: process(padio_ipd, datain_ipd, oe_ipd, regin, differentialin_ipd)
6248
        variable combout_VitalGlitchData : VitalGlitchDataType;
6249
                variable padio_VitalGlitchData : VitalGlitchDataType;
6250
        variable regout_VitalGlitchData : VitalGlitchDataType;
6251
 
6252
        variable tmp_combout, tmp_padio : std_logic;
6253
        variable prev_value : std_logic := 'H';
6254
 
6255
                variable differentialout_VitalGlitchData : VitalGlitchDataType;
6256
        variable tmp_combout_differentialin_or_pad : std_logic;
6257
        variable differentialout_tmp : std_logic;
6258
 
6259
 
6260
        begin
6261
 
6262
        if (bus_hold = "true" ) then
6263
                if ( operation_mode = "input") then
6264
                        if ( padio_ipd = 'Z') then
6265
                                tmp_combout := to_x01z(prev_value);
6266
                        else
6267
                                if ( padio_ipd = '1') then
6268
                                        prev_value := 'H';
6269
                                elsif ( padio_ipd = '0') then
6270
                                        prev_value := 'L';
6271
                                else
6272
                                        prev_value := 'W';
6273
                                end if;
6274
                                tmp_combout := to_x01z(padio_ipd);
6275
                        end if;
6276
                        tmp_padio := 'Z';
6277
                elsif ( operation_mode = "output" or operation_mode = "bidir") then
6278
                        if ( oe_ipd = '1') then
6279
                                if ( open_drain_output = "true" ) then
6280
                                        if (datain_ipd = '0') then
6281
                                                tmp_padio := '0';
6282
                                                prev_value := 'L';
6283
                                        elsif (datain_ipd = 'X') then
6284
                                                tmp_padio := 'X';
6285
                                                prev_value := 'W';
6286
                                        else   -- 'Z'
6287
                                                -- need to update prev_value
6288
                                                if (padio_ipd = '1') then
6289
                                                        prev_value := 'H';
6290
                                                elsif (padio_ipd = '0') then
6291
                                                        prev_value := 'L';
6292
                                                elsif (padio_ipd = 'X') then
6293
                                                        prev_value := 'W';
6294
                                                end if;
6295
                                                tmp_padio := prev_value;
6296
                                        end if;
6297
                                else
6298
                                        tmp_padio := datain_ipd;
6299
                                        if ( datain_ipd = '1') then
6300
                                                prev_value := 'H';
6301
                                        elsif (datain_ipd = '0' ) then
6302
                                                prev_value := 'L';
6303
                                        elsif ( datain_ipd = 'X') then
6304
                                                prev_value := 'W';
6305
                                        else
6306
                                                prev_value := datain_ipd;
6307
                                        end if;
6308
                                end if; -- end open_drain_output
6309
 
6310
                        elsif ( oe_ipd = '0' ) then
6311
                                -- need to update prev_value
6312
                                if (padio_ipd = '1') then
6313
                                        prev_value := 'H';
6314
                                elsif (padio_ipd = '0') then
6315
                                        prev_value := 'L';
6316
                                elsif (padio_ipd = 'X') then
6317
                                        prev_value := 'W';
6318
                                end if;
6319
                                tmp_padio := prev_value;
6320
                        else
6321
                                tmp_padio := 'X';
6322
                                prev_value := 'W';
6323
                        end if; -- end oe_in
6324
 
6325
                        if ( operation_mode = "bidir") then
6326
                                tmp_combout := to_x01z(padio_ipd);
6327
                        else
6328
                                tmp_combout := 'Z';
6329
                        end if;
6330
                end if;
6331
 
6332
                if ( now <= 1 ps AND prev_value = 'W' ) then     --hack for autotest to pass
6333
                        prev_value := 'L';
6334
                end if;
6335
 
6336
        else    -- bus_hold is false
6337
                if ( operation_mode = "input") then
6338
                        tmp_combout := padio_ipd;
6339
                        tmp_padio := 'Z';
6340
                elsif (operation_mode = "output" or operation_mode = "bidir" ) then
6341
                        if ( operation_mode  = "bidir") then
6342
                                tmp_combout := padio_ipd;
6343
                        else
6344
                                tmp_combout := 'Z';
6345
                        end if;
6346
 
6347
                        if ( oe_ipd = '1') then
6348
                                if ( open_drain_output = "true" ) then
6349
                                        if (datain_ipd = '0') then
6350
                                                tmp_padio := '0';
6351
                                        elsif (datain_ipd = 'X') then
6352
                                                tmp_padio := 'X';
6353
                                        else
6354
                                                tmp_padio := 'Z';
6355
                                        end if;
6356
                                else
6357
                                        tmp_padio := datain_ipd;
6358
                                end if;
6359
                        elsif ( oe_ipd = '0' ) then
6360
                                tmp_padio := 'Z';
6361
                        else
6362
                                tmp_padio := 'X';
6363
                        end if;
6364
                end if;
6365
        end if; -- end bus_hold
6366
 
6367
        if (use_differential_input = "true") then
6368
            tmp_combout_differentialin_or_pad := differentialin_ipd;
6369
        else
6370
            tmp_combout_differentialin_or_pad := tmp_combout;
6371
        end if;
6372
 
6373
        if (operation_mode = "input" or operation_mode = "bidir") then
6374
            differentialout_tmp := padio_ipd;
6375
        else
6376
            differentialout_tmp := 'X';
6377
        end if;
6378
 
6379
    ----------------------
6380
    --  Path Delay Section
6381
    ----------------------
6382
    VitalPathDelay01 (
6383
        OutSignal => combout,
6384
        OutSignalName => "combout",
6385
        OutTemp => tmp_combout_differentialin_or_pad,
6386
        Paths => (1 => (padio_ipd'last_event, tpd_padio_combout, use_differential_input = "false"),
6387
                  2 => (differentialin_ipd'last_event, tpd_differentialin_combout, use_differential_input = "true")),
6388
        GlitchData => combout_VitalGlitchData,
6389
        Mode => DefGlitchMode,
6390
        XOn  => XOn,
6391
        MsgOn  => MsgOn );
6392
 
6393
        VitalPathDelay01 (
6394
        OutSignal => padio,
6395
        OutSignalName => "padio",
6396
        OutTemp => tmp_padio,
6397
        Paths => (1 => (datain_ipd'last_event, tpd_datain_padio, TRUE),
6398
                  2 => (oe_ipd'last_event, tpd_oe_padio_posedge, oe_ipd = '1'),
6399
                  3 => (oe_ipd'last_event, tpd_oe_padio_negedge, oe_ipd = '0')),
6400
        GlitchData => padio_VitalGlitchData,
6401
        Mode => DefGlitchMode,
6402
        XOn  => XOn,
6403
        MsgOn  => MsgOn );
6404
 
6405
    VitalPathDelay01 (
6406
        OutSignal => regout,
6407
        OutSignalName => "regout",
6408
        OutTemp => regin,
6409
        Paths => (1 => (regin'last_event, tpd_regin_regout, TRUE)),
6410
        GlitchData => regout_VitalGlitchData,
6411
        Mode => DefGlitchMode,
6412
        XOn  => XOn,
6413
        MsgOn  => MsgOn );
6414
 
6415
        VitalPathDelay01 (
6416
        OutSignal => differentialout,
6417
        OutSignalName => "differentialout",
6418
        OutTemp => differentialout_tmp,
6419
        Paths => (1 => (padio_ipd'last_event, tpd_padio_differentialout, TRUE)),
6420
        GlitchData => differentialout_VitalGlitchData,
6421
        Mode => DefGlitchMode,
6422
        XOn  => XOn,
6423
        MsgOn  => MsgOn );
6424
 
6425
    end process;
6426
 
6427
end behave;
6428
 
6429
--
6430
-- CYCLONEII_IO
6431
--
6432
LIBRARY IEEE;
6433
use IEEE.std_logic_1164.all;
6434
use IEEE.VITAL_Timing.all;
6435
use IEEE.VITAL_Primitives.all;
6436
use work.cycloneii_atom_pack.all;
6437
use work.cycloneii_asynch_io;
6438
use work.cycloneii_dffe;
6439
use work.cycloneii_mux21;
6440
 
6441
entity  cycloneii_io is
6442
    generic (
6443
                operation_mode : string := "input";
6444
                open_drain_output : string := "false";
6445
                bus_hold : string := "false";
6446
                output_register_mode : string := "none";
6447
                output_async_reset : string := "none";
6448
                output_sync_reset : string := "none";
6449
                output_power_up : string := "low";
6450
                tie_off_output_clock_enable : string := "false";
6451
                oe_register_mode : string := "none";
6452
                oe_async_reset : string := "none";
6453
                oe_sync_reset : string := "none";
6454
                oe_power_up : string := "low";
6455
                tie_off_oe_clock_enable : string := "false";
6456
                input_register_mode : string := "none";
6457
                input_async_reset : string := "none";
6458
                input_sync_reset : string := "none";
6459
                use_differential_input  : string := "false";
6460
                lpm_type : string    := "cycloneii_io";
6461
                input_power_up : string := "low");
6462
        port (
6463
                datain          : in std_logic := '0';
6464
                oe              : in std_logic := '1';
6465
                outclk          : in std_logic := '0';
6466
                outclkena       : in std_logic := '1';
6467
                inclk           : in std_logic := '0';
6468
                inclkena        : in std_logic := '1';
6469
                areset          : in std_logic := '0';
6470
                sreset          : in std_logic := '0';
6471
                devclrn         : in std_logic := '1';
6472
                devpor          : in std_logic := '1';
6473
                devoe           : in std_logic := '1';
6474
                linkin          : in std_logic := '0';
6475
                differentialin  : in std_logic := '0';
6476
                differentialout : out std_logic;
6477
                linkout         : out std_logic;
6478
                combout         : out std_logic;
6479
                regout          : out std_logic;
6480
                padio           : inout std_logic
6481
    );
6482
end cycloneii_io;
6483
 
6484
architecture structure of cycloneii_io is
6485
component cycloneii_asynch_io
6486
        generic(
6487
                operation_mode : string := "input";
6488
                open_drain_output : string := "false";
6489
                use_differential_input : STRING := "false";
6490
                bus_hold : string := "false");
6491
        port(
6492
                datain : in  STD_LOGIC := '0';
6493
                oe         : in  STD_LOGIC := '0';
6494
                regin  : in std_logic;
6495
                differentialin  : in STD_LOGIC;
6496
                differentialout : out STD_LOGIC;
6497
                padio  : inout STD_LOGIC;
6498
                combout: out STD_LOGIC;
6499
                regout : out STD_LOGIC);
6500
end component;
6501
 
6502
component cycloneii_dffe
6503
   generic(
6504
      TimingChecksOn: Boolean := true;
6505
      InstancePath: STRING := "*";
6506
      XOn: Boolean := DefGlitchXOn;
6507
      MsgOn: Boolean := DefGlitchMsgOn;
6508
      MsgOnChecks: Boolean := DefMsgOnChecks;
6509
      XOnChecks: Boolean := DefXOnChecks;
6510
      tpd_PRN_Q_negedge              :  VitalDelayType01 := DefPropDelay01;
6511
      tpd_CLRN_Q_negedge             :  VitalDelayType01 := DefPropDelay01;
6512
      tpd_CLK_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
6513
      tpd_ENA_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
6514
      tsetup_D_CLK_noedge_posedge    :  VitalDelayType := DefSetupHoldCnst;
6515
      tsetup_D_CLK_noedge_negedge    :  VitalDelayType := DefSetupHoldCnst;
6516
      tsetup_ENA_CLK_noedge_posedge  :  VitalDelayType := DefSetupHoldCnst;
6517
      thold_D_CLK_noedge_posedge     :  VitalDelayType := DefSetupHoldCnst;
6518
      thold_D_CLK_noedge_negedge     :  VitalDelayType := DefSetupHoldCnst;
6519
      thold_ENA_CLK_noedge_posedge   :  VitalDelayType := DefSetupHoldCnst;
6520
      tipd_D                         :  VitalDelayType01 := DefPropDelay01;
6521
      tipd_CLRN                      :  VitalDelayType01 := DefPropDelay01;
6522
      tipd_PRN                       :  VitalDelayType01 := DefPropDelay01;
6523
      tipd_CLK                       :  VitalDelayType01 := DefPropDelay01;
6524
      tipd_ENA                       :  VitalDelayType01 := DefPropDelay01);
6525
 
6526
   port(
6527
      Q                              :  out   STD_LOGIC := '0';
6528
      D                              :  in    STD_LOGIC := '1';
6529
      CLRN                           :  in    STD_LOGIC := '1';
6530
      PRN                            :  in    STD_LOGIC := '1';
6531
      CLK                            :  in    STD_LOGIC := '0';
6532
      ENA                            :  in    STD_LOGIC := '1');
6533
end component;
6534
 
6535
component cycloneii_mux21
6536
        port (
6537
                A : in std_logic := '0';
6538
        B : in std_logic := '0';
6539
        S : in std_logic := '0';
6540
        MO : out std_logic);
6541
end component;
6542
 
6543
        signal  is_bidir_or_output : std_logic;
6544
        signal  out_reg_clk_ena, oe_reg_clk_ena : std_logic;
6545
 
6546
        signal  tmp_oe_reg_out, tmp_input_reg_out, tmp_output_reg_out : std_logic;
6547
 
6548
        signal  inreg_sreset_is_used, outreg_sreset_is_used, oereg_sreset_is_used : std_logic;
6549
 
6550
        signal  inreg_sreset, outreg_sreset, oereg_sreset : std_logic;
6551
 
6552
        signal  in_reg_aclr, in_reg_apreset : std_logic;
6553
 
6554
        signal  oe_reg_aclr, oe_reg_apreset, oe_reg_sel : std_logic;
6555
 
6556
        signal  out_reg_aclr, out_reg_apreset, out_reg_sel : std_logic;
6557
 
6558
        signal  input_reg_pu_low, output_reg_pu_low, oe_reg_pu_low : std_logic;
6559
 
6560
        signal  inreg_D, outreg_D, oereg_D : std_logic;
6561
 
6562
        signal  tmp_datain, tmp_oe : std_logic;
6563
 
6564
        signal  iareset, isreset : std_logic;
6565
 
6566
        signal  inreg_mux_sel, outreg_mux_sel, oereg_mux_sel : std_logic;
6567
 
6568
        signal  input_dffe_aclr, input_dffe_apreset, output_dffe_aclr, output_dffe_apreset : std_logic;
6569
        signal  oe_dffe_aclr, oe_dffe_apreset : std_logic;
6570
 
6571
    signal  pad_or_differentialin : std_logic;
6572
 
6573
begin
6574
 
6575
is_bidir_or_output <= '1' WHEN (operation_mode = "bidir" OR operation_mode = "output") ELSE '0';
6576
 
6577
input_reg_pu_low <=  '0' WHEN input_power_up = "low" ELSE '1';
6578
output_reg_pu_low <= '0' WHEN output_power_up = "low" ELSE '1';
6579
oe_reg_pu_low <= '0' WHEN oe_power_up = "low" ELSE '1';
6580
 
6581
out_reg_sel <= '1' WHEN output_register_mode = "register" ELSE '0';
6582
oe_reg_sel <= '1' WHEN oe_register_mode = "register" ELSE '0';
6583
 
6584
iareset <= (NOT areset) WHEN ( areset = '1' OR areset = '0') ELSE '1';
6585
isreset <= sreset WHEN ( areset = '1' OR areset = '0') ELSE '0';
6586
 
6587
 
6588
-- output registere signals
6589
out_reg_aclr <= iareset WHEN output_async_reset = "clear" ELSE '1';
6590
out_reg_apreset <= iareset WHEN output_async_reset = "preset" ELSE '1';
6591
outreg_sreset_is_used <= '0' WHEN output_sync_reset = "none" ELSE '1';
6592
outreg_sreset <= '0' WHEN output_sync_reset = "clear" ELSE '1';
6593
 
6594
-- oe register signals
6595
oe_reg_aclr <= iareset WHEN oe_async_reset = "clear" ELSE '1';
6596
oe_reg_apreset <= iareset WHEN oe_async_reset = "preset" ELSE '1';
6597
oereg_sreset_is_used <= '0' WHEN oe_sync_reset = "none" ELSE '1';
6598
oereg_sreset <= '0' WHEN oe_sync_reset = "clear" ELSE '1';
6599
 
6600
-- input register signals
6601
in_reg_aclr <= iareset WHEN input_async_reset = "clear" ELSE '1';
6602
in_reg_apreset <= iareset WHEN input_async_reset = "preset" ELSE '1';
6603
inreg_sreset_is_used <= '0' WHEN input_sync_reset = "none" ELSE '1';
6604
inreg_sreset <= '0' WHEN input_sync_reset = "clear" ELSE '1';
6605
 
6606
-- oe and output register clock enable signals
6607
out_reg_clk_ena <= '1' WHEN tie_off_output_clock_enable = "true" ELSE outclkena;
6608
oe_reg_clk_ena <= '1' WHEN tie_off_oe_clock_enable = "true" ELSE outclkena;
6609
 
6610
-- input register
6611
inreg_mux_sel <= isreset AND inreg_sreset_is_used;
6612
input_dffe_aclr  <= in_reg_aclr AND devclrn AND (input_reg_pu_low OR devpor);
6613
input_dffe_apreset <= in_reg_apreset AND ( (NOT input_reg_pu_low) OR devpor);
6614
 
6615
-- differentialin 
6616
pad_or_differentialin <= differentialin WHEN use_differential_input = "true" ELSE padio;
6617
 
6618
inreg_D_mux : cycloneii_mux21
6619
        port map ( A => pad_or_differentialin,
6620
                           B => inreg_sreset,
6621
                           S => inreg_mux_sel,
6622
                           MO=> inreg_D);
6623
 
6624
input_reg : cycloneii_dffe
6625
        port map (D => inreg_D,
6626
              CLRN => input_dffe_aclr,
6627
              PRN => input_dffe_apreset,
6628
              CLK => inclk,
6629
              ENA => inclkena,
6630
              Q => tmp_input_reg_out);
6631
 
6632
-- output register
6633
outreg_mux_sel <= isreset AND outreg_sreset_is_used;
6634
output_dffe_aclr <= out_reg_aclr AND devclrn AND (output_reg_pu_low OR devpor);
6635
output_dffe_apreset <= out_reg_apreset AND ( (NOT output_reg_pu_low) OR devpor);
6636
outreg_D_mux : cycloneii_mux21
6637
        port map ( A => datain,
6638
                           B => outreg_sreset,
6639
                           S => outreg_mux_sel,
6640
                           MO=> outreg_D);
6641
 
6642
output_reg : cycloneii_dffe
6643
        port map (D => outreg_D,
6644
              CLRN => output_dffe_aclr,
6645
              PRN => output_dffe_apreset,
6646
              CLK => outclk,
6647
              ENA => out_reg_clk_ena,
6648
              Q => tmp_output_reg_out);
6649
 
6650
-- oe register
6651
oereg_mux_sel <= isreset AND oereg_sreset_is_used;
6652
oe_dffe_aclr <= oe_reg_aclr AND devclrn AND (oe_reg_pu_low OR devpor);
6653
oe_dffe_apreset <= oe_reg_apreset AND ( (NOT oe_reg_pu_low) OR devpor);
6654
 
6655
oereg_D_mux : cycloneii_mux21
6656
        port map ( A => oe,
6657
                           B => oereg_sreset,
6658
                           S => oereg_mux_sel,
6659
                           MO=> oereg_D);
6660
 
6661
oe_reg : cycloneii_dffe
6662
        port map (D => oereg_D,
6663
              CLRN => oe_dffe_aclr,
6664
              PRN => oe_dffe_apreset,
6665
              CLK => outclk,
6666
              ENA => oe_reg_clk_ena,
6667
              Q => tmp_oe_reg_out);
6668
 
6669
 
6670
-- asynchrous block
6671
tmp_oe <= tmp_oe_reg_out WHEN oe_reg_sel = '1' ELSE oe;
6672
tmp_datain <= tmp_output_reg_out WHEN (is_bidir_or_output = '1' AND out_reg_sel = '1') ELSE datain;
6673
 
6674
asynch_inst : cycloneii_asynch_io
6675
        generic map (OPERATION_MODE => operation_mode,
6676
                                 OPEN_DRAIN_OUTPUT => open_drain_output,
6677
                                 USE_DIFFERENTIAL_INPUT => use_differential_input,
6678
                                 BUS_HOLD => bus_hold)
6679
        port map (datain => tmp_datain,
6680
              oe => tmp_oe,
6681
              regin => tmp_input_reg_out,
6682
              differentialin => differentialin,
6683
              differentialout => differentialout,
6684
              padio => padio,
6685
              combout => combout,
6686
              regout => regout);
6687
 
6688
end structure;
6689
 
6690
 
6691
--/////////////////////////////////////////////////////////////////////////////
6692
--
6693
--          VHDL Simulation Model for Cyclone II CLK DELAY CTRL Atom
6694
--
6695
--/////////////////////////////////////////////////////////////////////////////
6696
 
6697
--
6698
--
6699
--  CYCLONEII_CLKCTRL Model
6700
--
6701
--
6702
 
6703
LIBRARY IEEE;
6704
use IEEE.std_logic_1164.all;
6705
use IEEE.std_logic_unsigned.all;
6706
use IEEE.VITAL_Timing.all;
6707
use IEEE.VITAL_Primitives.all;
6708
use work.cycloneii_atom_pack.all;
6709
 
6710
entity cycloneii_clk_delay_ctrl is
6711
    generic (
6712
             behavioral_sim_delay : integer := 0;
6713
             delay_chain          : STRING := "54";
6714
             delay_chain_mode     : STRING := "static";
6715
             uses_calibration     : STRING := "false";
6716
             use_new_style_dq_detection : STRING := "false";
6717
             tan_delay_under_delay_ctrl_signal :    STRING := "unused";
6718
             delay_ctrl_sim_delay_15_0  : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6719
             delay_ctrl_sim_delay_31_16 : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6720
             delay_ctrl_sim_delay_47_32 : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6721
             delay_ctrl_sim_delay_63_48 : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6722
             lpm_type : STRING    := "cycloneii_clk_delay_ctrl";
6723
             TimingChecksOn : Boolean := True;
6724
             MsgOn : Boolean := DefGlitchMsgOn;
6725
             XOn : Boolean := DefGlitchXOn;
6726
             MsgOnChecks : Boolean := DefMsgOnChecks;
6727
             XOnChecks : Boolean := DefXOnChecks;
6728
             InstancePath : STRING := "*";
6729
             tpd_clk_clkout                : VitalDelayType01 := DefPropDelay01;
6730
             tpd_disablecalibration_clkout : VitalDelayType01 := DefPropDelay01;
6731
             tpd_pllcalibrateclkdelayedin_clkout : VitalDelayType01 := DefPropDelay01;
6732
             tipd_clk                      : VitalDelayType01 := DefPropDelay01;
6733
             tipd_delayctrlin              : VitalDelayArrayType01(5 downto 0) := (OTHERS => DefPropDelay01);
6734
             tipd_disablecalibration       : VitalDelayType01 := DefPropDelay01;
6735
             tipd_pllcalibrateclkdelayedin : VitalDelayType01 := DefPropDelay01
6736
             );
6737
    port (
6738
             clk                : in std_logic := '0';
6739
             delayctrlin        : in std_logic_vector(5 downto 0) := "000000";
6740
             disablecalibration : in std_logic := '1';
6741
             pllcalibrateclkdelayedin: in std_logic := '0';
6742
             devclrn     : in std_logic := '1';
6743
             devpor      : in std_logic := '1';
6744
             clkout      : out std_logic
6745
                 );
6746
   attribute VITAL_LEVEL0 of cycloneii_clk_delay_ctrl : entity is TRUE;
6747
end cycloneii_clk_delay_ctrl;
6748
 
6749
architecture vital_clk_delay_ctrl of cycloneii_clk_delay_ctrl is
6750
    attribute VITAL_LEVEL0 of vital_clk_delay_ctrl : architecture is TRUE;
6751
 
6752
type cycloneii_clkdlyctrl_int_vec is array (natural range <>) of integer;
6753
 
6754
    signal clk_ipd                      : std_logic;
6755
    signal delayctrlin_ipd              : std_logic_vector(5 downto 0);
6756
    signal disablecalibration_ipd       : std_logic;
6757
    signal pllcalibrateclkdelayedin_ipd : std_logic := '0';
6758
 
6759
    signal dqs_dynamic_dly_si : integer := 0;
6760
begin
6761
 
6762
    ---------------------
6763
    --  INPUT PATH DELAYs
6764
    ---------------------
6765
    WireDelay : block
6766
    begin
6767
        VitalWireDelay (clk_ipd, clk, tipd_clk);
6768
        VitalWireDelay (delayctrlin_ipd(0), delayctrlin(0), tipd_delayctrlin(0));
6769
        VitalWireDelay (delayctrlin_ipd(1), delayctrlin(1), tipd_delayctrlin(1));
6770
        VitalWireDelay (delayctrlin_ipd(2), delayctrlin(2), tipd_delayctrlin(2));
6771
        VitalWireDelay (delayctrlin_ipd(3), delayctrlin(3), tipd_delayctrlin(3));
6772
        VitalWireDelay (delayctrlin_ipd(4), delayctrlin(4), tipd_delayctrlin(4));
6773
        VitalWireDelay (delayctrlin_ipd(5), delayctrlin(5), tipd_delayctrlin(5));
6774
        VitalWireDelay (disablecalibration_ipd, disablecalibration, tipd_disablecalibration);
6775
        VitalWireDelay (pllcalibrateclkdelayedin_ipd, pllcalibrateclkdelayedin, tipd_pllcalibrateclkdelayedin);
6776
    end block;
6777
 
6778
    --  generate dynamic delay table and dynamic delay       
6779
    process(delayctrlin_ipd)
6780
        variable init : boolean := true;
6781
                variable i : natural := 0;
6782
        variable w_index_l : integer := 0;
6783
        variable sim_dly_all : std_logic_vector(2047 downto 0) := (OTHERS => '0');
6784
        variable dly_table : cycloneii_clkdlyctrl_int_vec(63 downto 0) := (OTHERS => 0);
6785
        variable dly_index : integer := 0;
6786
    begin
6787
        if (init) then
6788
            sim_dly_all := delay_ctrl_sim_delay_63_48 & delay_ctrl_sim_delay_47_32 & delay_ctrl_sim_delay_31_16 & delay_ctrl_sim_delay_15_0;
6789
            while ( i < 64 ) loop
6790
                w_index_l := 32*i;
6791
                dly_table(i) := conv_integer(sim_dly_all((w_index_l + 31) downto w_index_l));
6792
                i := i + 1;
6793
            end loop;
6794
 
6795
            init := false;
6796
        end if;
6797
 
6798
        dly_index := conv_integer(delayctrlin_ipd);
6799
        if (dly_index >= 0 and dly_index < 64) then
6800
            dqs_dynamic_dly_si <= dly_table(dly_index);
6801
        end if;
6802
 
6803
    end process;
6804
 
6805
    VITAL: process(clk_ipd, pllcalibrateclkdelayedin_ipd, disablecalibration_ipd)
6806
        variable clkout_VitalGlitchData : VitalGlitchDataType;
6807
        variable clkout_delay : VitalDelayType01 := (0 ps, 0 ps);
6808
        variable use_calib_clk : std_logic := '0';
6809
        variable clkout_tmp : std_logic := '0';
6810
    begin
6811
        if ((uses_calibration = "true") and (disablecalibration_ipd = '0')) then
6812
            use_calib_clk := '1';
6813
            clkout_tmp := pllcalibrateclkdelayedin_ipd;
6814
            clkout_delay := tpd_pllcalibrateclkdelayedin_clkout;
6815
        else
6816
            use_calib_clk := '0';
6817
            clkout_tmp := clk_ipd;
6818
            if (delay_chain_mode = "static") then
6819
                clkout_delay := tpd_clk_clkout; -- contains behavioral_sim_delay in timing sim
6820
                for i in clkout_delay'range loop
6821
                    clkout_delay(i) := clkout_delay(i) + (behavioral_sim_delay * 1 ps);
6822
                end loop;
6823
            elsif (delay_chain_mode = "dynamic") then
6824
                clkout_delay := (0 ps, 0 ps);
6825
                for i in clkout_delay'range loop
6826
                    clkout_delay(i) := clkout_delay(i) + (dqs_dynamic_dly_si * 1 ps);
6827
                end loop;
6828
            end if;
6829
        end if;
6830
 
6831
        ----------------------
6832
        --  Path Delay Section
6833
        ----------------------
6834
        VitalPathDelay01 (
6835
            OutSignal => clkout,
6836
            OutSignalName => "clkout",
6837
            OutTemp => clkout_tmp,
6838
            Paths => (0 => (pllcalibrateclkdelayedin_ipd'last_event, clkout_delay, use_calib_clk = '1'),
6839
                      1 => (clk_ipd'last_event, clkout_delay, use_calib_clk = '0')),
6840
            GlitchData => clkout_VitalGlitchData,
6841
            Mode => DefGlitchMode,
6842
            XOn  => XOn,
6843
            MsgOn  => MsgOn );
6844
 
6845
    end process;
6846
 
6847
end vital_clk_delay_ctrl;
6848
 
6849
 
6850
--/////////////////////////////////////////////////////////////////////////////
6851
--
6852
--    VHDL Simulation Model for Cyclone II CLK DELAY Calibration CTRL Atom
6853
--
6854
--/////////////////////////////////////////////////////////////////////////////
6855
 
6856
--
6857
--
6858
--  CYCLONEII_CLK_DELAY_CAL_CTRL ATOM Model
6859
--
6860
--
6861
 
6862
LIBRARY IEEE;
6863
use IEEE.std_logic_1164.all;
6864
use IEEE.std_logic_unsigned.all;
6865
use IEEE.VITAL_Timing.all;
6866
use IEEE.VITAL_Primitives.all;
6867
use work.cycloneii_atom_pack.all;
6868
 
6869
entity cycloneii_clk_delay_cal_ctrl is
6870
    generic (
6871
             delay_ctrl_sim_delay_15_0  : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6872
             delay_ctrl_sim_delay_31_16 : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6873
             delay_ctrl_sim_delay_47_32 : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6874
             delay_ctrl_sim_delay_63_48 : STD_LOGIC_VECTOR(511 downto 0) := (OTHERS => '0');
6875
             lpm_type : STRING    := "cycloneii_clk_delay_cal_ctrl";
6876
             TimingChecksOn : Boolean := True;
6877
             MsgOn : Boolean := DefGlitchMsgOn;
6878
             XOn : Boolean := DefGlitchXOn;
6879
             MsgOnChecks : Boolean := DefMsgOnChecks;
6880
             XOnChecks : Boolean := DefXOnChecks;
6881
             InstancePath : STRING := "*";
6882
             tpd_plldataclk_calibratedata                     : VitalDelayType01 := DefPropDelay01;
6883
             tpd_disablecalibration_calibratedata             : VitalDelayType01 := DefPropDelay01;
6884
             tpd_pllcalibrateclk_pllcalibrateclkdelayedout    : VitalDelayType01 := DefPropDelay01;
6885
             tpd_disablecalibration_pllcalibrateclkdelayedout : VitalDelayType01 := DefPropDelay01;
6886
             tipd_plldataclk             : VitalDelayType01 := DefPropDelay01;
6887
             tipd_pllcalibrateclk        : VitalDelayType01 := DefPropDelay01;
6888
             tipd_delayctrlin            : VitalDelayArrayType01(5 downto 0) := (OTHERS => DefPropDelay01);
6889
             tipd_disablecalibration     : VitalDelayType01 := DefPropDelay01
6890
             );
6891
    port (
6892
             plldataclk                  : in std_logic := '0';
6893
             pllcalibrateclk             : in std_logic := '0';
6894
             disablecalibration          : in std_logic := '1';
6895
             delayctrlin                 : in std_logic_vector(5 downto 0) := "000000";
6896
             devclrn                     : in std_logic := '1';
6897
             devpor                      : in std_logic := '1';
6898
             calibratedata               : out std_logic;
6899
             pllcalibrateclkdelayedout   : out std_logic
6900
                 );
6901
    attribute VITAL_LEVEL0 of cycloneii_clk_delay_cal_ctrl : entity is TRUE;
6902
end cycloneii_clk_delay_cal_ctrl;
6903
 
6904
architecture vital_clk_delay_cal_ctrl of cycloneii_clk_delay_cal_ctrl is
6905
    attribute VITAL_LEVEL0 of vital_clk_delay_cal_ctrl : architecture is TRUE;
6906
 
6907
type cycloneii_clkdlycal_int_vec is array (natural range <>) of integer;
6908
 
6909
    signal plldataclk_ipd               : std_logic := '0';
6910
    signal pllcalibrateclk_ipd          : std_logic := '0';
6911
    signal delayctrlin_ipd              : std_logic_vector(5 downto 0) := "000000";
6912
    signal disablecalibration_ipd       : std_logic := '0';
6913
 
6914
 
6915
    signal cal_clk_prev                                 : std_logic := 'X';
6916
    signal cal_data_prev                                : std_logic := 'X';
6917
    signal by2_areset                                   : std_logic := '0';
6918
    signal cal_clk_by2_s                : std_logic := '0';
6919
    signal cal_data_by2_s               : std_logic := '0';
6920
    signal dqs_dynamic_dly_si           : integer := 0;
6921
begin
6922
 
6923
    ---------------------
6924
    --  INPUT PATH DELAYs
6925
    ---------------------
6926
    WireDelay : block
6927
    begin
6928
        VitalWireDelay (plldataclk_ipd, plldataclk, tipd_plldataclk);
6929
        VitalWireDelay (pllcalibrateclk_ipd, pllcalibrateclk, tipd_pllcalibrateclk);
6930
        VitalWireDelay (delayctrlin_ipd(0), delayctrlin(0), tipd_delayctrlin(0));
6931
        VitalWireDelay (delayctrlin_ipd(1), delayctrlin(1), tipd_delayctrlin(1));
6932
        VitalWireDelay (delayctrlin_ipd(2), delayctrlin(2), tipd_delayctrlin(2));
6933
        VitalWireDelay (delayctrlin_ipd(3), delayctrlin(3), tipd_delayctrlin(3));
6934
        VitalWireDelay (delayctrlin_ipd(4), delayctrlin(4), tipd_delayctrlin(4));
6935
        VitalWireDelay (delayctrlin_ipd(5), delayctrlin(5), tipd_delayctrlin(5));
6936
        VitalWireDelay (disablecalibration_ipd, disablecalibration, tipd_disablecalibration);
6937
    end block;
6938
 
6939
    --  generate dynamic delay table and dynamic delay       
6940
    process(delayctrlin_ipd)
6941
        variable init : boolean := true;
6942
                variable i : natural := 0;
6943
        variable w_index_l : integer := 0;
6944
        variable sim_dly_all : std_logic_vector(2047 downto 0) := (OTHERS => '0');
6945
        variable dly_table : cycloneii_clkdlycal_int_vec(63 downto 0) := (OTHERS => 0);
6946
        variable dly_index : integer := 0;
6947
    begin
6948
        if (init) then
6949
            i := 0;
6950
            sim_dly_all := delay_ctrl_sim_delay_63_48 & delay_ctrl_sim_delay_47_32 & delay_ctrl_sim_delay_31_16 & delay_ctrl_sim_delay_15_0;
6951
            while ( i < 64 ) loop
6952
                w_index_l := 32*i;
6953
                dly_table(i) := conv_integer(sim_dly_all((w_index_l + 31) downto w_index_l));
6954
                i := i + 1;
6955
            end loop;
6956
 
6957
            init := false;
6958
        end if;
6959
 
6960
        dly_index := conv_integer(delayctrlin_ipd);
6961
        if (dly_index >= 0 and dly_index < 64) then
6962
            dqs_dynamic_dly_si <= dly_table(dly_index);
6963
        end if;
6964
 
6965
    end process;
6966
 
6967
    -- internal clocks
6968
    by2_areset <= disablecalibration_ipd or (NOT devclrn) or (NOT devpor);
6969
 
6970
    process(pllcalibrateclk_ipd, by2_areset)
6971
    begin
6972
        if (by2_areset = '1' and by2_areset'event) then
6973
            cal_clk_prev <= 'X';
6974
            cal_clk_by2_s <= '0';
6975
        elsif (by2_areset /= '1' and pllcalibrateclk_ipd'event) then
6976
            cal_clk_prev <= pllcalibrateclk_ipd;
6977
            if (pllcalibrateclk_ipd = '1' and cal_clk_prev /= 'X') then
6978
                cal_clk_by2_s <=  not cal_clk_by2_s;
6979
            end if;
6980
        end if;
6981
    end process;
6982
 
6983
    process(plldataclk_ipd, by2_areset)
6984
    begin
6985
        if (by2_areset = '1' and by2_areset'event) then
6986
            cal_data_by2_s <= '0';
6987
            cal_data_prev <= 'X';
6988
        elsif (by2_areset /= '1' and plldataclk_ipd'event) then
6989
            cal_data_prev <= plldataclk_ipd;
6990
            if (plldataclk_ipd = '1' and cal_data_prev /= 'X') then
6991
                cal_data_by2_s <=  not cal_data_by2_s;
6992
            end if;
6993
        end if;
6994
 
6995
    end process;
6996
 
6997
    -- timing and delay
6998
 
6999
    VITAL: process(plldataclk_ipd, pllcalibrateclk_ipd, by2_areset, cal_data_by2_s, cal_clk_by2_s)
7000
        variable calibratedata_VitalGlitchData : VitalGlitchDataType;
7001
        variable pllcalibrateclkdelayedout_VitalGlitchData : VitalGlitchDataType;
7002
        variable calclkout_delay : VitalDelayType01 := (0 ps, 0 ps);
7003
    begin
7004
        calclkout_delay := (0 ps, 0 ps); -- included in delay chain
7005
        for i in calclkout_delay'range loop
7006
            calclkout_delay(i) := calclkout_delay(i) + (dqs_dynamic_dly_si * 1 ps);
7007
        end loop;
7008
 
7009
        ----------------------
7010
        --  Path Delay Section
7011
        ----------------------
7012
        VitalPathDelay01 (
7013
            OutSignal     => calibratedata,
7014
            OutSignalName => "calibratedata",
7015
            OutTemp       => cal_data_by2_s,
7016
            Paths => (0 => (by2_areset'last_event, tpd_disablecalibration_calibratedata, (by2_areset = '1')),
7017
                      1 => (plldataclk_ipd'last_event, tpd_plldataclk_calibratedata, (by2_areset = '0'))),
7018
            GlitchData    => calibratedata_VitalGlitchData,
7019
            Mode          => DefGlitchMode,
7020
            XOn           => XOn,
7021
            MsgOn         => MsgOn );
7022
 
7023
        VitalPathDelay01 (
7024
            OutSignal     => pllcalibrateclkdelayedout,
7025
            OutSignalName => "pllcalibrateclkdelayedout",
7026
            OutTemp       => cal_clk_by2_s,
7027
            Paths => (0 => (by2_areset'last_event, calclkout_delay, (by2_areset = '1')),
7028
                      1 => (pllcalibrateclk_ipd'last_event, calclkout_delay, (by2_areset = '0'))),
7029
            GlitchData    => pllcalibrateclkdelayedout_VitalGlitchData,
7030
            Mode          => DefGlitchMode,
7031
            XOn           => XOn,
7032
            MsgOn         => MsgOn );
7033
 
7034
    end process;
7035
 
7036
end vital_clk_delay_cal_ctrl;
7037
 
7038
-----------------------------------------------------------------------
7039
--
7040
-- Module Name : cycloneii_mac_data_reg
7041
--
7042
-- Description : Simulation model for the data input register of 
7043
--               Cyclone II MAC_MULT
7044
--
7045
-----------------------------------------------------------------------
7046
 
7047
LIBRARY IEEE;
7048
USE IEEE.VITAL_Primitives.all;
7049
USE IEEE.VITAL_Timing.all;
7050
USE IEEE.std_logic_1164.all;
7051
USE work.cycloneii_atom_pack.all;
7052
 
7053
ENTITY cycloneii_mac_data_reg IS
7054
    GENERIC (
7055
             TimingChecksOn : Boolean := True;
7056
             MsgOn : Boolean := DefGlitchMsgOn;
7057
             XOn : Boolean := DefGlitchXOn;
7058
             MsgOnChecks : Boolean := DefMsgOnChecks;
7059
             XOnChecks : Boolean := DefXOnChecks;
7060
             InstancePath : STRING := "*";
7061
             tipd_data : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
7062
             tipd_clk : VitalDelayType01 := DefPropDelay01;
7063
             tipd_ena : VitalDelayType01 := DefPropDelay01;
7064
             tipd_aclr : VitalDelayType01 := DefPropDelay01;
7065
                 tsetup_data_clk_noedge_posedge : VitalDelayArrayType(17 downto 0) := (OTHERS => DefSetupHoldCnst);
7066
                 thold_data_clk_noedge_posedge : VitalDelayArrayType(17 downto 0) := (OTHERS => DefSetupHoldCnst);
7067
             tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7068
                 thold_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7069
             tpd_aclr_dataout_posedge : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
7070
             tpd_clk_dataout_posedge : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
7071
             data_width : integer := 18
7072
            );
7073
    PORT (
7074
          -- INPUT PORTS
7075
          clk : IN std_logic;
7076
          data : IN std_logic_vector(17 DOWNTO 0);
7077
          ena : IN std_logic;
7078
          aclr : IN std_logic;
7079
          -- OUTPUT PORTS
7080
          dataout : OUT std_logic_vector(17 DOWNTO 0)
7081
         );
7082
END cycloneii_mac_data_reg;
7083
 
7084
ARCHITECTURE vital_cycloneii_mac_data_reg OF cycloneii_mac_data_reg IS
7085
 
7086
    SIGNAL data_ipd : std_logic_vector(17 DOWNTO 0);
7087
    SIGNAL aclr_ipd : std_logic;
7088
    SIGNAL clk_ipd : std_logic;
7089
    SIGNAL ena_ipd : std_logic;
7090
    SIGNAL dataout_tmp : std_logic_vector(17 DOWNTO 0) := (OTHERS => '0');
7091
 
7092
BEGIN
7093
 
7094
    ---------------------
7095
    --  INPUT PATH DELAYs
7096
    ---------------------
7097
    WireDelay : block
7098
    begin
7099
        g1 : for i in data'range generate
7100
            VitalWireDelay (data_ipd(i), data(i), tipd_data(i));
7101
        end generate;
7102
        VitalWireDelay (clk_ipd, clk, tipd_clk);
7103
        VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
7104
        VitalWireDelay (ena_ipd, ena, tipd_ena);
7105
    end block;
7106
 
7107
 
7108
    process (clk_ipd, aclr_ipd, data_ipd)
7109
        begin
7110
    if (aclr_ipd = '1') then
7111
            dataout_tmp <= (OTHERS => '0');
7112
        elsif (clk_ipd'event and clk_ipd = '1' and (ena_ipd = '1')) then
7113
            dataout_tmp <= data_ipd;
7114
        end if;
7115
 
7116
    end process;
7117
 
7118
    sh: block
7119
                begin
7120
                g0 : for i in data'range generate
7121
        process (data_ipd(i),clk_ipd,ena_ipd)
7122
    variable Tviol_data_clk : std_ulogic := '0';
7123
    variable TimingData_data_clk : VitalTimingDataType := VitalTimingDataInit;
7124
    variable Tviol_ena_clk : std_ulogic := '0';
7125
    variable TimingData_ena_clk : VitalTimingDataType := VitalTimingDataInit;
7126
    begin
7127
 
7128
        ------------------------
7129
        --  Timing Check Section
7130
        ------------------------
7131
        if (TimingChecksOn) then
7132
 
7133
            VitalSetupHoldCheck (
7134
                Violation       => Tviol_data_clk,
7135
                TimingData      => TimingData_data_clk,
7136
                TestSignal      => data_ipd(i),
7137
                TestSignalName  => "DATA(i)",
7138
                RefSignal       => clk_ipd,
7139
                RefSignalName   => "CLK",
7140
                SetupHigh       => tsetup_data_clk_noedge_posedge(i),
7141
                SetupLow        => tsetup_data_clk_noedge_posedge(i),
7142
                HoldHigh        => thold_data_clk_noedge_posedge(i),
7143
                HoldLow         => thold_data_clk_noedge_posedge(i),
7144
                CheckEnabled    => TO_X01((aclr) OR
7145
                                          (NOT ena)) /= '1',
7146
                RefTransition   => '/',
7147
                HeaderMsg       => InstancePath & "/MAC_DATA_REG",
7148
                XOn             => XOnChecks,
7149
                MsgOn           => MsgOnChecks );
7150
 
7151
            VitalSetupHoldCheck (
7152
                Violation       => Tviol_ena_clk,
7153
                TimingData      => TimingData_ena_clk,
7154
                TestSignal      => ena_ipd,
7155
                TestSignalName  => "ENA",
7156
                RefSignal       => clk_ipd,
7157
                RefSignalName   => "CLK",
7158
                SetupHigh       => tsetup_ena_clk_noedge_posedge,
7159
                SetupLow        => tsetup_ena_clk_noedge_posedge,
7160
                HoldHigh        => thold_ena_clk_noedge_posedge,
7161
                HoldLow         => thold_ena_clk_noedge_posedge,
7162
                CheckEnabled    => TO_X01(aclr)  /= '1',
7163
                RefTransition   => '/',
7164
                HeaderMsg       => InstancePath & "/MAC_DATA_REG",
7165
                XOn             => XOnChecks,
7166
                MsgOn           => MsgOnChecks );
7167
 
7168
        end if;
7169
 
7170
    END PROCESS;
7171
    end generate g0;
7172
    end block;
7173
 
7174
    ----------------------
7175
    --  Path Delay Section
7176
    ----------------------
7177
    PathDelay : block
7178
    begin
7179
        g1 : for i in dataout_tmp'range generate
7180
          VITALtiming :  process (dataout_tmp(i))
7181
              variable dataout_VitalGlitchData : VitalGlitchDataType;
7182
          begin
7183
            VitalPathDelay01 (OutSignal => dataout(i),
7184
                              OutSignalName => "DATAOUT",
7185
                              OutTemp => dataout_tmp(i),
7186
                              Paths => (0 => (clk_ipd'last_event,  tpd_clk_dataout_posedge(i),  TRUE),
7187
                                        1 => (aclr_ipd'last_event, tpd_aclr_dataout_posedge(i), TRUE)),
7188
                              GlitchData => dataout_VitalGlitchData,
7189
                              Mode => DefGlitchMode,
7190
                              XOn  => XOn,
7191
                              MsgOn  => MsgOn);
7192
          end process;
7193
        end generate;
7194
    end block;
7195
 
7196
END vital_cycloneii_mac_data_reg;
7197
 
7198
--------------------------------------------------------------------
7199
--
7200
-- Module Name : cycloneii_mac_sign_reg
7201
--
7202
-- Description : Simulation model for the sign input register of 
7203
--               Cyclone II MAC_MULT
7204
--
7205
--------------------------------------------------------------------
7206
 
7207
LIBRARY IEEE;
7208
USE IEEE.VITAL_Primitives.all;
7209
USE IEEE.VITAL_Timing.all;
7210
USE IEEE.std_logic_1164.all;
7211
USE work.cycloneii_atom_pack.all;
7212
 
7213
ENTITY cycloneii_mac_sign_reg IS
7214
    GENERIC (
7215
             TimingChecksOn : Boolean := True;
7216
             MsgOn : Boolean := DefGlitchMsgOn;
7217
             XOn : Boolean := DefGlitchXOn;
7218
             MsgOnChecks : Boolean := DefMsgOnChecks;
7219
             XOnChecks : Boolean := DefXOnChecks;
7220
             InstancePath : STRING := "*";
7221
             tsetup_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7222
             thold_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7223
             tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7224
             thold_ena_clk_noedge_posedge       : VitalDelayType := DefSetupHoldCnst;
7225
             tpd_clk_q_posedge : VitalDelayType01 := DefPropDelay01;
7226
             tpd_aclr_q_posedge : VitalDelayType01 := DefPropDelay01;
7227
             tipd_d : VitalDelayType01 := DefPropDelay01;
7228
             tipd_ena : VitalDelayType01 := DefPropDelay01;
7229
             tipd_aclr : VitalDelayType01 := DefPropDelay01;
7230
             tipd_clk : VitalDelayType01 := DefPropDelay01
7231
            );
7232
    PORT (
7233
          -- INPUT PORTS
7234
          clk : IN std_logic;
7235
          d : IN std_logic;
7236
          ena : IN std_logic;
7237
          aclr : IN std_logic;
7238
 
7239
          -- OUTPUT PORTS
7240
          q : OUT std_logic
7241
         );
7242
END cycloneii_mac_sign_reg;
7243
 
7244
ARCHITECTURE cycloneii_mac_sign_reg OF cycloneii_mac_sign_reg IS
7245
 
7246
    signal d_ipd : std_logic;
7247
    signal clk_ipd : std_logic;
7248
    signal aclr_ipd : std_logic;
7249
    signal ena_ipd : std_logic;
7250
begin
7251
 
7252
    ---------------------
7253
    --  INPUT PATH DELAYs
7254
    ---------------------
7255
    WireDelay : block
7256
    begin
7257
        VitalWireDelay (d_ipd, d, tipd_d);
7258
        VitalWireDelay (clk_ipd, clk, tipd_clk);
7259
        VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
7260
        VitalWireDelay (ena_ipd, ena, tipd_ena);
7261
    end block;
7262
 
7263
    VITALtiming :  process (clk_ipd, aclr_ipd)
7264
    variable Tviol_d_clk : std_ulogic := '0';
7265
    variable TimingData_d_clk : VitalTimingDataType := VitalTimingDataInit;
7266
    variable Tviol_ena_clk : std_ulogic := '0';
7267
    variable TimingData_ena_clk : VitalTimingDataType := VitalTimingDataInit;
7268
    variable q_VitalGlitchData : VitalGlitchDataType;
7269
    variable q_reg : std_logic := '0';
7270
    begin
7271
 
7272
        ------------------------
7273
        --  Timing Check Section
7274
        ------------------------
7275
        if (TimingChecksOn) then
7276
 
7277
            VitalSetupHoldCheck (
7278
                Violation       => Tviol_d_clk,
7279
                TimingData      => TimingData_d_clk,
7280
                TestSignal      => d,
7281
                TestSignalName  => "D",
7282
                RefSignal       => clk_ipd,
7283
                RefSignalName   => "CLK",
7284
                SetupHigh       => tsetup_d_clk_noedge_posedge,
7285
                SetupLow        => tsetup_d_clk_noedge_posedge,
7286
                HoldHigh        => thold_d_clk_noedge_posedge,
7287
                HoldLow         => thold_d_clk_noedge_posedge,
7288
                CheckEnabled    => TO_X01((aclr) OR
7289
                                          (NOT ena)) /= '1',
7290
                RefTransition   => '/',
7291
                HeaderMsg       => InstancePath & "/SIGN_REG",
7292
                XOn             => XOnChecks,
7293
                MsgOn           => MsgOnChecks );
7294
 
7295
            VitalSetupHoldCheck (
7296
                Violation       => Tviol_ena_clk,
7297
                TimingData      => TimingData_ena_clk,
7298
                TestSignal      => ena,
7299
                TestSignalName  => "ENA",
7300
                RefSignal       => clk_ipd,
7301
                RefSignalName   => "CLK",
7302
                SetupHigh       => tsetup_ena_clk_noedge_posedge,
7303
                SetupLow        => tsetup_ena_clk_noedge_posedge,
7304
                HoldHigh        => thold_ena_clk_noedge_posedge,
7305
                HoldLow         => thold_ena_clk_noedge_posedge,
7306
                CheckEnabled    => TO_X01(aclr) /= '1',
7307
                RefTransition   => '/',
7308
                HeaderMsg       => InstancePath & "/SIGN_REG",
7309
                XOn             => XOnChecks,
7310
                MsgOn           => MsgOnChecks );
7311
 
7312
        end if;
7313
 
7314
        if (aclr_ipd = '1') then
7315
            q_reg := '0';
7316
        elsif (clk_ipd'event and clk_ipd = '1' and (ena_ipd = '1')) then
7317
            q_reg := d_ipd;
7318
        end if;
7319
 
7320
        ----------------------
7321
        --  Path Delay Section
7322
        ----------------------
7323
        VitalPathDelay01 (
7324
            OutSignal => q,
7325
            OutSignalName => "Q",
7326
            OutTemp => q_reg,
7327
            Paths => (0 => (clk_ipd'last_event, tpd_clk_q_posedge, TRUE),
7328
                      1 => (aclr_ipd'last_event, tpd_aclr_q_posedge, TRUE)),
7329
            GlitchData => q_VitalGlitchData,
7330
            Mode => DefGlitchMode,
7331
            XOn  => XOn,
7332
            MsgOn  => MsgOn );
7333
    end process;
7334
END cycloneii_mac_sign_reg;
7335
 
7336
--------------------------------------------------------------------
7337
--
7338
-- Module Name : cycloneii_mac_mult_internal
7339
--
7340
-- Description : Cyclone II MAC_MULT_INTERNAL VHDL simulation model 
7341
--
7342
--------------------------------------------------------------------
7343
 
7344
LIBRARY IEEE;
7345
USE IEEE.VITAL_Primitives.all;
7346
USE IEEE.VITAL_Timing.all;
7347
USE IEEE.std_logic_1164.all;
7348
USE IEEE.std_logic_arith.all;
7349
USE IEEE.std_logic_unsigned.all;
7350
USE work.cycloneii_atom_pack.all;
7351
 
7352
ENTITY cycloneii_mac_mult_internal IS
7353
    GENERIC (
7354
             TimingChecksOn : Boolean := True;
7355
             MsgOn : Boolean := DefGlitchMsgOn;
7356
             XOn : Boolean := DefGlitchXOn;
7357
             MsgOnChecks : Boolean := DefMsgOnChecks;
7358
             XOnChecks : Boolean := DefXOnChecks;
7359
             InstancePath : STRING := "*";
7360
             tipd_dataa : VitalDelayArrayType01(17 downto 0)
7361
                                   := (OTHERS => DefPropDelay01);
7362
             tipd_datab : VitalDelayArrayType01(17 downto 0)
7363
                                   := (OTHERS => DefPropDelay01);
7364
             tipd_signa : VitalDelayType01 := DefPropDelay01;
7365
             tipd_signb : VitalDelayType01 := DefPropDelay01;
7366
             tpd_dataa_dataout : VitalDelayArrayType01(18*36 -1 downto 0) :=(others => DefPropDelay01);
7367
             tpd_datab_dataout : VitalDelayArrayType01(18*36 -1 downto 0) :=(others => DefPropDelay01);
7368
             tpd_signa_dataout : VitalDelayArrayType01(35 downto 0) :=(others => DefPropDelay01);
7369
             tpd_signb_dataout : VitalDelayArrayType01(35 downto 0) :=(others => DefPropDelay01);
7370
             dataa_width : integer := 18;
7371
             datab_width : integer := 18
7372
            );
7373
    PORT (
7374
          dataa : IN std_logic_vector(17 DOWNTO 0) := (OTHERS => '0');
7375
          datab : IN std_logic_vector(17 DOWNTO 0) := (OTHERS => '0');
7376
          signa : IN std_logic := '1';
7377
          signb : IN std_logic := '1';
7378
          dataout : OUT std_logic_vector((dataa_width+datab_width)-1 DOWNTO 0)
7379
         );
7380
END cycloneii_mac_mult_internal;
7381
 
7382
ARCHITECTURE vital_cycloneii_mac_mult_internal OF cycloneii_mac_mult_internal IS
7383
 
7384
    -- Internal variables
7385
    SIGNAL dataa_ipd : std_logic_vector(17 DOWNTO 0);
7386
    SIGNAL datab_ipd : std_logic_vector(17 DOWNTO 0);
7387
    SIGNAL signa_ipd : std_logic;
7388
    SIGNAL signb_ipd : std_logic;
7389
 
7390
    --  padding with 1's for input negation
7391
    SIGNAL reg_aclr : std_logic;
7392
    SIGNAL dataout_tmp : STD_LOGIC_VECTOR (dataa_width + datab_width downto 0) := (others => '0');
7393
 
7394
BEGIN
7395
 
7396
    ---------------------
7397
    --  INPUT PATH DELAYs
7398
    ---------------------
7399
    WireDelay : block
7400
    begin
7401
        g1 : for i in dataa'range generate
7402
            VitalWireDelay (dataa_ipd(i), dataa(i), tipd_dataa(i));
7403
        end generate;
7404
        g2 : for i in datab'range generate
7405
            VitalWireDelay (datab_ipd(i), datab(i), tipd_datab(i));
7406
        end generate;
7407
 
7408
        VitalWireDelay (signa_ipd, signa, tipd_signa);
7409
        VitalWireDelay (signb_ipd, signb, tipd_signb);
7410
    end block;
7411
 
7412
 
7413
    VITALtiming : process(dataa_ipd, datab_ipd, signa_ipd, signb_ipd)
7414
    begin
7415
        if((signa_ipd = '0') and (signb_ipd = '1')) then
7416
            dataout_tmp <=
7417
                unsigned(dataa_ipd(dataa_width-1 downto 0)) *
7418
                signed(datab_ipd(datab_width-1 downto 0));
7419
        elsif((signa_ipd = '1') and (signb_ipd = '0')) then
7420
            dataout_tmp <=
7421
                signed(dataa_ipd(dataa_width-1 downto 0)) *
7422
                unsigned(datab_ipd(datab_width-1 downto 0));
7423
        elsif((signa_ipd = '1') and (signb_ipd = '1')) then
7424
            dataout_tmp(dataout'range) <=
7425
                signed(dataa_ipd(dataa_width-1 downto 0)) *
7426
                signed(datab_ipd(datab_width-1 downto 0));
7427
        else --((signa_ipd = '0') and (signb_ipd = '0')) then
7428
            dataout_tmp(dataout'range) <=
7429
                unsigned(dataa_ipd(dataa_width-1 downto 0)) *
7430
                unsigned(datab_ipd(datab_width-1 downto 0));
7431
        end if;
7432
    end process;
7433
 
7434
    ----------------------
7435
    --  Path Delay Section
7436
    ----------------------
7437
    PathDelay : block
7438
    begin
7439
        g1 : for i in dataout'range generate
7440
          VITALtiming :  process (dataout_tmp(i))
7441
              variable dataout_VitalGlitchData : VitalGlitchDataType;
7442
          begin
7443
              VitalPathDelay01 (OutSignal => dataout(i),
7444
                                OutSignalName => "dataout",
7445
                                OutTemp => dataout_tmp(i),
7446
                                Paths => (0 => (dataa_ipd'last_event, tpd_dataa_dataout(i), TRUE),
7447
                                          1 => (datab_ipd'last_event, tpd_datab_dataout(i), TRUE),
7448
                                          2 => (signa'last_event, tpd_signa_dataout(i), TRUE),
7449
                                          3 => (signb'last_event, tpd_signb_dataout(i), TRUE)),
7450
                                GlitchData => dataout_VitalGlitchData,
7451
                                Mode => DefGlitchMode,
7452
                                MsgOn => FALSE,
7453
                                XOn  => TRUE );
7454
          end process;
7455
        end generate;
7456
    end block;
7457
 
7458
END vital_cycloneii_mac_mult_internal;
7459
 
7460
--------------------------------------------------------------------
7461
--
7462
-- Module Name : cycloneii_mac_mult
7463
--
7464
-- Description : Cyclone II MAC_MULT VHDL simulation model 
7465
--
7466
--------------------------------------------------------------------
7467
 
7468
LIBRARY IEEE;
7469
USE IEEE.VITAL_Primitives.all;
7470
USE IEEE.VITAL_Timing.all;
7471
USE IEEE.std_logic_1164.all;
7472
USE IEEE.std_logic_arith.all;
7473
USE IEEE.std_logic_unsigned.all;
7474
USE work.cycloneii_atom_pack.all;
7475
USE work.cycloneii_mac_data_reg;
7476
USE work.cycloneii_mac_sign_reg;
7477
USE work.cycloneii_mac_mult_internal;
7478
 
7479
ENTITY cycloneii_mac_mult IS
7480
    GENERIC (
7481
             dataa_width : integer := 18;
7482
             datab_width : integer := 18;
7483
             dataa_clock : string := "none";
7484
             datab_clock : string := "none";
7485
             signa_clock : string := "none";
7486
             signb_clock : string := "none";
7487
             TimingChecksOn : Boolean := True;
7488
             MsgOn : Boolean := DefGlitchMsgOn;
7489
             XOn : Boolean := DefGlitchXOn;
7490
             MsgOnChecks : Boolean := DefMsgOnChecks;
7491
             XOnChecks : Boolean := DefXOnChecks;
7492
             InstancePath : STRING := "*";
7493
             lpm_hint : string := "true";
7494
             lpm_type : string := "cycloneii_mac_mult"
7495
            );
7496
    PORT (
7497
          dataa : IN std_logic_vector(dataa_width-1 DOWNTO 0) := (OTHERS => '0');
7498
          datab : IN std_logic_vector(datab_width-1 DOWNTO 0) := (OTHERS => '0');
7499
          signa : IN std_logic := '1';
7500
          signb : IN std_logic := '1';
7501
          clk : IN std_logic := '0';
7502
          aclr : IN std_logic := '0';
7503
          ena : IN std_logic := '0';
7504
          dataout : OUT std_logic_vector((dataa_width+datab_width)-1 DOWNTO 0);
7505
          devclrn : IN std_logic := '1';
7506
          devpor : IN std_logic := '1'
7507
         );
7508
END cycloneii_mac_mult;
7509
 
7510
ARCHITECTURE vital_cycloneii_mac_mult OF cycloneii_mac_mult IS
7511
 
7512
    COMPONENT cycloneii_mac_data_reg
7513
        GENERIC (
7514
                 TimingChecksOn : Boolean := True;
7515
                 MsgOn : Boolean := DefGlitchMsgOn;
7516
                 XOn : Boolean := DefGlitchXOn;
7517
                 MsgOnChecks : Boolean := DefMsgOnChecks;
7518
                 XOnChecks : Boolean := DefXOnChecks;
7519
                 InstancePath : STRING := "*";
7520
                 tipd_data : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
7521
                 tipd_clk : VitalDelayType01 := DefPropDelay01;
7522
                 tipd_ena : VitalDelayType01 := DefPropDelay01;
7523
                 tipd_aclr : VitalDelayType01 := DefPropDelay01;
7524
                 tsetup_data_clk_noedge_posedge : VitalDelayArrayType(17 downto 0) := (OTHERS => DefSetupHoldCnst);
7525
                 thold_data_clk_noedge_posedge : VitalDelayArrayType(17 downto 0) := (OTHERS => DefSetupHoldCnst);
7526
                 tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7527
                 thold_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7528
             tpd_aclr_dataout_posedge : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
7529
             tpd_clk_dataout_posedge : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
7530
                 data_width : integer := 18
7531
                );
7532
        PORT (
7533
              -- INPUT PORTS
7534
              clk : IN std_logic;
7535
              data : IN std_logic_vector(17 DOWNTO 0);
7536
              ena : IN std_logic;
7537
              aclr : IN std_logic;
7538
              -- OUTPUT PORTS
7539
              dataout : OUT std_logic_vector(17 DOWNTO 0)
7540
             );
7541
    END COMPONENT;
7542
 
7543
    COMPONENT cycloneii_mac_sign_reg
7544
        GENERIC (
7545
                 TimingChecksOn : Boolean := True;
7546
                 MsgOn : Boolean := DefGlitchMsgOn;
7547
                 XOn : Boolean := DefGlitchXOn;
7548
                 MsgOnChecks : Boolean := DefMsgOnChecks;
7549
                 XOnChecks : Boolean := DefXOnChecks;
7550
                 InstancePath : STRING := "*";
7551
                 tsetup_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7552
                 thold_d_clk_noedge_posedge     : VitalDelayType := DefSetupHoldCnst;
7553
                 tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7554
                 thold_ena_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
7555
                 tpd_clk_q_posedge : VitalDelayType01 := DefPropDelay01;
7556
                 tpd_aclr_q_posedge : VitalDelayType01 := DefPropDelay01;
7557
                 tipd_d : VitalDelayType01 := DefPropDelay01;
7558
                 tipd_ena : VitalDelayType01 := DefPropDelay01;
7559
                 tipd_aclr : VitalDelayType01 := DefPropDelay01;
7560
                 tipd_clk : VitalDelayType01 := DefPropDelay01
7561
                );
7562
        PORT (
7563
              -- INPUT PORTS
7564
              clk : IN std_logic;
7565
              d : IN std_logic;
7566
              ena : IN std_logic;
7567
              aclr : IN std_logic;
7568
 
7569
              -- OUTPUT PORTS
7570
              q : OUT std_logic
7571
             );
7572
    END COMPONENT;
7573
 
7574
    COMPONENT cycloneii_mac_mult_internal
7575
        GENERIC (
7576
                 TimingChecksOn : Boolean := True;
7577
                 MsgOn : Boolean := DefGlitchMsgOn;
7578
                 XOn : Boolean := DefGlitchXOn;
7579
                 MsgOnChecks : Boolean := DefMsgOnChecks;
7580
                 XOnChecks : Boolean := DefXOnChecks;
7581
                 InstancePath : STRING := "*";
7582
                 tipd_dataa : VitalDelayArrayType01(17 downto 0)
7583
                                       := (OTHERS => DefPropDelay01);
7584
                 tipd_datab : VitalDelayArrayType01(17 downto 0)
7585
                                       := (OTHERS => DefPropDelay01);
7586
                 tipd_signa : VitalDelayType01 := DefPropDelay01;
7587
                 tipd_signb : VitalDelayType01 := DefPropDelay01;
7588
                tpd_dataa_dataout : VitalDelayArrayType01(18*36 -1 downto 0) :=(others => DefPropDelay01);
7589
                tpd_datab_dataout : VitalDelayArrayType01(18*36 -1 downto 0) :=(others => DefPropDelay01);
7590
                tpd_signa_dataout : VitalDelayArrayType01(35 downto 0) :=(others => DefPropDelay01);
7591
                tpd_signb_dataout : VitalDelayArrayType01(35 downto 0) :=(others => DefPropDelay01);
7592
                 dataa_width : integer := 18;
7593
                 datab_width : integer := 18
7594
                );
7595
        PORT (
7596
              dataa : IN std_logic_vector(17 DOWNTO 0) := (OTHERS => '0');
7597
              datab : IN std_logic_vector(17 DOWNTO 0) := (OTHERS => '0');
7598
              signa : IN std_logic := '1';
7599
              signb : IN std_logic := '1';
7600
              dataout : OUT std_logic_vector((dataa_width+datab_width)-1 DOWNTO 0)
7601
             );
7602
    END COMPONENT;
7603
 
7604
    -- Internal variables
7605
    SIGNAL dataa_ipd : std_logic_vector(17 DOWNTO 0);
7606
    SIGNAL datab_ipd : std_logic_vector(17 DOWNTO 0);
7607
    SIGNAL idataa_reg : std_logic_vector(17 DOWNTO 0);   --  optional register for dataa input
7608
    SIGNAL idatab_reg : std_logic_vector(17 DOWNTO 0);   --  optional register for datab input
7609
    SIGNAL isigna_reg : std_logic;   --  optional register for signa input
7610
    SIGNAL isignb_reg : std_logic;   --  optional register for signb input
7611
    SIGNAL idataa_int : std_logic_vector(17 DOWNTO 0);   --  dataa as seen by the multiplier input
7612
    SIGNAL idatab_int : std_logic_vector(17 DOWNTO 0);   --  datab as seen by the multiplier input
7613
    SIGNAL isigna_int : std_logic;   --  signa as seen by the multiplier input
7614
    SIGNAL isignb_int : std_logic;   --  signb as seen by the multiplier input
7615
    --  padding with 1's for input negation
7616
    SIGNAL reg_aclr : std_logic;
7617
    SIGNAL dataout_tmp : STD_LOGIC_VECTOR (dataa_width + datab_width downto 0) := (others => '0');
7618
 
7619
BEGIN
7620
 
7621
    ---------------------
7622
    --  INPUT PATH DELAYs
7623
    ---------------------
7624
 
7625
    reg_aclr <= (NOT devpor) OR (NOT devclrn) OR (aclr) ;
7626
 
7627
    -- padding input data to full bus width
7628
    dataa_ipd(dataa_width-1 downto 0) <= dataa;
7629
    datab_ipd(datab_width-1 downto 0) <= datab;
7630
 
7631
    -- Optional input registers for dataa,b and signa,b
7632
    dataa_reg : cycloneii_mac_data_reg
7633
        GENERIC MAP (
7634
            data_width => dataa_width)
7635
        PORT MAP (
7636
            clk => clk,
7637
            data => dataa_ipd,
7638
            ena => ena,
7639
            aclr => reg_aclr,
7640
            dataout => idataa_reg);
7641
 
7642
    datab_reg : cycloneii_mac_data_reg
7643
        GENERIC MAP (
7644
            data_width => datab_width)
7645
        PORT MAP (
7646
            clk => clk,
7647
            data => datab_ipd,
7648
            ena => ena,
7649
            aclr => reg_aclr,
7650
            dataout => idatab_reg);
7651
 
7652
    signa_reg : cycloneii_mac_sign_reg
7653
        PORT MAP (
7654
            clk => clk,
7655
            d => signa,
7656
            ena => ena,
7657
            aclr => reg_aclr,
7658
            q => isigna_reg);
7659
 
7660
    signb_reg : cycloneii_mac_sign_reg
7661
        PORT MAP (
7662
            clk => clk,
7663
            d => signb,
7664
            ena => ena,
7665
            aclr => reg_aclr,
7666
            q => isignb_reg);
7667
 
7668
    idataa_int <= dataa_ipd WHEN (dataa_clock = "none") ELSE idataa_reg;
7669
    idatab_int <= datab_ipd WHEN (datab_clock = "none") ELSE idatab_reg;
7670
    isigna_int <= signa WHEN (signa_clock = "none") ELSE isigna_reg;
7671
    isignb_int <= signb WHEN (signb_clock = "none") ELSE isignb_reg;
7672
 
7673
    mac_multiply : cycloneii_mac_mult_internal
7674
        GENERIC MAP (
7675
             dataa_width => dataa_width,
7676
             datab_width => datab_width
7677
            )
7678
        PORT MAP (
7679
              dataa => idataa_int,
7680
              datab => idatab_int,
7681
              signa => isigna_int,
7682
              signb => isignb_int,
7683
              dataout => dataout
7684
             );
7685
END vital_cycloneii_mac_mult;
7686
 
7687
--------------------------------------------------------------------
7688
--
7689
-- Module Name : cycloneii_mac_out
7690
--
7691
-- Description : Cyclone II MAC_OUT VHDL simulation model 
7692
--
7693
--------------------------------------------------------------------
7694
 
7695
LIBRARY IEEE;
7696
USE IEEE.VITAL_Primitives.all;
7697
USE IEEE.VITAL_Timing.all;
7698
USE IEEE.std_logic_1164.all;
7699
USE work.cycloneii_atom_pack.all;
7700
 
7701
ENTITY cycloneii_mac_out IS
7702
    GENERIC (
7703
             dataa_width : integer := 1;
7704
             output_clock : string := "none";
7705
                         TimingChecksOn : Boolean := True;
7706
             MsgOn : Boolean := DefGlitchMsgOn;
7707
             XOn : Boolean := DefGlitchXOn;
7708
             MsgOnChecks : Boolean := DefMsgOnChecks;
7709
             XOnChecks : Boolean := DefXOnChecks;
7710
             InstancePath : STRING := "*";
7711
             tipd_dataa : VitalDelayArrayType01(35 downto 0)
7712
                                   := (OTHERS => DefPropDelay01);
7713
             tipd_clk : VitalDelayType01 := DefPropDelay01;
7714
             tipd_ena : VitalDelayType01 := DefPropDelay01;
7715
             tipd_aclr : VitalDelayType01 := DefPropDelay01;
7716
             tpd_dataa_dataout :VitalDelayArrayType01(36*36 -1 downto 0) :=(others => DefPropDelay01);
7717
             tpd_aclr_dataout_posedge : VitalDelayArrayType01(35 downto 0) :=(others => DefPropDelay01);
7718
             tpd_clk_dataout_posedge :VitalDelayArrayType01(35  downto 0) :=(others => DefPropDelay01);
7719
             tsetup_dataa_clk_noedge_posedge : VitalDelayArrayType(35 downto 0) := (OTHERS => DefSetupHoldCnst);
7720
             thold_dataa_clk_noedge_posedge :  VitalDelayArrayType(35 downto 0) := (OTHERS => DefSetupHoldCnst);
7721
             tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7722
             thold_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7723
             lpm_hint : string := "true";
7724
             lpm_type : string := "cycloneii_mac_out");
7725
    PORT (
7726
          dataa : IN std_logic_vector(dataa_width-1 DOWNTO 0) := (OTHERS => '0');
7727
          clk : IN std_logic := '0';
7728
          aclr : IN std_logic := '0';
7729
          ena : IN std_logic := '1';
7730
          dataout : OUT std_logic_vector(dataa_width-1 DOWNTO 0);
7731
          devclrn : IN std_logic := '1';
7732
          devpor : IN std_logic := '1'
7733
         );
7734
END cycloneii_mac_out;
7735
 
7736
ARCHITECTURE vital_cycloneii_mac_out OF cycloneii_mac_out IS
7737
 
7738
    --  internal variables
7739
    SIGNAL dataa_ipd : std_logic_vector(dataa'range);
7740
    SIGNAL clk_ipd : std_logic;
7741
    SIGNAL aclr_ipd : std_logic;
7742
    SIGNAL ena_ipd : std_logic;
7743
 
7744
    --  optional register
7745
    SIGNAL use_reg : std_logic;
7746
 
7747
    SIGNAL dataout_tmp : std_logic_vector(dataout'range) := (OTHERS => '0');
7748
 
7749
BEGIN
7750
 
7751
    ---------------------
7752
    -- PATH DELAYs
7753
    ---------------------
7754
    WireDelay : block
7755
    begin
7756
        g1 : for i in dataa'range generate
7757
            VitalWireDelay (dataa_ipd(i), dataa(i), tipd_dataa(i));
7758
            VITALtiming :  process (clk_ipd, aclr_ipd, dataout_tmp(i))
7759
              variable dataout_VitalGlitchData : VitalGlitchDataType;
7760
              begin
7761
                VitalPathDelay01 (
7762
                  OutSignal => dataout(i),
7763
                  OutSignalName => "DATAOUT",
7764
                  OutTemp => dataout_tmp(i),
7765
                  Paths => (0 => (clk_ipd'last_event, tpd_clk_dataout_posedge(i), use_reg = '1'),
7766
                            1 => (aclr_ipd'last_event, tpd_aclr_dataout_posedge(i), use_reg = '1'),
7767
                            2 => (dataa_ipd(i)'last_event, tpd_dataa_dataout(i), use_reg = '0')),
7768
                  GlitchData => dataout_VitalGlitchData,
7769
                  Mode => DefGlitchMode,
7770
                  XOn  => XOn,
7771
                  MsgOn  => MsgOn );
7772
              end process;
7773
        end generate;
7774
 
7775
        VitalWireDelay (clk_ipd, clk, tipd_clk);
7776
        VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
7777
        VitalWireDelay (ena_ipd, ena, tipd_ena);
7778
 
7779
    end block;
7780
 
7781
    use_reg <= '1' WHEN (output_clock /= "none") ELSE '0';
7782
 
7783
    sh: block
7784
        begin
7785
        g0 : for i in dataa'range generate
7786
    VITALtiming :  process (clk_ipd, ena_ipd, dataa_ipd(i))
7787
    variable Tviol_dataa_clk : std_ulogic := '0';
7788
    variable TimingData_dataa_clk : VitalTimingDataType := VitalTimingDataInit;
7789
    variable Tviol_ena_clk : std_ulogic := '0';
7790
    variable TimingData_ena_clk : VitalTimingDataType := VitalTimingDataInit;
7791
    begin
7792
 
7793
        ------------------------
7794
        --  Timing Check Section
7795
        ------------------------
7796
        if (TimingChecksOn) then
7797
 
7798
            VitalSetupHoldCheck (
7799
                Violation       => Tviol_dataa_clk,
7800
                TimingData      => TimingData_dataa_clk,
7801
                TestSignal      => dataa(i),
7802
                TestSignalName  => "D",
7803
                RefSignal       => clk_ipd,
7804
                RefSignalName   => "CLK",
7805
                SetupHigh       => tsetup_dataa_clk_noedge_posedge(i),
7806
                SetupLow        => tsetup_dataa_clk_noedge_posedge(i),
7807
                HoldHigh        => thold_dataa_clk_noedge_posedge(i),
7808
                HoldLow         => thold_dataa_clk_noedge_posedge(i),
7809
                CheckEnabled    => TO_X01((aclr) OR (NOT use_reg) OR
7810
                                          (NOT ena)) /= '1',
7811
                RefTransition   => '/',
7812
                HeaderMsg       => InstancePath & "/MAC_DATA_REG",
7813
                XOn             => XOnChecks,
7814
                MsgOn           => MsgOnChecks );
7815
 
7816
            VitalSetupHoldCheck (
7817
                Violation       => Tviol_ena_clk,
7818
                TimingData      => TimingData_ena_clk,
7819
                TestSignal      => ena,
7820
                TestSignalName  => "ENA",
7821
                RefSignal       => clk_ipd,
7822
                RefSignalName   => "CLK",
7823
                SetupHigh       => tsetup_ena_clk_noedge_posedge,
7824
                SetupLow        => tsetup_ena_clk_noedge_posedge,
7825
                HoldHigh        => thold_ena_clk_noedge_posedge,
7826
                HoldLow         => thold_ena_clk_noedge_posedge,
7827
                CheckEnabled    => TO_X01((aclr) OR
7828
                                          (NOT use_reg)) /= '1',
7829
                RefTransition   => '/',
7830
                HeaderMsg       => InstancePath & "/MAC_DATA_REG",
7831
                XOn             => XOnChecks,
7832
                MsgOn           => MsgOnChecks );
7833
 
7834
        end if;
7835
        END PROCESS;
7836
    end generate g0;
7837
    end block;
7838
 
7839
    process (clk_ipd, aclr_ipd,ena_ipd, dataa_ipd)
7840
    begin
7841
            if (use_reg = '0') then
7842
            dataout_tmp <= dataa_ipd;
7843
        else
7844
            if (aclr_ipd = '1') then
7845
                dataout_tmp <= (OTHERS => '0');
7846
            elsif (clk_ipd'event and clk_ipd = '1' and (ena_ipd = '1')) then
7847
                dataout_tmp <= dataa_ipd;
7848
            end if;
7849
        end if;
7850
 
7851
    end process;
7852
 
7853
END vital_cycloneii_mac_out;
7854
 
7855
 
7856
--/////////////////////////////////////////////////////////////////////////////
7857
--
7858
-- Entity Name : cycloneii_ena_reg
7859
--
7860
-- Description : Simulation model for a simple DFF.
7861
--               This is used for the gated clock generation
7862
--               Powers upto 1.
7863
--
7864
--/////////////////////////////////////////////////////////////////////////////
7865
 
7866
LIBRARY IEEE;
7867
USE IEEE.std_logic_1164.all;
7868
use IEEE.VITAL_Timing.all;
7869
use IEEE.VITAL_Primitives.all;
7870
use work.cycloneii_atom_pack.all;
7871
 
7872
ENTITY cycloneii_ena_reg is
7873
    generic (
7874
             TimingChecksOn : Boolean := True;
7875
             MsgOn : Boolean := DefGlitchMsgOn;
7876
             XOn : Boolean := DefGlitchXOn;
7877
             MsgOnChecks : Boolean := DefMsgOnChecks;
7878
             XOnChecks : Boolean := DefXOnChecks;
7879
             InstancePath : STRING := "*";
7880
             tsetup_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7881
             thold_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7882
             tpd_clk_q_posedge : VitalDelayType01 := DefPropDelay01;
7883
             tipd_d : VitalDelayType01 := DefPropDelay01;
7884
             tipd_clk : VitalDelayType01 := DefPropDelay01
7885
            );
7886
    PORT (
7887
          clk : in std_logic;
7888
          ena : in std_logic := '1';
7889
          d : in std_logic;
7890
          clrn : in std_logic := '1';
7891
          prn : in std_logic := '1';
7892
          q : out std_logic
7893
         );
7894
   attribute VITAL_LEVEL0 of cycloneii_ena_reg : entity is TRUE;
7895
end cycloneii_ena_reg;
7896
 
7897
ARCHITECTURE behave of cycloneii_ena_reg is
7898
    attribute VITAL_LEVEL0 of behave : architecture is TRUE;
7899
    signal d_ipd : std_logic;
7900
    signal clk_ipd : std_logic;
7901
begin
7902
 
7903
    ---------------------
7904
    --  INPUT PATH DELAYs
7905
    ---------------------
7906
    WireDelay : block
7907
    begin
7908
        VitalWireDelay (d_ipd, d, tipd_d);
7909
        VitalWireDelay (clk_ipd, clk, tipd_clk);
7910
    end block;
7911
 
7912
    VITALtiming :  process (clk_ipd, prn, clrn)
7913
    variable Tviol_d_clk : std_ulogic := '0';
7914
    variable TimingData_d_clk : VitalTimingDataType := VitalTimingDataInit;
7915
    variable q_VitalGlitchData : VitalGlitchDataType;
7916
    variable q_reg : std_logic := '1';
7917
    begin
7918
 
7919
        ------------------------
7920
        --  Timing Check Section
7921
        ------------------------
7922
        if (TimingChecksOn) then
7923
 
7924
            VitalSetupHoldCheck (
7925
                Violation       => Tviol_d_clk,
7926
                TimingData      => TimingData_d_clk,
7927
                TestSignal      => d,
7928
                TestSignalName  => "D",
7929
                RefSignal       => clk_ipd,
7930
                RefSignalName   => "CLK",
7931
                SetupHigh       => tsetup_d_clk_noedge_posedge,
7932
                SetupLow        => tsetup_d_clk_noedge_posedge,
7933
                HoldHigh        => thold_d_clk_noedge_posedge,
7934
                HoldLow         => thold_d_clk_noedge_posedge,
7935
                CheckEnabled    => TO_X01((clrn) OR
7936
                                          (NOT ena)) /= '1',
7937
                RefTransition   => '/',
7938
                HeaderMsg       => InstancePath & "/cycloneii_ena_reg",
7939
                XOn             => XOnChecks,
7940
                MsgOn           => MsgOnChecks );
7941
 
7942
        end if;
7943
 
7944
        if (prn = '0') then
7945
            q_reg := '1';
7946
        elsif (clrn = '0') then
7947
            q_reg := '0';
7948
        elsif (clk_ipd'event and clk_ipd = '1' and clk_ipd'last_value = '0' and (ena = '1')) then
7949
            q_reg := d_ipd;
7950
        end if;
7951
 
7952
        ----------------------
7953
        --  Path Delay Section
7954
        ----------------------
7955
        VitalPathDelay01 (
7956
            OutSignal => q,
7957
            OutSignalName => "Q",
7958
            OutTemp => q_reg,
7959
            Paths => (0 => (clk_ipd'last_event, tpd_clk_q_posedge, TRUE)),
7960
            GlitchData => q_VitalGlitchData,
7961
            Mode => DefGlitchMode,
7962
            XOn  => XOn,
7963
            MsgOn  => MsgOn );
7964
 
7965
    end process;
7966
 
7967
end behave;
7968
 
7969
--/////////////////////////////////////////////////////////////////////////////
7970
--
7971
--              VHDL Simulation Model for Cyclone II CLKCTRL Atom
7972
--
7973
--/////////////////////////////////////////////////////////////////////////////
7974
 
7975
--
7976
--
7977
--  CYCLONEII_CLKCTRL Model
7978
--
7979
--
7980
LIBRARY IEEE;
7981
use IEEE.std_logic_1164.all;
7982
use IEEE.VITAL_Timing.all;
7983
use IEEE.VITAL_Primitives.all;
7984
use work.cycloneii_atom_pack.all;
7985
use work.cycloneii_ena_reg;
7986
 
7987
entity cycloneii_clkctrl is
7988
    generic (
7989
             clock_type : STRING := "Auto";
7990
             lpm_type : STRING := "cycloneii_clkctrl";
7991
             ena_register_mode : STRING := "Falling Edge";
7992
             TimingChecksOn : Boolean := True;
7993
             MsgOn : Boolean := DefGlitchMsgOn;
7994
             XOn : Boolean := DefGlitchXOn;
7995
             MsgOnChecks : Boolean := DefMsgOnChecks;
7996
             XOnChecks : Boolean := DefXOnChecks;
7997
             InstancePath : STRING := "*";
7998
             tipd_inclk : VitalDelayArrayType01(3 downto 0) := (OTHERS => DefPropDelay01);
7999
             tipd_clkselect : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01);
8000
             tipd_ena : VitalDelayType01 := DefPropDelay01
8001
             );
8002
    port (
8003
          inclk : in std_logic_vector(3 downto 0) := "0000";
8004
          clkselect : in std_logic_vector(1 downto 0) := "00";
8005
          ena : in std_logic := '1';
8006
          devclrn : in std_logic := '1';
8007
          devpor : in std_logic := '1';
8008
          outclk : out std_logic
8009
          );
8010
   attribute VITAL_LEVEL0 of cycloneii_clkctrl : entity is TRUE;
8011
end cycloneii_clkctrl;
8012
 
8013
architecture vital_clkctrl of cycloneii_clkctrl is
8014
    attribute VITAL_LEVEL0 of vital_clkctrl : architecture is TRUE;
8015
 
8016
    component cycloneii_ena_reg
8017
        generic (
8018
                 TimingChecksOn : Boolean := True;
8019
                 MsgOn : Boolean := DefGlitchMsgOn;
8020
                 XOn : Boolean := DefGlitchXOn;
8021
                 MsgOnChecks : Boolean := DefMsgOnChecks;
8022
                 XOnChecks : Boolean := DefXOnChecks;
8023
                 InstancePath : STRING := "*";
8024
                 tsetup_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
8025
                 thold_d_clk_noedge_posedge     : VitalDelayType := DefSetupHoldCnst;
8026
                 tpd_clk_q_posedge : VitalDelayType01 := DefPropDelay01;
8027
                 tipd_d : VitalDelayType01 := DefPropDelay01;
8028
                 tipd_clk : VitalDelayType01 := DefPropDelay01
8029
                );
8030
        PORT (
8031
              clk : in std_logic;
8032
              ena : in std_logic := '1';
8033
              d : in std_logic;
8034
              clrn : in std_logic := '1';
8035
              prn : in std_logic := '1';
8036
              q : out std_logic
8037
             );
8038
    end component;
8039
 
8040
    signal inclk_ipd : std_logic_vector(3 downto 0);
8041
    signal clkselect_ipd : std_logic_vector(1 downto 0);
8042
    signal ena_ipd : std_logic;
8043
    signal clkmux_out : std_logic;
8044
    signal clkmux_out_inv : std_logic;
8045
    signal cereg_clr : std_logic;
8046
    signal cereg_out : std_logic;
8047
    signal ena_out : std_logic;
8048
    signal vcc : std_logic := '1';
8049
begin
8050
 
8051
    ---------------------
8052
    --  INPUT PATH DELAYs
8053
    ---------------------
8054
    WireDelay : block
8055
    begin
8056
        VitalWireDelay (ena_ipd, ena, tipd_ena);
8057
        VitalWireDelay (inclk_ipd(0), inclk(0), tipd_inclk(0));
8058
        VitalWireDelay (inclk_ipd(1), inclk(1), tipd_inclk(1));
8059
        VitalWireDelay (inclk_ipd(2), inclk(2), tipd_inclk(2));
8060
        VitalWireDelay (inclk_ipd(3), inclk(3), tipd_inclk(3));
8061
        VitalWireDelay (clkselect_ipd(0), clkselect(0), tipd_clkselect(0));
8062
        VitalWireDelay (clkselect_ipd(1), clkselect(1), tipd_clkselect(1));
8063
    end block;
8064
 
8065
    process(inclk_ipd, clkselect_ipd)
8066
    variable tmp : std_logic;
8067
    begin
8068
        if (clkselect_ipd = "11") then
8069
            tmp := inclk_ipd(3);
8070
        elsif (clkselect_ipd = "10") then
8071
            tmp := inclk_ipd(2);
8072
        elsif (clkselect_ipd = "01") then
8073
            tmp := inclk_ipd(1);
8074
        else
8075
            tmp := inclk_ipd(0);
8076
        end if;
8077
        clkmux_out <= tmp;
8078
        clkmux_out_inv <= NOT tmp;
8079
    end process;
8080
 
8081
    extena0_reg : cycloneii_ena_reg
8082
                  port map (
8083
                            clk => clkmux_out_inv,
8084
                            ena => vcc,
8085
                            d => ena_ipd,
8086
                            clrn => vcc,
8087
                            prn => devpor,
8088
                            q => cereg_out
8089
                           );
8090
 
8091
    ena_out <= cereg_out WHEN (ena_register_mode = "falling edge") ELSE ena_ipd;
8092
 
8093
    outclk <= ena_out AND clkmux_out;
8094
 
8095
end vital_clkctrl;
8096
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.