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/] [cycloneiii/] [simprims/] [cycloneiii_atoms.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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