OpenCores
URL https://opencores.org/ocsvn/mips_enhanced/mips_enhanced/trunk

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [tech/] [stratixii/] [simprims/] [stratixii_atoms.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
-- Copyright (C) 1991-2006 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 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
 
15
 
16
-- Quartus II 6.0 Build 178 04/27/2006
17
 
18
 
19
library IEEE;
20
use IEEE.std_logic_1164.all;
21
use IEEE.VITAL_Timing.all;
22
use IEEE.VITAL_Primitives.all;
23
 
24
package stratixii_atom_pack is
25
 
26
function str_to_bin (lut_mask : string ) return std_logic_vector;
27
 
28
function product(list : std_logic_vector) return std_logic ;
29
 
30
function alt_conv_integer(arg : in std_logic_vector) return integer;
31
 
32
 
33
-- default generic values
34
    CONSTANT DefWireDelay        : VitalDelayType01      := (0 ns, 0 ns);
35
    CONSTANT DefPropDelay01      : VitalDelayType01      := (1 ns, 1 ns);
36
    CONSTANT DefPropDelay01Z     : VitalDelayType01Z     := (OTHERS => 1 ns);
37
    CONSTANT DefSetupHoldCnst    : TIME := 0 ns;
38
    CONSTANT DefPulseWdthCnst    : TIME := 0 ns;
39
-- default control options
40
--    CONSTANT DefGlitchMode       : VitalGlitchKindType   := OnEvent;
41
-- change default delay type to Transport : for spr 68748
42
    CONSTANT DefGlitchMode       : VitalGlitchKindType   := VitalTransport;
43
    CONSTANT DefGlitchMsgOn      : BOOLEAN       := FALSE;
44
    CONSTANT DefGlitchXOn        : BOOLEAN       := FALSE;
45
    CONSTANT DefMsgOnChecks      : BOOLEAN       := TRUE;
46
    CONSTANT DefXOnChecks        : BOOLEAN       := TRUE;
47
-- output strength mapping
48
                                                --  UX01ZWHL-
49
    CONSTANT PullUp      : VitalOutputMapType    := "UX01HX01X";
50
    CONSTANT NoPullUpZ   : VitalOutputMapType    := "UX01ZX01X";
51
    CONSTANT PullDown    : VitalOutputMapType    := "UX01LX01X";
52
-- primitive result strength mapping
53
    CONSTANT wiredOR     : VitalResultMapType    := ( 'U', 'X', 'L', '1' );
54
    CONSTANT wiredAND    : VitalResultMapType    := ( 'U', 'X', '0', 'H' );
55
    CONSTANT L : VitalTableSymbolType := '0';
56
    CONSTANT H : VitalTableSymbolType := '1';
57
    CONSTANT x : VitalTableSymbolType := '-';
58
    CONSTANT S : VitalTableSymbolType := 'S';
59
    CONSTANT R : VitalTableSymbolType := '/';
60
    CONSTANT U : VitalTableSymbolType := 'X';
61
    CONSTANT V : VitalTableSymbolType := 'B'; -- valid clock signal (non-rising)
62
 
63
-- Declare array types for CAM_SLICE
64
    TYPE stratixii_mem_data IS ARRAY (0 to 31) of STD_LOGIC_VECTOR (31 downto 0);
65
 
66
function int2str( value : integer ) return string;
67
 
68
function map_x_to_0 (value : std_logic) return std_logic;
69
 
70
function SelectDelay (CONSTANT Paths: IN  VitalPathArray01Type) return TIME;
71
 
72
end stratixii_atom_pack;
73
 
74
library IEEE;
75
use IEEE.std_logic_1164.all;
76
 
77
package body stratixii_atom_pack is
78
 
79
type masklength is array (4 downto 1) of std_logic_vector(3 downto 0);
80
function str_to_bin (lut_mask : string) return std_logic_vector is
81
variable slice : masklength := (OTHERS => "0000");
82
variable mask : std_logic_vector(15 downto 0);
83
 
84
 
85
begin
86
 
87
    for i in 1 to lut_mask'length loop
88
        case lut_mask(i) is
89
            when '0' => slice(i) := "0000";
90
            when '1' => slice(i) := "0001";
91
            when '2' => slice(i) := "0010";
92
            when '3' => slice(i) := "0011";
93
            when '4' => slice(i) := "0100";
94
            when '5' => slice(i) := "0101";
95
            when '6' => slice(i) := "0110";
96
            when '7' => slice(i) := "0111";
97
            when '8' => slice(i) := "1000";
98
            when '9' => slice(i) := "1001";
99
            when 'a' => slice(i) := "1010";
100
            when 'A' => slice(i) := "1010";
101
            when 'b' => slice(i) := "1011";
102
            when 'B' => slice(i) := "1011";
103
            when 'c' => slice(i) := "1100";
104
            when 'C' => slice(i) := "1100";
105
            when 'd' => slice(i) := "1101";
106
            when 'D' => slice(i) := "1101";
107
            when 'e' => slice(i) := "1110";
108
            when 'E' => slice(i) := "1110";
109
            when others => slice(i) := "1111";
110
        end case;
111
    end loop;
112
 
113
 
114
    mask := (slice(1) & slice(2) & slice(3) & slice(4));
115
    return (mask);
116
 
117
end str_to_bin;
118
 
119
function product (list: std_logic_vector) return std_logic is
120
begin
121
 
122
    for i in 0 to 31 loop
123
        if list(i) = '0' then
124
            return ('0');
125
        end if;
126
    end loop;
127
    return ('1');
128
 
129
end product;
130
 
131
function alt_conv_integer(arg : in std_logic_vector) return integer is
132
variable result : integer;
133
begin
134
    result := 0;
135
    for i in arg'range loop
136
        if arg(i) = '1' then
137
            result := result + 2**i;
138
        end if;
139
    end loop;
140
    return result;
141
end alt_conv_integer;
142
 
143
function int2str( value : integer ) return string is
144
variable ivalue,index : integer;
145
variable digit : integer;
146
variable line_no: string(8 downto 1) := "        ";
147
begin
148
    ivalue := value;
149
    index := 1;
150
    if (ivalue = 0) then
151
        line_no := "       0";
152
    end if;
153
    while (ivalue > 0) loop
154
        digit := ivalue MOD 10;
155
        ivalue := ivalue/10;
156
        case digit is
157
            when 0 =>
158
                    line_no(index) := '0';
159
            when 1 =>
160
                    line_no(index) := '1';
161
            when 2 =>
162
                    line_no(index) := '2';
163
            when 3 =>
164
                    line_no(index) := '3';
165
            when 4 =>
166
                    line_no(index) := '4';
167
            when 5 =>
168
                    line_no(index) := '5';
169
            when 6 =>
170
                    line_no(index) := '6';
171
            when 7 =>
172
                    line_no(index) := '7';
173
            when 8 =>
174
                    line_no(index) := '8';
175
            when 9 =>
176
                    line_no(index) := '9';
177
            when others =>
178
                    ASSERT FALSE
179
                    REPORT "Illegal number!"
180
                    SEVERITY ERROR;
181
        end case;
182
        index := index + 1;
183
    end loop;
184
    return line_no;
185
end;
186
 
187
function map_x_to_0 (value : std_logic) return std_logic is
188
begin
189
    if (Is_X (value) = TRUE) then
190
        return '0';
191
    else
192
        return value;
193
    end if;
194
end;
195
 
196
function SelectDelay (CONSTANT Paths : IN  VitalPathArray01Type) return TIME IS
197
 
198
variable Temp  : TIME;
199
variable TransitionTime  : TIME := TIME'HIGH;
200
variable PathDelay : TIME := TIME'HIGH;
201
 
202
begin
203
 
204
    for i IN Paths'RANGE loop
205
        next when not Paths(i).PathCondition;
206
 
207
        next when Paths(i).InputChangeTime > TransitionTime;
208
 
209
        Temp := Paths(i).PathDelay(tr01);
210
 
211
        if Paths(i).InputChangeTime < TransitionTime then
212
            PathDelay := Temp;
213
        else
214
            if Temp < PathDelay then
215
                PathDelay := Temp;
216
            end if;
217
        end if;
218
        TransitionTime := Paths(i).InputChangeTime;
219
    end loop;
220
 
221
    return PathDelay;
222
 
223
end;
224
 
225
end stratixii_atom_pack;
226
 
227
Library ieee;
228
use ieee.std_logic_1164.all;
229
 
230
Package stratixii_pllpack is
231
 
232
 
233
    procedure find_simple_integer_fraction( numerator   : in integer;
234
                                            denominator : in integer;
235
                                            max_denom   : in integer;
236
                                            fraction_num : out integer;
237
                                            fraction_div : out integer);
238
 
239
    function gcd (X: integer; Y: integer) return integer;
240
 
241
    function count_digit (X: integer) return integer;
242
 
243
    function scale_num (X: integer; Y: integer) return integer;
244
 
245
    function lcm (A1: integer; A2: integer; A3: integer; A4: integer;
246
                A5: integer; A6: integer; A7: integer;
247
                A8: integer; A9: integer; A10: integer; P: integer) return integer;
248
 
249
    function output_counter_value (clk_divide: integer; clk_mult : integer ;
250
            M: integer; N: integer ) return integer;
251
 
252
    function counter_mode (duty_cycle: integer; output_counter_value: integer) return string;
253
 
254
    function counter_high (output_counter_value: integer := 1; duty_cycle: integer)
255
                        return integer;
256
 
257
    function counter_low (output_counter_value: integer; duty_cycle: integer)
258
                        return integer;
259
 
260
    function mintimedelay (t1: integer; t2: integer; t3: integer; t4: integer;
261
                        t5: integer; t6: integer; t7: integer; t8: integer;
262
                        t9: integer; t10: integer) return integer;
263
 
264
    function maxnegabs (t1: integer; t2: integer; t3: integer; t4: integer;
265
                        t5: integer; t6: integer; t7: integer; t8: integer;
266
                        t9: integer; t10: integer) return integer;
267
 
268
    function counter_time_delay ( clk_time_delay: integer;
269
                        m_time_delay: integer; n_time_delay: integer)
270
                        return integer;
271
 
272
    function get_phase_degree (phase_shift: integer; clk_period: integer) return integer;
273
 
274
    function counter_initial (tap_phase: integer; m: integer; n: integer)
275
                        return integer;
276
 
277
    function counter_ph (tap_phase: integer; m : integer; n: integer) return integer;
278
 
279
    function ph_adjust (tap_phase: integer; ph_base : integer) return integer;
280
 
281
    function translate_string (mode : string) return string;
282
 
283
    function str2int (s : string) return integer;
284
 
285
    function dqs_str2int (s : string) return integer;
286
 
287
end stratixii_pllpack;
288
 
289
package body stratixii_pllpack is
290
 
291
 
292
-- finds the closest integer fraction of a given pair of numerator and denominator.
293
procedure find_simple_integer_fraction( numerator   : in integer;
294
                                        denominator : in integer;
295
                                        max_denom   : in integer;
296
                                        fraction_num : out integer;
297
                                        fraction_div : out integer) is
298
    constant MAX_ITER : integer := 20;
299
    type INT_ARRAY is array ((MAX_ITER-1) downto 0) of integer;
300
 
301
    variable quotient_array : INT_ARRAY;
302
    variable int_loop_iter : integer;
303
    variable int_quot  : integer;
304
    variable m_value   : integer;
305
    variable d_value   : integer;
306
    variable old_m_value : integer;
307
    variable swap  : integer;
308
    variable loop_iter : integer;
309
    variable num   : integer;
310
    variable den   : integer;
311
    variable i_max_iter : integer;
312
 
313
begin
314
    loop_iter := 0;
315
    num := numerator;
316
    den := denominator;
317
    i_max_iter := max_iter;
318
 
319
    while (loop_iter < i_max_iter) loop
320
        int_quot := num / den;
321
        quotient_array(loop_iter) := int_quot;
322
        num := num - (den*int_quot);
323
        loop_iter := loop_iter+1;
324
 
325
        if ((num = 0) or (max_denom /= -1) or (loop_iter = i_max_iter)) then
326
            -- calculate the numerator and denominator if there is a restriction on the
327
            -- max denom value or if the loop is ending
328
            m_value := 0;
329
            d_value := 1;
330
            -- get the rounded value at this stage for the remaining fraction
331
            if (den /= 0) then
332
                m_value := (2*num/den);
333
            end if;
334
            -- calculate the fraction numerator and denominator at this stage
335
            for int_loop_iter in (loop_iter-1) downto 0 loop
336
                if (m_value = 0) then
337
                    m_value := quotient_array(int_loop_iter);
338
                    d_value := 1;
339
                else
340
                    old_m_value := m_value;
341
                    m_value := (quotient_array(int_loop_iter)*m_value) + d_value;
342
                    d_value := old_m_value;
343
                end if;
344
            end loop;
345
            -- if the denominator is less than the maximum denom_value or if there is no restriction save it
346
            if ((d_value <= max_denom) or (max_denom = -1)) then
347
                if ((m_value = 0) or (d_value = 0)) then
348
                    fraction_num := numerator;
349
                    fraction_div := denominator;
350
                else
351
                    fraction_num := m_value;
352
                    fraction_div := d_value;
353
                end if;
354
            end if;
355
            -- end the loop if the denomitor has overflown or the numerator is zero (no remainder during this round)
356
            if (((d_value > max_denom) and (max_denom /= -1)) or (num = 0)) then
357
                i_max_iter := loop_iter;
358
            end if;
359
        end if;
360
        -- swap the numerator and denominator for the next round
361
        swap := den;
362
        den := num;
363
        num := swap;
364
    end loop;
365
end find_simple_integer_fraction;
366
 
367
-- find the greatest common denominator of X and Y
368
function gcd (X: integer; Y: integer) return integer is
369
variable L, S, R, G : integer := 1;
370
begin
371
    if (X < Y) then -- find which is smaller.
372
        S := X;
373
        L := Y;
374
    else
375
        S := Y;
376
        L := X;
377
    end if;
378
 
379
    R := S;
380
    while ( R > 1) loop
381
        S := L;
382
        L := R;
383
        R := S rem L;   -- divide bigger number by smaller.
384
                        -- remainder becomes smaller number.
385
    end loop;
386
    if (R = 0) then  -- if evenly divisible then L is gcd else it is 1.
387
        G := L;
388
    else
389
        G := R;
390
    end if;
391
 
392
    return G;
393
end gcd;
394
 
395
-- count the number of digits in the given integer
396
function count_digit (X: integer)
397
        return integer is
398
variable count, result: integer := 0;
399
begin
400
    result := X;
401
    while (result /= 0) loop
402
        result := (result / 10);
403
        count := count + 1;
404
    end loop;
405
 
406
    return count;
407
end count_digit;
408
 
409
-- reduce the given huge number to Y significant digits
410
function scale_num (X: integer; Y: integer)
411
        return integer is
412
variable count : integer := 0;
413
variable lc, fac_ten, result: integer := 1;
414
begin
415
    count := count_digit(X);
416
 
417
    for lc in 1 to (count-Y) loop
418
        fac_ten := fac_ten * 10;
419
    end loop;
420
 
421
    result := (X / fac_ten);
422
 
423
    return result;
424
end scale_num;
425
 
426
-- find the least common multiple of A1 to A10
427
function lcm (A1: integer; A2: integer; A3: integer; A4: integer;
428
            A5: integer; A6: integer; A7: integer;
429
            A8: integer; A9: integer; A10: integer; P: integer)
430
        return integer is
431
variable M1, M2, M3, M4, M5 , M6, M7, M8, M9, R: integer := 1;
432
begin
433
    M1 := (A1 * A2)/gcd(A1, A2);
434
    M2 := (M1 * A3)/gcd(M1, A3);
435
    M3 := (M2 * A4)/gcd(M2, A4);
436
    M4 := (M3 * A5)/gcd(M3, A5);
437
    M5 := (M4 * A6)/gcd(M4, A6);
438
    M6 := (M5 * A7)/gcd(M5, A7);
439
    M7 := (M6 * A8)/gcd(M6, A8);
440
    M8 := (M7 * A9)/gcd(M7, A9);
441
    M9 := (M8 * A10)/gcd(M8, A10);
442
    if (M9 < 3) then
443
        R := 10;
444
    elsif ((M9 <= 10) and (M9 >= 3)) then
445
        R := 4 * M9;
446
    elsif (M9 > 1000) then
447
        R := scale_num(M9,3);
448
    else
449
        R := M9 ;
450
    end if;
451
 
452
    return R;
453
end lcm;
454
 
455
-- find the factor of division of the output clock frequency compared to the VCO
456
function output_counter_value (clk_divide: integer; clk_mult: integer ;
457
                                M: integer; N: integer ) return integer is
458
variable R: integer := 1;
459
begin
460
    R := (clk_divide * M)/(clk_mult * N);
461
 
462
    return R;
463
end output_counter_value;
464
 
465
-- find the mode of each PLL counter - bypass, even or odd
466
function counter_mode (duty_cycle: integer; output_counter_value: integer)
467
        return string is
468
variable R: string (1 to 6) := "      ";
469
variable counter_value: integer := 1;
470
begin
471
    counter_value := (2*duty_cycle*output_counter_value)/100;
472
    if output_counter_value = 1 then
473
        R := "bypass";
474
    elsif (counter_value REM 2) = 0 then
475
        R := "  even";
476
    else
477
        R := "   odd";
478
    end if;
479
 
480
    return R;
481
end counter_mode;
482
 
483
-- find the number of VCO clock cycles to hold the output clock high
484
function counter_high (output_counter_value: integer := 1; duty_cycle: integer)
485
        return integer is
486
variable R: integer := 1;
487
variable half_cycle_high : integer := 1;
488
begin
489
    half_cycle_high := (duty_cycle * output_counter_value *2)/100 ;
490
    if (half_cycle_high REM 2 = 0) then
491
        R := half_cycle_high/2 ;
492
    else
493
        R := (half_cycle_high/2) + 1;
494
    end if;
495
 
496
    return R;
497
end;
498
 
499
-- find the number of VCO clock cycles to hold the output clock low
500
function counter_low (output_counter_value: integer; duty_cycle: integer)
501
        return integer is
502
variable R, R1: integer := 1;
503
variable half_cycle_high : integer := 1;
504
begin
505
    half_cycle_high := (duty_cycle * output_counter_value*2)/100 ;
506
    if (half_cycle_high REM 2 = 0) then
507
        R1 := half_cycle_high/2 ;
508
    else
509
        R1 := (half_cycle_high/2) + 1;
510
    end if;
511
 
512
    R := output_counter_value - R1;
513
 
514
    return R;
515
end;
516
 
517
-- find the smallest time delay amongst t1 to t10
518
function mintimedelay (t1: integer; t2: integer; t3: integer; t4: integer;
519
                        t5: integer; t6: integer; t7: integer; t8: integer;
520
                        t9: integer; t10: integer) return integer is
521
variable m1,m2,m3,m4,m5,m6,m7,m8,m9 : integer := 0;
522
begin
523
    if (t1 < t2) then m1 := t1; else m1 := t2; end if;
524
    if (m1 < t3) then m2 := m1; else m2 := t3; end if;
525
    if (m2 < t4) then m3 := m2; else m3 := t4; end if;
526
    if (m3 < t5) then m4 := m3; else m4 := t5; end if;
527
    if (m4 < t6) then m5 := m4; else m5 := t6; end if;
528
    if (m5 < t7) then m6 := m5; else m6 := t7; end if;
529
    if (m6 < t8) then m7 := m6; else m7 := t8; end if;
530
    if (m7 < t9) then m8 := m7; else m8 := t9; end if;
531
    if (m8 < t10) then m9 := m8; else m9 := t10; end if;
532
    if (m9 > 0) then return m9; else return 0; end if;
533
end;
534
 
535
-- find the numerically largest negative number, and return its absolute value
536
function maxnegabs (t1: integer; t2: integer; t3: integer; t4: integer;
537
                    t5: integer; t6: integer; t7: integer; t8: integer;
538
                    t9: integer; t10: integer) return integer is
539
variable m1,m2,m3,m4,m5,m6,m7,m8,m9 : integer := 0;
540
begin
541
    if (t1 < t2) then m1 := t1; else m1 := t2; end if;
542
    if (m1 < t3) then m2 := m1; else m2 := t3; end if;
543
    if (m2 < t4) then m3 := m2; else m3 := t4; end if;
544
    if (m3 < t5) then m4 := m3; else m4 := t5; end if;
545
    if (m4 < t6) then m5 := m4; else m5 := t6; end if;
546
    if (m5 < t7) then m6 := m5; else m6 := t7; end if;
547
    if (m6 < t8) then m7 := m6; else m7 := t8; end if;
548
    if (m7 < t9) then m8 := m7; else m8 := t9; end if;
549
    if (m8 < t10) then m9 := m8; else m9 := t10; end if;
550
    if (m9 < 0) then return (0 - m9); else return 0; end if;
551
end;
552
 
553
-- adjust the phase (tap_phase) with the largest negative number (ph_base)
554
function ph_adjust (tap_phase: integer; ph_base : integer) return integer is
555
begin
556
    return (tap_phase + ph_base);
557
end;
558
 
559
-- find the time delay for each PLL counter
560
function counter_time_delay (clk_time_delay: integer;
561
                            m_time_delay: integer; n_time_delay: integer)
562
        return integer is
563
variable R: integer := 0;
564
begin
565
    R := clk_time_delay + m_time_delay - n_time_delay;
566
 
567
    return R;
568
end;
569
 
570
-- calculate the given phase shift (in ps) in terms of degrees
571
function get_phase_degree (phase_shift: integer; clk_period: integer)
572
        return integer is
573
variable result: integer := 0;
574
begin
575
    result := ( phase_shift * 360 ) / clk_period;
576
    -- to round up the calculation result
577
    if (result > 0) then
578
        result := result + 1;
579
    elsif (result < 0) then
580
        result := result - 1;
581
    else
582
        result := 0;
583
    end if;
584
 
585
    return result;
586
end;
587
 
588
-- find the number of VCO clock cycles to wait initially before the first rising
589
-- edge of the output clock
590
function counter_initial (tap_phase: integer; m: integer; n: integer)
591
        return integer is
592
variable R: integer;
593
variable R1: real;
594
begin
595
    R1 := (real(abs(tap_phase)) * real(m))/(360.0 * real(n)) + 0.5;
596
    -- Note NCSim VHDL had problem in rounding up for 0.5 - 0.99.
597
    -- This checking will ensure that the rounding up is done.
598
    if (R1 >= 0.5) and (R1 <= 1.0) then
599
        R1 := 1.0;
600
    end if;
601
 
602
    R := integer(R1);
603
 
604
    return R;
605
end;
606
 
607
-- find which VCO phase tap (0 to 7) to align the rising edge of the output clock to
608
function counter_ph (tap_phase: integer; m: integer; n: integer) return integer is
609
variable R: integer := 0;
610
begin
611
    -- 0.5 is added for proper rounding of the tap_phase.
612
    R := (integer(real(tap_phase * m / n)+ 0.5) REM 360)/45;
613
 
614
    return R;
615
end;
616
 
617
-- convert given string to length 6 by padding with spaces
618
function translate_string (mode : string) return string is
619
variable new_mode : string (1 to 6) := "      ";
620
begin
621
    if (mode = "bypass") then
622
        new_mode := "bypass";
623
    elsif (mode = "even") then
624
        new_mode := "  even";
625
    elsif (mode = "odd") then
626
        new_mode := "   odd";
627
    end if;
628
 
629
    return new_mode;
630
end;
631
 
632
function str2int (s : string) return integer is
633
variable len : integer := s'length;
634
variable newdigit : integer := 0;
635
variable sign : integer := 1;
636
variable digit : integer := 0;
637
begin
638
    for i in 1 to len loop
639
        case s(i) is
640
            when '-' =>
641
                if i = 1 then
642
                    sign := -1;
643
                else
644
                    ASSERT FALSE
645
                    REPORT "Illegal Character "&  s(i) & "i n string parameter! "
646
                    SEVERITY ERROR;
647
                end if;
648
            when '0' =>
649
                digit := 0;
650
            when '1' =>
651
                digit := 1;
652
            when '2' =>
653
                digit := 2;
654
            when '3' =>
655
                digit := 3;
656
            when '4' =>
657
                digit := 4;
658
            when '5' =>
659
                digit := 5;
660
            when '6' =>
661
                digit := 6;
662
            when '7' =>
663
                digit := 7;
664
            when '8' =>
665
                digit := 8;
666
            when '9' =>
667
                digit := 9;
668
            when others =>
669
                ASSERT FALSE
670
                REPORT "Illegal Character "&  s(i) & "in string parameter! "
671
                SEVERITY ERROR;
672
        end case;
673
        newdigit := newdigit * 10 + digit;
674
    end loop;
675
 
676
    return (sign*newdigit);
677
end;
678
 
679
function dqs_str2int (s : string) return integer is
680
variable len : integer := s'length;
681
variable newdigit : integer := 0;
682
variable sign : integer := 1;
683
variable digit : integer := 0;
684
variable err : boolean := false;
685
begin
686
    for i in 1 to len loop
687
        case s(i) is
688
            when '-' =>
689
                if i = 1 then
690
                    sign := -1;
691
                else
692
                    ASSERT FALSE
693
                    REPORT "Illegal Character "&  s(i) & " in string parameter! "
694
                    SEVERITY ERROR;
695
                    err := true;
696
                end if;
697
            when '0' =>
698
                digit := 0;
699
            when '1' =>
700
                digit := 1;
701
            when '2' =>
702
                digit := 2;
703
            when '3' =>
704
                digit := 3;
705
            when '4' =>
706
                digit := 4;
707
            when '5' =>
708
                digit := 5;
709
            when '6' =>
710
                digit := 6;
711
            when '7' =>
712
                digit := 7;
713
            when '8' =>
714
                digit := 8;
715
            when '9' =>
716
                digit := 9;
717
            when others =>
718
                -- set error flag
719
                err := true;
720
        end case;
721
        if (err) then
722
            err := false;
723
        else
724
            newdigit := newdigit * 10 + digit;
725
        end if;
726
    end loop;
727
 
728
    return (sign*newdigit);
729
end;
730
 
731
end stratixii_pllpack;
732
 
733
--
734
--
735
--  DFFE Model
736
--
737
--
738
 
739
LIBRARY IEEE;
740
use IEEE.STD_LOGIC_1164.all;
741
use IEEE.VITAL_Timing.all;
742
use IEEE.VITAL_Primitives.all;
743
use work.stratixii_atom_pack.all;
744
 
745
entity stratixii_dffe is
746
    generic(
747
        TimingChecksOn: Boolean := True;
748
        XOn: Boolean := DefGlitchXOn;
749
        MsgOn: Boolean := DefGlitchMsgOn;
750
        MsgOnChecks: Boolean := DefMsgOnChecks;
751
        XOnChecks: Boolean := DefXOnChecks;
752
        InstancePath: STRING := "*";
753
        tpd_PRN_Q_negedge              :  VitalDelayType01 := DefPropDelay01;
754
        tpd_CLRN_Q_negedge             :  VitalDelayType01 := DefPropDelay01;
755
        tpd_CLK_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
756
        tpd_ENA_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
757
        tsetup_D_CLK_noedge_posedge    :  VitalDelayType := DefSetupHoldCnst;
758
        tsetup_D_CLK_noedge_negedge    :  VitalDelayType := DefSetupHoldCnst;
759
        tsetup_ENA_CLK_noedge_posedge  :  VitalDelayType := DefSetupHoldCnst;
760
        thold_D_CLK_noedge_posedge     :   VitalDelayType := DefSetupHoldCnst;
761
        thold_D_CLK_noedge_negedge     :   VitalDelayType := DefSetupHoldCnst;
762
        thold_ENA_CLK_noedge_posedge   :   VitalDelayType := DefSetupHoldCnst;
763
        tipd_D                         :  VitalDelayType01 := DefPropDelay01;
764
        tipd_CLRN                      :  VitalDelayType01 := DefPropDelay01;
765
        tipd_PRN                       :  VitalDelayType01 := DefPropDelay01;
766
        tipd_CLK                       :  VitalDelayType01 := DefPropDelay01;
767
        tipd_ENA                       :  VitalDelayType01 := DefPropDelay01);
768
 
769
    port(
770
        Q                              :  out   STD_LOGIC := '0';
771
        D                              :  in    STD_LOGIC;
772
        CLRN                           :  in    STD_LOGIC;
773
        PRN                            :  in    STD_LOGIC;
774
        CLK                            :  in    STD_LOGIC;
775
        ENA                            :  in    STD_LOGIC);
776
    attribute VITAL_LEVEL0 of stratixii_dffe : entity is TRUE;
777
end stratixii_dffe;
778
 
779
-- architecture body --
780
 
781
architecture behave of stratixii_dffe is
782
    attribute VITAL_LEVEL0 of behave : architecture is TRUE;
783
 
784
    signal D_ipd  : STD_ULOGIC := 'U';
785
    signal CLRN_ipd       : STD_ULOGIC := 'U';
786
    signal PRN_ipd        : STD_ULOGIC := 'U';
787
    signal CLK_ipd        : STD_ULOGIC := 'U';
788
    signal ENA_ipd        : STD_ULOGIC := 'U';
789
 
790
begin
791
 
792
    ---------------------
793
    --  INPUT PATH DELAYs
794
    ---------------------
795
    WireDelay : block
796
    begin
797
        VitalWireDelay (D_ipd, D, tipd_D);
798
        VitalWireDelay (CLRN_ipd, CLRN, tipd_CLRN);
799
        VitalWireDelay (PRN_ipd, PRN, tipd_PRN);
800
        VitalWireDelay (CLK_ipd, CLK, tipd_CLK);
801
        VitalWireDelay (ENA_ipd, ENA, tipd_ENA);
802
    end block;
803
    --------------------
804
    --  BEHAVIOR SECTION
805
    --------------------
806
    VITALBehavior : process (D_ipd, CLRN_ipd, PRN_ipd, CLK_ipd, ENA_ipd)
807
 
808
    -- timing check results
809
    VARIABLE Tviol_D_CLK : STD_ULOGIC := '0';
810
    VARIABLE Tviol_ENA_CLK       : STD_ULOGIC := '0';
811
    VARIABLE TimingData_D_CLK : VitalTimingDataType := VitalTimingDataInit;
812
    VARIABLE TimingData_ENA_CLK : VitalTimingDataType := VitalTimingDataInit;
813
 
814
    -- functionality results
815
    VARIABLE Violation : STD_ULOGIC := '0';
816
    VARIABLE PrevData_Q : STD_LOGIC_VECTOR(0 to 7);
817
    VARIABLE D_delayed : STD_ULOGIC := 'U';
818
    VARIABLE CLK_delayed : STD_ULOGIC := 'U';
819
    VARIABLE ENA_delayed : STD_ULOGIC := 'U';
820
    VARIABLE Results : STD_LOGIC_VECTOR(1 to 1) := (others => '0');
821
 
822
    -- output glitch detection variables
823
    VARIABLE Q_VitalGlitchData   : VitalGlitchDataType;
824
 
825
 
826
    CONSTANT dffe_Q_tab : VitalStateTableType := (
827
        ( L,  L,  x,  x,  x,  x,  x,  x,  x,  L ),
828
        ( L,  H,  L,  H,  H,  x,  x,  H,  x,  H ),
829
        ( L,  H,  L,  H,  x,  L,  x,  H,  x,  H ),
830
        ( L,  H,  L,  x,  H,  H,  x,  H,  x,  H ),
831
        ( L,  H,  H,  x,  x,  x,  H,  x,  x,  S ),
832
        ( L,  H,  x,  x,  x,  x,  L,  x,  x,  H ),
833
        ( L,  H,  x,  x,  x,  x,  H,  L,  x,  S ),
834
        ( L,  x,  L,  L,  L,  x,  H,  H,  x,  L ),
835
        ( L,  x,  L,  L,  x,  L,  H,  H,  x,  L ),
836
        ( L,  x,  L,  x,  L,  H,  H,  H,  x,  L ),
837
        ( L,  x,  x,  x,  x,  x,  x,  x,  x,  S ));
838
    begin
839
 
840
        ------------------------
841
        --  Timing Check Section
842
        ------------------------
843
        if (TimingChecksOn) then
844
            VitalSetupHoldCheck (
845
                Violation       => Tviol_D_CLK,
846
                TimingData      => TimingData_D_CLK,
847
                TestSignal      => D_ipd,
848
                TestSignalName  => "D",
849
                RefSignal       => CLK_ipd,
850
                RefSignalName   => "CLK",
851
                SetupHigh       => tsetup_D_CLK_noedge_posedge,
852
                SetupLow        => tsetup_D_CLK_noedge_posedge,
853
                HoldHigh        => thold_D_CLK_noedge_posedge,
854
                HoldLow         => thold_D_CLK_noedge_posedge,
855
                CheckEnabled    => TO_X01(( (NOT PRN_ipd) ) OR ( (NOT CLRN_ipd) ) OR ( (NOT ENA_ipd) )) /= '1',
856
                RefTransition   => '/',
857
                HeaderMsg       => InstancePath & "/DFFE",
858
                XOn             => XOnChecks,
859
                MsgOn           => MsgOnChecks );
860
 
861
            VitalSetupHoldCheck (
862
                Violation       => Tviol_ENA_CLK,
863
                TimingData      => TimingData_ENA_CLK,
864
                TestSignal      => ENA_ipd,
865
                TestSignalName  => "ENA",
866
                RefSignal       => CLK_ipd,
867
                RefSignalName   => "CLK",
868
                SetupHigh       => tsetup_ENA_CLK_noedge_posedge,
869
                SetupLow        => tsetup_ENA_CLK_noedge_posedge,
870
                HoldHigh        => thold_ENA_CLK_noedge_posedge,
871
                HoldLow         => thold_ENA_CLK_noedge_posedge,
872
                CheckEnabled    => TO_X01(( (NOT PRN_ipd) ) OR ( (NOT CLRN_ipd) ) ) /= '1',
873
                RefTransition   => '/',
874
                HeaderMsg       => InstancePath & "/DFFE",
875
                XOn             => XOnChecks,
876
                MsgOn           => MsgOnChecks );
877
        end if;
878
 
879
        -------------------------
880
        --  Functionality Section
881
        -------------------------
882
        Violation := Tviol_D_CLK or Tviol_ENA_CLK;
883
        VitalStateTable(
884
        StateTable => dffe_Q_tab,
885
        DataIn => (
886
                Violation, CLRN_ipd, CLK_delayed, Results(1), D_delayed, ENA_delayed, PRN_ipd, CLK_ipd),
887
        Result => Results,
888
        NumStates => 1,
889
        PreviousDataIn => PrevData_Q);
890
        D_delayed := D_ipd;
891
        CLK_delayed := CLK_ipd;
892
        ENA_delayed := ENA_ipd;
893
 
894
        ----------------------
895
        --  Path Delay Section
896
        ----------------------
897
        VitalPathDelay01 (
898
        OutSignal => Q,
899
        OutSignalName => "Q",
900
        OutTemp => Results(1),
901
        Paths => (  0 => (PRN_ipd'last_event, tpd_PRN_Q_negedge, TRUE),
902
                    1 => (CLRN_ipd'last_event, tpd_CLRN_Q_negedge, TRUE),
903
                    2 => (CLK_ipd'last_event, tpd_CLK_Q_posedge, TRUE)),
904
        GlitchData => Q_VitalGlitchData,
905
        Mode => DefGlitchMode,
906
        XOn  => XOn,
907
        MsgOn        => MsgOn );
908
 
909
    end process;
910
 
911
end behave;
912
 
913
--
914
--
915
--  stratixii_mux21 Model
916
--
917
--
918
 
919
LIBRARY IEEE;
920
use ieee.std_logic_1164.all;
921
use IEEE.VITAL_Timing.all;
922
use work.stratixii_atom_pack.all;
923
 
924
entity stratixii_mux21 is
925
    generic(
926
        TimingChecksOn: Boolean := True;
927
        MsgOn: Boolean := DefGlitchMsgOn;
928
        XOn: Boolean := DefGlitchXOn;
929
        InstancePath: STRING := "*";
930
        tpd_A_MO                      :   VitalDelayType01 := DefPropDelay01;
931
        tpd_B_MO                      :   VitalDelayType01 := DefPropDelay01;
932
        tpd_S_MO                      :   VitalDelayType01 := DefPropDelay01;
933
        tipd_A                       :    VitalDelayType01 := DefPropDelay01;
934
        tipd_B                       :    VitalDelayType01 := DefPropDelay01;
935
        tipd_S                       :    VitalDelayType01 := DefPropDelay01);
936
    port (
937
        A : in std_logic := '0';
938
        B : in std_logic := '0';
939
        S : in std_logic := '0';
940
        MO : out std_logic);
941
    attribute VITAL_LEVEL0 of stratixii_mux21 : entity is TRUE;
942
end stratixii_mux21;
943
 
944
architecture AltVITAL of stratixii_mux21 is
945
    attribute VITAL_LEVEL0 of AltVITAL : architecture is TRUE;
946
 
947
    signal A_ipd, B_ipd, S_ipd  : std_logic;
948
 
949
begin
950
 
951
    ---------------------
952
    --  INPUT PATH DELAYs
953
    ---------------------
954
    WireDelay : block
955
    begin
956
        VitalWireDelay (A_ipd, A, tipd_A);
957
        VitalWireDelay (B_ipd, B, tipd_B);
958
        VitalWireDelay (S_ipd, S, tipd_S);
959
    end block;
960
 
961
    --------------------
962
    --  BEHAVIOR SECTION
963
    --------------------
964
    VITALBehavior : process (A_ipd, B_ipd, S_ipd)
965
 
966
    -- output glitch detection variables
967
    VARIABLE MO_GlitchData       : VitalGlitchDataType;
968
 
969
    variable tmp_MO : std_logic;
970
    begin
971
        -------------------------
972
        --  Functionality Section
973
        -------------------------
974
        if (S_ipd = '1') then
975
            tmp_MO := B_ipd;
976
        else
977
            tmp_MO := A_ipd;
978
        end if;
979
 
980
        ----------------------
981
        --  Path Delay Section
982
        ----------------------
983
        VitalPathDelay01 (
984
        OutSignal => MO,
985
        OutSignalName => "MO",
986
        OutTemp => tmp_MO,
987
        Paths => (  0 => (A_ipd'last_event, tpd_A_MO, TRUE),
988
                    1 => (B_ipd'last_event, tpd_B_MO, TRUE),
989
                    2 => (S_ipd'last_event, tpd_S_MO, TRUE)),
990
        GlitchData => MO_GlitchData,
991
        Mode => DefGlitchMode,
992
        XOn  => XOn,
993
        MsgOn        => MsgOn );
994
 
995
    end process;
996
end AltVITAL;
997
 
998
--
999
--
1000
--  stratixii_mux41 Model
1001
--
1002
--
1003
 
1004
LIBRARY IEEE;
1005
use ieee.std_logic_1164.all;
1006
use IEEE.VITAL_Timing.all;
1007
use work.stratixii_atom_pack.all;
1008
 
1009
entity stratixii_mux41 is
1010
    generic(
1011
            TimingChecksOn: Boolean := True;
1012
            MsgOn: Boolean := DefGlitchMsgOn;
1013
            XOn: Boolean := DefGlitchXOn;
1014
            InstancePath: STRING := "*";
1015
            tpd_IN0_MO : VitalDelayType01 := DefPropDelay01;
1016
            tpd_IN1_MO : VitalDelayType01 := DefPropDelay01;
1017
            tpd_IN2_MO : VitalDelayType01 := DefPropDelay01;
1018
            tpd_IN3_MO : VitalDelayType01 := DefPropDelay01;
1019
            tpd_S_MO : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01);
1020
            tipd_IN0 : VitalDelayType01 := DefPropDelay01;
1021
            tipd_IN1 : VitalDelayType01 := DefPropDelay01;
1022
            tipd_IN2 : VitalDelayType01 := DefPropDelay01;
1023
            tipd_IN3 : VitalDelayType01 := DefPropDelay01;
1024
            tipd_S : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01)
1025
        );
1026
    port (
1027
            IN0 : in std_logic := '0';
1028
            IN1 : in std_logic := '0';
1029
            IN2 : in std_logic := '0';
1030
            IN3 : in std_logic := '0';
1031
            S : in std_logic_vector(1 downto 0) := (OTHERS => '0');
1032
            MO : out std_logic
1033
        );
1034
    attribute VITAL_LEVEL0 of stratixii_mux41 : entity is TRUE;
1035
end stratixii_mux41;
1036
 
1037
architecture AltVITAL of stratixii_mux41 is
1038
    attribute VITAL_LEVEL0 of AltVITAL : architecture is TRUE;
1039
 
1040
    signal IN0_ipd, IN1_ipd, IN2_ipd, IN3_ipd  : std_logic;
1041
    signal S_ipd : std_logic_vector(1 downto 0);
1042
 
1043
begin
1044
 
1045
    ---------------------
1046
    --  INPUT PATH DELAYs
1047
    ---------------------
1048
    WireDelay : block
1049
    begin
1050
        VitalWireDelay (IN0_ipd, IN0, tipd_IN0);
1051
        VitalWireDelay (IN1_ipd, IN1, tipd_IN1);
1052
        VitalWireDelay (IN2_ipd, IN2, tipd_IN2);
1053
        VitalWireDelay (IN3_ipd, IN3, tipd_IN3);
1054
        VitalWireDelay (S_ipd(0), S(0), tipd_S(0));
1055
        VitalWireDelay (S_ipd(1), S(1), tipd_S(1));
1056
    end block;
1057
 
1058
    --------------------
1059
    --  BEHAVIOR SECTION
1060
    --------------------
1061
    VITALBehavior : process (IN0_ipd, IN1_ipd, IN2_ipd, IN3_ipd, S_ipd(0), S_ipd(1))
1062
 
1063
    -- output glitch detection variables
1064
    VARIABLE MO_GlitchData       : VitalGlitchDataType;
1065
 
1066
    variable tmp_MO : std_logic;
1067
    begin
1068
        -------------------------
1069
        --  Functionality Section
1070
        -------------------------
1071
        if ((S_ipd(1) = '1') AND (S_ipd(0) = '1')) then
1072
            tmp_MO := IN3_ipd;
1073
        elsif ((S_ipd(1) = '1') AND (S_ipd(0) = '0')) then
1074
            tmp_MO := IN2_ipd;
1075
        elsif ((S_ipd(1) = '0') AND (S_ipd(0) = '1')) then
1076
            tmp_MO := IN1_ipd;
1077
        else
1078
            tmp_MO := IN0_ipd;
1079
        end if;
1080
 
1081
        ----------------------
1082
        --  Path Delay Section
1083
        ----------------------
1084
        VitalPathDelay01 (
1085
                        OutSignal => MO,
1086
                        OutSignalName => "MO",
1087
                        OutTemp => tmp_MO,
1088
                        Paths => (  0 => (IN0_ipd'last_event, tpd_IN0_MO, TRUE),
1089
                                    1 => (IN1_ipd'last_event, tpd_IN1_MO, TRUE),
1090
                                    2 => (IN2_ipd'last_event, tpd_IN2_MO, TRUE),
1091
                                    3 => (IN3_ipd'last_event, tpd_IN3_MO, TRUE),
1092
                                    4 => (S_ipd(0)'last_event, tpd_S_MO(0), TRUE),
1093
                                    5 => (S_ipd(1)'last_event, tpd_S_MO(1), TRUE)),
1094
                        GlitchData => MO_GlitchData,
1095
                        Mode => DefGlitchMode,
1096
                        XOn  => XOn,
1097
                        MsgOn => MsgOn );
1098
 
1099
    end process;
1100
end AltVITAL;
1101
 
1102
--
1103
--
1104
--  stratixii_and1 Model
1105
--
1106
--
1107
LIBRARY IEEE;
1108
use IEEE.STD_LOGIC_1164.all;
1109
use IEEE.VITAL_Timing.all;
1110
use work.stratixii_atom_pack.all;
1111
 
1112
-- entity declaration --
1113
entity stratixii_and1 is
1114
    generic(
1115
        TimingChecksOn: Boolean := True;
1116
        MsgOn: Boolean := DefGlitchMsgOn;
1117
        XOn: Boolean := DefGlitchXOn;
1118
        InstancePath: STRING := "*";
1119
        tpd_IN1_Y                      :  VitalDelayType01 := DefPropDelay01;
1120
        tipd_IN1                       :  VitalDelayType01 := DefPropDelay01);
1121
 
1122
    port(
1123
        Y                              :  out   STD_LOGIC;
1124
        IN1                            :  in    STD_LOGIC);
1125
    attribute VITAL_LEVEL0 of stratixii_and1 : entity is TRUE;
1126
end stratixii_and1;
1127
 
1128
-- architecture body --
1129
 
1130
architecture AltVITAL of stratixii_and1 is
1131
    attribute VITAL_LEVEL0 of AltVITAL : architecture is TRUE;
1132
 
1133
    SIGNAL IN1_ipd    : STD_ULOGIC := 'U';
1134
 
1135
begin
1136
 
1137
    ---------------------
1138
    --  INPUT PATH DELAYs
1139
    ---------------------
1140
    WireDelay : block
1141
    begin
1142
    VitalWireDelay (IN1_ipd, IN1, tipd_IN1);
1143
    end block;
1144
    --------------------
1145
    --  BEHAVIOR SECTION
1146
    --------------------
1147
    VITALBehavior : process (IN1_ipd)
1148
 
1149
 
1150
    -- functionality results
1151
    VARIABLE Results : STD_LOGIC_VECTOR(1 to 1) := (others => 'X');
1152
    ALIAS Y_zd : STD_ULOGIC is Results(1);
1153
 
1154
    -- output glitch detection variables
1155
    VARIABLE Y_GlitchData    : VitalGlitchDataType;
1156
 
1157
    begin
1158
 
1159
        -------------------------
1160
        --  Functionality Section
1161
        -------------------------
1162
        Y_zd := TO_X01(IN1_ipd);
1163
 
1164
        ----------------------
1165
        --  Path Delay Section
1166
        ----------------------
1167
        VitalPathDelay01 (
1168
            OutSignal => Y,
1169
            OutSignalName => "Y",
1170
            OutTemp => Y_zd,
1171
            Paths => (0 => (IN1_ipd'last_event, tpd_IN1_Y, TRUE)),
1172
            GlitchData => Y_GlitchData,
1173
            Mode => DefGlitchMode,
1174
            XOn  => XOn,
1175
            MsgOn        => MsgOn );
1176
 
1177
    end process;
1178
end AltVITAL;
1179
----------------------------------------------------------------------------
1180
-- Module Name     : stratixii_ram_register
1181
-- Description     : Register module for RAM inputs/outputs
1182
----------------------------------------------------------------------------
1183
 
1184
LIBRARY IEEE;
1185
USE IEEE.STD_LOGIC_1164.ALL;
1186
USE IEEE.VITAL_Timing.all;
1187
USE IEEE.VITAL_Primitives.all;
1188
USE work.stratixii_atom_pack.all;
1189
 
1190
ENTITY stratixii_ram_register IS
1191
 
1192
GENERIC (
1193
    width   : INTEGER := 1;
1194
    preset  : STD_LOGIC := '0';
1195
    tipd_d  : VitalDelayArrayType01(143 DOWNTO 0) := (OTHERS => DefPropDelay01);
1196
    tipd_clk        : VitalDelayType01 := DefPropDelay01;
1197
    tipd_ena        : VitalDelayType01 := DefPropDelay01;
1198
    tipd_stall      : VitalDelayType01 := DefPropDelay01;
1199
    tipd_aclr       : VitalDelayType01 := DefPropDelay01;
1200
    tpw_ena_posedge : VitalDelayType   := DefPulseWdthCnst;
1201
    tpd_clk_q_posedge        : VitalDelayType01 := DefPropDelay01;
1202
    tpd_aclr_q_posedge       : VitalDelayType01 := DefPropDelay01;
1203
    tsetup_d_clk_noedge_posedge    : VitalDelayType := DefSetupHoldCnst;
1204
    thold_d_clk_noedge_posedge     : VitalDelayType := DefSetupHoldCnst;
1205
    tsetup_ena_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
1206
    thold_ena_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
1207
    tsetup_stall_clk_noedge_posedge  : VitalDelayType   := DefSetupHoldCnst;
1208
    thold_stall_clk_noedge_posedge   : VitalDelayType   := DefSetupHoldCnst;
1209
    tsetup_aclr_clk_noedge_posedge : VitalDelayType   := DefSetupHoldCnst;
1210
    thold_aclr_clk_noedge_posedge  : VitalDelayType   := DefSetupHoldCnst
1211
    );
1212
 
1213
PORT (
1214
    d       : IN STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1215
    clk     : IN STD_LOGIC;
1216
    ena     : IN STD_LOGIC;
1217
    stall : IN STD_LOGIC;
1218
    aclr    : IN STD_LOGIC;
1219
    devclrn : IN STD_LOGIC;
1220
    devpor  : IN STD_LOGIC;
1221
    q       : OUT STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1222
    aclrout : OUT STD_LOGIC
1223
    );
1224
 
1225
END stratixii_ram_register;
1226
 
1227
ARCHITECTURE reg_arch OF stratixii_ram_register IS
1228
 
1229
SIGNAL d_ipd : STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1230
SIGNAL clk_ipd  : STD_LOGIC;
1231
SIGNAL ena_ipd  : STD_LOGIC;
1232
SIGNAL aclr_ipd : STD_LOGIC;
1233
SIGNAL stall_ipd : STD_LOGIC;
1234
 
1235
BEGIN
1236
 
1237
WireDelay : BLOCK
1238
BEGIN
1239
    loopbits : FOR i in d'RANGE GENERATE
1240
        VitalWireDelay (d_ipd(i), d(i), tipd_d(i));
1241
    END GENERATE;
1242
    VitalWireDelay (clk_ipd, clk, tipd_clk);
1243
    VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
1244
    VitalWireDelay (ena_ipd, ena, tipd_ena);
1245
    VitalWireDelay (stall_ipd, stall, tipd_stall);
1246
END BLOCK;
1247
 
1248
   PROCESS (d_ipd,ena_ipd,stall_ipd,clk_ipd,aclr_ipd,devclrn,devpor)
1249
VARIABLE Tviol_clk_ena        : STD_ULOGIC := '0';
1250
VARIABLE Tviol_clk_aclr       : STD_ULOGIC := '0';
1251
VARIABLE Tviol_data_clk       : STD_ULOGIC := '0';
1252
VARIABLE TimingData_clk_ena   : VitalTimingDataType := VitalTimingDataInit;
1253
VARIABLE TimingData_clk_stall   : VitalTimingDataType := VitalTimingDataInit;
1254
VARIABLE TimingData_clk_aclr  : VitalTimingDataType := VitalTimingDataInit;
1255
VARIABLE TimingData_data_clk  : VitalTimingDataType := VitalTimingDataInit;
1256
VARIABLE Tviol_ena            : STD_ULOGIC := '0';
1257
VARIABLE PeriodData_ena       : VitalPeriodDataType := VitalPeriodDataInit;
1258
VARIABLE q_VitalGlitchDataArray : VitalGlitchDataArrayType(143 downto 0);
1259
VARIABLE CQDelay  : TIME := 0 ns;
1260
VARIABLE q_reg    : STD_LOGIC_VECTOR(width - 1 DOWNTO 0) := (OTHERS => preset);
1261
BEGIN
1262
 
1263
    IF (aclr_ipd = '1' OR devclrn = '0' OR devpor = '0') THEN
1264
        q_reg := (OTHERS => preset);
1265
       ELSIF (clk_ipd = '1' AND clk_ipd'EVENT AND ena_ipd = '1' AND stall_ipd = '0') THEN
1266
        q_reg := d_ipd;
1267
    END IF;
1268
 
1269
    -- Timing checks
1270
    VitalSetupHoldCheck (
1271
        Violation       => Tviol_clk_ena,
1272
        TimingData      => TimingData_clk_ena,
1273
        TestSignal      => ena_ipd,
1274
        TestSignalName  => "ena",
1275
        RefSignal       => clk_ipd,
1276
        RefSignalName   => "clk",
1277
        SetupHigh       => tsetup_ena_clk_noedge_posedge,
1278
        SetupLow        => tsetup_ena_clk_noedge_posedge,
1279
        HoldHigh        => thold_ena_clk_noedge_posedge,
1280
        HoldLow         => thold_ena_clk_noedge_posedge,
1281
        CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1282
        RefTransition   => '/',
1283
        HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1284
        XOn           => DefXOnChecks,
1285
        MsgOn         => DefMsgOnChecks );
1286
 
1287
  VitalSetupHoldCheck (
1288
      Violation       => Tviol_clk_ena,
1289
      TimingData      => TimingData_clk_stall,
1290
      TestSignal      => stall_ipd,
1291
      TestSignalName  => "stall",
1292
      RefSignal       => clk_ipd,
1293
      RefSignalName   => "clk",
1294
      SetupHigh       => tsetup_stall_clk_noedge_posedge,
1295
      SetupLow        => tsetup_stall_clk_noedge_posedge,
1296
      HoldHigh        => thold_stall_clk_noedge_posedge,
1297
      HoldLow         => thold_stall_clk_noedge_posedge,
1298
      CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1299
      RefTransition   => '/',
1300
      HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1301
      XOn           => DefXOnChecks,
1302
      MsgOn         => DefMsgOnChecks );
1303
 
1304
    VitalSetupHoldCheck (
1305
        Violation       => Tviol_clk_aclr,
1306
        TimingData      => TimingData_clk_aclr,
1307
        TestSignal      => aclr_ipd,
1308
        TestSignalName  => "aclr",
1309
        RefSignal       => clk_ipd,
1310
        RefSignalName   => "clk",
1311
        SetupHigh       => tsetup_aclr_clk_noedge_posedge,
1312
        SetupLow        => tsetup_aclr_clk_noedge_posedge,
1313
        HoldHigh        => thold_aclr_clk_noedge_posedge,
1314
        HoldLow         => thold_aclr_clk_noedge_posedge,
1315
        CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1316
        RefTransition   => '/',
1317
        HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1318
        XOn           => DefXOnChecks,
1319
        MsgOn         => DefMsgOnChecks );
1320
 
1321
    VitalSetupHoldCheck (
1322
        Violation       => Tviol_data_clk,
1323
        TimingData      => TimingData_data_clk,
1324
        TestSignal      => d_ipd,
1325
        TestSignalName  => "data",
1326
        RefSignal       => clk_ipd,
1327
        RefSignalName   => "clk",
1328
        SetupHigh       => tsetup_d_clk_noedge_posedge,
1329
        SetupLow        => tsetup_d_clk_noedge_posedge,
1330
        HoldHigh        => thold_d_clk_noedge_posedge,
1331
        HoldLow         => thold_d_clk_noedge_posedge,
1332
        CheckEnabled    => ((aclr_ipd) OR (NOT ena_ipd)) /= '1',
1333
        RefTransition   => '/',
1334
        HeaderMsg       => "/RAM Register VitalSetupHoldCheck",
1335
        XOn           => DefXOnChecks,
1336
        MsgOn         => DefMsgOnChecks );
1337
 
1338
    VitalPeriodPulseCheck (
1339
        Violation       => Tviol_ena,
1340
        PeriodData      => PeriodData_ena,
1341
        TestSignal      => ena_ipd,
1342
        TestSignalName  => "ena",
1343
        PulseWidthHigh  => tpw_ena_posedge,
1344
        HeaderMsg       => "/RAM Register VitalPeriodPulseCheck",
1345
        XOn           => DefXOnChecks,
1346
        MsgOn         => DefMsgOnChecks );
1347
 
1348
    -- Path Delay Selection
1349
    CQDelay := SelectDelay (
1350
                   Paths => (
1351
                       (0 => (clk_ipd'LAST_EVENT,tpd_clk_q_posedge,TRUE),
1352
                        1 => (aclr_ipd'LAST_EVENT,tpd_aclr_q_posedge,TRUE))
1353
                   )
1354
               );
1355
    q <= TRANSPORT q_reg AFTER CQDelay;
1356
 
1357
END PROCESS;
1358
 
1359
aclrout <= aclr_ipd;
1360
 
1361
END reg_arch;
1362
 
1363
----------------------------------------------------------------------------
1364
-- Module Name     : stratixii_ram_pulse_generator
1365
-- Description     : Generate pulse to initiate memory read/write operations
1366
----------------------------------------------------------------------------
1367
 
1368
LIBRARY IEEE;
1369
USE IEEE.STD_LOGIC_1164.ALL;
1370
USE IEEE.VITAL_Timing.all;
1371
USE IEEE.VITAL_Primitives.all;
1372
USE work.stratixii_atom_pack.all;
1373
 
1374
ENTITY stratixii_ram_pulse_generator IS
1375
GENERIC (
1376
    tipd_clk : VitalDelayType01 := (0.5 ns,0.5 ns);
1377
    tipd_ena : VitalDelayType01 := DefPropDelay01;
1378
    tpd_clk_pulse_posedge : VitalDelayType01 := DefPropDelay01
1379
    );
1380
PORT (
1381
    clk,ena : IN STD_LOGIC;
1382
    pulse,cycle : OUT STD_LOGIC
1383
    );
1384
ATTRIBUTE VITAL_Level0 OF stratixii_ram_pulse_generator:ENTITY IS TRUE;
1385
END stratixii_ram_pulse_generator;
1386
 
1387
ARCHITECTURE pgen_arch OF stratixii_ram_pulse_generator IS
1388
ATTRIBUTE VITAL_Level0 OF pgen_arch:ARCHITECTURE IS TRUE;
1389
SIGNAL clk_ipd,ena_ipd : STD_LOGIC;
1390
SIGNAL state : STD_LOGIC;
1391
BEGIN
1392
 
1393
WireDelay : BLOCK
1394
BEGIN
1395
    VitalWireDelay (clk_ipd, clk, tipd_clk);
1396
    VitalWireDelay (ena_ipd, ena, tipd_ena);
1397
END BLOCK;
1398
 
1399
PROCESS (clk_ipd,state)
1400
BEGIN
1401
    IF (state = '1' AND state'EVENT) THEN
1402
        state <= '0';
1403
    ELSIF (clk_ipd = '1' AND clk_ipd'EVENT AND ena_ipd = '1') THEN
1404
        state <= '1';
1405
    END IF;
1406
END PROCESS;
1407
 
1408
PathDelay : PROCESS
1409
VARIABLE pulse_VitalGlitchData : VitalGlitchDataType;
1410
BEGIN
1411
    WAIT UNTIL state'EVENT;
1412
    VitalPathDelay01 (
1413
        OutSignal     => pulse,
1414
        OutSignalName => "pulse",
1415
        OutTemp       => state,
1416
        Paths         => (0 => (clk_ipd'LAST_EVENT,tpd_clk_pulse_posedge,TRUE)),
1417
        GlitchData    => pulse_VitalGlitchData,
1418
        Mode          => DefGlitchMode,
1419
        XOn           => DefXOnChecks,
1420
        MsgOn         => DefMsgOnChecks
1421
    );
1422
END PROCESS;
1423
 
1424
cycle <= clk_ipd;
1425
 
1426
END pgen_arch;
1427
 
1428
LIBRARY IEEE;
1429
USE IEEE.STD_LOGIC_1164.ALL;
1430
USE IEEE.VITAL_Timing.all;
1431
USE IEEE.VITAL_Primitives.all;
1432
USE work.stratixii_atom_pack.all;
1433
USE work.stratixii_ram_register;
1434
USE work.stratixii_ram_pulse_generator;
1435
 
1436
ENTITY stratixii_ram_block IS
1437
    GENERIC (
1438
        -- -------- GLOBAL PARAMETERS ---------
1439
        operation_mode                 :  STRING := "single_port";
1440
        mixed_port_feed_through_mode   :  STRING := "dont_care";
1441
        ram_block_type                 :  STRING := "auto";
1442
        logical_ram_name               :  STRING := "ram_name";
1443
        init_file                      :  STRING := "init_file.hex";
1444
        init_file_layout               :  STRING := "none";
1445
        data_interleave_width_in_bits  :  INTEGER := 1;
1446
        data_interleave_offset_in_bits :  INTEGER := 1;
1447
        port_a_logical_ram_depth       :  INTEGER := 0;
1448
        port_a_logical_ram_width       :  INTEGER := 0;
1449
        port_a_first_address           :  INTEGER := 0;
1450
        port_a_last_address            :  INTEGER := 0;
1451
        port_a_first_bit_number        :  INTEGER := 0;
1452
        port_a_data_in_clear           :  STRING := "none";
1453
        port_a_address_clear           :  STRING := "none";
1454
        port_a_write_enable_clear      :  STRING := "none";
1455
        port_a_data_out_clear          :  STRING := "none";
1456
        port_a_byte_enable_clear       :  STRING := "none";
1457
        port_a_data_in_clock           :  STRING := "clock0";
1458
        port_a_address_clock           :  STRING := "clock0";
1459
        port_a_write_enable_clock      :  STRING := "clock0";
1460
        port_a_byte_enable_clock       :  STRING := "clock0";
1461
        port_a_data_out_clock          :  STRING := "none";
1462
        port_a_data_width              :  INTEGER := 1;
1463
        port_a_address_width           :  INTEGER := 1;
1464
        port_a_byte_enable_mask_width  :  INTEGER := 1;
1465
        port_b_logical_ram_depth       :  INTEGER := 0;
1466
        port_b_logical_ram_width       :  INTEGER := 0;
1467
        port_b_first_address           :  INTEGER := 0;
1468
        port_b_last_address            :  INTEGER := 0;
1469
        port_b_first_bit_number        :  INTEGER := 0;
1470
        port_b_data_in_clear           :  STRING := "none";
1471
        port_b_address_clear           :  STRING := "none";
1472
        port_b_read_enable_write_enable_clear: STRING := "none";
1473
        port_b_byte_enable_clear       :  STRING := "none";
1474
        port_b_data_out_clear          :  STRING := "none";
1475
        port_b_data_in_clock           :  STRING := "clock0";
1476
        port_b_address_clock           :  STRING := "clock0";
1477
        port_b_read_enable_write_enable_clock: STRING := "clock0";
1478
        port_b_byte_enable_clock       :  STRING := "none";
1479
        port_b_data_out_clock          :  STRING := "none";
1480
        port_b_data_width              :  INTEGER := 1;
1481
        port_b_address_width           :  INTEGER := 1;
1482
        port_b_byte_enable_mask_width  :  INTEGER := 1;
1483
        power_up_uninitialized         :  STRING := "false";
1484
        port_b_disable_ce_on_output_registers : STRING := "off";
1485
        port_b_disable_ce_on_input_registers : STRING := "off";
1486
        port_b_byte_size : INTEGER := 0;
1487
        port_a_disable_ce_on_output_registers : STRING := "off";
1488
        port_a_disable_ce_on_input_registers : STRING := "off";
1489
        port_a_byte_size : INTEGER := 0;
1490
        lpm_type                  : string := "stratixii_ram_block";
1491
        lpm_hint                  : string := "true";
1492
        connectivity_checking     : string := "off";
1493
        mem_init0 : BIT_VECTOR := X"0";
1494
        mem_init1 : BIT_VECTOR := X"0"
1495
        );
1496
    -- -------- PORT DECLARATIONS ---------
1497
    PORT (
1498
        portadatain             : IN STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0)    := (OTHERS => '0');
1499
        portaaddr               : IN STD_LOGIC_VECTOR(port_a_address_width - 1 DOWNTO 0) := (OTHERS => '0');
1500
        portawe                 : IN STD_LOGIC := '0';
1501
        portbdatain             : IN STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0)    := (OTHERS => '0');
1502
        portbaddr               : IN STD_LOGIC_VECTOR(port_b_address_width - 1 DOWNTO 0) := (OTHERS => '0');
1503
        portbrewe               : IN STD_LOGIC := '0';
1504
        clk0                    : IN STD_LOGIC := '0';
1505
        clk1                    : IN STD_LOGIC := '0';
1506
        ena0                    : IN STD_LOGIC := '1';
1507
        ena1                    : IN STD_LOGIC := '1';
1508
        clr0                    : IN STD_LOGIC := '0';
1509
        clr1                    : IN STD_LOGIC := '0';
1510
        portabyteenamasks       : IN STD_LOGIC_VECTOR(port_a_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '1');
1511
        portbbyteenamasks       : IN STD_LOGIC_VECTOR(port_b_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '1');
1512
        devclrn                 : IN STD_LOGIC := '1';
1513
        devpor                  : IN STD_LOGIC := '1';
1514
         portaaddrstall : IN STD_LOGIC := '0';
1515
         portbaddrstall : IN STD_LOGIC := '0';
1516
        portadataout            : OUT STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1517
        portbdataout            : OUT STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0)
1518
        );
1519
 
1520
END stratixii_ram_block;
1521
 
1522
ARCHITECTURE block_arch OF stratixii_ram_block IS
1523
 
1524
COMPONENT stratixii_ram_pulse_generator
1525
    PORT (
1526
          clk                     : IN  STD_LOGIC;
1527
          ena                     : IN  STD_LOGIC;
1528
          pulse                   : OUT STD_LOGIC;
1529
          cycle                   : OUT STD_LOGIC
1530
    );
1531
END COMPONENT;
1532
 
1533
COMPONENT stratixii_ram_register
1534
    GENERIC (
1535
        preset                    :  STD_LOGIC := '0';
1536
        width                     :  integer := 1
1537
    );
1538
    PORT    (
1539
        d                       : IN  STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1540
        clk                     : IN  STD_LOGIC;
1541
        aclr                    : IN  STD_LOGIC;
1542
        devclrn                 : IN  STD_LOGIC;
1543
        devpor                  : IN  STD_LOGIC;
1544
        ena                     : IN  STD_LOGIC;
1545
        stall                     : IN  STD_LOGIC;
1546
        q                       : OUT STD_LOGIC_VECTOR(width - 1 DOWNTO 0);
1547
        aclrout                 : OUT STD_LOGIC
1548
     );
1549
END COMPONENT;
1550
 
1551
FUNCTION cond (condition : BOOLEAN;CONSTANT a,b : INTEGER) RETURN INTEGER IS
1552
VARIABLE c: INTEGER;
1553
BEGIN
1554
    IF (condition) THEN c := a; ELSE c := b; END IF;
1555
    RETURN c;
1556
END;
1557
 
1558
SUBTYPE port_type IS BOOLEAN;
1559
 
1560
CONSTANT primary   : port_type := TRUE;
1561
CONSTANT secondary : port_type := FALSE;
1562
 
1563
CONSTANT primary_port_is_a : BOOLEAN := (port_b_data_width <= port_a_data_width);
1564
CONSTANT primary_port_is_b : BOOLEAN := NOT primary_port_is_a;
1565
 
1566
CONSTANT mode_is_rom : BOOLEAN := (operation_mode = "rom");
1567
CONSTANT mode_is_sp  : BOOLEAN := (operation_mode = "single_port");
1568
CONSTANT mode_is_dp  : BOOLEAN := (operation_mode = "dual_port");
1569
CONSTANT mode_is_bdp : BOOLEAN := (operation_mode = "bidir_dual_port");
1570
 
1571
CONSTANT wired_mode : BOOLEAN := (port_a_address_width = port_b_address_width) AND (port_a_address_width = 1)
1572
                                  AND (port_a_data_width /= port_b_data_width);
1573
CONSTANT num_cols : INTEGER := cond(mode_is_rom OR mode_is_sp,1,
1574
                                    cond(wired_mode,2,2 ** (ABS(port_b_address_width - port_a_address_width))));
1575
CONSTANT data_width      : INTEGER := cond(primary_port_is_a,port_a_data_width,port_b_data_width);
1576
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);
1577
 
1578
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);
1579
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);
1580
 
1581
CONSTANT byte_size_a : INTEGER := port_a_data_width / port_a_byte_enable_mask_width;
1582
CONSTANT byte_size_b : INTEGER := port_b_data_width / port_b_byte_enable_mask_width;
1583
 
1584
CONSTANT out_a_is_reg : BOOLEAN := (port_a_data_out_clock /= "none" AND port_a_data_out_clock /= "UNUSED");
1585
CONSTANT out_b_is_reg : BOOLEAN := (port_b_data_out_clock /= "none" AND port_b_data_out_clock /= "UNUSED");
1586
 
1587
CONSTANT bytes_a_disabled : STD_LOGIC_VECTOR(port_a_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '0');
1588
CONSTANT bytes_b_disabled : STD_LOGIC_VECTOR(port_b_byte_enable_mask_width - 1 DOWNTO 0) := (OTHERS => '0');
1589
 
1590
CONSTANT ram_type : BOOLEAN := (ram_block_type = "M-RAM" OR ram_block_type = "m-ram" OR ram_block_type = "MegaRAM" OR
1591
                               (ram_block_type = "auto"  AND mixed_port_feed_through_mode = "dont_care" AND port_b_read_enable_write_enable_clock = "clock0"));
1592
 
1593
TYPE bool_to_std_logic_map IS ARRAY(TRUE DOWNTO FALSE) OF STD_LOGIC;
1594
CONSTANT bool_to_std_logic : bool_to_std_logic_map := ('1','0');
1595
 
1596
-- -------- internal signals ---------
1597
-- clock / clock enable
1598
SIGNAL clk_a_in,clk_b_in : STD_LOGIC;
1599
SIGNAL clk_a_byteena,clk_b_byteena : STD_LOGIC;
1600
SIGNAL clk_a_out,clk_b_out : STD_LOGIC;
1601
SIGNAL clkena_a_out,clkena_b_out : STD_LOGIC;
1602
SIGNAL write_cycle_a,write_cycle_b : STD_LOGIC;
1603
 
1604
-- asynch clear
1605
TYPE   clear_mode_type IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF BOOLEAN;
1606
TYPE   clear_vec_type  IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF STD_LOGIC;
1607
SIGNAL datain_a_clr,datain_b_clr   :  STD_LOGIC;
1608
SIGNAL dataout_a_clr,dataout_b_clr :  STD_LOGIC;
1609
SIGNAL addr_a_clr,addr_b_clr       :  STD_LOGIC;
1610
SIGNAL byteena_a_clr,byteena_b_clr :  STD_LOGIC;
1611
SIGNAL we_a_clr,rewe_b_clr         :  STD_LOGIC;
1612
SIGNAL datain_a_clr_in,datain_b_clr_in :  STD_LOGIC;
1613
SIGNAL addr_a_clr_in,addr_b_clr_in     :  STD_LOGIC;
1614
SIGNAL byteena_a_clr_in,byteena_b_clr_in  :  STD_LOGIC;
1615
SIGNAL we_a_clr_in,rewe_b_clr_in          :  STD_LOGIC;
1616
SIGNAL mem_invalidate,mem_invalidate_loc,read_latch_invalidate : clear_mode_type;
1617
SIGNAL clear_asserted_during_write :  clear_vec_type;
1618
 
1619
SUBTYPE one_bit_bus_type IS STD_LOGIC_VECTOR(0 DOWNTO 0);
1620
-- port A registers
1621
SIGNAL we_a_reg                 :  STD_LOGIC;
1622
SIGNAL we_a_reg_in,we_a_reg_out :  one_bit_bus_type;
1623
SIGNAL addr_a_reg               :  STD_LOGIC_VECTOR(port_a_address_width - 1 DOWNTO 0);
1624
SIGNAL datain_a_reg             :  STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1625
SIGNAL dataout_a_reg            :  STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1626
SIGNAL dataout_a                :  STD_LOGIC_VECTOR(port_a_data_width - 1 DOWNTO 0);
1627
SIGNAL byteena_a_reg            :  STD_LOGIC_VECTOR(port_a_byte_enable_mask_width- 1 DOWNTO 0);
1628
-- port B registers
1629
SIGNAL rewe_b_reg               :  STD_LOGIC;
1630
SIGNAL rewe_b_reg_in,rewe_b_reg_out :  one_bit_bus_type;
1631
SIGNAL addr_b_reg               :  STD_LOGIC_VECTOR(port_b_address_width - 1 DOWNTO 0);
1632
SIGNAL datain_b_reg             :  STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0);
1633
SIGNAL dataout_b_reg            :  STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0);
1634
SIGNAL dataout_b                :  STD_LOGIC_VECTOR(port_b_data_width - 1 DOWNTO 0);
1635
SIGNAL byteena_b_reg            :  STD_LOGIC_VECTOR(port_b_byte_enable_mask_width- 1 DOWNTO 0);
1636
-- pulses
1637
TYPE   pulse_vec IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF STD_LOGIC;
1638
SIGNAL write_pulse,read_pulse,read_pulse_feedthru : pulse_vec;
1639
SIGNAL wpgen_a_clk,wpgen_a_clkena,wpgen_b_clk,wpgen_b_clkena : STD_LOGIC;
1640
SIGNAL rpgen_a_clkena,rpgen_b_clkena : STD_LOGIC;
1641
SIGNAL ftpgen_a_clkena,ftpgen_b_clkena : STD_LOGIC;
1642
 
1643
-- registered address
1644
SIGNAL addr_prime_reg,addr_sec_reg :  INTEGER;
1645
-- input/output
1646
SIGNAL datain_prime_reg,dataout_prime     :  STD_LOGIC_VECTOR(data_width - 1 DOWNTO 0);
1647
SIGNAL datain_sec_reg,dataout_sec         :  STD_LOGIC_VECTOR(data_unit_width - 1 DOWNTO 0);
1648
--  overlapping location write
1649
SIGNAL dual_write : BOOLEAN;
1650
 
1651
-- memory core
1652
SUBTYPE  mem_word_type IS STD_LOGIC_VECTOR (data_width - 1 DOWNTO 0);
1653
SUBTYPE  mem_col_type  IS STD_LOGIC_VECTOR (data_unit_width - 1 DOWNTO 0);
1654
TYPE     mem_row_type  IS ARRAY (num_cols - 1 DOWNTO 0) OF mem_col_type;
1655
TYPE     mem_type IS ARRAY ((2 ** address_unit_width) - 1 DOWNTO 0) OF mem_row_type;
1656
SIGNAL   mem : mem_type;
1657
SIGNAL   init_mem : BOOLEAN := FALSE;
1658
CONSTANT mem_x : mem_type     := (OTHERS => (OTHERS => (OTHERS => 'X')));
1659
CONSTANT row_x : mem_row_type := (OTHERS => (OTHERS => 'X'));
1660
CONSTANT col_x : mem_col_type := (OTHERS => 'X');
1661
SIGNAL   mem_data : mem_row_type;
1662
SIGNAL   mem_unit_data : mem_col_type;
1663
 
1664
-- latches
1665
TYPE   read_latch_rec IS RECORD
1666
       prime : mem_row_type;
1667
       sec   : mem_col_type;
1668
END RECORD;
1669
SIGNAL read_latch      :  read_latch_rec;
1670
-- (row,column) coordinates
1671
SIGNAL row_sec,col_sec  : INTEGER;
1672
-- byte enable
1673
TYPE   mask_type IS (normal,inverse);
1674
TYPE   mask_prime_type IS ARRAY(mask_type'HIGH DOWNTO mask_type'LOW) OF mem_word_type;
1675
TYPE   mask_sec_type   IS ARRAY(mask_type'HIGH DOWNTO mask_type'LOW) OF mem_col_type;
1676
TYPE   mask_rec IS RECORD
1677
       prime : mask_prime_type;
1678
       sec   : mask_sec_type;
1679
END RECORD;
1680
SIGNAL mask_vector : mask_rec;
1681
SIGNAL mask_vector_common : mem_col_type;
1682
 
1683
FUNCTION get_mask(
1684
    b_ena : IN STD_LOGIC_VECTOR;
1685
    mode  : port_type;
1686
    CONSTANT b_ena_width ,byte_size: INTEGER
1687
) RETURN mask_rec IS
1688
 
1689
VARIABLE l : INTEGER;
1690
VARIABLE mask : mask_rec := (
1691
                                (normal => (OTHERS => '0'),inverse => (OTHERS => 'X')),
1692
                                (normal => (OTHERS => '0'),inverse => (OTHERS => 'X'))
1693
                            );
1694
BEGIN
1695
    FOR l in 0 TO b_ena_width - 1  LOOP
1696
        IF (b_ena(l) = '0') THEN
1697
            IF (mode = primary) THEN
1698
                mask.prime(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
1699
                mask.prime(inverse)((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => '0');
1700
            ELSE
1701
                mask.sec(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
1702
                mask.sec(inverse)((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => '0');
1703
            END IF;
1704
        ELSIF (b_ena(l) = 'X' OR b_ena(l) = 'U') THEN
1705
            IF (mode = primary) THEN
1706
                mask.prime(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
1707
            ELSE
1708
                mask.sec(normal) ((l+1)*byte_size - 1 DOWNTO l*byte_size) := (OTHERS => 'X');
1709
            END IF;
1710
        END IF;
1711
    END LOOP;
1712
    RETURN mask;
1713
END get_mask;
1714
-- port active for read/write
1715
SIGNAL active_a_in_vec,active_b_in_vec,active_a_out,active_b_out : one_bit_bus_type;
1716
SIGNAL active_a_in,active_b_in   : STD_LOGIC;
1717
SIGNAL active_a,active_write_a :  BOOLEAN;
1718
SIGNAL active_b,active_write_b :  BOOLEAN;
1719
SIGNAL wire_vcc : STD_LOGIC := '1';
1720
SIGNAL wire_gnd : STD_LOGIC := '0';
1721
BEGIN
1722
    -- memory initialization
1723
    init_mem <= TRUE;
1724
 
1725
    -- -------- core logic ---------------
1726
    clk_a_in      <= clk0;
1727
    clk_a_byteena <= '0'   WHEN (port_a_byte_enable_clock = "none" OR port_a_byte_enable_clock = "UNUSED") ELSE clk_a_in;
1728
    clk_a_out     <= '0'   WHEN (port_a_data_out_clock = "none" OR port_a_data_out_clock = "UNUSED")    ELSE
1729
                      clk0 WHEN (port_a_data_out_clock = "clock0")  ELSE clk1;
1730
 
1731
    clk_b_in      <=  clk0 WHEN (port_b_read_enable_write_enable_clock = "clock0") ELSE clk1;
1732
    clk_b_byteena <=  '0'  WHEN (port_b_byte_enable_clock = "none" OR port_b_byte_enable_clock = "UNUSED") ELSE
1733
                      clk0 WHEN (port_b_byte_enable_clock = "clock0") ELSE clk1;
1734
    clk_b_out     <=  '0'  WHEN (port_b_data_out_clock = "none" OR port_b_data_out_clock = "UNUSED")    ELSE
1735
                      clk0 WHEN (port_b_data_out_clock = "clock0")  ELSE clk1;
1736
 
1737
    addr_a_clr_in <=  '0'  WHEN (port_a_address_clear = "none" OR port_a_address_clear = "UNUSED") ELSE clr0;
1738
    addr_b_clr_in <=  '0'  WHEN (port_b_address_clear = "none" OR port_b_address_clear = "UNUSED") ELSE
1739
                      clr0 WHEN (port_b_address_clear = "clear0") ELSE clr1;
1740
 
1741
    datain_a_clr_in <= '0' WHEN (port_a_data_in_clear = "none" OR port_a_data_in_clear = "UNUSED") ELSE clr0;
1742
    datain_b_clr_in <= '0' WHEN (port_b_data_in_clear = "none" OR port_b_data_in_clear = "UNUSED") ELSE
1743
                      clr0 WHEN (port_b_data_in_clear = "clear0") ELSE clr1;
1744
 
1745
    dataout_a_clr   <= '0' WHEN (port_a_data_out_clear = "none" OR port_a_data_out_clear = "UNUSED")   ELSE
1746
                      clr0 WHEN (port_a_data_out_clear = "clear0") ELSE clr1;
1747
    dataout_b_clr   <= '0' WHEN (port_b_data_out_clear = "none" OR port_b_data_out_clear = "UNUSED")   ELSE
1748
                      clr0 WHEN (port_b_data_out_clear = "clear0") ELSE clr1;
1749
 
1750
    byteena_a_clr_in <= '0' WHEN (port_a_byte_enable_clear = "none" OR port_a_byte_enable_clear = "UNUSED") ELSE clr0;
1751
    byteena_b_clr_in <= '0' WHEN (port_b_byte_enable_clear = "none" OR port_b_byte_enable_clear = "UNUSED") ELSE
1752
                       clr0 WHEN (port_b_byte_enable_clear = "clear0") ELSE clr1;
1753
 
1754
    we_a_clr_in      <= '0' WHEN (port_a_write_enable_clear = "none" OR port_a_write_enable_clear = "UNUSED") ELSE clr0;
1755
    rewe_b_clr_in    <= '0' WHEN (port_b_read_enable_write_enable_clear = "none" OR port_b_read_enable_write_enable_clear = "UNUSED")   ELSE
1756
                       clr0 WHEN (port_b_read_enable_write_enable_clear = "clear0") ELSE clr1;
1757
 
1758
        active_a_in <= '1'  WHEN (port_a_disable_ce_on_input_registers = "on") ELSE ena0;
1759
        active_b_in <= '1'  WHEN (port_b_disable_ce_on_input_registers = "on") ELSE
1760
                       ena0 WHEN (port_b_read_enable_write_enable_clock = "clock0") ELSE ena1;
1761
 
1762
    -- A port active
1763
    active_a_in_vec(0) <= active_a_in;
1764
    active_port_a : stratixii_ram_register
1765
        GENERIC MAP ( width => 1 )
1766
        PORT MAP (
1767
            d => active_a_in_vec,
1768
            clk => clk_a_in,
1769
            aclr => wire_gnd,
1770
            devclrn => wire_vcc,devpor => wire_vcc,
1771
            ena => wire_vcc,
1772
            stall => wire_gnd,
1773
            q => active_a_out
1774
        );
1775
    active_a <= (active_a_out(0) = '1');
1776
    active_write_a <= active_a AND (byteena_a_reg /= bytes_a_disabled);
1777
 
1778
    -- B port active
1779
    active_b_in_vec(0) <= active_b_in;
1780
    active_port_b : stratixii_ram_register
1781
        GENERIC MAP ( width => 1 )
1782
        PORT MAP (
1783
            d => active_b_in_vec,
1784
            clk => clk_b_in,
1785
            aclr => wire_gnd,
1786
            devclrn => wire_vcc,devpor => wire_vcc,
1787
            stall => wire_gnd,
1788
            ena => wire_vcc,
1789
            q => active_b_out
1790
        );
1791
    active_b <= (active_b_out(0) = '1');
1792
    active_write_b <= active_b AND (byteena_b_reg /= bytes_b_disabled);
1793
 
1794
    -- ------ A input registers
1795
    -- write enable
1796
    we_a_reg_in(0) <= '0' WHEN mode_is_rom ELSE portawe;
1797
    we_a_register : stratixii_ram_register
1798
        GENERIC MAP ( width => 1 )
1799
        PORT MAP (
1800
            d => we_a_reg_in,
1801
            clk => clk_a_in,
1802
            aclr => we_a_clr_in,
1803
            devclrn => devclrn,
1804
            devpor => devpor,
1805
            stall => wire_gnd,
1806
            ena => active_a_in,
1807
            q   => we_a_reg_out,
1808
            aclrout => we_a_clr
1809
        );
1810
    we_a_reg <= we_a_reg_out(0);
1811
    -- address
1812
    addr_a_register : stratixii_ram_register
1813
        GENERIC MAP ( width => port_a_address_width )
1814
        PORT MAP (
1815
            d => portaaddr,
1816
            clk => clk_a_in,
1817
            aclr => addr_a_clr_in,
1818
            devclrn => devclrn,
1819
            devpor => devpor,
1820
            stall => portaaddrstall,
1821
            ena => active_a_in,
1822
            q   => addr_a_reg,
1823
            aclrout => addr_a_clr
1824
        );
1825
    -- data
1826
    datain_a_register : stratixii_ram_register
1827
        GENERIC MAP ( width => port_a_data_width )
1828
        PORT MAP (
1829
            d => portadatain,
1830
            clk => clk_a_in,
1831
            aclr => datain_a_clr_in,
1832
            devclrn => devclrn,
1833
            devpor => devpor,
1834
            stall => wire_gnd,
1835
            ena => active_a_in,
1836
            q   => datain_a_reg,
1837
            aclrout => datain_a_clr
1838
        );
1839
    -- byte enable
1840
    byteena_a_register : stratixii_ram_register
1841
        GENERIC MAP (
1842
            width  => port_a_byte_enable_mask_width,
1843
            preset => '1'
1844
        )
1845
        PORT MAP (
1846
            d => portabyteenamasks,
1847
            clk => clk_a_byteena,
1848
            aclr => byteena_a_clr_in,
1849
            devclrn => devclrn,
1850
            devpor => devpor,
1851
            stall => wire_gnd,
1852
            ena => active_a_in,
1853
            q   => byteena_a_reg,
1854
            aclrout => byteena_a_clr
1855
        );
1856
    -- ------ B input registers
1857
    -- read/write enable
1858
    rewe_b_reg_in(0) <= portbrewe;
1859
    rewe_b_register : stratixii_ram_register
1860
        GENERIC MAP (
1861
            width  => 1,
1862
            preset => bool_to_std_logic(mode_is_dp)
1863
        )
1864
        PORT MAP (
1865
            d => rewe_b_reg_in,
1866
            clk => clk_b_in,
1867
            aclr => rewe_b_clr_in,
1868
            devclrn => devclrn,
1869
            devpor => devpor,
1870
            stall => wire_gnd,
1871
            ena => active_b_in,
1872
            q   => rewe_b_reg_out,
1873
            aclrout => rewe_b_clr
1874
        );
1875
    rewe_b_reg <= rewe_b_reg_out(0);
1876
    -- address
1877
    addr_b_register : stratixii_ram_register
1878
        GENERIC MAP ( width  => port_b_address_width )
1879
        PORT MAP (
1880
            d => portbaddr,
1881
            clk => clk_b_in,
1882
            aclr => addr_b_clr_in,
1883
            devclrn => devclrn,
1884
            devpor => devpor,
1885
            stall => portbaddrstall,
1886
            ena => active_b_in,
1887
            q   => addr_b_reg,
1888
            aclrout => addr_b_clr
1889
        );
1890
    -- data
1891
    datain_b_register : stratixii_ram_register
1892
        GENERIC MAP ( width  => port_b_data_width )
1893
        PORT MAP (
1894
            d => portbdatain,
1895
            clk => clk_b_in,
1896
            aclr => datain_b_clr_in,
1897
            devclrn => devclrn,
1898
            devpor => devpor,
1899
            stall => wire_gnd,
1900
            ena => active_b_in,
1901
            q   => datain_b_reg,
1902
            aclrout => datain_b_clr
1903
        );
1904
    -- byte enable
1905
    byteena_b_register : stratixii_ram_register
1906
        GENERIC MAP (
1907
            width  => port_b_byte_enable_mask_width,
1908
            preset => '1'
1909
        )
1910
        PORT MAP (
1911
            d => portbbyteenamasks,
1912
            clk => clk_b_byteena,
1913
            aclr => byteena_b_clr_in,
1914
            devclrn => devclrn,
1915
            devpor => devpor,
1916
            stall => wire_gnd,
1917
            ena => active_b_in,
1918
            q   => byteena_b_reg,
1919
            aclrout => byteena_b_clr
1920
        );
1921
 
1922
    datain_prime_reg <= datain_a_reg WHEN primary_port_is_a ELSE datain_b_reg;
1923
    addr_prime_reg   <= alt_conv_integer(addr_a_reg)   WHEN primary_port_is_a ELSE alt_conv_integer(addr_b_reg);
1924
 
1925
    datain_sec_reg   <= (OTHERS => 'U') WHEN (mode_is_rom OR mode_is_sp) ELSE
1926
                        datain_b_reg    WHEN primary_port_is_a           ELSE datain_a_reg;
1927
    addr_sec_reg     <= alt_conv_integer(addr_b_reg)   WHEN primary_port_is_a ELSE alt_conv_integer(addr_a_reg);
1928
 
1929
    -- Write pulse generation
1930
    wpgen_a_clk <= clk_a_in WHEN ram_type ELSE (NOT clk_a_in);
1931
    wpgen_a_clkena <= '1' WHEN (active_write_a AND (we_a_reg = '1')) ELSE '0';
1932
    wpgen_a : stratixii_ram_pulse_generator
1933
        PORT MAP (
1934
            clk => wpgen_a_clk,
1935
            ena => wpgen_a_clkena,
1936
            pulse => write_pulse(primary_port_is_a),
1937
            cycle => write_cycle_a
1938
        );
1939
    wpgen_b_clk <= clk_b_in WHEN ram_type ELSE (NOT clk_b_in);
1940
    wpgen_b_clkena <= '1' WHEN (active_write_b AND mode_is_bdp AND (rewe_b_reg = '1')) ELSE '0';
1941
    wpgen_b : stratixii_ram_pulse_generator
1942
        PORT MAP (
1943
            clk => wpgen_b_clk,
1944
            ena => wpgen_b_clkena,
1945
            pulse => write_pulse(primary_port_is_b),
1946
            cycle => write_cycle_b
1947
            );
1948
 
1949
    -- Read  pulse generation
1950
    rpgen_a_clkena <= '1' WHEN (active_a AND (we_a_reg = '0')) ELSE '0';
1951
    rpgen_a : stratixii_ram_pulse_generator
1952
        PORT MAP (
1953
            clk => clk_a_in,
1954
            ena => rpgen_a_clkena,
1955
            pulse => read_pulse(primary_port_is_a)
1956
        );
1957
    rpgen_b_clkena <= '1' WHEN (active_b AND mode_is_dp  AND (rewe_b_reg = '1')) OR
1958
                               (active_b AND mode_is_bdp AND (rewe_b_reg = '0'))
1959
                          ELSE '0';
1960
    rpgen_b : stratixii_ram_pulse_generator
1961
        PORT MAP (
1962
            clk => clk_b_in,
1963
            ena => rpgen_b_clkena,
1964
            pulse => read_pulse(primary_port_is_b)
1965
        );
1966
 
1967
    -- Create internal masks for byte enable processing
1968
    mask_create : PROCESS (byteena_a_reg,byteena_b_reg)
1969
    VARIABLE mask : mask_rec;
1970
    BEGIN
1971
        IF (byteena_a_reg'EVENT) THEN
1972
            mask := get_mask(byteena_a_reg,primary_port_is_a,port_a_byte_enable_mask_width,byte_size_a);
1973
            IF (primary_port_is_a) THEN
1974
                mask_vector.prime <= mask.prime;
1975
            ELSE
1976
                mask_vector.sec   <= mask.sec;
1977
            END IF;
1978
        END IF;
1979
        IF (byteena_b_reg'EVENT) THEN
1980
            mask := get_mask(byteena_b_reg,primary_port_is_b,port_b_byte_enable_mask_width,byte_size_b);
1981
            IF (primary_port_is_b) THEN
1982
                mask_vector.prime <= mask.prime;
1983
            ELSE
1984
                mask_vector.sec   <= mask.sec;
1985
            END IF;
1986
        END IF;
1987
    END PROCESS mask_create;
1988
 
1989
    -- (row,col) coordinates
1990
    row_sec <= addr_sec_reg / num_cols;
1991
    col_sec <= addr_sec_reg mod num_cols;
1992
 
1993
    mem_rw : PROCESS (init_mem,
1994
                      write_pulse,read_pulse,read_pulse_feedthru,
1995
                      mem_invalidate,mem_invalidate_loc,read_latch_invalidate)
1996
    -- mem init
1997
    TYPE rw_type IS ARRAY (port_type'HIGH DOWNTO port_type'LOW) OF BOOLEAN;
1998
    VARIABLE addr_range_init,row,col,index :  INTEGER;
1999
    VARIABLE mem_init_std :  STD_LOGIC_VECTOR((port_a_last_address - port_a_first_address + 1)*port_a_data_width - 1 DOWNTO 0);
2000
    VARIABLE mem_val : mem_type;
2001
    -- read/write
2002
    VARIABLE mem_data_p : mem_row_type;
2003
    VARIABLE row_prime,col_prime  : INTEGER;
2004
    VARIABLE access_same_location : BOOLEAN;
2005
    VARIABLE read_during_write    : rw_type;
2006
    BEGIN
2007
        read_during_write := (FALSE,FALSE);
2008
        -- Memory initialization
2009
        IF (init_mem'EVENT) THEN
2010
            -- Initialize output latches to 0
2011
            IF (primary_port_is_a) THEN
2012
                dataout_prime <= (OTHERS => '0');
2013
                IF (mode_is_dp OR mode_is_bdp) THEN dataout_sec <= (OTHERS => '0'); END IF;
2014
            ELSE
2015
                dataout_sec   <= (OTHERS => '0');
2016
                IF (mode_is_dp OR mode_is_bdp) THEN dataout_prime <= (OTHERS => '0'); END IF;
2017
            END IF;
2018
             IF (power_up_uninitialized = "false" AND (NOT ram_type)) THEN
2019
                 mem_val := (OTHERS => (OTHERS => (OTHERS => '0')));
2020
             END IF;
2021
            IF (primary_port_is_a) THEN
2022
                addr_range_init := port_a_last_address - port_a_first_address + 1;
2023
            ELSE
2024
                addr_range_init := port_b_last_address - port_b_first_address + 1;
2025
            END IF;
2026
            IF (init_file_layout = "port_a" OR init_file_layout = "port_b") THEN
2027
                mem_init_std := to_stdlogicvector(mem_init1 & mem_init0)((port_a_last_address - port_a_first_address + 1)*port_a_data_width - 1 DOWNTO 0);
2028
                FOR row IN 0 TO addr_range_init - 1 LOOP
2029
                    FOR col IN 0 to num_cols - 1 LOOP
2030
                        index := row * data_width;
2031
                        mem_val(row)(col) := mem_init_std(index + (col+1)*data_unit_width -1 DOWNTO
2032
                                                          index +  col*data_unit_width);
2033
                    END LOOP;
2034
                END LOOP;
2035
            END IF;
2036
            mem <= mem_val;
2037
        END IF;
2038
        access_same_location := (mode_is_dp OR mode_is_bdp) AND (addr_prime_reg = row_sec);
2039
        -- Write stage 1 : X to buffer
2040
        -- Write stage 2 : actual data to memory
2041
        IF (write_pulse(primary)'EVENT) THEN
2042
            IF (write_pulse(primary) = '1') THEN
2043
                mem_data_p := mem(addr_prime_reg);
2044
                FOR i IN 0 TO num_cols - 1 LOOP
2045
                    mem_data_p(i) := mem_data_p(i) XOR
2046
                                     mask_vector.prime(inverse)((i + 1)*data_unit_width - 1 DOWNTO i*data_unit_width);
2047
                END LOOP;
2048
                read_during_write(secondary) := (access_same_location AND read_pulse(secondary)'EVENT AND read_pulse(secondary) = '1');
2049
                IF (read_during_write(secondary)) THEN
2050
                    read_latch.sec <= mem_data_p(col_sec);
2051
                ELSE
2052
                    mem_data <= mem_data_p;
2053
                END IF;
2054
            ELSIF (clear_asserted_during_write(primary) /= '1') THEN
2055
                FOR i IN 0 TO data_width - 1 LOOP
2056
                    IF (mask_vector.prime(normal)(i) = '0') THEN
2057
                        mem(addr_prime_reg)(i / data_unit_width)(i mod data_unit_width) <= datain_prime_reg(i);
2058
                    ELSIF (mask_vector.prime(inverse)(i) = 'X') THEN
2059
                        mem(addr_prime_reg)(i / data_unit_width)(i mod data_unit_width) <= 'X';
2060
                    END IF;
2061
                END LOOP;
2062
            END IF;
2063
        END IF;
2064
 
2065
        IF (write_pulse(secondary)'EVENT) THEN
2066
            IF (write_pulse(secondary) = '1') THEN
2067
                read_during_write(primary) := (access_same_location AND read_pulse(primary)'EVENT AND read_pulse(primary) = '1');
2068
                IF (read_during_write(primary)) THEN
2069
                    read_latch.prime <= mem(addr_prime_reg);
2070
                    read_latch.prime(col_sec) <= mem(row_sec)(col_sec) XOR mask_vector.sec(inverse);
2071
                ELSE
2072
                    mem_unit_data <= mem(row_sec)(col_sec) XOR mask_vector.sec(inverse);
2073
                END IF;
2074
 
2075
                IF (access_same_location AND write_pulse(primary)'EVENT AND write_pulse(primary) = '1') THEN
2076
                    mask_vector_common <=
2077
                       mask_vector.prime(inverse)(((col_sec + 1)* data_unit_width - 1) DOWNTO col_sec*data_unit_width) AND
2078
                       mask_vector.sec(inverse);
2079
                    dual_write <= TRUE;
2080
                END IF;
2081
            ELSIF (clear_asserted_during_write(secondary) /= '1') THEN
2082
                FOR i IN 0 TO data_unit_width - 1 LOOP
2083
                    IF (mask_vector.sec(normal)(i) = '0') THEN
2084
                        mem(row_sec)(col_sec)(i) <= datain_sec_reg(i);
2085
                    ELSIF (mask_vector.sec(inverse)(i) = 'X') THEN
2086
                        mem(row_sec)(col_sec)(i) <= 'X';
2087
                    END IF;
2088
                END LOOP;
2089
            END IF;
2090
        END IF;
2091
        -- Simultaneous write
2092
        IF (dual_write AND write_pulse = "00") THEN
2093
           mem(row_sec)(col_sec) <= mem(row_sec)(col_sec) XOR mask_vector_common;
2094
           dual_write <= FALSE;
2095
        END IF;
2096
        -- Read stage 1 : read data
2097
        -- Read stage 2 : send data to output
2098
        IF ((NOT read_during_write(primary)) AND read_pulse(primary)'EVENT) THEN
2099
            IF (read_pulse(primary) = '1') THEN
2100
                read_latch.prime <= mem(addr_prime_reg);
2101
                IF (access_same_location AND write_pulse(secondary) = '1') THEN
2102
                    read_latch.prime(col_sec) <= mem_unit_data;
2103
                END IF;
2104
            ELSE
2105
                FOR i IN 0 TO data_width - 1 LOOP
2106
                    row_prime := i / data_unit_width; col_prime := i mod data_unit_width;
2107
                    dataout_prime(i) <= read_latch.prime(row_prime)(col_prime);
2108
                END LOOP;
2109
            END IF;
2110
        END IF;
2111
 
2112
        IF ((NOT read_during_write(secondary)) AND read_pulse(secondary)'EVENT) THEN
2113
            IF (read_pulse(secondary) = '1') THEN
2114
                IF (access_same_location AND write_pulse(primary) = '1') THEN
2115
                    read_latch.sec <= mem_data(col_sec);
2116
                ELSE
2117
                    read_latch.sec <= mem(row_sec)(col_sec);
2118
                END IF;
2119
            ELSE
2120
                dataout_sec <= read_latch.sec;
2121
            END IF;
2122
        END IF;
2123
        -- Same port feed thru
2124
        IF (read_pulse_feedthru(primary)'EVENT AND read_pulse_feedthru(primary) = '0') THEN
2125
            dataout_prime <= datain_prime_reg XOR mask_vector.prime(normal);
2126
        END IF;
2127
 
2128
        IF (read_pulse_feedthru(secondary)'EVENT AND read_pulse_feedthru(secondary) = '0') THEN
2129
            dataout_sec <= datain_sec_reg XOR mask_vector.sec(normal);
2130
        END IF;
2131
        -- Async clear
2132
        IF (mem_invalidate'EVENT) THEN
2133
            IF (mem_invalidate(primary) = TRUE OR mem_invalidate(secondary) = TRUE) THEN
2134
                mem <= mem_x;
2135
            END IF;
2136
        END IF;
2137
        IF (mem_invalidate_loc'EVENT) THEN
2138
            IF (mem_invalidate_loc(primary))   THEN mem(addr_prime_reg)   <= row_x;  END IF;
2139
            IF (mem_invalidate_loc(secondary)) THEN mem(row_sec)(col_sec) <= col_x;  END IF;
2140
        END IF;
2141
        IF (read_latch_invalidate'EVENT) THEN
2142
            IF (read_latch_invalidate(primary))   THEN read_latch.prime <= row_x; END IF;
2143
            IF (read_latch_invalidate(secondary)) THEN read_latch.sec   <= col_x; END IF;
2144
        END IF;
2145
    END PROCESS mem_rw;
2146
 
2147
    -- Same port feed through
2148
    ftpgen_a_clkena <= '1' WHEN (active_a AND (NOT mode_is_dp) AND (we_a_reg = '1')) ELSE '0';
2149
    ftpgen_a : stratixii_ram_pulse_generator
2150
        PORT MAP (
2151
            clk => clk_a_in,
2152
            ena => ftpgen_a_clkena,
2153
            pulse => read_pulse_feedthru(primary_port_is_a)
2154
        );
2155
    ftpgen_b_clkena <= '1' WHEN (active_b AND mode_is_bdp AND (rewe_b_reg = '1')) ELSE '0';
2156
    ftpgen_b : stratixii_ram_pulse_generator
2157
        PORT MAP (
2158
            clk => clk_b_in,
2159
            ena => ftpgen_b_clkena,
2160
            pulse => read_pulse_feedthru(primary_port_is_b)
2161
        );
2162
 
2163
    -- Asynch clear events
2164
    clear_a : PROCESS(addr_a_clr,we_a_clr,datain_a_clr)
2165
    BEGIN
2166
        IF (addr_a_clr'EVENT AND addr_a_clr = '1') THEN
2167
            clear_asserted_during_write(primary_port_is_a) <= write_pulse(primary_port_is_a);
2168
            IF (active_write_a AND (write_cycle_a = '1') AND (we_a_reg = '1')) THEN
2169
                mem_invalidate(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2170
            ELSIF (active_a AND we_a_reg = '1') THEN
2171
                read_latch_invalidate(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2172
            END IF;
2173
        END IF;
2174
        IF ((we_a_clr'EVENT AND we_a_clr = '1') OR (datain_a_clr'EVENT AND datain_a_clr = '1')) THEN
2175
            clear_asserted_during_write(primary_port_is_a) <= write_pulse(primary_port_is_a);
2176
            IF (active_write_a AND (write_cycle_a = '1') AND (we_a_reg = '1')) THEN
2177
                mem_invalidate_loc(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2178
                read_latch_invalidate(primary_port_is_a) <= TRUE,FALSE AFTER 0.5 ns;
2179
            END IF;
2180
        END IF;
2181
    END PROCESS clear_a;
2182
 
2183
    clear_b : PROCESS(addr_b_clr,rewe_b_clr,datain_b_clr)
2184
    BEGIN
2185
        IF (addr_b_clr'EVENT AND addr_b_clr = '1') THEN
2186
            clear_asserted_during_write(primary_port_is_b) <= write_pulse(primary_port_is_b);
2187
            IF (mode_is_bdp AND active_write_b AND (write_cycle_b = '1') AND (rewe_b_reg = '1')) THEN
2188
                mem_invalidate(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2189
            ELSIF (active_b AND ((mode_is_dp AND rewe_b_reg = '1') OR (mode_is_bdp AND rewe_b_reg = '0'))) THEN
2190
                read_latch_invalidate(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2191
            END IF;
2192
        END IF;
2193
        IF ((rewe_b_clr'EVENT AND rewe_b_clr = '1') OR (datain_b_clr'EVENT AND datain_b_clr = '1')) THEN
2194
            clear_asserted_during_write(primary_port_is_b) <= write_pulse(primary_port_is_b);
2195
            IF (mode_is_bdp AND active_write_b AND (write_cycle_b = '1') AND (rewe_b_reg = '1')) THEN
2196
                mem_invalidate_loc(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2197
                read_latch_invalidate(primary_port_is_b) <= TRUE,FALSE AFTER 0.5 ns;
2198
            END IF;
2199
        END IF;
2200
    END PROCESS clear_b;
2201
 
2202
    -- ------ Output registers
2203
       clkena_a_out <= '1'  WHEN (port_a_disable_ce_on_output_registers = "on") ELSE
2204
                       ena0 WHEN (port_a_data_out_clock = "clock0") ELSE ena1;
2205
       clkena_b_out <= '1'  WHEN (port_b_disable_ce_on_output_registers = "on") ELSE
2206
                       ena0 WHEN (port_b_data_out_clock = "clock0") ELSE ena1;
2207
 
2208
    dataout_a <= dataout_prime WHEN primary_port_is_a ELSE dataout_sec;
2209
    dataout_b <= (OTHERS => 'U') WHEN (mode_is_rom OR mode_is_sp) ELSE
2210
                 dataout_prime   WHEN primary_port_is_b ELSE dataout_sec;
2211
 
2212
    dataout_a_register : stratixii_ram_register
2213
        GENERIC MAP ( width => port_a_data_width )
2214
        PORT MAP (
2215
            d => dataout_a,
2216
            clk => clk_a_out,
2217
            aclr => dataout_a_clr,
2218
            devclrn => devclrn,
2219
            devpor => devpor,
2220
            stall => wire_gnd,
2221
            ena => clkena_a_out,
2222
            q => dataout_a_reg
2223
        );
2224
 
2225
    dataout_b_register : stratixii_ram_register
2226
        GENERIC MAP ( width => port_b_data_width )
2227
        PORT MAP (
2228
            d => dataout_b,
2229
            clk => clk_b_out,
2230
            aclr => dataout_b_clr,
2231
            devclrn => devclrn,
2232
            devpor => devpor,
2233
            stall => wire_gnd,
2234
            ena => clkena_b_out,
2235
            q => dataout_b_reg
2236
        );
2237
 
2238
    portadataout <= dataout_a_reg WHEN out_a_is_reg ELSE dataout_a;
2239
    portbdataout <= dataout_b_reg WHEN out_b_is_reg ELSE dataout_b;
2240
 
2241
END block_arch;
2242
 
2243
 
2244
-------------------------------------------------------------------
2245
--
2246
-- Entity Name : stratixii_jtag
2247
--
2248
-- Description : StratixII JTAG VHDL Simulation model
2249
--
2250
-------------------------------------------------------------------
2251
LIBRARY IEEE;
2252
use IEEE.std_logic_1164.all;
2253
use work.stratixii_atom_pack.all;
2254
 
2255
entity  stratixii_jtag is
2256
         generic (
2257
                                        lpm_type        : string := "stratixii_jtag"
2258
                                );
2259
    port (tms : in std_logic;
2260
                 tck : in std_logic;
2261
                 tdi : in std_logic;
2262
                 ntrst : in std_logic;
2263
                 tdoutap : in std_logic;
2264
                 tdouser : in std_logic;
2265
          tdo: out std_logic;
2266
          tmsutap: out std_logic;
2267
          tckutap: out std_logic;
2268
          tdiutap: out std_logic;
2269
          shiftuser: out std_logic;
2270
          clkdruser: out std_logic;
2271
          updateuser: out std_logic;
2272
          runidleuser: out std_logic;
2273
          usr1user: out std_logic);
2274
end stratixii_jtag;
2275
 
2276
architecture architecture_jtag of stratixii_jtag is
2277
begin
2278
 
2279
--process(tms, tck, tdi, ntrst, tdoutap, tdouser)
2280
--begin
2281
--
2282
--end process;
2283
 
2284
end architecture_jtag;
2285
 
2286
-------------------------------------------------------------------
2287
--
2288
-- Entity Name : stratixii_crcblock
2289
--
2290
-- Description : StratixII CRCBLOCK VHDL Simulation model
2291
--
2292
-------------------------------------------------------------------
2293
LIBRARY IEEE;
2294
use IEEE.std_logic_1164.all;
2295
use work.stratixii_atom_pack.all;
2296
 
2297
entity  stratixii_crcblock is
2298
        generic         (
2299
                                        oscillator_divider      : integer := 1;
2300
                                        lpm_type        : string := "stratixii_crcblock"
2301
                                );
2302
        port (clk                       : in std_logic;
2303
                shiftnld                : in std_logic;
2304
                ldsrc                   : in std_logic;
2305
         crcerror               : out std_logic;
2306
         regout         : out std_logic);
2307
end stratixii_crcblock;
2308
 
2309
architecture architecture_crcblock of stratixii_crcblock is
2310
begin
2311
 
2312
end architecture_crcblock;
2313
-------------------------------------------------------------------
2314
--
2315
-- Entity Name : stratixii_asmiblock
2316
--
2317
-- Description : StratixIIII ASMIBLOCK VHDL Simulation model
2318
--
2319
-------------------------------------------------------------------
2320
LIBRARY IEEE;
2321
use IEEE.std_logic_1164.all;
2322
use work.stratixii_atom_pack.all;
2323
 
2324
entity  stratixii_asmiblock is
2325
         generic (
2326
                                        lpm_type        : string := "stratixii_asmiblock"
2327
                                );
2328
    port (dclkin : in std_logic;
2329
                 scein : in std_logic;
2330
                 sdoin : in std_logic;
2331
                 oe : in std_logic;
2332
          data0out: out std_logic);
2333
end stratixii_asmiblock;
2334
 
2335
architecture architecture_asmiblock of stratixii_asmiblock is
2336
begin
2337
 
2338
--process(dclkin, scein, sdoin, oe)
2339
--begin
2340
--
2341
--end process;
2342
 
2343
end architecture_asmiblock;  -- end of stratixii_asmiblock
2344
---------------------------------------------------------------------
2345
--
2346
-- Entity Name :  stratixii_lcell_ff
2347
--
2348
-- Description :  StratixII LCELL_FF VHDL simulation model
2349
--
2350
--
2351
---------------------------------------------------------------------
2352
LIBRARY IEEE;
2353
use IEEE.std_logic_1164.all;
2354
use IEEE.VITAL_Timing.all;
2355
use IEEE.VITAL_Primitives.all;
2356
use work.stratixii_atom_pack.all;
2357
use work.stratixii_and1;
2358
 
2359
entity stratixii_lcell_ff is
2360
    generic (
2361
             x_on_violation : string := "on";
2362
             lpm_type : string := "stratixii_lcell_ff";
2363
             tsetup_datain_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2364
             tsetup_adatasdata_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2365
             tsetup_sclr_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2366
             tsetup_sload_clk_noedge_posedge    : VitalDelayType := DefSetupHoldCnst;
2367
             tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2368
             thold_datain_clk_noedge_posedge    : VitalDelayType := DefSetupHoldCnst;
2369
             thold_adatasdata_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2370
             thold_sclr_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2371
             thold_sload_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2372
             thold_ena_clk_noedge_posedge       : VitalDelayType := DefSetupHoldCnst;
2373
             tpd_clk_regout_posedge : VitalDelayType01 := DefPropDelay01;
2374
             tpd_aclr_regout_posedge : VitalDelayType01 := DefPropDelay01;
2375
             tpd_aload_regout_posedge : VitalDelayType01 := DefPropDelay01;
2376
             tpd_adatasdata_regout: VitalDelayType01 := DefPropDelay01;
2377
             tipd_clk : VitalDelayType01 := DefPropDelay01;
2378
             tipd_datain : VitalDelayType01 := DefPropDelay01;
2379
             tipd_adatasdata : VitalDelayType01 := DefPropDelay01;
2380
             tipd_sclr : VitalDelayType01 := DefPropDelay01;
2381
             tipd_sload : VitalDelayType01 := DefPropDelay01;
2382
             tipd_aclr : VitalDelayType01 := DefPropDelay01;
2383
             tipd_aload : VitalDelayType01 := DefPropDelay01;
2384
             tipd_ena : VitalDelayType01 := DefPropDelay01;
2385
             TimingChecksOn: Boolean := True;
2386
             MsgOn: Boolean := DefGlitchMsgOn;
2387
             XOn: Boolean := DefGlitchXOn;
2388
             MsgOnChecks: Boolean := DefMsgOnChecks;
2389
             XOnChecks: Boolean := DefXOnChecks;
2390
             InstancePath: STRING := "*"
2391
            );
2392
 
2393
    port (
2394
          datain : in std_logic := '0';
2395
          clk : in std_logic := '0';
2396
          aclr : in std_logic := '0';
2397
          aload : in std_logic := '0';
2398
          sclr : in std_logic := '0';
2399
          sload : in std_logic := '0';
2400
          ena : in std_logic := '1';
2401
          adatasdata : in std_logic := '0';
2402
          devclrn : in std_logic := '1';
2403
          devpor : in std_logic := '1';
2404
          regout : out std_logic
2405
         );
2406
   attribute VITAL_LEVEL0 of stratixii_lcell_ff : entity is TRUE;
2407
end stratixii_lcell_ff;
2408
 
2409
architecture vital_lcell_ff of stratixii_lcell_ff is
2410
   attribute VITAL_LEVEL0 of vital_lcell_ff : architecture is TRUE;
2411
   signal clk_ipd : std_logic;
2412
   signal datain_ipd : std_logic;
2413
   signal datain_dly : std_logic;
2414
   signal adatasdata_ipd : std_logic;
2415
   signal adatasdata_dly : std_logic;
2416
   signal adatasdata_dly1 : std_logic;
2417
   signal sclr_ipd : std_logic;
2418
   signal sload_ipd : std_logic;
2419
   signal aclr_ipd : std_logic;
2420
   signal aload_ipd : std_logic;
2421
   signal ena_ipd : std_logic;
2422
 
2423
component stratixii_and1
2424
    generic (XOn                  : Boolean := DefGlitchXOn;
2425
             MsgOn                : Boolean := DefGlitchMsgOn;
2426
             tpd_IN1_Y            : VitalDelayType01 := DefPropDelay01;
2427
             tipd_IN1             : VitalDelayType01 := DefPropDelay01
2428
            );
2429
 
2430
    port    (Y                    :  out   STD_LOGIC;
2431
             IN1                  :  in    STD_LOGIC
2432
            );
2433
end component;
2434
 
2435
begin
2436
 
2437
dataindelaybuffer: stratixii_and1
2438
                   port map(IN1 => datain_ipd,
2439
                            Y => datain_dly);
2440
 
2441
adatasdatadelaybuffer: stratixii_and1
2442
                   port map(IN1 => adatasdata_ipd,
2443
                            Y => adatasdata_dly);
2444
 
2445
adatasdatadelaybuffer1: stratixii_and1
2446
                   port map(IN1 => adatasdata_dly,
2447
                            Y => adatasdata_dly1);
2448
 
2449
 
2450
    ---------------------
2451
    --  INPUT PATH DELAYs
2452
    ---------------------
2453
    WireDelay : block
2454
    begin
2455
        VitalWireDelay (clk_ipd, clk, tipd_clk);
2456
        VitalWireDelay (datain_ipd, datain, tipd_datain);
2457
        VitalWireDelay (adatasdata_ipd, adatasdata, tipd_adatasdata);
2458
        VitalWireDelay (sclr_ipd, sclr, tipd_sclr);
2459
        VitalWireDelay (sload_ipd, sload, tipd_sload);
2460
        VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
2461
        VitalWireDelay (aload_ipd, aload, tipd_aload);
2462
        VitalWireDelay (ena_ipd, ena, tipd_ena);
2463
    end block;
2464
 
2465
    VITALtiming : process (clk_ipd, datain_dly, adatasdata_dly1,
2466
                           sclr_ipd, sload_ipd, aclr_ipd, aload_ipd,
2467
                           ena_ipd, devclrn, devpor)
2468
 
2469
    variable Tviol_datain_clk : std_ulogic := '0';
2470
    variable Tviol_adatasdata_clk : std_ulogic := '0';
2471
    variable Tviol_sclr_clk : std_ulogic := '0';
2472
    variable Tviol_sload_clk : std_ulogic := '0';
2473
    variable Tviol_ena_clk : std_ulogic := '0';
2474
    variable TimingData_datain_clk : VitalTimingDataType := VitalTimingDataInit;
2475
    variable TimingData_adatasdata_clk : VitalTimingDataType := VitalTimingDataInit;
2476
    variable TimingData_sclr_clk : VitalTimingDataType := VitalTimingDataInit;
2477
    variable TimingData_sload_clk : VitalTimingDataType := VitalTimingDataInit;
2478
    variable TimingData_ena_clk : VitalTimingDataType := VitalTimingDataInit;
2479
    variable regout_VitalGlitchData : VitalGlitchDataType;
2480
 
2481
    variable iregout : std_logic := '0';
2482
    variable idata: std_logic := '0';
2483
 
2484
    -- variables for 'X' generation
2485
    variable violation : std_logic := '0';
2486
 
2487
    begin
2488
 
2489
        ------------------------
2490
        --  Timing Check Section
2491
        ------------------------
2492
        if (TimingChecksOn) then
2493
 
2494
            VitalSetupHoldCheck (
2495
                Violation       => Tviol_datain_clk,
2496
                TimingData      => TimingData_datain_clk,
2497
                TestSignal      => datain_ipd,
2498
                TestSignalName  => "DATAIN",
2499
                RefSignal       => clk_ipd,
2500
                RefSignalName   => "CLK",
2501
                SetupHigh       => tsetup_datain_clk_noedge_posedge,
2502
                SetupLow        => tsetup_datain_clk_noedge_posedge,
2503
                HoldHigh        => thold_datain_clk_noedge_posedge,
2504
                HoldLow         => thold_datain_clk_noedge_posedge,
2505
                CheckEnabled    => TO_X01((aclr_ipd) OR
2506
                                          (sload_ipd) OR
2507
                                          (sclr_ipd) OR
2508
                                          (NOT devpor) OR
2509
                                          (NOT devclrn) OR
2510
                                          (NOT ena_ipd)) /= '1',
2511
                RefTransition   => '/',
2512
                HeaderMsg       => InstancePath & "/LCELL_FF",
2513
                XOn             => XOnChecks,
2514
                MsgOn           => MsgOnChecks );
2515
 
2516
            VitalSetupHoldCheck (
2517
                Violation       => Tviol_adatasdata_clk,
2518
                TimingData      => TimingData_adatasdata_clk,
2519
                TestSignal      => adatasdata_ipd,
2520
                TestSignalName  => "ADATASDATA",
2521
                RefSignal       => clk_ipd,
2522
                RefSignalName   => "CLK",
2523
                SetupHigh       => tsetup_adatasdata_clk_noedge_posedge,
2524
                SetupLow        => tsetup_adatasdata_clk_noedge_posedge,
2525
                HoldHigh        => thold_adatasdata_clk_noedge_posedge,
2526
                HoldLow         => thold_adatasdata_clk_noedge_posedge,
2527
                CheckEnabled    => TO_X01((aclr_ipd) OR
2528
                                          (NOT sload_ipd) OR
2529
                                          (NOT devpor) OR
2530
                                          (NOT devclrn) OR
2531
                                          (NOT ena_ipd)) /= '1',
2532
                RefTransition   => '/',
2533
                HeaderMsg       => InstancePath & "/LCELL_FF",
2534
                XOn             => XOnChecks,
2535
                MsgOn           => MsgOnChecks );
2536
 
2537
            VitalSetupHoldCheck (
2538
                Violation       => Tviol_sclr_clk,
2539
                TimingData      => TimingData_sclr_clk,
2540
                TestSignal      => sclr_ipd,
2541
                TestSignalName  => "SCLR",
2542
                RefSignal       => clk_ipd,
2543
                RefSignalName   => "CLK",
2544
                SetupHigh       => tsetup_sclr_clk_noedge_posedge,
2545
                SetupLow        => tsetup_sclr_clk_noedge_posedge,
2546
                HoldHigh        => thold_sclr_clk_noedge_posedge,
2547
                HoldLow         => thold_sclr_clk_noedge_posedge,
2548
                CheckEnabled    => TO_X01((aclr_ipd) OR
2549
                                          (NOT devpor) OR
2550
                                          (NOT devclrn) OR
2551
                                          (NOT ena_ipd)) /= '1',
2552
                RefTransition   => '/',
2553
                HeaderMsg       => InstancePath & "/LCELL_FF",
2554
                XOn             => XOnChecks,
2555
                MsgOn           => MsgOnChecks );
2556
 
2557
            VitalSetupHoldCheck (
2558
                Violation       => Tviol_sload_clk,
2559
                TimingData      => TimingData_sload_clk,
2560
                TestSignal      => sload_ipd,
2561
                TestSignalName  => "SLOAD",
2562
                RefSignal       => clk_ipd,
2563
                RefSignalName   => "CLK",
2564
                SetupHigh       => tsetup_sload_clk_noedge_posedge,
2565
                SetupLow        => tsetup_sload_clk_noedge_posedge,
2566
                HoldHigh        => thold_sload_clk_noedge_posedge,
2567
                HoldLow         => thold_sload_clk_noedge_posedge,
2568
                CheckEnabled    => TO_X01((aclr_ipd) OR
2569
                                          (NOT devpor) OR
2570
                                          (NOT devclrn) OR
2571
                                          (NOT ena_ipd)) /= '1',
2572
                RefTransition   => '/',
2573
                HeaderMsg       => InstancePath & "/LCELL_FF",
2574
                XOn             => XOnChecks,
2575
                MsgOn           => MsgOnChecks );
2576
 
2577
            VitalSetupHoldCheck (
2578
                Violation       => Tviol_ena_clk,
2579
                TimingData      => TimingData_ena_clk,
2580
                TestSignal      => ena_ipd,
2581
                TestSignalName  => "ENA",
2582
                RefSignal       => clk_ipd,
2583
                RefSignalName   => "CLK",
2584
                SetupHigh       => tsetup_ena_clk_noedge_posedge,
2585
                SetupLow        => tsetup_ena_clk_noedge_posedge,
2586
                HoldHigh        => thold_ena_clk_noedge_posedge,
2587
                HoldLow         => thold_ena_clk_noedge_posedge,
2588
                CheckEnabled    => TO_X01((aclr_ipd) OR
2589
                                          (NOT devpor) OR
2590
                                          (NOT devclrn) ) /= '1',
2591
                RefTransition   => '/',
2592
                HeaderMsg       => InstancePath & "/LCELL_FF",
2593
                XOn             => XOnChecks,
2594
                MsgOn           => MsgOnChecks );
2595
 
2596
        end if;
2597
 
2598
        violation := Tviol_datain_clk or Tviol_adatasdata_clk or
2599
                     Tviol_sclr_clk or Tviol_sload_clk or Tviol_ena_clk;
2600
 
2601
 
2602
        if ((devpor = '0') or (devclrn = '0') or (aclr_ipd = '1'))  then
2603
            iregout := '0';
2604
        elsif (aload_ipd = '1') then
2605
            iregout := adatasdata_dly1;
2606
        elsif (violation = 'X' and x_on_violation = "on") then
2607
            iregout := 'X';
2608
        elsif clk_ipd'event and clk_ipd = '1' and clk_ipd'last_value = '0' then
2609
            if (ena_ipd = '1') then
2610
                if (sclr_ipd = '1') then
2611
                    iregout := '0';
2612
                elsif (sload_ipd = '1') then
2613
                    iregout := adatasdata_dly1;
2614
                else
2615
                    iregout := datain_dly;
2616
                end if;
2617
            end if;
2618
        end if;
2619
 
2620
        ----------------------
2621
        --  Path Delay Section
2622
        ----------------------
2623
        VitalPathDelay01 (
2624
            OutSignal => regout,
2625
            OutSignalName => "REGOUT",
2626
            OutTemp => iregout,
2627
            Paths => (0 => (aclr_ipd'last_event, tpd_aclr_regout_posedge, TRUE),
2628
                      1 => (aload_ipd'last_event, tpd_aload_regout_posedge, TRUE),
2629
                      2 => (adatasdata_ipd'last_event, tpd_adatasdata_regout, TRUE),
2630
                      3 => (clk_ipd'last_event, tpd_clk_regout_posedge, TRUE)),
2631
            GlitchData => regout_VitalGlitchData,
2632
            Mode => DefGlitchMode,
2633
            XOn  => XOn,
2634
            MsgOn  => MsgOn );
2635
 
2636
    end process;
2637
 
2638
end vital_lcell_ff;
2639
 
2640
---------------------------------------------------------------------
2641
--
2642
-- Entity Name :  stratixii_lcell_comb
2643
--
2644
-- Description :  StratixII LCELL_COMB VHDL simulation model
2645
--
2646
--
2647
---------------------------------------------------------------------
2648
 
2649
LIBRARY IEEE;
2650
use IEEE.std_logic_1164.all;
2651
use IEEE.VITAL_Timing.all;
2652
use IEEE.VITAL_Primitives.all;
2653
use work.stratixii_atom_pack.all;
2654
 
2655
entity stratixii_lcell_comb is
2656
    generic (
2657
             lut_mask : std_logic_vector(63 downto 0) := (OTHERS => '1');
2658
             shared_arith : string := "off";
2659
             extended_lut : string := "off";
2660
             lpm_type : string := "stratixii_lcell_comb";
2661
             TimingChecksOn: Boolean := True;
2662
             MsgOn: Boolean := DefGlitchMsgOn;
2663
             XOn: Boolean := DefGlitchXOn;
2664
             MsgOnChecks: Boolean := DefMsgOnChecks;
2665
             XOnChecks: Boolean := DefXOnChecks;
2666
             InstancePath: STRING := "*";
2667
             tpd_dataa_combout : VitalDelayType01 := DefPropDelay01;
2668
             tpd_datab_combout : VitalDelayType01 := DefPropDelay01;
2669
             tpd_datac_combout : VitalDelayType01 := DefPropDelay01;
2670
             tpd_datad_combout : VitalDelayType01 := DefPropDelay01;
2671
             tpd_datae_combout : VitalDelayType01 := DefPropDelay01;
2672
             tpd_dataf_combout : VitalDelayType01 := DefPropDelay01;
2673
             tpd_datag_combout : VitalDelayType01 := DefPropDelay01;
2674
             tpd_dataa_sumout : VitalDelayType01 := DefPropDelay01;
2675
             tpd_datab_sumout : VitalDelayType01 := DefPropDelay01;
2676
             tpd_datac_sumout : VitalDelayType01 := DefPropDelay01;
2677
             tpd_datad_sumout : VitalDelayType01 := DefPropDelay01;
2678
             tpd_dataf_sumout : VitalDelayType01 := DefPropDelay01;
2679
             tpd_cin_sumout : VitalDelayType01 := DefPropDelay01;
2680
             tpd_sharein_sumout : VitalDelayType01 := DefPropDelay01;
2681
             tpd_dataa_cout : VitalDelayType01 := DefPropDelay01;
2682
             tpd_datab_cout : VitalDelayType01 := DefPropDelay01;
2683
             tpd_datac_cout : VitalDelayType01 := DefPropDelay01;
2684
             tpd_datad_cout : VitalDelayType01 := DefPropDelay01;
2685
             tpd_dataf_cout : VitalDelayType01 := DefPropDelay01;
2686
             tpd_cin_cout : VitalDelayType01 := DefPropDelay01;
2687
             tpd_sharein_cout : VitalDelayType01 := DefPropDelay01;
2688
             tpd_dataa_shareout : VitalDelayType01 := DefPropDelay01;
2689
             tpd_datab_shareout : VitalDelayType01 := DefPropDelay01;
2690
             tpd_datac_shareout : VitalDelayType01 := DefPropDelay01;
2691
             tpd_datad_shareout : VitalDelayType01 := DefPropDelay01;
2692
             tipd_dataa : VitalDelayType01 := DefPropDelay01;
2693
             tipd_datab : VitalDelayType01 := DefPropDelay01;
2694
             tipd_datac : VitalDelayType01 := DefPropDelay01;
2695
             tipd_datad : VitalDelayType01 := DefPropDelay01;
2696
             tipd_datae : VitalDelayType01 := DefPropDelay01;
2697
             tipd_dataf : VitalDelayType01 := DefPropDelay01;
2698
             tipd_datag : VitalDelayType01 := DefPropDelay01;
2699
             tipd_cin : VitalDelayType01 := DefPropDelay01;
2700
             tipd_sharein : VitalDelayType01 := DefPropDelay01
2701
            );
2702
 
2703
    port (
2704
          dataa : in std_logic := '0';
2705
          datab : in std_logic := '0';
2706
          datac : in std_logic := '0';
2707
          datad : in std_logic := '0';
2708
          datae : in std_logic := '0';
2709
          dataf : in std_logic := '0';
2710
          datag : in std_logic := '0';
2711
          cin : in std_logic := '0';
2712
          sharein : in std_logic := '0';
2713
          combout : out std_logic;
2714
          sumout : out std_logic;
2715
          cout : out std_logic;
2716
          shareout : out std_logic
2717
         );
2718
   attribute VITAL_LEVEL0 of stratixii_lcell_comb : entity is TRUE;
2719
end stratixii_lcell_comb;
2720
 
2721
architecture vital_lcell_comb of stratixii_lcell_comb is
2722
    attribute VITAL_LEVEL0 of vital_lcell_comb : architecture is TRUE;
2723
    signal dataa_ipd : std_logic;
2724
    signal datab_ipd : std_logic;
2725
    signal datac_ipd : std_logic;
2726
    signal datad_ipd : std_logic;
2727
    signal datae_ipd : std_logic;
2728
    signal dataf_ipd : std_logic;
2729
    signal datag_ipd : std_logic;
2730
    signal cin_ipd : std_logic;
2731
    signal sharein_ipd : std_logic;
2732
    signal f2_input3 : std_logic;
2733
    -- sub masks
2734
    signal f0_mask : std_logic_vector(15 downto 0);
2735
    signal f1_mask : std_logic_vector(15 downto 0);
2736
    signal f2_mask : std_logic_vector(15 downto 0);
2737
    signal f3_mask : std_logic_vector(15 downto 0);
2738
begin
2739
 
2740
    ---------------------
2741
    --  INPUT PATH DELAYs
2742
    ---------------------
2743
    WireDelay : block
2744
    begin
2745
        VitalWireDelay (dataa_ipd, dataa, tipd_dataa);
2746
        VitalWireDelay (datab_ipd, datab, tipd_datab);
2747
        VitalWireDelay (datac_ipd, datac, tipd_datac);
2748
        VitalWireDelay (datad_ipd, datad, tipd_datad);
2749
        VitalWireDelay (datae_ipd, datae, tipd_datae);
2750
        VitalWireDelay (dataf_ipd, dataf, tipd_dataf);
2751
        VitalWireDelay (datag_ipd, datag, tipd_datag);
2752
        VitalWireDelay (cin_ipd, cin, tipd_cin);
2753
        VitalWireDelay (sharein_ipd, sharein, tipd_sharein);
2754
    end block;
2755
 
2756
    f0_mask <= lut_mask(15 downto 0);
2757
    f1_mask <= lut_mask(31 downto 16);
2758
    f2_mask <= lut_mask(47 downto 32);
2759
    f3_mask <= lut_mask(63 downto 48);
2760
 
2761
    f2_input3 <= datag_ipd WHEN (extended_lut = "on") ELSE datac_ipd;
2762
 
2763
VITALtiming : process(dataa_ipd, datab_ipd, datac_ipd, datad_ipd,
2764
                      datae_ipd, dataf_ipd, f2_input3, cin_ipd,
2765
                      sharein_ipd)
2766
 
2767
variable combout_VitalGlitchData : VitalGlitchDataType;
2768
variable sumout_VitalGlitchData : VitalGlitchDataType;
2769
variable cout_VitalGlitchData : VitalGlitchDataType;
2770
variable shareout_VitalGlitchData : VitalGlitchDataType;
2771
-- sub lut outputs
2772
variable f0_out : std_logic;
2773
variable f1_out : std_logic;
2774
variable f2_out : std_logic;
2775
variable f3_out : std_logic;
2776
-- muxed output
2777
variable g0_out : std_logic;
2778
variable g1_out : std_logic;
2779
-- internal variables
2780
variable f2_f : std_logic;
2781
variable adder_input2 : std_logic;
2782
-- output variables
2783
variable combout_tmp : std_logic;
2784
variable sumout_tmp : std_logic;
2785
variable cout_tmp : std_logic;
2786
-- temp variable for NCVHDL
2787
variable lut_mask_var : std_logic_vector(63 downto 0) := (OTHERS => '1');
2788
 
2789
begin
2790
 
2791
    lut_mask_var := lut_mask;
2792
 
2793
    ------------------------
2794
    --  Timing Check Section
2795
    ------------------------
2796
 
2797
    f0_out := VitalMUX(data => f0_mask,
2798
                       dselect => (datad_ipd,
2799
                                   datac_ipd,
2800
                                   datab_ipd,
2801
                                   dataa_ipd));
2802
    f1_out := VitalMUX(data => f1_mask,
2803
                       dselect => (datad_ipd,
2804
                                   f2_input3,
2805
                                   datab_ipd,
2806
                                   dataa_ipd));
2807
    f2_out := VitalMUX(data => f2_mask,
2808
                       dselect => (datad_ipd,
2809
                                   datac_ipd,
2810
                                   datab_ipd,
2811
                                   dataa_ipd));
2812
    f3_out := VitalMUX(data => f3_mask,
2813
                       dselect => (datad_ipd,
2814
                                   f2_input3,
2815
                                   datab_ipd,
2816
                                   dataa_ipd));
2817
 
2818
    -- combout
2819
    if (extended_lut = "on") then
2820
        if (datae_ipd = '0') then
2821
            g0_out := f0_out;
2822
            g1_out := f2_out;
2823
        elsif (datae_ipd = '1') then
2824
            g0_out := f1_out;
2825
            g1_out := f3_out;
2826
        else
2827
            g0_out := 'X';
2828
            g1_out := 'X';
2829
        end if;
2830
 
2831
        if (dataf_ipd = '0') then
2832
            combout_tmp := g0_out;
2833
        elsif ((dataf_ipd = '1')  or (g0_out = g1_out))then
2834
            combout_tmp := g1_out;
2835
        else
2836
            combout_tmp := 'X';
2837
        end if;
2838
    else
2839
        combout_tmp := VitalMUX(data => lut_mask_var,
2840
                                dselect => (dataf_ipd,
2841
                                            datae_ipd,
2842
                                            datad_ipd,
2843
                                            datac_ipd,
2844
                                            datab_ipd,
2845
                                            dataa_ipd));
2846
    end if;
2847
 
2848
    -- sumout and cout
2849
    f2_f := VitalMUX(data => f2_mask,
2850
                     dselect => (dataf_ipd,
2851
                                 datac_ipd,
2852
                                 datab_ipd,
2853
                                 dataa_ipd));
2854
 
2855
    if (shared_arith = "on") then
2856
        adder_input2 := sharein_ipd;
2857
    else
2858
        adder_input2 := NOT f2_f;
2859
    end if;
2860
 
2861
    sumout_tmp := cin_ipd XOR f0_out XOR adder_input2;
2862
    cout_tmp := (cin_ipd AND f0_out) OR (cin_ipd AND adder_input2) OR
2863
                (f0_out AND adder_input2);
2864
 
2865
    ----------------------
2866
    --  Path Delay Section
2867
    ----------------------
2868
 
2869
    VitalPathDelay01 (
2870
        OutSignal => combout,
2871
        OutSignalName => "COMBOUT",
2872
        OutTemp => combout_tmp,
2873
        Paths => (0 => (dataa_ipd'last_event, tpd_dataa_combout, TRUE),
2874
                  1 => (datab_ipd'last_event, tpd_datab_combout, TRUE),
2875
                  2 => (datac_ipd'last_event, tpd_datac_combout, TRUE),
2876
                  3 => (datad_ipd'last_event, tpd_datad_combout, TRUE),
2877
                  4 => (datae_ipd'last_event, tpd_datae_combout, TRUE),
2878
                  5 => (dataf_ipd'last_event, tpd_dataf_combout, TRUE),
2879
                  6 => (datag_ipd'last_event, tpd_datag_combout, TRUE)),
2880
        GlitchData => combout_VitalGlitchData,
2881
        Mode => DefGlitchMode,
2882
        XOn  => XOn,
2883
        MsgOn => MsgOn );
2884
 
2885
    VitalPathDelay01 (
2886
        OutSignal => sumout,
2887
        OutSignalName => "SUMOUT",
2888
        OutTemp => sumout_tmp,
2889
        Paths => (0 => (dataa_ipd'last_event, tpd_dataa_sumout, TRUE),
2890
                  1 => (datab_ipd'last_event, tpd_datab_sumout, TRUE),
2891
                  2 => (datac_ipd'last_event, tpd_datac_sumout, TRUE),
2892
                  3 => (datad_ipd'last_event, tpd_datad_sumout, TRUE),
2893
                  4 => (dataf_ipd'last_event, tpd_dataf_sumout, TRUE),
2894
                  5 => (cin_ipd'last_event, tpd_cin_sumout, TRUE),
2895
                  6 => (sharein_ipd'last_event, tpd_sharein_sumout, TRUE)),
2896
        GlitchData => sumout_VitalGlitchData,
2897
        Mode => DefGlitchMode,
2898
        XOn  => XOn,
2899
        MsgOn => MsgOn );
2900
 
2901
    VitalPathDelay01 (
2902
        OutSignal => cout,
2903
        OutSignalName => "COUT",
2904
        OutTemp => cout_tmp,
2905
        Paths => (0 => (dataa_ipd'last_event, tpd_dataa_cout, TRUE),
2906
                  1 => (datab_ipd'last_event, tpd_datab_cout, TRUE),
2907
                  2 => (datac_ipd'last_event, tpd_datac_cout, TRUE),
2908
                  3 => (datad_ipd'last_event, tpd_datad_cout, TRUE),
2909
                  4 => (dataf_ipd'last_event, tpd_dataf_cout, TRUE),
2910
                  5 => (cin_ipd'last_event, tpd_cin_cout, TRUE),
2911
                  6 => (sharein_ipd'last_event, tpd_sharein_cout, TRUE)),
2912
        GlitchData => cout_VitalGlitchData,
2913
        Mode => DefGlitchMode,
2914
        XOn  => XOn,
2915
        MsgOn => MsgOn );
2916
 
2917
    VitalPathDelay01 (
2918
        OutSignal => shareout,
2919
        OutSignalName => "SHAREOUT",
2920
        OutTemp => f2_out,
2921
        Paths => (0 => (dataa_ipd'last_event, tpd_dataa_shareout, TRUE),
2922
                  1 => (datab_ipd'last_event, tpd_datab_shareout, TRUE),
2923
                  2 => (datac_ipd'last_event, tpd_datac_shareout, TRUE),
2924
                  3 => (datad_ipd'last_event, tpd_datad_shareout, TRUE)),
2925
        GlitchData => shareout_VitalGlitchData,
2926
        Mode => DefGlitchMode,
2927
        XOn  => XOn,
2928
        MsgOn => MsgOn );
2929
 
2930
end process;
2931
 
2932
end vital_lcell_comb;
2933
 
2934
--/////////////////////////////////////////////////////////////////////////////
2935
--
2936
-- Entity Name : ena_reg
2937
--
2938
-- Description : Simulation model for a simple DFF.
2939
--               This is used for the gated clock generation
2940
--               Powers upto 1.
2941
--
2942
--/////////////////////////////////////////////////////////////////////////////
2943
 
2944
LIBRARY IEEE;
2945
USE IEEE.std_logic_1164.all;
2946
use IEEE.VITAL_Timing.all;
2947
use IEEE.VITAL_Primitives.all;
2948
use work.stratixii_atom_pack.all;
2949
 
2950
ENTITY stratixii_ena_reg is
2951
    generic (
2952
             TimingChecksOn : Boolean := True;
2953
             MsgOn : Boolean := DefGlitchMsgOn;
2954
             XOn : Boolean := DefGlitchXOn;
2955
             MsgOnChecks : Boolean := DefMsgOnChecks;
2956
             XOnChecks : Boolean := DefXOnChecks;
2957
             InstancePath : STRING := "*";
2958
             tsetup_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2959
             thold_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
2960
             tpd_clk_q_posedge : VitalDelayType01 := DefPropDelay01;
2961
             tipd_d : VitalDelayType01 := DefPropDelay01;
2962
             tipd_clk : VitalDelayType01 := DefPropDelay01
2963
            );
2964
    PORT (
2965
          clk : in std_logic;
2966
          ena : in std_logic := '1';
2967
          d : in std_logic;
2968
          clrn : in std_logic := '1';
2969
          prn : in std_logic := '1';
2970
          q : out std_logic
2971
         );
2972
   attribute VITAL_LEVEL0 of stratixii_ena_reg : entity is TRUE;
2973
end stratixii_ena_reg;
2974
 
2975
ARCHITECTURE behave of stratixii_ena_reg is
2976
    attribute VITAL_LEVEL0 of behave : architecture is TRUE;
2977
    signal d_ipd : std_logic;
2978
    signal clk_ipd : std_logic;
2979
begin
2980
 
2981
    ---------------------
2982
    --  INPUT PATH DELAYs
2983
    ---------------------
2984
    WireDelay : block
2985
    begin
2986
        VitalWireDelay (d_ipd, d, tipd_d);
2987
        VitalWireDelay (clk_ipd, clk, tipd_clk);
2988
    end block;
2989
 
2990
    VITALtiming :  process (clk_ipd, prn, clrn)
2991
    variable Tviol_d_clk : std_ulogic := '0';
2992
    variable TimingData_d_clk : VitalTimingDataType := VitalTimingDataInit;
2993
    variable q_VitalGlitchData : VitalGlitchDataType;
2994
    variable q_reg : std_logic := '1';
2995
    begin
2996
 
2997
        ------------------------
2998
        --  Timing Check Section
2999
        ------------------------
3000
        if (TimingChecksOn) then
3001
 
3002
            VitalSetupHoldCheck (
3003
                Violation       => Tviol_d_clk,
3004
                TimingData      => TimingData_d_clk,
3005
                TestSignal      => d,
3006
                TestSignalName  => "D",
3007
                RefSignal       => clk_ipd,
3008
                RefSignalName   => "CLK",
3009
                SetupHigh       => tsetup_d_clk_noedge_posedge,
3010
                SetupLow        => tsetup_d_clk_noedge_posedge,
3011
                HoldHigh        => thold_d_clk_noedge_posedge,
3012
                HoldLow         => thold_d_clk_noedge_posedge,
3013
                CheckEnabled    => TO_X01((clrn) OR
3014
                                          (NOT ena)) /= '1',
3015
                RefTransition   => '/',
3016
                HeaderMsg       => InstancePath & "/ENA_REG",
3017
                XOn             => XOnChecks,
3018
                MsgOn           => MsgOnChecks );
3019
 
3020
        end if;
3021
 
3022
        if (prn = '0') then
3023
            q_reg := '1';
3024
        elsif (clrn = '0') then
3025
            q_reg := '0';
3026
        elsif (clk_ipd'event and clk_ipd = '1' and (ena = '1')) then
3027
            q_reg := d_ipd;
3028
        end if;
3029
 
3030
        ----------------------
3031
        --  Path Delay Section
3032
        ----------------------
3033
        VitalPathDelay01 (
3034
            OutSignal => q,
3035
            OutSignalName => "Q",
3036
            OutTemp => q_reg,
3037
            Paths => (0 => (clk_ipd'last_event, tpd_clk_q_posedge, TRUE)),
3038
            GlitchData => q_VitalGlitchData,
3039
            Mode => DefGlitchMode,
3040
            XOn  => XOn,
3041
            MsgOn  => MsgOn );
3042
    end process;
3043
 
3044
end behave;
3045
 
3046
--/////////////////////////////////////////////////////////////////////////////
3047
--
3048
--              VHDL Simulation Model for StratixII CLKCTRL Atom
3049
--
3050
--/////////////////////////////////////////////////////////////////////////////
3051
 
3052
--
3053
--
3054
--  STRATIXII_CLKCTRL Model
3055
--
3056
--
3057
 
3058
LIBRARY IEEE;
3059
use IEEE.std_logic_1164.all;
3060
use IEEE.VITAL_Timing.all;
3061
use IEEE.VITAL_Primitives.all;
3062
use work.stratixii_atom_pack.all;
3063
use work.stratixii_ena_reg;
3064
 
3065
entity stratixii_clkctrl is
3066
    generic (
3067
             clock_type : STRING := "Auto";
3068
             lpm_type : STRING := "stratixii_clkctrl";
3069
             TimingChecksOn : Boolean := True;
3070
             MsgOn : Boolean := DefGlitchMsgOn;
3071
             XOn : Boolean := DefGlitchXOn;
3072
             MsgOnChecks : Boolean := DefMsgOnChecks;
3073
             XOnChecks : Boolean := DefXOnChecks;
3074
             InstancePath : STRING := "*";
3075
             tipd_inclk : VitalDelayArrayType01(3 downto 0) := (OTHERS => DefPropDelay01);
3076
             tipd_clkselect : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01);
3077
             tipd_ena : VitalDelayType01 := DefPropDelay01
3078
             );
3079
    port (
3080
          inclk : in std_logic_vector(3 downto 0) := "0000";
3081
          clkselect : in std_logic_vector(1 downto 0) := "00";
3082
          ena : in std_logic := '1';
3083
          devclrn : in std_logic := '1';
3084
          devpor : in std_logic := '1';
3085
          outclk : out std_logic
3086
          );
3087
   attribute VITAL_LEVEL0 of stratixii_clkctrl : entity is TRUE;
3088
end stratixii_clkctrl;
3089
 
3090
architecture vital_clkctrl of stratixii_clkctrl is
3091
    attribute VITAL_LEVEL0 of vital_clkctrl : architecture is TRUE;
3092
 
3093
    component stratixii_ena_reg
3094
        generic (
3095
                 TimingChecksOn : Boolean := True;
3096
                 MsgOn : Boolean := DefGlitchMsgOn;
3097
                 XOn : Boolean := DefGlitchXOn;
3098
                 MsgOnChecks : Boolean := DefMsgOnChecks;
3099
                 XOnChecks : Boolean := DefXOnChecks;
3100
                 InstancePath : STRING := "*";
3101
                 tsetup_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
3102
                 thold_d_clk_noedge_posedge     : VitalDelayType := DefSetupHoldCnst;
3103
                 tpd_clk_q_posedge : VitalDelayType01 := DefPropDelay01;
3104
                 tipd_d : VitalDelayType01 := DefPropDelay01;
3105
                 tipd_clk : VitalDelayType01 := DefPropDelay01
3106
                );
3107
        PORT (
3108
              clk : in std_logic;
3109
              ena : in std_logic := '1';
3110
              d : in std_logic;
3111
              clrn : in std_logic := '1';
3112
              prn : in std_logic := '1';
3113
              q : out std_logic
3114
             );
3115
    end component;
3116
 
3117
    signal inclk_ipd : std_logic_vector(3 downto 0);
3118
    signal clkselect_ipd : std_logic_vector(1 downto 0);
3119
    signal ena_ipd : std_logic;
3120
    signal clkmux_out : std_logic;
3121
    signal clkmux_out_inv : std_logic;
3122
    signal cereg_clr : std_logic;
3123
    signal cereg_out : std_logic;
3124
    signal vcc : std_logic := '1';
3125
begin
3126
 
3127
    ---------------------
3128
    --  INPUT PATH DELAYs
3129
    ---------------------
3130
    WireDelay : block
3131
    begin
3132
        VitalWireDelay (ena_ipd, ena, tipd_ena);
3133
        VitalWireDelay (inclk_ipd(0), inclk(0), tipd_inclk(0));
3134
        VitalWireDelay (inclk_ipd(1), inclk(1), tipd_inclk(1));
3135
        VitalWireDelay (inclk_ipd(2), inclk(2), tipd_inclk(2));
3136
        VitalWireDelay (inclk_ipd(3), inclk(3), tipd_inclk(3));
3137
        VitalWireDelay (clkselect_ipd(0), clkselect(0), tipd_clkselect(0));
3138
        VitalWireDelay (clkselect_ipd(1), clkselect(1), tipd_clkselect(1));
3139
    end block;
3140
 
3141
    process(inclk_ipd, clkselect_ipd)
3142
    variable tmp : std_logic;
3143
    begin
3144
        if (clkselect_ipd = "11") then
3145
            tmp := inclk_ipd(3);
3146
        elsif (clkselect_ipd = "10") then
3147
            tmp := inclk_ipd(2);
3148
        elsif (clkselect_ipd = "01") then
3149
            tmp := inclk_ipd(1);
3150
        else
3151
            tmp := inclk_ipd(0);
3152
        end if;
3153
        clkmux_out <= tmp;
3154
        clkmux_out_inv <= NOT tmp;
3155
    end process;
3156
 
3157
    extena0_reg : stratixii_ena_reg
3158
                  port map (
3159
                            clk => clkmux_out_inv,
3160
                            ena => vcc,
3161
                            d => ena_ipd,
3162
                            clrn => vcc,
3163
                            prn => devpor,
3164
                            q => cereg_out
3165
                           );
3166
 
3167
    outclk <= cereg_out AND clkmux_out;
3168
 
3169
end vital_clkctrl;
3170
 
3171
 
3172
--
3173
--
3174
--  STRATIXII_ASYNCH_IO Model
3175
--
3176
--
3177
LIBRARY IEEE;
3178
use IEEE.std_logic_1164.all;
3179
use IEEE.VITAL_Timing.all;
3180
use IEEE.VITAL_Primitives.all;
3181
use work.stratixii_atom_pack.all;
3182
 
3183
entity stratixii_asynch_io is
3184
    generic(
3185
                operation_mode  : STRING := "input";
3186
                open_drain_output : STRING := "false";
3187
                bus_hold : STRING := "false";
3188
 
3189
                dqs_input_frequency      : STRING := "10000 ps";
3190
                dqs_out_mode             : STRING := "none";
3191
                dqs_delay_buffer_mode    : STRING := "low";
3192
                dqs_phase_shift          : INTEGER := 0;
3193
                dqs_offsetctrl_enable    : STRING := "false";
3194
                dqs_ctrl_latches_enable  : STRING := "false";
3195
                dqs_edge_detect_enable   : STRING := "false";
3196
                gated_dqs                : STRING := "false";
3197
                sim_dqs_intrinsic_delay  : INTEGER := 0;
3198
                sim_dqs_delay_increment  : INTEGER := 0;
3199
                sim_dqs_offset_increment : INTEGER := 0;
3200
 
3201
                XOn: Boolean := DefGlitchXOn;
3202
                MsgOn: Boolean := DefGlitchMsgOn;
3203
 
3204
                tpd_datain_padio        : VitalDelayType01 := DefPropDelay01;
3205
                tpd_oe_padio_posedge       : VitalDelayType01 := DefPropDelay01;
3206
                tpd_oe_padio_negedge       : VitalDelayType01 := DefPropDelay01;
3207
                tpd_padio_combout   : VitalDelayType01 := DefPropDelay01;
3208
                tpd_regin_regout   : VitalDelayType01 := DefPropDelay01;
3209
                tpd_ddioregin_ddioregout   : VitalDelayType01 := DefPropDelay01;
3210
                tpd_padio_dqsbusout   : VitalDelayType01 := DefPropDelay01;
3211
                tpd_regin_dqsbusout   : VitalDelayType01 := DefPropDelay01;
3212
 
3213
                tipd_datain         : VitalDelayType01 := DefPropDelay01;
3214
                tipd_oe             : VitalDelayType01 := DefPropDelay01;
3215
                tipd_padio          : VitalDelayType01 := DefPropDelay01;
3216
                tipd_dqsupdateen    : VitalDelayType01 := DefPropDelay01;
3217
                tipd_offsetctrlin   : VitalDelayArrayType01(5 downto 0) := (OTHERS => DefPropDelay01);
3218
                tipd_delayctrlin    : VitalDelayArrayType01(5 downto 0) := (OTHERS => DefPropDelay01));
3219
        port(
3220
                datain  : in  STD_LOGIC := '0';
3221
                oe          : in  STD_LOGIC := '1';
3222
                regin  : in std_logic;
3223
                ddioregin  : in std_logic;
3224
                padio   : inout STD_LOGIC;
3225
                delayctrlin  : in std_logic_vector(5 downto 0);
3226
                offsetctrlin : in std_logic_vector(5 downto 0);
3227
                dqsupdateen  : in std_logic;
3228
                dqsbusout    : out std_logic;
3229
                combout : out STD_LOGIC;
3230
                regout : out STD_LOGIC;
3231
                ddioregout : out STD_LOGIC);
3232
 
3233
    attribute VITAL_LEVEL0 of stratixii_asynch_io : entity is TRUE;
3234
end stratixii_asynch_io;
3235
 
3236
architecture behave of stratixii_asynch_io is
3237
attribute VITAL_LEVEL0 of behave : architecture is TRUE;
3238
signal datain_ipd, oe_ipd, padio_ipd: std_logic;
3239
signal delayctrlin_in  : std_logic_vector(5 downto 0);
3240
signal offsetctrlin_in : std_logic_vector(5 downto 0);
3241
signal dqsupdateen_in : std_logic;
3242
 
3243
signal dqs_delay_int : integer := 0;
3244
signal tmp_dqsbusout : std_logic;
3245
 
3246
signal dqs_ctrl_latches_ena : std_logic := '1';
3247
signal combout_tmp_sig      : std_logic := '0';
3248
signal dqsbusout_tmp_sig    : std_logic := '0';
3249
 
3250
begin
3251
    ---------------------
3252
    --  INPUT PATH DELAYs
3253
    ---------------------
3254
    WireDelay : block
3255
    begin
3256
        VitalWireDelay (datain_ipd, datain, tipd_datain);
3257
        VitalWireDelay (oe_ipd, oe, tipd_oe);
3258
        VitalWireDelay (padio_ipd, padio, tipd_padio);
3259
        VitalWireDelay (delayctrlin_in(5), delayctrlin(5), tipd_delayctrlin(5));
3260
        VitalWireDelay (delayctrlin_in(4), delayctrlin(4), tipd_delayctrlin(4));
3261
        VitalWireDelay (delayctrlin_in(3), delayctrlin(3), tipd_delayctrlin(3));
3262
        VitalWireDelay (delayctrlin_in(2), delayctrlin(2), tipd_delayctrlin(2));
3263
        VitalWireDelay (delayctrlin_in(1), delayctrlin(1), tipd_delayctrlin(1));
3264
        VitalWireDelay (delayctrlin_in(0), delayctrlin(0), tipd_delayctrlin(0));
3265
        VitalWireDelay (dqsupdateen_in, dqsupdateen, tipd_dqsupdateen);
3266
        VitalWireDelay (offsetctrlin_in(5), offsetctrlin(5), tipd_offsetctrlin(5));
3267
        VitalWireDelay (offsetctrlin_in(4), offsetctrlin(4), tipd_offsetctrlin(4));
3268
        VitalWireDelay (offsetctrlin_in(3), offsetctrlin(3), tipd_offsetctrlin(3));
3269
        VitalWireDelay (offsetctrlin_in(2), offsetctrlin(2), tipd_offsetctrlin(2));
3270
        VitalWireDelay (offsetctrlin_in(1), offsetctrlin(1), tipd_offsetctrlin(1));
3271
        VitalWireDelay (offsetctrlin_in(0), offsetctrlin(0), tipd_offsetctrlin(0));
3272
    end block;
3273
 
3274
   dqs_ctrl_latches_ena <= '1'              when dqs_ctrl_latches_enable = "false" ELSE
3275
                           dqsupdateen_in when dqs_edge_detect_enable = "false"  ELSE
3276
                           (not (combout_tmp_sig xor tmp_dqsbusout) and dqsupdateen_in);
3277
 
3278
    process(delayctrlin_in, offsetctrlin_in, dqs_ctrl_latches_ena)
3279
        variable tmp_delayctrl  : integer := 0;
3280
        variable tmp_offsetctrl : integer := 0;
3281
    begin
3282
        tmp_delayctrl  := alt_conv_integer(delayctrlin_in);
3283
 
3284
        if (dqs_offsetctrl_enable = "true") then
3285
            tmp_offsetctrl := alt_conv_integer(offsetctrlin_in);
3286
        else
3287
            tmp_offsetctrl := 0;
3288
        end if;
3289
 
3290
        if (dqs_ctrl_latches_ena = '1') THEN
3291
            dqs_delay_int <= sim_dqs_intrinsic_delay + sim_dqs_delay_increment*tmp_delayctrl + sim_dqs_offset_increment*tmp_offsetctrl;
3292
        end if;
3293
 
3294
        if ((dqs_delay_buffer_mode = "high") AND (delayctrlin_in(5) = '1')) THEN
3295
            assert false report "DELAYCTRLIN of DQS I/O exceeds 5-bit range in high-frequency mode" severity warning;
3296
            dqs_delay_int <= 0;
3297
        end if;
3298
    end process;
3299
 
3300
    VITAL: process(padio_ipd, datain_ipd, oe_ipd, regin, ddioregin, tmp_dqsbusout)
3301
        variable combout_VitalGlitchData : VitalGlitchDataType;
3302
        variable dqsbusout_VitalGlitchData : VitalGlitchDataType;
3303
        variable padio_VitalGlitchData : VitalGlitchDataType;
3304
        variable regout_VitalGlitchData : VitalGlitchDataType;
3305
        variable ddioregout_VitalGlitchData : VitalGlitchDataType;
3306
 
3307
        variable tmp_combout, tmp_padio : std_logic;
3308
        variable prev_value : std_logic := 'H';
3309
 
3310
        variable dqsbusout_tmp   : std_logic;
3311
        variable combout_delay   : VitalDelayType01 := (0 ps, 0 ps);
3312
        variable init : boolean := true;
3313
 
3314
        begin
3315
 
3316
        if (init) then
3317
            combout_delay := tpd_padio_combout;
3318
            init := false;
3319
        end if;
3320
 
3321
        if (bus_hold = "true" ) then
3322
                if ( operation_mode = "input") then
3323
                        if ( padio_ipd = 'Z') then
3324
                                tmp_combout := to_x01z(prev_value);
3325
                        else
3326
                                if ( padio_ipd = '1') then
3327
                                        prev_value := 'H';
3328
                                elsif ( padio_ipd = '0') then
3329
                                        prev_value := 'L';
3330
                                else
3331
                                        prev_value := 'W';
3332
                                end if;
3333
                                tmp_combout := to_x01z(padio_ipd);
3334
                        end if;
3335
                        tmp_padio := 'Z';
3336
                elsif ( operation_mode = "output" or operation_mode = "bidir") then
3337
                        if ( oe_ipd = '1') then
3338
                                if ( open_drain_output = "true" ) then
3339
                                        if (datain_ipd = '0') then
3340
                                                tmp_padio := '0';
3341
                                                prev_value := 'L';
3342
                                        elsif (datain_ipd = 'X') then
3343
                                                tmp_padio := 'X';
3344
                                                prev_value := 'W';
3345
                                        else   -- 'Z'
3346
                                                -- need to update prev_value
3347
                                                if (padio_ipd = '1') then
3348
                                                        prev_value := 'H';
3349
                                                elsif (padio_ipd = '0') then
3350
                                                        prev_value := 'L';
3351
                                                elsif (padio_ipd = 'X') then
3352
                                                        prev_value := 'W';
3353
                                                end if;
3354
                                                tmp_padio := prev_value;
3355
                                        end if;
3356
                                else
3357
                                        tmp_padio := datain_ipd;
3358
                                        if ( datain_ipd = '1') then
3359
                                                prev_value := 'H';
3360
                                        elsif (datain_ipd = '0' ) then
3361
                                                prev_value := 'L';
3362
                                        elsif ( datain_ipd = 'X') then
3363
                                                prev_value := 'W';
3364
                                        else
3365
                                                prev_value := datain_ipd;
3366
                                        end if;
3367
                                end if; -- end open_drain_output
3368
 
3369
                        elsif ( oe_ipd = '0' ) then
3370
                                -- need to update prev_value
3371
                                if (padio_ipd = '1') then
3372
                                        prev_value := 'H';
3373
                                elsif (padio_ipd = '0') then
3374
                                        prev_value := 'L';
3375
                                elsif (padio_ipd = 'X') then
3376
                                        prev_value := 'W';
3377
                                end if;
3378
                                tmp_padio := prev_value;
3379
                        else
3380
                                tmp_padio := 'X';
3381
                                prev_value := 'W';
3382
                        end if; -- end oe_in
3383
 
3384
                        if ( operation_mode = "bidir") then
3385
                                tmp_combout := to_x01z(padio_ipd);
3386
                        else
3387
                                tmp_combout := 'Z';
3388
                        end if;
3389
                end if;
3390
 
3391
                if ( now <= 1 ps AND prev_value = 'W' ) then     --hack for autotest to pass
3392
                        prev_value := 'L';
3393
                end if;
3394
 
3395
        else    -- bus_hold is false
3396
                if ( operation_mode = "input") then
3397
                        tmp_combout := padio_ipd;
3398
                        tmp_padio := 'Z';
3399
                elsif (operation_mode = "output" or operation_mode = "bidir" ) then
3400
                        if ( operation_mode  = "bidir") then
3401
                                tmp_combout := padio_ipd;
3402
                        else
3403
                                tmp_combout := 'Z';
3404
                        end if;
3405
 
3406
                        if ( oe_ipd = '1') then
3407
                                if ( open_drain_output = "true" ) then
3408
                                        if (datain_ipd = '0') then
3409
                                                tmp_padio := '0';
3410
                                        elsif (datain_ipd = 'X') then
3411
                                                tmp_padio := 'X';
3412
                                        else
3413
                                                tmp_padio := 'Z';
3414
                                        end if;
3415
                                else
3416
                                        tmp_padio := datain_ipd;
3417
                                end if;
3418
                        elsif ( oe_ipd = '0' ) then
3419
                                tmp_padio := 'Z';
3420
                        else
3421
                                tmp_padio := 'X';
3422
                        end if;
3423
                end if;
3424
        end if; -- end bus_hold
3425
 
3426
                tmp_dqsbusout <= transport tmp_combout after (dqs_delay_int * 1 ps);
3427
 
3428
        if (gated_dqs = "true") then
3429
            dqsbusout_tmp := tmp_dqsbusout AND regin;
3430
        else
3431
            dqsbusout_tmp := tmp_dqsbusout;
3432
        end if;
3433
 
3434
        -- for dqs delay ctrl latches enable
3435
        dqsbusout_tmp_sig <= dqsbusout_tmp;
3436
        combout_tmp_sig <= tmp_combout;
3437
 
3438
    ----------------------
3439
    --  Path Delay Section
3440
    ----------------------
3441
    VitalPathDelay01 (
3442
        OutSignal => combout,
3443
        OutSignalName => "combout",
3444
        OutTemp => tmp_combout,
3445
        Paths => (1 => (padio_ipd'last_event, combout_delay, TRUE)),
3446
        GlitchData => combout_VitalGlitchData,
3447
        Mode => DefGlitchMode,
3448
        XOn  => XOn,
3449
        MsgOn  => MsgOn );
3450
 
3451
    VitalPathDelay01 (
3452
        OutSignal => dqsbusout,
3453
        OutSignalName => "dqsbusout",
3454
        OutTemp => dqsbusout_tmp,
3455
        Paths => (1 => (tmp_dqsbusout'last_event, tpd_padio_dqsbusout, TRUE),
3456
                  2 => (regin'last_event, tpd_regin_dqsbusout, gated_dqs = "true")),
3457
        GlitchData => dqsbusout_VitalGlitchData,
3458
        Mode => DefGlitchMode,
3459
        XOn  => XOn,
3460
        MsgOn  => MsgOn );
3461
 
3462
    VitalPathDelay01 (
3463
        OutSignal => padio,
3464
        OutSignalName => "padio",
3465
        OutTemp => tmp_padio,
3466
        Paths => (1 => (datain_ipd'last_event, tpd_datain_padio, TRUE),
3467
                  2 => (oe_ipd'last_event, tpd_oe_padio_posedge, oe_ipd = '1'),
3468
                  3 => (oe_ipd'last_event, tpd_oe_padio_negedge, oe_ipd = '0')),
3469
        GlitchData => padio_VitalGlitchData,
3470
        Mode => DefGlitchMode,
3471
        XOn  => XOn,
3472
        MsgOn  => MsgOn );
3473
 
3474
    VitalPathDelay01 (
3475
        OutSignal => regout,
3476
        OutSignalName => "regout",
3477
        OutTemp => regin,
3478
        Paths => (1 => (regin'last_event, tpd_regin_regout, TRUE)),
3479
        GlitchData => regout_VitalGlitchData,
3480
        Mode => DefGlitchMode,
3481
        XOn  => XOn,
3482
        MsgOn  => MsgOn );
3483
 
3484
    VitalPathDelay01 (
3485
        OutSignal => ddioregout,
3486
        OutSignalName => "ddioregout",
3487
        OutTemp => ddioregin,
3488
        Paths => (1 => (ddioregin'last_event, tpd_ddioregin_ddioregout, TRUE)),
3489
        GlitchData => ddioregout_VitalGlitchData,
3490
        Mode => DefGlitchMode,
3491
        XOn  => XOn,
3492
        MsgOn  => MsgOn );
3493
 
3494
    end process;
3495
 
3496
end behave;
3497
 
3498
--
3499
-- STRATIXII_IO_REGISTER
3500
--
3501
 
3502
LIBRARY IEEE;
3503
use IEEE.std_logic_1164.all;
3504
use IEEE.VITAL_Timing.all;
3505
use IEEE.VITAL_Primitives.all;
3506
use work.stratixii_atom_pack.all;
3507
 
3508
entity stratixii_io_register is
3509
  generic (
3510
      async_reset : string := "none";
3511
          sync_reset : string := "none";
3512
          power_up : string := "low";
3513
 
3514
          TimingChecksOn: Boolean := True;
3515
      MsgOn: Boolean := DefGlitchMsgOn;
3516
      XOn: Boolean := DefGlitchXOn;
3517
      MsgOnChecks: Boolean := DefMsgOnChecks;
3518
      XOnChecks: Boolean := DefXOnChecks;
3519
      InstancePath: STRING := "*";
3520
 
3521
      tsetup_datain_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
3522
          tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
3523
      tsetup_sreset_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
3524
      thold_datain_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
3525
          thold_ena_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
3526
      thold_sreset_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
3527
      tpd_clk_regout_posedge            : VitalDelayType01 := DefPropDelay01;
3528
      tpd_areset_regout_posedge         : VitalDelayType01 := DefPropDelay01;
3529
 
3530
          tipd_clk                      : VitalDelayType01 := DefPropDelay01;
3531
          tipd_datain                   : VitalDelayType01 := DefPropDelay01;
3532
          tipd_ena              : VitalDelayType01 := DefPropDelay01;
3533
          tipd_areset                   : VitalDelayType01 := DefPropDelay01;
3534
      tipd_sreset                       : VitalDelayType01 := DefPropDelay01);
3535
 
3536
  port (clk :in std_logic := '0';
3537
        datain  : in std_logic := '0';
3538
        ena     : in std_logic := '1';
3539
        sreset : in std_logic := '0';
3540
        areset : in std_logic := '0';
3541
        devclrn   : in std_logic := '1';
3542
        devpor    : in std_logic := '1';
3543
        regout    : out std_logic);
3544
   attribute VITAL_LEVEL0 of stratixii_io_register : entity is TRUE;
3545
end stratixii_io_register;
3546
 
3547
architecture vital_io_reg of stratixii_io_register is
3548
   attribute VITAL_LEVEL0 of vital_io_reg : architecture is TRUE;
3549
   signal datain_ipd, ena_ipd, sreset_ipd : std_logic;
3550
   signal clk_ipd, areset_ipd : std_logic;
3551
begin
3552
   ---------------------
3553
   --  INPUT PATH DELAYs
3554
   ---------------------
3555
   WireDelay : block
3556
   begin
3557
   VitalWireDelay (datain_ipd, datain, tipd_datain);
3558
   VitalWireDelay (clk_ipd, clk, tipd_clk);
3559
   VitalWireDelay (ena_ipd, ena, tipd_ena);
3560
   VitalWireDelay (sreset_ipd, sreset, tipd_sreset);
3561
   VitalWireDelay (areset_ipd, areset, tipd_areset);
3562
   end block;
3563
 
3564
VITALtiming : process(clk_ipd, datain_ipd, ena_ipd, sreset_ipd, areset_ipd, devclrn, devpor)
3565
 
3566
variable Tviol_datain_clk : std_ulogic := '0';
3567
variable Tviol_ena_clk : std_ulogic := '0';
3568
variable Tviol_sreset_clk : std_ulogic := '0';
3569
variable TimingData_datain_clk : VitalTimingDataType := VitalTimingDataInit;
3570
variable TimingData_ena_clk : VitalTimingDataType := VitalTimingDataInit;
3571
variable TimingData_sreset_clk : VitalTimingDataType := VitalTimingDataInit;
3572
variable regout_VitalGlitchData : VitalGlitchDataType;
3573
 
3574
variable iregout : std_logic;
3575
variable idata : std_logic := '0';
3576
variable tmp_regout : std_logic;
3577
variable tmp_reset : std_logic := '0';
3578
 
3579
-- variables for 'X' generation
3580
variable violation : std_logic := '0';
3581
 
3582
begin
3583
 
3584
      if (now = 0 ns) then
3585
         if (power_up = "low") then
3586
            iregout := '0';
3587
         elsif (power_up = "high") then
3588
            iregout := '1';
3589
         end if;
3590
      end if;
3591
 
3592
      if ( async_reset /= "none") then
3593
                tmp_reset := areset_ipd; -- this is used to enable timing check.
3594
          end if;
3595
      ------------------------
3596
      --  Timing Check Section
3597
      ------------------------
3598
      if (TimingChecksOn) then
3599
 
3600
         VitalSetupHoldCheck (
3601
                Violation       => Tviol_datain_clk,
3602
                TimingData      => TimingData_datain_clk,
3603
                TestSignal      => datain_ipd,
3604
                TestSignalName  => "DATAIN",
3605
                RefSignal       => clk_ipd,
3606
                RefSignalName   => "CLK",
3607
                SetupHigh       => tsetup_datain_clk_noedge_posedge,
3608
                SetupLow        => tsetup_datain_clk_noedge_posedge,
3609
                HoldHigh        => thold_datain_clk_noedge_posedge,
3610
                HoldLow         => thold_datain_clk_noedge_posedge,
3611
                CheckEnabled    => TO_X01((tmp_reset) OR (NOT devpor) OR (NOT devclrn) OR (NOT ena_ipd)) /= '1',
3612
                RefTransition   => '/',
3613
                HeaderMsg       => InstancePath & "/LCELL",
3614
                XOn             => XOnChecks,
3615
                MsgOn           => MsgOnChecks );
3616
 
3617
         VitalSetupHoldCheck (
3618
                Violation       => Tviol_ena_clk,
3619
                TimingData      => TimingData_ena_clk,
3620
                TestSignal      => ena_ipd,
3621
                TestSignalName  => "ENA",
3622
                RefSignal       => clk_ipd,
3623
                RefSignalName   => "CLK",
3624
                SetupHigh       => tsetup_ena_clk_noedge_posedge,
3625
                SetupLow        => tsetup_ena_clk_noedge_posedge,
3626
                HoldHigh        => thold_ena_clk_noedge_posedge,
3627
                HoldLow         => thold_ena_clk_noedge_posedge,
3628
                CheckEnabled    => TO_X01((tmp_reset) OR (NOT devpor) OR (NOT devclrn) OR (NOT ena_ipd)) /= '1',
3629
                RefTransition   => '/',
3630
                HeaderMsg       => InstancePath & "/LCELL",
3631
                XOn             => XOnChecks,
3632
                MsgOn           => MsgOnChecks );
3633
 
3634
                VitalSetupHoldCheck (
3635
                Violation       => Tviol_sreset_clk,
3636
                TimingData      => TimingData_sreset_clk,
3637
                TestSignal      => sreset_ipd,
3638
                TestSignalName  => "SRESET",
3639
                RefSignal       => clk_ipd,
3640
                RefSignalName   => "CLK",
3641
                SetupHigh       => tsetup_sreset_clk_noedge_posedge,
3642
                SetupLow        => tsetup_sreset_clk_noedge_posedge,
3643
                HoldHigh        => thold_sreset_clk_noedge_posedge,
3644
                HoldLow         => thold_sreset_clk_noedge_posedge,
3645
                CheckEnabled    => TO_X01((tmp_reset) OR (NOT devpor) OR (NOT devclrn) OR (NOT ena_ipd)) /= '1',
3646
                RefTransition   => '/',
3647
                HeaderMsg       => InstancePath & "/LCELL",
3648
                XOn             => XOnChecks,
3649
                MsgOn           => MsgOnChecks );
3650
      end if;
3651
 
3652
      violation := Tviol_datain_clk or Tviol_ena_clk or Tviol_sreset_clk;
3653
 
3654
        if (devpor = '0') then
3655
                if (power_up = "low") then
3656
                        iregout := '0';
3657
                elsif (power_up = "high") then
3658
                        iregout := '1';
3659
                end if;
3660
        elsif (devclrn = '0') then
3661
                iregout := '0';
3662
        elsif (async_reset = "clear" and areset_ipd = '1') then
3663
                iregout := '0';
3664
        elsif ( async_reset = "preset" and areset_ipd = '1') then
3665
                iregout := '1';
3666
    elsif (violation = 'X') then
3667
                iregout := 'X';
3668
        elsif (ena_ipd = '1' and clk_ipd'event and clk_ipd = '1' and clk_ipd'last_value = '0') then
3669
                if (sync_reset = "clear" and sreset_ipd = '1' ) then
3670
                        iregout := '0';
3671
                elsif (sync_reset = "preset" and sreset_ipd = '1' ) then
3672
                        iregout := '1';
3673
                else
3674
                        iregout := to_x01z(datain_ipd);
3675
                end if;
3676
        end if;
3677
 
3678
      tmp_regout := iregout;
3679
 
3680
      ----------------------
3681
      --  Path Delay Section
3682
      ----------------------
3683
      VitalPathDelay01 (
3684
       OutSignal => regout,
3685
       OutSignalName => "REGOUT",
3686
       OutTemp => tmp_regout,
3687
       Paths => (0 => (areset_ipd'last_event, tpd_areset_regout_posedge, async_reset /= "none"),
3688
                                 1 => (clk_ipd'last_event, tpd_clk_regout_posedge, TRUE)),
3689
       GlitchData => regout_VitalGlitchData,
3690
       Mode => DefGlitchMode,
3691
       XOn  => XOn,
3692
       MsgOn  => MsgOn );
3693
end process;
3694
end vital_io_reg;
3695
 
3696
--
3697
-- STRATIXII_IO
3698
--
3699
LIBRARY IEEE;
3700
use IEEE.std_logic_1164.all;
3701
use IEEE.VITAL_Timing.all;
3702
use IEEE.VITAL_Primitives.all;
3703
use work.stratixii_atom_pack.all;
3704
use work.stratixii_asynch_io;
3705
use work.stratixii_io_register;
3706
use work.stratixii_mux21;
3707
use work.stratixii_and1;
3708
 
3709
entity  stratixii_io is
3710
generic (
3711
         operation_mode : string := "input";
3712
         ddio_mode : string := "none";
3713
         open_drain_output : string := "false";
3714
         bus_hold : string := "false";
3715
         output_register_mode : string := "none";
3716
         output_async_reset : string := "none";
3717
         output_power_up : string := "low";
3718
         output_sync_reset : string := "none";
3719
         tie_off_output_clock_enable : string := "false";
3720
         oe_register_mode : string := "none";
3721
         oe_async_reset : string := "none";
3722
         oe_power_up : string := "low";
3723
         oe_sync_reset : string := "none";
3724
         tie_off_oe_clock_enable : string := "false";
3725
         input_register_mode : string := "none";
3726
         input_async_reset : string := "none";
3727
         input_power_up : string := "low";
3728
         input_sync_reset : string := "none";
3729
         extend_oe_disable : string := "false";
3730
         dqs_input_frequency : string := "10000 ps";
3731
         dqs_out_mode : string := "none";
3732
         dqs_delay_buffer_mode : string := "low";
3733
         dqs_phase_shift : integer := 0;
3734
         inclk_input : string := "normal";
3735
         ddioinclk_input : string := "negated_inclk";
3736
         dqs_offsetctrl_enable : string := "false";
3737
         dqs_ctrl_latches_enable : string := "false";
3738
         dqs_edge_detect_enable : string := "false";
3739
                 gated_dqs : string := "false";
3740
         sim_dqs_intrinsic_delay : integer := 0;
3741
         sim_dqs_delay_increment : integer := 0;
3742
         sim_dqs_offset_increment : integer := 0;
3743
         lpm_type : string := "stratixii_io"
3744
        );
3745
port (
3746
      datain          : in std_logic := '0';
3747
      ddiodatain      : in std_logic := '0';
3748
      oe              : in std_logic := '1';
3749
      outclk          : in std_logic := '0';
3750
      outclkena       : in std_logic := '1';
3751
      inclk           : in std_logic := '0';
3752
      inclkena        : in std_logic := '1';
3753
      areset          : in std_logic := '0';
3754
      sreset          : in std_logic := '0';
3755
      ddioinclk       : in std_logic := '0';
3756
      delayctrlin     : in std_logic_vector(5 downto 0) := "000000";
3757
      offsetctrlin    : in std_logic_vector(5 downto 0) := "000000";
3758
      dqsupdateen     : in std_logic := '0';
3759
      linkin              : in std_logic := '0';
3760
      terminationcontrol : in std_logic_vector(13 downto 0) := "00000000000000";
3761
      devclrn         : in std_logic := '1';
3762
      devpor          : in std_logic := '1';
3763
      devoe           : in std_logic := '0';
3764
      padio           : inout std_logic;
3765
      combout         : out std_logic;
3766
      regout          : out std_logic;
3767
      ddioregout      : out std_logic;
3768
      dqsbusout           : out std_logic;
3769
      linkout             : out std_logic
3770
);
3771
end stratixii_io;
3772
 
3773
architecture structure of stratixii_io is
3774
component stratixii_asynch_io
3775
        generic(
3776
                operation_mode : string := "input";
3777
                open_drain_output : string := "false";
3778
                bus_hold : string := "false";
3779
                dqs_input_frequency      : string := "10000 ps";
3780
                dqs_out_mode             : string := "none";
3781
                dqs_delay_buffer_mode    : string := "low";
3782
                dqs_phase_shift          : integer := 0;
3783
                dqs_offsetctrl_enable    : string := "false";
3784
                dqs_ctrl_latches_enable  : string := "false";
3785
                dqs_edge_detect_enable   : string := "false";
3786
                gated_dqs                : string := "false";
3787
                sim_dqs_intrinsic_delay  : integer := 0;
3788
                sim_dqs_delay_increment  : integer := 0;
3789
                sim_dqs_offset_increment : integer := 0);
3790
        port(
3791
                datain : in  STD_LOGIC := '0';
3792
                oe         : in  STD_LOGIC := '1';
3793
                regin  : in std_logic;
3794
                ddioregin  : in std_logic;
3795
                padio  : inout STD_LOGIC;
3796
                delayctrlin  : in std_logic_vector(5 downto 0);
3797
                offsetctrlin : in std_logic_vector(5 downto 0);
3798
                dqsupdateen  : in std_logic;
3799
                dqsbusout    : out std_logic;
3800
                combout: out STD_LOGIC;
3801
                regout : out STD_LOGIC;
3802
                ddioregout : out STD_LOGIC);
3803
end component;
3804
 
3805
component stratixii_io_register
3806
   generic(async_reset : string := "none";
3807
          sync_reset : string := "none";
3808
          power_up : string := "low";
3809
 
3810
          TimingChecksOn: Boolean := True;
3811
      MsgOn: Boolean := DefGlitchMsgOn;
3812
      XOn: Boolean := DefGlitchXOn;
3813
      MsgOnChecks: Boolean := DefMsgOnChecks;
3814
      XOnChecks: Boolean := DefXOnChecks;
3815
      InstancePath: STRING := "*";
3816
 
3817
      tsetup_datain_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
3818
          tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
3819
      tsetup_sreset_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
3820
      thold_datain_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
3821
          thold_ena_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
3822
      thold_sreset_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
3823
      tpd_clk_regout_posedge            : VitalDelayType01 := DefPropDelay01;
3824
      tpd_areset_regout_posedge         : VitalDelayType01 := DefPropDelay01;
3825
 
3826
          tipd_clk                      : VitalDelayType01 := DefPropDelay01;
3827
          tipd_datain                   : VitalDelayType01 := DefPropDelay01;
3828
          tipd_ena              : VitalDelayType01 := DefPropDelay01;
3829
          tipd_areset                   : VitalDelayType01 := DefPropDelay01;
3830
      tipd_sreset                       : VitalDelayType01 := DefPropDelay01);
3831
   port(clk :in std_logic := '0';
3832
        datain  : in std_logic := '0';
3833
        ena     : in std_logic := '1';
3834
        sreset : in std_logic := '0';
3835
        areset : in std_logic := '0';
3836
        devclrn   : in std_logic := '1';
3837
        devpor    : in std_logic := '1';
3838
        regout    : out std_logic);
3839
end component;
3840
 
3841
component stratixii_mux21
3842
   generic(
3843
      TimingChecksOn: Boolean := True;
3844
      MsgOn: Boolean := DefGlitchMsgOn;
3845
      XOn: Boolean := DefGlitchXOn;
3846
      InstancePath: STRING := "*";
3847
      tpd_A_MO                     :   VitalDelayType01 := DefPropDelay01;
3848
      tpd_B_MO                     :   VitalDelayType01 := DefPropDelay01;
3849
      tpd_S_MO                     :   VitalDelayType01 := DefPropDelay01;
3850
      tipd_A                       :   VitalDelayType01 := DefPropDelay01;
3851
      tipd_B                       :   VitalDelayType01 := DefPropDelay01;
3852
      tipd_S                       :   VitalDelayType01 := DefPropDelay01);
3853
 
3854
     port ( A : in std_logic := '0';
3855
            B : in std_logic := '0';
3856
            S : in std_logic := '0';
3857
            MO : out std_logic);
3858
end component;
3859
 
3860
component stratixii_and1
3861
   generic(
3862
      TimingChecksOn: Boolean := True;
3863
      MsgOn: Boolean := DefGlitchMsgOn;
3864
      XOn: Boolean := DefGlitchXOn;
3865
      InstancePath: STRING := "*";
3866
      tpd_IN1_Y                      :  VitalDelayType01 := DefPropDelay01;
3867
      tipd_IN1                       :  VitalDelayType01 := DefPropDelay01);
3868
 
3869
   port( Y                              :  out   STD_LOGIC;
3870
         IN1                            :  in    STD_LOGIC);
3871
end component;
3872
 
3873
        signal  oe_out : std_logic;
3874
 
3875
        signal  in_reg_out, in_ddio0_reg_out, in_ddio1_reg_out: std_logic;
3876
        signal  oe_reg_out, oe_pulse_reg_out : std_logic;
3877
        signal  out_reg_out, out_ddio_reg_out: std_logic;
3878
 
3879
 
3880
        signal  tmp_datain : std_logic;
3881
        signal  not_inclk, not_outclk : std_logic;
3882
 
3883
        -- for DDIO
3884
        signal ddio_data : std_logic;
3885
        signal outclk_delayed : std_logic;
3886
 
3887
        signal out_clk_ena, oe_clk_ena : std_logic;
3888
 
3889
begin
3890
 
3891
 
3892
not_inclk <= (ddioinclk) WHEN (ddioinclk_input = "dqsb_bus") ELSE (not inclk);
3893
 
3894
not_outclk <= not outclk;
3895
 
3896
out_clk_ena <= '1' WHEN tie_off_output_clock_enable = "true" ELSE outclkena;
3897
oe_clk_ena <= '1' WHEN tie_off_oe_clock_enable = "true" ELSE outclkena;
3898
 
3899
--input register
3900
in_reg : stratixii_io_register
3901
        generic map ( ASYNC_RESET => input_async_reset,
3902
                                  SYNC_RESET => input_sync_reset,
3903
                                  POWER_UP => input_power_up)
3904
        port map ( regout  => in_reg_out,
3905
               clk => inclk,
3906
                           ena => inclkena,
3907
                           datain => padio,
3908
                           areset => areset,
3909
                           sreset => sreset,
3910
                           devpor => devpor,
3911
                           devclrn => devclrn);
3912
 
3913
-- in_ddio0_reg
3914
in_ddio0_reg : stratixii_io_register
3915
        generic map ( ASYNC_RESET => input_async_reset,
3916
                                  SYNC_RESET => input_sync_reset,
3917
                                  POWER_UP => input_power_up)
3918
        port map (regout => in_ddio0_reg_out,
3919
              clk => not_inclk,
3920
                          ena => inclkena,
3921
                          datain => padio,
3922
                          areset => areset,
3923
                          sreset => sreset,
3924
                          devpor => devpor,
3925
                          devclrn => devclrn);
3926
-- in_ddio1_reg
3927
in_ddio1_reg : stratixii_io_register
3928
        generic map ( ASYNC_RESET => input_async_reset,
3929
                                  SYNC_RESET => "none",  -- this register does not have sync_reset
3930
                                  POWER_UP => input_power_up)
3931
        port map (regout  => in_ddio1_reg_out,
3932
              clk => inclk,
3933
                          ena => inclkena,
3934
                          datain => in_ddio0_reg_out,
3935
                          areset => areset,
3936
                          devpor => devpor,
3937
                          devclrn => devclrn);
3938
 
3939
-- out_reg
3940
out_reg : stratixii_io_register
3941
        generic map ( ASYNC_RESET => output_async_reset,
3942
                                  SYNC_RESET => output_sync_reset,
3943
                                  POWER_UP => output_power_up)
3944
        port map (regout  => out_reg_out,
3945
              clk => outclk,
3946
                          ena => out_clk_ena,
3947
                          datain => datain,
3948
                          areset => areset,
3949
                          sreset => sreset,
3950
                          devpor => devpor,
3951
                          devclrn => devclrn);
3952
 
3953
-- out ddio reg
3954
out_ddio_reg : stratixii_io_register
3955
        generic map ( ASYNC_RESET => output_async_reset,
3956
                                  SYNC_RESET => output_sync_reset,
3957
                                  POWER_UP => output_power_up)
3958
        port map (regout  => out_ddio_reg_out,
3959
              clk => outclk,
3960
                          ena => out_clk_ena,
3961
                          datain => ddiodatain,
3962
                          areset => areset,
3963
                          sreset => sreset,
3964
                          devpor => devpor,
3965
                          devclrn => devclrn);
3966
 
3967
-- oe reg
3968
oe_reg : stratixii_io_register
3969
        generic map (ASYNC_RESET => oe_async_reset,
3970
                                 SYNC_RESET => oe_sync_reset,
3971
                                 POWER_UP => oe_power_up)
3972
        port map (regout  => oe_reg_out,
3973
              clk => outclk,
3974
                          ena => oe_clk_ena,
3975
                          datain => oe,
3976
                          areset => areset,
3977
                          sreset => sreset,
3978
                          devpor => devpor,
3979
                          devclrn => devclrn);
3980
 
3981
-- oe_pulse reg
3982
oe_pulse_reg : stratixii_io_register
3983
        generic map (ASYNC_RESET => oe_async_reset,
3984
                                 SYNC_RESET => oe_sync_reset,
3985
                                 POWER_UP => oe_power_up)
3986
        port map (regout  => oe_pulse_reg_out,
3987
              clk => not_outclk,
3988
                          ena => oe_clk_ena,
3989
                          datain => oe_reg_out,
3990
                          areset => areset,
3991
                          sreset => sreset,
3992
                          devpor => devpor,
3993
                          devclrn => devclrn);
3994
 
3995
 
3996
oe_out <= (oe_pulse_reg_out and oe_reg_out) WHEN (extend_oe_disable = "true") ELSE oe_reg_out WHEN (oe_register_mode = "register") ELSE oe;
3997
 
3998
sel_delaybuf  : stratixii_and1
3999
           port map (Y => outclk_delayed,
4000
                     IN1 => outclk);
4001
 
4002
ddio_data_mux : stratixii_mux21
4003
           port map (MO => ddio_data,
4004
                     A => out_ddio_reg_out,
4005
                     B => out_reg_out,
4006
                     S => outclk_delayed);
4007
 
4008
tmp_datain <= ddio_data WHEN (ddio_mode = "output" or ddio_mode = "bidir") ELSE
4009
              out_reg_out WHEN (output_register_mode = "register") ELSE
4010
              datain;
4011
 
4012
 
4013
-- timing info in case output and/or input are not registered.
4014
inst1 : stratixii_asynch_io
4015
        generic map ( OPERATION_MODE => operation_mode,
4016
                      OPEN_DRAIN_OUTPUT => open_drain_output,
4017
                      BUS_HOLD => bus_hold,
4018
                      dqs_input_frequency => dqs_input_frequency,
4019
                      dqs_out_mode => dqs_out_mode,
4020
                      dqs_delay_buffer_mode => dqs_delay_buffer_mode,
4021
                      dqs_phase_shift => dqs_phase_shift,
4022
                      dqs_offsetctrl_enable => dqs_offsetctrl_enable,
4023
                      dqs_ctrl_latches_enable => dqs_ctrl_latches_enable,
4024
                      dqs_edge_detect_enable => dqs_edge_detect_enable,
4025
                      gated_dqs => gated_dqs,
4026
                      sim_dqs_intrinsic_delay => sim_dqs_intrinsic_delay,
4027
                      sim_dqs_delay_increment => sim_dqs_delay_increment,
4028
                      sim_dqs_offset_increment => sim_dqs_offset_increment)
4029
        port map( datain => tmp_datain,
4030
                  oe => oe_out,
4031
                  regin => in_reg_out,
4032
                  ddioregin => in_ddio1_reg_out,
4033
                  padio => padio,
4034
                  delayctrlin  => delayctrlin,
4035
                  offsetctrlin => offsetctrlin,
4036
                  dqsupdateen  => dqsupdateen,
4037
                  dqsbusout    => dqsbusout,
4038
                  combout => combout,
4039
                  regout => regout,
4040
                  ddioregout => ddioregout);
4041
 
4042
 
4043
end structure;
4044
--///////////////////////////////////////////////////////////////////////////
4045
--
4046
-- Entity Name : stratixii_mn_cntr
4047
--
4048
-- Description : Timing simulation model for the M and N counter. This is a
4049
--               common model for the input counter and the loop feedback
4050
--               counter of the StratixII PLL.
4051
--
4052
--///////////////////////////////////////////////////////////////////////////
4053
 
4054
LIBRARY IEEE;
4055
USE IEEE.std_logic_1164.all;
4056
USE IEEE.VITAL_Timing.all;
4057
USE IEEE.VITAL_Primitives.all;
4058
 
4059
ENTITY stratixii_mn_cntr is
4060
    PORT(  clk           : IN std_logic;
4061
            reset         : IN std_logic := '0';
4062
            cout          : OUT std_logic;
4063
            initial_value : IN integer := 1;
4064
            modulus       : IN integer := 1;
4065
            time_delay    : IN integer := 0
4066
        );
4067
END stratixii_mn_cntr;
4068
 
4069
ARCHITECTURE behave of stratixii_mn_cntr is
4070
begin
4071
 
4072
    process (clk, reset)
4073
    variable count : integer := 1;
4074
    variable first_rising_edge : boolean := true;
4075
    variable tmp_cout : std_logic;
4076
    begin
4077
        if (reset = '1') then
4078
            count := 1;
4079
            tmp_cout := '0';
4080
            first_rising_edge := true;
4081
        elsif (clk'event and clk = '1' and first_rising_edge) then
4082
            first_rising_edge := false;
4083
            tmp_cout := clk;
4084
        elsif (not first_rising_edge) then
4085
            if (count < modulus) then
4086
                count := count + 1;
4087
            else
4088
                count := 1;
4089
                tmp_cout := not tmp_cout;
4090
            end if;
4091
        end if;
4092
        cout <= transport tmp_cout after time_delay * 1 ps;
4093
    end process;
4094
end behave;
4095
 
4096
--/////////////////////////////////////////////////////////////////////////////
4097
--
4098
-- Entity Name : stratixii_scale_cntr
4099
--
4100
-- Description : Timing simulation model for the output scale-down counters.
4101
--               This is a common model for the C0, C1, C2, C3, C4 and C5
4102
--               output counters of the StratixII PLL.
4103
--
4104
--/////////////////////////////////////////////////////////////////////////////
4105
 
4106
LIBRARY IEEE;
4107
USE IEEE.std_logic_1164.all;
4108
USE IEEE.VITAL_Timing.all;
4109
USE IEEE.VITAL_Primitives.all;
4110
 
4111
ENTITY stratixii_scale_cntr is
4112
    PORT(   clk            : IN std_logic;
4113
            reset          : IN std_logic := '0';
4114
            initial        : IN integer := 1;
4115
            high           : IN integer := 1;
4116
            low            : IN integer := 1;
4117
            mode           : IN string := "bypass";
4118
            ph_tap         : IN integer := 0;
4119
            cout           : OUT std_logic
4120
        );
4121
END stratixii_scale_cntr;
4122
 
4123
ARCHITECTURE behave of stratixii_scale_cntr is
4124
begin
4125
    process (clk, reset)
4126
    variable tmp_cout : std_logic := '0';
4127
    variable count : integer := 1;
4128
    variable output_shift_count : integer := 1;
4129
    variable first_rising_edge : boolean := false;
4130
    begin
4131
        if (reset = '1') then
4132
            count := 1;
4133
            output_shift_count := 1;
4134
            tmp_cout := '0';
4135
            first_rising_edge := false;
4136
        elsif (clk'event) then
4137
            if (mode = "   off") then
4138
                tmp_cout := '0';
4139
            elsif (mode = "bypass") then
4140
                tmp_cout := clk;
4141
                first_rising_edge := true;
4142
            elsif (not first_rising_edge) then
4143
                if (clk = '1') then
4144
                    if (output_shift_count = initial) then
4145
                        tmp_cout := clk;
4146
                        first_rising_edge := true;
4147
                    else
4148
                        output_shift_count := output_shift_count + 1;
4149
                    end if;
4150
                end if;
4151
            elsif (output_shift_count < initial) then
4152
                if (clk = '1') then
4153
                    output_shift_count := output_shift_count + 1;
4154
                end if;
4155
            else
4156
                count := count + 1;
4157
                if (mode = "  even" and (count = (high*2) + 1)) then
4158
                    tmp_cout := '0';
4159
                elsif (mode = "   odd" and (count = high*2)) then
4160
                    tmp_cout := '0';
4161
                elsif (count = (high + low)*2 + 1) then
4162
                    tmp_cout := '1';
4163
                    count := 1;  -- reset count
4164
                end if;
4165
            end if;
4166
        end if;
4167
        cout <= transport tmp_cout;
4168
    end process;
4169
 
4170
end behave;
4171
 
4172
--/////////////////////////////////////////////////////////////////////////////
4173
--
4174
-- Entity Name : stratixii_pll_reg
4175
--
4176
-- Description : Simulation model for a simple DFF.
4177
--               This is required for the generation of the bit slip-signals.
4178
--               No timing, powers upto 0.
4179
--
4180
--/////////////////////////////////////////////////////////////////////////////
4181
LIBRARY IEEE;
4182
USE IEEE.std_logic_1164.all;
4183
 
4184
ENTITY stratixii_pll_reg is
4185
    PORT(   clk : in std_logic;
4186
            ena : in std_logic := '1';
4187
            d : in std_logic;
4188
            clrn : in std_logic := '1';
4189
            prn : in std_logic := '1';
4190
            q : out std_logic
4191
        );
4192
end stratixii_pll_reg;
4193
 
4194
ARCHITECTURE behave of stratixii_pll_reg is
4195
begin
4196
    process (clk, prn, clrn)
4197
    variable q_reg : std_logic := '0';
4198
    begin
4199
        if (prn = '0') then
4200
            q_reg := '1';
4201
        elsif (clrn = '0') then
4202
            q_reg := '0';
4203
        elsif (clk'event and clk = '1' and (ena = '1')) then
4204
            q_reg := D;
4205
        end if;
4206
 
4207
        Q <= q_reg;
4208
    end process;
4209
end behave;
4210
--///////////////////////////////////////////////////////////////////////////
4211
--
4212
-- Entity Name : stratixii_pll
4213
--
4214
-- Description : Timing simulation model for the StratixII PLL.
4215
--               In the functional mode, it is also the model for the altpll
4216
--               megafunction.
4217
--
4218
-- Limitations : Does not support Spread Spectrum and Bandwidth.
4219
--
4220
-- Outputs     : Up to 6 output clocks, each defined by its own set of
4221
--               parameters. Locked output (active high) indicates when the
4222
--               PLL locks. clkbad, clkloss and activeclock are used for
4223
--               clock switchover to indicate which input clock has gone
4224
--               bad, when the clock switchover initiates and which input
4225
--               clock is being used as the reference, respectively.
4226
--               scandataout is the data output of the serial scan chain.
4227
--
4228
--///////////////////////////////////////////////////////////////////////////
4229
LIBRARY IEEE, std;
4230
USE IEEE.std_logic_1164.all;
4231
USE IEEE.VITAL_Timing.all;
4232
USE IEEE.VITAL_Primitives.all;
4233
USE STD.TEXTIO.all;
4234
USE work.stratixii_atom_pack.all;
4235
USE work.stratixii_pllpack.all;
4236
USE work.stratixii_mn_cntr;
4237
USE work.stratixii_scale_cntr;
4238
USE work.stratixii_dffe;
4239
USE work.stratixii_pll_reg;
4240
 
4241
ENTITY stratixii_pll is
4242
    GENERIC (
4243
        operation_mode              : string := "normal";
4244
        pll_type                    : string := "auto";  -- EGPP/FAST/AUTO
4245
        compensate_clock            : string := "clk0";
4246
        feedback_source             : string := "clk0";
4247
        qualify_conf_done           : string := "off";
4248
 
4249
        test_input_comp_delay       : integer := 0;
4250
        test_feedback_comp_delay    : integer := 0;
4251
 
4252
        inclk0_input_frequency      : integer := 10000;
4253
        inclk1_input_frequency      : integer := 10000;
4254
 
4255
        gate_lock_signal            : string := "no";
4256
        gate_lock_counter           : integer := 1;
4257
        self_reset_on_gated_loss_lock : string := "off";
4258
        valid_lock_multiplier       : integer := 1;
4259
        invalid_lock_multiplier     : integer := 5;
4260
 
4261
        switch_over_type            : string := "auto";
4262
        switch_over_on_lossclk      : string := "off";
4263
        switch_over_on_gated_lock   : string := "off";
4264
        switch_over_counter         : integer := 1;
4265
        enable_switch_over_counter  : string := "on";
4266
 
4267
        bandwidth                   : integer := 0;
4268
        bandwidth_type              : string := "auto";
4269
        down_spread                 : string := "0.0";
4270
        spread_frequency            : integer := 0;
4271
 
4272
        clk0_output_frequency       : integer := 0;
4273
        clk0_multiply_by            : integer := 1;
4274
        clk0_divide_by              : integer := 1;
4275
        clk0_phase_shift            : string := "0";
4276
        clk0_duty_cycle             : integer := 50;
4277
 
4278
        clk1_output_frequency       : integer := 0;
4279
        clk1_multiply_by            : integer := 1;
4280
        clk1_divide_by              : integer := 1;
4281
        clk1_phase_shift            : string := "0";
4282
        clk1_duty_cycle             : integer := 50;
4283
 
4284
        clk2_output_frequency       : integer := 0;
4285
        clk2_multiply_by            : integer := 1;
4286
        clk2_divide_by              : integer := 1;
4287
        clk2_phase_shift            : string := "0";
4288
        clk2_duty_cycle             : integer := 50;
4289
 
4290
        clk3_output_frequency       : integer := 0;
4291
        clk3_multiply_by            : integer := 1;
4292
        clk3_divide_by              : integer := 1;
4293
        clk3_phase_shift            : string := "0";
4294
        clk3_duty_cycle             : integer := 50;
4295
 
4296
        clk4_output_frequency       : integer := 0;
4297
        clk4_multiply_by            : integer := 1;
4298
        clk4_divide_by              : integer := 1;
4299
        clk4_phase_shift            : string := "0";
4300
        clk4_duty_cycle             : integer := 50;
4301
 
4302
        clk5_output_frequency       : integer := 0;
4303
        clk5_multiply_by            : integer := 1;
4304
        clk5_divide_by              : integer := 1;
4305
        clk5_phase_shift            : string := "0";
4306
        clk5_duty_cycle             : integer := 50;
4307
 
4308
        pfd_min                     : integer := 0;
4309
        pfd_max                     : integer := 0;
4310
        vco_min                     : integer := 0;
4311
        vco_max                     : integer := 0;
4312
        vco_center                  : integer := 0;
4313
 
4314
        -- ADVANCED USER PARAMETERS
4315
        m_initial                   : integer := 1;
4316
        m                           : integer := 1;
4317
        n                           : integer := 1;
4318
        m2                          : integer := 1;
4319
        n2                          : integer := 1;
4320
        ss                          : integer := 0;
4321
 
4322
        c0_high                     : integer := 1;
4323
        c0_low                      : integer := 1;
4324
        c0_initial                  : integer := 1;
4325
        c0_mode                     : string := "bypass";
4326
        c0_ph                       : integer := 0;
4327
 
4328
        c1_high                     : integer := 1;
4329
        c1_low                      : integer := 1;
4330
        c1_initial                  : integer := 1;
4331
        c1_mode                     : string := "bypass";
4332
        c1_ph                       : integer := 0;
4333
 
4334
        c2_high                     : integer := 1;
4335
        c2_low                      : integer := 1;
4336
        c2_initial                  : integer := 1;
4337
        c2_mode                     : string := "bypass";
4338
        c2_ph                       : integer := 0;
4339
 
4340
        c3_high                     : integer := 1;
4341
        c3_low                      : integer := 1;
4342
        c3_initial                  : integer := 1;
4343
        c3_mode                     : string := "bypass";
4344
        c3_ph                       : integer := 0;
4345
 
4346
        c4_high                     : integer := 1;
4347
        c4_low                      : integer := 1;
4348
        c4_initial                  : integer := 1;
4349
        c4_mode                     : string := "bypass";
4350
        c4_ph                       : integer := 0;
4351
 
4352
        c5_high                     : integer := 1;
4353
        c5_low                      : integer := 1;
4354
        c5_initial                  : integer := 1;
4355
        c5_mode                     : string := "bypass";
4356
        c5_ph                       : integer := 0;
4357
 
4358
        m_ph                        : integer := 0;
4359
 
4360
        clk0_counter                : string := "c0";
4361
        clk1_counter                : string := "c1";
4362
        clk2_counter                : string := "c2";
4363
        clk3_counter                : string := "c3";
4364
        clk4_counter                : string := "c4";
4365
        clk5_counter                : string := "c5";
4366
 
4367
        c1_use_casc_in              : string := "off";
4368
        c2_use_casc_in              : string := "off";
4369
        c3_use_casc_in              : string := "off";
4370
        c4_use_casc_in              : string := "off";
4371
        c5_use_casc_in              : string := "off";
4372
 
4373
        m_test_source               : integer := 5;
4374
        c0_test_source              : integer := 5;
4375
        c1_test_source              : integer := 5;
4376
        c2_test_source              : integer := 5;
4377
        c3_test_source              : integer := 5;
4378
        c4_test_source              : integer := 5;
4379
        c5_test_source              : integer := 5;
4380
 
4381
        -- LVDS mode parameters
4382
        enable0_counter             : string := "c0";
4383
        enable1_counter             : string := "c1";
4384
        sclkout0_phase_shift        : string := "0";
4385
        sclkout1_phase_shift        : string := "0";
4386
 
4387
        charge_pump_current         : integer := 0;
4388
        loop_filter_r               : string := " 1.000000";
4389
        loop_filter_c               : integer := 1;
4390
        common_rx_tx                : string := "off";
4391
        rx_outclock_resource        : string := "auto";
4392
        use_vco_bypass              : string := "false";
4393
        use_dc_coupling             : string := "false";
4394
 
4395
        pll_compensation_delay      : integer := 0;
4396
        simulation_type             : string := "functional";
4397
        lpm_type                    : string := "stratixii_pll";
4398
 
4399
        clk0_use_even_counter_mode  : string := "off";
4400
        clk1_use_even_counter_mode  : string := "off";
4401
        clk2_use_even_counter_mode  : string := "off";
4402
        clk3_use_even_counter_mode  : string := "off";
4403
        clk4_use_even_counter_mode  : string := "off";
4404
        clk5_use_even_counter_mode  : string := "off";
4405
 
4406
        clk0_use_even_counter_value : string := "off";
4407
        clk1_use_even_counter_value : string := "off";
4408
        clk2_use_even_counter_value : string := "off";
4409
        clk3_use_even_counter_value : string := "off";
4410
        clk4_use_even_counter_value : string := "off";
4411
        clk5_use_even_counter_value : string := "off";
4412
 
4413
        vco_multiply_by             : integer := 0;
4414
        vco_divide_by               : integer := 0;
4415
        vco_post_scale              : integer := 1;
4416
 
4417
        -- VITAL generics
4418
        XOn                         : Boolean := DefGlitchXOn;
4419
        MsgOn                       : Boolean := DefGlitchMsgOn;
4420
        MsgOnChecks                 : Boolean := DefMsgOnChecks;
4421
        XOnChecks                   : Boolean := DefXOnChecks;
4422
        TimingChecksOn              : Boolean := true;
4423
        InstancePath                : STRING := "*";
4424
        tipd_inclk                  : VitalDelayArrayType01(1 downto 0) := (OTHERS => DefPropDelay01);
4425
        tipd_ena                    : VitalDelayType01 := DefPropDelay01;
4426
        tipd_pfdena                 : VitalDelayType01 := DefPropDelay01;
4427
        tipd_areset                 : VitalDelayType01 := DefPropDelay01;
4428
        tipd_fbin                   : VitalDelayType01 := DefPropDelay01;
4429
        tipd_scanclk                : VitalDelayType01 := DefPropDelay01;
4430
        tipd_scanread               : VitalDelayType01 := DefPropDelay01;
4431
        tipd_scandata               : VitalDelayType01 := DefPropDelay01;
4432
        tipd_scanwrite              : VitalDelayType01 := DefPropDelay01;
4433
        tipd_clkswitch              : VitalDelayType01 := DefPropDelay01;
4434
        tsetup_scandata_scanclk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
4435
        thold_scandata_scanclk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
4436
        tsetup_scanread_scanclk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
4437
        thold_scanread_scanclk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
4438
        tsetup_scanwrite_scanclk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
4439
        thold_scanwrite_scanclk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst
4440
    );
4441
 
4442
    PORT
4443
    (
4444
        inclk                       : in std_logic_vector(1 downto 0);
4445
        fbin                        : in std_logic := '0';
4446
        ena                         : in std_logic := '1';
4447
        clkswitch                   : in std_logic := '0';
4448
        areset                      : in std_logic := '0';
4449
        pfdena                      : in std_logic := '1';
4450
        scanread                    : in std_logic := '0';
4451
        scanwrite                   : in std_logic := '0';
4452
        scandata                    : in std_logic := '0';
4453
        scanclk                     : in std_logic := '0';
4454
        testin                      : in std_logic_vector(3 downto 0) := "0000";
4455
        clk                         : out std_logic_vector(5 downto 0);
4456
        clkbad                      : out std_logic_vector(1 downto 0);
4457
        activeclock                 : out std_logic;
4458
        locked                      : out std_logic;
4459
        clkloss                     : out std_logic;
4460
        scandataout                 : out std_logic;
4461
        scandone                    : out std_logic;
4462
        testupout                   : out std_logic;
4463
        testdownout                 : out std_logic;
4464
        -- lvds specific ports
4465
        enable0                     : out std_logic;
4466
        enable1                     : out std_logic;
4467
        sclkout                     : out std_logic_vector(1 downto 0)
4468
    );
4469
END stratixii_pll;
4470
 
4471
ARCHITECTURE vital_pll of stratixii_pll is
4472
 
4473
TYPE int_array is ARRAY(NATURAL RANGE <>) of integer;
4474
TYPE str_array is ARRAY(NATURAL RANGE <>) of string(1 to 6);
4475
TYPE str_array1 is ARRAY(NATURAL RANGE <>) of string(1 to 9);
4476
TYPE std_logic_array is ARRAY(NATURAL RANGE <>) of std_logic;
4477
 
4478
-- internal advanced parameter signals
4479
signal   i_vco_min      : integer;
4480
signal   i_vco_max      : integer;
4481
signal   i_vco_center   : integer;
4482
signal   i_pfd_min      : integer;
4483
signal   i_pfd_max      : integer;
4484
signal   c_ph_val       : int_array(0 to 5) := (OTHERS => 0);
4485
signal   c_high_val     : int_array(0 to 5) := (OTHERS => 1);
4486
signal   c_low_val      : int_array(0 to 5) := (OTHERS => 1);
4487
signal   c_initial_val  : int_array(0 to 5) := (OTHERS => 1);
4488
signal   c_mode_val     : str_array(0 to 5);
4489
 
4490
-- old values
4491
signal   c_high_val_old : int_array(0 to 5) := (OTHERS => 1);
4492
signal   c_low_val_old  : int_array(0 to 5) := (OTHERS => 1);
4493
signal   c_ph_val_old   : int_array(0 to 5) := (OTHERS => 0);
4494
signal   c_mode_val_old : str_array(0 to 5);
4495
 
4496
-- hold registers
4497
signal   c_high_val_hold : int_array(0 to 5) := (OTHERS => 1);
4498
signal   c_low_val_hold  : int_array(0 to 5) := (OTHERS => 1);
4499
signal   c_ph_val_hold   : int_array(0 to 5) := (OTHERS => 0);
4500
signal   c_mode_val_hold : str_array(0 to 5);
4501
 
4502
-- temp registers
4503
signal   sig_c_ph_val_tmp   : int_array(0 to 5) := (OTHERS => 0);
4504
signal   sig_c_low_val_tmp  : int_array(0 to 5) := (OTHERS => 1);
4505
signal   c_ph_val_orig  : int_array(0 to 5) := (OTHERS => 0);
4506
 
4507
--signal   i_clk5_counter         : string(1 to 2) := "c5";
4508
--signal   i_clk4_counter         : string(1 to 2) := "c4";
4509
--signal   i_clk3_counter         : string(1 to 2) := "c3";
4510
--signal   i_clk2_counter         : string(1 to 2) := "c2";
4511
--signal   i_clk1_counter         : string(1 to 2) := "c1";
4512
--signal   i_clk0_counter         : string(1 to 2) := "c0";
4513
 
4514
signal   i_clk5_counter         : integer := 5;
4515
signal   i_clk4_counter         : integer := 4;
4516
signal   i_clk3_counter         : integer := 3;
4517
signal   i_clk2_counter         : integer := 2;
4518
signal   i_clk1_counter         : integer := 1;
4519
signal   i_clk0_counter         : integer := 0;
4520
signal   i_charge_pump_current  : integer;
4521
signal   i_loop_filter_r        : integer;
4522
 
4523
-- end internal advanced parameter signals
4524
 
4525
-- CONSTANTS
4526
CONSTANT GPP_SCAN_CHAIN : integer := 174;
4527
CONSTANT FAST_SCAN_CHAIN : integer := 75;
4528
CONSTANT cntrs : str_array(5 downto 0) := ("    C5", "    C4", "    C3", "    C2", "    C1", "    C0");
4529
CONSTANT ss_cntrs : str_array(0 to 3) := ("     M", "    M2", "     N", "    N2");
4530
 
4531
CONSTANT loop_filter_c_arr : int_array(0 to 3) := (57, 16, 36, 5);
4532
CONSTANT fpll_loop_filter_c_arr : int_array(0 to 3) := (18, 13, 8, 2);
4533
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);
4534
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");
4535
 
4536
-- signals
4537
 
4538
signal vcc : std_logic := '1';
4539
 
4540
signal fbclk       : std_logic;
4541
signal refclk      : std_logic;
4542
 
4543
--signal c0_clk : std_logic;
4544
--signal c1_clk : std_logic;
4545
--signal c2_clk : std_logic;
4546
--signal c3_clk : std_logic;
4547
--signal c4_clk : std_logic;
4548
--signal c5_clk : std_logic;
4549
 
4550
signal c_clk : std_logic_array(0 to 5);
4551
signal vco_out : std_logic_vector(7 downto 0) := (OTHERS => '0');
4552
 
4553
-- signals to assign values to counter params
4554
signal m_val : int_array(0 to 1) := (OTHERS => 1);
4555
signal n_val : int_array(0 to 1) := (OTHERS => 1);
4556
signal m_ph_val : integer := 0;
4557
signal m_initial_val : integer := m_initial;
4558
 
4559
signal m_mode_val : str_array(0 to 1) := (OTHERS => "      ");
4560
signal n_mode_val : str_array(0 to 1) := (OTHERS => "      ");
4561
signal lfc_val : integer := 0;
4562
signal cp_curr_val : integer := 0;
4563
signal lfr_val : string(1 to 9) := "         ";
4564
 
4565
-- old values
4566
signal m_val_old : int_array(0 to 1) := (OTHERS => 1);
4567
signal n_val_old : int_array(0 to 1) := (OTHERS => 1);
4568
signal m_mode_val_old : str_array(0 to 1) := (OTHERS => "      ");
4569
signal n_mode_val_old : str_array(0 to 1) := (OTHERS => "      ");
4570
signal m_ph_val_old : integer := 0;
4571
signal lfc_old : integer := 0;
4572
signal cp_curr_old : integer := 0;
4573
signal lfr_old : string(1 to 9) := "         ";
4574
signal num_output_cntrs : integer := 6;
4575
 
4576
signal scan_data : std_logic_vector(173 downto 0) := (OTHERS => '0');
4577
 
4578
signal clk0_tmp : std_logic;
4579
signal clk1_tmp : std_logic;
4580
signal clk2_tmp : std_logic;
4581
signal clk3_tmp : std_logic;
4582
signal clk4_tmp : std_logic;
4583
signal clk5_tmp : std_logic;
4584
signal sclkout0_tmp : std_logic;
4585
signal sclkout1_tmp : std_logic;
4586
 
4587
signal clkin : std_logic := '0';
4588
signal gate_locked : std_logic := '0';
4589
signal lock : std_logic := '0';
4590
signal about_to_lock : boolean := false;
4591
signal reconfig_err : boolean := false;
4592
 
4593
signal inclk_c0 : std_logic;
4594
signal inclk_c1 : std_logic;
4595
signal inclk_c2 : std_logic;
4596
signal inclk_c3 : std_logic;
4597
signal inclk_c4 : std_logic;
4598
signal inclk_c5 : std_logic;
4599
signal inclk_m : std_logic;
4600
signal devpor : std_logic;
4601
signal devclrn : std_logic;
4602
 
4603
signal inclk0_ipd : std_logic;
4604
signal inclk1_ipd : std_logic;
4605
signal ena_ipd : std_logic;
4606
signal pfdena_ipd : std_logic;
4607
signal areset_ipd : std_logic;
4608
signal fbin_ipd : std_logic;
4609
signal scanclk_ipd : std_logic;
4610
signal scanread_ipd : std_logic;
4611
signal scanwrite_ipd : std_logic;
4612
signal scandata_ipd : std_logic;
4613
signal clkswitch_ipd : std_logic;
4614
-- registered signals
4615
signal scanread_reg : std_logic := '0';
4616
signal scanwrite_reg : std_logic := '0';
4617
signal scanwrite_enabled : std_logic := '0';
4618
signal gated_scanclk : std_logic := '1';
4619
 
4620
signal inclk_c0_dly1 : std_logic := '0';
4621
signal inclk_c0_dly2 : std_logic := '0';
4622
signal inclk_c0_dly3 : std_logic := '0';
4623
signal inclk_c0_dly4 : std_logic := '0';
4624
signal inclk_c0_dly5 : std_logic := '0';
4625
signal inclk_c0_dly6 : std_logic := '0';
4626
signal inclk_c1_dly1 : std_logic := '0';
4627
signal inclk_c1_dly2 : std_logic := '0';
4628
signal inclk_c1_dly3 : std_logic := '0';
4629
signal inclk_c1_dly4 : std_logic := '0';
4630
signal inclk_c1_dly5 : std_logic := '0';
4631
signal inclk_c1_dly6 : std_logic := '0';
4632
 
4633
 
4634
signal sig_offset : time := 0 ps;
4635
signal sig_refclk_time : time := 0 ps;
4636
signal sig_fbclk_period : time := 0 ps;
4637
signal sig_vco_period_was_phase_adjusted : boolean := false;
4638
signal sig_phase_adjust_was_scheduled : boolean := false;
4639
signal sig_stop_vco : std_logic := '0';
4640
signal sig_m_times_vco_period : time := 0 ps;
4641
signal sig_new_m_times_vco_period : time := 0 ps;
4642
signal sig_got_refclk_posedge : boolean := false;
4643
signal sig_got_fbclk_posedge : boolean := false;
4644
signal sig_got_second_refclk : boolean := false;
4645
 
4646
signal m_delay : integer := 0;
4647
signal n_delay : integer := 0;
4648
 
4649
signal inclk1_tmp : std_logic := '0';
4650
 
4651
signal ext_fbk_cntr_high : integer := 0;
4652
signal ext_fbk_cntr_low : integer := 0;
4653
signal ext_fbk_cntr_ph : integer := 0;
4654
signal ext_fbk_cntr_initial : integer := 1;
4655
signal ext_fbk_cntr     : string(1 to 2) := "c0";
4656
signal ext_fbk_cntr_mode : string(1 to 6) := "bypass";
4657
signal ext_fbk_cntr_index : integer := 0;
4658
 
4659
signal enable0_tmp : std_logic := '0';
4660
signal enable1_tmp : std_logic := '0';
4661
signal reset_low : std_logic := '0';
4662
 
4663
signal scandataout_tmp : std_logic := '0';
4664
signal scandone_tmp : std_logic := '0';
4665
 
4666
signal sig_refclk_period : time := (inclk0_input_frequency * 1 ps) * n;
4667
 
4668
signal schedule_vco : std_logic := '0';
4669
 
4670
signal areset_ena_sig : std_logic := '0';
4671
signal pll_in_test_mode : boolean := false;
4672
 
4673
signal inclk_c_from_vco : std_logic_array(0 to 5);
4674
 
4675
signal inclk_m_from_vco : std_logic;
4676
signal inclk_sclkout0_from_vco : std_logic;
4677
signal inclk_sclkout1_from_vco : std_logic;
4678
 
4679
COMPONENT stratixii_mn_cntr
4680
    PORT (
4681
        clk           : IN std_logic;
4682
        reset         : IN std_logic := '0';
4683
        cout          : OUT std_logic;
4684
        initial_value : IN integer := 1;
4685
        modulus       : IN integer := 1;
4686
        time_delay    : IN integer := 0
4687
    );
4688
END COMPONENT;
4689
 
4690
COMPONENT stratixii_scale_cntr
4691
    PORT (
4692
        clk            : IN std_logic;
4693
        reset          : IN std_logic := '0';
4694
        cout           : OUT std_logic;
4695
        initial        : IN integer := 1;
4696
        high           : IN integer := 1;
4697
        low            : IN integer := 1;
4698
        mode           : IN string := "bypass";
4699
        ph_tap         : IN integer := 0
4700
    );
4701
END COMPONENT;
4702
 
4703
COMPONENT stratixii_dffe
4704
    GENERIC(
4705
      TimingChecksOn: Boolean := true;
4706
      InstancePath: STRING := "*";
4707
      XOn: Boolean := DefGlitchXOn;
4708
      MsgOn: Boolean := DefGlitchMsgOn;
4709
      MsgOnChecks: Boolean := DefMsgOnChecks;
4710
      XOnChecks: Boolean := DefXOnChecks;
4711
      tpd_PRN_Q_negedge              :  VitalDelayType01 := DefPropDelay01;
4712
      tpd_CLRN_Q_negedge             :  VitalDelayType01 := DefPropDelay01;
4713
      tpd_CLK_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
4714
      tpd_ENA_Q_posedge              :  VitalDelayType01 := DefPropDelay01;
4715
      tsetup_D_CLK_noedge_posedge    :  VitalDelayType := DefSetupHoldCnst;
4716
      tsetup_D_CLK_noedge_negedge    :  VitalDelayType := DefSetupHoldCnst;
4717
      tsetup_ENA_CLK_noedge_posedge  :  VitalDelayType := DefSetupHoldCnst;
4718
      thold_D_CLK_noedge_posedge     :  VitalDelayType := DefSetupHoldCnst;
4719
      thold_D_CLK_noedge_negedge     :  VitalDelayType := DefSetupHoldCnst;
4720
      thold_ENA_CLK_noedge_posedge   :  VitalDelayType := DefSetupHoldCnst;
4721
      tipd_D                         :  VitalDelayType01 := DefPropDelay01;
4722
      tipd_CLRN                      :  VitalDelayType01 := DefPropDelay01;
4723
      tipd_PRN                       :  VitalDelayType01 := DefPropDelay01;
4724
      tipd_CLK                       :  VitalDelayType01 := DefPropDelay01;
4725
      tipd_ENA                       :  VitalDelayType01 := DefPropDelay01);
4726
 
4727
    PORT(
4728
        Q                              :  out   STD_LOGIC := '0';
4729
        D                              :  in    STD_LOGIC := '1';
4730
        CLRN                           :  in    STD_LOGIC := '1';
4731
        PRN                            :  in    STD_LOGIC := '1';
4732
        CLK                            :  in    STD_LOGIC := '0';
4733
        ENA                            :  in    STD_LOGIC := '1');
4734
END COMPONENT;
4735
 
4736
COMPONENT stratixii_pll_reg
4737
    PORT(
4738
        Q                              :  out   STD_LOGIC := '0';
4739
        D                              :  in    STD_LOGIC := '1';
4740
        CLRN                           :  in    STD_LOGIC := '1';
4741
        PRN                            :  in    STD_LOGIC := '1';
4742
        CLK                            :  in    STD_LOGIC := '0';
4743
        ENA                            :  in    STD_LOGIC := '1');
4744
END COMPONENT;
4745
 
4746
begin
4747
 
4748
    ----------------------
4749
    --  INPUT PATH DELAYs
4750
    ----------------------
4751
    WireDelay : block
4752
    begin
4753
        VitalWireDelay (inclk0_ipd, inclk(0), tipd_inclk(0));
4754
        VitalWireDelay (inclk1_ipd, inclk(1), tipd_inclk(1));
4755
        VitalWireDelay (areset_ipd, areset, tipd_areset);
4756
        VitalWireDelay (ena_ipd, ena, tipd_ena);
4757
        VitalWireDelay (fbin_ipd, fbin, tipd_fbin);
4758
        VitalWireDelay (pfdena_ipd, pfdena, tipd_pfdena);
4759
        VitalWireDelay (scanclk_ipd, scanclk, tipd_scanclk);
4760
        VitalWireDelay (scanread_ipd, scanread, tipd_scanread);
4761
        VitalWireDelay (scandata_ipd, scandata, tipd_scandata);
4762
        VitalWireDelay (scanwrite_ipd, scanwrite, tipd_scanwrite);
4763
        VitalWireDelay (clkswitch_ipd, clkswitch, tipd_clkswitch);
4764
    end block;
4765
 
4766
    inclk_m <=  clkin when m_test_source = 0 else
4767
                clk0_tmp when operation_mode = "external_feedback" and feedback_source = "clk0" else
4768
                clk1_tmp when operation_mode = "external_feedback" and feedback_source = "clk1" else
4769
                clk2_tmp when operation_mode = "external_feedback" and feedback_source = "clk2" else
4770
                clk3_tmp when operation_mode = "external_feedback" and feedback_source = "clk3" else
4771
                clk4_tmp when operation_mode = "external_feedback" and feedback_source = "clk4" else
4772
                clk5_tmp when operation_mode = "external_feedback" and feedback_source = "clk5" else
4773
                inclk_m_from_vco;
4774
 
4775
 
4776
    ext_fbk_cntr_high <= c_high_val(ext_fbk_cntr_index);
4777
    ext_fbk_cntr_low  <= c_low_val(ext_fbk_cntr_index);
4778
    ext_fbk_cntr_ph   <= c_ph_val(ext_fbk_cntr_index);
4779
    ext_fbk_cntr_initial <= c_initial_val(ext_fbk_cntr_index);
4780
    ext_fbk_cntr_mode <= c_mode_val(ext_fbk_cntr_index);
4781
 
4782
    areset_ena_sig <= areset_ipd or (not ena_ipd) or sig_stop_vco;
4783
 
4784
    pll_in_test_mode <= true when   m_test_source /= 5 or c0_test_source /= 5 or
4785
                                    c1_test_source /= 5 or c2_test_source /= 5 or
4786
                                    c3_test_source /= 5 or c4_test_source /= 5 or
4787
                                    c5_test_source /= 5 else
4788
                        false;
4789
 
4790
 
4791
    m1 : stratixii_mn_cntr
4792
        port map (  clk           => inclk_m,
4793
                    reset         => areset_ena_sig,
4794
                    cout          => fbclk,
4795
                    initial_value => m_initial_val,
4796
                    modulus       => m_val(0),
4797
                    time_delay    => m_delay
4798
                );
4799
 
4800
    -- add delta delay to inclk1 to ensure inclk0 and inclk1 are processed
4801
    -- in different simulation deltas.
4802
    inclk1_tmp <= inclk1_ipd;
4803
 
4804
    process (inclk0_ipd, inclk1_tmp, clkswitch_ipd)
4805
    variable input_value : std_logic := '0';
4806
    variable current_clock : integer := 0;
4807
    variable clk0_count, clk1_count : integer := 0;
4808
    variable clk0_is_bad, clk1_is_bad : std_logic := '0';
4809
    variable primary_clk_is_bad : boolean := false;
4810
    variable current_clk_is_bad : boolean := false;
4811
    variable got_curr_clk_falling_edge_after_clkswitch : boolean := false;
4812
    variable switch_over_count : integer := 0;
4813
    variable active_clock : std_logic := '0';
4814
    variable external_switch : boolean := false;
4815
    begin
4816
        if (now = 0 ps) then
4817
            if (switch_over_type = "manual" and clkswitch_ipd = '1') then
4818
                current_clock := 1;
4819
                active_clock := '1';
4820
            end if;
4821
        end if;
4822
        if (clkswitch_ipd'event and clkswitch_ipd = '1' and switch_over_type = "auto") then
4823
            external_switch := true;
4824
        elsif (switch_over_type = "manual") then
4825
            if (clkswitch_ipd'event and clkswitch_ipd = '1') then
4826
                current_clock := 1;
4827
                active_clock := '1';
4828
                clkin <= transport inclk1_tmp;
4829
            elsif (clkswitch_ipd'event and clkswitch_ipd = '0') then
4830
                current_clock := 0;
4831
                active_clock := '0';
4832
                clkin <= transport inclk0_ipd;
4833
            end if;
4834
        end if;
4835
        -- save the current inclk event value
4836
        if (inclk0_ipd'event) then
4837
            input_value := inclk0_ipd;
4838
        elsif (inclk1_tmp'event) then
4839
            input_value := inclk1_tmp;
4840
        end if;
4841
 
4842
        -- check if either input clk is bad
4843
        if (inclk0_ipd'event and inclk0_ipd = '1') then
4844
            clk0_count := clk0_count + 1;
4845
            clk0_is_bad := '0';
4846
            clk1_count := 0;
4847
            if (clk0_count > 2) then
4848
                -- no event on other clk for 2 cycles
4849
                clk1_is_bad := '1';
4850
                if (current_clock = 1) then
4851
                    current_clk_is_bad := true;
4852
                end if;
4853
            end if;
4854
        end if;
4855
        if (inclk1_tmp'event and inclk1_tmp = '1') then
4856
            clk1_count := clk1_count + 1;
4857
            clk1_is_bad := '0';
4858
            clk0_count := 0;
4859
            if (clk1_count > 2) then
4860
                -- no event on other clk for 2 cycles
4861
                clk0_is_bad := '1';
4862
                if (current_clock = 0) then
4863
                    current_clk_is_bad := true;
4864
                end if;
4865
            end if;
4866
        end if;
4867
 
4868
        -- check if the bad clk is the primary clock
4869
        if (clk0_is_bad = '1') then
4870
            primary_clk_is_bad := true;
4871
        else
4872
            primary_clk_is_bad := false;
4873
        end if;
4874
 
4875
        -- actual switching
4876
        if (inclk0_ipd'event and current_clock = 0) then
4877
            if (external_switch) then
4878
                if (not got_curr_clk_falling_edge_after_clkswitch) then
4879
                    if (inclk0_ipd = '0') then
4880
                        got_curr_clk_falling_edge_after_clkswitch := true;
4881
                    end if;
4882
                    clkin <= transport inclk0_ipd;
4883
                end if;
4884
            else
4885
                clkin <= transport inclk0_ipd;
4886
            end if;
4887
        elsif (inclk1_tmp'event and current_clock = 1) then
4888
            if (external_switch) then
4889
                if (not got_curr_clk_falling_edge_after_clkswitch) then
4890
                    if (inclk1_tmp = '0') then
4891
                        got_curr_clk_falling_edge_after_clkswitch := true;
4892
                    end if;
4893
                    clkin <= transport inclk1_tmp;
4894
                end if;
4895
            else
4896
                clkin <= transport inclk1_tmp;
4897
            end if;
4898
        else
4899
            if (input_value = '1' and switch_over_on_lossclk = "on"  and enable_switch_over_counter = "on" and primary_clk_is_bad) then
4900
                switch_over_count := switch_over_count + 1;
4901
            end if;
4902
            if (input_value = '0') then
4903
                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 (enable_switch_over_counter = "off" or switch_over_count = switch_over_counter)) then
4904
                    got_curr_clk_falling_edge_after_clkswitch := false;
4905
                    if (current_clock = 0) then
4906
                        current_clock := 1;
4907
                    else
4908
                        current_clock := 0;
4909
                    end if;
4910
                    active_clock := not active_clock;
4911
                    switch_over_count := 0;
4912
                    external_switch := false;
4913
                    current_clk_is_bad := false;
4914
                end if;
4915
 
4916
            end if;
4917
        end if;
4918
 
4919
        -- schedule outputs
4920
        clkbad(0) <= clk0_is_bad;
4921
        clkbad(1) <= clk1_is_bad;
4922
        if (switch_over_on_lossclk = "on" and clkswitch_ipd /= '1') then
4923
            if (primary_clk_is_bad) then
4924
                -- assert clkloss
4925
                clkloss <= '1';
4926
            else
4927
                clkloss <= '0';
4928
            end if;
4929
        else
4930
            clkloss <= clkswitch_ipd;
4931
        end if;
4932
        activeclock <= active_clock;
4933
 
4934
    end process;
4935
 
4936
    process (inclk_sclkout0_from_vco)
4937
    begin
4938
        sclkout0_tmp <= inclk_sclkout0_from_vco;
4939
    end process;
4940
 
4941
    process (inclk_sclkout1_from_vco)
4942
    begin
4943
        sclkout1_tmp <= inclk_sclkout1_from_vco;
4944
    end process;
4945
 
4946
    n1 : stratixii_mn_cntr
4947
        port map (
4948
                clk           => clkin,
4949
                reset         => areset_ipd,
4950
                cout          => refclk,
4951
                initial_value => n_val(0),
4952
                modulus       => n_val(0));
4953
 
4954
 
4955
    inclk_c0 <= clkin when c0_test_source = 0 else
4956
                refclk when c0_test_source = 1 else
4957
                inclk_c_from_vco(0);
4958
    c0 : stratixii_scale_cntr
4959
        port map (
4960
                clk            => inclk_c0,
4961
                reset          => areset_ena_sig,
4962
                cout           => c_clk(0),
4963
                initial        => c_initial_val(0),
4964
                high           => c_high_val(0),
4965
                low            => c_low_val(0),
4966
                mode           => c_mode_val(0),
4967
                ph_tap         => c_ph_val(0));
4968
 
4969
 
4970
    inclk_c1 <= clkin when c1_test_source = 0 else
4971
                fbclk when c1_test_source = 2 else
4972
                c_clk(0) when c1_use_casc_in = "on" else
4973
                inclk_c_from_vco(1);
4974
    c1 : stratixii_scale_cntr
4975
        port map (
4976
                clk            => inclk_c1,
4977
                reset          => areset_ena_sig,
4978
                cout           => c_clk(1),
4979
                initial        => c_initial_val(1),
4980
                high           => c_high_val(1),
4981
                low            => c_low_val(1),
4982
                mode           => c_mode_val(1),
4983
                ph_tap         => c_ph_val(1));
4984
 
4985
 
4986
    inclk_c2 <= clkin when c2_test_source = 0 else
4987
                c_clk(1) when c2_use_casc_in = "on" else
4988
                inclk_c_from_vco(2);
4989
    c2 : stratixii_scale_cntr
4990
        port map (
4991
                clk            => inclk_c2,
4992
                reset          => areset_ena_sig,
4993
                cout           => c_clk(2),
4994
                initial        => c_initial_val(2),
4995
                high           => c_high_val(2),
4996
                low            => c_low_val(2),
4997
                mode           => c_mode_val(2),
4998
                ph_tap         => c_ph_val(2));
4999
 
5000
 
5001
    inclk_c3 <= clkin when c3_test_source = 0 else
5002
                c_clk(2) when c3_use_casc_in = "on" else
5003
                inclk_c_from_vco(3);
5004
    c3 : stratixii_scale_cntr
5005
        port map (
5006
                clk            => inclk_c3,
5007
                reset          => areset_ena_sig,
5008
                cout           => c_clk(3),
5009
                initial        => c_initial_val(3),
5010
                high           => c_high_val(3),
5011
                low            => c_low_val(3),
5012
                mode           => c_mode_val(3),
5013
                ph_tap         => c_ph_val(3));
5014
 
5015
    inclk_c4 <= '0' when (pll_type = "fast") else
5016
                clkin when (c4_test_source = 0) else
5017
                c_clk(3) when (c4_use_casc_in = "on") else
5018
                inclk_c_from_vco(4);
5019
    c4 : stratixii_scale_cntr
5020
        port map (
5021
                clk            => inclk_c4,
5022
                reset          => areset_ena_sig,
5023
                cout           => c_clk(4),
5024
                initial        => c_initial_val(4),
5025
                high           => c_high_val(4),
5026
                low            => c_low_val(4),
5027
                mode           => c_mode_val(4),
5028
                ph_tap         => c_ph_val(4));
5029
 
5030
    inclk_c5 <= '0' when (pll_type = "fast") else
5031
                clkin when c5_test_source = 0 else
5032
                c_clk(4) when c5_use_casc_in = "on" else
5033
                inclk_c_from_vco(5);
5034
    c5 : stratixii_scale_cntr
5035
        port map (
5036
                clk            => inclk_c5,
5037
                reset          => areset_ena_sig,
5038
                cout           => c_clk(5),
5039
                initial        => c_initial_val(5),
5040
                high           => c_high_val(5),
5041
                low            => c_low_val(5),
5042
                mode           => c_mode_val(5),
5043
                ph_tap         => c_ph_val(5));
5044
 
5045
    inclk_c0_dly1 <= inclk_c0 when (pll_type = "fast" or pll_type = "lvds")
5046
                    else '0';
5047
    inclk_c0_dly2 <= inclk_c0_dly1;
5048
    inclk_c0_dly3 <= inclk_c0_dly2;
5049
    inclk_c0_dly4 <= inclk_c0_dly3;
5050
    inclk_c0_dly5 <= inclk_c0_dly4;
5051
    inclk_c0_dly6 <= inclk_c0_dly5;
5052
 
5053
    inclk_c1_dly1 <= inclk_c1 when (pll_type = "fast" or pll_type = "lvds")
5054
                    else '0';
5055
    inclk_c1_dly2 <= inclk_c1_dly1;
5056
    inclk_c1_dly3 <= inclk_c1_dly2;
5057
    inclk_c1_dly4 <= inclk_c1_dly3;
5058
    inclk_c1_dly5 <= inclk_c1_dly4;
5059
    inclk_c1_dly6 <= inclk_c1_dly5;
5060
 
5061
    process(inclk_c0_dly6, inclk_c1_dly6, areset_ipd, ena_ipd, sig_stop_vco)
5062
    variable c0_got_first_rising_edge : boolean := false;
5063
    variable c0_count : integer := 2;
5064
    variable c0_initial_count : integer := 1;
5065
    variable c0_tmp, c1_tmp : std_logic := '0';
5066
    variable c1_got_first_rising_edge : boolean := false;
5067
    variable c1_count : integer := 2;
5068
    variable c1_initial_count : integer := 1;
5069
    begin
5070
        if (areset_ipd = '1' or ena_ipd = '0' or sig_stop_vco = '1') then
5071
            c0_count := 2;
5072
            c1_count := 2;
5073
            c0_initial_count := 1;
5074
            c1_initial_count := 1;
5075
            c0_got_first_rising_edge := false;
5076
            c1_got_first_rising_edge := false;
5077
        else
5078
            if (not c0_got_first_rising_edge) then
5079
                if (inclk_c0_dly6'event and inclk_c0_dly6 = '1') then
5080
                    if (c0_initial_count = c_initial_val(0)) then
5081
                        c0_got_first_rising_edge := true;
5082
                    else
5083
                        c0_initial_count := c0_initial_count + 1;
5084
                    end if;
5085
                end if;
5086
            elsif (inclk_c0_dly6'event) then
5087
                c0_count := c0_count + 1;
5088
                if (c0_count = (c_high_val(0) + c_low_val(0)) * 2) then
5089
                    c0_count := 1;
5090
                end if;
5091
            end if;
5092
            if (inclk_c0_dly6'event and inclk_c0_dly6 = '0') then
5093
                if (c0_count = 1) then
5094
                    c0_tmp := '1';
5095
                    c0_got_first_rising_edge := false;
5096
                else
5097
                    c0_tmp := '0';
5098
                end if;
5099
            end if;
5100
 
5101
            if (not c1_got_first_rising_edge) then
5102
                if (inclk_c1_dly6'event and inclk_c1_dly6 = '1') then
5103
                    if (c1_initial_count = c_initial_val(1)) then
5104
                        c1_got_first_rising_edge := true;
5105
                    else
5106
                        c1_initial_count := c1_initial_count + 1;
5107
                    end if;
5108
                end if;
5109
            elsif (inclk_c1_dly6'event) then
5110
                c1_count := c1_count + 1;
5111
                if (c1_count = (c_high_val(1) + c_low_val(1)) * 2) then
5112
                    c1_count := 1;
5113
                end if;
5114
            end if;
5115
            if (inclk_c1_dly6'event and inclk_c1_dly6 = '0') then
5116
                if (c1_count = 1) then
5117
                    c1_tmp := '1';
5118
                    c1_got_first_rising_edge := false;
5119
                else
5120
                    c1_tmp := '0';
5121
                end if;
5122
            end if;
5123
        end if;
5124
 
5125
        if (enable0_counter = "c0") then
5126
            enable0_tmp <= c0_tmp;
5127
        elsif (enable0_counter = "c1") then
5128
            enable0_tmp <= c1_tmp;
5129
        else
5130
            enable0_tmp <= '0';
5131
        end if;
5132
 
5133
        if (enable1_counter = "c0") then
5134
            enable1_tmp <= c0_tmp;
5135
        elsif (enable1_counter = "c1") then
5136
            enable1_tmp <= c1_tmp;
5137
        else
5138
            enable1_tmp <= '0';
5139
        end if;
5140
 
5141
    end process;
5142
 
5143
    glocked_cntr : process(clkin, ena_ipd, areset_ipd)
5144
    variable count : integer := 0;
5145
    variable output : std_logic := '0';
5146
    begin
5147
        if (areset_ipd = '1') then
5148
            count := 0;
5149
            output := '0';
5150
        elsif (clkin'event and clkin = '1') then
5151
            if (ena_ipd = '1') then
5152
                count := count + 1;
5153
                if (count = gate_lock_counter) then
5154
                    output := '1';
5155
                end if;
5156
            end if;
5157
        end if;
5158
        gate_locked <= output;
5159
    end process;
5160
 
5161
    locked <=   gate_locked and lock when gate_lock_signal = "yes" else
5162
                lock;
5163
 
5164
 
5165
    process (scandone_tmp)
5166
    variable buf : line;
5167
    begin
5168
        if (scandone_tmp'event and scandone_tmp = '1') then
5169
            if (reconfig_err = false) then
5170
                ASSERT false REPORT "PLL Reprogramming completed with the following values (Values in parantheses indicate values before reprogramming) :" severity note;
5171
                write (buf, string'("    N modulus = "));
5172
                write (buf, n_val(0));
5173
                write (buf, string'(" ( "));
5174
                write (buf, n_val_old(0));
5175
                write (buf, string'(" )"));
5176
                writeline (output, buf);
5177
 
5178
                write (buf, string'("    M modulus = "));
5179
                write (buf, m_val(0));
5180
                write (buf, string'(" ( "));
5181
                write (buf, m_val_old(0));
5182
                write (buf, string'(" )"));
5183
                writeline (output, buf);
5184
 
5185
                write (buf, string'("    M ph_tap = "));
5186
                write (buf, m_ph_val);
5187
                write (buf, string'(" ( "));
5188
                write (buf, m_ph_val_old);
5189
                write (buf, string'(" )"));
5190
                writeline (output, buf);
5191
 
5192
                if (ss > 0) then
5193
                    write (buf, string'("    M2 modulus = "));
5194
                    write (buf, m_val(1));
5195
                    write (buf, string'(" ( "));
5196
                    write (buf, m_val_old(1));
5197
                    write (buf, string'(" )"));
5198
                    writeline (output, buf);
5199
 
5200
                    write (buf, string'("    N2 modulus = "));
5201
                    write (buf, n_val(1));
5202
                    write (buf, string'(" ( "));
5203
                    write (buf, n_val_old(1));
5204
                    write (buf, string'(" )"));
5205
                    writeline (output, buf);
5206
                end if;
5207
 
5208
                for i in 0 to (num_output_cntrs-1) loop
5209
                    write (buf, cntrs(i));
5210
                    write (buf, string'(" :   high = "));
5211
                    write (buf, c_high_val(i));
5212
                    write (buf, string'(" ("));
5213
                    write (buf, c_high_val_old(i));
5214
                    write (buf, string'(") "));
5215
                    write (buf, string'(" ,   low = "));
5216
                    write (buf, sig_c_low_val_tmp(i));
5217
                    write (buf, string'(" ("));
5218
                    write (buf, c_low_val_old(i));
5219
                    write (buf, string'(") "));
5220
                    write (buf, string'(" ,   mode = "));
5221
                    write (buf, c_mode_val(i));
5222
                    write (buf, string'(" ("));
5223
                    write (buf, c_mode_val_old(i));
5224
                    write (buf, string'(") "));
5225
                    write (buf, string'(" ,   phase tap = "));
5226
                    write (buf, c_ph_val(i));
5227
                    write (buf, string'(" ("));
5228
                    write (buf, c_ph_val_old(i));
5229
                    write (buf, string'(") "));
5230
                    writeline(output, buf);
5231
                end loop;
5232
 
5233
                write (buf, string'("    Charge Pump Current (uA) = "));
5234
                write (buf, cp_curr_val);
5235
                write (buf, string'(" ( "));
5236
                write (buf, cp_curr_old);
5237
                write (buf, string'(" ) "));
5238
                writeline (output, buf);
5239
 
5240
                write (buf, string'("    Loop Filter Capacitor (pF) = "));
5241
                write (buf, lfc_val);
5242
                write (buf, string'(" ( "));
5243
                write (buf, lfc_old);
5244
                write (buf, string'(" ) "));
5245
                writeline (output, buf);
5246
 
5247
                write (buf, string'("    Loop Filter Resistor (Kohm) = "));
5248
                write (buf, lfr_val);
5249
                write (buf, string'(" ( "));
5250
                write (buf, lfr_old);
5251
                write (buf, string'(" ) "));
5252
                writeline (output, buf);
5253
 
5254
            else ASSERT false REPORT "Errors were encountered during PLL reprogramming. Please refer to error/warning messages above." severity warning;
5255
            end if;
5256
        end if;
5257
    end process;
5258
 
5259
    process (scanwrite_enabled, c_clk(0), c_clk(1), c_clk(2), c_clk(3), c_clk(4), c_clk(5), vco_out, fbclk, scanclk_ipd, gated_scanclk)
5260
    variable init : boolean := true;
5261
    variable low, high : std_logic_vector(7 downto 0);
5262
    variable low_fast, high_fast : std_logic_vector(3 downto 0);
5263
    variable mode : string(1 to 6) := "bypass";
5264
    variable is_error : boolean := false;
5265
    variable m_tmp, n_tmp : std_logic_vector(8 downto 0);
5266
    variable n_fast : std_logic_vector(1 downto 0);
5267
    variable c_high_val_tmp : int_array(0 to 5) := (OTHERS => 1);
5268
    variable c_low_val_tmp  : int_array(0 to 5) := (OTHERS => 1);
5269
    variable c_ph_val_tmp   : int_array(0 to 5) := (OTHERS => 0);
5270
    variable c_mode_val_tmp : str_array(0 to 5);
5271
    variable m_ph_val_tmp   : integer := 0;
5272
    variable m_val_tmp      : int_array(0 to 1) := (OTHERS => 1);
5273
    variable c0_rising_edge_transfer_done : boolean := false;
5274
    variable c1_rising_edge_transfer_done : boolean := false;
5275
    variable c2_rising_edge_transfer_done : boolean := false;
5276
    variable c3_rising_edge_transfer_done : boolean := false;
5277
    variable c4_rising_edge_transfer_done : boolean := false;
5278
    variable c5_rising_edge_transfer_done : boolean := false;
5279
 
5280
    -- variables for scaling of multiply_by and divide_by values
5281
    variable i_clk0_mult_by    : integer := 1;
5282
    variable i_clk0_div_by     : integer := 1;
5283
    variable i_clk1_mult_by    : integer := 1;
5284
    variable i_clk1_div_by     : integer := 1;
5285
    variable i_clk2_mult_by    : integer := 1;
5286
    variable i_clk2_div_by     : integer := 1;
5287
    variable i_clk3_mult_by    : integer := 1;
5288
    variable i_clk3_div_by     : integer := 1;
5289
    variable i_clk4_mult_by    : integer := 1;
5290
    variable i_clk4_div_by     : integer := 1;
5291
    variable i_clk5_mult_by    : integer := 1;
5292
    variable i_clk5_div_by     : integer := 1;
5293
    variable max_d_value       : integer := 1;
5294
    variable new_multiplier    : integer := 1;
5295
 
5296
    -- internal variables for storing the phase shift number.(used in lvds mode only)
5297
    variable i_clk0_phase_shift : integer := 1;
5298
    variable i_clk1_phase_shift : integer := 1;
5299
    variable i_clk2_phase_shift : integer := 1;
5300
 
5301
    -- user to advanced variables
5302
 
5303
    variable   max_neg_abs    : integer := 0;
5304
    variable   i_m_initial    : integer;
5305
    variable   i_m            : integer := 1;
5306
    variable   i_n            : integer := 1;
5307
    variable   i_m2           : integer;
5308
    variable   i_n2           : integer;
5309
    variable   i_ss           : integer;
5310
    variable   i_c_high       : int_array(0 to 5);
5311
    variable   i_c_low        : int_array(0 to 5);
5312
    variable   i_c_initial    : int_array(0 to 5);
5313
    variable   i_c_ph         : int_array(0 to 5);
5314
    variable   i_c_mode       : str_array(0 to 5);
5315
    variable   i_m_ph         : integer;
5316
    variable   output_count   : integer;
5317
    variable   new_divisor    : integer;
5318
 
5319
    variable clk0_cntr : string(1 to 2) := "c0";
5320
    variable clk1_cntr : string(1 to 2) := "c1";
5321
    variable clk2_cntr : string(1 to 2) := "c2";
5322
    variable clk3_cntr : string(1 to 2) := "c3";
5323
    variable clk4_cntr : string(1 to 2) := "c4";
5324
    variable clk5_cntr : string(1 to 2) := "c5";
5325
 
5326
    variable fbk_cntr : string(1 to 2);
5327
    variable fbk_cntr_index : integer;
5328
    variable start_bit : integer;
5329
    variable quiet_time : time := 0 ps;
5330
    variable slowest_clk_old : time := 0 ps;
5331
    variable slowest_clk_new : time := 0 ps;
5332
    variable tmp_scan_data : std_logic_vector(173 downto 0) := (OTHERS => '0');
5333
    variable m_lo, m_hi : std_logic_vector(4 downto 0);
5334
 
5335
    variable j : integer := 0;
5336
    variable scanread_active_edge : time := 0 ps;
5337
    variable got_first_scanclk : boolean := false;
5338
    variable got_first_gated_scanclk : boolean := false;
5339
    variable scanclk_last_rising_edge : time := 0 ps;
5340
    variable scanclk_period : time := 0 ps;
5341
    variable current_scan_data : std_logic_vector(173 downto 0) := (OTHERS => '0');
5342
    variable index : integer := 0;
5343
    variable Tviol_scandata_scanclk : std_ulogic := '0';
5344
    variable Tviol_scanread_scanclk : std_ulogic := '0';
5345
    variable Tviol_scanwrite_scanclk : std_ulogic := '0';
5346
    variable TimingData_scandata_scanclk : VitalTimingDataType := VitalTimingDataInit;
5347
    variable TimingData_scanread_scanclk : VitalTimingDataType := VitalTimingDataInit;
5348
    variable TimingData_scanwrite_scanclk : VitalTimingDataType := VitalTimingDataInit;
5349
    variable scan_chain_length : integer := GPP_SCAN_CHAIN;
5350
    variable tmp_rem : integer := 0;
5351
    variable scanclk_cycles : integer := 0;
5352
    variable lfc_tmp : std_logic_vector(1 downto 0);
5353
    variable lfr_tmp : std_logic_vector(5 downto 0);
5354
    variable lfr_int : integer := 0;
5355
 
5356
    function slowest_clk (
5357
            C0 : integer; C0_mode : string(1 to 6);
5358
            C1 : integer; C1_mode : string(1 to 6);
5359
            C2 : integer; C2_mode : string(1 to 6);
5360
            C3 : integer; C3_mode : string(1 to 6);
5361
            C4 : integer; C4_mode : string(1 to 6);
5362
            C5 : integer; C5_mode : string(1 to 6);
5363
            refclk : time; m_mod : integer) return time is
5364
    variable max_modulus : integer := 1;
5365
    variable q_period : time := 0 ps;
5366
    variable refclk_int : integer := 0;
5367
    begin
5368
        if (C0_mode /= "bypass" and C0_mode /= "   off") then
5369
            max_modulus := C0;
5370
        end if;
5371
        if (C1 > max_modulus and C1_mode /= "bypass" and C1_mode /= "   off") then
5372
            max_modulus := C1;
5373
        end if;
5374
        if (C2 > max_modulus and C2_mode /= "bypass" and C2_mode /= "   off") then
5375
            max_modulus := C2;
5376
        end if;
5377
        if (C3 > max_modulus and C3_mode /= "bypass" and C3_mode /= "   off") then
5378
            max_modulus := C3;
5379
        end if;
5380
        if (C4 > max_modulus and C4_mode /= "bypass" and C4_mode /= "   off") then
5381
            max_modulus := C4;
5382
        end if;
5383
        if (C5 > max_modulus and C5_mode /= "bypass" and C5_mode /= "   off") then
5384
            max_modulus := C5;
5385
        end if;
5386
 
5387
        refclk_int := refclk / 1 ps;
5388
        if (m_mod /= 0) then
5389
            q_period := (refclk_int * max_modulus / m_mod) * 1 ps;
5390
        end if;
5391
        return (2*q_period);
5392
    end slowest_clk;
5393
 
5394
    function int2bin (arg : integer; size : integer) return std_logic_vector is
5395
    variable int_val : integer := arg;
5396
    variable result : std_logic_vector(size-1 downto 0);
5397
    begin
5398
        for i in 0 to result'left loop
5399
            if ((int_val mod 2) = 0) then
5400
                result(i) := '0';
5401
            else
5402
                result(i) := '1';
5403
            end if;
5404
            int_val := int_val/2;
5405
        end loop;
5406
        return result;
5407
    end int2bin;
5408
 
5409
    function extract_cntr_index (arg:string) return integer is
5410
    variable index : integer := 0;
5411
    begin
5412
        if (arg(2) = '0') then
5413
            index := 0;
5414
        elsif (arg(2) = '1') then
5415
            index := 1;
5416
        elsif (arg(2) = '2') then
5417
            index := 2;
5418
        elsif (arg(2) = '3') then
5419
            index := 3;
5420
        elsif (arg(2) = '4') then
5421
            index := 4;
5422
        else index := 5;
5423
        end if;
5424
 
5425
        return index;
5426
    end extract_cntr_index;
5427
 
5428
    begin
5429
        if (init) then
5430
            if (m = 0) then
5431
                clk5_cntr  := "c5";
5432
                clk4_cntr  := "c4";
5433
                clk3_cntr  := "c3";
5434
                clk2_cntr  := "c2";
5435
                clk1_cntr  := "c1";
5436
                clk0_cntr  := "c0";
5437
            else
5438
                clk5_cntr  := clk5_counter;
5439
                clk4_cntr  := clk4_counter;
5440
                clk3_cntr  := clk3_counter;
5441
                clk2_cntr  := clk2_counter;
5442
                clk1_cntr  := clk1_counter;
5443
                clk0_cntr  := clk0_counter;
5444
            end if;
5445
 
5446
            if (operation_mode = "external_feedback") then
5447
                if (feedback_source = "clk0") then
5448
                    fbk_cntr := clk0_cntr;
5449
                elsif (feedback_source = "clk1") then
5450
                    fbk_cntr := clk1_cntr;
5451
                elsif (feedback_source = "clk2") then
5452
                    fbk_cntr := clk2_cntr;
5453
                elsif (feedback_source = "clk3") then
5454
                    fbk_cntr := clk3_cntr;
5455
                elsif (feedback_source = "clk4") then
5456
                    fbk_cntr := clk4_cntr;
5457
                elsif (feedback_source = "clk5") then
5458
                    fbk_cntr := clk5_cntr;
5459
                else
5460
                    fbk_cntr := "c0";
5461
                end if;
5462
 
5463
                if (fbk_cntr = "c0") then
5464
                    fbk_cntr_index := 0;
5465
                elsif (fbk_cntr = "c1") then
5466
                    fbk_cntr_index := 1;
5467
                elsif (fbk_cntr = "c2") then
5468
                    fbk_cntr_index := 2;
5469
                elsif (fbk_cntr = "c3") then
5470
                    fbk_cntr_index := 3;
5471
                elsif (fbk_cntr = "c4") then
5472
                    fbk_cntr_index := 4;
5473
                elsif (fbk_cntr = "c5") then
5474
                    fbk_cntr_index := 5;
5475
                end if;
5476
 
5477
                ext_fbk_cntr <= fbk_cntr;
5478
                ext_fbk_cntr_index <= fbk_cntr_index;
5479
            end if;
5480
            i_clk0_counter <= extract_cntr_index(clk0_cntr);
5481
            i_clk1_counter <= extract_cntr_index(clk1_cntr);
5482
            i_clk2_counter <= extract_cntr_index(clk2_cntr);
5483
            i_clk3_counter <= extract_cntr_index(clk3_cntr);
5484
            i_clk4_counter <= extract_cntr_index(clk4_cntr);
5485
            i_clk5_counter <= extract_cntr_index(clk5_cntr);
5486
 
5487
 
5488
            if (m = 0) then  -- convert user parameters to advanced
5489
                -- set the limit of the divide_by value that can be returned by
5490
                -- the following function.
5491
                max_d_value := 500;
5492
 
5493
                -- scale down the multiply_by and divide_by values provided by the design
5494
                -- before attempting to use them in the calculations below
5495
                find_simple_integer_fraction(clk0_multiply_by, clk0_divide_by,
5496
                                max_d_value, i_clk0_mult_by, i_clk0_div_by);
5497
                find_simple_integer_fraction(clk1_multiply_by, clk1_divide_by,
5498
                                max_d_value, i_clk1_mult_by, i_clk1_div_by);
5499
                find_simple_integer_fraction(clk2_multiply_by, clk2_divide_by,
5500
                                max_d_value, i_clk2_mult_by, i_clk2_div_by);
5501
                find_simple_integer_fraction(clk3_multiply_by, clk3_divide_by,
5502
                                max_d_value, i_clk3_mult_by, i_clk3_div_by);
5503
                find_simple_integer_fraction(clk4_multiply_by, clk4_divide_by,
5504
                                max_d_value, i_clk4_mult_by, i_clk4_div_by);
5505
                find_simple_integer_fraction(clk5_multiply_by, clk5_divide_by,
5506
                                max_d_value, i_clk5_mult_by, i_clk5_div_by);
5507
 
5508
                if (((pll_type = "fast") or (pll_type = "lvds")) and ((vco_multiply_by /= 0) and (vco_divide_by /= 0))) then
5509
                    i_n := vco_divide_by;
5510
                    i_m := vco_multiply_by;
5511
                else
5512
                    i_n := 1;
5513
                    i_m := lcm (i_clk0_mult_by, i_clk1_mult_by,
5514
                                i_clk2_mult_by, i_clk3_mult_by,
5515
                                i_clk4_mult_by, i_clk5_mult_by,
5516
                                1, 1, 1, 1, inclk0_input_frequency);
5517
                end if;
5518
 
5519
                if (pll_type = "flvds") then
5520
                    -- Need to readjust phase shift values when the clock multiply value has been readjusted.
5521
                    new_multiplier := clk0_multiply_by / i_clk0_mult_by;
5522
                    i_clk0_phase_shift := str2int(clk0_phase_shift) * new_multiplier;
5523
                    i_clk1_phase_shift := str2int(clk1_phase_shift) * new_multiplier;
5524
                    i_clk2_phase_shift := str2int(clk2_phase_shift) * new_multiplier;
5525
                else
5526
                    i_clk0_phase_shift := str2int(clk0_phase_shift);
5527
                    i_clk1_phase_shift := str2int(clk1_phase_shift);
5528
                    i_clk2_phase_shift := str2int(clk2_phase_shift);
5529
                end if;
5530
 
5531
                max_neg_abs := maxnegabs(i_clk0_phase_shift,
5532
                                        i_clk1_phase_shift,
5533
                                        i_clk2_phase_shift,
5534
                                        str2int(clk3_phase_shift),
5535
                                        str2int(clk4_phase_shift),
5536
                                        str2int(clk5_phase_shift),
5537
                                        0, 0, 0, 0);
5538
                i_m_ph  := counter_ph(get_phase_degree(max_neg_abs,inclk0_input_frequency), i_m, i_n);
5539
 
5540
                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);
5541
                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);
5542
                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);
5543
                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);
5544
                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);
5545
                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);
5546
                i_c_high(0) := counter_high(output_counter_value(i_clk0_div_by,
5547
                                i_clk0_mult_by, i_m, i_n), clk0_duty_cycle);
5548
                i_c_high(1) := counter_high(output_counter_value(i_clk1_div_by,
5549
                                i_clk1_mult_by, i_m, i_n), clk1_duty_cycle);
5550
                i_c_high(2) := counter_high(output_counter_value(i_clk2_div_by,
5551
                                i_clk2_mult_by, i_m, i_n), clk2_duty_cycle);
5552
                i_c_high(3) := counter_high(output_counter_value(i_clk3_div_by,
5553
                                i_clk3_mult_by, i_m, i_n), clk3_duty_cycle);
5554
                i_c_high(4) := counter_high(output_counter_value(i_clk4_div_by,
5555
                                i_clk4_mult_by,  i_m, i_n), clk4_duty_cycle);
5556
                i_c_high(5) := counter_high(output_counter_value(i_clk5_div_by,
5557
                                i_clk5_mult_by,  i_m, i_n), clk5_duty_cycle);
5558
                i_c_low(0)  := counter_low(output_counter_value(i_clk0_div_by,
5559
                                i_clk0_mult_by,  i_m, i_n), clk0_duty_cycle);
5560
                i_c_low(1)  := counter_low(output_counter_value(i_clk1_div_by,
5561
                                i_clk1_mult_by,  i_m, i_n), clk1_duty_cycle);
5562
                i_c_low(2)  := counter_low(output_counter_value(i_clk2_div_by,
5563
                                i_clk2_mult_by,  i_m, i_n), clk2_duty_cycle);
5564
                i_c_low(3)  := counter_low(output_counter_value(i_clk3_div_by,
5565
                                i_clk3_mult_by,  i_m, i_n), clk3_duty_cycle);
5566
                i_c_low(4)  := counter_low(output_counter_value(i_clk4_div_by,
5567
                                i_clk4_mult_by,  i_m, i_n), clk4_duty_cycle);
5568
                i_c_low(5)  := counter_low(output_counter_value(i_clk5_div_by,
5569
                                i_clk5_mult_by,  i_m, i_n), clk5_duty_cycle);
5570
                i_m_initial  := counter_initial(get_phase_degree(max_neg_abs, inclk0_input_frequency), i_m,i_n);
5571
 
5572
                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);
5573
                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);
5574
                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);
5575
                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);
5576
                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);
5577
                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);
5578
                i_c_mode(0) := counter_mode(clk0_duty_cycle, output_counter_value(i_clk0_div_by, i_clk0_mult_by,  i_m, i_n));
5579
                i_c_mode(1) := counter_mode(clk1_duty_cycle, output_counter_value(i_clk1_div_by, i_clk1_mult_by,  i_m, i_n));
5580
                i_c_mode(2) := counter_mode(clk2_duty_cycle, output_counter_value(i_clk2_div_by, i_clk2_mult_by,  i_m, i_n));
5581
                i_c_mode(3) := counter_mode(clk3_duty_cycle, output_counter_value(i_clk3_div_by, i_clk3_mult_by,  i_m, i_n));
5582
                i_c_mode(4) := counter_mode(clk4_duty_cycle, output_counter_value(i_clk4_div_by, i_clk4_mult_by,  i_m, i_n));
5583
                i_c_mode(5) := counter_mode(clk5_duty_cycle, output_counter_value(i_clk5_div_by, i_clk5_mult_by,  i_m, i_n));
5584
 
5585
                -- in external feedback mode, need to adjust M value to take
5586
                -- into consideration the external feedback counter value
5587
                if(operation_mode = "external_feedback") then
5588
                    -- if there is a negative phase shift, m_initial can
5589
                    -- only be 1
5590
                    if (max_neg_abs > 0) then
5591
                        i_m_initial := 1;
5592
                    end if;
5593
 
5594
                    -- calculate the feedback counter multiplier
5595
                    if (i_c_mode(fbk_cntr_index) = "bypass") then
5596
                        output_count := 1;
5597
                    else
5598
                        output_count := i_c_high(fbk_cntr_index) + i_c_low(fbk_cntr_index);
5599
                    end if;
5600
 
5601
                    new_divisor := gcd(i_m, output_count);
5602
                    i_m := i_m / new_divisor;
5603
                    i_n := output_count / new_divisor;
5604
                end if;
5605
 
5606
            else -- m /= 0
5607
 
5608
                i_n             := n;
5609
                i_m             := m;
5610
                i_m_initial     := m_initial;
5611
                i_m_ph          := m_ph;
5612
                i_c_ph(0)         := c0_ph;
5613
                i_c_ph(1)         := c1_ph;
5614
                i_c_ph(2)         := c2_ph;
5615
                i_c_ph(3)         := c3_ph;
5616
                i_c_ph(4)         := c4_ph;
5617
                i_c_ph(5)         := c5_ph;
5618
                i_c_high(0)       := c0_high;
5619
                i_c_high(1)       := c1_high;
5620
                i_c_high(2)       := c2_high;
5621
                i_c_high(3)       := c3_high;
5622
                i_c_high(4)       := c4_high;
5623
                i_c_high(5)       := c5_high;
5624
                i_c_low(0)        := c0_low;
5625
                i_c_low(1)        := c1_low;
5626
                i_c_low(2)        := c2_low;
5627
                i_c_low(3)        := c3_low;
5628
                i_c_low(4)        := c4_low;
5629
                i_c_low(5)        := c5_low;
5630
                i_c_initial(0)    := c0_initial;
5631
                i_c_initial(1)    := c1_initial;
5632
                i_c_initial(2)    := c2_initial;
5633
                i_c_initial(3)    := c3_initial;
5634
                i_c_initial(4)    := c4_initial;
5635
                i_c_initial(5)    := c5_initial;
5636
                i_c_mode(0)       := translate_string(c0_mode);
5637
                i_c_mode(1)       := translate_string(c1_mode);
5638
                i_c_mode(2)       := translate_string(c2_mode);
5639
                i_c_mode(3)       := translate_string(c3_mode);
5640
                i_c_mode(4)       := translate_string(c4_mode);
5641
                i_c_mode(5)       := translate_string(c5_mode);
5642
 
5643
            end if; -- user to advanced conversion.
5644
 
5645
            m_initial_val <= i_m_initial;
5646
            n_val(0) <= i_n;
5647
            m_val(0) <= i_m;
5648
            m_val(1) <= m2;
5649
            n_val(1) <= n2;
5650
 
5651
            if (i_m = 1) then
5652
                m_mode_val(0) <= "bypass";
5653
            else
5654
                m_mode_val(0) <= "      ";
5655
            end if;
5656
            if (m2 = 1) then
5657
                m_mode_val(1) <= "bypass";
5658
            end if;
5659
            if (i_n = 1) then
5660
                n_mode_val(0) <= "bypass";
5661
            end if;
5662
            if (n2 = 1) then
5663
                n_mode_val(1) <= "bypass";
5664
            end if;
5665
 
5666
            m_ph_val  <= i_m_ph;
5667
            m_ph_val_tmp := i_m_ph;
5668
            m_val_tmp := m_val;
5669
 
5670
            for i in 0 to 5 loop
5671
                if (i_c_mode(i) = "bypass") then
5672
                    if (pll_type = "fast" or pll_type = "lvds") then
5673
                        i_c_high(i) := 16;
5674
                        i_c_low(i) := 16;
5675
                    else
5676
                        i_c_high(i) := 256;
5677
                        i_c_low(i) := 256;
5678
                    end if;
5679
                end if;
5680
                c_ph_val(i)         <= i_c_ph(i);
5681
                c_initial_val(i)    <= i_c_initial(i);
5682
                c_high_val(i)       <= i_c_high(i);
5683
                c_low_val(i)        <= i_c_low(i);
5684
                c_mode_val(i)       <= i_c_mode(i);
5685
                c_high_val_tmp(i)   := i_c_high(i);
5686
                c_low_val_tmp(i)    := i_c_low(i);
5687
                c_mode_val_tmp(i)   := i_c_mode(i);
5688
                c_ph_val_tmp(i)     := i_c_ph(i);
5689
                c_ph_val_orig(i)    <= i_c_ph(i);
5690
                c_high_val_hold(i)  <= i_c_high(i);
5691
                c_low_val_hold(i)   <= i_c_low(i);
5692
                c_mode_val_hold(i)  <= i_c_mode(i);
5693
            end loop;
5694
 
5695
            lfc_val <= loop_filter_c;
5696
            lfr_val <= loop_filter_r;
5697
            cp_curr_val <= charge_pump_current;
5698
 
5699
            if (pll_type = "fast") then
5700
                scan_chain_length := FAST_SCAN_CHAIN;
5701
            end if;
5702
            -- initialize the scan_chain contents
5703
            -- CP/LF bits
5704
            scan_data(11 downto 0) <= "000000000000";
5705
            for i in 0 to 3 loop
5706
                if (pll_type = "fast" or pll_type = "lvds") then
5707
                    if (fpll_loop_filter_c_arr(i) = loop_filter_c) then
5708
                        scan_data(11 downto 10) <= int2bin(i, 2);
5709
                    end if;
5710
                else
5711
                    if (loop_filter_c_arr(i) = loop_filter_c) then
5712
                        scan_data(11 downto 10) <= int2bin(i, 2);
5713
                    end if;
5714
                end if;
5715
            end loop;
5716
            for i in 0 to 15 loop
5717
                if (charge_pump_curr_arr(i) = charge_pump_current) then
5718
                    scan_data(3 downto 0) <= int2bin(i, 4);
5719
                end if;
5720
            end loop;
5721
            for i in 0 to 39 loop
5722
                if (loop_filter_r_arr(i) = loop_filter_r) then
5723
                    if (i >= 16 and i <= 23) then
5724
                        scan_data(9 downto 4) <= int2bin((i+8), 6);
5725
                    elsif (i >= 24 and i <= 31) then
5726
                        scan_data(9 downto 4) <= int2bin((i+16), 6);
5727
                    elsif (i >= 32) then
5728
                        scan_data(9 downto 4) <= int2bin((i+24), 6);
5729
                    else
5730
                        scan_data(9 downto 4) <= int2bin(i, 6);
5731
                    end if;
5732
                end if;
5733
            end loop;
5734
 
5735
            if (pll_type = "fast" or pll_type = "lvds") then
5736
                scan_data(21 downto 12) <= "0000000000"; -- M, C3-C0 ph
5737
                -- C0-C3 high
5738
                scan_data(25 downto 22) <= int2bin(i_c_high(0), 4);
5739
                scan_data(35 downto 32) <= int2bin(i_c_high(1), 4);
5740
                scan_data(45 downto 42) <= int2bin(i_c_high(2), 4);
5741
                scan_data(55 downto 52) <= int2bin(i_c_high(3), 4);
5742
                -- C0-C3 low
5743
                scan_data(30 downto 27) <= int2bin(i_c_low(0), 4);
5744
                scan_data(40 downto 37) <= int2bin(i_c_low(1), 4);
5745
                scan_data(50 downto 47) <= int2bin(i_c_low(2), 4);
5746
                scan_data(60 downto 57) <= int2bin(i_c_low(3), 4);
5747
                -- C0-C3 mode
5748
                for i in 0 to 3 loop
5749
                    if (i_c_mode(i) = "   off" or i_c_mode(i) = "bypass") then
5750
                        scan_data(26 + (10*i)) <= '1';
5751
                        if (i_c_mode(i) = "   off") then
5752
                            scan_data(31 + (10*i)) <= '1';
5753
                        else
5754
                            scan_data(31 + (10*i)) <= '0';
5755
                        end if;
5756
                    else
5757
                        scan_data(26 + (10*i)) <= '0';
5758
                        if (i_c_mode(i) = "   odd") then
5759
                            scan_data(31 + (10*i)) <= '1';
5760
                        else
5761
                            scan_data(31 + (10*i)) <= '0';
5762
                        end if;
5763
                    end if;
5764
                end loop;
5765
                -- M
5766
                if (i_m = 1) then
5767
                    scan_data(66) <= '1';
5768
                    scan_data(71) <= '0';
5769
                    scan_data(65 downto 62) <= "0000";
5770
                    scan_data(70 downto 67) <= "0000";
5771
                else
5772
                    scan_data(66) <= '0';       -- set BYPASS bit to 0
5773
                    scan_data(70 downto 67) <= int2bin(i_m/2, 4);   -- set M low
5774
                    if (i_m rem 2 = 0) then
5775
                        -- M is an even no. : set M high = low,
5776
                        -- set odd/even bit to 0
5777
                        scan_data(65 downto 62) <= int2bin(i_m/2, 4);
5778
                        scan_data(71) <= '0';
5779
                    else       -- M is odd : M high = low + 1
5780
                        scan_data(65 downto 62) <= int2bin((i_m/2) + 1, 4);
5781
                        scan_data(71) <= '1';
5782
                    end if;
5783
                end if;
5784
                -- N
5785
                scan_data(73 downto 72) <= int2bin(i_n, 2);
5786
                if (i_n = 1) then
5787
                    scan_data(74) <= '1';
5788
                    scan_data(73 downto 72) <= "00";
5789
                end if;
5790
            else          -- PLL type is auto or enhanced
5791
                scan_data(25 downto 12) <= "00000000000000"; -- M, C5-C0 ph
5792
                -- C0-C5 high
5793
                scan_data(123 downto 116) <= int2bin(i_c_high(0), 8);
5794
                scan_data(105 downto 98) <= int2bin(i_c_high(1), 8);
5795
                scan_data(87 downto 80) <= int2bin(i_c_high(2), 8);
5796
                scan_data(69 downto 62) <= int2bin(i_c_high(3), 8);
5797
                scan_data(51 downto 44) <= int2bin(i_c_high(4), 8);
5798
                scan_data(33 downto 26) <= int2bin(i_c_high(5), 8);
5799
                -- C0-C5 low
5800
                scan_data(132 downto 125) <= int2bin(i_c_low(0), 8);
5801
                scan_data(114 downto 107) <= int2bin(i_c_low(1), 8);
5802
                scan_data(96 downto 89) <= int2bin(i_c_low(2), 8);
5803
                scan_data(78 downto 71) <= int2bin(i_c_low(3), 8);
5804
                scan_data(60 downto 53) <= int2bin(i_c_low(4), 8);
5805
                scan_data(42 downto 35) <= int2bin(i_c_low(5), 8);
5806
                -- C0-C5 mode
5807
                for i in 0 to 5 loop
5808
                    if (i_c_mode(i) = "   off" or i_c_mode(i) = "bypass") then
5809
                        scan_data(124 - (18*i)) <= '1';
5810
                        if (i_c_mode(i) = "   off") then
5811
                            scan_data(133 - (18*i)) <= '1';
5812
                        else
5813
                            scan_data(133 - (18*i)) <= '0';
5814
                        end if;
5815
                    else
5816
                        scan_data(124 - (18*i)) <= '0';
5817
                        if (i_c_mode(i) = "   odd") then
5818
                            scan_data(133 - (18*i)) <= '1';
5819
                        else
5820
                            scan_data(133 - (18*i)) <= '0';
5821
                        end if;
5822
                    end if;
5823
                end loop;
5824
 
5825
                -- M/M2
5826
                scan_data(142 downto 134) <= int2bin(i_m, 9);
5827
                scan_data(143) <= '0';
5828
                scan_data(152 downto 144) <= int2bin(m2, 9);
5829
                scan_data(153) <= '0';
5830
                if (i_m = 1) then
5831
                    scan_data(143) <= '1';
5832
                    scan_data(142 downto 134) <= "000000000";
5833
                end if;
5834
                if (m2 = 1) then
5835
                    scan_data(153) <= '1';
5836
                    scan_data(152 downto 144) <= "000000000";
5837
                end if;
5838
 
5839
                -- N/N2
5840
                scan_data(162 downto 154) <= int2bin(i_n, 9);
5841
                scan_data(172 downto 164) <= int2bin(n2, 9);
5842
                if (i_n = 1) then
5843
                    scan_data(163) <= '1';
5844
                    scan_data(162 downto 154) <= "000000000";
5845
                end if;
5846
                if (n2 = 1) then
5847
                    scan_data(173) <= '1';
5848
                    scan_data(172 downto 164) <= "000000000";
5849
                end if;
5850
 
5851
            end if;
5852
            if (pll_type = "fast" or pll_type = "lvds") then
5853
                num_output_cntrs <= 4;
5854
            else
5855
                num_output_cntrs <= 6;
5856
            end if;
5857
 
5858
            init := false;
5859
        elsif (scanwrite_enabled'event and scanwrite_enabled = '0') then
5860
            -- falling edge : deassert scandone
5861
            scandone_tmp <= transport '0' after (1.5 * scanclk_period);
5862
            c0_rising_edge_transfer_done := false;
5863
            c1_rising_edge_transfer_done := false;
5864
            c2_rising_edge_transfer_done := false;
5865
            c3_rising_edge_transfer_done := false;
5866
            c4_rising_edge_transfer_done := false;
5867
            c5_rising_edge_transfer_done := false;
5868
        elsif (scanwrite_enabled'event and scanwrite_enabled = '1') then
5869
            ASSERT false REPORT "PLL Reprogramming Initiated" severity note;
5870
 
5871
            reconfig_err <= false;
5872
 
5873
            -- make temporary copy of scan_data for processing
5874
            tmp_scan_data := scan_data;
5875
 
5876
            -- save old values
5877
            lfc_old <= lfc_val;
5878
            lfr_old <= lfr_val;
5879
            cp_curr_old <= cp_curr_val;
5880
 
5881
            -- CP
5882
            -- Bits 0-3 : all values are legal
5883
            cp_curr_val <= charge_pump_curr_arr(alt_conv_integer(scan_data(3 downto 0)));
5884
 
5885
            -- LF Resistance : bits 4-9
5886
            -- values from 010000 - 010111, 100000 - 100111,
5887
            --             110000 - 110111 are illegal
5888
            lfr_tmp := tmp_scan_data(9 downto 4);
5889
            lfr_int := alt_conv_integer(lfr_tmp);
5890
            if (((lfr_int >= 16) and (lfr_int <= 23)) or
5891
                ((lfr_int >= 32) and (lfr_int <= 39)) or
5892
                ((lfr_int >= 48) and (lfr_int <= 55))) then
5893
                reconfig_err <= true;
5894
                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;
5895
            else
5896
                if (lfr_int >= 56) then
5897
                    lfr_int := lfr_int - 24;
5898
                elsif ((lfr_int >= 40) and (lfr_int <= 47)) then
5899
                    lfr_int := lfr_int - 16;
5900
                elsif ((lfr_int >= 24) and (lfr_int <= 31)) then
5901
                    lfr_int := lfr_int - 8;
5902
                end if;
5903
                lfr_val <= loop_filter_r_arr(lfr_int);
5904
            end if;
5905
 
5906
            -- LF Capacitance : bits 10,11 : all values are legal
5907
            lfc_tmp := scan_data(11 downto 10);
5908
            if (pll_type = "fast" or pll_type = "lvds") then
5909
                lfc_val <= fpll_loop_filter_c_arr(alt_conv_integer(lfc_tmp));
5910
            else
5911
                lfc_val <= loop_filter_c_arr(alt_conv_integer(lfc_tmp));
5912
            end if;
5913
 
5914
            -- cntrs c0-c5
5915
            -- save old values for display info.
5916
            m_val_old <= m_val;
5917
            n_val_old <= n_val;
5918
            m_mode_val_old <= m_mode_val;
5919
            n_mode_val_old <= n_mode_val;
5920
            m_ph_val_old <= m_ph_val;
5921
            c_high_val_old <= c_high_val;
5922
            c_low_val_old <= c_low_val;
5923
            c_ph_val_old <= c_ph_val;
5924
            c_mode_val_old <= c_mode_val;
5925
 
5926
            -- first the M counter phase : bit order same for fast and GPP
5927
            if (scan_data(12) = '0') then
5928
                -- do nothing
5929
            elsif (scan_data(12) = '1' and scan_data(13) = '1') then
5930
                m_ph_val_tmp := m_ph_val_tmp + 1;
5931
                if (m_ph_val_tmp > 7) then
5932
                    m_ph_val_tmp := 0;
5933
                end if;
5934
            elsif (scan_data(12) = '1' and scan_data(13) = '0') then
5935
                m_ph_val_tmp := m_ph_val_tmp - 1;
5936
                if (m_ph_val_tmp < 0) then
5937
                    m_ph_val_tmp := 7;
5938
                end if;
5939
            else
5940
                reconfig_err <= true;
5941
                ASSERT false REPORT "Illegal values for M counter phase tap. Reconfiguration may not work." severity warning;
5942
            end if;
5943
 
5944
            -- read the fast PLL bits
5945
            if (pll_type = "fast" or pll_type = "lvds") then
5946
                -- C3-C0 phase bits
5947
                for i in 3 downto 0 loop
5948
                    start_bit := 14 + ((3-i)*2);
5949
                    if (tmp_scan_data(start_bit) = '0') then
5950
                        -- do nothing
5951
                    elsif (tmp_scan_data(start_bit) = '1') then
5952
                        if (tmp_scan_data(start_bit + 1) = '1') then
5953
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) + 1;
5954
                            if (c_ph_val_tmp(i) > 7) then
5955
                                c_ph_val_tmp(i) := 0;
5956
                            end if;
5957
                        elsif (tmp_scan_data(start_bit + 1) = '0') then
5958
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) - 1;
5959
                            if (c_ph_val_tmp(i) < 0) then
5960
                                c_ph_val_tmp(i) := 7;
5961
                            end if;
5962
                        end if;
5963
                    end if;
5964
                end loop;
5965
                -- C0-C3 counter moduli
5966
                for i in 0 to 3 loop
5967
                    start_bit := 22 + (i*10);
5968
                    if (tmp_scan_data(start_bit + 4) = '1') then
5969
                        c_mode_val_tmp(i) := "bypass";
5970
                        if (tmp_scan_data(start_bit + 9) = '1') then
5971
                            c_mode_val_tmp(i) := "   off";
5972
                            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;
5973
                        end if;
5974
                    elsif (tmp_scan_data(start_bit + 9) = '1') then
5975
                        c_mode_val_tmp(i) := "   odd";
5976
                    else
5977
                        c_mode_val_tmp(i) := "  even";
5978
                    end if;
5979
                    high_fast := tmp_scan_data(start_bit+3 downto start_bit);
5980
                    low_fast := tmp_scan_data(start_bit+8 downto start_bit+5);
5981
                    if (tmp_scan_data(start_bit+3 downto start_bit) = "0000") then
5982
                        c_high_val_tmp(i) := 16;
5983
                    else
5984
                        c_high_val_tmp(i) := alt_conv_integer(high_fast);
5985
                    end if;
5986
                    if (tmp_scan_data(start_bit+8 downto start_bit+5) = "0000") then
5987
                        c_low_val_tmp(i) := 16;
5988
                    else
5989
                        c_low_val_tmp(i) := alt_conv_integer(low_fast);
5990
                    end if;
5991
                end loop;
5992
                sig_c_ph_val_tmp <= c_ph_val_tmp;
5993
                sig_c_low_val_tmp <= c_low_val_tmp;
5994
                -- M
5995
                -- some temporary storage
5996
                if (tmp_scan_data(65 downto 62) = "0000") then
5997
                    m_hi := "10000";
5998
                else
5999
                    m_hi := "0" & tmp_scan_data(65 downto 62);
6000
                end if;
6001
                if (tmp_scan_data(70 downto 67) = "0000") then
6002
                    m_lo := "10000";
6003
                else
6004
                    m_lo := "0" & tmp_scan_data(70 downto 67);
6005
                end if;
6006
                m_val_tmp(0) := alt_conv_integer(m_hi) + alt_conv_integer(m_lo);
6007
                if (tmp_scan_data(66) = '1') then
6008
                    if (tmp_scan_data(71) = '1') then
6009
                        -- this will turn off the M counter : error
6010
                        reconfig_err <= true;
6011
                        is_error := true;
6012
                        ASSERT false REPORT "The specified bit settings will turn OFF the M counter. This is illegal. Reconfiguration may not work." severity warning;
6013
                    else -- M counter is being bypassed
6014
                        if (m_mode_val(0) /= "bypass") then
6015
                            -- mode is switched : give warning
6016
                            ASSERT false REPORT "M counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
6017
                        end if;
6018
                        m_val_tmp(0) := 1;
6019
                        m_mode_val(0) <= "bypass";
6020
                    end if;
6021
                else
6022
                    if (m_mode_val(0) = "bypass") then
6023
                        -- mode is switched : give warning
6024
                        ASSERT false REPORT "M counter switched BYPASS mode to enabled. PLL may lose lock." severity warning;
6025
                    end if;
6026
                    m_mode_val(0) <= "      ";
6027
                    if (tmp_scan_data(71) = '1') then
6028
                        -- odd : check for duty cycle, if not 50% -- error
6029
                        if (alt_conv_integer(m_hi) - alt_conv_integer(m_lo) /= 1) then
6030
                            reconfig_err <= true;
6031
                            ASSERT FALSE REPORT "The M counter of the StratixII 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;
6032
                        end if;
6033
                    else -- even
6034
                        if (alt_conv_integer(m_hi) /= alt_conv_integer(m_lo)) then
6035
                            reconfig_err <= true;
6036
                            ASSERT FALSE REPORT "The M counter of the StratixII 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;
6037
                        end if;
6038
                    end if;
6039
                end if;
6040
 
6041
                -- N
6042
                is_error := false;
6043
                n_fast := tmp_scan_data(73 downto 72);
6044
                n_val(0) <= alt_conv_integer(n_fast);
6045
                if (tmp_scan_data(74) /= '1') then
6046
                    if (alt_conv_integer(n_fast) = 1) then
6047
                        is_error := true;
6048
                        reconfig_err <= true;
6049
                        -- cntr value is illegal : give warning
6050
                        ASSERT false REPORT "Illegal 1 value for N counter. Instead the counter should be BYPASSED. Reconfiguration may not work." severity warning;
6051
                    elsif (alt_conv_integer(n_fast) = 0) then
6052
                        n_val(0) <= 4;
6053
                        ASSERT FALSE REPORT "N Modulus = " &int2str(4)& " " severity note;
6054
                    end if;
6055
                    if (not is_error) then
6056
                        if (n_mode_val(0) = "bypass") then
6057
                            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;
6058
                        else
6059
                            ASSERT FALSE REPORT "N modulus = " &int2str(alt_conv_integer(n_fast))& " "severity note;
6060
                        end if;
6061
                        n_mode_val(0) <= "      ";
6062
                    end if;
6063
                elsif (tmp_scan_data(74) = '1') then
6064
                    if (tmp_scan_data(72) /= '0') then
6065
                        is_error := true;
6066
                        reconfig_err <= true;
6067
                        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;
6068
                    else
6069
                        if (n_mode_val(0) /= "bypass") then
6070
                            ASSERT false REPORT "N Counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
6071
                        end if;
6072
                        n_val(0) <= 1;
6073
                        n_mode_val(0) <= "bypass";
6074
                    end if;
6075
                end if;
6076
            else   -- GENERAL PURPOSE PLL
6077
                for i in 0 to 5 loop
6078
                    start_bit := 116 - (i*18);
6079
                    if (tmp_scan_data(start_bit + 8) = '1') then
6080
                        c_mode_val_tmp(i) := "bypass";
6081
                        if (tmp_scan_data(start_bit + 17) = '1') then
6082
                            c_mode_val_tmp(i) := "   off";
6083
                            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;
6084
                        end if;
6085
                    elsif (tmp_scan_data(start_bit + 17) = '1') then
6086
                        c_mode_val_tmp(i) := "   odd";
6087
                    else
6088
                        c_mode_val_tmp(i) := "  even";
6089
                    end if;
6090
                    high := tmp_scan_data(start_bit + 7 downto start_bit);
6091
                    low := tmp_scan_data(start_bit+16 downto start_bit+9);
6092
                    if (tmp_scan_data(start_bit+7 downto start_bit) = "00000000") then
6093
                        c_high_val_tmp(i) := 256;
6094
                    else
6095
                        c_high_val_tmp(i) := alt_conv_integer(high);
6096
                    end if;
6097
                    if (tmp_scan_data(start_bit+16 downto start_bit+9) = "00000000") then
6098
                        c_low_val_tmp(i) := 256;
6099
                    else
6100
                        c_low_val_tmp(i) := alt_conv_integer(low);
6101
                    end if;
6102
                end loop;
6103
                -- the phase taps
6104
                for i in 0 to 5 loop
6105
                    start_bit := 14 + (i*2);
6106
                    if (tmp_scan_data(start_bit) = '0') then
6107
                        -- do nothing
6108
                    elsif (tmp_scan_data(start_bit) = '1') then
6109
                        if (tmp_scan_data(start_bit + 1) = '1') then
6110
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) + 1;
6111
                            if (c_ph_val_tmp(i) > 7) then
6112
                                c_ph_val_tmp(i) := 0;
6113
                            end if;
6114
                        elsif (tmp_scan_data(start_bit + 1) = '0') then
6115
                            c_ph_val_tmp(i) := c_ph_val_tmp(i) - 1;
6116
                            if (c_ph_val_tmp(i) < 0) then
6117
                                c_ph_val_tmp(i) := 7;
6118
                            end if;
6119
                        end if;
6120
                    end if;
6121
                end loop;
6122
                sig_c_ph_val_tmp <= c_ph_val_tmp;
6123
                sig_c_low_val_tmp <= c_low_val_tmp;
6124
 
6125
                -- cntrs M/M2
6126
                for i in 0 to 1 loop
6127
                    start_bit := 134 + (i*10);
6128
                    if ( i = 0 or (i = 1 and ss > 0) ) then
6129
                        is_error := false;
6130
                        m_tmp := tmp_scan_data(start_bit+8 downto start_bit);
6131
                        m_val_tmp(i) := alt_conv_integer(m_tmp);
6132
                        if (tmp_scan_data(start_bit+9) /= '1') then
6133
                            if (alt_conv_integer(m_tmp) = 1) then
6134
                                is_error := true;
6135
                                reconfig_err <= true;
6136
                                -- cntr value is illegal : give warning
6137
                                ASSERT false REPORT "Illegal 1 value for " &ss_cntrs(i)& "counter. Instead " &ss_cntrs(i)& "should be BYPASSED. Reconfiguration may not work." severity warning;
6138
                            elsif (tmp_scan_data(start_bit+8 downto start_bit) = "000000000") then
6139
                                m_val_tmp(i) := 512;
6140
                            end if;
6141
                            if (not is_error) then
6142
                                if (m_mode_val(i) = "bypass") then
6143
                                    -- Mode is switched : give warning
6144
                                    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;
6145
                                else
6146
                                end if;
6147
                                m_mode_val(i) <= "      ";
6148
                            end if;
6149
                        elsif (tmp_scan_data(start_bit+9) = '1') then
6150
                            if (tmp_scan_data(start_bit) /= '0') then
6151
                                is_error := true;
6152
                                reconfig_err <= true;
6153
                                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;
6154
                            else
6155
                                if (m_mode_val(i) /= "bypass") then
6156
                                    -- Mode is switched : give warning
6157
                                    ASSERT false REPORT "M Counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
6158
                                end if;
6159
                                m_val_tmp(i) := 1;
6160
                                m_mode_val(i) <= "bypass";
6161
                            end if;
6162
                        end if;
6163
                    end if;
6164
                end loop;
6165
                if (ss > 0) then
6166
                    if (m_mode_val(0) /= m_mode_val(1)) then
6167
                        reconfig_err <= true;
6168
                        is_error := true;
6169
                        ASSERT false REPORT "Incompatible modes for M/M2 counters. Either both should be BYPASSED or both NON-BYPASSED. Reconfiguration may not work." severity warning;
6170
                    end if;
6171
                end if;
6172
 
6173
                -- cntrs N/N2
6174
                for i in 0 to 1 loop
6175
                    start_bit := 154 + i*10;
6176
                    if ( i = 0 or (i = 1 and ss > 0) ) then
6177
                        is_error := false;
6178
                        n_tmp := tmp_scan_data(start_bit+8 downto start_bit);
6179
                        n_val(i) <= alt_conv_integer(n_tmp);
6180
                        if (tmp_scan_data(start_bit+9) /= '1') then
6181
                            if (alt_conv_integer(n_tmp) = 1) then
6182
                                is_error := true;
6183
                                reconfig_err <= true;
6184
                                -- cntr value is illegal : give warning
6185
                                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;
6186
                            elsif (alt_conv_integer(n_tmp) = 0) then
6187
                                n_val(i) <= 512;
6188
                            end if;
6189
                            if (not is_error) then
6190
                                if (n_mode_val(i) = "bypass") then
6191
                                    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;
6192
                                else
6193
                                end if;
6194
                                n_mode_val(i) <= "      ";
6195
                            end if;
6196
                        elsif (tmp_scan_data(start_bit+9) = '1') then
6197
                            if (tmp_scan_data(start_bit) /= '0') then
6198
                                is_error := true;
6199
                                reconfig_err <= true;
6200
                                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;
6201
                            else
6202
                                if (n_mode_val(i) /= "bypass") then
6203
                                    ASSERT false REPORT "N Counter switched from enabled to BYPASS mode. PLL may lose lock." severity warning;
6204
                                end if;
6205
                                n_val(i) <= 1;
6206
                                n_mode_val(i) <= "bypass";
6207
                            end if;
6208
                        end if;
6209
                    end if;
6210
                end loop;
6211
                if (ss > 0) then
6212
                    if (n_mode_val(0) /= n_mode_val(1)) then
6213
                        reconfig_err <= true;
6214
                        is_error := true;
6215
                        ASSERT false REPORT "Incompatible modes for N/N2 counters. Either both should be BYPASSED or both NON-BYPASSED. Reconfiguration may not work." severity warning;
6216
                    end if;
6217
                end if;
6218
            end if;
6219
 
6220
            slowest_clk_old := slowest_clk(c_high_val(0)+c_low_val(0), c_mode_val(0),
6221
                                    c_high_val(1)+c_low_val(1), c_mode_val(1),
6222
                                    c_high_val(2)+c_low_val(2), c_mode_val(2),
6223
                                    c_high_val(3)+c_low_val(3), c_mode_val(3),
6224
                                    c_high_val(4)+c_low_val(4), c_mode_val(4),
6225
                                    c_high_val(5)+c_low_val(5), c_mode_val(5),
6226
                                    sig_refclk_period, m_val(0));
6227
 
6228
            slowest_clk_new := slowest_clk(c_high_val(0)+c_low_val(0), c_mode_val(0),
6229
                                    c_high_val_tmp(1)+c_low_val(1), c_mode_val_tmp(1),
6230
                                    c_high_val_tmp(2)+c_low_val(2), c_mode_val_tmp(2),
6231
                                    c_high_val_tmp(3)+c_low_val(3), c_mode_val_tmp(3),
6232
                                    c_high_val_tmp(4)+c_low_val(4), c_mode_val_tmp(4),
6233
                                    c_high_val_tmp(5)+c_low_val(5), c_mode_val_tmp(5),
6234
                                    sig_refclk_period, m_val(0));
6235
 
6236
            if (slowest_clk_new > slowest_clk_old) then
6237
                quiet_time := slowest_clk_new;
6238
            else
6239
                quiet_time := slowest_clk_old;
6240
            end if;
6241
 
6242
            tmp_rem := (quiet_time/1 ps) rem (scanclk_period/ 1 ps);
6243
            scanclk_cycles := (quiet_time/1 ps) / (scanclk_period/1 ps);
6244
            if (tmp_rem /= 0) then
6245
                scanclk_cycles := scanclk_cycles + 1;
6246
            end if;
6247
            scandone_tmp <= transport '1' after ((scanclk_cycles+1)*scanclk_period - (scanclk_period/2));
6248
        end if;
6249
 
6250
        if (scanwrite_enabled = '1') then
6251
            if (fbclk'event and fbclk = '1') then
6252
                m_val <= m_val_tmp;
6253
            end if;
6254
 
6255
            if (c_clk(0)'event and c_clk(0) = '1') then
6256
                c_high_val_hold(0) <= c_high_val_tmp(0);
6257
                c_mode_val_hold(0) <= c_mode_val_tmp(0);
6258
                c0_rising_edge_transfer_done := true;
6259
                c_high_val(0) <= c_high_val_hold(0);
6260
                c_mode_val(0) <= c_mode_val_hold(0);
6261
            end if;
6262
            if (c_clk(1)'event and c_clk(1) = '1') then
6263
                c_high_val_hold(1) <= c_high_val_tmp(1);
6264
                c_mode_val_hold(1) <= c_mode_val_tmp(1);
6265
                c1_rising_edge_transfer_done := true;
6266
                c_high_val(1) <= c_high_val_hold(1);
6267
                c_mode_val(1) <= c_mode_val_hold(1);
6268
            end if;
6269
            if (c_clk(2)'event and c_clk(2) = '1') then
6270
                c_high_val_hold(2) <= c_high_val_tmp(2);
6271
                c_mode_val_hold(2) <= c_mode_val_tmp(2);
6272
                c2_rising_edge_transfer_done := true;
6273
                c_high_val(2) <= c_high_val_hold(2);
6274
                c_mode_val(2) <= c_mode_val_hold(2);
6275
            end if;
6276
            if (c_clk(3)'event and c_clk(3) = '1') then
6277
                c_high_val_hold(3) <= c_high_val_tmp(3);
6278
                c_mode_val_hold(3) <= c_mode_val_tmp(3);
6279
                c_high_val(3) <= c_high_val_hold(3);
6280
                c_mode_val(3) <= c_mode_val_hold(3);
6281
                c3_rising_edge_transfer_done := true;
6282
            end if;
6283
            if (c_clk(4)'event and c_clk(4) = '1') then
6284
                c_high_val_hold(4) <= c_high_val_tmp(4);
6285
                c_mode_val_hold(4) <= c_mode_val_tmp(4);
6286
                c_high_val(4) <= c_high_val_hold(4);
6287
                c_mode_val(4) <= c_mode_val_hold(4);
6288
                c4_rising_edge_transfer_done := true;
6289
            end if;
6290
            if (c_clk(5)'event and c_clk(5) = '1') then
6291
                c_high_val_hold(5) <= c_high_val_tmp(5);
6292
                c_mode_val_hold(5) <= c_mode_val_tmp(5);
6293
                c_high_val(5) <= c_high_val_hold(5);
6294
                c_mode_val(5) <= c_mode_val_hold(5);
6295
                c5_rising_edge_transfer_done := true;
6296
            end if;
6297
        end if;
6298
 
6299
        if (c_clk(0)'event and c_clk(0) = '0' and c0_rising_edge_transfer_done) then
6300
            c_low_val_hold(0) <= c_low_val_tmp(0);
6301
            c_low_val(0) <= c_low_val_hold(0);
6302
        end if;
6303
        if (c_clk(1)'event and c_clk(1) = '0' and c1_rising_edge_transfer_done) then
6304
            c_low_val_hold(1) <= c_low_val_tmp(1);
6305
            c_low_val(1) <= c_low_val_hold(1);
6306
        end if;
6307
        if (c_clk(2)'event and c_clk(2) = '0' and c2_rising_edge_transfer_done) then
6308
            c_low_val_hold(2) <= c_low_val_tmp(2);
6309
            c_low_val(2) <= c_low_val_hold(2);
6310
        end if;
6311
        if (c_clk(3)'event and c_clk(3) = '0' and c3_rising_edge_transfer_done) then
6312
            c_low_val_hold(3) <= c_low_val_tmp(3);
6313
            c_low_val(3) <= c_low_val_hold(3);
6314
        end if;
6315
        if (c_clk(4)'event and c_clk(4) = '0' and c4_rising_edge_transfer_done) then
6316
            c_low_val_hold(4) <= c_low_val_tmp(4);
6317
            c_low_val(4) <= c_low_val_hold(4);
6318
        end if;
6319
        if (c_clk(5)'event and c_clk(5) = '0' and c5_rising_edge_transfer_done) then
6320
            c_low_val_hold(5) <= c_low_val_tmp(5);
6321
            c_low_val(5) <= c_low_val_hold(5);
6322
        end if;
6323
 
6324
        if (scanwrite_enabled = '1') then
6325
            if (vco_out(0)'event and vco_out(0) = '0') then
6326
                for i in 0 to 5 loop
6327
                    if (c_ph_val(i) = 0) then
6328
                        c_ph_val(i) <= c_ph_val_tmp(i);
6329
                    end if;
6330
                end loop;
6331
                if (m_ph_val = 0) then
6332
                    m_ph_val <= m_ph_val_tmp;
6333
                end if;
6334
            end if;
6335
            if (vco_out(1)'event and vco_out(1) = '0') then
6336
                for i in 0 to 5 loop
6337
                    if (c_ph_val(i) = 1) then
6338
                        c_ph_val(i) <= c_ph_val_tmp(i);
6339
                    end if;
6340
                end loop;
6341
                if (m_ph_val = 1) then
6342
                    m_ph_val <= m_ph_val_tmp;
6343
                end if;
6344
            end if;
6345
            if (vco_out(2)'event and vco_out(2) = '0') then
6346
                for i in 0 to 5 loop
6347
                    if (c_ph_val(i) = 2) then
6348
                        c_ph_val(i) <= c_ph_val_tmp(i);
6349
                    end if;
6350
                end loop;
6351
                if (m_ph_val = 2) then
6352
                    m_ph_val <= m_ph_val_tmp;
6353
                end if;
6354
            end if;
6355
            if (vco_out(3)'event and vco_out(3) = '0') then
6356
                for i in 0 to 5 loop
6357
                    if (c_ph_val(i) = 3) then
6358
                        c_ph_val(i) <= c_ph_val_tmp(i);
6359
                    end if;
6360
                end loop;
6361
                if (m_ph_val = 3) then
6362
                    m_ph_val <= m_ph_val_tmp;
6363
                end if;
6364
            end if;
6365
            if (vco_out(4)'event and vco_out(4) = '0') then
6366
                for i in 0 to 5 loop
6367
                    if (c_ph_val(i) = 4) then
6368
                        c_ph_val(i) <= c_ph_val_tmp(i);
6369
                    end if;
6370
                end loop;
6371
                if (m_ph_val = 4) then
6372
                    m_ph_val <= m_ph_val_tmp;
6373
                end if;
6374
            end if;
6375
            if (vco_out(5)'event and vco_out(5) = '0') then
6376
                for i in 0 to 5 loop
6377
                    if (c_ph_val(i) = 5) then
6378
                        c_ph_val(i) <= c_ph_val_tmp(i);
6379
                    end if;
6380
                end loop;
6381
                if (m_ph_val = 5) then
6382
                    m_ph_val <= m_ph_val_tmp;
6383
                end if;
6384
            end if;
6385
            if (vco_out(6)'event and vco_out(6) = '0') then
6386
                for i in 0 to 5 loop
6387
                    if (c_ph_val(i) = 6) then
6388
                        c_ph_val(i) <= c_ph_val_tmp(i);
6389
                    end if;
6390
                end loop;
6391
                if (m_ph_val = 6) then
6392
                    m_ph_val <= m_ph_val_tmp;
6393
                end if;
6394
            end if;
6395
            if (vco_out(7)'event and vco_out(7) = '0') then
6396
                for i in 0 to 5 loop
6397
                    if (c_ph_val(i) = 7) then
6398
                        c_ph_val(i) <= c_ph_val_tmp(i);
6399
                    end if;
6400
                end loop;
6401
                if (m_ph_val = 7) then
6402
                    m_ph_val <= m_ph_val_tmp;
6403
                end if;
6404
            end if;
6405
        end if;
6406
 
6407
        -- revert counter phase tap values to POF programmed values
6408
        -- if PLL is reset
6409
 
6410
        if (areset_ipd = '1') then
6411
            c_ph_val <= i_c_ph;
6412
            c_ph_val_tmp := i_c_ph;
6413
            m_ph_val <= i_m_ph;
6414
            m_ph_val_tmp := i_m_ph;
6415
        end if;
6416
 
6417
        if (vco_out(0)'event) then
6418
            for i in 0 to 5 loop
6419
                if (c_ph_val(i) = 0) then
6420
                    inclk_c_from_vco(i) <= vco_out(0);
6421
                    if (i = 0 and enable0_counter = "c0") then
6422
                        inclk_sclkout0_from_vco <= vco_out(0);
6423
                    end if;
6424
                    if (i = 0 and enable1_counter = "c0") then
6425
                        inclk_sclkout1_from_vco <= vco_out(0);
6426
                    end if;
6427
                    if (i = 1 and enable0_counter = "c1") then
6428
                        inclk_sclkout0_from_vco <= vco_out(0);
6429
                    end if;
6430
                    if (i = 1 and enable1_counter = "c1") then
6431
                        inclk_sclkout1_from_vco <= vco_out(0);
6432
                    end if;
6433
                end if;
6434
            end loop;
6435
            if (m_ph_val = 0) then
6436
                inclk_m_from_vco <= vco_out(0);
6437
            end if;
6438
        end if;
6439
        if (vco_out(1)'event) then
6440
            for i in 0 to 5 loop
6441
                if (c_ph_val(i) = 1) then
6442
                    inclk_c_from_vco(i) <= vco_out(1);
6443
                    if (i = 0 and enable0_counter = "c0") then
6444
                        inclk_sclkout0_from_vco <= vco_out(1);
6445
                    end if;
6446
                    if (i = 0 and enable1_counter = "c0") then
6447
                        inclk_sclkout1_from_vco <= vco_out(1);
6448
                    end if;
6449
                    if (i = 1 and enable0_counter = "c1") then
6450
                        inclk_sclkout0_from_vco <= vco_out(1);
6451
                    end if;
6452
                    if (i = 1 and enable1_counter = "c1") then
6453
                        inclk_sclkout1_from_vco <= vco_out(1);
6454
                    end if;
6455
                end if;
6456
            end loop;
6457
            if (m_ph_val = 1) then
6458
                inclk_m_from_vco <= vco_out(1);
6459
            end if;
6460
        end if;
6461
        if (vco_out(2)'event) then
6462
            for i in 0 to 5 loop
6463
                if (c_ph_val(i) = 2) then
6464
                    inclk_c_from_vco(i) <= vco_out(2);
6465
                    if (i = 0 and enable0_counter = "c0") then
6466
                        inclk_sclkout0_from_vco <= vco_out(2);
6467
                    end if;
6468
                    if (i = 0 and enable1_counter = "c0") then
6469
                        inclk_sclkout1_from_vco <= vco_out(2);
6470
                    end if;
6471
                    if (i = 1 and enable0_counter = "c1") then
6472
                        inclk_sclkout0_from_vco <= vco_out(2);
6473
                    end if;
6474
                    if (i = 1 and enable1_counter = "c1") then
6475
                        inclk_sclkout1_from_vco <= vco_out(2);
6476
                    end if;
6477
                end if;
6478
            end loop;
6479
            if (m_ph_val = 2) then
6480
                inclk_m_from_vco <= vco_out(2);
6481
            end if;
6482
        end if;
6483
        if (vco_out(3)'event) then
6484
            for i in 0 to 5 loop
6485
                if (c_ph_val(i) = 3) then
6486
                    inclk_c_from_vco(i) <= vco_out(3);
6487
                    if (i = 0 and enable0_counter = "c0") then
6488
                        inclk_sclkout0_from_vco <= vco_out(3);
6489
                    end if;
6490
                    if (i = 0 and enable1_counter = "c0") then
6491
                        inclk_sclkout1_from_vco <= vco_out(3);
6492
                    end if;
6493
                    if (i = 1 and enable0_counter = "c1") then
6494
                        inclk_sclkout0_from_vco <= vco_out(3);
6495
                    end if;
6496
                    if (i = 1 and enable1_counter = "c1") then
6497
                        inclk_sclkout1_from_vco <= vco_out(3);
6498
                    end if;
6499
                end if;
6500
            end loop;
6501
            if (m_ph_val = 3) then
6502
                inclk_m_from_vco <= vco_out(3);
6503
            end if;
6504
        end if;
6505
        if (vco_out(4)'event) then
6506
            for i in 0 to 5 loop
6507
                if (c_ph_val(i) = 4) then
6508
                    inclk_c_from_vco(i) <= vco_out(4);
6509
                    if (i = 0 and enable0_counter = "c0") then
6510
                        inclk_sclkout0_from_vco <= vco_out(4);
6511
                    end if;
6512
                    if (i = 0 and enable1_counter = "c0") then
6513
                        inclk_sclkout1_from_vco <= vco_out(4);
6514
                    end if;
6515
                    if (i = 1 and enable0_counter = "c1") then
6516
                        inclk_sclkout0_from_vco <= vco_out(4);
6517
                    end if;
6518
                    if (i = 1 and enable1_counter = "c1") then
6519
                        inclk_sclkout1_from_vco <= vco_out(4);
6520
                    end if;
6521
                end if;
6522
            end loop;
6523
            if (m_ph_val = 4) then
6524
                inclk_m_from_vco <= vco_out(4);
6525
            end if;
6526
        end if;
6527
        if (vco_out(5)'event) then
6528
            for i in 0 to 5 loop
6529
                if (c_ph_val(i) = 5) then
6530
                    inclk_c_from_vco(i) <= vco_out(5);
6531
                    if (i = 0 and enable0_counter = "c0") then
6532
                        inclk_sclkout0_from_vco <= vco_out(5);
6533
                    end if;
6534
                    if (i = 0 and enable1_counter = "c0") then
6535
                        inclk_sclkout1_from_vco <= vco_out(5);
6536
                    end if;
6537
                    if (i = 1 and enable0_counter = "c1") then
6538
                        inclk_sclkout0_from_vco <= vco_out(5);
6539
                    end if;
6540
                    if (i = 1 and enable1_counter = "c1") then
6541
                        inclk_sclkout1_from_vco <= vco_out(5);
6542
                    end if;
6543
                end if;
6544
            end loop;
6545
            if (m_ph_val = 5) then
6546
                inclk_m_from_vco <= vco_out(5);
6547
            end if;
6548
        end if;
6549
        if (vco_out(6)'event) then
6550
            for i in 0 to 5 loop
6551
                if (c_ph_val(i) = 6) then
6552
                    inclk_c_from_vco(i) <= vco_out(6);
6553
                    if (i = 0 and enable0_counter = "c0") then
6554
                        inclk_sclkout0_from_vco <= vco_out(6);
6555
                    end if;
6556
                    if (i = 0 and enable1_counter = "c0") then
6557
                        inclk_sclkout1_from_vco <= vco_out(6);
6558
                    end if;
6559
                    if (i = 1 and enable0_counter = "c1") then
6560
                        inclk_sclkout0_from_vco <= vco_out(6);
6561
                    end if;
6562
                    if (i = 1 and enable1_counter = "c1") then
6563
                        inclk_sclkout1_from_vco <= vco_out(6);
6564
                    end if;
6565
                end if;
6566
            end loop;
6567
            if (m_ph_val = 6) then
6568
                inclk_m_from_vco <= vco_out(6);
6569
            end if;
6570
        end if;
6571
        if (vco_out(7)'event) then
6572
            for i in 0 to 5 loop
6573
                if (c_ph_val(i) = 7) then
6574
                    inclk_c_from_vco(i) <= vco_out(7);
6575
                    if (i = 0 and enable0_counter = "c0") then
6576
                        inclk_sclkout0_from_vco <= vco_out(7);
6577
                    end if;
6578
                    if (i = 0 and enable1_counter = "c0") then
6579
                        inclk_sclkout1_from_vco <= vco_out(7);
6580
                    end if;
6581
                    if (i = 1 and enable0_counter = "c1") then
6582
                        inclk_sclkout0_from_vco <= vco_out(7);
6583
                    end if;
6584
                    if (i = 1 and enable1_counter = "c1") then
6585
                        inclk_sclkout1_from_vco <= vco_out(7);
6586
                    end if;
6587
                end if;
6588
            end loop;
6589
            if (m_ph_val = 7) then
6590
                inclk_m_from_vco <= vco_out(7);
6591
            end if;
6592
        end if;
6593
 
6594
      ------------------------
6595
      --  Timing Check Section
6596
      ------------------------
6597
      if (TimingChecksOn) then
6598
         VitalSetupHoldCheck (
6599
              Violation       => Tviol_scandata_scanclk,
6600
              TimingData      => TimingData_scandata_scanclk,
6601
              TestSignal      => scandata_ipd,
6602
              TestSignalName  => "scandata",
6603
              RefSignal       => scanclk_ipd,
6604
              RefSignalName   => "scanclk",
6605
              SetupHigh       => tsetup_scandata_scanclk_noedge_posedge,
6606
              SetupLow        => tsetup_scandata_scanclk_noedge_posedge,
6607
              HoldHigh        => thold_scandata_scanclk_noedge_posedge,
6608
              HoldLow         => thold_scandata_scanclk_noedge_posedge,
6609
--                    CheckEnabled    => TO_X01( (NOT ena_ipd) ) /= '1',
6610
              RefTransition   => '/',
6611
              HeaderMsg       => InstancePath & "/stratixii_pll",
6612
              XOn             => XOnChecks,
6613
              MsgOn           => MsgOnChecks );
6614
 
6615
         VitalSetupHoldCheck (
6616
              Violation       => Tviol_scanread_scanclk,
6617
              TimingData      => TimingData_scanread_scanclk,
6618
              TestSignal      => scanread_ipd,
6619
              TestSignalName  => "scanread",
6620
              RefSignal       => scanclk_ipd,
6621
              RefSignalName   => "scanclk",
6622
              SetupHigh       => tsetup_scanread_scanclk_noedge_posedge,
6623
              SetupLow        => tsetup_scanread_scanclk_noedge_posedge,
6624
              HoldHigh        => thold_scanread_scanclk_noedge_posedge,
6625
              HoldLow         => thold_scanread_scanclk_noedge_posedge,
6626
--                    CheckEnabled    => TO_X01( (NOT ena_ipd) ) /= '1',
6627
              RefTransition   => '/',
6628
              HeaderMsg       => InstancePath & "/stratixii_pll",
6629
              XOn             => XOnChecks,
6630
              MsgOn           => MsgOnChecks );
6631
 
6632
         VitalSetupHoldCheck (
6633
              Violation       => Tviol_scanwrite_scanclk,
6634
              TimingData      => TimingData_scanwrite_scanclk,
6635
              TestSignal      => scanwrite_ipd,
6636
              TestSignalName  => "scanwrite",
6637
              RefSignal       => scanclk_ipd,
6638
              RefSignalName   => "scanclk",
6639
              SetupHigh       => tsetup_scanwrite_scanclk_noedge_posedge,
6640
              SetupLow        => tsetup_scanwrite_scanclk_noedge_posedge,
6641
              HoldHigh        => thold_scanwrite_scanclk_noedge_posedge,
6642
              HoldLow         => thold_scanwrite_scanclk_noedge_posedge,
6643
--                    CheckEnabled    => TO_X01( (NOT ena_ipd) ) /= '1',
6644
              RefTransition   => '/',
6645
              HeaderMsg       => InstancePath & "/stratixii_pll",
6646
              XOn             => XOnChecks,
6647
              MsgOn           => MsgOnChecks );
6648
 
6649
      end if;
6650
 
6651
        if (scanclk_ipd'event and scanclk_ipd = '0') then
6652
            -- enable scanwrite on falling edge
6653
            scanwrite_enabled <= scanwrite_reg;
6654
        end if;
6655
 
6656
        if (scanread_reg = '1') then
6657
            gated_scanclk <= transport scanclk_ipd and scanread_reg;
6658
        else
6659
            gated_scanclk <= transport '1';
6660
        end if;
6661
 
6662
        if (scanclk_ipd'event and scanclk_ipd = '1') then
6663
            -- register scanread and scanwrite
6664
            scanread_reg <= scanread_ipd;
6665
            scanwrite_reg <= scanwrite_ipd;
6666
 
6667
            if (got_first_scanclk) then
6668
                scanclk_period := now - scanclk_last_rising_edge;
6669
            else
6670
                got_first_scanclk := true;
6671
            end if;
6672
            -- reset got_first_scanclk on falling edge of scanread_reg
6673
            if (scanread_ipd = '0' and scanread_reg = '1') then
6674
                got_first_scanclk := false;
6675
                got_first_gated_scanclk := false;
6676
            end if;
6677
 
6678
            scanclk_last_rising_edge := now;
6679
        end if;
6680
 
6681
        if (gated_scanclk'event and gated_scanclk = '1' and now > 0 ps) then
6682
            if (not got_first_gated_scanclk) then
6683
                got_first_gated_scanclk := true;
6684
            end if;
6685
            for j in scan_chain_length - 1 downto 1 loop
6686
                scan_data(j) <= scan_data(j-1);
6687
            end loop;
6688
            scan_data(0) <= scandata_ipd;
6689
        end if;
6690
    end process;
6691
 
6692
    scandataout_tmp <= scan_data(FAST_SCAN_CHAIN-1) when (pll_type = "fast" or pll_type = "lvds") else scan_data(GPP_SCAN_CHAIN-1);
6693
 
6694
    process (schedule_vco, areset_ipd, ena_ipd, pfdena_ipd, refclk, fbclk)
6695
    variable sched_time : time := 0 ps;
6696
 
6697
    TYPE time_array is ARRAY (0 to 7) of time;
6698
    variable init : boolean := true;
6699
    variable refclk_period : time;
6700
    variable m_times_vco_period : time;
6701
    variable new_m_times_vco_period : time;
6702
 
6703
    variable phase_shift : time_array := (OTHERS => 0 ps);
6704
    variable last_phase_shift : time_array := (OTHERS => 0 ps);
6705
 
6706
    variable l_index : integer := 1;
6707
    variable cycle_to_adjust : integer := 0;
6708
 
6709
    variable stop_vco : boolean := false;
6710
 
6711
    variable locked_tmp : std_logic := '0';
6712
    variable pll_is_locked : boolean := false;
6713
    variable pll_about_to_lock : boolean := false;
6714
    variable cycles_to_lock : integer := 0;
6715
    variable cycles_to_unlock : integer := 0;
6716
 
6717
    variable got_first_refclk : boolean := false;
6718
    variable got_second_refclk : boolean := false;
6719
    variable got_first_fbclk : boolean := false;
6720
 
6721
    variable refclk_time : time := 0 ps;
6722
    variable fbclk_time : time := 0 ps;
6723
    variable first_fbclk_time : time := 0 ps;
6724
 
6725
    variable fbclk_period : time := 0 ps;
6726
 
6727
    variable first_schedule : boolean := true;
6728
 
6729
    variable vco_val : std_logic := '0';
6730
    variable vco_period_was_phase_adjusted : boolean := false;
6731
    variable phase_adjust_was_scheduled : boolean := false;
6732
 
6733
    variable loop_xplier : integer;
6734
    variable loop_initial : integer := 0;
6735
    variable loop_ph : integer := 0;
6736
    variable loop_time_delay : integer := 0;
6737
 
6738
    variable initial_delay : time := 0 ps;
6739
    variable vco_per : time;
6740
    variable tmp_rem : integer;
6741
    variable my_rem : integer;
6742
    variable fbk_phase : integer := 0;
6743
 
6744
    variable pull_back_M : integer := 0;
6745
    variable total_pull_back : integer := 0;
6746
    variable fbk_delay : integer := 0;
6747
 
6748
    variable offset : time := 0 ps;
6749
 
6750
    variable tmp_vco_per : integer := 0;
6751
    variable high_time : time;
6752
    variable low_time : time;
6753
 
6754
    variable got_refclk_posedge : boolean := false;
6755
    variable got_fbclk_posedge : boolean := false;
6756
    variable inclk_out_of_range : boolean := false;
6757
    variable no_warn : boolean := false;
6758
 
6759
    variable ext_fbk_cntr_modulus : integer := 1;
6760
    variable init_clks : boolean := true;
6761
    variable pll_is_in_reset : boolean := false;
6762
    begin
6763
        if (init) then
6764
 
6765
            -- jump-start the VCO
6766
            -- add 1 ps delay to ensure all signals are updated to initial
6767
            -- values
6768
            schedule_vco <= transport not schedule_vco after 1 ps;
6769
 
6770
            init := false;
6771
        end if;
6772
 
6773
        if (schedule_vco'event) then
6774
            if (init_clks) then
6775
                refclk_period := inclk0_input_frequency * n_val(0) * 1 ps;
6776
 
6777
                m_times_vco_period := refclk_period;
6778
                new_m_times_vco_period := refclk_period;
6779
                init_clks := false;
6780
            end if;
6781
            sched_time := 0 ps;
6782
            for i in 0 to 7 loop
6783
                last_phase_shift(i) := phase_shift(i);
6784
            end loop;
6785
            cycle_to_adjust := 0;
6786
            l_index := 1;
6787
            m_times_vco_period := new_m_times_vco_period;
6788
        end if;
6789
 
6790
        -- areset was asserted
6791
        if (areset_ipd'event and areset_ipd = '1') then
6792
            assert false report "PLL was reset" severity note;
6793
            -- reset lock parameters
6794
            locked_tmp := '0';
6795
            pll_is_locked := false;
6796
            pll_about_to_lock := false;
6797
            cycles_to_lock := 0;
6798
            cycles_to_unlock := 0;
6799
        end if;
6800
 
6801
        -- ena was deasserted
6802
        if (ena_ipd'event and ena_ipd = '0') then
6803
            assert false report "PLL was disabled" severity note;
6804
        end if;
6805
 
6806
        if (schedule_vco'event and (areset_ipd = '1' or ena_ipd = '0' or stop_vco)) then
6807
 
6808
            if (areset_ipd = '1') then
6809
                pll_is_in_reset := true;
6810
            end if;
6811
 
6812
            -- drop VCO taps to 0
6813
            for i in 0 to 7 loop
6814
                vco_out(i) <= transport '0' after last_phase_shift(i);
6815
                phase_shift(i) := 0 ps;
6816
                last_phase_shift(i) := 0 ps;
6817
            end loop;
6818
 
6819
            -- reset lock parameters
6820
            locked_tmp := '0';
6821
            pll_is_locked := false;
6822
            pll_about_to_lock := false;
6823
            cycles_to_lock := 0;
6824
            cycles_to_unlock := 0;
6825
 
6826
            got_first_refclk := false;
6827
            got_second_refclk := false;
6828
            refclk_time := 0 ps;
6829
            got_first_fbclk := false;
6830
            fbclk_time := 0 ps;
6831
            first_fbclk_time := 0 ps;
6832
            fbclk_period := 0 ps;
6833
 
6834
            first_schedule := true;
6835
            vco_val := '0';
6836
            vco_period_was_phase_adjusted := false;
6837
            phase_adjust_was_scheduled := false;
6838
 
6839
        elsif ((schedule_vco'event or ena_ipd'event or areset_ipd'event) and areset_ipd = '0' and ena_ipd = '1' and (not stop_vco) and now > 0 ps) then
6840
 
6841
            -- note areset deassert time
6842
            -- note it as refclk_time to prevent false triggering
6843
            -- of stop_vco after areset
6844
            if (areset_ipd'event and areset_ipd = '0' and pll_is_in_reset) then
6845
                refclk_time := now;
6846
                pll_is_in_reset := false;
6847
            end if;
6848
 
6849
            -- calculate loop_xplier : this will be different from m_val
6850
            -- in external_feedback_mode
6851
            loop_xplier := m_val(0);
6852
            loop_initial := m_initial_val - 1;
6853
            loop_ph := m_ph_val;
6854
 
6855
            if (operation_mode = "external_feedback") then
6856
                if (ext_fbk_cntr_mode = "bypass") then
6857
                    ext_fbk_cntr_modulus := 1;
6858
                else
6859
                    ext_fbk_cntr_modulus := ext_fbk_cntr_high + ext_fbk_cntr_low;
6860
                end if;
6861
                loop_xplier := m_val(0) * (ext_fbk_cntr_modulus);
6862
                loop_ph := ext_fbk_cntr_ph;
6863
                loop_initial := ext_fbk_cntr_initial - 1 + ((m_initial_val - 1) * ext_fbk_cntr_modulus);
6864
            end if;
6865
 
6866
            -- convert initial value to delay
6867
            initial_delay := (loop_initial * m_times_vco_period)/loop_xplier;
6868
 
6869
            -- convert loop ph_tap to delay
6870
            my_rem := (m_times_vco_period/1 ps) rem loop_xplier;
6871
            tmp_vco_per := (m_times_vco_period/1 ps) / loop_xplier;
6872
            if (my_rem /= 0) then
6873
                tmp_vco_per := tmp_vco_per + 1;
6874
            end if;
6875
            fbk_phase := (loop_ph * tmp_vco_per)/8;
6876
 
6877
            if (operation_mode = "external_feedback") then
6878
                pull_back_M :=  (m_initial_val - 1) * ext_fbk_cntr_modulus * ((refclk_period/loop_xplier)/1 ps);
6879
                while (pull_back_M > refclk_period/1 ps) loop
6880
                    pull_back_M := pull_back_M - refclk_period/ 1 ps;
6881
                end loop;
6882
            else
6883
                pull_back_M := initial_delay/1 ps + fbk_phase;
6884
            end if;
6885
 
6886
            total_pull_back := pull_back_M;
6887
 
6888
            if (simulation_type = "timing") then
6889
                total_pull_back := total_pull_back + pll_compensation_delay;
6890
            end if;
6891
            while (total_pull_back > refclk_period/1 ps) loop
6892
                total_pull_back := total_pull_back - refclk_period/1 ps;
6893
            end loop;
6894
 
6895
            if (total_pull_back > 0) then
6896
                offset := refclk_period - (total_pull_back * 1 ps);
6897
            end if;
6898
            if (operation_mode = "external_feedback") then
6899
                fbk_delay := pull_back_M;
6900
                if (simulation_type = "timing") then
6901
                    fbk_delay := fbk_delay + pll_compensation_delay;
6902
                end if;
6903
            else
6904
                fbk_delay := total_pull_back - fbk_phase;
6905
                if (fbk_delay < 0) then
6906
                    offset := offset - (fbk_phase * 1 ps);
6907
                    fbk_delay := total_pull_back;
6908
                end if;
6909
            end if;
6910
 
6911
            -- assign m_delay
6912
            m_delay <= transport fbk_delay after 1 ps;
6913
 
6914
            my_rem := (m_times_vco_period/1 ps) rem loop_xplier;
6915
            for i in 1 to loop_xplier loop
6916
                -- adjust cycles
6917
                tmp_vco_per := (m_times_vco_period/1 ps)/loop_xplier;
6918
                if (my_rem /= 0 and l_index <= my_rem) then
6919
                    tmp_rem := (loop_xplier * l_index) rem my_rem;
6920
                    cycle_to_adjust := (loop_xplier * l_index) / my_rem;
6921
                    if (tmp_rem /= 0) then
6922
                        cycle_to_adjust := cycle_to_adjust + 1;
6923
                    end if;
6924
                end if;
6925
                if (cycle_to_adjust = i) then
6926
                    tmp_vco_per := tmp_vco_per + 1;
6927
                    l_index := l_index + 1;
6928
                end if;
6929
 
6930
                -- calculate high and low periods
6931
                vco_per := tmp_vco_per * 1 ps;
6932
                high_time := (tmp_vco_per/2) * 1 ps;
6933
                if (tmp_vco_per rem 2 /= 0) then
6934
                    high_time := high_time + 1 ps;
6935
                end if;
6936
                low_time := vco_per - high_time;
6937
 
6938
                -- schedule the rising and falling edges
6939
                for j in 1 to 2 loop
6940
                    vco_val := not vco_val;
6941
                    if (vco_val = '0') then
6942
                        sched_time := sched_time + high_time;
6943
                    elsif (vco_val = '1') then
6944
                        sched_time := sched_time + low_time;
6945
                    end if;
6946
 
6947
                    -- schedule the phase taps
6948
                    for k in 0 to 7 loop
6949
                        phase_shift(k) := (k * vco_per)/8;
6950
                        if (first_schedule) then
6951
                            vco_out(k) <= transport vco_val after (sched_time + phase_shift(k));
6952
                        else
6953
                            vco_out(k) <= transport vco_val after (sched_time + last_phase_shift(k));
6954
                        end if;
6955
                    end loop;
6956
                end loop;
6957
            end loop;
6958
 
6959
            -- schedule once more
6960
            if (first_schedule) then
6961
                vco_val := not vco_val;
6962
                if (vco_val = '0') then
6963
                    sched_time := sched_time + high_time;
6964
                elsif (vco_val = '1') then
6965
                    sched_time := sched_time + low_time;
6966
                end if;
6967
                -- schedule the phase taps
6968
                for k in 0 to 7 loop
6969
                    phase_shift(k) := (k * vco_per)/8;
6970
                    vco_out(k) <= transport vco_val after (sched_time + phase_shift(k));
6971
                end loop;
6972
                first_schedule := false;
6973
            end if;
6974
 
6975
            schedule_vco <= transport not schedule_vco after sched_time;
6976
 
6977
            if (vco_period_was_phase_adjusted) then
6978
                m_times_vco_period := refclk_period;
6979
                new_m_times_vco_period := refclk_period;
6980
                vco_period_was_phase_adjusted := false;
6981
                phase_adjust_was_scheduled := true;
6982
 
6983
                vco_per := m_times_vco_period/loop_xplier;
6984
                for k in 0 to 7 loop
6985
                    phase_shift(k) := (k * vco_per)/8;
6986
                end loop;
6987
            end if;
6988
        end if;
6989
 
6990
        if (refclk'event and refclk = '1' and areset_ipd = '0') then
6991
            got_refclk_posedge := true;
6992
            if (not got_first_refclk) then
6993
                got_first_refclk := true;
6994
            else
6995
                got_second_refclk := true;
6996
                refclk_period := now - refclk_time;
6997
 
6998
                -- check if incoming freq. will cause VCO range to be
6999
                -- exceeded
7000
                if ( (vco_max /= 0 and vco_min /= 0 and pfdena_ipd = '1') and
7001
                    (((refclk_period/1 ps)/loop_xplier > vco_max) or
7002
                    ((refclk_period/1 ps)/loop_xplier < vco_min)) ) then
7003
                    if (pll_is_locked) then
7004
                        assert false report " Input clock freq. is not within VCO range : PLL may lose lock" severity warning;
7005
                        if (inclk_out_of_range) then
7006
                            pll_is_locked := false;
7007
                            locked_tmp := '0';
7008
                            pll_about_to_lock := false;
7009
                            cycles_to_lock := 0;
7010
                            vco_period_was_phase_adjusted := false;
7011
                            phase_adjust_was_scheduled := false;
7012
                            assert false report "Stratixii PLL lost lock." severity note;
7013
                        end if;
7014
                    elsif (not no_warn) then
7015
                        assert false report " Input clock freq. is not within VCO range : PLL may not lock. Please use the correct frequency." severity warning;
7016
                        no_warn := true;
7017
                    end if;
7018
                    inclk_out_of_range := true;
7019
                else
7020
                    inclk_out_of_range := false;
7021
                end if;
7022
            end if;
7023
 
7024
            if (stop_vco) then
7025
                stop_vco := false;
7026
                schedule_vco <= not schedule_vco;
7027
            end if;
7028
 
7029
            refclk_time := now;
7030
        else
7031
            got_refclk_posedge := false;
7032
        end if;
7033
 
7034
        if (fbclk'event and fbclk = '1') then
7035
            got_fbclk_posedge := true;
7036
            if (not got_first_fbclk) then
7037
                got_first_fbclk := true;
7038
            else
7039
                fbclk_period := now - fbclk_time;
7040
            end if;
7041
 
7042
            -- need refclk_period here, so initialized to proper value above
7043
            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
7044
                stop_vco := true;
7045
                -- reset
7046
                got_first_refclk := false;
7047
                got_first_fbclk := false;
7048
                got_second_refclk := false;
7049
                if (pll_is_locked) then
7050
                    pll_is_locked := false;
7051
                    locked_tmp := '0';
7052
                    assert false report "PLL lost lock due to loss of input clock" severity note;
7053
                end if;
7054
                pll_about_to_lock := false;
7055
                cycles_to_lock := 0;
7056
                cycles_to_unlock := 0;
7057
                first_schedule := true;
7058
                vco_period_was_phase_adjusted := false;
7059
                phase_adjust_was_scheduled := false;
7060
            end if;
7061
            fbclk_time := now;
7062
        else
7063
            got_fbclk_posedge := false;
7064
        end if;
7065
 
7066
        if ((got_refclk_posedge or got_fbclk_posedge) and got_second_refclk and pfdena_ipd = '1' and (not inclk_out_of_range)) then
7067
 
7068
            -- now we know actual incoming period
7069
            if ( abs(fbclk_time - refclk_time) <= 5 ps or
7070
                (got_first_fbclk and abs(refclk_period - abs(fbclk_time - refclk_time)) <= 5 ps)) then
7071
                -- considered in phase
7072
                if (cycles_to_lock = valid_lock_multiplier - 1) then
7073
                    pll_about_to_lock := true;
7074
                end if;
7075
                if (cycles_to_lock = valid_lock_multiplier) then
7076
                    if (not pll_is_locked) then
7077
                        assert false report "PLL locked to incoming clock" severity note;
7078
                    end if;
7079
                    pll_is_locked := true;
7080
                    locked_tmp := '1';
7081
                    cycles_to_unlock := 0;
7082
                end if;
7083
                -- increment lock counter only if second part of above
7084
                -- time check is NOT true
7085
                if (not(abs(refclk_period - abs(fbclk_time - refclk_time)) <= 5 ps)) then
7086
                    cycles_to_lock := cycles_to_lock + 1;
7087
                end if;
7088
 
7089
                -- adjust m_times_vco_period
7090
                new_m_times_vco_period := refclk_period;
7091
            else
7092
                -- if locked, begin unlock
7093
                if (pll_is_locked) then
7094
                    cycles_to_unlock := cycles_to_unlock + 1;
7095
                    if (cycles_to_unlock = invalid_lock_multiplier) then
7096
                        pll_is_locked := false;
7097
                        locked_tmp := '0';
7098
                        pll_about_to_lock := false;
7099
                        cycles_to_lock := 0;
7100
                        vco_period_was_phase_adjusted := false;
7101
                        phase_adjust_was_scheduled := false;
7102
                        assert false report "PLL lost lock." severity note;
7103
                    end if;
7104
                end if;
7105
                if ( abs(refclk_period - fbclk_period) <= 2 ps ) then
7106
                    -- frequency is still good
7107
                    if (now = fbclk_time and (not phase_adjust_was_scheduled)) then
7108
                        if ( abs(fbclk_time - refclk_time) > refclk_period/2) then
7109
                            new_m_times_vco_period := m_times_vco_period + (refclk_period - abs(fbclk_time - refclk_time));
7110
                            vco_period_was_phase_adjusted := true;
7111
                        else
7112
                            new_m_times_vco_period := m_times_vco_period - abs(fbclk_time - refclk_time);
7113
                            vco_period_was_phase_adjusted := true;
7114
                        end if;
7115
 
7116
                    end if;
7117
                else
7118
                    phase_adjust_was_scheduled := false;
7119
                    new_m_times_vco_period := refclk_period;
7120
                end if;
7121
            end if;
7122
        end if;
7123
 
7124
        if (pfdena_ipd = '0') then
7125
            if (pll_is_locked) then
7126
                locked_tmp := 'X';
7127
            end if;
7128
            pll_is_locked := false;
7129
            cycles_to_lock := 0;
7130
        end if;
7131
 
7132
        -- give message only at time of deassertion
7133
        if (pfdena_ipd'event and pfdena_ipd = '0') then
7134
            assert false report "PFDENA deasserted." severity note;
7135
        elsif (pfdena_ipd'event and pfdena_ipd = '1') then
7136
            got_first_refclk := false;
7137
            got_second_refclk := false;
7138
            refclk_time := now;
7139
        end if;
7140
 
7141
        if (reconfig_err) then
7142
            lock <= '0';
7143
        else
7144
            lock <= locked_tmp;
7145
        end if;
7146
        about_to_lock <= pll_about_to_lock after 1 ps;
7147
 
7148
        -- signal to calculate quiet_time
7149
        sig_refclk_period <= refclk_period;
7150
 
7151
        if (stop_vco = true) then
7152
            sig_stop_vco <= '1';
7153
        else
7154
            sig_stop_vco <= '0';
7155
        end if;
7156
    end process;
7157
 
7158
    clk0_tmp <= c_clk(i_clk0_counter);
7159
--    clk0_tmp <= c0_clk when i_clk0_counter = "c0" else
7160
--                c_clk(1) when i_clk0_counter = "c1" else
7161
--                c2_clk when i_clk0_counter = "c2" else
7162
--                c3_clk when i_clk0_counter = "c3" else
7163
--                c4_clk when i_clk0_counter = "c4" else
7164
--                c5_clk when i_clk0_counter = "c5" else
7165
--                '0';
7166
    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
7167
                'X';
7168
 
7169
    clk1_tmp <= c_clk(i_clk1_counter);
7170
--    clk1_tmp <= c_clk(0) when i_clk1_counter = "c0" else
7171
--                c_clk(1) when i_clk1_counter = "c1" else
7172
--                c2_clk when i_clk1_counter = "c2" else
7173
--                c3_clk when i_clk1_counter = "c3" else
7174
--                c4_clk when i_clk1_counter = "c4" else
7175
--                c5_clk when i_clk1_counter = "c5" else
7176
--                '0';
7177
    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
7178
                'X';
7179
 
7180
    clk2_tmp <= c_clk(i_clk2_counter);
7181
--    clk2_tmp <= c_clk(0) when i_clk2_counter = "c0" else
7182
--                c_clk(1) when i_clk2_counter = "c1" else
7183
--                c2_clk when i_clk2_counter = "c2" else
7184
--                c3_clk when i_clk2_counter = "c3" else
7185
--                c4_clk when i_clk2_counter = "c4" else
7186
--                c5_clk when i_clk2_counter = "c5" else
7187
--                '0';
7188
    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
7189
                'X';
7190
 
7191
    clk3_tmp <= c_clk(i_clk3_counter);
7192
--    clk3_tmp <= c_clk(0) when i_clk3_counter = "c0" else
7193
--                c_clk(1) when i_clk3_counter = "c1" else
7194
--                c2_clk when i_clk3_counter = "c2" else
7195
--                c3_clk when i_clk3_counter = "c3" else
7196
--                c4_clk when i_clk3_counter = "c4" else
7197
--                c5_clk when i_clk3_counter = "c5" else
7198
--                '0';
7199
    clk(3)   <= clk3_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
7200
                'X';
7201
 
7202
    clk4_tmp <= c_clk(i_clk4_counter);
7203
--    clk4_tmp <= c_clk(0) when i_clk4_counter = "c0" else
7204
--                c_clk(1) when i_clk4_counter = "c1" else
7205
--                c2_clk when i_clk4_counter = "c2" else
7206
--                c3_clk when i_clk4_counter = "c3" else
7207
--                c4_clk when i_clk4_counter = "c4" else
7208
--                c5_clk when i_clk4_counter = "c5" else
7209
--                '0';
7210
    clk(4)   <= clk4_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
7211
                'X';
7212
 
7213
    clk5_tmp <= c_clk(i_clk5_counter);
7214
--    clk5_tmp <= c_clk(0) when i_clk5_counter = "c0" else
7215
--                c_clk(1) when i_clk5_counter = "c1" else
7216
--                c2_clk when i_clk5_counter = "c2" else
7217
--                c3_clk when i_clk5_counter = "c3" else
7218
--                c4_clk when i_clk5_counter = "c4" else
7219
--                c5_clk when i_clk5_counter = "c5" else
7220
--                '0';
7221
    clk(5)   <= clk5_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
7222
                'X';
7223
 
7224
    sclkout(0) <= sclkout0_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
7225
                'X';
7226
 
7227
    sclkout(1) <= sclkout1_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
7228
                'X';
7229
 
7230
    enable0 <= enable0_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
7231
                'X';
7232
    enable1 <= enable1_tmp when (areset_ipd = '1' or ena_ipd = '0' or pll_in_test_mode) or (about_to_lock and (not reconfig_err)) else
7233
                'X';
7234
 
7235
    scandataout <= scandataout_tmp;
7236
    scandone <= scandone_tmp;
7237
 
7238
end vital_pll;
7239
-- END ARCHITECTURE VITAL_PLL
7240
--/////////////////////////////////////////////////////////////////////////////
7241
--
7242
-- Entity Name : stratixii_mac_bit_register
7243
--
7244
-- Description : a single bit register. This is used for registering all
7245
--               single bit input ports.
7246
--
7247
--/////////////////////////////////////////////////////////////////////////////
7248
 
7249
LIBRARY IEEE;
7250
USE ieee.std_logic_1164.all;
7251
use IEEE.VITAL_Timing.all;
7252
use IEEE.VITAL_Primitives.all;
7253
use work.stratixii_atom_pack.all;
7254
 
7255
ENTITY stratixii_mac_bit_register IS
7256
    GENERIC (
7257
             power_up :  std_logic := '0';
7258
             tipd_data : VitalDelayType01 := DefPropDelay01;
7259
             tipd_clk : VitalDelayType01 := DefPropDelay01;
7260
             tipd_ena : VitalDelayType01 := DefPropDelay01;
7261
             tipd_aclr : VitalDelayType01 := DefPropDelay01;
7262
             tpd_aclr_dataout_posedge : VitalDelayType01 := DefPropDelay01;
7263
             tpd_clk_dataout_posedge : VitalDelayType01 := DefPropDelay01;
7264
             tsetup_data_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7265
             thold_data_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7266
             tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7267
             thold_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst);
7268
   PORT (
7269
         data : IN std_logic := '0';
7270
         clk : IN std_logic := '0';
7271
         aclr : IN std_logic := '0';
7272
         if_aclr : IN std_logic := '0';
7273
         ena : IN std_logic := '1';
7274
         async : IN std_logic := '1';
7275
         dataout : OUT std_logic :=  '0'
7276
        );
7277
END stratixii_mac_bit_register;
7278
 
7279
ARCHITECTURE arch OF stratixii_mac_bit_register IS
7280
 
7281
    SIGNAL data_ipd : std_logic := '0';
7282
    SIGNAL clk_ipd : std_logic := '0';
7283
    SIGNAL aclr_ipd : std_logic := '0';
7284
    SIGNAL ena_ipd : std_logic := '1';
7285
    SIGNAL dataout_reg : std_logic := '0';
7286
    SIGNAL viol_notifier : std_logic := '0';
7287
    SIGNAL data_dly : std_logic := '0';
7288
 
7289
BEGIN
7290
 
7291
    WireDelay : block
7292
    begin
7293
        VitalWireDelay (data_ipd, data, tipd_data);
7294
        VitalWireDelay (clk_ipd, clk, tipd_clk);
7295
        VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
7296
        VitalWireDelay (ena_ipd, ena, tipd_ena);
7297
    end block;
7298
 
7299
    clk_delay: process (data_ipd)
7300
        begin
7301
            data_dly <= data_ipd;
7302
        end process;
7303
 
7304
    PROCESS (data_dly, clk_ipd, aclr_ipd, ena_ipd, async)
7305
    variable dataout_reg       : STD_LOGIC := '0';
7306
    variable dataout_VitalGlitchData : VitalGlitchDataType;
7307
    variable Tviol_clk_ena     : STD_ULOGIC := '0';
7308
    variable Tviol_data_clk    : STD_ULOGIC := '0';
7309
    variable TimingData_clk_ena : VitalTimingDataType := VitalTimingDataInit;
7310
    variable TimingData_data_clk : VitalTimingDataType := VitalTimingDataInit;
7311
    variable Tviol_ena         : STD_ULOGIC := '0';
7312
    variable PeriodData_ena    : VitalPeriodDataType := VitalPeriodDataInit;
7313
    BEGIN
7314
        if(async = '1') then
7315
            dataout_reg := data_dly;
7316
        else
7317
           if (if_aclr = '1') then
7318
               IF (aclr_ipd = '1') THEN
7319
                   dataout_reg := '0';
7320
               ELSIF (clk_ipd'EVENT AND clk_ipd = '1') THEN
7321
                   IF (ena_ipd = '1') THEN
7322
                       dataout_reg := data_dly;
7323
                   ELSE
7324
                       dataout_reg := dataout_reg;
7325
                   END IF;
7326
               END IF;
7327
           else
7328
               IF (clk_ipd'EVENT AND clk_ipd = '1') THEN
7329
                   IF (ena_ipd = '1') THEN
7330
                       dataout_reg := data_dly;
7331
                   ELSE
7332
                       dataout_reg := dataout_reg;
7333
                   END IF;
7334
               END IF;
7335
           end if;
7336
        end if;
7337
 
7338
        VitalPathDelay01 (
7339
            OutSignal     => dataout,
7340
            OutSignalName => "dataout",
7341
            OutTemp       => dataout_reg,
7342
            Paths         => (0 => (clk_ipd'last_event, tpd_clk_dataout_posedge, TRUE),
7343
            1 => (aclr_ipd'last_event, tpd_aclr_dataout_posedge, TRUE)),
7344
            GlitchData    => dataout_VitalGlitchData,
7345
            Mode          => DefGlitchMode,
7346
            XOn           => TRUE,
7347
            MsgOn         => TRUE );
7348
    END PROCESS;
7349
END arch;
7350
--/////////////////////////////////////////////////////////////////////////////
7351
--
7352
--                              STRATIXII_MAC_REGISTER
7353
--
7354
--/////////////////////////////////////////////////////////////////////////////
7355
 
7356
LIBRARY IEEE;
7357
USE ieee.std_logic_1164.all;
7358
use IEEE.VITAL_Timing.all;
7359
use IEEE.VITAL_Primitives.all;
7360
use work.stratixii_atom_pack.all;
7361
 
7362
ENTITY stratixii_mac_register IS
7363
   GENERIC (
7364
      data_width      :  integer := 18;
7365
      power_up        :  std_logic := '0';
7366
      tipd_data       : VitalDelayArrayType01(143 downto 0) := (OTHERS => DefPropDelay01);
7367
      tipd_clk        : VitalDelayType01 := DefPropDelay01;
7368
      tipd_ena        : VitalDelayType01 := DefPropDelay01;
7369
      tipd_aclr       : VitalDelayType01 := DefPropDelay01;
7370
      tpd_aclr_dataout_posedge  : VitalDelayType01 := DefPropDelay01;
7371
      tpd_clk_dataout_posedge   : VitalDelayType01 := DefPropDelay01;
7372
      tsetup_data_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7373
      thold_data_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7374
      tsetup_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
7375
      thold_ena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst);
7376
   PORT (
7377
      data                    : IN std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
7378
      clk                     : IN std_logic := '0';
7379
      aclr                    : IN std_logic := '0';
7380
      if_aclr                 : IN std_logic := '0';
7381
      ena                     : IN std_logic := '1';
7382
      async                   : IN std_logic := '1';
7383
      dataout                 : OUT std_logic_vector(data_width -1 DOWNTO 0) := (others => '0'));
7384
END stratixii_mac_register;
7385
 
7386
ARCHITECTURE arch OF stratixii_mac_register IS
7387
 
7388
   SIGNAL data_ipd                 :  std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
7389
   SIGNAL clk_ipd                  :  std_logic := '0';
7390
   SIGNAL aclr_ipd                 :  std_logic := '0';
7391
   SIGNAL ena_ipd                  :  std_logic := '1';
7392
   SIGNAL dataout_reg              :  std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
7393
   SIGNAL viol_notifier            :  std_logic := '0';
7394
 
7395
BEGIN
7396
 
7397
  WireDelay : block
7398
  begin
7399
    g1 : for i in data'range generate
7400
      VitalWireDelay (data_ipd(i), data(i), tipd_data(i));
7401
    end generate;
7402
    VitalWireDelay (clk_ipd, clk, tipd_clk);
7403
    VitalWireDelay (aclr_ipd, aclr, tipd_aclr);
7404
    VitalWireDelay (ena_ipd, ena, tipd_ena);
7405
  end block;
7406
 
7407
  PROCESS (data_ipd, clk_ipd, aclr_ipd, ena_ipd, async)
7408
     variable dataout_VitalGlitchDataArray : VitalGlitchDataArrayType(71 downto 0);
7409
     variable Tviol_clk_ena     : STD_ULOGIC := '0';
7410
     variable Tviol_data_clk    : STD_ULOGIC := '0';
7411
     variable TimingData_clk_ena : VitalTimingDataType := VitalTimingDataInit;
7412
     variable TimingData_data_clk : VitalTimingDataType := VitalTimingDataInit;
7413
     variable Tviol_ena         : STD_ULOGIC := '0';
7414
     variable PeriodData_ena    : VitalPeriodDataType := VitalPeriodDataInit;
7415
   BEGIN
7416
     if(async = '1') then
7417
       dataout_reg <= data_ipd;
7418
     else
7419
       if (if_aclr = '1') then
7420
         IF (aclr_ipd = '1') THEN
7421
           dataout_reg <= (others => '0');
7422
         ELSIF (clk_ipd'EVENT AND clk_ipd = '1') THEN
7423
           IF (ena_ipd = '1') THEN
7424
             dataout_reg <= data_ipd;
7425
           ELSE
7426
             dataout_reg <= dataout_reg;
7427
           END IF;
7428
         END IF;
7429
       else
7430
         IF (clk_ipd'EVENT AND clk_ipd = '1') THEN
7431
           IF (ena_ipd = '1') THEN
7432
             dataout_reg <= data_ipd;
7433
           ELSE
7434
             dataout_reg <= dataout_reg;
7435
           END IF;
7436
         END IF;
7437
       end if;
7438
     end if;
7439
   END PROCESS;
7440
 
7441
  PathDelay : block
7442
  begin
7443
    g1 : for i in dataout'range generate
7444
      PROCESS (dataout_reg(i))
7445
        variable dataout_VitalGlitchData : VitalGlitchDataType;
7446
      begin
7447
        VitalPathDelay01 (
7448
          OutSignal     => dataout(i),
7449
          OutSignalName => "dataout",
7450
          OutTemp       => dataout_reg(i),
7451
          Paths         => (0 => (clk_ipd'last_event, tpd_clk_dataout_posedge, TRUE),
7452
                            1 => (aclr_ipd'last_event, tpd_aclr_dataout_posedge, TRUE)),
7453
          GlitchData    => dataout_VitalGlitchData,
7454
          Mode          => DefGlitchMode,
7455
          XOn           => TRUE,
7456
          MsgOn         => TRUE );
7457
      end process;
7458
    end generate;
7459
  end block;
7460
 
7461
END arch;
7462
 
7463
--/////////////////////////////////////////////////////////////////////////////
7464
--
7465
--                              STRATIXII_MAC_RS_BLOCK
7466
--
7467
--/////////////////////////////////////////////////////////////////////////////
7468
 
7469
LIBRARY IEEE;
7470
USE ieee.std_logic_1164.all;
7471
use IEEE.VITAL_Timing.all;
7472
use IEEE.VITAL_Primitives.all;
7473
use work.stratixii_atom_pack.all;
7474
library grlib;
7475
use grlib.stdlib.all;
7476
 
7477
ENTITY stratixii_mac_rs_block IS
7478
   GENERIC (
7479
     tpd_saturate_dataout           : VitalDelayType01 := DefPropDelay01;
7480
     tpd_round_dataout              : VitalDelayType01 := DefPropDelay01;
7481
     block_type                     :  string := "mac_mult";
7482
     dataa_width                    :  integer := 18;
7483
     datab_width                    :  integer := 18);
7484
   PORT (
7485
      operation               : IN std_logic_vector(3 DOWNTO 0) := (others => '0');
7486
      round                   : IN std_logic := '0';
7487
      saturate                : IN std_logic := '0';
7488
      addnsub                 : IN std_logic := '0';
7489
      signa                   : IN std_logic := '0';
7490
      signb                   : IN std_logic := '0';
7491
      signsize                : IN std_logic_vector(7 DOWNTO 0) := (others => '0');
7492
      roundsize               : IN std_logic_vector(7 DOWNTO 0) := (others => '0');
7493
      dataoutsize             : IN std_logic_vector(7 DOWNTO 0) := (others => '0');
7494
      dataa                   : IN std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
7495
      datab                   : IN std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
7496
      datain                  : IN std_logic_vector(71 DOWNTO 0) := (others => '0');
7497
      dataout                 : OUT std_logic_vector(71 DOWNTO 0) := (others => '0'));
7498
END stratixii_mac_rs_block;
7499
 
7500
ARCHITECTURE arch OF stratixii_mac_rs_block IS
7501
 
7502
   SIGNAL round_ipd                :  std_logic := '0';
7503
   SIGNAL saturate_ipd             :  std_logic := '0';
7504
   SIGNAL addnsub_ipd              :  std_logic := '0';
7505
   SIGNAL signa_ipd                :  std_logic := '0';
7506
   SIGNAL signb_ipd                :  std_logic := '0';
7507
   SIGNAL dataa_ipd                :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7508
   SIGNAL datab_ipd                :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7509
   SIGNAL datain_ipd               :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7510
   SIGNAL dataout_tbuf             :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7511
   SIGNAL rs_saturate              :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7512
   SIGNAL rs_mac_mult              :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7513
   SIGNAL rs_mac_out               :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7514
   SIGNAL dataout_round            :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7515
   SIGNAL dataout_saturate         :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7516
   SIGNAL dataout_dly              :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7517
   SIGNAL saturated                :  std_logic := '0';
7518
   SIGNAL min                      :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7519
   SIGNAL max                      :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7520
   SIGNAL msb                      :  std_logic := '0';
7521
   SIGNAL dataout_tmp1            :  std_logic_vector(71 DOWNTO 0) := (others => '0');
7522
 
7523
BEGIN
7524
   round_ipd <= round ;
7525
   saturate_ipd <= saturate ;
7526
   addnsub_ipd <= addnsub ;
7527
   signa_ipd <= signa ;
7528
   signb_ipd <= signb ;
7529
   dataa_ipd(dataa_width-1 downto 0) <= dataa;
7530
   datab_ipd(datab_width-1 downto 0) <= datab;
7531
   datain_ipd(71 downto 0) <= datain(71 downto 0) ;
7532
   PROCESS (datain_ipd,
7533
            signa_ipd,
7534
            signb_ipd,
7535
            addnsub_ipd,
7536
            round_ipd)
7537
      VARIABLE dataout_round_tmp2  : std_logic_vector(71 DOWNTO 0);
7538
   BEGIN
7539
      IF (round_ipd = '1') THEN
7540
        dataout_round_tmp2 := datain_ipd + (2 **(conv_integer(dataoutsize - signsize - roundsize - "00000001")));
7541
      ELSE
7542
        dataout_round_tmp2 := datain_ipd;
7543
      END IF;
7544
      dataout_round <= dataout_round_tmp2;
7545
   END PROCESS;
7546
   PROCESS (datain_ipd,
7547
            signa_ipd,
7548
            signb_ipd,
7549
            round_ipd,
7550
            saturate_ipd,
7551
            addnsub_ipd,
7552
            dataout_round)
7553
      VARIABLE dataout_saturate_tmp3  : std_logic_vector(71 DOWNTO 0) := (others => '0');
7554
      VARIABLE saturated_tmp4  : std_logic := '0';
7555
      VARIABLE gnd       : std_logic_vector(71 DOWNTO 0) := (others => '0');
7556
      VARIABLE min_tmp5  : std_logic_vector(71 DOWNTO 0) := (others => '0');
7557
      VARIABLE max_tmp6  : std_logic_vector(71 DOWNTO 0) := (others => '0');
7558
      VARIABLE msb_tmp7  : std_logic := '0';
7559
      VARIABLE i         :  integer;
7560
   BEGIN
7561
      IF (saturate_ipd = '1') THEN
7562
         IF (block_type = "mac_mult") THEN
7563
            IF (dataout_round(dataa_width + datab_width - 1) = '0' AND dataout_round(dataa_width + datab_width - 2) = '1') THEN
7564
               dataout_saturate_tmp3 := "111111111111111111111111111111111111111111111111111111111111111111111111";
7565
               FOR i IN dataa_width + datab_width - 2 TO (72 - 1) LOOP
7566
                  dataout_saturate_tmp3(i) := '0';
7567
               END LOOP;
7568
               saturated_tmp4 := '1';
7569
            ELSE
7570
               dataout_saturate_tmp3 := dataout_round;
7571
               saturated_tmp4 := '0';
7572
            END IF;
7573
            min_tmp5 := dataout_saturate_tmp3;
7574
            max_tmp6 := dataout_saturate_tmp3;
7575
         ELSE
7576
           IF ((operation(2) = '1') AND ((block_type = "ab") OR (block_type = "cd"))) THEN
7577
             saturated_tmp4 := '0';
7578
             i := datab_width - 2;
7579
             WHILE (i < (datab_width + signsize - 2)) LOOP
7580
               IF (dataout_round(datab_width - 2) /= dataout_round(i)) THEN
7581
                 saturated_tmp4 := '1';
7582
               END IF;
7583
               i := i + 1;
7584
             END LOOP;
7585
             IF (saturated_tmp4 = '1') THEN
7586
               min_tmp5 := "111111111111111111111111111111111111111111111111111111111111111111111111";
7587
               max_tmp6 := "111111111111111111111111111111111111111111111111111111111111111111111111";
7588
               FOR i IN 0 TO ((datab_width - 2) - 1) LOOP
7589
                 max_tmp6(i) := '0';
7590
               END LOOP;
7591
               FOR i IN datab_width - 2 TO (72 - 1) LOOP
7592
                 min_tmp5(i) := '0';
7593
               END LOOP;
7594
             ELSE
7595
               dataout_saturate_tmp3 := dataout_round;
7596
             END IF;
7597
             msb_tmp7 := dataout_round(datab_width + 15);
7598
           ELSE
7599
             IF ((signa_ipd OR signb_ipd OR NOT addnsub_ipd) = '1') THEN
7600
               min_tmp5 := gnd + (2**((dataa_width)));
7601
               max_tmp6 := gnd + ((2**((dataa_width))) - 1);
7602
             ELSE
7603
               min_tmp5 := "000000000000000000000000000000000000000000000000000000000000000000000000";
7604
               max_tmp6 := gnd + ((2**((dataa_width + 1))) - 1);
7605
             END IF;
7606
             saturated_tmp4 := '0';
7607
             i := dataa_width - 2;
7608
             WHILE (i < (dataa_width + signsize - 1)) LOOP
7609
               IF (dataout_round(dataa_width - 2) /= dataout_round(i)) THEN
7610
                 saturated_tmp4 := '1';
7611
               END IF;
7612
               i := i + 1;
7613
             END LOOP;
7614
             msb_tmp7 := dataout_round(i);
7615
           END IF;
7616
           IF (saturated_tmp4 = '1') THEN
7617
             IF (msb_tmp7 = '1') THEN
7618
               dataout_saturate_tmp3 := max_tmp6;
7619
             ELSE
7620
               dataout_saturate_tmp3 := min_tmp5;
7621
             END IF;
7622
           ELSE
7623
             dataout_saturate_tmp3 := dataout_round;
7624
           END IF;
7625
         END IF;
7626
      ELSE
7627
        saturated_tmp4 := '0';
7628
        dataout_saturate_tmp3 := dataout_round;
7629
      END IF;
7630
      dataout_saturate <= dataout_saturate_tmp3;
7631
      saturated <= saturated_tmp4;
7632
      min <= min_tmp5;
7633
      max <= max_tmp6;
7634
      msb <= msb_tmp7;
7635
   END PROCESS;
7636
 
7637
   PROCESS (datain_ipd,
7638
            signa_ipd,
7639
            signb_ipd,
7640
            round_ipd,
7641
            saturate_ipd,
7642
            dataout_round,
7643
            dataout_saturate)
7644
      VARIABLE dataout_dly_tmp8 : std_logic_vector(71 DOWNTO 0);
7645
      VARIABLE i                :  integer;
7646
   BEGIN
7647
      IF (round_ipd = '1') THEN
7648
         dataout_dly_tmp8 := dataout_saturate;
7649
         i := 0;
7650
         WHILE (i < (dataoutsize - signsize - roundsize)) LOOP
7651
            dataout_dly_tmp8(i) := '0';
7652
            i := i + 1;
7653
         END LOOP;
7654
      ELSE
7655
         dataout_dly_tmp8 := dataout_saturate;
7656
      END IF;
7657
      dataout_dly <= dataout_dly_tmp8;
7658
   END PROCESS;
7659
   dataout_tbuf <= datain WHEN (operation = "0000") OR (operation = "0111") ELSE rs_saturate ;
7660
   rs_saturate <= rs_mac_mult WHEN (saturate_ipd = '1') ELSE rs_mac_out ;
7661
   rs_mac_mult <= (dataout_dly(71 DOWNTO 3) & "00" & saturated)
7662
                  WHEN ((saturate_ipd = '1') AND (saturated = '1') AND (block_type = "mac_mult")) ELSE rs_mac_out ;
7663
   rs_mac_out <= (dataout_dly(71 DOWNTO 3) & saturated & datain_ipd(1 DOWNTO 0))
7664
                 WHEN ((saturate_ipd = '1') AND (block_type /= "mac_mult")) ELSE dataout_dly ;
7665
 
7666
   PROCESS (dataout_tbuf)
7667
     VARIABLE dataout_VitalGlitchDataArray : VitalGlitchDataArrayType(71 downto 0);
7668
   BEGIN
7669
     VitalPathDelay01 (
7670
       OutSignal     => dataout(0),
7671
       OutSignalName => "dataout",
7672
       OutTemp       => dataout_tbuf(0),
7673
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7674
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7675
       GlitchData    => dataout_VitalGlitchDataArray(0),
7676
       Mode          => DefGlitchMode,
7677
       XOn           => TRUE,
7678
       MsgOn         => TRUE );
7679
     VitalPathDelay01 (
7680
       OutSignal     => dataout(1),
7681
       OutSignalName => "dataout",
7682
       OutTemp       => dataout_tbuf(1),
7683
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7684
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7685
       GlitchData    => dataout_VitalGlitchDataArray(1),
7686
       Mode          => DefGlitchMode,
7687
       XOn           => TRUE,
7688
       MsgOn         => TRUE );
7689
     VitalPathDelay01 (
7690
       OutSignal     => dataout(2),
7691
       OutSignalName => "dataout",
7692
       OutTemp       => dataout_tbuf(2),
7693
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7694
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7695
       GlitchData    => dataout_VitalGlitchDataArray(2),
7696
       Mode          => DefGlitchMode,
7697
       XOn           => TRUE,
7698
       MsgOn         => TRUE );
7699
     VitalPathDelay01 (
7700
       OutSignal     => dataout(3),
7701
       OutSignalName => "dataout",
7702
       OutTemp       => dataout_tbuf(3),
7703
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7704
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7705
       GlitchData    => dataout_VitalGlitchDataArray(3),
7706
       Mode          => DefGlitchMode,
7707
       XOn           => TRUE,
7708
       MsgOn         => TRUE );
7709
     VitalPathDelay01 (
7710
       OutSignal     => dataout(4),
7711
       OutSignalName => "dataout",
7712
       OutTemp       => dataout_tbuf(4),
7713
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7714
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7715
       GlitchData    => dataout_VitalGlitchDataArray(4),
7716
       Mode          => DefGlitchMode,
7717
       XOn           => TRUE,
7718
       MsgOn         => TRUE );
7719
     VitalPathDelay01 (
7720
       OutSignal     => dataout(5),
7721
       OutSignalName => "dataout",
7722
       OutTemp       => dataout_tbuf(5),
7723
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7724
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7725
       GlitchData    => dataout_VitalGlitchDataArray(5),
7726
       Mode          => DefGlitchMode,
7727
       XOn           => TRUE,
7728
       MsgOn         => TRUE );
7729
     VitalPathDelay01 (
7730
       OutSignal     => dataout(6),
7731
       OutSignalName => "dataout",
7732
       OutTemp       => dataout_tbuf(6),
7733
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7734
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7735
       GlitchData    => dataout_VitalGlitchDataArray(6),
7736
       Mode          => DefGlitchMode,
7737
       XOn           => TRUE,
7738
       MsgOn         => TRUE );
7739
     VitalPathDelay01 (
7740
       OutSignal     => dataout(7),
7741
       OutSignalName => "dataout",
7742
       OutTemp       => dataout_tbuf(7),
7743
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7744
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7745
       GlitchData    => dataout_VitalGlitchDataArray(7),
7746
       Mode          => DefGlitchMode,
7747
       XOn           => TRUE,
7748
       MsgOn         => TRUE );
7749
     VitalPathDelay01 (
7750
       OutSignal     => dataout(8),
7751
       OutSignalName => "dataout",
7752
       OutTemp       => dataout_tbuf(8),
7753
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7754
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7755
       GlitchData    => dataout_VitalGlitchDataArray(8),
7756
       Mode          => DefGlitchMode,
7757
       XOn           => TRUE,
7758
       MsgOn         => TRUE );
7759
     VitalPathDelay01 (
7760
       OutSignal     => dataout(9),
7761
       OutSignalName => "dataout",
7762
       OutTemp       => dataout_tbuf(9),
7763
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7764
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7765
       GlitchData    => dataout_VitalGlitchDataArray(9),
7766
       Mode          => DefGlitchMode,
7767
       XOn           => TRUE,
7768
       MsgOn         => TRUE );
7769
     VitalPathDelay01 (
7770
       OutSignal     => dataout(10),
7771
       OutSignalName => "dataout",
7772
       OutTemp       => dataout_tbuf(10),
7773
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7774
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7775
       GlitchData    => dataout_VitalGlitchDataArray(10),
7776
       Mode          => DefGlitchMode,
7777
       XOn           => TRUE,
7778
       MsgOn         => TRUE );
7779
     VitalPathDelay01 (
7780
       OutSignal     => dataout(11),
7781
       OutSignalName => "dataout",
7782
       OutTemp       => dataout_tbuf(11),
7783
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7784
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7785
       GlitchData    => dataout_VitalGlitchDataArray(11),
7786
       Mode          => DefGlitchMode,
7787
       XOn           => TRUE,
7788
       MsgOn         => TRUE );
7789
     VitalPathDelay01 (
7790
       OutSignal     => dataout(12),
7791
       OutSignalName => "dataout",
7792
       OutTemp       => dataout_tbuf(12),
7793
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7794
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7795
       GlitchData    => dataout_VitalGlitchDataArray(12),
7796
       Mode          => DefGlitchMode,
7797
       XOn           => TRUE,
7798
       MsgOn         => TRUE );
7799
     VitalPathDelay01 (
7800
       OutSignal     => dataout(13),
7801
       OutSignalName => "dataout",
7802
       OutTemp       => dataout_tbuf(13),
7803
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7804
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7805
       GlitchData    => dataout_VitalGlitchDataArray(13),
7806
       Mode          => DefGlitchMode,
7807
       XOn           => TRUE,
7808
       MsgOn         => TRUE );
7809
     VitalPathDelay01 (
7810
       OutSignal     => dataout(14),
7811
       OutSignalName => "dataout",
7812
       OutTemp       => dataout_tbuf(14),
7813
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7814
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7815
       GlitchData    => dataout_VitalGlitchDataArray(14),
7816
       Mode          => DefGlitchMode,
7817
       XOn           => TRUE,
7818
       MsgOn         => TRUE );
7819
     VitalPathDelay01 (
7820
       OutSignal     => dataout(15),
7821
       OutSignalName => "dataout",
7822
       OutTemp       => dataout_tbuf(15),
7823
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7824
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7825
       GlitchData    => dataout_VitalGlitchDataArray(15),
7826
       Mode          => DefGlitchMode,
7827
       XOn           => TRUE,
7828
       MsgOn         => TRUE );
7829
     VitalPathDelay01 (
7830
       OutSignal     => dataout(16),
7831
       OutSignalName => "dataout",
7832
       OutTemp       => dataout_tbuf(16),
7833
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7834
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7835
       GlitchData    => dataout_VitalGlitchDataArray(16),
7836
       Mode          => DefGlitchMode,
7837
       XOn           => TRUE,
7838
       MsgOn         => TRUE );
7839
     VitalPathDelay01 (
7840
       OutSignal     => dataout(17),
7841
       OutSignalName => "dataout",
7842
       OutTemp       => dataout_tbuf(17),
7843
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7844
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7845
       GlitchData    => dataout_VitalGlitchDataArray(17),
7846
       Mode          => DefGlitchMode,
7847
       XOn           => TRUE,
7848
       MsgOn         => TRUE );
7849
     VitalPathDelay01 (
7850
       OutSignal     => dataout(18),
7851
       OutSignalName => "dataout",
7852
       OutTemp       => dataout_tbuf(18),
7853
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7854
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7855
       GlitchData    => dataout_VitalGlitchDataArray(18),
7856
       Mode          => DefGlitchMode,
7857
       XOn           => TRUE,
7858
       MsgOn         => TRUE );
7859
     VitalPathDelay01 (
7860
       OutSignal     => dataout(19),
7861
       OutSignalName => "dataout",
7862
       OutTemp       => dataout_tbuf(19),
7863
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7864
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7865
       GlitchData    => dataout_VitalGlitchDataArray(19),
7866
       Mode          => DefGlitchMode,
7867
       XOn           => TRUE,
7868
       MsgOn         => TRUE );
7869
     VitalPathDelay01 (
7870
       OutSignal     => dataout(20),
7871
       OutSignalName => "dataout",
7872
       OutTemp       => dataout_tbuf(20),
7873
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7874
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7875
       GlitchData    => dataout_VitalGlitchDataArray(20),
7876
       Mode          => DefGlitchMode,
7877
       XOn           => TRUE,
7878
       MsgOn         => TRUE );
7879
     VitalPathDelay01 (
7880
       OutSignal     => dataout(21),
7881
       OutSignalName => "dataout",
7882
       OutTemp       => dataout_tbuf(21),
7883
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7884
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7885
       GlitchData    => dataout_VitalGlitchDataArray(21),
7886
       Mode          => DefGlitchMode,
7887
       XOn           => TRUE,
7888
       MsgOn         => TRUE );
7889
     VitalPathDelay01 (
7890
       OutSignal     => dataout(22),
7891
       OutSignalName => "dataout",
7892
       OutTemp       => dataout_tbuf(22),
7893
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7894
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7895
       GlitchData    => dataout_VitalGlitchDataArray(22),
7896
       Mode          => DefGlitchMode,
7897
       XOn           => TRUE,
7898
       MsgOn         => TRUE );
7899
     VitalPathDelay01 (
7900
       OutSignal     => dataout(23),
7901
       OutSignalName => "dataout",
7902
       OutTemp       => dataout_tbuf(23),
7903
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7904
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7905
       GlitchData    => dataout_VitalGlitchDataArray(23),
7906
       Mode          => DefGlitchMode,
7907
       XOn           => TRUE,
7908
       MsgOn         => TRUE );
7909
     VitalPathDelay01 (
7910
       OutSignal     => dataout(24),
7911
       OutSignalName => "dataout",
7912
       OutTemp       => dataout_tbuf(24),
7913
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7914
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7915
       GlitchData    => dataout_VitalGlitchDataArray(24),
7916
       Mode          => DefGlitchMode,
7917
       XOn           => TRUE,
7918
       MsgOn         => TRUE );
7919
     VitalPathDelay01 (
7920
       OutSignal     => dataout(25),
7921
       OutSignalName => "dataout",
7922
       OutTemp       => dataout_tbuf(25),
7923
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7924
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7925
       GlitchData    => dataout_VitalGlitchDataArray(25),
7926
       Mode          => DefGlitchMode,
7927
       XOn           => TRUE,
7928
       MsgOn         => TRUE );
7929
     VitalPathDelay01 (
7930
       OutSignal     => dataout(26),
7931
       OutSignalName => "dataout",
7932
       OutTemp       => dataout_tbuf(26),
7933
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7934
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7935
       GlitchData    => dataout_VitalGlitchDataArray(26),
7936
       Mode          => DefGlitchMode,
7937
       XOn           => TRUE,
7938
       MsgOn         => TRUE );
7939
     VitalPathDelay01 (
7940
       OutSignal     => dataout(27),
7941
       OutSignalName => "dataout",
7942
       OutTemp       => dataout_tbuf(27),
7943
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7944
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7945
       GlitchData    => dataout_VitalGlitchDataArray(27),
7946
       Mode          => DefGlitchMode,
7947
       XOn           => TRUE,
7948
       MsgOn         => TRUE );
7949
     VitalPathDelay01 (
7950
       OutSignal     => dataout(28),
7951
       OutSignalName => "dataout",
7952
       OutTemp       => dataout_tbuf(28),
7953
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7954
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7955
       GlitchData    => dataout_VitalGlitchDataArray(28),
7956
       Mode          => DefGlitchMode,
7957
       XOn           => TRUE,
7958
       MsgOn         => TRUE );
7959
     VitalPathDelay01 (
7960
       OutSignal     => dataout(29),
7961
       OutSignalName => "dataout",
7962
       OutTemp       => dataout_tbuf(29),
7963
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7964
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7965
       GlitchData    => dataout_VitalGlitchDataArray(29),
7966
       Mode          => DefGlitchMode,
7967
       XOn           => TRUE,
7968
       MsgOn         => TRUE );
7969
     VitalPathDelay01 (
7970
       OutSignal     => dataout(30),
7971
       OutSignalName => "dataout",
7972
       OutTemp       => dataout_tbuf(30),
7973
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7974
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7975
       GlitchData    => dataout_VitalGlitchDataArray(30),
7976
       Mode          => DefGlitchMode,
7977
       XOn           => TRUE,
7978
       MsgOn         => TRUE );
7979
     VitalPathDelay01 (
7980
       OutSignal     => dataout(31),
7981
       OutSignalName => "dataout",
7982
       OutTemp       => dataout_tbuf(31),
7983
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7984
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7985
       GlitchData    => dataout_VitalGlitchDataArray(31),
7986
       Mode          => DefGlitchMode,
7987
       XOn           => TRUE,
7988
       MsgOn         => TRUE );
7989
     VitalPathDelay01 (
7990
       OutSignal     => dataout(32),
7991
       OutSignalName => "dataout",
7992
       OutTemp       => dataout_tbuf(32),
7993
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
7994
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
7995
       GlitchData    => dataout_VitalGlitchDataArray(32),
7996
       Mode          => DefGlitchMode,
7997
       XOn           => TRUE,
7998
       MsgOn         => TRUE );
7999
     VitalPathDelay01 (
8000
       OutSignal     => dataout(33),
8001
       OutSignalName => "dataout",
8002
       OutTemp       => dataout_tbuf(33),
8003
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8004
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8005
       GlitchData    => dataout_VitalGlitchDataArray(33),
8006
       Mode          => DefGlitchMode,
8007
       XOn           => TRUE,
8008
       MsgOn         => TRUE );
8009
     VitalPathDelay01 (
8010
       OutSignal     => dataout(34),
8011
       OutSignalName => "dataout",
8012
       OutTemp       => dataout_tbuf(34),
8013
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8014
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8015
       GlitchData    => dataout_VitalGlitchDataArray(34),
8016
       Mode          => DefGlitchMode,
8017
       XOn           => TRUE,
8018
       MsgOn         => TRUE );
8019
     VitalPathDelay01 (
8020
       OutSignal     => dataout(35),
8021
       OutSignalName => "dataout",
8022
       OutTemp       => dataout_tbuf(35),
8023
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8024
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8025
       GlitchData    => dataout_VitalGlitchDataArray(35),
8026
       Mode          => DefGlitchMode,
8027
       XOn           => TRUE,
8028
       MsgOn         => TRUE );
8029
     VitalPathDelay01 (
8030
       OutSignal     => dataout(36),
8031
       OutSignalName => "dataout",
8032
       OutTemp       => dataout_tbuf(36),
8033
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8034
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8035
       GlitchData    => dataout_VitalGlitchDataArray(36),
8036
       Mode          => DefGlitchMode,
8037
       XOn           => TRUE,
8038
       MsgOn         => TRUE );
8039
     VitalPathDelay01 (
8040
       OutSignal     => dataout(37),
8041
       OutSignalName => "dataout",
8042
       OutTemp       => dataout_tbuf(37),
8043
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8044
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8045
       GlitchData    => dataout_VitalGlitchDataArray(37),
8046
       Mode          => DefGlitchMode,
8047
       XOn           => TRUE,
8048
       MsgOn         => TRUE );
8049
     VitalPathDelay01 (
8050
       OutSignal     => dataout(38),
8051
       OutSignalName => "dataout",
8052
       OutTemp       => dataout_tbuf(38),
8053
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8054
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8055
       GlitchData    => dataout_VitalGlitchDataArray(38),
8056
       Mode          => DefGlitchMode,
8057
       XOn           => TRUE,
8058
       MsgOn         => TRUE );
8059
     VitalPathDelay01 (
8060
       OutSignal     => dataout(39),
8061
       OutSignalName => "dataout",
8062
       OutTemp       => dataout_tbuf(39),
8063
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8064
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8065
       GlitchData    => dataout_VitalGlitchDataArray(39),
8066
       Mode          => DefGlitchMode,
8067
       XOn           => TRUE,
8068
       MsgOn         => TRUE );
8069
     VitalPathDelay01 (
8070
       OutSignal     => dataout(40),
8071
       OutSignalName => "dataout",
8072
       OutTemp       => dataout_tbuf(40),
8073
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8074
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8075
       GlitchData    => dataout_VitalGlitchDataArray(40),
8076
       Mode          => DefGlitchMode,
8077
       XOn           => TRUE,
8078
       MsgOn         => TRUE );
8079
     VitalPathDelay01 (
8080
       OutSignal     => dataout(41),
8081
       OutSignalName => "dataout",
8082
       OutTemp       => dataout_tbuf(41),
8083
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8084
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8085
       GlitchData    => dataout_VitalGlitchDataArray(41),
8086
       Mode          => DefGlitchMode,
8087
       XOn           => TRUE,
8088
       MsgOn         => TRUE );
8089
     VitalPathDelay01 (
8090
       OutSignal     => dataout(42),
8091
       OutSignalName => "dataout",
8092
       OutTemp       => dataout_tbuf(42),
8093
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8094
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8095
       GlitchData    => dataout_VitalGlitchDataArray(42),
8096
       Mode          => DefGlitchMode,
8097
       XOn           => TRUE,
8098
       MsgOn         => TRUE );
8099
     VitalPathDelay01 (
8100
       OutSignal     => dataout(43),
8101
       OutSignalName => "dataout",
8102
       OutTemp       => dataout_tbuf(43),
8103
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8104
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8105
       GlitchData    => dataout_VitalGlitchDataArray(43),
8106
       Mode          => DefGlitchMode,
8107
       XOn           => TRUE,
8108
       MsgOn         => TRUE );
8109
     VitalPathDelay01 (
8110
       OutSignal     => dataout(44),
8111
       OutSignalName => "dataout",
8112
       OutTemp       => dataout_tbuf(44),
8113
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8114
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8115
       GlitchData    => dataout_VitalGlitchDataArray(44),
8116
       Mode          => DefGlitchMode,
8117
       XOn           => TRUE,
8118
       MsgOn         => TRUE );
8119
     VitalPathDelay01 (
8120
       OutSignal     => dataout(45),
8121
       OutSignalName => "dataout",
8122
       OutTemp       => dataout_tbuf(45),
8123
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8124
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8125
       GlitchData    => dataout_VitalGlitchDataArray(45),
8126
       Mode          => DefGlitchMode,
8127
       XOn           => TRUE,
8128
       MsgOn         => TRUE );
8129
     VitalPathDelay01 (
8130
       OutSignal     => dataout(46),
8131
       OutSignalName => "dataout",
8132
       OutTemp       => dataout_tbuf(46),
8133
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8134
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8135
       GlitchData    => dataout_VitalGlitchDataArray(46),
8136
       Mode          => DefGlitchMode,
8137
       XOn           => TRUE,
8138
       MsgOn         => TRUE );
8139
     VitalPathDelay01 (
8140
       OutSignal     => dataout(47),
8141
       OutSignalName => "dataout",
8142
       OutTemp       => dataout_tbuf(47),
8143
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8144
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8145
       GlitchData    => dataout_VitalGlitchDataArray(47),
8146
       Mode          => DefGlitchMode,
8147
       XOn           => TRUE,
8148
       MsgOn         => TRUE );
8149
     VitalPathDelay01 (
8150
       OutSignal     => dataout(48),
8151
       OutSignalName => "dataout",
8152
       OutTemp       => dataout_tbuf(48),
8153
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8154
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8155
       GlitchData    => dataout_VitalGlitchDataArray(48),
8156
       Mode          => DefGlitchMode,
8157
       XOn           => TRUE,
8158
       MsgOn         => TRUE );
8159
     VitalPathDelay01 (
8160
       OutSignal     => dataout(49),
8161
       OutSignalName => "dataout",
8162
       OutTemp       => dataout_tbuf(49),
8163
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8164
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8165
       GlitchData    => dataout_VitalGlitchDataArray(49),
8166
       Mode          => DefGlitchMode,
8167
       XOn           => TRUE,
8168
       MsgOn         => TRUE );
8169
     VitalPathDelay01 (
8170
       OutSignal     => dataout(50),
8171
       OutSignalName => "dataout",
8172
       OutTemp       => dataout_tbuf(50),
8173
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8174
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8175
       GlitchData    => dataout_VitalGlitchDataArray(50),
8176
       Mode          => DefGlitchMode,
8177
       XOn           => TRUE,
8178
       MsgOn         => TRUE );
8179
     VitalPathDelay01 (
8180
       OutSignal     => dataout(51),
8181
       OutSignalName => "dataout",
8182
       OutTemp       => dataout_tbuf(51),
8183
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8184
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8185
       GlitchData    => dataout_VitalGlitchDataArray(51),
8186
       Mode          => DefGlitchMode,
8187
       XOn           => TRUE,
8188
       MsgOn         => TRUE );
8189
     VitalPathDelay01 (
8190
       OutSignal     => dataout(52),
8191
       OutSignalName => "dataout",
8192
       OutTemp       => dataout_tbuf(52),
8193
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8194
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8195
       GlitchData    => dataout_VitalGlitchDataArray(52),
8196
       Mode          => DefGlitchMode,
8197
       XOn           => TRUE,
8198
       MsgOn         => TRUE );
8199
     VitalPathDelay01 (
8200
       OutSignal     => dataout(53),
8201
       OutSignalName => "dataout",
8202
       OutTemp       => dataout_tbuf(53),
8203
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8204
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8205
       GlitchData    => dataout_VitalGlitchDataArray(53),
8206
       Mode          => DefGlitchMode,
8207
       XOn           => TRUE,
8208
       MsgOn         => TRUE );
8209
     VitalPathDelay01 (
8210
       OutSignal     => dataout(54),
8211
       OutSignalName => "dataout",
8212
       OutTemp       => dataout_tbuf(54),
8213
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8214
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8215
       GlitchData    => dataout_VitalGlitchDataArray(54),
8216
       Mode          => DefGlitchMode,
8217
       XOn           => TRUE,
8218
       MsgOn         => TRUE );
8219
     VitalPathDelay01 (
8220
       OutSignal     => dataout(55),
8221
       OutSignalName => "dataout",
8222
       OutTemp       => dataout_tbuf(55),
8223
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8224
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8225
       GlitchData    => dataout_VitalGlitchDataArray(55),
8226
       Mode          => DefGlitchMode,
8227
       XOn           => TRUE,
8228
       MsgOn         => TRUE );
8229
     VitalPathDelay01 (
8230
       OutSignal     => dataout(56),
8231
       OutSignalName => "dataout",
8232
       OutTemp       => dataout_tbuf(56),
8233
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8234
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8235
       GlitchData    => dataout_VitalGlitchDataArray(56),
8236
       Mode          => DefGlitchMode,
8237
       XOn           => TRUE,
8238
       MsgOn         => TRUE );
8239
     VitalPathDelay01 (
8240
       OutSignal     => dataout(57),
8241
       OutSignalName => "dataout",
8242
       OutTemp       => dataout_tbuf(57),
8243
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8244
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8245
       GlitchData    => dataout_VitalGlitchDataArray(57),
8246
       Mode          => DefGlitchMode,
8247
       XOn           => TRUE,
8248
       MsgOn         => TRUE );
8249
     VitalPathDelay01 (
8250
       OutSignal     => dataout(58),
8251
       OutSignalName => "dataout",
8252
       OutTemp       => dataout_tbuf(58),
8253
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8254
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8255
       GlitchData    => dataout_VitalGlitchDataArray(58),
8256
       Mode          => DefGlitchMode,
8257
       XOn           => TRUE,
8258
       MsgOn         => TRUE );
8259
     VitalPathDelay01 (
8260
       OutSignal     => dataout(59),
8261
       OutSignalName => "dataout",
8262
       OutTemp       => dataout_tbuf(59),
8263
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8264
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8265
       GlitchData    => dataout_VitalGlitchDataArray(59),
8266
       Mode          => DefGlitchMode,
8267
       XOn           => TRUE,
8268
       MsgOn         => TRUE );
8269
     VitalPathDelay01 (
8270
       OutSignal     => dataout(60),
8271
       OutSignalName => "dataout",
8272
       OutTemp       => dataout_tbuf(60),
8273
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8274
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8275
       GlitchData    => dataout_VitalGlitchDataArray(60),
8276
       Mode          => DefGlitchMode,
8277
       XOn           => TRUE,
8278
       MsgOn         => TRUE );
8279
     VitalPathDelay01 (
8280
       OutSignal     => dataout(61),
8281
       OutSignalName => "dataout",
8282
       OutTemp       => dataout_tbuf(61),
8283
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8284
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8285
       GlitchData    => dataout_VitalGlitchDataArray(61),
8286
       Mode          => DefGlitchMode,
8287
       XOn           => TRUE,
8288
       MsgOn         => TRUE );
8289
     VitalPathDelay01 (
8290
       OutSignal     => dataout(62),
8291
       OutSignalName => "dataout",
8292
       OutTemp       => dataout_tbuf(62),
8293
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8294
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8295
       GlitchData    => dataout_VitalGlitchDataArray(62),
8296
       Mode          => DefGlitchMode,
8297
       XOn           => TRUE,
8298
       MsgOn         => TRUE );
8299
     VitalPathDelay01 (
8300
       OutSignal     => dataout(63),
8301
       OutSignalName => "dataout",
8302
       OutTemp       => dataout_tbuf(63),
8303
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8304
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8305
       GlitchData    => dataout_VitalGlitchDataArray(63),
8306
       Mode          => DefGlitchMode,
8307
       XOn           => TRUE,
8308
       MsgOn         => TRUE );
8309
     VitalPathDelay01 (
8310
       OutSignal     => dataout(64),
8311
       OutSignalName => "dataout",
8312
       OutTemp       => dataout_tbuf(64),
8313
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8314
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8315
       GlitchData    => dataout_VitalGlitchDataArray(64),
8316
       Mode          => DefGlitchMode,
8317
       XOn           => TRUE,
8318
       MsgOn         => TRUE );
8319
     VitalPathDelay01 (
8320
       OutSignal     => dataout(65),
8321
       OutSignalName => "dataout",
8322
       OutTemp       => dataout_tbuf(65),
8323
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8324
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8325
       GlitchData    => dataout_VitalGlitchDataArray(65),
8326
       Mode          => DefGlitchMode,
8327
       XOn           => TRUE,
8328
       MsgOn         => TRUE );
8329
     VitalPathDelay01 (
8330
       OutSignal     => dataout(66),
8331
       OutSignalName => "dataout",
8332
       OutTemp       => dataout_tbuf(66),
8333
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8334
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8335
       GlitchData    => dataout_VitalGlitchDataArray(66),
8336
       Mode          => DefGlitchMode,
8337
       XOn           => TRUE,
8338
       MsgOn         => TRUE );
8339
     VitalPathDelay01 (
8340
       OutSignal     => dataout(67),
8341
       OutSignalName => "dataout",
8342
       OutTemp       => dataout_tbuf(67),
8343
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8344
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8345
       GlitchData    => dataout_VitalGlitchDataArray(67),
8346
       Mode          => DefGlitchMode,
8347
       XOn           => TRUE,
8348
       MsgOn         => TRUE );
8349
     VitalPathDelay01 (
8350
       OutSignal     => dataout(68),
8351
       OutSignalName => "dataout",
8352
       OutTemp       => dataout_tbuf(68),
8353
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8354
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8355
       GlitchData    => dataout_VitalGlitchDataArray(68),
8356
       Mode          => DefGlitchMode,
8357
       XOn           => TRUE,
8358
       MsgOn         => TRUE );
8359
     VitalPathDelay01 (
8360
       OutSignal     => dataout(69),
8361
       OutSignalName => "dataout",
8362
       OutTemp       => dataout_tbuf(69),
8363
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8364
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8365
       GlitchData    => dataout_VitalGlitchDataArray(69),
8366
       Mode          => DefGlitchMode,
8367
       XOn           => TRUE,
8368
       MsgOn         => TRUE );
8369
     VitalPathDelay01 (
8370
       OutSignal     => dataout(70),
8371
       OutSignalName => "dataout",
8372
       OutTemp       => dataout_tbuf(70),
8373
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8374
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8375
       GlitchData    => dataout_VitalGlitchDataArray(70),
8376
       Mode          => DefGlitchMode,
8377
       XOn           => TRUE,
8378
       MsgOn         => TRUE );
8379
     VitalPathDelay01 (
8380
       OutSignal     => dataout(71),
8381
       OutSignalName => "dataout",
8382
       OutTemp       => dataout_tbuf(71),
8383
       Paths         => (0 => (round_ipd'last_event, tpd_round_dataout, TRUE),
8384
                         1 => (saturate_ipd'last_event, tpd_saturate_dataout, TRUE)),
8385
       GlitchData    => dataout_VitalGlitchDataArray(71),
8386
       Mode          => DefGlitchMode,
8387
       XOn           => TRUE,
8388
       MsgOn         => TRUE );
8389
   end process;
8390
END arch;
8391
 
8392
--/////////////////////////////////////////////////////////////////////////////
8393
--
8394
--                         STRATIXII_MAC_MULT_INTERNAL
8395
--
8396
--/////////////////////////////////////////////////////////////////////////////
8397
 
8398
LIBRARY IEEE;
8399
USE ieee.std_logic_1164.all;
8400
use IEEE.VITAL_Timing.all;
8401
use IEEE.VITAL_Primitives.all;
8402
use work.stratixii_atom_pack.all;
8403
library grlib;
8404
use grlib.stdlib.all;
8405
 
8406
ENTITY stratixii_mac_mult_internal IS
8407
   GENERIC (
8408
      dataa_width                    :  integer := 18;
8409
      datab_width                    :  integer := 18;
8410
      dataout_width                  :  integer := 36;
8411
      dynamic_mode                   :  string  := "no";
8412
      tipd_dataa        : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
8413
      tipd_datab        : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
8414
      tpd_dataa_dataout : VitalDelayType01 := DefPropDelay01;
8415
      tpd_datab_dataout : VitalDelayType01 := DefPropDelay01;
8416
      tpd_signa_dataout : VitalDelayType01 := DefPropDelay01;
8417
      tpd_signb_dataout : VitalDelayType01 := DefPropDelay01;
8418
      tpd_dataa_scanouta   : VitalDelayType01 := DefPropDelay01;
8419
      tpd_datab_scanoutb   : VitalDelayType01 := DefPropDelay01;
8420
      XOn               : Boolean := DefGlitchXOn;
8421
      MsgOn             : Boolean := DefGlitchMsgOn
8422
      );
8423
   PORT (
8424
      dataa                   : IN std_logic_vector(dataa_width - 1 DOWNTO 0) := (others => '0');
8425
      datab                   : IN std_logic_vector(datab_width - 1 DOWNTO 0) := (others => '0');
8426
      signa                   : IN std_logic := '0';
8427
      signb                   : IN std_logic := '0';
8428
      bypass                  : IN std_logic := '0';
8429
      scanouta                : OUT std_logic_vector(dataa_width - 1 DOWNTO 0) := (others => '0');
8430
      scanoutb                : OUT std_logic_vector(datab_width - 1 DOWNTO 0) := (others => '0');
8431
      dataout                 : OUT std_logic_vector(35 DOWNTO 0) := (others => '0')
8432
      );
8433
END stratixii_mac_mult_internal;
8434
 
8435
ARCHITECTURE arch OF stratixii_mac_mult_internal IS
8436
 
8437
   SIGNAL dataa_ipd                :  std_logic_vector(17 DOWNTO 0) := (others => '0');
8438
   SIGNAL datab_ipd                :  std_logic_vector(17 DOWNTO 0) := (others => '0');
8439
   SIGNAL neg                      :  std_logic := '0';
8440
   SIGNAL dataout_pre_bypass       :  std_logic_vector((dataa_width+datab_width) -1 DOWNTO 0) := (others => '0');
8441
   SIGNAL dataout_tmp              :  std_logic_vector((dataa_width+datab_width) -1 DOWNTO 0) := (others => '0');
8442
   SIGNAL abs_a                    :  std_logic_vector(dataa_width - 1 DOWNTO 0) := (others => '0');
8443
   SIGNAL abs_b                    :  std_logic_vector(datab_width - 1 DOWNTO 0) := (others => '0');
8444
   SIGNAL abs_output               :  std_logic_vector((dataa_width+datab_width) -1 DOWNTO 0) := (others => '0');
8445
 
8446
BEGIN
8447
 
8448
    neg <= (dataa_ipd(dataa_width - 1) AND signa) XOR (datab_ipd(datab_width - 1) AND signb) ;
8449
    abs_a <= (NOT dataa_ipd(dataa_width - 1 DOWNTO 0) + 1) WHEN (signa AND dataa_ipd(dataa_width - 1)) = '1' ELSE dataa_ipd(dataa_width - 1 DOWNTO 0) ;
8450
    abs_b <= (NOT datab_ipd(datab_width - 1 DOWNTO 0) + 1) WHEN (signb AND datab_ipd(datab_width - 1)) = '1' ELSE datab_ipd(datab_width - 1 DOWNTO 0) ;
8451
    abs_output((dataa_width + datab_width) - 1 DOWNTO 0) <= abs_a(dataa_width-1 downto 0) * abs_b(datab_width-1 downto 0) ;
8452
    dataout_pre_bypass((dataa_width + datab_width) - 1 DOWNTO 0) <= (NOT abs_output + 1) WHEN neg = '1' ELSE abs_output ;
8453
    dataout_tmp((dataa_width + datab_width) - 1 DOWNTO 0) <= datab(datab_width-1 downto 0) & dataa(dataa_width-1 downto 0) when ((dynamic_mode = "yes") and (bypass = '1')) else dataa(dataa_width-1 downto 0) & datab(datab_width-1 downto 0) WHEN (bypass = '1') ELSE dataout_pre_bypass ;
8454
 
8455
  PathDelay : block
8456
  begin
8457
    g1 : for i in 0 to 256 generate
8458
      do: if i < dataout_width generate
8459
        process(dataout_tmp(i))
8460
          VARIABLE dataout_VitalGlitchData : VitalGlitchDataType;
8461
        begin
8462
          VitalPathDelay01 (
8463
            OutSignal => dataout(i),
8464
            OutSignalName => "dataout",
8465
            OutTemp => dataout_tmp(i),
8466
            Paths => (0 => (dataa_ipd'last_event, tpd_dataa_dataout, TRUE),
8467
                      1 => (datab_ipd'last_event, tpd_datab_dataout, TRUE),
8468
                      2 => (signa'last_event, tpd_signa_dataout, TRUE),
8469
                      3 => (signb'last_event, tpd_signb_dataout, TRUE)),
8470
            GlitchData => dataout_VitalGlitchData,
8471
            Mode => DefGlitchMode,
8472
            MsgOn => FALSE,
8473
            XOn  => TRUE
8474
            );
8475
        end process;
8476
      end generate do;
8477
      sa: if i < dataa_width generate
8478
        VitalWireDelay (dataa_ipd(i), dataa(i), tipd_dataa(i));
8479
        PROCESS(dataa_ipd)
8480
          variable scanouta_VitalGlitchData : VitalGlitchDataType;
8481
        BEGIN
8482
          VitalPathDelay01 (
8483
            OutSignal => scanouta(i),
8484
            OutSignalName => "scanouta",
8485
            OutTemp => dataa_ipd(i),
8486
            Paths => (1 => (dataa_ipd'last_event, tpd_dataa_scanouta, TRUE)),
8487
            GlitchData => scanouta_VitalGlitchData,
8488
            Mode => DefGlitchMode,
8489
            XOn  => XOn,
8490
            MsgOn => MsgOn
8491
            );
8492
        end process;
8493
      end generate;
8494
      sb: if i < datab_width generate
8495
        VitalWireDelay (datab_ipd(i), datab(i), tipd_datab(i));
8496
        PROCESS(datab_ipd)
8497
          variable scanoutb_VitalGlitchData : VitalGlitchDataType;
8498
        BEGIN
8499
          VitalPathDelay01 (
8500
            OutSignal => scanoutb(i),
8501
            OutSignalName => "scanoutb",
8502
            OutTemp => datab_ipd(i),
8503
            Paths => (1 => (datab_ipd'last_event, tpd_datab_scanoutb, TRUE)),
8504
            GlitchData => scanoutb_VitalGlitchData,
8505
            Mode => DefGlitchMode,
8506
            XOn  => XOn,
8507
            MsgOn => MsgOn
8508
            );
8509
        end process;
8510
      end generate;
8511
    end generate;
8512
  end block;
8513
 
8514
END arch;
8515
--/////////////////////////////////////////////////////////////////////////////
8516
--
8517
--                              STRATIXII_MAC_MULT
8518
--
8519
--/////////////////////////////////////////////////////////////////////////////
8520
LIBRARY IEEE;
8521
USE ieee.std_logic_1164.all;
8522
use IEEE.VITAL_Timing.all;
8523
use IEEE.VITAL_Primitives.all;
8524
use work.stratixii_atom_pack.all;
8525
use work.stratixii_mac_mult_internal;
8526
use work.stratixii_mac_bit_register;
8527
use work.stratixii_mac_register;
8528
use work.stratixii_mac_rs_block;
8529
library grlib;
8530
use grlib.stdlib.all;
8531
 
8532
ENTITY stratixii_mac_mult IS
8533
   GENERIC (
8534
      dataa_width                    :  integer := 18;
8535
      datab_width                    :  integer := 18;
8536
      dataa_clock                    :  string := "none";
8537
      datab_clock                    :  string := "none";
8538
      signa_clock                    :  string := "none";
8539
      signb_clock                    :  string := "none";
8540
      round_clock                    :  string := "none";
8541
      saturate_clock                 :  string := "none";
8542
      output_clock                   :  string := "none";
8543
      round_clear                    :  string := "none";
8544
      saturate_clear                 :  string := "none";
8545
      dataa_clear                    :  string := "none";
8546
      datab_clear                    :  string := "none";
8547
      signa_clear                    :  string := "none";
8548
      signb_clear                    :  string := "none";
8549
      output_clear                   :  string := "none";
8550
      bypass_multiplier              :  string := "no";
8551
      mode_clock                     :  string := "none";
8552
      zeroacc_clock                  :  string := "none";
8553
      mode_clear                     :  string := "none";
8554
      zeroacc_clear                  :  string := "none";
8555
      signa_internally_grounded      :  string := "false";
8556
      signb_internally_grounded      :  string := "false";
8557
      lpm_hint                       :  string := "true";
8558
      lpm_type                       :  string := "stratixii_mac_mult";
8559
      dynamic_mode                   :  string := "no");
8560
   PORT (
8561
      dataa                   : IN std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
8562
      datab                   : IN std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
8563
      scanina                 : IN std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
8564
      scaninb                 : IN std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
8565
      sourcea                 : IN std_logic := '0';
8566
      sourceb                 : IN std_logic := '0';
8567
      signa                   : IN std_logic := '0';
8568
      signb                   : IN std_logic := '0';
8569
      round                   : IN std_logic := '0';
8570
      saturate                : IN std_logic := '0';
8571
      clk                     : IN std_logic_vector(3 DOWNTO 0) := (others => '0');
8572
      aclr                    : IN std_logic_vector(3 DOWNTO 0) := (others => '0');
8573
      ena                     : IN std_logic_vector(3 DOWNTO 0) := (others => '0');
8574
      mode                    : IN std_logic := '0';
8575
      zeroacc                 : IN std_logic := '0';
8576
      dataout                 : OUT std_logic_vector((dataa_width+datab_width)-1 DOWNTO 0) := (others => '0');
8577
      scanouta                : OUT std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
8578
      scanoutb                : OUT std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
8579
      devclrn                 : IN std_logic := '1';
8580
      devpor                  : IN std_logic := '1'
8581
      );
8582
END stratixii_mac_mult;
8583
 
8584
ARCHITECTURE arch OF stratixii_mac_mult IS
8585
 
8586
   COMPONENT stratixii_mac_mult_internal
8587
      GENERIC (
8588
          dataout_width                  :  integer := 36;
8589
          dataa_width                    :  integer := 18;
8590
          datab_width                    :  integer := 18;
8591
          dynamic_mode                   :  string  := "no";
8592
          tipd_dataa        : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
8593
          tipd_datab        : VitalDelayArrayType01(17 downto 0) := (OTHERS => DefPropDelay01);
8594
          tpd_dataa_dataout : VitalDelayType01 := DefPropDelay01;
8595
          tpd_datab_dataout : VitalDelayType01 := DefPropDelay01;
8596
          tpd_signa_dataout : VitalDelayType01 := DefPropDelay01;
8597
          tpd_signb_dataout : VitalDelayType01 := DefPropDelay01;
8598
          tpd_dataa_scanouta   : VitalDelayType01 := DefPropDelay01;
8599
          tpd_datab_scanoutb   : VitalDelayType01 := DefPropDelay01;
8600
          XOn               : Boolean := DefGlitchXOn;
8601
          MsgOn             : Boolean := DefGlitchMsgOn
8602
          );
8603
      PORT (
8604
         dataa                   : IN  std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
8605
         datab                   : IN  std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
8606
         signa                   : IN  std_logic := '0';
8607
         signb                   : IN  std_logic := '0';
8608
         bypass                  : IN  std_logic := '0';
8609
         scanouta                : OUT std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
8610
         scanoutb                : OUT std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
8611
         dataout                 : OUT std_logic_vector(35 DOWNTO 0));
8612
   END COMPONENT;
8613
 
8614
   COMPONENT stratixii_mac_bit_register
8615
      GENERIC (
8616
          power_up                       :  std_logic := '0');
8617
      PORT (
8618
        data                    : IN std_logic := '0';
8619
        clk                     : IN std_logic := '0';
8620
        aclr                    : IN std_logic := '0';
8621
        if_aclr                 : IN std_logic := '0';
8622
        ena                     : IN std_logic := '1';
8623
        async                   : IN std_logic := '1';
8624
        dataout                 : OUT std_logic := '0');
8625
   END COMPONENT;
8626
 
8627
   COMPONENT stratixii_mac_register
8628
      GENERIC (
8629
          power_up                       :  std_logic := '0';
8630
          data_width                     :  integer := 18);
8631
      PORT (
8632
        data                    : IN std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
8633
        clk                     : IN std_logic := '0';
8634
        aclr                    : IN std_logic := '0';
8635
        if_aclr                 : IN std_logic := '0';
8636
        ena                     : IN std_logic := '1';
8637
        async                   : IN std_logic := '1';
8638
        dataout                 : OUT std_logic_vector(data_width -1 DOWNTO 0) := (others => '0'));
8639
   END COMPONENT;
8640
 
8641
   COMPONENT stratixii_mac_rs_block
8642
      GENERIC (
8643
        tpd_saturate_dataout           : VitalDelayType01 := DefPropDelay01;
8644
        tpd_round_dataout              : VitalDelayType01 := DefPropDelay01;
8645
        block_type                     :  string := "mac_mult";
8646
        dataa_width                    :  integer := 18;
8647
        datab_width                    :  integer := 18);
8648
      PORT (
8649
         operation               : IN  std_logic_vector(3 DOWNTO 0) := (others => '0');
8650
         round                   : IN  std_logic := '0';
8651
         saturate                : IN  std_logic := '0';
8652
         addnsub                 : IN  std_logic := '0';
8653
         signa                   : IN  std_logic := '0';
8654
         signb                   : IN  std_logic := '0';
8655
         signsize                : IN  std_logic_vector(7 DOWNTO 0) := (others => '0');
8656
         roundsize               : IN  std_logic_vector(7 DOWNTO 0) := (others => '0');
8657
         dataoutsize             : IN  std_logic_vector(7 DOWNTO 0) := (others => '0');
8658
         dataa                   : IN  std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
8659
         datab                   : IN  std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
8660
         datain                  : IN  std_logic_vector(71 DOWNTO 0) := (others => '0');
8661
         dataout                 : OUT std_logic_vector(71 DOWNTO 0) := (others => '0'));
8662
   END COMPONENT;
8663
 
8664
 
8665
   SIGNAL mult_output              :  std_logic_vector(35 DOWNTO 0) := (others => '0');
8666
   SIGNAL signa_out                :  std_logic := '0';
8667
   SIGNAL signb_out                :  std_logic := '0';
8668
   SIGNAL round_out                :  std_logic := '0';
8669
   SIGNAL saturate_out             :  std_logic := '0';
8670
   SIGNAL mode_out                 :  std_logic := '0';
8671
   SIGNAL zeroacc_out              :  std_logic := '0';
8672
   SIGNAL dataout_tmp              :  std_logic_vector(71 DOWNTO 0) := (others => '0');
8673
   SIGNAL dataout_reg              :  std_logic_vector(71 DOWNTO 0) := (others => '0');
8674
   SIGNAL dataout_rs               :  std_logic_vector(71 DOWNTO 0) := (others => '0');
8675
   SIGNAL scanouta_tmp             :  std_logic_vector(dataa_width -1 DOWNTO 0) := (others => '0');
8676
   SIGNAL scanoutb_tmp             :  std_logic_vector(datab_width -1 DOWNTO 0) := (others => '0');
8677
   SIGNAL dataa_src                :  std_logic_vector(dataa_width -1 DOWNTO 0) := (others => '0');
8678
   SIGNAL datab_src                :  std_logic_vector(datab_width -1 DOWNTO 0) := (others => '0');
8679
   SIGNAL dataa_clk                :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8680
   SIGNAL datab_clk                :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8681
   SIGNAL signa_clk                :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8682
   SIGNAL signb_clk                :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8683
   SIGNAL round_clk                :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8684
   SIGNAL saturate_clk             :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8685
   SIGNAL output_clk               :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8686
   SIGNAL round_aclr               :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8687
   SIGNAL saturate_aclr            :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8688
   SIGNAL dataa_aclr               :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8689
   SIGNAL datab_aclr               :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8690
   SIGNAL signa_aclr               :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8691
   SIGNAL signb_aclr               :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8692
   SIGNAL output_aclr              :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8693
   SIGNAL mode_clk                 :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8694
   SIGNAL zeroacc_clk              :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8695
   SIGNAL mode_aclr                :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8696
   SIGNAL zeroacc_aclr             :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8697
   SIGNAL clk_dataa                :  std_logic := '0';
8698
   SIGNAL clear_dataa              :  std_logic := '0';
8699
   SIGNAL aclr_dataa               :  std_logic := '0';
8700
   SIGNAL ena_dataa                :  std_logic := '0';
8701
   SIGNAL async_dataa              :  std_logic := '0';
8702
   SIGNAL clk_datab                :  std_logic := '0';
8703
   SIGNAL clear_datab              :  std_logic := '0';
8704
   SIGNAL aclr_datab               :  std_logic := '0';
8705
   SIGNAL ena_datab                :  std_logic := '0';
8706
   SIGNAL async_datab              :  std_logic := '0';
8707
   SIGNAL clk_signa                :  std_logic := '0';
8708
   SIGNAL clear_signa              :  std_logic := '0';
8709
   SIGNAL aclr_signa               :  std_logic := '0';
8710
   SIGNAL ena_signa                :  std_logic := '0';
8711
   SIGNAL async_signa              :  std_logic := '0';
8712
   SIGNAL clk_signb                :  std_logic := '0';
8713
   SIGNAL clear_signb              :  std_logic := '0';
8714
   SIGNAL aclr_signb               :  std_logic := '0';
8715
   SIGNAL ena_signb                :  std_logic := '0';
8716
   SIGNAL async_signb              :  std_logic := '0';
8717
   SIGNAL clk_round                :  std_logic := '0';
8718
   SIGNAL clear_round              :  std_logic := '0';
8719
   SIGNAL aclr_round               :  std_logic := '0';
8720
   SIGNAL ena_round                :  std_logic := '0';
8721
   SIGNAL async_round              :  std_logic := '0';
8722
   SIGNAL clk_saturate             :  std_logic := '0';
8723
   SIGNAL clear_saturate           :  std_logic := '0';
8724
   SIGNAL aclr_saturate            :  std_logic := '0';
8725
   SIGNAL ena_saturate             :  std_logic := '0';
8726
   SIGNAL async_saturate           :  std_logic := '0';
8727
   SIGNAL clk_mode                 :  std_logic := '0';
8728
   SIGNAL clear_mode               :  std_logic := '0';
8729
   SIGNAL aclr_mode                :  std_logic := '0';
8730
   SIGNAL ena_mode                 :  std_logic := '0';
8731
   SIGNAL async_mode               :  std_logic := '0';
8732
   SIGNAL clk_zeroacc              :  std_logic := '0';
8733
   SIGNAL clear_zeroacc            :  std_logic := '0';
8734
   SIGNAL aclr_zeroacc             :  std_logic := '0';
8735
   SIGNAL ena_zeroacc              :  std_logic := '0';
8736
   SIGNAL async_zeroacc            :  std_logic := '0';
8737
   SIGNAL clk_output               :  std_logic := '0';
8738
   SIGNAL clear_output             :  std_logic := '0';
8739
   SIGNAL aclr_output              :  std_logic := '0';
8740
   SIGNAL ena_output               :  std_logic := '0';
8741
   SIGNAL async_output             :  std_logic := '0';
8742
   SIGNAL signa_internal           :  std_logic := '0';
8743
   SIGNAL signb_internal           :  std_logic := '0';
8744
   SIGNAL bypass                   :  std_logic := '0';
8745
   SIGNAL mac_mult_dataoutsize     :  std_logic_vector(7 DOWNTO 0) := (others => '0');
8746
   SIGNAL tmp_4                   :  std_logic_vector(71 DOWNTO 0) := (others => '0');
8747
   SIGNAL tmp_60                  :  std_logic_vector(71 DOWNTO 0) := (others => '0');
8748
   SIGNAL port_tmp62              :  std_logic_vector(3 DOWNTO 0) := (others => '0');
8749
   SIGNAL port_tmp63              :  std_logic := '0';
8750
   SIGNAL port_tmp64              :  std_logic_vector(7 DOWNTO 0) := (others => '0');
8751
   SIGNAL port_tmp65              :  std_logic_vector(7 DOWNTO 0) := (others => '0');
8752
   SIGNAL dataout_tmp1            :  std_logic_vector(35 DOWNTO 0) := (others => '0');
8753
   SIGNAL scanouta_tmp2           :  std_logic_vector(dataa_width-1 DOWNTO 0) := (others => '0');
8754
   SIGNAL scanoutb_tmp3           :  std_logic_vector(datab_width-1 DOWNTO 0) := (others => '0');
8755
 
8756
 
8757
BEGIN
8758
   dataout <= dataout_tmp1(dataout'range);
8759
   scanouta <= scanouta_tmp2;
8760
   scanoutb <= scanoutb_tmp3;
8761
   dataout_tmp1 <= dataout_tmp(35 DOWNTO 0) ;
8762
   dataa_src <= scanina WHEN (sourcea = '1') ELSE dataa ;
8763
   datab_src <= scaninb WHEN (sourceb = '1') ELSE datab ;
8764
   dataa_mac_reg : stratixii_mac_register
8765
      GENERIC MAP (
8766
         data_width => dataa_width,
8767
         power_up => '0')
8768
      PORT MAP (
8769
         data => dataa_src,
8770
         clk => clk_dataa,
8771
         aclr => aclr_dataa,
8772
         if_aclr => clear_dataa,
8773
         ena => ena_dataa,
8774
         dataout => scanouta_tmp,
8775
         async => async_dataa);
8776
 
8777
   async_dataa <= '1' WHEN (dataa_clock = "none") ELSE '0' ;
8778
   clear_dataa <= '1' WHEN (dataa_clear /= "none") ELSE '0' ;
8779
   clk_dataa <= '1' WHEN clk(conv_integer(dataa_clk)) = '1' ELSE '0' ;
8780
   aclr_dataa <= '1' WHEN (aclr(conv_integer(dataa_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8781
   ena_dataa <= '1' WHEN ena(conv_integer(dataa_clk)) = '1' ELSE '0' ;
8782
   dataa_clk <= "0000" WHEN ((dataa_clock = "0") OR (dataa_clock = "none")) ELSE "0001" WHEN (dataa_clock = "1") ELSE "0010" WHEN (dataa_clock = "2") ELSE "0011" WHEN (dataa_clock = "3") ELSE "0000" ;
8783
   dataa_aclr <= "0000" WHEN ((dataa_clear = "0") OR (dataa_clear = "none")) ELSE "0001" WHEN (dataa_clear = "1") ELSE "0010" WHEN (dataa_clear = "2") ELSE "0011" WHEN (dataa_clear = "3") ELSE "0000" ;
8784
   datab_mac_reg : stratixii_mac_register
8785
      GENERIC MAP (
8786
         data_width => datab_width,
8787
         power_up => '0')
8788
      PORT MAP (
8789
         data => datab_src,
8790
         clk => clk_datab,
8791
         aclr => aclr_datab,
8792
         if_aclr => clear_datab,
8793
         ena => ena_datab,
8794
         dataout => scanoutb_tmp,
8795
         async => async_datab);
8796
 
8797
   async_datab <= '1' WHEN (datab_clock = "none") ELSE '0' ;
8798
   clear_datab <= '1' WHEN (datab_clear /= "none") ELSE '0' ;
8799
   clk_datab <= '1' WHEN clk(conv_integer(datab_clk)) = '1' ELSE '0' ;
8800
   aclr_datab <= '1' WHEN (aclr(conv_integer(datab_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8801
   ena_datab <= '1' WHEN ena(conv_integer(datab_clk)) = '1' ELSE '0' ;
8802
   datab_clk <= "0000" WHEN ((datab_clock = "0") OR (datab_clock = "none")) ELSE "0001" WHEN (datab_clock = "1") ELSE "0010" WHEN (datab_clock = "2") ELSE "0011" WHEN (datab_clock = "3") ELSE "0000" ;
8803
   datab_aclr <= "0000" WHEN ((datab_clear = "0") OR (datab_clear = "none")) ELSE "0001" WHEN (datab_clear = "1") ELSE "0010" WHEN (datab_clear = "2") ELSE "0011" WHEN (datab_clear = "3") ELSE "0000" ;
8804
   signa_mac_reg : stratixii_mac_bit_register
8805
      GENERIC MAP (
8806
         power_up => '0')
8807
      PORT MAP (
8808
         data => signa,
8809
         clk => clk_signa,
8810
         aclr => aclr_signa,
8811
         if_aclr => clear_signa,
8812
         ena => ena_signa,
8813
         dataout => signa_out,
8814
         async => async_signa);
8815
 
8816
   async_signa <= '1' WHEN (signa_clock = "none") ELSE '0' ;
8817
   clear_signa <= '1' WHEN (signa_clear /= "none") ELSE '0' ;
8818
   clk_signa <= '1' WHEN clk(conv_integer(signa_clk)) = '1' ELSE '0' ;
8819
   aclr_signa <= '1' WHEN (aclr(conv_integer(signa_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8820
   ena_signa <= '1' WHEN ena(conv_integer(signa_clk)) = '1' ELSE '0' ;
8821
   signa_clk <= "0000" WHEN ((signa_clock = "0") OR (signa_clock = "none")) ELSE "0001" WHEN (signa_clock = "1") ELSE "0010" WHEN (signa_clock = "2") ELSE "0011" WHEN (signa_clock = "3") ELSE "0000" ;
8822
   signa_aclr <= "0000" WHEN ((signa_clear = "0") OR (signa_clear = "none")) ELSE "0001" WHEN (signa_clear = "1") ELSE "0010" WHEN (signa_clear = "2") ELSE "0011" WHEN (signa_clear = "3") ELSE "0000" ;
8823
   signb_mac_reg : stratixii_mac_bit_register
8824
      GENERIC MAP (
8825
         power_up => '0')
8826
      PORT MAP (
8827
         data => signb,
8828
         clk => clk_signb,
8829
         aclr => aclr_signb,
8830
         if_aclr => clear_signb,
8831
         ena => ena_signb,
8832
         dataout => signb_out,
8833
         async => async_signb);
8834
 
8835
   async_signb <= '1' WHEN (signb_clock = "none") ELSE '0' ;
8836
   clear_signb <= '1' WHEN (signb_clear /= "none") ELSE '0' ;
8837
   clk_signb <= '1' WHEN clk(conv_integer(signb_clk)) = '1' ELSE '0' ;
8838
   aclr_signb <= '1' WHEN (aclr(conv_integer(signb_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8839
   ena_signb <= '1' WHEN ena(conv_integer(signb_clk)) = '1' ELSE '0' ;
8840
   signb_clk <= "0000" WHEN ((signb_clock = "0") OR (signb_clock = "none")) ELSE "0001" WHEN (signb_clock = "1") ELSE "0010" WHEN (signb_clock = "2") ELSE "0011" WHEN (signb_clock = "3") ELSE "0000" ;
8841
   signb_aclr <= "0000" WHEN ((signb_clear = "0") OR (signb_clear = "none")) ELSE "0001" WHEN (signb_clear = "1") ELSE "0010" WHEN (signb_clear = "2") ELSE "0011" WHEN (signb_clear = "3") ELSE "0000" ;
8842
   round_mac_reg : stratixii_mac_bit_register
8843
      GENERIC MAP (
8844
         power_up => '0')
8845
      PORT MAP (
8846
         data => round,
8847
         clk => clk_round,
8848
         aclr => aclr_round,
8849
         if_aclr => clear_round,
8850
         ena => ena_round,
8851
         dataout => round_out,
8852
         async => async_round);
8853
 
8854
   async_round <= '1' WHEN (round_clock = "none") ELSE '0' ;
8855
   clear_round <= '1' WHEN (round_clear /= "none") ELSE '0' ;
8856
   clk_round <= '1' WHEN clk(conv_integer(round_clk)) = '1' ELSE '0' ;
8857
   aclr_round <= '1' WHEN (aclr(conv_integer(round_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8858
   ena_round <= '1' WHEN ena(conv_integer(round_clk)) = '1' ELSE '0' ;
8859
   round_clk <= "0000" WHEN ((round_clock = "0") OR (round_clock = "none")) ELSE "0001" WHEN (round_clock = "1") ELSE "0010" WHEN (round_clock = "2") ELSE "0011" WHEN (round_clock = "3") ELSE "0000" ;
8860
   round_aclr <= "0000" WHEN ((round_clear = "0") OR (round_clear = "none")) ELSE "0001" WHEN (round_clear = "1") ELSE "0010" WHEN (round_clear = "2") ELSE "0011" WHEN (round_clear = "3") ELSE "0000" ;
8861
   saturate_mac_reg : stratixii_mac_bit_register
8862
      GENERIC MAP (
8863
         power_up => '0')
8864
      PORT MAP (
8865
         data => saturate,
8866
         clk => clk_saturate,
8867
         aclr => aclr_saturate,
8868
         if_aclr => clear_saturate,
8869
         ena => ena_saturate,
8870
         dataout => saturate_out,
8871
         async => async_saturate);
8872
 
8873
   async_saturate <= '1' WHEN (saturate_clock = "none") ELSE '0' ;
8874
   clear_saturate <= '1' WHEN (saturate_clear /= "none") ELSE '0' ;
8875
   clk_saturate <= '1' WHEN clk(conv_integer(saturate_clk)) = '1' ELSE '0' ;
8876
   aclr_saturate <= '1' WHEN (aclr(conv_integer(saturate_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8877
   ena_saturate <= '1' WHEN ena(conv_integer(saturate_clk)) = '1' ELSE '0' ;
8878
   saturate_clk <= "0000" WHEN ((saturate_clock = "0") OR (saturate_clock = "none")) ELSE "0001" WHEN (saturate_clock = "1") ELSE "0010" WHEN (saturate_clock = "2") ELSE "0011" WHEN (saturate_clock = "3") ELSE "0000" ;
8879
   saturate_aclr <= "0000" WHEN ((saturate_clear = "0") OR (saturate_clear = "none")) ELSE "0001" WHEN (saturate_clear = "1") ELSE "0010" WHEN (saturate_clear = "2") ELSE "0011" WHEN (saturate_clear = "3") ELSE "0000" ;
8880
   mode_mac_reg : stratixii_mac_bit_register
8881
      GENERIC MAP (
8882
         power_up => '0')
8883
      PORT MAP (
8884
         data => mode,
8885
         clk => clk_mode,
8886
         aclr => aclr_mode,
8887
         if_aclr => clear_mode,
8888
         ena => ena_mode,
8889
         dataout => mode_out,
8890
         async => async_mode);
8891
 
8892
   async_mode <= '1' WHEN (mode_clock = "none") ELSE '0' ;
8893
   clear_mode <= '1' WHEN (mode_clear /= "none") ELSE '0' ;
8894
   clk_mode <= '1' WHEN clk(conv_integer(mode_clk)) = '1' ELSE '0' ;
8895
   aclr_mode <= '1' WHEN (aclr(conv_integer(mode_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8896
   ena_mode <= '1' WHEN ena(conv_integer(mode_clk)) = '1' ELSE '0' ;
8897
   mode_clk <= "0000" WHEN ((mode_clock = "0") OR (mode_clock = "none")) ELSE "0001" WHEN (mode_clock = "1") ELSE "0010" WHEN (mode_clock = "2") ELSE "0011" WHEN (mode_clock = "3") ELSE "0000" ;
8898
   mode_aclr <= "0000" WHEN ((mode_clear = "0") OR (mode_clear = "none")) ELSE "0001" WHEN (mode_clear = "1") ELSE "0010" WHEN (mode_clear = "2") ELSE "0011" WHEN (mode_clear = "3") ELSE "0000" ;
8899
   zeroacc_mac_reg : stratixii_mac_bit_register
8900
      GENERIC MAP (
8901
         power_up => '0')
8902
      PORT MAP (
8903
         data => zeroacc,
8904
         clk => clk_zeroacc,
8905
         aclr => aclr_zeroacc,
8906
         if_aclr => clear_zeroacc,
8907
         ena => ena_zeroacc,
8908
         dataout => zeroacc_out,
8909
         async => async_zeroacc);
8910
 
8911
   async_zeroacc <= '1' WHEN (zeroacc_clock = "none") ELSE '0' ;
8912
   clear_zeroacc <= '1' WHEN (zeroacc_clear /= "none") ELSE '0' ;
8913
   clk_zeroacc <= '1' WHEN clk(conv_integer(zeroacc_clk)) = '1' ELSE '0' ;
8914
   aclr_zeroacc <= '1' WHEN (aclr(conv_integer(zeroacc_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8915
   ena_zeroacc <= '1' WHEN ena(conv_integer(zeroacc_clk)) = '1' ELSE '0' ;
8916
   zeroacc_clk <= "0000" WHEN ((zeroacc_clock = "0") OR (zeroacc_clock = "none")) ELSE "0001" WHEN (zeroacc_clock = "1") ELSE "0010" WHEN (zeroacc_clock = "2") ELSE "0011" WHEN (zeroacc_clock = "3") ELSE "0000" ;
8917
   zeroacc_aclr <= "0000" WHEN ((zeroacc_clear = "0") OR (zeroacc_clear = "none")) ELSE "0001" WHEN (zeroacc_clear = "1") ELSE "0010" WHEN (zeroacc_clear = "2") ELSE "0011" WHEN (zeroacc_clear = "3") ELSE "0000" ;
8918
   mac_multiply : stratixii_mac_mult_internal
8919
      GENERIC MAP (
8920
         dataa_width => dataa_width,
8921
         datab_width => datab_width,
8922
         dataout_width => dataa_width + datab_width,
8923
         dynamic_mode => dynamic_mode)
8924
      PORT MAP (
8925
         dataa => scanouta_tmp,
8926
         datab => scanoutb_tmp,
8927
         signa => signa_internal,
8928
         signb => signb_internal,
8929
         bypass => bypass,
8930
         scanouta => scanouta_tmp2,
8931
         scanoutb => scanoutb_tmp3,
8932
         dataout => mult_output);
8933
 
8934
   signa_internal <= '0' WHEN ((signa_internally_grounded = "true") AND (dynamic_mode = "no")) OR ((((signa_internally_grounded = "true") AND (dynamic_mode = "yes")) AND (zeroacc_out = '1')) AND (mode_out = '0')) ELSE signa_out ;
8935
   signb_internal <= '0' WHEN ((signb_internally_grounded = "true") AND (dynamic_mode = "no")) OR ((((signb_internally_grounded = "true") AND (dynamic_mode = "yes")) AND (zeroacc_out = '1')) AND (mode_out = '0')) ELSE signb_out ;
8936
   bypass <= '1' WHEN ((bypass_multiplier = "yes") AND (dynamic_mode = "no")) OR (((bypass_multiplier = "yes") AND (mode_out = '1')) AND (dynamic_mode = "yes")) ELSE '0' ;
8937
   tmp_60 <= '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & '0' & mult_output(35 DOWNTO 0);
8938
   port_tmp62 <= "1111";
8939
   port_tmp63 <= '0';
8940
   port_tmp64 <= "00000010";
8941
   port_tmp65 <= "00001111";
8942
   mac_rs_block : stratixii_mac_rs_block
8943
      GENERIC MAP (
8944
         block_type => "mac_mult",
8945
         dataa_width => dataa_width,
8946
         datab_width => datab_width)
8947
      PORT MAP (
8948
         operation => port_tmp62,
8949
         round => round_out,
8950
         saturate => saturate_out,
8951
         addnsub => port_tmp63,
8952
         signa => signa_out,
8953
         signb => signb_out,
8954
         signsize => port_tmp64,
8955
         roundsize => port_tmp65,
8956
         dataoutsize => mac_mult_dataoutsize,
8957
         dataa => scanouta_tmp,
8958
         datab => scanoutb_tmp,
8959
         datain => tmp_60,
8960
         dataout => dataout_rs);
8961
 
8962
   mac_mult_dataoutsize <= CONV_STD_LOGIC_VECTOR(dataa_width + datab_width, 8) ;
8963
 
8964
   dataout_reg <= tmp_60 when bypass = '1' else dataout_rs;
8965
 
8966
   dataout_mac_reg : stratixii_mac_register
8967
      GENERIC MAP (
8968
         data_width => dataa_width + datab_width,
8969
         power_up => '0')
8970
      PORT MAP (
8971
         data => dataout_reg((dataa_width + datab_width) -1 downto 0),
8972
         clk => clk_output,
8973
         aclr => aclr_output,
8974
         if_aclr => clear_output,
8975
         ena => ena_output,
8976
         dataout => dataout_tmp((dataa_width + datab_width) -1 downto 0),
8977
         async => async_output);
8978
 
8979
   async_output <= '1' WHEN (output_clock = "none") ELSE '0' ;
8980
   clear_output <= '1' WHEN (output_clear /= "none") ELSE '0' ;
8981
   clk_output <= '1' WHEN clk(conv_integer(output_clk)) = '1' ELSE '0' ;
8982
   aclr_output <= '1' WHEN (aclr(conv_integer(output_aclr)) OR NOT devclrn OR NOT devpor) = '1' ELSE '0' ;
8983
   ena_output <= '1' WHEN ena(conv_integer(output_clk)) = '1' ELSE '0' ;
8984
   output_clk <= "0000" WHEN ((output_clock = "0") OR (output_clock = "none")) ELSE "0001" WHEN (output_clock = "1") ELSE "0010" WHEN (output_clock = "2") ELSE "0011" WHEN (output_clock = "3") ELSE "0000" ;
8985
   output_aclr <= "0000" WHEN ((output_clear = "0") OR (output_clear = "none")) ELSE "0001" WHEN (output_clear = "1") ELSE "0010" WHEN (output_clear = "2") ELSE "0011" WHEN (output_clear = "3") ELSE "0000" ;
8986
 
8987
END arch;
8988
 
8989
 
8990
 
8991
--/////////////////////////////////////////////////////////////////////////////
8992
--
8993
--                           STRATIXII_MAC_DYNAMIC_MUX
8994
--
8995
--/////////////////////////////////////////////////////////////////////////////
8996
 
8997
LIBRARY IEEE;
8998
USE ieee.std_logic_1164.all;
8999
use IEEE.VITAL_Timing.all;
9000
use IEEE.VITAL_Primitives.all;
9001
use work.stratixii_atom_pack.all;
9002
 
9003
ENTITY stratixii_mac_dynamic_mux IS
9004
   PORT (
9005
      ab                      : IN std_logic_vector(71 DOWNTO 0) := (others => '0');
9006
      cd                      : IN std_logic_vector(71 DOWNTO 0) := (others => '0');
9007
      sata                    : IN std_logic := '0';
9008
      satb                    : IN std_logic := '0';
9009
      satc                    : IN std_logic := '0';
9010
      satd                    : IN std_logic := '0';
9011
      multsatab               : IN std_logic := '0';
9012
      multsatcd               : IN std_logic := '0';
9013
      outsatab                : IN std_logic := '0';
9014
      outsatcd                : IN std_logic := '0';
9015
      multabsaturate          : IN std_logic := '0';
9016
      multcdsaturate          : IN std_logic := '0';
9017
      saturateab              : IN std_logic := '0';
9018
      saturatecd              : IN std_logic := '0';
9019
      overab                  : IN std_logic := '0';
9020
      overcd                  : IN std_logic := '0';
9021
      sum                     : IN std_logic_vector(71 DOWNTO 0) := (others => '0');
9022
      m36                     : IN std_logic_vector(71 DOWNTO 0) := (others => '0');
9023
      bypass                  : IN std_logic_vector(143 DOWNTO 0) := (others => '0');
9024
      operation               : IN std_logic_vector(3 DOWNTO 0) := (others => '0');
9025
      dataout                 : OUT std_logic_vector(143 DOWNTO 0) := (others => '0');
9026
      accoverflow             : OUT std_logic := '0');
9027
END stratixii_mac_dynamic_mux;
9028
 
9029
ARCHITECTURE arch OF stratixii_mac_dynamic_mux IS
9030
 
9031
 
9032
   SIGNAL dataout_tmp              :  std_logic_vector(143 DOWNTO 0) := (others => '0');
9033
   SIGNAL accoverflow_tmp          :  std_logic := '0';
9034
   SIGNAL dataout_tmp1            :  std_logic_vector(143 DOWNTO 0) := (others => '0');
9035
   SIGNAL accoverflow_tmp2        :  std_logic := '0';
9036
 
9037
BEGIN
9038
   dataout <= dataout_tmp1;
9039
   accoverflow <= accoverflow_tmp2;
9040
 
9041
   PROCESS (ab, cd, sata, satb, satc, satd, multsatab, multsatcd, outsatab, outsatcd, multabsaturate, multcdsaturate, saturateab, saturatecd, overab, overcd, sum, m36, bypass, operation)
9042
      VARIABLE dataout_tmp_tmp3  : std_logic_vector(143 DOWNTO 0) := (others => '0');
9043
      VARIABLE accoverflow_tmp_tmp4  : std_logic := '0';
9044
      VARIABLE temp_tmp5  : std_logic_vector(1 DOWNTO 0) := (others => '0');
9045
      VARIABLE temp_tmp6  : std_logic_vector(1 DOWNTO 0) := (others => '0');
9046
      VARIABLE temp_tmp7  : std_logic_vector(3 DOWNTO 0) := (others => '0');
9047
      VARIABLE temp_tmp8  : std_logic_vector(1 DOWNTO 0) := (others => '0');
9048
      VARIABLE temp_tmp9  : std_logic_vector(1 DOWNTO 0) := (others => '0');
9049
   BEGIN
9050
      CASE operation IS
9051
         WHEN "0000" =>
9052
                  dataout_tmp_tmp3 := bypass;
9053
                  accoverflow_tmp_tmp4 := '0';
9054
         WHEN "0100" =>
9055
                  temp_tmp5 := saturateab & multabsaturate;
9056
                  CASE temp_tmp5 IS
9057
                     WHEN "00" =>
9058
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 36) & ab(35 DOWNTO 0);
9059
                     WHEN "01" =>
9060
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 36) & ab(35 DOWNTO 2) & multsatab & ab(0);
9061
                     WHEN "10" =>
9062
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 36) & ab(35 DOWNTO 3) & outsatab & ab(1 DOWNTO 0);
9063
                     WHEN "11" =>
9064
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 36) & ab(35 DOWNTO 3) & outsatab & multsatab & ab(0);
9065
                     WHEN OTHERS  =>
9066
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 36) & ab(35 DOWNTO 0);
9067
 
9068
                  END CASE;
9069
                  accoverflow_tmp_tmp4 := overab;
9070
         WHEN "0001" =>
9071
                  IF (multabsaturate = '1') THEN
9072
                     dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 2) & satb & sata;
9073
                  ELSE
9074
                     dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 0);
9075
                  END IF;
9076
                  accoverflow_tmp_tmp4 := '0';
9077
         WHEN "0010" =>
9078
                  temp_tmp6 := multsatcd & multsatab;
9079
                  CASE temp_tmp6 IS
9080
                     WHEN "00" =>
9081
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & sum(71 DOWNTO 0);
9082
                              accoverflow_tmp_tmp4 := '0';
9083
                     WHEN "01" =>
9084
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & sum(71 DOWNTO 2) & satb & sata;
9085
                              accoverflow_tmp_tmp4 := '0';
9086
                     WHEN "10" =>
9087
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & sum(71 DOWNTO 3) & satc & sum(1 DOWNTO 0);
9088
                              accoverflow_tmp_tmp4 := satd;
9089
                     WHEN "11" =>
9090
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & sum(71 DOWNTO 3) & satc & satb & sata;
9091
                              accoverflow_tmp_tmp4 := satd;
9092
                     WHEN OTHERS  =>
9093
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & sum(71 DOWNTO 0);
9094
                              accoverflow_tmp_tmp4 := '0';
9095
 
9096
                  END CASE;
9097
         WHEN "0111" =>
9098
                  dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & m36;
9099
                  accoverflow_tmp_tmp4 := '0';
9100
         WHEN "1100" =>
9101
                  temp_tmp7 := saturatecd & saturateab & multsatcd & multsatab;
9102
                  CASE temp_tmp7 IS
9103
                     WHEN "0000" =>
9104
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 0);
9105
                     WHEN "0001" =>
9106
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 2) & multsatab & ab(0);
9107
                     WHEN "0010" =>
9108
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 2) & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 0);
9109
                     WHEN "0011" =>
9110
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 2) & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 2) & multsatab & ab(0);
9111
                     WHEN "0100" =>
9112
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & ab(1 DOWNTO 0);
9113
                     WHEN "0101" =>
9114
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & multsatab & ab(0);
9115
                     WHEN "0110" =>
9116
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 2) & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & ab(1 DOWNTO 0);
9117
                     WHEN "0111" =>
9118
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 2) & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & multsatab & ab(0);
9119
                     WHEN "1000" =>
9120
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & cd(1 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 0);
9121
                     WHEN "1001" =>
9122
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & cd(1 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 2) & multsatab & ab(0);
9123
                     WHEN "1010" =>
9124
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 0);
9125
                     WHEN "1011" =>
9126
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 2) & multsatab & ab(0);
9127
                     WHEN "1100" =>
9128
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & cd(1 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & ab(1 DOWNTO 0);
9129
                     WHEN "1101" =>
9130
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & cd(1 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & multsatab & ab(0);
9131
                     WHEN "1110" =>
9132
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & ab(1 DOWNTO 0);
9133
                     WHEN "1111" =>
9134
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & multsatcd & cd(0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & multsatab & ab(0);
9135
                     WHEN OTHERS  =>
9136
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 0) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 0);
9137
 
9138
                  END CASE;
9139
                  accoverflow_tmp_tmp4 := overab;
9140
         WHEN "1101" =>
9141
                  temp_tmp8 := saturateab & multabsaturate;
9142
                  CASE temp_tmp8 IS
9143
                     WHEN "00" =>
9144
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 36) & ab(35 DOWNTO 0);
9145
                     WHEN "01" =>
9146
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 2) & multsatab & ab(0);
9147
                     WHEN "10" =>
9148
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & ab(1 DOWNTO 0);
9149
                     WHEN "11" =>
9150
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 3) & outsatab & multsatab & ab(0);
9151
                     WHEN OTHERS  =>
9152
                              dataout_tmp_tmp3 := bypass(143 DOWNTO 72) & ab(71 DOWNTO 53) & overab & ab(51 DOWNTO 36) & ab(35 DOWNTO 0);
9153
 
9154
                  END CASE;
9155
                  accoverflow_tmp_tmp4 := overab;
9156
         WHEN "1110" =>
9157
                  temp_tmp9 := saturatecd & multcdsaturate;
9158
                  CASE temp_tmp9 IS
9159
                     WHEN "00" =>
9160
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 0) & bypass(71 DOWNTO 0);
9161
                     WHEN "01" =>
9162
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 2) & multsatcd & cd(0) & bypass(71 DOWNTO 0);
9163
                     WHEN "10" =>
9164
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & cd(1 DOWNTO 0) & bypass(71 DOWNTO 0);
9165
                     WHEN "11" =>
9166
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 3) & outsatcd & multsatcd & cd(0) & bypass(71 DOWNTO 0);
9167
                     WHEN OTHERS  =>
9168
                              dataout_tmp_tmp3 := cd(71 DOWNTO 53) & overcd & cd(51 DOWNTO 0) & bypass(71 DOWNTO 0);
9169
 
9170
                  END CASE;
9171
                  accoverflow_tmp_tmp4 := overcd;
9172
         WHEN OTHERS  =>
9173
                  dataout_tmp_tmp3 := bypass;
9174
                  accoverflow_tmp_tmp4 := '0';
9175
 
9176
      END CASE;
9177
      dataout_tmp <= dataout_tmp_tmp3;
9178
      accoverflow_tmp <= accoverflow_tmp_tmp4;
9179
   END PROCESS;
9180
   dataout_tmp1 <= dataout_tmp ;
9181
   accoverflow_tmp2 <= accoverflow_tmp ;
9182
END arch;
9183
 
9184
--/////////////////////////////////////////////////////////////////////////////
9185
--
9186
--                             STRATIXII_MAC_PIN_MAP
9187
--
9188
--/////////////////////////////////////////////////////////////////////////////
9189
 
9190
LIBRARY IEEE;
9191
USE ieee.std_logic_1164.all;
9192
use IEEE.VITAL_Timing.all;
9193
use IEEE.VITAL_Primitives.all;
9194
use work.stratixii_atom_pack.all;
9195
 
9196
ENTITY stratixii_mac_pin_map IS
9197
   GENERIC (
9198
      tipd_addnsub : VitalDelayType01 := DefPropDelay01;
9199
      data_width :              integer := 144;
9200
      tipd_datain               : VitalDelayArrayType01(143 downto 0) := (OTHERS => (20 ps,20 ps));
9201
      operation_mode            :  string := "output_only";
9202
      pinmap                    :  string := "map");
9203
   PORT (
9204
      datain                  : IN std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
9205
      operation               : IN std_logic_vector(3 DOWNTO 0) := (others => '0');
9206
          addnsub                                 : IN std_logic := '0';
9207
      dataout                 : OUT std_logic_vector(data_width -1 DOWNTO 0) := (others => '0'));
9208
END stratixii_mac_pin_map;
9209
 
9210
ARCHITECTURE arch OF stratixii_mac_pin_map IS
9211
   SIGNAL addnsub_ipd : std_logic := '0';
9212
   SIGNAL datain_ipd             :  std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
9213
   SIGNAL dataout_tmp              :  std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
9214
   SIGNAL dataout_tmp2            :  std_logic_vector(data_width -1 DOWNTO 0) := (others => '0');
9215
 
9216
BEGIN
9217
    WireDelay : block
9218
    begin
9219
        VitalWireDelay (addnsub_ipd, addnsub, tipd_addnsub);
9220
        loopbits : FOR i in datain'RANGE GENERATE
9221
            VitalWireDelay (datain_ipd(i), datain(i), tipd_datain(i));
9222
        END GENERATE;
9223
    end block;
9224
 
9225
   dataout <= dataout_tmp2(dataout'range);
9226
 
9227
   PROCESS (datain_ipd, addnsub_ipd)
9228
      VARIABLE dataout_tmp_tmp3  : std_logic_vector(143 DOWNTO 0) := (others => '0');
9229
   BEGIN
9230
      IF (operation_mode = "dynamic") THEN
9231
         IF (pinmap = "map") THEN
9232
           CASE operation IS
9233
             WHEN "1100" =>
9234
               dataout_tmp_tmp3 := "XXXXXXXXXXXXXXXXXXX" & datain_ipd(123 DOWNTO 108) &
9235
                                   'X' & datain_ipd(107 DOWNTO 72) &
9236
                                   "XXXXXXXXXXXXXXXXXXX" & datain_ipd(51 DOWNTO 36) &
9237
                                   'X' & datain_ipd(35 DOWNTO 0);
9238
             WHEN "1101" =>
9239
               dataout_tmp_tmp3 := datain_ipd(143 DOWNTO 72)& "XXXXXXXXXXXXXXXXXXX" & datain_ipd(51 DOWNTO 36) & 'X' & datain_ipd(35 DOWNTO 0);
9240
             WHEN "1110" =>
9241
               dataout_tmp_tmp3 := "XXXXXXXXXXXXXXXXXXX" & datain_ipd(123 DOWNTO 108) & 'X' & datain_ipd(107 DOWNTO 0);
9242
             WHEN "0111" =>
9243
                                IF (addnsub_ipd = '1') THEN
9244
                       dataout_tmp_tmp3(17 DOWNTO 0) := datain_ipd(17 DOWNTO 0);
9245
                       dataout_tmp_tmp3(35 DOWNTO 18) := datain_ipd(53 DOWNTO 36);
9246
                       dataout_tmp_tmp3(53 DOWNTO 36) := datain_ipd(35 DOWNTO 18);
9247
                       dataout_tmp_tmp3(71 DOWNTO 54) := datain_ipd(71 DOWNTO 54);
9248
                                ELSE
9249
                       dataout_tmp_tmp3(17 DOWNTO 0) := "XXXXXXXXXXXXXXXXXX";
9250
                       dataout_tmp_tmp3(35 DOWNTO 18) := "XXXXXXXXXXXXXXXXXX";
9251
                       dataout_tmp_tmp3(53 DOWNTO 36) := "XXXXXXXXXXXXXXXXXX";
9252
                       dataout_tmp_tmp3(71 DOWNTO 54) := "XXXXXXXXXXXXXXXXXX";
9253
                                END IF;
9254
               dataout_tmp_tmp3(143 DOWNTO 72) := "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
9255
             WHEN OTHERS  =>
9256
               dataout_tmp_tmp3 := datain_ipd;
9257
           END CASE;
9258
         ELSE
9259
            CASE operation IS
9260
               WHEN "1100" =>
9261
                        dataout_tmp_tmp3(35 DOWNTO 0) := datain_ipd(35 DOWNTO 0);
9262
                        dataout_tmp_tmp3(70 DOWNTO 36) := datain_ipd(71 DOWNTO 37);
9263
                        dataout_tmp_tmp3(107 DOWNTO 72) := datain_ipd(107 DOWNTO 72);
9264
                        dataout_tmp_tmp3(142 DOWNTO 108) := datain_ipd(143 DOWNTO 109);
9265
               WHEN "1101" =>
9266
                        dataout_tmp_tmp3(35 DOWNTO 0) := datain_ipd(35 DOWNTO 0);
9267
                        dataout_tmp_tmp3(70 DOWNTO 36) := datain_ipd(71 DOWNTO 37);
9268
                        dataout_tmp_tmp3(143 DOWNTO 72) := datain_ipd(143 DOWNTO 72);
9269
               WHEN "1110" =>
9270
                        dataout_tmp_tmp3(107 DOWNTO 0) := datain_ipd(107 DOWNTO 0);
9271
                        dataout_tmp_tmp3(107 DOWNTO 72) := datain_ipd(107 DOWNTO 72);
9272
                        dataout_tmp_tmp3(142 DOWNTO 108) := datain_ipd(143 DOWNTO 109);
9273
               WHEN "0111" =>
9274
                        dataout_tmp_tmp3(17 DOWNTO 0) := datain_ipd(17 DOWNTO 0);
9275
                        dataout_tmp_tmp3(53 DOWNTO 36) := datain_ipd(35 DOWNTO 18);
9276
                        dataout_tmp_tmp3(35 DOWNTO 18) := datain_ipd(53 DOWNTO 36);
9277
                        dataout_tmp_tmp3(71 DOWNTO 54) := datain_ipd(71 DOWNTO 54);
9278
                        dataout_tmp_tmp3(143 DOWNTO 72) := "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
9279
               WHEN OTHERS  =>
9280
                        dataout_tmp_tmp3 := datain_ipd;
9281
 
9282
            END CASE;
9283
         END IF;
9284
      ELSE
9285
         dataout_tmp_tmp3 := datain_ipd;
9286
      END IF;
9287
      dataout_tmp <= dataout_tmp_tmp3;
9288
   END PROCESS;
9289
   dataout_tmp2 <= dataout_tmp ;
9290
 
9291
END arch;
9292
 
9293
 
9294
--/////////////////////////////////////////////////////////////////////////////
9295
--
9296
-- Module Name : stratixii_lvds_tx_reg
9297
--
9298
-- Description : Simulation model for a simple DFF.
9299
--               This is used for registering the enable inputs.
9300
--               No timing, powers upto 0.
9301
--
9302
--/////////////////////////////////////////////////////////////////////////////
9303
 
9304
LIBRARY IEEE, std;
9305
USE ieee.std_logic_1164.all;
9306
USE IEEE.VITAL_Timing.all;
9307
USE IEEE.VITAL_Primitives.all;
9308
USE work.stratixii_atom_pack.all;
9309
 
9310
ENTITY stratixii_lvds_tx_reg is
9311
    GENERIC ( MsgOn                       : Boolean := DefGlitchMsgOn;
9312
              XOn                         : Boolean := DefGlitchXOn;
9313
              MsgOnChecks                 : Boolean := DefMsgOnChecks;
9314
              XOnChecks                   : Boolean := DefXOnChecks;
9315
              TimingChecksOn              : Boolean := True;
9316
              InstancePath                : String := "*";
9317
              tipd_clk                    : VitalDelayType01 := DefpropDelay01;
9318
              tipd_ena                    : VitalDelayType01 := DefpropDelay01;
9319
              tipd_d                      : VitalDelayType01 := DefpropDelay01;
9320
              tsetup_d_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
9321
              thold_d_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
9322
              tpd_clk_q_posedge           : VitalDelayType01 := DefPropDelay01
9323
            );
9324
 
9325
    PORT    ( q                       : OUT std_logic;
9326
              clk                     : IN std_logic;
9327
              ena                     : IN std_logic;
9328
              d                       : IN std_logic;
9329
              clrn                    : IN std_logic;
9330
              prn                     : IN std_logic
9331
            );
9332
    attribute VITAL_LEVEL0 of stratixii_lvds_tx_reg : ENTITY is TRUE;
9333
END stratixii_lvds_tx_reg;
9334
 
9335
ARCHITECTURE vital_stratixii_lvds_tx_reg of stratixii_lvds_tx_reg is
9336
 
9337
    attribute VITAL_LEVEL0 of vital_stratixii_lvds_tx_reg : architecture is TRUE;
9338
 
9339
    -- INTERNAL SIGNALS
9340
    signal clk_ipd                  :  std_logic;
9341
    signal d_ipd                    :  std_logic;
9342
    signal ena_ipd                  :  std_logic;
9343
 
9344
    begin
9345
 
9346
        ----------------------
9347
        --  INPUT PATH DELAYs
9348
        ----------------------
9349
        WireDelay : block
9350
        begin
9351
            VitalWireDelay (clk_ipd, clk, tipd_clk);
9352
            VitalWireDelay (ena_ipd, ena, tipd_ena);
9353
            VitalWireDelay (d_ipd, d, tipd_d);
9354
        end block;
9355
 
9356
        process (clk_ipd, clrn, prn)
9357
        variable q_tmp :  std_logic := '0';
9358
        variable q_VitalGlitchData : VitalGlitchDataType;
9359
        variable Tviol_d_clk : std_ulogic := '0';
9360
        variable TimingData_d_clk : VitalTimingDataType := VitalTimingDataInit;
9361
        begin
9362
 
9363
            ------------------------
9364
            --  Timing Check Section
9365
            ------------------------
9366
            if (TimingChecksOn) then
9367
               VitalSetupHoldCheck (
9368
                      Violation       => Tviol_d_clk,
9369
                      TimingData      => TimingData_d_clk,
9370
                      TestSignal      => d_ipd,
9371
                      TestSignalName  => "d",
9372
                      RefSignal       => clk_ipd,
9373
                      RefSignalName   => "clk",
9374
                      SetupHigh       => tsetup_d_clk_noedge_posedge,
9375
                      SetupLow        => tsetup_d_clk_noedge_posedge,
9376
                      HoldHigh        => thold_d_clk_noedge_posedge,
9377
                      HoldLow         => thold_d_clk_noedge_posedge,
9378
                      CheckEnabled    => TO_X01( (NOT ena_ipd) ) /= '1',
9379
                      RefTransition   => '/',
9380
                      HeaderMsg       => InstancePath & "/stratixii_lvds_tx_reg",
9381
                      XOn             => XOnChecks,
9382
                      MsgOn           => MsgOnChecks );
9383
            end if;
9384
 
9385
            if (prn = '0') then
9386
                q_tmp := '1';
9387
            elsif (clrn = '0') then
9388
                q_tmp := '0';
9389
            elsif (clk_ipd'event and clk_ipd = '1') then
9390
                if (ena_ipd = '1') then
9391
                    q_tmp := d_ipd;
9392
                end if;
9393
            end if;
9394
 
9395
            ----------------------
9396
            --  Path Delay Section
9397
            ----------------------
9398
            VitalPathDelay01 (
9399
                        OutSignal => q,
9400
                        OutSignalName => "Q",
9401
                        OutTemp => q_tmp,
9402
                        Paths => (1 => (clk_ipd'last_event, tpd_clk_q_posedge, TRUE)),
9403
                        GlitchData => q_VitalGlitchData,
9404
                        Mode => DefGlitchMode,
9405
                        XOn  => XOn,
9406
                        MsgOn  => MsgOn );
9407
 
9408
        end process;
9409
 
9410
end vital_stratixii_lvds_tx_reg;
9411
 
9412
--////////////////////////////////////////////////////////////////////////////
9413
--
9414
-- Entity name : stratixii_lvds_tx_parallel_register
9415
--
9416
-- Description : Register for the 10 data input channels of the StratixII
9417
--               LVDS Tx
9418
--
9419
--////////////////////////////////////////////////////////////////////////////
9420
 
9421
LIBRARY IEEE, std;
9422
USE IEEE.std_logic_1164.all;
9423
USE IEEE.VITAL_Timing.all;
9424
USE IEEE.VITAL_Primitives.all;
9425
USE work.stratixii_atom_pack.all;
9426
USE std.textio.all;
9427
 
9428
ENTITY stratixii_lvds_tx_parallel_register is
9429
    GENERIC ( channel_width                     : integer := 10;
9430
              TimingChecksOn                    : Boolean := True;
9431
              MsgOn                             : Boolean := DefGlitchMsgOn;
9432
              XOn                               : Boolean := DefGlitchXOn;
9433
              MsgOnChecks                       : Boolean := DefMsgOnChecks;
9434
              XOnChecks                         : Boolean := DefXOnChecks;
9435
              InstancePath                      : String := "*";
9436
              tsetup_datain_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
9437
              thold_datain_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
9438
              tpd_clk_dataout_posedge           : VitalDelayType01 := DefPropDelay01;
9439
              tipd_clk                          : VitalDelayType01 := DefpropDelay01;
9440
              tipd_enable                       : VitalDelayType01 := DefpropDelay01;
9441
              tipd_datain                       : VitalDelayArrayType01(9 downto 0) := (OTHERS => DefpropDelay01)
9442
            );
9443
 
9444
    PORT    ( clk                            : in std_logic;
9445
              enable                         : in std_logic;
9446
              datain                         : in std_logic_vector(channel_width - 1 downto 0);
9447
              devclrn                        : in std_logic := '1';
9448
              devpor                         : in std_logic := '1';
9449
              dataout                        : out std_logic_vector(channel_width - 1 downto 0)
9450
            );
9451
 
9452
END stratixii_lvds_tx_parallel_register;
9453
 
9454
ARCHITECTURE vital_tx_reg of stratixii_lvds_tx_parallel_register is
9455
    signal clk_ipd : std_logic;
9456
    signal enable_ipd : std_logic;
9457
    signal datain_ipd : std_logic_vector(channel_width - 1 downto 0);
9458
 
9459
begin
9460
 
9461
    ----------------------
9462
    --  INPUT PATH DELAYs
9463
    ----------------------
9464
    WireDelay : block
9465
    begin
9466
        VitalWireDelay (clk_ipd, clk, tipd_clk);
9467
        VitalWireDelay (enable_ipd, enable, tipd_enable);
9468
        loopbits : FOR i in datain'RANGE GENERATE
9469
            VitalWireDelay (datain_ipd(i), datain(i), tipd_datain(i));
9470
        END GENERATE;
9471
    end block;
9472
 
9473
    VITAL: process (clk_ipd, enable_ipd, datain_ipd, devpor, devclrn)
9474
        variable Tviol_datain_clk : std_ulogic := '0';
9475
        variable TimingData_datain_clk : VitalTimingDataType := VitalTimingDataInit;
9476
        variable dataout_VitalGlitchDataArray : VitalGlitchDataArrayType(9 downto 0);
9477
        variable i : integer := 0;
9478
        variable dataout_tmp : std_logic_vector(channel_width - 1 downto 0);
9479
        variable CQDelay : TIME := 0 ns;
9480
    begin
9481
 
9482
        if (now = 0 ns) then
9483
             dataout_tmp := (OTHERS => '0');
9484
        end if;
9485
 
9486
        ------------------------
9487
        --  Timing Check Section
9488
        ------------------------
9489
        if (TimingChecksOn) then
9490
 
9491
            VitalSetupHoldCheck (
9492
                Violation       => Tviol_datain_clk,
9493
                TimingData      => TimingData_datain_clk,
9494
                TestSignal      => datain_ipd,
9495
                TestSignalName  => "DATAIN",
9496
                RefSignal       => clk_ipd,
9497
                RefSignalName   => "CLK",
9498
                SetupHigh       => tsetup_datain_clk_noedge_posedge,
9499
                SetupLow        => tsetup_datain_clk_noedge_posedge,
9500
                HoldHigh        => thold_datain_clk_noedge_posedge,
9501
                HoldLow         => thold_datain_clk_noedge_posedge,
9502
                RefTransition   => '/',
9503
                HeaderMsg       => InstancePath & "/stratixii_lvds_tx_parallel_register",
9504
                XOn             => XOn,
9505
                MsgOn           => MsgOnChecks );
9506
        end if;
9507
 
9508
        if ((devpor = '0') or (devclrn = '0')) then
9509
            dataout_tmp := (OTHERS => '0');
9510
        else
9511
            if (clk_ipd'event and clk_ipd = '1') then
9512
                if (enable_ipd = '1') then
9513
                    dataout_tmp := datain_ipd;
9514
                end if;
9515
            end if;
9516
        end if;
9517
 
9518
        ----------------------
9519
        --  Path Delay Section
9520
        ----------------------
9521
        CQDelay := SelectDelay(
9522
                        (1 => (clk_ipd'last_event, tpd_clk_dataout_posedge, TRUE))
9523
                    );
9524
        dataout <= TRANSPORT dataout_tmp AFTER CQDelay;
9525
 
9526
    end process;
9527
 
9528
end vital_tx_reg;
9529
 
9530
--////////////////////////////////////////////////////////////////////////////
9531
--
9532
-- Entity name : stratixii_lvds_tx_out_block
9533
--
9534
-- Description : Negative-edge triggered register on the Tx output.
9535
--               Also, optionally generates an identical/inverted output clock
9536
--
9537
--////////////////////////////////////////////////////////////////////////////
9538
 
9539
LIBRARY IEEE, std;
9540
USE IEEE.std_logic_1164.all;
9541
USE IEEE.VITAL_Timing.all;
9542
USE IEEE.VITAL_Primitives.all;
9543
USE work.stratixii_atom_pack.all;
9544
USE std.textio.all;
9545
 
9546
ENTITY stratixii_lvds_tx_out_block is
9547
    GENERIC ( bypass_serializer          : String := "false";
9548
              invert_clock               : String := "false";
9549
              use_falling_clock_edge     : String := "false";
9550
              TimingChecksOn             : Boolean := True;
9551
              MsgOn                      : Boolean := DefGlitchMsgOn;
9552
              XOn                        : Boolean := DefGlitchXOn;
9553
              MsgOnChecks                : Boolean := DefMsgOnChecks;
9554
              XOnChecks                  : Boolean := DefXOnChecks;
9555
              InstancePath               : String := "*";
9556
              tpd_clk_dataout            : VitalDelayType01 := DefPropDelay01;
9557
              tpd_clk_dataout_negedge    : VitalDelayType01 := DefPropDelay01;
9558
              tipd_clk                   : VitalDelayType01 := DefpropDelay01;
9559
              tipd_datain                : VitalDelayType01 := DefpropDelay01
9560
            );
9561
 
9562
    PORT    ( clk                        : in std_logic;
9563
              datain                     : in std_logic;
9564
              devclrn                    : in std_logic := '1';
9565
              devpor                     : in std_logic := '1';
9566
              dataout                    : out std_logic
9567
            );
9568
 
9569
END stratixii_lvds_tx_out_block;
9570
 
9571
ARCHITECTURE vital_tx_out_block of stratixii_lvds_tx_out_block is
9572
    signal clk_ipd : std_logic;
9573
    signal datain_ipd : std_logic;
9574
    signal inv_clk : integer;
9575
 
9576
begin
9577
 
9578
    ----------------------
9579
    --  INPUT PATH DELAYs
9580
    ----------------------
9581
    WireDelay : block
9582
    begin
9583
        VitalWireDelay (clk_ipd, clk, tipd_clk);
9584
        VitalWireDelay (datain_ipd, datain, tipd_datain);
9585
    end block;
9586
 
9587
 
9588
    VITAL: process (clk_ipd, datain_ipd, devpor, devclrn)
9589
        variable dataout_VitalGlitchData : VitalGlitchDataType;
9590
        variable dataout_tmp : std_logic;
9591
    begin
9592
        if (now = 0 ns) then
9593
            dataout_tmp := '0';
9594
        else
9595
            if (bypass_serializer = "false") then
9596
                if (use_falling_clock_edge = "false") then
9597
                    dataout_tmp := datain_ipd;
9598
                end if;
9599
 
9600
                if (clk_ipd'event and clk_ipd = '0') then
9601
                    if (use_falling_clock_edge = "true") then
9602
                        dataout_tmp := datain_ipd;
9603
                    end if;
9604
                end if;
9605
            else
9606
                if (invert_clock = "false") then
9607
                    dataout_tmp := clk_ipd;
9608
                else
9609
                    dataout_tmp := NOT (clk_ipd);
9610
                end if;
9611
 
9612
                if (invert_clock = "false") then
9613
                    inv_clk <= 0;
9614
                else
9615
                    inv_clk <= 1;
9616
                end if;
9617
            end if;
9618
        end if;
9619
 
9620
        ----------------------
9621
        --  Path Delay Section
9622
        ----------------------
9623
        if (bypass_serializer = "false") then
9624
            VitalPathDelay01 (
9625
                OutSignal => dataout,
9626
                OutSignalName => "DATAOUT",
9627
                OutTemp => dataout_tmp,
9628
                Paths => (0 => (datain_ipd'last_event, DefpropDelay01, TRUE),
9629
                          1 => (clk_ipd'last_event, tpd_clk_dataout_negedge, TRUE)),
9630
                GlitchData => dataout_VitalGlitchData,
9631
                Mode => DefGlitchMode,
9632
                XOn  => XOn,
9633
                MsgOn  => MsgOn );
9634
        end if;
9635
 
9636
        if (bypass_serializer = "true") then
9637
            VitalPathDelay01 (
9638
                OutSignal => dataout,
9639
                OutSignalName => "DATAOUT",
9640
                OutTemp => dataout_tmp,
9641
                Paths => (1 => (clk_ipd'last_event, tpd_clk_dataout, TRUE)),
9642
                GlitchData => dataout_VitalGlitchData,
9643
                Mode => DefGlitchMode,
9644
                XOn  => XOn,
9645
                MsgOn  => MsgOn );
9646
        end if;
9647
    end process;
9648
end vital_tx_out_block;
9649
 
9650
--////////////////////////////////////////////////////////////////////////////
9651
--
9652
-- Entity name : stratixii_lvds_transmitter
9653
--
9654
-- Description : Timing simulation model for the StratixII LVDS Tx WYSIWYG.
9655
--               It instantiates the following sub-modules :
9656
--               1) primitive DFFE
9657
--               2) StratixII_lvds_tx_parallel_register and
9658
--               3) StratixII_lvds_tx_out_block
9659
--
9660
--////////////////////////////////////////////////////////////////////////////
9661
LIBRARY IEEE, std;
9662
USE IEEE.std_logic_1164.all;
9663
USE IEEE.VITAL_Timing.all;
9664
USE IEEE.VITAL_Primitives.all;
9665
USE work.stratixii_atom_pack.all;
9666
USE std.textio.all;
9667
USE work.stratixii_lvds_tx_parallel_register;
9668
USE work.stratixii_lvds_tx_out_block;
9669
USE work.stratixii_lvds_tx_reg;
9670
 
9671
ENTITY stratixii_lvds_transmitter is
9672
    GENERIC ( channel_width                    : integer := 10;
9673
              bypass_serializer                : String  := "false";
9674
              invert_clock                     : String  := "false";
9675
              use_falling_clock_edge           : String  := "false";
9676
              use_serial_data_input            : String  := "false";
9677
              use_post_dpa_serial_data_input   : String  := "false";
9678
              preemphasis_setting              : integer := 0;
9679
              vod_setting                      : integer := 0;
9680
              differential_drive               : integer := 0;
9681
              lpm_type                         : string  := "stratixii_lvds_transmitter";
9682
              TimingChecksOn                   : Boolean := True;
9683
              MsgOn                            : Boolean := DefGlitchMsgOn;
9684
              XOn                              : Boolean := DefGlitchXOn;
9685
              MsgOnChecks                      : Boolean := DefMsgOnChecks;
9686
              XOnChecks                        : Boolean := DefXOnChecks;
9687
              InstancePath                     : String := "*";
9688
              tpd_clk0_dataout_posedge         : VitalDelayType01 := DefPropDelay01;
9689
              tpd_clk0_dataout_negedge         : VitalDelayType01 := DefPropDelay01;
9690
              tpd_serialdatain_dataout         : VitalDelayType01 := DefPropDelay01;
9691
              tpd_postdpaserialdatain_dataout  : VitalDelayType01 := DefPropDelay01;
9692
              tipd_clk0                        : VitalDelayType01 := DefpropDelay01;
9693
              tipd_enable0                     : VitalDelayType01 := DefpropDelay01;
9694
              tipd_datain                      : VitalDelayArrayType01(9 downto 0) := (OTHERS => DefpropDelay01);
9695
              tipd_serialdatain                : VitalDelayType01 := DefpropDelay01;
9696
              tipd_postdpaserialdatain         : VitalDelayType01 := DefpropDelay01
9697
            );
9698
 
9699
    PORT    ( clk0                     : in std_logic;
9700
              enable0                  : in std_logic;
9701
              datain                   : in std_logic_vector(channel_width - 1 downto 0);
9702
              serialdatain             : in std_logic := '0';
9703
              postdpaserialdatain      : in std_logic := '0';
9704
              devclrn                  : in std_logic := '1';
9705
              devpor                   : in std_logic := '1';
9706
              dataout                  : out std_logic;
9707
              serialfdbkout            : out std_logic
9708
            );
9709
 
9710
end stratixii_lvds_transmitter;
9711
 
9712
ARCHITECTURE vital_transmitter_atom of stratixii_lvds_transmitter is
9713
 
9714
signal clk0_ipd : std_logic;
9715
signal serialdatain_ipd : std_logic;
9716
signal postdpaserialdatain_ipd : std_logic;
9717
 
9718
signal input_data : std_logic_vector(channel_width - 1 downto 0);
9719
signal txload0 : std_logic;
9720
signal shift_out : std_logic;
9721
 
9722
signal clk0_dly0 : std_logic;
9723
signal clk0_dly1 : std_logic;
9724
signal clk0_dly2 : std_logic;
9725
 
9726
signal datain_dly : std_logic_vector(channel_width - 1 downto 0);
9727
signal datain_dly1 : std_logic_vector(channel_width - 1 downto 0);
9728
signal datain_dly2 : std_logic_vector(channel_width - 1 downto 0);
9729
signal datain_dly3 : std_logic_vector(channel_width - 1 downto 0);
9730
signal datain_dly4 : std_logic_vector(channel_width - 1 downto 0);
9731
 
9732
signal vcc : std_logic := '1';
9733
signal tmp_dataout : std_logic;
9734
 
9735
COMPONENT stratixii_lvds_tx_parallel_register
9736
    GENERIC ( channel_width           : integer := 10;
9737
              TimingChecksOn          : Boolean := True;
9738
              MsgOn                   : Boolean := DefGlitchMsgOn;
9739
              XOn                     : Boolean := DefGlitchXOn;
9740
              MsgOnChecks             : Boolean := DefMsgOnChecks;
9741
              XOnChecks               : Boolean := DefXOnChecks;
9742
              InstancePath                : String := "*";
9743
              tpd_clk_dataout_posedge : VitalDelayType01 := DefPropDelay01;
9744
              tipd_clk                : VitalDelayType01 := DefpropDelay01;
9745
              tipd_enable             : VitalDelayType01 := DefpropDelay01;
9746
              tipd_datain             : VitalDelayArrayType01(9 downto 0) := (OTHERS => DefpropDelay01)
9747
            );
9748
 
9749
    PORT    ( clk                     : in std_logic;
9750
              enable                  : in std_logic;
9751
              datain                  : in std_logic_vector(channel_width - 1 downto 0);
9752
              devclrn                 : in std_logic := '1';
9753
              devpor                  : in std_logic := '1';
9754
              dataout                 : out std_logic_vector(channel_width - 1 downto 0)
9755
            );
9756
 
9757
END COMPONENT;
9758
 
9759
COMPONENT stratixii_lvds_tx_out_block
9760
    GENERIC ( bypass_serializer        : String := "false";
9761
              invert_clock             : String := "false";
9762
              use_falling_clock_edge   : String := "false";
9763
              TimingChecksOn           : Boolean := True;
9764
              MsgOn                    : Boolean := DefGlitchMsgOn;
9765
              XOn                      : Boolean := DefGlitchXOn;
9766
              MsgOnChecks              : Boolean := DefMsgOnChecks;
9767
              XOnChecks                : Boolean := DefXOnChecks;
9768
              InstancePath             : String := "*";
9769
              tpd_clk_dataout          : VitalDelayType01 := DefPropDelay01;
9770
              tpd_clk_dataout_negedge  : VitalDelayType01 := DefPropDelay01;
9771
              tipd_clk                 : VitalDelayType01 := DefpropDelay01;
9772
              tipd_datain              : VitalDelayType01 := DefpropDelay01
9773
            );
9774
 
9775
    PORT    ( clk                      : in std_logic;
9776
              datain                   : in std_logic;
9777
              devclrn                  : in std_logic := '1';
9778
              devpor                   : in std_logic := '1';
9779
              dataout                  : out std_logic
9780
            );
9781
END COMPONENT;
9782
 
9783
COMPONENT stratixii_lvds_tx_reg
9784
    GENERIC (TimingChecksOn                : Boolean := true;
9785
             InstancePath                  : STRING := "*";
9786
             XOn                           : Boolean := DefGlitchXOn;
9787
             MsgOn                         : Boolean := DefGlitchMsgOn;
9788
             MsgOnChecks                   : Boolean := DefMsgOnChecks;
9789
             XOnChecks                     : Boolean := DefXOnChecks;
9790
             tpd_clk_q_posedge             : VitalDelayType01 := DefPropDelay01;
9791
             tsetup_d_clk_noedge_posedge   : VitalDelayType := DefSetupHoldCnst;
9792
             thold_d_clk_noedge_posedge    : VitalDelayType := DefSetupHoldCnst;
9793
             tipd_d                        : VitalDelayType01 := DefPropDelay01;
9794
             tipd_clk                      : VitalDelayType01 := DefPropDelay01;
9795
             tipd_ena                      : VitalDelayType01 := DefPropDelay01
9796
            );
9797
 
9798
    PORT  ( q                              :  out   STD_LOGIC := '0';
9799
            d                              :  in    STD_LOGIC := '1';
9800
            clrn                           :  in    STD_LOGIC := '1';
9801
            prn                            :  in    STD_LOGIC := '1';
9802
            clk                            :  in    STD_LOGIC := '0';
9803
            ena                            :  in    STD_LOGIC := '1'
9804
          );
9805
END COMPONENT;
9806
 
9807
begin
9808
 
9809
    ----------------------
9810
    --  INPUT PATH DELAYs
9811
    ----------------------
9812
    WireDelay : block
9813
    begin
9814
        VitalWireDelay (clk0_ipd, clk0, tipd_clk0);
9815
        VitalWireDelay (serialdatain_ipd, serialdatain, tipd_serialdatain);
9816
        VitalWireDelay (postdpaserialdatain_ipd, postdpaserialdatain, tipd_postdpaserialdatain);
9817
    end block;
9818
 
9819
    txload0_reg: stratixii_lvds_tx_reg
9820
             PORT MAP (d    => enable0,
9821
                       clrn => vcc,
9822
                       prn  => vcc,
9823
                       ena  => vcc,
9824
                       clk  => clk0_dly2,
9825
                       q    => txload0
9826
                      );
9827
 
9828
    input_reg: stratixii_lvds_tx_parallel_register
9829
             GENERIC MAP ( channel_width => channel_width)
9830
             PORT MAP    ( clk => txload0,
9831
                           enable => vcc,
9832
                           datain => datain_dly,
9833
                           dataout => input_data,
9834
                           devclrn => devclrn,
9835
                           devpor => devpor
9836
                         );
9837
 
9838
    output_module: stratixii_lvds_tx_out_block
9839
             GENERIC MAP ( bypass_serializer => bypass_serializer,
9840
                           use_falling_clock_edge => use_falling_clock_edge,
9841
                           invert_clock => invert_clock)
9842
             PORT MAP    ( clk => clk0_dly2,
9843
                           datain => shift_out,
9844
                           dataout => tmp_dataout,
9845
                           devclrn => devclrn,
9846
                           devpor => devpor
9847
                         );
9848
 
9849
    clk_delay: process (clk0_ipd, datain)
9850
    begin
9851
        clk0_dly0 <= clk0_ipd;
9852
        datain_dly1 <= datain;
9853
    end process;
9854
 
9855
    clk_delay1: process (clk0_dly0, datain_dly1)
9856
    begin
9857
        clk0_dly1 <= clk0_dly0;
9858
        datain_dly2 <= datain_dly1;
9859
    end process;
9860
 
9861
    clk_delay2: process (clk0_dly1, datain_dly2)
9862
    begin
9863
        clk0_dly2 <= clk0_dly1;
9864
        datain_dly3 <= datain_dly2;
9865
    end process;
9866
 
9867
    data_delay: process (datain_dly3)
9868
    begin
9869
        datain_dly4 <= datain_dly3;
9870
    end process;
9871
 
9872
    data_delay1: process (datain_dly4)
9873
    begin
9874
        datain_dly <= datain_dly4;
9875
    end process;
9876
 
9877
    VITAL: process (clk0_ipd, devclrn, devpor)
9878
    variable dataout_VitalGlitchData : VitalGlitchDataType;
9879
    variable i : integer := 0;
9880
    variable shift_data : std_logic_vector(channel_width-1 downto 0);
9881
    begin
9882
        if (now = 0 ns) then
9883
            shift_data := (OTHERS => '0');
9884
        end if;
9885
 
9886
        if ((devpor = '0') or (devclrn = '0')) then
9887
            shift_data := (OTHERS => '0');
9888
        else
9889
            if (bypass_serializer = "false") then
9890
                if (clk0_ipd'event and clk0_ipd = '1') then
9891
                    if (txload0 = '1') then
9892
                        shift_data := input_data;
9893
                    end if;
9894
 
9895
                    shift_out <= shift_data(channel_width - 1);
9896
 
9897
                    for i in channel_width-1 downto 1 loop
9898
                        shift_data(i) := shift_data(i - 1);
9899
                    end loop;
9900
                end if;
9901
            end if;
9902
        end if;
9903
 
9904
    end process;
9905
 
9906
    process (serialdatain_ipd, postdpaserialdatain_ipd, tmp_dataout)
9907
    variable dataout_tmp : std_logic := '0';
9908
    variable dataout_VitalGlitchData : VitalGlitchDataType;
9909
    begin
9910
        if (serialdatain_ipd'event and use_serial_data_input = "true") then
9911
            dataout_tmp := serialdatain_ipd;
9912
        elsif (postdpaserialdatain_ipd'event and use_post_dpa_serial_data_input = "true") then
9913
            dataout_tmp := postdpaserialdatain_ipd;
9914
        else
9915
            dataout_tmp := tmp_dataout;
9916
        end if;
9917
 
9918
        ----------------------
9919
        --  Path Delay Section
9920
        ----------------------
9921
        if (use_serial_data_input = "true") then
9922
            VitalPathDelay01 (
9923
                OutSignal => dataout,
9924
                OutSignalName => "DATAOUT",
9925
                OutTemp => dataout_tmp,
9926
                Paths => (0 => (serialdatain_ipd'last_event, tpd_serialdatain_dataout, TRUE)),
9927
                GlitchData => dataout_VitalGlitchData,
9928
                Mode => DefGlitchMode,
9929
                XOn  => XOn,
9930
                MsgOn  => MsgOn );
9931
 
9932
        elsif (use_post_dpa_serial_data_input = "true") then
9933
            VitalPathDelay01 (
9934
                OutSignal => dataout,
9935
                OutSignalName => "DATAOUT",
9936
                OutTemp => dataout_tmp,
9937
                Paths => (0 => (postdpaserialdatain_ipd'last_event, tpd_postdpaserialdatain_dataout, TRUE)),
9938
                GlitchData => dataout_VitalGlitchData,
9939
                Mode => DefGlitchMode,
9940
                XOn  => XOn,
9941
                MsgOn  => MsgOn );
9942
 
9943
        else
9944
            VitalPathDelay01 (
9945
                OutSignal => dataout,
9946
                OutSignalName => "DATAOUT",
9947
                OutTemp => dataout_tmp,
9948
                Paths => (0 => (tmp_dataout'last_event, DefPropDelay01, TRUE)),
9949
                GlitchData => dataout_VitalGlitchData,
9950
                Mode => DefGlitchMode,
9951
                XOn  => XOn,
9952
                MsgOn  => MsgOn );
9953
        end if;
9954
    end process;
9955
 
9956
end vital_transmitter_atom;
9957
--/////////////////////////////////////////////////////////////////////////////
9958
--
9959
-- Module Name : stratixii_lvds_reg
9960
--
9961
-- Description : Simulation model for a simple DFF.
9962
--               This is used for registering the enable inputs.
9963
--               No timing, powers upto 0.
9964
--
9965
--/////////////////////////////////////////////////////////////////////////////
9966
 
9967
LIBRARY IEEE, std;
9968
USE ieee.std_logic_1164.all;
9969
USE IEEE.VITAL_Timing.all;
9970
USE IEEE.VITAL_Primitives.all;
9971
USE work.stratixii_atom_pack.all;
9972
 
9973
ENTITY stratixii_lvds_reg is
9974
    GENERIC ( MsgOn                   : Boolean := DefGlitchMsgOn;
9975
              XOn                     : Boolean := DefGlitchXOn;
9976
              MsgOnChecks             : Boolean := DefMsgOnChecks;
9977
              XOnChecks               : Boolean := DefXOnChecks;
9978
              TimingChecksOn          : Boolean := True;
9979
              InstancePath            : String := "*";
9980
              tipd_clk                : VitalDelayType01 := DefpropDelay01;
9981
              tipd_ena                : VitalDelayType01 := DefpropDelay01;
9982
              tipd_d                  : VitalDelayType01 := DefpropDelay01;
9983
              tpd_clk_q_posedge       : VitalDelayType01 := DefPropDelay01;
9984
              tpd_prn_q_negedge       : VitalDelayType01 := DefPropDelay01;
9985
              tpd_clrn_q_negedge      : VitalDelayType01 := DefPropDelay01
9986
            );
9987
 
9988
    PORT    ( q                       : OUT std_logic;
9989
              clk                     : IN std_logic;
9990
              ena                     : IN std_logic := '1';
9991
              d                       : IN std_logic;
9992
              clrn                    : IN std_logic := '1';
9993
              prn                     : IN std_logic := '1'
9994
            );
9995
END stratixii_lvds_reg;
9996
 
9997
ARCHITECTURE vital_stratixii_lvds_reg of stratixii_lvds_reg is
9998
 
9999
 
10000
    -- INTERNAL SIGNALS
10001
    signal clk_ipd                  :  std_logic;
10002
    signal d_ipd                    :  std_logic;
10003
    signal ena_ipd                  :  std_logic;
10004
 
10005
    begin
10006
 
10007
        ----------------------
10008
        --  INPUT PATH DELAYs
10009
        ----------------------
10010
        WireDelay : block
10011
        begin
10012
            VitalWireDelay (clk_ipd, clk, tipd_clk);
10013
            VitalWireDelay (ena_ipd, ena, tipd_ena);
10014
            VitalWireDelay (d_ipd, d, tipd_d);
10015
        end block;
10016
 
10017
        process (clk_ipd, d_ipd, clrn, prn)
10018
        variable q_tmp :  std_logic := '0';
10019
        variable q_VitalGlitchData : VitalGlitchDataType;
10020
        variable Tviol_d_clk : std_ulogic := '0';
10021
        variable TimingData_d_clk : VitalTimingDataType := VitalTimingDataInit;
10022
        begin
10023
 
10024
            ------------------------
10025
            --  Timing Check Section
10026
            ------------------------
10027
 
10028
            if (prn = '0') then
10029
                q_tmp := '1';
10030
            elsif (clrn = '0') then
10031
                q_tmp := '0';
10032
            elsif (clk_ipd'event and clk_ipd = '1') then
10033
                if (ena_ipd = '1') then
10034
                    q_tmp := d_ipd;
10035
                end if;
10036
            end if;
10037
 
10038
            ----------------------
10039
            --  Path Delay Section
10040
            ----------------------
10041
            VitalPathDelay01 (
10042
                        OutSignal => q,
10043
                        OutSignalName => "Q",
10044
                        OutTemp => q_tmp,
10045
                        Paths => (1 => (clk_ipd'last_event, tpd_clk_q_posedge, TRUE)),
10046
                        GlitchData => q_VitalGlitchData,
10047
                        Mode => DefGlitchMode,
10048
                        XOn  => XOn,
10049
                        MsgOn  => MsgOn );
10050
 
10051
        end process;
10052
 
10053
end vital_stratixii_lvds_reg;
10054
 
10055
--/////////////////////////////////////////////////////////////////////////////
10056
--
10057
-- Module Name : stratixii_lvds_rx_fifo_sync_ram
10058
--
10059
-- Description :
10060
--
10061
--/////////////////////////////////////////////////////////////////////////////
10062
 
10063
LIBRARY IEEE, std;
10064
USE ieee.std_logic_1164.all;
10065
USE IEEE.VITAL_Timing.all;
10066
USE IEEE.VITAL_Primitives.all;
10067
USE work.stratixii_atom_pack.all;
10068
 
10069
ENTITY stratixii_lvds_rx_fifo_sync_ram is
10070
    PORT ( clk                     : IN std_logic;
10071
           datain                  : IN std_logic := '0';
10072
           writereset             : IN std_logic := '0';
10073
           waddr                   : IN std_logic_vector(2 DOWNTO 0) := "000";
10074
           raddr                   : IN std_logic_vector(2 DOWNTO 0) := "000";
10075
           we                      : IN std_logic := '0';
10076
           dataout                 : OUT std_logic
10077
         );
10078
 
10079
END stratixii_lvds_rx_fifo_sync_ram;
10080
 
10081
ARCHITECTURE vital_arm_lvds_rx_fifo_sync_ram OF stratixii_lvds_rx_fifo_sync_ram IS
10082
 
10083
    -- INTERNAL SIGNALS
10084
    signal dataout_tmp              :  std_logic;
10085
    signal ram_d                    :  std_logic_vector(0 TO 5);
10086
    signal ram_q                    :  std_logic_vector(0 TO 5);
10087
    signal data_reg                 :  std_logic_vector(0 TO 5);
10088
 
10089
    begin
10090
        dataout <= dataout_tmp;
10091
 
10092
    process (clk, writereset)
10093
    variable initial : boolean := true;
10094
    begin
10095
        if (initial) then
10096
            for i in 0 to 5 loop
10097
                ram_q(i) <= '0';
10098
            end loop;
10099
            initial := false;
10100
        end if;
10101
        if (writereset = '1') then
10102
            for i in 0 to 5 loop
10103
                ram_q(i) <= '0';
10104
            end loop;
10105
        elsif (clk'event and clk = '1') then
10106
            for i in 0 to 5 loop
10107
                ram_q(i) <= ram_d(i);
10108
            end loop;
10109
        end if;
10110
    end process;
10111
 
10112
    process (we, data_reg, ram_q)
10113
    begin
10114
        if (we = '1') then
10115
            ram_d <= data_reg;
10116
        else
10117
            ram_d <= ram_q;
10118
        end if;
10119
    end process;
10120
 
10121
   data_reg(0) <= datain when (waddr = "000") else ram_q(0) ;
10122
   data_reg(1) <= datain when (waddr = "001") else ram_q(1) ;
10123
   data_reg(2) <= datain when (waddr = "010") else ram_q(2) ;
10124
   data_reg(3) <= datain when (waddr = "011") else ram_q(3) ;
10125
   data_reg(4) <= datain when (waddr = "100") else ram_q(4) ;
10126
   data_reg(5) <= datain when (waddr = "101") else ram_q(5) ;
10127
 
10128
    process (ram_q, we, waddr, raddr)
10129
    variable initial : boolean := true;
10130
    begin
10131
        if (initial) then
10132
            dataout_tmp <= '0';
10133
            initial := false;
10134
        end if;
10135
        case raddr is
10136
            when "000" =>
10137
                  dataout_tmp <= ram_q(0);
10138
            when "001" =>
10139
                  dataout_tmp <= ram_q(1);
10140
            when "010" =>
10141
                  dataout_tmp <= ram_q(2);
10142
            when "011" =>
10143
                  dataout_tmp <= ram_q(3);
10144
            when "100" =>
10145
                  dataout_tmp <= ram_q(4);
10146
            when "101" =>
10147
                  dataout_tmp <= ram_q(5);
10148
            when others  =>
10149
                  dataout_tmp <= '0';
10150
      end case;
10151
   end process;
10152
 
10153
END vital_arm_lvds_rx_fifo_sync_ram;
10154
 
10155
--/////////////////////////////////////////////////////////////////////////////
10156
--
10157
-- Module Name : stratixii_lvds_rx_fifo
10158
--
10159
-- Description :
10160
--
10161
--/////////////////////////////////////////////////////////////////////////////
10162
LIBRARY IEEE, std;
10163
USE ieee.std_logic_1164.all;
10164
USE IEEE.VITAL_Timing.all;
10165
USE IEEE.VITAL_Primitives.all;
10166
USE work.stratixii_atom_pack.all;
10167
USE work.stratixii_lvds_rx_fifo_sync_ram;
10168
 
10169
ENTITY stratixii_lvds_rx_fifo is
10170
    GENERIC ( channel_width           :  integer := 10;
10171
              MsgOn                   : Boolean := DefGlitchMsgOn;
10172
              XOn                     : Boolean := DefGlitchXOn;
10173
              MsgOnChecks             : Boolean := DefMsgOnChecks;
10174
              XOnChecks               : Boolean := DefXOnChecks;
10175
              InstancePath            : String := "*";
10176
              tipd_wclk               : VitalDelayType01 := DefpropDelay01;
10177
              tipd_rclk               : VitalDelayType01 := DefpropDelay01;
10178
              tipd_dparst             : VitalDelayType01 := DefpropDelay01;
10179
              tipd_fiforst            : VitalDelayType01 := DefpropDelay01;
10180
              tipd_datain             : VitalDelayType01 := DefpropDelay01;
10181
              tpd_rclk_dataout_posedge: VitalDelayType01 := DefPropDelay01;
10182
              tpd_dparst_dataout_posedge: VitalDelayType01 := DefPropDelay01
10183
            );
10184
 
10185
    PORT    ( wclk                    : IN std_logic:= '0';
10186
              rclk                    : IN std_logic:= '0';
10187
              dparst                  : IN std_logic := '0';
10188
              fiforst                 : IN std_logic := '0';
10189
              datain                  : IN std_logic := '0';
10190
              dataout                 : OUT std_logic
10191
            );
10192
 
10193
END stratixii_lvds_rx_fifo;
10194
 
10195
ARCHITECTURE vital_arm_lvds_rx_fifo of stratixii_lvds_rx_fifo is
10196
    -- INTERNAL SIGNALS
10197
    signal datain_in                :  std_logic;
10198
    signal rclk_in                  :  std_logic;
10199
    signal dparst_in                :  std_logic;
10200
    signal fiforst_in               :  std_logic;
10201
    signal wclk_in                  :  std_logic;
10202
 
10203
    signal ram_datain               :  std_logic;
10204
    signal ram_dataout              :  std_logic;
10205
    signal wrPtr                    :  std_logic_vector(2 DOWNTO 0);
10206
    signal rdPtr                    :  std_logic_vector(2 DOWNTO 0);
10207
    signal rdAddr                   :  std_logic_vector(2 DOWNTO 0);
10208
    signal ram_we                   :  std_logic;
10209
    signal write_side_sync_reset    :  std_logic;
10210
    signal read_side_sync_reset     :  std_logic;
10211
 
10212
    COMPONENT stratixii_lvds_rx_fifo_sync_ram
10213
        PORT ( clk                  : IN  std_logic;
10214
               datain               : IN  std_logic := '0';
10215
               writereset          : IN  std_logic := '0';
10216
               waddr                : IN  std_logic_vector(2 DOWNTO 0) := "000";
10217
               raddr                : IN  std_logic_vector(2 DOWNTO 0) := "000";
10218
               we                   : IN  std_logic := '0';
10219
               dataout              : OUT std_logic
10220
             );
10221
    END COMPONENT;
10222
 
10223
begin
10224
 
10225
    ----------------------
10226
    --  INPUT PATH DELAYs
10227
    ----------------------
10228
    WireDelay : block
10229
    begin
10230
        VitalWireDelay (wclk_in, wclk, tipd_wclk);
10231
        VitalWireDelay (rclk_in, rclk, tipd_rclk);
10232
        VitalWireDelay (dparst_in, dparst, tipd_dparst);
10233
        VitalWireDelay (fiforst_in, fiforst, tipd_fiforst);
10234
        VitalWireDelay (datain_in, datain, tipd_datain);
10235
    end block;
10236
 
10237
    rdAddr <= rdPtr ;
10238
    s_fifo_ram : stratixii_lvds_rx_fifo_sync_ram
10239
           PORT MAP ( clk         => wclk_in,
10240
                      datain      => ram_datain,
10241
                      writereset => write_side_sync_reset,
10242
                      waddr       => wrPtr,
10243
                      raddr       => rdAddr,
10244
                      we          => ram_we,
10245
                      dataout     => ram_dataout
10246
                    );
10247
 
10248
 
10249
    process (wclk_in, dparst_in)
10250
    variable initial : boolean := true;
10251
    begin
10252
        if (initial) then
10253
            wrPtr <= "000";
10254
            write_side_sync_reset <= '0';
10255
            ram_we <= '0';
10256
            ram_datain <= '0';
10257
            initial := false;
10258
        end if;
10259
        if (dparst_in = '1' or (fiforst_in = '1' and wclk_in'event and wclk_in = '1')) then
10260
            write_side_sync_reset <= '1';
10261
            ram_datain <= '0';
10262
            wrPtr <= "000";
10263
            ram_we <= '0';
10264
        elsif (dparst_in = '0' and (fiforst_in = '0' and wclk_in'event and wclk_in = '1')) then
10265
            write_side_sync_reset <= '0';
10266
        end if;
10267
        if (wclk_in'event and wclk_in = '1' and write_side_sync_reset = '0' and  fiforst_in = '0' and dparst_in = '0') then
10268
            ram_datain <= datain_in;
10269
            ram_we <= '1';
10270
            case wrPtr is
10271
                when "000" => wrPtr <= "001";
10272
                when "001" => wrPtr <= "010";
10273
                when "010" => wrPtr <= "011";
10274
                when "011" => wrPtr <= "100";
10275
                when "100" => wrPtr <= "101";
10276
                when "101" => wrPtr <= "000";
10277
                when others => wrPtr <= "000";
10278
            end case;
10279
        end if;
10280
    end process;
10281
 
10282
    process (rclk_in, dparst_in)
10283
    variable initial : boolean := true;
10284
    variable dataout_tmp : std_logic := '0';
10285
    variable dataout_VitalGlitchData : VitalGlitchDataType;
10286
    begin
10287
        if (initial) then
10288
            rdPtr <= "011";
10289
            read_side_sync_reset <= '0';
10290
            dataout_tmp := '0';
10291
            initial := false;
10292
        end if;
10293
        if (dparst_in = '1' or (fiforst_in = '1' and rclk_in'event and rclk_in = '1')) then
10294
            read_side_sync_reset <= '1';
10295
            rdPtr <= "011";
10296
            dataout_tmp := '0';
10297
        elsif (dparst_in = '0' and (fiforst_in = '0' and rclk_in'event and rclk_in = '1')) then
10298
            read_side_sync_reset <= '0';
10299
        end if;
10300
        if (rclk_in'event and rclk_in = '1' and read_side_sync_reset = '0' and fiforst_in = '0' and dparst_in = '0') then
10301
            case rdPtr is
10302
                when "000" => rdPtr <= "001";
10303
                when "001" => rdPtr <= "010";
10304
                when "010" => rdPtr <= "011";
10305
                when "011" => rdPtr <= "100";
10306
                when "100" => rdPtr <= "101";
10307
                when "101" => rdPtr <= "000";
10308
                when others => rdPtr <= "000";
10309
            end case;
10310
            dataout_tmp := ram_dataout;
10311
        end if;
10312
 
10313
        ----------------------
10314
        --  Path Delay Section
10315
        ----------------------
10316
        VitalPathDelay01 (
10317
                        Outsignal => dataout,
10318
                        OutsignalName => "DATAOUT",
10319
                        OutTemp => dataout_tmp,
10320
                        Paths => (1 => (rclk_in'last_event, tpd_rclk_dataout_posedge, TRUE)),
10321
                        GlitchData => dataout_VitalGlitchData,
10322
                        Mode => DefGlitchMode,
10323
                        XOn  => XOn,
10324
                        MsgOn  => MsgOn );
10325
 
10326
    end process;
10327
 
10328
END vital_arm_lvds_rx_fifo;
10329
 
10330
--/////////////////////////////////////////////////////////////////////////////
10331
--
10332
-- Module Name : stratixii_lvds_rx_bitslip
10333
--
10334
-- Description :
10335
--
10336
--/////////////////////////////////////////////////////////////////////////////
10337
LIBRARY IEEE, std;
10338
USE ieee.std_logic_1164.all;
10339
USE IEEE.VITAL_Timing.all;
10340
USE IEEE.VITAL_Primitives.all;
10341
USE work.stratixii_atom_pack.all;
10342
USE work.stratixii_lvds_reg;
10343
 
10344
ENTITY stratixii_lvds_rx_bitslip is
10345
    GENERIC ( channel_width            : integer := 10;
10346
              bitslip_rollover         : integer := 12;
10347
              x_on_bitslip             : string  := "on";
10348
              MsgOn                    : Boolean := DefGlitchMsgOn;
10349
              XOn                      : Boolean := DefGlitchXOn;
10350
              MsgOnChecks              : Boolean := DefMsgOnChecks;
10351
              XOnChecks                : Boolean := DefXOnChecks;
10352
              InstancePath             : String := "*";
10353
              tipd_clk0                : VitalDelayType01 := DefpropDelay01;
10354
              tipd_bslipcntl           : VitalDelayType01 := DefpropDelay01;
10355
              tipd_bsliprst            : VitalDelayType01 := DefpropDelay01;
10356
              tipd_datain              : VitalDelayType01 := DefpropDelay01;
10357
              tpd_bsliprst_bslipmax_posedge: VitalDelayType01 := DefPropDelay01;
10358
              tpd_clk0_bslipmax_posedge: VitalDelayType01 := DefPropDelay01
10359
            );
10360
 
10361
    PORT    ( clk0                     : IN std_logic := '0';
10362
              bslipcntl                : IN std_logic := '0';
10363
              bsliprst                 : IN std_logic := '0';
10364
              datain                   : IN std_logic := '0';
10365
              bslipmax                 : OUT std_logic;
10366
              dataout                  : OUT std_logic
10367
            );
10368
END stratixii_lvds_rx_bitslip;
10369
 
10370
ARCHITECTURE vital_arm_lvds_rx_bitslip OF stratixii_lvds_rx_bitslip IS
10371
    -- INTERNAL SIGNALS
10372
    signal clk0_in               :  std_logic;
10373
    signal bslipcntl_in          :  std_logic;
10374
    signal bsliprst_in           :  std_logic;
10375
    signal datain_in             :  std_logic;
10376
 
10377
    signal slip_count            :  integer := 0;
10378
    signal dataout_tmp           :  std_logic;
10379
    signal bitslip_arr           :  std_logic_vector(11 DOWNTO 0) := "000000000000";
10380
    signal bslipcntl_reg         :  std_logic;
10381
    signal vcc                   : std_logic := '1';
10382
    signal slip_data             : std_logic := '0';
10383
    signal start_corrupt_bits    : std_logic := '0';
10384
    signal num_corrupt_bits      : integer := 0;
10385
 
10386
    COMPONENT stratixii_lvds_reg
10387
        GENERIC ( MsgOn                   : Boolean := DefGlitchMsgOn;
10388
                  XOn                     : Boolean := DefGlitchXOn;
10389
                  MsgOnChecks             : Boolean := DefMsgOnChecks;
10390
                  XOnChecks               : Boolean := DefXOnChecks;
10391
                  InstancePath            : String := "*";
10392
                  tipd_clk                : VitalDelayType01 := DefpropDelay01;
10393
                  tipd_ena                : VitalDelayType01 := DefpropDelay01;
10394
                  tipd_d                  : VitalDelayType01 := DefpropDelay01;
10395
                  tpd_clk_q_posedge       : VitalDelayType01 := DefPropDelay01
10396
                );
10397
 
10398
        PORT    ( q                       : OUT std_logic;
10399
                  clk                     : IN  std_logic;
10400
                  ena                     : IN  std_logic := '1';
10401
                  d                       : IN  std_logic;
10402
                  clrn                    : IN  std_logic := '1';
10403
                  prn                     : IN  std_logic := '1'
10404
                );
10405
    END COMPONENT;
10406
 
10407
begin
10408
 
10409
    ----------------------
10410
    --  INPUT PATH DELAYs
10411
    ----------------------
10412
    WireDelay : block
10413
    begin
10414
        VitalWireDelay (clk0_in, clk0, tipd_clk0);
10415
        VitalWireDelay (bslipcntl_in, bslipcntl, tipd_bslipcntl);
10416
        VitalWireDelay (bsliprst_in, bsliprst, tipd_bsliprst);
10417
        VitalWireDelay (datain_in, datain, tipd_datain);
10418
    end block;
10419
 
10420
    bslipcntlreg : stratixii_lvds_reg
10421
           PORT MAP ( d    => bslipcntl_in,
10422
                      clk  => clk0_in,
10423
                      ena  => vcc,
10424
                      clrn => vcc,
10425
                      prn  => vcc,
10426
                      q    => bslipcntl_reg
10427
                    );
10428
 
10429
    -- 4-bit slip counter and 12-bit shift register
10430
    process (bslipcntl_reg, bsliprst_in, clk0_in)
10431
    variable initial : boolean := true;
10432
    variable bslipmax_tmp : std_logic := '0';
10433
    variable bslipmax_VitalGlitchData : VitalGlitchDataType;
10434
    begin
10435
        if (bsliprst_in = '1') then
10436
            slip_count <= 0;
10437
            bslipmax_tmp := '0';
10438
--            bitslip_arr <= (OTHERS => '0');
10439
            if (bsliprst_in'event and bsliprst_in = '1' and bsliprst_in'last_value = '0') then
10440
                ASSERT false report "Bit Slip Circuit was reset. Serial Data stream will have 0 latency" severity note;
10441
            end if;
10442
        else
10443
            if (bslipcntl_reg'event and bslipcntl_reg = '1' and bslipcntl_reg'last_value = '0') then
10444
                if (x_on_bitslip = "on") then
10445
                    start_corrupt_bits <= '1';
10446
                end if;
10447
                num_corrupt_bits <= 0;
10448
                if (slip_count = bitslip_rollover) then
10449
                    ASSERT false report "Rollover occurred on Bit Slip circuit. Serial data stream will have 0 latency." severity note;
10450
                    slip_count <= 0;
10451
                    bslipmax_tmp := '0';
10452
                else
10453
                    slip_count <= slip_count + 1;
10454
                    if ((slip_count + 1) = bitslip_rollover) then
10455
                        ASSERT false report "The Bit Slip circuit has reached the maximum Bit Slip limit. Rollover will occur on the next slip." severity note;
10456
                        bslipmax_tmp := '1';
10457
                    end if;
10458
                end if;
10459
            elsif (bslipcntl_reg'event and bslipcntl_reg = '0' and bslipcntl_reg'last_value = '1') then
10460
                start_corrupt_bits <= '0';
10461
                num_corrupt_bits <= 0;
10462
            end if;
10463
        end if;
10464
            if (clk0_in'event and clk0_in = '1' and clk0_in'last_value = '0') then
10465
                bitslip_arr(0) <= datain_in;
10466
                for i in 0 to (bitslip_rollover - 1) loop
10467
                    bitslip_arr(i + 1) <= bitslip_arr(i);
10468
                end loop;
10469
 
10470
                if (start_corrupt_bits = '1') then
10471
                    num_corrupt_bits <= num_corrupt_bits + 1;
10472
                end if;
10473
                if (num_corrupt_bits+1 = 3) then
10474
                    start_corrupt_bits <= '0';
10475
                end if;
10476
            end if;
10477
--        end if;
10478
 
10479
        ----------------------
10480
        --  Path Delay Section
10481
        ----------------------
10482
        VitalPathDelay01 (
10483
                        Outsignal => bslipmax,
10484
                        OutsignalName => "BSLIPMAX",
10485
                        OutTemp => bslipmax_tmp,
10486
                        Paths => (1 => (clk0_in'last_event, tpd_clk0_bslipmax_posedge, TRUE),
10487
                                  2 => (bsliprst_in'last_event, tpd_bsliprst_bslipmax_posedge, TRUE)),
10488
                        GlitchData => bslipmax_VitalGlitchData,
10489
                        Mode => DefGlitchMode,
10490
                        XOn  => XOn,
10491
                        MsgOn  => MsgOn );
10492
    end process;
10493
 
10494
    -- Bit Slip shift register
10495
--    process (clk0_in, bsliprst_in)
10496
--    begin
10497
--        if (bsliprst_in = '1') then
10498
--        elsif (clk0_in'event and clk0_in = '1' and clk0'last_value = '0') then
10499
--            bitslip_arr(0) <= datain_in;
10500
--            for i in 0 to (bitslip_rollover - 1) loop
10501
--                bitslip_arr(i + 1) <= bitslip_arr(i);
10502
--            end loop;
10503
--
10504
--            if (start_corrupt_bits = '1') then
10505
--                num_corrupt_bits <= num_corrupt_bits + 1;
10506
--            end if;
10507
--            if (num_corrupt_bits+1 = 3) then
10508
--                start_corrupt_bits <= '0';
10509
--            end if;
10510
--        end if;
10511
--    end process;
10512
 
10513
    slip_data <= bitslip_arr(slip_count);
10514
 
10515
    dataoutreg : stratixii_lvds_reg
10516
          PORT MAP ( d => slip_data,
10517
                     clk => clk0_in,
10518
                     ena => vcc,
10519
                     clrn => vcc,
10520
                     prn => vcc,
10521
                     q => dataout_tmp
10522
                   );
10523
 
10524
    dataout <= dataout_tmp when start_corrupt_bits = '0' else
10525
               'X' when start_corrupt_bits = '1' and num_corrupt_bits < 3 else
10526
               dataout_tmp;
10527
 
10528
END vital_arm_lvds_rx_bitslip;
10529
 
10530
--/////////////////////////////////////////////////////////////////////////////
10531
--
10532
-- Module Name : stratixii_lvds_rx_deser
10533
--
10534
-- Description : Timing simulation model for the STRATIXII LVDS RECEIVER
10535
--               DESERIALIZER. This module receives serial data and outputs
10536
--               parallel data word of width = channel width
10537
--
10538
--////////////////////////////////////////////////////////////////////////////
10539
 
10540
LIBRARY IEEE;
10541
USE ieee.std_logic_1164.all;
10542
USE IEEE.VITAL_Timing.all;
10543
USE IEEE.VITAL_Primitives.all;
10544
USE work.stratixii_atom_pack.all;
10545
 
10546
ENTITY stratixii_lvds_rx_deser IS
10547
    GENERIC ( channel_width            :  integer := 4;
10548
              MsgOn                    : Boolean := DefGlitchMsgOn;
10549
              XOn                      : Boolean := DefGlitchXOn;
10550
              MsgOnChecks              : Boolean := DefMsgOnChecks;
10551
              XOnChecks                : Boolean := DefXOnChecks;
10552
              InstancePath             : String := "*";
10553
              tipd_clk                 : VitalDelayType01 := DefpropDelay01;
10554
              tipd_datain              : VitalDelayType01 := DefpropDelay01;
10555
              tpd_clk_dataout_posedge  : VitalDelayType01 := DefPropDelay01
10556
            );
10557
 
10558
    PORT    ( clk                      : IN std_logic := '0';
10559
              datain                   : IN std_logic := '0';
10560
              dataout                  : OUT std_logic_vector(channel_width - 1 DOWNTO 0);
10561
              devclrn                  : IN std_logic := '1';
10562
              devpor                   : IN std_logic := '1'
10563
            );
10564
 
10565
END stratixii_lvds_rx_deser;
10566
 
10567
ARCHITECTURE vital_arm_lvds_rx_deser OF stratixii_lvds_rx_deser IS
10568
 
10569
    -- INTERNAL SIGNALS
10570
    signal clk_ipd                  :  std_logic;
10571
    signal datain_ipd               :  std_logic;
10572
 
10573
    begin
10574
 
10575
        ----------------------
10576
        --  INPUT PATH DELAYs
10577
        ----------------------
10578
        WireDelay : block
10579
        begin
10580
            VitalWireDelay (clk_ipd, clk, tipd_clk);
10581
            VitalWireDelay (datain_ipd, datain, tipd_datain);
10582
        end block;
10583
 
10584
        VITAL: process (clk_ipd, devpor, devclrn)
10585
        variable dataout_tmp : std_logic_vector(channel_width - 1 downto 0) := (OTHERS => '0');
10586
        variable i : integer := 0;
10587
        variable dataout_VitalGlitchDataArray : VitalGlitchDataArrayType(9 downto 0);
10588
        variable CQDelay : TIME := 0 ns;
10589
        begin
10590
            if (devclrn = '0' or devpor = '0') then
10591
                dataout_tmp := (OTHERS => '0');
10592
        else
10593
            if (clk_ipd'event and clk_ipd  = '1' and clk_ipd'last_value = '0') then
10594
                for i in channel_width - 1 DOWNTO 1 loop
10595
                    dataout_tmp(i) := dataout_tmp(i - 1);
10596
                end loop;
10597
                dataout_tmp(0) := datain_ipd;
10598
            end if;
10599
        end if;
10600
 
10601
            ----------------------
10602
            --  Path Delay Section
10603
            ----------------------
10604
 
10605
            CQDelay := SelectDelay (
10606
                       (1 => (clk_ipd'last_event, tpd_clk_dataout_posedge, TRUE))
10607
            );
10608
            dataout <= TRANSPORT dataout_tmp AFTER CQDelay;
10609
        end process;
10610
 
10611
END vital_arm_lvds_rx_deser;
10612
 
10613
--/////////////////////////////////////////////////////////////////////////////
10614
--
10615
-- Module Name : stratixii_lvds_rx_parallel_reg
10616
--
10617
-- Description : Timing simulation model for the STRATIXII LVDS RECEIVER
10618
--               PARALLEL REGISTER. The data width equals max. channel width,
10619
--               which is 10.
10620
--
10621
--////////////////////////////////////////////////////////////////////////////
10622
 
10623
LIBRARY IEEE;
10624
USE ieee.std_logic_1164.all;
10625
USE IEEE.VITAL_Timing.all;
10626
USE IEEE.VITAL_Primitives.all;
10627
USE work.stratixii_atom_pack.all;
10628
 
10629
ENTITY stratixii_lvds_rx_parallel_reg IS
10630
    GENERIC ( channel_width            :  integer := 4;
10631
              MsgOn                    : Boolean := DefGlitchMsgOn;
10632
              XOn                      : Boolean := DefGlitchXOn;
10633
              MsgOnChecks              : Boolean := DefMsgOnChecks;
10634
              XOnChecks                : Boolean := DefXOnChecks;
10635
              InstancePath             : String := "*";
10636
              tipd_clk                 : VitalDelayType01 := DefpropDelay01;
10637
              tipd_enable              : VitalDelayType01 := DefpropDelay01;
10638
              tipd_datain              : VitalDelayArrayType01(9 downto 0) := (OTHERS => DefpropDelay01);
10639
              tpd_clk_dataout_posedge  : VitalDelayType01 := DefPropDelay01
10640
            );
10641
    PORT    ( clk                      : IN std_logic;
10642
              enable                   : IN std_logic := '1';
10643
              datain                   : IN std_logic_vector(channel_width - 1 DOWNTO 0);
10644
              dataout                  : OUT std_logic_vector(channel_width - 1 DOWNTO 0);
10645
              devclrn                  : IN std_logic := '1';
10646
              devpor                   : IN std_logic := '1'
10647
            );
10648
 
10649
END stratixii_lvds_rx_parallel_reg;
10650
 
10651
ARCHITECTURE vital_arm_lvds_rx_parallel_reg OF stratixii_lvds_rx_parallel_reg IS
10652
    -- INTERNAL SIGNALS
10653
    signal clk_ipd                  :  std_logic;
10654
    signal datain_ipd               :  std_logic_vector(channel_width - 1 downto 0);
10655
    signal enable_ipd               :  std_logic;
10656
 
10657
    begin
10658
 
10659
        ----------------------
10660
        --  INPUT PATH DELAYs
10661
        ----------------------
10662
        WireDelay : block
10663
        begin
10664
            VitalWireDelay (clk_ipd, clk, tipd_clk);
10665
            VitalWireDelay (enable_ipd, enable, tipd_enable);
10666
            loopbits : FOR i in datain'RANGE GENERATE
10667
                VitalWireDelay (datain_ipd(i), datain(i), tipd_datain(i));
10668
            END GENERATE;
10669
        end block;
10670
 
10671
        VITAL: process (clk_ipd, devpor, devclrn)
10672
        variable dataout_tmp : std_logic_vector(channel_width - 1 downto 0) := (OTHERS => '0');
10673
        variable i : integer := 0;
10674
        variable dataout_VitalGlitchDataArray : VitalGlitchDataArrayType(9 downto 0);
10675
        variable CQDelay : TIME := 0 ns;
10676
        begin
10677
            if ((devpor = '0') or (devclrn = '0')) then
10678
                dataout_tmp := (OTHERS => '0');
10679
            else
10680
                if (clk_ipd'event and clk_ipd = '1') then
10681
                    if (enable_ipd = '1') then
10682
                        dataout_tmp := datain_ipd;
10683
                    end if;
10684
                end if;
10685
            end if;
10686
 
10687
            ----------------------
10688
            --  Path Delay Section
10689
            ----------------------
10690
 
10691
            CQDelay := SelectDelay (
10692
                    (1 => (clk_ipd'last_event, tpd_clk_dataout_posedge, TRUE))
10693
            );
10694
            dataout <= dataout_tmp AFTER CQDelay;
10695
        end process;
10696
END vital_arm_lvds_rx_parallel_reg;
10697
--/////////////////////////////////////////////////////////////////////////////
10698
--
10699
-- Module Name : STRATIXII_LVDS_RECEIVER
10700
--
10701
-- Description : Timing simulation model for the STRATIXII LVDS RECEIVER
10702
--               atom. This module instantiates the following sub-modules :
10703
--               1) stratixii_lvds_rx_fifo
10704
--               2) stratixii_lvds_rx_bitslip
10705
--               3) DFFEs for the LOADEN signals
10706
--               4) stratixii_lvds_rx_parallel_reg
10707
--
10708
--/////////////////////////////////////////////////////////////////////////////
10709
LIBRARY IEEE;
10710
USE ieee.std_logic_1164.all;
10711
USE IEEE.VITAL_Timing.all;
10712
USE IEEE.VITAL_Primitives.all;
10713
USE work.stratixii_atom_pack.all;
10714
USE work.stratixii_lvds_rx_bitslip;
10715
USE work.stratixii_lvds_rx_fifo;
10716
USE work.stratixii_lvds_rx_deser;
10717
USE work.stratixii_lvds_rx_parallel_reg;
10718
USE work.stratixii_lvds_reg;
10719
 
10720
ENTITY stratixii_lvds_receiver IS
10721
    GENERIC ( channel_width                  :  integer := 10;
10722
              data_align_rollover            :  integer := 2;
10723
              enable_dpa                     :  string := "off";
10724
              lose_lock_on_one_change        :  string := "off";
10725
              reset_fifo_at_first_lock       :  string := "on";
10726
              align_to_rising_edge_only      :  string := "on";
10727
              use_serial_feedback_input      :  string := "off";
10728
              dpa_debug                      :  string := "off";
10729
              x_on_bitslip                   :  string := "on";
10730
              lpm_type                       :  string := "stratixii_lvds_receiver";
10731
              MsgOn                    : Boolean := DefGlitchMsgOn;
10732
              XOn                      : Boolean := DefGlitchXOn;
10733
              MsgOnChecks              : Boolean := DefMsgOnChecks;
10734
              XOnChecks                : Boolean := DefXOnChecks;
10735
              InstancePath             : String := "*";
10736
              tipd_clk0                : VitalDelayType01 := DefpropDelay01;
10737
              tipd_datain              : VitalDelayType01 := DefpropDelay01;
10738
              tipd_enable0             : VitalDelayType01 := DefpropDelay01;
10739
              tipd_dpareset            : VitalDelayType01 := DefpropDelay01;
10740
              tipd_dpahold             : VitalDelayType01 := DefpropDelay01;
10741
              tipd_dpaswitch           : VitalDelayType01 := DefpropDelay01;
10742
              tipd_fiforeset           : VitalDelayType01 := DefpropDelay01;
10743
              tipd_bitslip             : VitalDelayType01 := DefpropDelay01;
10744
              tipd_bitslipreset        : VitalDelayType01 := DefpropDelay01;
10745
              tipd_serialfbk           : VitalDelayType01 := DefpropDelay01;
10746
              tpd_clk0_dpalock_posedge : VitalDelayType01 := DefPropDelay01
10747
            );
10748
    PORT    ( clk0                    : IN std_logic;
10749
              datain                  : IN std_logic := '0';
10750
              enable0                 : IN std_logic := '0';
10751
              dpareset                : IN std_logic := '0';
10752
              dpahold                 : IN std_logic := '0';
10753
              dpaswitch               : IN std_logic := '0';
10754
              fiforeset               : IN std_logic := '0';
10755
              bitslip                 : IN std_logic := '0';
10756
              bitslipreset            : IN std_logic := '0';
10757
              serialfbk               : IN std_logic := '0';
10758
              dataout                 : OUT std_logic_vector(channel_width - 1 DOWNTO 0);
10759
              dpalock                 : OUT std_logic;
10760
              bitslipmax              : OUT std_logic;
10761
              serialdataout           : OUT std_logic;
10762
              postdpaserialdataout    : OUT std_logic;
10763
              devclrn                 : IN std_logic := '1';
10764
              devpor                  : IN std_logic := '1'
10765
            );
10766
 
10767
END stratixii_lvds_receiver;
10768
 
10769
ARCHITECTURE vital_arm_lvds_receiver OF stratixii_lvds_receiver IS
10770
 
10771
    COMPONENT stratixii_lvds_rx_bitslip
10772
        GENERIC ( channel_width            : integer := 10;
10773
                  bitslip_rollover         : integer := 12;
10774
                  x_on_bitslip             : string  := "on";
10775
                  MsgOn                    : Boolean := DefGlitchMsgOn;
10776
                  XOn                      : Boolean := DefGlitchXOn;
10777
                  MsgOnChecks              : Boolean := DefMsgOnChecks;
10778
                  XOnChecks                : Boolean := DefXOnChecks;
10779
                  InstancePath             : String := "*";
10780
                  tipd_clk0                : VitalDelayType01 := DefpropDelay01;
10781
                  tipd_bslipcntl           : VitalDelayType01 := DefpropDelay01;
10782
                  tipd_bsliprst            : VitalDelayType01 := DefpropDelay01;
10783
                  tipd_datain              : VitalDelayType01 := DefpropDelay01;
10784
                  tpd_bsliprst_bslipmax_posedge: VitalDelayType01 := DefPropDelay01;
10785
                  tpd_clk0_bslipmax_posedge: VitalDelayType01 := DefPropDelay01
10786
                );
10787
        PORT    ( clk0                    : IN  std_logic := '0';
10788
                  bslipcntl               : IN  std_logic := '0';
10789
                  bsliprst                : IN  std_logic := '0';
10790
                  datain                  : IN  std_logic := '0';
10791
                  bslipmax                : OUT std_logic;
10792
                  dataout                 : OUT std_logic
10793
                );
10794
    END COMPONENT;
10795
 
10796
    COMPONENT stratixii_lvds_rx_fifo
10797
        GENERIC ( channel_width           :  integer := 10
10798
                );
10799
        PORT    ( wclk                    : IN  std_logic := '0';
10800
                  rclk                    : IN  std_logic := '0';
10801
                  fiforst                 : IN  std_logic := '0';
10802
                  dparst                  : IN  std_logic := '0';
10803
                  datain                  : IN  std_logic := '0';
10804
                  dataout                 : OUT std_logic
10805
                );
10806
    END COMPONENT;
10807
 
10808
    COMPONENT stratixii_lvds_rx_deser
10809
        GENERIC ( channel_width           :  integer := 4
10810
                );
10811
        PORT    ( clk                     : IN  std_logic;
10812
                  datain                  : IN  std_logic;
10813
                  dataout                 : OUT std_logic_vector(channel_width - 1 DOWNTO 0);
10814
                  devclrn                 : IN  std_logic := '1';
10815
                  devpor                  : IN  std_logic := '1'
10816
                );
10817
    END COMPONENT;
10818
 
10819
    COMPONENT stratixii_lvds_rx_parallel_reg
10820
        GENERIC ( channel_width           :  integer := 4
10821
                );
10822
        PORT    ( clk                     : IN  std_logic;
10823
                  enable                  : IN  std_logic := '1';
10824
                  datain                  : IN  std_logic_vector(channel_width - 1 DOWNTO 0);
10825
                  dataout                 : OUT std_logic_vector(channel_width - 1 DOWNTO 0);
10826
                  devclrn                 : IN  std_logic := '1';
10827
                  devpor                  : IN  std_logic := '1'
10828
                );
10829
    END COMPONENT;
10830
 
10831
    COMPONENT stratixii_lvds_reg
10832
        GENERIC ( MsgOn                   : Boolean := DefGlitchMsgOn;
10833
                  XOn                     : Boolean := DefGlitchXOn;
10834
                  MsgOnChecks             : Boolean := DefMsgOnChecks;
10835
                  XOnChecks               : Boolean := DefXOnChecks;
10836
                  InstancePath            : String := "*";
10837
                  tipd_clk                : VitalDelayType01 := DefpropDelay01;
10838
                  tipd_ena                : VitalDelayType01 := DefpropDelay01;
10839
                  tipd_d                  : VitalDelayType01 := DefpropDelay01;
10840
                  tpd_clk_q_posedge       : VitalDelayType01 := DefPropDelay01
10841
                );
10842
        PORT    ( q                       : OUT std_logic;
10843
                  clk                     : IN  std_logic;
10844
                  ena                     : IN  std_logic := '1';
10845
                  d                       : IN  std_logic;
10846
                  clrn                    : IN  std_logic := '1';
10847
                  prn                     : IN  std_logic := '1'
10848
                );
10849
    END COMPONENT;
10850
 
10851
    -- INTERNAL SIGNALS
10852
    signal bitslip_ipd              :  std_logic;
10853
    signal bitslipreset_ipd         :  std_logic;
10854
    signal clk0_ipd                 :  std_logic;
10855
    signal datain_ipd               :  std_logic;
10856
    signal dpahold_ipd              :  std_logic;
10857
    signal dpareset_ipd             :  std_logic;
10858
    signal dpaswitch_ipd            :  std_logic;
10859
    signal enable0_ipd              :  std_logic;
10860
    signal fiforeset_ipd            :  std_logic;
10861
    signal serialfbk_ipd            :  std_logic;
10862
 
10863
    signal fifo_wclk                :  std_logic;
10864
    signal fifo_rclk                :  std_logic;
10865
    signal fifo_datain              :  std_logic;
10866
    signal fifo_dataout             :  std_logic;
10867
    signal fifo_reset               :  std_logic;
10868
    signal slip_datain              :  std_logic;
10869
    signal slip_dataout             :  std_logic;
10870
    signal bitslip_reset            :  std_logic;
10871
    --    wire deser_dataout;
10872
    signal dpareg0_out              :  std_logic;
10873
    signal dpareg1_out              :  std_logic;
10874
    signal dpa_clk                  :  std_logic;
10875
    signal dpa_rst                  :  std_logic;
10876
    signal datain_reg               :  std_logic;
10877
    signal deser_dataout            :  std_logic_vector(channel_width - 1 DOWNTO 0);
10878
    signal reset_fifo               :  std_logic;
10879
    signal first_dpa_lock           :  std_logic;
10880
    signal loadreg_datain           :  std_logic_vector(channel_width - 1 DOWNTO 0);
10881
    signal reset_int                :  std_logic;
10882
    signal gnd                      :  std_logic := '0';
10883
    signal vcc                      :  std_logic := '1';
10884
    signal in_reg_data              :  std_logic;
10885
    signal clk0_dly                 :  std_logic;
10886
    signal datain_tmp               :  std_logic;
10887
 
10888
    -- INTERNAL PARAMETERS
10889
    CONSTANT  DPA_CYCLES_TO_LOCK    :  integer := 2;
10890
 
10891
    signal xhdl_12                  :  std_logic;
10892
    signal rxload                   :  std_logic;
10893
 
10894
    begin
10895
 
10896
        WireDelay : block
10897
        begin
10898
            VitalWireDelay (clk0_ipd, clk0, tipd_clk0);
10899
            VitalWireDelay (datain_ipd, datain, tipd_datain);
10900
            VitalWireDelay (enable0_ipd, enable0, tipd_enable0);
10901
            VitalWireDelay (dpareset_ipd, dpareset, tipd_dpareset);
10902
            VitalWireDelay (dpahold_ipd, dpahold, tipd_dpahold);
10903
            VitalWireDelay (dpaswitch_ipd, dpaswitch, tipd_dpaswitch);
10904
            VitalWireDelay (fiforeset_ipd, fiforeset, tipd_fiforeset);
10905
            VitalWireDelay (bitslip_ipd, bitslip, tipd_bitslip);
10906
            VitalWireDelay (bitslipreset_ipd, bitslipreset, tipd_bitslipreset);
10907
            VitalWireDelay (serialfbk_ipd, serialfbk, tipd_serialfbk);
10908
        end block;
10909
 
10910
        fifo_rclk <= clk0_ipd WHEN (enable_dpa = "on") ELSE gnd ;
10911
        fifo_wclk <= dpa_clk ;
10912
        fifo_datain <= dpareg1_out WHEN (enable_dpa = "on") ELSE gnd ;
10913
        reset_int <= (NOT devpor) OR (NOT devclrn) ;
10914
        fifo_reset <= (NOT devpor) OR (NOT devclrn) OR fiforeset_ipd OR dpareset_ipd OR reset_fifo ;
10915
        bitslip_reset <= (NOT devpor) OR (NOT devclrn) OR bitslipreset_ipd ;
10916
        in_reg_data <= serialfbk_ipd WHEN (use_serial_feedback_input = "on") ELSE datain_ipd;
10917
        clk0_dly <= clk0_ipd;
10918
 
10919
        xhdl_12 <= devclrn OR devpor;
10920
 
10921
        -- SUB-MODULE INSTANTIATION
10922
 
10923
        -- input register in non-DPA mode for sampling incoming data
10924
        in_reg : stratixii_lvds_reg
10925
            PORT MAP ( d    => in_reg_data,
10926
                       clk  => clk0_dly,
10927
                       ena  => vcc,
10928
                       clrn => xhdl_12,
10929
                       prn  => vcc,
10930
                       q    => datain_reg
10931
                     );
10932
 
10933
        dpa_clk <= clk0_ipd when (enable_dpa = "on") else '0' ;
10934
        dpa_rst <= dpareset_ipd when (enable_dpa = "on") else '0' ;
10935
 
10936
        process (dpa_clk, dpa_rst)
10937
        variable dpa_lock_count : integer := 0;
10938
        variable dparst_msg : boolean := false;
10939
        variable dpa_is_locked : std_logic := '0';
10940
        variable dpalock_VitalGlitchData : VitalGlitchDataType;
10941
        variable initial : boolean := true;
10942
        begin
10943
            if (initial) then
10944
                if (reset_fifo_at_first_lock = "on") then
10945
                    reset_fifo <= '1';
10946
                else
10947
                    reset_fifo <= '0';
10948
                end if;
10949
                initial := false;
10950
            end if;
10951
 
10952
            if (dpa_rst = '1') then
10953
                dpa_is_locked := '0';
10954
                dpa_lock_count := 0;
10955
                if (not dparst_msg) then
10956
                    ASSERT false report "DPA was reset" severity note;
10957
                    dparst_msg := true;
10958
                end if;
10959
            elsif (dpa_clk'event and dpa_clk = '1') then
10960
                dparst_msg := false;
10961
                if (dpa_is_locked = '0') then
10962
                    dpa_lock_count := dpa_lock_count + 1;
10963
                    if (dpa_lock_count > DPA_CYCLES_TO_LOCK) then
10964
                        dpa_is_locked := '1';
10965
                        ASSERT false report "DPA locked" severity note;
10966
                        reset_fifo <= '0';
10967
                    end if;
10968
                end if;
10969
            end if;
10970
 
10971
            ----------------------
10972
            --  Path Delay Section
10973
            ----------------------
10974
            VitalPathDelay01 (
10975
                        OutSignal => dpalock,
10976
                        OutSignalName => "DPALOCK",
10977
                        OutTemp => dpa_is_locked,
10978
                        Paths => (1 => (clk0_ipd'last_event, tpd_clk0_dpalock_posedge, enable_dpa = "on")),
10979
                        GlitchData => dpalock_VitalGlitchData,
10980
                        Mode => DefGlitchMode,
10981
                        XOn  => XOn,
10982
                        MsgOn  => MsgOn );
10983
    end process;
10984
 
10985
    -- ?????????? insert delay to mimic DPLL dataout ?????????
10986
 
10987
    -- DPA registers
10988
    dpareg0 : stratixii_lvds_reg
10989
        PORT MAP ( d    => in_reg_data,
10990
                   clk  => dpa_clk,
10991
                   clrn => vcc,
10992
                   prn  => vcc,
10993
                   ena  => vcc,
10994
                   q    => dpareg0_out
10995
                 );
10996
 
10997
    dpareg1 : stratixii_lvds_reg
10998
        PORT MAP ( d    => dpareg0_out,
10999
                   clk  => dpa_clk,
11000
                   clrn => vcc,
11001
                   prn  => vcc,
11002
                   ena  => vcc,
11003
                   q    => dpareg1_out
11004
                 );
11005
 
11006
    s_fifo : stratixii_lvds_rx_fifo
11007
        GENERIC MAP ( channel_width => channel_width
11008
                    )
11009
        PORT MAP    ( wclk    => fifo_wclk,
11010
                      rclk    => fifo_rclk,
11011
                      fiforst => fifo_reset,
11012
                      dparst  => dpa_rst,
11013
                      datain  => fifo_datain,
11014
                      dataout => fifo_dataout
11015
                    );
11016
 
11017
    slip_datain <= fifo_dataout when (enable_dpa = "on" and dpaswitch_ipd = '1') else datain_reg ;
11018
    s_bslip : stratixii_lvds_rx_bitslip
11019
        GENERIC MAP ( bitslip_rollover => data_align_rollover,
11020
                      channel_width    => channel_width,
11021
                      x_on_bitslip     => x_on_bitslip
11022
                    )
11023
        PORT MAP    ( clk0      => clk0_dly,
11024
                      bslipcntl => bitslip_ipd,
11025
                      bsliprst  => bitslip_reset,
11026
                      datain    => slip_datain,
11027
                      bslipmax  => bitslipmax,
11028
                      dataout   => slip_dataout
11029
                    );
11030
 
11031
    --********* DESERIALISER *********//
11032
 
11033
   -- only 1 enable signal used for StratixII
11034
    rxload_reg : stratixii_lvds_reg
11035
        PORT MAP ( d    => enable0_ipd,
11036
                   clk  => clk0_dly,
11037
                   ena  => vcc,
11038
                   clrn => vcc,
11039
                   prn  => vcc,
11040
                   q    => rxload
11041
                 );
11042
 
11043
    s_deser : stratixii_lvds_rx_deser
11044
        GENERIC MAP (channel_width => channel_width
11045
                    )
11046
        PORT MAP    (clk => clk0_dly,
11047
                     datain => slip_dataout,
11048
                     devclrn => devclrn,
11049
                     devpor => devpor,
11050
                     dataout => deser_dataout
11051
                    );
11052
 
11053
    output_reg : stratixii_lvds_rx_parallel_reg
11054
        GENERIC MAP ( channel_width => channel_width
11055
                    )
11056
        PORT MAP    ( clk => clk0_dly,
11057
                      enable => rxload,
11058
                      datain => deser_dataout,
11059
                      devpor => devpor,
11060
                      devclrn => devclrn,
11061
                      dataout => dataout
11062
                    );
11063
 
11064
    postdpaserialdataout <= dpareg1_out ;
11065
    serialdataout <= datain_ipd;
11066
 
11067
END vital_arm_lvds_receiver;
11068
-------------------------------------------------------------------------------
11069
--
11070
-- Entity Name : StratixII_dll
11071
--
11072
-- Outputs     : delayctrlout - current delay chain settings for DQS pin
11073
--               offsetctrlout - current delay offset setting
11074
--               dqsupdate - update enable signal for delay setting latces
11075
--               upndnout - raw output of the phase comparator
11076
--
11077
-- Inputs      : clk - reference clock matching in frequency to DQS clock
11078
--               aload - asychronous load signal for delay setting counter
11079
--                       when asserted, counter is loaded with initial value
11080
--               offset - offset added/subtracted from delayctrlout
11081
--               upndnin - up/down input port for delay setting counter in
11082
--                         use_updndnin mode (user control mode)
11083
--               upndninclkena - clock enable for the delaying setting counter
11084
--               addnsub - dynamically control +/- on offsetctrlout
11085
--
11086
-- Formulae    : delay (input_period) = sim_loop_intrinsic_delay +
11087
--                                      sim_loop_delay_increment * dllcounter;
11088
--
11089
-- Latency     : 3 (clk8 cycles) = pc + dc + dr
11090
-------------------------------------------------------------------------------
11091
 
11092
library IEEE;
11093
use IEEE.std_logic_1164.all;
11094
use IEEE.VITAL_Timing.all;
11095
use IEEE.VITAL_Primitives.all;
11096
use work.stratixii_atom_pack.all;
11097
USE work.stratixii_pllpack.all;
11098
 
11099
ENTITY stratixii_dll is
11100
    GENERIC (
11101
    input_frequency          : string := "10000 ps";
11102
    delay_chain_length       : integer := 16;
11103
    delay_buffer_mode        : string := "low";
11104
    delayctrlout_mode        : string := "normal";
11105
    static_delay_ctrl        : integer := 0;
11106
    offsetctrlout_mode       : string := "static";
11107
    static_offset            : string := "0";
11108
    jitter_reduction         : string := "false";
11109
    use_upndnin              : string := "false";
11110
    use_upndninclkena        : string := "false";
11111
    sim_valid_lock           : integer := 1;
11112
    sim_loop_intrinsic_delay : integer := 1000;
11113
    sim_loop_delay_increment : integer := 100;
11114
    sim_valid_lockcount      : integer := 90;  -- 10000 = 1000 + 100*dllcounter
11115
    lpm_type                 : string := "stratixii_dll";
11116
    tipd_clk                 : VitalDelayType01 := DefpropDelay01;
11117
    tipd_aload               : VitalDelayType01 := DefpropDelay01;
11118
    tipd_offset              : VitalDelayArrayType01(5 downto 0) := (OTHERS => DefPropDelay01);
11119
    tipd_upndnin             : VitalDelayType01 := DefpropDelay01;
11120
    tipd_upndninclkena       : VitalDelayType01 := DefpropDelay01;
11121
    tipd_addnsub             : VitalDelayType01 := DefpropDelay01;
11122
    TimingChecksOn           : Boolean := True;
11123
    MsgOn                    : Boolean := DefGlitchMsgOn;
11124
    XOn                      : Boolean := DefGlitchXOn;
11125
    MsgOnChecks              : Boolean := DefMsgOnChecks;
11126
    XOnChecks                : Boolean := DefXOnChecks;
11127
    InstancePath             : String := "*";
11128
    tpd_offset_delayctrlout  : VitalDelayType01 := DefPropDelay01;
11129
    tpd_clk_upndnout_posedge : VitalDelayType01 := DefPropDelay01;
11130
    tsetup_offset_clk_noedge_posedge        : VitalDelayArrayType(5 downto 0) := (OTHERS => DefSetupHoldCnst);
11131
    thold_offset_clk_noedge_posedge         : VitalDelayArrayType(5 downto 0) := (OTHERS => DefSetupHoldCnst);
11132
    tsetup_upndnin_clk_noedge_posedge       : VitalDelayType := DefSetupHoldCnst;
11133
    thold_upndnin_clk_noedge_posedge        : VitalDelayType := DefSetupHoldCnst;
11134
    tsetup_upndninclkena_clk_noedge_posedge : VitalDelayType := DefSetupHoldCnst;
11135
    thold_upndninclkena_clk_noedge_posedge  : VitalDelayType := DefSetupHoldCnst;
11136
    tsetup_addnsub_clk_noedge_posedge       : VitalDelayType := DefSetupHoldCnst;
11137
    thold_addnsub_clk_noedge_posedge        : VitalDelayType := DefSetupHoldCnst;
11138
    tpd_clk_delayctrlout_posedge            : VitalDelayArrayType01(5 downto 0) := (OTHERS => DefPropDelay01)
11139
    );
11140
 
11141
    PORT    ( clk                      : IN std_logic := '0';
11142
              aload                    : IN std_logic := '0';
11143
              offset                   : IN std_logic_vector(5 DOWNTO 0) := "000000";
11144
              upndnin                  : IN std_logic := '1';
11145
              upndninclkena            : IN std_logic := '1';
11146
              addnsub                  : IN std_logic := '1';
11147
              delayctrlout             : OUT std_logic_vector(5 DOWNTO 0);
11148
              offsetctrlout            : OUT std_logic_vector(5 DOWNTO 0);
11149
              dqsupdate                : OUT std_logic;
11150
              upndnout                 : OUT std_logic;
11151
              devclrn                  : IN std_logic := '1';
11152
              devpor                   : IN std_logic := '1'
11153
            );
11154
 
11155
END stratixii_dll;
11156
 
11157
 
11158
ARCHITECTURE vital_armdll of stratixii_dll is
11159
 
11160
-- tuncate input integer to get 6 LSB bits
11161
function dll_unsigned2bin (in_int : integer) return std_logic_vector is
11162
variable tmp_int, i : integer;
11163
variable tmp_bit : integer;
11164
variable result : std_logic_vector(5 downto 0) := "000000";
11165
begin
11166
    tmp_int := in_int;
11167
    for i in 0 to 5 loop
11168
        tmp_bit := tmp_int MOD 2;
11169
        if (tmp_bit = 1) then
11170
            result(i) := '1';
11171
        else
11172
            result(i) := '0';
11173
            end if;
11174
                tmp_int := tmp_int/2;
11175
    end loop;
11176
    return result;
11177
end dll_unsigned2bin;
11178
 
11179
signal clk_in               : std_logic := '0';
11180
signal aload_in             : std_logic := '0';
11181
signal offset_in            : std_logic_vector(5 DOWNTO 0) := "000000";
11182
signal upndn_in             : std_logic := '0';
11183
signal upndninclkena_in     : std_logic := '1';
11184
signal addnsub_in           : std_logic := '0';
11185
 
11186
signal delayctrl_out        : std_logic_vector(5 DOWNTO 0) := "000000";
11187
signal offsetctrl_out       : std_logic_vector(5 DOWNTO 0) := "000000";
11188
signal dqsupdate_out        : std_logic := '1';
11189
signal upndn_out            : std_logic := '0';
11190
 
11191
signal para_delay_buffer_mode       : std_logic_vector (1 DOWNTO 0) := "01";
11192
signal para_delayctrlout_mode       : std_logic_vector (1 DOWNTO 0) := "00";
11193
signal para_offsetctrlout_mode      : std_logic_vector (1 DOWNTO 0) := "00";
11194
signal para_static_offset           : integer := 0;
11195
signal para_static_delay_ctrl       : integer := 0;
11196
signal para_jitter_reduction        : std_logic := '0';
11197
signal para_use_upndnin             : std_logic := '0';
11198
signal para_use_upndninclkena       : std_logic := '1';
11199
 
11200
-- INTERNAL NETS AND VARIABLES
11201
 
11202
-- for functionality - by modules
11203
 
11204
-- delay and offset control out resolver
11205
signal dr_delayctrl_out       : std_logic_vector (5 DOWNTO 0) := "000000";
11206
signal dr_delayctrl_int       : integer := 0;
11207
signal dr_offsetctrl_out      : std_logic_vector (5 DOWNTO 0) := "000000";
11208
signal dr_offsetctrl_int      : integer := 0;
11209
signal dr_offset_in           : integer := 0;
11210
signal dr_dllcount_in         : integer := 0;
11211
signal dr_addnsub_in          : std_logic := '1';
11212
signal dr_clk8_in             : std_logic := '0';
11213
signal dr_aload_in             : std_logic := '0';
11214
 
11215
signal dr_reg_offset          : integer := 0;
11216
signal dr_reg_dllcount        : integer := 0;
11217
signal dr_delayctrl_out_tmp   : integer := 0;
11218
 
11219
 
11220
 
11221
-- delay chain setting counter
11222
signal dc_dllcount_out        : integer := 0;
11223
signal dc_dqsupdate_out       : std_logic := '0';
11224
signal dc_upndn_in            : std_logic := '1';
11225
signal dc_aload_in            : std_logic := '0';
11226
signal dc_upndnclkena_in      : std_logic := '1';
11227
signal dc_clk8_in             : std_logic := '0';
11228
signal dc_clk1_in             : std_logic := '0';
11229
signal dc_dlltolock_in        : std_logic := '0';
11230
 
11231
signal dc_reg_dllcount        : integer := 0;
11232
signal dc_reg_dlltolock_pulse : std_logic := '0';
11233
 
11234
-- jitter reduction counter
11235
signal jc_upndn_out           : std_logic := '0';
11236
signal jc_upndnclkena_out     : std_logic := '1';
11237
signal jc_clk8_in             : std_logic := '0';
11238
signal jc_upndn_in            : std_logic := '1';
11239
signal jc_aload_in            : std_logic := '0';
11240
 
11241
signal jc_count               : integer   := 8;
11242
signal jc_reg_upndn           : std_logic := '0';
11243
signal jc_reg_upndnclkena     : std_logic := '0';
11244
 
11245
-- phase comparator
11246
signal pc_upndn_out           : std_logic := '1';
11247
signal pc_dllcount_in         : integer := 0;
11248
signal pc_clk1_in             : std_logic := '0';
11249
signal pc_clk8_in             : std_logic := '0';
11250
signal pc_aload_in            : std_logic := '0';
11251
 
11252
signal pc_reg_upndn           : std_logic := '1';
11253
signal pc_delay               : integer   := 0;
11254
 
11255
-- clock generator
11256
signal cg_clk_in              : std_logic := '0';
11257
signal cg_aload_in            : std_logic := '0';
11258
signal cg_clk1_out            : std_logic := '0';
11259
 
11260
signal cg_clk8a_out           : std_logic := '0';
11261
signal cg_clk8b_out           : std_logic := '0';
11262
 
11263
-- por: 000
11264
signal cg_reg_1           : std_logic := '0';
11265
signal cg_rega_2          : std_logic := '0';
11266
signal cg_rega_3          : std_logic := '0';
11267
 
11268
-- por: 010
11269
signal cg_regb_2          : std_logic := '1';
11270
signal cg_regb_3          : std_logic := '0';
11271
 
11272
-- for violation checks
11273
signal dll_to_lock            : std_logic := '0';
11274
signal input_period           : integer := 10000;
11275
signal clk_in_last_value      : std_logic := 'X';
11276
 
11277
 
11278
begin
11279
    -- paramters
11280
    input_period           <= dqs_str2int(input_frequency);
11281
    para_static_offset     <= dqs_str2int(static_offset);
11282
        para_static_delay_ctrl <= static_delay_ctrl;
11283
    para_use_upndnin       <= '1' WHEN use_upndnin = "true" ELSE '0';
11284
    para_jitter_reduction  <= '1' WHEN jitter_reduction = "true" ELSE '0';
11285
    para_use_upndninclkena  <= '1' WHEN use_upndninclkena = "true" ELSE '0';
11286
    para_delay_buffer_mode  <= "00" WHEN delay_buffer_mode = "auto" ELSE "01" WHEN delay_buffer_mode = "low" ELSE "10";
11287
    para_delayctrlout_mode  <= "01" WHEN delayctrlout_mode = "offset_only" ELSE "10" WHEN delayctrlout_mode="normal_offset" ELSE "11" WHEN delayctrlout_mode="static" ELSE "00";
11288
    para_offsetctrlout_mode <= "11" WHEN offsetctrlout_mode = "dynamic_addnsub" ELSE "10" WHEN offsetctrlout_mode = "dynamic_sub" ELSE "01" WHEN offsetctrlout_mode = "dynamic_add" ELSE "00";
11289
 
11290
        -- violation check block
11291
    process (clk_in)
11292
 
11293
    variable got_first_rising_edge  : std_logic := '0';
11294
    variable got_first_falling_edge : std_logic := '0';
11295
 
11296
    variable per_violation              : std_logic  := '0';
11297
    variable duty_violation             : std_logic  := '0';
11298
    variable sent_per_violation         : std_logic  := '0';
11299
    variable sent_duty_violation        : std_logic  := '0';
11300
 
11301
    variable clk_in_last_rising_edge  : time := 0 ps;
11302
    variable clk_in_last_falling_edge : time := 0 ps;
11303
 
11304
    variable input_period_ps     : time := 10000 ps;
11305
    variable duty_cycle          : time := 5000 ps;
11306
    variable clk_in_period       : time := 10000 ps;
11307
    variable clk_in_duty_cycle   : time := 5000 ps;
11308
    variable clk_per_tolerance   : time := 2 ps;
11309
    variable half_cycles_to_lock : integer := 1;
11310
 
11311
    variable init : boolean := true;
11312
 
11313
    begin
11314
        if (init) then
11315
            input_period_ps := dqs_str2int(input_frequency) * 1 ps;
11316
                        if (input_period_ps = 0 ps) then
11317
                assert false report "Need to specify ps scale in simulation command" severity error;
11318
            end if;
11319
 
11320
            duty_cycle := input_period_ps/2;
11321
            clk_per_tolerance := 2 ps;
11322
            half_cycles_to_lock := 0;
11323
            init := false;
11324
        end if;
11325
 
11326
        if (clk_in'event and clk_in = '1')    then -- rising edge
11327
            if (got_first_rising_edge = '0') then
11328
                got_first_rising_edge := '1';
11329
            else     -- subsequent rising
11330
                -- check for clock period and duty cycle violation
11331
                clk_in_period := now - clk_in_last_rising_edge;
11332
                clk_in_duty_cycle := now - clk_in_last_falling_edge;
11333
                if ((clk_in_period < (input_period_ps - clk_per_tolerance)) or (clk_in_period > (input_period_ps + clk_per_tolerance))) then
11334
                    per_violation := '1';
11335
                    if (sent_per_violation /= '1') then
11336
                        sent_per_violation := '1';
11337
                        assert false report "Input clock frequency violation." severity warning;
11338
                    end if;
11339
                elsif ((clk_in_duty_cycle < (duty_cycle - clk_per_tolerance/2 - 1 ps)) or (clk_in_duty_cycle > (duty_cycle + clk_per_tolerance/2 + 1 ps))) then
11340
                    duty_violation := '1';
11341
                    if (sent_duty_violation /= '1') then
11342
                        sent_duty_violation := '1';
11343
                        assert false report "Input clock duty cycle violation." severity warning;
11344
                    end if;
11345
                else
11346
                    if (per_violation = '1') then
11347
                        sent_per_violation := '0';
11348
                        assert false report "Input clock frequency now matches specified clock frequency." severity warning;
11349
                    end if;
11350
                    per_violation := '0';
11351
                    duty_violation := '0';
11352
                end if;
11353
            end if;
11354
 
11355
            if (per_violation = '0' and duty_violation = '0' and dll_to_lock = '0') then
11356
                half_cycles_to_lock := half_cycles_to_lock + 1;
11357
                if (half_cycles_to_lock >= sim_valid_lock) then
11358
                    dll_to_lock <= '1';
11359
                    assert false report "DLL to lock to incoming clock" severity note;
11360
                end if;
11361
            end if;
11362
            clk_in_last_rising_edge := now;
11363
        elsif (clk_in'event and clk_in = '0') then  -- falling edge
11364
            got_first_falling_edge := '1';
11365
            if (got_first_rising_edge = '1') then
11366
                -- duty cycle check
11367
                clk_in_duty_cycle := now - clk_in_last_rising_edge;
11368
                if ((clk_in_duty_cycle < (duty_cycle - clk_per_tolerance/2 - 1 ps)) or (clk_in_duty_cycle > (duty_cycle + clk_per_tolerance/2 + 1 ps))) then
11369
                    duty_violation := '1';
11370
                    if (sent_duty_violation /= '1') then
11371
                        sent_duty_violation := '1';
11372
                        assert false report "Input clock duty cycle violation." severity warning;
11373
                    end if;
11374
                else
11375
                    duty_violation := '0';
11376
                end if;
11377
 
11378
                if (dll_to_lock = '0' and duty_violation = '0') then
11379
                    half_cycles_to_lock := half_cycles_to_lock + 1;
11380
                end if;
11381
            end if;
11382
            clk_in_last_falling_edge := now;
11383
        elsif (got_first_falling_edge = '1' or got_first_rising_edge = '1') then
11384
            -- switches from 1, 0 to X
11385
            half_cycles_to_lock := 0;
11386
            got_first_rising_edge := '0';
11387
            got_first_falling_edge := '0';
11388
            if (dll_to_lock = '1') then
11389
                dll_to_lock <= '0';
11390
                assert false report "Illegal value detected on input clock. DLL will lose lock." severity error;
11391
            else
11392
                assert false report "Illegal value detected on input clock." severity error;
11393
            end if;
11394
        end if;
11395
 
11396
        clk_in_last_value <= clk_in;
11397
 
11398
    end process ; -- violation check
11399
 
11400
 
11401
    -- outputs
11402
    delayctrl_out  <= dr_delayctrl_out;
11403
    offsetctrl_out <= dr_offsetctrl_out;
11404
    dqsupdate_out  <= cg_clk8a_out;
11405
    upndn_out      <= pc_upndn_out;
11406
 
11407
 
11408
    -- Delay and offset ctrl out resolver -------------------------------------
11409
    -------- convert calculations into integer
11410
 
11411
    -- inputs
11412
    dr_clk8_in     <= not cg_clk8b_out;
11413
    dr_offset_in   <= (64 - alt_conv_integer(offset_in)) WHEN ((offset_in /= "000000") AND ((offsetctrlout_mode = "dynamic_addnsub" AND  addnsub_in = '0') or (offsetctrlout_mode = "dynamic_sub"))) ELSE
11414
                       alt_conv_integer(offset_in);
11415
    dr_dllcount_in <= dc_dllcount_out;
11416
    dr_addnsub_in  <= addnsub_in;
11417
    dr_aload_in    <= aload_in;
11418
 
11419
    -- outputs
11420
    dr_delayctrl_out  <= dll_unsigned2bin(dr_delayctrl_out_tmp);
11421
    dr_offsetctrl_out <= dll_unsigned2bin(dr_reg_offset);
11422
 
11423
    dr_delayctrl_out_tmp <= dr_offset_in    WHEN (delayctrlout_mode = "offset_only")   ELSE
11424
                            dr_reg_offset   WHEN (delayctrlout_mode = "normal_offset") ELSE
11425
                            dr_reg_dllcount;
11426
 
11427
    dr_delayctrl_int <= para_static_delay_ctrl WHEN (delayctrlout_mode = "static") ELSE
11428
                        dr_dllcount_in;
11429
 
11430
    dr_offsetctrl_int <= para_static_offset WHEN (offsetctrlout_mode = "static") ELSE
11431
                         dr_offset_in;
11432
 
11433
    -- model
11434
    process(dr_clk8_in, dr_aload_in)
11435
    begin
11436
        if (dr_aload_in = '1' and dr_aload_in'event) then
11437
            dr_reg_dllcount <= 0;
11438
        elsif (dr_clk8_in = '1' and dr_clk8_in'event and dr_aload_in /= '1') then
11439
            dr_reg_dllcount <= dr_delayctrl_int;
11440
        end if;
11441
     end process;
11442
 
11443
    -- generating dr_reg_offset
11444
    process(dr_clk8_in, dr_aload_in)
11445
    begin
11446
        if (dr_aload_in = '1' and dr_aload_in'event) then
11447
            dr_reg_offset <= 0;
11448
        elsif (dr_aload_in /= '1' and dr_clk8_in = '1' and dr_clk8_in'event) then
11449
                  if (offsetctrlout_mode = "dynamic_addnsub") then
11450
            if (dr_addnsub_in = '1') then
11451
                if (dr_delayctrl_int < 63 - dr_offset_in) then
11452
                    dr_reg_offset <= dr_delayctrl_int + dr_offset_in;
11453
                else
11454
                    dr_reg_offset <= 63;
11455
                end if;
11456
            elsif (dr_addnsub_in = '0') then
11457
                if (dr_delayctrl_int > dr_offset_in) then
11458
                    dr_reg_offset <= dr_delayctrl_int - dr_offset_in;
11459
                else
11460
                    dr_reg_offset <= 0;
11461
                end if;
11462
            end if;
11463
          elsif (offsetctrlout_mode = "dynamic_sub") then
11464
            if (dr_delayctrl_int > dr_offset_in) then
11465
                dr_reg_offset <= dr_delayctrl_int - dr_offset_in;
11466
            else
11467
                dr_reg_offset <= 0;
11468
            end if;
11469
          elsif (offsetctrlout_mode = "dynamic_add") then
11470
            if (dr_delayctrl_int < 63 - dr_offset_in) then
11471
                dr_reg_offset <= dr_delayctrl_int + dr_offset_in;
11472
            else
11473
                dr_reg_offset <= 63;
11474
            end if;
11475
          elsif (offsetctrlout_mode = "static") then
11476
            if (para_static_offset >= 0) then
11477
                if ((para_static_offset < 64) AND (para_static_offset < 64 - dr_delayctrl_int)) then
11478
                    dr_reg_offset <= dr_delayctrl_int + para_static_offset;
11479
                else
11480
                    dr_reg_offset <= 64;
11481
                end if;
11482
            else
11483
                if ((para_static_offset > -63) AND (dr_delayctrl_int > (-1)*para_static_offset)) then
11484
                    dr_reg_offset <= dr_delayctrl_int + para_static_offset;
11485
                else
11486
                    dr_reg_offset <= 0;
11487
                end if;
11488
            end if;
11489
          else
11490
            dr_reg_offset <= 14;  -- error
11491
          end if; -- modes
11492
        end if; -- rising clock
11493
    end process ;  -- generating dr_reg_offset
11494
 
11495
    -- Delay Setting Control Counter ------------------------------------------
11496
 
11497
    --inputs
11498
    dc_dlltolock_in   <= dll_to_lock;
11499
    dc_aload_in       <= aload_in;
11500
    dc_clk1_in        <= cg_clk1_out;
11501
    dc_clk8_in        <= not cg_clk8b_out;
11502
    dc_upndnclkena_in <= jc_upndnclkena_out WHEN (para_jitter_reduction = '1') ELSE
11503
                         upndninclkena      WHEN (para_use_upndninclkena = '1')      ELSE
11504
                         '1';
11505
    dc_upndn_in       <= upndnin      WHEN (para_use_upndnin = '1')      ELSE
11506
                         jc_upndn_out WHEN (para_jitter_reduction = '1') ELSE
11507
                         pc_upndn_out;
11508
 
11509
    -- outputs
11510
    dc_dllcount_out  <= dc_reg_dllcount;
11511
 
11512
    -- dll counter logic
11513
    process(dc_clk8_in, dc_aload_in, dc_dlltolock_in)
11514
    variable dc_var_dllcount : integer := 64;
11515
    variable init            : boolean := true;
11516
    begin
11517
        if (init) then
11518
            if (delay_buffer_mode = "low") then
11519
                dc_var_dllcount := 32;
11520
            else
11521
                dc_var_dllcount := 16;
11522
                    end if;
11523
            init := false;
11524
        end if;
11525
 
11526
        if (dc_aload_in = '1' and dc_aload_in'event) then
11527
            if (delay_buffer_mode = "low") then
11528
                dc_var_dllcount := 32;
11529
            else
11530
                dc_var_dllcount := 16;
11531
            end if;
11532
        elsif (dc_aload_in /= '1' and dc_dlltolock_in = '1' and dc_reg_dlltolock_pulse /= '1' and
11533
               dc_upndnclkena_in = '1' and para_use_upndnin = '0') then
11534
                dc_var_dllcount := sim_valid_lockcount;
11535
                dc_reg_dlltolock_pulse <= '1';
11536
        elsif (dc_aload_in /= '1' and
11537
                dc_upndnclkena_in = '1' and dc_clk8_in'event and dc_clk8_in = '1')  then  -- posedge clk
11538
                if (dc_upndn_in = '1') then
11539
                    if ((para_delay_buffer_mode = "01" and dc_var_dllcount < 63) or
11540
                        (para_delay_buffer_mode /= "01" and dc_var_dllcount < 31)) then
11541
                       dc_var_dllcount := dc_var_dllcount + 1;
11542
                    end if;
11543
                elsif (dc_upndn_in = '0') then
11544
                    if (dc_var_dllcount > 0) then
11545
                        dc_var_dllcount := dc_var_dllcount - 1;
11546
                    end if;
11547
                end if;
11548
        end if;  -- rising clock
11549
 
11550
        -- schedule signal dc_reg_dllcount
11551
        dc_reg_dllcount <= dc_var_dllcount;
11552
    end process;
11553
 
11554
    -- Jitter reduction counter -----------------------------------------------
11555
 
11556
    -- inputs
11557
    jc_clk8_in  <= not cg_clk8b_out;
11558
    jc_upndn_in <= pc_upndn_out;
11559
    jc_aload_in <= aload_in;
11560
 
11561
    -- outputs
11562
    jc_upndn_out       <= jc_reg_upndn;
11563
    jc_upndnclkena_out <= jc_reg_upndnclkena;
11564
 
11565
    -- Model
11566
    process (jc_clk8_in, jc_aload_in)
11567
    begin
11568
        if (jc_aload_in = '1' and jc_aload_in'event) then
11569
            jc_count <= 8;
11570
        elsif (jc_aload_in /= '1' and jc_clk8_in'event and jc_clk8_in = '1') then
11571
            if (jc_count = 12) then
11572
                jc_reg_upndn <= '1';
11573
                jc_reg_upndnclkena <= '1';
11574
                jc_count <= 8;
11575
            elsif (jc_count = 4) then
11576
                jc_reg_upndn <= '0';
11577
                jc_reg_upndnclkena <= '1';
11578
                jc_count <= 8;
11579
            else  -- increment/decrement counter
11580
                jc_reg_upndnclkena <= '0';
11581
                if (jc_upndn_in = '1') then
11582
                    jc_count <= jc_count + 1;
11583
                elsif (jc_upndn_in = '0') then
11584
                    jc_count <= jc_count - 1;
11585
                end if;
11586
            end if;
11587
        end if;
11588
    end process;
11589
 
11590
    -- Phase comparator -------------------------------------------------------
11591
 
11592
    -- inputs
11593
    pc_clk1_in <= cg_clk1_out;
11594
    pc_clk8_in <= cg_clk8b_out;  -- positive
11595
    pc_dllcount_in <= dc_dllcount_out; -- for phase loop calculation
11596
    pc_aload_in <= aload_in;
11597
 
11598
    -- outputs
11599
    pc_upndn_out <= pc_reg_upndn;
11600
 
11601
    -- parameter used
11602
    -- sim_loop_intrinsic_delay, sim_loop_delay_increment
11603
 
11604
    -- Model
11605
    process (pc_clk8_in, pc_aload_in)
11606
    variable pc_var_delay : integer := 0;
11607
    begin
11608
        if (pc_aload_in = '1' and pc_aload_in'event) then
11609
            pc_var_delay := 0;
11610
        elsif (pc_aload_in /= '1' and pc_clk8_in'event and pc_clk8_in = '1' ) then
11611
            pc_var_delay := sim_loop_intrinsic_delay + sim_loop_delay_increment * pc_dllcount_in;
11612
            if (pc_var_delay > input_period) then
11613
                pc_reg_upndn <= '0';
11614
            else
11615
                pc_reg_upndn <= '1';
11616
            end if;
11617
 
11618
            pc_delay <= pc_var_delay;
11619
        end if;
11620
    end process;
11621
 
11622
    -- Clock Generator -------------------------------------------------------
11623
 
11624
    -- inputs
11625
    cg_clk_in <= clk_in;
11626
    cg_aload_in <= aload_in;
11627
 
11628
    -- outputs
11629
    cg_clk8a_out <= cg_rega_3;
11630
    cg_clk8b_out <= cg_regb_3;
11631
    cg_clk1_out <= '0' WHEN cg_aload_in = '1' ELSE cg_clk_in;
11632
 
11633
    -- Model
11634
    process(cg_clk1_out, cg_aload_in)
11635
    begin
11636
        if (cg_aload_in = '1' and cg_aload_in'event) then
11637
            cg_reg_1 <= '0';
11638
        elsif (cg_aload_in /= '1' and cg_clk1_out = '1' and cg_clk1_out'event) then
11639
            cg_reg_1 <= not cg_reg_1;
11640
        end if;
11641
    end  process;
11642
 
11643
    process(cg_reg_1, cg_aload_in)
11644
    begin
11645
        if (cg_aload_in = '1' and cg_aload_in'event) then
11646
            cg_rega_2 <= '0';
11647
            cg_regb_2 <= '1';
11648
        elsif (cg_aload_in /= '1' and cg_reg_1 = '1' and cg_reg_1'event) then
11649
            cg_rega_2 <= not cg_rega_2;
11650
            cg_regb_2 <= not cg_regb_2;
11651
        end if;
11652
    end  process;
11653
 
11654
    process (cg_rega_2, cg_aload_in)
11655
    begin
11656
        if (cg_aload_in = '1' and cg_aload_in'event) then
11657
            cg_rega_3 <= '0';
11658
        elsif (cg_aload_in /= '1' and cg_rega_2 = '1' and cg_rega_2'event) then
11659
            cg_rega_3 <= not cg_rega_3;
11660
        end if;
11661
    end  process;
11662
 
11663
    process (cg_regb_2, cg_aload_in)
11664
    begin
11665
        if (cg_aload_in = '1' and cg_aload_in'event) then
11666
            cg_regb_3 <= '0';
11667
        elsif (cg_aload_in /= '1' and cg_regb_2 = '1' and cg_regb_2'event) then
11668
            cg_regb_3 <= not cg_regb_3;
11669
        end if;
11670
    end  process;
11671
 
11672
    --------------------
11673
    -- INPUT PATH DELAYS
11674
    --------------------
11675
    WireDelay : block
11676
    begin
11677
        VitalWireDelay (clk_in,       clk,       tipd_clk);
11678
        VitalWireDelay (aload_in,     aload,     tipd_aload);
11679
        VitalWireDelay (upndn_in,     upndnin,   tipd_upndnin);
11680
        VitalWireDelay (addnsub_in,   addnsub,   tipd_addnsub);
11681
        VitalWireDelay (offset_in(0), offset(0), tipd_offset(0));
11682
        VitalWireDelay (offset_in(1), offset(1), tipd_offset(1));
11683
        VitalWireDelay (offset_in(2), offset(2), tipd_offset(2));
11684
        VitalWireDelay (offset_in(3), offset(3), tipd_offset(3));
11685
        VitalWireDelay (offset_in(4), offset(4), tipd_offset(4));
11686
        VitalWireDelay (offset_in(5), offset(5), tipd_offset(5));
11687
        VitalWireDelay (upndninclkena_in, upndninclkena, tipd_upndninclkena);
11688
    end block;
11689
 
11690
        ------------------------
11691
    --  Timing Check Section
11692
    ------------------------
11693
    VITALtiming : process (clk_in, offset_in, upndn_in, upndninclkena_in, addnsub_in,
11694
                           delayctrl_out, offsetctrl_out, dqsupdate_out, upndn_out)
11695
 
11696
    variable Tviol_offset_clk        : std_ulogic := '0';
11697
    variable Tviol_upndnin_clk       : std_ulogic := '0';
11698
    variable Tviol_addnsub_clk       : std_ulogic := '0';
11699
    variable Tviol_upndninclkena_clk : std_ulogic := '0';
11700
 
11701
    variable TimingData_offset_clk        : VitalTimingDataType := VitalTimingDataInit;
11702
    variable TimingData_upndnin_clk       : VitalTimingDataType := VitalTimingDataInit;
11703
    variable TimingData_addnsub_clk       : VitalTimingDataType := VitalTimingDataInit;
11704
    variable TimingData_upndninclkena_clk : VitalTimingDataType := VitalTimingDataInit;
11705
 
11706
    variable delayctrlout_VitalGlitchDataArray  : VitalGlitchDataArrayType(5 downto 0);
11707
        variable upndnout_VitalGlitchData           : VitalGlitchDataType;
11708
 
11709
    begin
11710
 
11711
        if (TimingChecksOn) then
11712
 
11713
           VitalSetupHoldCheck (
11714
               Violation       => Tviol_offset_clk,
11715
               TimingData      => TimingData_offset_clk,
11716
               TestSignal      => offset_in,
11717
               TestSignalName  => "OFFSET",
11718
               RefSignal       => clk_in,
11719
               RefSignalName   => "CLK",
11720
               SetupHigh       => tsetup_offset_clk_noedge_posedge(0),
11721
               SetupLow        => tsetup_offset_clk_noedge_posedge(0),
11722
               HoldHigh        => thold_offset_clk_noedge_posedge(0),
11723
               HoldLow         => thold_offset_clk_noedge_posedge(0),
11724
               RefTransition   => '/',
11725
               HeaderMsg       => InstancePath & "/SRRATIXII_DLL",
11726
               XOn             => XOn,
11727
               MsgOn           => MsgOnChecks );
11728
 
11729
           VitalSetupHoldCheck (
11730
               Violation       => Tviol_upndnin_clk,
11731
               TimingData      => TimingData_upndnin_clk,
11732
               TestSignal      => upndn_in,
11733
               TestSignalName  => "UPNDNIN",
11734
               RefSignal       => clk_in,
11735
               RefSignalName   => "CLK",
11736
               SetupHigh       => tsetup_upndnin_clk_noedge_posedge,
11737
               SetupLow        => tsetup_upndnin_clk_noedge_posedge,
11738
               HoldHigh        => thold_upndnin_clk_noedge_posedge,
11739
               HoldLow         => thold_upndnin_clk_noedge_posedge,
11740
               RefTransition   => '/',
11741
               HeaderMsg       => InstancePath & "/STRATIXII_DLL",
11742
               XOn             => XOn,
11743
               MsgOn           => MsgOnChecks );
11744
 
11745
           VitalSetupHoldCheck (
11746
               Violation       => Tviol_upndninclkena_clk,
11747
               TimingData      => TimingData_upndninclkena_clk,
11748
               TestSignal      => upndninclkena_in,
11749
               TestSignalName  => "UPNDNINCLKENA",
11750
               RefSignal       => clk_in,
11751
               RefSignalName   => "CLK",
11752
               SetupHigh       => tsetup_upndninclkena_clk_noedge_posedge,
11753
               SetupLow        => tsetup_upndninclkena_clk_noedge_posedge,
11754
               HoldHigh        => thold_upndninclkena_clk_noedge_posedge,
11755
               HoldLow         => thold_upndninclkena_clk_noedge_posedge,
11756
               RefTransition   => '/',
11757
               HeaderMsg       => InstancePath & "/STRATIXII_DLL",
11758
               XOn             => XOn,
11759
               MsgOn           => MsgOnChecks );
11760
 
11761
           VitalSetupHoldCheck (
11762
               Violation       => Tviol_addnsub_clk,
11763
               TimingData      => TimingData_addnsub_clk,
11764
               TestSignal      => addnsub_in,
11765
               TestSignalName  => "ADDNSUB",
11766
               RefSignal       => clk_in,
11767
               RefSignalName   => "CLK",
11768
               SetupHigh       => tsetup_addnsub_clk_noedge_posedge,
11769
               SetupLow        => tsetup_addnsub_clk_noedge_posedge,
11770
               HoldHigh        => thold_addnsub_clk_noedge_posedge,
11771
               HoldLow         => thold_addnsub_clk_noedge_posedge,
11772
               RefTransition   => '/',
11773
               HeaderMsg       => InstancePath & "/STRATIXII_DLL",
11774
               XOn             => XOn,
11775
               MsgOn           => MsgOnChecks );
11776
       end if;
11777
 
11778
       ----------------------
11779
       --  Path Delay Section
11780
       ----------------------
11781
 
11782
       offsetctrlout <= offsetctrl_out;
11783
           dqsupdate <= dqsupdate_out;
11784
 
11785
       VitalPathDelay01 (
11786
           OutSignal     => upndnout,
11787
           OutSignalName => "UPNDNOUT",
11788
           OutTemp       => upndn_out,
11789
           Paths => (0   => (clk_in'last_event,   tpd_clk_upndnout_posedge,   TRUE)),
11790
           GlitchData    => upndnout_VitalGlitchData,
11791
           Mode          => DefGlitchMode,
11792
           XOn           => XOn,
11793
           MsgOn         => MsgOn );
11794
 
11795
       VitalPathDelay01 (
11796
           OutSignal     => delayctrlout(0),
11797
           OutSignalName => "DELAYCTRLOUT",
11798
           OutTemp       => delayctrl_out(0),
11799
           Paths => (0   => (clk_in'last_event,   tpd_clk_delayctrlout_posedge(0),   TRUE),
11800
                     1   => (offset_in'last_event, tpd_offset_delayctrlout, TRUE)),
11801
           GlitchData    => delayctrlout_VitalGlitchDataArray(0),
11802
           Mode          => DefGlitchMode,
11803
           XOn           => XOn,
11804
           MsgOn         => MsgOn );
11805
 
11806
       VitalPathDelay01 (
11807
           OutSignal     => delayctrlout(1),
11808
           OutSignalName => "DELAYCTRLOUT",
11809
           OutTemp       => delayctrl_out(1),
11810
           Paths => (0   => (clk_in'last_event,   tpd_clk_delayctrlout_posedge(0),   TRUE),
11811
                     1   => (offset_in'last_event, tpd_offset_delayctrlout, TRUE)),
11812
           GlitchData    => delayctrlout_VitalGlitchDataArray(1),
11813
           Mode          => DefGlitchMode,
11814
           XOn           => XOn,
11815
           MsgOn         => MsgOn );
11816
 
11817
       VitalPathDelay01 (
11818
           OutSignal     => delayctrlout(2),
11819
           OutSignalName => "DELAYCTRLOUT",
11820
           OutTemp       => delayctrl_out(2),
11821
           Paths => (0   => (clk_in'last_event,   tpd_clk_delayctrlout_posedge(0),   TRUE),
11822
                     1   => (offset_in'last_event, tpd_offset_delayctrlout, TRUE)),
11823
           GlitchData    => delayctrlout_VitalGlitchDataArray(2),
11824
           Mode          => DefGlitchMode,
11825
           XOn           => XOn,
11826
           MsgOn         => MsgOn );
11827
 
11828
       VitalPathDelay01 (
11829
           OutSignal     => delayctrlout(3),
11830
           OutSignalName => "DELAYCTRLOUT",
11831
           OutTemp       => delayctrl_out(3),
11832
           Paths => (0   => (clk_in'last_event,   tpd_clk_delayctrlout_posedge(0),   TRUE),
11833
                     1   => (offset_in'last_event, tpd_offset_delayctrlout, TRUE)),
11834
           GlitchData    => delayctrlout_VitalGlitchDataArray(3),
11835
           Mode          => DefGlitchMode,
11836
           XOn           => XOn,
11837
           MsgOn         => MsgOn );
11838
 
11839
       VitalPathDelay01 (
11840
           OutSignal     => delayctrlout(4),
11841
           OutSignalName => "DELAYCTRLOUT",
11842
           OutTemp       => delayctrl_out(4),
11843
           Paths => (0   => (clk_in'last_event,   tpd_clk_delayctrlout_posedge(0),   TRUE),
11844
                     1   => (offset_in'last_event, tpd_offset_delayctrlout, TRUE)),
11845
           GlitchData    => delayctrlout_VitalGlitchDataArray(4),
11846
           Mode          => DefGlitchMode,
11847
           XOn           => XOn,
11848
           MsgOn         => MsgOn );
11849
 
11850
       VitalPathDelay01 (
11851
           OutSignal     => delayctrlout(5),
11852
           OutSignalName => "DELAYCTRLOUT",
11853
           OutTemp       => delayctrl_out(5),
11854
           Paths => (0   => (clk_in'last_event,   tpd_clk_delayctrlout_posedge(0),   TRUE),
11855
                     1   => (offset_in'last_event, tpd_offset_delayctrlout, TRUE)),
11856
           GlitchData    => delayctrlout_VitalGlitchDataArray(5),
11857
           Mode          => DefGlitchMode,
11858
           XOn           => XOn,
11859
           MsgOn         => MsgOn );
11860
 
11861
 
11862
 
11863
    end process;  -- vital timing
11864
 
11865
 
11866
end vital_armdll;
11867
 
11868
--
11869
--
11870
--  STRATIXII_RUBLOCK Model
11871
--
11872
--
11873
LIBRARY IEEE;
11874
use IEEE.std_logic_1164.all;
11875
use work.stratixii_atom_pack.all;
11876
library grlib;
11877
use grlib.stdlib.all;
11878
 
11879
entity  stratixii_rublock is
11880
        generic
11881
        (
11882
                operation_mode                  : string := "remote";
11883
                sim_init_config                 : string := "factory";
11884
                sim_init_watchdog_value : integer := 0;
11885
                sim_init_page_select    : integer := 0;
11886
                sim_init_status                 : integer := 0;
11887
                lpm_type                                : string := "stratixii_rublock"
11888
        );
11889
        port
11890
        (
11891
                clk                     : in std_logic;
11892
                shiftnld        : in std_logic;
11893
                captnupdt       : in std_logic;
11894
                regin           : in std_logic;
11895
                rsttimer        : in std_logic;
11896
                rconfig         : in std_logic;
11897
                regout          : out std_logic;
11898
                pgmout          : out std_logic_vector(2 downto 0)
11899
        );
11900
 
11901
end stratixii_rublock;
11902
 
11903
architecture architecture_rublock of stratixii_rublock is
11904
 
11905
        signal update_reg : std_logic_vector(20 downto 0);
11906
        signal status_reg : std_logic_vector(4 downto 0) := conv_std_logic_vector(sim_init_status, 5);
11907
        signal shift_reg : std_logic_vector(25 downto 0) := (others => '0');
11908
 
11909
        signal pgmout_update : std_logic_vector(2 downto 0) := (others => '0');
11910
 
11911
begin
11912
 
11913
        -- regout is output of shift-reg bit 0
11914
        -- note that in Stratix, there is an inverter to regout.
11915
        -- but in Stratix II, there is no inverter.
11916
        regout <= shift_reg(0);
11917
 
11918
        -- pgmout is set when reconfig is asserted
11919
        pgmout <= pgmout_update;
11920
 
11921
        process (clk)
11922
        begin
11923
 
11924
                -- initialize registers/outputs
11925
                if ( now = 0 ns ) then
11926
 
11927
                        -- wd_timeout field
11928
                        update_reg(20 downto 9) <= conv_std_logic_vector(sim_init_watchdog_value, 12);
11929
 
11930
                        -- wd enable field
11931
                        if (sim_init_watchdog_value > 0) then
11932
                                update_reg(8) <= '1';
11933
                        else
11934
                                update_reg(8) <= '0';
11935
                        end if;
11936
 
11937
                        -- PGM[] field
11938
                        update_reg(7 downto 1) <= conv_std_logic_vector(sim_init_page_select, 7);
11939
 
11940
                        -- AnF bit
11941
                        if (sim_init_config = "factory") then
11942
                                update_reg(0) <= '0';
11943
                        else
11944
                                update_reg(0) <= '1';
11945
                        end if;
11946
 
11947
                        --to-do: print field values
11948
                        --report "Remote Update Block: Initial configuration:";
11949
                        --report "        -> Field CRC, POF ID, SW ID Error Caused Reconfiguration is set to" & status_reg(0);
11950
                        --report "        -> Field nSTATUS Caused Reconfiguration is set to %s", status_reg[1] ? "True" : "False";
11951
                        --report "        -> Field Core nCONFIG Caused Reconfiguration is set to %s", status_reg[2] ? "True" : "False";
11952
                        --report "        -> Field Pin nCONFIG Caused Reconfiguration is set to %s", status_reg[3] ? "True" : "False";
11953
                        --report "        -> Field Watchdog Timeout Caused Reconfiguration is set to %s", status_reg[4] ? "True" : "False";
11954
                        --report "        -> Field Current Configuration is set to %s", update_reg[0] ? "Application" : "Factory";
11955
                        --report "        -> Field PGM[] Page Select is set to %d", update_reg[7:1]);
11956
                        --report "        -> Field User Watchdog is set to %s", update_reg[8] ? "Enabled" : "Disabled";
11957
                        --report "        -> Field User Watchdog Timeout Value is set to %d", update_reg[20:9];
11958
 
11959
                else
11960
                        -- dont handle clk events during initialization since this will
11961
                        -- destroy the register values that we just initialized
11962
 
11963
                        if (clk = '1') then
11964
                                if (shiftnld = '1') then
11965
                                        -- register shifting
11966
                                        for i in 0 to 24 loop
11967
                                                shift_reg(i) <= shift_reg(i+1);
11968
                                        end loop;
11969
 
11970
                                        shift_reg(25) <= regin;
11971
 
11972
                                elsif (shiftnld = '0') then
11973
                                        -- register loading
11974
 
11975
                                        if (captnupdt = '1') then
11976
                                                -- capture data into shift register
11977
                                                shift_reg <= update_reg & status_reg;
11978
 
11979
                                        elsif (captnupdt = '0') then
11980
                                                -- update data from shift into Update Register
11981
 
11982
                                                if (sim_init_config = "factory" and
11983
                                                        (operation_mode = "remote" or operation_mode = "active_serial_remote")) then
11984
                                                        -- every bit in Update Reg gets updated
11985
                                                        update_reg(20 downto 0) <= shift_reg(25 downto 5);
11986
 
11987
                                                        --to-do: print field values
11988
                                                        --VHDL93 only: report "Remote Update Block: Update Register updated at time " & time'image(now);
11989
                                                        --report "        -> Field PGM[] Page Select is set to %d", shift_reg[12:6];
11990
                                                        --report "        -> Field User Watchdog is set to %s", (shift_reg[13] == 1) ? "Enableds" : (shift_reg[13] == 0) ? "Disabled" : "x";
11991
                                                        --report "        -> Field User Watchdog Timeout Value is set to %d", shift_reg[25:14];
11992
                                                else
11993
                                                        -- trying to do update in Application mode
11994
                                                        --VHDL93 only: report "Remote Update Block: Attempted update of Update Register at time " & time'image(now) & " when Configuration is set to Application" severity WARNING;
11995
                                                end if;
11996
 
11997
                                        else
11998
                                                -- invalid captnupdt
11999
                                                -- destroys update and shift regs
12000
                                                shift_reg <= (others => 'X');
12001
                                                if (sim_init_config = "factory") then
12002
                                                        update_reg(20 downto 1) <= (others => 'X');
12003
                                                end if;
12004
                                        end if;
12005
 
12006
                                else
12007
                                        -- invalid shiftnld: destroys update and shift regs
12008
                                        shift_reg <= (others => 'X');
12009
                                        if (sim_init_config = "factory") then
12010
                                                update_reg(20 downto 1) <= (others => 'X');
12011
                                        end if;
12012
                                end if;
12013
 
12014
                        elsif (clk /= '0') then
12015
                                -- invalid clk: destroys registers
12016
                                shift_reg <= (others => 'X');
12017
                                if (sim_init_config = "factory") then
12018
                                        update_reg(20 downto 1) <= (others => 'X');
12019
                                end if;
12020
                        end if;
12021
                end if;
12022
        end process;
12023
 
12024
        process (rconfig)
12025
        begin
12026
                -- initialize registers/outputs
12027
                if ( now = 0 ns ) then
12028
 
12029
                        -- pgmout update
12030
 
12031
                        if (operation_mode = "local") then
12032
                                pgmout_update <= "001";
12033
                        elsif (operation_mode = "remote") then
12034
                                pgmout_update <= conv_std_logic_vector(sim_init_page_select, 3);
12035
                                -- PGM[] field
12036
                        else
12037
                                pgmout_update <= (others => 'X');
12038
                        end if;
12039
                end if;
12040
 
12041
                if (rconfig = '1') then
12042
                        -- start reconfiguration
12043
                        --to-do: print field values
12044
                        --VHDL93 only: report "Remote Update Block: Reconfiguration initiated at time " & time'image(now);
12045
                        --report "        -> Field Current Configuration is set to %s", update_reg[0] ? "Application" : "Factory";
12046
                        --report "        -> Field PGM[] Page Select is set to %d", update_reg[7:1];
12047
                        --report "        -> Field User Watchdog is set to %s", (update_reg[8] == 1) ? "Enabled" : (update_reg[8] == 0) ? "Disabled" : "x";
12048
                        --report "        -> Field User Watchdog Timeout Value is set to %d", update_reg[20:9];
12049
 
12050
                        if (operation_mode = "remote") then
12051
                                -- set pgm[] to page as set in Update Register
12052
                                pgmout_update <= update_reg(3 downto 1);
12053
 
12054
                        elsif (operation_mode = "local") then
12055
                                -- set pgm[] to page as 001
12056
                                pgmout_update <= "001";
12057
                        else
12058
                                -- invalid rconfig: destroys pgmout (only if not initializing)
12059
                                pgmout_update <= (others => 'X');
12060
                        end if;
12061
 
12062
                elsif (rconfig /= '0') then
12063
                        -- invalid rconfig: destroys pgmout (only if not initializing)
12064
                        if (now /= 0 ns) then
12065
                                pgmout_update <= (others => 'X');
12066
                        end if;
12067
                end if;
12068
        end process;
12069
 
12070
end architecture_rublock;
12071
 
12072
 
12073
-------------------------------------------------------------------------------
12074
--
12075
-- Entity Name : stratixii_termination
12076
--
12077
-- Outputs     : incrup and incrdn - output of voltage comparator
12078
--               terminationcontrol - to I/O, cannot wired to PLD
12079
--               terminationcontrolprobe - internal testing outputs only
12080
--
12081
-- Descriptions : the Atom represent On Chip Termination calibration block.
12082
--               The block has no digital outputs that can be observed in PLD.
12083
--               Therefore we do not have simulation model other than entity
12084
--               declaration.
12085
-------------------------------------------------------------------------------
12086
 
12087
library IEEE;
12088
use IEEE.std_logic_1164.all;
12089
use IEEE.VITAL_Timing.all;
12090
use IEEE.VITAL_Primitives.all;
12091
use work.stratixii_atom_pack.all;
12092
 
12093
ENTITY stratixii_termination is
12094
    GENERIC (
12095
    runtime_control           : string := "false";
12096
    use_core_control          : string := "false";
12097
    pullup_control_to_core    : string := "true";
12098
    use_high_voltage_compare  : string := "true";
12099
    use_both_compares         : string := "false";
12100
    pullup_adder              : integer := 0;
12101
    pulldown_adder            : integer := 0;
12102
    half_rate_clock           : string := "false";
12103
    power_down : string       := "true";
12104
    left_shift : string       := "false";
12105
    test_mode : string        := "false";
12106
    lpm_type : string         := "stratixii_termination";
12107
 
12108
    tipd_rup                  : VitalDelayType01 := DefpropDelay01;
12109
    tipd_rdn                  : VitalDelayType01 := DefpropDelay01;
12110
    tipd_terminationclock     : VitalDelayType01 := DefpropDelay01;
12111
    tipd_terminationclear     : VitalDelayType01 := DefpropDelay01;
12112
    tipd_terminationenable    : VitalDelayType01 := DefpropDelay01;
12113
    tipd_terminationpullup    : VitalDelayArrayType01(6 downto 0) := (OTHERS => DefPropDelay01);
12114
    tipd_terminationpulldown  : VitalDelayArrayType01(6 downto 0) := (OTHERS => DefPropDelay01);
12115
 
12116
    TimingChecksOn           : Boolean := True;
12117
    MsgOn                    : Boolean := DefGlitchMsgOn;
12118
    XOn                      : Boolean := DefGlitchXOn;
12119
    MsgOnChecks              : Boolean := DefMsgOnChecks;
12120
    XOnChecks                : Boolean := DefXOnChecks;
12121
    InstancePath             : String := "*";
12122
 
12123
    tpd_terminationclock_terminationcontrol_posedge       : VitalDelayArrayType01(13 downto 0) := (OTHERS => DefPropDelay01);
12124
    tpd_terminationclock_terminationcontrolprobe_posedge  : VitalDelayArrayType01(6 downto 0)  := (OTHERS => DefPropDelay01)
12125
    );
12126
 
12127
    PORT (
12128
    rup                      : IN std_logic := '0';
12129
    rdn                      : IN std_logic := '0';
12130
    terminationclock         : IN std_logic := '0';
12131
    terminationclear         : IN std_logic := '0';
12132
    terminationenable        : IN std_logic := '1';
12133
    terminationpullup        : IN std_logic_vector(6 DOWNTO 0) := "0000000";
12134
    terminationpulldown      : IN std_logic_vector(6 DOWNTO 0) := "0000000";
12135
    devclrn                  : IN std_logic := '1';
12136
    devpor                   : IN std_logic := '0';
12137
    incrup                   : OUT std_logic;
12138
    incrdn                   : OUT std_logic;
12139
    terminationcontrol       : OUT std_logic_vector(13 DOWNTO 0);
12140
    terminationcontrolprobe  : OUT std_logic_vector(6 DOWNTO 0)
12141
    );
12142
 
12143
END stratixii_termination;
12144
 
12145
ARCHITECTURE vital_armtermination of stratixii_termination is
12146
 
12147
begin
12148
    --------------------
12149
    -- INPUT PATH DELAYS
12150
    --------------------
12151
 
12152
        ------------------------
12153
    --  Timing Check Section
12154
    ------------------------
12155
 
12156
    ----------------------
12157
    --  Path Delay Section
12158
    ----------------------
12159
 
12160
end vital_armtermination;
12161
 
12162
---------------------------------------------------------------------
12163
--
12164
-- Entity Name :  stratixii_routing_wire
12165
--
12166
-- Description :  StratixII Routing Wire VHDL simulation model
12167
--
12168
--
12169
---------------------------------------------------------------------
12170
 
12171
LIBRARY IEEE;
12172
use IEEE.std_logic_1164.all;
12173
use IEEE.VITAL_Timing.all;
12174
use IEEE.VITAL_Primitives.all;
12175
use work.stratixii_atom_pack.all;
12176
 
12177
ENTITY stratixii_routing_wire is
12178
    generic (
12179
             MsgOn : Boolean := DefGlitchMsgOn;
12180
             XOn : Boolean := DefGlitchXOn;
12181
             tpd_datain_dataout : VitalDelayType01 := DefPropDelay01;
12182
             tpd_datainglitch_dataout : VitalDelayType01 := DefPropDelay01;
12183
             tipd_datain : VitalDelayType01 := DefPropDelay01
12184
            );
12185
    PORT (
12186
          datain : in std_logic;
12187
          dataout : out std_logic
12188
         );
12189
   attribute VITAL_LEVEL0 of stratixii_routing_wire : entity is TRUE;
12190
end stratixii_routing_wire;
12191
 
12192
ARCHITECTURE behave of stratixii_routing_wire is
12193
attribute VITAL_LEVEL0 of behave : architecture is TRUE;
12194
signal datain_ipd : std_logic;
12195
signal datainglitch_inert : std_logic;
12196
begin
12197
    ---------------------
12198
    --  INPUT PATH DELAYs
12199
    ---------------------
12200
    WireDelay : block
12201
    begin
12202
        VitalWireDelay (datain_ipd, datain, tipd_datain);
12203
    end block;
12204
 
12205
    VITAL: process(datain_ipd, datainglitch_inert)
12206
    variable datain_inert_VitalGlitchData : VitalGlitchDataType;
12207
    variable dataout_VitalGlitchData : VitalGlitchDataType;
12208
 
12209
    begin
12210
        ----------------------
12211
        --  Path Delay Section
12212
        ----------------------
12213
        VitalPathDelay01 (
12214
            OutSignal => datainglitch_inert,
12215
            OutSignalName => "datainglitch_inert",
12216
            OutTemp => datain_ipd,
12217
            Paths => (1 => (datain_ipd'last_event, tpd_datainglitch_dataout, TRUE)),
12218
            GlitchData => datain_inert_VitalGlitchData,
12219
            Mode => VitalInertial,
12220
            XOn  => XOn,
12221
            MsgOn  => MsgOn );
12222
 
12223
        VitalPathDelay01 (
12224
            OutSignal => dataout,
12225
            OutSignalName => "dataout",
12226
            OutTemp => datainglitch_inert,
12227
            Paths => (1 => (datain_ipd'last_event, tpd_datain_dataout, TRUE)),
12228
            GlitchData => dataout_VitalGlitchData,
12229
            Mode => DefGlitchMode,
12230
            XOn  => XOn,
12231
            MsgOn  => MsgOn );
12232
 
12233
    end process;
12234
 
12235
end behave;

powered by: WebSVN 2.1.0

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