text
stringlengths
938
1.05M
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: INSTITUTO TECNOLOGICO DE COSTA RICA // Engineer: MAURICIO CARVAJAL DELGADO // // Create Date: 10:32:12 03/17/2013 // Design Name: // Module Name: Receptor // Project Name: // Target Devices: // Tool versions: // Description: ////////////////////////////////////////////////////////////////////////////////// module Receptor#( parameter DBIT=8, // #databits SB_TICK=16 //#ticks for stop bits ) ( input wire clk, reset, input wire rx, s_tick, output reg rx_done_tick, output wire [7:0] dout ); //symbolic state declaration localparam [1:0] idle = 2'b00, start = 2'b01, data = 2'b10, stop = 2'b11; // signal declaration reg [1:0] state_reg=0, state_next=0; reg [3:0] s_reg=0, s_next=0; reg [2:0] n_reg=0, n_next=0; reg [7:0] b_reg=0, b_next=0; // body // FSMD state&data registers always @( posedge clk, posedge reset) if (reset) begin state_reg <= idle; s_reg <= 0; n_reg <= 0; b_reg <= 0; end else begin state_reg <=state_next; s_reg <= s_next; n_reg <= n_next; b_reg <= b_next; end // FSMD next_state logic always @* begin state_next = state_reg; rx_done_tick = 1'b0; s_next = s_reg; n_next = n_reg; b_next = b_reg; case (state_reg) idle: if (~rx) begin state_next = start; s_next =0; end start: if (s_tick) if (s_reg==7) begin state_next = data; s_next = 0; n_next = 0; end else s_next = s_reg+1; data: if (s_tick) if (s_reg == 15) begin s_next = 0; b_next = {rx,b_reg [7:1]}; if (n_reg==(DBIT-1)) state_next = stop; else n_next = n_reg + 1; end else s_next = s_reg + 1; stop: if (s_tick) if (s_reg==(SB_TICK-1)) begin state_next = idle; rx_done_tick = 1'b1; end else s_next = s_reg + 1; endcase end //output assign dout = b_reg; endmodule
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Import Bool NAxioms NSub NPow NDiv NParity NLog. (** Derived properties of bitwise operations *) Module Type NBitsProp (Import A : NAxiomsSig') (Import B : NSubProp A) (Import C : NParityProp A B) (Import D : NPowProp A B C) (Import E : NDivProp A B) (Import F : NLog2Prop A B C D). Include BoolEqualityFacts A. Ltac order_nz := try apply pow_nonzero; order'. Hint Rewrite div_0_l mod_0_l div_1_r mod_1_r : nz. (** Some properties of power and division *) Lemma pow_sub_r : forall a b c, a~=0 -> c<=b -> a^(b-c) == a^b / a^c. Proof. intros a b c Ha H. apply div_unique with 0. generalize (pow_nonzero a c Ha) (le_0_l (a^c)); order'. nzsimpl. now rewrite <- pow_add_r, add_comm, sub_add. Qed. Lemma pow_div_l : forall a b c, b~=0 -> a mod b == 0 -> (a/b)^c == a^c / b^c. Proof. intros a b c Hb H. apply div_unique with 0. generalize (pow_nonzero b c Hb) (le_0_l (b^c)); order'. nzsimpl. rewrite <- pow_mul_l. f_equiv. now apply div_exact. Qed. (** An injection from bits [true] and [false] to numbers 1 and 0. We declare it as a (local) coercion for shorter statements. *) Definition b2n (b:bool) := if b then 1 else 0. Local Coercion b2n : bool >-> t. Instance b2n_proper : Proper (Logic.eq ==> eq) b2n. Proof. solve_proper. Qed. Lemma exists_div2 a : exists a' (b:bool), a == 2*a' + b. Proof. elim (Even_or_Odd a); [intros (a',H)| intros (a',H)]. exists a'. exists false. now nzsimpl. exists a'. exists true. now simpl. Qed. (** We can compact [testbit_odd_0] [testbit_even_0] [testbit_even_succ] [testbit_odd_succ] in only two lemmas. *) Lemma testbit_0_r a (b:bool) : testbit (2*a+b) 0 = b. Proof. destruct b; simpl; rewrite ?add_0_r. apply testbit_odd_0. apply testbit_even_0. Qed. Lemma testbit_succ_r a (b:bool) n : testbit (2*a+b) (succ n) = testbit a n. Proof. destruct b; simpl; rewrite ?add_0_r. apply testbit_odd_succ, le_0_l. apply testbit_even_succ, le_0_l. Qed. (** Alternative caracterisations of [testbit] *) (** This concise equation could have been taken as specification for testbit in the interface, but it would have been hard to implement with little initial knowledge about div and mod *) Lemma testbit_spec' a n : a.[n] == (a / 2^n) mod 2. Proof. revert a. induct n. intros a. nzsimpl. destruct (exists_div2 a) as (a' & b & H). rewrite H at 1. rewrite testbit_0_r. apply mod_unique with a'; trivial. destruct b; order'. intros n IH a. destruct (exists_div2 a) as (a' & b & H). rewrite H at 1. rewrite testbit_succ_r, IH. f_equiv. rewrite pow_succ_r', <- div_div by order_nz. f_equiv. apply div_unique with b; trivial. destruct b; order'. Qed. (** This caracterisation that uses only basic operations and power was initially taken as specification for testbit. We describe [a] as having a low part and a high part, with the corresponding bit in the middle. This caracterisation is moderatly complex to implement, but also moderately usable... *) Lemma testbit_spec a n : exists l h, 0<=l<2^n /\ a == l + (a.[n] + 2*h)*2^n. Proof. exists (a mod 2^n). exists (a / 2^n / 2). split. split; [apply le_0_l | apply mod_upper_bound; order_nz]. rewrite add_comm, mul_comm, (add_comm a.[n]). rewrite (div_mod a (2^n)) at 1 by order_nz. do 2 f_equiv. rewrite testbit_spec'. apply div_mod. order'. Qed. Lemma testbit_true : forall a n, a.[n] = true <-> (a / 2^n) mod 2 == 1. Proof. intros a n. rewrite <- testbit_spec'; destruct a.[n]; split; simpl; now try order'. Qed. Lemma testbit_false : forall a n, a.[n] = false <-> (a / 2^n) mod 2 == 0. Proof. intros a n. rewrite <- testbit_spec'; destruct a.[n]; split; simpl; now try order'. Qed. Lemma testbit_eqb : forall a n, a.[n] = eqb ((a / 2^n) mod 2) 1. Proof. intros a n. apply eq_true_iff_eq. now rewrite testbit_true, eqb_eq. Qed. (** Results about the injection [b2n] *) Lemma b2n_inj : forall (a0 b0:bool), a0 == b0 -> a0 = b0. Proof. intros [|] [|]; simpl; trivial; order'. Qed. Lemma add_b2n_double_div2 : forall (a0:bool) a, (a0+2*a)/2 == a. Proof. intros a0 a. rewrite mul_comm, div_add by order'. now rewrite div_small, add_0_l by (destruct a0; order'). Qed. Lemma add_b2n_double_bit0 : forall (a0:bool) a, (a0+2*a).[0] = a0. Proof. intros a0 a. apply b2n_inj. rewrite testbit_spec'. nzsimpl. rewrite mul_comm, mod_add by order'. now rewrite mod_small by (destruct a0; order'). Qed. Lemma b2n_div2 : forall (a0:bool), a0/2 == 0. Proof. intros a0. rewrite <- (add_b2n_double_div2 a0 0). now nzsimpl. Qed. Lemma b2n_bit0 : forall (a0:bool), a0.[0] = a0. Proof. intros a0. rewrite <- (add_b2n_double_bit0 a0 0) at 2. now nzsimpl. Qed. (** The specification of testbit by low and high parts is complete *) Lemma testbit_unique : forall a n (a0:bool) l h, l<2^n -> a == l + (a0 + 2*h)*2^n -> a.[n] = a0. Proof. intros a n a0 l h Hl EQ. apply b2n_inj. rewrite testbit_spec' by trivial. symmetry. apply mod_unique with h. destruct a0; simpl; order'. symmetry. apply div_unique with l; trivial. now rewrite add_comm, (add_comm _ a0), mul_comm. Qed. (** All bits of number 0 are 0 *) Lemma bits_0 : forall n, 0.[n] = false. Proof. intros n. apply testbit_false. nzsimpl; order_nz. Qed. (** Various ways to refer to the lowest bit of a number *) Lemma bit0_odd : forall a, a.[0] = odd a. Proof. intros. symmetry. destruct (exists_div2 a) as (a' & b & EQ). rewrite EQ, testbit_0_r, add_comm, odd_add_mul_2. destruct b; simpl; apply odd_1 || apply odd_0. Qed. Lemma bit0_eqb : forall a, a.[0] = eqb (a mod 2) 1. Proof. intros a. rewrite testbit_eqb. now nzsimpl. Qed. Lemma bit0_mod : forall a, a.[0] == a mod 2. Proof. intros a. rewrite testbit_spec'. now nzsimpl. Qed. (** Hence testing a bit is equivalent to shifting and testing parity *) Lemma testbit_odd : forall a n, a.[n] = odd (a>>n). Proof. intros. now rewrite <- bit0_odd, shiftr_spec, add_0_l. Qed. (** [log2] gives the highest nonzero bit *) Lemma bit_log2 : forall a, a~=0 -> a.[log2 a] = true. Proof. intros a Ha. assert (Ha' : 0 < a) by (generalize (le_0_l a); order). destruct (log2_spec_alt a Ha') as (r & EQ & (_,Hr)). rewrite EQ at 1. rewrite testbit_true, add_comm. rewrite <- (mul_1_l (2^log2 a)) at 1. rewrite div_add by order_nz. rewrite div_small by trivial. rewrite add_0_l. apply mod_small. order'. Qed. Lemma bits_above_log2 : forall a n, log2 a < n -> a.[n] = false. Proof. intros a n H. rewrite testbit_false. rewrite div_small. nzsimpl; order'. apply log2_lt_cancel. rewrite log2_pow2; trivial using le_0_l. Qed. (** Hence the number of bits of [a] is [1+log2 a] (see [Pos.size_nat] and [Pos.size]). *) (** Testing bits after division or multiplication by a power of two *) Lemma div2_bits : forall a n, (a/2).[n] = a.[S n]. Proof. intros. apply eq_true_iff_eq. rewrite 2 testbit_true. rewrite pow_succ_r by apply le_0_l. now rewrite div_div by order_nz. Qed. Lemma div_pow2_bits : forall a n m, (a/2^n).[m] = a.[m+n]. Proof. intros a n. revert a. induct n. intros a m. now nzsimpl. intros n IH a m. nzsimpl; try apply le_0_l. rewrite <- div_div by order_nz. now rewrite IH, div2_bits. Qed. Lemma double_bits_succ : forall a n, (2*a).[S n] = a.[n]. Proof. intros. rewrite <- div2_bits. now rewrite mul_comm, div_mul by order'. Qed. Lemma mul_pow2_bits_add : forall a n m, (a*2^n).[m+n] = a.[m]. Proof. intros. rewrite <- div_pow2_bits. now rewrite div_mul by order_nz. Qed. Lemma mul_pow2_bits_high : forall a n m, n<=m -> (a*2^n).[m] = a.[m-n]. Proof. intros. rewrite <- (sub_add n m) at 1 by order'. now rewrite mul_pow2_bits_add. Qed. Lemma mul_pow2_bits_low : forall a n m, m<n -> (a*2^n).[m] = false. Proof. intros. apply testbit_false. rewrite <- (sub_add m n) by order'. rewrite pow_add_r, mul_assoc. rewrite div_mul by order_nz. rewrite <- (succ_pred (n-m)). rewrite pow_succ_r. now rewrite (mul_comm 2), mul_assoc, mod_mul by order'. apply lt_le_pred. apply sub_gt in H. generalize (le_0_l (n-m)); order. now apply sub_gt. Qed. (** Selecting the low part of a number can be done by a modulo *) Lemma mod_pow2_bits_high : forall a n m, n<=m -> (a mod 2^n).[m] = false. Proof. intros a n m H. destruct (eq_0_gt_0_cases (a mod 2^n)) as [EQ|LT]. now rewrite EQ, bits_0. apply bits_above_log2. apply lt_le_trans with n; trivial. apply log2_lt_pow2; trivial. apply mod_upper_bound; order_nz. Qed. Lemma mod_pow2_bits_low : forall a n m, m<n -> (a mod 2^n).[m] = a.[m]. Proof. intros a n m H. rewrite testbit_eqb. rewrite <- (mod_add _ (2^(P (n-m))*(a/2^n))) by order'. rewrite <- div_add by order_nz. rewrite (mul_comm _ 2), mul_assoc, <- pow_succ_r', succ_pred by now apply sub_gt. rewrite mul_comm, mul_assoc, <- pow_add_r, (add_comm m), sub_add by order. rewrite add_comm, <- div_mod by order_nz. symmetry. apply testbit_eqb. Qed. (** We now prove that having the same bits implies equality. For that we use a notion of equality over functional streams of bits. *) Definition eqf (f g:t -> bool) := forall n:t, f n = g n. Instance eqf_equiv : Equivalence eqf. Proof. split; congruence. Qed. Local Infix "===" := eqf (at level 70, no associativity). Instance testbit_eqf : Proper (eq==>eqf) testbit. Proof. intros a a' Ha n. now rewrite Ha. Qed. (** Only zero corresponds to the always-false stream. *) Lemma bits_inj_0 : forall a, (forall n, a.[n] = false) -> a == 0. Proof. intros a H. destruct (eq_decidable a 0) as [EQ|NEQ]; trivial. apply bit_log2 in NEQ. now rewrite H in NEQ. Qed. (** If two numbers produce the same stream of bits, they are equal. *) Lemma bits_inj : forall a b, testbit a === testbit b -> a == b. Proof. intros a. pattern a. apply strong_right_induction with 0;[solve_proper|clear a|apply le_0_l]. intros a _ IH b H. destruct (eq_0_gt_0_cases a) as [EQ|LT]. rewrite EQ in H |- *. symmetry. apply bits_inj_0. intros n. now rewrite <- H, bits_0. rewrite (div_mod a 2), (div_mod b 2) by order'. f_equiv; [ | now rewrite <- 2 bit0_mod, H]. f_equiv. apply IH; trivial using le_0_l. apply div_lt; order'. intro n. rewrite 2 div2_bits. apply H. Qed. Lemma bits_inj_iff : forall a b, testbit a === testbit b <-> a == b. Proof. split. apply bits_inj. intros EQ; now rewrite EQ. Qed. Hint Rewrite lxor_spec lor_spec land_spec ldiff_spec bits_0 : bitwise. Ltac bitwise := apply bits_inj; intros ?m; autorewrite with bitwise. (** The streams of bits that correspond to a natural numbers are exactly the ones that are always 0 after some point *) Lemma are_bits : forall (f:t->bool), Proper (eq==>Logic.eq) f -> ((exists n, f === testbit n) <-> (exists k, forall m, k<=m -> f m = false)). Proof. intros f Hf. split. intros (a,H). exists (S (log2 a)). intros m Hm. apply le_succ_l in Hm. rewrite H, bits_above_log2; trivial using lt_succ_diag_r. intros (k,Hk). revert f Hf Hk. induct k. intros f Hf H0. exists 0. intros m. rewrite bits_0, H0; trivial. apply le_0_l. intros k IH f Hf Hk. destruct (IH (fun m => f (S m))) as (n, Hn). solve_proper. intros m Hm. apply Hk. now rewrite <- succ_le_mono. exists (f 0 + 2*n). intros m. destruct (zero_or_succ m) as [Hm|(m', Hm)]; rewrite Hm. symmetry. apply add_b2n_double_bit0. rewrite Hn, <- div2_bits. rewrite mul_comm, div_add, b2n_div2, add_0_l; trivial. order'. Qed. (** Properties of shifts *) Lemma shiftr_spec' : forall a n m, (a >> n).[m] = a.[m+n]. Proof. intros. apply shiftr_spec. apply le_0_l. Qed. Lemma shiftl_spec_high' : forall a n m, n<=m -> (a << n).[m] = a.[m-n]. Proof. intros. apply shiftl_spec_high; trivial. apply le_0_l. Qed. Lemma shiftr_div_pow2 : forall a n, a >> n == a / 2^n. Proof. intros. bitwise. rewrite shiftr_spec'. symmetry. apply div_pow2_bits. Qed. Lemma shiftl_mul_pow2 : forall a n, a << n == a * 2^n. Proof. intros. bitwise. destruct (le_gt_cases n m) as [H|H]. now rewrite shiftl_spec_high', mul_pow2_bits_high. now rewrite shiftl_spec_low, mul_pow2_bits_low. Qed. Lemma shiftl_spec_alt : forall a n m, (a << n).[m+n] = a.[m]. Proof. intros. now rewrite shiftl_mul_pow2, mul_pow2_bits_add. Qed. Instance shiftr_wd : Proper (eq==>eq==>eq) shiftr. Proof. intros a a' Ha b b' Hb. now rewrite 2 shiftr_div_pow2, Ha, Hb. Qed. Instance shiftl_wd : Proper (eq==>eq==>eq) shiftl. Proof. intros a a' Ha b b' Hb. now rewrite 2 shiftl_mul_pow2, Ha, Hb. Qed. Lemma shiftl_shiftl : forall a n m, (a << n) << m == a << (n+m). Proof. intros. now rewrite !shiftl_mul_pow2, pow_add_r, mul_assoc. Qed. Lemma shiftr_shiftr : forall a n m, (a >> n) >> m == a >> (n+m). Proof. intros. now rewrite !shiftr_div_pow2, pow_add_r, div_div by order_nz. Qed. Lemma shiftr_shiftl_l : forall a n m, m<=n -> (a << n) >> m == a << (n-m). Proof. intros. rewrite shiftr_div_pow2, !shiftl_mul_pow2. rewrite <- (sub_add m n) at 1 by trivial. now rewrite pow_add_r, mul_assoc, div_mul by order_nz. Qed. Lemma shiftr_shiftl_r : forall a n m, n<=m -> (a << n) >> m == a >> (m-n). Proof. intros. rewrite !shiftr_div_pow2, shiftl_mul_pow2. rewrite <- (sub_add n m) at 1 by trivial. rewrite pow_add_r, (mul_comm (2^(m-n))). now rewrite <- div_div, div_mul by order_nz. Qed. (** shifts and constants *) Lemma shiftl_1_l : forall n, 1 << n == 2^n. Proof. intros. now rewrite shiftl_mul_pow2, mul_1_l. Qed. Lemma shiftl_0_r : forall a, a << 0 == a. Proof. intros. rewrite shiftl_mul_pow2. now nzsimpl. Qed. Lemma shiftr_0_r : forall a, a >> 0 == a. Proof. intros. rewrite shiftr_div_pow2. now nzsimpl. Qed. Lemma shiftl_0_l : forall n, 0 << n == 0. Proof. intros. rewrite shiftl_mul_pow2. now nzsimpl. Qed. Lemma shiftr_0_l : forall n, 0 >> n == 0. Proof. intros. rewrite shiftr_div_pow2. nzsimpl; order_nz. Qed. Lemma shiftl_eq_0_iff : forall a n, a << n == 0 <-> a == 0. Proof. intros a n. rewrite shiftl_mul_pow2. rewrite eq_mul_0. split. intros [H | H]; trivial. contradict H; order_nz. intros H. now left. Qed. Lemma shiftr_eq_0_iff : forall a n, a >> n == 0 <-> a==0 \/ (0<a /\ log2 a < n). Proof. intros a n. rewrite shiftr_div_pow2, div_small_iff by order_nz. destruct (eq_0_gt_0_cases a) as [EQ|LT]. rewrite EQ. split. now left. intros _. assert (H : 2~=0) by order'. generalize (pow_nonzero 2 n H) (le_0_l (2^n)); order. rewrite log2_lt_pow2; trivial. split. right; split; trivial. intros [H|[_ H]]; now order. Qed. Lemma shiftr_eq_0 : forall a n, log2 a < n -> a >> n == 0. Proof. intros a n H. rewrite shiftr_eq_0_iff. destruct (eq_0_gt_0_cases a) as [EQ|LT]. now left. right; now split. Qed. (** Properties of [div2]. *) Lemma div2_div : forall a, div2 a == a/2. Proof. intros. rewrite div2_spec, shiftr_div_pow2. now nzsimpl. Qed. Instance div2_wd : Proper (eq==>eq) div2. Proof. intros a a' Ha. now rewrite 2 div2_div, Ha. Qed. Lemma div2_odd : forall a, a == 2*(div2 a) + odd a. Proof. intros a. rewrite div2_div, <- bit0_odd, bit0_mod. apply div_mod. order'. Qed. (** Properties of [lxor] and others, directly deduced from properties of [xorb] and others. *) Instance lxor_wd : Proper (eq ==> eq ==> eq) lxor. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance land_wd : Proper (eq ==> eq ==> eq) land. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance lor_wd : Proper (eq ==> eq ==> eq) lor. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance ldiff_wd : Proper (eq ==> eq ==> eq) ldiff. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Lemma lxor_eq : forall a a', lxor a a' == 0 -> a == a'. Proof. intros a a' H. bitwise. apply xorb_eq. now rewrite <- lxor_spec, H, bits_0. Qed. Lemma lxor_nilpotent : forall a, lxor a a == 0. Proof. intros. bitwise. apply xorb_nilpotent. Qed. Lemma lxor_eq_0_iff : forall a a', lxor a a' == 0 <-> a == a'. Proof. split. apply lxor_eq. intros EQ; rewrite EQ; apply lxor_nilpotent. Qed. Lemma lxor_0_l : forall a, lxor 0 a == a. Proof. intros. bitwise. apply xorb_false_l. Qed. Lemma lxor_0_r : forall a, lxor a 0 == a. Proof. intros. bitwise. apply xorb_false_r. Qed. Lemma lxor_comm : forall a b, lxor a b == lxor b a. Proof. intros. bitwise. apply xorb_comm. Qed. Lemma lxor_assoc : forall a b c, lxor (lxor a b) c == lxor a (lxor b c). Proof. intros. bitwise. apply xorb_assoc. Qed. Lemma lor_0_l : forall a, lor 0 a == a. Proof. intros. bitwise. trivial. Qed. Lemma lor_0_r : forall a, lor a 0 == a. Proof. intros. bitwise. apply orb_false_r. Qed. Lemma lor_comm : forall a b, lor a b == lor b a. Proof. intros. bitwise. apply orb_comm. Qed. Lemma lor_assoc : forall a b c, lor a (lor b c) == lor (lor a b) c. Proof. intros. bitwise. apply orb_assoc. Qed. Lemma lor_diag : forall a, lor a a == a. Proof. intros. bitwise. apply orb_diag. Qed. Lemma lor_eq_0_l : forall a b, lor a b == 0 -> a == 0. Proof. intros a b H. bitwise. apply (orb_false_iff a.[m] b.[m]). now rewrite <- lor_spec, H, bits_0. Qed. Lemma lor_eq_0_iff : forall a b, lor a b == 0 <-> a == 0 /\ b == 0. Proof. intros a b. split. split. now apply lor_eq_0_l in H. rewrite lor_comm in H. now apply lor_eq_0_l in H. intros (EQ,EQ'). now rewrite EQ, lor_0_l. Qed. Lemma land_0_l : forall a, land 0 a == 0. Proof. intros. bitwise. trivial. Qed. Lemma land_0_r : forall a, land a 0 == 0. Proof. intros. bitwise. apply andb_false_r. Qed. Lemma land_comm : forall a b, land a b == land b a. Proof. intros. bitwise. apply andb_comm. Qed. Lemma land_assoc : forall a b c, land a (land b c) == land (land a b) c. Proof. intros. bitwise. apply andb_assoc. Qed. Lemma land_diag : forall a, land a a == a. Proof. intros. bitwise. apply andb_diag. Qed. Lemma ldiff_0_l : forall a, ldiff 0 a == 0. Proof. intros. bitwise. trivial. Qed. Lemma ldiff_0_r : forall a, ldiff a 0 == a. Proof. intros. bitwise. now rewrite andb_true_r. Qed. Lemma ldiff_diag : forall a, ldiff a a == 0. Proof. intros. bitwise. apply andb_negb_r. Qed. Lemma lor_land_distr_l : forall a b c, lor (land a b) c == land (lor a c) (lor b c). Proof. intros. bitwise. apply orb_andb_distrib_l. Qed. Lemma lor_land_distr_r : forall a b c, lor a (land b c) == land (lor a b) (lor a c). Proof. intros. bitwise. apply orb_andb_distrib_r. Qed. Lemma land_lor_distr_l : forall a b c, land (lor a b) c == lor (land a c) (land b c). Proof. intros. bitwise. apply andb_orb_distrib_l. Qed. Lemma land_lor_distr_r : forall a b c, land a (lor b c) == lor (land a b) (land a c). Proof. intros. bitwise. apply andb_orb_distrib_r. Qed. Lemma ldiff_ldiff_l : forall a b c, ldiff (ldiff a b) c == ldiff a (lor b c). Proof. intros. bitwise. now rewrite negb_orb, andb_assoc. Qed. Lemma lor_ldiff_and : forall a b, lor (ldiff a b) (land a b) == a. Proof. intros. bitwise. now rewrite <- andb_orb_distrib_r, orb_comm, orb_negb_r, andb_true_r. Qed. Lemma land_ldiff : forall a b, land (ldiff a b) b == 0. Proof. intros. bitwise. now rewrite <-andb_assoc, (andb_comm (negb _)), andb_negb_r, andb_false_r. Qed. (** Properties of [setbit] and [clearbit] *) Definition setbit a n := lor a (1<<n). Definition clearbit a n := ldiff a (1<<n). Lemma setbit_spec' : forall a n, setbit a n == lor a (2^n). Proof. intros. unfold setbit. now rewrite shiftl_1_l. Qed. Lemma clearbit_spec' : forall a n, clearbit a n == ldiff a (2^n). Proof. intros. unfold clearbit. now rewrite shiftl_1_l. Qed. Instance setbit_wd : Proper (eq==>eq==>eq) setbit. Proof. unfold setbit. solve_proper. Qed. Instance clearbit_wd : Proper (eq==>eq==>eq) clearbit. Proof. unfold clearbit. solve_proper. Qed. Lemma pow2_bits_true : forall n, (2^n).[n] = true. Proof. intros. rewrite <- (mul_1_l (2^n)). rewrite <- (add_0_l n) at 2. now rewrite mul_pow2_bits_add, bit0_odd, odd_1. Qed. Lemma pow2_bits_false : forall n m, n~=m -> (2^n).[m] = false. Proof. intros. rewrite <- (mul_1_l (2^n)). destruct (le_gt_cases n m). rewrite mul_pow2_bits_high; trivial. rewrite <- (succ_pred (m-n)) by (apply sub_gt; order). now rewrite <- div2_bits, div_small, bits_0 by order'. rewrite mul_pow2_bits_low; trivial. Qed. Lemma pow2_bits_eqb : forall n m, (2^n).[m] = eqb n m. Proof. intros. apply eq_true_iff_eq. rewrite eqb_eq. split. destruct (eq_decidable n m) as [H|H]. trivial. now rewrite (pow2_bits_false _ _ H). intros EQ. rewrite EQ. apply pow2_bits_true. Qed. Lemma setbit_eqb : forall a n m, (setbit a n).[m] = eqb n m || a.[m]. Proof. intros. now rewrite setbit_spec', lor_spec, pow2_bits_eqb, orb_comm. Qed. Lemma setbit_iff : forall a n m, (setbit a n).[m] = true <-> n==m \/ a.[m] = true. Proof. intros. now rewrite setbit_eqb, orb_true_iff, eqb_eq. Qed. Lemma setbit_eq : forall a n, (setbit a n).[n] = true. Proof. intros. apply setbit_iff. now left. Qed. Lemma setbit_neq : forall a n m, n~=m -> (setbit a n).[m] = a.[m]. Proof. intros a n m H. rewrite setbit_eqb. rewrite <- eqb_eq in H. apply not_true_is_false in H. now rewrite H. Qed. Lemma clearbit_eqb : forall a n m, (clearbit a n).[m] = a.[m] && negb (eqb n m). Proof. intros. now rewrite clearbit_spec', ldiff_spec, pow2_bits_eqb. Qed. Lemma clearbit_iff : forall a n m, (clearbit a n).[m] = true <-> a.[m] = true /\ n~=m. Proof. intros. rewrite clearbit_eqb, andb_true_iff, <- eqb_eq. now rewrite negb_true_iff, not_true_iff_false. Qed. Lemma clearbit_eq : forall a n, (clearbit a n).[n] = false. Proof. intros. rewrite clearbit_eqb, (proj2 (eqb_eq _ _) (eq_refl n)). apply andb_false_r. Qed. Lemma clearbit_neq : forall a n m, n~=m -> (clearbit a n).[m] = a.[m]. Proof. intros a n m H. rewrite clearbit_eqb. rewrite <- eqb_eq in H. apply not_true_is_false in H. rewrite H. apply andb_true_r. Qed. (** Shifts of bitwise operations *) Lemma shiftl_lxor : forall a b n, (lxor a b) << n == lxor (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', lxor_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_lxor : forall a b n, (lxor a b) >> n == lxor (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', lxor_spec. Qed. Lemma shiftl_land : forall a b n, (land a b) << n == land (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', land_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_land : forall a b n, (land a b) >> n == land (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', land_spec. Qed. Lemma shiftl_lor : forall a b n, (lor a b) << n == lor (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', lor_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_lor : forall a b n, (lor a b) >> n == lor (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', lor_spec. Qed. Lemma shiftl_ldiff : forall a b n, (ldiff a b) << n == ldiff (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', ldiff_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_ldiff : forall a b n, (ldiff a b) >> n == ldiff (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', ldiff_spec. Qed. (** We cannot have a function complementing all bits of a number, otherwise it would have an infinity of bit 1. Nonetheless, we can design a bounded complement *) Definition ones n := P (1 << n). Definition lnot a n := lxor a (ones n). Instance ones_wd : Proper (eq==>eq) ones. Proof. unfold ones. solve_proper. Qed. Instance lnot_wd : Proper (eq==>eq==>eq) lnot. Proof. unfold lnot. solve_proper. Qed. Lemma ones_equiv : forall n, ones n == P (2^n). Proof. intros; unfold ones; now rewrite shiftl_1_l. Qed. Lemma ones_add : forall n m, ones (m+n) == 2^m * ones n + ones m. Proof. intros n m. rewrite !ones_equiv. rewrite <- !sub_1_r, mul_sub_distr_l, mul_1_r, <- pow_add_r. rewrite add_sub_assoc, sub_add. reflexivity. apply pow_le_mono_r. order'. rewrite <- (add_0_r m) at 1. apply add_le_mono_l, le_0_l. rewrite <- (pow_0_r 2). apply pow_le_mono_r. order'. apply le_0_l. Qed. Lemma ones_div_pow2 : forall n m, m<=n -> ones n / 2^m == ones (n-m). Proof. intros n m H. symmetry. apply div_unique with (ones m). rewrite ones_equiv. apply le_succ_l. rewrite succ_pred; order_nz. rewrite <- (sub_add m n H) at 1. rewrite (add_comm _ m). apply ones_add. Qed. Lemma ones_mod_pow2 : forall n m, m<=n -> (ones n) mod (2^m) == ones m. Proof. intros n m H. symmetry. apply mod_unique with (ones (n-m)). rewrite ones_equiv. apply le_succ_l. rewrite succ_pred; order_nz. rewrite <- (sub_add m n H) at 1. rewrite (add_comm _ m). apply ones_add. Qed. Lemma ones_spec_low : forall n m, m<n -> (ones n).[m] = true. Proof. intros. apply testbit_true. rewrite ones_div_pow2 by order. rewrite <- (pow_1_r 2). rewrite ones_mod_pow2. rewrite ones_equiv. now nzsimpl'. apply le_add_le_sub_r. nzsimpl. now apply le_succ_l. Qed. Lemma ones_spec_high : forall n m, n<=m -> (ones n).[m] = false. Proof. intros. destruct (eq_0_gt_0_cases n) as [EQ|LT]; rewrite ones_equiv. now rewrite EQ, pow_0_r, one_succ, pred_succ, bits_0. apply bits_above_log2. rewrite log2_pred_pow2; trivial. rewrite <-le_succ_l, succ_pred; order. Qed. Lemma ones_spec_iff : forall n m, (ones n).[m] = true <-> m<n. Proof. intros. split. intros H. apply lt_nge. intro H'. apply ones_spec_high in H'. rewrite H in H'; discriminate. apply ones_spec_low. Qed. Lemma lnot_spec_low : forall a n m, m<n -> (lnot a n).[m] = negb a.[m]. Proof. intros. unfold lnot. now rewrite lxor_spec, ones_spec_low. Qed. Lemma lnot_spec_high : forall a n m, n<=m -> (lnot a n).[m] = a.[m]. Proof. intros. unfold lnot. now rewrite lxor_spec, ones_spec_high, xorb_false_r. Qed. Lemma lnot_involutive : forall a n, lnot (lnot a n) n == a. Proof. intros a n. bitwise. destruct (le_gt_cases n m). now rewrite 2 lnot_spec_high. now rewrite 2 lnot_spec_low, negb_involutive. Qed. Lemma lnot_0_l : forall n, lnot 0 n == ones n. Proof. intros. unfold lnot. apply lxor_0_l. Qed. Lemma lnot_ones : forall n, lnot (ones n) n == 0. Proof. intros. unfold lnot. apply lxor_nilpotent. Qed. (** Bounded complement and other operations *) Lemma lor_ones_low : forall a n, log2 a < n -> lor a (ones n) == ones n. Proof. intros a n H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. now rewrite ones_spec_low, orb_true_r. Qed. Lemma land_ones : forall a n, land a (ones n) == a mod 2^n. Proof. intros a n. bitwise. destruct (le_gt_cases n m). now rewrite ones_spec_high, mod_pow2_bits_high, andb_false_r. now rewrite ones_spec_low, mod_pow2_bits_low, andb_true_r. Qed. Lemma land_ones_low : forall a n, log2 a < n -> land a (ones n) == a. Proof. intros; rewrite land_ones. apply mod_small. apply log2_lt_cancel. rewrite log2_pow2; trivial using le_0_l. Qed. Lemma ldiff_ones_r : forall a n, ldiff a (ones n) == (a >> n) << n. Proof. intros a n. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, shiftl_spec_high', shiftr_spec'; trivial. rewrite sub_add; trivial. apply andb_true_r. now rewrite ones_spec_low, shiftl_spec_low, andb_false_r. Qed. Lemma ldiff_ones_r_low : forall a n, log2 a < n -> ldiff a (ones n) == 0. Proof. intros a n H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. now rewrite ones_spec_low, andb_false_r. Qed. Lemma ldiff_ones_l_low : forall a n, log2 a < n -> ldiff (ones n) a == lnot a n. Proof. intros a n H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, lnot_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. now rewrite ones_spec_low, lnot_spec_low. Qed. Lemma lor_lnot_diag : forall a n, lor a (lnot a n) == lor a (ones n). Proof. intros a n. bitwise. destruct (le_gt_cases n m). rewrite lnot_spec_high, ones_spec_high; trivial. now destruct a.[m]. rewrite lnot_spec_low, ones_spec_low; trivial. now destruct a.[m]. Qed. Lemma lor_lnot_diag_low : forall a n, log2 a < n -> lor a (lnot a n) == ones n. Proof. intros a n H. now rewrite lor_lnot_diag, lor_ones_low. Qed. Lemma land_lnot_diag : forall a n, land a (lnot a n) == ldiff a (ones n). Proof. intros a n. bitwise. destruct (le_gt_cases n m). rewrite lnot_spec_high, ones_spec_high; trivial. now destruct a.[m]. rewrite lnot_spec_low, ones_spec_low; trivial. now destruct a.[m]. Qed. Lemma land_lnot_diag_low : forall a n, log2 a < n -> land a (lnot a n) == 0. Proof. intros. now rewrite land_lnot_diag, ldiff_ones_r_low. Qed. Lemma lnot_lor_low : forall a b n, log2 a < n -> log2 b < n -> lnot (lor a b) n == land (lnot a n) (lnot b n). Proof. intros a b n Ha Hb. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, lor_spec, !bits_above_log2; trivial. now apply lt_le_trans with n. now apply lt_le_trans with n. now rewrite !lnot_spec_low, lor_spec, negb_orb. Qed. Lemma lnot_land_low : forall a b n, log2 a < n -> log2 b < n -> lnot (land a b) n == lor (lnot a n) (lnot b n). Proof. intros a b n Ha Hb. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, land_spec, !bits_above_log2; trivial. now apply lt_le_trans with n. now apply lt_le_trans with n. now rewrite !lnot_spec_low, land_spec, negb_andb. Qed. Lemma ldiff_land_low : forall a b n, log2 a < n -> ldiff a b == land a (lnot b n). Proof. intros a b n Ha. bitwise. destruct (le_gt_cases n m). rewrite (bits_above_log2 a m). trivial. now apply lt_le_trans with n. rewrite !lnot_spec_low; trivial. Qed. Lemma lnot_ldiff_low : forall a b n, log2 a < n -> log2 b < n -> lnot (ldiff a b) n == lor (lnot a n) b. Proof. intros a b n Ha Hb. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, ldiff_spec, !bits_above_log2; trivial. now apply lt_le_trans with n. now apply lt_le_trans with n. now rewrite !lnot_spec_low, ldiff_spec, negb_andb, negb_involutive. Qed. Lemma lxor_lnot_lnot : forall a b n, lxor (lnot a n) (lnot b n) == lxor a b. Proof. intros a b n. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high; trivial. rewrite !lnot_spec_low, xorb_negb_negb; trivial. Qed. Lemma lnot_lxor_l : forall a b n, lnot (lxor a b) n == lxor (lnot a n) b. Proof. intros a b n. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, lxor_spec; trivial. rewrite !lnot_spec_low, lxor_spec, negb_xorb_l; trivial. Qed. Lemma lnot_lxor_r : forall a b n, lnot (lxor a b) n == lxor a (lnot b n). Proof. intros a b n. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, lxor_spec; trivial. rewrite !lnot_spec_low, lxor_spec, negb_xorb_r; trivial. Qed. Lemma lxor_lor : forall a b, land a b == 0 -> lxor a b == lor a b. Proof. intros a b H. bitwise. assert (a.[m] && b.[m] = false) by now rewrite <- land_spec, H, bits_0. now destruct a.[m], b.[m]. Qed. (** Bitwise operations and log2 *) Lemma log2_bits_unique : forall a n, a.[n] = true -> (forall m, n<m -> a.[m] = false) -> log2 a == n. Proof. intros a n H H'. destruct (eq_0_gt_0_cases a) as [Ha|Ha]. now rewrite Ha, bits_0 in H. apply le_antisymm; apply le_ngt; intros LT. specialize (H' _ LT). now rewrite bit_log2 in H' by order. now rewrite bits_above_log2 in H by order. Qed. Lemma log2_shiftr : forall a n, log2 (a >> n) == log2 a - n. Proof. intros a n. destruct (eq_0_gt_0_cases a) as [Ha|Ha]. now rewrite Ha, shiftr_0_l, log2_nonpos, sub_0_l by order. destruct (lt_ge_cases (log2 a) n). rewrite shiftr_eq_0, log2_nonpos by order. symmetry. rewrite sub_0_le; order. apply log2_bits_unique. now rewrite shiftr_spec', sub_add, bit_log2 by order. intros m Hm. rewrite shiftr_spec'; trivial. apply bits_above_log2; try order. now apply lt_sub_lt_add_r. Qed. Lemma log2_shiftl : forall a n, a~=0 -> log2 (a << n) == log2 a + n. Proof. intros a n Ha. rewrite shiftl_mul_pow2, add_comm by trivial. apply log2_mul_pow2. generalize (le_0_l a); order. apply le_0_l. Qed. Lemma log2_lor : forall a b, log2 (lor a b) == max (log2 a) (log2 b). Proof. assert (AUX : forall a b, a<=b -> log2 (lor a b) == log2 b). intros a b H. destruct (eq_0_gt_0_cases a) as [Ha|Ha]. now rewrite Ha, lor_0_l. apply log2_bits_unique. now rewrite lor_spec, bit_log2, orb_true_r by order. intros m Hm. assert (H' := log2_le_mono _ _ H). now rewrite lor_spec, 2 bits_above_log2 by order. (* main *) intros a b. destruct (le_ge_cases a b) as [H|H]. rewrite max_r by now apply log2_le_mono. now apply AUX. rewrite max_l by now apply log2_le_mono. rewrite lor_comm. now apply AUX. Qed. Lemma log2_land : forall a b, log2 (land a b) <= min (log2 a) (log2 b). Proof. assert (AUX : forall a b, a<=b -> log2 (land a b) <= log2 a). intros a b H. apply le_ngt. intros H'. destruct (eq_decidable (land a b) 0) as [EQ|NEQ]. rewrite EQ in H'. apply log2_lt_cancel in H'. generalize (le_0_l a); order. generalize (bit_log2 (land a b) NEQ). now rewrite land_spec, bits_above_log2. (* main *) intros a b. destruct (le_ge_cases a b) as [H|H]. rewrite min_l by now apply log2_le_mono. now apply AUX. rewrite min_r by now apply log2_le_mono. rewrite land_comm. now apply AUX. Qed. Lemma log2_lxor : forall a b, log2 (lxor a b) <= max (log2 a) (log2 b). Proof. assert (AUX : forall a b, a<=b -> log2 (lxor a b) <= log2 b). intros a b H. apply le_ngt. intros H'. destruct (eq_decidable (lxor a b) 0) as [EQ|NEQ]. rewrite EQ in H'. apply log2_lt_cancel in H'. generalize (le_0_l a); order. generalize (bit_log2 (lxor a b) NEQ). rewrite lxor_spec, 2 bits_above_log2; try order. discriminate. apply le_lt_trans with (log2 b); trivial. now apply log2_le_mono. (* main *) intros a b. destruct (le_ge_cases a b) as [H|H]. rewrite max_r by now apply log2_le_mono. now apply AUX. rewrite max_l by now apply log2_le_mono. rewrite lxor_comm. now apply AUX. Qed. (** Bitwise operations and arithmetical operations *) Local Notation xor3 a b c := (xorb (xorb a b) c). Local Notation lxor3 a b c := (lxor (lxor a b) c). Local Notation nextcarry a b c := ((a&&b) || (c && (a||b))). Local Notation lnextcarry a b c := (lor (land a b) (land c (lor a b))). Lemma add_bit0 : forall a b, (a+b).[0] = xorb a.[0] b.[0]. Proof. intros. now rewrite !bit0_odd, odd_add. Qed. Lemma add3_bit0 : forall a b c, (a+b+c).[0] = xor3 a.[0] b.[0] c.[0]. Proof. intros. now rewrite !add_bit0. Qed. Lemma add3_bits_div2 : forall (a0 b0 c0 : bool), (a0 + b0 + c0)/2 == nextcarry a0 b0 c0. Proof. assert (H : 1+1 == 2) by now nzsimpl'. intros [|] [|] [|]; simpl; rewrite ?add_0_l, ?add_0_r, ?H; (apply div_same; order') || (apply div_small; order') || idtac. symmetry. apply div_unique with 1. order'. now nzsimpl'. Qed. Lemma add_carry_div2 : forall a b (c0:bool), (a + b + c0)/2 == a/2 + b/2 + nextcarry a.[0] b.[0] c0. Proof. intros. rewrite <- add3_bits_div2. rewrite (add_comm ((a/2)+_)). rewrite <- div_add by order'. f_equiv. rewrite <- !div2_div, mul_comm, mul_add_distr_l. rewrite (div2_odd a), <- bit0_odd at 1. fold (b2n a.[0]). rewrite (div2_odd b), <- bit0_odd at 1. fold (b2n b.[0]). rewrite add_shuffle1. rewrite <-(add_assoc _ _ c0). apply add_comm. Qed. (** The main result concerning addition: we express the bits of the sum in term of bits of [a] and [b] and of some carry stream which is also recursively determined by another equation. *) Lemma add_carry_bits : forall a b (c0:bool), exists c, a+b+c0 == lxor3 a b c /\ c/2 == lnextcarry a b c /\ c.[0] = c0. Proof. intros a b c0. (* induction over some n such that [a<2^n] and [b<2^n] *) set (n:=max a b). assert (Ha : a<2^n). apply lt_le_trans with (2^a). apply pow_gt_lin_r, lt_1_2. apply pow_le_mono_r. order'. unfold n. destruct (le_ge_cases a b); [rewrite max_r|rewrite max_l]; order'. assert (Hb : b<2^n). apply lt_le_trans with (2^b). apply pow_gt_lin_r, lt_1_2. apply pow_le_mono_r. order'. unfold n. destruct (le_ge_cases a b); [rewrite max_r|rewrite max_l]; order'. clearbody n. revert a b c0 Ha Hb. induct n. (*base*) intros a b c0. rewrite !pow_0_r, !one_succ, !lt_succ_r. intros Ha Hb. exists c0. setoid_replace a with 0 by (generalize (le_0_l a); order'). setoid_replace b with 0 by (generalize (le_0_l b); order'). rewrite !add_0_l, !lxor_0_l, !lor_0_r, !land_0_r, !lor_0_r. rewrite b2n_div2, b2n_bit0; now repeat split. (*step*) intros n IH a b c0 Ha Hb. set (c1:=nextcarry a.[0] b.[0] c0). destruct (IH (a/2) (b/2) c1) as (c & IH1 & IH2 & Hc); clear IH. apply div_lt_upper_bound; trivial. order'. now rewrite <- pow_succ_r'. apply div_lt_upper_bound; trivial. order'. now rewrite <- pow_succ_r'. exists (c0 + 2*c). repeat split. (* - add *) bitwise. destruct (zero_or_succ m) as [EQ|[m' EQ]]; rewrite EQ; clear EQ. now rewrite add_b2n_double_bit0, add3_bit0, b2n_bit0. rewrite <- !div2_bits, <- 2 lxor_spec. f_equiv. rewrite add_b2n_double_div2, <- IH1. apply add_carry_div2. (* - carry *) rewrite add_b2n_double_div2. bitwise. destruct (zero_or_succ m) as [EQ|[m' EQ]]; rewrite EQ; clear EQ. now rewrite add_b2n_double_bit0. rewrite <- !div2_bits, IH2. autorewrite with bitwise. now rewrite add_b2n_double_div2. (* - carry0 *) apply add_b2n_double_bit0. Qed. (** Particular case : the second bit of an addition *) Lemma add_bit1 : forall a b, (a+b).[1] = xor3 a.[1] b.[1] (a.[0] && b.[0]). Proof. intros a b. destruct (add_carry_bits a b false) as (c & EQ1 & EQ2 & Hc). simpl in EQ1; rewrite add_0_r in EQ1. rewrite EQ1. autorewrite with bitwise. f_equal. rewrite one_succ, <- div2_bits, EQ2. autorewrite with bitwise. rewrite Hc. simpl. apply orb_false_r. Qed. (** In an addition, there will be no carries iff there is no common bits in the numbers to add *) Lemma nocarry_equiv : forall a b c, c/2 == lnextcarry a b c -> c.[0] = false -> (c == 0 <-> land a b == 0). Proof. intros a b c H H'. split. intros EQ; rewrite EQ in *. rewrite div_0_l in H by order'. symmetry in H. now apply lor_eq_0_l in H. intros EQ. rewrite EQ, lor_0_l in H. apply bits_inj_0. induct n. trivial. intros n IH. rewrite <- div2_bits, H. autorewrite with bitwise. now rewrite IH. Qed. (** When there is no common bits, the addition is just a xor *) Lemma add_nocarry_lxor : forall a b, land a b == 0 -> a+b == lxor a b. Proof. intros a b H. destruct (add_carry_bits a b false) as (c & EQ1 & EQ2 & Hc). simpl in EQ1; rewrite add_0_r in EQ1. rewrite EQ1. apply (nocarry_equiv a b c) in H; trivial. rewrite H. now rewrite lxor_0_r. Qed. (** A null [ldiff] implies being smaller *) Lemma ldiff_le : forall a b, ldiff a b == 0 -> a <= b. Proof. cut (forall n a b, a < 2^n -> ldiff a b == 0 -> a <= b). intros H a b. apply (H a), pow_gt_lin_r; order'. induct n. intros a b Ha _. rewrite pow_0_r, one_succ, lt_succ_r in Ha. assert (Ha' : a == 0) by (generalize (le_0_l a); order'). rewrite Ha'. apply le_0_l. intros n IH a b Ha H. assert (NEQ : 2 ~= 0) by order'. rewrite (div_mod a 2 NEQ), (div_mod b 2 NEQ). apply add_le_mono. apply mul_le_mono_l. apply IH. apply div_lt_upper_bound; trivial. now rewrite <- pow_succ_r'. rewrite <- (pow_1_r 2), <- 2 shiftr_div_pow2. now rewrite <- shiftr_ldiff, H, shiftr_div_pow2, pow_1_r, div_0_l. rewrite <- 2 bit0_mod. apply bits_inj_iff in H. specialize (H 0). rewrite ldiff_spec, bits_0 in H. destruct a.[0], b.[0]; try discriminate; simpl; order'. Qed. (** Subtraction can be a ldiff when the opposite ldiff is null. *) Lemma sub_nocarry_ldiff : forall a b, ldiff b a == 0 -> a-b == ldiff a b. Proof. intros a b H. apply add_cancel_r with b. rewrite sub_add. symmetry. rewrite add_nocarry_lxor. bitwise. apply bits_inj_iff in H. specialize (H m). rewrite ldiff_spec, bits_0 in H. now destruct a.[m], b.[m]. apply land_ldiff. now apply ldiff_le. Qed. (** We can express lnot in term of subtraction *) Lemma add_lnot_diag_low : forall a n, log2 a < n -> a + lnot a n == ones n. Proof. intros a n H. assert (H' := land_lnot_diag_low a n H). rewrite add_nocarry_lxor, lxor_lor by trivial. now apply lor_lnot_diag_low. Qed. Lemma lnot_sub_low : forall a n, log2 a < n -> lnot a n == ones n - a. Proof. intros a n H. now rewrite <- (add_lnot_diag_low a n H), add_comm, add_sub. Qed. (** Adding numbers with no common bits cannot lead to a much bigger number *) Lemma add_nocarry_lt_pow2 : forall a b n, land a b == 0 -> a < 2^n -> b < 2^n -> a+b < 2^n. Proof. intros a b n H Ha Hb. rewrite add_nocarry_lxor by trivial. apply div_small_iff. order_nz. rewrite <- shiftr_div_pow2, shiftr_lxor, !shiftr_div_pow2. rewrite 2 div_small by trivial. apply lxor_0_l. Qed. Lemma add_nocarry_mod_lt_pow2 : forall a b n, land a b == 0 -> a mod 2^n + b mod 2^n < 2^n. Proof. intros a b n H. apply add_nocarry_lt_pow2. bitwise. destruct (le_gt_cases n m). now rewrite mod_pow2_bits_high. now rewrite !mod_pow2_bits_low, <- land_spec, H, bits_0. apply mod_upper_bound; order_nz. apply mod_upper_bound; order_nz. Qed. End NBitsProp.
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Import Bool NAxioms NSub NPow NDiv NParity NLog. (** Derived properties of bitwise operations *) Module Type NBitsProp (Import A : NAxiomsSig') (Import B : NSubProp A) (Import C : NParityProp A B) (Import D : NPowProp A B C) (Import E : NDivProp A B) (Import F : NLog2Prop A B C D). Include BoolEqualityFacts A. Ltac order_nz := try apply pow_nonzero; order'. Hint Rewrite div_0_l mod_0_l div_1_r mod_1_r : nz. (** Some properties of power and division *) Lemma pow_sub_r : forall a b c, a~=0 -> c<=b -> a^(b-c) == a^b / a^c. Proof. intros a b c Ha H. apply div_unique with 0. generalize (pow_nonzero a c Ha) (le_0_l (a^c)); order'. nzsimpl. now rewrite <- pow_add_r, add_comm, sub_add. Qed. Lemma pow_div_l : forall a b c, b~=0 -> a mod b == 0 -> (a/b)^c == a^c / b^c. Proof. intros a b c Hb H. apply div_unique with 0. generalize (pow_nonzero b c Hb) (le_0_l (b^c)); order'. nzsimpl. rewrite <- pow_mul_l. f_equiv. now apply div_exact. Qed. (** An injection from bits [true] and [false] to numbers 1 and 0. We declare it as a (local) coercion for shorter statements. *) Definition b2n (b:bool) := if b then 1 else 0. Local Coercion b2n : bool >-> t. Instance b2n_proper : Proper (Logic.eq ==> eq) b2n. Proof. solve_proper. Qed. Lemma exists_div2 a : exists a' (b:bool), a == 2*a' + b. Proof. elim (Even_or_Odd a); [intros (a',H)| intros (a',H)]. exists a'. exists false. now nzsimpl. exists a'. exists true. now simpl. Qed. (** We can compact [testbit_odd_0] [testbit_even_0] [testbit_even_succ] [testbit_odd_succ] in only two lemmas. *) Lemma testbit_0_r a (b:bool) : testbit (2*a+b) 0 = b. Proof. destruct b; simpl; rewrite ?add_0_r. apply testbit_odd_0. apply testbit_even_0. Qed. Lemma testbit_succ_r a (b:bool) n : testbit (2*a+b) (succ n) = testbit a n. Proof. destruct b; simpl; rewrite ?add_0_r. apply testbit_odd_succ, le_0_l. apply testbit_even_succ, le_0_l. Qed. (** Alternative caracterisations of [testbit] *) (** This concise equation could have been taken as specification for testbit in the interface, but it would have been hard to implement with little initial knowledge about div and mod *) Lemma testbit_spec' a n : a.[n] == (a / 2^n) mod 2. Proof. revert a. induct n. intros a. nzsimpl. destruct (exists_div2 a) as (a' & b & H). rewrite H at 1. rewrite testbit_0_r. apply mod_unique with a'; trivial. destruct b; order'. intros n IH a. destruct (exists_div2 a) as (a' & b & H). rewrite H at 1. rewrite testbit_succ_r, IH. f_equiv. rewrite pow_succ_r', <- div_div by order_nz. f_equiv. apply div_unique with b; trivial. destruct b; order'. Qed. (** This caracterisation that uses only basic operations and power was initially taken as specification for testbit. We describe [a] as having a low part and a high part, with the corresponding bit in the middle. This caracterisation is moderatly complex to implement, but also moderately usable... *) Lemma testbit_spec a n : exists l h, 0<=l<2^n /\ a == l + (a.[n] + 2*h)*2^n. Proof. exists (a mod 2^n). exists (a / 2^n / 2). split. split; [apply le_0_l | apply mod_upper_bound; order_nz]. rewrite add_comm, mul_comm, (add_comm a.[n]). rewrite (div_mod a (2^n)) at 1 by order_nz. do 2 f_equiv. rewrite testbit_spec'. apply div_mod. order'. Qed. Lemma testbit_true : forall a n, a.[n] = true <-> (a / 2^n) mod 2 == 1. Proof. intros a n. rewrite <- testbit_spec'; destruct a.[n]; split; simpl; now try order'. Qed. Lemma testbit_false : forall a n, a.[n] = false <-> (a / 2^n) mod 2 == 0. Proof. intros a n. rewrite <- testbit_spec'; destruct a.[n]; split; simpl; now try order'. Qed. Lemma testbit_eqb : forall a n, a.[n] = eqb ((a / 2^n) mod 2) 1. Proof. intros a n. apply eq_true_iff_eq. now rewrite testbit_true, eqb_eq. Qed. (** Results about the injection [b2n] *) Lemma b2n_inj : forall (a0 b0:bool), a0 == b0 -> a0 = b0. Proof. intros [|] [|]; simpl; trivial; order'. Qed. Lemma add_b2n_double_div2 : forall (a0:bool) a, (a0+2*a)/2 == a. Proof. intros a0 a. rewrite mul_comm, div_add by order'. now rewrite div_small, add_0_l by (destruct a0; order'). Qed. Lemma add_b2n_double_bit0 : forall (a0:bool) a, (a0+2*a).[0] = a0. Proof. intros a0 a. apply b2n_inj. rewrite testbit_spec'. nzsimpl. rewrite mul_comm, mod_add by order'. now rewrite mod_small by (destruct a0; order'). Qed. Lemma b2n_div2 : forall (a0:bool), a0/2 == 0. Proof. intros a0. rewrite <- (add_b2n_double_div2 a0 0). now nzsimpl. Qed. Lemma b2n_bit0 : forall (a0:bool), a0.[0] = a0. Proof. intros a0. rewrite <- (add_b2n_double_bit0 a0 0) at 2. now nzsimpl. Qed. (** The specification of testbit by low and high parts is complete *) Lemma testbit_unique : forall a n (a0:bool) l h, l<2^n -> a == l + (a0 + 2*h)*2^n -> a.[n] = a0. Proof. intros a n a0 l h Hl EQ. apply b2n_inj. rewrite testbit_spec' by trivial. symmetry. apply mod_unique with h. destruct a0; simpl; order'. symmetry. apply div_unique with l; trivial. now rewrite add_comm, (add_comm _ a0), mul_comm. Qed. (** All bits of number 0 are 0 *) Lemma bits_0 : forall n, 0.[n] = false. Proof. intros n. apply testbit_false. nzsimpl; order_nz. Qed. (** Various ways to refer to the lowest bit of a number *) Lemma bit0_odd : forall a, a.[0] = odd a. Proof. intros. symmetry. destruct (exists_div2 a) as (a' & b & EQ). rewrite EQ, testbit_0_r, add_comm, odd_add_mul_2. destruct b; simpl; apply odd_1 || apply odd_0. Qed. Lemma bit0_eqb : forall a, a.[0] = eqb (a mod 2) 1. Proof. intros a. rewrite testbit_eqb. now nzsimpl. Qed. Lemma bit0_mod : forall a, a.[0] == a mod 2. Proof. intros a. rewrite testbit_spec'. now nzsimpl. Qed. (** Hence testing a bit is equivalent to shifting and testing parity *) Lemma testbit_odd : forall a n, a.[n] = odd (a>>n). Proof. intros. now rewrite <- bit0_odd, shiftr_spec, add_0_l. Qed. (** [log2] gives the highest nonzero bit *) Lemma bit_log2 : forall a, a~=0 -> a.[log2 a] = true. Proof. intros a Ha. assert (Ha' : 0 < a) by (generalize (le_0_l a); order). destruct (log2_spec_alt a Ha') as (r & EQ & (_,Hr)). rewrite EQ at 1. rewrite testbit_true, add_comm. rewrite <- (mul_1_l (2^log2 a)) at 1. rewrite div_add by order_nz. rewrite div_small by trivial. rewrite add_0_l. apply mod_small. order'. Qed. Lemma bits_above_log2 : forall a n, log2 a < n -> a.[n] = false. Proof. intros a n H. rewrite testbit_false. rewrite div_small. nzsimpl; order'. apply log2_lt_cancel. rewrite log2_pow2; trivial using le_0_l. Qed. (** Hence the number of bits of [a] is [1+log2 a] (see [Pos.size_nat] and [Pos.size]). *) (** Testing bits after division or multiplication by a power of two *) Lemma div2_bits : forall a n, (a/2).[n] = a.[S n]. Proof. intros. apply eq_true_iff_eq. rewrite 2 testbit_true. rewrite pow_succ_r by apply le_0_l. now rewrite div_div by order_nz. Qed. Lemma div_pow2_bits : forall a n m, (a/2^n).[m] = a.[m+n]. Proof. intros a n. revert a. induct n. intros a m. now nzsimpl. intros n IH a m. nzsimpl; try apply le_0_l. rewrite <- div_div by order_nz. now rewrite IH, div2_bits. Qed. Lemma double_bits_succ : forall a n, (2*a).[S n] = a.[n]. Proof. intros. rewrite <- div2_bits. now rewrite mul_comm, div_mul by order'. Qed. Lemma mul_pow2_bits_add : forall a n m, (a*2^n).[m+n] = a.[m]. Proof. intros. rewrite <- div_pow2_bits. now rewrite div_mul by order_nz. Qed. Lemma mul_pow2_bits_high : forall a n m, n<=m -> (a*2^n).[m] = a.[m-n]. Proof. intros. rewrite <- (sub_add n m) at 1 by order'. now rewrite mul_pow2_bits_add. Qed. Lemma mul_pow2_bits_low : forall a n m, m<n -> (a*2^n).[m] = false. Proof. intros. apply testbit_false. rewrite <- (sub_add m n) by order'. rewrite pow_add_r, mul_assoc. rewrite div_mul by order_nz. rewrite <- (succ_pred (n-m)). rewrite pow_succ_r. now rewrite (mul_comm 2), mul_assoc, mod_mul by order'. apply lt_le_pred. apply sub_gt in H. generalize (le_0_l (n-m)); order. now apply sub_gt. Qed. (** Selecting the low part of a number can be done by a modulo *) Lemma mod_pow2_bits_high : forall a n m, n<=m -> (a mod 2^n).[m] = false. Proof. intros a n m H. destruct (eq_0_gt_0_cases (a mod 2^n)) as [EQ|LT]. now rewrite EQ, bits_0. apply bits_above_log2. apply lt_le_trans with n; trivial. apply log2_lt_pow2; trivial. apply mod_upper_bound; order_nz. Qed. Lemma mod_pow2_bits_low : forall a n m, m<n -> (a mod 2^n).[m] = a.[m]. Proof. intros a n m H. rewrite testbit_eqb. rewrite <- (mod_add _ (2^(P (n-m))*(a/2^n))) by order'. rewrite <- div_add by order_nz. rewrite (mul_comm _ 2), mul_assoc, <- pow_succ_r', succ_pred by now apply sub_gt. rewrite mul_comm, mul_assoc, <- pow_add_r, (add_comm m), sub_add by order. rewrite add_comm, <- div_mod by order_nz. symmetry. apply testbit_eqb. Qed. (** We now prove that having the same bits implies equality. For that we use a notion of equality over functional streams of bits. *) Definition eqf (f g:t -> bool) := forall n:t, f n = g n. Instance eqf_equiv : Equivalence eqf. Proof. split; congruence. Qed. Local Infix "===" := eqf (at level 70, no associativity). Instance testbit_eqf : Proper (eq==>eqf) testbit. Proof. intros a a' Ha n. now rewrite Ha. Qed. (** Only zero corresponds to the always-false stream. *) Lemma bits_inj_0 : forall a, (forall n, a.[n] = false) -> a == 0. Proof. intros a H. destruct (eq_decidable a 0) as [EQ|NEQ]; trivial. apply bit_log2 in NEQ. now rewrite H in NEQ. Qed. (** If two numbers produce the same stream of bits, they are equal. *) Lemma bits_inj : forall a b, testbit a === testbit b -> a == b. Proof. intros a. pattern a. apply strong_right_induction with 0;[solve_proper|clear a|apply le_0_l]. intros a _ IH b H. destruct (eq_0_gt_0_cases a) as [EQ|LT]. rewrite EQ in H |- *. symmetry. apply bits_inj_0. intros n. now rewrite <- H, bits_0. rewrite (div_mod a 2), (div_mod b 2) by order'. f_equiv; [ | now rewrite <- 2 bit0_mod, H]. f_equiv. apply IH; trivial using le_0_l. apply div_lt; order'. intro n. rewrite 2 div2_bits. apply H. Qed. Lemma bits_inj_iff : forall a b, testbit a === testbit b <-> a == b. Proof. split. apply bits_inj. intros EQ; now rewrite EQ. Qed. Hint Rewrite lxor_spec lor_spec land_spec ldiff_spec bits_0 : bitwise. Ltac bitwise := apply bits_inj; intros ?m; autorewrite with bitwise. (** The streams of bits that correspond to a natural numbers are exactly the ones that are always 0 after some point *) Lemma are_bits : forall (f:t->bool), Proper (eq==>Logic.eq) f -> ((exists n, f === testbit n) <-> (exists k, forall m, k<=m -> f m = false)). Proof. intros f Hf. split. intros (a,H). exists (S (log2 a)). intros m Hm. apply le_succ_l in Hm. rewrite H, bits_above_log2; trivial using lt_succ_diag_r. intros (k,Hk). revert f Hf Hk. induct k. intros f Hf H0. exists 0. intros m. rewrite bits_0, H0; trivial. apply le_0_l. intros k IH f Hf Hk. destruct (IH (fun m => f (S m))) as (n, Hn). solve_proper. intros m Hm. apply Hk. now rewrite <- succ_le_mono. exists (f 0 + 2*n). intros m. destruct (zero_or_succ m) as [Hm|(m', Hm)]; rewrite Hm. symmetry. apply add_b2n_double_bit0. rewrite Hn, <- div2_bits. rewrite mul_comm, div_add, b2n_div2, add_0_l; trivial. order'. Qed. (** Properties of shifts *) Lemma shiftr_spec' : forall a n m, (a >> n).[m] = a.[m+n]. Proof. intros. apply shiftr_spec. apply le_0_l. Qed. Lemma shiftl_spec_high' : forall a n m, n<=m -> (a << n).[m] = a.[m-n]. Proof. intros. apply shiftl_spec_high; trivial. apply le_0_l. Qed. Lemma shiftr_div_pow2 : forall a n, a >> n == a / 2^n. Proof. intros. bitwise. rewrite shiftr_spec'. symmetry. apply div_pow2_bits. Qed. Lemma shiftl_mul_pow2 : forall a n, a << n == a * 2^n. Proof. intros. bitwise. destruct (le_gt_cases n m) as [H|H]. now rewrite shiftl_spec_high', mul_pow2_bits_high. now rewrite shiftl_spec_low, mul_pow2_bits_low. Qed. Lemma shiftl_spec_alt : forall a n m, (a << n).[m+n] = a.[m]. Proof. intros. now rewrite shiftl_mul_pow2, mul_pow2_bits_add. Qed. Instance shiftr_wd : Proper (eq==>eq==>eq) shiftr. Proof. intros a a' Ha b b' Hb. now rewrite 2 shiftr_div_pow2, Ha, Hb. Qed. Instance shiftl_wd : Proper (eq==>eq==>eq) shiftl. Proof. intros a a' Ha b b' Hb. now rewrite 2 shiftl_mul_pow2, Ha, Hb. Qed. Lemma shiftl_shiftl : forall a n m, (a << n) << m == a << (n+m). Proof. intros. now rewrite !shiftl_mul_pow2, pow_add_r, mul_assoc. Qed. Lemma shiftr_shiftr : forall a n m, (a >> n) >> m == a >> (n+m). Proof. intros. now rewrite !shiftr_div_pow2, pow_add_r, div_div by order_nz. Qed. Lemma shiftr_shiftl_l : forall a n m, m<=n -> (a << n) >> m == a << (n-m). Proof. intros. rewrite shiftr_div_pow2, !shiftl_mul_pow2. rewrite <- (sub_add m n) at 1 by trivial. now rewrite pow_add_r, mul_assoc, div_mul by order_nz. Qed. Lemma shiftr_shiftl_r : forall a n m, n<=m -> (a << n) >> m == a >> (m-n). Proof. intros. rewrite !shiftr_div_pow2, shiftl_mul_pow2. rewrite <- (sub_add n m) at 1 by trivial. rewrite pow_add_r, (mul_comm (2^(m-n))). now rewrite <- div_div, div_mul by order_nz. Qed. (** shifts and constants *) Lemma shiftl_1_l : forall n, 1 << n == 2^n. Proof. intros. now rewrite shiftl_mul_pow2, mul_1_l. Qed. Lemma shiftl_0_r : forall a, a << 0 == a. Proof. intros. rewrite shiftl_mul_pow2. now nzsimpl. Qed. Lemma shiftr_0_r : forall a, a >> 0 == a. Proof. intros. rewrite shiftr_div_pow2. now nzsimpl. Qed. Lemma shiftl_0_l : forall n, 0 << n == 0. Proof. intros. rewrite shiftl_mul_pow2. now nzsimpl. Qed. Lemma shiftr_0_l : forall n, 0 >> n == 0. Proof. intros. rewrite shiftr_div_pow2. nzsimpl; order_nz. Qed. Lemma shiftl_eq_0_iff : forall a n, a << n == 0 <-> a == 0. Proof. intros a n. rewrite shiftl_mul_pow2. rewrite eq_mul_0. split. intros [H | H]; trivial. contradict H; order_nz. intros H. now left. Qed. Lemma shiftr_eq_0_iff : forall a n, a >> n == 0 <-> a==0 \/ (0<a /\ log2 a < n). Proof. intros a n. rewrite shiftr_div_pow2, div_small_iff by order_nz. destruct (eq_0_gt_0_cases a) as [EQ|LT]. rewrite EQ. split. now left. intros _. assert (H : 2~=0) by order'. generalize (pow_nonzero 2 n H) (le_0_l (2^n)); order. rewrite log2_lt_pow2; trivial. split. right; split; trivial. intros [H|[_ H]]; now order. Qed. Lemma shiftr_eq_0 : forall a n, log2 a < n -> a >> n == 0. Proof. intros a n H. rewrite shiftr_eq_0_iff. destruct (eq_0_gt_0_cases a) as [EQ|LT]. now left. right; now split. Qed. (** Properties of [div2]. *) Lemma div2_div : forall a, div2 a == a/2. Proof. intros. rewrite div2_spec, shiftr_div_pow2. now nzsimpl. Qed. Instance div2_wd : Proper (eq==>eq) div2. Proof. intros a a' Ha. now rewrite 2 div2_div, Ha. Qed. Lemma div2_odd : forall a, a == 2*(div2 a) + odd a. Proof. intros a. rewrite div2_div, <- bit0_odd, bit0_mod. apply div_mod. order'. Qed. (** Properties of [lxor] and others, directly deduced from properties of [xorb] and others. *) Instance lxor_wd : Proper (eq ==> eq ==> eq) lxor. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance land_wd : Proper (eq ==> eq ==> eq) land. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance lor_wd : Proper (eq ==> eq ==> eq) lor. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance ldiff_wd : Proper (eq ==> eq ==> eq) ldiff. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Lemma lxor_eq : forall a a', lxor a a' == 0 -> a == a'. Proof. intros a a' H. bitwise. apply xorb_eq. now rewrite <- lxor_spec, H, bits_0. Qed. Lemma lxor_nilpotent : forall a, lxor a a == 0. Proof. intros. bitwise. apply xorb_nilpotent. Qed. Lemma lxor_eq_0_iff : forall a a', lxor a a' == 0 <-> a == a'. Proof. split. apply lxor_eq. intros EQ; rewrite EQ; apply lxor_nilpotent. Qed. Lemma lxor_0_l : forall a, lxor 0 a == a. Proof. intros. bitwise. apply xorb_false_l. Qed. Lemma lxor_0_r : forall a, lxor a 0 == a. Proof. intros. bitwise. apply xorb_false_r. Qed. Lemma lxor_comm : forall a b, lxor a b == lxor b a. Proof. intros. bitwise. apply xorb_comm. Qed. Lemma lxor_assoc : forall a b c, lxor (lxor a b) c == lxor a (lxor b c). Proof. intros. bitwise. apply xorb_assoc. Qed. Lemma lor_0_l : forall a, lor 0 a == a. Proof. intros. bitwise. trivial. Qed. Lemma lor_0_r : forall a, lor a 0 == a. Proof. intros. bitwise. apply orb_false_r. Qed. Lemma lor_comm : forall a b, lor a b == lor b a. Proof. intros. bitwise. apply orb_comm. Qed. Lemma lor_assoc : forall a b c, lor a (lor b c) == lor (lor a b) c. Proof. intros. bitwise. apply orb_assoc. Qed. Lemma lor_diag : forall a, lor a a == a. Proof. intros. bitwise. apply orb_diag. Qed. Lemma lor_eq_0_l : forall a b, lor a b == 0 -> a == 0. Proof. intros a b H. bitwise. apply (orb_false_iff a.[m] b.[m]). now rewrite <- lor_spec, H, bits_0. Qed. Lemma lor_eq_0_iff : forall a b, lor a b == 0 <-> a == 0 /\ b == 0. Proof. intros a b. split. split. now apply lor_eq_0_l in H. rewrite lor_comm in H. now apply lor_eq_0_l in H. intros (EQ,EQ'). now rewrite EQ, lor_0_l. Qed. Lemma land_0_l : forall a, land 0 a == 0. Proof. intros. bitwise. trivial. Qed. Lemma land_0_r : forall a, land a 0 == 0. Proof. intros. bitwise. apply andb_false_r. Qed. Lemma land_comm : forall a b, land a b == land b a. Proof. intros. bitwise. apply andb_comm. Qed. Lemma land_assoc : forall a b c, land a (land b c) == land (land a b) c. Proof. intros. bitwise. apply andb_assoc. Qed. Lemma land_diag : forall a, land a a == a. Proof. intros. bitwise. apply andb_diag. Qed. Lemma ldiff_0_l : forall a, ldiff 0 a == 0. Proof. intros. bitwise. trivial. Qed. Lemma ldiff_0_r : forall a, ldiff a 0 == a. Proof. intros. bitwise. now rewrite andb_true_r. Qed. Lemma ldiff_diag : forall a, ldiff a a == 0. Proof. intros. bitwise. apply andb_negb_r. Qed. Lemma lor_land_distr_l : forall a b c, lor (land a b) c == land (lor a c) (lor b c). Proof. intros. bitwise. apply orb_andb_distrib_l. Qed. Lemma lor_land_distr_r : forall a b c, lor a (land b c) == land (lor a b) (lor a c). Proof. intros. bitwise. apply orb_andb_distrib_r. Qed. Lemma land_lor_distr_l : forall a b c, land (lor a b) c == lor (land a c) (land b c). Proof. intros. bitwise. apply andb_orb_distrib_l. Qed. Lemma land_lor_distr_r : forall a b c, land a (lor b c) == lor (land a b) (land a c). Proof. intros. bitwise. apply andb_orb_distrib_r. Qed. Lemma ldiff_ldiff_l : forall a b c, ldiff (ldiff a b) c == ldiff a (lor b c). Proof. intros. bitwise. now rewrite negb_orb, andb_assoc. Qed. Lemma lor_ldiff_and : forall a b, lor (ldiff a b) (land a b) == a. Proof. intros. bitwise. now rewrite <- andb_orb_distrib_r, orb_comm, orb_negb_r, andb_true_r. Qed. Lemma land_ldiff : forall a b, land (ldiff a b) b == 0. Proof. intros. bitwise. now rewrite <-andb_assoc, (andb_comm (negb _)), andb_negb_r, andb_false_r. Qed. (** Properties of [setbit] and [clearbit] *) Definition setbit a n := lor a (1<<n). Definition clearbit a n := ldiff a (1<<n). Lemma setbit_spec' : forall a n, setbit a n == lor a (2^n). Proof. intros. unfold setbit. now rewrite shiftl_1_l. Qed. Lemma clearbit_spec' : forall a n, clearbit a n == ldiff a (2^n). Proof. intros. unfold clearbit. now rewrite shiftl_1_l. Qed. Instance setbit_wd : Proper (eq==>eq==>eq) setbit. Proof. unfold setbit. solve_proper. Qed. Instance clearbit_wd : Proper (eq==>eq==>eq) clearbit. Proof. unfold clearbit. solve_proper. Qed. Lemma pow2_bits_true : forall n, (2^n).[n] = true. Proof. intros. rewrite <- (mul_1_l (2^n)). rewrite <- (add_0_l n) at 2. now rewrite mul_pow2_bits_add, bit0_odd, odd_1. Qed. Lemma pow2_bits_false : forall n m, n~=m -> (2^n).[m] = false. Proof. intros. rewrite <- (mul_1_l (2^n)). destruct (le_gt_cases n m). rewrite mul_pow2_bits_high; trivial. rewrite <- (succ_pred (m-n)) by (apply sub_gt; order). now rewrite <- div2_bits, div_small, bits_0 by order'. rewrite mul_pow2_bits_low; trivial. Qed. Lemma pow2_bits_eqb : forall n m, (2^n).[m] = eqb n m. Proof. intros. apply eq_true_iff_eq. rewrite eqb_eq. split. destruct (eq_decidable n m) as [H|H]. trivial. now rewrite (pow2_bits_false _ _ H). intros EQ. rewrite EQ. apply pow2_bits_true. Qed. Lemma setbit_eqb : forall a n m, (setbit a n).[m] = eqb n m || a.[m]. Proof. intros. now rewrite setbit_spec', lor_spec, pow2_bits_eqb, orb_comm. Qed. Lemma setbit_iff : forall a n m, (setbit a n).[m] = true <-> n==m \/ a.[m] = true. Proof. intros. now rewrite setbit_eqb, orb_true_iff, eqb_eq. Qed. Lemma setbit_eq : forall a n, (setbit a n).[n] = true. Proof. intros. apply setbit_iff. now left. Qed. Lemma setbit_neq : forall a n m, n~=m -> (setbit a n).[m] = a.[m]. Proof. intros a n m H. rewrite setbit_eqb. rewrite <- eqb_eq in H. apply not_true_is_false in H. now rewrite H. Qed. Lemma clearbit_eqb : forall a n m, (clearbit a n).[m] = a.[m] && negb (eqb n m). Proof. intros. now rewrite clearbit_spec', ldiff_spec, pow2_bits_eqb. Qed. Lemma clearbit_iff : forall a n m, (clearbit a n).[m] = true <-> a.[m] = true /\ n~=m. Proof. intros. rewrite clearbit_eqb, andb_true_iff, <- eqb_eq. now rewrite negb_true_iff, not_true_iff_false. Qed. Lemma clearbit_eq : forall a n, (clearbit a n).[n] = false. Proof. intros. rewrite clearbit_eqb, (proj2 (eqb_eq _ _) (eq_refl n)). apply andb_false_r. Qed. Lemma clearbit_neq : forall a n m, n~=m -> (clearbit a n).[m] = a.[m]. Proof. intros a n m H. rewrite clearbit_eqb. rewrite <- eqb_eq in H. apply not_true_is_false in H. rewrite H. apply andb_true_r. Qed. (** Shifts of bitwise operations *) Lemma shiftl_lxor : forall a b n, (lxor a b) << n == lxor (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', lxor_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_lxor : forall a b n, (lxor a b) >> n == lxor (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', lxor_spec. Qed. Lemma shiftl_land : forall a b n, (land a b) << n == land (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', land_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_land : forall a b n, (land a b) >> n == land (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', land_spec. Qed. Lemma shiftl_lor : forall a b n, (lor a b) << n == lor (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', lor_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_lor : forall a b n, (lor a b) >> n == lor (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', lor_spec. Qed. Lemma shiftl_ldiff : forall a b n, (ldiff a b) << n == ldiff (a << n) (b << n). Proof. intros. bitwise. destruct (le_gt_cases n m). now rewrite !shiftl_spec_high', ldiff_spec. now rewrite !shiftl_spec_low. Qed. Lemma shiftr_ldiff : forall a b n, (ldiff a b) >> n == ldiff (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec', ldiff_spec. Qed. (** We cannot have a function complementing all bits of a number, otherwise it would have an infinity of bit 1. Nonetheless, we can design a bounded complement *) Definition ones n := P (1 << n). Definition lnot a n := lxor a (ones n). Instance ones_wd : Proper (eq==>eq) ones. Proof. unfold ones. solve_proper. Qed. Instance lnot_wd : Proper (eq==>eq==>eq) lnot. Proof. unfold lnot. solve_proper. Qed. Lemma ones_equiv : forall n, ones n == P (2^n). Proof. intros; unfold ones; now rewrite shiftl_1_l. Qed. Lemma ones_add : forall n m, ones (m+n) == 2^m * ones n + ones m. Proof. intros n m. rewrite !ones_equiv. rewrite <- !sub_1_r, mul_sub_distr_l, mul_1_r, <- pow_add_r. rewrite add_sub_assoc, sub_add. reflexivity. apply pow_le_mono_r. order'. rewrite <- (add_0_r m) at 1. apply add_le_mono_l, le_0_l. rewrite <- (pow_0_r 2). apply pow_le_mono_r. order'. apply le_0_l. Qed. Lemma ones_div_pow2 : forall n m, m<=n -> ones n / 2^m == ones (n-m). Proof. intros n m H. symmetry. apply div_unique with (ones m). rewrite ones_equiv. apply le_succ_l. rewrite succ_pred; order_nz. rewrite <- (sub_add m n H) at 1. rewrite (add_comm _ m). apply ones_add. Qed. Lemma ones_mod_pow2 : forall n m, m<=n -> (ones n) mod (2^m) == ones m. Proof. intros n m H. symmetry. apply mod_unique with (ones (n-m)). rewrite ones_equiv. apply le_succ_l. rewrite succ_pred; order_nz. rewrite <- (sub_add m n H) at 1. rewrite (add_comm _ m). apply ones_add. Qed. Lemma ones_spec_low : forall n m, m<n -> (ones n).[m] = true. Proof. intros. apply testbit_true. rewrite ones_div_pow2 by order. rewrite <- (pow_1_r 2). rewrite ones_mod_pow2. rewrite ones_equiv. now nzsimpl'. apply le_add_le_sub_r. nzsimpl. now apply le_succ_l. Qed. Lemma ones_spec_high : forall n m, n<=m -> (ones n).[m] = false. Proof. intros. destruct (eq_0_gt_0_cases n) as [EQ|LT]; rewrite ones_equiv. now rewrite EQ, pow_0_r, one_succ, pred_succ, bits_0. apply bits_above_log2. rewrite log2_pred_pow2; trivial. rewrite <-le_succ_l, succ_pred; order. Qed. Lemma ones_spec_iff : forall n m, (ones n).[m] = true <-> m<n. Proof. intros. split. intros H. apply lt_nge. intro H'. apply ones_spec_high in H'. rewrite H in H'; discriminate. apply ones_spec_low. Qed. Lemma lnot_spec_low : forall a n m, m<n -> (lnot a n).[m] = negb a.[m]. Proof. intros. unfold lnot. now rewrite lxor_spec, ones_spec_low. Qed. Lemma lnot_spec_high : forall a n m, n<=m -> (lnot a n).[m] = a.[m]. Proof. intros. unfold lnot. now rewrite lxor_spec, ones_spec_high, xorb_false_r. Qed. Lemma lnot_involutive : forall a n, lnot (lnot a n) n == a. Proof. intros a n. bitwise. destruct (le_gt_cases n m). now rewrite 2 lnot_spec_high. now rewrite 2 lnot_spec_low, negb_involutive. Qed. Lemma lnot_0_l : forall n, lnot 0 n == ones n. Proof. intros. unfold lnot. apply lxor_0_l. Qed. Lemma lnot_ones : forall n, lnot (ones n) n == 0. Proof. intros. unfold lnot. apply lxor_nilpotent. Qed. (** Bounded complement and other operations *) Lemma lor_ones_low : forall a n, log2 a < n -> lor a (ones n) == ones n. Proof. intros a n H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. now rewrite ones_spec_low, orb_true_r. Qed. Lemma land_ones : forall a n, land a (ones n) == a mod 2^n. Proof. intros a n. bitwise. destruct (le_gt_cases n m). now rewrite ones_spec_high, mod_pow2_bits_high, andb_false_r. now rewrite ones_spec_low, mod_pow2_bits_low, andb_true_r. Qed. Lemma land_ones_low : forall a n, log2 a < n -> land a (ones n) == a. Proof. intros; rewrite land_ones. apply mod_small. apply log2_lt_cancel. rewrite log2_pow2; trivial using le_0_l. Qed. Lemma ldiff_ones_r : forall a n, ldiff a (ones n) == (a >> n) << n. Proof. intros a n. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, shiftl_spec_high', shiftr_spec'; trivial. rewrite sub_add; trivial. apply andb_true_r. now rewrite ones_spec_low, shiftl_spec_low, andb_false_r. Qed. Lemma ldiff_ones_r_low : forall a n, log2 a < n -> ldiff a (ones n) == 0. Proof. intros a n H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. now rewrite ones_spec_low, andb_false_r. Qed. Lemma ldiff_ones_l_low : forall a n, log2 a < n -> ldiff (ones n) a == lnot a n. Proof. intros a n H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, lnot_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. now rewrite ones_spec_low, lnot_spec_low. Qed. Lemma lor_lnot_diag : forall a n, lor a (lnot a n) == lor a (ones n). Proof. intros a n. bitwise. destruct (le_gt_cases n m). rewrite lnot_spec_high, ones_spec_high; trivial. now destruct a.[m]. rewrite lnot_spec_low, ones_spec_low; trivial. now destruct a.[m]. Qed. Lemma lor_lnot_diag_low : forall a n, log2 a < n -> lor a (lnot a n) == ones n. Proof. intros a n H. now rewrite lor_lnot_diag, lor_ones_low. Qed. Lemma land_lnot_diag : forall a n, land a (lnot a n) == ldiff a (ones n). Proof. intros a n. bitwise. destruct (le_gt_cases n m). rewrite lnot_spec_high, ones_spec_high; trivial. now destruct a.[m]. rewrite lnot_spec_low, ones_spec_low; trivial. now destruct a.[m]. Qed. Lemma land_lnot_diag_low : forall a n, log2 a < n -> land a (lnot a n) == 0. Proof. intros. now rewrite land_lnot_diag, ldiff_ones_r_low. Qed. Lemma lnot_lor_low : forall a b n, log2 a < n -> log2 b < n -> lnot (lor a b) n == land (lnot a n) (lnot b n). Proof. intros a b n Ha Hb. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, lor_spec, !bits_above_log2; trivial. now apply lt_le_trans with n. now apply lt_le_trans with n. now rewrite !lnot_spec_low, lor_spec, negb_orb. Qed. Lemma lnot_land_low : forall a b n, log2 a < n -> log2 b < n -> lnot (land a b) n == lor (lnot a n) (lnot b n). Proof. intros a b n Ha Hb. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, land_spec, !bits_above_log2; trivial. now apply lt_le_trans with n. now apply lt_le_trans with n. now rewrite !lnot_spec_low, land_spec, negb_andb. Qed. Lemma ldiff_land_low : forall a b n, log2 a < n -> ldiff a b == land a (lnot b n). Proof. intros a b n Ha. bitwise. destruct (le_gt_cases n m). rewrite (bits_above_log2 a m). trivial. now apply lt_le_trans with n. rewrite !lnot_spec_low; trivial. Qed. Lemma lnot_ldiff_low : forall a b n, log2 a < n -> log2 b < n -> lnot (ldiff a b) n == lor (lnot a n) b. Proof. intros a b n Ha Hb. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, ldiff_spec, !bits_above_log2; trivial. now apply lt_le_trans with n. now apply lt_le_trans with n. now rewrite !lnot_spec_low, ldiff_spec, negb_andb, negb_involutive. Qed. Lemma lxor_lnot_lnot : forall a b n, lxor (lnot a n) (lnot b n) == lxor a b. Proof. intros a b n. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high; trivial. rewrite !lnot_spec_low, xorb_negb_negb; trivial. Qed. Lemma lnot_lxor_l : forall a b n, lnot (lxor a b) n == lxor (lnot a n) b. Proof. intros a b n. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, lxor_spec; trivial. rewrite !lnot_spec_low, lxor_spec, negb_xorb_l; trivial. Qed. Lemma lnot_lxor_r : forall a b n, lnot (lxor a b) n == lxor a (lnot b n). Proof. intros a b n. bitwise. destruct (le_gt_cases n m). rewrite !lnot_spec_high, lxor_spec; trivial. rewrite !lnot_spec_low, lxor_spec, negb_xorb_r; trivial. Qed. Lemma lxor_lor : forall a b, land a b == 0 -> lxor a b == lor a b. Proof. intros a b H. bitwise. assert (a.[m] && b.[m] = false) by now rewrite <- land_spec, H, bits_0. now destruct a.[m], b.[m]. Qed. (** Bitwise operations and log2 *) Lemma log2_bits_unique : forall a n, a.[n] = true -> (forall m, n<m -> a.[m] = false) -> log2 a == n. Proof. intros a n H H'. destruct (eq_0_gt_0_cases a) as [Ha|Ha]. now rewrite Ha, bits_0 in H. apply le_antisymm; apply le_ngt; intros LT. specialize (H' _ LT). now rewrite bit_log2 in H' by order. now rewrite bits_above_log2 in H by order. Qed. Lemma log2_shiftr : forall a n, log2 (a >> n) == log2 a - n. Proof. intros a n. destruct (eq_0_gt_0_cases a) as [Ha|Ha]. now rewrite Ha, shiftr_0_l, log2_nonpos, sub_0_l by order. destruct (lt_ge_cases (log2 a) n). rewrite shiftr_eq_0, log2_nonpos by order. symmetry. rewrite sub_0_le; order. apply log2_bits_unique. now rewrite shiftr_spec', sub_add, bit_log2 by order. intros m Hm. rewrite shiftr_spec'; trivial. apply bits_above_log2; try order. now apply lt_sub_lt_add_r. Qed. Lemma log2_shiftl : forall a n, a~=0 -> log2 (a << n) == log2 a + n. Proof. intros a n Ha. rewrite shiftl_mul_pow2, add_comm by trivial. apply log2_mul_pow2. generalize (le_0_l a); order. apply le_0_l. Qed. Lemma log2_lor : forall a b, log2 (lor a b) == max (log2 a) (log2 b). Proof. assert (AUX : forall a b, a<=b -> log2 (lor a b) == log2 b). intros a b H. destruct (eq_0_gt_0_cases a) as [Ha|Ha]. now rewrite Ha, lor_0_l. apply log2_bits_unique. now rewrite lor_spec, bit_log2, orb_true_r by order. intros m Hm. assert (H' := log2_le_mono _ _ H). now rewrite lor_spec, 2 bits_above_log2 by order. (* main *) intros a b. destruct (le_ge_cases a b) as [H|H]. rewrite max_r by now apply log2_le_mono. now apply AUX. rewrite max_l by now apply log2_le_mono. rewrite lor_comm. now apply AUX. Qed. Lemma log2_land : forall a b, log2 (land a b) <= min (log2 a) (log2 b). Proof. assert (AUX : forall a b, a<=b -> log2 (land a b) <= log2 a). intros a b H. apply le_ngt. intros H'. destruct (eq_decidable (land a b) 0) as [EQ|NEQ]. rewrite EQ in H'. apply log2_lt_cancel in H'. generalize (le_0_l a); order. generalize (bit_log2 (land a b) NEQ). now rewrite land_spec, bits_above_log2. (* main *) intros a b. destruct (le_ge_cases a b) as [H|H]. rewrite min_l by now apply log2_le_mono. now apply AUX. rewrite min_r by now apply log2_le_mono. rewrite land_comm. now apply AUX. Qed. Lemma log2_lxor : forall a b, log2 (lxor a b) <= max (log2 a) (log2 b). Proof. assert (AUX : forall a b, a<=b -> log2 (lxor a b) <= log2 b). intros a b H. apply le_ngt. intros H'. destruct (eq_decidable (lxor a b) 0) as [EQ|NEQ]. rewrite EQ in H'. apply log2_lt_cancel in H'. generalize (le_0_l a); order. generalize (bit_log2 (lxor a b) NEQ). rewrite lxor_spec, 2 bits_above_log2; try order. discriminate. apply le_lt_trans with (log2 b); trivial. now apply log2_le_mono. (* main *) intros a b. destruct (le_ge_cases a b) as [H|H]. rewrite max_r by now apply log2_le_mono. now apply AUX. rewrite max_l by now apply log2_le_mono. rewrite lxor_comm. now apply AUX. Qed. (** Bitwise operations and arithmetical operations *) Local Notation xor3 a b c := (xorb (xorb a b) c). Local Notation lxor3 a b c := (lxor (lxor a b) c). Local Notation nextcarry a b c := ((a&&b) || (c && (a||b))). Local Notation lnextcarry a b c := (lor (land a b) (land c (lor a b))). Lemma add_bit0 : forall a b, (a+b).[0] = xorb a.[0] b.[0]. Proof. intros. now rewrite !bit0_odd, odd_add. Qed. Lemma add3_bit0 : forall a b c, (a+b+c).[0] = xor3 a.[0] b.[0] c.[0]. Proof. intros. now rewrite !add_bit0. Qed. Lemma add3_bits_div2 : forall (a0 b0 c0 : bool), (a0 + b0 + c0)/2 == nextcarry a0 b0 c0. Proof. assert (H : 1+1 == 2) by now nzsimpl'. intros [|] [|] [|]; simpl; rewrite ?add_0_l, ?add_0_r, ?H; (apply div_same; order') || (apply div_small; order') || idtac. symmetry. apply div_unique with 1. order'. now nzsimpl'. Qed. Lemma add_carry_div2 : forall a b (c0:bool), (a + b + c0)/2 == a/2 + b/2 + nextcarry a.[0] b.[0] c0. Proof. intros. rewrite <- add3_bits_div2. rewrite (add_comm ((a/2)+_)). rewrite <- div_add by order'. f_equiv. rewrite <- !div2_div, mul_comm, mul_add_distr_l. rewrite (div2_odd a), <- bit0_odd at 1. fold (b2n a.[0]). rewrite (div2_odd b), <- bit0_odd at 1. fold (b2n b.[0]). rewrite add_shuffle1. rewrite <-(add_assoc _ _ c0). apply add_comm. Qed. (** The main result concerning addition: we express the bits of the sum in term of bits of [a] and [b] and of some carry stream which is also recursively determined by another equation. *) Lemma add_carry_bits : forall a b (c0:bool), exists c, a+b+c0 == lxor3 a b c /\ c/2 == lnextcarry a b c /\ c.[0] = c0. Proof. intros a b c0. (* induction over some n such that [a<2^n] and [b<2^n] *) set (n:=max a b). assert (Ha : a<2^n). apply lt_le_trans with (2^a). apply pow_gt_lin_r, lt_1_2. apply pow_le_mono_r. order'. unfold n. destruct (le_ge_cases a b); [rewrite max_r|rewrite max_l]; order'. assert (Hb : b<2^n). apply lt_le_trans with (2^b). apply pow_gt_lin_r, lt_1_2. apply pow_le_mono_r. order'. unfold n. destruct (le_ge_cases a b); [rewrite max_r|rewrite max_l]; order'. clearbody n. revert a b c0 Ha Hb. induct n. (*base*) intros a b c0. rewrite !pow_0_r, !one_succ, !lt_succ_r. intros Ha Hb. exists c0. setoid_replace a with 0 by (generalize (le_0_l a); order'). setoid_replace b with 0 by (generalize (le_0_l b); order'). rewrite !add_0_l, !lxor_0_l, !lor_0_r, !land_0_r, !lor_0_r. rewrite b2n_div2, b2n_bit0; now repeat split. (*step*) intros n IH a b c0 Ha Hb. set (c1:=nextcarry a.[0] b.[0] c0). destruct (IH (a/2) (b/2) c1) as (c & IH1 & IH2 & Hc); clear IH. apply div_lt_upper_bound; trivial. order'. now rewrite <- pow_succ_r'. apply div_lt_upper_bound; trivial. order'. now rewrite <- pow_succ_r'. exists (c0 + 2*c). repeat split. (* - add *) bitwise. destruct (zero_or_succ m) as [EQ|[m' EQ]]; rewrite EQ; clear EQ. now rewrite add_b2n_double_bit0, add3_bit0, b2n_bit0. rewrite <- !div2_bits, <- 2 lxor_spec. f_equiv. rewrite add_b2n_double_div2, <- IH1. apply add_carry_div2. (* - carry *) rewrite add_b2n_double_div2. bitwise. destruct (zero_or_succ m) as [EQ|[m' EQ]]; rewrite EQ; clear EQ. now rewrite add_b2n_double_bit0. rewrite <- !div2_bits, IH2. autorewrite with bitwise. now rewrite add_b2n_double_div2. (* - carry0 *) apply add_b2n_double_bit0. Qed. (** Particular case : the second bit of an addition *) Lemma add_bit1 : forall a b, (a+b).[1] = xor3 a.[1] b.[1] (a.[0] && b.[0]). Proof. intros a b. destruct (add_carry_bits a b false) as (c & EQ1 & EQ2 & Hc). simpl in EQ1; rewrite add_0_r in EQ1. rewrite EQ1. autorewrite with bitwise. f_equal. rewrite one_succ, <- div2_bits, EQ2. autorewrite with bitwise. rewrite Hc. simpl. apply orb_false_r. Qed. (** In an addition, there will be no carries iff there is no common bits in the numbers to add *) Lemma nocarry_equiv : forall a b c, c/2 == lnextcarry a b c -> c.[0] = false -> (c == 0 <-> land a b == 0). Proof. intros a b c H H'. split. intros EQ; rewrite EQ in *. rewrite div_0_l in H by order'. symmetry in H. now apply lor_eq_0_l in H. intros EQ. rewrite EQ, lor_0_l in H. apply bits_inj_0. induct n. trivial. intros n IH. rewrite <- div2_bits, H. autorewrite with bitwise. now rewrite IH. Qed. (** When there is no common bits, the addition is just a xor *) Lemma add_nocarry_lxor : forall a b, land a b == 0 -> a+b == lxor a b. Proof. intros a b H. destruct (add_carry_bits a b false) as (c & EQ1 & EQ2 & Hc). simpl in EQ1; rewrite add_0_r in EQ1. rewrite EQ1. apply (nocarry_equiv a b c) in H; trivial. rewrite H. now rewrite lxor_0_r. Qed. (** A null [ldiff] implies being smaller *) Lemma ldiff_le : forall a b, ldiff a b == 0 -> a <= b. Proof. cut (forall n a b, a < 2^n -> ldiff a b == 0 -> a <= b). intros H a b. apply (H a), pow_gt_lin_r; order'. induct n. intros a b Ha _. rewrite pow_0_r, one_succ, lt_succ_r in Ha. assert (Ha' : a == 0) by (generalize (le_0_l a); order'). rewrite Ha'. apply le_0_l. intros n IH a b Ha H. assert (NEQ : 2 ~= 0) by order'. rewrite (div_mod a 2 NEQ), (div_mod b 2 NEQ). apply add_le_mono. apply mul_le_mono_l. apply IH. apply div_lt_upper_bound; trivial. now rewrite <- pow_succ_r'. rewrite <- (pow_1_r 2), <- 2 shiftr_div_pow2. now rewrite <- shiftr_ldiff, H, shiftr_div_pow2, pow_1_r, div_0_l. rewrite <- 2 bit0_mod. apply bits_inj_iff in H. specialize (H 0). rewrite ldiff_spec, bits_0 in H. destruct a.[0], b.[0]; try discriminate; simpl; order'. Qed. (** Subtraction can be a ldiff when the opposite ldiff is null. *) Lemma sub_nocarry_ldiff : forall a b, ldiff b a == 0 -> a-b == ldiff a b. Proof. intros a b H. apply add_cancel_r with b. rewrite sub_add. symmetry. rewrite add_nocarry_lxor. bitwise. apply bits_inj_iff in H. specialize (H m). rewrite ldiff_spec, bits_0 in H. now destruct a.[m], b.[m]. apply land_ldiff. now apply ldiff_le. Qed. (** We can express lnot in term of subtraction *) Lemma add_lnot_diag_low : forall a n, log2 a < n -> a + lnot a n == ones n. Proof. intros a n H. assert (H' := land_lnot_diag_low a n H). rewrite add_nocarry_lxor, lxor_lor by trivial. now apply lor_lnot_diag_low. Qed. Lemma lnot_sub_low : forall a n, log2 a < n -> lnot a n == ones n - a. Proof. intros a n H. now rewrite <- (add_lnot_diag_low a n H), add_comm, add_sub. Qed. (** Adding numbers with no common bits cannot lead to a much bigger number *) Lemma add_nocarry_lt_pow2 : forall a b n, land a b == 0 -> a < 2^n -> b < 2^n -> a+b < 2^n. Proof. intros a b n H Ha Hb. rewrite add_nocarry_lxor by trivial. apply div_small_iff. order_nz. rewrite <- shiftr_div_pow2, shiftr_lxor, !shiftr_div_pow2. rewrite 2 div_small by trivial. apply lxor_0_l. Qed. Lemma add_nocarry_mod_lt_pow2 : forall a b n, land a b == 0 -> a mod 2^n + b mod 2^n < 2^n. Proof. intros a b n H. apply add_nocarry_lt_pow2. bitwise. destruct (le_gt_cases n m). now rewrite mod_pow2_bits_high. now rewrite !mod_pow2_bits_low, <- land_spec, H, bits_0. apply mod_upper_bound; order_nz. apply mod_upper_bound; order_nz. Qed. End NBitsProp.
////////////////////////////////////////////////////////////////////////////// // // Xilinx, Inc. 2008 www.xilinx.com // ////////////////////////////////////////////////////////////////////////////// // // File name : serdes_n_to_1.v // // Description : 1-bit generic n:1 transmitter module // Takes in n bits of data and serialises this to 1 bit // data is transmitted LSB first // 0, 1, 2 ...... // // Date - revision : August 1st 2008 - v 1.0 // // Author : NJS // // Disclaimer: LIMITED WARRANTY AND DISCLAMER. These designs are // provided to you "as is". Xilinx and its licensors make and you // receive no warranties or conditions, express, implied, // statutory or otherwise, and Xilinx specifically disclaims any // implied warranties of merchantability, non-infringement,or // fitness for a particular purpose. Xilinx does not warrant that // the functions contained in these designs will meet your // requirements, or that the operation of these designs will be // uninterrupted or error free, or that defects in the Designs // will be corrected. Furthermore, Xilinx does not warrantor // make any representations regarding use or the results of the // use of the designs in terms of correctness, accuracy, // reliability, or otherwise. // // LIMITATION OF LIABILITY. In no event will Xilinx or its // licensors be liable for any loss of data, lost profits,cost // or procurement of substitute goods or services, or for any // special, incidental, consequential, or indirect damages // arising from the use or operation of the designs or // accompanying documentation, however caused and on any theory // of liability. This limitation will apply even if Xilinx // has been advised of the possibility of such damage. This // limitation shall apply not-withstanding the failure of the // essential purpose of any limited remedies herein. // // Copyright © 2008 Xilinx, Inc. // All rights reserved // ////////////////////////////////////////////////////////////////////////////// // `timescale 1ps/1ps module serdes_n_to_1 (ioclk, serdesstrobe, reset, gclk, datain, iob_data_out) ; parameter integer SF = 8 ; // Parameter to set the serdes factor 1..8 input ioclk ; // IO Clock network input serdesstrobe ; // Parallel data capture strobe input reset ; // Reset input gclk ; // Global clock input [SF-1 : 0] datain ; // Data for output output iob_data_out ; // output data wire cascade_di ; // wire cascade_do ; // wire cascade_ti ; // wire cascade_to ; // wire [8:0] mdatain ; // genvar i ; // Pad out the input data bus with 0's to 8 bits to avoid errors generate for (i = 0 ; i <= (SF - 1) ; i = i + 1) begin : loop0 assign mdatain[i] = datain[i] ; end endgenerate generate for (i = (SF) ; i <= 8 ; i = i + 1) begin : loop1 assign mdatain[i] = 1'b0 ; end endgenerate OSERDES2 #( .DATA_WIDTH (SF), // SERDES word width. This should match the setting is BUFPLL .DATA_RATE_OQ ("SDR"), // <SDR>, DDR .DATA_RATE_OT ("SDR"), // <SDR>, DDR .SERDES_MODE ("MASTER"), // <DEFAULT>, MASTER, SLAVE .OUTPUT_MODE ("DIFFERENTIAL")) oserdes_m ( .OQ (iob_data_out), .OCE (1'b1), .CLK0 (ioclk), .CLK1 (1'b0), .IOCE (serdesstrobe), .RST (reset), .CLKDIV (gclk), .D4 (mdatain[7]), .D3 (mdatain[6]), .D2 (mdatain[5]), .D1 (mdatain[4]), .TQ (), .T1 (1'b0), .T2 (1'b0), .T3 (1'b0), .T4 (1'b0), .TRAIN (1'b0), .TCE (1'b1), .SHIFTIN1 (1'b1), // Dummy input in Master .SHIFTIN2 (1'b1), // Dummy input in Master .SHIFTIN3 (cascade_do), // Cascade output D data from slave .SHIFTIN4 (cascade_to), // Cascade output T data from slave .SHIFTOUT1 (cascade_di), // Cascade input D data to slave .SHIFTOUT2 (cascade_ti), // Cascade input T data to slave .SHIFTOUT3 (), // Dummy output in Master .SHIFTOUT4 ()) ; // Dummy output in Master OSERDES2 #( .DATA_WIDTH (SF), // SERDES word width. This should match the setting is BUFPLL .DATA_RATE_OQ ("SDR"), // <SDR>, DDR .DATA_RATE_OT ("SDR"), // <SDR>, DDR .SERDES_MODE ("SLAVE"), // <DEFAULT>, MASTER, SLAVE .OUTPUT_MODE ("DIFFERENTIAL")) oserdes_s ( .OQ (), .OCE (1'b1), .CLK0 (ioclk), .CLK1 (1'b0), .IOCE (serdesstrobe), .RST (reset), .CLKDIV (gclk), .D4 (mdatain[3]), .D3 (mdatain[2]), .D2 (mdatain[1]), .D1 (mdatain[0]), .TQ (), .T1 (1'b0), .T2 (1'b0), .T3 (1'b0), .T4 (1'b0), .TRAIN (1'b0), .TCE (1'b1), .SHIFTIN1 (cascade_di), // Cascade input D from Master .SHIFTIN2 (cascade_ti), // Cascade input T from Master .SHIFTIN3 (1'b1), // Dummy input in Slave .SHIFTIN4 (1'b1), // Dummy input in Slave .SHIFTOUT1 (), // Dummy output in Slave .SHIFTOUT2 (), // Dummy output in Slave .SHIFTOUT3 (cascade_do), // Cascade output D data to Master .SHIFTOUT4 (cascade_to)) ; // Cascade output T data to Master endmodule
////////////////////////////////////////////////////////////////////////////// // // Xilinx, Inc. 2008 www.xilinx.com // ////////////////////////////////////////////////////////////////////////////// // // File name : serdes_n_to_1.v // // Description : 1-bit generic n:1 transmitter module // Takes in n bits of data and serialises this to 1 bit // data is transmitted LSB first // 0, 1, 2 ...... // // Date - revision : August 1st 2008 - v 1.0 // // Author : NJS // // Disclaimer: LIMITED WARRANTY AND DISCLAMER. These designs are // provided to you "as is". Xilinx and its licensors make and you // receive no warranties or conditions, express, implied, // statutory or otherwise, and Xilinx specifically disclaims any // implied warranties of merchantability, non-infringement,or // fitness for a particular purpose. Xilinx does not warrant that // the functions contained in these designs will meet your // requirements, or that the operation of these designs will be // uninterrupted or error free, or that defects in the Designs // will be corrected. Furthermore, Xilinx does not warrantor // make any representations regarding use or the results of the // use of the designs in terms of correctness, accuracy, // reliability, or otherwise. // // LIMITATION OF LIABILITY. In no event will Xilinx or its // licensors be liable for any loss of data, lost profits,cost // or procurement of substitute goods or services, or for any // special, incidental, consequential, or indirect damages // arising from the use or operation of the designs or // accompanying documentation, however caused and on any theory // of liability. This limitation will apply even if Xilinx // has been advised of the possibility of such damage. This // limitation shall apply not-withstanding the failure of the // essential purpose of any limited remedies herein. // // Copyright © 2008 Xilinx, Inc. // All rights reserved // ////////////////////////////////////////////////////////////////////////////// // `timescale 1ps/1ps module serdes_n_to_1 (ioclk, serdesstrobe, reset, gclk, datain, iob_data_out) ; parameter integer SF = 8 ; // Parameter to set the serdes factor 1..8 input ioclk ; // IO Clock network input serdesstrobe ; // Parallel data capture strobe input reset ; // Reset input gclk ; // Global clock input [SF-1 : 0] datain ; // Data for output output iob_data_out ; // output data wire cascade_di ; // wire cascade_do ; // wire cascade_ti ; // wire cascade_to ; // wire [8:0] mdatain ; // genvar i ; // Pad out the input data bus with 0's to 8 bits to avoid errors generate for (i = 0 ; i <= (SF - 1) ; i = i + 1) begin : loop0 assign mdatain[i] = datain[i] ; end endgenerate generate for (i = (SF) ; i <= 8 ; i = i + 1) begin : loop1 assign mdatain[i] = 1'b0 ; end endgenerate OSERDES2 #( .DATA_WIDTH (SF), // SERDES word width. This should match the setting is BUFPLL .DATA_RATE_OQ ("SDR"), // <SDR>, DDR .DATA_RATE_OT ("SDR"), // <SDR>, DDR .SERDES_MODE ("MASTER"), // <DEFAULT>, MASTER, SLAVE .OUTPUT_MODE ("DIFFERENTIAL")) oserdes_m ( .OQ (iob_data_out), .OCE (1'b1), .CLK0 (ioclk), .CLK1 (1'b0), .IOCE (serdesstrobe), .RST (reset), .CLKDIV (gclk), .D4 (mdatain[7]), .D3 (mdatain[6]), .D2 (mdatain[5]), .D1 (mdatain[4]), .TQ (), .T1 (1'b0), .T2 (1'b0), .T3 (1'b0), .T4 (1'b0), .TRAIN (1'b0), .TCE (1'b1), .SHIFTIN1 (1'b1), // Dummy input in Master .SHIFTIN2 (1'b1), // Dummy input in Master .SHIFTIN3 (cascade_do), // Cascade output D data from slave .SHIFTIN4 (cascade_to), // Cascade output T data from slave .SHIFTOUT1 (cascade_di), // Cascade input D data to slave .SHIFTOUT2 (cascade_ti), // Cascade input T data to slave .SHIFTOUT3 (), // Dummy output in Master .SHIFTOUT4 ()) ; // Dummy output in Master OSERDES2 #( .DATA_WIDTH (SF), // SERDES word width. This should match the setting is BUFPLL .DATA_RATE_OQ ("SDR"), // <SDR>, DDR .DATA_RATE_OT ("SDR"), // <SDR>, DDR .SERDES_MODE ("SLAVE"), // <DEFAULT>, MASTER, SLAVE .OUTPUT_MODE ("DIFFERENTIAL")) oserdes_s ( .OQ (), .OCE (1'b1), .CLK0 (ioclk), .CLK1 (1'b0), .IOCE (serdesstrobe), .RST (reset), .CLKDIV (gclk), .D4 (mdatain[3]), .D3 (mdatain[2]), .D2 (mdatain[1]), .D1 (mdatain[0]), .TQ (), .T1 (1'b0), .T2 (1'b0), .T3 (1'b0), .T4 (1'b0), .TRAIN (1'b0), .TCE (1'b1), .SHIFTIN1 (cascade_di), // Cascade input D from Master .SHIFTIN2 (cascade_ti), // Cascade input T from Master .SHIFTIN3 (1'b1), // Dummy input in Slave .SHIFTIN4 (1'b1), // Dummy input in Slave .SHIFTOUT1 (), // Dummy output in Slave .SHIFTOUT2 (), // Dummy output in Slave .SHIFTOUT3 (cascade_do), // Cascade output D data to Master .SHIFTOUT4 (cascade_to)) ; // Cascade output T data to Master endmodule
////////////////////////////////////////////////////////////////////////////// // // Xilinx, Inc. 2008 www.xilinx.com // ////////////////////////////////////////////////////////////////////////////// // // File name : serdes_n_to_1.v // // Description : 1-bit generic n:1 transmitter module // Takes in n bits of data and serialises this to 1 bit // data is transmitted LSB first // 0, 1, 2 ...... // // Date - revision : August 1st 2008 - v 1.0 // // Author : NJS // // Disclaimer: LIMITED WARRANTY AND DISCLAMER. These designs are // provided to you "as is". Xilinx and its licensors make and you // receive no warranties or conditions, express, implied, // statutory or otherwise, and Xilinx specifically disclaims any // implied warranties of merchantability, non-infringement,or // fitness for a particular purpose. Xilinx does not warrant that // the functions contained in these designs will meet your // requirements, or that the operation of these designs will be // uninterrupted or error free, or that defects in the Designs // will be corrected. Furthermore, Xilinx does not warrantor // make any representations regarding use or the results of the // use of the designs in terms of correctness, accuracy, // reliability, or otherwise. // // LIMITATION OF LIABILITY. In no event will Xilinx or its // licensors be liable for any loss of data, lost profits,cost // or procurement of substitute goods or services, or for any // special, incidental, consequential, or indirect damages // arising from the use or operation of the designs or // accompanying documentation, however caused and on any theory // of liability. This limitation will apply even if Xilinx // has been advised of the possibility of such damage. This // limitation shall apply not-withstanding the failure of the // essential purpose of any limited remedies herein. // // Copyright © 2008 Xilinx, Inc. // All rights reserved // ////////////////////////////////////////////////////////////////////////////// // `timescale 1ps/1ps module serdes_n_to_1 (ioclk, serdesstrobe, reset, gclk, datain, iob_data_out) ; parameter integer SF = 8 ; // Parameter to set the serdes factor 1..8 input ioclk ; // IO Clock network input serdesstrobe ; // Parallel data capture strobe input reset ; // Reset input gclk ; // Global clock input [SF-1 : 0] datain ; // Data for output output iob_data_out ; // output data wire cascade_di ; // wire cascade_do ; // wire cascade_ti ; // wire cascade_to ; // wire [8:0] mdatain ; // genvar i ; // Pad out the input data bus with 0's to 8 bits to avoid errors generate for (i = 0 ; i <= (SF - 1) ; i = i + 1) begin : loop0 assign mdatain[i] = datain[i] ; end endgenerate generate for (i = (SF) ; i <= 8 ; i = i + 1) begin : loop1 assign mdatain[i] = 1'b0 ; end endgenerate OSERDES2 #( .DATA_WIDTH (SF), // SERDES word width. This should match the setting is BUFPLL .DATA_RATE_OQ ("SDR"), // <SDR>, DDR .DATA_RATE_OT ("SDR"), // <SDR>, DDR .SERDES_MODE ("MASTER"), // <DEFAULT>, MASTER, SLAVE .OUTPUT_MODE ("DIFFERENTIAL")) oserdes_m ( .OQ (iob_data_out), .OCE (1'b1), .CLK0 (ioclk), .CLK1 (1'b0), .IOCE (serdesstrobe), .RST (reset), .CLKDIV (gclk), .D4 (mdatain[7]), .D3 (mdatain[6]), .D2 (mdatain[5]), .D1 (mdatain[4]), .TQ (), .T1 (1'b0), .T2 (1'b0), .T3 (1'b0), .T4 (1'b0), .TRAIN (1'b0), .TCE (1'b1), .SHIFTIN1 (1'b1), // Dummy input in Master .SHIFTIN2 (1'b1), // Dummy input in Master .SHIFTIN3 (cascade_do), // Cascade output D data from slave .SHIFTIN4 (cascade_to), // Cascade output T data from slave .SHIFTOUT1 (cascade_di), // Cascade input D data to slave .SHIFTOUT2 (cascade_ti), // Cascade input T data to slave .SHIFTOUT3 (), // Dummy output in Master .SHIFTOUT4 ()) ; // Dummy output in Master OSERDES2 #( .DATA_WIDTH (SF), // SERDES word width. This should match the setting is BUFPLL .DATA_RATE_OQ ("SDR"), // <SDR>, DDR .DATA_RATE_OT ("SDR"), // <SDR>, DDR .SERDES_MODE ("SLAVE"), // <DEFAULT>, MASTER, SLAVE .OUTPUT_MODE ("DIFFERENTIAL")) oserdes_s ( .OQ (), .OCE (1'b1), .CLK0 (ioclk), .CLK1 (1'b0), .IOCE (serdesstrobe), .RST (reset), .CLKDIV (gclk), .D4 (mdatain[3]), .D3 (mdatain[2]), .D2 (mdatain[1]), .D1 (mdatain[0]), .TQ (), .T1 (1'b0), .T2 (1'b0), .T3 (1'b0), .T4 (1'b0), .TRAIN (1'b0), .TCE (1'b1), .SHIFTIN1 (cascade_di), // Cascade input D from Master .SHIFTIN2 (cascade_ti), // Cascade input T from Master .SHIFTIN3 (1'b1), // Dummy input in Slave .SHIFTIN4 (1'b1), // Dummy input in Slave .SHIFTOUT1 (), // Dummy output in Slave .SHIFTOUT2 (), // Dummy output in Slave .SHIFTOUT3 (cascade_do), // Cascade output D data to Master .SHIFTOUT4 (cascade_to)) ; // Cascade output T data to Master endmodule
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2007 by Wilson Snyder. module t (/*AUTOARG*/ // Inputs clk ); input clk; v95 v95 (); v01 v01 (); v05 v05 (); s05 s05 (); s09 s09 (); a23 a23 (); s12 s12 (); initial begin $finish; end endmodule `begin_keywords "1364-1995" module v95; integer signed; initial signed = 1; endmodule `end_keywords `begin_keywords "1364-2001" module v01; integer bit; initial bit = 1; endmodule `end_keywords `begin_keywords "1364-2005" module v05; integer final; initial final = 1; endmodule `end_keywords `begin_keywords "1800-2005" module s05; integer global; initial global = 1; endmodule `end_keywords `begin_keywords "1800-2009" module s09; integer soft; initial soft = 1; endmodule `end_keywords `begin_keywords "1800-2012" module s12; final begin $write("*-* All Finished *-*\n"); end endmodule `end_keywords `begin_keywords "VAMS-2.3" module a23; real foo; initial foo = sqrt(2.0); endmodule `end_keywords
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : mig_7series_v1_9_ddr_phy_tempmon.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Jul 25 2012 // \___\/\___\ // //Device : 7 Series //Design Name : DDR3 SDRAM //Purpose : Monitors chip temperature via the XADC and adjusts the // stage 2 tap values as appropriate. //Reference : //Revision History : //***************************************************************************** `timescale 1 ps / 1 ps module mig_7series_v1_9_ddr_phy_tempmon # ( parameter TCQ = 100, // Register delay (simulation only) // Temperature bands must be in order. To disable bands, set to extreme. parameter BAND1_TEMP_MIN = 0, // Degrees C. Min=-273. Max=231 parameter BAND2_TEMP_MIN = 12, // Degrees C. Min=-273. Max=231 parameter BAND3_TEMP_MIN = 46, // Degrees C. Min=-273. Max=231 parameter BAND4_TEMP_MIN = 82, // Degrees C. Min=-273. Max=231 parameter TEMP_HYST = 5 ) ( input clk, // Fabric clock input rst, // System reset input calib_complete, // Calibration complete input tempmon_sample_en, // Signal to enable sampling input [11:0] device_temp, // Current device temperature output tempmon_pi_f_inc, // Increment PHASER_IN taps output tempmon_pi_f_dec, // Decrement PHASER_IN taps output tempmon_sel_pi_incdec // Assume control of PHASER_IN taps ); // translate hysteresis into XADC units localparam HYST_OFFSET = (TEMP_HYST * 4096) / 504; // translate band boundaries into XADC units localparam BAND1_OFFSET = ((BAND1_TEMP_MIN + 273) * 4096) / 504; localparam BAND2_OFFSET = ((BAND2_TEMP_MIN + 273) * 4096) / 504; localparam BAND3_OFFSET = ((BAND3_TEMP_MIN + 273) * 4096) / 504; localparam BAND4_OFFSET = ((BAND4_TEMP_MIN + 273) * 4096) / 504; // incorporate hysteresis into band boundaries localparam BAND0_DEC_OFFSET = BAND1_OFFSET - HYST_OFFSET > 0 ? BAND1_OFFSET - HYST_OFFSET : 0 ; localparam BAND1_INC_OFFSET = BAND1_OFFSET + HYST_OFFSET < 4096 ? BAND1_OFFSET + HYST_OFFSET : 4096 ; localparam BAND1_DEC_OFFSET = BAND2_OFFSET - HYST_OFFSET > 0 ? BAND2_OFFSET - HYST_OFFSET : 0 ; localparam BAND2_INC_OFFSET = BAND2_OFFSET + HYST_OFFSET < 4096 ? BAND2_OFFSET + HYST_OFFSET : 4096 ; localparam BAND2_DEC_OFFSET = BAND3_OFFSET - HYST_OFFSET > 0 ? BAND3_OFFSET - HYST_OFFSET : 0 ; localparam BAND3_INC_OFFSET = BAND3_OFFSET + HYST_OFFSET < 4096 ? BAND3_OFFSET + HYST_OFFSET : 4096 ; localparam BAND3_DEC_OFFSET = BAND4_OFFSET - HYST_OFFSET > 0 ? BAND4_OFFSET - HYST_OFFSET : 0 ; localparam BAND4_INC_OFFSET = BAND4_OFFSET + HYST_OFFSET < 4096 ? BAND4_OFFSET + HYST_OFFSET : 4096 ; // Temperature sampler FSM encoding localparam INIT = 2'b00; localparam IDLE = 2'b01; localparam UPDATE = 2'b10; localparam WAIT = 2'b11; // Temperature sampler state reg [2:0] tempmon_state = INIT; reg [2:0] tempmon_next_state = INIT; // Temperature storage reg [11:0] previous_temp = 12'b0; // Temperature bands reg [2:0] target_band = 3'b000; reg [2:0] current_band = 3'b000; // Tap count and control reg pi_f_inc = 1'b0; reg pi_f_dec = 1'b0; reg sel_pi_incdec = 1'b0; // Temperature and band comparisons reg device_temp_lt_previous_temp = 1'b0; reg device_temp_gt_previous_temp = 1'b0; reg device_temp_lt_band1 = 1'b0; reg device_temp_lt_band2 = 1'b0; reg device_temp_lt_band3 = 1'b0; reg device_temp_lt_band4 = 1'b0; reg device_temp_lt_band0_dec = 1'b0; reg device_temp_lt_band1_dec = 1'b0; reg device_temp_lt_band2_dec = 1'b0; reg device_temp_lt_band3_dec = 1'b0; reg device_temp_gt_band1_inc = 1'b0; reg device_temp_gt_band2_inc = 1'b0; reg device_temp_gt_band3_inc = 1'b0; reg device_temp_gt_band4_inc = 1'b0; reg current_band_lt_target_band = 1'b0; reg current_band_gt_target_band = 1'b0; reg target_band_gt_1 = 1'b0; reg target_band_gt_2 = 1'b0; reg target_band_gt_3 = 1'b0; reg target_band_lt_1 = 1'b0; reg target_band_lt_2 = 1'b0; reg target_band_lt_3 = 1'b0; // Pass tap control signals back up to PHY assign tempmon_pi_f_inc = pi_f_inc; assign tempmon_pi_f_dec = pi_f_dec; assign tempmon_sel_pi_incdec = sel_pi_incdec; // XADC sampler state transition always @(posedge clk) if(rst) tempmon_state <= #TCQ INIT; else tempmon_state <= #TCQ tempmon_next_state; // XADC sampler next state transition always @(tempmon_state or calib_complete or tempmon_sample_en) begin tempmon_next_state = tempmon_state; case(tempmon_state) INIT: if(calib_complete) tempmon_next_state = IDLE; IDLE: if(tempmon_sample_en) tempmon_next_state = UPDATE; UPDATE: tempmon_next_state = WAIT; WAIT: if(~tempmon_sample_en) tempmon_next_state = IDLE; default: tempmon_next_state = INIT; endcase end // Record previous temperature during update cycle always @(posedge clk) if((tempmon_state == INIT) || (tempmon_state == UPDATE)) previous_temp <= #TCQ device_temp; // Update target band always @(posedge clk) begin // register temperature comparisons device_temp_lt_previous_temp <= #TCQ (device_temp < previous_temp) ? 1'b1 : 1'b0; device_temp_gt_previous_temp <= #TCQ (device_temp > previous_temp) ? 1'b1 : 1'b0; device_temp_lt_band1 <= #TCQ (device_temp < BAND1_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band2 <= #TCQ (device_temp < BAND2_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band3 <= #TCQ (device_temp < BAND3_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band4 <= #TCQ (device_temp < BAND4_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band0_dec <= #TCQ (device_temp < BAND0_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band1_dec <= #TCQ (device_temp < BAND1_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band2_dec <= #TCQ (device_temp < BAND2_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band3_dec <= #TCQ (device_temp < BAND3_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band1_inc <= #TCQ (device_temp > BAND1_INC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band2_inc <= #TCQ (device_temp > BAND2_INC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band3_inc <= #TCQ (device_temp > BAND3_INC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band4_inc <= #TCQ (device_temp > BAND4_INC_OFFSET) ? 1'b1 : 1'b0; target_band_gt_1 <= #TCQ (target_band > 3'b001) ? 1'b1 : 1'b0; target_band_gt_2 <= #TCQ (target_band > 3'b010) ? 1'b1 : 1'b0; target_band_gt_3 <= #TCQ (target_band > 3'b011) ? 1'b1 : 1'b0; target_band_lt_1 <= #TCQ (target_band < 3'b001) ? 1'b1 : 1'b0; target_band_lt_2 <= #TCQ (target_band < 3'b010) ? 1'b1 : 1'b0; target_band_lt_3 <= #TCQ (target_band < 3'b011) ? 1'b1 : 1'b0; // Initialize band if(tempmon_state == INIT) begin if(device_temp_lt_band1) target_band <= #TCQ 3'b000; else if(device_temp_lt_band2) target_band <= #TCQ 3'b001; else if(device_temp_lt_band3) target_band <= #TCQ 3'b010; else if(device_temp_lt_band4) target_band <= #TCQ 3'b011; else target_band <= #TCQ 3'b100; end // Ready to update else if(tempmon_state == IDLE) begin // Temperature has increased, see if it is in a new band if(device_temp_gt_previous_temp) begin if(device_temp_gt_band4_inc) target_band <= #TCQ 3'b100; else if(device_temp_gt_band3_inc && target_band_lt_3) target_band <= #TCQ 3'b011; else if(device_temp_gt_band2_inc && target_band_lt_2) target_band <= #TCQ 3'b010; else if(device_temp_gt_band1_inc && target_band_lt_1) target_band <= #TCQ 3'b001; end // Temperature has decreased, see if it is in new band else if(device_temp_lt_previous_temp) begin if(device_temp_lt_band0_dec) target_band <= #TCQ 3'b000; else if(device_temp_lt_band1_dec && target_band_gt_1) target_band <= #TCQ 3'b001; else if(device_temp_lt_band2_dec && target_band_gt_2) target_band <= #TCQ 3'b010; else if(device_temp_lt_band3_dec && target_band_gt_3) target_band <= #TCQ 3'b011; end end end // Current band always @(posedge clk) begin current_band_lt_target_band = (current_band < target_band) ? 1'b1 : 1'b0; current_band_gt_target_band = (current_band > target_band) ? 1'b1 : 1'b0; if(tempmon_state == INIT) begin if(device_temp_lt_band1) current_band <= #TCQ 3'b000; else if(device_temp_lt_band2) current_band <= #TCQ 3'b001; else if(device_temp_lt_band3) current_band <= #TCQ 3'b010; else if(device_temp_lt_band4) current_band <= #TCQ 3'b011; else current_band <= #TCQ 3'b100; end else if(tempmon_state == UPDATE) begin if(current_band_lt_target_band) current_band <= #TCQ current_band + 1; else if(current_band_gt_target_band) current_band <= #TCQ current_band - 1; end end // Tap control always @(posedge clk) begin if(rst) begin pi_f_inc <= #TCQ 1'b0; pi_f_dec <= #TCQ 1'b0; sel_pi_incdec <= #TCQ 1'b0; end else if(tempmon_state == UPDATE) begin if(current_band_lt_target_band) begin sel_pi_incdec <= #TCQ 1'b1; pi_f_dec <= #TCQ 1'b1; end else if(current_band_gt_target_band) begin sel_pi_incdec <= #TCQ 1'b1; pi_f_inc <= #TCQ 1'b1; end end else begin pi_f_inc <= #TCQ 1'b0; pi_f_dec <= #TCQ 1'b0; sel_pi_incdec <= #TCQ 1'b0; end end endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : mig_7series_v1_9_ddr_phy_tempmon.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Jul 25 2012 // \___\/\___\ // //Device : 7 Series //Design Name : DDR3 SDRAM //Purpose : Monitors chip temperature via the XADC and adjusts the // stage 2 tap values as appropriate. //Reference : //Revision History : //***************************************************************************** `timescale 1 ps / 1 ps module mig_7series_v1_9_ddr_phy_tempmon # ( parameter TCQ = 100, // Register delay (simulation only) // Temperature bands must be in order. To disable bands, set to extreme. parameter BAND1_TEMP_MIN = 0, // Degrees C. Min=-273. Max=231 parameter BAND2_TEMP_MIN = 12, // Degrees C. Min=-273. Max=231 parameter BAND3_TEMP_MIN = 46, // Degrees C. Min=-273. Max=231 parameter BAND4_TEMP_MIN = 82, // Degrees C. Min=-273. Max=231 parameter TEMP_HYST = 5 ) ( input clk, // Fabric clock input rst, // System reset input calib_complete, // Calibration complete input tempmon_sample_en, // Signal to enable sampling input [11:0] device_temp, // Current device temperature output tempmon_pi_f_inc, // Increment PHASER_IN taps output tempmon_pi_f_dec, // Decrement PHASER_IN taps output tempmon_sel_pi_incdec // Assume control of PHASER_IN taps ); // translate hysteresis into XADC units localparam HYST_OFFSET = (TEMP_HYST * 4096) / 504; // translate band boundaries into XADC units localparam BAND1_OFFSET = ((BAND1_TEMP_MIN + 273) * 4096) / 504; localparam BAND2_OFFSET = ((BAND2_TEMP_MIN + 273) * 4096) / 504; localparam BAND3_OFFSET = ((BAND3_TEMP_MIN + 273) * 4096) / 504; localparam BAND4_OFFSET = ((BAND4_TEMP_MIN + 273) * 4096) / 504; // incorporate hysteresis into band boundaries localparam BAND0_DEC_OFFSET = BAND1_OFFSET - HYST_OFFSET > 0 ? BAND1_OFFSET - HYST_OFFSET : 0 ; localparam BAND1_INC_OFFSET = BAND1_OFFSET + HYST_OFFSET < 4096 ? BAND1_OFFSET + HYST_OFFSET : 4096 ; localparam BAND1_DEC_OFFSET = BAND2_OFFSET - HYST_OFFSET > 0 ? BAND2_OFFSET - HYST_OFFSET : 0 ; localparam BAND2_INC_OFFSET = BAND2_OFFSET + HYST_OFFSET < 4096 ? BAND2_OFFSET + HYST_OFFSET : 4096 ; localparam BAND2_DEC_OFFSET = BAND3_OFFSET - HYST_OFFSET > 0 ? BAND3_OFFSET - HYST_OFFSET : 0 ; localparam BAND3_INC_OFFSET = BAND3_OFFSET + HYST_OFFSET < 4096 ? BAND3_OFFSET + HYST_OFFSET : 4096 ; localparam BAND3_DEC_OFFSET = BAND4_OFFSET - HYST_OFFSET > 0 ? BAND4_OFFSET - HYST_OFFSET : 0 ; localparam BAND4_INC_OFFSET = BAND4_OFFSET + HYST_OFFSET < 4096 ? BAND4_OFFSET + HYST_OFFSET : 4096 ; // Temperature sampler FSM encoding localparam INIT = 2'b00; localparam IDLE = 2'b01; localparam UPDATE = 2'b10; localparam WAIT = 2'b11; // Temperature sampler state reg [2:0] tempmon_state = INIT; reg [2:0] tempmon_next_state = INIT; // Temperature storage reg [11:0] previous_temp = 12'b0; // Temperature bands reg [2:0] target_band = 3'b000; reg [2:0] current_band = 3'b000; // Tap count and control reg pi_f_inc = 1'b0; reg pi_f_dec = 1'b0; reg sel_pi_incdec = 1'b0; // Temperature and band comparisons reg device_temp_lt_previous_temp = 1'b0; reg device_temp_gt_previous_temp = 1'b0; reg device_temp_lt_band1 = 1'b0; reg device_temp_lt_band2 = 1'b0; reg device_temp_lt_band3 = 1'b0; reg device_temp_lt_band4 = 1'b0; reg device_temp_lt_band0_dec = 1'b0; reg device_temp_lt_band1_dec = 1'b0; reg device_temp_lt_band2_dec = 1'b0; reg device_temp_lt_band3_dec = 1'b0; reg device_temp_gt_band1_inc = 1'b0; reg device_temp_gt_band2_inc = 1'b0; reg device_temp_gt_band3_inc = 1'b0; reg device_temp_gt_band4_inc = 1'b0; reg current_band_lt_target_band = 1'b0; reg current_band_gt_target_band = 1'b0; reg target_band_gt_1 = 1'b0; reg target_band_gt_2 = 1'b0; reg target_band_gt_3 = 1'b0; reg target_band_lt_1 = 1'b0; reg target_band_lt_2 = 1'b0; reg target_band_lt_3 = 1'b0; // Pass tap control signals back up to PHY assign tempmon_pi_f_inc = pi_f_inc; assign tempmon_pi_f_dec = pi_f_dec; assign tempmon_sel_pi_incdec = sel_pi_incdec; // XADC sampler state transition always @(posedge clk) if(rst) tempmon_state <= #TCQ INIT; else tempmon_state <= #TCQ tempmon_next_state; // XADC sampler next state transition always @(tempmon_state or calib_complete or tempmon_sample_en) begin tempmon_next_state = tempmon_state; case(tempmon_state) INIT: if(calib_complete) tempmon_next_state = IDLE; IDLE: if(tempmon_sample_en) tempmon_next_state = UPDATE; UPDATE: tempmon_next_state = WAIT; WAIT: if(~tempmon_sample_en) tempmon_next_state = IDLE; default: tempmon_next_state = INIT; endcase end // Record previous temperature during update cycle always @(posedge clk) if((tempmon_state == INIT) || (tempmon_state == UPDATE)) previous_temp <= #TCQ device_temp; // Update target band always @(posedge clk) begin // register temperature comparisons device_temp_lt_previous_temp <= #TCQ (device_temp < previous_temp) ? 1'b1 : 1'b0; device_temp_gt_previous_temp <= #TCQ (device_temp > previous_temp) ? 1'b1 : 1'b0; device_temp_lt_band1 <= #TCQ (device_temp < BAND1_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band2 <= #TCQ (device_temp < BAND2_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band3 <= #TCQ (device_temp < BAND3_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band4 <= #TCQ (device_temp < BAND4_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band0_dec <= #TCQ (device_temp < BAND0_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band1_dec <= #TCQ (device_temp < BAND1_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band2_dec <= #TCQ (device_temp < BAND2_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_lt_band3_dec <= #TCQ (device_temp < BAND3_DEC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band1_inc <= #TCQ (device_temp > BAND1_INC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band2_inc <= #TCQ (device_temp > BAND2_INC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band3_inc <= #TCQ (device_temp > BAND3_INC_OFFSET) ? 1'b1 : 1'b0; device_temp_gt_band4_inc <= #TCQ (device_temp > BAND4_INC_OFFSET) ? 1'b1 : 1'b0; target_band_gt_1 <= #TCQ (target_band > 3'b001) ? 1'b1 : 1'b0; target_band_gt_2 <= #TCQ (target_band > 3'b010) ? 1'b1 : 1'b0; target_band_gt_3 <= #TCQ (target_band > 3'b011) ? 1'b1 : 1'b0; target_band_lt_1 <= #TCQ (target_band < 3'b001) ? 1'b1 : 1'b0; target_band_lt_2 <= #TCQ (target_band < 3'b010) ? 1'b1 : 1'b0; target_band_lt_3 <= #TCQ (target_band < 3'b011) ? 1'b1 : 1'b0; // Initialize band if(tempmon_state == INIT) begin if(device_temp_lt_band1) target_band <= #TCQ 3'b000; else if(device_temp_lt_band2) target_band <= #TCQ 3'b001; else if(device_temp_lt_band3) target_band <= #TCQ 3'b010; else if(device_temp_lt_band4) target_band <= #TCQ 3'b011; else target_band <= #TCQ 3'b100; end // Ready to update else if(tempmon_state == IDLE) begin // Temperature has increased, see if it is in a new band if(device_temp_gt_previous_temp) begin if(device_temp_gt_band4_inc) target_band <= #TCQ 3'b100; else if(device_temp_gt_band3_inc && target_band_lt_3) target_band <= #TCQ 3'b011; else if(device_temp_gt_band2_inc && target_band_lt_2) target_band <= #TCQ 3'b010; else if(device_temp_gt_band1_inc && target_band_lt_1) target_band <= #TCQ 3'b001; end // Temperature has decreased, see if it is in new band else if(device_temp_lt_previous_temp) begin if(device_temp_lt_band0_dec) target_band <= #TCQ 3'b000; else if(device_temp_lt_band1_dec && target_band_gt_1) target_band <= #TCQ 3'b001; else if(device_temp_lt_band2_dec && target_band_gt_2) target_band <= #TCQ 3'b010; else if(device_temp_lt_band3_dec && target_band_gt_3) target_band <= #TCQ 3'b011; end end end // Current band always @(posedge clk) begin current_band_lt_target_band = (current_band < target_band) ? 1'b1 : 1'b0; current_band_gt_target_band = (current_band > target_band) ? 1'b1 : 1'b0; if(tempmon_state == INIT) begin if(device_temp_lt_band1) current_band <= #TCQ 3'b000; else if(device_temp_lt_band2) current_band <= #TCQ 3'b001; else if(device_temp_lt_band3) current_band <= #TCQ 3'b010; else if(device_temp_lt_band4) current_band <= #TCQ 3'b011; else current_band <= #TCQ 3'b100; end else if(tempmon_state == UPDATE) begin if(current_band_lt_target_band) current_band <= #TCQ current_band + 1; else if(current_band_gt_target_band) current_band <= #TCQ current_band - 1; end end // Tap control always @(posedge clk) begin if(rst) begin pi_f_inc <= #TCQ 1'b0; pi_f_dec <= #TCQ 1'b0; sel_pi_incdec <= #TCQ 1'b0; end else if(tempmon_state == UPDATE) begin if(current_band_lt_target_band) begin sel_pi_incdec <= #TCQ 1'b1; pi_f_dec <= #TCQ 1'b1; end else if(current_band_gt_target_band) begin sel_pi_incdec <= #TCQ 1'b1; pi_f_inc <= #TCQ 1'b1; end end else begin pi_f_inc <= #TCQ 1'b0; pi_f_dec <= #TCQ 1'b0; sel_pi_incdec <= #TCQ 1'b0; end end endmodule
(** * ProofObjects: Working with Explicit Evidence in Coq *) Require Export MoreLogic. (* ##################################################### *) (** We have seen that Coq has mechanisms both for _programming_, using inductive data types (like [nat] or [list]) and functions over these types, and for _proving_ properties of these programs, using inductive propositions (like [ev] or [eq]), implication, and universal quantification. So far, we have treated these mechanisms as if they were quite separate, and for many purposes this is a good way to think. But we have also seen hints that Coq's programming and proving facilities are closely related. For example, the keyword [Inductive] is used to declare both data types and propositions, and [->] is used both to describe the type of functions on data and logical implication. This is not just a syntactic accident! In fact, programs and proofs in Coq are almost the same thing. In this chapter we will study how this works. We have already seen the fundamental idea: provability in Coq is represented by concrete _evidence_. When we construct the proof of a basic proposition, we are actually building a tree of evidence, which can be thought of as a data structure. If the proposition is an implication like [A -> B], then its proof will be an evidence _transformer_: a recipe for converting evidence for A into evidence for B. So at a fundamental level, proofs are simply programs that manipulate evidence. *) (** Q. If evidence is data, what are propositions themselves? A. They are types! Look again at the formal definition of the [beautiful] property. *) Print beautiful. (* ==> Inductive beautiful : nat -> Prop := b_0 : beautiful 0 | b_3 : beautiful 3 | b_5 : beautiful 5 | b_sum : forall n m : nat, beautiful n -> beautiful m -> beautiful (n + m) *) (** *** *) (** The trick is to introduce an alternative pronunciation of "[:]". Instead of "has type," we can also say "is a proof of." For example, the second line in the definition of [beautiful] declares that [b_0 : beautiful 0]. Instead of "[b_0] has type [beautiful 0]," we can say that "[b_0] is a proof of [beautiful 0]." Similarly for [b_3] and [b_5]. *) (** *** *) (** This pun between types and propositions (between [:] as "has type" and [:] as "is a proof of" or "is evidence for") is called the _Curry-Howard correspondence_. It proposes a deep connection between the world of logic and the world of computation. << propositions ~ types proofs ~ data values >> Many useful insights follow from this connection. To begin with, it gives us a natural interpretation of the type of [b_sum] constructor: *) Check b_sum. (* ===> b_sum : forall n m, beautiful n -> beautiful m -> beautiful (n+m) *) (** This can be read "[b_sum] is a constructor that takes four arguments -- two numbers, [n] and [m], and two pieces of evidence, for the propositions [beautiful n] and [beautiful m], respectively -- and yields evidence for the proposition [beautiful (n+m)]." *) (** Now let's look again at a previous proof involving [beautiful]. *) Theorem eight_is_beautiful: beautiful 8. Proof. apply b_sum with (n := 3) (m := 5). apply b_3. apply b_5. Qed. (** Just as with ordinary data values and functions, we can use the [Print] command to see the _proof object_ that results from this proof script. *) Print eight_is_beautiful. (* ===> eight_is_beautiful = b_sum 3 5 b_3 b_5 : beautiful 8 *) (** In view of this, we might wonder whether we can write such an expression ourselves. Indeed, we can: *) Check (b_sum 3 5 b_3 b_5). (* ===> beautiful (3 + 5) *) (** The expression [b_sum 3 5 b_3 b_5] can be thought of as instantiating the parameterized constructor [b_sum] with the specific arguments [3] [5] and the corresponding proof objects for its premises [beautiful 3] and [beautiful 5] (Coq is smart enough to figure out that 3+5=8). Alternatively, we can think of [b_sum] as a primitive "evidence constructor" that, when applied to two particular numbers, wants to be further applied to evidence that those two numbers are beautiful; its type, forall n m, beautiful n -> beautiful m -> beautiful (n+m), expresses this functionality, in the same way that the polymorphic type [forall X, list X] in the previous chapter expressed the fact that the constructor [nil] can be thought of as a function from types to empty lists with elements of that type. *) (** This gives us an alternative way to write the proof that [8] is beautiful: *) Theorem eight_is_beautiful': beautiful 8. Proof. apply (b_sum 3 5 b_3 b_5). Qed. (** Notice that we're using [apply] here in a new way: instead of just supplying the _name_ of a hypothesis or previously proved theorem whose type matches the current goal, we are supplying an _expression_ that directly builds evidence with the required type. *) (* ##################################################### *) (** * Proof Scripts and Proof Objects *) (** These proof objects lie at the core of how Coq operates. When Coq is following a proof script, what is happening internally is that it is gradually constructing a proof object -- a term whose type is the proposition being proved. The tactics between the [Proof] command and the [Qed] instruct Coq how to build up a term of the required type. To see this process in action, let's use the [Show Proof] command to display the current state of the proof tree at various points in the following tactic proof. *) Theorem eight_is_beautiful'': beautiful 8. Proof. Show Proof. apply b_sum with (n:=3) (m:=5). Show Proof. apply b_3. Show Proof. apply b_5. Show Proof. Qed. (** At any given moment, Coq has constructed a term with some "holes" (indicated by [?1], [?2], and so on), and it knows what type of evidence is needed at each hole. *) (** Each of the holes corresponds to a subgoal, and the proof is finished when there are no more subgoals. At this point, the [Theorem] command gives a name to the evidence we've built and stores it in the global context. *) (** Tactic proofs are useful and convenient, but they are not essential: in principle, we can always construct the required evidence by hand, as shown above. Then we can use [Definition] (rather than [Theorem]) to give a global name directly to a piece of evidence. *) Definition eight_is_beautiful''' : beautiful 8 := b_sum 3 5 b_3 b_5. (** All these different ways of building the proof lead to exactly the same evidence being saved in the global environment. *) Print eight_is_beautiful. (* ===> eight_is_beautiful = b_sum 3 5 b_3 b_5 : beautiful 8 *) Print eight_is_beautiful'. (* ===> eight_is_beautiful' = b_sum 3 5 b_3 b_5 : beautiful 8 *) Print eight_is_beautiful''. (* ===> eight_is_beautiful'' = b_sum 3 5 b_3 b_5 : beautiful 8 *) Print eight_is_beautiful'''. (* ===> eight_is_beautiful''' = b_sum 3 5 b_3 b_5 : beautiful 8 *) (** **** Exercise: 1 star (six_is_beautiful) *) (** Give a tactic proof and a proof object showing that [6] is [beautiful]. *) Theorem six_is_beautiful : beautiful 6. Proof. (* FILL IN HERE *) Admitted. Definition six_is_beautiful' : beautiful 6 := (* FILL IN HERE *) admit. (** [] *) (** **** Exercise: 1 star (nine_is_beautiful) *) (** Give a tactic proof and a proof object showing that [9] is [beautiful]. *) Theorem nine_is_beautiful : beautiful 9. Proof. (* FILL IN HERE *) Admitted. Definition nine_is_beautiful' : beautiful 9 := (* FILL IN HERE *) admit. (** [] *) (* ##################################################### *) (** * Quantification, Implications and Functions *) (** In Coq's computational universe (where we've mostly been living until this chapter), there are two sorts of values with arrows in their types: _constructors_ introduced by [Inductive]-ly defined data types, and _functions_. Similarly, in Coq's logical universe, there are two ways of giving evidence for an implication: constructors introduced by [Inductive]-ly defined propositions, and... functions! For example, consider this statement: *) Theorem b_plus3: forall n, beautiful n -> beautiful (3+n). Proof. intros n H. apply b_sum. apply b_3. apply H. Qed. (** What is the proof object corresponding to [b_plus3]? We're looking for an expression whose _type_ is [forall n, beautiful n -> beautiful (3+n)] -- that is, a _function_ that takes two arguments (one number and a piece of evidence) and returns a piece of evidence! Here it is: *) Definition b_plus3' : forall n, beautiful n -> beautiful (3+n) := fun (n : nat) => fun (H : beautiful n) => b_sum 3 n b_3 H. Check b_plus3'. (* ===> b_plus3' : forall n : nat, beautiful n -> beautiful (3+n) *) (** Recall that [fun n => blah] means "the function that, given [n], yields [blah]." Another equivalent way to write this definition is: *) Definition b_plus3'' (n : nat) (H : beautiful n) : beautiful (3+n) := b_sum 3 n b_3 H. Check b_plus3''. (* ===> b_plus3'' : forall n, beautiful n -> beautiful (3+n) *) (** When we view the proposition being proved by [b_plus3] as a function type, one aspect of it may seem a little unusual. The second argument's type, [beautiful n], mentions the _value_ of the first argument, [n]. While such _dependent types_ are not commonly found in programming languages, even functional ones like ML or Haskell, they can be useful there too. Notice that both implication ([->]) and quantification ([forall]) correspond to functions on evidence. In fact, they are really the same thing: [->] is just a shorthand for a degenerate use of [forall] where there is no dependency, i.e., no need to give a name to the type on the LHS of the arrow. *) (** For example, consider this proposition: *) Definition beautiful_plus3 : Prop := forall n, forall (E : beautiful n), beautiful (n+3). (** A proof term inhabiting this proposition would be a function with two arguments: a number [n] and some evidence [E] that [n] is beautiful. But the name [E] for this evidence is not used in the rest of the statement of [funny_prop1], so it's a bit silly to bother making up a name for it. We could write it like this instead, using the dummy identifier [_] in place of a real name: *) Definition beautiful_plus3' : Prop := forall n, forall (_ : beautiful n), beautiful (n+3). (** Or, equivalently, we can write it in more familiar notation: *) Definition beatiful_plus3'' : Prop := forall n, beautiful n -> beautiful (n+3). (** In general, "[P -> Q]" is just syntactic sugar for "[forall (_:P), Q]". *) (** **** Exercise: 2 stars b_times2 *) (** Give a proof object corresponding to the theorem [b_times2] from Prop.v *) Definition b_times2': forall n, beautiful n -> beautiful (2*n) := (* FILL IN HERE *) admit. (** [] *) (** **** Exercise: 2 stars, optional (gorgeous_plus13_po) *) (** Give a proof object corresponding to the theorem [gorgeous_plus13] from Prop.v *) Definition gorgeous_plus13_po: forall n, gorgeous n -> gorgeous (13+n):= (* FILL IN HERE *) admit. (** [] *) (** It is particularly revealing to look at proof objects involving the logical connectives that we defined with inductive propositions in Logic.v. *) Theorem and_example : (beautiful 0) /\ (beautiful 3). Proof. apply conj. (* Case "left". *) apply b_0. (* Case "right". *) apply b_3. Qed. (** Let's take a look at the proof object for the above theorem. *) Print and_example. (* ===> conj (beautiful 0) (beautiful 3) b_0 b_3 : beautiful 0 /\ beautiful 3 *) (** Note that the proof is of the form conj (beautiful 0) (beautiful 3) (...pf of beautiful 3...) (...pf of beautiful 3...) as you'd expect, given the type of [conj]. *) (** **** Exercise: 1 star, optional (case_proof_objects) *) (** The [Case] tactics were commented out in the proof of [and_example] to avoid cluttering the proof object. What would you guess the proof object will look like if we uncomment them? Try it and see. *) (** [] *) Theorem and_commut : forall P Q : Prop, P /\ Q -> Q /\ P. Proof. intros P Q H. inversion H as [HP HQ]. split. (* Case "left". *) apply HQ. (* Case "right". *) apply HP. Qed. (** Once again, we have commented out the [Case] tactics to make the proof object for this theorem easier to understand. It is still a little complicated, but after performing some simple reduction steps, we can see that all that is really happening is taking apart a record containing evidence for [P] and [Q] and rebuilding it in the opposite order: *) Print and_commut. (* ===> and_commut = fun (P Q : Prop) (H : P /\ Q) => (fun H0 : Q /\ P => H0) match H with | conj HP HQ => (fun (HP0 : P) (HQ0 : Q) => conj Q P HQ0 HP0) HP HQ end : forall P Q : Prop, P /\ Q -> Q /\ P *) (** After simplifying some direct application of [fun] expressions to arguments, we get: *) (* ===> and_commut = fun (P Q : Prop) (H : P /\ Q) => match H with | conj HP HQ => conj Q P HQ HP end : forall P Q : Prop, P /\ Q -> Q /\ P *) (** **** Exercise: 2 stars, optional (conj_fact) *) (** Construct a proof object demonstrating the following proposition. *) Definition conj_fact : forall P Q R, P /\ Q -> Q /\ R -> P /\ R := (* FILL IN HERE *) admit. (** [] *) (** **** Exercise: 2 stars, advanced, optional (beautiful_iff_gorgeous) *) (** We have seen that the families of propositions [beautiful] and [gorgeous] actually characterize the same set of numbers. Prove that [beautiful n <-> gorgeous n] for all [n]. Just for fun, write your proof as an explicit proof object, rather than using tactics. (_Hint_: if you make use of previously defined theorems, you should only need a single line!) *) Definition beautiful_iff_gorgeous : forall n, beautiful n <-> gorgeous n := (* FILL IN HERE *) admit. (** [] *) (** **** Exercise: 2 stars, optional (or_commut'') *) (** Try to write down an explicit proof object for [or_commut] (without using [Print] to peek at the ones we already defined!). *) (* FILL IN HERE *) (** [] *) (** Recall that we model an existential for a property as a pair consisting of a witness value and a proof that the witness obeys that property. We can choose to construct the proof explicitly. For example, consider this existentially quantified proposition: *) Check ex. Definition some_nat_is_even : Prop := ex _ ev. (** To prove this proposition, we need to choose a particular number as witness -- say, 4 -- and give some evidence that that number is even. *) Definition snie : some_nat_is_even := ex_intro _ ev 4 (ev_SS 2 (ev_SS 0 ev_0)). (** **** Exercise: 2 stars, optional (ex_beautiful_Sn) *) (** Complete the definition of the following proof object: *) Definition p : ex _ (fun n => beautiful (S n)) := (* FILL IN HERE *) admit. (** [] *) (* ##################################################### *) (** * Giving Explicit Arguments to Lemmas and Hypotheses *) (** Even when we are using tactic-based proof, it can be very useful to understand the underlying functional nature of implications and quantification. For example, it is often convenient to [apply] or [rewrite] using a lemma or hypothesis with one or more quantifiers or assumptions already instantiated in order to direct what happens. For example: *) Check plus_comm. (* ==> plus_comm : forall n m : nat, n + m = m + n *) Lemma plus_comm_r : forall a b c, c + (b + a) = c + (a + b). Proof. intros a b c. (* rewrite plus_comm. *) (* rewrites in the first possible spot; not what we want *) rewrite (plus_comm b a). (* directs rewriting to the right spot *) reflexivity. Qed. (** In this case, giving just one argument would be sufficient. *) Lemma plus_comm_r' : forall a b c, c + (b + a) = c + (a + b). Proof. intros a b c. rewrite (plus_comm b). reflexivity. Qed. (** Arguments must be given in order, but wildcards (_) may be used to skip arguments that Coq can infer. *) Lemma plus_comm_r'' : forall a b c, c + (b + a) = c + (a + b). Proof. intros a b c. rewrite (plus_comm _ a). reflexivity. Qed. (** The author of a lemma can choose to declare easily inferable arguments to be implicit, just as with functions and constructors. The [with] clauses we've already seen is really just a way of specifying selected arguments by name rather than position: *) Lemma plus_comm_r''' : forall a b c, c + (b + a) = c + (a + b). Proof. intros a b c. rewrite plus_comm with (n := b). reflexivity. Qed. (** **** Exercise: 2 stars (trans_eq_example_redux) *) (** Redo the proof of the following theorem (from MoreCoq.v) using an [apply] of [trans_eq] but _not_ using a [with] clause. *) Example trans_eq_example' : forall (a b c d e f : nat), [a;b] = [c;d] -> [c;d] = [e;f] -> [a;b] = [e;f]. Proof. (* FILL IN HERE *) Admitted. (** [] *) (* ##################################################### *) (** * Programming with Tactics (Advanced) *) (** If we can build proofs with explicit terms rather than tactics, you may be wondering if we can build programs using tactics rather than explicit terms. Sure! *) Definition add1 : nat -> nat. intro n. Show Proof. apply S. Show Proof. apply n. Defined. Print add1. (* ==> add1 = fun n : nat => S n : nat -> nat *) Eval compute in add1 2. (* ==> 3 : nat *) (** Notice that we terminate the [Definition] with a [.] rather than with [:=] followed by a term. This tells Coq to enter proof scripting mode to build an object of type [nat -> nat]. Also, we terminate the proof with [Defined] rather than [Qed]; this makes the definition _transparent_ so that it can be used in computation like a normally-defined function. This feature is mainly useful for writing functions with dependent types, which we won't explore much further in this book. But it does illustrate the uniformity and orthogonality of the basic ideas in Coq. *) (** $Date: 2014-12-31 15:31:47 -0500 (Wed, 31 Dec 2014) $ *)
(** * ImpCEvalFun: Evaluation Function for Imp *) (* #################################### *) (** * Evaluation Function *) Require Import Imp. (** Here's a first try at an evaluation function for commands, omitting [WHILE]. *) Fixpoint ceval_step1 (st : state) (c : com) : state := match c with | SKIP => st | l ::= a1 => update st l (aeval st a1) | c1 ;; c2 => let st' := ceval_step1 st c1 in ceval_step1 st' c2 | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step1 st c1 else ceval_step1 st c2 | WHILE b1 DO c1 END => st (* bogus *) end. (** In a traditional functional programming language like ML or Haskell we could write the WHILE case as follows: << | WHILE b1 DO c1 END => if (beval st b1) then ceval_step1 st (c1;; WHILE b1 DO c1 END) else st >> Coq doesn't accept such a definition ([Error: Cannot guess decreasing argument of fix]) because the function we want to define is not guaranteed to terminate. Indeed, the changed [ceval_step1] function applied to the [loop] program from [Imp.v] would never terminate. Since Coq is not just a functional programming language, but also a consistent logic, any potentially non-terminating function needs to be rejected. Here is an invalid(!) Coq program showing what would go wrong if Coq allowed non-terminating recursive functions: << Fixpoint loop_false (n : nat) : False := loop_false n. >> That is, propositions like [False] would become provable (e.g. [loop_false 0] would be a proof of [False]), which would be a disaster for Coq's logical consistency. Thus, because it doesn't terminate on all inputs, the full version of [ceval_step1] cannot be written in Coq -- at least not without one additional trick... *) (** Second try, using an extra numeric argument as a "step index" to ensure that evaluation always terminates. *) Fixpoint ceval_step2 (st : state) (c : com) (i : nat) : state := match i with | O => empty_state | S i' => match c with | SKIP => st | l ::= a1 => update st l (aeval st a1) | c1 ;; c2 => let st' := ceval_step2 st c1 i' in ceval_step2 st' c2 i' | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step2 st c1 i' else ceval_step2 st c2 i' | WHILE b1 DO c1 END => if (beval st b1) then let st' := ceval_step2 st c1 i' in ceval_step2 st' c i' else st end end. (** _Note_: It is tempting to think that the index [i] here is counting the "number of steps of evaluation." But if you look closely you'll see that this is not the case: for example, in the rule for sequencing, the same [i] is passed to both recursive calls. Understanding the exact way that [i] is treated will be important in the proof of [ceval__ceval_step], which is given as an exercise below. *) (** Third try, returning an [option state] instead of just a [state] so that we can distinguish between normal and abnormal termination. *) Fixpoint ceval_step3 (st : state) (c : com) (i : nat) : option state := match i with | O => None | S i' => match c with | SKIP => Some st | l ::= a1 => Some (update st l (aeval st a1)) | c1 ;; c2 => match (ceval_step3 st c1 i') with | Some st' => ceval_step3 st' c2 i' | None => None end | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step3 st c1 i' else ceval_step3 st c2 i' | WHILE b1 DO c1 END => if (beval st b1) then match (ceval_step3 st c1 i') with | Some st' => ceval_step3 st' c i' | None => None end else Some st end end. (** We can improve the readability of this definition by introducing a bit of auxiliary notation to hide the "plumbing" involved in repeatedly matching against optional states. *) Notation "'LETOPT' x <== e1 'IN' e2" := (match e1 with | Some x => e2 | None => None end) (right associativity, at level 60). Fixpoint ceval_step (st : state) (c : com) (i : nat) : option state := match i with | O => None | S i' => match c with | SKIP => Some st | l ::= a1 => Some (update st l (aeval st a1)) | c1 ;; c2 => LETOPT st' <== ceval_step st c1 i' IN ceval_step st' c2 i' | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step st c1 i' else ceval_step st c2 i' | WHILE b1 DO c1 END => if (beval st b1) then LETOPT st' <== ceval_step st c1 i' IN ceval_step st' c i' else Some st end end. Definition test_ceval (st:state) (c:com) := match ceval_step st c 500 with | None => None | Some st => Some (st X, st Y, st Z) end. (* Eval compute in (test_ceval empty_state (X ::= ANum 2;; IFB BLe (AId X) (ANum 1) THEN Y ::= ANum 3 ELSE Z ::= ANum 4 FI)). ====> Some (2, 0, 4) *) (** **** Exercise: 2 stars (pup_to_n) *) (** Write an Imp program that sums the numbers from [1] to [X] (inclusive: [1 + 2 + ... + X]) in the variable [Y]. Make sure your solution satisfies the test that follows. *) Definition pup_to_n : com := (* FILL IN HERE *) admit. (* Example pup_to_n_1 : test_ceval (update empty_state X 5) pup_to_n = Some (0, 15, 0). Proof. reflexivity. Qed. *) (** [] *) (** **** Exercise: 2 stars, optional (peven) *) (** Write a [While] program that sets [Z] to [0] if [X] is even and sets [Z] to [1] otherwise. Use [ceval_test] to test your program. *) (* FILL IN HERE *) (** [] *) (* ################################################################ *) (** * Equivalence of Relational and Step-Indexed Evaluation *) (** As with arithmetic and boolean expressions, we'd hope that the two alternative definitions of evaluation actually boil down to the same thing. This section shows that this is the case. Make sure you understand the statements of the theorems and can follow the structure of the proofs. *) Theorem ceval_step__ceval: forall c st st', (exists i, ceval_step st c i = Some st') -> c / st || st'. Proof. intros c st st' H. inversion H as [i E]. clear H. generalize dependent st'. generalize dependent st. generalize dependent c. induction i as [| i' ]. Case "i = 0 -- contradictory". intros c st st' H. inversion H. Case "i = S i'". intros c st st' H. com_cases (destruct c) SCase; simpl in H; inversion H; subst; clear H. SCase "SKIP". apply E_Skip. SCase "::=". apply E_Ass. reflexivity. SCase ";;". destruct (ceval_step st c1 i') eqn:Heqr1. SSCase "Evaluation of r1 terminates normally". apply E_Seq with s. apply IHi'. rewrite Heqr1. reflexivity. apply IHi'. simpl in H1. assumption. SSCase "Otherwise -- contradiction". inversion H1. SCase "IFB". destruct (beval st b) eqn:Heqr. SSCase "r = true". apply E_IfTrue. rewrite Heqr. reflexivity. apply IHi'. assumption. SSCase "r = false". apply E_IfFalse. rewrite Heqr. reflexivity. apply IHi'. assumption. SCase "WHILE". destruct (beval st b) eqn :Heqr. SSCase "r = true". destruct (ceval_step st c i') eqn:Heqr1. SSSCase "r1 = Some s". apply E_WhileLoop with s. rewrite Heqr. reflexivity. apply IHi'. rewrite Heqr1. reflexivity. apply IHi'. simpl in H1. assumption. SSSCase "r1 = None". inversion H1. SSCase "r = false". inversion H1. apply E_WhileEnd. rewrite <- Heqr. subst. reflexivity. Qed. (** **** Exercise: 4 stars (ceval_step__ceval_inf) *) (** Write an informal proof of [ceval_step__ceval], following the usual template. (The template for case analysis on an inductively defined value should look the same as for induction, except that there is no induction hypothesis.) Make your proof communicate the main ideas to a human reader; do not simply transcribe the steps of the formal proof. (* FILL IN HERE *) [] *) Theorem ceval_step_more: forall i1 i2 st st' c, i1 <= i2 -> ceval_step st c i1 = Some st' -> ceval_step st c i2 = Some st'. Proof. induction i1 as [|i1']; intros i2 st st' c Hle Hceval. Case "i1 = 0". simpl in Hceval. inversion Hceval. Case "i1 = S i1'". destruct i2 as [|i2']. inversion Hle. assert (Hle': i1' <= i2') by omega. com_cases (destruct c) SCase. SCase "SKIP". simpl in Hceval. inversion Hceval. reflexivity. SCase "::=". simpl in Hceval. inversion Hceval. reflexivity. SCase ";;". simpl in Hceval. simpl. destruct (ceval_step st c1 i1') eqn:Heqst1'o. SSCase "st1'o = Some". apply (IHi1' i2') in Heqst1'o; try assumption. rewrite Heqst1'o. simpl. simpl in Hceval. apply (IHi1' i2') in Hceval; try assumption. SSCase "st1'o = None". inversion Hceval. SCase "IFB". simpl in Hceval. simpl. destruct (beval st b); apply (IHi1' i2') in Hceval; assumption. SCase "WHILE". simpl in Hceval. simpl. destruct (beval st b); try assumption. destruct (ceval_step st c i1') eqn: Heqst1'o. SSCase "st1'o = Some". apply (IHi1' i2') in Heqst1'o; try assumption. rewrite -> Heqst1'o. simpl. simpl in Hceval. apply (IHi1' i2') in Hceval; try assumption. SSCase "i1'o = None". simpl in Hceval. inversion Hceval. Qed. (** **** Exercise: 3 stars (ceval__ceval_step) *) (** Finish the following proof. You'll need [ceval_step_more] in a few places, as well as some basic facts about [<=] and [plus]. *) Theorem ceval__ceval_step: forall c st st', c / st || st' -> exists i, ceval_step st c i = Some st'. Proof. intros c st st' Hce. ceval_cases (induction Hce) Case. (* FILL IN HERE *) Admitted. (** [] *) Theorem ceval_and_ceval_step_coincide: forall c st st', c / st || st' <-> exists i, ceval_step st c i = Some st'. Proof. intros c st st'. split. apply ceval__ceval_step. apply ceval_step__ceval. Qed. (* ####################################################### *) (** * Determinism of Evaluation (Simpler Proof) *) (** Here's a slicker proof showing that the evaluation relation is deterministic, using the fact that the relational and step-indexed definition of evaluation are the same. *) Theorem ceval_deterministic' : forall c st st1 st2, c / st || st1 -> c / st || st2 -> st1 = st2. Proof. intros c st st1 st2 He1 He2. apply ceval__ceval_step in He1. apply ceval__ceval_step in He2. inversion He1 as [i1 E1]. inversion He2 as [i2 E2]. apply ceval_step_more with (i2 := i1 + i2) in E1. apply ceval_step_more with (i2 := i1 + i2) in E2. rewrite E1 in E2. inversion E2. reflexivity. omega. omega. Qed. (** $Date: 2014-12-31 11:17:56 -0500 (Wed, 31 Dec 2014) $ *)
(** * ImpCEvalFun: Evaluation Function for Imp *) (* #################################### *) (** * Evaluation Function *) Require Import Imp. (** Here's a first try at an evaluation function for commands, omitting [WHILE]. *) Fixpoint ceval_step1 (st : state) (c : com) : state := match c with | SKIP => st | l ::= a1 => update st l (aeval st a1) | c1 ;; c2 => let st' := ceval_step1 st c1 in ceval_step1 st' c2 | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step1 st c1 else ceval_step1 st c2 | WHILE b1 DO c1 END => st (* bogus *) end. (** In a traditional functional programming language like ML or Haskell we could write the WHILE case as follows: << | WHILE b1 DO c1 END => if (beval st b1) then ceval_step1 st (c1;; WHILE b1 DO c1 END) else st >> Coq doesn't accept such a definition ([Error: Cannot guess decreasing argument of fix]) because the function we want to define is not guaranteed to terminate. Indeed, the changed [ceval_step1] function applied to the [loop] program from [Imp.v] would never terminate. Since Coq is not just a functional programming language, but also a consistent logic, any potentially non-terminating function needs to be rejected. Here is an invalid(!) Coq program showing what would go wrong if Coq allowed non-terminating recursive functions: << Fixpoint loop_false (n : nat) : False := loop_false n. >> That is, propositions like [False] would become provable (e.g. [loop_false 0] would be a proof of [False]), which would be a disaster for Coq's logical consistency. Thus, because it doesn't terminate on all inputs, the full version of [ceval_step1] cannot be written in Coq -- at least not without one additional trick... *) (** Second try, using an extra numeric argument as a "step index" to ensure that evaluation always terminates. *) Fixpoint ceval_step2 (st : state) (c : com) (i : nat) : state := match i with | O => empty_state | S i' => match c with | SKIP => st | l ::= a1 => update st l (aeval st a1) | c1 ;; c2 => let st' := ceval_step2 st c1 i' in ceval_step2 st' c2 i' | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step2 st c1 i' else ceval_step2 st c2 i' | WHILE b1 DO c1 END => if (beval st b1) then let st' := ceval_step2 st c1 i' in ceval_step2 st' c i' else st end end. (** _Note_: It is tempting to think that the index [i] here is counting the "number of steps of evaluation." But if you look closely you'll see that this is not the case: for example, in the rule for sequencing, the same [i] is passed to both recursive calls. Understanding the exact way that [i] is treated will be important in the proof of [ceval__ceval_step], which is given as an exercise below. *) (** Third try, returning an [option state] instead of just a [state] so that we can distinguish between normal and abnormal termination. *) Fixpoint ceval_step3 (st : state) (c : com) (i : nat) : option state := match i with | O => None | S i' => match c with | SKIP => Some st | l ::= a1 => Some (update st l (aeval st a1)) | c1 ;; c2 => match (ceval_step3 st c1 i') with | Some st' => ceval_step3 st' c2 i' | None => None end | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step3 st c1 i' else ceval_step3 st c2 i' | WHILE b1 DO c1 END => if (beval st b1) then match (ceval_step3 st c1 i') with | Some st' => ceval_step3 st' c i' | None => None end else Some st end end. (** We can improve the readability of this definition by introducing a bit of auxiliary notation to hide the "plumbing" involved in repeatedly matching against optional states. *) Notation "'LETOPT' x <== e1 'IN' e2" := (match e1 with | Some x => e2 | None => None end) (right associativity, at level 60). Fixpoint ceval_step (st : state) (c : com) (i : nat) : option state := match i with | O => None | S i' => match c with | SKIP => Some st | l ::= a1 => Some (update st l (aeval st a1)) | c1 ;; c2 => LETOPT st' <== ceval_step st c1 i' IN ceval_step st' c2 i' | IFB b THEN c1 ELSE c2 FI => if (beval st b) then ceval_step st c1 i' else ceval_step st c2 i' | WHILE b1 DO c1 END => if (beval st b1) then LETOPT st' <== ceval_step st c1 i' IN ceval_step st' c i' else Some st end end. Definition test_ceval (st:state) (c:com) := match ceval_step st c 500 with | None => None | Some st => Some (st X, st Y, st Z) end. (* Eval compute in (test_ceval empty_state (X ::= ANum 2;; IFB BLe (AId X) (ANum 1) THEN Y ::= ANum 3 ELSE Z ::= ANum 4 FI)). ====> Some (2, 0, 4) *) (** **** Exercise: 2 stars (pup_to_n) *) (** Write an Imp program that sums the numbers from [1] to [X] (inclusive: [1 + 2 + ... + X]) in the variable [Y]. Make sure your solution satisfies the test that follows. *) Definition pup_to_n : com := (* FILL IN HERE *) admit. (* Example pup_to_n_1 : test_ceval (update empty_state X 5) pup_to_n = Some (0, 15, 0). Proof. reflexivity. Qed. *) (** [] *) (** **** Exercise: 2 stars, optional (peven) *) (** Write a [While] program that sets [Z] to [0] if [X] is even and sets [Z] to [1] otherwise. Use [ceval_test] to test your program. *) (* FILL IN HERE *) (** [] *) (* ################################################################ *) (** * Equivalence of Relational and Step-Indexed Evaluation *) (** As with arithmetic and boolean expressions, we'd hope that the two alternative definitions of evaluation actually boil down to the same thing. This section shows that this is the case. Make sure you understand the statements of the theorems and can follow the structure of the proofs. *) Theorem ceval_step__ceval: forall c st st', (exists i, ceval_step st c i = Some st') -> c / st || st'. Proof. intros c st st' H. inversion H as [i E]. clear H. generalize dependent st'. generalize dependent st. generalize dependent c. induction i as [| i' ]. Case "i = 0 -- contradictory". intros c st st' H. inversion H. Case "i = S i'". intros c st st' H. com_cases (destruct c) SCase; simpl in H; inversion H; subst; clear H. SCase "SKIP". apply E_Skip. SCase "::=". apply E_Ass. reflexivity. SCase ";;". destruct (ceval_step st c1 i') eqn:Heqr1. SSCase "Evaluation of r1 terminates normally". apply E_Seq with s. apply IHi'. rewrite Heqr1. reflexivity. apply IHi'. simpl in H1. assumption. SSCase "Otherwise -- contradiction". inversion H1. SCase "IFB". destruct (beval st b) eqn:Heqr. SSCase "r = true". apply E_IfTrue. rewrite Heqr. reflexivity. apply IHi'. assumption. SSCase "r = false". apply E_IfFalse. rewrite Heqr. reflexivity. apply IHi'. assumption. SCase "WHILE". destruct (beval st b) eqn :Heqr. SSCase "r = true". destruct (ceval_step st c i') eqn:Heqr1. SSSCase "r1 = Some s". apply E_WhileLoop with s. rewrite Heqr. reflexivity. apply IHi'. rewrite Heqr1. reflexivity. apply IHi'. simpl in H1. assumption. SSSCase "r1 = None". inversion H1. SSCase "r = false". inversion H1. apply E_WhileEnd. rewrite <- Heqr. subst. reflexivity. Qed. (** **** Exercise: 4 stars (ceval_step__ceval_inf) *) (** Write an informal proof of [ceval_step__ceval], following the usual template. (The template for case analysis on an inductively defined value should look the same as for induction, except that there is no induction hypothesis.) Make your proof communicate the main ideas to a human reader; do not simply transcribe the steps of the formal proof. (* FILL IN HERE *) [] *) Theorem ceval_step_more: forall i1 i2 st st' c, i1 <= i2 -> ceval_step st c i1 = Some st' -> ceval_step st c i2 = Some st'. Proof. induction i1 as [|i1']; intros i2 st st' c Hle Hceval. Case "i1 = 0". simpl in Hceval. inversion Hceval. Case "i1 = S i1'". destruct i2 as [|i2']. inversion Hle. assert (Hle': i1' <= i2') by omega. com_cases (destruct c) SCase. SCase "SKIP". simpl in Hceval. inversion Hceval. reflexivity. SCase "::=". simpl in Hceval. inversion Hceval. reflexivity. SCase ";;". simpl in Hceval. simpl. destruct (ceval_step st c1 i1') eqn:Heqst1'o. SSCase "st1'o = Some". apply (IHi1' i2') in Heqst1'o; try assumption. rewrite Heqst1'o. simpl. simpl in Hceval. apply (IHi1' i2') in Hceval; try assumption. SSCase "st1'o = None". inversion Hceval. SCase "IFB". simpl in Hceval. simpl. destruct (beval st b); apply (IHi1' i2') in Hceval; assumption. SCase "WHILE". simpl in Hceval. simpl. destruct (beval st b); try assumption. destruct (ceval_step st c i1') eqn: Heqst1'o. SSCase "st1'o = Some". apply (IHi1' i2') in Heqst1'o; try assumption. rewrite -> Heqst1'o. simpl. simpl in Hceval. apply (IHi1' i2') in Hceval; try assumption. SSCase "i1'o = None". simpl in Hceval. inversion Hceval. Qed. (** **** Exercise: 3 stars (ceval__ceval_step) *) (** Finish the following proof. You'll need [ceval_step_more] in a few places, as well as some basic facts about [<=] and [plus]. *) Theorem ceval__ceval_step: forall c st st', c / st || st' -> exists i, ceval_step st c i = Some st'. Proof. intros c st st' Hce. ceval_cases (induction Hce) Case. (* FILL IN HERE *) Admitted. (** [] *) Theorem ceval_and_ceval_step_coincide: forall c st st', c / st || st' <-> exists i, ceval_step st c i = Some st'. Proof. intros c st st'. split. apply ceval__ceval_step. apply ceval_step__ceval. Qed. (* ####################################################### *) (** * Determinism of Evaluation (Simpler Proof) *) (** Here's a slicker proof showing that the evaluation relation is deterministic, using the fact that the relational and step-indexed definition of evaluation are the same. *) Theorem ceval_deterministic' : forall c st st1 st2, c / st || st1 -> c / st || st2 -> st1 = st2. Proof. intros c st st1 st2 He1 He2. apply ceval__ceval_step in He1. apply ceval__ceval_step in He2. inversion He1 as [i1 E1]. inversion He2 as [i2 E2]. apply ceval_step_more with (i2 := i1 + i2) in E1. apply ceval_step_more with (i2 := i1 + i2) in E2. rewrite E1 in E2. inversion E2. reflexivity. omega. omega. Qed. (** $Date: 2014-12-31 11:17:56 -0500 (Wed, 31 Dec 2014) $ *)
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Import Bool ZAxioms ZMulOrder ZPow ZDivFloor ZSgnAbs ZParity NZLog. (** Derived properties of bitwise operations *) Module Type ZBitsProp (Import A : ZAxiomsSig') (Import B : ZMulOrderProp A) (Import C : ZParityProp A B) (Import D : ZSgnAbsProp A B) (Import E : ZPowProp A B C D) (Import F : ZDivProp A B D) (Import G : NZLog2Prop A A A B E). Include BoolEqualityFacts A. Ltac order_nz := try apply pow_nonzero; order'. Ltac order_pos' := try apply abs_nonneg; order_pos. Hint Rewrite div_0_l mod_0_l div_1_r mod_1_r : nz. (** Some properties of power and division *) Lemma pow_sub_r : forall a b c, a~=0 -> 0<=c<=b -> a^(b-c) == a^b / a^c. Proof. intros a b c Ha (H,H'). rewrite <- (sub_simpl_r b c) at 2. rewrite pow_add_r; trivial. rewrite div_mul. reflexivity. now apply pow_nonzero. now apply le_0_sub. Qed. Lemma pow_div_l : forall a b c, b~=0 -> 0<=c -> a mod b == 0 -> (a/b)^c == a^c / b^c. Proof. intros a b c Hb Hc H. rewrite (div_mod a b Hb) at 2. rewrite H, add_0_r, pow_mul_l, mul_comm, div_mul. reflexivity. now apply pow_nonzero. Qed. (** An injection from bits [true] and [false] to numbers 1 and 0. We declare it as a (local) coercion for shorter statements. *) Definition b2z (b:bool) := if b then 1 else 0. Local Coercion b2z : bool >-> t. Instance b2z_wd : Proper (Logic.eq ==> eq) b2z := _. Lemma exists_div2 a : exists a' (b:bool), a == 2*a' + b. Proof. elim (Even_or_Odd a); [intros (a',H)| intros (a',H)]. exists a'. exists false. now nzsimpl. exists a'. exists true. now simpl. Qed. (** We can compact [testbit_odd_0] [testbit_even_0] [testbit_even_succ] [testbit_odd_succ] in only two lemmas. *) Lemma testbit_0_r a (b:bool) : testbit (2*a+b) 0 = b. Proof. destruct b; simpl; rewrite ?add_0_r. apply testbit_odd_0. apply testbit_even_0. Qed. Lemma testbit_succ_r a (b:bool) n : 0<=n -> testbit (2*a+b) (succ n) = testbit a n. Proof. destruct b; simpl; rewrite ?add_0_r. now apply testbit_odd_succ. now apply testbit_even_succ. Qed. (** Alternative caracterisations of [testbit] *) (** This concise equation could have been taken as specification for testbit in the interface, but it would have been hard to implement with little initial knowledge about div and mod *) Lemma testbit_spec' a n : 0<=n -> a.[n] == (a / 2^n) mod 2. Proof. intro Hn. revert a. apply le_ind with (4:=Hn). solve_proper. intros a. nzsimpl. destruct (exists_div2 a) as (a' & b & H). rewrite H at 1. rewrite testbit_0_r. apply mod_unique with a'; trivial. left. destruct b; split; simpl; order'. clear n Hn. intros n Hn IH a. destruct (exists_div2 a) as (a' & b & H). rewrite H at 1. rewrite testbit_succ_r, IH by trivial. f_equiv. rewrite pow_succ_r, <- div_div by order_pos. f_equiv. apply div_unique with b; trivial. left. destruct b; split; simpl; order'. Qed. (** This caracterisation that uses only basic operations and power was initially taken as specification for testbit. We describe [a] as having a low part and a high part, with the corresponding bit in the middle. This caracterisation is moderatly complex to implement, but also moderately usable... *) Lemma testbit_spec a n : 0<=n -> exists l h, 0<=l<2^n /\ a == l + (a.[n] + 2*h)*2^n. Proof. intro Hn. exists (a mod 2^n). exists (a / 2^n / 2). split. apply mod_pos_bound; order_pos. rewrite add_comm, mul_comm, (add_comm a.[n]). rewrite (div_mod a (2^n)) at 1 by order_nz. do 2 f_equiv. rewrite testbit_spec' by trivial. apply div_mod. order'. Qed. Lemma testbit_true : forall a n, 0<=n -> (a.[n] = true <-> (a / 2^n) mod 2 == 1). Proof. intros a n Hn. rewrite <- testbit_spec' by trivial. destruct a.[n]; split; simpl; now try order'. Qed. Lemma testbit_false : forall a n, 0<=n -> (a.[n] = false <-> (a / 2^n) mod 2 == 0). Proof. intros a n Hn. rewrite <- testbit_spec' by trivial. destruct a.[n]; split; simpl; now try order'. Qed. Lemma testbit_eqb : forall a n, 0<=n -> a.[n] = eqb ((a / 2^n) mod 2) 1. Proof. intros a n Hn. apply eq_true_iff_eq. now rewrite testbit_true, eqb_eq. Qed. (** Results about the injection [b2z] *) Lemma b2z_inj : forall (a0 b0:bool), a0 == b0 -> a0 = b0. Proof. intros [|] [|]; simpl; trivial; order'. Qed. Lemma add_b2z_double_div2 : forall (a0:bool) a, (a0+2*a)/2 == a. Proof. intros a0 a. rewrite mul_comm, div_add by order'. now rewrite div_small, add_0_l by (destruct a0; split; simpl; order'). Qed. Lemma add_b2z_double_bit0 : forall (a0:bool) a, (a0+2*a).[0] = a0. Proof. intros a0 a. apply b2z_inj. rewrite testbit_spec' by order. nzsimpl. rewrite mul_comm, mod_add by order'. now rewrite mod_small by (destruct a0; split; simpl; order'). Qed. Lemma b2z_div2 : forall (a0:bool), a0/2 == 0. Proof. intros a0. rewrite <- (add_b2z_double_div2 a0 0). now nzsimpl. Qed. Lemma b2z_bit0 : forall (a0:bool), a0.[0] = a0. Proof. intros a0. rewrite <- (add_b2z_double_bit0 a0 0) at 2. now nzsimpl. Qed. (** The specification of testbit by low and high parts is complete *) Lemma testbit_unique : forall a n (a0:bool) l h, 0<=l<2^n -> a == l + (a0 + 2*h)*2^n -> a.[n] = a0. Proof. intros a n a0 l h Hl EQ. assert (0<=n). destruct (le_gt_cases 0 n) as [Hn|Hn]; trivial. rewrite pow_neg_r in Hl by trivial. destruct Hl; order. apply b2z_inj. rewrite testbit_spec' by trivial. symmetry. apply mod_unique with h. left; destruct a0; simpl; split; order'. symmetry. apply div_unique with l. now left. now rewrite add_comm, (add_comm _ a0), mul_comm. Qed. (** All bits of number 0 are 0 *) Lemma bits_0 : forall n, 0.[n] = false. Proof. intros n. destruct (le_gt_cases 0 n). apply testbit_false; trivial. nzsimpl; order_nz. now apply testbit_neg_r. Qed. (** For negative numbers, we are actually doing two's complement *) Lemma bits_opp : forall a n, 0<=n -> (-a).[n] = negb (P a).[n]. Proof. intros a n Hn. destruct (testbit_spec (-a) n Hn) as (l & h & Hl & EQ). fold (b2z (-a).[n]) in EQ. apply negb_sym. apply testbit_unique with (2^n-l-1) (-h-1). split. apply lt_succ_r. rewrite sub_1_r, succ_pred. now apply lt_0_sub. apply le_succ_l. rewrite sub_1_r, succ_pred. apply le_sub_le_add_r. rewrite <- (add_0_r (2^n)) at 1. now apply add_le_mono_l. rewrite <- add_sub_swap, sub_1_r. f_equiv. apply opp_inj. rewrite opp_add_distr, opp_sub_distr. rewrite (add_comm _ l), <- add_assoc. rewrite EQ at 1. apply add_cancel_l. rewrite <- opp_add_distr. rewrite <- (mul_1_l (2^n)) at 2. rewrite <- mul_add_distr_r. rewrite <- mul_opp_l. f_equiv. rewrite !opp_add_distr. rewrite <- mul_opp_r. rewrite opp_sub_distr, opp_involutive. rewrite (add_comm h). rewrite mul_add_distr_l. rewrite !add_assoc. apply add_cancel_r. rewrite mul_1_r. rewrite add_comm, add_assoc, !add_opp_r, sub_1_r, two_succ, pred_succ. destruct (-a).[n]; simpl. now rewrite sub_0_r. now nzsimpl'. Qed. (** All bits of number (-1) are 1 *) Lemma bits_m1 : forall n, 0<=n -> (-1).[n] = true. Proof. intros. now rewrite bits_opp, one_succ, pred_succ, bits_0. Qed. (** Various ways to refer to the lowest bit of a number *) Lemma bit0_odd : forall a, a.[0] = odd a. Proof. intros. symmetry. destruct (exists_div2 a) as (a' & b & EQ). rewrite EQ, testbit_0_r, add_comm, odd_add_mul_2. destruct b; simpl; apply odd_1 || apply odd_0. Qed. Lemma bit0_eqb : forall a, a.[0] = eqb (a mod 2) 1. Proof. intros a. rewrite testbit_eqb by order. now nzsimpl. Qed. Lemma bit0_mod : forall a, a.[0] == a mod 2. Proof. intros a. rewrite testbit_spec' by order. now nzsimpl. Qed. (** Hence testing a bit is equivalent to shifting and testing parity *) Lemma testbit_odd : forall a n, a.[n] = odd (a>>n). Proof. intros. now rewrite <- bit0_odd, shiftr_spec, add_0_l. Qed. (** [log2] gives the highest nonzero bit of positive numbers *) Lemma bit_log2 : forall a, 0<a -> a.[log2 a] = true. Proof. intros a Ha. assert (Ha' := log2_nonneg a). destruct (log2_spec_alt a Ha) as (r & EQ & Hr). rewrite EQ at 1. rewrite testbit_true, add_comm by trivial. rewrite <- (mul_1_l (2^log2 a)) at 1. rewrite div_add by order_nz. rewrite div_small; trivial. rewrite add_0_l. apply mod_small. split; order'. Qed. Lemma bits_above_log2 : forall a n, 0<=a -> log2 a < n -> a.[n] = false. Proof. intros a n Ha H. assert (Hn : 0<=n). transitivity (log2 a). apply log2_nonneg. order'. rewrite testbit_false by trivial. rewrite div_small. nzsimpl; order'. split. order. apply log2_lt_cancel. now rewrite log2_pow2. Qed. (** Hence the number of bits of [a] is [1+log2 a] (see [Pos.size_nat] and [Pos.size]). *) (** For negative numbers, things are the other ways around: log2 gives the highest zero bit (for numbers below -1). *) Lemma bit_log2_neg : forall a, a < -1 -> a.[log2 (P (-a))] = false. Proof. intros a Ha. rewrite <- (opp_involutive a) at 1. rewrite bits_opp. apply negb_false_iff. apply bit_log2. apply opp_lt_mono in Ha. rewrite opp_involutive in Ha. apply lt_succ_lt_pred. now rewrite <- one_succ. apply log2_nonneg. Qed. Lemma bits_above_log2_neg : forall a n, a < 0 -> log2 (P (-a)) < n -> a.[n] = true. Proof. intros a n Ha H. assert (Hn : 0<=n). transitivity (log2 (P (-a))). apply log2_nonneg. order'. rewrite <- (opp_involutive a), bits_opp, negb_true_iff by trivial. apply bits_above_log2; trivial. now rewrite <- opp_succ, opp_nonneg_nonpos, le_succ_l. Qed. (** Accesing a high enough bit of a number gives its sign *) Lemma bits_iff_nonneg : forall a n, log2 (abs a) < n -> (0<=a <-> a.[n] = false). Proof. intros a n Hn. split; intros H. rewrite abs_eq in Hn; trivial. now apply bits_above_log2. destruct (le_gt_cases 0 a); trivial. rewrite abs_neq in Hn by order. rewrite bits_above_log2_neg in H; try easy. apply le_lt_trans with (log2 (-a)); trivial. apply log2_le_mono. apply le_pred_l. Qed. Lemma bits_iff_nonneg' : forall a, 0<=a <-> a.[S (log2 (abs a))] = false. Proof. intros. apply bits_iff_nonneg. apply lt_succ_diag_r. Qed. Lemma bits_iff_nonneg_ex : forall a, 0<=a <-> (exists k, forall m, k<m -> a.[m] = false). Proof. intros a. split. intros Ha. exists (log2 a). intros m Hm. now apply bits_above_log2. intros (k,Hk). destruct (le_gt_cases k (log2 (abs a))). now apply bits_iff_nonneg', Hk, lt_succ_r. apply (bits_iff_nonneg a (S k)). now apply lt_succ_r, lt_le_incl. apply Hk. apply lt_succ_diag_r. Qed. Lemma bits_iff_neg : forall a n, log2 (abs a) < n -> (a<0 <-> a.[n] = true). Proof. intros a n Hn. now rewrite lt_nge, <- not_false_iff_true, (bits_iff_nonneg a n). Qed. Lemma bits_iff_neg' : forall a, a<0 <-> a.[S (log2 (abs a))] = true. Proof. intros. apply bits_iff_neg. apply lt_succ_diag_r. Qed. Lemma bits_iff_neg_ex : forall a, a<0 <-> (exists k, forall m, k<m -> a.[m] = true). Proof. intros a. split. intros Ha. exists (log2 (P (-a))). intros m Hm. now apply bits_above_log2_neg. intros (k,Hk). destruct (le_gt_cases k (log2 (abs a))). now apply bits_iff_neg', Hk, lt_succ_r. apply (bits_iff_neg a (S k)). now apply lt_succ_r, lt_le_incl. apply Hk. apply lt_succ_diag_r. Qed. (** Testing bits after division or multiplication by a power of two *) Lemma div2_bits : forall a n, 0<=n -> (a/2).[n] = a.[S n]. Proof. intros a n Hn. apply eq_true_iff_eq. rewrite 2 testbit_true by order_pos. rewrite pow_succ_r by trivial. now rewrite div_div by order_pos. Qed. Lemma div_pow2_bits : forall a n m, 0<=n -> 0<=m -> (a/2^n).[m] = a.[m+n]. Proof. intros a n m Hn. revert a m. apply le_ind with (4:=Hn). solve_proper. intros a m Hm. now nzsimpl. clear n Hn. intros n Hn IH a m Hm. nzsimpl; trivial. rewrite <- div_div by order_pos. now rewrite IH, div2_bits by order_pos. Qed. Lemma double_bits_succ : forall a n, (2*a).[S n] = a.[n]. Proof. intros a n. destruct (le_gt_cases 0 n) as [Hn|Hn]. now rewrite <- div2_bits, mul_comm, div_mul by order'. rewrite (testbit_neg_r a n Hn). apply le_succ_l in Hn. le_elim Hn. now rewrite testbit_neg_r. now rewrite Hn, bit0_odd, odd_mul, odd_2. Qed. Lemma double_bits : forall a n, (2*a).[n] = a.[P n]. Proof. intros a n. rewrite <- (succ_pred n) at 1. apply double_bits_succ. Qed. Lemma mul_pow2_bits_add : forall a n m, 0<=n -> (a*2^n).[n+m] = a.[m]. Proof. intros a n m Hn. revert a m. apply le_ind with (4:=Hn). solve_proper. intros a m. now nzsimpl. clear n Hn. intros n Hn IH a m. nzsimpl; trivial. rewrite mul_assoc, (mul_comm _ 2), <- mul_assoc. now rewrite double_bits_succ. Qed. Lemma mul_pow2_bits : forall a n m, 0<=n -> (a*2^n).[m] = a.[m-n]. Proof. intros. rewrite <- (add_simpl_r m n) at 1. rewrite add_sub_swap, add_comm. now apply mul_pow2_bits_add. Qed. Lemma mul_pow2_bits_low : forall a n m, m<n -> (a*2^n).[m] = false. Proof. intros. destruct (le_gt_cases 0 n). rewrite mul_pow2_bits by trivial. apply testbit_neg_r. now apply lt_sub_0. now rewrite pow_neg_r, mul_0_r, bits_0. Qed. (** Selecting the low part of a number can be done by a modulo *) Lemma mod_pow2_bits_high : forall a n m, 0<=n<=m -> (a mod 2^n).[m] = false. Proof. intros a n m (Hn,H). destruct (mod_pos_bound a (2^n)) as [LE LT]. order_pos. le_elim LE. apply bits_above_log2; try order. apply lt_le_trans with n; trivial. apply log2_lt_pow2; trivial. now rewrite <- LE, bits_0. Qed. Lemma mod_pow2_bits_low : forall a n m, m<n -> (a mod 2^n).[m] = a.[m]. Proof. intros a n m H. destruct (le_gt_cases 0 m) as [Hm|Hm]; [|now rewrite !testbit_neg_r]. rewrite testbit_eqb; trivial. rewrite <- (mod_add _ (2^(P (n-m))*(a/2^n))) by order'. rewrite <- div_add by order_nz. rewrite (mul_comm _ 2), mul_assoc, <- pow_succ_r, succ_pred. rewrite mul_comm, mul_assoc, <- pow_add_r, (add_comm m), sub_add; trivial. rewrite add_comm, <- div_mod by order_nz. symmetry. apply testbit_eqb; trivial. apply le_0_sub; order. now apply lt_le_pred, lt_0_sub. Qed. (** We now prove that having the same bits implies equality. For that we use a notion of equality over functional streams of bits. *) Definition eqf (f g:t -> bool) := forall n:t, f n = g n. Instance eqf_equiv : Equivalence eqf. Proof. split; congruence. Qed. Local Infix "===" := eqf (at level 70, no associativity). Instance testbit_eqf : Proper (eq==>eqf) testbit. Proof. intros a a' Ha n. now rewrite Ha. Qed. (** Only zero corresponds to the always-false stream. *) Lemma bits_inj_0 : forall a, (forall n, a.[n] = false) -> a == 0. Proof. intros a H. destruct (lt_trichotomy a 0) as [Ha|[Ha|Ha]]; trivial. apply (bits_above_log2_neg a (S (log2 (P (-a))))) in Ha. now rewrite H in Ha. apply lt_succ_diag_r. apply bit_log2 in Ha. now rewrite H in Ha. Qed. (** If two numbers produce the same stream of bits, they are equal. *) Lemma bits_inj : forall a b, testbit a === testbit b -> a == b. Proof. assert (AUX : forall n, 0<=n -> forall a b, 0<=a<2^n -> testbit a === testbit b -> a == b). intros n Hn. apply le_ind with (4:=Hn). solve_proper. intros a b Ha H. rewrite pow_0_r, one_succ, lt_succ_r in Ha. assert (Ha' : a == 0) by (destruct Ha; order). rewrite Ha' in *. symmetry. apply bits_inj_0. intros m. now rewrite <- H, bits_0. clear n Hn. intros n Hn IH a b (Ha,Ha') H. rewrite (div_mod a 2), (div_mod b 2) by order'. f_equiv; [ | now rewrite <- 2 bit0_mod, H]. f_equiv. apply IH. split. apply div_pos; order'. apply div_lt_upper_bound. order'. now rewrite <- pow_succ_r. intros m. destruct (le_gt_cases 0 m). rewrite 2 div2_bits by trivial. apply H. now rewrite 2 testbit_neg_r. intros a b H. destruct (le_gt_cases 0 a) as [Ha|Ha]. apply (AUX a); trivial. split; trivial. apply pow_gt_lin_r; order'. apply succ_inj, opp_inj. assert (0 <= - S a). apply opp_le_mono. now rewrite opp_involutive, opp_0, le_succ_l. apply (AUX (-(S a))); trivial. split; trivial. apply pow_gt_lin_r; order'. intros m. destruct (le_gt_cases 0 m). now rewrite 2 bits_opp, 2 pred_succ, H. now rewrite 2 testbit_neg_r. Qed. Lemma bits_inj_iff : forall a b, testbit a === testbit b <-> a == b. Proof. split. apply bits_inj. intros EQ; now rewrite EQ. Qed. (** In fact, checking the bits at positive indexes is enough. *) Lemma bits_inj' : forall a b, (forall n, 0<=n -> a.[n] = b.[n]) -> a == b. Proof. intros a b H. apply bits_inj. intros n. destruct (le_gt_cases 0 n). now apply H. now rewrite 2 testbit_neg_r. Qed. Lemma bits_inj_iff' : forall a b, (forall n, 0<=n -> a.[n] = b.[n]) <-> a == b. Proof. split. apply bits_inj'. intros EQ n Hn; now rewrite EQ. Qed. Ltac bitwise := apply bits_inj'; intros ?m ?Hm; autorewrite with bitwise. Hint Rewrite lxor_spec lor_spec land_spec ldiff_spec bits_0 : bitwise. (** The streams of bits that correspond to a numbers are exactly the ones which are stationary after some point. *) Lemma are_bits : forall (f:t->bool), Proper (eq==>Logic.eq) f -> ((exists n, forall m, 0<=m -> f m = n.[m]) <-> (exists k, forall m, k<=m -> f m = f k)). Proof. intros f Hf. split. intros (a,H). destruct (le_gt_cases 0 a). exists (S (log2 a)). intros m Hm. apply le_succ_l in Hm. rewrite 2 H, 2 bits_above_log2; trivial using lt_succ_diag_r. order_pos. apply le_trans with (log2 a); order_pos. exists (S (log2 (P (-a)))). intros m Hm. apply le_succ_l in Hm. rewrite 2 H, 2 bits_above_log2_neg; trivial using lt_succ_diag_r. order_pos. apply le_trans with (log2 (P (-a))); order_pos. intros (k,Hk). destruct (lt_ge_cases k 0) as [LT|LE]. case_eq (f 0); intros H0. exists (-1). intros m Hm. rewrite bits_m1, Hk by order. symmetry; rewrite <- H0. apply Hk; order. exists 0. intros m Hm. rewrite bits_0, Hk by order. symmetry; rewrite <- H0. apply Hk; order. revert f Hf Hk. apply le_ind with (4:=LE). (* compat : solve_proper fails here *) apply proper_sym_impl_iff. exact eq_sym. clear k LE. intros k k' Hk IH f Hf H. apply IH; trivial. now setoid_rewrite Hk. (* /compat *) intros f Hf H0. destruct (f 0). exists (-1). intros m Hm. now rewrite bits_m1, H0. exists 0. intros m Hm. now rewrite bits_0, H0. clear k LE. intros k LE IH f Hf Hk. destruct (IH (fun m => f (S m))) as (n, Hn). solve_proper. intros m Hm. apply Hk. now rewrite <- succ_le_mono. exists (f 0 + 2*n). intros m Hm. le_elim Hm. rewrite <- (succ_pred m), Hn, <- div2_bits. rewrite mul_comm, div_add, b2z_div2, add_0_l; trivial. order'. now rewrite <- lt_succ_r, succ_pred. now rewrite <- lt_succ_r, succ_pred. rewrite <- Hm. symmetry. apply add_b2z_double_bit0. Qed. (** * Properties of shifts *) (** First, a unified specification for [shiftl] : the [shiftl_spec] below (combined with [testbit_neg_r]) is equivalent to [shiftl_spec_low] and [shiftl_spec_high]. *) Lemma shiftl_spec : forall a n m, 0<=m -> (a << n).[m] = a.[m-n]. Proof. intros. destruct (le_gt_cases n m). now apply shiftl_spec_high. rewrite shiftl_spec_low, testbit_neg_r; trivial. now apply lt_sub_0. Qed. (** A shiftl by a negative number is a shiftr, and vice-versa *) Lemma shiftr_opp_r : forall a n, a >> (-n) == a << n. Proof. intros. bitwise. now rewrite shiftr_spec, shiftl_spec, add_opp_r. Qed. Lemma shiftl_opp_r : forall a n, a << (-n) == a >> n. Proof. intros. bitwise. now rewrite shiftr_spec, shiftl_spec, sub_opp_r. Qed. (** Shifts correspond to multiplication or division by a power of two *) Lemma shiftr_div_pow2 : forall a n, 0<=n -> a >> n == a / 2^n. Proof. intros. bitwise. now rewrite shiftr_spec, div_pow2_bits. Qed. Lemma shiftr_mul_pow2 : forall a n, n<=0 -> a >> n == a * 2^(-n). Proof. intros. bitwise. rewrite shiftr_spec, mul_pow2_bits; trivial. now rewrite sub_opp_r. now apply opp_nonneg_nonpos. Qed. Lemma shiftl_mul_pow2 : forall a n, 0<=n -> a << n == a * 2^n. Proof. intros. bitwise. now rewrite shiftl_spec, mul_pow2_bits. Qed. Lemma shiftl_div_pow2 : forall a n, n<=0 -> a << n == a / 2^(-n). Proof. intros. bitwise. rewrite shiftl_spec, div_pow2_bits; trivial. now rewrite add_opp_r. now apply opp_nonneg_nonpos. Qed. (** Shifts are morphisms *) Instance shiftr_wd : Proper (eq==>eq==>eq) shiftr. Proof. intros a a' Ha n n' Hn. destruct (le_ge_cases n 0) as [H|H]; assert (H':=H); rewrite Hn in H'. now rewrite 2 shiftr_mul_pow2, Ha, Hn. now rewrite 2 shiftr_div_pow2, Ha, Hn. Qed. Instance shiftl_wd : Proper (eq==>eq==>eq) shiftl. Proof. intros a a' Ha n n' Hn. now rewrite <- 2 shiftr_opp_r, Ha, Hn. Qed. (** We could also have specified shiftl with an addition on the left. *) Lemma shiftl_spec_alt : forall a n m, 0<=n -> (a << n).[m+n] = a.[m]. Proof. intros. now rewrite shiftl_mul_pow2, mul_pow2_bits, add_simpl_r. Qed. (** Chaining several shifts. The only case for which there isn't any simple expression is a true shiftr followed by a true shiftl. *) Lemma shiftl_shiftl : forall a n m, 0<=n -> (a << n) << m == a << (n+m). Proof. intros a n p Hn. bitwise. rewrite 2 (shiftl_spec _ _ m) by trivial. rewrite add_comm, sub_add_distr. destruct (le_gt_cases 0 (m-p)) as [H|H]. now rewrite shiftl_spec. rewrite 2 testbit_neg_r; trivial. apply lt_sub_0. now apply lt_le_trans with 0. Qed. Lemma shiftr_shiftl_l : forall a n m, 0<=n -> (a << n) >> m == a << (n-m). Proof. intros. now rewrite <- shiftl_opp_r, shiftl_shiftl, add_opp_r. Qed. Lemma shiftr_shiftl_r : forall a n m, 0<=n -> (a << n) >> m == a >> (m-n). Proof. intros. now rewrite <- 2 shiftl_opp_r, shiftl_shiftl, opp_sub_distr, add_comm. Qed. Lemma shiftr_shiftr : forall a n m, 0<=m -> (a >> n) >> m == a >> (n+m). Proof. intros a n p Hn. bitwise. rewrite 3 shiftr_spec; trivial. now rewrite (add_comm n p), add_assoc. now apply add_nonneg_nonneg. Qed. (** shifts and constants *) Lemma shiftl_1_l : forall n, 1 << n == 2^n. Proof. intros n. destruct (le_gt_cases 0 n). now rewrite shiftl_mul_pow2, mul_1_l. rewrite shiftl_div_pow2, div_1_l, pow_neg_r; try order. apply pow_gt_1. order'. now apply opp_pos_neg. Qed. Lemma shiftl_0_r : forall a, a << 0 == a. Proof. intros. rewrite shiftl_mul_pow2 by order. now nzsimpl. Qed. Lemma shiftr_0_r : forall a, a >> 0 == a. Proof. intros. now rewrite <- shiftl_opp_r, opp_0, shiftl_0_r. Qed. Lemma shiftl_0_l : forall n, 0 << n == 0. Proof. intros. destruct (le_ge_cases 0 n). rewrite shiftl_mul_pow2 by trivial. now nzsimpl. rewrite shiftl_div_pow2 by trivial. rewrite <- opp_nonneg_nonpos in H. nzsimpl; order_nz. Qed. Lemma shiftr_0_l : forall n, 0 >> n == 0. Proof. intros. now rewrite <- shiftl_opp_r, shiftl_0_l. Qed. Lemma shiftl_eq_0_iff : forall a n, 0<=n -> (a << n == 0 <-> a == 0). Proof. intros a n Hn. rewrite shiftl_mul_pow2 by trivial. rewrite eq_mul_0. split. intros [H | H]; trivial. contradict H; order_nz. intros H. now left. Qed. Lemma shiftr_eq_0_iff : forall a n, a >> n == 0 <-> a==0 \/ (0<a /\ log2 a < n). Proof. intros a n. destruct (le_gt_cases 0 n) as [Hn|Hn]. rewrite shiftr_div_pow2, div_small_iff by order_nz. destruct (lt_trichotomy a 0) as [LT|[EQ|LT]]. split. intros [(H,_)|(H,H')]. order. generalize (pow_nonneg 2 n le_0_2); order. intros [H|(H,H')]; order. rewrite EQ. split. now left. intros _; left. split; order_pos. split. intros [(H,H')|(H,H')]; right. split; trivial. apply log2_lt_pow2; trivial. generalize (pow_nonneg 2 n le_0_2); order. intros [H|(H,H')]. order. left. split. order. now apply log2_lt_pow2. rewrite shiftr_mul_pow2 by order. rewrite eq_mul_0. split; intros [H|H]. now left. elim (pow_nonzero 2 (-n)); try apply opp_nonneg_nonpos; order'. now left. destruct H. generalize (log2_nonneg a); order. Qed. Lemma shiftr_eq_0 : forall a n, 0<=a -> log2 a < n -> a >> n == 0. Proof. intros a n Ha H. apply shiftr_eq_0_iff. le_elim Ha. right. now split. now left. Qed. (** Properties of [div2]. *) Lemma div2_div : forall a, div2 a == a/2. Proof. intros. rewrite div2_spec, shiftr_div_pow2. now nzsimpl. order'. Qed. Instance div2_wd : Proper (eq==>eq) div2. Proof. intros a a' Ha. now rewrite 2 div2_div, Ha. Qed. Lemma div2_odd : forall a, a == 2*(div2 a) + odd a. Proof. intros a. rewrite div2_div, <- bit0_odd, bit0_mod. apply div_mod. order'. Qed. (** Properties of [lxor] and others, directly deduced from properties of [xorb] and others. *) Instance lxor_wd : Proper (eq ==> eq ==> eq) lxor. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance land_wd : Proper (eq ==> eq ==> eq) land. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance lor_wd : Proper (eq ==> eq ==> eq) lor. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Instance ldiff_wd : Proper (eq ==> eq ==> eq) ldiff. Proof. intros a a' Ha b b' Hb. bitwise. now rewrite Ha, Hb. Qed. Lemma lxor_eq : forall a a', lxor a a' == 0 -> a == a'. Proof. intros a a' H. bitwise. apply xorb_eq. now rewrite <- lxor_spec, H, bits_0. Qed. Lemma lxor_nilpotent : forall a, lxor a a == 0. Proof. intros. bitwise. apply xorb_nilpotent. Qed. Lemma lxor_eq_0_iff : forall a a', lxor a a' == 0 <-> a == a'. Proof. split. apply lxor_eq. intros EQ; rewrite EQ; apply lxor_nilpotent. Qed. Lemma lxor_0_l : forall a, lxor 0 a == a. Proof. intros. bitwise. apply xorb_false_l. Qed. Lemma lxor_0_r : forall a, lxor a 0 == a. Proof. intros. bitwise. apply xorb_false_r. Qed. Lemma lxor_comm : forall a b, lxor a b == lxor b a. Proof. intros. bitwise. apply xorb_comm. Qed. Lemma lxor_assoc : forall a b c, lxor (lxor a b) c == lxor a (lxor b c). Proof. intros. bitwise. apply xorb_assoc. Qed. Lemma lor_0_l : forall a, lor 0 a == a. Proof. intros. bitwise. trivial. Qed. Lemma lor_0_r : forall a, lor a 0 == a. Proof. intros. bitwise. apply orb_false_r. Qed. Lemma lor_comm : forall a b, lor a b == lor b a. Proof. intros. bitwise. apply orb_comm. Qed. Lemma lor_assoc : forall a b c, lor a (lor b c) == lor (lor a b) c. Proof. intros. bitwise. apply orb_assoc. Qed. Lemma lor_diag : forall a, lor a a == a. Proof. intros. bitwise. apply orb_diag. Qed. Lemma lor_eq_0_l : forall a b, lor a b == 0 -> a == 0. Proof. intros a b H. bitwise. apply (orb_false_iff a.[m] b.[m]). now rewrite <- lor_spec, H, bits_0. Qed. Lemma lor_eq_0_iff : forall a b, lor a b == 0 <-> a == 0 /\ b == 0. Proof. intros a b. split. split. now apply lor_eq_0_l in H. rewrite lor_comm in H. now apply lor_eq_0_l in H. intros (EQ,EQ'). now rewrite EQ, lor_0_l. Qed. Lemma land_0_l : forall a, land 0 a == 0. Proof. intros. bitwise. trivial. Qed. Lemma land_0_r : forall a, land a 0 == 0. Proof. intros. bitwise. apply andb_false_r. Qed. Lemma land_comm : forall a b, land a b == land b a. Proof. intros. bitwise. apply andb_comm. Qed. Lemma land_assoc : forall a b c, land a (land b c) == land (land a b) c. Proof. intros. bitwise. apply andb_assoc. Qed. Lemma land_diag : forall a, land a a == a. Proof. intros. bitwise. apply andb_diag. Qed. Lemma ldiff_0_l : forall a, ldiff 0 a == 0. Proof. intros. bitwise. trivial. Qed. Lemma ldiff_0_r : forall a, ldiff a 0 == a. Proof. intros. bitwise. now rewrite andb_true_r. Qed. Lemma ldiff_diag : forall a, ldiff a a == 0. Proof. intros. bitwise. apply andb_negb_r. Qed. Lemma lor_land_distr_l : forall a b c, lor (land a b) c == land (lor a c) (lor b c). Proof. intros. bitwise. apply orb_andb_distrib_l. Qed. Lemma lor_land_distr_r : forall a b c, lor a (land b c) == land (lor a b) (lor a c). Proof. intros. bitwise. apply orb_andb_distrib_r. Qed. Lemma land_lor_distr_l : forall a b c, land (lor a b) c == lor (land a c) (land b c). Proof. intros. bitwise. apply andb_orb_distrib_l. Qed. Lemma land_lor_distr_r : forall a b c, land a (lor b c) == lor (land a b) (land a c). Proof. intros. bitwise. apply andb_orb_distrib_r. Qed. Lemma ldiff_ldiff_l : forall a b c, ldiff (ldiff a b) c == ldiff a (lor b c). Proof. intros. bitwise. now rewrite negb_orb, andb_assoc. Qed. Lemma lor_ldiff_and : forall a b, lor (ldiff a b) (land a b) == a. Proof. intros. bitwise. now rewrite <- andb_orb_distrib_r, orb_comm, orb_negb_r, andb_true_r. Qed. Lemma land_ldiff : forall a b, land (ldiff a b) b == 0. Proof. intros. bitwise. now rewrite <-andb_assoc, (andb_comm (negb _)), andb_negb_r, andb_false_r. Qed. (** Properties of [setbit] and [clearbit] *) Definition setbit a n := lor a (1 << n). Definition clearbit a n := ldiff a (1 << n). Lemma setbit_spec' : forall a n, setbit a n == lor a (2^n). Proof. intros. unfold setbit. now rewrite shiftl_1_l. Qed. Lemma clearbit_spec' : forall a n, clearbit a n == ldiff a (2^n). Proof. intros. unfold clearbit. now rewrite shiftl_1_l. Qed. Instance setbit_wd : Proper (eq==>eq==>eq) setbit. Proof. unfold setbit. solve_proper. Qed. Instance clearbit_wd : Proper (eq==>eq==>eq) clearbit. Proof. unfold clearbit. solve_proper. Qed. Lemma pow2_bits_true : forall n, 0<=n -> (2^n).[n] = true. Proof. intros. rewrite <- (mul_1_l (2^n)). now rewrite mul_pow2_bits, sub_diag, bit0_odd, odd_1. Qed. Lemma pow2_bits_false : forall n m, n~=m -> (2^n).[m] = false. Proof. intros. destruct (le_gt_cases 0 n); [|now rewrite pow_neg_r, bits_0]. destruct (le_gt_cases n m). rewrite <- (mul_1_l (2^n)), mul_pow2_bits; trivial. rewrite <- (succ_pred (m-n)), <- div2_bits. now rewrite div_small, bits_0 by (split; order'). rewrite <- lt_succ_r, succ_pred, lt_0_sub. order. rewrite <- (mul_1_l (2^n)), mul_pow2_bits_low; trivial. Qed. Lemma pow2_bits_eqb : forall n m, 0<=n -> (2^n).[m] = eqb n m. Proof. intros n m Hn. apply eq_true_iff_eq. rewrite eqb_eq. split. destruct (eq_decidable n m) as [H|H]. trivial. now rewrite (pow2_bits_false _ _ H). intros EQ. rewrite EQ. apply pow2_bits_true; order. Qed. Lemma setbit_eqb : forall a n m, 0<=n -> (setbit a n).[m] = eqb n m || a.[m]. Proof. intros. now rewrite setbit_spec', lor_spec, pow2_bits_eqb, orb_comm. Qed. Lemma setbit_iff : forall a n m, 0<=n -> ((setbit a n).[m] = true <-> n==m \/ a.[m] = true). Proof. intros. now rewrite setbit_eqb, orb_true_iff, eqb_eq. Qed. Lemma setbit_eq : forall a n, 0<=n -> (setbit a n).[n] = true. Proof. intros. apply setbit_iff; trivial. now left. Qed. Lemma setbit_neq : forall a n m, 0<=n -> n~=m -> (setbit a n).[m] = a.[m]. Proof. intros a n m Hn H. rewrite setbit_eqb; trivial. rewrite <- eqb_eq in H. apply not_true_is_false in H. now rewrite H. Qed. Lemma clearbit_eqb : forall a n m, (clearbit a n).[m] = a.[m] && negb (eqb n m). Proof. intros. destruct (le_gt_cases 0 m); [| now rewrite 2 testbit_neg_r]. rewrite clearbit_spec', ldiff_spec. f_equal. f_equal. destruct (le_gt_cases 0 n) as [Hn|Hn]. now apply pow2_bits_eqb. symmetry. rewrite pow_neg_r, bits_0, <- not_true_iff_false, eqb_eq; order. Qed. Lemma clearbit_iff : forall a n m, (clearbit a n).[m] = true <-> a.[m] = true /\ n~=m. Proof. intros. rewrite clearbit_eqb, andb_true_iff, <- eqb_eq. now rewrite negb_true_iff, not_true_iff_false. Qed. Lemma clearbit_eq : forall a n, (clearbit a n).[n] = false. Proof. intros. rewrite clearbit_eqb, (proj2 (eqb_eq _ _) (eq_refl n)). apply andb_false_r. Qed. Lemma clearbit_neq : forall a n m, n~=m -> (clearbit a n).[m] = a.[m]. Proof. intros a n m H. rewrite clearbit_eqb. rewrite <- eqb_eq in H. apply not_true_is_false in H. rewrite H. apply andb_true_r. Qed. (** Shifts of bitwise operations *) Lemma shiftl_lxor : forall a b n, (lxor a b) << n == lxor (a << n) (b << n). Proof. intros. bitwise. now rewrite !shiftl_spec, lxor_spec. Qed. Lemma shiftr_lxor : forall a b n, (lxor a b) >> n == lxor (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec, lxor_spec. Qed. Lemma shiftl_land : forall a b n, (land a b) << n == land (a << n) (b << n). Proof. intros. bitwise. now rewrite !shiftl_spec, land_spec. Qed. Lemma shiftr_land : forall a b n, (land a b) >> n == land (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec, land_spec. Qed. Lemma shiftl_lor : forall a b n, (lor a b) << n == lor (a << n) (b << n). Proof. intros. bitwise. now rewrite !shiftl_spec, lor_spec. Qed. Lemma shiftr_lor : forall a b n, (lor a b) >> n == lor (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec, lor_spec. Qed. Lemma shiftl_ldiff : forall a b n, (ldiff a b) << n == ldiff (a << n) (b << n). Proof. intros. bitwise. now rewrite !shiftl_spec, ldiff_spec. Qed. Lemma shiftr_ldiff : forall a b n, (ldiff a b) >> n == ldiff (a >> n) (b >> n). Proof. intros. bitwise. now rewrite !shiftr_spec, ldiff_spec. Qed. (** For integers, we do have a binary complement function *) Definition lnot a := P (-a). Instance lnot_wd : Proper (eq==>eq) lnot. Proof. unfold lnot. solve_proper. Qed. Lemma lnot_spec : forall a n, 0<=n -> (lnot a).[n] = negb a.[n]. Proof. intros. unfold lnot. rewrite <- (opp_involutive a) at 2. rewrite bits_opp, negb_involutive; trivial. Qed. Lemma lnot_involutive : forall a, lnot (lnot a) == a. Proof. intros a. bitwise. now rewrite 2 lnot_spec, negb_involutive. Qed. Lemma lnot_0 : lnot 0 == -1. Proof. unfold lnot. now rewrite opp_0, <- sub_1_r, sub_0_l. Qed. Lemma lnot_m1 : lnot (-1) == 0. Proof. unfold lnot. now rewrite opp_involutive, one_succ, pred_succ. Qed. (** Complement and other operations *) Lemma lor_m1_r : forall a, lor a (-1) == -1. Proof. intros. bitwise. now rewrite bits_m1, orb_true_r. Qed. Lemma lor_m1_l : forall a, lor (-1) a == -1. Proof. intros. now rewrite lor_comm, lor_m1_r. Qed. Lemma land_m1_r : forall a, land a (-1) == a. Proof. intros. bitwise. now rewrite bits_m1, andb_true_r. Qed. Lemma land_m1_l : forall a, land (-1) a == a. Proof. intros. now rewrite land_comm, land_m1_r. Qed. Lemma ldiff_m1_r : forall a, ldiff a (-1) == 0. Proof. intros. bitwise. now rewrite bits_m1, andb_false_r. Qed. Lemma ldiff_m1_l : forall a, ldiff (-1) a == lnot a. Proof. intros. bitwise. now rewrite lnot_spec, bits_m1. Qed. Lemma lor_lnot_diag : forall a, lor a (lnot a) == -1. Proof. intros a. bitwise. rewrite lnot_spec, bits_m1; trivial. now destruct a.[m]. Qed. Lemma add_lnot_diag : forall a, a + lnot a == -1. Proof. intros a. unfold lnot. now rewrite add_pred_r, add_opp_r, sub_diag, one_succ, opp_succ, opp_0. Qed. Lemma ldiff_land : forall a b, ldiff a b == land a (lnot b). Proof. intros. bitwise. now rewrite lnot_spec. Qed. Lemma land_lnot_diag : forall a, land a (lnot a) == 0. Proof. intros. now rewrite <- ldiff_land, ldiff_diag. Qed. Lemma lnot_lor : forall a b, lnot (lor a b) == land (lnot a) (lnot b). Proof. intros a b. bitwise. now rewrite !lnot_spec, lor_spec, negb_orb. Qed. Lemma lnot_land : forall a b, lnot (land a b) == lor (lnot a) (lnot b). Proof. intros a b. bitwise. now rewrite !lnot_spec, land_spec, negb_andb. Qed. Lemma lnot_ldiff : forall a b, lnot (ldiff a b) == lor (lnot a) b. Proof. intros a b. bitwise. now rewrite !lnot_spec, ldiff_spec, negb_andb, negb_involutive. Qed. Lemma lxor_lnot_lnot : forall a b, lxor (lnot a) (lnot b) == lxor a b. Proof. intros a b. bitwise. now rewrite !lnot_spec, xorb_negb_negb. Qed. Lemma lnot_lxor_l : forall a b, lnot (lxor a b) == lxor (lnot a) b. Proof. intros a b. bitwise. now rewrite !lnot_spec, !lxor_spec, negb_xorb_l. Qed. Lemma lnot_lxor_r : forall a b, lnot (lxor a b) == lxor a (lnot b). Proof. intros a b. bitwise. now rewrite !lnot_spec, !lxor_spec, negb_xorb_r. Qed. Lemma lxor_m1_r : forall a, lxor a (-1) == lnot a. Proof. intros. now rewrite <- (lxor_0_r (lnot a)), <- lnot_m1, lxor_lnot_lnot. Qed. Lemma lxor_m1_l : forall a, lxor (-1) a == lnot a. Proof. intros. now rewrite lxor_comm, lxor_m1_r. Qed. Lemma lxor_lor : forall a b, land a b == 0 -> lxor a b == lor a b. Proof. intros a b H. bitwise. assert (a.[m] && b.[m] = false) by now rewrite <- land_spec, H, bits_0. now destruct a.[m], b.[m]. Qed. Lemma lnot_shiftr : forall a n, 0<=n -> lnot (a >> n) == (lnot a) >> n. Proof. intros a n Hn. bitwise. now rewrite lnot_spec, 2 shiftr_spec, lnot_spec by order_pos. Qed. (** [(ones n)] is [2^n-1], the number with [n] digits 1 *) Definition ones n := P (1<<n). Instance ones_wd : Proper (eq==>eq) ones. Proof. unfold ones. solve_proper. Qed. Lemma ones_equiv : forall n, ones n == P (2^n). Proof. intros. unfold ones. destruct (le_gt_cases 0 n). now rewrite shiftl_mul_pow2, mul_1_l. f_equiv. rewrite pow_neg_r; trivial. rewrite <- shiftr_opp_r. apply shiftr_eq_0_iff. right; split. order'. rewrite log2_1. now apply opp_pos_neg. Qed. Lemma ones_add : forall n m, 0<=n -> 0<=m -> ones (m+n) == 2^m * ones n + ones m. Proof. intros n m Hn Hm. rewrite !ones_equiv. rewrite <- !sub_1_r, mul_sub_distr_l, mul_1_r, <- pow_add_r by trivial. rewrite add_sub_assoc, sub_add. reflexivity. Qed. Lemma ones_div_pow2 : forall n m, 0<=m<=n -> ones n / 2^m == ones (n-m). Proof. intros n m (Hm,H). symmetry. apply div_unique with (ones m). left. rewrite ones_equiv. split. rewrite <- lt_succ_r, succ_pred. order_pos. now rewrite <- le_succ_l, succ_pred. rewrite <- (sub_add m n) at 1. rewrite (add_comm _ m). apply ones_add; trivial. now apply le_0_sub. Qed. Lemma ones_mod_pow2 : forall n m, 0<=m<=n -> (ones n) mod (2^m) == ones m. Proof. intros n m (Hm,H). symmetry. apply mod_unique with (ones (n-m)). left. rewrite ones_equiv. split. rewrite <- lt_succ_r, succ_pred. order_pos. now rewrite <- le_succ_l, succ_pred. rewrite <- (sub_add m n) at 1. rewrite (add_comm _ m). apply ones_add; trivial. now apply le_0_sub. Qed. Lemma ones_spec_low : forall n m, 0<=m<n -> (ones n).[m] = true. Proof. intros n m (Hm,H). apply testbit_true; trivial. rewrite ones_div_pow2 by (split; order). rewrite <- (pow_1_r 2). rewrite ones_mod_pow2. rewrite ones_equiv. now nzsimpl'. split. order'. apply le_add_le_sub_r. nzsimpl. now apply le_succ_l. Qed. Lemma ones_spec_high : forall n m, 0<=n<=m -> (ones n).[m] = false. Proof. intros n m (Hn,H). le_elim Hn. apply bits_above_log2; rewrite ones_equiv. rewrite <-lt_succ_r, succ_pred; order_pos. rewrite log2_pred_pow2; trivial. now rewrite <-le_succ_l, succ_pred. rewrite ones_equiv. now rewrite <- Hn, pow_0_r, one_succ, pred_succ, bits_0. Qed. Lemma ones_spec_iff : forall n m, 0<=n -> ((ones n).[m] = true <-> 0<=m<n). Proof. intros n m Hn. split. intros H. destruct (lt_ge_cases m 0) as [Hm|Hm]. now rewrite testbit_neg_r in H. split; trivial. apply lt_nge. intro H'. rewrite ones_spec_high in H. discriminate. now split. apply ones_spec_low. Qed. Lemma lor_ones_low : forall a n, 0<=a -> log2 a < n -> lor a (ones n) == ones n. Proof. intros a n Ha H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, bits_above_log2; try split; trivial. now apply lt_le_trans with n. apply le_trans with (log2 a); order_pos. rewrite ones_spec_low, orb_true_r; try split; trivial. Qed. Lemma land_ones : forall a n, 0<=n -> land a (ones n) == a mod 2^n. Proof. intros a n Hn. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, mod_pow2_bits_high, andb_false_r; try split; trivial. rewrite ones_spec_low, mod_pow2_bits_low, andb_true_r; try split; trivial. Qed. Lemma land_ones_low : forall a n, 0<=a -> log2 a < n -> land a (ones n) == a. Proof. intros a n Ha H. assert (Hn : 0<=n) by (generalize (log2_nonneg a); order). rewrite land_ones; trivial. apply mod_small. split; trivial. apply log2_lt_cancel. now rewrite log2_pow2. Qed. Lemma ldiff_ones_r : forall a n, 0<=n -> ldiff a (ones n) == (a >> n) << n. Proof. intros a n Hn. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, shiftl_spec_high, shiftr_spec; trivial. rewrite sub_add; trivial. apply andb_true_r. now apply le_0_sub. now split. rewrite ones_spec_low, shiftl_spec_low, andb_false_r; try split; trivial. Qed. Lemma ldiff_ones_r_low : forall a n, 0<=a -> log2 a < n -> ldiff a (ones n) == 0. Proof. intros a n Ha H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. split; trivial. now apply le_trans with (log2 a); order_pos. rewrite ones_spec_low, andb_false_r; try split; trivial. Qed. Lemma ldiff_ones_l_low : forall a n, 0<=a -> log2 a < n -> ldiff (ones n) a == lxor a (ones n). Proof. intros a n Ha H. bitwise. destruct (le_gt_cases n m). rewrite ones_spec_high, bits_above_log2; trivial. now apply lt_le_trans with n. split; trivial. now apply le_trans with (log2 a); order_pos. rewrite ones_spec_low, xorb_true_r; try split; trivial. Qed. (** Bitwise operations and sign *) Lemma shiftl_nonneg : forall a n, 0 <= (a << n) <-> 0 <= a. Proof. intros a n. destruct (le_ge_cases 0 n) as [Hn|Hn]. (* 0<=n *) rewrite 2 bits_iff_nonneg_ex. split; intros (k,Hk). exists (k-n). intros m Hm. destruct (le_gt_cases 0 m); [|now rewrite testbit_neg_r]. rewrite <- (add_simpl_r m n), <- (shiftl_spec a n) by order_pos. apply Hk. now apply lt_sub_lt_add_r. exists (k+n). intros m Hm. destruct (le_gt_cases 0 m); [|now rewrite testbit_neg_r]. rewrite shiftl_spec by trivial. apply Hk. now apply lt_add_lt_sub_r. (* n<=0*) rewrite <- shiftr_opp_r, 2 bits_iff_nonneg_ex. split; intros (k,Hk). destruct (le_gt_cases 0 k). exists (k-n). intros m Hm. apply lt_sub_lt_add_r in Hm. rewrite <- (add_simpl_r m n), <- add_opp_r, <- (shiftr_spec a (-n)). now apply Hk. order. assert (EQ : a >> (-n) == 0). apply bits_inj'. intros m Hm. rewrite bits_0. apply Hk; order. apply shiftr_eq_0_iff in EQ. rewrite <- bits_iff_nonneg_ex. destruct EQ as [EQ|[LT _]]; order. exists (k+n). intros m Hm. destruct (le_gt_cases 0 m); [|now rewrite testbit_neg_r]. rewrite shiftr_spec by trivial. apply Hk. rewrite add_opp_r. now apply lt_add_lt_sub_r. Qed. Lemma shiftl_neg : forall a n, (a << n) < 0 <-> a < 0. Proof. intros a n. now rewrite 2 lt_nge, shiftl_nonneg. Qed. Lemma shiftr_nonneg : forall a n, 0 <= (a >> n) <-> 0 <= a. Proof. intros. rewrite <- shiftl_opp_r. apply shiftl_nonneg. Qed. Lemma shiftr_neg : forall a n, (a >> n) < 0 <-> a < 0. Proof. intros a n. now rewrite 2 lt_nge, shiftr_nonneg. Qed. Lemma div2_nonneg : forall a, 0 <= div2 a <-> 0 <= a. Proof. intros. rewrite div2_spec. apply shiftr_nonneg. Qed. Lemma div2_neg : forall a, div2 a < 0 <-> a < 0. Proof. intros a. now rewrite 2 lt_nge, div2_nonneg. Qed. Lemma lor_nonneg : forall a b, 0 <= lor a b <-> 0<=a /\ 0<=b. Proof. intros a b. rewrite 3 bits_iff_nonneg_ex. split. intros (k,Hk). split; exists k; intros m Hm; apply (orb_false_elim a.[m] b.[m]); rewrite <- lor_spec; now apply Hk. intros ((k,Hk),(k',Hk')). destruct (le_ge_cases k k'); [ exists k' | exists k ]; intros m Hm; rewrite lor_spec, Hk, Hk'; trivial; order. Qed. Lemma lor_neg : forall a b, lor a b < 0 <-> a < 0 \/ b < 0. Proof. intros a b. rewrite 3 lt_nge, lor_nonneg. split. apply not_and. apply le_decidable. now intros [H|H] (H',H''). Qed. Lemma lnot_nonneg : forall a, 0 <= lnot a <-> a < 0. Proof. intros a; unfold lnot. now rewrite <- opp_succ, opp_nonneg_nonpos, le_succ_l. Qed. Lemma lnot_neg : forall a, lnot a < 0 <-> 0 <= a. Proof. intros a. now rewrite le_ngt, lt_nge, lnot_nonneg. Qed. Lemma land_nonneg : forall a b, 0 <= land a b <-> 0<=a \/ 0<=b. Proof. intros a b. now rewrite <- (lnot_involutive (land a b)), lnot_land, lnot_nonneg, lor_neg, !lnot_neg. Qed. Lemma land_neg : forall a b, land a b < 0 <-> a < 0 /\ b < 0. Proof. intros a b. now rewrite <- (lnot_involutive (land a b)), lnot_land, lnot_neg, lor_nonneg, !lnot_nonneg. Qed. Lemma ldiff_nonneg : forall a b, 0 <= ldiff a b <-> 0<=a \/ b<0. Proof. intros. now rewrite ldiff_land, land_nonneg, lnot_nonneg. Qed. Lemma ldiff_neg : forall a b, ldiff a b < 0 <-> a<0 /\ 0<=b. Proof. intros. now rewrite ldiff_land, land_neg, lnot_neg. Qed. Lemma lxor_nonneg : forall a b, 0 <= lxor a b <-> (0<=a <-> 0<=b). Proof. assert (H : forall a b, 0<=a -> 0<=b -> 0<=lxor a b). intros a b. rewrite 3 bits_iff_nonneg_ex. intros (k,Hk) (k', Hk'). destruct (le_ge_cases k k'); [ exists k' | exists k]; intros m Hm; rewrite lxor_spec, Hk, Hk'; trivial; order. assert (H' : forall a b, 0<=a -> b<0 -> lxor a b<0). intros a b. rewrite bits_iff_nonneg_ex, 2 bits_iff_neg_ex. intros (k,Hk) (k', Hk'). destruct (le_ge_cases k k'); [ exists k' | exists k]; intros m Hm; rewrite lxor_spec, Hk, Hk'; trivial; order. intros a b. split. intros Hab. split. intros Ha. destruct (le_gt_cases 0 b) as [Hb|Hb]; trivial. generalize (H' _ _ Ha Hb). order. intros Hb. destruct (le_gt_cases 0 a) as [Ha|Ha]; trivial. generalize (H' _ _ Hb Ha). rewrite lxor_comm. order. intros E. destruct (le_gt_cases 0 a) as [Ha|Ha]. apply H; trivial. apply E; trivial. destruct (le_gt_cases 0 b) as [Hb|Hb]. apply H; trivial. apply E; trivial. rewrite <- lxor_lnot_lnot. apply H; now apply lnot_nonneg. Qed. (** Bitwise operations and log2 *) Lemma log2_bits_unique : forall a n, a.[n] = true -> (forall m, n<m -> a.[m] = false) -> log2 a == n. Proof. intros a n H H'. destruct (lt_trichotomy a 0) as [Ha|[Ha|Ha]]. (* a < 0 *) destruct (proj1 (bits_iff_neg_ex a) Ha) as (k,Hk). destruct (le_gt_cases n k). specialize (Hk (S k) (lt_succ_diag_r _)). rewrite H' in Hk. discriminate. apply lt_succ_r; order. specialize (H' (S n) (lt_succ_diag_r _)). rewrite Hk in H'. discriminate. apply lt_succ_r; order. (* a = 0 *) now rewrite Ha, bits_0 in H. (* 0 < a *) apply le_antisymm; apply le_ngt; intros LT. specialize (H' _ LT). now rewrite bit_log2 in H'. now rewrite bits_above_log2 in H by order. Qed. Lemma log2_shiftr : forall a n, 0<a -> log2 (a >> n) == max 0 (log2 a - n). Proof. intros a n Ha. destruct (le_gt_cases 0 (log2 a - n)); [rewrite max_r | rewrite max_l]; try order. apply log2_bits_unique. now rewrite shiftr_spec, sub_add, bit_log2. intros m Hm. destruct (le_gt_cases 0 m); [|now rewrite testbit_neg_r]. rewrite shiftr_spec; trivial. apply bits_above_log2; try order. now apply lt_sub_lt_add_r. rewrite lt_sub_lt_add_r, add_0_l in H. apply log2_nonpos. apply le_lteq; right. apply shiftr_eq_0_iff. right. now split. Qed. Lemma log2_shiftl : forall a n, 0<a -> 0<=n -> log2 (a << n) == log2 a + n. Proof. intros a n Ha Hn. rewrite shiftl_mul_pow2, add_comm by trivial. now apply log2_mul_pow2. Qed. Lemma log2_shiftl' : forall a n, 0<a -> log2 (a << n) == max 0 (log2 a + n). Proof. intros a n Ha. rewrite <- shiftr_opp_r, log2_shiftr by trivial. destruct (le_gt_cases 0 (log2 a + n)); [rewrite 2 max_r | rewrite 2 max_l]; rewrite ?sub_opp_r; try order. Qed. Lemma log2_lor : forall a b, 0<=a -> 0<=b -> log2 (lor a b) == max (log2 a) (log2 b). Proof. assert (AUX : forall a b, 0<=a -> a<=b -> log2 (lor a b) == log2 b). intros a b Ha H. le_elim Ha; [|now rewrite <- Ha, lor_0_l]. apply log2_bits_unique. now rewrite lor_spec, bit_log2, orb_true_r by order. intros m Hm. assert (H' := log2_le_mono _ _ H). now rewrite lor_spec, 2 bits_above_log2 by order. (* main *) intros a b Ha Hb. destruct (le_ge_cases a b) as [H|H]. rewrite max_r by now apply log2_le_mono. now apply AUX. rewrite max_l by now apply log2_le_mono. rewrite lor_comm. now apply AUX. Qed. Lemma log2_land : forall a b, 0<=a -> 0<=b -> log2 (land a b) <= min (log2 a) (log2 b). Proof. assert (AUX : forall a b, 0<=a -> a<=b -> log2 (land a b) <= log2 a). intros a b Ha Hb. apply le_ngt. intros LT. assert (H : 0 <= land a b) by (apply land_nonneg; now left). le_elim H. generalize (bit_log2 (land a b) H). now rewrite land_spec, bits_above_log2. rewrite <- H in LT. apply log2_lt_cancel in LT; order. (* main *) intros a b Ha Hb. destruct (le_ge_cases a b) as [H|H]. rewrite min_l by now apply log2_le_mono. now apply AUX. rewrite min_r by now apply log2_le_mono. rewrite land_comm. now apply AUX. Qed. Lemma log2_lxor : forall a b, 0<=a -> 0<=b -> log2 (lxor a b) <= max (log2 a) (log2 b). Proof. assert (AUX : forall a b, 0<=a -> a<=b -> log2 (lxor a b) <= log2 b). intros a b Ha Hb. apply le_ngt. intros LT. assert (H : 0 <= lxor a b) by (apply lxor_nonneg; split; order). le_elim H. generalize (bit_log2 (lxor a b) H). rewrite lxor_spec, 2 bits_above_log2; try order. discriminate. apply le_lt_trans with (log2 b); trivial. now apply log2_le_mono. rewrite <- H in LT. apply log2_lt_cancel in LT; order. (* main *) intros a b Ha Hb. destruct (le_ge_cases a b) as [H|H]. rewrite max_r by now apply log2_le_mono. now apply AUX. rewrite max_l by now apply log2_le_mono. rewrite lxor_comm. now apply AUX. Qed. (** Bitwise operations and arithmetical operations *) Local Notation xor3 a b c := (xorb (xorb a b) c). Local Notation lxor3 a b c := (lxor (lxor a b) c). Local Notation nextcarry a b c := ((a&&b) || (c && (a||b))). Local Notation lnextcarry a b c := (lor (land a b) (land c (lor a b))). Lemma add_bit0 : forall a b, (a+b).[0] = xorb a.[0] b.[0]. Proof. intros. now rewrite !bit0_odd, odd_add. Qed. Lemma add3_bit0 : forall a b c, (a+b+c).[0] = xor3 a.[0] b.[0] c.[0]. Proof. intros. now rewrite !add_bit0. Qed. Lemma add3_bits_div2 : forall (a0 b0 c0 : bool), (a0 + b0 + c0)/2 == nextcarry a0 b0 c0. Proof. assert (H : 1+1 == 2) by now nzsimpl'. intros [|] [|] [|]; simpl; rewrite ?add_0_l, ?add_0_r, ?H; (apply div_same; order') || (apply div_small; split; order') || idtac. symmetry. apply div_unique with 1. left; split; order'. now nzsimpl'. Qed. Lemma add_carry_div2 : forall a b (c0:bool), (a + b + c0)/2 == a/2 + b/2 + nextcarry a.[0] b.[0] c0. Proof. intros. rewrite <- add3_bits_div2. rewrite (add_comm ((a/2)+_)). rewrite <- div_add by order'. f_equiv. rewrite <- !div2_div, mul_comm, mul_add_distr_l. rewrite (div2_odd a), <- bit0_odd at 1. rewrite (div2_odd b), <- bit0_odd at 1. rewrite add_shuffle1. rewrite <-(add_assoc _ _ c0). apply add_comm. Qed. (** The main result concerning addition: we express the bits of the sum in term of bits of [a] and [b] and of some carry stream which is also recursively determined by another equation. *) Lemma add_carry_bits_aux : forall n, 0<=n -> forall a b (c0:bool), -(2^n) <= a < 2^n -> -(2^n) <= b < 2^n -> exists c, a+b+c0 == lxor3 a b c /\ c/2 == lnextcarry a b c /\ c.[0] = c0. Proof. intros n Hn. apply le_ind with (4:=Hn). solve_proper. (* base *) intros a b c0. rewrite !pow_0_r, !one_succ, !lt_succ_r, <- !one_succ. intros (Ha1,Ha2) (Hb1,Hb2). le_elim Ha1; rewrite <- ?le_succ_l, ?succ_m1 in Ha1; le_elim Hb1; rewrite <- ?le_succ_l, ?succ_m1 in Hb1. (* base, a = 0, b = 0 *) exists c0. rewrite (le_antisymm _ _ Ha2 Ha1), (le_antisymm _ _ Hb2 Hb1). rewrite !add_0_l, !lxor_0_l, !lor_0_r, !land_0_r, !lor_0_r. rewrite b2z_div2, b2z_bit0; now repeat split. (* base, a = 0, b = -1 *) exists (-c0). rewrite <- Hb1, (le_antisymm _ _ Ha2 Ha1). repeat split. rewrite add_0_l, lxor_0_l, lxor_m1_l. unfold lnot. now rewrite opp_involutive, add_comm, add_opp_r, sub_1_r. rewrite land_0_l, !lor_0_l, land_m1_r. symmetry. apply div_unique with c0. left; destruct c0; simpl; split; order'. now rewrite two_succ, mul_succ_l, mul_1_l, add_opp_r, sub_add. rewrite bit0_odd, odd_opp; destruct c0; simpl; apply odd_1 || apply odd_0. (* base, a = -1, b = 0 *) exists (-c0). rewrite <- Ha1, (le_antisymm _ _ Hb2 Hb1). repeat split. rewrite add_0_r, lxor_0_r, lxor_m1_l. unfold lnot. now rewrite opp_involutive, add_comm, add_opp_r, sub_1_r. rewrite land_0_r, lor_0_r, lor_0_l, land_m1_r. symmetry. apply div_unique with c0. left; destruct c0; simpl; split; order'. now rewrite two_succ, mul_succ_l, mul_1_l, add_opp_r, sub_add. rewrite bit0_odd, odd_opp; destruct c0; simpl; apply odd_1 || apply odd_0. (* base, a = -1, b = -1 *) exists (c0 + 2*(-1)). rewrite <- Ha1, <- Hb1. repeat split. rewrite lxor_m1_l, lnot_m1, lxor_0_l. now rewrite two_succ, mul_succ_l, mul_1_l, add_comm, add_assoc. rewrite land_m1_l, lor_m1_l. apply add_b2z_double_div2. apply add_b2z_double_bit0. (* step *) clear n Hn. intros n Hn IH a b c0 Ha Hb. set (c1:=nextcarry a.[0] b.[0] c0). destruct (IH (a/2) (b/2) c1) as (c & IH1 & IH2 & Hc); clear IH. split. apply div_le_lower_bound. order'. now rewrite mul_opp_r, <- pow_succ_r. apply div_lt_upper_bound. order'. now rewrite <- pow_succ_r. split. apply div_le_lower_bound. order'. now rewrite mul_opp_r, <- pow_succ_r. apply div_lt_upper_bound. order'. now rewrite <- pow_succ_r. exists (c0 + 2*c). repeat split. (* step, add *) bitwise. le_elim Hm. rewrite <- (succ_pred m), lt_succ_r in Hm. rewrite <- (succ_pred m), <- !div2_bits, <- 2 lxor_spec by trivial. f_equiv. rewrite add_b2z_double_div2, <- IH1. apply add_carry_div2. rewrite <- Hm. now rewrite add_b2z_double_bit0, add3_bit0, b2z_bit0. (* step, carry *) rewrite add_b2z_double_div2. bitwise. le_elim Hm. rewrite <- (succ_pred m), lt_succ_r in Hm. rewrite <- (succ_pred m), <- !div2_bits, IH2 by trivial. autorewrite with bitwise. now rewrite add_b2z_double_div2. rewrite <- Hm. now rewrite add_b2z_double_bit0. (* step, carry0 *) apply add_b2z_double_bit0. Qed. Lemma add_carry_bits : forall a b (c0:bool), exists c, a+b+c0 == lxor3 a b c /\ c/2 == lnextcarry a b c /\ c.[0] = c0. Proof. intros a b c0. set (n := max (abs a) (abs b)). apply (add_carry_bits_aux n). (* positivity *) unfold n. destruct (le_ge_cases (abs a) (abs b)); [rewrite max_r|rewrite max_l]; order_pos'. (* bound for a *) assert (Ha : abs a < 2^n). apply lt_le_trans with (2^(abs a)). apply pow_gt_lin_r; order_pos'. apply pow_le_mono_r. order'. unfold n. destruct (le_ge_cases (abs a) (abs b)); [rewrite max_r|rewrite max_l]; try order. apply abs_lt in Ha. destruct Ha; split; order. (* bound for b *) assert (Hb : abs b < 2^n). apply lt_le_trans with (2^(abs b)). apply pow_gt_lin_r; order_pos'. apply pow_le_mono_r. order'. unfold n. destruct (le_ge_cases (abs a) (abs b)); [rewrite max_r|rewrite max_l]; try order. apply abs_lt in Hb. destruct Hb; split; order. Qed. (** Particular case : the second bit of an addition *) Lemma add_bit1 : forall a b, (a+b).[1] = xor3 a.[1] b.[1] (a.[0] && b.[0]). Proof. intros a b. destruct (add_carry_bits a b false) as (c & EQ1 & EQ2 & Hc). simpl in EQ1; rewrite add_0_r in EQ1. rewrite EQ1. autorewrite with bitwise. f_equal. rewrite one_succ, <- div2_bits, EQ2 by order. autorewrite with bitwise. rewrite Hc. simpl. apply orb_false_r. Qed. (** In an addition, there will be no carries iff there is no common bits in the numbers to add *) Lemma nocarry_equiv : forall a b c, c/2 == lnextcarry a b c -> c.[0] = false -> (c == 0 <-> land a b == 0). Proof. intros a b c H H'. split. intros EQ; rewrite EQ in *. rewrite div_0_l in H by order'. symmetry in H. now apply lor_eq_0_l in H. intros EQ. rewrite EQ, lor_0_l in H. apply bits_inj'. intros n Hn. rewrite bits_0. apply le_ind with (4:=Hn). solve_proper. trivial. clear n Hn. intros n Hn IH. rewrite <- div2_bits, H; trivial. autorewrite with bitwise. now rewrite IH. Qed. (** When there is no common bits, the addition is just a xor *) Lemma add_nocarry_lxor : forall a b, land a b == 0 -> a+b == lxor a b. Proof. intros a b H. destruct (add_carry_bits a b false) as (c & EQ1 & EQ2 & Hc). simpl in EQ1; rewrite add_0_r in EQ1. rewrite EQ1. apply (nocarry_equiv a b c) in H; trivial. rewrite H. now rewrite lxor_0_r. Qed. (** A null [ldiff] implies being smaller *) Lemma ldiff_le : forall a b, 0<=b -> ldiff a b == 0 -> 0 <= a <= b. Proof. assert (AUX : forall n, 0<=n -> forall a b, 0 <= a < 2^n -> 0<=b -> ldiff a b == 0 -> a <= b). intros n Hn. apply le_ind with (4:=Hn); clear n Hn. solve_proper. intros a b Ha Hb _. rewrite pow_0_r, one_succ, lt_succ_r in Ha. setoid_replace a with 0 by (destruct Ha; order'); trivial. intros n Hn IH a b (Ha,Ha') Hb H. assert (NEQ : 2 ~= 0) by order'. rewrite (div_mod a 2 NEQ), (div_mod b 2 NEQ). apply add_le_mono. apply mul_le_mono_pos_l; try order'. apply IH. split. apply div_pos; order'. apply div_lt_upper_bound; try order'. now rewrite <- pow_succ_r. apply div_pos; order'. rewrite <- (pow_1_r 2), <- 2 shiftr_div_pow2 by order'. rewrite <- shiftr_ldiff, H, shiftr_div_pow2, pow_1_r, div_0_l; order'. rewrite <- 2 bit0_mod. apply bits_inj_iff in H. specialize (H 0). rewrite ldiff_spec, bits_0 in H. destruct a.[0], b.[0]; try discriminate; simpl; order'. (* main *) intros a b Hb Hd. assert (Ha : 0<=a). apply le_ngt; intros Ha'. apply (lt_irrefl 0). rewrite <- Hd at 1. apply ldiff_neg. now split. split; trivial. apply (AUX a); try split; trivial. apply pow_gt_lin_r; order'. Qed. (** Subtraction can be a ldiff when the opposite ldiff is null. *) Lemma sub_nocarry_ldiff : forall a b, ldiff b a == 0 -> a-b == ldiff a b. Proof. intros a b H. apply add_cancel_r with b. rewrite sub_add. symmetry. rewrite add_nocarry_lxor; trivial. bitwise. apply bits_inj_iff in H. specialize (H m). rewrite ldiff_spec, bits_0 in H. now destruct a.[m], b.[m]. apply land_ldiff. Qed. (** Adding numbers with no common bits cannot lead to a much bigger number *) Lemma add_nocarry_lt_pow2 : forall a b n, land a b == 0 -> a < 2^n -> b < 2^n -> a+b < 2^n. Proof. intros a b n H Ha Hb. destruct (le_gt_cases a 0) as [Ha'|Ha']. apply le_lt_trans with (0+b). now apply add_le_mono_r. now nzsimpl. destruct (le_gt_cases b 0) as [Hb'|Hb']. apply le_lt_trans with (a+0). now apply add_le_mono_l. now nzsimpl. rewrite add_nocarry_lxor by order. destruct (lt_ge_cases 0 (lxor a b)); [|apply le_lt_trans with 0; order_pos]. apply log2_lt_pow2; trivial. apply log2_lt_pow2 in Ha; trivial. apply log2_lt_pow2 in Hb; trivial. apply le_lt_trans with (max (log2 a) (log2 b)). apply log2_lxor; order. destruct (le_ge_cases (log2 a) (log2 b)); [rewrite max_r|rewrite max_l]; order. Qed. Lemma add_nocarry_mod_lt_pow2 : forall a b n, 0<=n -> land a b == 0 -> a mod 2^n + b mod 2^n < 2^n. Proof. intros a b n Hn H. apply add_nocarry_lt_pow2. bitwise. destruct (le_gt_cases n m). rewrite mod_pow2_bits_high; now split. now rewrite !mod_pow2_bits_low, <- land_spec, H, bits_0. apply mod_pos_bound; order_pos. apply mod_pos_bound; order_pos. Qed. End ZBitsProp.
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_128.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Receives data from the rx_engine and buffers the output // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_128 #( parameter C_DATA_WIDTH = 9'd128, parameter C_MAIN_FIFO_DEPTH = 1024, parameter C_SG_FIFO_DEPTH = 512, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_MAIN_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_MAIN_FIFO_DEPTH))+1), parameter C_SG_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_SG_FIFO_DEPTH))+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B output SG_RX_BUF_RECVD, // Scatter gather RX buffer completely read (ready for next if applicable) input [31:0] SG_RX_BUF_DATA, // Scatter gather RX buffer data input SG_RX_BUF_LEN_VALID, // Scatter gather RX buffer length valid input SG_RX_BUF_ADDR_HI_VALID, // Scatter gather RX buffer high address valid input SG_RX_BUF_ADDR_LO_VALID, // Scatter gather RX buffer low address valid output SG_TX_BUF_RECVD, // Scatter gather TX buffer completely read (ready for next if applicable) input [31:0] SG_TX_BUF_DATA, // Scatter gather TX buffer data input SG_TX_BUF_LEN_VALID, // Scatter gather TX buffer length valid input SG_TX_BUF_ADDR_HI_VALID, // Scatter gather TX buffer high address valid input SG_TX_BUF_ADDR_LO_VALID, // Scatter gather TX buffer low address valid output [C_DATA_WIDTH-1:0] SG_DATA, // Scatter gather TX buffer data output SG_DATA_EMPTY, // Scatter gather TX buffer data empty input SG_DATA_REN, // Scatter gather TX buffer data read enable input SG_RST, // Scatter gather TX buffer data reset output SG_ERR, // Scatter gather TX encountered an error input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done input TXN_DONE_ACK, // Read transaction actual transfer length read output RX_REQ, // Read request input RX_REQ_ACK, // Read request accepted output [1:0] RX_REQ_TAG, // Read request data tag output [63:0] RX_REQ_ADDR, // Read request address output [9:0] RX_REQ_LEN, // Read request length input [C_DATA_WIDTH-1:0] MAIN_DATA, // Main incoming data input [C_DATA_WORD_WIDTH-1:0] MAIN_DATA_EN, // Main incoming data enable input MAIN_DONE, // Main incoming data complete input MAIN_ERR, // Main incoming data completed with error input [C_DATA_WIDTH-1:0] SG_RX_DATA, // Scatter gather for RX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_RX_DATA_EN, // Scatter gather for RX incoming data enable input SG_RX_DONE, // Scatter gather for RX incoming data complete input SG_RX_ERR, // Scatter gather for RX incoming data completed with error input [C_DATA_WIDTH-1:0] SG_TX_DATA, // Scatter gather for TX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_TX_DATA_EN, // Scatter gather for TX incoming data enable input SG_TX_DONE, // Scatter gather for TX incoming data complete input SG_TX_ERR, // Scatter gather for TX incoming data completed with error input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal input CHNL_RX_ACK, // Channle read received signal output CHNL_RX_LAST, // Channel last read output [31:0] CHNL_RX_LEN, // Channel read length output [30:0] CHNL_RX_OFF, // Channel read offset output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data output CHNL_RX_DATA_VALID, // Channel read data valid input CHNL_RX_DATA_REN // Channel read data has been recieved ); `include "functions.vh" wire [C_DATA_WIDTH-1:0] wPackedMainData; wire wPackedMainWen; wire wPackedMainDone; wire wPackedMainErr; wire wMainFlush; wire wMainFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgRxData; wire wPackedSgRxWen; wire wPackedSgRxDone; wire wPackedSgRxErr; wire wSgRxFlush; wire wSgRxFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgTxData; wire wPackedSgTxWen; wire wPackedSgTxDone; wire wPackedSgTxErr; wire wSgTxFlush; wire wSgTxFlushed; wire wMainDataRen; wire wMainDataEmpty; wire [C_DATA_WIDTH-1:0] wMainData; wire wSgRxRst; wire wSgRxDataRen; wire wSgRxDataEmpty; wire [C_DATA_WIDTH-1:0] wSgRxData; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgRxFifoCount; wire wSgTxRst; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgTxFifoCount; wire wSgRxReq; wire [63:0] wSgRxReqAddr; wire [9:0] wSgRxReqLen; wire wSgTxReq; wire [63:0] wSgTxReqAddr; wire [9:0] wSgTxReqLen; wire wSgRxReqProc; wire wSgTxReqProc; wire wMainReqProc; wire wReqAck; wire wSgElemRdy; wire wSgElemRen; wire [63:0] wSgElemAddr; wire [31:0] wSgElemLen; wire wSgRst; wire wMainReq; wire [63:0] wMainReqAddr; wire [9:0] wMainReqLen; wire wTxnErr; wire wChnlRx; wire wChnlRxRecvd; wire wChnlRxAckRecvd; wire wChnlRxLast; wire [31:0] wChnlRxLen; wire [30:0] wChnlRxOff; wire [31:0] wChnlRxConsumed; reg [4:0] rWideRst=0; reg rRst=0; assign SG_ERR = (wPackedSgTxDone & wPackedSgTxErr); // Generate a wide reset from the input reset. always @ (posedge CLK) begin rRst <= #1 rWideRst[4]; if (RST) rWideRst <= #1 5'b11111; else rWideRst <= (rWideRst<<1); end // Pack received data tightly into our FIFOs fifo_packer_128 mainFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(MAIN_DATA), .DATA_IN_EN(MAIN_DATA_EN), .DATA_IN_DONE(MAIN_DONE), .DATA_IN_ERR(MAIN_ERR), .DATA_IN_FLUSH(wMainFlush), .PACKED_DATA(wPackedMainData), .PACKED_WEN(wPackedMainWen), .PACKED_DATA_DONE(wPackedMainDone), .PACKED_DATA_ERR(wPackedMainErr), .PACKED_DATA_FLUSHED(wMainFlushed) ); fifo_packer_128 sgRxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_RX_DATA), .DATA_IN_EN(SG_RX_DATA_EN), .DATA_IN_DONE(SG_RX_DONE), .DATA_IN_ERR(SG_RX_ERR), .DATA_IN_FLUSH(wSgRxFlush), .PACKED_DATA(wPackedSgRxData), .PACKED_WEN(wPackedSgRxWen), .PACKED_DATA_DONE(wPackedSgRxDone), .PACKED_DATA_ERR(wPackedSgRxErr), .PACKED_DATA_FLUSHED(wSgRxFlushed) ); fifo_packer_128 sgTxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_TX_DATA), .DATA_IN_EN(SG_TX_DATA_EN), .DATA_IN_DONE(SG_TX_DONE), .DATA_IN_ERR(SG_TX_ERR), .DATA_IN_FLUSH(wSgTxFlush), .PACKED_DATA(wPackedSgTxData), .PACKED_WEN(wPackedSgTxWen), .PACKED_DATA_DONE(wPackedSgTxDone), .PACKED_DATA_ERR(wPackedSgTxErr), .PACKED_DATA_FLUSHED(wSgTxFlushed) ); // FIFOs for storing received data for the channel. (* RAM_STYLE="BLOCK" *) async_fifo_fwft #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_MAIN_FIFO_DEPTH)) mainFifo ( .WR_CLK(CLK), .WR_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .WR_EN(wPackedMainWen), .WR_DATA(wPackedMainData), .WR_FULL(), .RD_CLK(CHNL_CLK), .RD_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .RD_EN(wMainDataRen), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgRxFifo ( .RST(rRst | wSgRxRst), .CLK(CLK), .WR_EN(wPackedSgRxWen), .WR_DATA(wPackedSgRxData), .FULL(), .RD_EN(wSgRxDataRen), .RD_DATA(wSgRxData), .EMPTY(wSgRxDataEmpty), .COUNT(wSgRxFifoCount) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgTxFifo ( .RST(rRst | wSgTxRst), .CLK(CLK), .WR_EN(wPackedSgTxWen), .WR_DATA(wPackedSgTxData), .FULL(), .RD_EN(SG_DATA_REN), .RD_DATA(SG_DATA), .EMPTY(SG_DATA_EMPTY), .COUNT(wSgTxFifoCount) ); // Manage requesting and acknowledging scatter gather data. Note that // these modules will share the main requestor's RX channel. They will // take priority over the main logic's use of the RX channel. sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgRxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(wSgRst), .BUF_RECVD(SG_RX_BUF_RECVD), .BUF_DATA(SG_RX_BUF_DATA), .BUF_LEN_VALID(SG_RX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_RX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_RX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgRxFifoCount), .FIFO_FLUSH(wSgRxFlush), .FIFO_FLUSHED(wSgRxFlushed), .FIFO_RST(wSgRxRst), .RX_REQ(wSgRxReq), .RX_ADDR(wSgRxReqAddr), .RX_LEN(wSgRxReqLen), .RX_REQ_ACK(wReqAck & wSgRxReqProc), .RX_DONE(wPackedSgRxDone) ); sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgTxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(SG_RST), .BUF_RECVD(SG_TX_BUF_RECVD), .BUF_DATA(SG_TX_BUF_DATA), .BUF_LEN_VALID(SG_TX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_TX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_TX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgTxFifoCount), .FIFO_FLUSH(wSgTxFlush), .FIFO_FLUSHED(wSgTxFlushed), .FIFO_RST(wSgTxRst), .RX_REQ(wSgTxReq), .RX_ADDR(wSgTxReqAddr), .RX_LEN(wSgTxReqLen), .RX_REQ_ACK(wReqAck & wSgTxReqProc), .RX_DONE(wPackedSgTxDone) ); // A read requester for the channel and scatter gather requesters. rx_port_requester_mux requesterMux ( .RST(rRst), .CLK(CLK), .SG_RX_REQ(wSgRxReq), .SG_RX_LEN(wSgRxReqLen), .SG_RX_ADDR(wSgRxReqAddr), .SG_RX_REQ_PROC(wSgRxReqProc), .SG_TX_REQ(wSgTxReq), .SG_TX_LEN(wSgTxReqLen), .SG_TX_ADDR(wSgTxReqAddr), .SG_TX_REQ_PROC(wSgTxReqProc), .MAIN_REQ(wMainReq), .MAIN_LEN(wMainReqLen), .MAIN_ADDR(wMainReqAddr), .MAIN_REQ_PROC(wMainReqProc), .RX_REQ(RX_REQ), .RX_REQ_ACK(RX_REQ_ACK), .RX_REQ_TAG(RX_REQ_TAG), .RX_REQ_ADDR(RX_REQ_ADDR), .RX_REQ_LEN(RX_REQ_LEN), .REQ_ACK(wReqAck) ); // Read the scatter gather buffer address and length, continuously so that // we have it ready whenever the next buffer is needed. sg_list_reader_128 #(.C_DATA_WIDTH(C_DATA_WIDTH)) sgListReader ( .CLK(CLK), .RST(rRst | wSgRst), .BUF_DATA(wSgRxData), .BUF_DATA_EMPTY(wSgRxDataEmpty), .BUF_DATA_REN(wSgRxDataRen), .VALID(wSgElemRdy), .EMPTY(), .REN(wSgElemRen), .ADDR(wSgElemAddr), .LEN(wSgElemLen) ); // Main port reader logic rx_port_reader #(.C_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_MAIN_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) reader ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .TXN_DATA(TXN_DATA), .TXN_LEN_VALID(TXN_LEN_VALID), .TXN_OFF_LAST_VALID(TXN_OFF_LAST_VALID), .TXN_DONE_LEN(TXN_DONE_LEN), .TXN_DONE(TXN_DONE), .TXN_ERR(wTxnErr), .TXN_DONE_ACK(TXN_DONE_ACK), .TXN_DATA_FLUSH(wMainFlush), .TXN_DATA_FLUSHED(wMainFlushed), .RX_REQ(wMainReq), .RX_ADDR(wMainReqAddr), .RX_LEN(wMainReqLen), .RX_REQ_ACK(wReqAck & wMainReqProc), .RX_DATA_EN(MAIN_DATA_EN), .RX_DONE(wPackedMainDone), .RX_ERR(wPackedMainErr), .SG_DONE(wPackedSgRxDone), .SG_ERR(wPackedSgRxErr), .SG_ELEM_ADDR(wSgElemAddr), .SG_ELEM_LEN(wSgElemLen), .SG_ELEM_RDY(wSgElemRdy), .SG_ELEM_REN(wSgElemRen), .SG_RST(wSgRst), .CHNL_RX(wChnlRx), .CHNL_RX_LEN(wChnlRxLen), .CHNL_RX_LAST(wChnlRxLast), .CHNL_RX_OFF(wChnlRxOff), .CHNL_RX_RECVD(wChnlRxRecvd), .CHNL_RX_ACK_RECVD(wChnlRxAckRecvd), .CHNL_RX_CONSUMED(wChnlRxConsumed) ); // Manage the CHNL_RX* signals in the CHNL_CLK domain. rx_port_channel_gate #(.C_DATA_WIDTH(C_DATA_WIDTH)) gate ( .RST(rRst), .CLK(CLK), .RX(wChnlRx), .RX_RECVD(wChnlRxRecvd), .RX_ACK_RECVD(wChnlRxAckRecvd), .RX_LAST(wChnlRxLast), .RX_LEN(wChnlRxLen), .RX_OFF(wChnlRxOff), .RX_CONSUMED(wChnlRxConsumed), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty), .RD_EN(wMainDataRen), .CHNL_CLK(CHNL_CLK), .CHNL_RX(CHNL_RX), .CHNL_RX_ACK(CHNL_RX_ACK), .CHNL_RX_LAST(CHNL_RX_LAST), .CHNL_RX_LEN(CHNL_RX_LEN), .CHNL_RX_OFF(CHNL_RX_OFF), .CHNL_RX_DATA(CHNL_RX_DATA), .CHNL_RX_DATA_VALID(CHNL_RX_DATA_VALID), .CHNL_RX_DATA_REN(CHNL_RX_DATA_REN) ); /* reg [31:0] rCounter=0; always @ (posedge CLK) begin if (RST) rCounter <= #1 0; else rCounter <= #1 (RX_REQ_ACK ? rCounter + 1 : rCounter); end wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512_max a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({(SG_RX_DATA_EN != 0) | (MAIN_DATA_EN != 0), RX_REQ_ACK, wSgElemRen, (SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | SG_TX_BUF_ADDR_HI_VALID | SG_TX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID | wSgRst), rCounter[10:7]}), // .TRIG0({wSgRxReq & wSgRxReqProc & wReqAck, // wSgElemRen, // wMainReq | wSgRxReq | wSgTxReq, // (SG_RX_DATA_EN != 0), // SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID, // rSgElemRenCount > 1100, // wSgRst | wTxnErr | wSgRxFlush | wSgRxFlushed, // wPackedSgRxDone | wPackedSgRxErr}), .DATA({ MAIN_DATA_EN, // 3 //wPackedSgRxData, // 128 SG_RX_DONE, // 1 SG_RX_DATA_EN, // 3 SG_RX_DATA, // 128 wSgRxDataRen, // 1 wSgRxDataEmpty, // 1 MAIN_DATA, // 128 wSgRst, // 1 SG_RST, // 1 wPackedSgRxDone, // 1 wSgRxRst, // 1 wSgRxFlushed, // 1 wSgRxFlush, // 1 SG_RX_BUF_ADDR_LO_VALID, // 1 SG_RX_BUF_ADDR_HI_VALID, // 1 SG_RX_BUF_LEN_VALID, // 1 //SG_RX_BUF_DATA, // 32 rCounter, // 32 RX_REQ_ADDR, // 64 RX_REQ_TAG, // 2 RX_REQ_ACK, // 1 RX_REQ, // 1 wSgTxReqProc, // 1 wSgTxReq, // 1 wSgRxReqProc, // 1 //wSgRxReqAddr, // 64 //wSgElemAddr, // 64 44'd0, // 44 wSgRxReqLen, // 10 RX_REQ_LEN, // 10 wSgRxReq, // 1 wMainReqProc, // 1 wMainReqAddr, // 64 wMainReq, // 1 wReqAck, // 1 wTxnErr, // 1 TXN_OFF_LAST_VALID, // 1 TXN_LEN_VALID}) // 1 ); */ endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_128.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Receives data from the rx_engine and buffers the output // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_128 #( parameter C_DATA_WIDTH = 9'd128, parameter C_MAIN_FIFO_DEPTH = 1024, parameter C_SG_FIFO_DEPTH = 512, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_MAIN_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_MAIN_FIFO_DEPTH))+1), parameter C_SG_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_SG_FIFO_DEPTH))+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B output SG_RX_BUF_RECVD, // Scatter gather RX buffer completely read (ready for next if applicable) input [31:0] SG_RX_BUF_DATA, // Scatter gather RX buffer data input SG_RX_BUF_LEN_VALID, // Scatter gather RX buffer length valid input SG_RX_BUF_ADDR_HI_VALID, // Scatter gather RX buffer high address valid input SG_RX_BUF_ADDR_LO_VALID, // Scatter gather RX buffer low address valid output SG_TX_BUF_RECVD, // Scatter gather TX buffer completely read (ready for next if applicable) input [31:0] SG_TX_BUF_DATA, // Scatter gather TX buffer data input SG_TX_BUF_LEN_VALID, // Scatter gather TX buffer length valid input SG_TX_BUF_ADDR_HI_VALID, // Scatter gather TX buffer high address valid input SG_TX_BUF_ADDR_LO_VALID, // Scatter gather TX buffer low address valid output [C_DATA_WIDTH-1:0] SG_DATA, // Scatter gather TX buffer data output SG_DATA_EMPTY, // Scatter gather TX buffer data empty input SG_DATA_REN, // Scatter gather TX buffer data read enable input SG_RST, // Scatter gather TX buffer data reset output SG_ERR, // Scatter gather TX encountered an error input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done input TXN_DONE_ACK, // Read transaction actual transfer length read output RX_REQ, // Read request input RX_REQ_ACK, // Read request accepted output [1:0] RX_REQ_TAG, // Read request data tag output [63:0] RX_REQ_ADDR, // Read request address output [9:0] RX_REQ_LEN, // Read request length input [C_DATA_WIDTH-1:0] MAIN_DATA, // Main incoming data input [C_DATA_WORD_WIDTH-1:0] MAIN_DATA_EN, // Main incoming data enable input MAIN_DONE, // Main incoming data complete input MAIN_ERR, // Main incoming data completed with error input [C_DATA_WIDTH-1:0] SG_RX_DATA, // Scatter gather for RX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_RX_DATA_EN, // Scatter gather for RX incoming data enable input SG_RX_DONE, // Scatter gather for RX incoming data complete input SG_RX_ERR, // Scatter gather for RX incoming data completed with error input [C_DATA_WIDTH-1:0] SG_TX_DATA, // Scatter gather for TX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_TX_DATA_EN, // Scatter gather for TX incoming data enable input SG_TX_DONE, // Scatter gather for TX incoming data complete input SG_TX_ERR, // Scatter gather for TX incoming data completed with error input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal input CHNL_RX_ACK, // Channle read received signal output CHNL_RX_LAST, // Channel last read output [31:0] CHNL_RX_LEN, // Channel read length output [30:0] CHNL_RX_OFF, // Channel read offset output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data output CHNL_RX_DATA_VALID, // Channel read data valid input CHNL_RX_DATA_REN // Channel read data has been recieved ); `include "functions.vh" wire [C_DATA_WIDTH-1:0] wPackedMainData; wire wPackedMainWen; wire wPackedMainDone; wire wPackedMainErr; wire wMainFlush; wire wMainFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgRxData; wire wPackedSgRxWen; wire wPackedSgRxDone; wire wPackedSgRxErr; wire wSgRxFlush; wire wSgRxFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgTxData; wire wPackedSgTxWen; wire wPackedSgTxDone; wire wPackedSgTxErr; wire wSgTxFlush; wire wSgTxFlushed; wire wMainDataRen; wire wMainDataEmpty; wire [C_DATA_WIDTH-1:0] wMainData; wire wSgRxRst; wire wSgRxDataRen; wire wSgRxDataEmpty; wire [C_DATA_WIDTH-1:0] wSgRxData; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgRxFifoCount; wire wSgTxRst; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgTxFifoCount; wire wSgRxReq; wire [63:0] wSgRxReqAddr; wire [9:0] wSgRxReqLen; wire wSgTxReq; wire [63:0] wSgTxReqAddr; wire [9:0] wSgTxReqLen; wire wSgRxReqProc; wire wSgTxReqProc; wire wMainReqProc; wire wReqAck; wire wSgElemRdy; wire wSgElemRen; wire [63:0] wSgElemAddr; wire [31:0] wSgElemLen; wire wSgRst; wire wMainReq; wire [63:0] wMainReqAddr; wire [9:0] wMainReqLen; wire wTxnErr; wire wChnlRx; wire wChnlRxRecvd; wire wChnlRxAckRecvd; wire wChnlRxLast; wire [31:0] wChnlRxLen; wire [30:0] wChnlRxOff; wire [31:0] wChnlRxConsumed; reg [4:0] rWideRst=0; reg rRst=0; assign SG_ERR = (wPackedSgTxDone & wPackedSgTxErr); // Generate a wide reset from the input reset. always @ (posedge CLK) begin rRst <= #1 rWideRst[4]; if (RST) rWideRst <= #1 5'b11111; else rWideRst <= (rWideRst<<1); end // Pack received data tightly into our FIFOs fifo_packer_128 mainFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(MAIN_DATA), .DATA_IN_EN(MAIN_DATA_EN), .DATA_IN_DONE(MAIN_DONE), .DATA_IN_ERR(MAIN_ERR), .DATA_IN_FLUSH(wMainFlush), .PACKED_DATA(wPackedMainData), .PACKED_WEN(wPackedMainWen), .PACKED_DATA_DONE(wPackedMainDone), .PACKED_DATA_ERR(wPackedMainErr), .PACKED_DATA_FLUSHED(wMainFlushed) ); fifo_packer_128 sgRxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_RX_DATA), .DATA_IN_EN(SG_RX_DATA_EN), .DATA_IN_DONE(SG_RX_DONE), .DATA_IN_ERR(SG_RX_ERR), .DATA_IN_FLUSH(wSgRxFlush), .PACKED_DATA(wPackedSgRxData), .PACKED_WEN(wPackedSgRxWen), .PACKED_DATA_DONE(wPackedSgRxDone), .PACKED_DATA_ERR(wPackedSgRxErr), .PACKED_DATA_FLUSHED(wSgRxFlushed) ); fifo_packer_128 sgTxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_TX_DATA), .DATA_IN_EN(SG_TX_DATA_EN), .DATA_IN_DONE(SG_TX_DONE), .DATA_IN_ERR(SG_TX_ERR), .DATA_IN_FLUSH(wSgTxFlush), .PACKED_DATA(wPackedSgTxData), .PACKED_WEN(wPackedSgTxWen), .PACKED_DATA_DONE(wPackedSgTxDone), .PACKED_DATA_ERR(wPackedSgTxErr), .PACKED_DATA_FLUSHED(wSgTxFlushed) ); // FIFOs for storing received data for the channel. (* RAM_STYLE="BLOCK" *) async_fifo_fwft #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_MAIN_FIFO_DEPTH)) mainFifo ( .WR_CLK(CLK), .WR_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .WR_EN(wPackedMainWen), .WR_DATA(wPackedMainData), .WR_FULL(), .RD_CLK(CHNL_CLK), .RD_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .RD_EN(wMainDataRen), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgRxFifo ( .RST(rRst | wSgRxRst), .CLK(CLK), .WR_EN(wPackedSgRxWen), .WR_DATA(wPackedSgRxData), .FULL(), .RD_EN(wSgRxDataRen), .RD_DATA(wSgRxData), .EMPTY(wSgRxDataEmpty), .COUNT(wSgRxFifoCount) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgTxFifo ( .RST(rRst | wSgTxRst), .CLK(CLK), .WR_EN(wPackedSgTxWen), .WR_DATA(wPackedSgTxData), .FULL(), .RD_EN(SG_DATA_REN), .RD_DATA(SG_DATA), .EMPTY(SG_DATA_EMPTY), .COUNT(wSgTxFifoCount) ); // Manage requesting and acknowledging scatter gather data. Note that // these modules will share the main requestor's RX channel. They will // take priority over the main logic's use of the RX channel. sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgRxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(wSgRst), .BUF_RECVD(SG_RX_BUF_RECVD), .BUF_DATA(SG_RX_BUF_DATA), .BUF_LEN_VALID(SG_RX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_RX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_RX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgRxFifoCount), .FIFO_FLUSH(wSgRxFlush), .FIFO_FLUSHED(wSgRxFlushed), .FIFO_RST(wSgRxRst), .RX_REQ(wSgRxReq), .RX_ADDR(wSgRxReqAddr), .RX_LEN(wSgRxReqLen), .RX_REQ_ACK(wReqAck & wSgRxReqProc), .RX_DONE(wPackedSgRxDone) ); sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgTxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(SG_RST), .BUF_RECVD(SG_TX_BUF_RECVD), .BUF_DATA(SG_TX_BUF_DATA), .BUF_LEN_VALID(SG_TX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_TX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_TX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgTxFifoCount), .FIFO_FLUSH(wSgTxFlush), .FIFO_FLUSHED(wSgTxFlushed), .FIFO_RST(wSgTxRst), .RX_REQ(wSgTxReq), .RX_ADDR(wSgTxReqAddr), .RX_LEN(wSgTxReqLen), .RX_REQ_ACK(wReqAck & wSgTxReqProc), .RX_DONE(wPackedSgTxDone) ); // A read requester for the channel and scatter gather requesters. rx_port_requester_mux requesterMux ( .RST(rRst), .CLK(CLK), .SG_RX_REQ(wSgRxReq), .SG_RX_LEN(wSgRxReqLen), .SG_RX_ADDR(wSgRxReqAddr), .SG_RX_REQ_PROC(wSgRxReqProc), .SG_TX_REQ(wSgTxReq), .SG_TX_LEN(wSgTxReqLen), .SG_TX_ADDR(wSgTxReqAddr), .SG_TX_REQ_PROC(wSgTxReqProc), .MAIN_REQ(wMainReq), .MAIN_LEN(wMainReqLen), .MAIN_ADDR(wMainReqAddr), .MAIN_REQ_PROC(wMainReqProc), .RX_REQ(RX_REQ), .RX_REQ_ACK(RX_REQ_ACK), .RX_REQ_TAG(RX_REQ_TAG), .RX_REQ_ADDR(RX_REQ_ADDR), .RX_REQ_LEN(RX_REQ_LEN), .REQ_ACK(wReqAck) ); // Read the scatter gather buffer address and length, continuously so that // we have it ready whenever the next buffer is needed. sg_list_reader_128 #(.C_DATA_WIDTH(C_DATA_WIDTH)) sgListReader ( .CLK(CLK), .RST(rRst | wSgRst), .BUF_DATA(wSgRxData), .BUF_DATA_EMPTY(wSgRxDataEmpty), .BUF_DATA_REN(wSgRxDataRen), .VALID(wSgElemRdy), .EMPTY(), .REN(wSgElemRen), .ADDR(wSgElemAddr), .LEN(wSgElemLen) ); // Main port reader logic rx_port_reader #(.C_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_MAIN_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) reader ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .TXN_DATA(TXN_DATA), .TXN_LEN_VALID(TXN_LEN_VALID), .TXN_OFF_LAST_VALID(TXN_OFF_LAST_VALID), .TXN_DONE_LEN(TXN_DONE_LEN), .TXN_DONE(TXN_DONE), .TXN_ERR(wTxnErr), .TXN_DONE_ACK(TXN_DONE_ACK), .TXN_DATA_FLUSH(wMainFlush), .TXN_DATA_FLUSHED(wMainFlushed), .RX_REQ(wMainReq), .RX_ADDR(wMainReqAddr), .RX_LEN(wMainReqLen), .RX_REQ_ACK(wReqAck & wMainReqProc), .RX_DATA_EN(MAIN_DATA_EN), .RX_DONE(wPackedMainDone), .RX_ERR(wPackedMainErr), .SG_DONE(wPackedSgRxDone), .SG_ERR(wPackedSgRxErr), .SG_ELEM_ADDR(wSgElemAddr), .SG_ELEM_LEN(wSgElemLen), .SG_ELEM_RDY(wSgElemRdy), .SG_ELEM_REN(wSgElemRen), .SG_RST(wSgRst), .CHNL_RX(wChnlRx), .CHNL_RX_LEN(wChnlRxLen), .CHNL_RX_LAST(wChnlRxLast), .CHNL_RX_OFF(wChnlRxOff), .CHNL_RX_RECVD(wChnlRxRecvd), .CHNL_RX_ACK_RECVD(wChnlRxAckRecvd), .CHNL_RX_CONSUMED(wChnlRxConsumed) ); // Manage the CHNL_RX* signals in the CHNL_CLK domain. rx_port_channel_gate #(.C_DATA_WIDTH(C_DATA_WIDTH)) gate ( .RST(rRst), .CLK(CLK), .RX(wChnlRx), .RX_RECVD(wChnlRxRecvd), .RX_ACK_RECVD(wChnlRxAckRecvd), .RX_LAST(wChnlRxLast), .RX_LEN(wChnlRxLen), .RX_OFF(wChnlRxOff), .RX_CONSUMED(wChnlRxConsumed), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty), .RD_EN(wMainDataRen), .CHNL_CLK(CHNL_CLK), .CHNL_RX(CHNL_RX), .CHNL_RX_ACK(CHNL_RX_ACK), .CHNL_RX_LAST(CHNL_RX_LAST), .CHNL_RX_LEN(CHNL_RX_LEN), .CHNL_RX_OFF(CHNL_RX_OFF), .CHNL_RX_DATA(CHNL_RX_DATA), .CHNL_RX_DATA_VALID(CHNL_RX_DATA_VALID), .CHNL_RX_DATA_REN(CHNL_RX_DATA_REN) ); /* reg [31:0] rCounter=0; always @ (posedge CLK) begin if (RST) rCounter <= #1 0; else rCounter <= #1 (RX_REQ_ACK ? rCounter + 1 : rCounter); end wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512_max a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({(SG_RX_DATA_EN != 0) | (MAIN_DATA_EN != 0), RX_REQ_ACK, wSgElemRen, (SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | SG_TX_BUF_ADDR_HI_VALID | SG_TX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID | wSgRst), rCounter[10:7]}), // .TRIG0({wSgRxReq & wSgRxReqProc & wReqAck, // wSgElemRen, // wMainReq | wSgRxReq | wSgTxReq, // (SG_RX_DATA_EN != 0), // SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID, // rSgElemRenCount > 1100, // wSgRst | wTxnErr | wSgRxFlush | wSgRxFlushed, // wPackedSgRxDone | wPackedSgRxErr}), .DATA({ MAIN_DATA_EN, // 3 //wPackedSgRxData, // 128 SG_RX_DONE, // 1 SG_RX_DATA_EN, // 3 SG_RX_DATA, // 128 wSgRxDataRen, // 1 wSgRxDataEmpty, // 1 MAIN_DATA, // 128 wSgRst, // 1 SG_RST, // 1 wPackedSgRxDone, // 1 wSgRxRst, // 1 wSgRxFlushed, // 1 wSgRxFlush, // 1 SG_RX_BUF_ADDR_LO_VALID, // 1 SG_RX_BUF_ADDR_HI_VALID, // 1 SG_RX_BUF_LEN_VALID, // 1 //SG_RX_BUF_DATA, // 32 rCounter, // 32 RX_REQ_ADDR, // 64 RX_REQ_TAG, // 2 RX_REQ_ACK, // 1 RX_REQ, // 1 wSgTxReqProc, // 1 wSgTxReq, // 1 wSgRxReqProc, // 1 //wSgRxReqAddr, // 64 //wSgElemAddr, // 64 44'd0, // 44 wSgRxReqLen, // 10 RX_REQ_LEN, // 10 wSgRxReq, // 1 wMainReqProc, // 1 wMainReqAddr, // 64 wMainReq, // 1 wReqAck, // 1 wTxnErr, // 1 TXN_OFF_LAST_VALID, // 1 TXN_LEN_VALID}) // 1 ); */ endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_128.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Receives data from the rx_engine and buffers the output // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_128 #( parameter C_DATA_WIDTH = 9'd128, parameter C_MAIN_FIFO_DEPTH = 1024, parameter C_SG_FIFO_DEPTH = 512, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_MAIN_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_MAIN_FIFO_DEPTH))+1), parameter C_SG_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_SG_FIFO_DEPTH))+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B output SG_RX_BUF_RECVD, // Scatter gather RX buffer completely read (ready for next if applicable) input [31:0] SG_RX_BUF_DATA, // Scatter gather RX buffer data input SG_RX_BUF_LEN_VALID, // Scatter gather RX buffer length valid input SG_RX_BUF_ADDR_HI_VALID, // Scatter gather RX buffer high address valid input SG_RX_BUF_ADDR_LO_VALID, // Scatter gather RX buffer low address valid output SG_TX_BUF_RECVD, // Scatter gather TX buffer completely read (ready for next if applicable) input [31:0] SG_TX_BUF_DATA, // Scatter gather TX buffer data input SG_TX_BUF_LEN_VALID, // Scatter gather TX buffer length valid input SG_TX_BUF_ADDR_HI_VALID, // Scatter gather TX buffer high address valid input SG_TX_BUF_ADDR_LO_VALID, // Scatter gather TX buffer low address valid output [C_DATA_WIDTH-1:0] SG_DATA, // Scatter gather TX buffer data output SG_DATA_EMPTY, // Scatter gather TX buffer data empty input SG_DATA_REN, // Scatter gather TX buffer data read enable input SG_RST, // Scatter gather TX buffer data reset output SG_ERR, // Scatter gather TX encountered an error input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done input TXN_DONE_ACK, // Read transaction actual transfer length read output RX_REQ, // Read request input RX_REQ_ACK, // Read request accepted output [1:0] RX_REQ_TAG, // Read request data tag output [63:0] RX_REQ_ADDR, // Read request address output [9:0] RX_REQ_LEN, // Read request length input [C_DATA_WIDTH-1:0] MAIN_DATA, // Main incoming data input [C_DATA_WORD_WIDTH-1:0] MAIN_DATA_EN, // Main incoming data enable input MAIN_DONE, // Main incoming data complete input MAIN_ERR, // Main incoming data completed with error input [C_DATA_WIDTH-1:0] SG_RX_DATA, // Scatter gather for RX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_RX_DATA_EN, // Scatter gather for RX incoming data enable input SG_RX_DONE, // Scatter gather for RX incoming data complete input SG_RX_ERR, // Scatter gather for RX incoming data completed with error input [C_DATA_WIDTH-1:0] SG_TX_DATA, // Scatter gather for TX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_TX_DATA_EN, // Scatter gather for TX incoming data enable input SG_TX_DONE, // Scatter gather for TX incoming data complete input SG_TX_ERR, // Scatter gather for TX incoming data completed with error input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal input CHNL_RX_ACK, // Channle read received signal output CHNL_RX_LAST, // Channel last read output [31:0] CHNL_RX_LEN, // Channel read length output [30:0] CHNL_RX_OFF, // Channel read offset output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data output CHNL_RX_DATA_VALID, // Channel read data valid input CHNL_RX_DATA_REN // Channel read data has been recieved ); `include "functions.vh" wire [C_DATA_WIDTH-1:0] wPackedMainData; wire wPackedMainWen; wire wPackedMainDone; wire wPackedMainErr; wire wMainFlush; wire wMainFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgRxData; wire wPackedSgRxWen; wire wPackedSgRxDone; wire wPackedSgRxErr; wire wSgRxFlush; wire wSgRxFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgTxData; wire wPackedSgTxWen; wire wPackedSgTxDone; wire wPackedSgTxErr; wire wSgTxFlush; wire wSgTxFlushed; wire wMainDataRen; wire wMainDataEmpty; wire [C_DATA_WIDTH-1:0] wMainData; wire wSgRxRst; wire wSgRxDataRen; wire wSgRxDataEmpty; wire [C_DATA_WIDTH-1:0] wSgRxData; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgRxFifoCount; wire wSgTxRst; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgTxFifoCount; wire wSgRxReq; wire [63:0] wSgRxReqAddr; wire [9:0] wSgRxReqLen; wire wSgTxReq; wire [63:0] wSgTxReqAddr; wire [9:0] wSgTxReqLen; wire wSgRxReqProc; wire wSgTxReqProc; wire wMainReqProc; wire wReqAck; wire wSgElemRdy; wire wSgElemRen; wire [63:0] wSgElemAddr; wire [31:0] wSgElemLen; wire wSgRst; wire wMainReq; wire [63:0] wMainReqAddr; wire [9:0] wMainReqLen; wire wTxnErr; wire wChnlRx; wire wChnlRxRecvd; wire wChnlRxAckRecvd; wire wChnlRxLast; wire [31:0] wChnlRxLen; wire [30:0] wChnlRxOff; wire [31:0] wChnlRxConsumed; reg [4:0] rWideRst=0; reg rRst=0; assign SG_ERR = (wPackedSgTxDone & wPackedSgTxErr); // Generate a wide reset from the input reset. always @ (posedge CLK) begin rRst <= #1 rWideRst[4]; if (RST) rWideRst <= #1 5'b11111; else rWideRst <= (rWideRst<<1); end // Pack received data tightly into our FIFOs fifo_packer_128 mainFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(MAIN_DATA), .DATA_IN_EN(MAIN_DATA_EN), .DATA_IN_DONE(MAIN_DONE), .DATA_IN_ERR(MAIN_ERR), .DATA_IN_FLUSH(wMainFlush), .PACKED_DATA(wPackedMainData), .PACKED_WEN(wPackedMainWen), .PACKED_DATA_DONE(wPackedMainDone), .PACKED_DATA_ERR(wPackedMainErr), .PACKED_DATA_FLUSHED(wMainFlushed) ); fifo_packer_128 sgRxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_RX_DATA), .DATA_IN_EN(SG_RX_DATA_EN), .DATA_IN_DONE(SG_RX_DONE), .DATA_IN_ERR(SG_RX_ERR), .DATA_IN_FLUSH(wSgRxFlush), .PACKED_DATA(wPackedSgRxData), .PACKED_WEN(wPackedSgRxWen), .PACKED_DATA_DONE(wPackedSgRxDone), .PACKED_DATA_ERR(wPackedSgRxErr), .PACKED_DATA_FLUSHED(wSgRxFlushed) ); fifo_packer_128 sgTxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_TX_DATA), .DATA_IN_EN(SG_TX_DATA_EN), .DATA_IN_DONE(SG_TX_DONE), .DATA_IN_ERR(SG_TX_ERR), .DATA_IN_FLUSH(wSgTxFlush), .PACKED_DATA(wPackedSgTxData), .PACKED_WEN(wPackedSgTxWen), .PACKED_DATA_DONE(wPackedSgTxDone), .PACKED_DATA_ERR(wPackedSgTxErr), .PACKED_DATA_FLUSHED(wSgTxFlushed) ); // FIFOs for storing received data for the channel. (* RAM_STYLE="BLOCK" *) async_fifo_fwft #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_MAIN_FIFO_DEPTH)) mainFifo ( .WR_CLK(CLK), .WR_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .WR_EN(wPackedMainWen), .WR_DATA(wPackedMainData), .WR_FULL(), .RD_CLK(CHNL_CLK), .RD_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .RD_EN(wMainDataRen), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgRxFifo ( .RST(rRst | wSgRxRst), .CLK(CLK), .WR_EN(wPackedSgRxWen), .WR_DATA(wPackedSgRxData), .FULL(), .RD_EN(wSgRxDataRen), .RD_DATA(wSgRxData), .EMPTY(wSgRxDataEmpty), .COUNT(wSgRxFifoCount) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgTxFifo ( .RST(rRst | wSgTxRst), .CLK(CLK), .WR_EN(wPackedSgTxWen), .WR_DATA(wPackedSgTxData), .FULL(), .RD_EN(SG_DATA_REN), .RD_DATA(SG_DATA), .EMPTY(SG_DATA_EMPTY), .COUNT(wSgTxFifoCount) ); // Manage requesting and acknowledging scatter gather data. Note that // these modules will share the main requestor's RX channel. They will // take priority over the main logic's use of the RX channel. sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgRxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(wSgRst), .BUF_RECVD(SG_RX_BUF_RECVD), .BUF_DATA(SG_RX_BUF_DATA), .BUF_LEN_VALID(SG_RX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_RX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_RX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgRxFifoCount), .FIFO_FLUSH(wSgRxFlush), .FIFO_FLUSHED(wSgRxFlushed), .FIFO_RST(wSgRxRst), .RX_REQ(wSgRxReq), .RX_ADDR(wSgRxReqAddr), .RX_LEN(wSgRxReqLen), .RX_REQ_ACK(wReqAck & wSgRxReqProc), .RX_DONE(wPackedSgRxDone) ); sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgTxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(SG_RST), .BUF_RECVD(SG_TX_BUF_RECVD), .BUF_DATA(SG_TX_BUF_DATA), .BUF_LEN_VALID(SG_TX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_TX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_TX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgTxFifoCount), .FIFO_FLUSH(wSgTxFlush), .FIFO_FLUSHED(wSgTxFlushed), .FIFO_RST(wSgTxRst), .RX_REQ(wSgTxReq), .RX_ADDR(wSgTxReqAddr), .RX_LEN(wSgTxReqLen), .RX_REQ_ACK(wReqAck & wSgTxReqProc), .RX_DONE(wPackedSgTxDone) ); // A read requester for the channel and scatter gather requesters. rx_port_requester_mux requesterMux ( .RST(rRst), .CLK(CLK), .SG_RX_REQ(wSgRxReq), .SG_RX_LEN(wSgRxReqLen), .SG_RX_ADDR(wSgRxReqAddr), .SG_RX_REQ_PROC(wSgRxReqProc), .SG_TX_REQ(wSgTxReq), .SG_TX_LEN(wSgTxReqLen), .SG_TX_ADDR(wSgTxReqAddr), .SG_TX_REQ_PROC(wSgTxReqProc), .MAIN_REQ(wMainReq), .MAIN_LEN(wMainReqLen), .MAIN_ADDR(wMainReqAddr), .MAIN_REQ_PROC(wMainReqProc), .RX_REQ(RX_REQ), .RX_REQ_ACK(RX_REQ_ACK), .RX_REQ_TAG(RX_REQ_TAG), .RX_REQ_ADDR(RX_REQ_ADDR), .RX_REQ_LEN(RX_REQ_LEN), .REQ_ACK(wReqAck) ); // Read the scatter gather buffer address and length, continuously so that // we have it ready whenever the next buffer is needed. sg_list_reader_128 #(.C_DATA_WIDTH(C_DATA_WIDTH)) sgListReader ( .CLK(CLK), .RST(rRst | wSgRst), .BUF_DATA(wSgRxData), .BUF_DATA_EMPTY(wSgRxDataEmpty), .BUF_DATA_REN(wSgRxDataRen), .VALID(wSgElemRdy), .EMPTY(), .REN(wSgElemRen), .ADDR(wSgElemAddr), .LEN(wSgElemLen) ); // Main port reader logic rx_port_reader #(.C_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_MAIN_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) reader ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .TXN_DATA(TXN_DATA), .TXN_LEN_VALID(TXN_LEN_VALID), .TXN_OFF_LAST_VALID(TXN_OFF_LAST_VALID), .TXN_DONE_LEN(TXN_DONE_LEN), .TXN_DONE(TXN_DONE), .TXN_ERR(wTxnErr), .TXN_DONE_ACK(TXN_DONE_ACK), .TXN_DATA_FLUSH(wMainFlush), .TXN_DATA_FLUSHED(wMainFlushed), .RX_REQ(wMainReq), .RX_ADDR(wMainReqAddr), .RX_LEN(wMainReqLen), .RX_REQ_ACK(wReqAck & wMainReqProc), .RX_DATA_EN(MAIN_DATA_EN), .RX_DONE(wPackedMainDone), .RX_ERR(wPackedMainErr), .SG_DONE(wPackedSgRxDone), .SG_ERR(wPackedSgRxErr), .SG_ELEM_ADDR(wSgElemAddr), .SG_ELEM_LEN(wSgElemLen), .SG_ELEM_RDY(wSgElemRdy), .SG_ELEM_REN(wSgElemRen), .SG_RST(wSgRst), .CHNL_RX(wChnlRx), .CHNL_RX_LEN(wChnlRxLen), .CHNL_RX_LAST(wChnlRxLast), .CHNL_RX_OFF(wChnlRxOff), .CHNL_RX_RECVD(wChnlRxRecvd), .CHNL_RX_ACK_RECVD(wChnlRxAckRecvd), .CHNL_RX_CONSUMED(wChnlRxConsumed) ); // Manage the CHNL_RX* signals in the CHNL_CLK domain. rx_port_channel_gate #(.C_DATA_WIDTH(C_DATA_WIDTH)) gate ( .RST(rRst), .CLK(CLK), .RX(wChnlRx), .RX_RECVD(wChnlRxRecvd), .RX_ACK_RECVD(wChnlRxAckRecvd), .RX_LAST(wChnlRxLast), .RX_LEN(wChnlRxLen), .RX_OFF(wChnlRxOff), .RX_CONSUMED(wChnlRxConsumed), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty), .RD_EN(wMainDataRen), .CHNL_CLK(CHNL_CLK), .CHNL_RX(CHNL_RX), .CHNL_RX_ACK(CHNL_RX_ACK), .CHNL_RX_LAST(CHNL_RX_LAST), .CHNL_RX_LEN(CHNL_RX_LEN), .CHNL_RX_OFF(CHNL_RX_OFF), .CHNL_RX_DATA(CHNL_RX_DATA), .CHNL_RX_DATA_VALID(CHNL_RX_DATA_VALID), .CHNL_RX_DATA_REN(CHNL_RX_DATA_REN) ); /* reg [31:0] rCounter=0; always @ (posedge CLK) begin if (RST) rCounter <= #1 0; else rCounter <= #1 (RX_REQ_ACK ? rCounter + 1 : rCounter); end wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512_max a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({(SG_RX_DATA_EN != 0) | (MAIN_DATA_EN != 0), RX_REQ_ACK, wSgElemRen, (SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | SG_TX_BUF_ADDR_HI_VALID | SG_TX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID | wSgRst), rCounter[10:7]}), // .TRIG0({wSgRxReq & wSgRxReqProc & wReqAck, // wSgElemRen, // wMainReq | wSgRxReq | wSgTxReq, // (SG_RX_DATA_EN != 0), // SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID, // rSgElemRenCount > 1100, // wSgRst | wTxnErr | wSgRxFlush | wSgRxFlushed, // wPackedSgRxDone | wPackedSgRxErr}), .DATA({ MAIN_DATA_EN, // 3 //wPackedSgRxData, // 128 SG_RX_DONE, // 1 SG_RX_DATA_EN, // 3 SG_RX_DATA, // 128 wSgRxDataRen, // 1 wSgRxDataEmpty, // 1 MAIN_DATA, // 128 wSgRst, // 1 SG_RST, // 1 wPackedSgRxDone, // 1 wSgRxRst, // 1 wSgRxFlushed, // 1 wSgRxFlush, // 1 SG_RX_BUF_ADDR_LO_VALID, // 1 SG_RX_BUF_ADDR_HI_VALID, // 1 SG_RX_BUF_LEN_VALID, // 1 //SG_RX_BUF_DATA, // 32 rCounter, // 32 RX_REQ_ADDR, // 64 RX_REQ_TAG, // 2 RX_REQ_ACK, // 1 RX_REQ, // 1 wSgTxReqProc, // 1 wSgTxReq, // 1 wSgRxReqProc, // 1 //wSgRxReqAddr, // 64 //wSgElemAddr, // 64 44'd0, // 44 wSgRxReqLen, // 10 RX_REQ_LEN, // 10 wSgRxReq, // 1 wMainReqProc, // 1 wMainReqAddr, // 64 wMainReq, // 1 wReqAck, // 1 wTxnErr, // 1 TXN_OFF_LAST_VALID, // 1 TXN_LEN_VALID}) // 1 ); */ endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_128.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Receives data from the rx_engine and buffers the output // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_128 #( parameter C_DATA_WIDTH = 9'd128, parameter C_MAIN_FIFO_DEPTH = 1024, parameter C_SG_FIFO_DEPTH = 512, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_MAIN_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_MAIN_FIFO_DEPTH))+1), parameter C_SG_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_SG_FIFO_DEPTH))+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B output SG_RX_BUF_RECVD, // Scatter gather RX buffer completely read (ready for next if applicable) input [31:0] SG_RX_BUF_DATA, // Scatter gather RX buffer data input SG_RX_BUF_LEN_VALID, // Scatter gather RX buffer length valid input SG_RX_BUF_ADDR_HI_VALID, // Scatter gather RX buffer high address valid input SG_RX_BUF_ADDR_LO_VALID, // Scatter gather RX buffer low address valid output SG_TX_BUF_RECVD, // Scatter gather TX buffer completely read (ready for next if applicable) input [31:0] SG_TX_BUF_DATA, // Scatter gather TX buffer data input SG_TX_BUF_LEN_VALID, // Scatter gather TX buffer length valid input SG_TX_BUF_ADDR_HI_VALID, // Scatter gather TX buffer high address valid input SG_TX_BUF_ADDR_LO_VALID, // Scatter gather TX buffer low address valid output [C_DATA_WIDTH-1:0] SG_DATA, // Scatter gather TX buffer data output SG_DATA_EMPTY, // Scatter gather TX buffer data empty input SG_DATA_REN, // Scatter gather TX buffer data read enable input SG_RST, // Scatter gather TX buffer data reset output SG_ERR, // Scatter gather TX encountered an error input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done input TXN_DONE_ACK, // Read transaction actual transfer length read output RX_REQ, // Read request input RX_REQ_ACK, // Read request accepted output [1:0] RX_REQ_TAG, // Read request data tag output [63:0] RX_REQ_ADDR, // Read request address output [9:0] RX_REQ_LEN, // Read request length input [C_DATA_WIDTH-1:0] MAIN_DATA, // Main incoming data input [C_DATA_WORD_WIDTH-1:0] MAIN_DATA_EN, // Main incoming data enable input MAIN_DONE, // Main incoming data complete input MAIN_ERR, // Main incoming data completed with error input [C_DATA_WIDTH-1:0] SG_RX_DATA, // Scatter gather for RX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_RX_DATA_EN, // Scatter gather for RX incoming data enable input SG_RX_DONE, // Scatter gather for RX incoming data complete input SG_RX_ERR, // Scatter gather for RX incoming data completed with error input [C_DATA_WIDTH-1:0] SG_TX_DATA, // Scatter gather for TX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_TX_DATA_EN, // Scatter gather for TX incoming data enable input SG_TX_DONE, // Scatter gather for TX incoming data complete input SG_TX_ERR, // Scatter gather for TX incoming data completed with error input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal input CHNL_RX_ACK, // Channle read received signal output CHNL_RX_LAST, // Channel last read output [31:0] CHNL_RX_LEN, // Channel read length output [30:0] CHNL_RX_OFF, // Channel read offset output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data output CHNL_RX_DATA_VALID, // Channel read data valid input CHNL_RX_DATA_REN // Channel read data has been recieved ); `include "functions.vh" wire [C_DATA_WIDTH-1:0] wPackedMainData; wire wPackedMainWen; wire wPackedMainDone; wire wPackedMainErr; wire wMainFlush; wire wMainFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgRxData; wire wPackedSgRxWen; wire wPackedSgRxDone; wire wPackedSgRxErr; wire wSgRxFlush; wire wSgRxFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgTxData; wire wPackedSgTxWen; wire wPackedSgTxDone; wire wPackedSgTxErr; wire wSgTxFlush; wire wSgTxFlushed; wire wMainDataRen; wire wMainDataEmpty; wire [C_DATA_WIDTH-1:0] wMainData; wire wSgRxRst; wire wSgRxDataRen; wire wSgRxDataEmpty; wire [C_DATA_WIDTH-1:0] wSgRxData; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgRxFifoCount; wire wSgTxRst; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgTxFifoCount; wire wSgRxReq; wire [63:0] wSgRxReqAddr; wire [9:0] wSgRxReqLen; wire wSgTxReq; wire [63:0] wSgTxReqAddr; wire [9:0] wSgTxReqLen; wire wSgRxReqProc; wire wSgTxReqProc; wire wMainReqProc; wire wReqAck; wire wSgElemRdy; wire wSgElemRen; wire [63:0] wSgElemAddr; wire [31:0] wSgElemLen; wire wSgRst; wire wMainReq; wire [63:0] wMainReqAddr; wire [9:0] wMainReqLen; wire wTxnErr; wire wChnlRx; wire wChnlRxRecvd; wire wChnlRxAckRecvd; wire wChnlRxLast; wire [31:0] wChnlRxLen; wire [30:0] wChnlRxOff; wire [31:0] wChnlRxConsumed; reg [4:0] rWideRst=0; reg rRst=0; assign SG_ERR = (wPackedSgTxDone & wPackedSgTxErr); // Generate a wide reset from the input reset. always @ (posedge CLK) begin rRst <= #1 rWideRst[4]; if (RST) rWideRst <= #1 5'b11111; else rWideRst <= (rWideRst<<1); end // Pack received data tightly into our FIFOs fifo_packer_128 mainFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(MAIN_DATA), .DATA_IN_EN(MAIN_DATA_EN), .DATA_IN_DONE(MAIN_DONE), .DATA_IN_ERR(MAIN_ERR), .DATA_IN_FLUSH(wMainFlush), .PACKED_DATA(wPackedMainData), .PACKED_WEN(wPackedMainWen), .PACKED_DATA_DONE(wPackedMainDone), .PACKED_DATA_ERR(wPackedMainErr), .PACKED_DATA_FLUSHED(wMainFlushed) ); fifo_packer_128 sgRxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_RX_DATA), .DATA_IN_EN(SG_RX_DATA_EN), .DATA_IN_DONE(SG_RX_DONE), .DATA_IN_ERR(SG_RX_ERR), .DATA_IN_FLUSH(wSgRxFlush), .PACKED_DATA(wPackedSgRxData), .PACKED_WEN(wPackedSgRxWen), .PACKED_DATA_DONE(wPackedSgRxDone), .PACKED_DATA_ERR(wPackedSgRxErr), .PACKED_DATA_FLUSHED(wSgRxFlushed) ); fifo_packer_128 sgTxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_TX_DATA), .DATA_IN_EN(SG_TX_DATA_EN), .DATA_IN_DONE(SG_TX_DONE), .DATA_IN_ERR(SG_TX_ERR), .DATA_IN_FLUSH(wSgTxFlush), .PACKED_DATA(wPackedSgTxData), .PACKED_WEN(wPackedSgTxWen), .PACKED_DATA_DONE(wPackedSgTxDone), .PACKED_DATA_ERR(wPackedSgTxErr), .PACKED_DATA_FLUSHED(wSgTxFlushed) ); // FIFOs for storing received data for the channel. (* RAM_STYLE="BLOCK" *) async_fifo_fwft #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_MAIN_FIFO_DEPTH)) mainFifo ( .WR_CLK(CLK), .WR_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .WR_EN(wPackedMainWen), .WR_DATA(wPackedMainData), .WR_FULL(), .RD_CLK(CHNL_CLK), .RD_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .RD_EN(wMainDataRen), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgRxFifo ( .RST(rRst | wSgRxRst), .CLK(CLK), .WR_EN(wPackedSgRxWen), .WR_DATA(wPackedSgRxData), .FULL(), .RD_EN(wSgRxDataRen), .RD_DATA(wSgRxData), .EMPTY(wSgRxDataEmpty), .COUNT(wSgRxFifoCount) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgTxFifo ( .RST(rRst | wSgTxRst), .CLK(CLK), .WR_EN(wPackedSgTxWen), .WR_DATA(wPackedSgTxData), .FULL(), .RD_EN(SG_DATA_REN), .RD_DATA(SG_DATA), .EMPTY(SG_DATA_EMPTY), .COUNT(wSgTxFifoCount) ); // Manage requesting and acknowledging scatter gather data. Note that // these modules will share the main requestor's RX channel. They will // take priority over the main logic's use of the RX channel. sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgRxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(wSgRst), .BUF_RECVD(SG_RX_BUF_RECVD), .BUF_DATA(SG_RX_BUF_DATA), .BUF_LEN_VALID(SG_RX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_RX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_RX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgRxFifoCount), .FIFO_FLUSH(wSgRxFlush), .FIFO_FLUSHED(wSgRxFlushed), .FIFO_RST(wSgRxRst), .RX_REQ(wSgRxReq), .RX_ADDR(wSgRxReqAddr), .RX_LEN(wSgRxReqLen), .RX_REQ_ACK(wReqAck & wSgRxReqProc), .RX_DONE(wPackedSgRxDone) ); sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgTxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(SG_RST), .BUF_RECVD(SG_TX_BUF_RECVD), .BUF_DATA(SG_TX_BUF_DATA), .BUF_LEN_VALID(SG_TX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_TX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_TX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgTxFifoCount), .FIFO_FLUSH(wSgTxFlush), .FIFO_FLUSHED(wSgTxFlushed), .FIFO_RST(wSgTxRst), .RX_REQ(wSgTxReq), .RX_ADDR(wSgTxReqAddr), .RX_LEN(wSgTxReqLen), .RX_REQ_ACK(wReqAck & wSgTxReqProc), .RX_DONE(wPackedSgTxDone) ); // A read requester for the channel and scatter gather requesters. rx_port_requester_mux requesterMux ( .RST(rRst), .CLK(CLK), .SG_RX_REQ(wSgRxReq), .SG_RX_LEN(wSgRxReqLen), .SG_RX_ADDR(wSgRxReqAddr), .SG_RX_REQ_PROC(wSgRxReqProc), .SG_TX_REQ(wSgTxReq), .SG_TX_LEN(wSgTxReqLen), .SG_TX_ADDR(wSgTxReqAddr), .SG_TX_REQ_PROC(wSgTxReqProc), .MAIN_REQ(wMainReq), .MAIN_LEN(wMainReqLen), .MAIN_ADDR(wMainReqAddr), .MAIN_REQ_PROC(wMainReqProc), .RX_REQ(RX_REQ), .RX_REQ_ACK(RX_REQ_ACK), .RX_REQ_TAG(RX_REQ_TAG), .RX_REQ_ADDR(RX_REQ_ADDR), .RX_REQ_LEN(RX_REQ_LEN), .REQ_ACK(wReqAck) ); // Read the scatter gather buffer address and length, continuously so that // we have it ready whenever the next buffer is needed. sg_list_reader_128 #(.C_DATA_WIDTH(C_DATA_WIDTH)) sgListReader ( .CLK(CLK), .RST(rRst | wSgRst), .BUF_DATA(wSgRxData), .BUF_DATA_EMPTY(wSgRxDataEmpty), .BUF_DATA_REN(wSgRxDataRen), .VALID(wSgElemRdy), .EMPTY(), .REN(wSgElemRen), .ADDR(wSgElemAddr), .LEN(wSgElemLen) ); // Main port reader logic rx_port_reader #(.C_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_MAIN_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) reader ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .TXN_DATA(TXN_DATA), .TXN_LEN_VALID(TXN_LEN_VALID), .TXN_OFF_LAST_VALID(TXN_OFF_LAST_VALID), .TXN_DONE_LEN(TXN_DONE_LEN), .TXN_DONE(TXN_DONE), .TXN_ERR(wTxnErr), .TXN_DONE_ACK(TXN_DONE_ACK), .TXN_DATA_FLUSH(wMainFlush), .TXN_DATA_FLUSHED(wMainFlushed), .RX_REQ(wMainReq), .RX_ADDR(wMainReqAddr), .RX_LEN(wMainReqLen), .RX_REQ_ACK(wReqAck & wMainReqProc), .RX_DATA_EN(MAIN_DATA_EN), .RX_DONE(wPackedMainDone), .RX_ERR(wPackedMainErr), .SG_DONE(wPackedSgRxDone), .SG_ERR(wPackedSgRxErr), .SG_ELEM_ADDR(wSgElemAddr), .SG_ELEM_LEN(wSgElemLen), .SG_ELEM_RDY(wSgElemRdy), .SG_ELEM_REN(wSgElemRen), .SG_RST(wSgRst), .CHNL_RX(wChnlRx), .CHNL_RX_LEN(wChnlRxLen), .CHNL_RX_LAST(wChnlRxLast), .CHNL_RX_OFF(wChnlRxOff), .CHNL_RX_RECVD(wChnlRxRecvd), .CHNL_RX_ACK_RECVD(wChnlRxAckRecvd), .CHNL_RX_CONSUMED(wChnlRxConsumed) ); // Manage the CHNL_RX* signals in the CHNL_CLK domain. rx_port_channel_gate #(.C_DATA_WIDTH(C_DATA_WIDTH)) gate ( .RST(rRst), .CLK(CLK), .RX(wChnlRx), .RX_RECVD(wChnlRxRecvd), .RX_ACK_RECVD(wChnlRxAckRecvd), .RX_LAST(wChnlRxLast), .RX_LEN(wChnlRxLen), .RX_OFF(wChnlRxOff), .RX_CONSUMED(wChnlRxConsumed), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty), .RD_EN(wMainDataRen), .CHNL_CLK(CHNL_CLK), .CHNL_RX(CHNL_RX), .CHNL_RX_ACK(CHNL_RX_ACK), .CHNL_RX_LAST(CHNL_RX_LAST), .CHNL_RX_LEN(CHNL_RX_LEN), .CHNL_RX_OFF(CHNL_RX_OFF), .CHNL_RX_DATA(CHNL_RX_DATA), .CHNL_RX_DATA_VALID(CHNL_RX_DATA_VALID), .CHNL_RX_DATA_REN(CHNL_RX_DATA_REN) ); /* reg [31:0] rCounter=0; always @ (posedge CLK) begin if (RST) rCounter <= #1 0; else rCounter <= #1 (RX_REQ_ACK ? rCounter + 1 : rCounter); end wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512_max a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({(SG_RX_DATA_EN != 0) | (MAIN_DATA_EN != 0), RX_REQ_ACK, wSgElemRen, (SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | SG_TX_BUF_ADDR_HI_VALID | SG_TX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID | wSgRst), rCounter[10:7]}), // .TRIG0({wSgRxReq & wSgRxReqProc & wReqAck, // wSgElemRen, // wMainReq | wSgRxReq | wSgTxReq, // (SG_RX_DATA_EN != 0), // SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID | TXN_OFF_LAST_VALID | TXN_LEN_VALID, // rSgElemRenCount > 1100, // wSgRst | wTxnErr | wSgRxFlush | wSgRxFlushed, // wPackedSgRxDone | wPackedSgRxErr}), .DATA({ MAIN_DATA_EN, // 3 //wPackedSgRxData, // 128 SG_RX_DONE, // 1 SG_RX_DATA_EN, // 3 SG_RX_DATA, // 128 wSgRxDataRen, // 1 wSgRxDataEmpty, // 1 MAIN_DATA, // 128 wSgRst, // 1 SG_RST, // 1 wPackedSgRxDone, // 1 wSgRxRst, // 1 wSgRxFlushed, // 1 wSgRxFlush, // 1 SG_RX_BUF_ADDR_LO_VALID, // 1 SG_RX_BUF_ADDR_HI_VALID, // 1 SG_RX_BUF_LEN_VALID, // 1 //SG_RX_BUF_DATA, // 32 rCounter, // 32 RX_REQ_ADDR, // 64 RX_REQ_TAG, // 2 RX_REQ_ACK, // 1 RX_REQ, // 1 wSgTxReqProc, // 1 wSgTxReq, // 1 wSgRxReqProc, // 1 //wSgRxReqAddr, // 64 //wSgElemAddr, // 64 44'd0, // 44 wSgRxReqLen, // 10 RX_REQ_LEN, // 10 wSgRxReq, // 1 wMainReqProc, // 1 wMainReqAddr, // 64 wMainReq, // 1 wReqAck, // 1 wTxnErr, // 1 TXN_OFF_LAST_VALID, // 1 TXN_LEN_VALID}) // 1 ); */ endmodule
(* -*- coding: utf-8 -*- *) (************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) (** * Typeclass-based morphism definition and standard, minimal instances Author: Matthieu Sozeau Institution: LRI, CNRS UMR 8623 - University Paris Sud *) Require Import Coq.Program.Basics. Require Import Coq.Program.Tactics. Require Import Coq.Relations.Relation_Definitions. Require Export Coq.Classes.RelationClasses. Generalizable Variables A eqA B C D R RA RB RC m f x y. Local Obligation Tactic := simpl_relation. (** * Morphisms. We now turn to the definition of [Proper] and declare standard instances. These will be used by the [setoid_rewrite] tactic later. *) (** A morphism for a relation [R] is a proper element of the relation. The relation [R] will be instantiated by [respectful] and [A] by an arrow type for usual morphisms. *) Section Proper. Let U := Type. Context {A B : U}. Class Proper (R : relation A) (m : A) : Prop := proper_prf : R m m. (** Every element in the carrier of a reflexive relation is a morphism for this relation. We use a proxy class for this case which is used internally to discharge reflexivity constraints. The [Reflexive] instance will almost always be used, but it won't apply in general to any kind of [Proper (A -> B) _ _] goal, making proof-search much slower. A cleaner solution would be to be able to set different priorities in different hint bases and select a particular hint database for resolution of a type class constraint. *) Class ProperProxy (R : relation A) (m : A) : Prop := proper_proxy : R m m. Lemma eq_proper_proxy (x : A) : ProperProxy (@eq A) x. Proof. firstorder. Qed. Lemma reflexive_proper_proxy `(Reflexive A R) (x : A) : ProperProxy R x. Proof. firstorder. Qed. Lemma proper_proper_proxy x `(Proper R x) : ProperProxy R x. Proof. firstorder. Qed. (** Respectful morphisms. *) (** The fully dependent version, not used yet. *) Definition respectful_hetero (A B : Type) (C : A -> Type) (D : B -> Type) (R : A -> B -> Prop) (R' : forall (x : A) (y : B), C x -> D y -> Prop) : (forall x : A, C x) -> (forall x : B, D x) -> Prop := fun f g => forall x y, R x y -> R' x y (f x) (g y). (** The non-dependent version is an instance where we forget dependencies. *) Definition respectful (R : relation A) (R' : relation B) : relation (A -> B) := Eval compute in @respectful_hetero A A (fun _ => B) (fun _ => B) R (fun _ _ => R'). End Proper. (** We favor the use of Leibniz equality or a declared reflexive relation when resolving [ProperProxy], otherwise, if the relation is given (not an evar), we fall back to [Proper]. *) Hint Extern 1 (ProperProxy _ _) => class_apply @eq_proper_proxy || class_apply @reflexive_proper_proxy : typeclass_instances. Hint Extern 2 (ProperProxy ?R _) => not_evar R; class_apply @proper_proper_proxy : typeclass_instances. (** Notations reminiscent of the old syntax for declaring morphisms. *) Delimit Scope signature_scope with signature. Module ProperNotations. Notation " R ++> R' " := (@respectful _ _ (R%signature) (R'%signature)) (right associativity, at level 55) : signature_scope. Notation " R ==> R' " := (@respectful _ _ (R%signature) (R'%signature)) (right associativity, at level 55) : signature_scope. Notation " R --> R' " := (@respectful _ _ (flip (R%signature)) (R'%signature)) (right associativity, at level 55) : signature_scope. End ProperNotations. Arguments Proper {A}%type R%signature m. Arguments respectful {A B}%type (R R')%signature _ _. Export ProperNotations. Local Open Scope signature_scope. (** [solve_proper] try to solve the goal [Proper (?==> ... ==>?) f] by repeated introductions and setoid rewrites. It should work fine when [f] is a combination of already known morphisms and quantifiers. *) Ltac solve_respectful t := match goal with | |- respectful _ _ _ _ => let H := fresh "H" in intros ? ? H; solve_respectful ltac:(setoid_rewrite H; t) | _ => t; reflexivity end. Ltac solve_proper := unfold Proper; solve_respectful ltac:(idtac). (** [f_equiv] is a clone of [f_equal] that handles setoid equivalences. For example, if we know that [f] is a morphism for [E1==>E2==>E], then the goal [E (f x y) (f x' y')] will be transformed by [f_equiv] into the subgoals [E1 x x'] and [E2 y y']. *) Ltac f_equiv := match goal with | |- ?R (?f ?x) (?f' _) => let T := type of x in let Rx := fresh "R" in evar (Rx : relation T); let H := fresh in assert (H : (Rx==>R)%signature f f'); unfold Rx in *; clear Rx; [ f_equiv | apply H; clear H; try reflexivity ] | |- ?R ?f ?f' => solve [change (Proper R f); eauto with typeclass_instances | reflexivity ] | _ => idtac end. Section Relations. Let U := Type. Context {A B : U} (P : A -> U). (** [forall_def] reifies the dependent product as a definition. *) Definition forall_def : Type := forall x : A, P x. (** Dependent pointwise lifting of a relation on the range. *) Definition forall_relation (sig : forall a, relation (P a)) : relation (forall x, P x) := fun f g => forall a, sig a (f a) (g a). (** Non-dependent pointwise lifting *) Definition pointwise_relation (R : relation B) : relation (A -> B) := fun f g => forall a, R (f a) (g a). Lemma pointwise_pointwise (R : relation B) : relation_equivalence (pointwise_relation R) (@eq A ==> R). Proof. intros. split; reduce; subst; firstorder. Qed. (** Subrelations induce a morphism on the identity. *) Global Instance subrelation_id_proper `(subrelation A RA RA') : Proper (RA ==> RA') id. Proof. firstorder. Qed. (** The subrelation property goes through products as usual. *) Lemma subrelation_respectful `(subl : subrelation A RA' RA, subr : subrelation B RB RB') : subrelation (RA ==> RB) (RA' ==> RB'). Proof. unfold subrelation in *; firstorder. Qed. (** And of course it is reflexive. *) Lemma subrelation_refl R : @subrelation A R R. Proof. unfold subrelation; firstorder. Qed. (** [Proper] is itself a covariant morphism for [subrelation]. We use an unconvertible premise to avoid looping. *) Lemma subrelation_proper `(mor : Proper A R' m) `(unc : Unconvertible (relation A) R R') `(sub : subrelation A R' R) : Proper R m. Proof. intros. apply sub. apply mor. Qed. Global Instance proper_subrelation_proper : Proper (subrelation ++> eq ==> impl) (@Proper A). Proof. reduce. subst. firstorder. Qed. Global Instance pointwise_subrelation `(sub : subrelation B R R') : subrelation (pointwise_relation R) (pointwise_relation R') | 4. Proof. reduce. unfold pointwise_relation in *. apply sub. apply H. Qed. (** For dependent function types. *) Lemma forall_subrelation (R S : forall x : A, relation (P x)) : (forall a, subrelation (R a) (S a)) -> subrelation (forall_relation R) (forall_relation S). Proof. reduce. apply H. apply H0. Qed. End Relations. Typeclasses Opaque respectful pointwise_relation forall_relation. Arguments forall_relation {A P}%type sig%signature _ _. Arguments pointwise_relation A%type {B}%type R%signature _ _. Hint Unfold Reflexive : core. Hint Unfold Symmetric : core. Hint Unfold Transitive : core. (** Resolution with subrelation: favor decomposing products over applying reflexivity for unconstrained goals. *) Ltac subrelation_tac T U := (is_ground T ; is_ground U ; class_apply @subrelation_refl) || class_apply @subrelation_respectful || class_apply @subrelation_refl. Hint Extern 3 (@subrelation _ ?T ?U) => subrelation_tac T U : typeclass_instances. CoInductive apply_subrelation : Prop := do_subrelation. Ltac proper_subrelation := match goal with [ H : apply_subrelation |- _ ] => clear H ; class_apply @subrelation_proper end. Hint Extern 5 (@Proper _ ?H _) => proper_subrelation : typeclass_instances. (** Essential subrelation instances for [iff], [impl] and [pointwise_relation]. *) Instance iff_impl_subrelation : subrelation iff impl | 2. Proof. firstorder. Qed. Instance iff_flip_impl_subrelation : subrelation iff (flip impl) | 2. Proof. firstorder. Qed. (** We use an extern hint to help unification. *) Hint Extern 4 (subrelation (@forall_relation ?A ?B ?R) (@forall_relation _ _ ?S)) => apply (@forall_subrelation A B R S) ; intro : typeclass_instances. Section GenericInstances. (* Share universes *) Let U := Type. Context {A B C : U}. (** We can build a PER on the Coq function space if we have PERs on the domain and codomain. *) Program Instance respectful_per `(PER A R, PER B R') : PER (R ==> R'). Next Obligation. Proof with auto. assert(R x0 x0). transitivity y0... symmetry... transitivity (y x0)... Qed. (** The complement of a relation conserves its proper elements. *) Program Definition complement_proper `(mR : Proper (A -> A -> Prop) (RA ==> RA ==> iff) R) : Proper (RA ==> RA ==> iff) (complement R) := _. Next Obligation. Proof. unfold complement. pose (mR x y H x0 y0 H0). intuition. Qed. (** The [flip] too, actually the [flip] instance is a bit more general. *) Program Definition flip_proper `(mor : Proper (A -> B -> C) (RA ==> RB ==> RC) f) : Proper (RB ==> RA ==> RC) (flip f) := _. Next Obligation. Proof. apply mor ; auto. Qed. (** Every Transitive relation gives rise to a binary morphism on [impl], contravariant in the first argument, covariant in the second. *) Global Program Instance trans_contra_co_morphism `(Transitive A R) : Proper (R --> R ++> impl) R. Next Obligation. Proof with auto. transitivity x... transitivity x0... Qed. (** Proper declarations for partial applications. *) Global Program Instance trans_contra_inv_impl_morphism `(Transitive A R) : Proper (R --> flip impl) (R x) | 3. Next Obligation. Proof with auto. transitivity y... Qed. Global Program Instance trans_co_impl_morphism `(Transitive A R) : Proper (R ++> impl) (R x) | 3. Next Obligation. Proof with auto. transitivity x0... Qed. Global Program Instance trans_sym_co_inv_impl_morphism `(PER A R) : Proper (R ++> flip impl) (R x) | 3. Next Obligation. Proof with auto. transitivity y... symmetry... Qed. Global Program Instance trans_sym_contra_impl_morphism `(PER A R) : Proper (R --> impl) (R x) | 3. Next Obligation. Proof with auto. transitivity x0... symmetry... Qed. Global Program Instance per_partial_app_morphism `(PER A R) : Proper (R ==> iff) (R x) | 2. Next Obligation. Proof with auto. split. intros ; transitivity x0... intros. transitivity y... symmetry... Qed. (** Every Transitive relation induces a morphism by "pushing" an [R x y] on the left of an [R x z] proof to get an [R y z] goal. *) Global Program Instance trans_co_eq_inv_impl_morphism `(Transitive A R) : Proper (R ==> (@eq A) ==> flip impl) R | 2. Next Obligation. Proof with auto. transitivity y... Qed. (** Every Symmetric and Transitive relation gives rise to an equivariant morphism. *) Global Program Instance PER_morphism `(PER A R) : Proper (R ==> R ==> iff) R | 1. Next Obligation. Proof with auto. split ; intros. transitivity x0... transitivity x... symmetry... transitivity y... transitivity y0... symmetry... Qed. Lemma symmetric_equiv_flip `(Symmetric A R) : relation_equivalence R (flip R). Proof. firstorder. Qed. Global Program Instance compose_proper RA RB RC : Proper ((RB ==> RC) ==> (RA ==> RB) ==> (RA ==> RC)) (@compose A B C). Next Obligation. Proof. simpl_relation. unfold compose. apply H. apply H0. apply H1. Qed. (** Coq functions are morphisms for Leibniz equality, applied only if really needed. *) Global Instance reflexive_eq_dom_reflexive `(Reflexive B R') : Reflexive (@Logic.eq A ==> R'). Proof. simpl_relation. Qed. (** [respectful] is a morphism for relation equivalence. *) Global Instance respectful_morphism : Proper (relation_equivalence ++> relation_equivalence ++> relation_equivalence) (@respectful A B). Proof. reduce. unfold respectful, relation_equivalence, predicate_equivalence in * ; simpl in *. split ; intros. rewrite <- H0. apply H1. rewrite H. assumption. rewrite H0. apply H1. rewrite <- H. assumption. Qed. (** [R] is Reflexive, hence we can build the needed proof. *) Lemma Reflexive_partial_app_morphism `(Proper (A -> B) (R ==> R') m, ProperProxy A R x) : Proper R' (m x). Proof. simpl_relation. Qed. Lemma flip_respectful (R : relation A) (R' : relation B) : relation_equivalence (flip (R ==> R')) (flip R ==> flip R'). Proof. intros. unfold flip, respectful. split ; intros ; intuition. Qed. (** Treating flip: can't make them direct instances as we need at least a [flip] present in the goal. *) Lemma flip1 `(subrelation A R' R) : subrelation (flip (flip R')) R. Proof. firstorder. Qed. Lemma flip2 `(subrelation A R R') : subrelation R (flip (flip R')). Proof. firstorder. Qed. (** That's if and only if *) Lemma eq_subrelation `(Reflexive A R) : subrelation (@eq A) R. Proof. simpl_relation. Qed. (** Once we have normalized, we will apply this instance to simplify the problem. *) Definition proper_flip_proper `(mor : Proper A R m) : Proper (flip R) m := mor. (** Every reflexive relation gives rise to a morphism, only for immediately solving goals without variables. *) Lemma reflexive_proper `{Reflexive A R} (x : A) : Proper R x. Proof. firstorder. Qed. Lemma proper_eq (x : A) : Proper (@eq A) x. Proof. intros. apply reflexive_proper. Qed. End GenericInstances. Class PartialApplication. CoInductive normalization_done : Prop := did_normalization. Class Params {A : Type} (of : A) (arity : nat). Ltac partial_application_tactic := let rec do_partial_apps H m cont := match m with | ?m' ?x => class_apply @Reflexive_partial_app_morphism ; [(do_partial_apps H m' ltac:idtac)|clear H] | _ => cont end in let rec do_partial H ar m := match ar with | 0%nat => do_partial_apps H m ltac:(fail 1) | S ?n' => match m with ?m' ?x => do_partial H n' m' end end in let params m sk fk := (let m' := fresh in head_of_constr m' m ; let n := fresh in evar (n:nat) ; let v := eval compute in n in clear n ; let H := fresh in assert(H:Params m' v) by typeclasses eauto ; let v' := eval compute in v in subst m'; (sk H v' || fail 1)) || fk in let on_morphism m cont := params m ltac:(fun H n => do_partial H n m) ltac:(cont) in match goal with | [ _ : normalization_done |- _ ] => fail 1 | [ _ : @Params _ _ _ |- _ ] => fail 1 | [ |- @Proper ?T _ (?m ?x) ] => match goal with | [ H : PartialApplication |- _ ] => class_apply @Reflexive_partial_app_morphism; [|clear H] | _ => on_morphism (m x) ltac:(class_apply @Reflexive_partial_app_morphism) end end. (** Bootstrap !!! *) Instance proper_proper : Proper (relation_equivalence ==> eq ==> iff) (@Proper A). Proof. simpl_relation. reduce in H. split ; red ; intros. setoid_rewrite <- H. apply H0. setoid_rewrite H. apply H0. Qed. Ltac proper_reflexive := match goal with | [ _ : normalization_done |- _ ] => fail 1 | _ => class_apply proper_eq || class_apply @reflexive_proper end. Hint Extern 1 (subrelation (flip _) _) => class_apply @flip1 : typeclass_instances. Hint Extern 1 (subrelation _ (flip _)) => class_apply @flip2 : typeclass_instances. Hint Extern 1 (Proper _ (complement _)) => apply @complement_proper : typeclass_instances. Hint Extern 1 (Proper _ (flip _)) => apply @flip_proper : typeclass_instances. Hint Extern 2 (@Proper _ (flip _) _) => class_apply @proper_flip_proper : typeclass_instances. Hint Extern 4 (@Proper _ _ _) => partial_application_tactic : typeclass_instances. Hint Extern 7 (@Proper _ _ _) => proper_reflexive : typeclass_instances. (** Special-purpose class to do normalization of signatures w.r.t. flip. *) Section Normalize. Context (A : Type). Class Normalizes (m : relation A) (m' : relation A) : Prop := normalizes : relation_equivalence m m'. (** Current strategy: add [flip] everywhere and reduce using [subrelation] afterwards. *) Lemma proper_normalizes_proper `(Normalizes R0 R1, Proper A R1 m) : Proper R0 m. Proof. red in H, H0. rewrite H. assumption. Qed. Lemma flip_atom R : Normalizes R (flip (flip R)). Proof. firstorder. Qed. End Normalize. Lemma flip_arrow {A : Type} {B : Type} `(NA : Normalizes A R (flip R'''), NB : Normalizes B R' (flip R'')) : Normalizes (A -> B) (R ==> R') (flip (R''' ==> R'')%signature). Proof. unfold Normalizes in *. intros. unfold relation_equivalence in *. unfold predicate_equivalence in *. simpl in *. unfold respectful. unfold flip in *. firstorder. apply NB. apply H. apply NA. apply H0. apply NB. apply H. apply NA. apply H0. Qed. Ltac normalizes := match goal with | [ |- Normalizes _ (respectful _ _) _ ] => class_apply @flip_arrow | _ => class_apply @flip_atom end. Ltac proper_normalization := match goal with | [ _ : normalization_done |- _ ] => fail 1 | [ _ : apply_subrelation |- @Proper _ ?R _ ] => let H := fresh "H" in set(H:=did_normalization) ; class_apply @proper_normalizes_proper end. Hint Extern 1 (Normalizes _ _ _) => normalizes : typeclass_instances. Hint Extern 6 (@Proper _ _ _) => proper_normalization : typeclass_instances. (** When the relation on the domain is symmetric, we can flip the relation on the codomain. Same for binary functions. *) Lemma proper_sym_flip : forall `(Symmetric A R1)`(Proper (A->B) (R1==>R2) f), Proper (R1==>flip R2) f. Proof. intros A R1 Sym B R2 f Hf. intros x x' Hxx'. apply Hf, Sym, Hxx'. Qed. Lemma proper_sym_flip_2 : forall `(Symmetric A R1)`(Symmetric B R2)`(Proper (A->B->C) (R1==>R2==>R3) f), Proper (R1==>R2==>flip R3) f. Proof. intros A R1 Sym1 B R2 Sym2 C R3 f Hf. intros x x' Hxx' y y' Hyy'. apply Hf; auto. Qed. (** When the relation on the domain is symmetric, a predicate is compatible with [iff] as soon as it is compatible with [impl]. Same with a binary relation. *) Lemma proper_sym_impl_iff : forall `(Symmetric A R)`(Proper _ (R==>impl) f), Proper (R==>iff) f. Proof. intros A R Sym f Hf x x' Hxx'. repeat red in Hf. split; eauto. Qed. Lemma proper_sym_impl_iff_2 : forall `(Symmetric A R)`(Symmetric B R')`(Proper _ (R==>R'==>impl) f), Proper (R==>R'==>iff) f. Proof. intros A R Sym B R' Sym' f Hf x x' Hxx' y y' Hyy'. repeat red in Hf. split; eauto. Qed. (** A [PartialOrder] is compatible with its underlying equivalence. *) Instance PartialOrder_proper `(PartialOrder A eqA R) : Proper (eqA==>eqA==>iff) R. Proof. intros. apply proper_sym_impl_iff_2; auto with *. intros x x' Hx y y' Hy Hr. transitivity x. generalize (partial_order_equivalence x x'); compute; intuition. transitivity y; auto. generalize (partial_order_equivalence y y'); compute; intuition. Qed. (** From a [PartialOrder] to the corresponding [StrictOrder]: [lt = le /\ ~eq]. If the order is total, we could also say [gt = ~le]. *) Lemma PartialOrder_StrictOrder `(PartialOrder A eqA R) : StrictOrder (relation_conjunction R (complement eqA)). Proof. split; compute. intros x (_,Hx). apply Hx, Equivalence_Reflexive. intros x y z (Hxy,Hxy') (Hyz,Hyz'). split. apply PreOrder_Transitive with y; assumption. intro Hxz. apply Hxy'. apply partial_order_antisym; auto. rewrite Hxz; auto. Qed. (** From a [StrictOrder] to the corresponding [PartialOrder]: [le = lt \/ eq]. If the order is total, we could also say [ge = ~lt]. *) Lemma StrictOrder_PreOrder `(Equivalence A eqA, StrictOrder A R, Proper _ (eqA==>eqA==>iff) R) : PreOrder (relation_disjunction R eqA). Proof. split. intros x. right. reflexivity. intros x y z [Hxy|Hxy] [Hyz|Hyz]. left. transitivity y; auto. left. rewrite <- Hyz; auto. left. rewrite Hxy; auto. right. transitivity y; auto. Qed. Hint Extern 4 (PreOrder (relation_disjunction _ _)) => class_apply StrictOrder_PreOrder : typeclass_instances. Lemma StrictOrder_PartialOrder `(Equivalence A eqA, StrictOrder A R, Proper _ (eqA==>eqA==>iff) R) : PartialOrder eqA (relation_disjunction R eqA). Proof. intros. intros x y. compute. intuition. elim (StrictOrder_Irreflexive x). transitivity y; auto. Qed. Hint Extern 4 (StrictOrder (relation_conjunction _ _)) => class_apply PartialOrder_StrictOrder : typeclass_instances. Hint Extern 4 (PartialOrder _ (relation_disjunction _ _)) => class_apply StrictOrder_PartialOrder : typeclass_instances.
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_128.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Receives data from the tx_engine and buffers the input // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module tx_port_128 #( parameter C_DATA_WIDTH = 9'd128, parameter C_FIFO_DEPTH = 512, // Local parameters parameter C_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_FIFO_DEPTH))+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_PAYLOAD_SIZE, // Maximum write payload: 000=128B, 001=256B, 010=512B, 011=1024B output TXN, // Write transaction notification input TXN_ACK, // Write transaction acknowledged output [31:0] TXN_LEN, // Write transaction length output [31:0] TXN_OFF_LAST, // Write transaction offset/last output [31:0] TXN_DONE_LEN, // Write transaction actual transfer length output TXN_DONE, // Write transaction done input TXN_DONE_ACK, // Write transaction actual transfer length read input [C_DATA_WIDTH-1:0] SG_DATA, // Scatter gather data input SG_DATA_EMPTY, // Scatter gather buffer empty output SG_DATA_REN, // Scatter gather data read enable output SG_RST, // Scatter gather reset input SG_ERR, // Scatter gather read encountered an error output TX_REQ, // Outgoing write request input TX_REQ_ACK, // Outgoing write request acknowledged output [63:0] TX_ADDR, // Outgoing write high address output [9:0] TX_LEN, // Outgoing write length (in 32 bit words) output [C_DATA_WIDTH-1:0] TX_DATA, // Outgoing write data input TX_DATA_REN, // Outgoing write data read enable input TX_SENT, // Outgoing write complete input CHNL_CLK, // Channel write clock input CHNL_TX, // Channel write receive signal output CHNL_TX_ACK, // Channel write acknowledgement signal input CHNL_TX_LAST, // Channel last write input [31:0] CHNL_TX_LEN, // Channel write length (in 32 bit words) input [30:0] CHNL_TX_OFF, // Channel write offset input [C_DATA_WIDTH-1:0] CHNL_TX_DATA, // Channel write data input CHNL_TX_DATA_VALID, // Channel write data valid output CHNL_TX_DATA_REN // Channel write data has been recieved ); `include "functions.vh" wire wGateRen; wire wGateEmpty; wire [C_DATA_WIDTH:0] wGateData; wire wBufWen; wire [C_FIFO_DEPTH_WIDTH-1:0] wBufCount; wire [C_DATA_WIDTH-1:0] wBufData; wire wTxn; wire wTxnAck; wire wTxnLast; wire [31:0] wTxnLen; wire [30:0] wTxnOff; wire [31:0] wTxnWordsRecvd; wire wTxnDone; wire wTxnErr; wire wSgElemRen; wire wSgElemRdy; wire wSgElemEmpty; wire [31:0] wSgElemLen; wire [63:0] wSgElemAddr; wire wTxLast; reg [4:0] rWideRst=0; reg rRst=0; // Generate a wide reset from the input reset. always @ (posedge CLK) begin rRst <= #1 rWideRst[4]; if (RST) rWideRst <= #1 5'b11111; else rWideRst <= (rWideRst<<1); end // Capture channel transaction open/close events as well as channel data. tx_port_channel_gate_128 #(.C_DATA_WIDTH(C_DATA_WIDTH)) gate ( .RST(rRst), .RD_CLK(CLK), .RD_DATA(wGateData), .RD_EMPTY(wGateEmpty), .RD_EN(wGateRen), .CHNL_CLK(CHNL_CLK), .CHNL_TX(CHNL_TX), .CHNL_TX_ACK(CHNL_TX_ACK), .CHNL_TX_LAST(CHNL_TX_LAST), .CHNL_TX_LEN(CHNL_TX_LEN), .CHNL_TX_OFF(CHNL_TX_OFF), .CHNL_TX_DATA(CHNL_TX_DATA), .CHNL_TX_DATA_VALID(CHNL_TX_DATA_VALID), .CHNL_TX_DATA_REN(CHNL_TX_DATA_REN) ); // Filter transaction events from channel data. Use the events to put only // the requested amount of data into the port buffer. tx_port_monitor_128 #(.C_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_FIFO_DEPTH)) monitor ( .RST(rRst), .CLK(CLK), .EVT_DATA(wGateData), .EVT_DATA_EMPTY(wGateEmpty), .EVT_DATA_RD_EN(wGateRen), .WR_DATA(wBufData), .WR_EN(wBufWen), .WR_COUNT(wBufCount), .TXN(wTxn), .ACK(wTxnAck), .LAST(wTxnLast), .LEN(wTxnLen), .OFF(wTxnOff), .WORDS_RECVD(wTxnWordsRecvd), .DONE(wTxnDone), .TX_ERR(SG_ERR) ); // Buffer the incoming channel data. Also make sure to discard only as // much data as is needed for a transfer (which may involve non-integral // packets (i.e. reading only 1, 2, or 3 words out of the packet). tx_port_buffer_128 #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_FIFO_DEPTH)) buffer ( .CLK(CLK), .RST(rRst | (TXN_DONE & wTxnErr)), .RD_DATA(TX_DATA), .RD_EN(TX_DATA_REN), .LEN_VALID(TX_REQ_ACK), .LEN_LSB(TX_LEN[1:0]), .LEN_LAST(wTxLast), .WR_DATA(wBufData), .WR_EN(wBufWen), .WR_COUNT(wBufCount) ); // Read the scatter gather buffer address and length, continuously so that // we have it ready whenever the next buffer is needed. sg_list_reader_128 #(.C_DATA_WIDTH(C_DATA_WIDTH)) sgListReader ( .CLK(CLK), .RST(rRst | SG_RST), .BUF_DATA(SG_DATA), .BUF_DATA_EMPTY(SG_DATA_EMPTY), .BUF_DATA_REN(SG_DATA_REN), .VALID(wSgElemRdy), .EMPTY(wSgElemEmpty), .REN(wSgElemRen), .ADDR(wSgElemAddr), .LEN(wSgElemLen) ); // Controls the flow of request to the tx engine for transfers in a transaction. tx_port_writer writer ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_PAYLOAD_SIZE(CONFIG_MAX_PAYLOAD_SIZE), .TXN(TXN), .TXN_ACK(TXN_ACK), .TXN_LEN(TXN_LEN), .TXN_OFF_LAST(TXN_OFF_LAST), .TXN_DONE_LEN(TXN_DONE_LEN), .TXN_DONE(TXN_DONE), .TXN_ERR(wTxnErr), .TXN_DONE_ACK(TXN_DONE_ACK), .NEW_TXN(wTxn), .NEW_TXN_ACK(wTxnAck), .NEW_TXN_LAST(wTxnLast), .NEW_TXN_LEN(wTxnLen), .NEW_TXN_OFF(wTxnOff), .NEW_TXN_WORDS_RECVD(wTxnWordsRecvd), .NEW_TXN_DONE(wTxnDone), .SG_ELEM_ADDR(wSgElemAddr), .SG_ELEM_LEN(wSgElemLen), .SG_ELEM_RDY(wSgElemRdy), .SG_ELEM_EMPTY(wSgElemEmpty), .SG_ELEM_REN(wSgElemRen), .SG_RST(SG_RST), .SG_ERR(SG_ERR), .TX_REQ(TX_REQ), .TX_REQ_ACK(TX_REQ_ACK), .TX_ADDR(TX_ADDR), .TX_LEN(TX_LEN), .TX_LAST(wTxLast), .TX_SENT(TX_SENT) ); endmodule
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: INSTITUTO TECNOLOGICO DE COSTA RICA // Engineer: MAURICIO CARVAJAL DELGADO // // Create Date: 10:33:48 03/17/2013 // Design Name: // Module Name: Transmisor // Project Name: // Target Devices: // Tool versions: // Description: ////////////////////////////////////////////////////////////////////////////////// module Transmisor #( parameter DBIT = 8 , // #databits SB_TICK = 16 // #ticks fors top bits ) ( input wire clk, reset, input wire tx_start, s_tick, input wire [7:0] din, output reg TX_Done=0, output wire tx ); // synlbolic s t a t e d e c l a r a t i o n localparam [1:0] idle = 2'b00, start = 2'b01, data = 2'b10, stop = 2'b11; // signal declaratio n reg [1:0] state_reg=0, state_next=0; reg [3:0] s_reg=0, s_next=0; reg [2:0] n_reg=0, n_next=0; reg [7:0] b_reg=0, b_next=0; reg tx_reg=1, tx_next=1; // FSMD state & data registers always @(posedge clk, posedge reset) if (reset) begin state_reg <= idle; s_reg <= 0; n_reg <= 0; b_reg <= 0 ; tx_reg <= 1'b1; end else begin state_reg <= state_next; s_reg <= s_next; n_reg <= n_next; b_reg <= b_next; tx_reg <= tx_next; end // FSMD next_state logic&functional units always @* begin state_next = state_reg; TX_Done = 1'b0; s_next = s_reg; n_next = n_reg; b_next = b_reg; tx_next = tx_reg; case (state_reg) idle: begin tx_next = 1'b1; if (tx_start) begin state_next = start; s_next =0; b_next = din; end end start: begin tx_next =1'b0; if (s_tick) if (s_reg ==15) begin state_next = data; s_next = 0; n_next = 0; end else s_next = s_reg + 1; end data: begin tx_next =b_reg[0]; if (s_tick) if (s_reg == 15) begin s_next =0; b_next = b_reg>>1; if (n_reg==(DBIT-1)) state_next = stop; else n_next = n_reg + 1; end else s_next = s_reg + 1; end stop: begin tx_next =1'b1; if (s_tick) if (s_reg==(SB_TICK-1 )) begin state_next = idle; TX_Done = 1'b1; end else s_next = s_reg+ 1; end endcase end // output assign tx = tx_reg; endmodule
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2010 by Wilson Snyder. module t (/*AUTOARG*/ // Outputs out, // Inputs in ); input in; // inputs don't get flagged as undriven output out; // outputs don't get flagged as unused sub sub (); // Check we don't warn about unused UDP signals udp_mux2 udpsub (out, in, in, in); // Check ignoreds mark as used reg sysused; initial $bboxed(sysused); // Check file IO. The fopen is the "driver" all else a usage. integer infile; integer outfile; initial begin outfile = $fopen("obj_dir/t_lint_unused_bad/open.log", "w"); $fwrite(outfile, "1\n"); $fclose(outfile); infile = $fopen("obj_dir/t_lint_unused_bad/open.log", "r"); if ($fgetc(infile) != "1") begin end end wire _unused_ok; endmodule module sub; wire pub /*verilator public*/; // Ignore publics localparam THREE = 3; endmodule primitive udp_mux2 (q, a, b, s); output q; input a, b, s; table //a b s : out 1 ? 0 : 1 ; 0 ? 0 : 0 ; ? 1 1 : 1 ; ? 0 1 : 0 ; 0 0 x : 0 ; 1 1 x : 1 ; endtable endprimitive
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2010 by Wilson Snyder. module t (/*AUTOARG*/ // Outputs out, // Inputs in ); input in; // inputs don't get flagged as undriven output out; // outputs don't get flagged as unused sub sub (); // Check we don't warn about unused UDP signals udp_mux2 udpsub (out, in, in, in); // Check ignoreds mark as used reg sysused; initial $bboxed(sysused); // Check file IO. The fopen is the "driver" all else a usage. integer infile; integer outfile; initial begin outfile = $fopen("obj_dir/t_lint_unused_bad/open.log", "w"); $fwrite(outfile, "1\n"); $fclose(outfile); infile = $fopen("obj_dir/t_lint_unused_bad/open.log", "r"); if ($fgetc(infile) != "1") begin end end wire _unused_ok; endmodule module sub; wire pub /*verilator public*/; // Ignore publics localparam THREE = 3; endmodule primitive udp_mux2 (q, a, b, s); output q; input a, b, s; table //a b s : out 1 ? 0 : 1 ; 0 ? 0 : 0 ; ? 1 1 : 1 ; ? 0 1 : 0 ; 0 0 x : 0 ; 1 1 x : 1 ; endtable endprimitive
// (C) 2001-2016 Altera Corporation. All rights reserved. // Your use of Altera Corporation's design tools, logic functions and other // software and tools, and its AMPP partner logic functions, and any output // files any of the foregoing (including device programming or simulation // files), and any associated documentation or information are expressly subject // to the terms and conditions of the Altera Program License Subscription // Agreement, Altera MegaCore Function License Agreement, or other applicable // license agreement, including, without limitation, that your use is for the // sole purpose of programming logic devices manufactured by Altera and sold by // Altera or its authorized distributors. Please refer to the applicable // agreement for further details. // THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS // IN THIS FILE. /****************************************************************************** * * * This module reads and writes data to the RS232 connector on Altera's * * DE-series Development and Education Boards. * * * ******************************************************************************/ module soc_design_UART_COM ( // Inputs clk, reset, address, chipselect, byteenable, read, write, writedata, UART_RXD, // Bidirectionals // Outputs irq, readdata, UART_TXD ); /***************************************************************************** * Parameter Declarations * *****************************************************************************/ parameter CW = 10; // Baud counter width parameter BAUD_TICK_COUNT = 868; parameter HALF_BAUD_TICK_COUNT = 434; parameter TDW = 10; // Total data width parameter DW = 8; // Data width parameter ODD_PARITY = 1'b0; /***************************************************************************** * Port Declarations * *****************************************************************************/ // Inputs input clk; input reset; input address; input chipselect; input [ 3: 0] byteenable; input read; input write; input [31: 0] writedata; input UART_RXD; // Bidirectionals // Outputs output reg irq; output reg [31: 0] readdata; output UART_TXD; /***************************************************************************** * Constant Declarations * *****************************************************************************/ /***************************************************************************** * Internal Wires and Registers Declarations * *****************************************************************************/ // Internal Wires wire read_fifo_read_en; wire [ 7: 0] read_available; wire read_data_valid; wire [(DW-1):0] read_data; wire parity_error; wire write_data_parity; wire [ 7: 0] write_space; // Internal Registers reg read_interrupt_en; reg write_interrupt_en; reg read_interrupt; reg write_interrupt; reg write_fifo_write_en; reg [(DW-1):0] data_to_uart; // State Machine Registers /***************************************************************************** * Finite State Machine(s) * *****************************************************************************/ /***************************************************************************** * Sequential Logic * *****************************************************************************/ always @(posedge clk) begin if (reset) irq <= 1'b0; else irq <= write_interrupt | read_interrupt; end always @(posedge clk) begin if (reset) readdata <= 32'h00000000; else if (chipselect) begin if (address == 1'b0) readdata <= {8'h00, read_available, read_data_valid, 5'h00, parity_error, 1'b0, read_data[(DW - 1):0]}; else readdata <= {8'h00, write_space, 6'h00, write_interrupt, read_interrupt, 6'h00, write_interrupt_en, read_interrupt_en}; end end always @(posedge clk) begin if (reset) read_interrupt_en <= 1'b0; else if ((chipselect) && (write) && (address) && (byteenable[0])) read_interrupt_en <= writedata[0]; end always @(posedge clk) begin if (reset) write_interrupt_en <= 1'b0; else if ((chipselect) && (write) && (address) && (byteenable[0])) write_interrupt_en <= writedata[1]; end always @(posedge clk) begin if (reset) read_interrupt <= 1'b0; else if (read_interrupt_en == 1'b0) read_interrupt <= 1'b0; else read_interrupt <= (&(read_available[6:5]) | read_available[7]); end always @(posedge clk) begin if (reset) write_interrupt <= 1'b0; else if (write_interrupt_en == 1'b0) write_interrupt <= 1'b0; else write_interrupt <= (&(write_space[6:5]) | write_space[7]); end always @(posedge clk) begin if (reset) write_fifo_write_en <= 1'b0; else write_fifo_write_en <= chipselect & write & ~address & byteenable[0]; end always @(posedge clk) begin if (reset) data_to_uart <= 'h0; else data_to_uart <= writedata[(DW - 1):0]; end /***************************************************************************** * Combinational Logic * *****************************************************************************/ assign parity_error = 1'b0; assign read_fifo_read_en = chipselect & read & ~address & byteenable[0]; assign write_data_parity = (^(data_to_uart)) ^ ODD_PARITY; /***************************************************************************** * Internal Modules * *****************************************************************************/ altera_up_rs232_in_deserializer RS232_In_Deserializer ( // Inputs .clk (clk), .reset (reset), .serial_data_in (UART_RXD), .receive_data_en (read_fifo_read_en), // Bidirectionals // Outputs .fifo_read_available (read_available), .received_data_valid (read_data_valid), .received_data (read_data) ); defparam RS232_In_Deserializer.CW = CW, RS232_In_Deserializer.BAUD_TICK_COUNT = BAUD_TICK_COUNT, RS232_In_Deserializer.HALF_BAUD_TICK_COUNT = HALF_BAUD_TICK_COUNT, RS232_In_Deserializer.TDW = TDW, RS232_In_Deserializer.DW = (DW - 1); altera_up_rs232_out_serializer RS232_Out_Serializer ( // Inputs .clk (clk), .reset (reset), .transmit_data (data_to_uart), .transmit_data_en (write_fifo_write_en), // Bidirectionals // Outputs .fifo_write_space (write_space), .serial_data_out (UART_TXD) ); defparam RS232_Out_Serializer.CW = CW, RS232_Out_Serializer.BAUD_TICK_COUNT = BAUD_TICK_COUNT, RS232_Out_Serializer.HALF_BAUD_TICK_COUNT = HALF_BAUD_TICK_COUNT, RS232_Out_Serializer.TDW = TDW, RS232_Out_Serializer.DW = (DW - 1); endmodule
//***************************************************************************** // (c) Copyright 2009 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor: Xilinx // \ \ \/ Version: %version // \ \ Application: MIG // / / Filename: ddr_phy_init.v // /___/ /\ Date Last Modified: $Date: 2011/06/02 08:35:09 $ // \ \ / \ Date Created: // \___\/\___\ // //Device: 7 Series //Design Name: DDR3 SDRAM //Purpose: // Memory initialization and overall master state control during // initialization and calibration. Specifically, the following functions // are performed: // 1. Memory initialization (initial AR, mode register programming, etc.) // 2. Initiating write leveling // 3. Generate training pattern writes for read leveling. Generate // memory readback for read leveling. // This module has an interface for providing control/address and write // data to the PHY Control Block during initialization/calibration. // Once initialization and calibration are complete, control is passed to the MC. // //Reference: //Revision History: // //***************************************************************************** /****************************************************************************** **$Id: ddr_phy_init.v,v 1.1 2011/06/02 08:35:09 mishra Exp $ **$Date: 2011/06/02 08:35:09 $ **$Author: mishra $ **$Revision: 1.1 $ **$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_7series_v1_3/data/dlib/7series/ddr3_sdram/verilog/rtl/phy/ddr_phy_init.v,v $ ******************************************************************************/ `timescale 1ps/1ps module mig_7series_v1_9_ddr_phy_init # ( parameter TCQ = 100, parameter nCK_PER_CLK = 4, // # of memory clocks per CLK parameter CLK_PERIOD = 3000, // Logic (internal) clk period (in ps) parameter USE_ODT_PORT = 0, // 0 - No ODT output from FPGA // 1 - ODT output from FPGA parameter PRBS_WIDTH = 8, // PRBS sequence = 2^PRBS_WIDTH parameter BANK_WIDTH = 2, parameter CA_MIRROR = "OFF", // C/A mirror opt for DDR3 dual rank parameter COL_WIDTH = 10, parameter nCS_PER_RANK = 1, // # of CS bits per rank e.g. for // component I/F with CS_WIDTH=1, // nCS_PER_RANK=# of components parameter DQ_WIDTH = 64, parameter DQS_WIDTH = 8, parameter DQS_CNT_WIDTH = 3, // = ceil(log2(DQS_WIDTH)) parameter ROW_WIDTH = 14, parameter CS_WIDTH = 1, parameter RANKS = 1, // # of memory ranks in the interface parameter CKE_WIDTH = 1, // # of cke outputs parameter DRAM_TYPE = "DDR3", parameter REG_CTRL = "ON", parameter ADDR_CMD_MODE= "1T", // calibration Address parameter CALIB_ROW_ADD = 16'h0000,// Calibration row address parameter CALIB_COL_ADD = 12'h000, // Calibration column address parameter CALIB_BA_ADD = 3'h0, // Calibration bank address // DRAM mode settings parameter AL = "0", // Additive Latency option parameter BURST_MODE = "8", // Burst length parameter BURST_TYPE = "SEQ", // Burst type // parameter nAL = 0, // Additive latency (in clk cyc) parameter nCL = 5, // Read CAS latency (in clk cyc) parameter nCWL = 5, // Write CAS latency (in clk cyc) parameter tRFC = 110000, // Refresh-to-command delay (in ps) parameter OUTPUT_DRV = "HIGH", // DRAM reduced output drive option parameter RTT_NOM = "60", // Nominal ODT termination value parameter RTT_WR = "60", // Write ODT termination value parameter WRLVL = "ON", // Enable write leveling // parameter PHASE_DETECT = "ON", // Enable read phase detector parameter DDR2_DQSN_ENABLE = "YES", // Enable differential DQS for DDR2 parameter nSLOTS = 1, // Number of DIMM SLOTs in the system parameter SIM_INIT_OPTION = "NONE", // "NONE", "SKIP_PU_DLY", "SKIP_INIT" parameter SIM_CAL_OPTION = "NONE", // "NONE", "FAST_CAL", "SKIP_CAL" parameter CKE_ODT_AUX = "FALSE", parameter PRE_REV3ES = "OFF", // Enable TG error detection during calibration parameter TEST_AL = "0" // Internal use for ICM verification ) ( input clk, input rst, input [2*8*nCK_PER_CLK-1:0] prbs_o, input delay_incdec_done, input ck_addr_cmd_delay_done, input pi_phase_locked_all, input pi_dqs_found_done, input dqsfound_retry, input dqs_found_prech_req, output reg pi_phaselock_start, output pi_phase_locked_err, output pi_calib_done, input phy_if_empty, // Read/write calibration interface input wrlvl_done, input wrlvl_rank_done, input wrlvl_byte_done, input wrlvl_byte_redo, input wrlvl_final, output reg wrlvl_final_if_rst, input oclkdelay_calib_done, input oclk_prech_req, input oclk_calib_resume, output reg oclkdelay_calib_start, input done_dqs_tap_inc, input [5:0] rd_data_offset_0, input [5:0] rd_data_offset_1, input [5:0] rd_data_offset_2, input [6*RANKS-1:0] rd_data_offset_ranks_0, input [6*RANKS-1:0] rd_data_offset_ranks_1, input [6*RANKS-1:0] rd_data_offset_ranks_2, input pi_dqs_found_rank_done, input wrcal_done, input wrcal_prech_req, input wrcal_read_req, input wrcal_act_req, input temp_wrcal_done, input [7:0] slot_0_present, input [7:0] slot_1_present, output reg wl_sm_start, output reg wr_lvl_start, output reg wrcal_start, output reg wrcal_rd_wait, output reg wrcal_sanity_chk, output reg tg_timer_done, output reg no_rst_tg_mc, input rdlvl_stg1_done, input rdlvl_stg1_rank_done, output reg rdlvl_stg1_start, output reg pi_dqs_found_start, output reg detect_pi_found_dqs, // rdlvl stage 1 precharge requested after each DQS input rdlvl_prech_req, input rdlvl_last_byte_done, input wrcal_resume, input wrcal_sanity_chk_done, // MPR read leveling input mpr_rdlvl_done, input mpr_rnk_done, input mpr_last_byte_done, output reg mpr_rdlvl_start, output reg mpr_end_if_reset, // PRBS Read Leveling input prbs_rdlvl_done, input prbs_last_byte_done, input prbs_rdlvl_prech_req, output reg prbs_rdlvl_start, output reg prbs_gen_clk_en, // Signals shared btw multiple calibration stages output reg prech_done, // Data select / status output reg init_calib_complete, // Signal to mask memory model error for Invalid latching edge output reg calib_writes, // PHY address/control // 2 commands to PHY Control Block per div 2 clock in 2:1 mode // 4 commands to PHY Control Block per div 4 clock in 4:1 mode output reg [nCK_PER_CLK*ROW_WIDTH-1:0] phy_address, output reg [nCK_PER_CLK*BANK_WIDTH-1:0]phy_bank, output reg [nCK_PER_CLK-1:0] phy_ras_n, output reg [nCK_PER_CLK-1:0] phy_cas_n, output reg [nCK_PER_CLK-1:0] phy_we_n, output reg phy_reset_n, output [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] phy_cs_n, // Hard PHY Interface signals input phy_ctl_ready, input phy_ctl_full, input phy_cmd_full, input phy_data_full, output reg calib_ctl_wren, output reg calib_cmd_wren, output reg [1:0] calib_seq, output reg write_calib, output reg read_calib, // PHY_Ctl_Wd output reg [2:0] calib_cmd, // calib_aux_out used for CKE and ODT output reg [3:0] calib_aux_out, output reg [1:0] calib_odt , output reg [nCK_PER_CLK-1:0] calib_cke , output [1:0] calib_rank_cnt, output reg [1:0] calib_cas_slot, output reg [5:0] calib_data_offset_0, output reg [5:0] calib_data_offset_1, output reg [5:0] calib_data_offset_2, // PHY OUT_FIFO output reg calib_wrdata_en, output reg [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_wrdata, // PHY Read output phy_rddata_en, output phy_rddata_valid, output [255:0] dbg_phy_init ); //***************************************************************************** // Assertions to be added //***************************************************************************** // The phy_ctl_full signal must never be asserted in synchronous mode of // operation either 4:1 or 2:1 // // The RANKS parameter must never be set to '0' by the user // valid values: 1 to 4 // //***************************************************************************** //*************************************************************************** // Number of Read level stage 1 writes limited to a SDRAM row // The address of Read Level stage 1 reads must also be limited // to a single SDRAM row // (2^COL_WIDTH)/BURST_MODE = (2^10)/8 = 128 localparam NUM_STG1_WR_RD = (BURST_MODE == "8") ? 4 : (BURST_MODE == "4") ? 8 : 4; localparam ADDR_INC = (BURST_MODE == "8") ? 8 : (BURST_MODE == "4") ? 4 : 8; // In a 2 slot dual rank per system RTT_NOM values // for Rank2 and Rank3 default to 40 ohms localparam RTT_NOM2 = "40"; localparam RTT_NOM3 = "40"; localparam RTT_NOM_int = (USE_ODT_PORT == 1) ? RTT_NOM : RTT_WR; // Specifically for use with half-frequency controller (nCK_PER_CLK=2) // = 1 if burst length = 4, = 0 if burst length = 8. Determines how // often row command needs to be issued during read-leveling // For DDR3 the burst length is fixed during calibration localparam BURST4_FLAG = (DRAM_TYPE == "DDR3")? 1'b0 : (BURST_MODE == "8") ? 1'b0 : ((BURST_MODE == "4") ? 1'b1 : 1'b0); //*************************************************************************** // Counter values used to determine bus timing // NOTE on all counter terminal counts - these can/should be one less than // the actual delay to take into account extra clock cycle delay in // generating the corresponding "done" signal //*************************************************************************** localparam CLK_MEM_PERIOD = CLK_PERIOD / nCK_PER_CLK; // Calculate initial delay required in number of CLK clock cycles // to delay initially. The counter is clocked by [CLK/1024] - which // is approximately division by 1000 - note that the formulas below will // result in more than the minimum wait time because of this approximation. // NOTE: For DDR3 JEDEC specifies to delay reset // by 200us, and CKE by an additional 500us after power-up // For DDR2 CKE is delayed by 200us after power up. localparam DDR3_RESET_DELAY_NS = 200000; localparam DDR3_CKE_DELAY_NS = 500000 + DDR3_RESET_DELAY_NS; localparam DDR2_CKE_DELAY_NS = 200000; localparam PWRON_RESET_DELAY_CNT = ((DDR3_RESET_DELAY_NS+CLK_PERIOD-1)/CLK_PERIOD); localparam PWRON_CKE_DELAY_CNT = (DRAM_TYPE == "DDR3") ? (((DDR3_CKE_DELAY_NS+CLK_PERIOD-1)/CLK_PERIOD)) : (((DDR2_CKE_DELAY_NS+CLK_PERIOD-1)/CLK_PERIOD)); // FOR DDR2 -1 taken out. With -1 not getting 200us. The equation // needs to be reworked. localparam DDR2_INIT_PRE_DELAY_PS = 400000; localparam DDR2_INIT_PRE_CNT = ((DDR2_INIT_PRE_DELAY_PS+CLK_PERIOD-1)/CLK_PERIOD)-1; // Calculate tXPR time: reset from CKE HIGH to valid command after power-up // tXPR = (max(5nCK, tRFC(min)+10ns). Add a few (blah, messy) more clock // cycles because this counter actually starts up before CKE is asserted // to memory. localparam TXPR_DELAY_CNT = (5*CLK_MEM_PERIOD > tRFC+10000) ? (((5+nCK_PER_CLK-1)/nCK_PER_CLK)-1)+11 : (((tRFC+10000+CLK_PERIOD-1)/CLK_PERIOD)-1)+11; // tDLLK/tZQINIT time = 512*tCK = 256*tCLKDIV localparam TDLLK_TZQINIT_DELAY_CNT = 255; // TWR values in ns. Both DDR2 and DDR3 have the same value. // 15000ns/tCK localparam TWR_CYC = ((15000) % CLK_MEM_PERIOD) ? (15000/CLK_MEM_PERIOD) + 1 : 15000/CLK_MEM_PERIOD; // time to wait between consecutive commands in PHY_INIT - this is a // generic number, and must be large enough to account for worst case // timing parameter (tRFC - refresh-to-active) across all memory speed // grades and operating frequencies. Expressed in clk // (Divided by 4 or Divided by 2) clock cycles. localparam CNTNEXT_CMD = 7'b1111111; // Counter values to keep track of which MR register to load during init // Set value of INIT_CNT_MR_DONE to equal value of counter for last mode // register configured during initialization. // NOTE: Reserve more bits for DDR2 - more MR accesses for DDR2 init localparam INIT_CNT_MR2 = 2'b00; localparam INIT_CNT_MR3 = 2'b01; localparam INIT_CNT_MR1 = 2'b10; localparam INIT_CNT_MR0 = 2'b11; localparam INIT_CNT_MR_DONE = 2'b11; // Register chip programmable values for DDR3 // The register chip for the registered DIMM needs to be programmed // before the initialization of the registered DIMM. // Address for the control word is in : DBA2, DA2, DA1, DA0 // Data for the control word is in: DBA1 DBA0, DA4, DA3 // The values will be stored in the local param in the following format // {DBA[2:0], DA[4:0]} // RC0 is global features control word. Address == 000 localparam REG_RC0 = 8'b00000000; // RC1 Clock driver enable control word. Enables or disables the four // output clocks in the register chip. For single rank and dual rank // two clocks will be enabled and for quad rank all the four clocks // will be enabled. Address == 000. Data = 0110 for single and dual rank. // = 0000 for quad rank localparam REG_RC1 = (RANKS <= 2) ? 8'b00110001 : 8'b00000001; // RC2 timing control word. Set in 1T timing mode // Address = 010. Data = 0000 localparam REG_RC2 = 8'b00000010; // RC3 timing control word. Setting the data to 0000 localparam REG_RC3 = 8'b00000011; // RC4 timing control work. Setting the data to 0000 localparam REG_RC4 = 8'b00000100; // RC5 timing control work. Setting the data to 0000 localparam REG_RC5 = 8'b00000101; // For non-zero AL values localparam nAL = (AL == "CL-1") ? nCL - 1 : 0; // Adding the register dimm latency to write latency localparam CWL_M = (REG_CTRL == "ON") ? nCWL + nAL + 1 : nCWL + nAL; // Count value to generate pi_phase_locked_err signal localparam PHASELOCKED_TIMEOUT = (SIM_CAL_OPTION == "NONE") ? 16383 : 1000; // Timeout interval for detecting error with Traffic Generator localparam [13:0] TG_TIMER_TIMEOUT = (SIM_CAL_OPTION == "NONE") ? 14'h3FFF : 14'h0001; // Master state machine encoding localparam INIT_IDLE = 6'b000000; //0 localparam INIT_WAIT_CKE_EXIT = 6'b000001; //1 localparam INIT_LOAD_MR = 6'b000010; //2 localparam INIT_LOAD_MR_WAIT = 6'b000011; //3 localparam INIT_ZQCL = 6'b000100; //4 localparam INIT_WAIT_DLLK_ZQINIT = 6'b000101; //5 localparam INIT_WRLVL_START = 6'b000110; //6 localparam INIT_WRLVL_WAIT = 6'b000111; //7 localparam INIT_WRLVL_LOAD_MR = 6'b001000; //8 localparam INIT_WRLVL_LOAD_MR_WAIT = 6'b001001; //9 localparam INIT_WRLVL_LOAD_MR2 = 6'b001010; //A localparam INIT_WRLVL_LOAD_MR2_WAIT = 6'b001011; //B localparam INIT_RDLVL_ACT = 6'b001100; //C localparam INIT_RDLVL_ACT_WAIT = 6'b001101; //D localparam INIT_RDLVL_STG1_WRITE = 6'b001110; //E localparam INIT_RDLVL_STG1_WRITE_READ = 6'b001111; //F localparam INIT_RDLVL_STG1_READ = 6'b010000; //10 localparam INIT_RDLVL_STG2_READ = 6'b010001; //11 localparam INIT_RDLVL_STG2_READ_WAIT = 6'b010010; //12 localparam INIT_PRECHARGE_PREWAIT = 6'b010011; //13 localparam INIT_PRECHARGE = 6'b010100; //14 localparam INIT_PRECHARGE_WAIT = 6'b010101; //15 localparam INIT_DONE = 6'b010110; //16 localparam INIT_DDR2_PRECHARGE = 6'b010111; //17 localparam INIT_DDR2_PRECHARGE_WAIT = 6'b011000; //18 localparam INIT_REFRESH = 6'b011001; //19 localparam INIT_REFRESH_WAIT = 6'b011010; //1A localparam INIT_REG_WRITE = 6'b011011; //1B localparam INIT_REG_WRITE_WAIT = 6'b011100; //1C localparam INIT_DDR2_MULTI_RANK = 6'b011101; //1D localparam INIT_DDR2_MULTI_RANK_WAIT = 6'b011110; //1E localparam INIT_WRCAL_ACT = 6'b011111; //1F localparam INIT_WRCAL_ACT_WAIT = 6'b100000; //20 localparam INIT_WRCAL_WRITE = 6'b100001; //21 localparam INIT_WRCAL_WRITE_READ = 6'b100010; //22 localparam INIT_WRCAL_READ = 6'b100011; //23 localparam INIT_WRCAL_READ_WAIT = 6'b100100; //24 localparam INIT_WRCAL_MULT_READS = 6'b100101; //25 localparam INIT_PI_PHASELOCK_READS = 6'b100110; //26 localparam INIT_MPR_RDEN = 6'b100111; //27 localparam INIT_MPR_WAIT = 6'b101000; //28 localparam INIT_MPR_READ = 6'b101001; //29 localparam INIT_MPR_DISABLE_PREWAIT = 6'b101010; //2A localparam INIT_MPR_DISABLE = 6'b101011; //2B localparam INIT_MPR_DISABLE_WAIT = 6'b101100; //2C localparam INIT_OCLKDELAY_ACT = 6'b101101; //2D localparam INIT_OCLKDELAY_ACT_WAIT = 6'b101110; //2E localparam INIT_OCLKDELAY_WRITE = 6'b101111; //2F localparam INIT_OCLKDELAY_WRITE_WAIT = 6'b110000; //30 localparam INIT_OCLKDELAY_READ = 6'b110001; //31 localparam INIT_OCLKDELAY_READ_WAIT = 6'b110010; //32 localparam INIT_REFRESH_RNK2_WAIT = 6'b110011; //33 integer i, j, k, l, m, n, p, q; reg pi_dqs_found_all_r; (* ASYNC_REG = "TRUE" *) reg pi_phase_locked_all_r1; (* ASYNC_REG = "TRUE" *) reg pi_phase_locked_all_r2; (* ASYNC_REG = "TRUE" *) reg pi_phase_locked_all_r3; (* ASYNC_REG = "TRUE" *) reg pi_phase_locked_all_r4; reg pi_calib_rank_done_r; reg [13:0] pi_phaselock_timer; reg stg1_wr_done; reg rnk_ref_cnt; reg pi_dqs_found_done_r1; reg pi_dqs_found_rank_done_r; reg read_calib_int; reg read_calib_r; reg pi_calib_done_r; reg pi_calib_done_r1; reg burst_addr_r; reg [1:0] chip_cnt_r; reg [6:0] cnt_cmd_r; reg cnt_cmd_done_r; reg cnt_cmd_done_m7_r; reg [7:0] cnt_dllk_zqinit_r; reg cnt_dllk_zqinit_done_r; reg cnt_init_af_done_r; reg [1:0] cnt_init_af_r; reg [1:0] cnt_init_data_r; reg [1:0] cnt_init_mr_r; reg cnt_init_mr_done_r; reg cnt_init_pre_wait_done_r; reg [7:0] cnt_init_pre_wait_r; reg [9:0] cnt_pwron_ce_r; reg cnt_pwron_cke_done_r; reg cnt_pwron_cke_done_r1; reg [8:0] cnt_pwron_r; reg cnt_pwron_reset_done_r; reg cnt_txpr_done_r; reg [7:0] cnt_txpr_r; reg ddr2_pre_flag_r; reg ddr2_refresh_flag_r; reg ddr3_lm_done_r; reg [4:0] enable_wrlvl_cnt; reg init_complete_r; reg init_complete_r1; reg init_complete_r2; (* keep = "true" *) reg init_complete_r_timing; (* keep = "true" *) reg init_complete_r1_timing; reg [5:0] init_next_state; reg [5:0] init_state_r; reg [5:0] init_state_r1; wire [15:0] load_mr0; wire [15:0] load_mr1; wire [15:0] load_mr2; wire [15:0] load_mr3; reg mem_init_done_r; reg [1:0] mr2_r [0:3]; reg [2:0] mr1_r [0:3]; reg new_burst_r; reg [15:0] wrcal_start_dly_r; wire wrcal_start_pre; reg wrcal_resume_r; // Only one ODT signal per rank in PHY Control Block reg [nCK_PER_CLK-1:0] phy_tmp_odt_r; reg [nCK_PER_CLK-1:0] phy_tmp_odt_r1; reg [CS_WIDTH*nCS_PER_RANK-1:0] phy_tmp_cs1_r; reg [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] phy_int_cs_n; wire prech_done_pre; reg [15:0] prech_done_dly_r; reg prech_pending_r; reg prech_req_posedge_r; reg prech_req_r; reg pwron_ce_r; reg first_rdlvl_pat_r; reg first_wrcal_pat_r; reg phy_wrdata_en; reg phy_wrdata_en_r1; reg [1:0] wrdata_pat_cnt; reg [1:0] wrcal_pat_cnt; reg [ROW_WIDTH-1:0] address_w; reg [BANK_WIDTH-1:0] bank_w; reg rdlvl_stg1_done_r1; reg rdlvl_stg1_start_int; reg [15:0] rdlvl_start_dly0_r; reg rdlvl_start_pre; reg rdlvl_last_byte_done_r; wire rdlvl_rd; wire rdlvl_wr; reg rdlvl_wr_r; wire rdlvl_wr_rd; reg [2:0] reg_ctrl_cnt_r; reg [1:0] tmp_mr2_r [0:3]; reg [2:0] tmp_mr1_r [0:3]; reg wrlvl_done_r; reg wrlvl_done_r1; reg wrlvl_rank_done_r1; reg wrlvl_rank_done_r2; reg wrlvl_rank_done_r3; reg wrlvl_rank_done_r4; reg wrlvl_rank_done_r5; reg wrlvl_rank_done_r6; reg wrlvl_rank_done_r7; reg [2:0] wrlvl_rank_cntr; reg wrlvl_odt_ctl; reg wrlvl_odt; reg wrlvl_active; reg wrlvl_active_r1; reg [2:0] num_reads; reg temp_wrcal_done_r; reg temp_lmr_done; reg extend_cal_pat; reg [13:0] tg_timer; reg tg_timer_go; reg cnt_wrcal_rd; reg [3:0] cnt_wait; reg [7:0] wrcal_reads; reg [8:0] stg1_wr_rd_cnt; reg phy_data_full_r; reg wr_level_dqs_asrt; reg wr_level_dqs_asrt_r1; reg [1:0] dqs_asrt_cnt; reg [3:0] num_refresh; wire oclkdelay_calib_start_pre; reg [15:0] oclkdelay_start_dly_r; reg [3:0] oclk_wr_cnt; reg [3:0] wrcal_wr_cnt; reg wrlvl_final_r; reg prbs_rdlvl_done_r1; reg prbs_last_byte_done_r; reg phy_if_empty_r; reg wrcal_final_chk; //*************************************************************************** // Debug //*************************************************************************** //synthesis translate_off always @(posedge mem_init_done_r) begin if (!rst) $display ("PHY_INIT: Memory Initialization completed at %t", $time); end always @(posedge wrlvl_done) begin if (!rst && (WRLVL == "ON")) $display ("PHY_INIT: Write Leveling completed at %t", $time); end always @(posedge rdlvl_stg1_done) begin if (!rst) $display ("PHY_INIT: Read Leveling Stage 1 completed at %t", $time); end always @(posedge mpr_rdlvl_done) begin if (!rst) $display ("PHY_INIT: MPR Read Leveling completed at %t", $time); end always @(posedge oclkdelay_calib_done) begin if (!rst) $display ("PHY_INIT: OCLKDELAY calibration completed at %t", $time); end always @(posedge pi_calib_done_r1) begin if (!rst) $display ("PHY_INIT: Phaser_In Phase Locked at %t", $time); end always @(posedge pi_dqs_found_done) begin if (!rst) $display ("PHY_INIT: Phaser_In DQSFOUND completed at %t", $time); end always @(posedge wrcal_done) begin if (!rst && (WRLVL == "ON")) $display ("PHY_INIT: Write Calibration completed at %t", $time); end //synthesis translate_on assign dbg_phy_init[5:0] = init_state_r; //*************************************************************************** // DQS count to be sent to hard PHY during Phaser_IN Phase Locking stage //*************************************************************************** // assign pi_phaselock_calib_cnt = dqs_cnt_r; assign pi_calib_done = pi_calib_done_r1; always @(posedge clk) begin if (rst) wrcal_final_chk <= #TCQ 1'b0; else if ((init_next_state == INIT_WRCAL_ACT) && wrcal_done && (DRAM_TYPE == "DDR3")) wrcal_final_chk <= #TCQ 1'b1; end always @(posedge clk) begin rdlvl_stg1_done_r1 <= #TCQ rdlvl_stg1_done; prbs_rdlvl_done_r1 <= #TCQ prbs_rdlvl_done; wrcal_resume_r <= #TCQ wrcal_resume; wrcal_sanity_chk <= #TCQ wrcal_final_chk; end always @(posedge clk) begin if (rst) mpr_end_if_reset <= #TCQ 1'b0; else if (mpr_last_byte_done && (num_refresh != 'd0)) mpr_end_if_reset <= #TCQ 1'b1; else mpr_end_if_reset <= #TCQ 1'b0; end // Siganl to mask memory model error for Invalid latching edge always @(posedge clk) if (rst) calib_writes <= #TCQ 1'b0; else if ((init_state_r == INIT_OCLKDELAY_WRITE) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_RDLVL_STG1_WRITE_READ) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_WRCAL_WRITE_READ)) calib_writes <= #TCQ 1'b1; else calib_writes <= #TCQ 1'b0; always @(posedge clk) if (rst) wrcal_rd_wait <= #TCQ 1'b0; else if (init_state_r == INIT_WRCAL_READ_WAIT) wrcal_rd_wait <= #TCQ 1'b1; else wrcal_rd_wait <= #TCQ 1'b0; //*************************************************************************** // Signal PHY completion when calibration is finished // Signal assertion is delayed by four clock cycles to account for the // multi cycle path constraint to (phy_init_data_sel) signal. //*************************************************************************** always @(posedge clk) if (rst) begin init_complete_r <= #TCQ 1'b0; init_complete_r_timing <= #TCQ 1'b0; init_complete_r1 <= #TCQ 1'b0; init_complete_r1_timing <= #TCQ 1'b0; init_complete_r2 <= #TCQ 1'b0; init_calib_complete <= #TCQ 1'b0; end else begin if (init_state_r == INIT_DONE) begin init_complete_r <= #TCQ 1'b1; init_complete_r_timing <= #TCQ 1'b1; end init_complete_r1 <= #TCQ init_complete_r; init_complete_r1_timing <= #TCQ init_complete_r_timing; init_complete_r2 <= #TCQ init_complete_r1; init_calib_complete <= #TCQ init_complete_r2; end //*************************************************************************** // Instantiate FF for the phy_init_data_sel signal. A multi cycle path // constraint will be assigned to this signal. This signal will only be // used within the PHY //*************************************************************************** // FDRSE u_ff_phy_init_data_sel // ( // .Q (phy_init_data_sel), // .C (clk), // .CE (1'b1), // .D (init_complete_r), // .R (1'b0), // .S (1'b0) // ) /* synthesis syn_preserve=1 */ // /* synthesis syn_replicate = 0 */; //*************************************************************************** // Mode register programming //*************************************************************************** //***************************************************************** // DDR3 Load mode reg0 // Mode Register (MR0): // [15:13] - unused - 000 // [12] - Precharge Power-down DLL usage - 0 (DLL frozen, slow-exit), // 1 (DLL maintained) // [11:9] - write recovery for Auto Precharge (tWR/tCK = 6) // [8] - DLL reset - 0 or 1 // [7] - Test Mode - 0 (normal) // [6:4],[2] - CAS latency - CAS_LAT // [3] - Burst Type - BURST_TYPE // [1:0] - Burst Length - BURST_LEN // DDR2 Load mode register // Mode Register (MR): // [15:14] - unused - 00 // [13] - reserved - 0 // [12] - Power-down mode - 0 (normal) // [11:9] - write recovery - write recovery for Auto Precharge // (tWR/tCK = 6) // [8] - DLL reset - 0 or 1 // [7] - Test Mode - 0 (normal) // [6:4] - CAS latency - CAS_LAT // [3] - Burst Type - BURST_TYPE // [2:0] - Burst Length - BURST_LEN //***************************************************************** generate if(DRAM_TYPE == "DDR3") begin: gen_load_mr0_DDR3 assign load_mr0[1:0] = (BURST_MODE == "8") ? 2'b00 : (BURST_MODE == "OTF") ? 2'b01 : (BURST_MODE == "4") ? 2'b10 : 2'b11; assign load_mr0[2] = (nCL >= 12) ? 1'b1 : 1'b0; // LSb of CAS latency assign load_mr0[3] = (BURST_TYPE == "SEQ") ? 1'b0 : 1'b1; assign load_mr0[6:4] = ((nCL == 5) || (nCL == 13)) ? 3'b001 : ((nCL == 6) || (nCL == 14)) ? 3'b010 : (nCL == 7) ? 3'b011 : (nCL == 8) ? 3'b100 : (nCL == 9) ? 3'b101 : (nCL == 10) ? 3'b110 : (nCL == 11) ? 3'b111 : (nCL == 12) ? 3'b000 : 3'b111; assign load_mr0[7] = 1'b0; assign load_mr0[8] = 1'b1; // Reset DLL (init only) assign load_mr0[11:9] = (TWR_CYC == 5) ? 3'b001 : (TWR_CYC == 6) ? 3'b010 : (TWR_CYC == 7) ? 3'b011 : (TWR_CYC == 8) ? 3'b100 : (TWR_CYC == 9) ? 3'b101 : (TWR_CYC == 10) ? 3'b101 : (TWR_CYC == 11) ? 3'b110 : (TWR_CYC == 12) ? 3'b110 : (TWR_CYC == 13) ? 3'b111 : (TWR_CYC == 14) ? 3'b111 : (TWR_CYC == 15) ? 3'b000 : (TWR_CYC == 16) ? 3'b000 : 3'b010; assign load_mr0[12] = 1'b0; // Precharge Power-Down DLL 'slow-exit' assign load_mr0[15:13] = 3'b000; end else if (DRAM_TYPE == "DDR2") begin: gen_load_mr0_DDR2 // block: gen assign load_mr0[2:0] = (BURST_MODE == "8") ? 3'b011 : (BURST_MODE == "4") ? 3'b010 : 3'b111; assign load_mr0[3] = (BURST_TYPE == "SEQ") ? 1'b0 : 1'b1; assign load_mr0[6:4] = (nCL == 3) ? 3'b011 : (nCL == 4) ? 3'b100 : (nCL == 5) ? 3'b101 : (nCL == 6) ? 3'b110 : 3'b111; assign load_mr0[7] = 1'b0; assign load_mr0[8] = 1'b1; // Reset DLL (init only) assign load_mr0[11:9] = (TWR_CYC == 2) ? 3'b001 : (TWR_CYC == 3) ? 3'b010 : (TWR_CYC == 4) ? 3'b011 : (TWR_CYC == 5) ? 3'b100 : (TWR_CYC == 6) ? 3'b101 : 3'b010; assign load_mr0[15:12]= 4'b0000; // Reserved end endgenerate //***************************************************************** // DDR3 Load mode reg1 // Mode Register (MR1): // [15:13] - unused - 00 // [12] - output enable - 0 (enabled for DQ, DQS, DQS#) // [11] - TDQS enable - 0 (TDQS disabled and DM enabled) // [10] - reserved - 0 (must be '0') // [9] - RTT[2] - 0 // [8] - reserved - 0 (must be '0') // [7] - write leveling - 0 (disabled), 1 (enabled) // [6] - RTT[1] - RTT[1:0] = 0(no ODT), 1(75), 2(150), 3(50) // [5] - Output driver impedance[1] - 0 (RZQ/6 and RZQ/7) // [4:3] - Additive CAS - ADDITIVE_CAS // [2] - RTT[0] // [1] - Output driver impedance[0] - 0(RZQ/6), or 1 (RZQ/7) // [0] - DLL enable - 0 (normal) // DDR2 ext mode register // Extended Mode Register (MR): // [15:14] - unused - 00 // [13] - reserved - 0 // [12] - output enable - 0 (enabled) // [11] - RDQS enable - 0 (disabled) // [10] - DQS# enable - 0 (enabled) // [9:7] - OCD Program - 111 or 000 (first 111, then 000 during init) // [6] - RTT[1] - RTT[1:0] = 0(no ODT), 1(75), 2(150), 3(50) // [5:3] - Additive CAS - ADDITIVE_CAS // [2] - RTT[0] // [1] - Output drive - REDUCE_DRV (= 0(full), = 1 (reduced) // [0] - DLL enable - 0 (normal) //***************************************************************** generate if(DRAM_TYPE == "DDR3") begin: gen_load_mr1_DDR3 assign load_mr1[0] = 1'b0; // DLL enabled during Imitialization assign load_mr1[1] = (OUTPUT_DRV == "LOW") ? 1'b0 : 1'b1; assign load_mr1[2] = ((RTT_NOM_int == "30") || (RTT_NOM_int == "40") || (RTT_NOM_int == "60")) ? 1'b1 : 1'b0; assign load_mr1[4:3] = (AL == "0") ? 2'b00 : (AL == "CL-1") ? 2'b01 : (AL == "CL-2") ? 2'b10 : 2'b11; assign load_mr1[5] = 1'b0; assign load_mr1[6] = ((RTT_NOM_int == "40") || (RTT_NOM_int == "120")) ? 1'b1 : 1'b0; assign load_mr1[7] = 1'b0; // Enable write lvl after init sequence assign load_mr1[8] = 1'b0; assign load_mr1[9] = ((RTT_NOM_int == "20") || (RTT_NOM_int == "30")) ? 1'b1 : 1'b0; assign load_mr1[10] = 1'b0; assign load_mr1[15:11] = 5'b00000; end else if (DRAM_TYPE == "DDR2") begin: gen_load_mr1_DDR2 assign load_mr1[0] = 1'b0; // DLL enabled during Imitialization assign load_mr1[1] = (OUTPUT_DRV == "LOW") ? 1'b1 : 1'b0; assign load_mr1[2] = ((RTT_NOM_int == "75") || (RTT_NOM_int == "50")) ? 1'b1 : 1'b0; assign load_mr1[5:3] = (AL == "0") ? 3'b000 : (AL == "1") ? 3'b001 : (AL == "2") ? 3'b010 : (AL == "3") ? 3'b011 : (AL == "4") ? 3'b100 : 3'b111; assign load_mr1[6] = ((RTT_NOM_int == "50") || (RTT_NOM_int == "150")) ? 1'b1 : 1'b0; assign load_mr1[9:7] = 3'b000; assign load_mr1[10] = (DDR2_DQSN_ENABLE == "YES") ? 1'b0 : 1'b1; assign load_mr1[15:11] = 5'b00000; end endgenerate //***************************************************************** // DDR3 Load mode reg2 // Mode Register (MR2): // [15:11] - unused - 00 // [10:9] - RTT_WR - 00 (Dynamic ODT off) // [8] - reserved - 0 (must be '0') // [7] - self-refresh temperature range - // 0 (normal), 1 (extended) // [6] - Auto Self-Refresh - 0 (manual), 1(auto) // [5:3] - CAS Write Latency (CWL) - // 000 (5 for 400 MHz device), // 001 (6 for 400 MHz to 533 MHz devices), // 010 (7 for 533 MHz to 667 MHz devices), // 011 (8 for 667 MHz to 800 MHz) // [2:0] - Partial Array Self-Refresh (Optional) - // 000 (full array) // Not used for DDR2 //***************************************************************** generate if(DRAM_TYPE == "DDR3") begin: gen_load_mr2_DDR3 assign load_mr2[2:0] = 3'b000; assign load_mr2[5:3] = (nCWL == 5) ? 3'b000 : (nCWL == 6) ? 3'b001 : (nCWL == 7) ? 3'b010 : (nCWL == 8) ? 3'b011 : (nCWL == 9) ? 3'b100 : (nCWL == 10) ? 3'b101 : (nCWL == 11) ? 3'b110 : 3'b111; assign load_mr2[6] = 1'b0; assign load_mr2[7] = 1'b0; assign load_mr2[8] = 1'b0; // Dynamic ODT disabled assign load_mr2[10:9] = 2'b00; assign load_mr2[15:11] = 5'b00000; end else begin: gen_load_mr2_DDR2 assign load_mr2[15:0] = 16'd0; end endgenerate //***************************************************************** // DDR3 Load mode reg3 // Mode Register (MR3): // [15:3] - unused - All zeros // [2] - MPR Operation - 0(normal operation), 1(data flow from MPR) // [1:0] - MPR location - 00 (Predefined pattern) //***************************************************************** assign load_mr3[1:0] = 2'b00; assign load_mr3[2] = 1'b0; assign load_mr3[15:3] = 13'b0000000000000; // For multi-rank systems the rank being accessed during writes in // Read Leveling must be sent to phy_write for the bitslip logic assign calib_rank_cnt = chip_cnt_r; //*************************************************************************** // Logic to begin initial calibration, and to handle precharge requests // during read-leveling (to avoid tRAS violations if individual read // levelling calibration stages take more than max{tRAS) to complete). //*************************************************************************** // Assert when readback for each stage of read-leveling begins. However, // note this indicates only when the read command is issued and when // Phaser_IN has phase aligned FREQ_REF clock to read DQS. It does not // indicate when the read data is present on the bus (when this happens // after the read command is issued depends on CAS LATENCY) - there will // need to be some delay before valid data is present on the bus. // assign rdlvl_start_pre = (init_state_r == INIT_PI_PHASELOCK_READS); // Assert when read back for oclkdelay calibration begins assign oclkdelay_calib_start_pre = (init_state_r == INIT_OCLKDELAY_READ); // Assert when read back for write calibration begins assign wrcal_start_pre = (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_WRCAL_MULT_READS); // Common precharge signal done signal - pulses only when there has been // a precharge issued as a result of a PRECH_REQ pulse. Note also a common // PRECH_DONE signal is used for all blocks assign prech_done_pre = (((init_state_r == INIT_RDLVL_STG1_READ) || ((rdlvl_last_byte_done_r || prbs_last_byte_done_r) && (init_state_r == INIT_RDLVL_ACT_WAIT) && cnt_cmd_done_r) || (dqs_found_prech_req && (init_state_r == INIT_RDLVL_ACT_WAIT)) || (init_state_r == INIT_MPR_RDEN) || ((init_state_r == INIT_WRCAL_ACT_WAIT) && cnt_cmd_done_r) || ((init_state_r == INIT_OCLKDELAY_ACT_WAIT) && cnt_cmd_done_r) || (wrlvl_final && (init_state_r == INIT_REFRESH_WAIT) && cnt_cmd_done_r && ~oclkdelay_calib_done)) && prech_pending_r && !prech_req_posedge_r); always @(posedge clk) if (rst) pi_phaselock_start <= #TCQ 1'b0; else if (init_state_r == INIT_PI_PHASELOCK_READS) pi_phaselock_start <= #TCQ 1'b1; // Delay start of each calibration by 16 clock cycles to ensure that when // calibration logic begins, read data is already appearing on the bus. // Each circuit should synthesize using an SRL16. Assume that reset is // long enough to clear contents of SRL16. always @(posedge clk) begin rdlvl_last_byte_done_r <= #TCQ rdlvl_last_byte_done; prbs_last_byte_done_r <= #TCQ prbs_last_byte_done; rdlvl_start_dly0_r <= #TCQ {rdlvl_start_dly0_r[14:0], rdlvl_start_pre}; wrcal_start_dly_r <= #TCQ {wrcal_start_dly_r[14:0], wrcal_start_pre}; oclkdelay_start_dly_r <= #TCQ {oclkdelay_start_dly_r[14:0], oclkdelay_calib_start_pre}; prech_done_dly_r <= #TCQ {prech_done_dly_r[14:0], prech_done_pre}; end always @(posedge clk) prech_done <= #TCQ prech_done_dly_r[15]; always @(posedge clk) if (rst) mpr_rdlvl_start <= #TCQ 1'b0; else if (pi_dqs_found_done && (init_state_r == INIT_MPR_READ)) mpr_rdlvl_start <= #TCQ 1'b1; always @(posedge clk) phy_if_empty_r <= #TCQ phy_if_empty; always @(posedge clk) if (rst || (phy_if_empty_r && prbs_rdlvl_prech_req) || ((stg1_wr_rd_cnt == 'd1) && ~stg1_wr_done) || prbs_rdlvl_done) prbs_gen_clk_en <= #TCQ 1'b0; else if ((~phy_if_empty_r && rdlvl_stg1_done_r1 && ~prbs_rdlvl_done) || ((init_state_r == INIT_RDLVL_ACT_WAIT) && rdlvl_stg1_done_r1 && (cnt_cmd_r == 'd0))) prbs_gen_clk_en <= #TCQ 1'b1; generate if (RANKS < 2) begin always @(posedge clk) if (rst) begin rdlvl_stg1_start <= #TCQ 1'b0; rdlvl_stg1_start_int <= #TCQ 1'b0; rdlvl_start_pre <= #TCQ 1'b0; prbs_rdlvl_start <= #TCQ 1'b0; end else begin if (pi_dqs_found_done && cnt_cmd_done_r && (init_state_r == INIT_RDLVL_ACT_WAIT)) rdlvl_stg1_start_int <= #TCQ 1'b1; if (pi_dqs_found_done && (init_state_r == INIT_RDLVL_STG1_READ))begin rdlvl_start_pre <= #TCQ 1'b1; rdlvl_stg1_start <= #TCQ rdlvl_start_dly0_r[14]; end if (pi_dqs_found_done && rdlvl_stg1_done && (init_state_r == INIT_RDLVL_STG1_READ) && (WRLVL == "ON")) begin prbs_rdlvl_start <= #TCQ 1'b1; end end end else begin always @(posedge clk) if (rst || rdlvl_stg1_rank_done) begin rdlvl_stg1_start <= #TCQ 1'b0; rdlvl_stg1_start_int <= #TCQ 1'b0; rdlvl_start_pre <= #TCQ 1'b0; prbs_rdlvl_start <= #TCQ 1'b0; end else begin if (pi_dqs_found_done && cnt_cmd_done_r && (init_state_r == INIT_RDLVL_ACT_WAIT)) rdlvl_stg1_start_int <= #TCQ 1'b1; if (pi_dqs_found_done && (init_state_r == INIT_RDLVL_STG1_READ))begin rdlvl_start_pre <= #TCQ 1'b1; rdlvl_stg1_start <= #TCQ rdlvl_start_dly0_r[14]; end if (pi_dqs_found_done && rdlvl_stg1_done && (init_state_r == INIT_RDLVL_STG1_READ) && (WRLVL == "ON")) begin prbs_rdlvl_start <= #TCQ 1'b1; end end end endgenerate always @(posedge clk) begin if (rst || dqsfound_retry || wrlvl_byte_redo) begin pi_dqs_found_start <= #TCQ 1'b0; wrcal_start <= #TCQ 1'b0; end else begin if (!pi_dqs_found_done && init_state_r == INIT_RDLVL_STG2_READ) pi_dqs_found_start <= #TCQ 1'b1; if (wrcal_start_dly_r[5]) wrcal_start <= #TCQ 1'b1; end end // else: !if(rst) always @(posedge clk) if (rst) oclkdelay_calib_start <= #TCQ 1'b0; else if (oclkdelay_start_dly_r[5]) oclkdelay_calib_start <= #TCQ 1'b1; always @(posedge clk) if (rst) pi_dqs_found_done_r1 <= #TCQ 1'b0; else pi_dqs_found_done_r1 <= #TCQ pi_dqs_found_done; always @(posedge clk) wrlvl_final_r <= #TCQ wrlvl_final; // Reset IN_FIFO after final write leveling to make sure the FIFO // pointers are initialized always @(posedge clk) if (rst || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_REFRESH)) wrlvl_final_if_rst <= #TCQ 1'b0; else if (wrlvl_done_r && //(wrlvl_final_r && wrlvl_done_r && (init_state_r == INIT_WRLVL_LOAD_MR2)) wrlvl_final_if_rst <= #TCQ 1'b1; // Constantly enable DQS while write leveling is enabled in the memory // This is more to get rid of warnings in simulation, can later change // this code to only enable WRLVL_ACTIVE when WRLVL_START is asserted always @(posedge clk) if (rst || ((init_state_r1 != INIT_WRLVL_START) && (init_state_r == INIT_WRLVL_START))) wrlvl_odt_ctl <= #TCQ 1'b0; else if (wrlvl_rank_done && ~wrlvl_rank_done_r1) wrlvl_odt_ctl <= #TCQ 1'b1; generate if (nCK_PER_CLK == 4) begin: en_cnt_div4 always @ (posedge clk) if (rst) enable_wrlvl_cnt <= #TCQ 5'd0; else if ((init_state_r == INIT_WRLVL_START) || (wrlvl_odt && (enable_wrlvl_cnt == 5'd0))) enable_wrlvl_cnt <= #TCQ 5'd12; else if ((enable_wrlvl_cnt > 5'd0) && ~(phy_ctl_full || phy_cmd_full)) enable_wrlvl_cnt <= #TCQ enable_wrlvl_cnt - 1; // ODT stays asserted as long as write_calib // signal is asserted always @(posedge clk) if (rst || wrlvl_odt_ctl) wrlvl_odt <= #TCQ 1'b0; else if (enable_wrlvl_cnt == 5'd1) wrlvl_odt <= #TCQ 1'b1; end else begin: en_cnt_div2 always @ (posedge clk) if (rst) enable_wrlvl_cnt <= #TCQ 5'd0; else if ((init_state_r == INIT_WRLVL_START) || (wrlvl_odt && (enable_wrlvl_cnt == 5'd0))) enable_wrlvl_cnt <= #TCQ 5'd21; else if ((enable_wrlvl_cnt > 5'd0) && ~(phy_ctl_full || phy_cmd_full)) enable_wrlvl_cnt <= #TCQ enable_wrlvl_cnt - 1; // ODT stays asserted as long as write_calib // signal is asserted always @(posedge clk) if (rst || wrlvl_odt_ctl) wrlvl_odt <= #TCQ 1'b0; else if (enable_wrlvl_cnt == 5'd1) wrlvl_odt <= #TCQ 1'b1; end endgenerate always @(posedge clk) if (rst || wrlvl_rank_done || done_dqs_tap_inc) wrlvl_active <= #TCQ 1'b0; else if ((enable_wrlvl_cnt == 5'd1) && wrlvl_odt && !wrlvl_active) wrlvl_active <= #TCQ 1'b1; // signal used to assert DQS for write leveling. // the DQS will be asserted once every 16 clock cycles. always @(posedge clk)begin if(rst || (enable_wrlvl_cnt != 5'd1)) begin wr_level_dqs_asrt <= #TCQ 1'd0; end else if ((enable_wrlvl_cnt == 5'd1) && (wrlvl_active_r1)) begin wr_level_dqs_asrt <= #TCQ 1'd1; end end always @ (posedge clk) begin if (rst || (wrlvl_done_r && ~wrlvl_done_r1)) dqs_asrt_cnt <= #TCQ 2'd0; else if (wr_level_dqs_asrt && dqs_asrt_cnt != 2'd3) dqs_asrt_cnt <= #TCQ (dqs_asrt_cnt + 1); end always @ (posedge clk) begin if (rst || ~wrlvl_active) wr_lvl_start <= #TCQ 1'd0; else if (dqs_asrt_cnt == 2'd3) wr_lvl_start <= #TCQ 1'd1; end always @(posedge clk) begin if (rst) wl_sm_start <= #TCQ 1'b0; else wl_sm_start <= #TCQ wr_level_dqs_asrt_r1; end always @(posedge clk) begin wrlvl_active_r1 <= #TCQ wrlvl_active; wr_level_dqs_asrt_r1 <= #TCQ wr_level_dqs_asrt; wrlvl_done_r <= #TCQ wrlvl_done; wrlvl_done_r1 <= #TCQ wrlvl_done_r; wrlvl_rank_done_r1 <= #TCQ wrlvl_rank_done; wrlvl_rank_done_r2 <= #TCQ wrlvl_rank_done_r1; wrlvl_rank_done_r3 <= #TCQ wrlvl_rank_done_r2; wrlvl_rank_done_r4 <= #TCQ wrlvl_rank_done_r3; wrlvl_rank_done_r5 <= #TCQ wrlvl_rank_done_r4; wrlvl_rank_done_r6 <= #TCQ wrlvl_rank_done_r5; wrlvl_rank_done_r7 <= #TCQ wrlvl_rank_done_r6; end always @ (posedge clk) begin //if (rst) wrlvl_rank_cntr <= #TCQ 3'd0; //else if (wrlvl_rank_done) // wrlvl_rank_cntr <= #TCQ wrlvl_rank_cntr + 1'b1; end //***************************************************************** // Precharge request logic - those calibration logic blocks // that require greater than tRAS(max) to finish must break up // their calibration into smaller units of time, with precharges // issued in between. This is done using the XXX_PRECH_REQ and // PRECH_DONE handshaking between PHY_INIT and those blocks //***************************************************************** // Shared request from multiple sources assign prech_req = oclk_prech_req | rdlvl_prech_req | wrcal_prech_req | prbs_rdlvl_prech_req | (dqs_found_prech_req & (init_state_r == INIT_RDLVL_STG2_READ_WAIT)); // Handshaking logic to force precharge during read leveling, and to // notify read leveling logic when precharge has been initiated and // it's okay to proceed with leveling again always @(posedge clk) if (rst) begin prech_req_r <= #TCQ 1'b0; prech_req_posedge_r <= #TCQ 1'b0; prech_pending_r <= #TCQ 1'b0; end else begin prech_req_r <= #TCQ prech_req; prech_req_posedge_r <= #TCQ prech_req & ~prech_req_r; if (prech_req_posedge_r) prech_pending_r <= #TCQ 1'b1; // Clear after we've finished with the precharge and have // returned to issuing read leveling calibration reads else if (prech_done_pre) prech_pending_r <= #TCQ 1'b0; end //*************************************************************************** // Various timing counters //*************************************************************************** //***************************************************************** // Generic delay for various states that require it (e.g. for turnaround // between read and write). Make this a sufficiently large number of clock // cycles to cover all possible frequencies and memory components) // Requirements for this counter: // 1. Greater than tMRD // 2. tRFC (refresh-active) for DDR2 // 3. (list the other requirements, slacker...) //***************************************************************** always @(posedge clk) begin case (init_state_r) INIT_LOAD_MR_WAIT, INIT_WRLVL_LOAD_MR_WAIT, INIT_WRLVL_LOAD_MR2_WAIT, INIT_MPR_WAIT, INIT_MPR_DISABLE_PREWAIT, INIT_MPR_DISABLE_WAIT, INIT_OCLKDELAY_ACT_WAIT, INIT_OCLKDELAY_WRITE_WAIT, INIT_RDLVL_ACT_WAIT, INIT_RDLVL_STG1_WRITE_READ, INIT_RDLVL_STG2_READ_WAIT, INIT_WRCAL_ACT_WAIT, INIT_WRCAL_WRITE_READ, INIT_WRCAL_READ_WAIT, INIT_PRECHARGE_PREWAIT, INIT_PRECHARGE_WAIT, INIT_DDR2_PRECHARGE_WAIT, INIT_REG_WRITE_WAIT, INIT_REFRESH_WAIT, INIT_REFRESH_RNK2_WAIT: begin if (phy_ctl_full || phy_cmd_full) cnt_cmd_r <= #TCQ cnt_cmd_r; else cnt_cmd_r <= #TCQ cnt_cmd_r + 1; end INIT_WRLVL_WAIT: cnt_cmd_r <= #TCQ 'b0; default: cnt_cmd_r <= #TCQ 'b0; endcase end // pulse when count reaches terminal count always @(posedge clk) cnt_cmd_done_r <= #TCQ (cnt_cmd_r == CNTNEXT_CMD); // For ODT deassertion - hold throughout post read/write wait stage, but // deassert before next command. The post read/write stage is very long, so // we simply address the longest case here plus some margin. always @(posedge clk) cnt_cmd_done_m7_r <= #TCQ (cnt_cmd_r == (CNTNEXT_CMD - 7)); //************************************************************************ // Added to support PO fine delay inc when TG errors always @(posedge clk) begin case (init_state_r) INIT_WRCAL_READ_WAIT: begin if (phy_ctl_full || phy_cmd_full) cnt_wait <= #TCQ cnt_wait; else cnt_wait <= #TCQ cnt_wait + 1; end default: cnt_wait <= #TCQ 'b0; endcase end always @(posedge clk) cnt_wrcal_rd <= #TCQ (cnt_wait == 'd4); always @(posedge clk) begin if (rst || ~temp_wrcal_done) temp_lmr_done <= #TCQ 1'b0; else if (temp_wrcal_done && (init_state_r == INIT_LOAD_MR)) temp_lmr_done <= #TCQ 1'b1; end always @(posedge clk) temp_wrcal_done_r <= #TCQ temp_wrcal_done; always @(posedge clk) if (rst) begin tg_timer_go <= #TCQ 1'b0; end else if ((PRE_REV3ES == "ON") && temp_wrcal_done && temp_lmr_done && (init_state_r == INIT_WRCAL_READ_WAIT)) begin tg_timer_go <= #TCQ 1'b1; end else begin tg_timer_go <= #TCQ 1'b0; end always @(posedge clk) begin if (rst || (temp_wrcal_done && ~temp_wrcal_done_r) || (init_state_r == INIT_PRECHARGE_PREWAIT)) tg_timer <= #TCQ 'd0; else if ((pi_phaselock_timer == PHASELOCKED_TIMEOUT) && tg_timer_go && (tg_timer != TG_TIMER_TIMEOUT)) tg_timer <= #TCQ tg_timer + 1; end always @(posedge clk) begin if (rst) tg_timer_done <= #TCQ 1'b0; else if (tg_timer == TG_TIMER_TIMEOUT) tg_timer_done <= #TCQ 1'b1; else tg_timer_done <= #TCQ 1'b0; end always @(posedge clk) begin if (rst) no_rst_tg_mc <= #TCQ 1'b0; else if ((init_state_r == INIT_WRCAL_ACT) && wrcal_read_req) no_rst_tg_mc <= #TCQ 1'b1; else no_rst_tg_mc <= #TCQ 1'b0; end //************************************************************************ always @(posedge clk) begin if (rst) detect_pi_found_dqs <= #TCQ 1'b0; else if ((cnt_cmd_r == 7'b0111111) && (init_state_r == INIT_RDLVL_STG2_READ_WAIT)) detect_pi_found_dqs <= #TCQ 1'b1; else detect_pi_found_dqs <= #TCQ 1'b0; end //***************************************************************** // Initial delay after power-on for RESET, CKE // NOTE: Could reduce power consumption by turning off these counters // after initial power-up (at expense of more logic) // NOTE: Likely can combine multiple counters into single counter //***************************************************************** // Create divided by 1024 version of clock always @(posedge clk) if (rst) begin cnt_pwron_ce_r <= #TCQ 10'h000; pwron_ce_r <= #TCQ 1'b0; end else begin cnt_pwron_ce_r <= #TCQ cnt_pwron_ce_r + 1; pwron_ce_r <= #TCQ (cnt_pwron_ce_r == 10'h3FF); end // "Main" power-on counter - ticks every CLKDIV/1024 cycles always @(posedge clk) if (rst) cnt_pwron_r <= #TCQ 'b0; else if (pwron_ce_r) cnt_pwron_r <= #TCQ cnt_pwron_r + 1; always @(posedge clk) if (rst || ~phy_ctl_ready) begin cnt_pwron_reset_done_r <= #TCQ 1'b0; cnt_pwron_cke_done_r <= #TCQ 1'b0; end else begin // skip power-up count for simulation purposes only if ((SIM_INIT_OPTION == "SKIP_PU_DLY") || (SIM_INIT_OPTION == "SKIP_INIT")) begin cnt_pwron_reset_done_r <= #TCQ 1'b1; cnt_pwron_cke_done_r <= #TCQ 1'b1; end else begin // otherwise, create latched version of done signal for RESET, CKE if (DRAM_TYPE == "DDR3") begin if (!cnt_pwron_reset_done_r) cnt_pwron_reset_done_r <= #TCQ (cnt_pwron_r == PWRON_RESET_DELAY_CNT); if (!cnt_pwron_cke_done_r) cnt_pwron_cke_done_r <= #TCQ (cnt_pwron_r == PWRON_CKE_DELAY_CNT); end else begin // DDR2 cnt_pwron_reset_done_r <= #TCQ 1'b1; // not needed if (!cnt_pwron_cke_done_r) cnt_pwron_cke_done_r <= #TCQ (cnt_pwron_r == PWRON_CKE_DELAY_CNT); end end end // else: !if(rst || ~phy_ctl_ready) always @(posedge clk) cnt_pwron_cke_done_r1 <= #TCQ cnt_pwron_cke_done_r; // Keep RESET asserted and CKE deasserted until after power-on delay always @(posedge clk or posedge rst) begin if (rst) phy_reset_n <= #TCQ 1'b0; else phy_reset_n <= #TCQ cnt_pwron_reset_done_r; // phy_cke <= #TCQ {CKE_WIDTH{cnt_pwron_cke_done_r}}; end //***************************************************************** // Counter for tXPR (pronouned "Tax-Payer") - wait time after // CKE deassertion before first MRS command can be asserted //***************************************************************** always @(posedge clk) if (!cnt_pwron_cke_done_r) begin cnt_txpr_r <= #TCQ 'b0; cnt_txpr_done_r <= #TCQ 1'b0; end else begin cnt_txpr_r <= #TCQ cnt_txpr_r + 1; if (!cnt_txpr_done_r) cnt_txpr_done_r <= #TCQ (cnt_txpr_r == TXPR_DELAY_CNT); end //***************************************************************** // Counter for the initial 400ns wait for issuing precharge all // command after CKE assertion. Only for DDR2. //***************************************************************** always @(posedge clk) if (!cnt_pwron_cke_done_r) begin cnt_init_pre_wait_r <= #TCQ 'b0; cnt_init_pre_wait_done_r <= #TCQ 1'b0; end else begin cnt_init_pre_wait_r <= #TCQ cnt_init_pre_wait_r + 1; if (!cnt_init_pre_wait_done_r) cnt_init_pre_wait_done_r <= #TCQ (cnt_init_pre_wait_r >= DDR2_INIT_PRE_CNT); end //***************************************************************** // Wait for both DLL to lock (tDLLK) and ZQ calibration to finish // (tZQINIT). Both take the same amount of time (512*tCK) //***************************************************************** always @(posedge clk) if (init_state_r == INIT_ZQCL) begin cnt_dllk_zqinit_r <= #TCQ 'b0; cnt_dllk_zqinit_done_r <= #TCQ 1'b0; end else if (~(phy_ctl_full || phy_cmd_full)) begin cnt_dllk_zqinit_r <= #TCQ cnt_dllk_zqinit_r + 1; if (!cnt_dllk_zqinit_done_r) cnt_dllk_zqinit_done_r <= #TCQ (cnt_dllk_zqinit_r == TDLLK_TZQINIT_DELAY_CNT); end //***************************************************************** // Keep track of which MRS counter needs to be programmed during // memory initialization // The counter and the done signal are reset an additional time // for DDR2. The same signals are used for the additional DDR2 // initialization sequence. //***************************************************************** always @(posedge clk) if ((init_state_r == INIT_IDLE)|| ((init_state_r == INIT_REFRESH) && (~mem_init_done_r))) begin cnt_init_mr_r <= #TCQ 'b0; cnt_init_mr_done_r <= #TCQ 1'b0; end else if (init_state_r == INIT_LOAD_MR) begin cnt_init_mr_r <= #TCQ cnt_init_mr_r + 1; cnt_init_mr_done_r <= #TCQ (cnt_init_mr_r == INIT_CNT_MR_DONE); end //***************************************************************** // Flag to tell if the first precharge for DDR2 init sequence is // done //***************************************************************** always @(posedge clk) if (init_state_r == INIT_IDLE) ddr2_pre_flag_r<= #TCQ 'b0; else if (init_state_r == INIT_LOAD_MR) ddr2_pre_flag_r<= #TCQ 1'b1; // reset the flag for multi rank case else if ((ddr2_refresh_flag_r) && (init_state_r == INIT_LOAD_MR_WAIT)&& (cnt_cmd_done_r) && (cnt_init_mr_done_r)) ddr2_pre_flag_r <= #TCQ 'b0; //***************************************************************** // Flag to tell if the refresh stat for DDR2 init sequence is // reached //***************************************************************** always @(posedge clk) if (init_state_r == INIT_IDLE) ddr2_refresh_flag_r<= #TCQ 'b0; else if ((init_state_r == INIT_REFRESH) && (~mem_init_done_r)) // reset the flag for multi rank case ddr2_refresh_flag_r<= #TCQ 1'b1; else if ((ddr2_refresh_flag_r) && (init_state_r == INIT_LOAD_MR_WAIT)&& (cnt_cmd_done_r) && (cnt_init_mr_done_r)) ddr2_refresh_flag_r <= #TCQ 'b0; //***************************************************************** // Keep track of the number of auto refreshes for DDR2 // initialization. The spec asks for a minimum of two refreshes. // Four refreshes are performed here. The two extra refreshes is to // account for the 200 clock cycle wait between step h and l. // Without the two extra refreshes we would have to have a // wait state. //***************************************************************** always @(posedge clk) if (init_state_r == INIT_IDLE) begin cnt_init_af_r <= #TCQ 'b0; cnt_init_af_done_r <= #TCQ 1'b0; end else if ((init_state_r == INIT_REFRESH) && (~mem_init_done_r))begin cnt_init_af_r <= #TCQ cnt_init_af_r + 1; cnt_init_af_done_r <= #TCQ (cnt_init_af_r == 2'b11); end //***************************************************************** // Keep track of the register control word programming for // DDR3 RDIMM //***************************************************************** always @(posedge clk) if (init_state_r == INIT_IDLE) reg_ctrl_cnt_r <= #TCQ 'b0; else if (init_state_r == INIT_REG_WRITE) reg_ctrl_cnt_r <= #TCQ reg_ctrl_cnt_r + 1; generate if (RANKS < 2) begin: one_rank always @(posedge clk) if ((init_state_r == INIT_IDLE) || rdlvl_last_byte_done) stg1_wr_done <= #TCQ 1'b0; else if (init_state_r == INIT_RDLVL_STG1_WRITE_READ) stg1_wr_done <= #TCQ 1'b1; end else begin: two_ranks always @(posedge clk) if ((init_state_r == INIT_IDLE) || rdlvl_last_byte_done || (rdlvl_stg1_rank_done )) stg1_wr_done <= #TCQ 1'b0; else if (init_state_r == INIT_RDLVL_STG1_WRITE_READ) stg1_wr_done <= #TCQ 1'b1; end endgenerate always @(posedge clk) if (rst) rnk_ref_cnt <= #TCQ 1'b0; else if (stg1_wr_done && (init_state_r == INIT_REFRESH_WAIT) && cnt_cmd_done_r) rnk_ref_cnt <= #TCQ ~rnk_ref_cnt; always @(posedge clk) if (rst || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_RDLVL_ACT)) num_refresh <= #TCQ 'd0; else if ((init_state_r == INIT_REFRESH) && (~pi_dqs_found_done || ((DRAM_TYPE == "DDR3") && ~oclkdelay_calib_done) || (rdlvl_stg1_done && ~prbs_rdlvl_done) || ((CLK_PERIOD/nCK_PER_CLK <= 2500) && wrcal_done && ~rdlvl_stg1_done) || ((CLK_PERIOD/nCK_PER_CLK > 2500) && wrlvl_done_r1 && ~rdlvl_stg1_done))) num_refresh <= #TCQ num_refresh + 1; //*************************************************************************** // Initialization state machine //*************************************************************************** //***************************************************************** // Next-state logic //***************************************************************** always @(posedge clk) if (rst)begin init_state_r <= #TCQ INIT_IDLE; init_state_r1 <= #TCQ INIT_IDLE; end else begin init_state_r <= #TCQ init_next_state; init_state_r1 <= #TCQ init_state_r; end always @(burst_addr_r or chip_cnt_r or cnt_cmd_done_r or cnt_dllk_zqinit_done_r or cnt_init_af_done_r or cnt_init_mr_done_r or phy_ctl_ready or phy_ctl_full or stg1_wr_done or rdlvl_last_byte_done or phy_cmd_full or num_reads or rnk_ref_cnt or mpr_last_byte_done or oclk_wr_cnt or mpr_rdlvl_done or mpr_rnk_done or num_refresh or oclkdelay_calib_done or oclk_prech_req or oclk_calib_resume or wrlvl_byte_redo or wrlvl_byte_done or wrlvl_final or wrlvl_final_r or cnt_init_pre_wait_done_r or cnt_pwron_cke_done_r or delay_incdec_done or wrcal_wr_cnt or ck_addr_cmd_delay_done or wrcal_read_req or wrcal_reads or cnt_wrcal_rd or wrcal_act_req or temp_wrcal_done or temp_lmr_done or cnt_txpr_done_r or ddr2_pre_flag_r or ddr2_refresh_flag_r or ddr3_lm_done_r or init_state_r or mem_init_done_r or dqsfound_retry or dqs_found_prech_req or prech_req_posedge_r or prech_req_r or wrcal_done or wrcal_resume_r or rdlvl_stg1_done or rdlvl_stg1_done_r1 or rdlvl_stg1_rank_done or rdlvl_stg1_start_int or prbs_rdlvl_done or prbs_last_byte_done or prbs_rdlvl_done_r1 or stg1_wr_rd_cnt or rdlvl_prech_req or wrcal_prech_req or read_calib_int or read_calib_r or pi_calib_done_r1 or pi_phase_locked_all_r3 or pi_phase_locked_all_r4 or pi_dqs_found_done or pi_dqs_found_rank_done or pi_dqs_found_start or reg_ctrl_cnt_r or wrlvl_done_r1 or wrlvl_rank_done_r7 or wrcal_final_chk or wrcal_sanity_chk_done) begin init_next_state = init_state_r; (* full_case, parallel_case *) case (init_state_r) //******************************************************* // DRAM initialization //******************************************************* // Initial state - wait for: // 1. Power-on delays to pass // 2. PHY Control Block to assert phy_ctl_ready // 3. PHY Control FIFO must not be FULL // 4. Read path initialization to finish INIT_IDLE: if (cnt_pwron_cke_done_r && phy_ctl_ready && ck_addr_cmd_delay_done && delay_incdec_done && ~(phy_ctl_full || phy_cmd_full) ) begin // If skipping memory initialization (simulation only) if (SIM_INIT_OPTION == "SKIP_INIT") //if (WRLVL == "ON") // Proceed to write leveling // init_next_state = INIT_WRLVL_START; //else //if (SIM_CAL_OPTION != "SKIP_CAL") // Proceed to Phaser_In phase lock init_next_state = INIT_RDLVL_ACT; // else // Skip read leveling //init_next_state = INIT_DONE; else init_next_state = INIT_WAIT_CKE_EXIT; end // Wait minimum of Reset CKE exit time (tXPR = max(tXS, INIT_WAIT_CKE_EXIT: if ((cnt_txpr_done_r) && (DRAM_TYPE == "DDR3") && ~(phy_ctl_full || phy_cmd_full)) begin if((REG_CTRL == "ON") && ((nCS_PER_RANK > 1) || (RANKS > 1))) //register write for reg dimm. Some register chips // have the register chip in a pre-programmed state // in that case the nCS_PER_RANK == 1 && RANKS == 1 init_next_state = INIT_REG_WRITE; else // Load mode register - this state is repeated multiple times init_next_state = INIT_LOAD_MR; end else if ((cnt_init_pre_wait_done_r) && (DRAM_TYPE == "DDR2") && ~(phy_ctl_full || phy_cmd_full)) // DDR2 start with a precharge all command init_next_state = INIT_DDR2_PRECHARGE; INIT_REG_WRITE: init_next_state = INIT_REG_WRITE_WAIT; INIT_REG_WRITE_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) begin if(reg_ctrl_cnt_r == 3'd5) init_next_state = INIT_LOAD_MR; else init_next_state = INIT_REG_WRITE; end INIT_LOAD_MR: init_next_state = INIT_LOAD_MR_WAIT; // After loading MR, wait at least tMRD INIT_LOAD_MR_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) begin // If finished loading all mode registers, proceed to next step if (prbs_rdlvl_done && pi_dqs_found_done && rdlvl_stg1_done) // for ddr3 when the correct burst length is writtern at end init_next_state = INIT_PRECHARGE; else if (~wrcal_done && temp_lmr_done) init_next_state = INIT_PRECHARGE_PREWAIT; else if (cnt_init_mr_done_r)begin if(DRAM_TYPE == "DDR3") init_next_state = INIT_ZQCL; else begin //DDR2 if(ddr2_refresh_flag_r)begin // memory initialization per rank for multi-rank case if (!mem_init_done_r && (chip_cnt_r <= RANKS-1)) init_next_state = INIT_DDR2_MULTI_RANK; else init_next_state = INIT_RDLVL_ACT; // ddr2 initialization done.load mode state after refresh end else init_next_state = INIT_DDR2_PRECHARGE; end end else init_next_state = INIT_LOAD_MR; end // DDR2 multi rank transition state INIT_DDR2_MULTI_RANK: init_next_state = INIT_DDR2_MULTI_RANK_WAIT; INIT_DDR2_MULTI_RANK_WAIT: init_next_state = INIT_DDR2_PRECHARGE; // Initial ZQ calibration INIT_ZQCL: init_next_state = INIT_WAIT_DLLK_ZQINIT; // Wait until both DLL have locked, and ZQ calibration done INIT_WAIT_DLLK_ZQINIT: if (cnt_dllk_zqinit_done_r && ~(phy_ctl_full || phy_cmd_full)) // memory initialization per rank for multi-rank case if (!mem_init_done_r && (chip_cnt_r <= RANKS-1)) init_next_state = INIT_LOAD_MR; //else if (WRLVL == "ON") // init_next_state = INIT_WRLVL_START; else // skip write-leveling (e.g. for DDR2 interface) init_next_state = INIT_RDLVL_ACT; // Initial precharge for DDR2 INIT_DDR2_PRECHARGE: init_next_state = INIT_DDR2_PRECHARGE_WAIT; INIT_DDR2_PRECHARGE_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) begin if (ddr2_pre_flag_r) init_next_state = INIT_REFRESH; else // from precharge state initially go to load mode init_next_state = INIT_LOAD_MR; end INIT_REFRESH: if ((RANKS == 2) && (chip_cnt_r == RANKS - 1)) init_next_state = INIT_REFRESH_RNK2_WAIT; else init_next_state = INIT_REFRESH_WAIT; INIT_REFRESH_RNK2_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) init_next_state = INIT_PRECHARGE; INIT_REFRESH_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full))begin if(cnt_init_af_done_r && (~mem_init_done_r)) // go to lm state as part of DDR2 init sequence init_next_state = INIT_LOAD_MR; else if (pi_dqs_found_done && ~wrlvl_done_r1 && ~wrlvl_final && ~wrlvl_byte_redo && (WRLVL == "ON")) init_next_state = INIT_WRLVL_START; else if (~pi_dqs_found_done || (rdlvl_stg1_done && ~prbs_rdlvl_done) || ((CLK_PERIOD/nCK_PER_CLK <= 2500) && wrcal_done && ~rdlvl_stg1_done) || ((CLK_PERIOD/nCK_PER_CLK > 2500) && wrlvl_done_r1 && ~rdlvl_stg1_done)) begin if (num_refresh == 'd8) init_next_state = INIT_RDLVL_ACT; else init_next_state = INIT_REFRESH; end else if ((~wrcal_done && wrlvl_byte_redo)&& (DRAM_TYPE == "DDR3") && (CLK_PERIOD/nCK_PER_CLK > 2500)) init_next_state = INIT_WRLVL_LOAD_MR2; else if (((prbs_rdlvl_done && rdlvl_stg1_done && pi_dqs_found_done) && (WRLVL == "ON")) && mem_init_done_r && (CLK_PERIOD/nCK_PER_CLK > 2500)) init_next_state = INIT_WRCAL_ACT; else if (pi_dqs_found_done && (DRAM_TYPE == "DDR3") && ~(mpr_last_byte_done || mpr_rdlvl_done)) begin if (num_refresh == 'd8) init_next_state = INIT_MPR_RDEN; else init_next_state = INIT_REFRESH; end else if (((~oclkdelay_calib_done && wrlvl_final) || (~wrcal_done && wrlvl_byte_redo)) && (DRAM_TYPE == "DDR3")) init_next_state = INIT_WRLVL_LOAD_MR2; else if (~oclkdelay_calib_done && (mpr_last_byte_done || mpr_rdlvl_done) && (DRAM_TYPE == "DDR3")) begin if (num_refresh == 'd8) init_next_state = INIT_OCLKDELAY_ACT; else init_next_state = INIT_REFRESH; end else if ((~wrcal_done && (WRLVL == "ON") && (CLK_PERIOD/nCK_PER_CLK <= 2500)) && pi_dqs_found_done) init_next_state = INIT_WRCAL_ACT; else if (mem_init_done_r) begin if (RANKS < 2) init_next_state = INIT_RDLVL_ACT; else if (stg1_wr_done && ~rnk_ref_cnt && ~rdlvl_stg1_done) init_next_state = INIT_PRECHARGE; else init_next_state = INIT_RDLVL_ACT; end else // to DDR2 init state as part of DDR2 init sequence init_next_state = INIT_REFRESH; end //****************************************************** // Write Leveling //******************************************************* // Enable write leveling in MR1 and start write leveling // for current rank INIT_WRLVL_START: init_next_state = INIT_WRLVL_WAIT; // Wait for both MR load and write leveling to complete // (write leveling should take much longer than MR load..) INIT_WRLVL_WAIT: if (wrlvl_rank_done_r7 && ~(phy_ctl_full || phy_cmd_full)) init_next_state = INIT_WRLVL_LOAD_MR; // Disable write leveling in MR1 for current rank INIT_WRLVL_LOAD_MR: init_next_state = INIT_WRLVL_LOAD_MR_WAIT; INIT_WRLVL_LOAD_MR_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) init_next_state = INIT_WRLVL_LOAD_MR2; // Load MR2 to set ODT: Dynamic ODT for single rank case // And ODTs for multi-rank case as well INIT_WRLVL_LOAD_MR2: init_next_state = INIT_WRLVL_LOAD_MR2_WAIT; // Wait tMRD before proceeding INIT_WRLVL_LOAD_MR2_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) begin //if (wrlvl_byte_done) // init_next_state = INIT_PRECHARGE_PREWAIT; // else if ((RANKS == 2) && wrlvl_rank_done_r2) // init_next_state = INIT_WRLVL_LOAD_MR2_WAIT; if (~wrlvl_done_r1) init_next_state = INIT_WRLVL_START; else if (SIM_CAL_OPTION == "SKIP_CAL") // If skip rdlvl, then we're done init_next_state = INIT_DONE; else // Otherwise, proceed to read leveling //init_next_state = INIT_RDLVL_ACT; init_next_state = INIT_PRECHARGE_PREWAIT; end //******************************************************* // Read Leveling //******************************************************* // single row activate. All subsequent read leveling writes and // read will take place in this row INIT_RDLVL_ACT: init_next_state = INIT_RDLVL_ACT_WAIT; // hang out for awhile before issuing subsequent column commands // it's also possible to reach this state at various points // during read leveling - determine what the current stage is INIT_RDLVL_ACT_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) begin // Just finished an activate. Now either write, read, or precharge // depending on where we are in the training sequence if (!pi_calib_done_r1) init_next_state = INIT_PI_PHASELOCK_READS; else if (!pi_dqs_found_done) // (!pi_dqs_found_start || pi_dqs_found_rank_done)) init_next_state = INIT_RDLVL_STG2_READ; else if (~wrcal_done && (WRLVL == "ON") && (CLK_PERIOD/nCK_PER_CLK <= 2500)) init_next_state = INIT_WRCAL_ACT_WAIT; else if ((!rdlvl_stg1_done && ~stg1_wr_done && ~rdlvl_last_byte_done) || (!prbs_rdlvl_done && ~stg1_wr_done && ~prbs_last_byte_done)) begin // Added to avoid rdlvl_stg1 write data pattern at the start of PRBS rdlvl if (!prbs_rdlvl_done && ~stg1_wr_done && rdlvl_last_byte_done) init_next_state = INIT_RDLVL_ACT_WAIT; else init_next_state = INIT_RDLVL_STG1_WRITE; end else if ((!rdlvl_stg1_done && rdlvl_stg1_start_int) || !prbs_rdlvl_done) begin if (rdlvl_last_byte_done || prbs_last_byte_done) // Added to avoid extra reads at the end of read leveling init_next_state = INIT_RDLVL_ACT_WAIT; else // Case 2: If in stage 1, and just precharged after training // previous byte, then continue reading init_next_state = INIT_RDLVL_STG1_READ; end else if ((prbs_rdlvl_done && rdlvl_stg1_done && (RANKS == 1)) && (WRLVL == "ON") && (CLK_PERIOD/nCK_PER_CLK > 2500)) init_next_state = INIT_WRCAL_ACT_WAIT; else // Otherwise, if we're finished with calibration, then precharge // the row - silly, because we just opened it - possible to take // this out by adding logic to avoid the ACT in first place. Make // sure that cnt_cmd_done will handle tRAS(min) init_next_state = INIT_PRECHARGE_PREWAIT; end //************************************************** // Back-to-back reads for Phaser_IN Phase locking // DQS to FREQ_REF clock //************************************************** INIT_PI_PHASELOCK_READS: if (pi_phase_locked_all_r3 && ~pi_phase_locked_all_r4) init_next_state = INIT_PRECHARGE_PREWAIT; //********************************************* // Stage 1 read-leveling (write and continuous read) //********************************************* // Write training pattern for stage 1 // PRBS pattern of TBD length INIT_RDLVL_STG1_WRITE: // 4:1 DDR3 BL8 will require all 8 words in 1 DIV4 clock cycle // 2:1 DDR2/DDR3 BL8 will require 2 DIV2 clock cycles for 8 words // 2:1 DDR2 BL4 will require 1 DIV2 clock cycle for 4 words // An entire row worth of writes issued before proceeding to reads // The number of write is (2^column width)/burst length to accomodate // PRBS pattern for window detection. if (stg1_wr_rd_cnt == 9'd1) init_next_state = INIT_RDLVL_STG1_WRITE_READ; // Write-read turnaround INIT_RDLVL_STG1_WRITE_READ: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) init_next_state = INIT_RDLVL_STG1_READ; // Continuous read, where interruptible by precharge request from // calibration logic. Also precharges when stage 1 is complete // No precharges when reads provided to Phaser_IN for phase locking // FREQ_REF to read DQS since data integrity is not important. INIT_RDLVL_STG1_READ: if (rdlvl_stg1_rank_done || (rdlvl_stg1_done && ~rdlvl_stg1_done_r1) || prech_req_posedge_r || (prbs_rdlvl_done && ~prbs_rdlvl_done_r1)) init_next_state = INIT_PRECHARGE_PREWAIT; //********************************************* // DQSFOUND calibration (set of 4 reads with gaps) //********************************************* // Read of training data. Note that Stage 2 is not a constant read, // instead there is a large gap between each set of back-to-back reads INIT_RDLVL_STG2_READ: // 4 read commands issued back-to-back if (num_reads == 'b1) init_next_state = INIT_RDLVL_STG2_READ_WAIT; // Wait before issuing the next set of reads. If a precharge request // comes in then handle - this can occur after stage 2 calibration is // completed for a DQS group INIT_RDLVL_STG2_READ_WAIT: if (~(phy_ctl_full || phy_cmd_full)) begin if (pi_dqs_found_rank_done || pi_dqs_found_done || prech_req_posedge_r) init_next_state = INIT_PRECHARGE_PREWAIT; else if (cnt_cmd_done_r) init_next_state = INIT_RDLVL_STG2_READ; end //****************************************************************** // MPR Read Leveling for DDR3 OCLK_DELAYED calibration //****************************************************************** // Issue Load Mode Register 3 command with A[2]=1, A[1:0]=2'b00 // to enable Multi Purpose Register (MPR) Read INIT_MPR_RDEN: init_next_state = INIT_MPR_WAIT; //Wait tMRD, tMOD INIT_MPR_WAIT: if (cnt_cmd_done_r) begin init_next_state = INIT_MPR_READ; end // Issue back-to-back read commands to read from MPR with // Address bus 0x0000 for BL=8. DQ[0] will output the pre-defined // MPR pattern of 01010101 (Rise0 = 1'b0, Fall0 = 1'b1 ...) INIT_MPR_READ: if (mpr_rdlvl_done || mpr_rnk_done || rdlvl_prech_req) init_next_state = INIT_MPR_DISABLE_PREWAIT; INIT_MPR_DISABLE_PREWAIT: if (cnt_cmd_done_r) init_next_state = INIT_MPR_DISABLE; // Issue Load Mode Register 3 command with A[2]=0 to disable // MPR read INIT_MPR_DISABLE: init_next_state = INIT_MPR_DISABLE_WAIT; INIT_MPR_DISABLE_WAIT: init_next_state = INIT_PRECHARGE_PREWAIT; //*********************************************************************** // OCLKDELAY Calibration //*********************************************************************** // This calibration requires single write followed by single read to // determine the Phaser_Out stage 3 delay required to center write DQS // in write DQ valid window. // Single Row Activate command before issuing Write command INIT_OCLKDELAY_ACT: init_next_state = INIT_OCLKDELAY_ACT_WAIT; INIT_OCLKDELAY_ACT_WAIT: if (cnt_cmd_done_r && ~oclk_prech_req) init_next_state = INIT_OCLKDELAY_WRITE; else if (oclkdelay_calib_done || prech_req_posedge_r) init_next_state = INIT_PRECHARGE_PREWAIT; INIT_OCLKDELAY_WRITE: if (oclk_wr_cnt == 4'd1) init_next_state = INIT_OCLKDELAY_WRITE_WAIT; INIT_OCLKDELAY_WRITE_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) init_next_state = INIT_OCLKDELAY_READ; INIT_OCLKDELAY_READ: init_next_state = INIT_OCLKDELAY_READ_WAIT; INIT_OCLKDELAY_READ_WAIT: if (~(phy_ctl_full || phy_cmd_full)) begin if (oclk_calib_resume) init_next_state = INIT_OCLKDELAY_WRITE; else if (oclkdelay_calib_done || prech_req_posedge_r || wrlvl_final) init_next_state = INIT_PRECHARGE_PREWAIT; end //********************************************* // Write calibration //********************************************* // single row activate INIT_WRCAL_ACT: init_next_state = INIT_WRCAL_ACT_WAIT; // hang out for awhile before issuing subsequent column command INIT_WRCAL_ACT_WAIT: if (cnt_cmd_done_r && ~wrcal_prech_req) init_next_state = INIT_WRCAL_WRITE; else if (wrcal_done || prech_req_posedge_r) init_next_state = INIT_PRECHARGE_PREWAIT; // Write training pattern for write calibration INIT_WRCAL_WRITE: // Once we've issued enough commands for 8 words - proceed to reads //if (burst_addr_r == 1'b1) if (wrcal_wr_cnt == 4'd1) init_next_state = INIT_WRCAL_WRITE_READ; // Write-read turnaround INIT_WRCAL_WRITE_READ: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) init_next_state = INIT_WRCAL_READ; else if (dqsfound_retry) init_next_state = INIT_RDLVL_STG2_READ_WAIT; INIT_WRCAL_READ: if (burst_addr_r == 1'b1) init_next_state = INIT_WRCAL_READ_WAIT; INIT_WRCAL_READ_WAIT: if (~(phy_ctl_full || phy_cmd_full)) begin if (wrcal_resume_r) begin if (wrcal_final_chk) init_next_state = INIT_WRCAL_READ; else init_next_state = INIT_WRCAL_WRITE; end else if (wrcal_done || prech_req_posedge_r || wrcal_act_req || // Added to support PO fine delay inc when TG errors wrlvl_byte_redo || (temp_wrcal_done && ~temp_lmr_done)) init_next_state = INIT_PRECHARGE_PREWAIT; else if (dqsfound_retry) init_next_state = INIT_RDLVL_STG2_READ_WAIT; else if (wrcal_read_req && cnt_wrcal_rd) init_next_state = INIT_WRCAL_MULT_READS; end INIT_WRCAL_MULT_READS: // multiple read commands issued back-to-back if (wrcal_reads == 'b1) init_next_state = INIT_WRCAL_READ_WAIT; //********************************************* // Handling of precharge during and in between read-level stages //********************************************* // Make sure we aren't violating any timing specs by precharging // immediately INIT_PRECHARGE_PREWAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) init_next_state = INIT_PRECHARGE; // Initiate precharge INIT_PRECHARGE: init_next_state = INIT_PRECHARGE_WAIT; INIT_PRECHARGE_WAIT: if (cnt_cmd_done_r && ~(phy_ctl_full || phy_cmd_full)) begin if ((wrcal_sanity_chk_done && (DRAM_TYPE == "DDR3")) || (rdlvl_stg1_done && prbs_rdlvl_done && pi_dqs_found_done && (DRAM_TYPE == "DDR2"))) init_next_state = INIT_DONE; else if ((wrcal_done || (WRLVL == "OFF")) && rdlvl_stg1_done && prbs_rdlvl_done && pi_dqs_found_done && ((ddr3_lm_done_r) || (DRAM_TYPE == "DDR2"))) // If read leveling and phase detection calibration complete, // and programing the correct burst length then we're finished init_next_state = INIT_WRCAL_ACT; else if ((wrcal_done || (WRLVL == "OFF") || (~wrcal_done && temp_wrcal_done && ~temp_lmr_done)) && (rdlvl_stg1_done || (~wrcal_done && temp_wrcal_done && ~temp_lmr_done)) && prbs_rdlvl_done && rdlvl_stg1_done && pi_dqs_found_done) begin // after all calibration program the correct burst length init_next_state = INIT_LOAD_MR; // Added to support PO fine delay inc when TG errors end else if (~wrcal_done && temp_wrcal_done && temp_lmr_done) init_next_state = INIT_WRCAL_READ_WAIT; else if (rdlvl_stg1_done && pi_dqs_found_done && (WRLVL == "ON")) // If read leveling finished, proceed to write calibration init_next_state = INIT_REFRESH; else // Otherwise, open row for read-leveling purposes init_next_state = INIT_REFRESH; end //******************************************************* // Initialization/Calibration done. Take a long rest, relax //******************************************************* INIT_DONE: init_next_state = INIT_DONE; endcase end //***************************************************************** // Initialization done signal - asserted before leveling starts //***************************************************************** always @(posedge clk) if (rst) mem_init_done_r <= #TCQ 1'b0; else if ((!cnt_dllk_zqinit_done_r && (cnt_dllk_zqinit_r == TDLLK_TZQINIT_DELAY_CNT) && (chip_cnt_r == RANKS-1) && (DRAM_TYPE == "DDR3")) || ( (init_state_r == INIT_LOAD_MR_WAIT) && (ddr2_refresh_flag_r) && (chip_cnt_r == RANKS-1) && (cnt_init_mr_done_r) && (DRAM_TYPE == "DDR2"))) mem_init_done_r <= #TCQ 1'b1; //***************************************************************** // Write Calibration signal to PHY Control Block - asserted before // Write Leveling starts //***************************************************************** //generate //if (RANKS < 2) begin: ranks_one always @(posedge clk) begin if (rst || (done_dqs_tap_inc && (init_state_r == INIT_WRLVL_LOAD_MR2))) write_calib <= #TCQ 1'b0; else if (wrlvl_active_r1) write_calib <= #TCQ 1'b1; end //end else begin: ranks_two // always @(posedge clk) begin // if (rst || // ((init_state_r1 == INIT_WRLVL_LOAD_MR_WAIT) && // ((wrlvl_rank_done_r2 && (chip_cnt_r == RANKS-1)) || // (SIM_CAL_OPTION == "FAST_CAL")))) // write_calib <= #TCQ 1'b0; // else if (wrlvl_active_r1) // write_calib <= #TCQ 1'b1; // end //end //endgenerate //***************************************************************** // Read Calibration signal to PHY Control Block - asserted after // Write Leveling during PHASER_IN phase locking stage. // Must be de-asserted before Read Leveling //***************************************************************** always @(posedge clk) begin if (rst || pi_calib_done_r1) read_calib_int <= #TCQ 1'b0; else if (~pi_calib_done_r1 && (init_state_r == INIT_RDLVL_ACT_WAIT) && (cnt_cmd_r == CNTNEXT_CMD)) read_calib_int <= #TCQ 1'b1; end always @(posedge clk) read_calib_r <= #TCQ read_calib_int; always @(posedge clk) begin if (rst || pi_calib_done_r1) read_calib <= #TCQ 1'b0; else if (~pi_calib_done_r1 && (init_state_r == INIT_PI_PHASELOCK_READS)) read_calib <= #TCQ 1'b1; end always @(posedge clk) if (rst) pi_calib_done_r <= #TCQ 1'b0; else if (pi_calib_rank_done_r)// && (chip_cnt_r == RANKS-1)) pi_calib_done_r <= #TCQ 1'b1; always @(posedge clk) if (rst) pi_calib_rank_done_r <= #TCQ 1'b0; else if (pi_phase_locked_all_r3 && ~pi_phase_locked_all_r4) pi_calib_rank_done_r <= #TCQ 1'b1; else pi_calib_rank_done_r <= #TCQ 1'b0; always @(posedge clk) begin if (rst || ((PRE_REV3ES == "ON") && temp_wrcal_done && ~temp_wrcal_done_r)) pi_phaselock_timer <= #TCQ 'd0; else if (((init_state_r == INIT_PI_PHASELOCK_READS) && (pi_phaselock_timer != PHASELOCKED_TIMEOUT)) || tg_timer_go) pi_phaselock_timer <= #TCQ pi_phaselock_timer + 1; else pi_phaselock_timer <= #TCQ pi_phaselock_timer; end assign pi_phase_locked_err = (pi_phaselock_timer == PHASELOCKED_TIMEOUT) ? 1'b1 : 1'b0; //***************************************************************** // DDR3 final burst length programming done. For DDR3 during // calibration the burst length is fixed to BL8. After calibration // the correct burst length is programmed. //***************************************************************** always @(posedge clk) if (rst) ddr3_lm_done_r <= #TCQ 1'b0; else if ((init_state_r == INIT_LOAD_MR_WAIT) && (chip_cnt_r == RANKS-1) && wrcal_done) ddr3_lm_done_r <= #TCQ 1'b1; always @(posedge clk) begin pi_dqs_found_rank_done_r <= #TCQ pi_dqs_found_rank_done; pi_phase_locked_all_r1 <= #TCQ pi_phase_locked_all; pi_phase_locked_all_r2 <= #TCQ pi_phase_locked_all_r1; pi_phase_locked_all_r3 <= #TCQ pi_phase_locked_all_r2; pi_phase_locked_all_r4 <= #TCQ pi_phase_locked_all_r3; pi_dqs_found_all_r <= #TCQ pi_dqs_found_done; pi_calib_done_r1 <= #TCQ pi_calib_done_r; end //*************************************************************************** // Logic for deep memory (multi-rank) configurations //*************************************************************************** // For DDR3 asserted when generate if (RANKS < 2) begin: single_rank always @(posedge clk) chip_cnt_r <= #TCQ 2'b00; end else begin: dual_rank always @(posedge clk) if (rst || // Set chip_cnt_r to 2'b00 after both Ranks are read leveled (rdlvl_stg1_done && prbs_rdlvl_done && ~wrcal_done) || // Set chip_cnt_r to 2'b00 after both Ranks are write leveled (wrlvl_done_r && (init_state_r==INIT_WRLVL_LOAD_MR2_WAIT)))begin chip_cnt_r <= #TCQ 2'b00; end else if ((((init_state_r == INIT_WAIT_DLLK_ZQINIT) && (cnt_dllk_zqinit_r == TDLLK_TZQINIT_DELAY_CNT)) && (DRAM_TYPE == "DDR3")) || ((init_state_r==INIT_REFRESH_RNK2_WAIT) && (cnt_cmd_r=='d36)) || //mpr_rnk_done || //(rdlvl_stg1_rank_done && ~rdlvl_last_byte_done) || //(stg1_wr_done && (init_state_r == INIT_REFRESH) && //~(rnk_ref_cnt && rdlvl_last_byte_done)) || // Increment chip_cnt_r to issue Refresh to second rank (~pi_dqs_found_all_r && (init_state_r==INIT_PRECHARGE_PREWAIT) && (cnt_cmd_r=='d36)) || // Increment chip_cnt_r when DQSFOUND done for the Rank (pi_dqs_found_rank_done && ~pi_dqs_found_rank_done_r) || ((init_state_r == INIT_LOAD_MR_WAIT)&& cnt_cmd_done_r && wrcal_done) || ((init_state_r == INIT_DDR2_MULTI_RANK) && (DRAM_TYPE == "DDR2"))) begin if ((~mem_init_done_r || ~rdlvl_stg1_done || ~pi_dqs_found_done || // condition to increment chip_cnt during // final burst length programming for DDR3 ~pi_calib_done_r || wrcal_done) //~mpr_rdlvl_done || && (chip_cnt_r != RANKS-1)) chip_cnt_r <= #TCQ chip_cnt_r + 1; else chip_cnt_r <= #TCQ 2'b00; end end endgenerate generate if ((REG_CTRL == "ON") && (RANKS == 1)) begin: DDR3_RDIMM_1rank always @(posedge clk) begin if (rst) phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; else if (init_state_r == INIT_REG_WRITE) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if(!(CWL_M%2)) begin phy_int_cs_n[0%nCK_PER_CLK] <= #TCQ 1'b0; phy_int_cs_n[1%nCK_PER_CLK] <= #TCQ 1'b0; end else begin phy_int_cs_n[2%nCK_PER_CLK] <= #TCQ 1'b0; phy_int_cs_n[3%nCK_PER_CLK] <= #TCQ 1'b0; end end else if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r)) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if (!(CWL_M % 2)) //even CWL phy_int_cs_n[0] <= #TCQ 1'b0; else // odd CWL phy_int_cs_n[1*nCS_PER_RANK] <= #TCQ 1'b0; end else phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; end end else if (RANKS == 1) begin: DDR3_1rank always @(posedge clk) begin if (rst) phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; else if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r)) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if (!(CWL_M % 2)) begin //even CWL for (n = 0; n < nCS_PER_RANK; n = n + 1) begin phy_int_cs_n[n] <= #TCQ 1'b0; end end else begin //odd CWL for (p = nCS_PER_RANK; p < 2*nCS_PER_RANK; p = p + 1) begin phy_int_cs_n[p] <= #TCQ 1'b0; end end end else phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; end end else if ((REG_CTRL == "ON") && (RANKS == 2)) begin: DDR3_2rank always @(posedge clk) begin if (rst) phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; else if (init_state_r == INIT_REG_WRITE) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if(!(CWL_M%2)) begin phy_int_cs_n[0%nCK_PER_CLK] <= #TCQ 1'b0; phy_int_cs_n[1%nCK_PER_CLK] <= #TCQ 1'b0; end else begin phy_int_cs_n[2%nCK_PER_CLK] <= #TCQ 1'b0; phy_int_cs_n[3%nCK_PER_CLK] <= #TCQ 1'b0; end end else begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; case (chip_cnt_r) 2'b00:begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r)) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if (!(CWL_M % 2)) //even CWL phy_int_cs_n[0] <= #TCQ 1'b0; else // odd CWL phy_int_cs_n[1*CS_WIDTH*nCS_PER_RANK] <= #TCQ 1'b0; end else phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; //for (n = 0; n < nCS_PER_RANK*nCK_PER_CLK*2; n = n + (nCS_PER_RANK*2)) begin // // phy_int_cs_n[n+:nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; //end end 2'b01:begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r)) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if (!(CWL_M % 2)) //even CWL phy_int_cs_n[1] <= #TCQ 1'b0; else // odd CWL phy_int_cs_n[1+1*CS_WIDTH*nCS_PER_RANK] <= #TCQ 1'b0; end else phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; //for (p = nCS_PER_RANK; p < nCS_PER_RANK*nCK_PER_CLK*2; p = p + (nCS_PER_RANK*2)) begin // // phy_int_cs_n[p+:nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; //end end endcase end end end else if (RANKS == 2) begin: DDR3_2rank always @(posedge clk) begin if (rst) phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; else if (init_state_r == INIT_REG_WRITE) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if(!(CWL_M%2)) begin phy_int_cs_n[0%nCK_PER_CLK] <= #TCQ 1'b0; phy_int_cs_n[1%nCK_PER_CLK] <= #TCQ 1'b0; end else begin phy_int_cs_n[2%nCK_PER_CLK] <= #TCQ 1'b0; phy_int_cs_n[3%nCK_PER_CLK] <= #TCQ 1'b0; end end else begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; case (chip_cnt_r) 2'b00:begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r)) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if (!(CWL_M % 2)) begin //even CWL for (n = 0; n < nCS_PER_RANK; n = n + 1) begin phy_int_cs_n[n] <= #TCQ 1'b0; end end else begin // odd CWL for (p = CS_WIDTH*nCS_PER_RANK; p < (CS_WIDTH*nCS_PER_RANK + nCS_PER_RANK); p = p + 1) begin phy_int_cs_n[p] <= #TCQ 1'b0; end end end else phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; //for (n = 0; n < nCS_PER_RANK*nCK_PER_CLK*2; n = n + (nCS_PER_RANK*2)) begin // // phy_int_cs_n[n+:nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; //end end 2'b01:begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r)) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; if (!(CWL_M % 2)) begin //even CWL for (q = nCS_PER_RANK; q < (2 * nCS_PER_RANK); q = q + 1) begin phy_int_cs_n[q] <= #TCQ 1'b0; end end else begin // odd CWL for (m = (nCS_PER_RANK*CS_WIDTH + nCS_PER_RANK); m < (nCS_PER_RANK*CS_WIDTH + 2*nCS_PER_RANK); m = m + 1) begin phy_int_cs_n[m] <= #TCQ 1'b0; end end end else phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; //for (p = nCS_PER_RANK; p < nCS_PER_RANK*nCK_PER_CLK*2; p = p + (nCS_PER_RANK*2)) begin // // phy_int_cs_n[p+:nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; //end end endcase end end // always @ (posedge clk) end // commented out for now. Need it for DDR2 2T timing /* end else begin: DDR2 always @(posedge clk) if (rst) begin phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; end else begin if (init_state_r == INIT_REG_WRITE) begin // All ranks selected simultaneously phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b0}}; end else if ((wrlvl_odt) || (init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_PI_PHASELOCK_READS) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_RDLVL_STG1_READ) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_RDLVL_STG2_READ) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH)) begin phy_int_cs_n[0] <= #TCQ 1'b0; end else phy_int_cs_n <= #TCQ {CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK{1'b1}}; end // else: !if(rst) end // block: DDR2 */ endgenerate assign phy_cs_n = phy_int_cs_n; //*************************************************************************** // Write/read burst logic for calibration //*************************************************************************** assign rdlvl_wr = (init_state_r == INIT_OCLKDELAY_WRITE) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE); assign rdlvl_rd = (init_state_r == INIT_PI_PHASELOCK_READS) || (init_state_r == INIT_RDLVL_STG1_READ) || (init_state_r == INIT_RDLVL_STG2_READ) || (init_state_r == INIT_OCLKDELAY_READ) || (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_MPR_READ) || (init_state_r == INIT_WRCAL_MULT_READS); assign rdlvl_wr_rd = rdlvl_wr | rdlvl_rd; //*************************************************************************** // Address generation and logic to count # of writes/reads issued during // certain stages of calibration //*************************************************************************** // Column address generation logic: // Keep track of the current column address - since all bursts are in // increments of 8 only during calibration, we need to keep track of // addresses [COL_WIDTH-1:3], lower order address bits will always = 0 always @(posedge clk) if (rst || wrcal_done) burst_addr_r <= #TCQ 1'b0; else if ((init_state_r == INIT_WRCAL_ACT_WAIT) || (init_state_r == INIT_OCLKDELAY_ACT_WAIT) || (init_state_r == INIT_OCLKDELAY_WRITE) || (init_state_r == INIT_OCLKDELAY_READ) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_WRCAL_WRITE_READ) || (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_WRCAL_MULT_READS) || (init_state_r == INIT_WRCAL_READ_WAIT)) burst_addr_r <= #TCQ 1'b1; else if (rdlvl_wr_rd && new_burst_r) burst_addr_r <= #TCQ ~burst_addr_r; else burst_addr_r <= #TCQ 1'b0; // Read Level Stage 1 requires writes to the entire row since // a PRBS pattern is being written. This counter keeps track // of the number of writes which depends on the column width // The (stg1_wr_rd_cnt==9'd0) condition was added so the col // address wraps around during stage1 reads always @(posedge clk) if (rst || ((init_state_r == INIT_RDLVL_STG1_WRITE_READ) && ~rdlvl_stg1_done)) stg1_wr_rd_cnt <= #TCQ NUM_STG1_WR_RD; else if (rdlvl_last_byte_done || (stg1_wr_rd_cnt == 9'd1) || (prbs_rdlvl_prech_req && (init_state_r == INIT_RDLVL_ACT_WAIT))) stg1_wr_rd_cnt <= #TCQ 'd128; else if (((init_state_r == INIT_RDLVL_STG1_WRITE) && new_burst_r && ~phy_data_full) ||((init_state_r == INIT_RDLVL_STG1_READ) && rdlvl_stg1_done)) stg1_wr_rd_cnt <= #TCQ stg1_wr_rd_cnt - 1; // OCLKDELAY calibration requires multiple writes because // write can be up to 2 cycles early since OCLKDELAY tap // can go down to 0 always @(posedge clk) if (rst || (init_state_r == INIT_OCLKDELAY_WRITE_WAIT) || (oclk_wr_cnt == 4'd0)) oclk_wr_cnt <= #TCQ NUM_STG1_WR_RD; else if ((init_state_r == INIT_OCLKDELAY_WRITE) && new_burst_r && ~phy_data_full) oclk_wr_cnt <= #TCQ oclk_wr_cnt - 1; // Write calibration requires multiple writes because // write can be up to 2 cycles early due to new write // leveling algorithm to avoid late writes always @(posedge clk) if (rst || (init_state_r == INIT_WRCAL_WRITE_READ) || (wrcal_wr_cnt == 4'd0)) wrcal_wr_cnt <= #TCQ NUM_STG1_WR_RD; else if ((init_state_r == INIT_WRCAL_WRITE) && new_burst_r && ~phy_data_full) wrcal_wr_cnt <= #TCQ wrcal_wr_cnt - 1; generate if(nCK_PER_CLK == 4) begin:back_to_back_reads_4_1 // 4 back-to-back reads with gaps for // read data_offset calibration (rdlvl stage 2) always @(posedge clk) if (rst || (init_state_r == INIT_RDLVL_STG2_READ_WAIT)) num_reads <= #TCQ 3'b000; else if ((num_reads > 3'b000) && ~(phy_ctl_full || phy_cmd_full)) num_reads <= #TCQ num_reads - 1; else if ((init_state_r == INIT_RDLVL_STG2_READ) || phy_ctl_full || phy_cmd_full && new_burst_r) num_reads <= #TCQ 3'b011; end else if(nCK_PER_CLK == 2) begin: back_to_back_reads_2_1 // 4 back-to-back reads with gaps for // read data_offset calibration (rdlvl stage 2) always @(posedge clk) if (rst || (init_state_r == INIT_RDLVL_STG2_READ_WAIT)) num_reads <= #TCQ 3'b000; else if ((num_reads > 3'b000) && ~(phy_ctl_full || phy_cmd_full)) num_reads <= #TCQ num_reads - 1; else if ((init_state_r == INIT_RDLVL_STG2_READ) || phy_ctl_full || phy_cmd_full && new_burst_r) num_reads <= #TCQ 3'b111; end endgenerate // back-to-back reads during write calibration always @(posedge clk) if (rst ||(init_state_r == INIT_WRCAL_READ_WAIT)) wrcal_reads <= #TCQ 2'b00; else if ((wrcal_reads > 2'b00) && ~(phy_ctl_full || phy_cmd_full)) wrcal_reads <= #TCQ wrcal_reads - 1; else if ((init_state_r == INIT_WRCAL_MULT_READS) || phy_ctl_full || phy_cmd_full && new_burst_r) wrcal_reads <= #TCQ 'd255; // determine how often to issue row command during read leveling writes // and reads always @(posedge clk) if (rdlvl_wr_rd) begin // 2:1 mode - every other command issued is a data command // 4:1 mode - every command issued is a data command if (nCK_PER_CLK == 2) begin if (!phy_ctl_full) new_burst_r <= #TCQ ~new_burst_r; end else new_burst_r <= #TCQ 1'b1; end else new_burst_r <= #TCQ 1'b1; // indicate when a write is occurring. PHY_WRDATA_EN must be asserted // simultaneous with the corresponding command/address for CWL = 5,6 always @(posedge clk) begin rdlvl_wr_r <= #TCQ rdlvl_wr; calib_wrdata_en <= #TCQ phy_wrdata_en; end always @(posedge clk) begin if (rst || wrcal_done) extend_cal_pat <= #TCQ 1'b0; else if (temp_lmr_done && (PRE_REV3ES == "ON")) extend_cal_pat <= #TCQ 1'b1; end generate if ((nCK_PER_CLK == 4) || (BURST_MODE == "4")) begin: wrdqen_div4 // Write data enable asserted for one DIV4 clock cycle // Only BL8 supported with DIV4. DDR2 BL4 will use DIV2. always @(rst or phy_data_full or init_state_r) begin if (~phy_data_full && ((init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE) || (init_state_r == INIT_WRCAL_WRITE))) phy_wrdata_en = 1'b1; else phy_wrdata_en = 1'b0; end end else begin: wrdqen_div2 // block: wrdqen_div4 always @(rdlvl_wr or phy_ctl_full or new_burst_r or phy_wrdata_en_r1 or phy_data_full) if((rdlvl_wr & ~phy_ctl_full & new_burst_r & ~phy_data_full) | phy_wrdata_en_r1) phy_wrdata_en = 1'b1; else phy_wrdata_en = 1'b0; always @(posedge clk) phy_wrdata_en_r1 <= #TCQ rdlvl_wr & ~phy_ctl_full & new_burst_r & ~phy_data_full; always @(posedge clk) begin if (!phy_wrdata_en & first_rdlvl_pat_r) wrdata_pat_cnt <= #TCQ 2'b00; else if (wrdata_pat_cnt == 2'b11) wrdata_pat_cnt <= #TCQ 2'b10; else wrdata_pat_cnt <= #TCQ wrdata_pat_cnt + 1; end always @(posedge clk) begin if (!phy_wrdata_en & first_wrcal_pat_r) wrcal_pat_cnt <= #TCQ 2'b00; else if (extend_cal_pat && (wrcal_pat_cnt == 2'b01)) wrcal_pat_cnt <= #TCQ 2'b00; else if (wrcal_pat_cnt == 2'b11) wrcal_pat_cnt <= #TCQ 2'b10; else wrcal_pat_cnt <= #TCQ wrcal_pat_cnt + 1; end end endgenerate // indicate when a write is occurring. PHY_RDDATA_EN must be asserted // simultaneous with the corresponding command/address. PHY_RDDATA_EN // is used during read-leveling to determine read latency assign phy_rddata_en = ~phy_if_empty; // Read data valid generation for MC and User Interface after calibration is // complete assign phy_rddata_valid = init_complete_r1_timing ? phy_rddata_en : 1'b0; //*************************************************************************** // Generate training data written at start of each read-leveling stage // For every stage of read leveling, 8 words are written into memory // The format is as follows (shown as {rise,fall}): // Stage 1: 0xF, 0x0, 0xF, 0x0, 0xF, 0x0, 0xF, 0x0 // Stage 2: 0xF, 0x0, 0xA, 0x5, 0x5, 0xA, 0x9, 0x6 //*************************************************************************** always @(posedge clk) if ((init_state_r == INIT_IDLE) || (init_state_r == INIT_RDLVL_STG1_WRITE)) cnt_init_data_r <= #TCQ 2'b00; else if (phy_wrdata_en) cnt_init_data_r <= #TCQ cnt_init_data_r + 1; else if (init_state_r == INIT_WRCAL_WRITE) cnt_init_data_r <= #TCQ 2'b10; // write different sequence for very // first write to memory only. Used to help us differentiate // if the writes are "early" or "on-time" during read leveling always @(posedge clk) if (rst || rdlvl_stg1_rank_done) first_rdlvl_pat_r <= #TCQ 1'b1; else if (phy_wrdata_en && (init_state_r == INIT_RDLVL_STG1_WRITE)) first_rdlvl_pat_r <= #TCQ 1'b0; always @(posedge clk) if (rst || wrcal_resume || (init_state_r == INIT_WRCAL_ACT_WAIT)) first_wrcal_pat_r <= #TCQ 1'b1; else if (phy_wrdata_en && (init_state_r == INIT_WRCAL_WRITE)) first_wrcal_pat_r <= #TCQ 1'b0; generate if ((CLK_PERIOD/nCK_PER_CLK > 2500) && (nCK_PER_CLK == 2)) begin: wrdq_div2_2to1_rdlvl_first always @(posedge clk) if (~oclkdelay_calib_done) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hF}}, {DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}}, {DQ_WIDTH/4{4'h0}}}; else if (!rdlvl_stg1_done) begin // The 16 words for stage 1 write data in 2:1 mode is written // over 4 consecutive controller clock cycles. Note that write // data follows phy_wrdata_en by one clock cycle case (wrdata_pat_cnt) 2'b00: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h3}}, {DQ_WIDTH/4{4'h9}}}; end 2'b01: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hC}}}; end 2'b10: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h1}}, {DQ_WIDTH/4{4'hB}}}; end 2'b11: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hC}}}; end endcase end else if (!prbs_rdlvl_done && ~phy_data_full) begin // prbs_o is 8-bits wide hence {DQ_WIDTH/8{prbs_o}} results in // prbs_o being concatenated 8 times resulting in DQ_WIDTH phy_wrdata <= #TCQ {{DQ_WIDTH/8{prbs_o[4*8-1:3*8]}}, {DQ_WIDTH/8{prbs_o[3*8-1:2*8]}}, {DQ_WIDTH/8{prbs_o[2*8-1:8]}}, {DQ_WIDTH/8{prbs_o[8-1:0]}}}; end else if (!wrcal_done) begin case (wrcal_pat_cnt) 2'b00: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h5}}, {DQ_WIDTH/4{4'hA}}, {DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}}}; end 2'b01: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h6}}, {DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hA}}, {DQ_WIDTH/4{4'h5}}}; end 2'b10: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h1}}, {DQ_WIDTH/4{4'hB}}}; end 2'b11: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h8}}, {DQ_WIDTH/4{4'hD}}, {DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h4}}}; end endcase end end else if ((CLK_PERIOD/nCK_PER_CLK > 2500) && (nCK_PER_CLK == 4)) begin: wrdq_div2_4to1_rdlvl_first always @(posedge clk) if (~oclkdelay_calib_done) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}}; else if (!rdlvl_stg1_done && ~phy_data_full) // write different sequence for very // first write to memory only. Used to help us differentiate // if the writes are "early" or "on-time" during read leveling if (first_rdlvl_pat_r) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}},{DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}},{DQ_WIDTH/4{4'hC}}, {DQ_WIDTH/4{4'hE}},{DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h3}},{DQ_WIDTH/4{4'h9}}}; else // For all others, change the first two words written in order // to differentiate the "early write" and "on-time write" // readback patterns during read leveling phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}},{DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}},{DQ_WIDTH/4{4'hC}}, {DQ_WIDTH/4{4'hE}},{DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h1}},{DQ_WIDTH/4{4'hB}}}; else if (!prbs_rdlvl_done && ~phy_data_full) // prbs_o is 8-bits wide hence {DQ_WIDTH/8{prbs_o}} results in // prbs_o being concatenated 8 times resulting in DQ_WIDTH phy_wrdata <= #TCQ {{DQ_WIDTH/8{prbs_o[8*8-1:7*8]}},{DQ_WIDTH/8{prbs_o[7*8-1:6*8]}}, {DQ_WIDTH/8{prbs_o[6*8-1:5*8]}},{DQ_WIDTH/8{prbs_o[5*8-1:4*8]}}, {DQ_WIDTH/8{prbs_o[4*8-1:3*8]}},{DQ_WIDTH/8{prbs_o[3*8-1:2*8]}}, {DQ_WIDTH/8{prbs_o[2*8-1:8]}},{DQ_WIDTH/8{prbs_o[8-1:0]}}}; else if (!wrcal_done) if (first_wrcal_pat_r) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h6}},{DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hA}},{DQ_WIDTH/4{4'h5}}, {DQ_WIDTH/4{4'h5}},{DQ_WIDTH/4{4'hA}}, {DQ_WIDTH/4{4'h0}},{DQ_WIDTH/4{4'hF}}}; else phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h8}},{DQ_WIDTH/4{4'hD}}, {DQ_WIDTH/4{4'hE}},{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'h4}},{DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h1}},{DQ_WIDTH/4{4'hB}}}; end else if (nCK_PER_CLK == 4) begin: wrdq_div1_4to1_wrcal_first always @(posedge clk) if ((~oclkdelay_calib_done) && (DRAM_TYPE == "DDR3")) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}},{DQ_WIDTH/4{4'h0}}}; else if ((!wrcal_done)&& (DRAM_TYPE == "DDR3")) begin if (extend_cal_pat) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h6}},{DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hA}},{DQ_WIDTH/4{4'h5}}, {DQ_WIDTH/4{4'h5}},{DQ_WIDTH/4{4'hA}}, {DQ_WIDTH/4{4'h0}},{DQ_WIDTH/4{4'hF}}}; else if (first_wrcal_pat_r) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h6}},{DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hA}},{DQ_WIDTH/4{4'h5}}, {DQ_WIDTH/4{4'h5}},{DQ_WIDTH/4{4'hA}}, {DQ_WIDTH/4{4'h0}},{DQ_WIDTH/4{4'hF}}}; else phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h8}},{DQ_WIDTH/4{4'hD}}, {DQ_WIDTH/4{4'hE}},{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'h4}},{DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h1}},{DQ_WIDTH/4{4'hB}}}; end else if (!rdlvl_stg1_done && ~phy_data_full) begin // write different sequence for very // first write to memory only. Used to help us differentiate // if the writes are "early" or "on-time" during read leveling if (first_rdlvl_pat_r) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}},{DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}},{DQ_WIDTH/4{4'hC}}, {DQ_WIDTH/4{4'hE}},{DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h3}},{DQ_WIDTH/4{4'h9}}}; else // For all others, change the first two words written in order // to differentiate the "early write" and "on-time write" // readback patterns during read leveling phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}},{DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}},{DQ_WIDTH/4{4'hC}}, {DQ_WIDTH/4{4'hE}},{DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h1}},{DQ_WIDTH/4{4'hB}}}; end else if (!prbs_rdlvl_done && ~phy_data_full) // prbs_o is 8-bits wide hence {DQ_WIDTH/8{prbs_o}} results in // prbs_o being concatenated 8 times resulting in DQ_WIDTH phy_wrdata <= #TCQ {{DQ_WIDTH/8{prbs_o[8*8-1:7*8]}},{DQ_WIDTH/8{prbs_o[7*8-1:6*8]}}, {DQ_WIDTH/8{prbs_o[6*8-1:5*8]}},{DQ_WIDTH/8{prbs_o[5*8-1:4*8]}}, {DQ_WIDTH/8{prbs_o[4*8-1:3*8]}},{DQ_WIDTH/8{prbs_o[3*8-1:2*8]}}, {DQ_WIDTH/8{prbs_o[2*8-1:8]}},{DQ_WIDTH/8{prbs_o[8-1:0]}}}; end else begin: wrdq_div1_2to1_wrcal_first always @(posedge clk) if ((~oclkdelay_calib_done)&& (DRAM_TYPE == "DDR3")) phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hF}}, {DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}}, {DQ_WIDTH/4{4'h0}}}; else if ((!wrcal_done) && (DRAM_TYPE == "DDR3"))begin case (wrcal_pat_cnt) 2'b00: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h5}}, {DQ_WIDTH/4{4'hA}}, {DQ_WIDTH/4{4'h0}}, {DQ_WIDTH/4{4'hF}}}; end 2'b01: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h6}}, {DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hA}}, {DQ_WIDTH/4{4'h5}}}; end 2'b10: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h1}}, {DQ_WIDTH/4{4'hB}}}; end 2'b11: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h8}}, {DQ_WIDTH/4{4'hD}}, {DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h4}}}; end endcase end else if (!rdlvl_stg1_done) begin // The 16 words for stage 1 write data in 2:1 mode is written // over 4 consecutive controller clock cycles. Note that write // data follows phy_wrdata_en by one clock cycle case (wrdata_pat_cnt) 2'b00: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h3}}, {DQ_WIDTH/4{4'h9}}}; end 2'b01: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hC}}}; end 2'b10: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'hE}}, {DQ_WIDTH/4{4'h7}}, {DQ_WIDTH/4{4'h1}}, {DQ_WIDTH/4{4'hB}}}; end 2'b11: begin phy_wrdata <= #TCQ {{DQ_WIDTH/4{4'h4}}, {DQ_WIDTH/4{4'h2}}, {DQ_WIDTH/4{4'h9}}, {DQ_WIDTH/4{4'hC}}}; end endcase end else if (!prbs_rdlvl_done && ~phy_data_full) begin // prbs_o is 8-bits wide hence {DQ_WIDTH/8{prbs_o}} results in // prbs_o being concatenated 8 times resulting in DQ_WIDTH phy_wrdata <= #TCQ {{DQ_WIDTH/8{prbs_o[4*8-1:3*8]}}, {DQ_WIDTH/8{prbs_o[3*8-1:2*8]}}, {DQ_WIDTH/8{prbs_o[2*8-1:8]}}, {DQ_WIDTH/8{prbs_o[8-1:0]}}}; end end endgenerate //*************************************************************************** // Memory control/address //*************************************************************************** // Phases [2] and [3] are always deasserted for 4:1 mode generate if (nCK_PER_CLK == 4) begin: gen_div4_ca_tieoff always @(posedge clk) begin phy_ras_n[3:2] <= #TCQ 3'b11; phy_cas_n[3:2] <= #TCQ 3'b11; phy_we_n[3:2] <= #TCQ 3'b11; end end endgenerate // Assert RAS when: (1) Loading MRS, (2) Activating Row, (3) Precharging // (4) auto refresh generate if (!(CWL_M % 2)) begin: even_cwl always @(posedge clk) begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_REG_WRITE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH))begin phy_ras_n[0] <= #TCQ 1'b0; phy_ras_n[1] <= #TCQ 1'b1; end else begin phy_ras_n[0] <= #TCQ 1'b1; phy_ras_n[1] <= #TCQ 1'b1; end end // Assert CAS when: (1) Loading MRS, (2) Issuing Read/Write command // (3) auto refresh always @(posedge clk) begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_REG_WRITE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r))begin phy_cas_n[0] <= #TCQ 1'b0; phy_cas_n[1] <= #TCQ 1'b1; end else begin phy_cas_n[0] <= #TCQ 1'b1; phy_cas_n[1] <= #TCQ 1'b1; end end // Assert WE when: (1) Loading MRS, (2) Issuing Write command (only // occur during read leveling), (3) Issuing ZQ Long Calib command, // (4) Precharge always @(posedge clk) begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_REG_WRITE) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE)|| (rdlvl_wr && new_burst_r))begin phy_we_n[0] <= #TCQ 1'b0; phy_we_n[1] <= #TCQ 1'b1; end else begin phy_we_n[0] <= #TCQ 1'b1; phy_we_n[1] <= #TCQ 1'b1; end end end else begin: odd_cwl always @(posedge clk) begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_REG_WRITE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE) || (init_state_r == INIT_REFRESH))begin phy_ras_n[0] <= #TCQ 1'b1; phy_ras_n[1] <= #TCQ 1'b0; end else begin phy_ras_n[0] <= #TCQ 1'b1; phy_ras_n[1] <= #TCQ 1'b1; end end // Assert CAS when: (1) Loading MRS, (2) Issuing Read/Write command // (3) auto refresh always @(posedge clk) begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_REG_WRITE) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_REFRESH) || (rdlvl_wr_rd && new_burst_r))begin phy_cas_n[0] <= #TCQ 1'b1; phy_cas_n[1] <= #TCQ 1'b0; end else begin phy_cas_n[0] <= #TCQ 1'b1; phy_cas_n[1] <= #TCQ 1'b1; end end // Assert WE when: (1) Loading MRS, (2) Issuing Write command (only // occur during read leveling), (3) Issuing ZQ Long Calib command, // (4) Precharge always @(posedge clk) begin if ((init_state_r == INIT_LOAD_MR) || (init_state_r == INIT_MPR_RDEN) || (init_state_r == INIT_MPR_DISABLE) || (init_state_r == INIT_REG_WRITE) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_WRLVL_START) || (init_state_r == INIT_WRLVL_LOAD_MR) || (init_state_r == INIT_WRLVL_LOAD_MR2) || (init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_DDR2_PRECHARGE)|| (rdlvl_wr && new_burst_r))begin phy_we_n[0] <= #TCQ 1'b1; phy_we_n[1] <= #TCQ 1'b0; end else begin phy_we_n[0] <= #TCQ 1'b1; phy_we_n[1] <= #TCQ 1'b1; end end end endgenerate // Assign calib_cmd for the command field in PHY_Ctl_Word always @(posedge clk) begin if (wr_level_dqs_asrt) begin // Request to toggle DQS during write leveling calib_cmd <= #TCQ 3'b001; if (CWL_M % 2) begin // odd write latency calib_data_offset_0 <= #TCQ CWL_M + 3; calib_data_offset_1 <= #TCQ CWL_M + 3; calib_data_offset_2 <= #TCQ CWL_M + 3; calib_cas_slot <= #TCQ 2'b01; end else begin // even write latency calib_data_offset_0 <= #TCQ CWL_M + 2; calib_data_offset_1 <= #TCQ CWL_M + 2; calib_data_offset_2 <= #TCQ CWL_M + 2; calib_cas_slot <= #TCQ 2'b00; end end else if (rdlvl_wr && new_burst_r) begin // Write Command calib_cmd <= #TCQ 3'b001; if (CWL_M % 2) begin // odd write latency calib_data_offset_0 <= #TCQ (nCK_PER_CLK == 4) ? CWL_M + 3 : CWL_M - 1; calib_data_offset_1 <= #TCQ (nCK_PER_CLK == 4) ? CWL_M + 3 : CWL_M - 1; calib_data_offset_2 <= #TCQ (nCK_PER_CLK == 4) ? CWL_M + 3 : CWL_M - 1; calib_cas_slot <= #TCQ 2'b01; end else begin // even write latency calib_data_offset_0 <= #TCQ (nCK_PER_CLK == 4) ? CWL_M + 2 : CWL_M - 2 ; calib_data_offset_1 <= #TCQ (nCK_PER_CLK == 4) ? CWL_M + 2 : CWL_M - 2 ; calib_data_offset_2 <= #TCQ (nCK_PER_CLK == 4) ? CWL_M + 2 : CWL_M - 2 ; calib_cas_slot <= #TCQ 2'b00; end end else if (rdlvl_rd && new_burst_r) begin // Read Command calib_cmd <= #TCQ 3'b011; if (CWL_M % 2) calib_cas_slot <= #TCQ 2'b01; else calib_cas_slot <= #TCQ 2'b00; if (~pi_calib_done_r1) begin calib_data_offset_0 <= #TCQ 6'd0; calib_data_offset_1 <= #TCQ 6'd0; calib_data_offset_2 <= #TCQ 6'd0; end else if (~pi_dqs_found_done_r1) begin calib_data_offset_0 <= #TCQ rd_data_offset_0; calib_data_offset_1 <= #TCQ rd_data_offset_1; calib_data_offset_2 <= #TCQ rd_data_offset_2; end else begin calib_data_offset_0 <= #TCQ rd_data_offset_ranks_0[6*chip_cnt_r+:6]; calib_data_offset_1 <= #TCQ rd_data_offset_ranks_1[6*chip_cnt_r+:6]; calib_data_offset_2 <= #TCQ rd_data_offset_ranks_2[6*chip_cnt_r+:6]; end end else begin // Non-Data Commands like NOP, MRS, ZQ Long Cal, Precharge, // Active, Refresh calib_cmd <= #TCQ 3'b100; calib_data_offset_0 <= #TCQ 6'd0; calib_data_offset_1 <= #TCQ 6'd0; calib_data_offset_2 <= #TCQ 6'd0; if (CWL_M % 2) calib_cas_slot <= #TCQ 2'b01; else calib_cas_slot <= #TCQ 2'b00; end end // Write Enable to PHY_Control FIFO always asserted // No danger of this FIFO being Full with 4:1 sync clock ratio // This is also the write enable to the command OUT_FIFO always @(posedge clk) begin if (rst) begin calib_ctl_wren <= #TCQ 1'b0; calib_cmd_wren <= #TCQ 1'b0; calib_seq <= #TCQ 2'b00; end else if (cnt_pwron_cke_done_r && phy_ctl_ready && ~(phy_ctl_full || phy_cmd_full )) begin calib_ctl_wren <= #TCQ 1'b1; calib_cmd_wren <= #TCQ 1'b1; calib_seq <= #TCQ calib_seq + 1; end else begin calib_ctl_wren <= #TCQ 1'b0; calib_cmd_wren <= #TCQ 1'b0; calib_seq <= #TCQ calib_seq; end end generate genvar rnk_i; for (rnk_i = 0; rnk_i < 4; rnk_i = rnk_i + 1) begin: gen_rnk always @(posedge clk) begin if (rst) begin mr2_r[rnk_i] <= #TCQ 2'b00; mr1_r[rnk_i] <= #TCQ 3'b000; end else begin mr2_r[rnk_i] <= #TCQ tmp_mr2_r[rnk_i]; mr1_r[rnk_i] <= #TCQ tmp_mr1_r[rnk_i]; end end end endgenerate // ODT assignment based on slot config and slot present // For single slot systems slot_1_present input will be ignored // Assuming component interfaces to be single slot systems generate if (nSLOTS == 1) begin: gen_single_slot_odt always @(posedge clk) begin if (rst) begin tmp_mr2_r[1] <= #TCQ 2'b00; tmp_mr2_r[2] <= #TCQ 2'b00; tmp_mr2_r[3] <= #TCQ 2'b00; tmp_mr1_r[1] <= #TCQ 3'b000; tmp_mr1_r[2] <= #TCQ 3'b000; tmp_mr1_r[3] <= #TCQ 3'b000; phy_tmp_cs1_r <= #TCQ {CS_WIDTH*nCS_PER_RANK{1'b1}}; phy_tmp_odt_r <= #TCQ 4'b0000; phy_tmp_odt_r1 <= #TCQ phy_tmp_odt_r; end else begin case ({slot_0_present[0],slot_0_present[1], slot_0_present[2],slot_0_present[3]}) // Single slot configuration with quad rank // Assuming same behavior as single slot dual rank for now // DDR2 does not have quad rank parts 4'b1111: begin if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 RTT_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 RTT_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end phy_tmp_odt_r <= #TCQ 4'b0001; // Chip Select assignments phy_tmp_cs1_r[((chip_cnt_r*nCS_PER_RANK) ) +: nCS_PER_RANK] <= #TCQ 'b0; end // Single slot configuration with single rank 4'b1000: begin phy_tmp_odt_r <= #TCQ 4'b0001; if ((REG_CTRL == "ON") && (nCS_PER_RANK > 1)) begin phy_tmp_cs1_r[chip_cnt_r] <= #TCQ 1'b0; end else begin phy_tmp_cs1_r <= #TCQ {CS_WIDTH*nCS_PER_RANK{1'b0}}; end if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && ((cnt_init_mr_r == 2'd0) || (USE_ODT_PORT == 1)))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 RTT_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 RTT_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end end // Single slot configuration with dual rank 4'b1100: begin phy_tmp_odt_r <= #TCQ 4'b0001; // Chip Select assignments phy_tmp_cs1_r[((chip_cnt_r*nCS_PER_RANK) ) +: nCS_PER_RANK] <= #TCQ 'b0; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end end default: begin phy_tmp_odt_r <= #TCQ 4'b0001; phy_tmp_cs1_r <= #TCQ {CS_WIDTH*nCS_PER_RANK{1'b0}}; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done)) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end end endcase end end end else if (nSLOTS == 2) begin: gen_dual_slot_odt always @ (posedge clk) begin if (rst) begin tmp_mr2_r[1] <= #TCQ 2'b00; tmp_mr2_r[2] <= #TCQ 2'b00; tmp_mr2_r[3] <= #TCQ 2'b00; tmp_mr1_r[1] <= #TCQ 3'b000; tmp_mr1_r[2] <= #TCQ 3'b000; tmp_mr1_r[3] <= #TCQ 3'b000; phy_tmp_odt_r <= #TCQ 4'b0000; phy_tmp_cs1_r <= #TCQ {CS_WIDTH*nCS_PER_RANK{1'b1}}; phy_tmp_odt_r1 <= #TCQ phy_tmp_odt_r; end else begin case ({slot_0_present[0],slot_0_present[1], slot_1_present[0],slot_1_present[1]}) // Two slot configuration, one slot present, single rank 4'b10_00: begin if (//wrlvl_odt || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin // odt turned on only during write phy_tmp_odt_r <= #TCQ 4'b0001; end phy_tmp_cs1_r <= #TCQ {nCS_PER_RANK{1'b0}}; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done)) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end end 4'b00_10: begin //Rank1 ODT enabled if (//wrlvl_odt || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin // odt turned on only during write phy_tmp_odt_r <= #TCQ 4'b0001; end phy_tmp_cs1_r <= #TCQ {nCS_PER_RANK{1'b0}}; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done)) begin //Rank1 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank1 Rtt_NOM defaults to 120 ohms tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank1 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end end // Two slot configuration, one slot present, dual rank 4'b00_11: begin if (//wrlvl_odt || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin // odt turned on only during write phy_tmp_odt_r <= #TCQ 4'b0001; end // Chip Select assignments phy_tmp_cs1_r[(chip_cnt_r*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end end 4'b11_00: begin if (//wrlvl_odt || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin // odt turned on only during write phy_tmp_odt_r <= #TCQ 4'b0001; end // Chip Select assignments phy_tmp_cs1_r[(chip_cnt_r*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank1 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank1 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank1 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end end // Two slot configuration, one rank per slot 4'b10_10: begin if(DRAM_TYPE == "DDR2")begin if(chip_cnt_r == 2'b00)begin phy_tmp_odt_r <= #TCQ 4'b0010; //bit0 for rank0 end else begin phy_tmp_odt_r <= #TCQ 4'b0001; //bit0 for rank0 end end else begin if(init_state_r == INIT_WRLVL_WAIT) phy_tmp_odt_r <= #TCQ 4'b0011; // rank 0/1 odt0 else if((init_next_state == INIT_RDLVL_STG1_WRITE) || (init_next_state == INIT_WRCAL_WRITE) || (init_next_state == INIT_OCLKDELAY_WRITE)) phy_tmp_odt_r <= #TCQ 4'b0011; // bit0 for rank0/1 (write) else if ((init_next_state == INIT_PI_PHASELOCK_READS) || (init_next_state == INIT_MPR_READ) || (init_next_state == INIT_RDLVL_STG1_READ) || (init_next_state == INIT_RDLVL_STG2_READ) || (init_next_state == INIT_OCLKDELAY_READ) || (init_next_state == INIT_WRCAL_READ) || (init_next_state == INIT_WRCAL_MULT_READS)) phy_tmp_odt_r <= #TCQ 4'b0010; // bit0 for rank1 (rank 0 rd) end // Chip Select assignments phy_tmp_cs1_r[(chip_cnt_r*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_WR == "60") ? 3'b001 : (RTT_WR == "120") ? 3'b010 : 3'b000; //Rank1 Dynamic ODT disabled tmp_mr2_r[1] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : (RTT_NOM_int == "20") ? 3'b100 : (RTT_NOM_int == "30") ? 3'b101 : (RTT_NOM_int == "40") ? 3'b011 : 3'b000; //Rank1 Dynamic ODT defaults to 120 ohms tmp_mr2_r[1] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : (RTT_NOM_int == "20") ? 3'b100 : (RTT_NOM_int == "30") ? 3'b101 : (RTT_NOM_int == "40") ? 3'b011 : 3'b000; end end // Two Slots - One slot with dual rank and other with single rank 4'b10_11: begin //Rank3 Rtt_NOM tmp_mr1_r[2] <= #TCQ (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : (RTT_NOM_int == "20") ? 3'b100 : (RTT_NOM_int == "30") ? 3'b101 : (RTT_NOM_int == "40") ? 3'b011 : 3'b000; tmp_mr2_r[2] <= #TCQ 2'b00; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; //Rank1 Dynamic ODT disabled tmp_mr2_r[1] <= #TCQ 2'b00; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : (RTT_NOM_int == "20") ? 3'b100 : (RTT_NOM_int == "30") ? 3'b101 : (RTT_NOM_int == "40") ? 3'b011 : 3'b000; //Rank1 Dynamic ODT defaults to 120 ohms tmp_mr2_r[1] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM after write leveling completes tmp_mr1_r[1] <= #TCQ 3'b000; end //Slot1 Rank1 or Rank3 is being written if(DRAM_TYPE == "DDR2")begin if(chip_cnt_r == 2'b00)begin phy_tmp_odt_r <= #TCQ 4'b0010; end else begin phy_tmp_odt_r <= #TCQ 4'b0001; end end else begin if (//wrlvl_odt || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin if (chip_cnt_r[0] == 1'b1) begin phy_tmp_odt_r <= #TCQ 4'b0011; //Slot0 Rank0 is being written end else begin phy_tmp_odt_r <= #TCQ 4'b0101; // ODT for ranks 0 and 2 aserted end end else if ((init_state_r == INIT_RDLVL_STG1_READ) || (init_state_r == INIT_PI_PHASELOCK_READS) || (init_state_r == INIT_RDLVL_STG2_READ) || (init_state_r == INIT_OCLKDELAY_READ) || (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_WRCAL_MULT_READS))begin if (chip_cnt_r == 2'b00) begin phy_tmp_odt_r <= #TCQ 4'b0100; end else begin phy_tmp_odt_r <= #TCQ 4'b0001; end end end // Chip Select assignments phy_tmp_cs1_r[(chip_cnt_r*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; end // Two Slots - One slot with dual rank and other with single rank 4'b11_10: begin //Rank2 Rtt_NOM tmp_mr1_r[2] <= #TCQ (RTT_NOM2 == "60") ? 3'b001 : (RTT_NOM2 == "120") ? 3'b010 : (RTT_NOM2 == "20") ? 3'b100 : (RTT_NOM2 == "30") ? 3'b101 : (RTT_NOM2 == "40") ? 3'b011: 3'b000; tmp_mr2_r[2] <= #TCQ 2'b00; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; //Rank1 Dynamic ODT disabled tmp_mr2_r[1] <= #TCQ 2'b00; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank1 Dynamic ODT defaults to 120 ohms tmp_mr2_r[1] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : (RTT_NOM_int == "20") ? 3'b100 : (RTT_NOM_int == "30") ? 3'b101 : (RTT_NOM_int == "40") ? 3'b011: 3'b000; //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end if(DRAM_TYPE == "DDR2")begin if(chip_cnt_r[1] == 1'b1)begin phy_tmp_odt_r <= #TCQ 4'b0001; end else begin phy_tmp_odt_r <= #TCQ 4'b0100; // rank 2 ODT asserted end end else begin if (// wrlvl_odt || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin if (chip_cnt_r[1] == 1'b1) begin phy_tmp_odt_r <= #TCQ 4'b0110; end else begin phy_tmp_odt_r <= #TCQ 4'b0101; end end else if ((init_state_r == INIT_RDLVL_STG1_READ) || (init_state_r == INIT_PI_PHASELOCK_READS) || (init_state_r == INIT_RDLVL_STG2_READ) || (init_state_r == INIT_OCLKDELAY_READ) || (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_WRCAL_MULT_READS)) begin if (chip_cnt_r[1] == 1'b1) begin phy_tmp_odt_r[(1*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ 4'b0010; end else begin phy_tmp_odt_r <= #TCQ 4'b0100; end end end // Chip Select assignments phy_tmp_cs1_r[(chip_cnt_r*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; end // Two Slots - two ranks per slot 4'b11_11: begin //Rank2 Rtt_NOM tmp_mr1_r[2] <= #TCQ (RTT_NOM2 == "60") ? 3'b001 : (RTT_NOM2 == "120") ? 3'b010 : (RTT_NOM2 == "20") ? 3'b100 : (RTT_NOM2 == "30") ? 3'b101 : (RTT_NOM2 == "40") ? 3'b011 : 3'b000; //Rank3 Rtt_NOM tmp_mr1_r[3] <= #TCQ (RTT_NOM3 == "60") ? 3'b001 : (RTT_NOM3 == "120") ? 3'b010 : (RTT_NOM3 == "20") ? 3'b100 : (RTT_NOM3 == "30") ? 3'b101 : (RTT_NOM3 == "40") ? 3'b011 : 3'b000; tmp_mr2_r[2] <= #TCQ 2'b00; tmp_mr2_r[3] <= #TCQ 2'b00; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done && (wrlvl_rank_cntr==3'd0))) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; //Rank1 Dynamic ODT disabled tmp_mr2_r[1] <= #TCQ 2'b00; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; end else begin //Rank1 Dynamic ODT defaults to 120 ohms tmp_mr2_r[1] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM after write leveling completes tmp_mr1_r[1] <= #TCQ 3'b000; //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM after write leveling completes tmp_mr1_r[0] <= #TCQ 3'b000; end if(DRAM_TYPE == "DDR2")begin if(chip_cnt_r[1] == 1'b1)begin phy_tmp_odt_r <= #TCQ 4'b0001; end else begin phy_tmp_odt_r <= #TCQ 4'b0100; end end else begin if (//wrlvl_odt || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin //Slot1 Rank1 or Rank3 is being written if (chip_cnt_r[0] == 1'b1) begin phy_tmp_odt_r <= #TCQ 4'b0110; //Slot0 Rank0 or Rank2 is being written end else begin phy_tmp_odt_r <= #TCQ 4'b1001; end end else if ((init_state_r == INIT_RDLVL_STG1_READ) || (init_state_r == INIT_PI_PHASELOCK_READS) || (init_state_r == INIT_RDLVL_STG2_READ) || (init_state_r == INIT_OCLKDELAY_READ) || (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_WRCAL_MULT_READS))begin //Slot1 Rank1 or Rank3 is being read if (chip_cnt_r[0] == 1'b1) begin phy_tmp_odt_r <= #TCQ 4'b0100; //Slot0 Rank0 or Rank2 is being read end else begin phy_tmp_odt_r <= #TCQ 4'b1000; end end end // Chip Select assignments phy_tmp_cs1_r[(chip_cnt_r*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; end default: begin phy_tmp_odt_r <= #TCQ 4'b1111; // Chip Select assignments phy_tmp_cs1_r[(chip_cnt_r*nCS_PER_RANK) +: nCS_PER_RANK] <= #TCQ {nCS_PER_RANK{1'b0}}; if ((RTT_WR == "OFF") || ((WRLVL=="ON") && ~wrlvl_done)) begin //Rank0 Dynamic ODT disabled tmp_mr2_r[0] <= #TCQ 2'b00; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : 3'b000; //Rank1 Dynamic ODT disabled tmp_mr2_r[1] <= #TCQ 2'b00; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "40") ? 3'b011 : (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "60") ? 3'b010 : 3'b000; end else begin //Rank0 Dynamic ODT defaults to 120 ohms tmp_mr2_r[0] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank0 Rtt_NOM tmp_mr1_r[0] <= #TCQ (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : (RTT_NOM_int == "20") ? 3'b100 : (RTT_NOM_int == "30") ? 3'b101 : (RTT_NOM_int == "40") ? 3'b011 : 3'b000; //Rank1 Dynamic ODT defaults to 120 ohms tmp_mr2_r[1] <= #TCQ (RTT_WR == "60") ? 2'b01 : 2'b10; //Rank1 Rtt_NOM tmp_mr1_r[1] <= #TCQ (RTT_NOM_int == "60") ? 3'b001 : (RTT_NOM_int == "120") ? 3'b010 : (RTT_NOM_int == "20") ? 3'b100 : (RTT_NOM_int == "30") ? 3'b101 : (RTT_NOM_int == "40") ? 3'b011 : 3'b000; end end endcase end end end endgenerate // PHY only supports two ranks. // calib_aux_out[0] is CKE for rank 0 and calib_aux_out[1] is ODT for rank 0 // calib_aux_out[2] is CKE for rank 1 and calib_aux_out[3] is ODT for rank 1 generate if(CKE_ODT_AUX == "FALSE") begin if ((nSLOTS == 1) && (RANKS < 2)) begin always @(posedge clk) if (rst) begin calib_cke <= #TCQ {nCK_PER_CLK{1'b0}} ; calib_odt <= 2'b00 ; end else begin if (cnt_pwron_cke_done_r /*&& ~cnt_pwron_cke_done_r1*/)begin calib_cke <= #TCQ {nCK_PER_CLK{1'b1}}; end else begin calib_cke <= #TCQ {nCK_PER_CLK{1'b0}}; end if ((((RTT_NOM == "DISABLED") && (RTT_WR == "OFF"))/* || wrlvl_rank_done || wrlvl_rank_done_r1 || (wrlvl_done && !wrlvl_done_r)*/) && (DRAM_TYPE == "DDR3")) begin calib_odt[0] <= #TCQ 1'b0; calib_odt[1] <= #TCQ 1'b0; end else if (((DRAM_TYPE == "DDR3") ||((RTT_NOM != "DISABLED") && (DRAM_TYPE == "DDR2"))) && (((init_state_r == INIT_WRLVL_WAIT) && wrlvl_odt ) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_RDLVL_STG1_WRITE_READ) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_WRCAL_WRITE_READ) || (init_state_r == INIT_OCLKDELAY_WRITE)|| (init_state_r == INIT_OCLKDELAY_WRITE_WAIT))) begin // Quad rank in a single slot calib_odt[0] <= #TCQ phy_tmp_odt_r[0]; calib_odt[1] <= #TCQ phy_tmp_odt_r[1]; end else begin calib_odt[0] <= #TCQ 1'b0; calib_odt[1] <= #TCQ 1'b0; end end end else if ((nSLOTS == 1) && (RANKS <= 2)) begin always @(posedge clk) if (rst) begin calib_cke <= #TCQ {nCK_PER_CLK{1'b0}} ; calib_odt <= 2'b00 ; end else begin if (cnt_pwron_cke_done_r /*&& ~cnt_pwron_cke_done_r1*/)begin calib_cke <= #TCQ {nCK_PER_CLK{1'b1}}; end else begin calib_cke <= #TCQ {nCK_PER_CLK{1'b0}}; end if ((((RTT_NOM == "DISABLED") && (RTT_WR == "OFF"))/* || wrlvl_rank_done_r2 || (wrlvl_done && !wrlvl_done_r)*/) && (DRAM_TYPE == "DDR3")) begin calib_odt[0] <= #TCQ 1'b0; calib_odt[1] <= #TCQ 1'b0; end else if (((DRAM_TYPE == "DDR3") ||((RTT_NOM != "DISABLED") && (DRAM_TYPE == "DDR2"))) && (((init_state_r == INIT_WRLVL_WAIT) && wrlvl_odt)|| (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_RDLVL_STG1_WRITE_READ) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_WRCAL_WRITE_READ) || (init_state_r == INIT_OCLKDELAY_WRITE)|| (init_state_r == INIT_OCLKDELAY_WRITE_WAIT))) begin // Dual rank in a single slot calib_odt[0] <= #TCQ phy_tmp_odt_r[0]; calib_odt[1] <= #TCQ phy_tmp_odt_r[1]; end else begin calib_odt[0] <= #TCQ 1'b0; calib_odt[1] <= #TCQ 1'b0; end end end else if ((nSLOTS == 2) && (RANKS == 2)) begin always @(posedge clk) if (rst)begin calib_cke <= #TCQ {nCK_PER_CLK{1'b0}} ; calib_odt <= 2'b00 ; end else begin if (cnt_pwron_cke_done_r /*&& ~cnt_pwron_cke_done_r1*/)begin calib_cke <= #TCQ {nCK_PER_CLK{1'b1}}; end else begin calib_cke <= #TCQ {nCK_PER_CLK{1'b0}}; end if (((DRAM_TYPE == "DDR2") && (RTT_NOM == "DISABLED")) || ((DRAM_TYPE == "DDR3") && (RTT_NOM == "DISABLED") && (RTT_WR == "OFF"))) begin calib_odt[0] <= #TCQ 1'b0; calib_odt[1] <= #TCQ 1'b0; end else if (((init_state_r == INIT_WRLVL_WAIT) && wrlvl_odt) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE)) begin // Quad rank in a single slot if (nCK_PER_CLK == 2) begin calib_odt[0] <= #TCQ (!calib_odt[0]) ? phy_tmp_odt_r[0] : 1'b0; calib_odt[1] <= #TCQ (!calib_odt[1]) ? phy_tmp_odt_r[1] : 1'b0; end else begin calib_odt[0] <= #TCQ phy_tmp_odt_r[0]; calib_odt[1] <= #TCQ phy_tmp_odt_r[1]; end // Turn on for idle rank during read if dynamic ODT is enabled in DDR3 end else if(((DRAM_TYPE == "DDR3") && (RTT_WR != "OFF")) && ((init_state_r == INIT_PI_PHASELOCK_READS) || (init_state_r == INIT_MPR_READ) || (init_state_r == INIT_RDLVL_STG1_READ) || (init_state_r == INIT_RDLVL_STG2_READ) || (init_state_r == INIT_OCLKDELAY_READ) || (init_state_r == INIT_WRCAL_READ) || (init_state_r == INIT_WRCAL_MULT_READS))) begin if (nCK_PER_CLK == 2) begin calib_odt[0] <= #TCQ (!calib_odt[0]) ? phy_tmp_odt_r[0] : 1'b0; calib_odt[1] <= #TCQ (!calib_odt[1]) ? phy_tmp_odt_r[1] : 1'b0; end else begin calib_odt[0] <= #TCQ phy_tmp_odt_r[0]; calib_odt[1] <= #TCQ phy_tmp_odt_r[1]; end // disable well before next command and before disabling write leveling end else if(cnt_cmd_done_m7_r || (init_state_r == INIT_WRLVL_WAIT && ~wrlvl_odt)) calib_odt <= #TCQ 2'b00; end end end else begin//USE AUX OUTPUT for routing CKE and ODT. if ((nSLOTS == 1) && (RANKS < 2)) begin always @(posedge clk) if (rst) begin calib_aux_out <= #TCQ 4'b0000; end else begin if (cnt_pwron_cke_done_r && ~cnt_pwron_cke_done_r1)begin calib_aux_out[0] <= #TCQ 1'b1; calib_aux_out[2] <= #TCQ 1'b1; end else begin calib_aux_out[0] <= #TCQ 1'b0; calib_aux_out[2] <= #TCQ 1'b0; end if ((((RTT_NOM == "DISABLED") && (RTT_WR == "OFF")) || wrlvl_rank_done || wrlvl_rank_done_r1 || (wrlvl_done && !wrlvl_done_r)) && (DRAM_TYPE == "DDR3")) begin calib_aux_out[1] <= #TCQ 1'b0; calib_aux_out[3] <= #TCQ 1'b0; end else if (((DRAM_TYPE == "DDR3") ||((RTT_NOM != "DISABLED") && (DRAM_TYPE == "DDR2"))) && (((init_state_r == INIT_WRLVL_WAIT) && wrlvl_odt) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE))) begin // Quad rank in a single slot calib_aux_out[1] <= #TCQ phy_tmp_odt_r[0]; calib_aux_out[3] <= #TCQ phy_tmp_odt_r[1]; end else begin calib_aux_out[1] <= #TCQ 1'b0; calib_aux_out[3] <= #TCQ 1'b0; end end end else if ((nSLOTS == 1) && (RANKS <= 2)) begin always @(posedge clk) if (rst) begin calib_aux_out <= #TCQ 4'b0000; end else begin if (cnt_pwron_cke_done_r && ~cnt_pwron_cke_done_r1)begin calib_aux_out[0] <= #TCQ 1'b1; calib_aux_out[2] <= #TCQ 1'b1; end else begin calib_aux_out[0] <= #TCQ 1'b0; calib_aux_out[2] <= #TCQ 1'b0; end if ((((RTT_NOM == "DISABLED") && (RTT_WR == "OFF")) || wrlvl_rank_done_r2 || (wrlvl_done && !wrlvl_done_r)) && (DRAM_TYPE == "DDR3")) begin calib_aux_out[1] <= #TCQ 1'b0; calib_aux_out[3] <= #TCQ 1'b0; end else if (((DRAM_TYPE == "DDR3") ||((RTT_NOM != "DISABLED") && (DRAM_TYPE == "DDR2"))) && (((init_state_r == INIT_WRLVL_WAIT) && wrlvl_odt) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE))) begin // Dual rank in a single slot calib_aux_out[1] <= #TCQ phy_tmp_odt_r[0]; calib_aux_out[3] <= #TCQ phy_tmp_odt_r[1]; end else begin calib_aux_out[1] <= #TCQ 1'b0; calib_aux_out[3] <= #TCQ 1'b0; end end end else if ((nSLOTS == 2) && (RANKS == 2)) begin always @(posedge clk) if (rst) calib_aux_out <= #TCQ 4'b0000; else begin if (cnt_pwron_cke_done_r && ~cnt_pwron_cke_done_r1)begin calib_aux_out[0] <= #TCQ 1'b1; calib_aux_out[2] <= #TCQ 1'b1; end else begin calib_aux_out[0] <= #TCQ 1'b0; calib_aux_out[2] <= #TCQ 1'b0; end if ((((RTT_NOM == "DISABLED") && (RTT_WR == "OFF")) || wrlvl_rank_done_r2 || (wrlvl_done && !wrlvl_done_r)) && (DRAM_TYPE == "DDR3")) begin calib_aux_out[1] <= #TCQ 1'b0; calib_aux_out[3] <= #TCQ 1'b0; end else if (((DRAM_TYPE == "DDR3") ||((RTT_NOM != "DISABLED") && (DRAM_TYPE == "DDR2"))) && (((init_state_r == INIT_WRLVL_WAIT) && wrlvl_odt) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_OCLKDELAY_WRITE))) begin // Quad rank in a single slot if (nCK_PER_CLK == 2) begin calib_aux_out[1] <= #TCQ (!calib_aux_out[1]) ? phy_tmp_odt_r[0] : 1'b0; calib_aux_out[3] <= #TCQ (!calib_aux_out[3]) ? phy_tmp_odt_r[1] : 1'b0; end else begin calib_aux_out[1] <= #TCQ phy_tmp_odt_r[0]; calib_aux_out[3] <= #TCQ phy_tmp_odt_r[1]; end end else begin calib_aux_out[1] <= #TCQ 1'b0; calib_aux_out[3] <= #TCQ 1'b0; end end end end endgenerate //***************************************************************** // memory address during init //***************************************************************** always @(posedge clk) phy_data_full_r <= #TCQ phy_data_full; always @(burst_addr_r or cnt_init_mr_r or chip_cnt_r or wrcal_wr_cnt or ddr2_refresh_flag_r or init_state_r or load_mr0 or phy_data_full_r or load_mr1 or load_mr2 or load_mr3 or new_burst_r or phy_address or mr1_r[0][0] or mr1_r[0][1] or mr1_r[0][2] or mr1_r[1][0] or mr1_r[1][1] or mr1_r[1][2] or mr1_r[2][0] or mr1_r[2][1] or mr1_r[2][2] or mr1_r[3][0] or mr1_r[3][1] or mr1_r[3][2] or mr2_r[chip_cnt_r] or reg_ctrl_cnt_r or stg1_wr_rd_cnt or oclk_wr_cnt or rdlvl_stg1_done or prbs_rdlvl_done or pi_dqs_found_done or rdlvl_wr_rd)begin // Bus 0 for address/bank never used address_w = 'b0; bank_w = 'b0; if ((init_state_r == INIT_PRECHARGE) || (init_state_r == INIT_ZQCL) || (init_state_r == INIT_DDR2_PRECHARGE)) begin // Set A10=1 for ZQ long calibration or Precharge All address_w = 'b0; address_w[10] = 1'b1; bank_w = 'b0; end else if (init_state_r == INIT_WRLVL_START) begin // Enable wrlvl in MR1 bank_w[1:0] = 2'b01; address_w = load_mr1[ROW_WIDTH-1:0]; address_w[2] = mr1_r[chip_cnt_r][0]; address_w[6] = mr1_r[chip_cnt_r][1]; address_w[9] = mr1_r[chip_cnt_r][2]; address_w[7] = 1'b1; end else if (init_state_r == INIT_WRLVL_LOAD_MR) begin // Finished with write leveling, disable wrlvl in MR1 // For single rank disable Rtt_Nom bank_w[1:0] = 2'b01; address_w = load_mr1[ROW_WIDTH-1:0]; address_w[2] = mr1_r[chip_cnt_r][0]; address_w[6] = mr1_r[chip_cnt_r][1]; address_w[9] = mr1_r[chip_cnt_r][2]; end else if (init_state_r == INIT_WRLVL_LOAD_MR2) begin // Set RTT_WR in MR2 after write leveling disabled bank_w[1:0] = 2'b10; address_w = load_mr2[ROW_WIDTH-1:0]; address_w[10:9] = mr2_r[chip_cnt_r]; end else if (init_state_r == INIT_MPR_READ) begin address_w = 'b0; bank_w = 'b0; end else if (init_state_r == INIT_MPR_RDEN) begin // Enable MPR read with LMR3 and A2=1 bank_w[BANK_WIDTH-1:0] = 'd3; address_w = {ROW_WIDTH{1'b0}}; address_w[2] = 1'b1; end else if (init_state_r == INIT_MPR_DISABLE) begin // Disable MPR read with LMR3 and A2=0 bank_w[BANK_WIDTH-1:0] = 'd3; address_w = {ROW_WIDTH{1'b0}}; end else if ((init_state_r == INIT_REG_WRITE)& (DRAM_TYPE == "DDR3"))begin // bank_w is assigned a 3 bit value. In some // DDR2 cases there will be only two bank bits. //Qualifying the condition with DDR3 bank_w = 'b0; address_w = 'b0; case (reg_ctrl_cnt_r) REG_RC0[2:0]: address_w[4:0] = REG_RC0[4:0]; REG_RC1[2:0]:begin address_w[4:0] = REG_RC1[4:0]; bank_w = REG_RC1[7:5]; end REG_RC2[2:0]: address_w[4:0] = REG_RC2[4:0]; REG_RC3[2:0]: address_w[4:0] = REG_RC3[4:0]; REG_RC4[2:0]: address_w[4:0] = REG_RC4[4:0]; REG_RC5[2:0]: address_w[4:0] = REG_RC5[4:0]; endcase end else if (init_state_r == INIT_LOAD_MR) begin // If loading mode register, look at cnt_init_mr to determine // which MR is currently being programmed address_w = 'b0; bank_w = 'b0; if(DRAM_TYPE == "DDR3")begin if(rdlvl_stg1_done && prbs_rdlvl_done && pi_dqs_found_done)begin // end of the calibration programming correct // burst length if (TEST_AL == "0") begin bank_w[1:0] = 2'b00; address_w = load_mr0[ROW_WIDTH-1:0]; address_w[8]= 1'b0; //Don't reset DLL end else begin // programming correct AL value bank_w[1:0] = 2'b01; address_w = load_mr1[ROW_WIDTH-1:0]; if (TEST_AL == "CL-1") address_w[4:3]= 2'b01; // AL="CL-1" else address_w[4:3]= 2'b10; // AL="CL-2" end end else begin case (cnt_init_mr_r) INIT_CNT_MR2: begin bank_w[1:0] = 2'b10; address_w = load_mr2[ROW_WIDTH-1:0]; address_w[10:9] = mr2_r[chip_cnt_r]; end INIT_CNT_MR3: begin bank_w[1:0] = 2'b11; address_w = load_mr3[ROW_WIDTH-1:0]; end INIT_CNT_MR1: begin bank_w[1:0] = 2'b01; address_w = load_mr1[ROW_WIDTH-1:0]; address_w[2] = mr1_r[chip_cnt_r][0]; address_w[6] = mr1_r[chip_cnt_r][1]; address_w[9] = mr1_r[chip_cnt_r][2]; end INIT_CNT_MR0: begin bank_w[1:0] = 2'b00; address_w = load_mr0[ROW_WIDTH-1:0]; // fixing it to BL8 for calibration address_w[1:0] = 2'b00; end default: begin bank_w = {BANK_WIDTH{1'bx}}; address_w = {ROW_WIDTH{1'bx}}; end endcase end end else begin // DDR2 case (cnt_init_mr_r) INIT_CNT_MR2: begin if(~ddr2_refresh_flag_r)begin bank_w[1:0] = 2'b10; address_w = load_mr2[ROW_WIDTH-1:0]; end else begin // second set of lm commands bank_w[1:0] = 2'b00; address_w = load_mr0[ROW_WIDTH-1:0]; address_w[8]= 1'b0; //MRS command without resetting DLL end end INIT_CNT_MR3: begin if(~ddr2_refresh_flag_r)begin bank_w[1:0] = 2'b11; address_w = load_mr3[ROW_WIDTH-1:0]; end else begin // second set of lm commands bank_w[1:0] = 2'b00; address_w = load_mr0[ROW_WIDTH-1:0]; address_w[8]= 1'b0; //MRS command without resetting DLL. Repeted again // because there is an extra state. end end INIT_CNT_MR1: begin bank_w[1:0] = 2'b01; if(~ddr2_refresh_flag_r)begin address_w = load_mr1[ROW_WIDTH-1:0]; end else begin // second set of lm commands address_w = load_mr1[ROW_WIDTH-1:0]; address_w[9:7] = 3'b111; //OCD default state end end INIT_CNT_MR0: begin if(~ddr2_refresh_flag_r)begin bank_w[1:0] = 2'b00; address_w = load_mr0[ROW_WIDTH-1:0]; end else begin // second set of lm commands bank_w[1:0] = 2'b01; address_w = load_mr1[ROW_WIDTH-1:0]; if((chip_cnt_r == 2'd1) || (chip_cnt_r == 2'd3))begin // always disable odt for rank 1 and rank 3 as per SPEC address_w[2] = 'b0; address_w[6] = 'b0; end //OCD exit end end default: begin bank_w = {BANK_WIDTH{1'bx}}; address_w = {ROW_WIDTH{1'bx}}; end endcase end end else if ((init_state_r == INIT_PI_PHASELOCK_READS) || (init_state_r == INIT_RDLVL_STG1_WRITE) || (init_state_r == INIT_RDLVL_STG1_READ)) begin // Writing and reading PRBS pattern for read leveling stage 1 // Need to support burst length 4 or 8. PRBS pattern will be // written to entire row and read back from the same row repeatedly bank_w = CALIB_BA_ADD[BANK_WIDTH-1:0]; address_w[ROW_WIDTH-1:COL_WIDTH] = {ROW_WIDTH-COL_WIDTH{1'b0}}; if (((stg1_wr_rd_cnt == NUM_STG1_WR_RD) && ~rdlvl_stg1_done) || (stg1_wr_rd_cnt == 'd128)) address_w[COL_WIDTH-1:0] = {COL_WIDTH{1'b0}}; else if (phy_data_full_r || (!new_burst_r)) address_w[COL_WIDTH-1:0] = phy_address[COL_WIDTH-1:0]; else if ((stg1_wr_rd_cnt >= 9'd0) && new_burst_r && ~phy_data_full_r) address_w[COL_WIDTH-1:0] = phy_address[COL_WIDTH-1:0] + ADDR_INC; end else if ((init_state_r == INIT_OCLKDELAY_WRITE) || (init_state_r == INIT_OCLKDELAY_READ)) begin bank_w = CALIB_BA_ADD[BANK_WIDTH-1:0]; address_w[ROW_WIDTH-1:COL_WIDTH] = {ROW_WIDTH-COL_WIDTH{1'b0}}; if (oclk_wr_cnt == NUM_STG1_WR_RD) address_w[COL_WIDTH-1:0] = {COL_WIDTH{1'b0}}; else if (phy_data_full_r || (!new_burst_r)) address_w[COL_WIDTH-1:0] = phy_address[COL_WIDTH-1:0]; else if ((oclk_wr_cnt >= 4'd0) && new_burst_r && ~phy_data_full_r) address_w[COL_WIDTH-1:0] = phy_address[COL_WIDTH-1:0] + ADDR_INC; end else if ((init_state_r == INIT_WRCAL_WRITE) || (init_state_r == INIT_WRCAL_READ)) begin bank_w = CALIB_BA_ADD[BANK_WIDTH-1:0]; address_w[ROW_WIDTH-1:COL_WIDTH] = {ROW_WIDTH-COL_WIDTH{1'b0}}; if (wrcal_wr_cnt == NUM_STG1_WR_RD) address_w[COL_WIDTH-1:0] = {COL_WIDTH{1'b0}}; else if (phy_data_full_r || (!new_burst_r)) address_w[COL_WIDTH-1:0] = phy_address[COL_WIDTH-1:0]; else if ((wrcal_wr_cnt >= 4'd0) && new_burst_r && ~phy_data_full_r) address_w[COL_WIDTH-1:0] = phy_address[COL_WIDTH-1:0] + ADDR_INC; end else if ((init_state_r == INIT_WRCAL_MULT_READS) || (init_state_r == INIT_RDLVL_STG2_READ)) begin // when writing or reading back training pattern for read leveling stage2 // need to support burst length of 4 or 8. This may mean issuing // multiple commands to cover the entire range of addresses accessed // during read leveling. // Hard coding A[12] to 1 so that it will always be burst length of 8 // for DDR3. Does not have any effect on DDR2. bank_w = CALIB_BA_ADD[BANK_WIDTH-1:0]; address_w[ROW_WIDTH-1:COL_WIDTH] = {ROW_WIDTH-COL_WIDTH{1'b0}}; address_w[COL_WIDTH-1:0] = {CALIB_COL_ADD[COL_WIDTH-1:3],burst_addr_r, 3'b000}; address_w[12] = 1'b1; end else if ((init_state_r == INIT_RDLVL_ACT) || (init_state_r == INIT_WRCAL_ACT) || (init_state_r == INIT_OCLKDELAY_ACT)) begin bank_w = CALIB_BA_ADD[BANK_WIDTH-1:0]; address_w = CALIB_ROW_ADD[ROW_WIDTH-1:0]; end else begin bank_w = {BANK_WIDTH{1'bx}}; address_w = {ROW_WIDTH{1'bx}}; end end // registring before sending out generate genvar r,s; if ((DRAM_TYPE != "DDR3") || (CA_MIRROR != "ON")) begin: gen_no_mirror for (r = 0; r < nCK_PER_CLK; r = r + 1) begin: div_clk_loop always @(posedge clk) begin phy_address[(r*ROW_WIDTH) +: ROW_WIDTH] <= #TCQ address_w; phy_bank[(r*BANK_WIDTH) +: BANK_WIDTH] <= #TCQ bank_w; end end end else begin: gen_mirror // Control/addressing mirroring (optional for DDR3 dual rank DIMMs) // Mirror for the 2nd rank only. Logic needs to be enhanced to account // for multiple slots, currently only supports one slot, 2-rank config for (r = 0; r < nCK_PER_CLK; r = r + 1) begin: gen_ba_div_clk_loop for (s = 0; s < BANK_WIDTH; s = s + 1) begin: gen_ba always @(posedge clk) if (chip_cnt_r == 2'b00) begin phy_bank[(r*BANK_WIDTH) + s] <= #TCQ bank_w[s]; end else begin phy_bank[(r*BANK_WIDTH) + s] <= #TCQ bank_w[(s == 0) ? 1 : ((s == 1) ? 0 : s)]; end end end for (r = 0; r < nCK_PER_CLK; r = r + 1) begin: gen_addr_div_clk_loop for (s = 0; s < ROW_WIDTH; s = s + 1) begin: gen_addr always @(posedge clk) if (chip_cnt_r == 2'b00) begin phy_address[(r*ROW_WIDTH) + s] <= #TCQ address_w[s]; end else begin phy_address[(r*ROW_WIDTH) + s] <= #TCQ address_w[ (s == 3) ? 4 : ((s == 4) ? 3 : ((s == 5) ? 6 : ((s == 6) ? 5 : ((s == 7) ? 8 : ((s == 8) ? 7 : s)))))]; end end end end endgenerate endmodule
////////////////////////////////////////////////////////////////////////////// // // Xilinx, Inc. 2008 www.xilinx.com // ////////////////////////////////////////////////////////////////////////////// // // File name : encode.v // // Description : TMDS encoder // // Date - revision : Jan. 2008 - v 1.0 // // Author : Bob Feng // // Disclaimer: LIMITED WARRANTY AND DISCLAMER. These designs are // provided to you "as is". Xilinx and its licensors make and you // receive no warranties or conditions, express, implied, // statutory or otherwise, and Xilinx specifically disclaims any // implied warranties of merchantability, non-infringement,or // fitness for a particular purpose. Xilinx does not warrant that // the functions contained in these designs will meet your // requirements, or that the operation of these designs will be // uninterrupted or error free, or that defects in the Designs // will be corrected. Furthermore, Xilinx does not warrantor // make any representations regarding use or the results of the // use of the designs in terms of correctness, accuracy, // reliability, or otherwise. // // LIMITATION OF LIABILITY. In no event will Xilinx or its // licensors be liable for any loss of data, lost profits,cost // or procurement of substitute goods or services, or for any // special, incidental, consequential, or indirect damages // arising from the use or operation of the designs or // accompanying documentation, however caused and on any theory // of liability. This limitation will apply even if Xilinx // has been advised of the possibility of such damage. This // limitation shall apply not-withstanding the failure of the // essential purpose of any limited remedies herein. // // Copyright © 2006 Xilinx, Inc. // All rights reserved // ////////////////////////////////////////////////////////////////////////////// `timescale 1 ps / 1ps module encode ( input clkin, // pixel clock input input rstin, // async. reset input (active high) input [7:0] din, // data inputs: expect registered input c0, // c0 input input c1, // c1 input input de, // de input output reg [9:0] dout // data outputs ); //////////////////////////////////////////////////////////// // Counting number of 1s and 0s for each incoming pixel // component. Pipe line the result. // Register Data Input so it matches the pipe lined adder // output //////////////////////////////////////////////////////////// reg [3:0] n1d; //number of 1s in din reg [7:0] din_q; always @ (posedge clkin) begin n1d <=#1 din[0] + din[1] + din[2] + din[3] + din[4] + din[5] + din[6] + din[7]; din_q <=#1 din; end /////////////////////////////////////////////////////// // Stage 1: 8 bit -> 9 bit // Refer to DVI 1.0 Specification, page 29, Figure 3-5 /////////////////////////////////////////////////////// wire decision1; assign decision1 = (n1d > 4'h4) | ((n1d == 4'h4) & (din_q[0] == 1'b0)); /* reg [8:0] q_m; always @ (posedge clkin) begin q_m[0] <=#1 din_q[0]; q_m[1] <=#1 (decision1) ? (q_m[0] ^~ din_q[1]) : (q_m[0] ^ din_q[1]); q_m[2] <=#1 (decision1) ? (q_m[1] ^~ din_q[2]) : (q_m[1] ^ din_q[2]); q_m[3] <=#1 (decision1) ? (q_m[2] ^~ din_q[3]) : (q_m[2] ^ din_q[3]); q_m[4] <=#1 (decision1) ? (q_m[3] ^~ din_q[4]) : (q_m[3] ^ din_q[4]); q_m[5] <=#1 (decision1) ? (q_m[4] ^~ din_q[5]) : (q_m[4] ^ din_q[5]); q_m[6] <=#1 (decision1) ? (q_m[5] ^~ din_q[6]) : (q_m[5] ^ din_q[6]); q_m[7] <=#1 (decision1) ? (q_m[6] ^~ din_q[7]) : (q_m[6] ^ din_q[7]); q_m[8] <=#1 (decision1) ? 1'b0 : 1'b1; end */ wire [8:0] q_m; assign q_m[0] = din_q[0]; assign q_m[1] = (decision1) ? (q_m[0] ^~ din_q[1]) : (q_m[0] ^ din_q[1]); assign q_m[2] = (decision1) ? (q_m[1] ^~ din_q[2]) : (q_m[1] ^ din_q[2]); assign q_m[3] = (decision1) ? (q_m[2] ^~ din_q[3]) : (q_m[2] ^ din_q[3]); assign q_m[4] = (decision1) ? (q_m[3] ^~ din_q[4]) : (q_m[3] ^ din_q[4]); assign q_m[5] = (decision1) ? (q_m[4] ^~ din_q[5]) : (q_m[4] ^ din_q[5]); assign q_m[6] = (decision1) ? (q_m[5] ^~ din_q[6]) : (q_m[5] ^ din_q[6]); assign q_m[7] = (decision1) ? (q_m[6] ^~ din_q[7]) : (q_m[6] ^ din_q[7]); assign q_m[8] = (decision1) ? 1'b0 : 1'b1; ///////////////////////////////////////////////////////// // Stage 2: 9 bit -> 10 bit // Refer to DVI 1.0 Specification, page 29, Figure 3-5 ///////////////////////////////////////////////////////// reg [3:0] n1q_m, n0q_m; // number of 1s and 0s for q_m always @ (posedge clkin) begin n1q_m <=#1 q_m[0] + q_m[1] + q_m[2] + q_m[3] + q_m[4] + q_m[5] + q_m[6] + q_m[7]; n0q_m <=#1 4'h8 - (q_m[0] + q_m[1] + q_m[2] + q_m[3] + q_m[4] + q_m[5] + q_m[6] + q_m[7]); end parameter CTRLTOKEN0 = 10'b1101010100; parameter CTRLTOKEN1 = 10'b0010101011; parameter CTRLTOKEN2 = 10'b0101010100; parameter CTRLTOKEN3 = 10'b1010101011; reg [4:0] cnt; //disparity counter, MSB is the sign bit wire decision2, decision3; assign decision2 = (cnt == 5'h0) | (n1q_m == n0q_m); ///////////////////////////////////////////////////////////////////////// // [(cnt > 0) and (N1q_m > N0q_m)] or [(cnt < 0) and (N0q_m > N1q_m)] ///////////////////////////////////////////////////////////////////////// assign decision3 = (~cnt[4] & (n1q_m > n0q_m)) | (cnt[4] & (n0q_m > n1q_m)); //////////////////////////////////// // pipe line alignment //////////////////////////////////// reg de_q, de_reg; reg c0_q, c1_q; reg c0_reg, c1_reg; reg [8:0] q_m_reg; always @ (posedge clkin) begin de_q <=#1 de; de_reg <=#1 de_q; c0_q <=#1 c0; c0_reg <=#1 c0_q; c1_q <=#1 c1; c1_reg <=#1 c1_q; q_m_reg <=#1 q_m; end /////////////////////////////// // 10-bit out // disparity counter /////////////////////////////// always @ (posedge clkin or posedge rstin) begin if(rstin) begin dout <= 10'h0; cnt <= 5'h0; end else begin if (de_reg) begin if(decision2) begin dout[9] <=#1 ~q_m_reg[8]; dout[8] <=#1 q_m_reg[8]; dout[7:0] <=#1 (q_m_reg[8]) ? q_m_reg[7:0] : ~q_m_reg[7:0]; cnt <=#1 (~q_m_reg[8]) ? (cnt + n0q_m - n1q_m) : (cnt + n1q_m - n0q_m); end else begin if(decision3) begin dout[9] <=#1 1'b1; dout[8] <=#1 q_m_reg[8]; dout[7:0] <=#1 ~q_m_reg[7:0]; cnt <=#1 cnt + {q_m_reg[8], 1'b0} + (n0q_m - n1q_m); end else begin dout[9] <=#1 1'b0; dout[8] <=#1 q_m_reg[8]; dout[7:0] <=#1 q_m_reg[7:0]; cnt <=#1 cnt - {~q_m_reg[8], 1'b0} + (n1q_m - n0q_m); end end end else begin case ({c1_reg, c0_reg}) 2'b00: dout <=#1 CTRLTOKEN0; 2'b01: dout <=#1 CTRLTOKEN1; 2'b10: dout <=#1 CTRLTOKEN2; default: dout <=#1 CTRLTOKEN3; endcase cnt <=#1 5'h0; end end end endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : arb_row_col.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** // This block receives request to send row and column commands. These requests // come the individual bank machines. The arbitration winner is selected // and driven back to the bank machines. // // The CS enables are generated. For 2:1 mode, row commands are sent // in the "0" phase, and column commands are sent in the "1" phase. // // In 2T mode, a further arbitration is performed between the row // and column commands. The winner of this arbitration inhibits // arbitration by the loser. The winner is allowed to arbitrate, the loser is // blocked until the next state. The winning address command // is repeated on both the "0" and the "1" phases and the CS // is asserted for just the "1" phase. `timescale 1 ps / 1 ps module mig_7series_v1_9_arb_row_col # ( parameter TCQ = 100, parameter ADDR_CMD_MODE = "1T", parameter CWL = 5, parameter EARLY_WR_DATA_ADDR = "OFF", parameter nBANK_MACHS = 4, parameter nCK_PER_CLK = 2, parameter nRAS = 37500, // ACT->PRE cmd period (CKs) parameter nRCD = 12500, // ACT->R/W delay (CKs) parameter nWR = 6 // Write recovery (CKs) ) (/*AUTOARG*/ // Outputs grant_row_r, grant_pre_r, sent_row, sending_row, sending_pre, grant_config_r, rnk_config_strobe, rnk_config_valid_r, grant_col_r, sending_col, sent_col, sent_col_r, grant_col_wr, send_cmd0_row, send_cmd0_col, send_cmd1_row, send_cmd1_col, send_cmd2_row, send_cmd2_col, send_cmd2_pre, send_cmd3_col, col_channel_offset, cs_en0, cs_en1, cs_en2, cs_en3, insert_maint_r1, rnk_config_kill_rts_col, // Inputs clk, rst, rts_row, rts_pre, insert_maint_r, rts_col, rtc, col_rdy_wr ); // Create a delay when switching ranks localparam RNK2RNK_DLY = 12; localparam RNK2RNK_DLY_CLKS = (RNK2RNK_DLY / nCK_PER_CLK) + (RNK2RNK_DLY % nCK_PER_CLK ? 1 : 0); input clk; input rst; input [nBANK_MACHS-1:0] rts_row; input insert_maint_r; input [nBANK_MACHS-1:0] rts_col; reg [RNK2RNK_DLY_CLKS-1:0] rnk_config_strobe_r; wire block_grant_row; wire block_grant_col; wire rnk_config_kill_rts_col_lcl = RNK2RNK_DLY_CLKS > 0 ? |rnk_config_strobe_r : 1'b0; output rnk_config_kill_rts_col; assign rnk_config_kill_rts_col = rnk_config_kill_rts_col_lcl; wire [nBANK_MACHS-1:0] col_request; wire granted_col_ns = |col_request; wire [nBANK_MACHS-1:0] row_request = rts_row & {nBANK_MACHS{~insert_maint_r}}; wire granted_row_ns = |row_request; generate if (ADDR_CMD_MODE == "2T" && nCK_PER_CLK != 4) begin : row_col_2T_arb assign col_request = rts_col & {nBANK_MACHS{~(rnk_config_kill_rts_col_lcl || insert_maint_r)}}; // Give column command priority whenever previous state has no row request. wire [1:0] row_col_grant; wire [1:0] current_master = ~granted_row_ns ? 2'b10 : row_col_grant; wire upd_last_master = ~granted_row_ns || |row_col_grant; mig_7series_v1_9_round_robin_arb # (.WIDTH (2)) row_col_arb0 (.grant_ns (), .grant_r (row_col_grant), .upd_last_master (upd_last_master), .current_master (current_master), .clk (clk), .rst (rst), .req ({granted_row_ns, granted_col_ns}), .disable_grant (1'b0)); assign {block_grant_col, block_grant_row} = row_col_grant; end else begin : row_col_1T_arb assign col_request = rts_col & {nBANK_MACHS{~rnk_config_kill_rts_col_lcl}}; assign block_grant_row = 1'b0; assign block_grant_col = 1'b0; end endgenerate // Row address/command arbitration. wire[nBANK_MACHS-1:0] grant_row_r_lcl; output wire[nBANK_MACHS-1:0] grant_row_r; assign grant_row_r = grant_row_r_lcl; reg granted_row_r; always @(posedge clk) granted_row_r <= #TCQ granted_row_ns; wire sent_row_lcl = granted_row_r && ~block_grant_row; output wire sent_row; assign sent_row = sent_row_lcl; mig_7series_v1_9_round_robin_arb # (.WIDTH (nBANK_MACHS)) row_arb0 (.grant_ns (), .grant_r (grant_row_r_lcl[nBANK_MACHS-1:0]), .upd_last_master (sent_row_lcl), .current_master (grant_row_r_lcl[nBANK_MACHS-1:0]), .clk (clk), .rst (rst), .req (row_request), .disable_grant (1'b0)); output wire [nBANK_MACHS-1:0] sending_row; assign sending_row = grant_row_r_lcl & {nBANK_MACHS{~block_grant_row}}; // Precharge arbitration for 4:1 mode input [nBANK_MACHS-1:0] rts_pre; output wire[nBANK_MACHS-1:0] grant_pre_r; output wire [nBANK_MACHS-1:0] sending_pre; wire sent_pre_lcl; generate if((nCK_PER_CLK == 4) && (ADDR_CMD_MODE != "2T")) begin : pre_4_1_1T_arb reg granted_pre_r; wire[nBANK_MACHS-1:0] grant_pre_r_lcl; wire granted_pre_ns = |rts_pre; assign grant_pre_r = grant_pre_r_lcl; always @(posedge clk) granted_pre_r <= #TCQ granted_pre_ns; assign sent_pre_lcl = granted_pre_r; assign sending_pre = grant_pre_r_lcl; mig_7series_v1_9_round_robin_arb # (.WIDTH (nBANK_MACHS)) pre_arb0 (.grant_ns (), .grant_r (grant_pre_r_lcl[nBANK_MACHS-1:0]), .upd_last_master (sent_pre_lcl), .current_master (grant_pre_r_lcl[nBANK_MACHS-1:0]), .clk (clk), .rst (rst), .req (rts_pre), .disable_grant (1'b0)); end endgenerate `ifdef MC_SVA all_bank_machines_row_arb: cover property (@(posedge clk) (~rst && &rts_row)); `endif // Rank config arbitration. input [nBANK_MACHS-1:0] rtc; wire [nBANK_MACHS-1:0] grant_config_r_lcl; output wire [nBANK_MACHS-1:0] grant_config_r; assign grant_config_r = grant_config_r_lcl; wire upd_rnk_config_last_master; mig_7series_v1_9_round_robin_arb # (.WIDTH (nBANK_MACHS)) config_arb0 (.grant_ns (), .grant_r (grant_config_r_lcl[nBANK_MACHS-1:0]), .upd_last_master (upd_rnk_config_last_master), .current_master (grant_config_r_lcl[nBANK_MACHS-1:0]), .clk (clk), .rst (rst), .req (rtc[nBANK_MACHS-1:0]), .disable_grant (1'b0)); `ifdef MC_SVA all_bank_machines_config_arb: cover property (@(posedge clk) (~rst && &rtc)); `endif wire rnk_config_strobe_ns = ~rnk_config_strobe_r[0] && |rtc && ~granted_col_ns; always @(posedge clk) rnk_config_strobe_r[0] <= #TCQ rnk_config_strobe_ns; genvar i; generate for(i = 1; i < RNK2RNK_DLY_CLKS; i = i + 1) always @(posedge clk) rnk_config_strobe_r[i] <= #TCQ rnk_config_strobe_r[i-1]; endgenerate output wire rnk_config_strobe; assign rnk_config_strobe = rnk_config_strobe_r[0]; assign upd_rnk_config_last_master = rnk_config_strobe_r[0]; // Generate rnk_config_valid. reg rnk_config_valid_r_lcl; wire rnk_config_valid_ns; assign rnk_config_valid_ns = ~rst && (rnk_config_valid_r_lcl || rnk_config_strobe_ns); always @(posedge clk) rnk_config_valid_r_lcl <= #TCQ rnk_config_valid_ns; output wire rnk_config_valid_r; assign rnk_config_valid_r = rnk_config_valid_r_lcl; // Column address/command arbitration. wire [nBANK_MACHS-1:0] grant_col_r_lcl; output wire [nBANK_MACHS-1:0] grant_col_r; assign grant_col_r = grant_col_r_lcl; reg granted_col_r; always @(posedge clk) granted_col_r <= #TCQ granted_col_ns; wire sent_col_lcl; mig_7series_v1_9_round_robin_arb # (.WIDTH (nBANK_MACHS)) col_arb0 (.grant_ns (), .grant_r (grant_col_r_lcl[nBANK_MACHS-1:0]), .upd_last_master (sent_col_lcl), .current_master (grant_col_r_lcl[nBANK_MACHS-1:0]), .clk (clk), .rst (rst), .req (col_request), .disable_grant (1'b0)); `ifdef MC_SVA all_bank_machines_col_arb: cover property (@(posedge clk) (~rst && &rts_col)); `endif output wire [nBANK_MACHS-1:0] sending_col; assign sending_col = grant_col_r_lcl & {nBANK_MACHS{~block_grant_col}}; assign sent_col_lcl = granted_col_r && ~block_grant_col; reg sent_col_lcl_r = 1'b0; always @(posedge clk) sent_col_lcl_r <= #TCQ sent_col_lcl; output wire sent_col; assign sent_col = sent_col_lcl; output wire sent_col_r; assign sent_col_r = sent_col_lcl_r; // If we need early wr_data_addr because ECC is on, arbitrate // to see which bank machine might sent the next wr_data_addr; input [nBANK_MACHS-1:0] col_rdy_wr; output wire [nBANK_MACHS-1:0] grant_col_wr; generate if (EARLY_WR_DATA_ADDR == "OFF") begin : early_wr_addr_arb_off assign grant_col_wr = {nBANK_MACHS{1'b0}}; end else begin : early_wr_addr_arb_on wire [nBANK_MACHS-1:0] grant_col_wr_raw; mig_7series_v1_9_round_robin_arb # (.WIDTH (nBANK_MACHS)) col_arb0 (.grant_ns (grant_col_wr_raw), .grant_r (), .upd_last_master (sent_col_lcl), .current_master (grant_col_r_lcl[nBANK_MACHS-1:0]), .clk (clk), .rst (rst), .req (col_rdy_wr), .disable_grant (1'b0)); reg [nBANK_MACHS-1:0] grant_col_wr_r; wire [nBANK_MACHS-1:0] grant_col_wr_ns = granted_col_ns ? grant_col_wr_raw : grant_col_wr_r; always @(posedge clk) grant_col_wr_r <= #TCQ grant_col_wr_ns; assign grant_col_wr = grant_col_wr_ns; end // block: early_wr_addr_arb_on endgenerate output reg send_cmd0_row = 1'b0; output reg send_cmd0_col = 1'b0; output reg send_cmd1_row = 1'b0; output reg send_cmd1_col = 1'b0; output reg send_cmd2_row = 1'b0; output reg send_cmd2_col = 1'b0; output reg send_cmd2_pre = 1'b0; output reg send_cmd3_col = 1'b0; output reg cs_en0 = 1'b0; output reg cs_en1 = 1'b0; output reg cs_en2 = 1'b0; output reg cs_en3 = 1'b0; output wire [5:0] col_channel_offset; reg insert_maint_r1_lcl; always @(posedge clk) insert_maint_r1_lcl <= #TCQ insert_maint_r; output wire insert_maint_r1; assign insert_maint_r1 = insert_maint_r1_lcl; wire sent_row_or_maint = sent_row_lcl || insert_maint_r1_lcl; reg sent_row_or_maint_r = 1'b0; always @(posedge clk) sent_row_or_maint_r <= #TCQ sent_row_or_maint; generate case ({(nCK_PER_CLK == 4), (nCK_PER_CLK == 2), (ADDR_CMD_MODE == "2T")}) 3'b000 : begin : one_one_not2T end 3'b001 : begin : one_one_2T end 3'b010 : begin : two_one_not2T if(!(CWL % 2)) begin // Place column commands on slot 0 for even CWL always @(sent_col_lcl) begin cs_en0 = sent_col_lcl; send_cmd0_col = sent_col_lcl; end always @(sent_row_or_maint) begin cs_en1 = sent_row_or_maint; send_cmd1_row = sent_row_or_maint; end assign col_channel_offset = 0; end else begin // Place column commands on slot 1 for odd CWL always @(sent_row_or_maint) begin cs_en0 = sent_row_or_maint; send_cmd0_row = sent_row_or_maint; end always @(sent_col_lcl) begin cs_en1 = sent_col_lcl; send_cmd1_col = sent_col_lcl; end assign col_channel_offset = 1; end end 3'b011 : begin : two_one_2T if(!(CWL % 2)) begin // Place column commands on slot 1->0 for even CWL always @(sent_row_or_maint_r or sent_col_lcl_r) cs_en0 = sent_row_or_maint_r || sent_col_lcl_r; always @(sent_row_or_maint or sent_row_or_maint_r) begin send_cmd0_row = sent_row_or_maint_r; send_cmd1_row = sent_row_or_maint; end always @(sent_col_lcl or sent_col_lcl_r) begin send_cmd0_col = sent_col_lcl_r; send_cmd1_col = sent_col_lcl; end assign col_channel_offset = 0; end else begin // Place column commands on slot 0->1 for odd CWL always @(sent_col_lcl or sent_row_or_maint) cs_en1 = sent_row_or_maint || sent_col_lcl; always @(sent_row_or_maint) begin send_cmd0_row = sent_row_or_maint; send_cmd1_row = sent_row_or_maint; end always @(sent_col_lcl) begin send_cmd0_col = sent_col_lcl; send_cmd1_col = sent_col_lcl; end assign col_channel_offset = 1; end end 3'b100 : begin : four_one_not2T if(!(CWL % 2)) begin // Place column commands on slot 0 for even CWL always @(sent_col_lcl) begin cs_en0 = sent_col_lcl; send_cmd0_col = sent_col_lcl; end always @(sent_row_or_maint) begin cs_en1 = sent_row_or_maint; send_cmd1_row = sent_row_or_maint; end assign col_channel_offset = 0; end else begin // Place column commands on slot 1 for odd CWL always @(sent_row_or_maint) begin cs_en0 = sent_row_or_maint; send_cmd0_row = sent_row_or_maint; end always @(sent_col_lcl) begin cs_en1 = sent_col_lcl; send_cmd1_col = sent_col_lcl; end assign col_channel_offset = 1; end always @(sent_pre_lcl) begin cs_en2 = sent_pre_lcl; send_cmd2_pre = sent_pre_lcl; end end 3'b101 : begin : four_one_2T if(!(CWL % 2)) begin // Place column commands on slot 3->0 for even CWL always @(sent_col_lcl or sent_col_lcl_r) begin cs_en0 = sent_col_lcl_r; send_cmd0_col = sent_col_lcl_r; send_cmd3_col = sent_col_lcl; end always @(sent_row_or_maint) begin cs_en2 = sent_row_or_maint; send_cmd1_row = sent_row_or_maint; send_cmd2_row = sent_row_or_maint; end assign col_channel_offset = 0; end else begin // Place column commands on slot 2->3 for odd CWL always @(sent_row_or_maint) begin cs_en1 = sent_row_or_maint; send_cmd0_row = sent_row_or_maint; send_cmd1_row = sent_row_or_maint; end always @(sent_col_lcl) begin cs_en3 = sent_col_lcl; send_cmd2_col = sent_col_lcl; send_cmd3_col = sent_col_lcl; end assign col_channel_offset = 3; end end endcase endgenerate endmodule
/****************************************************************************** -- (c) Copyright 2006 - 2013 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -- ***************************************************************************** * * Filename: blk_mem_gen_v8_3_3.v * * Description: * This file is the Verilog behvarial model for the * Block Memory Generator Core. * ***************************************************************************** * Author: Xilinx * * History: Jan 11, 2006 Initial revision * Jun 11, 2007 Added independent register stages for * Port A and Port B (IP1_Jm/v2.5) * Aug 28, 2007 Added mux pipeline stages feature (IP2_Jm/v2.6) * Mar 13, 2008 Behavioral model optimizations * April 07, 2009 : Added support for Spartan-6 and Virtex-6 * features, including the following: * (i) error injection, detection and/or correction * (ii) reset priority * (iii) special reset behavior * *****************************************************************************/ `timescale 1ps/1ps module STATE_LOGIC_v8_3 (O, I0, I1, I2, I3, I4, I5); parameter INIT = 64'h0000000000000000; input I0, I1, I2, I3, I4, I5; output O; reg O; reg tmp; always @( I5 or I4 or I3 or I2 or I1 or I0 ) begin tmp = I0 ^ I1 ^ I2 ^ I3 ^ I4 ^ I5; if ( tmp == 0 || tmp == 1) O = INIT[{I5, I4, I3, I2, I1, I0}]; end endmodule module beh_vlog_muxf7_v8_3 (O, I0, I1, S); output O; reg O; input I0, I1, S; always @(I0 or I1 or S) if (S) O = I1; else O = I0; endmodule module beh_vlog_ff_clr_v8_3 (Q, C, CLR, D); parameter INIT = 0; localparam FLOP_DELAY = 100; output Q; input C, CLR, D; reg Q; initial Q= 1'b0; always @(posedge C ) if (CLR) Q<= 1'b0; else Q<= #FLOP_DELAY D; endmodule module beh_vlog_ff_pre_v8_3 (Q, C, D, PRE); parameter INIT = 0; localparam FLOP_DELAY = 100; output Q; input C, D, PRE; reg Q; initial Q= 1'b0; always @(posedge C ) if (PRE) Q <= 1'b1; else Q <= #FLOP_DELAY D; endmodule module beh_vlog_ff_ce_clr_v8_3 (Q, C, CE, CLR, D); parameter INIT = 0; localparam FLOP_DELAY = 100; output Q; input C, CE, CLR, D; reg Q; initial Q= 1'b0; always @(posedge C ) if (CLR) Q <= 1'b0; else if (CE) Q <= #FLOP_DELAY D; endmodule module write_netlist_v8_3 #( parameter C_AXI_TYPE = 0 ) ( S_ACLK, S_ARESETN, S_AXI_AWVALID, S_AXI_WVALID, S_AXI_BREADY, w_last_c, bready_timeout_c, aw_ready_r, S_AXI_WREADY, S_AXI_BVALID, S_AXI_WR_EN, addr_en_c, incr_addr_c, bvalid_c ); input S_ACLK; input S_ARESETN; input S_AXI_AWVALID; input S_AXI_WVALID; input S_AXI_BREADY; input w_last_c; input bready_timeout_c; output aw_ready_r; output S_AXI_WREADY; output S_AXI_BVALID; output S_AXI_WR_EN; output addr_en_c; output incr_addr_c; output bvalid_c; //------------------------------------------------------------------------- //AXI LITE //------------------------------------------------------------------------- generate if (C_AXI_TYPE == 0 ) begin : gbeh_axi_lite_sm wire w_ready_r_7; wire w_ready_c; wire aw_ready_c; wire NlwRenamedSignal_bvalid_c; wire NlwRenamedSignal_incr_addr_c; wire present_state_FSM_FFd3_13; wire present_state_FSM_FFd2_14; wire present_state_FSM_FFd1_15; wire present_state_FSM_FFd4_16; wire present_state_FSM_FFd4_In; wire present_state_FSM_FFd3_In; wire present_state_FSM_FFd2_In; wire present_state_FSM_FFd1_In; wire present_state_FSM_FFd4_In1_21; wire [0:0] Mmux_aw_ready_c ; begin assign S_AXI_WREADY = w_ready_r_7, S_AXI_BVALID = NlwRenamedSignal_incr_addr_c, S_AXI_WR_EN = NlwRenamedSignal_bvalid_c, incr_addr_c = NlwRenamedSignal_incr_addr_c, bvalid_c = NlwRenamedSignal_bvalid_c; assign NlwRenamedSignal_incr_addr_c = 1'b0; beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) aw_ready_r_2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( aw_ready_c), .Q ( aw_ready_r) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) w_ready_r ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( w_ready_c), .Q ( w_ready_r_7) ); beh_vlog_ff_pre_v8_3 #( .INIT (1'b1)) present_state_FSM_FFd4 ( .C ( S_ACLK), .D ( present_state_FSM_FFd4_In), .PRE ( S_ARESETN), .Q ( present_state_FSM_FFd4_16) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd3 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd3_In), .Q ( present_state_FSM_FFd3_13) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd2_In), .Q ( present_state_FSM_FFd2_14) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd1 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd1_In), .Q ( present_state_FSM_FFd1_15) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000055554440)) present_state_FSM_FFd3_In1 ( .I0 ( S_AXI_WVALID), .I1 ( S_AXI_AWVALID), .I2 ( present_state_FSM_FFd2_14), .I3 ( present_state_FSM_FFd4_16), .I4 ( present_state_FSM_FFd3_13), .I5 (1'b0), .O ( present_state_FSM_FFd3_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000088880800)) present_state_FSM_FFd2_In1 ( .I0 ( S_AXI_AWVALID), .I1 ( S_AXI_WVALID), .I2 ( bready_timeout_c), .I3 ( present_state_FSM_FFd2_14), .I4 ( present_state_FSM_FFd4_16), .I5 (1'b0), .O ( present_state_FSM_FFd2_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000AAAA2000)) Mmux_addr_en_c_0_1 ( .I0 ( S_AXI_AWVALID), .I1 ( bready_timeout_c), .I2 ( present_state_FSM_FFd2_14), .I3 ( S_AXI_WVALID), .I4 ( present_state_FSM_FFd4_16), .I5 (1'b0), .O ( addr_en_c) ); STATE_LOGIC_v8_3 #( .INIT (64'hF5F07570F5F05500)) Mmux_w_ready_c_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd3_13), .I4 ( present_state_FSM_FFd4_16), .I5 ( present_state_FSM_FFd2_14), .O ( w_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h88808880FFFF8880)) present_state_FSM_FFd1_In1 ( .I0 ( S_AXI_WVALID), .I1 ( bready_timeout_c), .I2 ( present_state_FSM_FFd3_13), .I3 ( present_state_FSM_FFd2_14), .I4 ( present_state_FSM_FFd1_15), .I5 ( S_AXI_BREADY), .O ( present_state_FSM_FFd1_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000A8)) Mmux_S_AXI_WR_EN_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( present_state_FSM_FFd2_14), .I2 ( present_state_FSM_FFd3_13), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( NlwRenamedSignal_bvalid_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h2F0F27072F0F2200)) present_state_FSM_FFd4_In1 ( .I0 ( S_AXI_WVALID), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd3_13), .I4 ( present_state_FSM_FFd4_16), .I5 ( present_state_FSM_FFd2_14), .O ( present_state_FSM_FFd4_In1_21) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000F8)) present_state_FSM_FFd4_In2 ( .I0 ( present_state_FSM_FFd1_15), .I1 ( S_AXI_BREADY), .I2 ( present_state_FSM_FFd4_In1_21), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( present_state_FSM_FFd4_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h7535753575305500)) Mmux_aw_ready_c_0_1 ( .I0 ( S_AXI_AWVALID), .I1 ( bready_timeout_c), .I2 ( S_AXI_WVALID), .I3 ( present_state_FSM_FFd4_16), .I4 ( present_state_FSM_FFd3_13), .I5 ( present_state_FSM_FFd2_14), .O ( Mmux_aw_ready_c[0]) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000F8)) Mmux_aw_ready_c_0_2 ( .I0 ( present_state_FSM_FFd1_15), .I1 ( S_AXI_BREADY), .I2 ( Mmux_aw_ready_c[0]), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( aw_ready_c) ); end end endgenerate //--------------------------------------------------------------------- // AXI FULL //--------------------------------------------------------------------- generate if (C_AXI_TYPE == 1 ) begin : gbeh_axi_full_sm wire w_ready_r_8; wire w_ready_c; wire aw_ready_c; wire NlwRenamedSig_OI_bvalid_c; wire present_state_FSM_FFd1_16; wire present_state_FSM_FFd4_17; wire present_state_FSM_FFd3_18; wire present_state_FSM_FFd2_19; wire present_state_FSM_FFd4_In; wire present_state_FSM_FFd3_In; wire present_state_FSM_FFd2_In; wire present_state_FSM_FFd1_In; wire present_state_FSM_FFd2_In1_24; wire present_state_FSM_FFd4_In1_25; wire N2; wire N4; begin assign S_AXI_WREADY = w_ready_r_8, bvalid_c = NlwRenamedSig_OI_bvalid_c, S_AXI_BVALID = 1'b0; beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) aw_ready_r_2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( aw_ready_c), .Q ( aw_ready_r) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) w_ready_r ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( w_ready_c), .Q ( w_ready_r_8) ); beh_vlog_ff_pre_v8_3 #( .INIT (1'b1)) present_state_FSM_FFd4 ( .C ( S_ACLK), .D ( present_state_FSM_FFd4_In), .PRE ( S_ARESETN), .Q ( present_state_FSM_FFd4_17) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd3 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd3_In), .Q ( present_state_FSM_FFd3_18) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd2_In), .Q ( present_state_FSM_FFd2_19) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd1 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd1_In), .Q ( present_state_FSM_FFd1_16) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000005540)) present_state_FSM_FFd3_In1 ( .I0 ( S_AXI_WVALID), .I1 ( present_state_FSM_FFd4_17), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( present_state_FSM_FFd3_In) ); STATE_LOGIC_v8_3 #( .INIT (64'hBF3FBB33AF0FAA00)) Mmux_aw_ready_c_0_2 ( .I0 ( S_AXI_BREADY), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd1_16), .I4 ( present_state_FSM_FFd4_17), .I5 ( NlwRenamedSig_OI_bvalid_c), .O ( aw_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'hAAAAAAAA20000000)) Mmux_addr_en_c_0_1 ( .I0 ( S_AXI_AWVALID), .I1 ( bready_timeout_c), .I2 ( present_state_FSM_FFd2_19), .I3 ( S_AXI_WVALID), .I4 ( w_last_c), .I5 ( present_state_FSM_FFd4_17), .O ( addr_en_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000A8)) Mmux_S_AXI_WR_EN_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( present_state_FSM_FFd2_19), .I2 ( present_state_FSM_FFd3_18), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( S_AXI_WR_EN) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000002220)) Mmux_incr_addr_c_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( w_last_c), .I2 ( present_state_FSM_FFd2_19), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( incr_addr_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000008880)) Mmux_aw_ready_c_0_11 ( .I0 ( S_AXI_WVALID), .I1 ( w_last_c), .I2 ( present_state_FSM_FFd2_19), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( NlwRenamedSig_OI_bvalid_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000000000D5C0)) present_state_FSM_FFd2_In1 ( .I0 ( w_last_c), .I1 ( S_AXI_AWVALID), .I2 ( present_state_FSM_FFd4_17), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( present_state_FSM_FFd2_In1_24) ); STATE_LOGIC_v8_3 #( .INIT (64'hFFFFAAAA08AAAAAA)) present_state_FSM_FFd2_In2 ( .I0 ( present_state_FSM_FFd2_19), .I1 ( S_AXI_AWVALID), .I2 ( bready_timeout_c), .I3 ( w_last_c), .I4 ( S_AXI_WVALID), .I5 ( present_state_FSM_FFd2_In1_24), .O ( present_state_FSM_FFd2_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h00C0004000C00000)) present_state_FSM_FFd4_In1 ( .I0 ( S_AXI_AWVALID), .I1 ( w_last_c), .I2 ( S_AXI_WVALID), .I3 ( bready_timeout_c), .I4 ( present_state_FSM_FFd3_18), .I5 ( present_state_FSM_FFd2_19), .O ( present_state_FSM_FFd4_In1_25) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000FFFF88F8)) present_state_FSM_FFd4_In2 ( .I0 ( present_state_FSM_FFd1_16), .I1 ( S_AXI_BREADY), .I2 ( present_state_FSM_FFd4_17), .I3 ( S_AXI_AWVALID), .I4 ( present_state_FSM_FFd4_In1_25), .I5 (1'b0), .O ( present_state_FSM_FFd4_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000007)) Mmux_w_ready_c_0_SW0 ( .I0 ( w_last_c), .I1 ( S_AXI_WVALID), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( N2) ); STATE_LOGIC_v8_3 #( .INIT (64'hFABAFABAFAAAF000)) Mmux_w_ready_c_0_Q ( .I0 ( N2), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd4_17), .I4 ( present_state_FSM_FFd3_18), .I5 ( present_state_FSM_FFd2_19), .O ( w_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000008)) Mmux_aw_ready_c_0_11_SW0 ( .I0 ( bready_timeout_c), .I1 ( S_AXI_WVALID), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( N4) ); STATE_LOGIC_v8_3 #( .INIT (64'h88808880FFFF8880)) present_state_FSM_FFd1_In1 ( .I0 ( w_last_c), .I1 ( N4), .I2 ( present_state_FSM_FFd2_19), .I3 ( present_state_FSM_FFd3_18), .I4 ( present_state_FSM_FFd1_16), .I5 ( S_AXI_BREADY), .O ( present_state_FSM_FFd1_In) ); end end endgenerate endmodule module read_netlist_v8_3 #( parameter C_AXI_TYPE = 1, parameter C_ADDRB_WIDTH = 12 ) ( S_AXI_R_LAST_INT, S_ACLK, S_ARESETN, S_AXI_ARVALID, S_AXI_RREADY,S_AXI_INCR_ADDR,S_AXI_ADDR_EN, S_AXI_SINGLE_TRANS,S_AXI_MUX_SEL, S_AXI_R_LAST, S_AXI_ARREADY, S_AXI_RLAST, S_AXI_RVALID, S_AXI_RD_EN, S_AXI_ARLEN); input S_AXI_R_LAST_INT; input S_ACLK; input S_ARESETN; input S_AXI_ARVALID; input S_AXI_RREADY; output S_AXI_INCR_ADDR; output S_AXI_ADDR_EN; output S_AXI_SINGLE_TRANS; output S_AXI_MUX_SEL; output S_AXI_R_LAST; output S_AXI_ARREADY; output S_AXI_RLAST; output S_AXI_RVALID; output S_AXI_RD_EN; input [7:0] S_AXI_ARLEN; wire present_state_FSM_FFd1_13 ; wire present_state_FSM_FFd2_14 ; wire gaxi_full_sm_outstanding_read_r_15 ; wire gaxi_full_sm_ar_ready_r_16 ; wire gaxi_full_sm_r_last_r_17 ; wire NlwRenamedSig_OI_gaxi_full_sm_r_valid_r ; wire gaxi_full_sm_r_valid_c ; wire S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o ; wire gaxi_full_sm_ar_ready_c ; wire gaxi_full_sm_outstanding_read_c ; wire NlwRenamedSig_OI_S_AXI_R_LAST ; wire S_AXI_ARLEN_7_GND_8_o_equal_1_o ; wire present_state_FSM_FFd2_In ; wire present_state_FSM_FFd1_In ; wire Mmux_S_AXI_R_LAST13 ; wire N01 ; wire N2 ; wire Mmux_gaxi_full_sm_ar_ready_c11 ; wire N4 ; wire N8 ; wire N9 ; wire N10 ; wire N11 ; wire N12 ; wire N13 ; assign S_AXI_R_LAST = NlwRenamedSig_OI_S_AXI_R_LAST, S_AXI_ARREADY = gaxi_full_sm_ar_ready_r_16, S_AXI_RLAST = gaxi_full_sm_r_last_r_17, S_AXI_RVALID = NlwRenamedSig_OI_gaxi_full_sm_r_valid_r; beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) gaxi_full_sm_outstanding_read_r ( .C (S_ACLK), .CLR(S_ARESETN), .D(gaxi_full_sm_outstanding_read_c), .Q(gaxi_full_sm_outstanding_read_r_15) ); beh_vlog_ff_ce_clr_v8_3 #( .INIT (1'b0)) gaxi_full_sm_r_valid_r ( .C (S_ACLK), .CE (S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .CLR (S_ARESETN), .D (gaxi_full_sm_r_valid_c), .Q (NlwRenamedSig_OI_gaxi_full_sm_r_valid_r) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) gaxi_full_sm_ar_ready_r ( .C (S_ACLK), .CLR (S_ARESETN), .D (gaxi_full_sm_ar_ready_c), .Q (gaxi_full_sm_ar_ready_r_16) ); beh_vlog_ff_ce_clr_v8_3 #( .INIT(1'b0)) gaxi_full_sm_r_last_r ( .C (S_ACLK), .CE (S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .CLR (S_ARESETN), .D (NlwRenamedSig_OI_S_AXI_R_LAST), .Q (gaxi_full_sm_r_last_r_17) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd2_In), .Q ( present_state_FSM_FFd2_14) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd1 ( .C (S_ACLK), .CLR (S_ARESETN), .D (present_state_FSM_FFd1_In), .Q (present_state_FSM_FFd1_13) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000000000000B)) S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o1 ( .I0 ( S_AXI_RREADY), .I1 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O (S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000008)) Mmux_S_AXI_SINGLE_TRANS11 ( .I0 (S_AXI_ARVALID), .I1 (S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O (S_AXI_SINGLE_TRANS) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000004)) Mmux_S_AXI_ADDR_EN11 ( .I0 (present_state_FSM_FFd1_13), .I1 (S_AXI_ARVALID), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O (S_AXI_ADDR_EN) ); STATE_LOGIC_v8_3 #( .INIT (64'hECEE2022EEEE2022)) present_state_FSM_FFd2_In1 ( .I0 ( S_AXI_ARVALID), .I1 ( present_state_FSM_FFd1_13), .I2 ( S_AXI_RREADY), .I3 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I4 ( present_state_FSM_FFd2_14), .I5 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .O ( present_state_FSM_FFd2_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000044440444)) Mmux_S_AXI_R_LAST131 ( .I0 ( present_state_FSM_FFd1_13), .I1 ( S_AXI_ARVALID), .I2 ( present_state_FSM_FFd2_14), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( S_AXI_RREADY), .I5 (1'b0), .O ( Mmux_S_AXI_R_LAST13) ); STATE_LOGIC_v8_3 #( .INIT (64'h4000FFFF40004000)) Mmux_S_AXI_INCR_ADDR11 ( .I0 ( S_AXI_R_LAST_INT), .I1 ( S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .I2 ( present_state_FSM_FFd2_14), .I3 ( present_state_FSM_FFd1_13), .I4 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I5 ( Mmux_S_AXI_R_LAST13), .O ( S_AXI_INCR_ADDR) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000FE)) S_AXI_ARLEN_7_GND_8_o_equal_1_o_7_SW0 ( .I0 ( S_AXI_ARLEN[2]), .I1 ( S_AXI_ARLEN[1]), .I2 ( S_AXI_ARLEN[0]), .I3 ( 1'b0), .I4 ( 1'b0), .I5 ( 1'b0), .O ( N01) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000001)) S_AXI_ARLEN_7_GND_8_o_equal_1_o_7_Q ( .I0 ( S_AXI_ARLEN[7]), .I1 ( S_AXI_ARLEN[6]), .I2 ( S_AXI_ARLEN[5]), .I3 ( S_AXI_ARLEN[4]), .I4 ( S_AXI_ARLEN[3]), .I5 ( N01), .O ( S_AXI_ARLEN_7_GND_8_o_equal_1_o) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000007)) Mmux_gaxi_full_sm_outstanding_read_c1_SW0 ( .I0 ( S_AXI_ARVALID), .I1 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I2 ( 1'b0), .I3 ( 1'b0), .I4 ( 1'b0), .I5 ( 1'b0), .O ( N2) ); STATE_LOGIC_v8_3 #( .INIT (64'h0020000002200200)) Mmux_gaxi_full_sm_outstanding_read_c1 ( .I0 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I1 ( S_AXI_RREADY), .I2 ( present_state_FSM_FFd1_13), .I3 ( present_state_FSM_FFd2_14), .I4 ( gaxi_full_sm_outstanding_read_r_15), .I5 ( N2), .O ( gaxi_full_sm_outstanding_read_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000004555)) Mmux_gaxi_full_sm_ar_ready_c12 ( .I0 ( S_AXI_ARVALID), .I1 ( S_AXI_RREADY), .I2 ( present_state_FSM_FFd2_14), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( 1'b0), .I5 ( 1'b0), .O ( Mmux_gaxi_full_sm_ar_ready_c11) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000EF)) Mmux_S_AXI_R_LAST11_SW0 ( .I0 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I1 ( S_AXI_RREADY), .I2 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I3 ( 1'b0), .I4 ( 1'b0), .I5 ( 1'b0), .O ( N4) ); STATE_LOGIC_v8_3 #( .INIT (64'hFCAAFC0A00AA000A)) Mmux_S_AXI_R_LAST11 ( .I0 ( S_AXI_ARVALID), .I1 ( gaxi_full_sm_outstanding_read_r_15), .I2 ( present_state_FSM_FFd2_14), .I3 ( present_state_FSM_FFd1_13), .I4 ( N4), .I5 ( S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .O ( gaxi_full_sm_r_valid_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000AAAAAA08)) S_AXI_MUX_SEL1 ( .I0 (present_state_FSM_FFd1_13), .I1 (NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I2 (S_AXI_RREADY), .I3 (present_state_FSM_FFd2_14), .I4 (gaxi_full_sm_outstanding_read_r_15), .I5 (1'b0), .O (S_AXI_MUX_SEL) ); STATE_LOGIC_v8_3 #( .INIT (64'hF3F3F755A2A2A200)) Mmux_S_AXI_RD_EN11 ( .I0 ( present_state_FSM_FFd1_13), .I1 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I2 ( S_AXI_RREADY), .I3 ( gaxi_full_sm_outstanding_read_r_15), .I4 ( present_state_FSM_FFd2_14), .I5 ( S_AXI_ARVALID), .O ( S_AXI_RD_EN) ); beh_vlog_muxf7_v8_3 present_state_FSM_FFd1_In3 ( .I0 ( N8), .I1 ( N9), .S ( present_state_FSM_FFd1_13), .O ( present_state_FSM_FFd1_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000005410F4F0)) present_state_FSM_FFd1_In3_F ( .I0 ( S_AXI_RREADY), .I1 ( present_state_FSM_FFd2_14), .I2 ( S_AXI_ARVALID), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I5 ( 1'b0), .O ( N8) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000072FF7272)) present_state_FSM_FFd1_In3_G ( .I0 ( present_state_FSM_FFd2_14), .I1 ( S_AXI_R_LAST_INT), .I2 ( gaxi_full_sm_outstanding_read_r_15), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N9) ); beh_vlog_muxf7_v8_3 Mmux_gaxi_full_sm_ar_ready_c14 ( .I0 ( N10), .I1 ( N11), .S ( present_state_FSM_FFd1_13), .O ( gaxi_full_sm_ar_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000FFFF88A8)) Mmux_gaxi_full_sm_ar_ready_c14_F ( .I0 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I1 ( S_AXI_RREADY), .I2 ( present_state_FSM_FFd2_14), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( Mmux_gaxi_full_sm_ar_ready_c11), .I5 ( 1'b0), .O ( N10) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000008D008D8D)) Mmux_gaxi_full_sm_ar_ready_c14_G ( .I0 ( present_state_FSM_FFd2_14), .I1 ( S_AXI_R_LAST_INT), .I2 ( gaxi_full_sm_outstanding_read_r_15), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N11) ); beh_vlog_muxf7_v8_3 Mmux_S_AXI_R_LAST1 ( .I0 ( N12), .I1 ( N13), .S ( present_state_FSM_FFd1_13), .O ( NlwRenamedSig_OI_S_AXI_R_LAST) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000088088888)) Mmux_S_AXI_R_LAST1_F ( .I0 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I1 ( S_AXI_ARVALID), .I2 ( present_state_FSM_FFd2_14), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N12) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000E400E4E4)) Mmux_S_AXI_R_LAST1_G ( .I0 ( present_state_FSM_FFd2_14), .I1 ( gaxi_full_sm_outstanding_read_r_15), .I2 ( S_AXI_R_LAST_INT), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N13) ); endmodule module blk_mem_axi_write_wrapper_beh_v8_3 # ( // AXI Interface related parameters start here parameter C_INTERFACE_TYPE = 0, // 0: Native Interface; 1: AXI Interface parameter C_AXI_TYPE = 0, // 0: AXI Lite; 1: AXI Full; parameter C_AXI_SLAVE_TYPE = 0, // 0: MEMORY SLAVE; 1: PERIPHERAL SLAVE; parameter C_MEMORY_TYPE = 0, // 0: SP-RAM, 1: SDP-RAM; 2: TDP-RAM; 3: DP-ROM; parameter C_WRITE_DEPTH_A = 0, parameter C_AXI_AWADDR_WIDTH = 32, parameter C_ADDRA_WIDTH = 12, parameter C_AXI_WDATA_WIDTH = 32, parameter C_HAS_AXI_ID = 0, parameter C_AXI_ID_WIDTH = 4, // AXI OUTSTANDING WRITES parameter C_AXI_OS_WR = 2 ) ( // AXI Global Signals input S_ACLK, input S_ARESETN, // AXI Full/Lite Slave Write Channel (write side) input [C_AXI_ID_WIDTH-1:0] S_AXI_AWID, input [C_AXI_AWADDR_WIDTH-1:0] S_AXI_AWADDR, input [8-1:0] S_AXI_AWLEN, input [2:0] S_AXI_AWSIZE, input [1:0] S_AXI_AWBURST, input S_AXI_AWVALID, output S_AXI_AWREADY, input S_AXI_WVALID, output S_AXI_WREADY, output reg [C_AXI_ID_WIDTH-1:0] S_AXI_BID = 0, output S_AXI_BVALID, input S_AXI_BREADY, // Signals for BMG interface output [C_ADDRA_WIDTH-1:0] S_AXI_AWADDR_OUT, output S_AXI_WR_EN ); localparam FLOP_DELAY = 100; // 100 ps localparam C_RANGE = ((C_AXI_WDATA_WIDTH == 8)?0: ((C_AXI_WDATA_WIDTH==16)?1: ((C_AXI_WDATA_WIDTH==32)?2: ((C_AXI_WDATA_WIDTH==64)?3: ((C_AXI_WDATA_WIDTH==128)?4: ((C_AXI_WDATA_WIDTH==256)?5:0)))))); wire bvalid_c ; reg bready_timeout_c = 0; wire [1:0] bvalid_rd_cnt_c; reg bvalid_r = 0; reg [2:0] bvalid_count_r = 0; reg [((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)? C_AXI_AWADDR_WIDTH:C_ADDRA_WIDTH)-1:0] awaddr_reg = 0; reg [1:0] bvalid_wr_cnt_r = 0; reg [1:0] bvalid_rd_cnt_r = 0; wire w_last_c ; wire addr_en_c ; wire incr_addr_c ; wire aw_ready_r ; wire dec_alen_c ; reg bvalid_d1_c = 0; reg [7:0] awlen_cntr_r = 0; reg [7:0] awlen_int = 0; reg [1:0] awburst_int = 0; integer total_bytes = 0; integer wrap_boundary = 0; integer wrap_base_addr = 0; integer num_of_bytes_c = 0; integer num_of_bytes_r = 0; // Array to store BIDs reg [C_AXI_ID_WIDTH-1:0] axi_bid_array[3:0] ; wire S_AXI_BVALID_axi_wr_fsm; //------------------------------------- //AXI WRITE FSM COMPONENT INSTANTIATION //------------------------------------- write_netlist_v8_3 #(.C_AXI_TYPE(C_AXI_TYPE)) axi_wr_fsm ( .S_ACLK(S_ACLK), .S_ARESETN(S_ARESETN), .S_AXI_AWVALID(S_AXI_AWVALID), .aw_ready_r(aw_ready_r), .S_AXI_WVALID(S_AXI_WVALID), .S_AXI_WREADY(S_AXI_WREADY), .S_AXI_BREADY(S_AXI_BREADY), .S_AXI_WR_EN(S_AXI_WR_EN), .w_last_c(w_last_c), .bready_timeout_c(bready_timeout_c), .addr_en_c(addr_en_c), .incr_addr_c(incr_addr_c), .bvalid_c(bvalid_c), .S_AXI_BVALID (S_AXI_BVALID_axi_wr_fsm) ); //Wrap Address boundary calculation always@(*) begin num_of_bytes_c = 2**((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_AWSIZE:0); total_bytes = (num_of_bytes_r)*(awlen_int+1); wrap_base_addr = ((awaddr_reg)/((total_bytes==0)?1:total_bytes))*(total_bytes); wrap_boundary = wrap_base_addr+total_bytes; end //------------------------------------------------------------------------- // BMG address generation //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin awaddr_reg <= 0; num_of_bytes_r <= 0; awburst_int <= 0; end else begin if (addr_en_c == 1'b1) begin awaddr_reg <= #FLOP_DELAY S_AXI_AWADDR ; num_of_bytes_r <= num_of_bytes_c; awburst_int <= ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_AWBURST:2'b01); end else if (incr_addr_c == 1'b1) begin if (awburst_int == 2'b10) begin if(awaddr_reg == (wrap_boundary-num_of_bytes_r)) begin awaddr_reg <= wrap_base_addr; end else begin awaddr_reg <= awaddr_reg + num_of_bytes_r; end end else if (awburst_int == 2'b01 || awburst_int == 2'b11) begin awaddr_reg <= awaddr_reg + num_of_bytes_r; end end end end assign S_AXI_AWADDR_OUT = ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)? awaddr_reg[C_AXI_AWADDR_WIDTH-1:C_RANGE]:awaddr_reg); //------------------------------------------------------------------------- // AXI wlast generation //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin awlen_cntr_r <= 0; awlen_int <= 0; end else begin if (addr_en_c == 1'b1) begin awlen_int <= #FLOP_DELAY (C_AXI_TYPE == 0?0:S_AXI_AWLEN) ; awlen_cntr_r <= #FLOP_DELAY (C_AXI_TYPE == 0?0:S_AXI_AWLEN) ; end else if (dec_alen_c == 1'b1) begin awlen_cntr_r <= #FLOP_DELAY awlen_cntr_r - 1 ; end end end assign w_last_c = (awlen_cntr_r == 0 && S_AXI_WVALID == 1'b1)?1'b1:1'b0; assign dec_alen_c = (incr_addr_c | w_last_c); //------------------------------------------------------------------------- // Generation of bvalid counter for outstanding transactions //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_count_r <= 0; end else begin // bvalid_count_r generation if (bvalid_c == 1'b1 && bvalid_r == 1'b1 && S_AXI_BREADY == 1'b1) begin bvalid_count_r <= #FLOP_DELAY bvalid_count_r ; end else if (bvalid_c == 1'b1) begin bvalid_count_r <= #FLOP_DELAY bvalid_count_r + 1 ; end else if (bvalid_r == 1'b1 && S_AXI_BREADY == 1'b1 && bvalid_count_r != 0) begin bvalid_count_r <= #FLOP_DELAY bvalid_count_r - 1 ; end end end //------------------------------------------------------------------------- // Generation of bvalid when BID is used //------------------------------------------------------------------------- generate if (C_HAS_AXI_ID == 1) begin:gaxi_bvalid_id_r always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_r <= 0; bvalid_d1_c <= 0; end else begin // Delay the generation o bvalid_r for generation for BID bvalid_d1_c <= bvalid_c; //external bvalid signal generation if (bvalid_d1_c == 1'b1) begin bvalid_r <= #FLOP_DELAY 1'b1 ; end else if (bvalid_count_r <= 1 && S_AXI_BREADY == 1'b1) begin bvalid_r <= #FLOP_DELAY 0 ; end end end end endgenerate //------------------------------------------------------------------------- // Generation of bvalid when BID is not used //------------------------------------------------------------------------- generate if(C_HAS_AXI_ID == 0) begin:gaxi_bvalid_noid_r always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_r <= 0; end else begin //external bvalid signal generation if (bvalid_c == 1'b1) begin bvalid_r <= #FLOP_DELAY 1'b1 ; end else if (bvalid_count_r <= 1 && S_AXI_BREADY == 1'b1) begin bvalid_r <= #FLOP_DELAY 0 ; end end end end endgenerate //------------------------------------------------------------------------- // Generation of Bready timeout //------------------------------------------------------------------------- always @(bvalid_count_r) begin // bready_timeout_c generation if(bvalid_count_r == C_AXI_OS_WR-1) begin bready_timeout_c <= 1'b1; end else begin bready_timeout_c <= 1'b0; end end //------------------------------------------------------------------------- // Generation of BID //------------------------------------------------------------------------- generate if(C_HAS_AXI_ID == 1) begin:gaxi_bid_gen always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_wr_cnt_r <= 0; bvalid_rd_cnt_r <= 0; end else begin // STORE AWID IN AN ARRAY if(bvalid_c == 1'b1) begin bvalid_wr_cnt_r <= bvalid_wr_cnt_r + 1; end // generate BID FROM AWID ARRAY bvalid_rd_cnt_r <= #FLOP_DELAY bvalid_rd_cnt_c ; S_AXI_BID <= axi_bid_array[bvalid_rd_cnt_c]; end end assign bvalid_rd_cnt_c = (bvalid_r == 1'b1 && S_AXI_BREADY == 1'b1)?bvalid_rd_cnt_r+1:bvalid_rd_cnt_r; //------------------------------------------------------------------------- // Storing AWID for generation of BID //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if(S_ARESETN == 1'b1) begin axi_bid_array[0] = 0; axi_bid_array[1] = 0; axi_bid_array[2] = 0; axi_bid_array[3] = 0; end else if(aw_ready_r == 1'b1 && S_AXI_AWVALID == 1'b1) begin axi_bid_array[bvalid_wr_cnt_r] <= S_AXI_AWID; end end end endgenerate assign S_AXI_BVALID = bvalid_r; assign S_AXI_AWREADY = aw_ready_r; endmodule module blk_mem_axi_read_wrapper_beh_v8_3 # ( //// AXI Interface related parameters start here parameter C_INTERFACE_TYPE = 0, parameter C_AXI_TYPE = 0, parameter C_AXI_SLAVE_TYPE = 0, parameter C_MEMORY_TYPE = 0, parameter C_WRITE_WIDTH_A = 4, parameter C_WRITE_DEPTH_A = 32, parameter C_ADDRA_WIDTH = 12, parameter C_AXI_PIPELINE_STAGES = 0, parameter C_AXI_ARADDR_WIDTH = 12, parameter C_HAS_AXI_ID = 0, parameter C_AXI_ID_WIDTH = 4, parameter C_ADDRB_WIDTH = 12 ) ( //// AXI Global Signals input S_ACLK, input S_ARESETN, //// AXI Full/Lite Slave Read (Read side) input [C_AXI_ARADDR_WIDTH-1:0] S_AXI_ARADDR, input [7:0] S_AXI_ARLEN, input [2:0] S_AXI_ARSIZE, input [1:0] S_AXI_ARBURST, input S_AXI_ARVALID, output S_AXI_ARREADY, output S_AXI_RLAST, output S_AXI_RVALID, input S_AXI_RREADY, input [C_AXI_ID_WIDTH-1:0] S_AXI_ARID, output reg [C_AXI_ID_WIDTH-1:0] S_AXI_RID = 0, //// AXI Full/Lite Read Address Signals to BRAM output [C_ADDRB_WIDTH-1:0] S_AXI_ARADDR_OUT, output S_AXI_RD_EN ); localparam FLOP_DELAY = 100; // 100 ps localparam C_RANGE = ((C_WRITE_WIDTH_A == 8)?0: ((C_WRITE_WIDTH_A==16)?1: ((C_WRITE_WIDTH_A==32)?2: ((C_WRITE_WIDTH_A==64)?3: ((C_WRITE_WIDTH_A==128)?4: ((C_WRITE_WIDTH_A==256)?5:0)))))); reg [C_AXI_ID_WIDTH-1:0] ar_id_r=0; wire addr_en_c; wire rd_en_c; wire incr_addr_c; wire single_trans_c; wire dec_alen_c; wire mux_sel_c; wire r_last_c; wire r_last_int_c; wire [C_ADDRB_WIDTH-1 : 0] araddr_out; reg [7:0] arlen_int_r=0; reg [7:0] arlen_cntr=8'h01; reg [1:0] arburst_int_c=0; reg [1:0] arburst_int_r=0; reg [((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)? C_AXI_ARADDR_WIDTH:C_ADDRA_WIDTH)-1:0] araddr_reg =0; integer num_of_bytes_c = 0; integer total_bytes = 0; integer num_of_bytes_r = 0; integer wrap_base_addr_r = 0; integer wrap_boundary_r = 0; reg [7:0] arlen_int_c=0; integer total_bytes_c = 0; integer wrap_base_addr_c = 0; integer wrap_boundary_c = 0; assign dec_alen_c = incr_addr_c | r_last_int_c; read_netlist_v8_3 #(.C_AXI_TYPE (1), .C_ADDRB_WIDTH (C_ADDRB_WIDTH)) axi_read_fsm ( .S_AXI_INCR_ADDR(incr_addr_c), .S_AXI_ADDR_EN(addr_en_c), .S_AXI_SINGLE_TRANS(single_trans_c), .S_AXI_MUX_SEL(mux_sel_c), .S_AXI_R_LAST(r_last_c), .S_AXI_R_LAST_INT(r_last_int_c), //// AXI Global Signals .S_ACLK(S_ACLK), .S_ARESETN(S_ARESETN), //// AXI Full/Lite Slave Read (Read side) .S_AXI_ARLEN(S_AXI_ARLEN), .S_AXI_ARVALID(S_AXI_ARVALID), .S_AXI_ARREADY(S_AXI_ARREADY), .S_AXI_RLAST(S_AXI_RLAST), .S_AXI_RVALID(S_AXI_RVALID), .S_AXI_RREADY(S_AXI_RREADY), //// AXI Full/Lite Read Address Signals to BRAM .S_AXI_RD_EN(rd_en_c) ); always@(*) begin num_of_bytes_c = 2**((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_ARSIZE:0); total_bytes = (num_of_bytes_r)*(arlen_int_r+1); wrap_base_addr_r = ((araddr_reg)/(total_bytes==0?1:total_bytes))*(total_bytes); wrap_boundary_r = wrap_base_addr_r+total_bytes; //////// combinatorial from interface arlen_int_c = (C_AXI_TYPE == 0?0:S_AXI_ARLEN); total_bytes_c = (num_of_bytes_c)*(arlen_int_c+1); wrap_base_addr_c = ((S_AXI_ARADDR)/(total_bytes_c==0?1:total_bytes_c))*(total_bytes_c); wrap_boundary_c = wrap_base_addr_c+total_bytes_c; arburst_int_c = ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_ARBURST:1); end ////------------------------------------------------------------------------- //// BMG address generation ////------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin araddr_reg <= 0; arburst_int_r <= 0; num_of_bytes_r <= 0; end else begin if (incr_addr_c == 1'b1 && addr_en_c == 1'b1 && single_trans_c == 1'b0) begin arburst_int_r <= arburst_int_c; num_of_bytes_r <= num_of_bytes_c; if (arburst_int_c == 2'b10) begin if(S_AXI_ARADDR == (wrap_boundary_c-num_of_bytes_c)) begin araddr_reg <= wrap_base_addr_c; end else begin araddr_reg <= S_AXI_ARADDR + num_of_bytes_c; end end else if (arburst_int_c == 2'b01 || arburst_int_c == 2'b11) begin araddr_reg <= S_AXI_ARADDR + num_of_bytes_c; end end else if (addr_en_c == 1'b1) begin araddr_reg <= S_AXI_ARADDR; num_of_bytes_r <= num_of_bytes_c; arburst_int_r <= arburst_int_c; end else if (incr_addr_c == 1'b1) begin if (arburst_int_r == 2'b10) begin if(araddr_reg == (wrap_boundary_r-num_of_bytes_r)) begin araddr_reg <= wrap_base_addr_r; end else begin araddr_reg <= araddr_reg + num_of_bytes_r; end end else if (arburst_int_r == 2'b01 || arburst_int_r == 2'b11) begin araddr_reg <= araddr_reg + num_of_bytes_r; end end end end assign araddr_out = ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?araddr_reg[C_AXI_ARADDR_WIDTH-1:C_RANGE]:araddr_reg); ////----------------------------------------------------------------------- //// Counter to generate r_last_int_c from registered ARLEN - AXI FULL FSM ////----------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin arlen_cntr <= 8'h01; arlen_int_r <= 0; end else begin if (addr_en_c == 1'b1 && dec_alen_c == 1'b1 && single_trans_c == 1'b0) begin arlen_int_r <= (C_AXI_TYPE == 0?0:S_AXI_ARLEN) ; arlen_cntr <= S_AXI_ARLEN - 1'b1; end else if (addr_en_c == 1'b1) begin arlen_int_r <= (C_AXI_TYPE == 0?0:S_AXI_ARLEN) ; arlen_cntr <= (C_AXI_TYPE == 0?0:S_AXI_ARLEN) ; end else if (dec_alen_c == 1'b1) begin arlen_cntr <= arlen_cntr - 1'b1 ; end else begin arlen_cntr <= arlen_cntr; end end end assign r_last_int_c = (arlen_cntr == 0 && S_AXI_RREADY == 1'b1)?1'b1:1'b0; ////------------------------------------------------------------------------ //// AXI FULL FSM //// Mux Selection of ARADDR //// ARADDR is driven out from the read fsm based on the mux_sel_c //// Based on mux_sel either ARADDR is given out or the latched ARADDR is //// given out to BRAM ////------------------------------------------------------------------------ assign S_AXI_ARADDR_OUT = (mux_sel_c == 1'b0)?((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_ARADDR[C_AXI_ARADDR_WIDTH-1:C_RANGE]:S_AXI_ARADDR):araddr_out; ////------------------------------------------------------------------------ //// Assign output signals - AXI FULL FSM ////------------------------------------------------------------------------ assign S_AXI_RD_EN = rd_en_c; generate if (C_HAS_AXI_ID == 1) begin:gaxi_bvalid_id_r always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin S_AXI_RID <= 0; ar_id_r <= 0; end else begin if (addr_en_c == 1'b1 && rd_en_c == 1'b1) begin S_AXI_RID <= S_AXI_ARID; ar_id_r <= S_AXI_ARID; end else if (addr_en_c == 1'b1 && rd_en_c == 1'b0) begin ar_id_r <= S_AXI_ARID; end else if (rd_en_c == 1'b1) begin S_AXI_RID <= ar_id_r; end end end end endgenerate endmodule module blk_mem_axi_regs_fwd_v8_3 #(parameter C_DATA_WIDTH = 8 )( input ACLK, input ARESET, input S_VALID, output S_READY, input [C_DATA_WIDTH-1:0] S_PAYLOAD_DATA, output M_VALID, input M_READY, output reg [C_DATA_WIDTH-1:0] M_PAYLOAD_DATA ); reg [C_DATA_WIDTH-1:0] STORAGE_DATA; wire S_READY_I; reg M_VALID_I; reg [1:0] ARESET_D; //assign local signal to its output signal assign S_READY = S_READY_I; assign M_VALID = M_VALID_I; always @(posedge ACLK) begin ARESET_D <= {ARESET_D[0], ARESET}; end //Save payload data whenever we have a transaction on the slave side always @(posedge ACLK or ARESET) begin if (ARESET == 1'b1) begin STORAGE_DATA <= 0; end else begin if(S_VALID == 1'b1 && S_READY_I == 1'b1 ) begin STORAGE_DATA <= S_PAYLOAD_DATA; end end end always @(posedge ACLK) begin M_PAYLOAD_DATA = STORAGE_DATA; end //M_Valid set to high when we have a completed transfer on slave side //Is removed on a M_READY except if we have a new transfer on the slave side always @(posedge ACLK or ARESET_D) begin if (ARESET_D != 2'b00) begin M_VALID_I <= 1'b0; end else begin if (S_VALID == 1'b1) begin //Always set M_VALID_I when slave side is valid M_VALID_I <= 1'b1; end else if (M_READY == 1'b1 ) begin //Clear (or keep) when no slave side is valid but master side is ready M_VALID_I <= 1'b0; end end end //Slave Ready is either when Master side drives M_READY or we have space in our storage data assign S_READY_I = (M_READY || (!M_VALID_I)) && !(|(ARESET_D)); endmodule //***************************************************************************** // Output Register Stage module // // This module builds the output register stages of the memory. This module is // instantiated in the main memory module (blk_mem_gen_v8_3_3) which is // declared/implemented further down in this file. //***************************************************************************** module blk_mem_gen_v8_3_3_output_stage #(parameter C_FAMILY = "virtex7", parameter C_XDEVICEFAMILY = "virtex7", parameter C_RST_TYPE = "SYNC", parameter C_HAS_RST = 0, parameter C_RSTRAM = 0, parameter C_RST_PRIORITY = "CE", parameter C_INIT_VAL = "0", parameter C_HAS_EN = 0, parameter C_HAS_REGCE = 0, parameter C_DATA_WIDTH = 32, parameter C_ADDRB_WIDTH = 10, parameter C_HAS_MEM_OUTPUT_REGS = 0, parameter C_USE_SOFTECC = 0, parameter C_USE_ECC = 0, parameter NUM_STAGES = 1, parameter C_EN_ECC_PIPE = 0, parameter FLOP_DELAY = 100 ) ( input CLK, input RST, input EN, input REGCE, input [C_DATA_WIDTH-1:0] DIN_I, output reg [C_DATA_WIDTH-1:0] DOUT, input SBITERR_IN_I, input DBITERR_IN_I, output reg SBITERR, output reg DBITERR, input [C_ADDRB_WIDTH-1:0] RDADDRECC_IN_I, input ECCPIPECE, output reg [C_ADDRB_WIDTH-1:0] RDADDRECC ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_FAMILY,C_XDEVICEFAMILY: Designates architecture targeted. The following // options are available - "spartan3", "spartan6", // "virtex4", "virtex5", "virtex6" and "virtex6l". // C_RST_TYPE : Type of reset - Synchronous or Asynchronous // C_HAS_RST : Determines the presence of the RST port // C_RSTRAM : Determines if special reset behavior is used // C_RST_PRIORITY : Determines the priority between CE and SR // C_INIT_VAL : Initialization value // C_HAS_EN : Determines the presence of the EN port // C_HAS_REGCE : Determines the presence of the REGCE port // C_DATA_WIDTH : Memory write/read width // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_MEM_OUTPUT_REGS : Designates the use of a register at the output // of the RAM primitive // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // C_USE_ECC : Determines if the ECC feature is used or // not. Only applicable for V5 and V6 // NUM_STAGES : Determines the number of output stages // FLOP_DELAY : Constant delay for register assignments ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLK : Clock to synchronize all read and write operations // RST : Reset input to reset memory outputs to a user-defined // reset state // EN : Enable all read and write operations // REGCE : Register Clock Enable to control each pipeline output // register stages // DIN : Data input to the Output stage. // DOUT : Final Data output // SBITERR_IN : SBITERR input signal to the Output stage. // SBITERR : Final SBITERR Output signal. // DBITERR_IN : DBITERR input signal to the Output stage. // DBITERR : Final DBITERR Output signal. // RDADDRECC_IN : RDADDRECC input signal to the Output stage. // RDADDRECC : Final RDADDRECC Output signal. ////////////////////////////////////////////////////////////////////////// // Fix for CR-509792 localparam REG_STAGES = (NUM_STAGES < 2) ? 1 : NUM_STAGES-1; // Declare the pipeline registers // (includes mem output reg, mux pipeline stages, and mux output reg) reg [C_DATA_WIDTH*REG_STAGES-1:0] out_regs; reg [C_ADDRB_WIDTH*REG_STAGES-1:0] rdaddrecc_regs; reg [REG_STAGES-1:0] sbiterr_regs; reg [REG_STAGES-1:0] dbiterr_regs; reg [C_DATA_WIDTH*8-1:0] init_str = C_INIT_VAL; reg [C_DATA_WIDTH-1:0] init_val ; //********************************************* // Wire off optional inputs based on parameters //********************************************* wire en_i; wire regce_i; wire rst_i; // Internal signals reg [C_DATA_WIDTH-1:0] DIN; reg [C_ADDRB_WIDTH-1:0] RDADDRECC_IN; reg SBITERR_IN; reg DBITERR_IN; // Internal enable for output registers is tied to user EN or '1' depending // on parameters assign en_i = (C_HAS_EN==0 || EN); // Internal register enable for output registers is tied to user REGCE, EN or // '1' depending on parameters // For V4 ECC, REGCE is always 1 // Virtex-4 ECC Not Yet Supported assign regce_i = ((C_HAS_REGCE==1) && REGCE) || ((C_HAS_REGCE==0) && (C_HAS_EN==0 || EN)); //Internal SRR is tied to user RST or '0' depending on parameters assign rst_i = (C_HAS_RST==1) && RST; //**************************************************** // Power on: load up the output registers and latches //**************************************************** initial begin if (!($sscanf(init_str, "%h", init_val))) begin init_val = 0; end DOUT = init_val; RDADDRECC = 0; SBITERR = 1'b0; DBITERR = 1'b0; DIN = {(C_DATA_WIDTH){1'b0}}; RDADDRECC_IN = 0; SBITERR_IN = 0; DBITERR_IN = 0; // This will be one wider than need, but 0 is an error out_regs = {(REG_STAGES+1){init_val}}; rdaddrecc_regs = 0; sbiterr_regs = {(REG_STAGES+1){1'b0}}; dbiterr_regs = {(REG_STAGES+1){1'b0}}; end //*********************************************** // NUM_STAGES = 0 (No output registers. RAM only) //*********************************************** generate if (NUM_STAGES == 0) begin : zero_stages always @* begin DOUT = DIN; RDADDRECC = RDADDRECC_IN; SBITERR = SBITERR_IN; DBITERR = DBITERR_IN; end end endgenerate generate if (C_EN_ECC_PIPE == 0) begin : no_ecc_pipe_reg always @* begin DIN = DIN_I; SBITERR_IN = SBITERR_IN_I; DBITERR_IN = DBITERR_IN_I; RDADDRECC_IN = RDADDRECC_IN_I; end end endgenerate generate if (C_EN_ECC_PIPE == 1) begin : with_ecc_pipe_reg always @(posedge CLK) begin if(ECCPIPECE == 1) begin DIN <= #FLOP_DELAY DIN_I; SBITERR_IN <= #FLOP_DELAY SBITERR_IN_I; DBITERR_IN <= #FLOP_DELAY DBITERR_IN_I; RDADDRECC_IN <= #FLOP_DELAY RDADDRECC_IN_I; end end end endgenerate //*********************************************** // NUM_STAGES = 1 // (Mem Output Reg only or Mux Output Reg only) //*********************************************** // Possible valid combinations: // Note: C_HAS_MUX_OUTPUT_REGS_*=0 when (C_RSTRAM_*=1) // +-----------------------------------------+ // | C_RSTRAM_* | Reset Behavior | // +----------------+------------------------+ // | 0 | Normal Behavior | // +----------------+------------------------+ // | 1 | Special Behavior | // +----------------+------------------------+ // // Normal = REGCE gates reset, as in the case of all families except S3ADSP. // Special = EN gates reset, as in the case of S3ADSP. generate if (NUM_STAGES == 1 && (C_RSTRAM == 0 || (C_RSTRAM == 1 && (C_XDEVICEFAMILY != "spartan3adsp" && C_XDEVICEFAMILY != "aspartan3adsp" )) || C_HAS_MEM_OUTPUT_REGS == 0 || C_HAS_RST == 0)) begin : one_stages_norm always @(posedge CLK) begin if (C_RST_PRIORITY == "CE") begin //REGCE has priority if (regce_i && rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY 0; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY DIN; RDADDRECC <= #FLOP_DELAY RDADDRECC_IN; SBITERR <= #FLOP_DELAY SBITERR_IN; DBITERR <= #FLOP_DELAY DBITERR_IN; end //Output signal assignments end else begin //RST has priority if (rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY RDADDRECC_IN; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY DIN; RDADDRECC <= #FLOP_DELAY RDADDRECC_IN; SBITERR <= #FLOP_DELAY SBITERR_IN; DBITERR <= #FLOP_DELAY DBITERR_IN; end //Output signal assignments end //end Priority conditions end //end RST Type conditions end //end one_stages_norm generate statement endgenerate // Special Reset Behavior for S3ADSP generate if (NUM_STAGES == 1 && C_RSTRAM == 1 && (C_XDEVICEFAMILY =="spartan3adsp" || C_XDEVICEFAMILY =="aspartan3adsp")) begin : one_stage_splbhv always @(posedge CLK) begin if (en_i && rst_i) begin DOUT <= #FLOP_DELAY init_val; end else if (regce_i && !rst_i) begin DOUT <= #FLOP_DELAY DIN; end //Output signal assignments end //end CLK end //end one_stage_splbhv generate statement endgenerate //************************************************************ // NUM_STAGES > 1 // Mem Output Reg + Mux Output Reg // or // Mem Output Reg + Mux Pipeline Stages (>0) + Mux Output Reg // or // Mux Pipeline Stages (>0) + Mux Output Reg //************************************************************* generate if (NUM_STAGES > 1) begin : multi_stage //Asynchronous Reset always @(posedge CLK) begin if (C_RST_PRIORITY == "CE") begin //REGCE has priority if (regce_i && rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY 0; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY out_regs[C_DATA_WIDTH*(NUM_STAGES-2)+:C_DATA_WIDTH]; RDADDRECC <= #FLOP_DELAY rdaddrecc_regs[C_ADDRB_WIDTH*(NUM_STAGES-2)+:C_ADDRB_WIDTH]; SBITERR <= #FLOP_DELAY sbiterr_regs[NUM_STAGES-2]; DBITERR <= #FLOP_DELAY dbiterr_regs[NUM_STAGES-2]; end //Output signal assignments end else begin //RST has priority if (rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY 0; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY out_regs[C_DATA_WIDTH*(NUM_STAGES-2)+:C_DATA_WIDTH]; RDADDRECC <= #FLOP_DELAY rdaddrecc_regs[C_ADDRB_WIDTH*(NUM_STAGES-2)+:C_ADDRB_WIDTH]; SBITERR <= #FLOP_DELAY sbiterr_regs[NUM_STAGES-2]; DBITERR <= #FLOP_DELAY dbiterr_regs[NUM_STAGES-2]; end //Output signal assignments end //end Priority conditions // Shift the data through the output stages if (en_i) begin out_regs <= #FLOP_DELAY (out_regs << C_DATA_WIDTH) | DIN; rdaddrecc_regs <= #FLOP_DELAY (rdaddrecc_regs << C_ADDRB_WIDTH) | RDADDRECC_IN; sbiterr_regs <= #FLOP_DELAY (sbiterr_regs << 1) | SBITERR_IN; dbiterr_regs <= #FLOP_DELAY (dbiterr_regs << 1) | DBITERR_IN; end end //end CLK end //end multi_stage generate statement endgenerate endmodule module blk_mem_gen_v8_3_3_softecc_output_reg_stage #(parameter C_DATA_WIDTH = 32, parameter C_ADDRB_WIDTH = 10, parameter C_HAS_SOFTECC_OUTPUT_REGS_B= 0, parameter C_USE_SOFTECC = 0, parameter FLOP_DELAY = 100 ) ( input CLK, input [C_DATA_WIDTH-1:0] DIN, output reg [C_DATA_WIDTH-1:0] DOUT, input SBITERR_IN, input DBITERR_IN, output reg SBITERR, output reg DBITERR, input [C_ADDRB_WIDTH-1:0] RDADDRECC_IN, output reg [C_ADDRB_WIDTH-1:0] RDADDRECC ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_DATA_WIDTH : Memory write/read width // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_SOFTECC_OUTPUT_REGS_B : Designates the use of a register at the output // of the RAM primitive // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // FLOP_DELAY : Constant delay for register assignments ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLK : Clock to synchronize all read and write operations // DIN : Data input to the Output stage. // DOUT : Final Data output // SBITERR_IN : SBITERR input signal to the Output stage. // SBITERR : Final SBITERR Output signal. // DBITERR_IN : DBITERR input signal to the Output stage. // DBITERR : Final DBITERR Output signal. // RDADDRECC_IN : RDADDRECC input signal to the Output stage. // RDADDRECC : Final RDADDRECC Output signal. ////////////////////////////////////////////////////////////////////////// reg [C_DATA_WIDTH-1:0] dout_i = 0; reg sbiterr_i = 0; reg dbiterr_i = 0; reg [C_ADDRB_WIDTH-1:0] rdaddrecc_i = 0; //*********************************************** // NO OUTPUT REGISTERS. //*********************************************** generate if (C_HAS_SOFTECC_OUTPUT_REGS_B==0) begin : no_output_stage always @* begin DOUT = DIN; RDADDRECC = RDADDRECC_IN; SBITERR = SBITERR_IN; DBITERR = DBITERR_IN; end end endgenerate //*********************************************** // WITH OUTPUT REGISTERS. //*********************************************** generate if (C_HAS_SOFTECC_OUTPUT_REGS_B==1) begin : has_output_stage always @(posedge CLK) begin dout_i <= #FLOP_DELAY DIN; rdaddrecc_i <= #FLOP_DELAY RDADDRECC_IN; sbiterr_i <= #FLOP_DELAY SBITERR_IN; dbiterr_i <= #FLOP_DELAY DBITERR_IN; end always @* begin DOUT = dout_i; RDADDRECC = rdaddrecc_i; SBITERR = sbiterr_i; DBITERR = dbiterr_i; end //end always end //end in_or_out_stage generate statement endgenerate endmodule //***************************************************************************** // Main Memory module // // This module is the top-level behavioral model and this implements the RAM //***************************************************************************** module blk_mem_gen_v8_3_3_mem_module #(parameter C_CORENAME = "blk_mem_gen_v8_3_3", parameter C_FAMILY = "virtex7", parameter C_XDEVICEFAMILY = "virtex7", parameter C_MEM_TYPE = 2, parameter C_BYTE_SIZE = 9, parameter C_USE_BRAM_BLOCK = 0, parameter C_ALGORITHM = 1, parameter C_PRIM_TYPE = 3, parameter C_LOAD_INIT_FILE = 0, parameter C_INIT_FILE_NAME = "", parameter C_INIT_FILE = "", parameter C_USE_DEFAULT_DATA = 0, parameter C_DEFAULT_DATA = "0", parameter C_RST_TYPE = "SYNC", parameter C_HAS_RSTA = 0, parameter C_RST_PRIORITY_A = "CE", parameter C_RSTRAM_A = 0, parameter C_INITA_VAL = "0", parameter C_HAS_ENA = 1, parameter C_HAS_REGCEA = 0, parameter C_USE_BYTE_WEA = 0, parameter C_WEA_WIDTH = 1, parameter C_WRITE_MODE_A = "WRITE_FIRST", parameter C_WRITE_WIDTH_A = 32, parameter C_READ_WIDTH_A = 32, parameter C_WRITE_DEPTH_A = 64, parameter C_READ_DEPTH_A = 64, parameter C_ADDRA_WIDTH = 5, parameter C_HAS_RSTB = 0, parameter C_RST_PRIORITY_B = "CE", parameter C_RSTRAM_B = 0, parameter C_INITB_VAL = "", parameter C_HAS_ENB = 1, parameter C_HAS_REGCEB = 0, parameter C_USE_BYTE_WEB = 0, parameter C_WEB_WIDTH = 1, parameter C_WRITE_MODE_B = "WRITE_FIRST", parameter C_WRITE_WIDTH_B = 32, parameter C_READ_WIDTH_B = 32, parameter C_WRITE_DEPTH_B = 64, parameter C_READ_DEPTH_B = 64, parameter C_ADDRB_WIDTH = 5, parameter C_HAS_MEM_OUTPUT_REGS_A = 0, parameter C_HAS_MEM_OUTPUT_REGS_B = 0, parameter C_HAS_MUX_OUTPUT_REGS_A = 0, parameter C_HAS_MUX_OUTPUT_REGS_B = 0, parameter C_HAS_SOFTECC_INPUT_REGS_A = 0, parameter C_HAS_SOFTECC_OUTPUT_REGS_B= 0, parameter C_MUX_PIPELINE_STAGES = 0, parameter C_USE_SOFTECC = 0, parameter C_USE_ECC = 0, parameter C_HAS_INJECTERR = 0, parameter C_SIM_COLLISION_CHECK = "NONE", parameter C_COMMON_CLK = 1, parameter FLOP_DELAY = 100, parameter C_DISABLE_WARN_BHV_COLL = 0, parameter C_EN_ECC_PIPE = 0, parameter C_DISABLE_WARN_BHV_RANGE = 0 ) (input CLKA, input RSTA, input ENA, input REGCEA, input [C_WEA_WIDTH-1:0] WEA, input [C_ADDRA_WIDTH-1:0] ADDRA, input [C_WRITE_WIDTH_A-1:0] DINA, output [C_READ_WIDTH_A-1:0] DOUTA, input CLKB, input RSTB, input ENB, input REGCEB, input [C_WEB_WIDTH-1:0] WEB, input [C_ADDRB_WIDTH-1:0] ADDRB, input [C_WRITE_WIDTH_B-1:0] DINB, output [C_READ_WIDTH_B-1:0] DOUTB, input INJECTSBITERR, input INJECTDBITERR, input ECCPIPECE, input SLEEP, output SBITERR, output DBITERR, output [C_ADDRB_WIDTH-1:0] RDADDRECC ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_CORENAME : Instance name of the Block Memory Generator core // C_FAMILY,C_XDEVICEFAMILY: Designates architecture targeted. The following // options are available - "spartan3", "spartan6", // "virtex4", "virtex5", "virtex6" and "virtex6l". // C_MEM_TYPE : Designates memory type. // It can be // 0 - Single Port Memory // 1 - Simple Dual Port Memory // 2 - True Dual Port Memory // 3 - Single Port Read Only Memory // 4 - Dual Port Read Only Memory // C_BYTE_SIZE : Size of a byte (8 or 9 bits) // C_ALGORITHM : Designates the algorithm method used // for constructing the memory. // It can be Fixed_Primitives, Minimum_Area or // Low_Power // C_PRIM_TYPE : Designates the user selected primitive used to // construct the memory. // // C_LOAD_INIT_FILE : Designates the use of an initialization file to // initialize memory contents. // C_INIT_FILE_NAME : Memory initialization file name. // C_USE_DEFAULT_DATA : Designates whether to fill remaining // initialization space with default data // C_DEFAULT_DATA : Default value of all memory locations // not initialized by the memory // initialization file. // C_RST_TYPE : Type of reset - Synchronous or Asynchronous // C_HAS_RSTA : Determines the presence of the RSTA port // C_RST_PRIORITY_A : Determines the priority between CE and SR for // Port A. // C_RSTRAM_A : Determines if special reset behavior is used for // Port A // C_INITA_VAL : The initialization value for Port A // C_HAS_ENA : Determines the presence of the ENA port // C_HAS_REGCEA : Determines the presence of the REGCEA port // C_USE_BYTE_WEA : Determines if the Byte Write is used or not. // C_WEA_WIDTH : The width of the WEA port // C_WRITE_MODE_A : Configurable write mode for Port A. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_A : Memory write width for Port A. // C_READ_WIDTH_A : Memory read width for Port A. // C_WRITE_DEPTH_A : Memory write depth for Port A. // C_READ_DEPTH_A : Memory read depth for Port A. // C_ADDRA_WIDTH : Width of the ADDRA input port // C_HAS_RSTB : Determines the presence of the RSTB port // C_RST_PRIORITY_B : Determines the priority between CE and SR for // Port B. // C_RSTRAM_B : Determines if special reset behavior is used for // Port B // C_INITB_VAL : The initialization value for Port B // C_HAS_ENB : Determines the presence of the ENB port // C_HAS_REGCEB : Determines the presence of the REGCEB port // C_USE_BYTE_WEB : Determines if the Byte Write is used or not. // C_WEB_WIDTH : The width of the WEB port // C_WRITE_MODE_B : Configurable write mode for Port B. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_B : Memory write width for Port B. // C_READ_WIDTH_B : Memory read width for Port B. // C_WRITE_DEPTH_B : Memory write depth for Port B. // C_READ_DEPTH_B : Memory read depth for Port B. // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_MEM_OUTPUT_REGS_A : Designates the use of a register at the output // of the RAM primitive for Port A. // C_HAS_MEM_OUTPUT_REGS_B : Designates the use of a register at the output // of the RAM primitive for Port B. // C_HAS_MUX_OUTPUT_REGS_A : Designates the use of a register at the output // of the MUX for Port A. // C_HAS_MUX_OUTPUT_REGS_B : Designates the use of a register at the output // of the MUX for Port B. // C_MUX_PIPELINE_STAGES : Designates the number of pipeline stages in // between the muxes. // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // C_USE_ECC : Determines if the ECC feature is used or // not. Only applicable for V5 and V6 // C_HAS_INJECTERR : Determines if the error injection pins // are present or not. If the ECC feature // is not used, this value is defaulted to // 0, else the following are the allowed // values: // 0 : No INJECTSBITERR or INJECTDBITERR pins // 1 : Only INJECTSBITERR pin exists // 2 : Only INJECTDBITERR pin exists // 3 : Both INJECTSBITERR and INJECTDBITERR pins exist // C_SIM_COLLISION_CHECK : Controls the disabling of Unisim model collision // warnings. It can be "ALL", "NONE", // "Warnings_Only" or "Generate_X_Only". // C_COMMON_CLK : Determins if the core has a single CLK input. // C_DISABLE_WARN_BHV_COLL : Controls the Behavioral Model Collision warnings // C_DISABLE_WARN_BHV_RANGE: Controls the Behavioral Model Out of Range // warnings ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLKA : Clock to synchronize all read and write operations of Port A. // RSTA : Reset input to reset memory outputs to a user-defined // reset state for Port A. // ENA : Enable all read and write operations of Port A. // REGCEA : Register Clock Enable to control each pipeline output // register stages for Port A. // WEA : Write Enable to enable all write operations of Port A. // ADDRA : Address of Port A. // DINA : Data input of Port A. // DOUTA : Data output of Port A. // CLKB : Clock to synchronize all read and write operations of Port B. // RSTB : Reset input to reset memory outputs to a user-defined // reset state for Port B. // ENB : Enable all read and write operations of Port B. // REGCEB : Register Clock Enable to control each pipeline output // register stages for Port B. // WEB : Write Enable to enable all write operations of Port B. // ADDRB : Address of Port B. // DINB : Data input of Port B. // DOUTB : Data output of Port B. // INJECTSBITERR : Single Bit ECC Error Injection Pin. // INJECTDBITERR : Double Bit ECC Error Injection Pin. // SBITERR : Output signal indicating that a Single Bit ECC Error has been // detected and corrected. // DBITERR : Output signal indicating that a Double Bit ECC Error has been // detected. // RDADDRECC : Read Address Output signal indicating address at which an // ECC error has occurred. ////////////////////////////////////////////////////////////////////////// // Note: C_CORENAME parameter is hard-coded to "blk_mem_gen_v8_3_3" and it is // only used by this module to print warning messages. It is neither passed // down from blk_mem_gen_v8_3_3_xst.v nor present in the instantiation template // coregen generates //*************************************************************************** // constants for the core behavior //*************************************************************************** // file handles for logging //-------------------------------------------------- localparam ADDRFILE = 32'h8000_0001; //stdout for addr out of range localparam COLLFILE = 32'h8000_0001; //stdout for coll detection localparam ERRFILE = 32'h8000_0001; //stdout for file I/O errors // other constants //-------------------------------------------------- localparam COLL_DELAY = 100; // 100 ps // locally derived parameters to determine memory shape //----------------------------------------------------- localparam CHKBIT_WIDTH = (C_WRITE_WIDTH_A>57 ? 8 : (C_WRITE_WIDTH_A>26 ? 7 : (C_WRITE_WIDTH_A>11 ? 6 : (C_WRITE_WIDTH_A>4 ? 5 : (C_WRITE_WIDTH_A<5 ? 4 :0))))); localparam MIN_WIDTH_A = (C_WRITE_WIDTH_A < C_READ_WIDTH_A) ? C_WRITE_WIDTH_A : C_READ_WIDTH_A; localparam MIN_WIDTH_B = (C_WRITE_WIDTH_B < C_READ_WIDTH_B) ? C_WRITE_WIDTH_B : C_READ_WIDTH_B; localparam MIN_WIDTH = (MIN_WIDTH_A < MIN_WIDTH_B) ? MIN_WIDTH_A : MIN_WIDTH_B; localparam MAX_DEPTH_A = (C_WRITE_DEPTH_A > C_READ_DEPTH_A) ? C_WRITE_DEPTH_A : C_READ_DEPTH_A; localparam MAX_DEPTH_B = (C_WRITE_DEPTH_B > C_READ_DEPTH_B) ? C_WRITE_DEPTH_B : C_READ_DEPTH_B; localparam MAX_DEPTH = (MAX_DEPTH_A > MAX_DEPTH_B) ? MAX_DEPTH_A : MAX_DEPTH_B; // locally derived parameters to assist memory access //---------------------------------------------------- // Calculate the width ratios of each port with respect to the narrowest // port localparam WRITE_WIDTH_RATIO_A = C_WRITE_WIDTH_A/MIN_WIDTH; localparam READ_WIDTH_RATIO_A = C_READ_WIDTH_A/MIN_WIDTH; localparam WRITE_WIDTH_RATIO_B = C_WRITE_WIDTH_B/MIN_WIDTH; localparam READ_WIDTH_RATIO_B = C_READ_WIDTH_B/MIN_WIDTH; // To modify the LSBs of the 'wider' data to the actual // address value //---------------------------------------------------- localparam WRITE_ADDR_A_DIV = C_WRITE_WIDTH_A/MIN_WIDTH_A; localparam READ_ADDR_A_DIV = C_READ_WIDTH_A/MIN_WIDTH_A; localparam WRITE_ADDR_B_DIV = C_WRITE_WIDTH_B/MIN_WIDTH_B; localparam READ_ADDR_B_DIV = C_READ_WIDTH_B/MIN_WIDTH_B; // If byte writes aren't being used, make sure BYTE_SIZE is not // wider than the memory elements to avoid compilation warnings localparam BYTE_SIZE = (C_BYTE_SIZE < MIN_WIDTH) ? C_BYTE_SIZE : MIN_WIDTH; // The memory reg [MIN_WIDTH-1:0] memory [0:MAX_DEPTH-1]; reg [MIN_WIDTH-1:0] temp_mem_array [0:MAX_DEPTH-1]; reg [C_WRITE_WIDTH_A+CHKBIT_WIDTH-1:0] doublebit_error = 3; // ECC error arrays reg sbiterr_arr [0:MAX_DEPTH-1]; reg dbiterr_arr [0:MAX_DEPTH-1]; reg softecc_sbiterr_arr [0:MAX_DEPTH-1]; reg softecc_dbiterr_arr [0:MAX_DEPTH-1]; // Memory output 'latches' reg [C_READ_WIDTH_A-1:0] memory_out_a; reg [C_READ_WIDTH_B-1:0] memory_out_b; // ECC error inputs and outputs from output_stage module: reg sbiterr_in; wire sbiterr_sdp; reg dbiterr_in; wire dbiterr_sdp; wire [C_READ_WIDTH_B-1:0] dout_i; wire dbiterr_i; wire sbiterr_i; wire [C_ADDRB_WIDTH-1:0] rdaddrecc_i; reg [C_ADDRB_WIDTH-1:0] rdaddrecc_in; wire [C_ADDRB_WIDTH-1:0] rdaddrecc_sdp; // Reset values reg [C_READ_WIDTH_A-1:0] inita_val; reg [C_READ_WIDTH_B-1:0] initb_val; // Collision detect reg is_collision; reg is_collision_a, is_collision_delay_a; reg is_collision_b, is_collision_delay_b; // Temporary variables for initialization //--------------------------------------- integer status; integer initfile; integer meminitfile; // data input buffer reg [C_WRITE_WIDTH_A-1:0] mif_data; reg [C_WRITE_WIDTH_A-1:0] mem_data; // string values in hex reg [C_READ_WIDTH_A*8-1:0] inita_str = C_INITA_VAL; reg [C_READ_WIDTH_B*8-1:0] initb_str = C_INITB_VAL; reg [C_WRITE_WIDTH_A*8-1:0] default_data_str = C_DEFAULT_DATA; // initialization filename reg [1023*8-1:0] init_file_str = C_INIT_FILE_NAME; reg [1023*8-1:0] mem_init_file_str = C_INIT_FILE; //Constants used to calculate the effective address widths for each of the //four ports. integer cnt = 1; integer write_addr_a_width, read_addr_a_width; integer write_addr_b_width, read_addr_b_width; localparam C_FAMILY_LOCALPARAM = (C_FAMILY=="zynquplus"?"virtex7":(C_FAMILY=="kintexuplus"?"virtex7":(C_FAMILY=="virtexuplus"?"virtex7":(C_FAMILY=="virtexu"?"virtex7":(C_FAMILY=="kintexu" ? "virtex7":(C_FAMILY=="virtex7" ? "virtex7" : (C_FAMILY=="virtex7l" ? "virtex7" : (C_FAMILY=="qvirtex7" ? "virtex7" : (C_FAMILY=="qvirtex7l" ? "virtex7" : (C_FAMILY=="kintex7" ? "virtex7" : (C_FAMILY=="kintex7l" ? "virtex7" : (C_FAMILY=="qkintex7" ? "virtex7" : (C_FAMILY=="qkintex7l" ? "virtex7" : (C_FAMILY=="artix7" ? "virtex7" : (C_FAMILY=="artix7l" ? "virtex7" : (C_FAMILY=="qartix7" ? "virtex7" : (C_FAMILY=="qartix7l" ? "virtex7" : (C_FAMILY=="aartix7" ? "virtex7" : (C_FAMILY=="zynq" ? "virtex7" : (C_FAMILY=="azynq" ? "virtex7" : (C_FAMILY=="qzynq" ? "virtex7" : C_FAMILY))))))))))))))))))))); // Internal configuration parameters //--------------------------------------------- localparam SINGLE_PORT = (C_MEM_TYPE==0 || C_MEM_TYPE==3); localparam IS_ROM = (C_MEM_TYPE==3 || C_MEM_TYPE==4); localparam HAS_A_WRITE = (!IS_ROM); localparam HAS_B_WRITE = (C_MEM_TYPE==2); localparam HAS_A_READ = (C_MEM_TYPE!=1); localparam HAS_B_READ = (!SINGLE_PORT); localparam HAS_B_PORT = (HAS_B_READ || HAS_B_WRITE); // Calculate the mux pipeline register stages for Port A and Port B //------------------------------------------------------------------ localparam MUX_PIPELINE_STAGES_A = (C_HAS_MUX_OUTPUT_REGS_A) ? C_MUX_PIPELINE_STAGES : 0; localparam MUX_PIPELINE_STAGES_B = (C_HAS_MUX_OUTPUT_REGS_B) ? C_MUX_PIPELINE_STAGES : 0; // Calculate total number of register stages in the core // ----------------------------------------------------- localparam NUM_OUTPUT_STAGES_A = (C_HAS_MEM_OUTPUT_REGS_A+MUX_PIPELINE_STAGES_A+C_HAS_MUX_OUTPUT_REGS_A); localparam NUM_OUTPUT_STAGES_B = (C_HAS_MEM_OUTPUT_REGS_B+MUX_PIPELINE_STAGES_B+C_HAS_MUX_OUTPUT_REGS_B); wire ena_i; wire enb_i; wire reseta_i; wire resetb_i; wire [C_WEA_WIDTH-1:0] wea_i; wire [C_WEB_WIDTH-1:0] web_i; wire rea_i; wire reb_i; wire rsta_outp_stage; wire rstb_outp_stage; // ECC SBITERR/DBITERR Outputs // The ECC Behavior is modeled by the behavioral models only for Virtex-6. // For Virtex-5, these outputs will be tied to 0. assign SBITERR = ((C_MEM_TYPE == 1 && C_USE_ECC == 1) || C_USE_SOFTECC == 1)?sbiterr_sdp:0; assign DBITERR = ((C_MEM_TYPE == 1 && C_USE_ECC == 1) || C_USE_SOFTECC == 1)?dbiterr_sdp:0; assign RDADDRECC = (((C_FAMILY_LOCALPARAM == "virtex7") && C_MEM_TYPE == 1 && C_USE_ECC == 1) || C_USE_SOFTECC == 1)?rdaddrecc_sdp:0; // This effectively wires off optional inputs assign ena_i = (C_HAS_ENA==0) || ENA; assign enb_i = ((C_HAS_ENB==0) || ENB) && HAS_B_PORT; //assign wea_i = (HAS_A_WRITE && ena_i) ? WEA : 'b0; // To Fix CR855535 assign wea_i = (HAS_A_WRITE == 1 && C_MEM_TYPE == 1 &&C_USE_ECC == 1 && C_HAS_ENA == 1 && ENA == 1) ? 'b1 :(HAS_A_WRITE == 1 && C_MEM_TYPE == 1 &&C_USE_ECC == 1 && C_HAS_ENA == 0) ? WEA : (HAS_A_WRITE && ena_i && C_USE_ECC == 0) ? WEA : 'b0; assign web_i = (HAS_B_WRITE && enb_i) ? WEB : 'b0; assign rea_i = (HAS_A_READ) ? ena_i : 'b0; assign reb_i = (HAS_B_READ) ? enb_i : 'b0; // These signals reset the memory latches assign reseta_i = ((C_HAS_RSTA==1 && RSTA && NUM_OUTPUT_STAGES_A==0) || (C_HAS_RSTA==1 && RSTA && C_RSTRAM_A==1)); assign resetb_i = ((C_HAS_RSTB==1 && RSTB && NUM_OUTPUT_STAGES_B==0) || (C_HAS_RSTB==1 && RSTB && C_RSTRAM_B==1)); // Tasks to access the memory //--------------------------- //************** // write_a //************** task write_a (input reg [C_ADDRA_WIDTH-1:0] addr, input reg [C_WEA_WIDTH-1:0] byte_en, input reg [C_WRITE_WIDTH_A-1:0] data, input inj_sbiterr, input inj_dbiterr); reg [C_WRITE_WIDTH_A-1:0] current_contents; reg [C_ADDRA_WIDTH-1:0] address; integer i; begin // Shift the address by the ratio address = (addr/WRITE_ADDR_A_DIV); if (address >= C_WRITE_DEPTH_A) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for A Write", C_CORENAME, addr); end // valid address end else begin // Combine w/ byte writes if (C_USE_BYTE_WEA) begin // Get the current memory contents if (WRITE_WIDTH_RATIO_A == 1) begin // Workaround for IUS 5.5 part-select issue current_contents = memory[address]; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_A; i = i + 1) begin current_contents[MIN_WIDTH*i+:MIN_WIDTH] = memory[address*WRITE_WIDTH_RATIO_A + i]; end end // Apply incoming bytes if (C_WEA_WIDTH == 1) begin // Workaround for IUS 5.5 part-select issue if (byte_en[0]) begin current_contents = data; end end else begin for (i = 0; i < C_WEA_WIDTH; i = i + 1) begin if (byte_en[i]) begin current_contents[BYTE_SIZE*i+:BYTE_SIZE] = data[BYTE_SIZE*i+:BYTE_SIZE]; end end end // No byte-writes, overwrite the whole word end else begin current_contents = data; end // Insert double bit errors: if (C_USE_ECC == 1) begin if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin // Modified for Implementing CR_859399 current_contents[0] = !(current_contents[30]); current_contents[1] = !(current_contents[62]); /*current_contents[0] = !(current_contents[0]); current_contents[1] = !(current_contents[1]);*/ end end // Insert softecc double bit errors: if (C_USE_SOFTECC == 1) begin if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-1:2] = doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-3:0]; doublebit_error[0] = doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-1]; doublebit_error[1] = doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-2]; current_contents = current_contents ^ doublebit_error[C_WRITE_WIDTH_A-1:0]; end end // Write data to memory if (WRITE_WIDTH_RATIO_A == 1) begin // Workaround for IUS 5.5 part-select issue memory[address*WRITE_WIDTH_RATIO_A] = current_contents; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_A; i = i + 1) begin memory[address*WRITE_WIDTH_RATIO_A + i] = current_contents[MIN_WIDTH*i+:MIN_WIDTH]; end end // Store the address at which error is injected: if ((C_FAMILY_LOCALPARAM == "virtex7") && C_USE_ECC == 1) begin if ((C_HAS_INJECTERR == 1 && inj_sbiterr == 1'b1) || (C_HAS_INJECTERR == 3 && inj_sbiterr == 1'b1 && inj_dbiterr != 1'b1)) begin sbiterr_arr[addr] = 1; end else begin sbiterr_arr[addr] = 0; end if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin dbiterr_arr[addr] = 1; end else begin dbiterr_arr[addr] = 0; end end // Store the address at which softecc error is injected: if (C_USE_SOFTECC == 1) begin if ((C_HAS_INJECTERR == 1 && inj_sbiterr == 1'b1) || (C_HAS_INJECTERR == 3 && inj_sbiterr == 1'b1 && inj_dbiterr != 1'b1)) begin softecc_sbiterr_arr[addr] = 1; end else begin softecc_sbiterr_arr[addr] = 0; end if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin softecc_dbiterr_arr[addr] = 1; end else begin softecc_dbiterr_arr[addr] = 0; end end end end endtask //************** // write_b //************** task write_b (input reg [C_ADDRB_WIDTH-1:0] addr, input reg [C_WEB_WIDTH-1:0] byte_en, input reg [C_WRITE_WIDTH_B-1:0] data); reg [C_WRITE_WIDTH_B-1:0] current_contents; reg [C_ADDRB_WIDTH-1:0] address; integer i; begin // Shift the address by the ratio address = (addr/WRITE_ADDR_B_DIV); if (address >= C_WRITE_DEPTH_B) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for B Write", C_CORENAME, addr); end // valid address end else begin // Combine w/ byte writes if (C_USE_BYTE_WEB) begin // Get the current memory contents if (WRITE_WIDTH_RATIO_B == 1) begin // Workaround for IUS 5.5 part-select issue current_contents = memory[address]; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_B; i = i + 1) begin current_contents[MIN_WIDTH*i+:MIN_WIDTH] = memory[address*WRITE_WIDTH_RATIO_B + i]; end end // Apply incoming bytes if (C_WEB_WIDTH == 1) begin // Workaround for IUS 5.5 part-select issue if (byte_en[0]) begin current_contents = data; end end else begin for (i = 0; i < C_WEB_WIDTH; i = i + 1) begin if (byte_en[i]) begin current_contents[BYTE_SIZE*i+:BYTE_SIZE] = data[BYTE_SIZE*i+:BYTE_SIZE]; end end end // No byte-writes, overwrite the whole word end else begin current_contents = data; end // Write data to memory if (WRITE_WIDTH_RATIO_B == 1) begin // Workaround for IUS 5.5 part-select issue memory[address*WRITE_WIDTH_RATIO_B] = current_contents; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_B; i = i + 1) begin memory[address*WRITE_WIDTH_RATIO_B + i] = current_contents[MIN_WIDTH*i+:MIN_WIDTH]; end end end end endtask //************** // read_a //************** task read_a (input reg [C_ADDRA_WIDTH-1:0] addr, input reg reset); reg [C_ADDRA_WIDTH-1:0] address; integer i; begin if (reset) begin memory_out_a <= #FLOP_DELAY inita_val; end else begin // Shift the address by the ratio address = (addr/READ_ADDR_A_DIV); if (address >= C_READ_DEPTH_A) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for A Read", C_CORENAME, addr); end memory_out_a <= #FLOP_DELAY 'bX; // valid address end else begin if (READ_WIDTH_RATIO_A==1) begin memory_out_a <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_A]; end else begin // Increment through the 'partial' words in the memory for (i = 0; i < READ_WIDTH_RATIO_A; i = i + 1) begin memory_out_a[MIN_WIDTH*i+:MIN_WIDTH] <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_A + i]; end end //end READ_WIDTH_RATIO_A==1 loop end //end valid address loop end //end reset-data assignment loops end endtask //************** // read_b //************** task read_b (input reg [C_ADDRB_WIDTH-1:0] addr, input reg reset); reg [C_ADDRB_WIDTH-1:0] address; integer i; begin if (reset) begin memory_out_b <= #FLOP_DELAY initb_val; sbiterr_in <= #FLOP_DELAY 1'b0; dbiterr_in <= #FLOP_DELAY 1'b0; rdaddrecc_in <= #FLOP_DELAY 0; end else begin // Shift the address address = (addr/READ_ADDR_B_DIV); if (address >= C_READ_DEPTH_B) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for B Read", C_CORENAME, addr); end memory_out_b <= #FLOP_DELAY 'bX; sbiterr_in <= #FLOP_DELAY 1'bX; dbiterr_in <= #FLOP_DELAY 1'bX; rdaddrecc_in <= #FLOP_DELAY 'bX; // valid address end else begin if (READ_WIDTH_RATIO_B==1) begin memory_out_b <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_B]; end else begin // Increment through the 'partial' words in the memory for (i = 0; i < READ_WIDTH_RATIO_B; i = i + 1) begin memory_out_b[MIN_WIDTH*i+:MIN_WIDTH] <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_B + i]; end end if ((C_FAMILY_LOCALPARAM == "virtex7") && C_USE_ECC == 1) begin rdaddrecc_in <= #FLOP_DELAY addr; if (sbiterr_arr[addr] == 1) begin sbiterr_in <= #FLOP_DELAY 1'b1; end else begin sbiterr_in <= #FLOP_DELAY 1'b0; end if (dbiterr_arr[addr] == 1) begin dbiterr_in <= #FLOP_DELAY 1'b1; end else begin dbiterr_in <= #FLOP_DELAY 1'b0; end end else if (C_USE_SOFTECC == 1) begin rdaddrecc_in <= #FLOP_DELAY addr; if (softecc_sbiterr_arr[addr] == 1) begin sbiterr_in <= #FLOP_DELAY 1'b1; end else begin sbiterr_in <= #FLOP_DELAY 1'b0; end if (softecc_dbiterr_arr[addr] == 1) begin dbiterr_in <= #FLOP_DELAY 1'b1; end else begin dbiterr_in <= #FLOP_DELAY 1'b0; end end else begin rdaddrecc_in <= #FLOP_DELAY 0; dbiterr_in <= #FLOP_DELAY 1'b0; sbiterr_in <= #FLOP_DELAY 1'b0; end //end SOFTECC Loop end //end Valid address loop end //end reset-data assignment loops end endtask //************** // reset_a //************** task reset_a (input reg reset); begin if (reset) memory_out_a <= #FLOP_DELAY inita_val; end endtask //************** // reset_b //************** task reset_b (input reg reset); begin if (reset) memory_out_b <= #FLOP_DELAY initb_val; end endtask //************** // init_memory //************** task init_memory; integer i, j, addr_step; integer status; reg [C_WRITE_WIDTH_A-1:0] default_data; begin default_data = 0; //Display output message indicating that the behavioral model is being //initialized if (C_USE_DEFAULT_DATA || C_LOAD_INIT_FILE) $display(" Block Memory Generator module loading initial data..."); // Convert the default to hex if (C_USE_DEFAULT_DATA) begin if (default_data_str == "") begin $fdisplay(ERRFILE, "%0s ERROR: C_DEFAULT_DATA is empty!", C_CORENAME); $finish; end else begin status = $sscanf(default_data_str, "%h", default_data); if (status == 0) begin $fdisplay(ERRFILE, {"%0s ERROR: Unsuccessful hexadecimal read", "from C_DEFAULT_DATA: %0s"}, C_CORENAME, C_DEFAULT_DATA); $finish; end end end // Step by WRITE_ADDR_A_DIV through the memory via the // Port A write interface to hit every location once addr_step = WRITE_ADDR_A_DIV; // 'write' to every location with default (or 0) for (i = 0; i < C_WRITE_DEPTH_A*addr_step; i = i + addr_step) begin write_a(i, {C_WEA_WIDTH{1'b1}}, default_data, 1'b0, 1'b0); end // Get specialized data from the MIF file if (C_LOAD_INIT_FILE) begin if (init_file_str == "") begin $fdisplay(ERRFILE, "%0s ERROR: C_INIT_FILE_NAME is empty!", C_CORENAME); $finish; end else begin initfile = $fopen(init_file_str, "r"); if (initfile == 0) begin $fdisplay(ERRFILE, {"%0s, ERROR: Problem opening", "C_INIT_FILE_NAME: %0s!"}, C_CORENAME, init_file_str); $finish; end else begin // loop through the mif file, loading in the data for (i = 0; i < C_WRITE_DEPTH_A*addr_step; i = i + addr_step) begin status = $fscanf(initfile, "%b", mif_data); if (status > 0) begin write_a(i, {C_WEA_WIDTH{1'b1}}, mif_data, 1'b0, 1'b0); end end $fclose(initfile); end //initfile end //init_file_str end //C_LOAD_INIT_FILE if (C_USE_BRAM_BLOCK) begin // Get specialized data from the MIF file if (C_INIT_FILE != "NONE") begin if (mem_init_file_str == "") begin $fdisplay(ERRFILE, "%0s ERROR: C_INIT_FILE is empty!", C_CORENAME); $finish; end else begin meminitfile = $fopen(mem_init_file_str, "r"); if (meminitfile == 0) begin $fdisplay(ERRFILE, {"%0s, ERROR: Problem opening", "C_INIT_FILE: %0s!"}, C_CORENAME, mem_init_file_str); $finish; end else begin // loop through the mif file, loading in the data $readmemh(mem_init_file_str, memory ); for (j = 0; j < MAX_DEPTH-1 ; j = j + 1) begin end $fclose(meminitfile); end //meminitfile end //mem_init_file_str end //C_INIT_FILE end //C_USE_BRAM_BLOCK //Display output message indicating that the behavioral model is done //initializing if (C_USE_DEFAULT_DATA || C_LOAD_INIT_FILE) $display(" Block Memory Generator data initialization complete."); end endtask //************** // log2roundup //************** function integer log2roundup (input integer data_value); integer width; integer cnt; begin width = 0; if (data_value > 1) begin for(cnt=1 ; cnt < data_value ; cnt = cnt * 2) begin width = width + 1; end //loop end //if log2roundup = width; end //log2roundup endfunction //******************* // collision_check //******************* function integer collision_check (input reg [C_ADDRA_WIDTH-1:0] addr_a, input integer iswrite_a, input reg [C_ADDRB_WIDTH-1:0] addr_b, input integer iswrite_b); reg c_aw_bw, c_aw_br, c_ar_bw; integer scaled_addra_to_waddrb_width; integer scaled_addrb_to_waddrb_width; integer scaled_addra_to_waddra_width; integer scaled_addrb_to_waddra_width; integer scaled_addra_to_raddrb_width; integer scaled_addrb_to_raddrb_width; integer scaled_addra_to_raddra_width; integer scaled_addrb_to_raddra_width; begin c_aw_bw = 0; c_aw_br = 0; c_ar_bw = 0; //If write_addr_b_width is smaller, scale both addresses to that width for //comparing write_addr_a and write_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to write_addr_b_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to write_addr_b_width. Once both are scaled to //write_addr_b_width, compare. scaled_addra_to_waddrb_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-write_addr_b_width)); scaled_addrb_to_waddrb_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-write_addr_b_width)); //If write_addr_a_width is smaller, scale both addresses to that width for //comparing write_addr_a and write_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to write_addr_a_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to write_addr_a_width. Once both are scaled to //write_addr_a_width, compare. scaled_addra_to_waddra_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-write_addr_a_width)); scaled_addrb_to_waddra_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-write_addr_a_width)); //If read_addr_b_width is smaller, scale both addresses to that width for //comparing write_addr_a and read_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to read_addr_b_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to read_addr_b_width. Once both are scaled to //read_addr_b_width, compare. scaled_addra_to_raddrb_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-read_addr_b_width)); scaled_addrb_to_raddrb_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-read_addr_b_width)); //If read_addr_a_width is smaller, scale both addresses to that width for //comparing read_addr_a and write_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to read_addr_a_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to read_addr_a_width. Once both are scaled to //read_addr_a_width, compare. scaled_addra_to_raddra_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-read_addr_a_width)); scaled_addrb_to_raddra_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-read_addr_a_width)); //Look for a write-write collision. In order for a write-write //collision to exist, both ports must have a write transaction. if (iswrite_a && iswrite_b) begin if (write_addr_a_width > write_addr_b_width) begin if (scaled_addra_to_waddrb_width == scaled_addrb_to_waddrb_width) begin c_aw_bw = 1; end else begin c_aw_bw = 0; end end else begin if (scaled_addrb_to_waddra_width == scaled_addra_to_waddra_width) begin c_aw_bw = 1; end else begin c_aw_bw = 0; end end //width end //iswrite_a and iswrite_b //If the B port is reading (which means it is enabled - so could be //a TX_WRITE or TX_READ), then check for a write-read collision). //This could happen whether or not a write-write collision exists due //to asymmetric write/read ports. if (iswrite_a) begin if (write_addr_a_width > read_addr_b_width) begin if (scaled_addra_to_raddrb_width == scaled_addrb_to_raddrb_width) begin c_aw_br = 1; end else begin c_aw_br = 0; end end else begin if (scaled_addrb_to_waddra_width == scaled_addra_to_waddra_width) begin c_aw_br = 1; end else begin c_aw_br = 0; end end //width end //iswrite_a //If the A port is reading (which means it is enabled - so could be // a TX_WRITE or TX_READ), then check for a write-read collision). //This could happen whether or not a write-write collision exists due // to asymmetric write/read ports. if (iswrite_b) begin if (read_addr_a_width > write_addr_b_width) begin if (scaled_addra_to_waddrb_width == scaled_addrb_to_waddrb_width) begin c_ar_bw = 1; end else begin c_ar_bw = 0; end end else begin if (scaled_addrb_to_raddra_width == scaled_addra_to_raddra_width) begin c_ar_bw = 1; end else begin c_ar_bw = 0; end end //width end //iswrite_b collision_check = c_aw_bw | c_aw_br | c_ar_bw; end endfunction //******************************* // power on values //******************************* initial begin // Load up the memory init_memory; // Load up the output registers and latches if ($sscanf(inita_str, "%h", inita_val)) begin memory_out_a = inita_val; end else begin memory_out_a = 0; end if ($sscanf(initb_str, "%h", initb_val)) begin memory_out_b = initb_val; end else begin memory_out_b = 0; end sbiterr_in = 1'b0; dbiterr_in = 1'b0; rdaddrecc_in = 0; // Determine the effective address widths for each of the 4 ports write_addr_a_width = C_ADDRA_WIDTH - log2roundup(WRITE_ADDR_A_DIV); read_addr_a_width = C_ADDRA_WIDTH - log2roundup(READ_ADDR_A_DIV); write_addr_b_width = C_ADDRB_WIDTH - log2roundup(WRITE_ADDR_B_DIV); read_addr_b_width = C_ADDRB_WIDTH - log2roundup(READ_ADDR_B_DIV); $display("Block Memory Generator module %m is using a behavioral model for simulation which will not precisely model memory collision behavior."); end //*************************************************************************** // These are the main blocks which schedule read and write operations // Note that the reset priority feature at the latch stage is only supported // for Spartan-6. For other families, the default priority at the latch stage // is "CE" //*************************************************************************** // Synchronous clocks: schedule port operations with respect to // both write operating modes generate if(C_COMMON_CLK && (C_WRITE_MODE_A == "WRITE_FIRST") && (C_WRITE_MODE_B == "WRITE_FIRST")) begin : com_clk_sched_wf_wf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A == "READ_FIRST") && (C_WRITE_MODE_B == "WRITE_FIRST")) begin : com_clk_sched_rf_wf always @(posedge CLKA) begin //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read B if (reb_i) read_b(ADDRB, resetb_i); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A == "WRITE_FIRST") && (C_WRITE_MODE_B == "READ_FIRST")) begin : com_clk_sched_wf_rf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A == "READ_FIRST") && (C_WRITE_MODE_B == "READ_FIRST")) begin : com_clk_sched_rf_rf always @(posedge CLKA) begin //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="WRITE_FIRST") && (C_WRITE_MODE_B == "NO_CHANGE")) begin : com_clk_sched_wf_nc always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="READ_FIRST") && (C_WRITE_MODE_B == "NO_CHANGE")) begin : com_clk_sched_rf_nc always @(posedge CLKA) begin //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="NO_CHANGE") && (C_WRITE_MODE_B == "WRITE_FIRST")) begin : com_clk_sched_nc_wf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="NO_CHANGE") && (C_WRITE_MODE_B == "READ_FIRST")) begin : com_clk_sched_nc_rf always @(posedge CLKA) begin //Read B if (reb_i) read_b(ADDRB, resetb_i); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="NO_CHANGE") && (C_WRITE_MODE_B == "NO_CHANGE")) begin : com_clk_sched_nc_nc always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); end end else if(C_COMMON_CLK) begin: com_clk_sched_default always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end endgenerate // Asynchronous clocks: port operation is independent generate if((!C_COMMON_CLK) && (C_WRITE_MODE_A == "WRITE_FIRST")) begin : async_clk_sched_clka_wf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i) read_a(ADDRA, reseta_i); end end else if((!C_COMMON_CLK) && (C_WRITE_MODE_A == "READ_FIRST")) begin : async_clk_sched_clka_rf always @(posedge CLKA) begin //Read A if (rea_i) read_a(ADDRA, reseta_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); end end else if((!C_COMMON_CLK) && (C_WRITE_MODE_A == "NO_CHANGE")) begin : async_clk_sched_clka_nc always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); end end endgenerate generate if ((!C_COMMON_CLK) && (C_WRITE_MODE_B == "WRITE_FIRST")) begin: async_clk_sched_clkb_wf always @(posedge CLKB) begin //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end else if ((!C_COMMON_CLK) && (C_WRITE_MODE_B == "READ_FIRST")) begin: async_clk_sched_clkb_rf always @(posedge CLKB) begin //Read B if (reb_i) read_b(ADDRB, resetb_i); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if ((!C_COMMON_CLK) && (C_WRITE_MODE_B == "NO_CHANGE")) begin: async_clk_sched_clkb_nc always @(posedge CLKB) begin //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); end end endgenerate //*************************************************************** // Instantiate the variable depth output register stage module //*************************************************************** // Port A assign rsta_outp_stage = RSTA & (~SLEEP); blk_mem_gen_v8_3_3_output_stage #(.C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_RST_TYPE ("SYNC"), .C_HAS_RST (C_HAS_RSTA), .C_RSTRAM (C_RSTRAM_A), .C_RST_PRIORITY (C_RST_PRIORITY_A), .C_INIT_VAL (C_INITA_VAL), .C_HAS_EN (C_HAS_ENA), .C_HAS_REGCE (C_HAS_REGCEA), .C_DATA_WIDTH (C_READ_WIDTH_A), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS (C_HAS_MEM_OUTPUT_REGS_A), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .NUM_STAGES (NUM_OUTPUT_STAGES_A), .C_EN_ECC_PIPE (0), .FLOP_DELAY (FLOP_DELAY)) reg_a (.CLK (CLKA), .RST (rsta_outp_stage),//(RSTA), .EN (ENA), .REGCE (REGCEA), .DIN_I (memory_out_a), .DOUT (DOUTA), .SBITERR_IN_I (1'b0), .DBITERR_IN_I (1'b0), .SBITERR (), .DBITERR (), .RDADDRECC_IN_I ({C_ADDRB_WIDTH{1'b0}}), .ECCPIPECE (1'b0), .RDADDRECC () ); assign rstb_outp_stage = RSTB & (~SLEEP); // Port B blk_mem_gen_v8_3_3_output_stage #(.C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_RST_TYPE ("SYNC"), .C_HAS_RST (C_HAS_RSTB), .C_RSTRAM (C_RSTRAM_B), .C_RST_PRIORITY (C_RST_PRIORITY_B), .C_INIT_VAL (C_INITB_VAL), .C_HAS_EN (C_HAS_ENB), .C_HAS_REGCE (C_HAS_REGCEB), .C_DATA_WIDTH (C_READ_WIDTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS (C_HAS_MEM_OUTPUT_REGS_B), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .NUM_STAGES (NUM_OUTPUT_STAGES_B), .C_EN_ECC_PIPE (C_EN_ECC_PIPE), .FLOP_DELAY (FLOP_DELAY)) reg_b (.CLK (CLKB), .RST (rstb_outp_stage),//(RSTB), .EN (ENB), .REGCE (REGCEB), .DIN_I (memory_out_b), .DOUT (dout_i), .SBITERR_IN_I (sbiterr_in), .DBITERR_IN_I (dbiterr_in), .SBITERR (sbiterr_i), .DBITERR (dbiterr_i), .RDADDRECC_IN_I (rdaddrecc_in), .ECCPIPECE (ECCPIPECE), .RDADDRECC (rdaddrecc_i) ); //*************************************************************** // Instantiate the Input and Output register stages //*************************************************************** blk_mem_gen_v8_3_3_softecc_output_reg_stage #(.C_DATA_WIDTH (C_READ_WIDTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_USE_SOFTECC (C_USE_SOFTECC), .FLOP_DELAY (FLOP_DELAY)) has_softecc_output_reg_stage (.CLK (CLKB), .DIN (dout_i), .DOUT (DOUTB), .SBITERR_IN (sbiterr_i), .DBITERR_IN (dbiterr_i), .SBITERR (sbiterr_sdp), .DBITERR (dbiterr_sdp), .RDADDRECC_IN (rdaddrecc_i), .RDADDRECC (rdaddrecc_sdp) ); //**************************************************** // Synchronous collision checks //**************************************************** // CR 780544 : To make verilog model's collison warnings in consistant with // vhdl model, the non-blocking assignments are replaced with blocking // assignments. generate if (!C_DISABLE_WARN_BHV_COLL && C_COMMON_CLK) begin : sync_coll always @(posedge CLKA) begin // Possible collision if both are enabled and the addresses match if (ena_i && enb_i) begin if (wea_i || web_i) begin is_collision = collision_check(ADDRA, wea_i, ADDRB, web_i); end else begin is_collision = 0; end end else begin is_collision = 0; end // If the write port is in READ_FIRST mode, there is no collision if (C_WRITE_MODE_A=="READ_FIRST" && wea_i && !web_i) begin is_collision = 0; end if (C_WRITE_MODE_B=="READ_FIRST" && web_i && !wea_i) begin is_collision = 0; end // Only flag if one of the accesses is a write if (is_collision && (wea_i || web_i)) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A %0s address: %0h, B %0s address: %0h\n", wea_i ? "write" : "read", ADDRA, web_i ? "write" : "read", ADDRB); end end //**************************************************** // Asynchronous collision checks //**************************************************** end else if (!C_DISABLE_WARN_BHV_COLL && !C_COMMON_CLK) begin : async_coll // Delay A and B addresses in order to mimic setup/hold times wire [C_ADDRA_WIDTH-1:0] #COLL_DELAY addra_delay = ADDRA; wire [0:0] #COLL_DELAY wea_delay = wea_i; wire #COLL_DELAY ena_delay = ena_i; wire [C_ADDRB_WIDTH-1:0] #COLL_DELAY addrb_delay = ADDRB; wire [0:0] #COLL_DELAY web_delay = web_i; wire #COLL_DELAY enb_delay = enb_i; // Do the checks w/rt A always @(posedge CLKA) begin // Possible collision if both are enabled and the addresses match if (ena_i && enb_i) begin if (wea_i || web_i) begin is_collision_a = collision_check(ADDRA, wea_i, ADDRB, web_i); end else begin is_collision_a = 0; end end else begin is_collision_a = 0; end if (ena_i && enb_delay) begin if(wea_i || web_delay) begin is_collision_delay_a = collision_check(ADDRA, wea_i, addrb_delay, web_delay); end else begin is_collision_delay_a = 0; end end else begin is_collision_delay_a = 0; end // Only flag if B access is a write if (is_collision_a && web_i) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A %0s address: %0h, B write address: %0h\n", wea_i ? "write" : "read", ADDRA, ADDRB); end else if (is_collision_delay_a && web_delay) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A %0s address: %0h, B write address: %0h\n", wea_i ? "write" : "read", ADDRA, addrb_delay); end end // Do the checks w/rt B always @(posedge CLKB) begin // Possible collision if both are enabled and the addresses match if (ena_i && enb_i) begin if (wea_i || web_i) begin is_collision_b = collision_check(ADDRA, wea_i, ADDRB, web_i); end else begin is_collision_b = 0; end end else begin is_collision_b = 0; end if (ena_delay && enb_i) begin if (wea_delay || web_i) begin is_collision_delay_b = collision_check(addra_delay, wea_delay, ADDRB, web_i); end else begin is_collision_delay_b = 0; end end else begin is_collision_delay_b = 0; end // Only flag if A access is a write if (is_collision_b && wea_i) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A write address: %0h, B %s address: %0h\n", ADDRA, web_i ? "write" : "read", ADDRB); end else if (is_collision_delay_b && wea_delay) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A write address: %0h, B %s address: %0h\n", addra_delay, web_i ? "write" : "read", ADDRB); end end end endgenerate endmodule //***************************************************************************** // Top module wraps Input register and Memory module // // This module is the top-level behavioral model and this implements the memory // module and the input registers //***************************************************************************** module blk_mem_gen_v8_3_3 #(parameter C_CORENAME = "blk_mem_gen_v8_3_3", parameter C_FAMILY = "virtex7", parameter C_XDEVICEFAMILY = "virtex7", parameter C_ELABORATION_DIR = "", parameter C_INTERFACE_TYPE = 0, parameter C_USE_BRAM_BLOCK = 0, parameter C_CTRL_ECC_ALGO = "NONE", parameter C_ENABLE_32BIT_ADDRESS = 0, parameter C_AXI_TYPE = 0, parameter C_AXI_SLAVE_TYPE = 0, parameter C_HAS_AXI_ID = 0, parameter C_AXI_ID_WIDTH = 4, parameter C_MEM_TYPE = 2, parameter C_BYTE_SIZE = 9, parameter C_ALGORITHM = 1, parameter C_PRIM_TYPE = 3, parameter C_LOAD_INIT_FILE = 0, parameter C_INIT_FILE_NAME = "", parameter C_INIT_FILE = "", parameter C_USE_DEFAULT_DATA = 0, parameter C_DEFAULT_DATA = "0", //parameter C_RST_TYPE = "SYNC", parameter C_HAS_RSTA = 0, parameter C_RST_PRIORITY_A = "CE", parameter C_RSTRAM_A = 0, parameter C_INITA_VAL = "0", parameter C_HAS_ENA = 1, parameter C_HAS_REGCEA = 0, parameter C_USE_BYTE_WEA = 0, parameter C_WEA_WIDTH = 1, parameter C_WRITE_MODE_A = "WRITE_FIRST", parameter C_WRITE_WIDTH_A = 32, parameter C_READ_WIDTH_A = 32, parameter C_WRITE_DEPTH_A = 64, parameter C_READ_DEPTH_A = 64, parameter C_ADDRA_WIDTH = 5, parameter C_HAS_RSTB = 0, parameter C_RST_PRIORITY_B = "CE", parameter C_RSTRAM_B = 0, parameter C_INITB_VAL = "", parameter C_HAS_ENB = 1, parameter C_HAS_REGCEB = 0, parameter C_USE_BYTE_WEB = 0, parameter C_WEB_WIDTH = 1, parameter C_WRITE_MODE_B = "WRITE_FIRST", parameter C_WRITE_WIDTH_B = 32, parameter C_READ_WIDTH_B = 32, parameter C_WRITE_DEPTH_B = 64, parameter C_READ_DEPTH_B = 64, parameter C_ADDRB_WIDTH = 5, parameter C_HAS_MEM_OUTPUT_REGS_A = 0, parameter C_HAS_MEM_OUTPUT_REGS_B = 0, parameter C_HAS_MUX_OUTPUT_REGS_A = 0, parameter C_HAS_MUX_OUTPUT_REGS_B = 0, parameter C_HAS_SOFTECC_INPUT_REGS_A = 0, parameter C_HAS_SOFTECC_OUTPUT_REGS_B= 0, parameter C_MUX_PIPELINE_STAGES = 0, parameter C_USE_SOFTECC = 0, parameter C_USE_ECC = 0, parameter C_EN_ECC_PIPE = 0, parameter C_HAS_INJECTERR = 0, parameter C_SIM_COLLISION_CHECK = "NONE", parameter C_COMMON_CLK = 1, parameter C_DISABLE_WARN_BHV_COLL = 0, parameter C_EN_SLEEP_PIN = 0, parameter C_USE_URAM = 0, parameter C_EN_RDADDRA_CHG = 0, parameter C_EN_RDADDRB_CHG = 0, parameter C_EN_DEEPSLEEP_PIN = 0, parameter C_EN_SHUTDOWN_PIN = 0, parameter C_EN_SAFETY_CKT = 0, parameter C_COUNT_36K_BRAM = "", parameter C_COUNT_18K_BRAM = "", parameter C_EST_POWER_SUMMARY = "", parameter C_DISABLE_WARN_BHV_RANGE = 0 ) (input clka, input rsta, input ena, input regcea, input [C_WEA_WIDTH-1:0] wea, input [C_ADDRA_WIDTH-1:0] addra, input [C_WRITE_WIDTH_A-1:0] dina, output [C_READ_WIDTH_A-1:0] douta, input clkb, input rstb, input enb, input regceb, input [C_WEB_WIDTH-1:0] web, input [C_ADDRB_WIDTH-1:0] addrb, input [C_WRITE_WIDTH_B-1:0] dinb, output [C_READ_WIDTH_B-1:0] doutb, input injectsbiterr, input injectdbiterr, output sbiterr, output dbiterr, output [C_ADDRB_WIDTH-1:0] rdaddrecc, input eccpipece, input sleep, input deepsleep, input shutdown, output rsta_busy, output rstb_busy, //AXI BMG Input and Output Port Declarations //AXI Global Signals input s_aclk, input s_aresetn, //AXI Full/lite slave write (write side) input [C_AXI_ID_WIDTH-1:0] s_axi_awid, input [31:0] s_axi_awaddr, input [7:0] s_axi_awlen, input [2:0] s_axi_awsize, input [1:0] s_axi_awburst, input s_axi_awvalid, output s_axi_awready, input [C_WRITE_WIDTH_A-1:0] s_axi_wdata, input [C_WEA_WIDTH-1:0] s_axi_wstrb, input s_axi_wlast, input s_axi_wvalid, output s_axi_wready, output [C_AXI_ID_WIDTH-1:0] s_axi_bid, output [1:0] s_axi_bresp, output s_axi_bvalid, input s_axi_bready, //AXI Full/lite slave read (write side) input [C_AXI_ID_WIDTH-1:0] s_axi_arid, input [31:0] s_axi_araddr, input [7:0] s_axi_arlen, input [2:0] s_axi_arsize, input [1:0] s_axi_arburst, input s_axi_arvalid, output s_axi_arready, output [C_AXI_ID_WIDTH-1:0] s_axi_rid, output [C_WRITE_WIDTH_B-1:0] s_axi_rdata, output [1:0] s_axi_rresp, output s_axi_rlast, output s_axi_rvalid, input s_axi_rready, //AXI Full/lite sideband signals input s_axi_injectsbiterr, input s_axi_injectdbiterr, output s_axi_sbiterr, output s_axi_dbiterr, output [C_ADDRB_WIDTH-1:0] s_axi_rdaddrecc ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_CORENAME : Instance name of the Block Memory Generator core // C_FAMILY,C_XDEVICEFAMILY: Designates architecture targeted. The following // options are available - "spartan3", "spartan6", // "virtex4", "virtex5", "virtex6" and "virtex6l". // C_MEM_TYPE : Designates memory type. // It can be // 0 - Single Port Memory // 1 - Simple Dual Port Memory // 2 - True Dual Port Memory // 3 - Single Port Read Only Memory // 4 - Dual Port Read Only Memory // C_BYTE_SIZE : Size of a byte (8 or 9 bits) // C_ALGORITHM : Designates the algorithm method used // for constructing the memory. // It can be Fixed_Primitives, Minimum_Area or // Low_Power // C_PRIM_TYPE : Designates the user selected primitive used to // construct the memory. // // C_LOAD_INIT_FILE : Designates the use of an initialization file to // initialize memory contents. // C_INIT_FILE_NAME : Memory initialization file name. // C_USE_DEFAULT_DATA : Designates whether to fill remaining // initialization space with default data // C_DEFAULT_DATA : Default value of all memory locations // not initialized by the memory // initialization file. // C_RST_TYPE : Type of reset - Synchronous or Asynchronous // C_HAS_RSTA : Determines the presence of the RSTA port // C_RST_PRIORITY_A : Determines the priority between CE and SR for // Port A. // C_RSTRAM_A : Determines if special reset behavior is used for // Port A // C_INITA_VAL : The initialization value for Port A // C_HAS_ENA : Determines the presence of the ENA port // C_HAS_REGCEA : Determines the presence of the REGCEA port // C_USE_BYTE_WEA : Determines if the Byte Write is used or not. // C_WEA_WIDTH : The width of the WEA port // C_WRITE_MODE_A : Configurable write mode for Port A. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_A : Memory write width for Port A. // C_READ_WIDTH_A : Memory read width for Port A. // C_WRITE_DEPTH_A : Memory write depth for Port A. // C_READ_DEPTH_A : Memory read depth for Port A. // C_ADDRA_WIDTH : Width of the ADDRA input port // C_HAS_RSTB : Determines the presence of the RSTB port // C_RST_PRIORITY_B : Determines the priority between CE and SR for // Port B. // C_RSTRAM_B : Determines if special reset behavior is used for // Port B // C_INITB_VAL : The initialization value for Port B // C_HAS_ENB : Determines the presence of the ENB port // C_HAS_REGCEB : Determines the presence of the REGCEB port // C_USE_BYTE_WEB : Determines if the Byte Write is used or not. // C_WEB_WIDTH : The width of the WEB port // C_WRITE_MODE_B : Configurable write mode for Port B. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_B : Memory write width for Port B. // C_READ_WIDTH_B : Memory read width for Port B. // C_WRITE_DEPTH_B : Memory write depth for Port B. // C_READ_DEPTH_B : Memory read depth for Port B. // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_MEM_OUTPUT_REGS_A : Designates the use of a register at the output // of the RAM primitive for Port A. // C_HAS_MEM_OUTPUT_REGS_B : Designates the use of a register at the output // of the RAM primitive for Port B. // C_HAS_MUX_OUTPUT_REGS_A : Designates the use of a register at the output // of the MUX for Port A. // C_HAS_MUX_OUTPUT_REGS_B : Designates the use of a register at the output // of the MUX for Port B. // C_HAS_SOFTECC_INPUT_REGS_A : // C_HAS_SOFTECC_OUTPUT_REGS_B : // C_MUX_PIPELINE_STAGES : Designates the number of pipeline stages in // between the muxes. // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // C_USE_ECC : Determines if the ECC feature is used or // not. Only applicable for V5 and V6 // C_HAS_INJECTERR : Determines if the error injection pins // are present or not. If the ECC feature // is not used, this value is defaulted to // 0, else the following are the allowed // values: // 0 : No INJECTSBITERR or INJECTDBITERR pins // 1 : Only INJECTSBITERR pin exists // 2 : Only INJECTDBITERR pin exists // 3 : Both INJECTSBITERR and INJECTDBITERR pins exist // C_SIM_COLLISION_CHECK : Controls the disabling of Unisim model collision // warnings. It can be "ALL", "NONE", // "Warnings_Only" or "Generate_X_Only". // C_COMMON_CLK : Determins if the core has a single CLK input. // C_DISABLE_WARN_BHV_COLL : Controls the Behavioral Model Collision warnings // C_DISABLE_WARN_BHV_RANGE: Controls the Behavioral Model Out of Range // warnings ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLKA : Clock to synchronize all read and write operations of Port A. // RSTA : Reset input to reset memory outputs to a user-defined // reset state for Port A. // ENA : Enable all read and write operations of Port A. // REGCEA : Register Clock Enable to control each pipeline output // register stages for Port A. // WEA : Write Enable to enable all write operations of Port A. // ADDRA : Address of Port A. // DINA : Data input of Port A. // DOUTA : Data output of Port A. // CLKB : Clock to synchronize all read and write operations of Port B. // RSTB : Reset input to reset memory outputs to a user-defined // reset state for Port B. // ENB : Enable all read and write operations of Port B. // REGCEB : Register Clock Enable to control each pipeline output // register stages for Port B. // WEB : Write Enable to enable all write operations of Port B. // ADDRB : Address of Port B. // DINB : Data input of Port B. // DOUTB : Data output of Port B. // INJECTSBITERR : Single Bit ECC Error Injection Pin. // INJECTDBITERR : Double Bit ECC Error Injection Pin. // SBITERR : Output signal indicating that a Single Bit ECC Error has been // detected and corrected. // DBITERR : Output signal indicating that a Double Bit ECC Error has been // detected. // RDADDRECC : Read Address Output signal indicating address at which an // ECC error has occurred. ////////////////////////////////////////////////////////////////////////// wire SBITERR; wire DBITERR; wire S_AXI_AWREADY; wire S_AXI_WREADY; wire S_AXI_BVALID; wire S_AXI_ARREADY; wire S_AXI_RLAST; wire S_AXI_RVALID; wire S_AXI_SBITERR; wire S_AXI_DBITERR; wire [C_WEA_WIDTH-1:0] WEA = wea; wire [C_ADDRA_WIDTH-1:0] ADDRA = addra; wire [C_WRITE_WIDTH_A-1:0] DINA = dina; wire [C_READ_WIDTH_A-1:0] DOUTA; wire [C_WEB_WIDTH-1:0] WEB = web; wire [C_ADDRB_WIDTH-1:0] ADDRB = addrb; wire [C_WRITE_WIDTH_B-1:0] DINB = dinb; wire [C_READ_WIDTH_B-1:0] DOUTB; wire [C_ADDRB_WIDTH-1:0] RDADDRECC; wire [C_AXI_ID_WIDTH-1:0] S_AXI_AWID = s_axi_awid; wire [31:0] S_AXI_AWADDR = s_axi_awaddr; wire [7:0] S_AXI_AWLEN = s_axi_awlen; wire [2:0] S_AXI_AWSIZE = s_axi_awsize; wire [1:0] S_AXI_AWBURST = s_axi_awburst; wire [C_WRITE_WIDTH_A-1:0] S_AXI_WDATA = s_axi_wdata; wire [C_WEA_WIDTH-1:0] S_AXI_WSTRB = s_axi_wstrb; wire [C_AXI_ID_WIDTH-1:0] S_AXI_BID; wire [1:0] S_AXI_BRESP; wire [C_AXI_ID_WIDTH-1:0] S_AXI_ARID = s_axi_arid; wire [31:0] S_AXI_ARADDR = s_axi_araddr; wire [7:0] S_AXI_ARLEN = s_axi_arlen; wire [2:0] S_AXI_ARSIZE = s_axi_arsize; wire [1:0] S_AXI_ARBURST = s_axi_arburst; wire [C_AXI_ID_WIDTH-1:0] S_AXI_RID; wire [C_WRITE_WIDTH_B-1:0] S_AXI_RDATA; wire [1:0] S_AXI_RRESP; wire [C_ADDRB_WIDTH-1:0] S_AXI_RDADDRECC; // Added to fix the simulation warning #CR731605 wire [C_WEB_WIDTH-1:0] WEB_parameterized = 0; wire ECCPIPECE; wire SLEEP; reg RSTA_BUSY = 0; reg RSTB_BUSY = 0; // Declaration of internal signals to avoid warnings #927399 wire CLKA; wire RSTA; wire ENA; wire REGCEA; wire CLKB; wire RSTB; wire ENB; wire REGCEB; wire INJECTSBITERR; wire INJECTDBITERR; wire S_ACLK; wire S_ARESETN; wire S_AXI_AWVALID; wire S_AXI_WLAST; wire S_AXI_WVALID; wire S_AXI_BREADY; wire S_AXI_ARVALID; wire S_AXI_RREADY; wire S_AXI_INJECTSBITERR; wire S_AXI_INJECTDBITERR; assign CLKA = clka; assign RSTA = rsta; assign ENA = ena; assign REGCEA = regcea; assign CLKB = clkb; assign RSTB = rstb; assign ENB = enb; assign REGCEB = regceb; assign INJECTSBITERR = injectsbiterr; assign INJECTDBITERR = injectdbiterr; assign ECCPIPECE = eccpipece; assign SLEEP = sleep; assign sbiterr = SBITERR; assign dbiterr = DBITERR; assign S_ACLK = s_aclk; assign S_ARESETN = s_aresetn; assign S_AXI_AWVALID = s_axi_awvalid; assign s_axi_awready = S_AXI_AWREADY; assign S_AXI_WLAST = s_axi_wlast; assign S_AXI_WVALID = s_axi_wvalid; assign s_axi_wready = S_AXI_WREADY; assign s_axi_bvalid = S_AXI_BVALID; assign S_AXI_BREADY = s_axi_bready; assign S_AXI_ARVALID = s_axi_arvalid; assign s_axi_arready = S_AXI_ARREADY; assign s_axi_rlast = S_AXI_RLAST; assign s_axi_rvalid = S_AXI_RVALID; assign S_AXI_RREADY = s_axi_rready; assign S_AXI_INJECTSBITERR = s_axi_injectsbiterr; assign S_AXI_INJECTDBITERR = s_axi_injectdbiterr; assign s_axi_sbiterr = S_AXI_SBITERR; assign s_axi_dbiterr = S_AXI_DBITERR; assign rsta_busy = RSTA_BUSY; assign rstb_busy = RSTB_BUSY; assign doutb = DOUTB; assign douta = DOUTA; assign rdaddrecc = RDADDRECC; assign s_axi_bid = S_AXI_BID; assign s_axi_bresp = S_AXI_BRESP; assign s_axi_rid = S_AXI_RID; assign s_axi_rdata = S_AXI_RDATA; assign s_axi_rresp = S_AXI_RRESP; assign s_axi_rdaddrecc = S_AXI_RDADDRECC; localparam FLOP_DELAY = 100; // 100 ps reg injectsbiterr_in; reg injectdbiterr_in; reg rsta_in; reg ena_in; reg regcea_in; reg [C_WEA_WIDTH-1:0] wea_in; reg [C_ADDRA_WIDTH-1:0] addra_in; reg [C_WRITE_WIDTH_A-1:0] dina_in; wire [C_ADDRA_WIDTH-1:0] s_axi_awaddr_out_c; wire [C_ADDRB_WIDTH-1:0] s_axi_araddr_out_c; wire s_axi_wr_en_c; wire s_axi_rd_en_c; wire s_aresetn_a_c; wire [7:0] s_axi_arlen_c ; wire [C_AXI_ID_WIDTH-1 : 0] s_axi_rid_c; wire [C_WRITE_WIDTH_B-1 : 0] s_axi_rdata_c; wire [1:0] s_axi_rresp_c; wire s_axi_rlast_c; wire s_axi_rvalid_c; wire s_axi_rready_c; wire regceb_c; localparam C_AXI_PAYLOAD = (C_HAS_MUX_OUTPUT_REGS_B == 1)?C_WRITE_WIDTH_B+C_AXI_ID_WIDTH+3:C_AXI_ID_WIDTH+3; wire [C_AXI_PAYLOAD-1 : 0] s_axi_payload_c; wire [C_AXI_PAYLOAD-1 : 0] m_axi_payload_c; // Safety logic related signals reg [4:0] RSTA_SHFT_REG = 0; reg POR_A = 0; reg [4:0] RSTB_SHFT_REG = 0; reg POR_B = 0; reg ENA_dly = 0; reg ENA_dly_D = 0; reg ENB_dly = 0; reg ENB_dly_D = 0; wire RSTA_I_SAFE; wire RSTB_I_SAFE; wire ENA_I_SAFE; wire ENB_I_SAFE; reg ram_rstram_a_busy = 0; reg ram_rstreg_a_busy = 0; reg ram_rstram_b_busy = 0; reg ram_rstreg_b_busy = 0; reg ENA_dly_reg = 0; reg ENB_dly_reg = 0; reg ENA_dly_reg_D = 0; reg ENB_dly_reg_D = 0; //************** // log2roundup //************** function integer log2roundup (input integer data_value); integer width; integer cnt; begin width = 0; if (data_value > 1) begin for(cnt=1 ; cnt < data_value ; cnt = cnt * 2) begin width = width + 1; end //loop end //if log2roundup = width; end //log2roundup endfunction //************** // log2int //************** function integer log2int (input integer data_value); integer width; integer cnt; begin width = 0; cnt= data_value; for(cnt=data_value ; cnt >1 ; cnt = cnt / 2) begin width = width + 1; end //loop log2int = width; end //log2int endfunction //************************************************************************** // FUNCTION : divroundup // Returns the ceiling value of the division // Data_value - the quantity to be divided, dividend // Divisor - the value to divide the data_value by //************************************************************************** function integer divroundup (input integer data_value,input integer divisor); integer div; begin div = data_value/divisor; if ((data_value % divisor) != 0) begin div = div+1; end //if divroundup = div; end //if endfunction localparam AXI_FULL_MEMORY_SLAVE = ((C_AXI_SLAVE_TYPE == 0 && C_AXI_TYPE == 1)?1:0); localparam C_AXI_ADDR_WIDTH_MSB = C_ADDRA_WIDTH+log2roundup(C_WRITE_WIDTH_A/8); localparam C_AXI_ADDR_WIDTH = C_AXI_ADDR_WIDTH_MSB; //Data Width Number of LSB address bits to be discarded //1 to 16 1 //17 to 32 2 //33 to 64 3 //65 to 128 4 //129 to 256 5 //257 to 512 6 //513 to 1024 7 // The following two constants determine this. localparam LOWER_BOUND_VAL = (log2roundup(divroundup(C_WRITE_WIDTH_A,8) == 0))?0:(log2roundup(divroundup(C_WRITE_WIDTH_A,8))); localparam C_AXI_ADDR_WIDTH_LSB = ((AXI_FULL_MEMORY_SLAVE == 1)?0:LOWER_BOUND_VAL); localparam C_AXI_OS_WR = 2; //*********************************************** // INPUT REGISTERS. //*********************************************** generate if (C_HAS_SOFTECC_INPUT_REGS_A==0) begin : no_softecc_input_reg_stage always @* begin injectsbiterr_in = INJECTSBITERR; injectdbiterr_in = INJECTDBITERR; rsta_in = RSTA; ena_in = ENA; regcea_in = REGCEA; wea_in = WEA; addra_in = ADDRA; dina_in = DINA; end //end always end //end no_softecc_input_reg_stage endgenerate generate if (C_HAS_SOFTECC_INPUT_REGS_A==1) begin : has_softecc_input_reg_stage always @(posedge CLKA) begin injectsbiterr_in <= #FLOP_DELAY INJECTSBITERR; injectdbiterr_in <= #FLOP_DELAY INJECTDBITERR; rsta_in <= #FLOP_DELAY RSTA; ena_in <= #FLOP_DELAY ENA; regcea_in <= #FLOP_DELAY REGCEA; wea_in <= #FLOP_DELAY WEA; addra_in <= #FLOP_DELAY ADDRA; dina_in <= #FLOP_DELAY DINA; end //end always end //end input_reg_stages generate statement endgenerate //************************************************************************** // NO SAFETY LOGIC //************************************************************************** generate if (C_EN_SAFETY_CKT == 0) begin : NO_SAFETY_CKT_GEN assign ENA_I_SAFE = ena_in; assign ENB_I_SAFE = ENB; assign RSTA_I_SAFE = rsta_in; assign RSTB_I_SAFE = RSTB; end endgenerate //*************************************************************************** // SAFETY LOGIC // Power-ON Reset Generation //*************************************************************************** generate if (C_EN_SAFETY_CKT == 1) begin always @(posedge clka) RSTA_SHFT_REG <= #FLOP_DELAY {RSTA_SHFT_REG[3:0],1'b1} ; always @(posedge clka) POR_A <= #FLOP_DELAY RSTA_SHFT_REG[4] ^ RSTA_SHFT_REG[0]; always @(posedge clkb) RSTB_SHFT_REG <= #FLOP_DELAY {RSTB_SHFT_REG[3:0],1'b1} ; always @(posedge clkb) POR_B <= #FLOP_DELAY RSTB_SHFT_REG[4] ^ RSTB_SHFT_REG[0]; assign RSTA_I_SAFE = rsta_in | POR_A; assign RSTB_I_SAFE = (C_MEM_TYPE == 0 || C_MEM_TYPE == 3) ? 1'b0 : (RSTB | POR_B); end endgenerate //----------------------------------------------------------------------------- // -- RSTA/B_BUSY Generation //----------------------------------------------------------------------------- generate if ((C_HAS_MEM_OUTPUT_REGS_A==0 || (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==1)) && (C_EN_SAFETY_CKT == 1)) begin : RSTA_BUSY_NO_REG always @(*) ram_rstram_a_busy = RSTA_I_SAFE | ENA_dly | ENA_dly_D; always @(posedge clka) RSTA_BUSY <= #FLOP_DELAY ram_rstram_a_busy; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==0 && C_EN_SAFETY_CKT == 1) begin : RSTA_BUSY_WITH_REG always @(*) ram_rstreg_a_busy = RSTA_I_SAFE | ENA_dly_reg | ENA_dly_reg_D; always @(posedge clka) RSTA_BUSY <= #FLOP_DELAY ram_rstreg_a_busy; end endgenerate generate if ( (C_MEM_TYPE == 0 || C_MEM_TYPE == 3) && C_EN_SAFETY_CKT == 1) begin : SPRAM_RST_BUSY always @(*) RSTB_BUSY = 1'b0; end endgenerate generate if ( (C_HAS_MEM_OUTPUT_REGS_B==0 || (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==1)) && (C_MEM_TYPE != 0 && C_MEM_TYPE != 3) && C_EN_SAFETY_CKT == 1) begin : RSTB_BUSY_NO_REG always @(*) ram_rstram_b_busy = RSTB_I_SAFE | ENB_dly | ENB_dly_D; always @(posedge clkb) RSTB_BUSY <= #FLOP_DELAY ram_rstram_b_busy; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==0 && C_MEM_TYPE != 0 && C_MEM_TYPE != 3 && C_EN_SAFETY_CKT == 1) begin : RSTB_BUSY_WITH_REG always @(*) ram_rstreg_b_busy = RSTB_I_SAFE | ENB_dly_reg | ENB_dly_reg_D; always @(posedge clkb) RSTB_BUSY <= #FLOP_DELAY ram_rstreg_b_busy; end endgenerate //----------------------------------------------------------------------------- // -- ENA/ENB Generation //----------------------------------------------------------------------------- generate if ((C_HAS_MEM_OUTPUT_REGS_A==0 || (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==1)) && C_EN_SAFETY_CKT == 1) begin : ENA_NO_REG always @(posedge clka) begin ENA_dly <= #FLOP_DELAY RSTA_I_SAFE; ENA_dly_D <= #FLOP_DELAY ENA_dly; end assign ENA_I_SAFE = (C_HAS_ENA == 0)? 1'b1 : (ENA_dly_D | ena_in); end endgenerate generate if ( (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==0) && C_EN_SAFETY_CKT == 1) begin : ENA_WITH_REG always @(posedge clka) begin ENA_dly_reg <= #FLOP_DELAY RSTA_I_SAFE; ENA_dly_reg_D <= #FLOP_DELAY ENA_dly_reg; end assign ENA_I_SAFE = (C_HAS_ENA == 0)? 1'b1 : (ENA_dly_reg_D | ena_in); end endgenerate generate if (C_MEM_TYPE == 0 || C_MEM_TYPE == 3) begin : SPRAM_ENB assign ENB_I_SAFE = 1'b0; end endgenerate generate if ((C_HAS_MEM_OUTPUT_REGS_B==0 || (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==1)) && C_MEM_TYPE != 0 && C_MEM_TYPE != 3 && C_EN_SAFETY_CKT == 1) begin : ENB_NO_REG always @(posedge clkb) begin : PROC_ENB_GEN ENB_dly <= #FLOP_DELAY RSTB_I_SAFE; ENB_dly_D <= #FLOP_DELAY ENB_dly; end assign ENB_I_SAFE = (C_HAS_ENB == 0)? 1'b1 : (ENB_dly_D | ENB); end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==0 && C_MEM_TYPE != 0 && C_MEM_TYPE != 3 && C_EN_SAFETY_CKT == 1)begin : ENB_WITH_REG always @(posedge clkb) begin : PROC_ENB_GEN ENB_dly_reg <= #FLOP_DELAY RSTB_I_SAFE; ENB_dly_reg_D <= #FLOP_DELAY ENB_dly_reg; end assign ENB_I_SAFE = (C_HAS_ENB == 0)? 1'b1 : (ENB_dly_reg_D | ENB); end endgenerate generate if ((C_INTERFACE_TYPE == 0) && (C_ENABLE_32BIT_ADDRESS == 0)) begin : native_mem_module blk_mem_gen_v8_3_3_mem_module #(.C_CORENAME (C_CORENAME), .C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_MEM_TYPE (C_MEM_TYPE), .C_BYTE_SIZE (C_BYTE_SIZE), .C_ALGORITHM (C_ALGORITHM), .C_USE_BRAM_BLOCK (C_USE_BRAM_BLOCK), .C_PRIM_TYPE (C_PRIM_TYPE), .C_LOAD_INIT_FILE (C_LOAD_INIT_FILE), .C_INIT_FILE_NAME (C_INIT_FILE_NAME), .C_INIT_FILE (C_INIT_FILE), .C_USE_DEFAULT_DATA (C_USE_DEFAULT_DATA), .C_DEFAULT_DATA (C_DEFAULT_DATA), .C_RST_TYPE ("SYNC"), .C_HAS_RSTA (C_HAS_RSTA), .C_RST_PRIORITY_A (C_RST_PRIORITY_A), .C_RSTRAM_A (C_RSTRAM_A), .C_INITA_VAL (C_INITA_VAL), .C_HAS_ENA (C_HAS_ENA), .C_HAS_REGCEA (C_HAS_REGCEA), .C_USE_BYTE_WEA (C_USE_BYTE_WEA), .C_WEA_WIDTH (C_WEA_WIDTH), .C_WRITE_MODE_A (C_WRITE_MODE_A), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_READ_WIDTH_A (C_READ_WIDTH_A), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_READ_DEPTH_A (C_READ_DEPTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_HAS_RSTB (C_HAS_RSTB), .C_RST_PRIORITY_B (C_RST_PRIORITY_B), .C_RSTRAM_B (C_RSTRAM_B), .C_INITB_VAL (C_INITB_VAL), .C_HAS_ENB (C_HAS_ENB), .C_HAS_REGCEB (C_HAS_REGCEB), .C_USE_BYTE_WEB (C_USE_BYTE_WEB), .C_WEB_WIDTH (C_WEB_WIDTH), .C_WRITE_MODE_B (C_WRITE_MODE_B), .C_WRITE_WIDTH_B (C_WRITE_WIDTH_B), .C_READ_WIDTH_B (C_READ_WIDTH_B), .C_WRITE_DEPTH_B (C_WRITE_DEPTH_B), .C_READ_DEPTH_B (C_READ_DEPTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS_A (C_HAS_MEM_OUTPUT_REGS_A), .C_HAS_MEM_OUTPUT_REGS_B (C_HAS_MEM_OUTPUT_REGS_B), .C_HAS_MUX_OUTPUT_REGS_A (C_HAS_MUX_OUTPUT_REGS_A), .C_HAS_MUX_OUTPUT_REGS_B (C_HAS_MUX_OUTPUT_REGS_B), .C_HAS_SOFTECC_INPUT_REGS_A (C_HAS_SOFTECC_INPUT_REGS_A), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_MUX_PIPELINE_STAGES (C_MUX_PIPELINE_STAGES), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .C_HAS_INJECTERR (C_HAS_INJECTERR), .C_SIM_COLLISION_CHECK (C_SIM_COLLISION_CHECK), .C_COMMON_CLK (C_COMMON_CLK), .FLOP_DELAY (FLOP_DELAY), .C_DISABLE_WARN_BHV_COLL (C_DISABLE_WARN_BHV_COLL), .C_EN_ECC_PIPE (C_EN_ECC_PIPE), .C_DISABLE_WARN_BHV_RANGE (C_DISABLE_WARN_BHV_RANGE)) blk_mem_gen_v8_3_3_inst (.CLKA (CLKA), .RSTA (RSTA_I_SAFE),//(rsta_in), .ENA (ENA_I_SAFE),//(ena_in), .REGCEA (regcea_in), .WEA (wea_in), .ADDRA (addra_in), .DINA (dina_in), .DOUTA (DOUTA), .CLKB (CLKB), .RSTB (RSTB_I_SAFE),//(RSTB), .ENB (ENB_I_SAFE),//(ENB), .REGCEB (REGCEB), .WEB (WEB), .ADDRB (ADDRB), .DINB (DINB), .DOUTB (DOUTB), .INJECTSBITERR (injectsbiterr_in), .INJECTDBITERR (injectdbiterr_in), .ECCPIPECE (ECCPIPECE), .SLEEP (SLEEP), .SBITERR (SBITERR), .DBITERR (DBITERR), .RDADDRECC (RDADDRECC) ); end endgenerate generate if((C_INTERFACE_TYPE == 0) && (C_ENABLE_32BIT_ADDRESS == 1)) begin : native_mem_mapped_module localparam C_ADDRA_WIDTH_ACTUAL = log2roundup(C_WRITE_DEPTH_A); localparam C_ADDRB_WIDTH_ACTUAL = log2roundup(C_WRITE_DEPTH_B); localparam C_ADDRA_WIDTH_MSB = C_ADDRA_WIDTH_ACTUAL+log2int(C_WRITE_WIDTH_A/8); localparam C_ADDRB_WIDTH_MSB = C_ADDRB_WIDTH_ACTUAL+log2int(C_WRITE_WIDTH_B/8); // localparam C_ADDRA_WIDTH_MSB = C_ADDRA_WIDTH_ACTUAL+log2roundup(C_WRITE_WIDTH_A/8); // localparam C_ADDRB_WIDTH_MSB = C_ADDRB_WIDTH_ACTUAL+log2roundup(C_WRITE_WIDTH_B/8); localparam C_MEM_MAP_ADDRA_WIDTH_MSB = C_ADDRA_WIDTH_MSB; localparam C_MEM_MAP_ADDRB_WIDTH_MSB = C_ADDRB_WIDTH_MSB; // Data Width Number of LSB address bits to be discarded // 1 to 16 1 // 17 to 32 2 // 33 to 64 3 // 65 to 128 4 // 129 to 256 5 // 257 to 512 6 // 513 to 1024 7 // The following two constants determine this. localparam MEM_MAP_LOWER_BOUND_VAL_A = (log2int(divroundup(C_WRITE_WIDTH_A,8)==0)) ? 0:(log2int(divroundup(C_WRITE_WIDTH_A,8))); localparam MEM_MAP_LOWER_BOUND_VAL_B = (log2int(divroundup(C_WRITE_WIDTH_A,8)==0)) ? 0:(log2int(divroundup(C_WRITE_WIDTH_A,8))); localparam C_MEM_MAP_ADDRA_WIDTH_LSB = MEM_MAP_LOWER_BOUND_VAL_A; localparam C_MEM_MAP_ADDRB_WIDTH_LSB = MEM_MAP_LOWER_BOUND_VAL_B; wire [C_ADDRB_WIDTH_ACTUAL-1 :0] rdaddrecc_i; wire [C_ADDRB_WIDTH-1:C_MEM_MAP_ADDRB_WIDTH_MSB] msb_zero_i; wire [C_MEM_MAP_ADDRB_WIDTH_LSB-1:0] lsb_zero_i; assign msb_zero_i = 0; assign lsb_zero_i = 0; assign RDADDRECC = {msb_zero_i,rdaddrecc_i,lsb_zero_i}; blk_mem_gen_v8_3_3_mem_module #(.C_CORENAME (C_CORENAME), .C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_MEM_TYPE (C_MEM_TYPE), .C_BYTE_SIZE (C_BYTE_SIZE), .C_USE_BRAM_BLOCK (C_USE_BRAM_BLOCK), .C_ALGORITHM (C_ALGORITHM), .C_PRIM_TYPE (C_PRIM_TYPE), .C_LOAD_INIT_FILE (C_LOAD_INIT_FILE), .C_INIT_FILE_NAME (C_INIT_FILE_NAME), .C_INIT_FILE (C_INIT_FILE), .C_USE_DEFAULT_DATA (C_USE_DEFAULT_DATA), .C_DEFAULT_DATA (C_DEFAULT_DATA), .C_RST_TYPE ("SYNC"), .C_HAS_RSTA (C_HAS_RSTA), .C_RST_PRIORITY_A (C_RST_PRIORITY_A), .C_RSTRAM_A (C_RSTRAM_A), .C_INITA_VAL (C_INITA_VAL), .C_HAS_ENA (C_HAS_ENA), .C_HAS_REGCEA (C_HAS_REGCEA), .C_USE_BYTE_WEA (C_USE_BYTE_WEA), .C_WEA_WIDTH (C_WEA_WIDTH), .C_WRITE_MODE_A (C_WRITE_MODE_A), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_READ_WIDTH_A (C_READ_WIDTH_A), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_READ_DEPTH_A (C_READ_DEPTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH_ACTUAL), .C_HAS_RSTB (C_HAS_RSTB), .C_RST_PRIORITY_B (C_RST_PRIORITY_B), .C_RSTRAM_B (C_RSTRAM_B), .C_INITB_VAL (C_INITB_VAL), .C_HAS_ENB (C_HAS_ENB), .C_HAS_REGCEB (C_HAS_REGCEB), .C_USE_BYTE_WEB (C_USE_BYTE_WEB), .C_WEB_WIDTH (C_WEB_WIDTH), .C_WRITE_MODE_B (C_WRITE_MODE_B), .C_WRITE_WIDTH_B (C_WRITE_WIDTH_B), .C_READ_WIDTH_B (C_READ_WIDTH_B), .C_WRITE_DEPTH_B (C_WRITE_DEPTH_B), .C_READ_DEPTH_B (C_READ_DEPTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH_ACTUAL), .C_HAS_MEM_OUTPUT_REGS_A (C_HAS_MEM_OUTPUT_REGS_A), .C_HAS_MEM_OUTPUT_REGS_B (C_HAS_MEM_OUTPUT_REGS_B), .C_HAS_MUX_OUTPUT_REGS_A (C_HAS_MUX_OUTPUT_REGS_A), .C_HAS_MUX_OUTPUT_REGS_B (C_HAS_MUX_OUTPUT_REGS_B), .C_HAS_SOFTECC_INPUT_REGS_A (C_HAS_SOFTECC_INPUT_REGS_A), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_MUX_PIPELINE_STAGES (C_MUX_PIPELINE_STAGES), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .C_HAS_INJECTERR (C_HAS_INJECTERR), .C_SIM_COLLISION_CHECK (C_SIM_COLLISION_CHECK), .C_COMMON_CLK (C_COMMON_CLK), .FLOP_DELAY (FLOP_DELAY), .C_DISABLE_WARN_BHV_COLL (C_DISABLE_WARN_BHV_COLL), .C_EN_ECC_PIPE (C_EN_ECC_PIPE), .C_DISABLE_WARN_BHV_RANGE (C_DISABLE_WARN_BHV_RANGE)) blk_mem_gen_v8_3_3_inst (.CLKA (CLKA), .RSTA (RSTA_I_SAFE),//(rsta_in), .ENA (ENA_I_SAFE),//(ena_in), .REGCEA (regcea_in), .WEA (wea_in), .ADDRA (addra_in[C_MEM_MAP_ADDRA_WIDTH_MSB-1:C_MEM_MAP_ADDRA_WIDTH_LSB]), .DINA (dina_in), .DOUTA (DOUTA), .CLKB (CLKB), .RSTB (RSTB_I_SAFE),//(RSTB), .ENB (ENB_I_SAFE),//(ENB), .REGCEB (REGCEB), .WEB (WEB), .ADDRB (ADDRB[C_MEM_MAP_ADDRB_WIDTH_MSB-1:C_MEM_MAP_ADDRB_WIDTH_LSB]), .DINB (DINB), .DOUTB (DOUTB), .INJECTSBITERR (injectsbiterr_in), .INJECTDBITERR (injectdbiterr_in), .ECCPIPECE (ECCPIPECE), .SLEEP (SLEEP), .SBITERR (SBITERR), .DBITERR (DBITERR), .RDADDRECC (rdaddrecc_i) ); end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 0 && C_HAS_MUX_OUTPUT_REGS_B == 0 ) begin : no_regs assign S_AXI_RDATA = s_axi_rdata_c; assign S_AXI_RLAST = s_axi_rlast_c; assign S_AXI_RVALID = s_axi_rvalid_c; assign S_AXI_RID = s_axi_rid_c; assign S_AXI_RRESP = s_axi_rresp_c; assign s_axi_rready_c = S_AXI_RREADY; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 1) begin : has_regceb assign regceb_c = s_axi_rvalid_c && s_axi_rready_c; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 0) begin : no_regceb assign regceb_c = REGCEB; end endgenerate generate if (C_HAS_MUX_OUTPUT_REGS_B == 1) begin : only_core_op_regs assign s_axi_payload_c = {s_axi_rid_c,s_axi_rdata_c,s_axi_rresp_c,s_axi_rlast_c}; assign S_AXI_RID = m_axi_payload_c[C_AXI_PAYLOAD-1 : C_AXI_PAYLOAD-C_AXI_ID_WIDTH]; assign S_AXI_RDATA = m_axi_payload_c[C_AXI_PAYLOAD-C_AXI_ID_WIDTH-1 : C_AXI_PAYLOAD-C_AXI_ID_WIDTH-C_WRITE_WIDTH_B]; assign S_AXI_RRESP = m_axi_payload_c[2:1]; assign S_AXI_RLAST = m_axi_payload_c[0]; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 1) begin : only_emb_op_regs assign s_axi_payload_c = {s_axi_rid_c,s_axi_rresp_c,s_axi_rlast_c}; assign S_AXI_RDATA = s_axi_rdata_c; assign S_AXI_RID = m_axi_payload_c[C_AXI_PAYLOAD-1 : C_AXI_PAYLOAD-C_AXI_ID_WIDTH]; assign S_AXI_RRESP = m_axi_payload_c[2:1]; assign S_AXI_RLAST = m_axi_payload_c[0]; end endgenerate generate if (C_HAS_MUX_OUTPUT_REGS_B == 1 || C_HAS_MEM_OUTPUT_REGS_B == 1) begin : has_regs_fwd blk_mem_axi_regs_fwd_v8_3 #(.C_DATA_WIDTH (C_AXI_PAYLOAD)) axi_regs_inst ( .ACLK (S_ACLK), .ARESET (s_aresetn_a_c), .S_VALID (s_axi_rvalid_c), .S_READY (s_axi_rready_c), .S_PAYLOAD_DATA (s_axi_payload_c), .M_VALID (S_AXI_RVALID), .M_READY (S_AXI_RREADY), .M_PAYLOAD_DATA (m_axi_payload_c) ); end endgenerate generate if (C_INTERFACE_TYPE == 1) begin : axi_mem_module assign s_aresetn_a_c = !S_ARESETN; assign S_AXI_BRESP = 2'b00; assign s_axi_rresp_c = 2'b00; assign s_axi_arlen_c = (C_AXI_TYPE == 1)?S_AXI_ARLEN:8'h0; blk_mem_axi_write_wrapper_beh_v8_3 #(.C_INTERFACE_TYPE (C_INTERFACE_TYPE), .C_AXI_TYPE (C_AXI_TYPE), .C_AXI_SLAVE_TYPE (C_AXI_SLAVE_TYPE), .C_MEMORY_TYPE (C_MEM_TYPE), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_AXI_AWADDR_WIDTH ((AXI_FULL_MEMORY_SLAVE == 1)?C_AXI_ADDR_WIDTH:C_AXI_ADDR_WIDTH-C_AXI_ADDR_WIDTH_LSB), .C_HAS_AXI_ID (C_HAS_AXI_ID), .C_AXI_ID_WIDTH (C_AXI_ID_WIDTH), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_AXI_WDATA_WIDTH (C_WRITE_WIDTH_A), .C_AXI_OS_WR (C_AXI_OS_WR)) axi_wr_fsm ( // AXI Global Signals .S_ACLK (S_ACLK), .S_ARESETN (s_aresetn_a_c), // AXI Full/Lite Slave Write interface .S_AXI_AWADDR (S_AXI_AWADDR[C_AXI_ADDR_WIDTH_MSB-1:C_AXI_ADDR_WIDTH_LSB]), .S_AXI_AWLEN (S_AXI_AWLEN), .S_AXI_AWID (S_AXI_AWID), .S_AXI_AWSIZE (S_AXI_AWSIZE), .S_AXI_AWBURST (S_AXI_AWBURST), .S_AXI_AWVALID (S_AXI_AWVALID), .S_AXI_AWREADY (S_AXI_AWREADY), .S_AXI_WVALID (S_AXI_WVALID), .S_AXI_WREADY (S_AXI_WREADY), .S_AXI_BVALID (S_AXI_BVALID), .S_AXI_BREADY (S_AXI_BREADY), .S_AXI_BID (S_AXI_BID), // Signals for BRAM interfac( .S_AXI_AWADDR_OUT (s_axi_awaddr_out_c), .S_AXI_WR_EN (s_axi_wr_en_c) ); blk_mem_axi_read_wrapper_beh_v8_3 #(.C_INTERFACE_TYPE (C_INTERFACE_TYPE), .C_AXI_TYPE (C_AXI_TYPE), .C_AXI_SLAVE_TYPE (C_AXI_SLAVE_TYPE), .C_MEMORY_TYPE (C_MEM_TYPE), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_AXI_PIPELINE_STAGES (1), .C_AXI_ARADDR_WIDTH ((AXI_FULL_MEMORY_SLAVE == 1)?C_AXI_ADDR_WIDTH:C_AXI_ADDR_WIDTH-C_AXI_ADDR_WIDTH_LSB), .C_HAS_AXI_ID (C_HAS_AXI_ID), .C_AXI_ID_WIDTH (C_AXI_ID_WIDTH), .C_ADDRB_WIDTH (C_ADDRB_WIDTH)) axi_rd_sm( //AXI Global Signals .S_ACLK (S_ACLK), .S_ARESETN (s_aresetn_a_c), //AXI Full/Lite Read Side .S_AXI_ARADDR (S_AXI_ARADDR[C_AXI_ADDR_WIDTH_MSB-1:C_AXI_ADDR_WIDTH_LSB]), .S_AXI_ARLEN (s_axi_arlen_c), .S_AXI_ARSIZE (S_AXI_ARSIZE), .S_AXI_ARBURST (S_AXI_ARBURST), .S_AXI_ARVALID (S_AXI_ARVALID), .S_AXI_ARREADY (S_AXI_ARREADY), .S_AXI_RLAST (s_axi_rlast_c), .S_AXI_RVALID (s_axi_rvalid_c), .S_AXI_RREADY (s_axi_rready_c), .S_AXI_ARID (S_AXI_ARID), .S_AXI_RID (s_axi_rid_c), //AXI Full/Lite Read FSM Outputs .S_AXI_ARADDR_OUT (s_axi_araddr_out_c), .S_AXI_RD_EN (s_axi_rd_en_c) ); blk_mem_gen_v8_3_3_mem_module #(.C_CORENAME (C_CORENAME), .C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_MEM_TYPE (C_MEM_TYPE), .C_BYTE_SIZE (C_BYTE_SIZE), .C_USE_BRAM_BLOCK (C_USE_BRAM_BLOCK), .C_ALGORITHM (C_ALGORITHM), .C_PRIM_TYPE (C_PRIM_TYPE), .C_LOAD_INIT_FILE (C_LOAD_INIT_FILE), .C_INIT_FILE_NAME (C_INIT_FILE_NAME), .C_INIT_FILE (C_INIT_FILE), .C_USE_DEFAULT_DATA (C_USE_DEFAULT_DATA), .C_DEFAULT_DATA (C_DEFAULT_DATA), .C_RST_TYPE ("SYNC"), .C_HAS_RSTA (C_HAS_RSTA), .C_RST_PRIORITY_A (C_RST_PRIORITY_A), .C_RSTRAM_A (C_RSTRAM_A), .C_INITA_VAL (C_INITA_VAL), .C_HAS_ENA (1), .C_HAS_REGCEA (C_HAS_REGCEA), .C_USE_BYTE_WEA (1), .C_WEA_WIDTH (C_WEA_WIDTH), .C_WRITE_MODE_A (C_WRITE_MODE_A), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_READ_WIDTH_A (C_READ_WIDTH_A), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_READ_DEPTH_A (C_READ_DEPTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_HAS_RSTB (C_HAS_RSTB), .C_RST_PRIORITY_B (C_RST_PRIORITY_B), .C_RSTRAM_B (C_RSTRAM_B), .C_INITB_VAL (C_INITB_VAL), .C_HAS_ENB (1), .C_HAS_REGCEB (C_HAS_MEM_OUTPUT_REGS_B), .C_USE_BYTE_WEB (1), .C_WEB_WIDTH (C_WEB_WIDTH), .C_WRITE_MODE_B (C_WRITE_MODE_B), .C_WRITE_WIDTH_B (C_WRITE_WIDTH_B), .C_READ_WIDTH_B (C_READ_WIDTH_B), .C_WRITE_DEPTH_B (C_WRITE_DEPTH_B), .C_READ_DEPTH_B (C_READ_DEPTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS_A (0), .C_HAS_MEM_OUTPUT_REGS_B (C_HAS_MEM_OUTPUT_REGS_B), .C_HAS_MUX_OUTPUT_REGS_A (0), .C_HAS_MUX_OUTPUT_REGS_B (0), .C_HAS_SOFTECC_INPUT_REGS_A (C_HAS_SOFTECC_INPUT_REGS_A), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_MUX_PIPELINE_STAGES (C_MUX_PIPELINE_STAGES), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .C_HAS_INJECTERR (C_HAS_INJECTERR), .C_SIM_COLLISION_CHECK (C_SIM_COLLISION_CHECK), .C_COMMON_CLK (C_COMMON_CLK), .FLOP_DELAY (FLOP_DELAY), .C_DISABLE_WARN_BHV_COLL (C_DISABLE_WARN_BHV_COLL), .C_EN_ECC_PIPE (0), .C_DISABLE_WARN_BHV_RANGE (C_DISABLE_WARN_BHV_RANGE)) blk_mem_gen_v8_3_3_inst (.CLKA (S_ACLK), .RSTA (s_aresetn_a_c), .ENA (s_axi_wr_en_c), .REGCEA (regcea_in), .WEA (S_AXI_WSTRB), .ADDRA (s_axi_awaddr_out_c), .DINA (S_AXI_WDATA), .DOUTA (DOUTA), .CLKB (S_ACLK), .RSTB (s_aresetn_a_c), .ENB (s_axi_rd_en_c), .REGCEB (regceb_c), .WEB (WEB_parameterized), .ADDRB (s_axi_araddr_out_c), .DINB (DINB), .DOUTB (s_axi_rdata_c), .INJECTSBITERR (injectsbiterr_in), .INJECTDBITERR (injectdbiterr_in), .SBITERR (SBITERR), .DBITERR (DBITERR), .ECCPIPECE (1'b0), .SLEEP (1'b0), .RDADDRECC (RDADDRECC) ); end endgenerate endmodule
/****************************************************************************** -- (c) Copyright 2006 - 2013 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -- ***************************************************************************** * * Filename: blk_mem_gen_v8_3_3.v * * Description: * This file is the Verilog behvarial model for the * Block Memory Generator Core. * ***************************************************************************** * Author: Xilinx * * History: Jan 11, 2006 Initial revision * Jun 11, 2007 Added independent register stages for * Port A and Port B (IP1_Jm/v2.5) * Aug 28, 2007 Added mux pipeline stages feature (IP2_Jm/v2.6) * Mar 13, 2008 Behavioral model optimizations * April 07, 2009 : Added support for Spartan-6 and Virtex-6 * features, including the following: * (i) error injection, detection and/or correction * (ii) reset priority * (iii) special reset behavior * *****************************************************************************/ `timescale 1ps/1ps module STATE_LOGIC_v8_3 (O, I0, I1, I2, I3, I4, I5); parameter INIT = 64'h0000000000000000; input I0, I1, I2, I3, I4, I5; output O; reg O; reg tmp; always @( I5 or I4 or I3 or I2 or I1 or I0 ) begin tmp = I0 ^ I1 ^ I2 ^ I3 ^ I4 ^ I5; if ( tmp == 0 || tmp == 1) O = INIT[{I5, I4, I3, I2, I1, I0}]; end endmodule module beh_vlog_muxf7_v8_3 (O, I0, I1, S); output O; reg O; input I0, I1, S; always @(I0 or I1 or S) if (S) O = I1; else O = I0; endmodule module beh_vlog_ff_clr_v8_3 (Q, C, CLR, D); parameter INIT = 0; localparam FLOP_DELAY = 100; output Q; input C, CLR, D; reg Q; initial Q= 1'b0; always @(posedge C ) if (CLR) Q<= 1'b0; else Q<= #FLOP_DELAY D; endmodule module beh_vlog_ff_pre_v8_3 (Q, C, D, PRE); parameter INIT = 0; localparam FLOP_DELAY = 100; output Q; input C, D, PRE; reg Q; initial Q= 1'b0; always @(posedge C ) if (PRE) Q <= 1'b1; else Q <= #FLOP_DELAY D; endmodule module beh_vlog_ff_ce_clr_v8_3 (Q, C, CE, CLR, D); parameter INIT = 0; localparam FLOP_DELAY = 100; output Q; input C, CE, CLR, D; reg Q; initial Q= 1'b0; always @(posedge C ) if (CLR) Q <= 1'b0; else if (CE) Q <= #FLOP_DELAY D; endmodule module write_netlist_v8_3 #( parameter C_AXI_TYPE = 0 ) ( S_ACLK, S_ARESETN, S_AXI_AWVALID, S_AXI_WVALID, S_AXI_BREADY, w_last_c, bready_timeout_c, aw_ready_r, S_AXI_WREADY, S_AXI_BVALID, S_AXI_WR_EN, addr_en_c, incr_addr_c, bvalid_c ); input S_ACLK; input S_ARESETN; input S_AXI_AWVALID; input S_AXI_WVALID; input S_AXI_BREADY; input w_last_c; input bready_timeout_c; output aw_ready_r; output S_AXI_WREADY; output S_AXI_BVALID; output S_AXI_WR_EN; output addr_en_c; output incr_addr_c; output bvalid_c; //------------------------------------------------------------------------- //AXI LITE //------------------------------------------------------------------------- generate if (C_AXI_TYPE == 0 ) begin : gbeh_axi_lite_sm wire w_ready_r_7; wire w_ready_c; wire aw_ready_c; wire NlwRenamedSignal_bvalid_c; wire NlwRenamedSignal_incr_addr_c; wire present_state_FSM_FFd3_13; wire present_state_FSM_FFd2_14; wire present_state_FSM_FFd1_15; wire present_state_FSM_FFd4_16; wire present_state_FSM_FFd4_In; wire present_state_FSM_FFd3_In; wire present_state_FSM_FFd2_In; wire present_state_FSM_FFd1_In; wire present_state_FSM_FFd4_In1_21; wire [0:0] Mmux_aw_ready_c ; begin assign S_AXI_WREADY = w_ready_r_7, S_AXI_BVALID = NlwRenamedSignal_incr_addr_c, S_AXI_WR_EN = NlwRenamedSignal_bvalid_c, incr_addr_c = NlwRenamedSignal_incr_addr_c, bvalid_c = NlwRenamedSignal_bvalid_c; assign NlwRenamedSignal_incr_addr_c = 1'b0; beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) aw_ready_r_2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( aw_ready_c), .Q ( aw_ready_r) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) w_ready_r ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( w_ready_c), .Q ( w_ready_r_7) ); beh_vlog_ff_pre_v8_3 #( .INIT (1'b1)) present_state_FSM_FFd4 ( .C ( S_ACLK), .D ( present_state_FSM_FFd4_In), .PRE ( S_ARESETN), .Q ( present_state_FSM_FFd4_16) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd3 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd3_In), .Q ( present_state_FSM_FFd3_13) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd2_In), .Q ( present_state_FSM_FFd2_14) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd1 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd1_In), .Q ( present_state_FSM_FFd1_15) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000055554440)) present_state_FSM_FFd3_In1 ( .I0 ( S_AXI_WVALID), .I1 ( S_AXI_AWVALID), .I2 ( present_state_FSM_FFd2_14), .I3 ( present_state_FSM_FFd4_16), .I4 ( present_state_FSM_FFd3_13), .I5 (1'b0), .O ( present_state_FSM_FFd3_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000088880800)) present_state_FSM_FFd2_In1 ( .I0 ( S_AXI_AWVALID), .I1 ( S_AXI_WVALID), .I2 ( bready_timeout_c), .I3 ( present_state_FSM_FFd2_14), .I4 ( present_state_FSM_FFd4_16), .I5 (1'b0), .O ( present_state_FSM_FFd2_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000AAAA2000)) Mmux_addr_en_c_0_1 ( .I0 ( S_AXI_AWVALID), .I1 ( bready_timeout_c), .I2 ( present_state_FSM_FFd2_14), .I3 ( S_AXI_WVALID), .I4 ( present_state_FSM_FFd4_16), .I5 (1'b0), .O ( addr_en_c) ); STATE_LOGIC_v8_3 #( .INIT (64'hF5F07570F5F05500)) Mmux_w_ready_c_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd3_13), .I4 ( present_state_FSM_FFd4_16), .I5 ( present_state_FSM_FFd2_14), .O ( w_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h88808880FFFF8880)) present_state_FSM_FFd1_In1 ( .I0 ( S_AXI_WVALID), .I1 ( bready_timeout_c), .I2 ( present_state_FSM_FFd3_13), .I3 ( present_state_FSM_FFd2_14), .I4 ( present_state_FSM_FFd1_15), .I5 ( S_AXI_BREADY), .O ( present_state_FSM_FFd1_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000A8)) Mmux_S_AXI_WR_EN_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( present_state_FSM_FFd2_14), .I2 ( present_state_FSM_FFd3_13), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( NlwRenamedSignal_bvalid_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h2F0F27072F0F2200)) present_state_FSM_FFd4_In1 ( .I0 ( S_AXI_WVALID), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd3_13), .I4 ( present_state_FSM_FFd4_16), .I5 ( present_state_FSM_FFd2_14), .O ( present_state_FSM_FFd4_In1_21) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000F8)) present_state_FSM_FFd4_In2 ( .I0 ( present_state_FSM_FFd1_15), .I1 ( S_AXI_BREADY), .I2 ( present_state_FSM_FFd4_In1_21), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( present_state_FSM_FFd4_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h7535753575305500)) Mmux_aw_ready_c_0_1 ( .I0 ( S_AXI_AWVALID), .I1 ( bready_timeout_c), .I2 ( S_AXI_WVALID), .I3 ( present_state_FSM_FFd4_16), .I4 ( present_state_FSM_FFd3_13), .I5 ( present_state_FSM_FFd2_14), .O ( Mmux_aw_ready_c[0]) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000F8)) Mmux_aw_ready_c_0_2 ( .I0 ( present_state_FSM_FFd1_15), .I1 ( S_AXI_BREADY), .I2 ( Mmux_aw_ready_c[0]), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( aw_ready_c) ); end end endgenerate //--------------------------------------------------------------------- // AXI FULL //--------------------------------------------------------------------- generate if (C_AXI_TYPE == 1 ) begin : gbeh_axi_full_sm wire w_ready_r_8; wire w_ready_c; wire aw_ready_c; wire NlwRenamedSig_OI_bvalid_c; wire present_state_FSM_FFd1_16; wire present_state_FSM_FFd4_17; wire present_state_FSM_FFd3_18; wire present_state_FSM_FFd2_19; wire present_state_FSM_FFd4_In; wire present_state_FSM_FFd3_In; wire present_state_FSM_FFd2_In; wire present_state_FSM_FFd1_In; wire present_state_FSM_FFd2_In1_24; wire present_state_FSM_FFd4_In1_25; wire N2; wire N4; begin assign S_AXI_WREADY = w_ready_r_8, bvalid_c = NlwRenamedSig_OI_bvalid_c, S_AXI_BVALID = 1'b0; beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) aw_ready_r_2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( aw_ready_c), .Q ( aw_ready_r) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) w_ready_r ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( w_ready_c), .Q ( w_ready_r_8) ); beh_vlog_ff_pre_v8_3 #( .INIT (1'b1)) present_state_FSM_FFd4 ( .C ( S_ACLK), .D ( present_state_FSM_FFd4_In), .PRE ( S_ARESETN), .Q ( present_state_FSM_FFd4_17) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd3 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd3_In), .Q ( present_state_FSM_FFd3_18) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd2_In), .Q ( present_state_FSM_FFd2_19) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd1 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd1_In), .Q ( present_state_FSM_FFd1_16) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000005540)) present_state_FSM_FFd3_In1 ( .I0 ( S_AXI_WVALID), .I1 ( present_state_FSM_FFd4_17), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( present_state_FSM_FFd3_In) ); STATE_LOGIC_v8_3 #( .INIT (64'hBF3FBB33AF0FAA00)) Mmux_aw_ready_c_0_2 ( .I0 ( S_AXI_BREADY), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd1_16), .I4 ( present_state_FSM_FFd4_17), .I5 ( NlwRenamedSig_OI_bvalid_c), .O ( aw_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'hAAAAAAAA20000000)) Mmux_addr_en_c_0_1 ( .I0 ( S_AXI_AWVALID), .I1 ( bready_timeout_c), .I2 ( present_state_FSM_FFd2_19), .I3 ( S_AXI_WVALID), .I4 ( w_last_c), .I5 ( present_state_FSM_FFd4_17), .O ( addr_en_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000A8)) Mmux_S_AXI_WR_EN_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( present_state_FSM_FFd2_19), .I2 ( present_state_FSM_FFd3_18), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( S_AXI_WR_EN) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000002220)) Mmux_incr_addr_c_0_1 ( .I0 ( S_AXI_WVALID), .I1 ( w_last_c), .I2 ( present_state_FSM_FFd2_19), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( incr_addr_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000008880)) Mmux_aw_ready_c_0_11 ( .I0 ( S_AXI_WVALID), .I1 ( w_last_c), .I2 ( present_state_FSM_FFd2_19), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( NlwRenamedSig_OI_bvalid_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000000000D5C0)) present_state_FSM_FFd2_In1 ( .I0 ( w_last_c), .I1 ( S_AXI_AWVALID), .I2 ( present_state_FSM_FFd4_17), .I3 ( present_state_FSM_FFd3_18), .I4 (1'b0), .I5 (1'b0), .O ( present_state_FSM_FFd2_In1_24) ); STATE_LOGIC_v8_3 #( .INIT (64'hFFFFAAAA08AAAAAA)) present_state_FSM_FFd2_In2 ( .I0 ( present_state_FSM_FFd2_19), .I1 ( S_AXI_AWVALID), .I2 ( bready_timeout_c), .I3 ( w_last_c), .I4 ( S_AXI_WVALID), .I5 ( present_state_FSM_FFd2_In1_24), .O ( present_state_FSM_FFd2_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h00C0004000C00000)) present_state_FSM_FFd4_In1 ( .I0 ( S_AXI_AWVALID), .I1 ( w_last_c), .I2 ( S_AXI_WVALID), .I3 ( bready_timeout_c), .I4 ( present_state_FSM_FFd3_18), .I5 ( present_state_FSM_FFd2_19), .O ( present_state_FSM_FFd4_In1_25) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000FFFF88F8)) present_state_FSM_FFd4_In2 ( .I0 ( present_state_FSM_FFd1_16), .I1 ( S_AXI_BREADY), .I2 ( present_state_FSM_FFd4_17), .I3 ( S_AXI_AWVALID), .I4 ( present_state_FSM_FFd4_In1_25), .I5 (1'b0), .O ( present_state_FSM_FFd4_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000007)) Mmux_w_ready_c_0_SW0 ( .I0 ( w_last_c), .I1 ( S_AXI_WVALID), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( N2) ); STATE_LOGIC_v8_3 #( .INIT (64'hFABAFABAFAAAF000)) Mmux_w_ready_c_0_Q ( .I0 ( N2), .I1 ( bready_timeout_c), .I2 ( S_AXI_AWVALID), .I3 ( present_state_FSM_FFd4_17), .I4 ( present_state_FSM_FFd3_18), .I5 ( present_state_FSM_FFd2_19), .O ( w_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000008)) Mmux_aw_ready_c_0_11_SW0 ( .I0 ( bready_timeout_c), .I1 ( S_AXI_WVALID), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O ( N4) ); STATE_LOGIC_v8_3 #( .INIT (64'h88808880FFFF8880)) present_state_FSM_FFd1_In1 ( .I0 ( w_last_c), .I1 ( N4), .I2 ( present_state_FSM_FFd2_19), .I3 ( present_state_FSM_FFd3_18), .I4 ( present_state_FSM_FFd1_16), .I5 ( S_AXI_BREADY), .O ( present_state_FSM_FFd1_In) ); end end endgenerate endmodule module read_netlist_v8_3 #( parameter C_AXI_TYPE = 1, parameter C_ADDRB_WIDTH = 12 ) ( S_AXI_R_LAST_INT, S_ACLK, S_ARESETN, S_AXI_ARVALID, S_AXI_RREADY,S_AXI_INCR_ADDR,S_AXI_ADDR_EN, S_AXI_SINGLE_TRANS,S_AXI_MUX_SEL, S_AXI_R_LAST, S_AXI_ARREADY, S_AXI_RLAST, S_AXI_RVALID, S_AXI_RD_EN, S_AXI_ARLEN); input S_AXI_R_LAST_INT; input S_ACLK; input S_ARESETN; input S_AXI_ARVALID; input S_AXI_RREADY; output S_AXI_INCR_ADDR; output S_AXI_ADDR_EN; output S_AXI_SINGLE_TRANS; output S_AXI_MUX_SEL; output S_AXI_R_LAST; output S_AXI_ARREADY; output S_AXI_RLAST; output S_AXI_RVALID; output S_AXI_RD_EN; input [7:0] S_AXI_ARLEN; wire present_state_FSM_FFd1_13 ; wire present_state_FSM_FFd2_14 ; wire gaxi_full_sm_outstanding_read_r_15 ; wire gaxi_full_sm_ar_ready_r_16 ; wire gaxi_full_sm_r_last_r_17 ; wire NlwRenamedSig_OI_gaxi_full_sm_r_valid_r ; wire gaxi_full_sm_r_valid_c ; wire S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o ; wire gaxi_full_sm_ar_ready_c ; wire gaxi_full_sm_outstanding_read_c ; wire NlwRenamedSig_OI_S_AXI_R_LAST ; wire S_AXI_ARLEN_7_GND_8_o_equal_1_o ; wire present_state_FSM_FFd2_In ; wire present_state_FSM_FFd1_In ; wire Mmux_S_AXI_R_LAST13 ; wire N01 ; wire N2 ; wire Mmux_gaxi_full_sm_ar_ready_c11 ; wire N4 ; wire N8 ; wire N9 ; wire N10 ; wire N11 ; wire N12 ; wire N13 ; assign S_AXI_R_LAST = NlwRenamedSig_OI_S_AXI_R_LAST, S_AXI_ARREADY = gaxi_full_sm_ar_ready_r_16, S_AXI_RLAST = gaxi_full_sm_r_last_r_17, S_AXI_RVALID = NlwRenamedSig_OI_gaxi_full_sm_r_valid_r; beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) gaxi_full_sm_outstanding_read_r ( .C (S_ACLK), .CLR(S_ARESETN), .D(gaxi_full_sm_outstanding_read_c), .Q(gaxi_full_sm_outstanding_read_r_15) ); beh_vlog_ff_ce_clr_v8_3 #( .INIT (1'b0)) gaxi_full_sm_r_valid_r ( .C (S_ACLK), .CE (S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .CLR (S_ARESETN), .D (gaxi_full_sm_r_valid_c), .Q (NlwRenamedSig_OI_gaxi_full_sm_r_valid_r) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) gaxi_full_sm_ar_ready_r ( .C (S_ACLK), .CLR (S_ARESETN), .D (gaxi_full_sm_ar_ready_c), .Q (gaxi_full_sm_ar_ready_r_16) ); beh_vlog_ff_ce_clr_v8_3 #( .INIT(1'b0)) gaxi_full_sm_r_last_r ( .C (S_ACLK), .CE (S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .CLR (S_ARESETN), .D (NlwRenamedSig_OI_S_AXI_R_LAST), .Q (gaxi_full_sm_r_last_r_17) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd2 ( .C ( S_ACLK), .CLR ( S_ARESETN), .D ( present_state_FSM_FFd2_In), .Q ( present_state_FSM_FFd2_14) ); beh_vlog_ff_clr_v8_3 #( .INIT (1'b0)) present_state_FSM_FFd1 ( .C (S_ACLK), .CLR (S_ARESETN), .D (present_state_FSM_FFd1_In), .Q (present_state_FSM_FFd1_13) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000000000000B)) S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o1 ( .I0 ( S_AXI_RREADY), .I1 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O (S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000008)) Mmux_S_AXI_SINGLE_TRANS11 ( .I0 (S_AXI_ARVALID), .I1 (S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O (S_AXI_SINGLE_TRANS) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000004)) Mmux_S_AXI_ADDR_EN11 ( .I0 (present_state_FSM_FFd1_13), .I1 (S_AXI_ARVALID), .I2 (1'b0), .I3 (1'b0), .I4 (1'b0), .I5 (1'b0), .O (S_AXI_ADDR_EN) ); STATE_LOGIC_v8_3 #( .INIT (64'hECEE2022EEEE2022)) present_state_FSM_FFd2_In1 ( .I0 ( S_AXI_ARVALID), .I1 ( present_state_FSM_FFd1_13), .I2 ( S_AXI_RREADY), .I3 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I4 ( present_state_FSM_FFd2_14), .I5 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .O ( present_state_FSM_FFd2_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000044440444)) Mmux_S_AXI_R_LAST131 ( .I0 ( present_state_FSM_FFd1_13), .I1 ( S_AXI_ARVALID), .I2 ( present_state_FSM_FFd2_14), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( S_AXI_RREADY), .I5 (1'b0), .O ( Mmux_S_AXI_R_LAST13) ); STATE_LOGIC_v8_3 #( .INIT (64'h4000FFFF40004000)) Mmux_S_AXI_INCR_ADDR11 ( .I0 ( S_AXI_R_LAST_INT), .I1 ( S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .I2 ( present_state_FSM_FFd2_14), .I3 ( present_state_FSM_FFd1_13), .I4 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I5 ( Mmux_S_AXI_R_LAST13), .O ( S_AXI_INCR_ADDR) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000FE)) S_AXI_ARLEN_7_GND_8_o_equal_1_o_7_SW0 ( .I0 ( S_AXI_ARLEN[2]), .I1 ( S_AXI_ARLEN[1]), .I2 ( S_AXI_ARLEN[0]), .I3 ( 1'b0), .I4 ( 1'b0), .I5 ( 1'b0), .O ( N01) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000001)) S_AXI_ARLEN_7_GND_8_o_equal_1_o_7_Q ( .I0 ( S_AXI_ARLEN[7]), .I1 ( S_AXI_ARLEN[6]), .I2 ( S_AXI_ARLEN[5]), .I3 ( S_AXI_ARLEN[4]), .I4 ( S_AXI_ARLEN[3]), .I5 ( N01), .O ( S_AXI_ARLEN_7_GND_8_o_equal_1_o) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000000007)) Mmux_gaxi_full_sm_outstanding_read_c1_SW0 ( .I0 ( S_AXI_ARVALID), .I1 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I2 ( 1'b0), .I3 ( 1'b0), .I4 ( 1'b0), .I5 ( 1'b0), .O ( N2) ); STATE_LOGIC_v8_3 #( .INIT (64'h0020000002200200)) Mmux_gaxi_full_sm_outstanding_read_c1 ( .I0 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I1 ( S_AXI_RREADY), .I2 ( present_state_FSM_FFd1_13), .I3 ( present_state_FSM_FFd2_14), .I4 ( gaxi_full_sm_outstanding_read_r_15), .I5 ( N2), .O ( gaxi_full_sm_outstanding_read_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000000004555)) Mmux_gaxi_full_sm_ar_ready_c12 ( .I0 ( S_AXI_ARVALID), .I1 ( S_AXI_RREADY), .I2 ( present_state_FSM_FFd2_14), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( 1'b0), .I5 ( 1'b0), .O ( Mmux_gaxi_full_sm_ar_ready_c11) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000000000EF)) Mmux_S_AXI_R_LAST11_SW0 ( .I0 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I1 ( S_AXI_RREADY), .I2 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I3 ( 1'b0), .I4 ( 1'b0), .I5 ( 1'b0), .O ( N4) ); STATE_LOGIC_v8_3 #( .INIT (64'hFCAAFC0A00AA000A)) Mmux_S_AXI_R_LAST11 ( .I0 ( S_AXI_ARVALID), .I1 ( gaxi_full_sm_outstanding_read_r_15), .I2 ( present_state_FSM_FFd2_14), .I3 ( present_state_FSM_FFd1_13), .I4 ( N4), .I5 ( S_AXI_RREADY_gaxi_full_sm_r_valid_r_OR_9_o), .O ( gaxi_full_sm_r_valid_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000AAAAAA08)) S_AXI_MUX_SEL1 ( .I0 (present_state_FSM_FFd1_13), .I1 (NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I2 (S_AXI_RREADY), .I3 (present_state_FSM_FFd2_14), .I4 (gaxi_full_sm_outstanding_read_r_15), .I5 (1'b0), .O (S_AXI_MUX_SEL) ); STATE_LOGIC_v8_3 #( .INIT (64'hF3F3F755A2A2A200)) Mmux_S_AXI_RD_EN11 ( .I0 ( present_state_FSM_FFd1_13), .I1 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I2 ( S_AXI_RREADY), .I3 ( gaxi_full_sm_outstanding_read_r_15), .I4 ( present_state_FSM_FFd2_14), .I5 ( S_AXI_ARVALID), .O ( S_AXI_RD_EN) ); beh_vlog_muxf7_v8_3 present_state_FSM_FFd1_In3 ( .I0 ( N8), .I1 ( N9), .S ( present_state_FSM_FFd1_13), .O ( present_state_FSM_FFd1_In) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000005410F4F0)) present_state_FSM_FFd1_In3_F ( .I0 ( S_AXI_RREADY), .I1 ( present_state_FSM_FFd2_14), .I2 ( S_AXI_ARVALID), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I5 ( 1'b0), .O ( N8) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000072FF7272)) present_state_FSM_FFd1_In3_G ( .I0 ( present_state_FSM_FFd2_14), .I1 ( S_AXI_R_LAST_INT), .I2 ( gaxi_full_sm_outstanding_read_r_15), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N9) ); beh_vlog_muxf7_v8_3 Mmux_gaxi_full_sm_ar_ready_c14 ( .I0 ( N10), .I1 ( N11), .S ( present_state_FSM_FFd1_13), .O ( gaxi_full_sm_ar_ready_c) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000FFFF88A8)) Mmux_gaxi_full_sm_ar_ready_c14_F ( .I0 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I1 ( S_AXI_RREADY), .I2 ( present_state_FSM_FFd2_14), .I3 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I4 ( Mmux_gaxi_full_sm_ar_ready_c11), .I5 ( 1'b0), .O ( N10) ); STATE_LOGIC_v8_3 #( .INIT (64'h000000008D008D8D)) Mmux_gaxi_full_sm_ar_ready_c14_G ( .I0 ( present_state_FSM_FFd2_14), .I1 ( S_AXI_R_LAST_INT), .I2 ( gaxi_full_sm_outstanding_read_r_15), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N11) ); beh_vlog_muxf7_v8_3 Mmux_S_AXI_R_LAST1 ( .I0 ( N12), .I1 ( N13), .S ( present_state_FSM_FFd1_13), .O ( NlwRenamedSig_OI_S_AXI_R_LAST) ); STATE_LOGIC_v8_3 #( .INIT (64'h0000000088088888)) Mmux_S_AXI_R_LAST1_F ( .I0 ( S_AXI_ARLEN_7_GND_8_o_equal_1_o), .I1 ( S_AXI_ARVALID), .I2 ( present_state_FSM_FFd2_14), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N12) ); STATE_LOGIC_v8_3 #( .INIT (64'h00000000E400E4E4)) Mmux_S_AXI_R_LAST1_G ( .I0 ( present_state_FSM_FFd2_14), .I1 ( gaxi_full_sm_outstanding_read_r_15), .I2 ( S_AXI_R_LAST_INT), .I3 ( S_AXI_RREADY), .I4 ( NlwRenamedSig_OI_gaxi_full_sm_r_valid_r), .I5 ( 1'b0), .O ( N13) ); endmodule module blk_mem_axi_write_wrapper_beh_v8_3 # ( // AXI Interface related parameters start here parameter C_INTERFACE_TYPE = 0, // 0: Native Interface; 1: AXI Interface parameter C_AXI_TYPE = 0, // 0: AXI Lite; 1: AXI Full; parameter C_AXI_SLAVE_TYPE = 0, // 0: MEMORY SLAVE; 1: PERIPHERAL SLAVE; parameter C_MEMORY_TYPE = 0, // 0: SP-RAM, 1: SDP-RAM; 2: TDP-RAM; 3: DP-ROM; parameter C_WRITE_DEPTH_A = 0, parameter C_AXI_AWADDR_WIDTH = 32, parameter C_ADDRA_WIDTH = 12, parameter C_AXI_WDATA_WIDTH = 32, parameter C_HAS_AXI_ID = 0, parameter C_AXI_ID_WIDTH = 4, // AXI OUTSTANDING WRITES parameter C_AXI_OS_WR = 2 ) ( // AXI Global Signals input S_ACLK, input S_ARESETN, // AXI Full/Lite Slave Write Channel (write side) input [C_AXI_ID_WIDTH-1:0] S_AXI_AWID, input [C_AXI_AWADDR_WIDTH-1:0] S_AXI_AWADDR, input [8-1:0] S_AXI_AWLEN, input [2:0] S_AXI_AWSIZE, input [1:0] S_AXI_AWBURST, input S_AXI_AWVALID, output S_AXI_AWREADY, input S_AXI_WVALID, output S_AXI_WREADY, output reg [C_AXI_ID_WIDTH-1:0] S_AXI_BID = 0, output S_AXI_BVALID, input S_AXI_BREADY, // Signals for BMG interface output [C_ADDRA_WIDTH-1:0] S_AXI_AWADDR_OUT, output S_AXI_WR_EN ); localparam FLOP_DELAY = 100; // 100 ps localparam C_RANGE = ((C_AXI_WDATA_WIDTH == 8)?0: ((C_AXI_WDATA_WIDTH==16)?1: ((C_AXI_WDATA_WIDTH==32)?2: ((C_AXI_WDATA_WIDTH==64)?3: ((C_AXI_WDATA_WIDTH==128)?4: ((C_AXI_WDATA_WIDTH==256)?5:0)))))); wire bvalid_c ; reg bready_timeout_c = 0; wire [1:0] bvalid_rd_cnt_c; reg bvalid_r = 0; reg [2:0] bvalid_count_r = 0; reg [((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)? C_AXI_AWADDR_WIDTH:C_ADDRA_WIDTH)-1:0] awaddr_reg = 0; reg [1:0] bvalid_wr_cnt_r = 0; reg [1:0] bvalid_rd_cnt_r = 0; wire w_last_c ; wire addr_en_c ; wire incr_addr_c ; wire aw_ready_r ; wire dec_alen_c ; reg bvalid_d1_c = 0; reg [7:0] awlen_cntr_r = 0; reg [7:0] awlen_int = 0; reg [1:0] awburst_int = 0; integer total_bytes = 0; integer wrap_boundary = 0; integer wrap_base_addr = 0; integer num_of_bytes_c = 0; integer num_of_bytes_r = 0; // Array to store BIDs reg [C_AXI_ID_WIDTH-1:0] axi_bid_array[3:0] ; wire S_AXI_BVALID_axi_wr_fsm; //------------------------------------- //AXI WRITE FSM COMPONENT INSTANTIATION //------------------------------------- write_netlist_v8_3 #(.C_AXI_TYPE(C_AXI_TYPE)) axi_wr_fsm ( .S_ACLK(S_ACLK), .S_ARESETN(S_ARESETN), .S_AXI_AWVALID(S_AXI_AWVALID), .aw_ready_r(aw_ready_r), .S_AXI_WVALID(S_AXI_WVALID), .S_AXI_WREADY(S_AXI_WREADY), .S_AXI_BREADY(S_AXI_BREADY), .S_AXI_WR_EN(S_AXI_WR_EN), .w_last_c(w_last_c), .bready_timeout_c(bready_timeout_c), .addr_en_c(addr_en_c), .incr_addr_c(incr_addr_c), .bvalid_c(bvalid_c), .S_AXI_BVALID (S_AXI_BVALID_axi_wr_fsm) ); //Wrap Address boundary calculation always@(*) begin num_of_bytes_c = 2**((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_AWSIZE:0); total_bytes = (num_of_bytes_r)*(awlen_int+1); wrap_base_addr = ((awaddr_reg)/((total_bytes==0)?1:total_bytes))*(total_bytes); wrap_boundary = wrap_base_addr+total_bytes; end //------------------------------------------------------------------------- // BMG address generation //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin awaddr_reg <= 0; num_of_bytes_r <= 0; awburst_int <= 0; end else begin if (addr_en_c == 1'b1) begin awaddr_reg <= #FLOP_DELAY S_AXI_AWADDR ; num_of_bytes_r <= num_of_bytes_c; awburst_int <= ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_AWBURST:2'b01); end else if (incr_addr_c == 1'b1) begin if (awburst_int == 2'b10) begin if(awaddr_reg == (wrap_boundary-num_of_bytes_r)) begin awaddr_reg <= wrap_base_addr; end else begin awaddr_reg <= awaddr_reg + num_of_bytes_r; end end else if (awburst_int == 2'b01 || awburst_int == 2'b11) begin awaddr_reg <= awaddr_reg + num_of_bytes_r; end end end end assign S_AXI_AWADDR_OUT = ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)? awaddr_reg[C_AXI_AWADDR_WIDTH-1:C_RANGE]:awaddr_reg); //------------------------------------------------------------------------- // AXI wlast generation //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin awlen_cntr_r <= 0; awlen_int <= 0; end else begin if (addr_en_c == 1'b1) begin awlen_int <= #FLOP_DELAY (C_AXI_TYPE == 0?0:S_AXI_AWLEN) ; awlen_cntr_r <= #FLOP_DELAY (C_AXI_TYPE == 0?0:S_AXI_AWLEN) ; end else if (dec_alen_c == 1'b1) begin awlen_cntr_r <= #FLOP_DELAY awlen_cntr_r - 1 ; end end end assign w_last_c = (awlen_cntr_r == 0 && S_AXI_WVALID == 1'b1)?1'b1:1'b0; assign dec_alen_c = (incr_addr_c | w_last_c); //------------------------------------------------------------------------- // Generation of bvalid counter for outstanding transactions //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_count_r <= 0; end else begin // bvalid_count_r generation if (bvalid_c == 1'b1 && bvalid_r == 1'b1 && S_AXI_BREADY == 1'b1) begin bvalid_count_r <= #FLOP_DELAY bvalid_count_r ; end else if (bvalid_c == 1'b1) begin bvalid_count_r <= #FLOP_DELAY bvalid_count_r + 1 ; end else if (bvalid_r == 1'b1 && S_AXI_BREADY == 1'b1 && bvalid_count_r != 0) begin bvalid_count_r <= #FLOP_DELAY bvalid_count_r - 1 ; end end end //------------------------------------------------------------------------- // Generation of bvalid when BID is used //------------------------------------------------------------------------- generate if (C_HAS_AXI_ID == 1) begin:gaxi_bvalid_id_r always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_r <= 0; bvalid_d1_c <= 0; end else begin // Delay the generation o bvalid_r for generation for BID bvalid_d1_c <= bvalid_c; //external bvalid signal generation if (bvalid_d1_c == 1'b1) begin bvalid_r <= #FLOP_DELAY 1'b1 ; end else if (bvalid_count_r <= 1 && S_AXI_BREADY == 1'b1) begin bvalid_r <= #FLOP_DELAY 0 ; end end end end endgenerate //------------------------------------------------------------------------- // Generation of bvalid when BID is not used //------------------------------------------------------------------------- generate if(C_HAS_AXI_ID == 0) begin:gaxi_bvalid_noid_r always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_r <= 0; end else begin //external bvalid signal generation if (bvalid_c == 1'b1) begin bvalid_r <= #FLOP_DELAY 1'b1 ; end else if (bvalid_count_r <= 1 && S_AXI_BREADY == 1'b1) begin bvalid_r <= #FLOP_DELAY 0 ; end end end end endgenerate //------------------------------------------------------------------------- // Generation of Bready timeout //------------------------------------------------------------------------- always @(bvalid_count_r) begin // bready_timeout_c generation if(bvalid_count_r == C_AXI_OS_WR-1) begin bready_timeout_c <= 1'b1; end else begin bready_timeout_c <= 1'b0; end end //------------------------------------------------------------------------- // Generation of BID //------------------------------------------------------------------------- generate if(C_HAS_AXI_ID == 1) begin:gaxi_bid_gen always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin bvalid_wr_cnt_r <= 0; bvalid_rd_cnt_r <= 0; end else begin // STORE AWID IN AN ARRAY if(bvalid_c == 1'b1) begin bvalid_wr_cnt_r <= bvalid_wr_cnt_r + 1; end // generate BID FROM AWID ARRAY bvalid_rd_cnt_r <= #FLOP_DELAY bvalid_rd_cnt_c ; S_AXI_BID <= axi_bid_array[bvalid_rd_cnt_c]; end end assign bvalid_rd_cnt_c = (bvalid_r == 1'b1 && S_AXI_BREADY == 1'b1)?bvalid_rd_cnt_r+1:bvalid_rd_cnt_r; //------------------------------------------------------------------------- // Storing AWID for generation of BID //------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if(S_ARESETN == 1'b1) begin axi_bid_array[0] = 0; axi_bid_array[1] = 0; axi_bid_array[2] = 0; axi_bid_array[3] = 0; end else if(aw_ready_r == 1'b1 && S_AXI_AWVALID == 1'b1) begin axi_bid_array[bvalid_wr_cnt_r] <= S_AXI_AWID; end end end endgenerate assign S_AXI_BVALID = bvalid_r; assign S_AXI_AWREADY = aw_ready_r; endmodule module blk_mem_axi_read_wrapper_beh_v8_3 # ( //// AXI Interface related parameters start here parameter C_INTERFACE_TYPE = 0, parameter C_AXI_TYPE = 0, parameter C_AXI_SLAVE_TYPE = 0, parameter C_MEMORY_TYPE = 0, parameter C_WRITE_WIDTH_A = 4, parameter C_WRITE_DEPTH_A = 32, parameter C_ADDRA_WIDTH = 12, parameter C_AXI_PIPELINE_STAGES = 0, parameter C_AXI_ARADDR_WIDTH = 12, parameter C_HAS_AXI_ID = 0, parameter C_AXI_ID_WIDTH = 4, parameter C_ADDRB_WIDTH = 12 ) ( //// AXI Global Signals input S_ACLK, input S_ARESETN, //// AXI Full/Lite Slave Read (Read side) input [C_AXI_ARADDR_WIDTH-1:0] S_AXI_ARADDR, input [7:0] S_AXI_ARLEN, input [2:0] S_AXI_ARSIZE, input [1:0] S_AXI_ARBURST, input S_AXI_ARVALID, output S_AXI_ARREADY, output S_AXI_RLAST, output S_AXI_RVALID, input S_AXI_RREADY, input [C_AXI_ID_WIDTH-1:0] S_AXI_ARID, output reg [C_AXI_ID_WIDTH-1:0] S_AXI_RID = 0, //// AXI Full/Lite Read Address Signals to BRAM output [C_ADDRB_WIDTH-1:0] S_AXI_ARADDR_OUT, output S_AXI_RD_EN ); localparam FLOP_DELAY = 100; // 100 ps localparam C_RANGE = ((C_WRITE_WIDTH_A == 8)?0: ((C_WRITE_WIDTH_A==16)?1: ((C_WRITE_WIDTH_A==32)?2: ((C_WRITE_WIDTH_A==64)?3: ((C_WRITE_WIDTH_A==128)?4: ((C_WRITE_WIDTH_A==256)?5:0)))))); reg [C_AXI_ID_WIDTH-1:0] ar_id_r=0; wire addr_en_c; wire rd_en_c; wire incr_addr_c; wire single_trans_c; wire dec_alen_c; wire mux_sel_c; wire r_last_c; wire r_last_int_c; wire [C_ADDRB_WIDTH-1 : 0] araddr_out; reg [7:0] arlen_int_r=0; reg [7:0] arlen_cntr=8'h01; reg [1:0] arburst_int_c=0; reg [1:0] arburst_int_r=0; reg [((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)? C_AXI_ARADDR_WIDTH:C_ADDRA_WIDTH)-1:0] araddr_reg =0; integer num_of_bytes_c = 0; integer total_bytes = 0; integer num_of_bytes_r = 0; integer wrap_base_addr_r = 0; integer wrap_boundary_r = 0; reg [7:0] arlen_int_c=0; integer total_bytes_c = 0; integer wrap_base_addr_c = 0; integer wrap_boundary_c = 0; assign dec_alen_c = incr_addr_c | r_last_int_c; read_netlist_v8_3 #(.C_AXI_TYPE (1), .C_ADDRB_WIDTH (C_ADDRB_WIDTH)) axi_read_fsm ( .S_AXI_INCR_ADDR(incr_addr_c), .S_AXI_ADDR_EN(addr_en_c), .S_AXI_SINGLE_TRANS(single_trans_c), .S_AXI_MUX_SEL(mux_sel_c), .S_AXI_R_LAST(r_last_c), .S_AXI_R_LAST_INT(r_last_int_c), //// AXI Global Signals .S_ACLK(S_ACLK), .S_ARESETN(S_ARESETN), //// AXI Full/Lite Slave Read (Read side) .S_AXI_ARLEN(S_AXI_ARLEN), .S_AXI_ARVALID(S_AXI_ARVALID), .S_AXI_ARREADY(S_AXI_ARREADY), .S_AXI_RLAST(S_AXI_RLAST), .S_AXI_RVALID(S_AXI_RVALID), .S_AXI_RREADY(S_AXI_RREADY), //// AXI Full/Lite Read Address Signals to BRAM .S_AXI_RD_EN(rd_en_c) ); always@(*) begin num_of_bytes_c = 2**((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_ARSIZE:0); total_bytes = (num_of_bytes_r)*(arlen_int_r+1); wrap_base_addr_r = ((araddr_reg)/(total_bytes==0?1:total_bytes))*(total_bytes); wrap_boundary_r = wrap_base_addr_r+total_bytes; //////// combinatorial from interface arlen_int_c = (C_AXI_TYPE == 0?0:S_AXI_ARLEN); total_bytes_c = (num_of_bytes_c)*(arlen_int_c+1); wrap_base_addr_c = ((S_AXI_ARADDR)/(total_bytes_c==0?1:total_bytes_c))*(total_bytes_c); wrap_boundary_c = wrap_base_addr_c+total_bytes_c; arburst_int_c = ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_ARBURST:1); end ////------------------------------------------------------------------------- //// BMG address generation ////------------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin araddr_reg <= 0; arburst_int_r <= 0; num_of_bytes_r <= 0; end else begin if (incr_addr_c == 1'b1 && addr_en_c == 1'b1 && single_trans_c == 1'b0) begin arburst_int_r <= arburst_int_c; num_of_bytes_r <= num_of_bytes_c; if (arburst_int_c == 2'b10) begin if(S_AXI_ARADDR == (wrap_boundary_c-num_of_bytes_c)) begin araddr_reg <= wrap_base_addr_c; end else begin araddr_reg <= S_AXI_ARADDR + num_of_bytes_c; end end else if (arburst_int_c == 2'b01 || arburst_int_c == 2'b11) begin araddr_reg <= S_AXI_ARADDR + num_of_bytes_c; end end else if (addr_en_c == 1'b1) begin araddr_reg <= S_AXI_ARADDR; num_of_bytes_r <= num_of_bytes_c; arburst_int_r <= arburst_int_c; end else if (incr_addr_c == 1'b1) begin if (arburst_int_r == 2'b10) begin if(araddr_reg == (wrap_boundary_r-num_of_bytes_r)) begin araddr_reg <= wrap_base_addr_r; end else begin araddr_reg <= araddr_reg + num_of_bytes_r; end end else if (arburst_int_r == 2'b01 || arburst_int_r == 2'b11) begin araddr_reg <= araddr_reg + num_of_bytes_r; end end end end assign araddr_out = ((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?araddr_reg[C_AXI_ARADDR_WIDTH-1:C_RANGE]:araddr_reg); ////----------------------------------------------------------------------- //// Counter to generate r_last_int_c from registered ARLEN - AXI FULL FSM ////----------------------------------------------------------------------- always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin arlen_cntr <= 8'h01; arlen_int_r <= 0; end else begin if (addr_en_c == 1'b1 && dec_alen_c == 1'b1 && single_trans_c == 1'b0) begin arlen_int_r <= (C_AXI_TYPE == 0?0:S_AXI_ARLEN) ; arlen_cntr <= S_AXI_ARLEN - 1'b1; end else if (addr_en_c == 1'b1) begin arlen_int_r <= (C_AXI_TYPE == 0?0:S_AXI_ARLEN) ; arlen_cntr <= (C_AXI_TYPE == 0?0:S_AXI_ARLEN) ; end else if (dec_alen_c == 1'b1) begin arlen_cntr <= arlen_cntr - 1'b1 ; end else begin arlen_cntr <= arlen_cntr; end end end assign r_last_int_c = (arlen_cntr == 0 && S_AXI_RREADY == 1'b1)?1'b1:1'b0; ////------------------------------------------------------------------------ //// AXI FULL FSM //// Mux Selection of ARADDR //// ARADDR is driven out from the read fsm based on the mux_sel_c //// Based on mux_sel either ARADDR is given out or the latched ARADDR is //// given out to BRAM ////------------------------------------------------------------------------ assign S_AXI_ARADDR_OUT = (mux_sel_c == 1'b0)?((C_AXI_TYPE == 1 && C_AXI_SLAVE_TYPE == 0)?S_AXI_ARADDR[C_AXI_ARADDR_WIDTH-1:C_RANGE]:S_AXI_ARADDR):araddr_out; ////------------------------------------------------------------------------ //// Assign output signals - AXI FULL FSM ////------------------------------------------------------------------------ assign S_AXI_RD_EN = rd_en_c; generate if (C_HAS_AXI_ID == 1) begin:gaxi_bvalid_id_r always @(posedge S_ACLK or S_ARESETN) begin if (S_ARESETN == 1'b1) begin S_AXI_RID <= 0; ar_id_r <= 0; end else begin if (addr_en_c == 1'b1 && rd_en_c == 1'b1) begin S_AXI_RID <= S_AXI_ARID; ar_id_r <= S_AXI_ARID; end else if (addr_en_c == 1'b1 && rd_en_c == 1'b0) begin ar_id_r <= S_AXI_ARID; end else if (rd_en_c == 1'b1) begin S_AXI_RID <= ar_id_r; end end end end endgenerate endmodule module blk_mem_axi_regs_fwd_v8_3 #(parameter C_DATA_WIDTH = 8 )( input ACLK, input ARESET, input S_VALID, output S_READY, input [C_DATA_WIDTH-1:0] S_PAYLOAD_DATA, output M_VALID, input M_READY, output reg [C_DATA_WIDTH-1:0] M_PAYLOAD_DATA ); reg [C_DATA_WIDTH-1:0] STORAGE_DATA; wire S_READY_I; reg M_VALID_I; reg [1:0] ARESET_D; //assign local signal to its output signal assign S_READY = S_READY_I; assign M_VALID = M_VALID_I; always @(posedge ACLK) begin ARESET_D <= {ARESET_D[0], ARESET}; end //Save payload data whenever we have a transaction on the slave side always @(posedge ACLK or ARESET) begin if (ARESET == 1'b1) begin STORAGE_DATA <= 0; end else begin if(S_VALID == 1'b1 && S_READY_I == 1'b1 ) begin STORAGE_DATA <= S_PAYLOAD_DATA; end end end always @(posedge ACLK) begin M_PAYLOAD_DATA = STORAGE_DATA; end //M_Valid set to high when we have a completed transfer on slave side //Is removed on a M_READY except if we have a new transfer on the slave side always @(posedge ACLK or ARESET_D) begin if (ARESET_D != 2'b00) begin M_VALID_I <= 1'b0; end else begin if (S_VALID == 1'b1) begin //Always set M_VALID_I when slave side is valid M_VALID_I <= 1'b1; end else if (M_READY == 1'b1 ) begin //Clear (or keep) when no slave side is valid but master side is ready M_VALID_I <= 1'b0; end end end //Slave Ready is either when Master side drives M_READY or we have space in our storage data assign S_READY_I = (M_READY || (!M_VALID_I)) && !(|(ARESET_D)); endmodule //***************************************************************************** // Output Register Stage module // // This module builds the output register stages of the memory. This module is // instantiated in the main memory module (blk_mem_gen_v8_3_3) which is // declared/implemented further down in this file. //***************************************************************************** module blk_mem_gen_v8_3_3_output_stage #(parameter C_FAMILY = "virtex7", parameter C_XDEVICEFAMILY = "virtex7", parameter C_RST_TYPE = "SYNC", parameter C_HAS_RST = 0, parameter C_RSTRAM = 0, parameter C_RST_PRIORITY = "CE", parameter C_INIT_VAL = "0", parameter C_HAS_EN = 0, parameter C_HAS_REGCE = 0, parameter C_DATA_WIDTH = 32, parameter C_ADDRB_WIDTH = 10, parameter C_HAS_MEM_OUTPUT_REGS = 0, parameter C_USE_SOFTECC = 0, parameter C_USE_ECC = 0, parameter NUM_STAGES = 1, parameter C_EN_ECC_PIPE = 0, parameter FLOP_DELAY = 100 ) ( input CLK, input RST, input EN, input REGCE, input [C_DATA_WIDTH-1:0] DIN_I, output reg [C_DATA_WIDTH-1:0] DOUT, input SBITERR_IN_I, input DBITERR_IN_I, output reg SBITERR, output reg DBITERR, input [C_ADDRB_WIDTH-1:0] RDADDRECC_IN_I, input ECCPIPECE, output reg [C_ADDRB_WIDTH-1:0] RDADDRECC ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_FAMILY,C_XDEVICEFAMILY: Designates architecture targeted. The following // options are available - "spartan3", "spartan6", // "virtex4", "virtex5", "virtex6" and "virtex6l". // C_RST_TYPE : Type of reset - Synchronous or Asynchronous // C_HAS_RST : Determines the presence of the RST port // C_RSTRAM : Determines if special reset behavior is used // C_RST_PRIORITY : Determines the priority between CE and SR // C_INIT_VAL : Initialization value // C_HAS_EN : Determines the presence of the EN port // C_HAS_REGCE : Determines the presence of the REGCE port // C_DATA_WIDTH : Memory write/read width // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_MEM_OUTPUT_REGS : Designates the use of a register at the output // of the RAM primitive // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // C_USE_ECC : Determines if the ECC feature is used or // not. Only applicable for V5 and V6 // NUM_STAGES : Determines the number of output stages // FLOP_DELAY : Constant delay for register assignments ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLK : Clock to synchronize all read and write operations // RST : Reset input to reset memory outputs to a user-defined // reset state // EN : Enable all read and write operations // REGCE : Register Clock Enable to control each pipeline output // register stages // DIN : Data input to the Output stage. // DOUT : Final Data output // SBITERR_IN : SBITERR input signal to the Output stage. // SBITERR : Final SBITERR Output signal. // DBITERR_IN : DBITERR input signal to the Output stage. // DBITERR : Final DBITERR Output signal. // RDADDRECC_IN : RDADDRECC input signal to the Output stage. // RDADDRECC : Final RDADDRECC Output signal. ////////////////////////////////////////////////////////////////////////// // Fix for CR-509792 localparam REG_STAGES = (NUM_STAGES < 2) ? 1 : NUM_STAGES-1; // Declare the pipeline registers // (includes mem output reg, mux pipeline stages, and mux output reg) reg [C_DATA_WIDTH*REG_STAGES-1:0] out_regs; reg [C_ADDRB_WIDTH*REG_STAGES-1:0] rdaddrecc_regs; reg [REG_STAGES-1:0] sbiterr_regs; reg [REG_STAGES-1:0] dbiterr_regs; reg [C_DATA_WIDTH*8-1:0] init_str = C_INIT_VAL; reg [C_DATA_WIDTH-1:0] init_val ; //********************************************* // Wire off optional inputs based on parameters //********************************************* wire en_i; wire regce_i; wire rst_i; // Internal signals reg [C_DATA_WIDTH-1:0] DIN; reg [C_ADDRB_WIDTH-1:0] RDADDRECC_IN; reg SBITERR_IN; reg DBITERR_IN; // Internal enable for output registers is tied to user EN or '1' depending // on parameters assign en_i = (C_HAS_EN==0 || EN); // Internal register enable for output registers is tied to user REGCE, EN or // '1' depending on parameters // For V4 ECC, REGCE is always 1 // Virtex-4 ECC Not Yet Supported assign regce_i = ((C_HAS_REGCE==1) && REGCE) || ((C_HAS_REGCE==0) && (C_HAS_EN==0 || EN)); //Internal SRR is tied to user RST or '0' depending on parameters assign rst_i = (C_HAS_RST==1) && RST; //**************************************************** // Power on: load up the output registers and latches //**************************************************** initial begin if (!($sscanf(init_str, "%h", init_val))) begin init_val = 0; end DOUT = init_val; RDADDRECC = 0; SBITERR = 1'b0; DBITERR = 1'b0; DIN = {(C_DATA_WIDTH){1'b0}}; RDADDRECC_IN = 0; SBITERR_IN = 0; DBITERR_IN = 0; // This will be one wider than need, but 0 is an error out_regs = {(REG_STAGES+1){init_val}}; rdaddrecc_regs = 0; sbiterr_regs = {(REG_STAGES+1){1'b0}}; dbiterr_regs = {(REG_STAGES+1){1'b0}}; end //*********************************************** // NUM_STAGES = 0 (No output registers. RAM only) //*********************************************** generate if (NUM_STAGES == 0) begin : zero_stages always @* begin DOUT = DIN; RDADDRECC = RDADDRECC_IN; SBITERR = SBITERR_IN; DBITERR = DBITERR_IN; end end endgenerate generate if (C_EN_ECC_PIPE == 0) begin : no_ecc_pipe_reg always @* begin DIN = DIN_I; SBITERR_IN = SBITERR_IN_I; DBITERR_IN = DBITERR_IN_I; RDADDRECC_IN = RDADDRECC_IN_I; end end endgenerate generate if (C_EN_ECC_PIPE == 1) begin : with_ecc_pipe_reg always @(posedge CLK) begin if(ECCPIPECE == 1) begin DIN <= #FLOP_DELAY DIN_I; SBITERR_IN <= #FLOP_DELAY SBITERR_IN_I; DBITERR_IN <= #FLOP_DELAY DBITERR_IN_I; RDADDRECC_IN <= #FLOP_DELAY RDADDRECC_IN_I; end end end endgenerate //*********************************************** // NUM_STAGES = 1 // (Mem Output Reg only or Mux Output Reg only) //*********************************************** // Possible valid combinations: // Note: C_HAS_MUX_OUTPUT_REGS_*=0 when (C_RSTRAM_*=1) // +-----------------------------------------+ // | C_RSTRAM_* | Reset Behavior | // +----------------+------------------------+ // | 0 | Normal Behavior | // +----------------+------------------------+ // | 1 | Special Behavior | // +----------------+------------------------+ // // Normal = REGCE gates reset, as in the case of all families except S3ADSP. // Special = EN gates reset, as in the case of S3ADSP. generate if (NUM_STAGES == 1 && (C_RSTRAM == 0 || (C_RSTRAM == 1 && (C_XDEVICEFAMILY != "spartan3adsp" && C_XDEVICEFAMILY != "aspartan3adsp" )) || C_HAS_MEM_OUTPUT_REGS == 0 || C_HAS_RST == 0)) begin : one_stages_norm always @(posedge CLK) begin if (C_RST_PRIORITY == "CE") begin //REGCE has priority if (regce_i && rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY 0; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY DIN; RDADDRECC <= #FLOP_DELAY RDADDRECC_IN; SBITERR <= #FLOP_DELAY SBITERR_IN; DBITERR <= #FLOP_DELAY DBITERR_IN; end //Output signal assignments end else begin //RST has priority if (rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY RDADDRECC_IN; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY DIN; RDADDRECC <= #FLOP_DELAY RDADDRECC_IN; SBITERR <= #FLOP_DELAY SBITERR_IN; DBITERR <= #FLOP_DELAY DBITERR_IN; end //Output signal assignments end //end Priority conditions end //end RST Type conditions end //end one_stages_norm generate statement endgenerate // Special Reset Behavior for S3ADSP generate if (NUM_STAGES == 1 && C_RSTRAM == 1 && (C_XDEVICEFAMILY =="spartan3adsp" || C_XDEVICEFAMILY =="aspartan3adsp")) begin : one_stage_splbhv always @(posedge CLK) begin if (en_i && rst_i) begin DOUT <= #FLOP_DELAY init_val; end else if (regce_i && !rst_i) begin DOUT <= #FLOP_DELAY DIN; end //Output signal assignments end //end CLK end //end one_stage_splbhv generate statement endgenerate //************************************************************ // NUM_STAGES > 1 // Mem Output Reg + Mux Output Reg // or // Mem Output Reg + Mux Pipeline Stages (>0) + Mux Output Reg // or // Mux Pipeline Stages (>0) + Mux Output Reg //************************************************************* generate if (NUM_STAGES > 1) begin : multi_stage //Asynchronous Reset always @(posedge CLK) begin if (C_RST_PRIORITY == "CE") begin //REGCE has priority if (regce_i && rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY 0; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY out_regs[C_DATA_WIDTH*(NUM_STAGES-2)+:C_DATA_WIDTH]; RDADDRECC <= #FLOP_DELAY rdaddrecc_regs[C_ADDRB_WIDTH*(NUM_STAGES-2)+:C_ADDRB_WIDTH]; SBITERR <= #FLOP_DELAY sbiterr_regs[NUM_STAGES-2]; DBITERR <= #FLOP_DELAY dbiterr_regs[NUM_STAGES-2]; end //Output signal assignments end else begin //RST has priority if (rst_i) begin DOUT <= #FLOP_DELAY init_val; RDADDRECC <= #FLOP_DELAY 0; SBITERR <= #FLOP_DELAY 1'b0; DBITERR <= #FLOP_DELAY 1'b0; end else if (regce_i) begin DOUT <= #FLOP_DELAY out_regs[C_DATA_WIDTH*(NUM_STAGES-2)+:C_DATA_WIDTH]; RDADDRECC <= #FLOP_DELAY rdaddrecc_regs[C_ADDRB_WIDTH*(NUM_STAGES-2)+:C_ADDRB_WIDTH]; SBITERR <= #FLOP_DELAY sbiterr_regs[NUM_STAGES-2]; DBITERR <= #FLOP_DELAY dbiterr_regs[NUM_STAGES-2]; end //Output signal assignments end //end Priority conditions // Shift the data through the output stages if (en_i) begin out_regs <= #FLOP_DELAY (out_regs << C_DATA_WIDTH) | DIN; rdaddrecc_regs <= #FLOP_DELAY (rdaddrecc_regs << C_ADDRB_WIDTH) | RDADDRECC_IN; sbiterr_regs <= #FLOP_DELAY (sbiterr_regs << 1) | SBITERR_IN; dbiterr_regs <= #FLOP_DELAY (dbiterr_regs << 1) | DBITERR_IN; end end //end CLK end //end multi_stage generate statement endgenerate endmodule module blk_mem_gen_v8_3_3_softecc_output_reg_stage #(parameter C_DATA_WIDTH = 32, parameter C_ADDRB_WIDTH = 10, parameter C_HAS_SOFTECC_OUTPUT_REGS_B= 0, parameter C_USE_SOFTECC = 0, parameter FLOP_DELAY = 100 ) ( input CLK, input [C_DATA_WIDTH-1:0] DIN, output reg [C_DATA_WIDTH-1:0] DOUT, input SBITERR_IN, input DBITERR_IN, output reg SBITERR, output reg DBITERR, input [C_ADDRB_WIDTH-1:0] RDADDRECC_IN, output reg [C_ADDRB_WIDTH-1:0] RDADDRECC ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_DATA_WIDTH : Memory write/read width // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_SOFTECC_OUTPUT_REGS_B : Designates the use of a register at the output // of the RAM primitive // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // FLOP_DELAY : Constant delay for register assignments ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLK : Clock to synchronize all read and write operations // DIN : Data input to the Output stage. // DOUT : Final Data output // SBITERR_IN : SBITERR input signal to the Output stage. // SBITERR : Final SBITERR Output signal. // DBITERR_IN : DBITERR input signal to the Output stage. // DBITERR : Final DBITERR Output signal. // RDADDRECC_IN : RDADDRECC input signal to the Output stage. // RDADDRECC : Final RDADDRECC Output signal. ////////////////////////////////////////////////////////////////////////// reg [C_DATA_WIDTH-1:0] dout_i = 0; reg sbiterr_i = 0; reg dbiterr_i = 0; reg [C_ADDRB_WIDTH-1:0] rdaddrecc_i = 0; //*********************************************** // NO OUTPUT REGISTERS. //*********************************************** generate if (C_HAS_SOFTECC_OUTPUT_REGS_B==0) begin : no_output_stage always @* begin DOUT = DIN; RDADDRECC = RDADDRECC_IN; SBITERR = SBITERR_IN; DBITERR = DBITERR_IN; end end endgenerate //*********************************************** // WITH OUTPUT REGISTERS. //*********************************************** generate if (C_HAS_SOFTECC_OUTPUT_REGS_B==1) begin : has_output_stage always @(posedge CLK) begin dout_i <= #FLOP_DELAY DIN; rdaddrecc_i <= #FLOP_DELAY RDADDRECC_IN; sbiterr_i <= #FLOP_DELAY SBITERR_IN; dbiterr_i <= #FLOP_DELAY DBITERR_IN; end always @* begin DOUT = dout_i; RDADDRECC = rdaddrecc_i; SBITERR = sbiterr_i; DBITERR = dbiterr_i; end //end always end //end in_or_out_stage generate statement endgenerate endmodule //***************************************************************************** // Main Memory module // // This module is the top-level behavioral model and this implements the RAM //***************************************************************************** module blk_mem_gen_v8_3_3_mem_module #(parameter C_CORENAME = "blk_mem_gen_v8_3_3", parameter C_FAMILY = "virtex7", parameter C_XDEVICEFAMILY = "virtex7", parameter C_MEM_TYPE = 2, parameter C_BYTE_SIZE = 9, parameter C_USE_BRAM_BLOCK = 0, parameter C_ALGORITHM = 1, parameter C_PRIM_TYPE = 3, parameter C_LOAD_INIT_FILE = 0, parameter C_INIT_FILE_NAME = "", parameter C_INIT_FILE = "", parameter C_USE_DEFAULT_DATA = 0, parameter C_DEFAULT_DATA = "0", parameter C_RST_TYPE = "SYNC", parameter C_HAS_RSTA = 0, parameter C_RST_PRIORITY_A = "CE", parameter C_RSTRAM_A = 0, parameter C_INITA_VAL = "0", parameter C_HAS_ENA = 1, parameter C_HAS_REGCEA = 0, parameter C_USE_BYTE_WEA = 0, parameter C_WEA_WIDTH = 1, parameter C_WRITE_MODE_A = "WRITE_FIRST", parameter C_WRITE_WIDTH_A = 32, parameter C_READ_WIDTH_A = 32, parameter C_WRITE_DEPTH_A = 64, parameter C_READ_DEPTH_A = 64, parameter C_ADDRA_WIDTH = 5, parameter C_HAS_RSTB = 0, parameter C_RST_PRIORITY_B = "CE", parameter C_RSTRAM_B = 0, parameter C_INITB_VAL = "", parameter C_HAS_ENB = 1, parameter C_HAS_REGCEB = 0, parameter C_USE_BYTE_WEB = 0, parameter C_WEB_WIDTH = 1, parameter C_WRITE_MODE_B = "WRITE_FIRST", parameter C_WRITE_WIDTH_B = 32, parameter C_READ_WIDTH_B = 32, parameter C_WRITE_DEPTH_B = 64, parameter C_READ_DEPTH_B = 64, parameter C_ADDRB_WIDTH = 5, parameter C_HAS_MEM_OUTPUT_REGS_A = 0, parameter C_HAS_MEM_OUTPUT_REGS_B = 0, parameter C_HAS_MUX_OUTPUT_REGS_A = 0, parameter C_HAS_MUX_OUTPUT_REGS_B = 0, parameter C_HAS_SOFTECC_INPUT_REGS_A = 0, parameter C_HAS_SOFTECC_OUTPUT_REGS_B= 0, parameter C_MUX_PIPELINE_STAGES = 0, parameter C_USE_SOFTECC = 0, parameter C_USE_ECC = 0, parameter C_HAS_INJECTERR = 0, parameter C_SIM_COLLISION_CHECK = "NONE", parameter C_COMMON_CLK = 1, parameter FLOP_DELAY = 100, parameter C_DISABLE_WARN_BHV_COLL = 0, parameter C_EN_ECC_PIPE = 0, parameter C_DISABLE_WARN_BHV_RANGE = 0 ) (input CLKA, input RSTA, input ENA, input REGCEA, input [C_WEA_WIDTH-1:0] WEA, input [C_ADDRA_WIDTH-1:0] ADDRA, input [C_WRITE_WIDTH_A-1:0] DINA, output [C_READ_WIDTH_A-1:0] DOUTA, input CLKB, input RSTB, input ENB, input REGCEB, input [C_WEB_WIDTH-1:0] WEB, input [C_ADDRB_WIDTH-1:0] ADDRB, input [C_WRITE_WIDTH_B-1:0] DINB, output [C_READ_WIDTH_B-1:0] DOUTB, input INJECTSBITERR, input INJECTDBITERR, input ECCPIPECE, input SLEEP, output SBITERR, output DBITERR, output [C_ADDRB_WIDTH-1:0] RDADDRECC ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_CORENAME : Instance name of the Block Memory Generator core // C_FAMILY,C_XDEVICEFAMILY: Designates architecture targeted. The following // options are available - "spartan3", "spartan6", // "virtex4", "virtex5", "virtex6" and "virtex6l". // C_MEM_TYPE : Designates memory type. // It can be // 0 - Single Port Memory // 1 - Simple Dual Port Memory // 2 - True Dual Port Memory // 3 - Single Port Read Only Memory // 4 - Dual Port Read Only Memory // C_BYTE_SIZE : Size of a byte (8 or 9 bits) // C_ALGORITHM : Designates the algorithm method used // for constructing the memory. // It can be Fixed_Primitives, Minimum_Area or // Low_Power // C_PRIM_TYPE : Designates the user selected primitive used to // construct the memory. // // C_LOAD_INIT_FILE : Designates the use of an initialization file to // initialize memory contents. // C_INIT_FILE_NAME : Memory initialization file name. // C_USE_DEFAULT_DATA : Designates whether to fill remaining // initialization space with default data // C_DEFAULT_DATA : Default value of all memory locations // not initialized by the memory // initialization file. // C_RST_TYPE : Type of reset - Synchronous or Asynchronous // C_HAS_RSTA : Determines the presence of the RSTA port // C_RST_PRIORITY_A : Determines the priority between CE and SR for // Port A. // C_RSTRAM_A : Determines if special reset behavior is used for // Port A // C_INITA_VAL : The initialization value for Port A // C_HAS_ENA : Determines the presence of the ENA port // C_HAS_REGCEA : Determines the presence of the REGCEA port // C_USE_BYTE_WEA : Determines if the Byte Write is used or not. // C_WEA_WIDTH : The width of the WEA port // C_WRITE_MODE_A : Configurable write mode for Port A. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_A : Memory write width for Port A. // C_READ_WIDTH_A : Memory read width for Port A. // C_WRITE_DEPTH_A : Memory write depth for Port A. // C_READ_DEPTH_A : Memory read depth for Port A. // C_ADDRA_WIDTH : Width of the ADDRA input port // C_HAS_RSTB : Determines the presence of the RSTB port // C_RST_PRIORITY_B : Determines the priority between CE and SR for // Port B. // C_RSTRAM_B : Determines if special reset behavior is used for // Port B // C_INITB_VAL : The initialization value for Port B // C_HAS_ENB : Determines the presence of the ENB port // C_HAS_REGCEB : Determines the presence of the REGCEB port // C_USE_BYTE_WEB : Determines if the Byte Write is used or not. // C_WEB_WIDTH : The width of the WEB port // C_WRITE_MODE_B : Configurable write mode for Port B. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_B : Memory write width for Port B. // C_READ_WIDTH_B : Memory read width for Port B. // C_WRITE_DEPTH_B : Memory write depth for Port B. // C_READ_DEPTH_B : Memory read depth for Port B. // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_MEM_OUTPUT_REGS_A : Designates the use of a register at the output // of the RAM primitive for Port A. // C_HAS_MEM_OUTPUT_REGS_B : Designates the use of a register at the output // of the RAM primitive for Port B. // C_HAS_MUX_OUTPUT_REGS_A : Designates the use of a register at the output // of the MUX for Port A. // C_HAS_MUX_OUTPUT_REGS_B : Designates the use of a register at the output // of the MUX for Port B. // C_MUX_PIPELINE_STAGES : Designates the number of pipeline stages in // between the muxes. // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // C_USE_ECC : Determines if the ECC feature is used or // not. Only applicable for V5 and V6 // C_HAS_INJECTERR : Determines if the error injection pins // are present or not. If the ECC feature // is not used, this value is defaulted to // 0, else the following are the allowed // values: // 0 : No INJECTSBITERR or INJECTDBITERR pins // 1 : Only INJECTSBITERR pin exists // 2 : Only INJECTDBITERR pin exists // 3 : Both INJECTSBITERR and INJECTDBITERR pins exist // C_SIM_COLLISION_CHECK : Controls the disabling of Unisim model collision // warnings. It can be "ALL", "NONE", // "Warnings_Only" or "Generate_X_Only". // C_COMMON_CLK : Determins if the core has a single CLK input. // C_DISABLE_WARN_BHV_COLL : Controls the Behavioral Model Collision warnings // C_DISABLE_WARN_BHV_RANGE: Controls the Behavioral Model Out of Range // warnings ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLKA : Clock to synchronize all read and write operations of Port A. // RSTA : Reset input to reset memory outputs to a user-defined // reset state for Port A. // ENA : Enable all read and write operations of Port A. // REGCEA : Register Clock Enable to control each pipeline output // register stages for Port A. // WEA : Write Enable to enable all write operations of Port A. // ADDRA : Address of Port A. // DINA : Data input of Port A. // DOUTA : Data output of Port A. // CLKB : Clock to synchronize all read and write operations of Port B. // RSTB : Reset input to reset memory outputs to a user-defined // reset state for Port B. // ENB : Enable all read and write operations of Port B. // REGCEB : Register Clock Enable to control each pipeline output // register stages for Port B. // WEB : Write Enable to enable all write operations of Port B. // ADDRB : Address of Port B. // DINB : Data input of Port B. // DOUTB : Data output of Port B. // INJECTSBITERR : Single Bit ECC Error Injection Pin. // INJECTDBITERR : Double Bit ECC Error Injection Pin. // SBITERR : Output signal indicating that a Single Bit ECC Error has been // detected and corrected. // DBITERR : Output signal indicating that a Double Bit ECC Error has been // detected. // RDADDRECC : Read Address Output signal indicating address at which an // ECC error has occurred. ////////////////////////////////////////////////////////////////////////// // Note: C_CORENAME parameter is hard-coded to "blk_mem_gen_v8_3_3" and it is // only used by this module to print warning messages. It is neither passed // down from blk_mem_gen_v8_3_3_xst.v nor present in the instantiation template // coregen generates //*************************************************************************** // constants for the core behavior //*************************************************************************** // file handles for logging //-------------------------------------------------- localparam ADDRFILE = 32'h8000_0001; //stdout for addr out of range localparam COLLFILE = 32'h8000_0001; //stdout for coll detection localparam ERRFILE = 32'h8000_0001; //stdout for file I/O errors // other constants //-------------------------------------------------- localparam COLL_DELAY = 100; // 100 ps // locally derived parameters to determine memory shape //----------------------------------------------------- localparam CHKBIT_WIDTH = (C_WRITE_WIDTH_A>57 ? 8 : (C_WRITE_WIDTH_A>26 ? 7 : (C_WRITE_WIDTH_A>11 ? 6 : (C_WRITE_WIDTH_A>4 ? 5 : (C_WRITE_WIDTH_A<5 ? 4 :0))))); localparam MIN_WIDTH_A = (C_WRITE_WIDTH_A < C_READ_WIDTH_A) ? C_WRITE_WIDTH_A : C_READ_WIDTH_A; localparam MIN_WIDTH_B = (C_WRITE_WIDTH_B < C_READ_WIDTH_B) ? C_WRITE_WIDTH_B : C_READ_WIDTH_B; localparam MIN_WIDTH = (MIN_WIDTH_A < MIN_WIDTH_B) ? MIN_WIDTH_A : MIN_WIDTH_B; localparam MAX_DEPTH_A = (C_WRITE_DEPTH_A > C_READ_DEPTH_A) ? C_WRITE_DEPTH_A : C_READ_DEPTH_A; localparam MAX_DEPTH_B = (C_WRITE_DEPTH_B > C_READ_DEPTH_B) ? C_WRITE_DEPTH_B : C_READ_DEPTH_B; localparam MAX_DEPTH = (MAX_DEPTH_A > MAX_DEPTH_B) ? MAX_DEPTH_A : MAX_DEPTH_B; // locally derived parameters to assist memory access //---------------------------------------------------- // Calculate the width ratios of each port with respect to the narrowest // port localparam WRITE_WIDTH_RATIO_A = C_WRITE_WIDTH_A/MIN_WIDTH; localparam READ_WIDTH_RATIO_A = C_READ_WIDTH_A/MIN_WIDTH; localparam WRITE_WIDTH_RATIO_B = C_WRITE_WIDTH_B/MIN_WIDTH; localparam READ_WIDTH_RATIO_B = C_READ_WIDTH_B/MIN_WIDTH; // To modify the LSBs of the 'wider' data to the actual // address value //---------------------------------------------------- localparam WRITE_ADDR_A_DIV = C_WRITE_WIDTH_A/MIN_WIDTH_A; localparam READ_ADDR_A_DIV = C_READ_WIDTH_A/MIN_WIDTH_A; localparam WRITE_ADDR_B_DIV = C_WRITE_WIDTH_B/MIN_WIDTH_B; localparam READ_ADDR_B_DIV = C_READ_WIDTH_B/MIN_WIDTH_B; // If byte writes aren't being used, make sure BYTE_SIZE is not // wider than the memory elements to avoid compilation warnings localparam BYTE_SIZE = (C_BYTE_SIZE < MIN_WIDTH) ? C_BYTE_SIZE : MIN_WIDTH; // The memory reg [MIN_WIDTH-1:0] memory [0:MAX_DEPTH-1]; reg [MIN_WIDTH-1:0] temp_mem_array [0:MAX_DEPTH-1]; reg [C_WRITE_WIDTH_A+CHKBIT_WIDTH-1:0] doublebit_error = 3; // ECC error arrays reg sbiterr_arr [0:MAX_DEPTH-1]; reg dbiterr_arr [0:MAX_DEPTH-1]; reg softecc_sbiterr_arr [0:MAX_DEPTH-1]; reg softecc_dbiterr_arr [0:MAX_DEPTH-1]; // Memory output 'latches' reg [C_READ_WIDTH_A-1:0] memory_out_a; reg [C_READ_WIDTH_B-1:0] memory_out_b; // ECC error inputs and outputs from output_stage module: reg sbiterr_in; wire sbiterr_sdp; reg dbiterr_in; wire dbiterr_sdp; wire [C_READ_WIDTH_B-1:0] dout_i; wire dbiterr_i; wire sbiterr_i; wire [C_ADDRB_WIDTH-1:0] rdaddrecc_i; reg [C_ADDRB_WIDTH-1:0] rdaddrecc_in; wire [C_ADDRB_WIDTH-1:0] rdaddrecc_sdp; // Reset values reg [C_READ_WIDTH_A-1:0] inita_val; reg [C_READ_WIDTH_B-1:0] initb_val; // Collision detect reg is_collision; reg is_collision_a, is_collision_delay_a; reg is_collision_b, is_collision_delay_b; // Temporary variables for initialization //--------------------------------------- integer status; integer initfile; integer meminitfile; // data input buffer reg [C_WRITE_WIDTH_A-1:0] mif_data; reg [C_WRITE_WIDTH_A-1:0] mem_data; // string values in hex reg [C_READ_WIDTH_A*8-1:0] inita_str = C_INITA_VAL; reg [C_READ_WIDTH_B*8-1:0] initb_str = C_INITB_VAL; reg [C_WRITE_WIDTH_A*8-1:0] default_data_str = C_DEFAULT_DATA; // initialization filename reg [1023*8-1:0] init_file_str = C_INIT_FILE_NAME; reg [1023*8-1:0] mem_init_file_str = C_INIT_FILE; //Constants used to calculate the effective address widths for each of the //four ports. integer cnt = 1; integer write_addr_a_width, read_addr_a_width; integer write_addr_b_width, read_addr_b_width; localparam C_FAMILY_LOCALPARAM = (C_FAMILY=="zynquplus"?"virtex7":(C_FAMILY=="kintexuplus"?"virtex7":(C_FAMILY=="virtexuplus"?"virtex7":(C_FAMILY=="virtexu"?"virtex7":(C_FAMILY=="kintexu" ? "virtex7":(C_FAMILY=="virtex7" ? "virtex7" : (C_FAMILY=="virtex7l" ? "virtex7" : (C_FAMILY=="qvirtex7" ? "virtex7" : (C_FAMILY=="qvirtex7l" ? "virtex7" : (C_FAMILY=="kintex7" ? "virtex7" : (C_FAMILY=="kintex7l" ? "virtex7" : (C_FAMILY=="qkintex7" ? "virtex7" : (C_FAMILY=="qkintex7l" ? "virtex7" : (C_FAMILY=="artix7" ? "virtex7" : (C_FAMILY=="artix7l" ? "virtex7" : (C_FAMILY=="qartix7" ? "virtex7" : (C_FAMILY=="qartix7l" ? "virtex7" : (C_FAMILY=="aartix7" ? "virtex7" : (C_FAMILY=="zynq" ? "virtex7" : (C_FAMILY=="azynq" ? "virtex7" : (C_FAMILY=="qzynq" ? "virtex7" : C_FAMILY))))))))))))))))))))); // Internal configuration parameters //--------------------------------------------- localparam SINGLE_PORT = (C_MEM_TYPE==0 || C_MEM_TYPE==3); localparam IS_ROM = (C_MEM_TYPE==3 || C_MEM_TYPE==4); localparam HAS_A_WRITE = (!IS_ROM); localparam HAS_B_WRITE = (C_MEM_TYPE==2); localparam HAS_A_READ = (C_MEM_TYPE!=1); localparam HAS_B_READ = (!SINGLE_PORT); localparam HAS_B_PORT = (HAS_B_READ || HAS_B_WRITE); // Calculate the mux pipeline register stages for Port A and Port B //------------------------------------------------------------------ localparam MUX_PIPELINE_STAGES_A = (C_HAS_MUX_OUTPUT_REGS_A) ? C_MUX_PIPELINE_STAGES : 0; localparam MUX_PIPELINE_STAGES_B = (C_HAS_MUX_OUTPUT_REGS_B) ? C_MUX_PIPELINE_STAGES : 0; // Calculate total number of register stages in the core // ----------------------------------------------------- localparam NUM_OUTPUT_STAGES_A = (C_HAS_MEM_OUTPUT_REGS_A+MUX_PIPELINE_STAGES_A+C_HAS_MUX_OUTPUT_REGS_A); localparam NUM_OUTPUT_STAGES_B = (C_HAS_MEM_OUTPUT_REGS_B+MUX_PIPELINE_STAGES_B+C_HAS_MUX_OUTPUT_REGS_B); wire ena_i; wire enb_i; wire reseta_i; wire resetb_i; wire [C_WEA_WIDTH-1:0] wea_i; wire [C_WEB_WIDTH-1:0] web_i; wire rea_i; wire reb_i; wire rsta_outp_stage; wire rstb_outp_stage; // ECC SBITERR/DBITERR Outputs // The ECC Behavior is modeled by the behavioral models only for Virtex-6. // For Virtex-5, these outputs will be tied to 0. assign SBITERR = ((C_MEM_TYPE == 1 && C_USE_ECC == 1) || C_USE_SOFTECC == 1)?sbiterr_sdp:0; assign DBITERR = ((C_MEM_TYPE == 1 && C_USE_ECC == 1) || C_USE_SOFTECC == 1)?dbiterr_sdp:0; assign RDADDRECC = (((C_FAMILY_LOCALPARAM == "virtex7") && C_MEM_TYPE == 1 && C_USE_ECC == 1) || C_USE_SOFTECC == 1)?rdaddrecc_sdp:0; // This effectively wires off optional inputs assign ena_i = (C_HAS_ENA==0) || ENA; assign enb_i = ((C_HAS_ENB==0) || ENB) && HAS_B_PORT; //assign wea_i = (HAS_A_WRITE && ena_i) ? WEA : 'b0; // To Fix CR855535 assign wea_i = (HAS_A_WRITE == 1 && C_MEM_TYPE == 1 &&C_USE_ECC == 1 && C_HAS_ENA == 1 && ENA == 1) ? 'b1 :(HAS_A_WRITE == 1 && C_MEM_TYPE == 1 &&C_USE_ECC == 1 && C_HAS_ENA == 0) ? WEA : (HAS_A_WRITE && ena_i && C_USE_ECC == 0) ? WEA : 'b0; assign web_i = (HAS_B_WRITE && enb_i) ? WEB : 'b0; assign rea_i = (HAS_A_READ) ? ena_i : 'b0; assign reb_i = (HAS_B_READ) ? enb_i : 'b0; // These signals reset the memory latches assign reseta_i = ((C_HAS_RSTA==1 && RSTA && NUM_OUTPUT_STAGES_A==0) || (C_HAS_RSTA==1 && RSTA && C_RSTRAM_A==1)); assign resetb_i = ((C_HAS_RSTB==1 && RSTB && NUM_OUTPUT_STAGES_B==0) || (C_HAS_RSTB==1 && RSTB && C_RSTRAM_B==1)); // Tasks to access the memory //--------------------------- //************** // write_a //************** task write_a (input reg [C_ADDRA_WIDTH-1:0] addr, input reg [C_WEA_WIDTH-1:0] byte_en, input reg [C_WRITE_WIDTH_A-1:0] data, input inj_sbiterr, input inj_dbiterr); reg [C_WRITE_WIDTH_A-1:0] current_contents; reg [C_ADDRA_WIDTH-1:0] address; integer i; begin // Shift the address by the ratio address = (addr/WRITE_ADDR_A_DIV); if (address >= C_WRITE_DEPTH_A) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for A Write", C_CORENAME, addr); end // valid address end else begin // Combine w/ byte writes if (C_USE_BYTE_WEA) begin // Get the current memory contents if (WRITE_WIDTH_RATIO_A == 1) begin // Workaround for IUS 5.5 part-select issue current_contents = memory[address]; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_A; i = i + 1) begin current_contents[MIN_WIDTH*i+:MIN_WIDTH] = memory[address*WRITE_WIDTH_RATIO_A + i]; end end // Apply incoming bytes if (C_WEA_WIDTH == 1) begin // Workaround for IUS 5.5 part-select issue if (byte_en[0]) begin current_contents = data; end end else begin for (i = 0; i < C_WEA_WIDTH; i = i + 1) begin if (byte_en[i]) begin current_contents[BYTE_SIZE*i+:BYTE_SIZE] = data[BYTE_SIZE*i+:BYTE_SIZE]; end end end // No byte-writes, overwrite the whole word end else begin current_contents = data; end // Insert double bit errors: if (C_USE_ECC == 1) begin if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin // Modified for Implementing CR_859399 current_contents[0] = !(current_contents[30]); current_contents[1] = !(current_contents[62]); /*current_contents[0] = !(current_contents[0]); current_contents[1] = !(current_contents[1]);*/ end end // Insert softecc double bit errors: if (C_USE_SOFTECC == 1) begin if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-1:2] = doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-3:0]; doublebit_error[0] = doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-1]; doublebit_error[1] = doublebit_error[C_WRITE_WIDTH_A+CHKBIT_WIDTH-2]; current_contents = current_contents ^ doublebit_error[C_WRITE_WIDTH_A-1:0]; end end // Write data to memory if (WRITE_WIDTH_RATIO_A == 1) begin // Workaround for IUS 5.5 part-select issue memory[address*WRITE_WIDTH_RATIO_A] = current_contents; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_A; i = i + 1) begin memory[address*WRITE_WIDTH_RATIO_A + i] = current_contents[MIN_WIDTH*i+:MIN_WIDTH]; end end // Store the address at which error is injected: if ((C_FAMILY_LOCALPARAM == "virtex7") && C_USE_ECC == 1) begin if ((C_HAS_INJECTERR == 1 && inj_sbiterr == 1'b1) || (C_HAS_INJECTERR == 3 && inj_sbiterr == 1'b1 && inj_dbiterr != 1'b1)) begin sbiterr_arr[addr] = 1; end else begin sbiterr_arr[addr] = 0; end if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin dbiterr_arr[addr] = 1; end else begin dbiterr_arr[addr] = 0; end end // Store the address at which softecc error is injected: if (C_USE_SOFTECC == 1) begin if ((C_HAS_INJECTERR == 1 && inj_sbiterr == 1'b1) || (C_HAS_INJECTERR == 3 && inj_sbiterr == 1'b1 && inj_dbiterr != 1'b1)) begin softecc_sbiterr_arr[addr] = 1; end else begin softecc_sbiterr_arr[addr] = 0; end if ((C_HAS_INJECTERR == 2 || C_HAS_INJECTERR == 3) && inj_dbiterr == 1'b1) begin softecc_dbiterr_arr[addr] = 1; end else begin softecc_dbiterr_arr[addr] = 0; end end end end endtask //************** // write_b //************** task write_b (input reg [C_ADDRB_WIDTH-1:0] addr, input reg [C_WEB_WIDTH-1:0] byte_en, input reg [C_WRITE_WIDTH_B-1:0] data); reg [C_WRITE_WIDTH_B-1:0] current_contents; reg [C_ADDRB_WIDTH-1:0] address; integer i; begin // Shift the address by the ratio address = (addr/WRITE_ADDR_B_DIV); if (address >= C_WRITE_DEPTH_B) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for B Write", C_CORENAME, addr); end // valid address end else begin // Combine w/ byte writes if (C_USE_BYTE_WEB) begin // Get the current memory contents if (WRITE_WIDTH_RATIO_B == 1) begin // Workaround for IUS 5.5 part-select issue current_contents = memory[address]; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_B; i = i + 1) begin current_contents[MIN_WIDTH*i+:MIN_WIDTH] = memory[address*WRITE_WIDTH_RATIO_B + i]; end end // Apply incoming bytes if (C_WEB_WIDTH == 1) begin // Workaround for IUS 5.5 part-select issue if (byte_en[0]) begin current_contents = data; end end else begin for (i = 0; i < C_WEB_WIDTH; i = i + 1) begin if (byte_en[i]) begin current_contents[BYTE_SIZE*i+:BYTE_SIZE] = data[BYTE_SIZE*i+:BYTE_SIZE]; end end end // No byte-writes, overwrite the whole word end else begin current_contents = data; end // Write data to memory if (WRITE_WIDTH_RATIO_B == 1) begin // Workaround for IUS 5.5 part-select issue memory[address*WRITE_WIDTH_RATIO_B] = current_contents; end else begin for (i = 0; i < WRITE_WIDTH_RATIO_B; i = i + 1) begin memory[address*WRITE_WIDTH_RATIO_B + i] = current_contents[MIN_WIDTH*i+:MIN_WIDTH]; end end end end endtask //************** // read_a //************** task read_a (input reg [C_ADDRA_WIDTH-1:0] addr, input reg reset); reg [C_ADDRA_WIDTH-1:0] address; integer i; begin if (reset) begin memory_out_a <= #FLOP_DELAY inita_val; end else begin // Shift the address by the ratio address = (addr/READ_ADDR_A_DIV); if (address >= C_READ_DEPTH_A) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for A Read", C_CORENAME, addr); end memory_out_a <= #FLOP_DELAY 'bX; // valid address end else begin if (READ_WIDTH_RATIO_A==1) begin memory_out_a <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_A]; end else begin // Increment through the 'partial' words in the memory for (i = 0; i < READ_WIDTH_RATIO_A; i = i + 1) begin memory_out_a[MIN_WIDTH*i+:MIN_WIDTH] <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_A + i]; end end //end READ_WIDTH_RATIO_A==1 loop end //end valid address loop end //end reset-data assignment loops end endtask //************** // read_b //************** task read_b (input reg [C_ADDRB_WIDTH-1:0] addr, input reg reset); reg [C_ADDRB_WIDTH-1:0] address; integer i; begin if (reset) begin memory_out_b <= #FLOP_DELAY initb_val; sbiterr_in <= #FLOP_DELAY 1'b0; dbiterr_in <= #FLOP_DELAY 1'b0; rdaddrecc_in <= #FLOP_DELAY 0; end else begin // Shift the address address = (addr/READ_ADDR_B_DIV); if (address >= C_READ_DEPTH_B) begin if (!C_DISABLE_WARN_BHV_RANGE) begin $fdisplay(ADDRFILE, "%0s WARNING: Address %0h is outside range for B Read", C_CORENAME, addr); end memory_out_b <= #FLOP_DELAY 'bX; sbiterr_in <= #FLOP_DELAY 1'bX; dbiterr_in <= #FLOP_DELAY 1'bX; rdaddrecc_in <= #FLOP_DELAY 'bX; // valid address end else begin if (READ_WIDTH_RATIO_B==1) begin memory_out_b <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_B]; end else begin // Increment through the 'partial' words in the memory for (i = 0; i < READ_WIDTH_RATIO_B; i = i + 1) begin memory_out_b[MIN_WIDTH*i+:MIN_WIDTH] <= #FLOP_DELAY memory[address*READ_WIDTH_RATIO_B + i]; end end if ((C_FAMILY_LOCALPARAM == "virtex7") && C_USE_ECC == 1) begin rdaddrecc_in <= #FLOP_DELAY addr; if (sbiterr_arr[addr] == 1) begin sbiterr_in <= #FLOP_DELAY 1'b1; end else begin sbiterr_in <= #FLOP_DELAY 1'b0; end if (dbiterr_arr[addr] == 1) begin dbiterr_in <= #FLOP_DELAY 1'b1; end else begin dbiterr_in <= #FLOP_DELAY 1'b0; end end else if (C_USE_SOFTECC == 1) begin rdaddrecc_in <= #FLOP_DELAY addr; if (softecc_sbiterr_arr[addr] == 1) begin sbiterr_in <= #FLOP_DELAY 1'b1; end else begin sbiterr_in <= #FLOP_DELAY 1'b0; end if (softecc_dbiterr_arr[addr] == 1) begin dbiterr_in <= #FLOP_DELAY 1'b1; end else begin dbiterr_in <= #FLOP_DELAY 1'b0; end end else begin rdaddrecc_in <= #FLOP_DELAY 0; dbiterr_in <= #FLOP_DELAY 1'b0; sbiterr_in <= #FLOP_DELAY 1'b0; end //end SOFTECC Loop end //end Valid address loop end //end reset-data assignment loops end endtask //************** // reset_a //************** task reset_a (input reg reset); begin if (reset) memory_out_a <= #FLOP_DELAY inita_val; end endtask //************** // reset_b //************** task reset_b (input reg reset); begin if (reset) memory_out_b <= #FLOP_DELAY initb_val; end endtask //************** // init_memory //************** task init_memory; integer i, j, addr_step; integer status; reg [C_WRITE_WIDTH_A-1:0] default_data; begin default_data = 0; //Display output message indicating that the behavioral model is being //initialized if (C_USE_DEFAULT_DATA || C_LOAD_INIT_FILE) $display(" Block Memory Generator module loading initial data..."); // Convert the default to hex if (C_USE_DEFAULT_DATA) begin if (default_data_str == "") begin $fdisplay(ERRFILE, "%0s ERROR: C_DEFAULT_DATA is empty!", C_CORENAME); $finish; end else begin status = $sscanf(default_data_str, "%h", default_data); if (status == 0) begin $fdisplay(ERRFILE, {"%0s ERROR: Unsuccessful hexadecimal read", "from C_DEFAULT_DATA: %0s"}, C_CORENAME, C_DEFAULT_DATA); $finish; end end end // Step by WRITE_ADDR_A_DIV through the memory via the // Port A write interface to hit every location once addr_step = WRITE_ADDR_A_DIV; // 'write' to every location with default (or 0) for (i = 0; i < C_WRITE_DEPTH_A*addr_step; i = i + addr_step) begin write_a(i, {C_WEA_WIDTH{1'b1}}, default_data, 1'b0, 1'b0); end // Get specialized data from the MIF file if (C_LOAD_INIT_FILE) begin if (init_file_str == "") begin $fdisplay(ERRFILE, "%0s ERROR: C_INIT_FILE_NAME is empty!", C_CORENAME); $finish; end else begin initfile = $fopen(init_file_str, "r"); if (initfile == 0) begin $fdisplay(ERRFILE, {"%0s, ERROR: Problem opening", "C_INIT_FILE_NAME: %0s!"}, C_CORENAME, init_file_str); $finish; end else begin // loop through the mif file, loading in the data for (i = 0; i < C_WRITE_DEPTH_A*addr_step; i = i + addr_step) begin status = $fscanf(initfile, "%b", mif_data); if (status > 0) begin write_a(i, {C_WEA_WIDTH{1'b1}}, mif_data, 1'b0, 1'b0); end end $fclose(initfile); end //initfile end //init_file_str end //C_LOAD_INIT_FILE if (C_USE_BRAM_BLOCK) begin // Get specialized data from the MIF file if (C_INIT_FILE != "NONE") begin if (mem_init_file_str == "") begin $fdisplay(ERRFILE, "%0s ERROR: C_INIT_FILE is empty!", C_CORENAME); $finish; end else begin meminitfile = $fopen(mem_init_file_str, "r"); if (meminitfile == 0) begin $fdisplay(ERRFILE, {"%0s, ERROR: Problem opening", "C_INIT_FILE: %0s!"}, C_CORENAME, mem_init_file_str); $finish; end else begin // loop through the mif file, loading in the data $readmemh(mem_init_file_str, memory ); for (j = 0; j < MAX_DEPTH-1 ; j = j + 1) begin end $fclose(meminitfile); end //meminitfile end //mem_init_file_str end //C_INIT_FILE end //C_USE_BRAM_BLOCK //Display output message indicating that the behavioral model is done //initializing if (C_USE_DEFAULT_DATA || C_LOAD_INIT_FILE) $display(" Block Memory Generator data initialization complete."); end endtask //************** // log2roundup //************** function integer log2roundup (input integer data_value); integer width; integer cnt; begin width = 0; if (data_value > 1) begin for(cnt=1 ; cnt < data_value ; cnt = cnt * 2) begin width = width + 1; end //loop end //if log2roundup = width; end //log2roundup endfunction //******************* // collision_check //******************* function integer collision_check (input reg [C_ADDRA_WIDTH-1:0] addr_a, input integer iswrite_a, input reg [C_ADDRB_WIDTH-1:0] addr_b, input integer iswrite_b); reg c_aw_bw, c_aw_br, c_ar_bw; integer scaled_addra_to_waddrb_width; integer scaled_addrb_to_waddrb_width; integer scaled_addra_to_waddra_width; integer scaled_addrb_to_waddra_width; integer scaled_addra_to_raddrb_width; integer scaled_addrb_to_raddrb_width; integer scaled_addra_to_raddra_width; integer scaled_addrb_to_raddra_width; begin c_aw_bw = 0; c_aw_br = 0; c_ar_bw = 0; //If write_addr_b_width is smaller, scale both addresses to that width for //comparing write_addr_a and write_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to write_addr_b_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to write_addr_b_width. Once both are scaled to //write_addr_b_width, compare. scaled_addra_to_waddrb_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-write_addr_b_width)); scaled_addrb_to_waddrb_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-write_addr_b_width)); //If write_addr_a_width is smaller, scale both addresses to that width for //comparing write_addr_a and write_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to write_addr_a_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to write_addr_a_width. Once both are scaled to //write_addr_a_width, compare. scaled_addra_to_waddra_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-write_addr_a_width)); scaled_addrb_to_waddra_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-write_addr_a_width)); //If read_addr_b_width is smaller, scale both addresses to that width for //comparing write_addr_a and read_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to read_addr_b_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to read_addr_b_width. Once both are scaled to //read_addr_b_width, compare. scaled_addra_to_raddrb_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-read_addr_b_width)); scaled_addrb_to_raddrb_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-read_addr_b_width)); //If read_addr_a_width is smaller, scale both addresses to that width for //comparing read_addr_a and write_addr_b; addr_a starts as C_ADDRA_WIDTH, //scale it down to read_addr_a_width. addr_b starts as C_ADDRB_WIDTH, //scale it down to read_addr_a_width. Once both are scaled to //read_addr_a_width, compare. scaled_addra_to_raddra_width = ((addr_a)/ 2**(C_ADDRA_WIDTH-read_addr_a_width)); scaled_addrb_to_raddra_width = ((addr_b)/ 2**(C_ADDRB_WIDTH-read_addr_a_width)); //Look for a write-write collision. In order for a write-write //collision to exist, both ports must have a write transaction. if (iswrite_a && iswrite_b) begin if (write_addr_a_width > write_addr_b_width) begin if (scaled_addra_to_waddrb_width == scaled_addrb_to_waddrb_width) begin c_aw_bw = 1; end else begin c_aw_bw = 0; end end else begin if (scaled_addrb_to_waddra_width == scaled_addra_to_waddra_width) begin c_aw_bw = 1; end else begin c_aw_bw = 0; end end //width end //iswrite_a and iswrite_b //If the B port is reading (which means it is enabled - so could be //a TX_WRITE or TX_READ), then check for a write-read collision). //This could happen whether or not a write-write collision exists due //to asymmetric write/read ports. if (iswrite_a) begin if (write_addr_a_width > read_addr_b_width) begin if (scaled_addra_to_raddrb_width == scaled_addrb_to_raddrb_width) begin c_aw_br = 1; end else begin c_aw_br = 0; end end else begin if (scaled_addrb_to_waddra_width == scaled_addra_to_waddra_width) begin c_aw_br = 1; end else begin c_aw_br = 0; end end //width end //iswrite_a //If the A port is reading (which means it is enabled - so could be // a TX_WRITE or TX_READ), then check for a write-read collision). //This could happen whether or not a write-write collision exists due // to asymmetric write/read ports. if (iswrite_b) begin if (read_addr_a_width > write_addr_b_width) begin if (scaled_addra_to_waddrb_width == scaled_addrb_to_waddrb_width) begin c_ar_bw = 1; end else begin c_ar_bw = 0; end end else begin if (scaled_addrb_to_raddra_width == scaled_addra_to_raddra_width) begin c_ar_bw = 1; end else begin c_ar_bw = 0; end end //width end //iswrite_b collision_check = c_aw_bw | c_aw_br | c_ar_bw; end endfunction //******************************* // power on values //******************************* initial begin // Load up the memory init_memory; // Load up the output registers and latches if ($sscanf(inita_str, "%h", inita_val)) begin memory_out_a = inita_val; end else begin memory_out_a = 0; end if ($sscanf(initb_str, "%h", initb_val)) begin memory_out_b = initb_val; end else begin memory_out_b = 0; end sbiterr_in = 1'b0; dbiterr_in = 1'b0; rdaddrecc_in = 0; // Determine the effective address widths for each of the 4 ports write_addr_a_width = C_ADDRA_WIDTH - log2roundup(WRITE_ADDR_A_DIV); read_addr_a_width = C_ADDRA_WIDTH - log2roundup(READ_ADDR_A_DIV); write_addr_b_width = C_ADDRB_WIDTH - log2roundup(WRITE_ADDR_B_DIV); read_addr_b_width = C_ADDRB_WIDTH - log2roundup(READ_ADDR_B_DIV); $display("Block Memory Generator module %m is using a behavioral model for simulation which will not precisely model memory collision behavior."); end //*************************************************************************** // These are the main blocks which schedule read and write operations // Note that the reset priority feature at the latch stage is only supported // for Spartan-6. For other families, the default priority at the latch stage // is "CE" //*************************************************************************** // Synchronous clocks: schedule port operations with respect to // both write operating modes generate if(C_COMMON_CLK && (C_WRITE_MODE_A == "WRITE_FIRST") && (C_WRITE_MODE_B == "WRITE_FIRST")) begin : com_clk_sched_wf_wf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A == "READ_FIRST") && (C_WRITE_MODE_B == "WRITE_FIRST")) begin : com_clk_sched_rf_wf always @(posedge CLKA) begin //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read B if (reb_i) read_b(ADDRB, resetb_i); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A == "WRITE_FIRST") && (C_WRITE_MODE_B == "READ_FIRST")) begin : com_clk_sched_wf_rf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A == "READ_FIRST") && (C_WRITE_MODE_B == "READ_FIRST")) begin : com_clk_sched_rf_rf always @(posedge CLKA) begin //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="WRITE_FIRST") && (C_WRITE_MODE_B == "NO_CHANGE")) begin : com_clk_sched_wf_nc always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="READ_FIRST") && (C_WRITE_MODE_B == "NO_CHANGE")) begin : com_clk_sched_rf_nc always @(posedge CLKA) begin //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="NO_CHANGE") && (C_WRITE_MODE_B == "WRITE_FIRST")) begin : com_clk_sched_nc_wf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="NO_CHANGE") && (C_WRITE_MODE_B == "READ_FIRST")) begin : com_clk_sched_nc_rf always @(posedge CLKA) begin //Read B if (reb_i) read_b(ADDRB, resetb_i); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if(C_COMMON_CLK && (C_WRITE_MODE_A =="NO_CHANGE") && (C_WRITE_MODE_B == "NO_CHANGE")) begin : com_clk_sched_nc_nc always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); end end else if(C_COMMON_CLK) begin: com_clk_sched_default always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read A if (rea_i) read_a(ADDRA, reseta_i); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end endgenerate // Asynchronous clocks: port operation is independent generate if((!C_COMMON_CLK) && (C_WRITE_MODE_A == "WRITE_FIRST")) begin : async_clk_sched_clka_wf always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i) read_a(ADDRA, reseta_i); end end else if((!C_COMMON_CLK) && (C_WRITE_MODE_A == "READ_FIRST")) begin : async_clk_sched_clka_rf always @(posedge CLKA) begin //Read A if (rea_i) read_a(ADDRA, reseta_i); //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); end end else if((!C_COMMON_CLK) && (C_WRITE_MODE_A == "NO_CHANGE")) begin : async_clk_sched_clka_nc always @(posedge CLKA) begin //Write A if (wea_i) write_a(ADDRA, wea_i, DINA, INJECTSBITERR, INJECTDBITERR); //Read A if (rea_i && (!wea_i || reseta_i)) read_a(ADDRA, reseta_i); end end endgenerate generate if ((!C_COMMON_CLK) && (C_WRITE_MODE_B == "WRITE_FIRST")) begin: async_clk_sched_clkb_wf always @(posedge CLKB) begin //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read B if (reb_i) read_b(ADDRB, resetb_i); end end else if ((!C_COMMON_CLK) && (C_WRITE_MODE_B == "READ_FIRST")) begin: async_clk_sched_clkb_rf always @(posedge CLKB) begin //Read B if (reb_i) read_b(ADDRB, resetb_i); //Write B if (web_i) write_b(ADDRB, web_i, DINB); end end else if ((!C_COMMON_CLK) && (C_WRITE_MODE_B == "NO_CHANGE")) begin: async_clk_sched_clkb_nc always @(posedge CLKB) begin //Write B if (web_i) write_b(ADDRB, web_i, DINB); //Read B if (reb_i && (!web_i || resetb_i)) read_b(ADDRB, resetb_i); end end endgenerate //*************************************************************** // Instantiate the variable depth output register stage module //*************************************************************** // Port A assign rsta_outp_stage = RSTA & (~SLEEP); blk_mem_gen_v8_3_3_output_stage #(.C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_RST_TYPE ("SYNC"), .C_HAS_RST (C_HAS_RSTA), .C_RSTRAM (C_RSTRAM_A), .C_RST_PRIORITY (C_RST_PRIORITY_A), .C_INIT_VAL (C_INITA_VAL), .C_HAS_EN (C_HAS_ENA), .C_HAS_REGCE (C_HAS_REGCEA), .C_DATA_WIDTH (C_READ_WIDTH_A), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS (C_HAS_MEM_OUTPUT_REGS_A), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .NUM_STAGES (NUM_OUTPUT_STAGES_A), .C_EN_ECC_PIPE (0), .FLOP_DELAY (FLOP_DELAY)) reg_a (.CLK (CLKA), .RST (rsta_outp_stage),//(RSTA), .EN (ENA), .REGCE (REGCEA), .DIN_I (memory_out_a), .DOUT (DOUTA), .SBITERR_IN_I (1'b0), .DBITERR_IN_I (1'b0), .SBITERR (), .DBITERR (), .RDADDRECC_IN_I ({C_ADDRB_WIDTH{1'b0}}), .ECCPIPECE (1'b0), .RDADDRECC () ); assign rstb_outp_stage = RSTB & (~SLEEP); // Port B blk_mem_gen_v8_3_3_output_stage #(.C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_RST_TYPE ("SYNC"), .C_HAS_RST (C_HAS_RSTB), .C_RSTRAM (C_RSTRAM_B), .C_RST_PRIORITY (C_RST_PRIORITY_B), .C_INIT_VAL (C_INITB_VAL), .C_HAS_EN (C_HAS_ENB), .C_HAS_REGCE (C_HAS_REGCEB), .C_DATA_WIDTH (C_READ_WIDTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS (C_HAS_MEM_OUTPUT_REGS_B), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .NUM_STAGES (NUM_OUTPUT_STAGES_B), .C_EN_ECC_PIPE (C_EN_ECC_PIPE), .FLOP_DELAY (FLOP_DELAY)) reg_b (.CLK (CLKB), .RST (rstb_outp_stage),//(RSTB), .EN (ENB), .REGCE (REGCEB), .DIN_I (memory_out_b), .DOUT (dout_i), .SBITERR_IN_I (sbiterr_in), .DBITERR_IN_I (dbiterr_in), .SBITERR (sbiterr_i), .DBITERR (dbiterr_i), .RDADDRECC_IN_I (rdaddrecc_in), .ECCPIPECE (ECCPIPECE), .RDADDRECC (rdaddrecc_i) ); //*************************************************************** // Instantiate the Input and Output register stages //*************************************************************** blk_mem_gen_v8_3_3_softecc_output_reg_stage #(.C_DATA_WIDTH (C_READ_WIDTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_USE_SOFTECC (C_USE_SOFTECC), .FLOP_DELAY (FLOP_DELAY)) has_softecc_output_reg_stage (.CLK (CLKB), .DIN (dout_i), .DOUT (DOUTB), .SBITERR_IN (sbiterr_i), .DBITERR_IN (dbiterr_i), .SBITERR (sbiterr_sdp), .DBITERR (dbiterr_sdp), .RDADDRECC_IN (rdaddrecc_i), .RDADDRECC (rdaddrecc_sdp) ); //**************************************************** // Synchronous collision checks //**************************************************** // CR 780544 : To make verilog model's collison warnings in consistant with // vhdl model, the non-blocking assignments are replaced with blocking // assignments. generate if (!C_DISABLE_WARN_BHV_COLL && C_COMMON_CLK) begin : sync_coll always @(posedge CLKA) begin // Possible collision if both are enabled and the addresses match if (ena_i && enb_i) begin if (wea_i || web_i) begin is_collision = collision_check(ADDRA, wea_i, ADDRB, web_i); end else begin is_collision = 0; end end else begin is_collision = 0; end // If the write port is in READ_FIRST mode, there is no collision if (C_WRITE_MODE_A=="READ_FIRST" && wea_i && !web_i) begin is_collision = 0; end if (C_WRITE_MODE_B=="READ_FIRST" && web_i && !wea_i) begin is_collision = 0; end // Only flag if one of the accesses is a write if (is_collision && (wea_i || web_i)) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A %0s address: %0h, B %0s address: %0h\n", wea_i ? "write" : "read", ADDRA, web_i ? "write" : "read", ADDRB); end end //**************************************************** // Asynchronous collision checks //**************************************************** end else if (!C_DISABLE_WARN_BHV_COLL && !C_COMMON_CLK) begin : async_coll // Delay A and B addresses in order to mimic setup/hold times wire [C_ADDRA_WIDTH-1:0] #COLL_DELAY addra_delay = ADDRA; wire [0:0] #COLL_DELAY wea_delay = wea_i; wire #COLL_DELAY ena_delay = ena_i; wire [C_ADDRB_WIDTH-1:0] #COLL_DELAY addrb_delay = ADDRB; wire [0:0] #COLL_DELAY web_delay = web_i; wire #COLL_DELAY enb_delay = enb_i; // Do the checks w/rt A always @(posedge CLKA) begin // Possible collision if both are enabled and the addresses match if (ena_i && enb_i) begin if (wea_i || web_i) begin is_collision_a = collision_check(ADDRA, wea_i, ADDRB, web_i); end else begin is_collision_a = 0; end end else begin is_collision_a = 0; end if (ena_i && enb_delay) begin if(wea_i || web_delay) begin is_collision_delay_a = collision_check(ADDRA, wea_i, addrb_delay, web_delay); end else begin is_collision_delay_a = 0; end end else begin is_collision_delay_a = 0; end // Only flag if B access is a write if (is_collision_a && web_i) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A %0s address: %0h, B write address: %0h\n", wea_i ? "write" : "read", ADDRA, ADDRB); end else if (is_collision_delay_a && web_delay) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A %0s address: %0h, B write address: %0h\n", wea_i ? "write" : "read", ADDRA, addrb_delay); end end // Do the checks w/rt B always @(posedge CLKB) begin // Possible collision if both are enabled and the addresses match if (ena_i && enb_i) begin if (wea_i || web_i) begin is_collision_b = collision_check(ADDRA, wea_i, ADDRB, web_i); end else begin is_collision_b = 0; end end else begin is_collision_b = 0; end if (ena_delay && enb_i) begin if (wea_delay || web_i) begin is_collision_delay_b = collision_check(addra_delay, wea_delay, ADDRB, web_i); end else begin is_collision_delay_b = 0; end end else begin is_collision_delay_b = 0; end // Only flag if A access is a write if (is_collision_b && wea_i) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A write address: %0h, B %s address: %0h\n", ADDRA, web_i ? "write" : "read", ADDRB); end else if (is_collision_delay_b && wea_delay) begin $fwrite(COLLFILE, "%0s collision detected at time: %0d, ", C_CORENAME, $time); $fwrite(COLLFILE, "A write address: %0h, B %s address: %0h\n", addra_delay, web_i ? "write" : "read", ADDRB); end end end endgenerate endmodule //***************************************************************************** // Top module wraps Input register and Memory module // // This module is the top-level behavioral model and this implements the memory // module and the input registers //***************************************************************************** module blk_mem_gen_v8_3_3 #(parameter C_CORENAME = "blk_mem_gen_v8_3_3", parameter C_FAMILY = "virtex7", parameter C_XDEVICEFAMILY = "virtex7", parameter C_ELABORATION_DIR = "", parameter C_INTERFACE_TYPE = 0, parameter C_USE_BRAM_BLOCK = 0, parameter C_CTRL_ECC_ALGO = "NONE", parameter C_ENABLE_32BIT_ADDRESS = 0, parameter C_AXI_TYPE = 0, parameter C_AXI_SLAVE_TYPE = 0, parameter C_HAS_AXI_ID = 0, parameter C_AXI_ID_WIDTH = 4, parameter C_MEM_TYPE = 2, parameter C_BYTE_SIZE = 9, parameter C_ALGORITHM = 1, parameter C_PRIM_TYPE = 3, parameter C_LOAD_INIT_FILE = 0, parameter C_INIT_FILE_NAME = "", parameter C_INIT_FILE = "", parameter C_USE_DEFAULT_DATA = 0, parameter C_DEFAULT_DATA = "0", //parameter C_RST_TYPE = "SYNC", parameter C_HAS_RSTA = 0, parameter C_RST_PRIORITY_A = "CE", parameter C_RSTRAM_A = 0, parameter C_INITA_VAL = "0", parameter C_HAS_ENA = 1, parameter C_HAS_REGCEA = 0, parameter C_USE_BYTE_WEA = 0, parameter C_WEA_WIDTH = 1, parameter C_WRITE_MODE_A = "WRITE_FIRST", parameter C_WRITE_WIDTH_A = 32, parameter C_READ_WIDTH_A = 32, parameter C_WRITE_DEPTH_A = 64, parameter C_READ_DEPTH_A = 64, parameter C_ADDRA_WIDTH = 5, parameter C_HAS_RSTB = 0, parameter C_RST_PRIORITY_B = "CE", parameter C_RSTRAM_B = 0, parameter C_INITB_VAL = "", parameter C_HAS_ENB = 1, parameter C_HAS_REGCEB = 0, parameter C_USE_BYTE_WEB = 0, parameter C_WEB_WIDTH = 1, parameter C_WRITE_MODE_B = "WRITE_FIRST", parameter C_WRITE_WIDTH_B = 32, parameter C_READ_WIDTH_B = 32, parameter C_WRITE_DEPTH_B = 64, parameter C_READ_DEPTH_B = 64, parameter C_ADDRB_WIDTH = 5, parameter C_HAS_MEM_OUTPUT_REGS_A = 0, parameter C_HAS_MEM_OUTPUT_REGS_B = 0, parameter C_HAS_MUX_OUTPUT_REGS_A = 0, parameter C_HAS_MUX_OUTPUT_REGS_B = 0, parameter C_HAS_SOFTECC_INPUT_REGS_A = 0, parameter C_HAS_SOFTECC_OUTPUT_REGS_B= 0, parameter C_MUX_PIPELINE_STAGES = 0, parameter C_USE_SOFTECC = 0, parameter C_USE_ECC = 0, parameter C_EN_ECC_PIPE = 0, parameter C_HAS_INJECTERR = 0, parameter C_SIM_COLLISION_CHECK = "NONE", parameter C_COMMON_CLK = 1, parameter C_DISABLE_WARN_BHV_COLL = 0, parameter C_EN_SLEEP_PIN = 0, parameter C_USE_URAM = 0, parameter C_EN_RDADDRA_CHG = 0, parameter C_EN_RDADDRB_CHG = 0, parameter C_EN_DEEPSLEEP_PIN = 0, parameter C_EN_SHUTDOWN_PIN = 0, parameter C_EN_SAFETY_CKT = 0, parameter C_COUNT_36K_BRAM = "", parameter C_COUNT_18K_BRAM = "", parameter C_EST_POWER_SUMMARY = "", parameter C_DISABLE_WARN_BHV_RANGE = 0 ) (input clka, input rsta, input ena, input regcea, input [C_WEA_WIDTH-1:0] wea, input [C_ADDRA_WIDTH-1:0] addra, input [C_WRITE_WIDTH_A-1:0] dina, output [C_READ_WIDTH_A-1:0] douta, input clkb, input rstb, input enb, input regceb, input [C_WEB_WIDTH-1:0] web, input [C_ADDRB_WIDTH-1:0] addrb, input [C_WRITE_WIDTH_B-1:0] dinb, output [C_READ_WIDTH_B-1:0] doutb, input injectsbiterr, input injectdbiterr, output sbiterr, output dbiterr, output [C_ADDRB_WIDTH-1:0] rdaddrecc, input eccpipece, input sleep, input deepsleep, input shutdown, output rsta_busy, output rstb_busy, //AXI BMG Input and Output Port Declarations //AXI Global Signals input s_aclk, input s_aresetn, //AXI Full/lite slave write (write side) input [C_AXI_ID_WIDTH-1:0] s_axi_awid, input [31:0] s_axi_awaddr, input [7:0] s_axi_awlen, input [2:0] s_axi_awsize, input [1:0] s_axi_awburst, input s_axi_awvalid, output s_axi_awready, input [C_WRITE_WIDTH_A-1:0] s_axi_wdata, input [C_WEA_WIDTH-1:0] s_axi_wstrb, input s_axi_wlast, input s_axi_wvalid, output s_axi_wready, output [C_AXI_ID_WIDTH-1:0] s_axi_bid, output [1:0] s_axi_bresp, output s_axi_bvalid, input s_axi_bready, //AXI Full/lite slave read (write side) input [C_AXI_ID_WIDTH-1:0] s_axi_arid, input [31:0] s_axi_araddr, input [7:0] s_axi_arlen, input [2:0] s_axi_arsize, input [1:0] s_axi_arburst, input s_axi_arvalid, output s_axi_arready, output [C_AXI_ID_WIDTH-1:0] s_axi_rid, output [C_WRITE_WIDTH_B-1:0] s_axi_rdata, output [1:0] s_axi_rresp, output s_axi_rlast, output s_axi_rvalid, input s_axi_rready, //AXI Full/lite sideband signals input s_axi_injectsbiterr, input s_axi_injectdbiterr, output s_axi_sbiterr, output s_axi_dbiterr, output [C_ADDRB_WIDTH-1:0] s_axi_rdaddrecc ); //****************************** // Port and Generic Definitions //****************************** ////////////////////////////////////////////////////////////////////////// // Generic Definitions ////////////////////////////////////////////////////////////////////////// // C_CORENAME : Instance name of the Block Memory Generator core // C_FAMILY,C_XDEVICEFAMILY: Designates architecture targeted. The following // options are available - "spartan3", "spartan6", // "virtex4", "virtex5", "virtex6" and "virtex6l". // C_MEM_TYPE : Designates memory type. // It can be // 0 - Single Port Memory // 1 - Simple Dual Port Memory // 2 - True Dual Port Memory // 3 - Single Port Read Only Memory // 4 - Dual Port Read Only Memory // C_BYTE_SIZE : Size of a byte (8 or 9 bits) // C_ALGORITHM : Designates the algorithm method used // for constructing the memory. // It can be Fixed_Primitives, Minimum_Area or // Low_Power // C_PRIM_TYPE : Designates the user selected primitive used to // construct the memory. // // C_LOAD_INIT_FILE : Designates the use of an initialization file to // initialize memory contents. // C_INIT_FILE_NAME : Memory initialization file name. // C_USE_DEFAULT_DATA : Designates whether to fill remaining // initialization space with default data // C_DEFAULT_DATA : Default value of all memory locations // not initialized by the memory // initialization file. // C_RST_TYPE : Type of reset - Synchronous or Asynchronous // C_HAS_RSTA : Determines the presence of the RSTA port // C_RST_PRIORITY_A : Determines the priority between CE and SR for // Port A. // C_RSTRAM_A : Determines if special reset behavior is used for // Port A // C_INITA_VAL : The initialization value for Port A // C_HAS_ENA : Determines the presence of the ENA port // C_HAS_REGCEA : Determines the presence of the REGCEA port // C_USE_BYTE_WEA : Determines if the Byte Write is used or not. // C_WEA_WIDTH : The width of the WEA port // C_WRITE_MODE_A : Configurable write mode for Port A. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_A : Memory write width for Port A. // C_READ_WIDTH_A : Memory read width for Port A. // C_WRITE_DEPTH_A : Memory write depth for Port A. // C_READ_DEPTH_A : Memory read depth for Port A. // C_ADDRA_WIDTH : Width of the ADDRA input port // C_HAS_RSTB : Determines the presence of the RSTB port // C_RST_PRIORITY_B : Determines the priority between CE and SR for // Port B. // C_RSTRAM_B : Determines if special reset behavior is used for // Port B // C_INITB_VAL : The initialization value for Port B // C_HAS_ENB : Determines the presence of the ENB port // C_HAS_REGCEB : Determines the presence of the REGCEB port // C_USE_BYTE_WEB : Determines if the Byte Write is used or not. // C_WEB_WIDTH : The width of the WEB port // C_WRITE_MODE_B : Configurable write mode for Port B. It can be // WRITE_FIRST, READ_FIRST or NO_CHANGE. // C_WRITE_WIDTH_B : Memory write width for Port B. // C_READ_WIDTH_B : Memory read width for Port B. // C_WRITE_DEPTH_B : Memory write depth for Port B. // C_READ_DEPTH_B : Memory read depth for Port B. // C_ADDRB_WIDTH : Width of the ADDRB input port // C_HAS_MEM_OUTPUT_REGS_A : Designates the use of a register at the output // of the RAM primitive for Port A. // C_HAS_MEM_OUTPUT_REGS_B : Designates the use of a register at the output // of the RAM primitive for Port B. // C_HAS_MUX_OUTPUT_REGS_A : Designates the use of a register at the output // of the MUX for Port A. // C_HAS_MUX_OUTPUT_REGS_B : Designates the use of a register at the output // of the MUX for Port B. // C_HAS_SOFTECC_INPUT_REGS_A : // C_HAS_SOFTECC_OUTPUT_REGS_B : // C_MUX_PIPELINE_STAGES : Designates the number of pipeline stages in // between the muxes. // C_USE_SOFTECC : Determines if the Soft ECC feature is used or // not. Only applicable Spartan-6 // C_USE_ECC : Determines if the ECC feature is used or // not. Only applicable for V5 and V6 // C_HAS_INJECTERR : Determines if the error injection pins // are present or not. If the ECC feature // is not used, this value is defaulted to // 0, else the following are the allowed // values: // 0 : No INJECTSBITERR or INJECTDBITERR pins // 1 : Only INJECTSBITERR pin exists // 2 : Only INJECTDBITERR pin exists // 3 : Both INJECTSBITERR and INJECTDBITERR pins exist // C_SIM_COLLISION_CHECK : Controls the disabling of Unisim model collision // warnings. It can be "ALL", "NONE", // "Warnings_Only" or "Generate_X_Only". // C_COMMON_CLK : Determins if the core has a single CLK input. // C_DISABLE_WARN_BHV_COLL : Controls the Behavioral Model Collision warnings // C_DISABLE_WARN_BHV_RANGE: Controls the Behavioral Model Out of Range // warnings ////////////////////////////////////////////////////////////////////////// // Port Definitions ////////////////////////////////////////////////////////////////////////// // CLKA : Clock to synchronize all read and write operations of Port A. // RSTA : Reset input to reset memory outputs to a user-defined // reset state for Port A. // ENA : Enable all read and write operations of Port A. // REGCEA : Register Clock Enable to control each pipeline output // register stages for Port A. // WEA : Write Enable to enable all write operations of Port A. // ADDRA : Address of Port A. // DINA : Data input of Port A. // DOUTA : Data output of Port A. // CLKB : Clock to synchronize all read and write operations of Port B. // RSTB : Reset input to reset memory outputs to a user-defined // reset state for Port B. // ENB : Enable all read and write operations of Port B. // REGCEB : Register Clock Enable to control each pipeline output // register stages for Port B. // WEB : Write Enable to enable all write operations of Port B. // ADDRB : Address of Port B. // DINB : Data input of Port B. // DOUTB : Data output of Port B. // INJECTSBITERR : Single Bit ECC Error Injection Pin. // INJECTDBITERR : Double Bit ECC Error Injection Pin. // SBITERR : Output signal indicating that a Single Bit ECC Error has been // detected and corrected. // DBITERR : Output signal indicating that a Double Bit ECC Error has been // detected. // RDADDRECC : Read Address Output signal indicating address at which an // ECC error has occurred. ////////////////////////////////////////////////////////////////////////// wire SBITERR; wire DBITERR; wire S_AXI_AWREADY; wire S_AXI_WREADY; wire S_AXI_BVALID; wire S_AXI_ARREADY; wire S_AXI_RLAST; wire S_AXI_RVALID; wire S_AXI_SBITERR; wire S_AXI_DBITERR; wire [C_WEA_WIDTH-1:0] WEA = wea; wire [C_ADDRA_WIDTH-1:0] ADDRA = addra; wire [C_WRITE_WIDTH_A-1:0] DINA = dina; wire [C_READ_WIDTH_A-1:0] DOUTA; wire [C_WEB_WIDTH-1:0] WEB = web; wire [C_ADDRB_WIDTH-1:0] ADDRB = addrb; wire [C_WRITE_WIDTH_B-1:0] DINB = dinb; wire [C_READ_WIDTH_B-1:0] DOUTB; wire [C_ADDRB_WIDTH-1:0] RDADDRECC; wire [C_AXI_ID_WIDTH-1:0] S_AXI_AWID = s_axi_awid; wire [31:0] S_AXI_AWADDR = s_axi_awaddr; wire [7:0] S_AXI_AWLEN = s_axi_awlen; wire [2:0] S_AXI_AWSIZE = s_axi_awsize; wire [1:0] S_AXI_AWBURST = s_axi_awburst; wire [C_WRITE_WIDTH_A-1:0] S_AXI_WDATA = s_axi_wdata; wire [C_WEA_WIDTH-1:0] S_AXI_WSTRB = s_axi_wstrb; wire [C_AXI_ID_WIDTH-1:0] S_AXI_BID; wire [1:0] S_AXI_BRESP; wire [C_AXI_ID_WIDTH-1:0] S_AXI_ARID = s_axi_arid; wire [31:0] S_AXI_ARADDR = s_axi_araddr; wire [7:0] S_AXI_ARLEN = s_axi_arlen; wire [2:0] S_AXI_ARSIZE = s_axi_arsize; wire [1:0] S_AXI_ARBURST = s_axi_arburst; wire [C_AXI_ID_WIDTH-1:0] S_AXI_RID; wire [C_WRITE_WIDTH_B-1:0] S_AXI_RDATA; wire [1:0] S_AXI_RRESP; wire [C_ADDRB_WIDTH-1:0] S_AXI_RDADDRECC; // Added to fix the simulation warning #CR731605 wire [C_WEB_WIDTH-1:0] WEB_parameterized = 0; wire ECCPIPECE; wire SLEEP; reg RSTA_BUSY = 0; reg RSTB_BUSY = 0; // Declaration of internal signals to avoid warnings #927399 wire CLKA; wire RSTA; wire ENA; wire REGCEA; wire CLKB; wire RSTB; wire ENB; wire REGCEB; wire INJECTSBITERR; wire INJECTDBITERR; wire S_ACLK; wire S_ARESETN; wire S_AXI_AWVALID; wire S_AXI_WLAST; wire S_AXI_WVALID; wire S_AXI_BREADY; wire S_AXI_ARVALID; wire S_AXI_RREADY; wire S_AXI_INJECTSBITERR; wire S_AXI_INJECTDBITERR; assign CLKA = clka; assign RSTA = rsta; assign ENA = ena; assign REGCEA = regcea; assign CLKB = clkb; assign RSTB = rstb; assign ENB = enb; assign REGCEB = regceb; assign INJECTSBITERR = injectsbiterr; assign INJECTDBITERR = injectdbiterr; assign ECCPIPECE = eccpipece; assign SLEEP = sleep; assign sbiterr = SBITERR; assign dbiterr = DBITERR; assign S_ACLK = s_aclk; assign S_ARESETN = s_aresetn; assign S_AXI_AWVALID = s_axi_awvalid; assign s_axi_awready = S_AXI_AWREADY; assign S_AXI_WLAST = s_axi_wlast; assign S_AXI_WVALID = s_axi_wvalid; assign s_axi_wready = S_AXI_WREADY; assign s_axi_bvalid = S_AXI_BVALID; assign S_AXI_BREADY = s_axi_bready; assign S_AXI_ARVALID = s_axi_arvalid; assign s_axi_arready = S_AXI_ARREADY; assign s_axi_rlast = S_AXI_RLAST; assign s_axi_rvalid = S_AXI_RVALID; assign S_AXI_RREADY = s_axi_rready; assign S_AXI_INJECTSBITERR = s_axi_injectsbiterr; assign S_AXI_INJECTDBITERR = s_axi_injectdbiterr; assign s_axi_sbiterr = S_AXI_SBITERR; assign s_axi_dbiterr = S_AXI_DBITERR; assign rsta_busy = RSTA_BUSY; assign rstb_busy = RSTB_BUSY; assign doutb = DOUTB; assign douta = DOUTA; assign rdaddrecc = RDADDRECC; assign s_axi_bid = S_AXI_BID; assign s_axi_bresp = S_AXI_BRESP; assign s_axi_rid = S_AXI_RID; assign s_axi_rdata = S_AXI_RDATA; assign s_axi_rresp = S_AXI_RRESP; assign s_axi_rdaddrecc = S_AXI_RDADDRECC; localparam FLOP_DELAY = 100; // 100 ps reg injectsbiterr_in; reg injectdbiterr_in; reg rsta_in; reg ena_in; reg regcea_in; reg [C_WEA_WIDTH-1:0] wea_in; reg [C_ADDRA_WIDTH-1:0] addra_in; reg [C_WRITE_WIDTH_A-1:0] dina_in; wire [C_ADDRA_WIDTH-1:0] s_axi_awaddr_out_c; wire [C_ADDRB_WIDTH-1:0] s_axi_araddr_out_c; wire s_axi_wr_en_c; wire s_axi_rd_en_c; wire s_aresetn_a_c; wire [7:0] s_axi_arlen_c ; wire [C_AXI_ID_WIDTH-1 : 0] s_axi_rid_c; wire [C_WRITE_WIDTH_B-1 : 0] s_axi_rdata_c; wire [1:0] s_axi_rresp_c; wire s_axi_rlast_c; wire s_axi_rvalid_c; wire s_axi_rready_c; wire regceb_c; localparam C_AXI_PAYLOAD = (C_HAS_MUX_OUTPUT_REGS_B == 1)?C_WRITE_WIDTH_B+C_AXI_ID_WIDTH+3:C_AXI_ID_WIDTH+3; wire [C_AXI_PAYLOAD-1 : 0] s_axi_payload_c; wire [C_AXI_PAYLOAD-1 : 0] m_axi_payload_c; // Safety logic related signals reg [4:0] RSTA_SHFT_REG = 0; reg POR_A = 0; reg [4:0] RSTB_SHFT_REG = 0; reg POR_B = 0; reg ENA_dly = 0; reg ENA_dly_D = 0; reg ENB_dly = 0; reg ENB_dly_D = 0; wire RSTA_I_SAFE; wire RSTB_I_SAFE; wire ENA_I_SAFE; wire ENB_I_SAFE; reg ram_rstram_a_busy = 0; reg ram_rstreg_a_busy = 0; reg ram_rstram_b_busy = 0; reg ram_rstreg_b_busy = 0; reg ENA_dly_reg = 0; reg ENB_dly_reg = 0; reg ENA_dly_reg_D = 0; reg ENB_dly_reg_D = 0; //************** // log2roundup //************** function integer log2roundup (input integer data_value); integer width; integer cnt; begin width = 0; if (data_value > 1) begin for(cnt=1 ; cnt < data_value ; cnt = cnt * 2) begin width = width + 1; end //loop end //if log2roundup = width; end //log2roundup endfunction //************** // log2int //************** function integer log2int (input integer data_value); integer width; integer cnt; begin width = 0; cnt= data_value; for(cnt=data_value ; cnt >1 ; cnt = cnt / 2) begin width = width + 1; end //loop log2int = width; end //log2int endfunction //************************************************************************** // FUNCTION : divroundup // Returns the ceiling value of the division // Data_value - the quantity to be divided, dividend // Divisor - the value to divide the data_value by //************************************************************************** function integer divroundup (input integer data_value,input integer divisor); integer div; begin div = data_value/divisor; if ((data_value % divisor) != 0) begin div = div+1; end //if divroundup = div; end //if endfunction localparam AXI_FULL_MEMORY_SLAVE = ((C_AXI_SLAVE_TYPE == 0 && C_AXI_TYPE == 1)?1:0); localparam C_AXI_ADDR_WIDTH_MSB = C_ADDRA_WIDTH+log2roundup(C_WRITE_WIDTH_A/8); localparam C_AXI_ADDR_WIDTH = C_AXI_ADDR_WIDTH_MSB; //Data Width Number of LSB address bits to be discarded //1 to 16 1 //17 to 32 2 //33 to 64 3 //65 to 128 4 //129 to 256 5 //257 to 512 6 //513 to 1024 7 // The following two constants determine this. localparam LOWER_BOUND_VAL = (log2roundup(divroundup(C_WRITE_WIDTH_A,8) == 0))?0:(log2roundup(divroundup(C_WRITE_WIDTH_A,8))); localparam C_AXI_ADDR_WIDTH_LSB = ((AXI_FULL_MEMORY_SLAVE == 1)?0:LOWER_BOUND_VAL); localparam C_AXI_OS_WR = 2; //*********************************************** // INPUT REGISTERS. //*********************************************** generate if (C_HAS_SOFTECC_INPUT_REGS_A==0) begin : no_softecc_input_reg_stage always @* begin injectsbiterr_in = INJECTSBITERR; injectdbiterr_in = INJECTDBITERR; rsta_in = RSTA; ena_in = ENA; regcea_in = REGCEA; wea_in = WEA; addra_in = ADDRA; dina_in = DINA; end //end always end //end no_softecc_input_reg_stage endgenerate generate if (C_HAS_SOFTECC_INPUT_REGS_A==1) begin : has_softecc_input_reg_stage always @(posedge CLKA) begin injectsbiterr_in <= #FLOP_DELAY INJECTSBITERR; injectdbiterr_in <= #FLOP_DELAY INJECTDBITERR; rsta_in <= #FLOP_DELAY RSTA; ena_in <= #FLOP_DELAY ENA; regcea_in <= #FLOP_DELAY REGCEA; wea_in <= #FLOP_DELAY WEA; addra_in <= #FLOP_DELAY ADDRA; dina_in <= #FLOP_DELAY DINA; end //end always end //end input_reg_stages generate statement endgenerate //************************************************************************** // NO SAFETY LOGIC //************************************************************************** generate if (C_EN_SAFETY_CKT == 0) begin : NO_SAFETY_CKT_GEN assign ENA_I_SAFE = ena_in; assign ENB_I_SAFE = ENB; assign RSTA_I_SAFE = rsta_in; assign RSTB_I_SAFE = RSTB; end endgenerate //*************************************************************************** // SAFETY LOGIC // Power-ON Reset Generation //*************************************************************************** generate if (C_EN_SAFETY_CKT == 1) begin always @(posedge clka) RSTA_SHFT_REG <= #FLOP_DELAY {RSTA_SHFT_REG[3:0],1'b1} ; always @(posedge clka) POR_A <= #FLOP_DELAY RSTA_SHFT_REG[4] ^ RSTA_SHFT_REG[0]; always @(posedge clkb) RSTB_SHFT_REG <= #FLOP_DELAY {RSTB_SHFT_REG[3:0],1'b1} ; always @(posedge clkb) POR_B <= #FLOP_DELAY RSTB_SHFT_REG[4] ^ RSTB_SHFT_REG[0]; assign RSTA_I_SAFE = rsta_in | POR_A; assign RSTB_I_SAFE = (C_MEM_TYPE == 0 || C_MEM_TYPE == 3) ? 1'b0 : (RSTB | POR_B); end endgenerate //----------------------------------------------------------------------------- // -- RSTA/B_BUSY Generation //----------------------------------------------------------------------------- generate if ((C_HAS_MEM_OUTPUT_REGS_A==0 || (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==1)) && (C_EN_SAFETY_CKT == 1)) begin : RSTA_BUSY_NO_REG always @(*) ram_rstram_a_busy = RSTA_I_SAFE | ENA_dly | ENA_dly_D; always @(posedge clka) RSTA_BUSY <= #FLOP_DELAY ram_rstram_a_busy; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==0 && C_EN_SAFETY_CKT == 1) begin : RSTA_BUSY_WITH_REG always @(*) ram_rstreg_a_busy = RSTA_I_SAFE | ENA_dly_reg | ENA_dly_reg_D; always @(posedge clka) RSTA_BUSY <= #FLOP_DELAY ram_rstreg_a_busy; end endgenerate generate if ( (C_MEM_TYPE == 0 || C_MEM_TYPE == 3) && C_EN_SAFETY_CKT == 1) begin : SPRAM_RST_BUSY always @(*) RSTB_BUSY = 1'b0; end endgenerate generate if ( (C_HAS_MEM_OUTPUT_REGS_B==0 || (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==1)) && (C_MEM_TYPE != 0 && C_MEM_TYPE != 3) && C_EN_SAFETY_CKT == 1) begin : RSTB_BUSY_NO_REG always @(*) ram_rstram_b_busy = RSTB_I_SAFE | ENB_dly | ENB_dly_D; always @(posedge clkb) RSTB_BUSY <= #FLOP_DELAY ram_rstram_b_busy; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==0 && C_MEM_TYPE != 0 && C_MEM_TYPE != 3 && C_EN_SAFETY_CKT == 1) begin : RSTB_BUSY_WITH_REG always @(*) ram_rstreg_b_busy = RSTB_I_SAFE | ENB_dly_reg | ENB_dly_reg_D; always @(posedge clkb) RSTB_BUSY <= #FLOP_DELAY ram_rstreg_b_busy; end endgenerate //----------------------------------------------------------------------------- // -- ENA/ENB Generation //----------------------------------------------------------------------------- generate if ((C_HAS_MEM_OUTPUT_REGS_A==0 || (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==1)) && C_EN_SAFETY_CKT == 1) begin : ENA_NO_REG always @(posedge clka) begin ENA_dly <= #FLOP_DELAY RSTA_I_SAFE; ENA_dly_D <= #FLOP_DELAY ENA_dly; end assign ENA_I_SAFE = (C_HAS_ENA == 0)? 1'b1 : (ENA_dly_D | ena_in); end endgenerate generate if ( (C_HAS_MEM_OUTPUT_REGS_A==1 && C_RSTRAM_A==0) && C_EN_SAFETY_CKT == 1) begin : ENA_WITH_REG always @(posedge clka) begin ENA_dly_reg <= #FLOP_DELAY RSTA_I_SAFE; ENA_dly_reg_D <= #FLOP_DELAY ENA_dly_reg; end assign ENA_I_SAFE = (C_HAS_ENA == 0)? 1'b1 : (ENA_dly_reg_D | ena_in); end endgenerate generate if (C_MEM_TYPE == 0 || C_MEM_TYPE == 3) begin : SPRAM_ENB assign ENB_I_SAFE = 1'b0; end endgenerate generate if ((C_HAS_MEM_OUTPUT_REGS_B==0 || (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==1)) && C_MEM_TYPE != 0 && C_MEM_TYPE != 3 && C_EN_SAFETY_CKT == 1) begin : ENB_NO_REG always @(posedge clkb) begin : PROC_ENB_GEN ENB_dly <= #FLOP_DELAY RSTB_I_SAFE; ENB_dly_D <= #FLOP_DELAY ENB_dly; end assign ENB_I_SAFE = (C_HAS_ENB == 0)? 1'b1 : (ENB_dly_D | ENB); end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B==1 && C_RSTRAM_B==0 && C_MEM_TYPE != 0 && C_MEM_TYPE != 3 && C_EN_SAFETY_CKT == 1)begin : ENB_WITH_REG always @(posedge clkb) begin : PROC_ENB_GEN ENB_dly_reg <= #FLOP_DELAY RSTB_I_SAFE; ENB_dly_reg_D <= #FLOP_DELAY ENB_dly_reg; end assign ENB_I_SAFE = (C_HAS_ENB == 0)? 1'b1 : (ENB_dly_reg_D | ENB); end endgenerate generate if ((C_INTERFACE_TYPE == 0) && (C_ENABLE_32BIT_ADDRESS == 0)) begin : native_mem_module blk_mem_gen_v8_3_3_mem_module #(.C_CORENAME (C_CORENAME), .C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_MEM_TYPE (C_MEM_TYPE), .C_BYTE_SIZE (C_BYTE_SIZE), .C_ALGORITHM (C_ALGORITHM), .C_USE_BRAM_BLOCK (C_USE_BRAM_BLOCK), .C_PRIM_TYPE (C_PRIM_TYPE), .C_LOAD_INIT_FILE (C_LOAD_INIT_FILE), .C_INIT_FILE_NAME (C_INIT_FILE_NAME), .C_INIT_FILE (C_INIT_FILE), .C_USE_DEFAULT_DATA (C_USE_DEFAULT_DATA), .C_DEFAULT_DATA (C_DEFAULT_DATA), .C_RST_TYPE ("SYNC"), .C_HAS_RSTA (C_HAS_RSTA), .C_RST_PRIORITY_A (C_RST_PRIORITY_A), .C_RSTRAM_A (C_RSTRAM_A), .C_INITA_VAL (C_INITA_VAL), .C_HAS_ENA (C_HAS_ENA), .C_HAS_REGCEA (C_HAS_REGCEA), .C_USE_BYTE_WEA (C_USE_BYTE_WEA), .C_WEA_WIDTH (C_WEA_WIDTH), .C_WRITE_MODE_A (C_WRITE_MODE_A), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_READ_WIDTH_A (C_READ_WIDTH_A), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_READ_DEPTH_A (C_READ_DEPTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_HAS_RSTB (C_HAS_RSTB), .C_RST_PRIORITY_B (C_RST_PRIORITY_B), .C_RSTRAM_B (C_RSTRAM_B), .C_INITB_VAL (C_INITB_VAL), .C_HAS_ENB (C_HAS_ENB), .C_HAS_REGCEB (C_HAS_REGCEB), .C_USE_BYTE_WEB (C_USE_BYTE_WEB), .C_WEB_WIDTH (C_WEB_WIDTH), .C_WRITE_MODE_B (C_WRITE_MODE_B), .C_WRITE_WIDTH_B (C_WRITE_WIDTH_B), .C_READ_WIDTH_B (C_READ_WIDTH_B), .C_WRITE_DEPTH_B (C_WRITE_DEPTH_B), .C_READ_DEPTH_B (C_READ_DEPTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS_A (C_HAS_MEM_OUTPUT_REGS_A), .C_HAS_MEM_OUTPUT_REGS_B (C_HAS_MEM_OUTPUT_REGS_B), .C_HAS_MUX_OUTPUT_REGS_A (C_HAS_MUX_OUTPUT_REGS_A), .C_HAS_MUX_OUTPUT_REGS_B (C_HAS_MUX_OUTPUT_REGS_B), .C_HAS_SOFTECC_INPUT_REGS_A (C_HAS_SOFTECC_INPUT_REGS_A), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_MUX_PIPELINE_STAGES (C_MUX_PIPELINE_STAGES), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .C_HAS_INJECTERR (C_HAS_INJECTERR), .C_SIM_COLLISION_CHECK (C_SIM_COLLISION_CHECK), .C_COMMON_CLK (C_COMMON_CLK), .FLOP_DELAY (FLOP_DELAY), .C_DISABLE_WARN_BHV_COLL (C_DISABLE_WARN_BHV_COLL), .C_EN_ECC_PIPE (C_EN_ECC_PIPE), .C_DISABLE_WARN_BHV_RANGE (C_DISABLE_WARN_BHV_RANGE)) blk_mem_gen_v8_3_3_inst (.CLKA (CLKA), .RSTA (RSTA_I_SAFE),//(rsta_in), .ENA (ENA_I_SAFE),//(ena_in), .REGCEA (regcea_in), .WEA (wea_in), .ADDRA (addra_in), .DINA (dina_in), .DOUTA (DOUTA), .CLKB (CLKB), .RSTB (RSTB_I_SAFE),//(RSTB), .ENB (ENB_I_SAFE),//(ENB), .REGCEB (REGCEB), .WEB (WEB), .ADDRB (ADDRB), .DINB (DINB), .DOUTB (DOUTB), .INJECTSBITERR (injectsbiterr_in), .INJECTDBITERR (injectdbiterr_in), .ECCPIPECE (ECCPIPECE), .SLEEP (SLEEP), .SBITERR (SBITERR), .DBITERR (DBITERR), .RDADDRECC (RDADDRECC) ); end endgenerate generate if((C_INTERFACE_TYPE == 0) && (C_ENABLE_32BIT_ADDRESS == 1)) begin : native_mem_mapped_module localparam C_ADDRA_WIDTH_ACTUAL = log2roundup(C_WRITE_DEPTH_A); localparam C_ADDRB_WIDTH_ACTUAL = log2roundup(C_WRITE_DEPTH_B); localparam C_ADDRA_WIDTH_MSB = C_ADDRA_WIDTH_ACTUAL+log2int(C_WRITE_WIDTH_A/8); localparam C_ADDRB_WIDTH_MSB = C_ADDRB_WIDTH_ACTUAL+log2int(C_WRITE_WIDTH_B/8); // localparam C_ADDRA_WIDTH_MSB = C_ADDRA_WIDTH_ACTUAL+log2roundup(C_WRITE_WIDTH_A/8); // localparam C_ADDRB_WIDTH_MSB = C_ADDRB_WIDTH_ACTUAL+log2roundup(C_WRITE_WIDTH_B/8); localparam C_MEM_MAP_ADDRA_WIDTH_MSB = C_ADDRA_WIDTH_MSB; localparam C_MEM_MAP_ADDRB_WIDTH_MSB = C_ADDRB_WIDTH_MSB; // Data Width Number of LSB address bits to be discarded // 1 to 16 1 // 17 to 32 2 // 33 to 64 3 // 65 to 128 4 // 129 to 256 5 // 257 to 512 6 // 513 to 1024 7 // The following two constants determine this. localparam MEM_MAP_LOWER_BOUND_VAL_A = (log2int(divroundup(C_WRITE_WIDTH_A,8)==0)) ? 0:(log2int(divroundup(C_WRITE_WIDTH_A,8))); localparam MEM_MAP_LOWER_BOUND_VAL_B = (log2int(divroundup(C_WRITE_WIDTH_A,8)==0)) ? 0:(log2int(divroundup(C_WRITE_WIDTH_A,8))); localparam C_MEM_MAP_ADDRA_WIDTH_LSB = MEM_MAP_LOWER_BOUND_VAL_A; localparam C_MEM_MAP_ADDRB_WIDTH_LSB = MEM_MAP_LOWER_BOUND_VAL_B; wire [C_ADDRB_WIDTH_ACTUAL-1 :0] rdaddrecc_i; wire [C_ADDRB_WIDTH-1:C_MEM_MAP_ADDRB_WIDTH_MSB] msb_zero_i; wire [C_MEM_MAP_ADDRB_WIDTH_LSB-1:0] lsb_zero_i; assign msb_zero_i = 0; assign lsb_zero_i = 0; assign RDADDRECC = {msb_zero_i,rdaddrecc_i,lsb_zero_i}; blk_mem_gen_v8_3_3_mem_module #(.C_CORENAME (C_CORENAME), .C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_MEM_TYPE (C_MEM_TYPE), .C_BYTE_SIZE (C_BYTE_SIZE), .C_USE_BRAM_BLOCK (C_USE_BRAM_BLOCK), .C_ALGORITHM (C_ALGORITHM), .C_PRIM_TYPE (C_PRIM_TYPE), .C_LOAD_INIT_FILE (C_LOAD_INIT_FILE), .C_INIT_FILE_NAME (C_INIT_FILE_NAME), .C_INIT_FILE (C_INIT_FILE), .C_USE_DEFAULT_DATA (C_USE_DEFAULT_DATA), .C_DEFAULT_DATA (C_DEFAULT_DATA), .C_RST_TYPE ("SYNC"), .C_HAS_RSTA (C_HAS_RSTA), .C_RST_PRIORITY_A (C_RST_PRIORITY_A), .C_RSTRAM_A (C_RSTRAM_A), .C_INITA_VAL (C_INITA_VAL), .C_HAS_ENA (C_HAS_ENA), .C_HAS_REGCEA (C_HAS_REGCEA), .C_USE_BYTE_WEA (C_USE_BYTE_WEA), .C_WEA_WIDTH (C_WEA_WIDTH), .C_WRITE_MODE_A (C_WRITE_MODE_A), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_READ_WIDTH_A (C_READ_WIDTH_A), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_READ_DEPTH_A (C_READ_DEPTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH_ACTUAL), .C_HAS_RSTB (C_HAS_RSTB), .C_RST_PRIORITY_B (C_RST_PRIORITY_B), .C_RSTRAM_B (C_RSTRAM_B), .C_INITB_VAL (C_INITB_VAL), .C_HAS_ENB (C_HAS_ENB), .C_HAS_REGCEB (C_HAS_REGCEB), .C_USE_BYTE_WEB (C_USE_BYTE_WEB), .C_WEB_WIDTH (C_WEB_WIDTH), .C_WRITE_MODE_B (C_WRITE_MODE_B), .C_WRITE_WIDTH_B (C_WRITE_WIDTH_B), .C_READ_WIDTH_B (C_READ_WIDTH_B), .C_WRITE_DEPTH_B (C_WRITE_DEPTH_B), .C_READ_DEPTH_B (C_READ_DEPTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH_ACTUAL), .C_HAS_MEM_OUTPUT_REGS_A (C_HAS_MEM_OUTPUT_REGS_A), .C_HAS_MEM_OUTPUT_REGS_B (C_HAS_MEM_OUTPUT_REGS_B), .C_HAS_MUX_OUTPUT_REGS_A (C_HAS_MUX_OUTPUT_REGS_A), .C_HAS_MUX_OUTPUT_REGS_B (C_HAS_MUX_OUTPUT_REGS_B), .C_HAS_SOFTECC_INPUT_REGS_A (C_HAS_SOFTECC_INPUT_REGS_A), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_MUX_PIPELINE_STAGES (C_MUX_PIPELINE_STAGES), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .C_HAS_INJECTERR (C_HAS_INJECTERR), .C_SIM_COLLISION_CHECK (C_SIM_COLLISION_CHECK), .C_COMMON_CLK (C_COMMON_CLK), .FLOP_DELAY (FLOP_DELAY), .C_DISABLE_WARN_BHV_COLL (C_DISABLE_WARN_BHV_COLL), .C_EN_ECC_PIPE (C_EN_ECC_PIPE), .C_DISABLE_WARN_BHV_RANGE (C_DISABLE_WARN_BHV_RANGE)) blk_mem_gen_v8_3_3_inst (.CLKA (CLKA), .RSTA (RSTA_I_SAFE),//(rsta_in), .ENA (ENA_I_SAFE),//(ena_in), .REGCEA (regcea_in), .WEA (wea_in), .ADDRA (addra_in[C_MEM_MAP_ADDRA_WIDTH_MSB-1:C_MEM_MAP_ADDRA_WIDTH_LSB]), .DINA (dina_in), .DOUTA (DOUTA), .CLKB (CLKB), .RSTB (RSTB_I_SAFE),//(RSTB), .ENB (ENB_I_SAFE),//(ENB), .REGCEB (REGCEB), .WEB (WEB), .ADDRB (ADDRB[C_MEM_MAP_ADDRB_WIDTH_MSB-1:C_MEM_MAP_ADDRB_WIDTH_LSB]), .DINB (DINB), .DOUTB (DOUTB), .INJECTSBITERR (injectsbiterr_in), .INJECTDBITERR (injectdbiterr_in), .ECCPIPECE (ECCPIPECE), .SLEEP (SLEEP), .SBITERR (SBITERR), .DBITERR (DBITERR), .RDADDRECC (rdaddrecc_i) ); end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 0 && C_HAS_MUX_OUTPUT_REGS_B == 0 ) begin : no_regs assign S_AXI_RDATA = s_axi_rdata_c; assign S_AXI_RLAST = s_axi_rlast_c; assign S_AXI_RVALID = s_axi_rvalid_c; assign S_AXI_RID = s_axi_rid_c; assign S_AXI_RRESP = s_axi_rresp_c; assign s_axi_rready_c = S_AXI_RREADY; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 1) begin : has_regceb assign regceb_c = s_axi_rvalid_c && s_axi_rready_c; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 0) begin : no_regceb assign regceb_c = REGCEB; end endgenerate generate if (C_HAS_MUX_OUTPUT_REGS_B == 1) begin : only_core_op_regs assign s_axi_payload_c = {s_axi_rid_c,s_axi_rdata_c,s_axi_rresp_c,s_axi_rlast_c}; assign S_AXI_RID = m_axi_payload_c[C_AXI_PAYLOAD-1 : C_AXI_PAYLOAD-C_AXI_ID_WIDTH]; assign S_AXI_RDATA = m_axi_payload_c[C_AXI_PAYLOAD-C_AXI_ID_WIDTH-1 : C_AXI_PAYLOAD-C_AXI_ID_WIDTH-C_WRITE_WIDTH_B]; assign S_AXI_RRESP = m_axi_payload_c[2:1]; assign S_AXI_RLAST = m_axi_payload_c[0]; end endgenerate generate if (C_HAS_MEM_OUTPUT_REGS_B == 1) begin : only_emb_op_regs assign s_axi_payload_c = {s_axi_rid_c,s_axi_rresp_c,s_axi_rlast_c}; assign S_AXI_RDATA = s_axi_rdata_c; assign S_AXI_RID = m_axi_payload_c[C_AXI_PAYLOAD-1 : C_AXI_PAYLOAD-C_AXI_ID_WIDTH]; assign S_AXI_RRESP = m_axi_payload_c[2:1]; assign S_AXI_RLAST = m_axi_payload_c[0]; end endgenerate generate if (C_HAS_MUX_OUTPUT_REGS_B == 1 || C_HAS_MEM_OUTPUT_REGS_B == 1) begin : has_regs_fwd blk_mem_axi_regs_fwd_v8_3 #(.C_DATA_WIDTH (C_AXI_PAYLOAD)) axi_regs_inst ( .ACLK (S_ACLK), .ARESET (s_aresetn_a_c), .S_VALID (s_axi_rvalid_c), .S_READY (s_axi_rready_c), .S_PAYLOAD_DATA (s_axi_payload_c), .M_VALID (S_AXI_RVALID), .M_READY (S_AXI_RREADY), .M_PAYLOAD_DATA (m_axi_payload_c) ); end endgenerate generate if (C_INTERFACE_TYPE == 1) begin : axi_mem_module assign s_aresetn_a_c = !S_ARESETN; assign S_AXI_BRESP = 2'b00; assign s_axi_rresp_c = 2'b00; assign s_axi_arlen_c = (C_AXI_TYPE == 1)?S_AXI_ARLEN:8'h0; blk_mem_axi_write_wrapper_beh_v8_3 #(.C_INTERFACE_TYPE (C_INTERFACE_TYPE), .C_AXI_TYPE (C_AXI_TYPE), .C_AXI_SLAVE_TYPE (C_AXI_SLAVE_TYPE), .C_MEMORY_TYPE (C_MEM_TYPE), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_AXI_AWADDR_WIDTH ((AXI_FULL_MEMORY_SLAVE == 1)?C_AXI_ADDR_WIDTH:C_AXI_ADDR_WIDTH-C_AXI_ADDR_WIDTH_LSB), .C_HAS_AXI_ID (C_HAS_AXI_ID), .C_AXI_ID_WIDTH (C_AXI_ID_WIDTH), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_AXI_WDATA_WIDTH (C_WRITE_WIDTH_A), .C_AXI_OS_WR (C_AXI_OS_WR)) axi_wr_fsm ( // AXI Global Signals .S_ACLK (S_ACLK), .S_ARESETN (s_aresetn_a_c), // AXI Full/Lite Slave Write interface .S_AXI_AWADDR (S_AXI_AWADDR[C_AXI_ADDR_WIDTH_MSB-1:C_AXI_ADDR_WIDTH_LSB]), .S_AXI_AWLEN (S_AXI_AWLEN), .S_AXI_AWID (S_AXI_AWID), .S_AXI_AWSIZE (S_AXI_AWSIZE), .S_AXI_AWBURST (S_AXI_AWBURST), .S_AXI_AWVALID (S_AXI_AWVALID), .S_AXI_AWREADY (S_AXI_AWREADY), .S_AXI_WVALID (S_AXI_WVALID), .S_AXI_WREADY (S_AXI_WREADY), .S_AXI_BVALID (S_AXI_BVALID), .S_AXI_BREADY (S_AXI_BREADY), .S_AXI_BID (S_AXI_BID), // Signals for BRAM interfac( .S_AXI_AWADDR_OUT (s_axi_awaddr_out_c), .S_AXI_WR_EN (s_axi_wr_en_c) ); blk_mem_axi_read_wrapper_beh_v8_3 #(.C_INTERFACE_TYPE (C_INTERFACE_TYPE), .C_AXI_TYPE (C_AXI_TYPE), .C_AXI_SLAVE_TYPE (C_AXI_SLAVE_TYPE), .C_MEMORY_TYPE (C_MEM_TYPE), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_AXI_PIPELINE_STAGES (1), .C_AXI_ARADDR_WIDTH ((AXI_FULL_MEMORY_SLAVE == 1)?C_AXI_ADDR_WIDTH:C_AXI_ADDR_WIDTH-C_AXI_ADDR_WIDTH_LSB), .C_HAS_AXI_ID (C_HAS_AXI_ID), .C_AXI_ID_WIDTH (C_AXI_ID_WIDTH), .C_ADDRB_WIDTH (C_ADDRB_WIDTH)) axi_rd_sm( //AXI Global Signals .S_ACLK (S_ACLK), .S_ARESETN (s_aresetn_a_c), //AXI Full/Lite Read Side .S_AXI_ARADDR (S_AXI_ARADDR[C_AXI_ADDR_WIDTH_MSB-1:C_AXI_ADDR_WIDTH_LSB]), .S_AXI_ARLEN (s_axi_arlen_c), .S_AXI_ARSIZE (S_AXI_ARSIZE), .S_AXI_ARBURST (S_AXI_ARBURST), .S_AXI_ARVALID (S_AXI_ARVALID), .S_AXI_ARREADY (S_AXI_ARREADY), .S_AXI_RLAST (s_axi_rlast_c), .S_AXI_RVALID (s_axi_rvalid_c), .S_AXI_RREADY (s_axi_rready_c), .S_AXI_ARID (S_AXI_ARID), .S_AXI_RID (s_axi_rid_c), //AXI Full/Lite Read FSM Outputs .S_AXI_ARADDR_OUT (s_axi_araddr_out_c), .S_AXI_RD_EN (s_axi_rd_en_c) ); blk_mem_gen_v8_3_3_mem_module #(.C_CORENAME (C_CORENAME), .C_FAMILY (C_FAMILY), .C_XDEVICEFAMILY (C_XDEVICEFAMILY), .C_MEM_TYPE (C_MEM_TYPE), .C_BYTE_SIZE (C_BYTE_SIZE), .C_USE_BRAM_BLOCK (C_USE_BRAM_BLOCK), .C_ALGORITHM (C_ALGORITHM), .C_PRIM_TYPE (C_PRIM_TYPE), .C_LOAD_INIT_FILE (C_LOAD_INIT_FILE), .C_INIT_FILE_NAME (C_INIT_FILE_NAME), .C_INIT_FILE (C_INIT_FILE), .C_USE_DEFAULT_DATA (C_USE_DEFAULT_DATA), .C_DEFAULT_DATA (C_DEFAULT_DATA), .C_RST_TYPE ("SYNC"), .C_HAS_RSTA (C_HAS_RSTA), .C_RST_PRIORITY_A (C_RST_PRIORITY_A), .C_RSTRAM_A (C_RSTRAM_A), .C_INITA_VAL (C_INITA_VAL), .C_HAS_ENA (1), .C_HAS_REGCEA (C_HAS_REGCEA), .C_USE_BYTE_WEA (1), .C_WEA_WIDTH (C_WEA_WIDTH), .C_WRITE_MODE_A (C_WRITE_MODE_A), .C_WRITE_WIDTH_A (C_WRITE_WIDTH_A), .C_READ_WIDTH_A (C_READ_WIDTH_A), .C_WRITE_DEPTH_A (C_WRITE_DEPTH_A), .C_READ_DEPTH_A (C_READ_DEPTH_A), .C_ADDRA_WIDTH (C_ADDRA_WIDTH), .C_HAS_RSTB (C_HAS_RSTB), .C_RST_PRIORITY_B (C_RST_PRIORITY_B), .C_RSTRAM_B (C_RSTRAM_B), .C_INITB_VAL (C_INITB_VAL), .C_HAS_ENB (1), .C_HAS_REGCEB (C_HAS_MEM_OUTPUT_REGS_B), .C_USE_BYTE_WEB (1), .C_WEB_WIDTH (C_WEB_WIDTH), .C_WRITE_MODE_B (C_WRITE_MODE_B), .C_WRITE_WIDTH_B (C_WRITE_WIDTH_B), .C_READ_WIDTH_B (C_READ_WIDTH_B), .C_WRITE_DEPTH_B (C_WRITE_DEPTH_B), .C_READ_DEPTH_B (C_READ_DEPTH_B), .C_ADDRB_WIDTH (C_ADDRB_WIDTH), .C_HAS_MEM_OUTPUT_REGS_A (0), .C_HAS_MEM_OUTPUT_REGS_B (C_HAS_MEM_OUTPUT_REGS_B), .C_HAS_MUX_OUTPUT_REGS_A (0), .C_HAS_MUX_OUTPUT_REGS_B (0), .C_HAS_SOFTECC_INPUT_REGS_A (C_HAS_SOFTECC_INPUT_REGS_A), .C_HAS_SOFTECC_OUTPUT_REGS_B (C_HAS_SOFTECC_OUTPUT_REGS_B), .C_MUX_PIPELINE_STAGES (C_MUX_PIPELINE_STAGES), .C_USE_SOFTECC (C_USE_SOFTECC), .C_USE_ECC (C_USE_ECC), .C_HAS_INJECTERR (C_HAS_INJECTERR), .C_SIM_COLLISION_CHECK (C_SIM_COLLISION_CHECK), .C_COMMON_CLK (C_COMMON_CLK), .FLOP_DELAY (FLOP_DELAY), .C_DISABLE_WARN_BHV_COLL (C_DISABLE_WARN_BHV_COLL), .C_EN_ECC_PIPE (0), .C_DISABLE_WARN_BHV_RANGE (C_DISABLE_WARN_BHV_RANGE)) blk_mem_gen_v8_3_3_inst (.CLKA (S_ACLK), .RSTA (s_aresetn_a_c), .ENA (s_axi_wr_en_c), .REGCEA (regcea_in), .WEA (S_AXI_WSTRB), .ADDRA (s_axi_awaddr_out_c), .DINA (S_AXI_WDATA), .DOUTA (DOUTA), .CLKB (S_ACLK), .RSTB (s_aresetn_a_c), .ENB (s_axi_rd_en_c), .REGCEB (regceb_c), .WEB (WEB_parameterized), .ADDRB (s_axi_araddr_out_c), .DINB (DINB), .DOUTB (s_axi_rdata_c), .INJECTSBITERR (injectsbiterr_in), .INJECTDBITERR (injectdbiterr_in), .SBITERR (SBITERR), .DBITERR (DBITERR), .ECCPIPECE (1'b0), .SLEEP (1'b0), .RDADDRECC (RDADDRECC) ); end endgenerate endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: sg_list_reader_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Reads data from the scatter gather list buffer. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_SGR64_RD_0 2'b01 `define S_SGR64_RD_1 2'b11 `define S_SGR64_RD_WAIT 2'b10 `define S_SGR64_CAP_0 2'b00 `define S_SGR64_CAP_1 2'b01 `define S_SGR64_CAP_RDY 2'b10 `timescale 1ns/1ns module sg_list_reader_64 #( parameter C_DATA_WIDTH = 9'd64 ) ( input CLK, input RST, input [C_DATA_WIDTH-1:0] BUF_DATA, // Scatter gather buffer data input BUF_DATA_EMPTY, // Scatter gather buffer data empty output BUF_DATA_REN, // Scatter gather buffer data read enable output VALID, // Scatter gather element data is valid output EMPTY, // Scatter gather elements empty input REN, // Scatter gather element data read enable output [63:0] ADDR, // Scatter gather element address output [31:0] LEN // Scatter gather element length (in words) ); (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [1:0] rRdState=`S_SGR64_RD_0, _rRdState=`S_SGR64_RD_0; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [1:0] rCapState=`S_SGR64_CAP_0, _rCapState=`S_SGR64_CAP_0; reg [C_DATA_WIDTH-1:0] rData={C_DATA_WIDTH{1'd0}}, _rData={C_DATA_WIDTH{1'd0}}; reg [63:0] rAddr=64'd0, _rAddr=64'd0; reg [31:0] rLen=0, _rLen=0; reg rFifoValid=0, _rFifoValid=0; reg rDataValid=0, _rDataValid=0; assign BUF_DATA_REN = rRdState[0]; // Not S_SGR64_RD_WAIT assign VALID = rCapState[1]; // S_SGR64_CAP_RDY assign EMPTY = (BUF_DATA_EMPTY & rRdState[0]); // Not S_SGR64_RD_WAIT assign ADDR = rAddr; assign LEN = rLen; // Capture address and length as it comes out of the FIFO always @ (posedge CLK) begin rRdState <= #1 (RST ? `S_SGR64_RD_0 : _rRdState); rCapState <= #1 (RST ? `S_SGR64_CAP_0 : _rCapState); rData <= #1 _rData; rFifoValid <= #1 (RST ? 1'd0 : _rFifoValid); rDataValid <= #1 (RST ? 1'd0 : _rDataValid); rAddr <= #1 _rAddr; rLen <= #1 _rLen; end always @ (*) begin _rRdState = rRdState; _rCapState = rCapState; _rAddr = rAddr; _rLen = rLen; _rData = BUF_DATA; _rFifoValid = (BUF_DATA_REN & !BUF_DATA_EMPTY); _rDataValid = rFifoValid; case (rCapState) `S_SGR64_CAP_0: begin if (rDataValid) begin _rAddr = rData; _rCapState = `S_SGR64_CAP_1; end end `S_SGR64_CAP_1: begin if (rDataValid) begin _rLen = rData[31:0]; _rCapState = `S_SGR64_CAP_RDY; end end `S_SGR64_CAP_RDY: begin if (REN) _rCapState = `S_SGR64_CAP_0; end default: begin _rCapState = `S_SGR64_CAP_0; end endcase case (rRdState) `S_SGR64_RD_0: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR64_RD_1; end `S_SGR64_RD_1: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR64_RD_WAIT; end `S_SGR64_RD_WAIT: begin // Wait for the data to be consumed if (REN) _rRdState = `S_SGR64_RD_0; end default: begin _rRdState = `S_SGR64_RD_0; end endcase end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: sg_list_reader_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Reads data from the scatter gather list buffer. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_SGR64_RD_0 2'b01 `define S_SGR64_RD_1 2'b11 `define S_SGR64_RD_WAIT 2'b10 `define S_SGR64_CAP_0 2'b00 `define S_SGR64_CAP_1 2'b01 `define S_SGR64_CAP_RDY 2'b10 `timescale 1ns/1ns module sg_list_reader_64 #( parameter C_DATA_WIDTH = 9'd64 ) ( input CLK, input RST, input [C_DATA_WIDTH-1:0] BUF_DATA, // Scatter gather buffer data input BUF_DATA_EMPTY, // Scatter gather buffer data empty output BUF_DATA_REN, // Scatter gather buffer data read enable output VALID, // Scatter gather element data is valid output EMPTY, // Scatter gather elements empty input REN, // Scatter gather element data read enable output [63:0] ADDR, // Scatter gather element address output [31:0] LEN // Scatter gather element length (in words) ); (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [1:0] rRdState=`S_SGR64_RD_0, _rRdState=`S_SGR64_RD_0; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [1:0] rCapState=`S_SGR64_CAP_0, _rCapState=`S_SGR64_CAP_0; reg [C_DATA_WIDTH-1:0] rData={C_DATA_WIDTH{1'd0}}, _rData={C_DATA_WIDTH{1'd0}}; reg [63:0] rAddr=64'd0, _rAddr=64'd0; reg [31:0] rLen=0, _rLen=0; reg rFifoValid=0, _rFifoValid=0; reg rDataValid=0, _rDataValid=0; assign BUF_DATA_REN = rRdState[0]; // Not S_SGR64_RD_WAIT assign VALID = rCapState[1]; // S_SGR64_CAP_RDY assign EMPTY = (BUF_DATA_EMPTY & rRdState[0]); // Not S_SGR64_RD_WAIT assign ADDR = rAddr; assign LEN = rLen; // Capture address and length as it comes out of the FIFO always @ (posedge CLK) begin rRdState <= #1 (RST ? `S_SGR64_RD_0 : _rRdState); rCapState <= #1 (RST ? `S_SGR64_CAP_0 : _rCapState); rData <= #1 _rData; rFifoValid <= #1 (RST ? 1'd0 : _rFifoValid); rDataValid <= #1 (RST ? 1'd0 : _rDataValid); rAddr <= #1 _rAddr; rLen <= #1 _rLen; end always @ (*) begin _rRdState = rRdState; _rCapState = rCapState; _rAddr = rAddr; _rLen = rLen; _rData = BUF_DATA; _rFifoValid = (BUF_DATA_REN & !BUF_DATA_EMPTY); _rDataValid = rFifoValid; case (rCapState) `S_SGR64_CAP_0: begin if (rDataValid) begin _rAddr = rData; _rCapState = `S_SGR64_CAP_1; end end `S_SGR64_CAP_1: begin if (rDataValid) begin _rLen = rData[31:0]; _rCapState = `S_SGR64_CAP_RDY; end end `S_SGR64_CAP_RDY: begin if (REN) _rCapState = `S_SGR64_CAP_0; end default: begin _rCapState = `S_SGR64_CAP_0; end endcase case (rRdState) `S_SGR64_RD_0: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR64_RD_1; end `S_SGR64_RD_1: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR64_RD_WAIT; end `S_SGR64_RD_WAIT: begin // Wait for the data to be consumed if (REN) _rRdState = `S_SGR64_RD_0; end default: begin _rRdState = `S_SGR64_RD_0; end endcase end endmodule
`timescale 1ns / 1ps //////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 14:40:38 05/31/2011 // Design Name: main // Module Name: /home/ikari/prj/sd2snes/verilog/sd2snes/main_tf.v // Project Name: sd2snes // Target Device: // Tool versions: // Description: // // Verilog Test Fixture created by ISE for module: main // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // //////////////////////////////////////////////////////////////////////////////// module main_tf; // Inputs reg CLKIN; reg [23:0] SNES_ADDR; reg SNES_READ; reg SNES_WRITE; reg SNES_CS; reg SNES_CPU_CLK; reg SNES_REFRESH; reg SNES_SYSCLK; reg SPI_MOSI; reg SPI_SS; reg MCU_OVR; reg [3:0] SD_DAT; // Outputs wire SNES_DATABUS_OE; wire SNES_DATABUS_DIR; wire IRQ_DIR; wire [22:0] ROM_ADDR; wire ROM_CE; wire ROM_OE; wire ROM_WE; wire ROM_BHE; wire ROM_BLE; wire [18:0] RAM_ADDR; wire RAM_CE; wire RAM_OE; wire RAM_WE; wire DAC_MCLK; wire DAC_LRCK; wire DAC_SDOUT; // Bidirs wire [7:0] SNES_DATA; wire SNES_IRQ; wire [15:0] ROM_DATA; wire [7:0] RAM_DATA; wire SPI_MISO; wire SPI_SCK; wire SD_CMD; wire SD_CLK; // Instantiate the Unit Under Test (UUT) main uut ( .CLKIN(CLKIN), .SNES_ADDR(SNES_ADDR), .SNES_READ(SNES_READ), .SNES_WRITE(SNES_WRITE), .SNES_CS(SNES_CS), .SNES_DATA(SNES_DATA), .SNES_CPU_CLK(SNES_CPU_CLK), .SNES_REFRESH(SNES_REFRESH), .SNES_IRQ(SNES_IRQ), .SNES_DATABUS_OE(SNES_DATABUS_OE), .SNES_DATABUS_DIR(SNES_DATABUS_DIR), .IRQ_DIR(IRQ_DIR), .SNES_SYSCLK(SNES_SYSCLK), .ROM_DATA(ROM_DATA), .ROM_ADDR(ROM_ADDR), .ROM_CE(ROM_CE), .ROM_OE(ROM_OE), .ROM_WE(ROM_WE), .ROM_BHE(ROM_BHE), .ROM_BLE(ROM_BLE), .RAM_DATA(RAM_DATA), .RAM_ADDR(RAM_ADDR), .RAM_CE(RAM_CE), .RAM_OE(RAM_OE), .RAM_WE(RAM_WE), .SPI_MOSI(SPI_MOSI), .SPI_MISO(SPI_MISO), .SPI_SS(SPI_SS), .SPI_SCK(SPI_SCK), .MCU_OVR(MCU_OVR), .DAC_MCLK(DAC_MCLK), .DAC_LRCK(DAC_LRCK), .DAC_SDOUT(DAC_SDOUT), .SD_DAT(SD_DAT), .SD_CMD(SD_CMD), .SD_CLK(SD_CLK) ); integer i; reg [7:0] SNES_DATA_OUT; reg [7:0] SNES_DATA_IN; assign SNES_DATA = (!SNES_READ) ? 8'bZ : SNES_DATA_IN; initial begin // Initialize Inputs CLKIN = 0; SNES_ADDR = 0; SNES_READ = 1; SNES_WRITE = 1; SNES_CS = 0; SNES_CPU_CLK = 0; SNES_REFRESH = 0; SNES_SYSCLK = 0; SPI_MOSI = 0; SPI_SS = 0; MCU_OVR = 1; SD_DAT = 0; // Wait 100 ns for global reset to finish #500; // Add stimulus here SNES_ADDR = 24'h208000; SNES_DATA_IN = 8'h1f; SNES_WRITE = 0; #100 SNES_WRITE = 1; #100; for (i = 0; i < 4096; i = i + 1) begin #140 SNES_READ = 0; SNES_CPU_CLK = 1; #140 SNES_READ = 1; SNES_CPU_CLK = 0; end end always #24 CLKIN = ~CLKIN; endmodule
`timescale 1ns / 1ps //////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 14:40:38 05/31/2011 // Design Name: main // Module Name: /home/ikari/prj/sd2snes/verilog/sd2snes/main_tf.v // Project Name: sd2snes // Target Device: // Tool versions: // Description: // // Verilog Test Fixture created by ISE for module: main // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // //////////////////////////////////////////////////////////////////////////////// module main_tf; // Inputs reg CLKIN; reg [23:0] SNES_ADDR; reg SNES_READ; reg SNES_WRITE; reg SNES_CS; reg SNES_CPU_CLK; reg SNES_REFRESH; reg SNES_SYSCLK; reg SPI_MOSI; reg SPI_SS; reg MCU_OVR; reg [3:0] SD_DAT; // Outputs wire SNES_DATABUS_OE; wire SNES_DATABUS_DIR; wire IRQ_DIR; wire [22:0] ROM_ADDR; wire ROM_CE; wire ROM_OE; wire ROM_WE; wire ROM_BHE; wire ROM_BLE; wire [18:0] RAM_ADDR; wire RAM_CE; wire RAM_OE; wire RAM_WE; wire DAC_MCLK; wire DAC_LRCK; wire DAC_SDOUT; // Bidirs wire [7:0] SNES_DATA; wire SNES_IRQ; wire [15:0] ROM_DATA; wire [7:0] RAM_DATA; wire SPI_MISO; wire SPI_SCK; wire SD_CMD; wire SD_CLK; // Instantiate the Unit Under Test (UUT) main uut ( .CLKIN(CLKIN), .SNES_ADDR(SNES_ADDR), .SNES_READ(SNES_READ), .SNES_WRITE(SNES_WRITE), .SNES_CS(SNES_CS), .SNES_DATA(SNES_DATA), .SNES_CPU_CLK(SNES_CPU_CLK), .SNES_REFRESH(SNES_REFRESH), .SNES_IRQ(SNES_IRQ), .SNES_DATABUS_OE(SNES_DATABUS_OE), .SNES_DATABUS_DIR(SNES_DATABUS_DIR), .IRQ_DIR(IRQ_DIR), .SNES_SYSCLK(SNES_SYSCLK), .ROM_DATA(ROM_DATA), .ROM_ADDR(ROM_ADDR), .ROM_CE(ROM_CE), .ROM_OE(ROM_OE), .ROM_WE(ROM_WE), .ROM_BHE(ROM_BHE), .ROM_BLE(ROM_BLE), .RAM_DATA(RAM_DATA), .RAM_ADDR(RAM_ADDR), .RAM_CE(RAM_CE), .RAM_OE(RAM_OE), .RAM_WE(RAM_WE), .SPI_MOSI(SPI_MOSI), .SPI_MISO(SPI_MISO), .SPI_SS(SPI_SS), .SPI_SCK(SPI_SCK), .MCU_OVR(MCU_OVR), .DAC_MCLK(DAC_MCLK), .DAC_LRCK(DAC_LRCK), .DAC_SDOUT(DAC_SDOUT), .SD_DAT(SD_DAT), .SD_CMD(SD_CMD), .SD_CLK(SD_CLK) ); integer i; reg [7:0] SNES_DATA_OUT; reg [7:0] SNES_DATA_IN; assign SNES_DATA = (!SNES_READ) ? 8'bZ : SNES_DATA_IN; initial begin // Initialize Inputs CLKIN = 0; SNES_ADDR = 0; SNES_READ = 1; SNES_WRITE = 1; SNES_CS = 0; SNES_CPU_CLK = 0; SNES_REFRESH = 0; SNES_SYSCLK = 0; SPI_MOSI = 0; SPI_SS = 0; MCU_OVR = 1; SD_DAT = 0; // Wait 100 ns for global reset to finish #500; // Add stimulus here SNES_ADDR = 24'h208000; SNES_DATA_IN = 8'h1f; SNES_WRITE = 0; #100 SNES_WRITE = 1; #100; for (i = 0; i < 4096; i = i + 1) begin #140 SNES_READ = 0; SNES_CPU_CLK = 1; #140 SNES_READ = 1; SNES_CPU_CLK = 0; end end always #24 CLKIN = ~CLKIN; endmodule
`timescale 1ns / 1ps //////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 14:40:38 05/31/2011 // Design Name: main // Module Name: /home/ikari/prj/sd2snes/verilog/sd2snes/main_tf.v // Project Name: sd2snes // Target Device: // Tool versions: // Description: // // Verilog Test Fixture created by ISE for module: main // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // //////////////////////////////////////////////////////////////////////////////// module main_tf; // Inputs reg CLKIN; reg [23:0] SNES_ADDR; reg SNES_READ; reg SNES_WRITE; reg SNES_CS; reg SNES_CPU_CLK; reg SNES_REFRESH; reg SNES_SYSCLK; reg SPI_MOSI; reg SPI_SS; reg MCU_OVR; reg [3:0] SD_DAT; // Outputs wire SNES_DATABUS_OE; wire SNES_DATABUS_DIR; wire IRQ_DIR; wire [22:0] ROM_ADDR; wire ROM_CE; wire ROM_OE; wire ROM_WE; wire ROM_BHE; wire ROM_BLE; wire [18:0] RAM_ADDR; wire RAM_CE; wire RAM_OE; wire RAM_WE; wire DAC_MCLK; wire DAC_LRCK; wire DAC_SDOUT; // Bidirs wire [7:0] SNES_DATA; wire SNES_IRQ; wire [15:0] ROM_DATA; wire [7:0] RAM_DATA; wire SPI_MISO; wire SPI_SCK; wire SD_CMD; wire SD_CLK; // Instantiate the Unit Under Test (UUT) main uut ( .CLKIN(CLKIN), .SNES_ADDR(SNES_ADDR), .SNES_READ(SNES_READ), .SNES_WRITE(SNES_WRITE), .SNES_CS(SNES_CS), .SNES_DATA(SNES_DATA), .SNES_CPU_CLK(SNES_CPU_CLK), .SNES_REFRESH(SNES_REFRESH), .SNES_IRQ(SNES_IRQ), .SNES_DATABUS_OE(SNES_DATABUS_OE), .SNES_DATABUS_DIR(SNES_DATABUS_DIR), .IRQ_DIR(IRQ_DIR), .SNES_SYSCLK(SNES_SYSCLK), .ROM_DATA(ROM_DATA), .ROM_ADDR(ROM_ADDR), .ROM_CE(ROM_CE), .ROM_OE(ROM_OE), .ROM_WE(ROM_WE), .ROM_BHE(ROM_BHE), .ROM_BLE(ROM_BLE), .RAM_DATA(RAM_DATA), .RAM_ADDR(RAM_ADDR), .RAM_CE(RAM_CE), .RAM_OE(RAM_OE), .RAM_WE(RAM_WE), .SPI_MOSI(SPI_MOSI), .SPI_MISO(SPI_MISO), .SPI_SS(SPI_SS), .SPI_SCK(SPI_SCK), .MCU_OVR(MCU_OVR), .DAC_MCLK(DAC_MCLK), .DAC_LRCK(DAC_LRCK), .DAC_SDOUT(DAC_SDOUT), .SD_DAT(SD_DAT), .SD_CMD(SD_CMD), .SD_CLK(SD_CLK) ); integer i; reg [7:0] SNES_DATA_OUT; reg [7:0] SNES_DATA_IN; assign SNES_DATA = (!SNES_READ) ? 8'bZ : SNES_DATA_IN; initial begin // Initialize Inputs CLKIN = 0; SNES_ADDR = 0; SNES_READ = 1; SNES_WRITE = 1; SNES_CS = 0; SNES_CPU_CLK = 0; SNES_REFRESH = 0; SNES_SYSCLK = 0; SPI_MOSI = 0; SPI_SS = 0; MCU_OVR = 1; SD_DAT = 0; // Wait 100 ns for global reset to finish #500; // Add stimulus here SNES_ADDR = 24'h208000; SNES_DATA_IN = 8'h1f; SNES_WRITE = 0; #100 SNES_WRITE = 1; #100; for (i = 0; i < 4096; i = i + 1) begin #140 SNES_READ = 0; SNES_CPU_CLK = 1; #140 SNES_READ = 1; SNES_CPU_CLK = 0; end end always #24 CLKIN = ~CLKIN; endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Receives data from the rx_engine and buffers the output // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_64 #( parameter C_DATA_WIDTH = 9'd64, parameter C_MAIN_FIFO_DEPTH = 1024, parameter C_SG_FIFO_DEPTH = 512, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_MAIN_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_MAIN_FIFO_DEPTH))+1), parameter C_SG_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_SG_FIFO_DEPTH))+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B output SG_RX_BUF_RECVD, // Scatter gather RX buffer completely read (ready for next if applicable) input [31:0] SG_RX_BUF_DATA, // Scatter gather RX buffer data input SG_RX_BUF_LEN_VALID, // Scatter gather RX buffer length valid input SG_RX_BUF_ADDR_HI_VALID, // Scatter gather RX buffer high address valid input SG_RX_BUF_ADDR_LO_VALID, // Scatter gather RX buffer low address valid output SG_TX_BUF_RECVD, // Scatter gather TX buffer completely read (ready for next if applicable) input [31:0] SG_TX_BUF_DATA, // Scatter gather TX buffer data input SG_TX_BUF_LEN_VALID, // Scatter gather TX buffer length valid input SG_TX_BUF_ADDR_HI_VALID, // Scatter gather TX buffer high address valid input SG_TX_BUF_ADDR_LO_VALID, // Scatter gather TX buffer low address valid output [C_DATA_WIDTH-1:0] SG_DATA, // Scatter gather TX buffer data output SG_DATA_EMPTY, // Scatter gather TX buffer data empty input SG_DATA_REN, // Scatter gather TX buffer data read enable input SG_RST, // Scatter gather TX buffer data reset output SG_ERR, // Scatter gather TX encountered an error input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done input TXN_DONE_ACK, // Read transaction actual transfer length read output RX_REQ, // Read request input RX_REQ_ACK, // Read request accepted output [1:0] RX_REQ_TAG, // Read request data tag output [63:0] RX_REQ_ADDR, // Read request address output [9:0] RX_REQ_LEN, // Read request length input [C_DATA_WIDTH-1:0] MAIN_DATA, // Main incoming data input [C_DATA_WORD_WIDTH-1:0] MAIN_DATA_EN, // Main incoming data enable input MAIN_DONE, // Main incoming data complete input MAIN_ERR, // Main incoming data completed with error input [C_DATA_WIDTH-1:0] SG_RX_DATA, // Scatter gather for RX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_RX_DATA_EN, // Scatter gather for RX incoming data enable input SG_RX_DONE, // Scatter gather for RX incoming data complete input SG_RX_ERR, // Scatter gather for RX incoming data completed with error input [C_DATA_WIDTH-1:0] SG_TX_DATA, // Scatter gather for TX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_TX_DATA_EN, // Scatter gather for TX incoming data enable input SG_TX_DONE, // Scatter gather for TX incoming data complete input SG_TX_ERR, // Scatter gather for TX incoming data completed with error input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal input CHNL_RX_ACK, // Channle read received signal output CHNL_RX_LAST, // Channel last read output [31:0] CHNL_RX_LEN, // Channel read length output [30:0] CHNL_RX_OFF, // Channel read offset output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data output CHNL_RX_DATA_VALID, // Channel read data valid input CHNL_RX_DATA_REN // Channel read data has been recieved ); `include "functions.vh" wire [C_DATA_WIDTH-1:0] wPackedMainData; wire wPackedMainWen; wire wPackedMainDone; wire wPackedMainErr; wire wMainFlush; wire wMainFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgRxData; wire wPackedSgRxWen; wire wPackedSgRxDone; wire wPackedSgRxErr; wire wSgRxFlush; wire wSgRxFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgTxData; wire wPackedSgTxWen; wire wPackedSgTxDone; wire wPackedSgTxErr; wire wSgTxFlush; wire wSgTxFlushed; wire wMainDataRen; wire wMainDataEmpty; wire [C_DATA_WIDTH-1:0] wMainData; wire wSgRxRst; wire wSgRxDataRen; wire wSgRxDataEmpty; wire [C_DATA_WIDTH-1:0] wSgRxData; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgRxFifoCount; wire wSgTxRst; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgTxFifoCount; wire wSgRxReq; wire [63:0] wSgRxReqAddr; wire [9:0] wSgRxReqLen; wire wSgTxReq; wire [63:0] wSgTxReqAddr; wire [9:0] wSgTxReqLen; wire wSgRxReqProc; wire wSgTxReqProc; wire wMainReqProc; wire wReqAck; wire wSgElemRdy; wire wSgElemRen; wire [63:0] wSgElemAddr; wire [31:0] wSgElemLen; wire wSgRst; wire wMainReq; wire [63:0] wMainReqAddr; wire [9:0] wMainReqLen; wire wTxnErr; wire wChnlRx; wire wChnlRxRecvd; wire wChnlRxAckRecvd; wire wChnlRxLast; wire [31:0] wChnlRxLen; wire [30:0] wChnlRxOff; wire [31:0] wChnlRxConsumed; reg [4:0] rWideRst=0; reg rRst=0; assign SG_ERR = (wPackedSgTxDone & wPackedSgTxErr); // Generate a wide reset from the input reset. always @ (posedge CLK) begin rRst <= #1 rWideRst[4]; if (RST) rWideRst <= #1 5'b11111; else rWideRst <= (rWideRst<<1); end // Pack received data tightly into our FIFOs fifo_packer_64 mainFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(MAIN_DATA), .DATA_IN_EN(MAIN_DATA_EN), .DATA_IN_DONE(MAIN_DONE), .DATA_IN_ERR(MAIN_ERR), .DATA_IN_FLUSH(wMainFlush), .PACKED_DATA(wPackedMainData), .PACKED_WEN(wPackedMainWen), .PACKED_DATA_DONE(wPackedMainDone), .PACKED_DATA_ERR(wPackedMainErr), .PACKED_DATA_FLUSHED(wMainFlushed) ); fifo_packer_64 sgRxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_RX_DATA), .DATA_IN_EN(SG_RX_DATA_EN), .DATA_IN_DONE(SG_RX_DONE), .DATA_IN_ERR(SG_RX_ERR), .DATA_IN_FLUSH(wSgRxFlush), .PACKED_DATA(wPackedSgRxData), .PACKED_WEN(wPackedSgRxWen), .PACKED_DATA_DONE(wPackedSgRxDone), .PACKED_DATA_ERR(wPackedSgRxErr), .PACKED_DATA_FLUSHED(wSgRxFlushed) ); fifo_packer_64 sgTxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_TX_DATA), .DATA_IN_EN(SG_TX_DATA_EN), .DATA_IN_DONE(SG_TX_DONE), .DATA_IN_ERR(SG_TX_ERR), .DATA_IN_FLUSH(wSgTxFlush), .PACKED_DATA(wPackedSgTxData), .PACKED_WEN(wPackedSgTxWen), .PACKED_DATA_DONE(wPackedSgTxDone), .PACKED_DATA_ERR(wPackedSgTxErr), .PACKED_DATA_FLUSHED(wSgTxFlushed) ); // FIFOs for storing received data for the channel. (* RAM_STYLE="BLOCK" *) async_fifo_fwft #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_MAIN_FIFO_DEPTH)) mainFifo ( .WR_CLK(CLK), .WR_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .WR_EN(wPackedMainWen), .WR_DATA(wPackedMainData), .WR_FULL(), .RD_CLK(CHNL_CLK), .RD_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .RD_EN(wMainDataRen), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgRxFifo ( .RST(rRst | wSgRxRst), .CLK(CLK), .WR_EN(wPackedSgRxWen), .WR_DATA(wPackedSgRxData), .FULL(), .RD_EN(wSgRxDataRen), .RD_DATA(wSgRxData), .EMPTY(wSgRxDataEmpty), .COUNT(wSgRxFifoCount) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgTxFifo ( .RST(rRst | wSgTxRst), .CLK(CLK), .WR_EN(wPackedSgTxWen), .WR_DATA(wPackedSgTxData), .FULL(), .RD_EN(SG_DATA_REN), .RD_DATA(SG_DATA), .EMPTY(SG_DATA_EMPTY), .COUNT(wSgTxFifoCount) ); // Manage requesting and acknowledging scatter gather data. Note that // these modules will share the main requestor's RX channel. They will // take priority over the main logic's use of the RX channel. sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgRxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(wSgRst), .BUF_RECVD(SG_RX_BUF_RECVD), .BUF_DATA(SG_RX_BUF_DATA), .BUF_LEN_VALID(SG_RX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_RX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_RX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgRxFifoCount), .FIFO_FLUSH(wSgRxFlush), .FIFO_FLUSHED(wSgRxFlushed), .FIFO_RST(wSgRxRst), .RX_REQ(wSgRxReq), .RX_ADDR(wSgRxReqAddr), .RX_LEN(wSgRxReqLen), .RX_REQ_ACK(wReqAck & wSgRxReqProc), .RX_DONE(wPackedSgRxDone) ); sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgTxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(SG_RST), .BUF_RECVD(SG_TX_BUF_RECVD), .BUF_DATA(SG_TX_BUF_DATA), .BUF_LEN_VALID(SG_TX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_TX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_TX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgTxFifoCount), .FIFO_FLUSH(wSgTxFlush), .FIFO_FLUSHED(wSgTxFlushed), .FIFO_RST(wSgTxRst), .RX_REQ(wSgTxReq), .RX_ADDR(wSgTxReqAddr), .RX_LEN(wSgTxReqLen), .RX_REQ_ACK(wReqAck & wSgTxReqProc), .RX_DONE(wPackedSgTxDone) ); // A read requester for the channel and scatter gather requesters. rx_port_requester_mux requesterMux ( .RST(rRst), .CLK(CLK), .SG_RX_REQ(wSgRxReq), .SG_RX_LEN(wSgRxReqLen), .SG_RX_ADDR(wSgRxReqAddr), .SG_RX_REQ_PROC(wSgRxReqProc), .SG_TX_REQ(wSgTxReq), .SG_TX_LEN(wSgTxReqLen), .SG_TX_ADDR(wSgTxReqAddr), .SG_TX_REQ_PROC(wSgTxReqProc), .MAIN_REQ(wMainReq), .MAIN_LEN(wMainReqLen), .MAIN_ADDR(wMainReqAddr), .MAIN_REQ_PROC(wMainReqProc), .RX_REQ(RX_REQ), .RX_REQ_ACK(RX_REQ_ACK), .RX_REQ_TAG(RX_REQ_TAG), .RX_REQ_ADDR(RX_REQ_ADDR), .RX_REQ_LEN(RX_REQ_LEN), .REQ_ACK(wReqAck) ); // Read the scatter gather buffer address and length, continuously so that // we have it ready whenever the next buffer is needed. sg_list_reader_64 #(.C_DATA_WIDTH(C_DATA_WIDTH)) sgListReader ( .CLK(CLK), .RST(rRst | wSgRst), .BUF_DATA(wSgRxData), .BUF_DATA_EMPTY(wSgRxDataEmpty), .BUF_DATA_REN(wSgRxDataRen), .VALID(wSgElemRdy), .EMPTY(), .REN(wSgElemRen), .ADDR(wSgElemAddr), .LEN(wSgElemLen) ); // Main port reader logic rx_port_reader #(.C_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_MAIN_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) reader ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .TXN_DATA(TXN_DATA), .TXN_LEN_VALID(TXN_LEN_VALID), .TXN_OFF_LAST_VALID(TXN_OFF_LAST_VALID), .TXN_DONE_LEN(TXN_DONE_LEN), .TXN_DONE(TXN_DONE), .TXN_ERR(wTxnErr), .TXN_DONE_ACK(TXN_DONE_ACK), .TXN_DATA_FLUSH(wMainFlush), .TXN_DATA_FLUSHED(wMainFlushed), .RX_REQ(wMainReq), .RX_ADDR(wMainReqAddr), .RX_LEN(wMainReqLen), .RX_REQ_ACK(wReqAck & wMainReqProc), .RX_DATA_EN(MAIN_DATA_EN), .RX_DONE(wPackedMainDone), .RX_ERR(wPackedMainErr), .SG_DONE(wPackedSgRxDone), .SG_ERR(wPackedSgRxErr), .SG_ELEM_ADDR(wSgElemAddr), .SG_ELEM_LEN(wSgElemLen), .SG_ELEM_RDY(wSgElemRdy), .SG_ELEM_REN(wSgElemRen), .SG_RST(wSgRst), .CHNL_RX(wChnlRx), .CHNL_RX_LEN(wChnlRxLen), .CHNL_RX_LAST(wChnlRxLast), .CHNL_RX_OFF(wChnlRxOff), .CHNL_RX_RECVD(wChnlRxRecvd), .CHNL_RX_ACK_RECVD(wChnlRxAckRecvd), .CHNL_RX_CONSUMED(wChnlRxConsumed) ); // Manage the CHNL_RX* signals in the CHNL_CLK domain. rx_port_channel_gate #(.C_DATA_WIDTH(C_DATA_WIDTH)) gate ( .RST(rRst), .CLK(CLK), .RX(wChnlRx), .RX_RECVD(wChnlRxRecvd), .RX_ACK_RECVD(wChnlRxAckRecvd), .RX_LAST(wChnlRxLast), .RX_LEN(wChnlRxLen), .RX_OFF(wChnlRxOff), .RX_CONSUMED(wChnlRxConsumed), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty), .RD_EN(wMainDataRen), .CHNL_CLK(CHNL_CLK), .CHNL_RX(CHNL_RX), .CHNL_RX_ACK(CHNL_RX_ACK), .CHNL_RX_LAST(CHNL_RX_LAST), .CHNL_RX_LEN(CHNL_RX_LEN), .CHNL_RX_OFF(CHNL_RX_OFF), .CHNL_RX_DATA(CHNL_RX_DATA), .CHNL_RX_DATA_VALID(CHNL_RX_DATA_VALID), .CHNL_RX_DATA_REN(CHNL_RX_DATA_REN) ); /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({SG_RX_DATA_EN != 0, wSgElemRen, wMainReq | wSgRxReq | wSgTxReq, RX_REQ, SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID, wSgRst, wTxnErr | wPackedSgRxDone | wSgRxFlush | wSgRxFlushed, TXN_OFF_LAST_VALID | TXN_LEN_VALID}), .DATA({ wPackedSgRxErr, // 1 wPackedSgRxDone, // 1 wPackedSgRxWen, // 1 wPackedSgRxData, // 64 SG_RX_ERR, // 1 SG_RX_DONE, // 1 SG_RX_DATA_EN, // 2 SG_RX_DATA, // 64 wSgRxDataRen, // 1 wSgRxDataEmpty, // 1 wSgRxData, // 64 wSgRst, // 1 SG_RST, // 1 wPackedSgRxDone, // 1 wSgRxRst, // 1 wSgRxFlushed, // 1 wSgRxFlush, // 1 SG_RX_BUF_ADDR_LO_VALID, // 1 SG_RX_BUF_ADDR_HI_VALID, // 1 SG_RX_BUF_LEN_VALID, // 1 SG_RX_BUF_DATA, // 32 RX_REQ_ADDR, // 64 RX_REQ_TAG, // 2 RX_REQ_ACK, // 1 RX_REQ, // 1 wSgTxReqProc, // 1 wSgTxReqAddr, // 64 wSgTxReq, // 1 wSgRxReqProc, // 1 wSgRxReqAddr, // 64 wSgRxReq, // 1 wMainReqProc, // 1 wMainReqAddr, // 64 wMainReq, // 1 wReqAck, // 1 wTxnErr, // 1 TXN_OFF_LAST_VALID, // 1 TXN_LEN_VALID}) // 1 ); */ endmodule
//***************************************************************************** // (c) Copyright 2009 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor: Xilinx // \ \ \/ Version: %version // \ \ Application: MIG // / / Filename: ddr_phy_oclkdelay_cal.v // /___/ /\ Date Last Modified: $Date: 2011/02/25 02:07:40 $ // \ \ / \ Date Created: Aug 03 2009 // \___\/\___\ // //Device: 7 Series //Design Name: DDR3 SDRAM //Purpose: Center write DQS in write DQ valid window using Phaser_Out Stage3 // delay //Reference: //Revision History: //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_ddr_phy_oclkdelay_cal # ( parameter TCQ = 100, parameter tCK = 2500, parameter nCK_PER_CLK = 4, parameter DRAM_TYPE = "DDR3", parameter DRAM_WIDTH = 8, parameter DQS_CNT_WIDTH = 3, parameter DQS_WIDTH = 8, parameter DQ_WIDTH = 64, parameter SIM_CAL_OPTION = "NONE", parameter OCAL_EN = "ON" ) ( input clk, input rst, // Start only after PO and PI FINE delay decremented input oclk_init_delay_start, input oclkdelay_calib_start, input [5:0] oclkdelay_init_val, // Detect write valid data edge during OCLKDELAY calib input phy_rddata_en, input [2*nCK_PER_CLK*DQ_WIDTH-1:0] rd_data, // Precharge done status from ddr_phy_init input prech_done, // Write Level signals during OCLKDELAY calibration input [6*DQS_WIDTH-1:0] wl_po_fine_cnt, output reg wrlvl_final, // Inc/dec Phaser_Out fine delay line output reg po_stg3_incdec, output reg po_en_stg3, output reg po_stg23_sel, output reg po_stg23_incdec, output reg po_en_stg23, // Completed initial delay increment output oclk_init_delay_done, output [DQS_CNT_WIDTH:0] oclkdelay_calib_cnt, output reg oclk_prech_req, output reg oclk_calib_resume, output oclkdelay_calib_done, output [255:0] dbg_phy_oclkdelay_cal, output [16*DRAM_WIDTH-1:0] dbg_oclkdelay_rd_data ); // Start with an initial delay of 0 on OCLKDELAY. This is required to // detect two valid data edges when possible. Two edges cannot be // detected if write DQ and DQS are exactly edge aligned at stage3 tap0. localparam TAP_CNT = 0; //(tCK <= 938) ? 13 : //(tCK <= 1072) ? 14 : //(tCK <= 1250) ? 15 : //(tCK <= 1500) ? 16 : 17; localparam WAIT_CNT = 15; // Default set to TRUE because there can be a case where the ocal_rise_right_edge // may not be detected if WRLVL stage2 tap value is large upto 63 and the initial // DQS position is more than 225 degrees localparam MINUS_32 = "TRUE"; localparam [4:0] OCAL_IDLE = 5'h00; localparam [4:0] OCAL_NEW_DQS_WAIT = 5'h01; localparam [4:0] OCAL_STG3_SEL = 5'h02; localparam [4:0] OCAL_STG3_SEL_WAIT = 5'h03; localparam [4:0] OCAL_STG3_EN_WAIT = 5'h04; localparam [4:0] OCAL_STG3_DEC = 5'h05; localparam [4:0] OCAL_STG3_WAIT = 5'h06; localparam [4:0] OCAL_STG3_CALC = 5'h07; localparam [4:0] OCAL_STG3_INC = 5'h08; localparam [4:0] OCAL_STG3_INC_WAIT = 5'h09; localparam [4:0] OCAL_STG2_SEL = 5'h0A; localparam [4:0] OCAL_STG2_WAIT = 5'h0B; localparam [4:0] OCAL_STG2_INC = 5'h0C; localparam [4:0] OCAL_STG2_DEC = 5'h0D; localparam [4:0] OCAL_STG2_DEC_WAIT = 5'h0E; localparam [4:0] OCAL_NEXT_DQS = 5'h0F; localparam [4:0] OCAL_NEW_DQS_READ = 5'h10; localparam [4:0] OCAL_INC_DONE_WAIT = 5'h11; localparam [4:0] OCAL_STG3_DEC_WAIT = 5'h12; localparam [4:0] OCAL_DEC_DONE_WAIT = 5'h13; localparam [4:0] OCAL_DONE = 5'h14; integer i; reg oclk_init_delay_start_r; reg [3:0] count; reg delay_done; reg delay_done_r1; reg delay_done_r2; reg delay_done_r3; reg delay_done_r4; reg [5:0] delay_cnt_r; reg po_stg3_dec; wire [DQ_WIDTH-1:0] rd_data_rise0; wire [DQ_WIDTH-1:0] rd_data_fall0; wire [DQ_WIDTH-1:0] rd_data_rise1; wire [DQ_WIDTH-1:0] rd_data_fall1; wire [DQ_WIDTH-1:0] rd_data_rise2; wire [DQ_WIDTH-1:0] rd_data_fall2; wire [DQ_WIDTH-1:0] rd_data_rise3; wire [DQ_WIDTH-1:0] rd_data_fall3; reg [DQS_CNT_WIDTH:0] cnt_dqs_r; reg [DQS_CNT_WIDTH:0] mux_sel_r; reg [DRAM_WIDTH-1:0] sel_rd_rise0_r; reg [DRAM_WIDTH-1:0] sel_rd_fall0_r; reg [DRAM_WIDTH-1:0] sel_rd_rise1_r; reg [DRAM_WIDTH-1:0] sel_rd_fall1_r; reg [DRAM_WIDTH-1:0] sel_rd_rise2_r; reg [DRAM_WIDTH-1:0] sel_rd_fall2_r; reg [DRAM_WIDTH-1:0] sel_rd_rise3_r; reg [DRAM_WIDTH-1:0] sel_rd_fall3_r; reg [DRAM_WIDTH-1:0] prev_rd_rise0_r; reg [DRAM_WIDTH-1:0] prev_rd_fall0_r; reg [DRAM_WIDTH-1:0] prev_rd_rise1_r; reg [DRAM_WIDTH-1:0] prev_rd_fall1_r; reg [DRAM_WIDTH-1:0] prev_rd_rise2_r; reg [DRAM_WIDTH-1:0] prev_rd_fall2_r; reg [DRAM_WIDTH-1:0] prev_rd_rise3_r; reg [DRAM_WIDTH-1:0] prev_rd_fall3_r; reg rd_active_r; reg rd_active_r1; reg rd_active_r2; reg rd_active_r3; reg rd_active_r4; reg [DRAM_WIDTH-1:0] pat_match_fall0_r; reg pat_match_fall0_and_r; reg [DRAM_WIDTH-1:0] pat_match_fall1_r; reg pat_match_fall1_and_r; reg [DRAM_WIDTH-1:0] pat_match_fall2_r; reg pat_match_fall2_and_r; reg [DRAM_WIDTH-1:0] pat_match_fall3_r; reg pat_match_fall3_and_r; reg [DRAM_WIDTH-1:0] pat_match_rise0_r; reg pat_match_rise0_and_r; reg [DRAM_WIDTH-1:0] pat_match_rise1_r; reg pat_match_rise1_and_r; reg [DRAM_WIDTH-1:0] pat_match_rise2_r; reg pat_match_rise2_and_r; reg [DRAM_WIDTH-1:0] pat_match_rise3_r; reg pat_match_rise3_and_r; reg pat_data_match_r; reg pat_data_match_valid_r; reg pat_data_match_valid_r1; //reg [3:0] stable_stg3_cnt; //reg stable_eye_r; reg [3:0] stable_rise_stg3_cnt; reg stable_rise_eye_r; reg [3:0] stable_fall_stg3_cnt; reg stable_fall_eye_r; reg wait_cnt_en_r; reg [3:0] wait_cnt_r; reg cnt_next_state; reg oclkdelay_calib_start_r; reg [5:0] stg3_tap_cnt; reg [5:0] stg3_incdec_limit; reg stg3_dec2inc; reg [5:0] stg2_tap_cnt; reg [1:0] stg2_inc2_cnt; reg [1:0] stg2_dec2_cnt; reg [5:0] stg2_dec_cnt; reg stg3_dec; reg stg3_dec_r; reg [4:0] ocal_state_r; reg [4:0] ocal_state_r1; reg [5:0] ocal_final_cnt_r; reg ocal_final_cnt_r_calc; reg [5:0] ocal_inc_cnt; reg [5:0] ocal_dec_cnt; reg ocal_stg3_inc_en; reg ocal_rise_edge1_found; reg ocal_rise_edge2_found; reg ocal_rise_edge1_found_timing; reg ocal_rise_edge2_found_timing; reg [5:0] ocal_rise_edge1_taps; reg [5:0] ocal_rise_edge2_taps; reg [5:0] ocal_rise_right_edge; reg ocal_fall_edge1_found; reg ocal_fall_edge2_found; reg [5:0] ocal_fall_edge1_taps; reg [5:0] ocal_fall_edge2_taps; reg [5:0] ocal_final_cnt_r_mux_a; reg [5:0] ocal_final_cnt_r_mux_b; reg [5:0] ocal_final_cnt_r_mux_c; reg [5:0] ocal_final_cnt_r_mux_d; reg ocal_byte_done; reg ocal_wrlvl_done; reg ocal_wrlvl_done_r; (* keep = "true", max_fanout = 10 *) reg ocal_done_r /* synthesis syn_maxfan = 10 */; reg [5:0] ocal_tap_cnt_r[0:DQS_WIDTH-1]; reg prech_done_r; reg rise_win; reg fall_win; // timing registers reg stg3_tap_cnt_eq_oclkdelay_init_val; reg stg3_tap_cnt_eq_0; //reg stg3_tap_cnt_gt_20; reg stg3_tap_cnt_eq_63; reg stg3_tap_cnt_less_oclkdelay_init_val; reg stg3_limit; wire [5:0] wl_po_fine_cnt_w[0:DQS_WIDTH-1]; //************************************************************************** // Debug signals //************************************************************************** genvar dqs_i; generate for (dqs_i=0; dqs_i < DQS_WIDTH; dqs_i = dqs_i + 1) begin: oclkdelay_tap_cnt assign dbg_phy_oclkdelay_cal[6*dqs_i+:6] = ocal_tap_cnt_r[dqs_i][5:0]; end endgenerate assign dbg_phy_oclkdelay_cal[57:54] = cnt_dqs_r; assign dbg_phy_oclkdelay_cal[58] = ocal_rise_edge1_found_timing; assign dbg_phy_oclkdelay_cal[59] = ocal_rise_edge2_found_timing; assign dbg_phy_oclkdelay_cal[65:60] = ocal_rise_edge1_taps; assign dbg_phy_oclkdelay_cal[71:66] = ocal_rise_edge2_taps; assign dbg_phy_oclkdelay_cal[76:72] = ocal_state_r1; assign dbg_phy_oclkdelay_cal[77] = pat_data_match_valid_r; assign dbg_phy_oclkdelay_cal[78] = pat_data_match_r; assign dbg_phy_oclkdelay_cal[84:79] = stg3_tap_cnt; assign dbg_phy_oclkdelay_cal[88:85] = stable_rise_stg3_cnt; assign dbg_phy_oclkdelay_cal[89] = stable_rise_eye_r; assign dbg_phy_oclkdelay_cal[97:90] = prev_rd_rise0_r; assign dbg_phy_oclkdelay_cal[105:98] = prev_rd_fall0_r; assign dbg_phy_oclkdelay_cal[113:106] = prev_rd_rise1_r; assign dbg_phy_oclkdelay_cal[121:114] = prev_rd_fall1_r; assign dbg_phy_oclkdelay_cal[129:122] = prev_rd_rise2_r; assign dbg_phy_oclkdelay_cal[137:130] = prev_rd_fall2_r; assign dbg_phy_oclkdelay_cal[145:138] = prev_rd_rise3_r; assign dbg_phy_oclkdelay_cal[153:146] = prev_rd_fall3_r; assign dbg_phy_oclkdelay_cal[154] = rd_active_r; assign dbg_phy_oclkdelay_cal[162:155] = sel_rd_rise0_r; assign dbg_phy_oclkdelay_cal[170:163] = sel_rd_fall0_r; assign dbg_phy_oclkdelay_cal[178:171] = sel_rd_rise1_r; assign dbg_phy_oclkdelay_cal[186:179] = sel_rd_fall1_r; assign dbg_phy_oclkdelay_cal[194:187] = sel_rd_rise2_r; assign dbg_phy_oclkdelay_cal[202:195] = sel_rd_fall2_r; assign dbg_phy_oclkdelay_cal[210:203] = sel_rd_rise3_r; assign dbg_phy_oclkdelay_cal[218:211] = sel_rd_fall3_r; assign dbg_phy_oclkdelay_cal[219+:6] = stg2_tap_cnt; assign dbg_phy_oclkdelay_cal[225] = ocal_fall_edge1_found; assign dbg_phy_oclkdelay_cal[226] = ocal_fall_edge2_found; assign dbg_phy_oclkdelay_cal[232:227] = ocal_fall_edge1_taps; assign dbg_phy_oclkdelay_cal[238:233] = ocal_fall_edge2_taps; assign dbg_phy_oclkdelay_cal[244:239] = ocal_rise_right_edge; assign dbg_phy_oclkdelay_cal[250:245] = 'd0; assign dbg_phy_oclkdelay_cal[251] = stable_fall_eye_r; assign dbg_phy_oclkdelay_cal[252] = rise_win; assign dbg_phy_oclkdelay_cal[253] = fall_win; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*1 -1:0] = prev_rd_rise0_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*2 -1:DRAM_WIDTH*1] = prev_rd_fall0_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*3 -1:DRAM_WIDTH*2] = prev_rd_rise1_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*4 -1:DRAM_WIDTH*3] = prev_rd_fall1_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*5 -1:DRAM_WIDTH*4] = prev_rd_rise2_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*6 -1:DRAM_WIDTH*5] = prev_rd_fall2_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*7 -1:DRAM_WIDTH*6] = prev_rd_rise3_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*8 -1:DRAM_WIDTH*7] = prev_rd_fall3_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*9 -1:DRAM_WIDTH*8] = sel_rd_rise0_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*10 -1:DRAM_WIDTH*9] = sel_rd_fall0_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*11 -1:DRAM_WIDTH*10] = sel_rd_rise1_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*12 -1:DRAM_WIDTH*11] = sel_rd_fall1_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*13 -1:DRAM_WIDTH*12] = sel_rd_rise2_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*14 -1:DRAM_WIDTH*13] = sel_rd_fall2_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*15 -1:DRAM_WIDTH*14] = sel_rd_rise3_r; assign dbg_oclkdelay_rd_data[DRAM_WIDTH*16 -1:DRAM_WIDTH*15] = sel_rd_fall3_r; assign oclk_init_delay_done = ((SIM_CAL_OPTION == "FAST_CAL") || (DRAM_TYPE!="DDR3")) ? 1'b1 : delay_done_r4; //(SIM_CAL_OPTION != "NONE") assign oclkdelay_calib_cnt = cnt_dqs_r; assign oclkdelay_calib_done = (OCAL_EN == "ON") ? ocal_done_r : 1'b1; always @(posedge clk) oclk_init_delay_start_r <= #TCQ oclk_init_delay_start; always @(posedge clk) begin if (rst || po_stg3_dec) count <= #TCQ WAIT_CNT; else if (oclk_init_delay_start && (count > 'd0)) count <= #TCQ count - 1; end always @(posedge clk) begin if (rst) po_stg3_dec <= #TCQ 1'b0; else if ((count == 'd1) && (delay_cnt_r != 'd0)) po_stg3_dec <= #TCQ 1'b1; else po_stg3_dec <= #TCQ 1'b0; end //po_stg3_incdec and po_en_stg3 asserted for all data byte lanes always @(posedge clk) begin if (rst) begin po_stg3_incdec <= #TCQ 1'b0; po_en_stg3 <= #TCQ 1'b0; end else if (po_stg3_dec) begin po_stg3_incdec <= #TCQ 1'b0; po_en_stg3 <= #TCQ 1'b1; end else begin po_stg3_incdec <= #TCQ 1'b0; po_en_stg3 <= #TCQ 1'b0; end end // delay counter to count TAP_CNT cycles always @(posedge clk) begin // load delay counter with init value of TAP_CNT if (rst) delay_cnt_r <= #TCQ TAP_CNT; else if (po_stg3_dec && (delay_cnt_r > 6'd0)) delay_cnt_r <= #TCQ delay_cnt_r - 1; end // when all the ctl_lanes have their output phase shifted by 1/4 cycle, delay shifting is done. always @(posedge clk) begin if (rst) begin delay_done <= #TCQ 1'b0; end else if ((TAP_CNT == 6'd0) || ((delay_cnt_r == 6'd1) && (count == 'd1))) begin delay_done <= #TCQ 1'b1; end end always @(posedge clk) begin delay_done_r1 <= #TCQ delay_done; delay_done_r2 <= #TCQ delay_done_r1; delay_done_r3 <= #TCQ delay_done_r2; delay_done_r4 <= #TCQ delay_done_r3; end //************************************************************************** // OCLKDELAY Calibration //************************************************************************** generate if (nCK_PER_CLK == 4) begin: gen_rd_data_div4 assign rd_data_rise0 = rd_data[DQ_WIDTH-1:0]; assign rd_data_fall0 = rd_data[2*DQ_WIDTH-1:DQ_WIDTH]; assign rd_data_rise1 = rd_data[3*DQ_WIDTH-1:2*DQ_WIDTH]; assign rd_data_fall1 = rd_data[4*DQ_WIDTH-1:3*DQ_WIDTH]; assign rd_data_rise2 = rd_data[5*DQ_WIDTH-1:4*DQ_WIDTH]; assign rd_data_fall2 = rd_data[6*DQ_WIDTH-1:5*DQ_WIDTH]; assign rd_data_rise3 = rd_data[7*DQ_WIDTH-1:6*DQ_WIDTH]; assign rd_data_fall3 = rd_data[8*DQ_WIDTH-1:7*DQ_WIDTH]; end else if (nCK_PER_CLK == 2) begin: gen_rd_data_div2 assign rd_data_rise0 = rd_data[DQ_WIDTH-1:0]; assign rd_data_fall0 = rd_data[2*DQ_WIDTH-1:DQ_WIDTH]; assign rd_data_rise1 = rd_data[3*DQ_WIDTH-1:2*DQ_WIDTH]; assign rd_data_fall1 = rd_data[4*DQ_WIDTH-1:3*DQ_WIDTH]; end endgenerate always @(posedge clk) begin mux_sel_r <= #TCQ cnt_dqs_r; oclkdelay_calib_start_r <= #TCQ oclkdelay_calib_start; ocal_wrlvl_done_r <= #TCQ ocal_wrlvl_done; rd_active_r <= #TCQ phy_rddata_en; rd_active_r1 <= #TCQ rd_active_r; rd_active_r2 <= #TCQ rd_active_r1; rd_active_r3 <= #TCQ rd_active_r2; rd_active_r4 <= #TCQ rd_active_r3; stg3_dec_r <= #TCQ stg3_dec; ocal_state_r1 <= #TCQ ocal_state_r; end // Register outputs for improved timing. // All bits in selected DQS group are checked in aggregate generate genvar mux_j; for (mux_j = 0; mux_j < DRAM_WIDTH; mux_j = mux_j + 1) begin: gen_mux_rd always @(posedge clk) begin if (phy_rddata_en) begin sel_rd_rise0_r[mux_j] <= #TCQ rd_data_rise0[DRAM_WIDTH*mux_sel_r + mux_j]; sel_rd_fall0_r[mux_j] <= #TCQ rd_data_fall0[DRAM_WIDTH*mux_sel_r + mux_j]; sel_rd_rise1_r[mux_j] <= #TCQ rd_data_rise1[DRAM_WIDTH*mux_sel_r + mux_j]; sel_rd_fall1_r[mux_j] <= #TCQ rd_data_fall1[DRAM_WIDTH*mux_sel_r + mux_j]; sel_rd_rise2_r[mux_j] <= #TCQ rd_data_rise2[DRAM_WIDTH*mux_sel_r + mux_j]; sel_rd_fall2_r[mux_j] <= #TCQ rd_data_fall2[DRAM_WIDTH*mux_sel_r + mux_j]; sel_rd_rise3_r[mux_j] <= #TCQ rd_data_rise3[DRAM_WIDTH*mux_sel_r + mux_j]; sel_rd_fall3_r[mux_j] <= #TCQ rd_data_fall3[DRAM_WIDTH*mux_sel_r + mux_j]; end end end endgenerate always @(posedge clk) if (((stg3_tap_cnt_eq_oclkdelay_init_val) && rd_active_r) | rd_active_r4) begin prev_rd_rise0_r <= #TCQ sel_rd_rise0_r; prev_rd_fall0_r <= #TCQ sel_rd_fall0_r; prev_rd_rise1_r <= #TCQ sel_rd_rise1_r; prev_rd_fall1_r <= #TCQ sel_rd_fall1_r; prev_rd_rise2_r <= #TCQ sel_rd_rise2_r; prev_rd_fall2_r <= #TCQ sel_rd_fall2_r; prev_rd_rise3_r <= #TCQ sel_rd_rise3_r; prev_rd_fall3_r <= #TCQ sel_rd_fall3_r; end // Each bit of each byte is compared with previous data to // detect an edge generate genvar pt_j; if (nCK_PER_CLK == 4) begin: gen_pat_match_div4 always @(posedge clk) begin if (rd_active_r) begin rise_win <= #TCQ ((|sel_rd_rise0_r) | (|sel_rd_rise1_r) | (|sel_rd_rise2_r) | (|sel_rd_rise3_r)); fall_win <= #TCQ ((&sel_rd_rise0_r) & (&sel_rd_rise1_r) & (&sel_rd_rise2_r) & (&sel_rd_rise3_r)); end end for (pt_j = 0; pt_j < DRAM_WIDTH; pt_j = pt_j + 1) begin: gen_pat_match always @(posedge clk) begin if (sel_rd_rise0_r[pt_j] == prev_rd_rise0_r[pt_j]) pat_match_rise0_r[pt_j] <= #TCQ 1'b1; else pat_match_rise0_r[pt_j] <= #TCQ 1'b0; if (sel_rd_fall0_r[pt_j] == prev_rd_fall0_r[pt_j]) pat_match_fall0_r[pt_j] <= #TCQ 1'b1; else pat_match_fall0_r[pt_j] <= #TCQ 1'b0; if (sel_rd_rise1_r[pt_j] == prev_rd_rise1_r[pt_j]) pat_match_rise1_r[pt_j] <= #TCQ 1'b1; else pat_match_rise1_r[pt_j] <= #TCQ 1'b0; if (sel_rd_fall1_r[pt_j] == prev_rd_fall1_r[pt_j]) pat_match_fall1_r[pt_j] <= #TCQ 1'b1; else pat_match_fall1_r[pt_j] <= #TCQ 1'b0; if (sel_rd_rise2_r[pt_j] == prev_rd_rise2_r[pt_j]) pat_match_rise2_r[pt_j] <= #TCQ 1'b1; else pat_match_rise2_r[pt_j] <= #TCQ 1'b0; if (sel_rd_fall2_r[pt_j] == prev_rd_fall2_r[pt_j]) pat_match_fall2_r[pt_j] <= #TCQ 1'b1; else pat_match_fall2_r[pt_j] <= #TCQ 1'b0; if (sel_rd_rise3_r[pt_j] == prev_rd_rise3_r[pt_j]) pat_match_rise3_r[pt_j] <= #TCQ 1'b1; else pat_match_rise3_r[pt_j] <= #TCQ 1'b0; if (sel_rd_fall3_r[pt_j] == prev_rd_fall3_r[pt_j]) pat_match_fall3_r[pt_j] <= #TCQ 1'b1; else pat_match_fall3_r[pt_j] <= #TCQ 1'b0; end end always @(posedge clk) begin pat_match_rise0_and_r <= #TCQ &pat_match_rise0_r; pat_match_fall0_and_r <= #TCQ &pat_match_fall0_r; pat_match_rise1_and_r <= #TCQ &pat_match_rise1_r; pat_match_fall1_and_r <= #TCQ &pat_match_fall1_r; pat_match_rise2_and_r <= #TCQ &pat_match_rise2_r; pat_match_fall2_and_r <= #TCQ &pat_match_fall2_r; pat_match_rise3_and_r <= #TCQ &pat_match_rise3_r; pat_match_fall3_and_r <= #TCQ &pat_match_fall3_r; pat_data_match_r <= #TCQ (//pat_match_rise0_and_r && //pat_match_fall0_and_r && pat_match_rise1_and_r && pat_match_fall1_and_r && pat_match_rise2_and_r && pat_match_fall2_and_r && pat_match_rise3_and_r && pat_match_fall3_and_r); pat_data_match_valid_r <= #TCQ rd_active_r2; end always @(posedge clk) pat_data_match_valid_r1 <= #TCQ pat_data_match_valid_r; end else if (nCK_PER_CLK == 2) begin: gen_pat_match_div2 always @(posedge clk) begin if (rd_active_r) begin rise_win <= #TCQ ((|sel_rd_rise0_r) | (|sel_rd_rise1_r)); fall_win <= #TCQ ((&sel_rd_rise0_r) & (&sel_rd_rise1_r)); end end for (pt_j = 0; pt_j < DRAM_WIDTH; pt_j = pt_j + 1) begin: gen_pat_match always @(posedge clk) begin if (sel_rd_rise0_r[pt_j] == prev_rd_rise0_r[pt_j]) pat_match_rise0_r[pt_j] <= #TCQ 1'b1; else pat_match_rise0_r[pt_j] <= #TCQ 1'b0; if (sel_rd_fall0_r[pt_j] == prev_rd_fall0_r[pt_j]) pat_match_fall0_r[pt_j] <= #TCQ 1'b1; else pat_match_fall0_r[pt_j] <= #TCQ 1'b0; if (sel_rd_rise1_r[pt_j] == prev_rd_rise1_r[pt_j]) pat_match_rise1_r[pt_j] <= #TCQ 1'b1; else pat_match_rise1_r[pt_j] <= #TCQ 1'b0; if (sel_rd_fall1_r[pt_j] == prev_rd_fall1_r[pt_j]) pat_match_fall1_r[pt_j] <= #TCQ 1'b1; else pat_match_fall1_r[pt_j] <= #TCQ 1'b0; end end always @(posedge clk) begin pat_match_rise0_and_r <= #TCQ &pat_match_rise0_r; pat_match_fall0_and_r <= #TCQ &pat_match_fall0_r; pat_match_rise1_and_r <= #TCQ &pat_match_rise1_r; pat_match_fall1_and_r <= #TCQ &pat_match_fall1_r; pat_data_match_r <= #TCQ (//pat_match_rise0_and_r && //pat_match_fall0_and_r && pat_match_rise1_and_r && pat_match_fall1_and_r); pat_data_match_valid_r <= #TCQ rd_active_r2; end always @(posedge clk) pat_data_match_valid_r1 <= #TCQ pat_data_match_valid_r; end endgenerate // Stable count of 16 PO Stage3 taps at 2x the resolution of stage2 taps // Required to inhibit false edge detection due to clock jitter always @(posedge clk)begin if (rst | (pat_data_match_valid_r & ~pat_data_match_r & (ocal_state_r == OCAL_NEW_DQS_WAIT)) | (ocal_state_r == OCAL_STG3_CALC)) stable_rise_stg3_cnt <= #TCQ 'd0; else if ((!stg3_tap_cnt_eq_oclkdelay_init_val) & pat_data_match_valid_r & pat_data_match_r & (ocal_state_r == OCAL_NEW_DQS_WAIT) & (stable_rise_stg3_cnt < 'd8) & ~rise_win) stable_rise_stg3_cnt <= #TCQ stable_rise_stg3_cnt + 1; end always @(posedge clk) begin if (rst | (stable_rise_stg3_cnt != 'd8)) stable_rise_eye_r <= #TCQ 1'b0; else if (stable_rise_stg3_cnt == 'd8) stable_rise_eye_r <= #TCQ 1'b1; end always @(posedge clk)begin if (rst | (pat_data_match_valid_r & ~pat_data_match_r & (ocal_state_r == OCAL_NEW_DQS_WAIT)) | (ocal_state_r == OCAL_STG3_CALC)) stable_fall_stg3_cnt <= #TCQ 'd0; else if ((!stg3_tap_cnt_eq_oclkdelay_init_val) & pat_data_match_valid_r & pat_data_match_r & (ocal_state_r == OCAL_NEW_DQS_WAIT) & (stable_fall_stg3_cnt < 'd8) & fall_win) stable_fall_stg3_cnt <= #TCQ stable_fall_stg3_cnt + 1; end always @(posedge clk) begin if (rst | (stable_fall_stg3_cnt != 'd8)) stable_fall_eye_r <= #TCQ 1'b0; else if (stable_fall_stg3_cnt == 'd8) stable_fall_eye_r <= #TCQ 1'b1; end always @(posedge clk) if ((ocal_state_r == OCAL_STG3_SEL_WAIT) || (ocal_state_r == OCAL_STG3_EN_WAIT) || (ocal_state_r == OCAL_STG3_WAIT) || (ocal_state_r == OCAL_STG3_INC_WAIT) || (ocal_state_r == OCAL_STG3_DEC_WAIT) || (ocal_state_r == OCAL_STG2_WAIT) || (ocal_state_r == OCAL_STG2_DEC_WAIT) || (ocal_state_r == OCAL_INC_DONE_WAIT) || (ocal_state_r == OCAL_DEC_DONE_WAIT)) wait_cnt_en_r <= #TCQ 1'b1; else wait_cnt_en_r <= #TCQ 1'b0; always @(posedge clk) if (!wait_cnt_en_r) begin wait_cnt_r <= #TCQ 'b0; cnt_next_state <= #TCQ 1'b0; end else begin if (wait_cnt_r != WAIT_CNT - 1) begin wait_cnt_r <= #TCQ wait_cnt_r + 1; cnt_next_state <= #TCQ 1'b0; end else begin // Need to reset to 0 to handle the case when there are two // different WAIT states back-to-back wait_cnt_r <= #TCQ 'b0; cnt_next_state <= #TCQ 1'b1; end end always @(posedge clk) begin if (rst) begin for (i=0; i < DQS_WIDTH; i = i + 1) begin: rst_ocal_tap_cnt ocal_tap_cnt_r[i] <= #TCQ 'b0; end end else if (stg3_dec_r && ~stg3_dec) ocal_tap_cnt_r[cnt_dqs_r][5:0] <= #TCQ stg3_tap_cnt; end always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEW_DQS_READ) || (ocal_state_r == OCAL_STG3_CALC) || (ocal_state_r == OCAL_DONE)) prech_done_r <= #TCQ 1'b0; else if (prech_done) prech_done_r <= #TCQ 1'b1; end // setting stg3_tap_cnt == oclkdelay_int_val always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEXT_DQS)) begin stg3_tap_cnt_eq_oclkdelay_init_val <= #TCQ 1'b1; end else begin if (ocal_state_r == OCAL_DONE) stg3_tap_cnt_eq_oclkdelay_init_val <= #TCQ 1'b0; else if (ocal_state_r == OCAL_STG3_DEC) stg3_tap_cnt_eq_oclkdelay_init_val <= #TCQ (stg3_tap_cnt == oclkdelay_init_val+1); else if (ocal_state_r == OCAL_STG3_INC) stg3_tap_cnt_eq_oclkdelay_init_val <= #TCQ (stg3_tap_cnt == oclkdelay_init_val-1); end // else: !if((rst || (ocal_state_r == OCAL_IDLE)) begin... end // always @ (posedge clk) // setting sg3_tap_cng > 20 // always @(posedge clk) begin // if ((rst)|| (ocal_state_r == OCAL_NEXT_DQS)) begin // stg3_tap_cnt_gt_20 <= #TCQ 1'b0; // end else begin // if (rst) // if (ocal_state_r == OCAL_STG3_DEC) // stg3_tap_cnt_gt_20 <= #TCQ (stg3_tap_cnt >= 'd22); // else if (ocal_state_r == OCAL_STG3_INC) // stg3_tap_cnt_gt_20 <= #TCQ (stg3_tap_cnt >= 'd20); // end // else: !if((rst || (ocal_state_r == OCAL_IDLE)) begin... // end // always @ (posedge clk) // setting sg3_tap_cnt == 0 always @(posedge clk) begin if ((rst)|| (ocal_state_r == OCAL_NEXT_DQS) || (ocal_state_r == OCAL_STG3_INC) ) begin stg3_tap_cnt_eq_0 <= #TCQ 1'b0; end else begin // if (rst) if (ocal_state_r == OCAL_STG3_DEC) stg3_tap_cnt_eq_0 <= #TCQ (stg3_tap_cnt == 'd1); end // else: !if((rst || (ocal_state_r == OCAL_IDLE)) begin... end // always @ (posedge clk) // setting sg3_tap_cnt == 63 always @(posedge clk) begin if ((rst)|| (ocal_state_r == OCAL_NEXT_DQS)) begin stg3_tap_cnt_eq_63 <= #TCQ 1'b0; end else begin // if (rst) if (ocal_state_r == OCAL_STG3_INC) stg3_tap_cnt_eq_63 <= #TCQ (stg3_tap_cnt >= 'd62); else if (ocal_state_r == OCAL_STG3_DEC) stg3_tap_cnt_eq_63 <= #TCQ 1'b0; end // else: !if((rst || (ocal_state_r == OCAL_IDLE)) begin... end // always @ (posedge clk) // setting sg3_tap_cnt < ocaldelay_init_val always @(posedge clk) begin if ((rst)|| (ocal_state_r == OCAL_NEXT_DQS)) begin stg3_tap_cnt_less_oclkdelay_init_val <= #TCQ 1'b0; end else begin // if (rst) if (ocal_state_r == OCAL_STG3_DEC) stg3_tap_cnt_less_oclkdelay_init_val <= #TCQ (stg3_tap_cnt <= oclkdelay_init_val); else if (ocal_state_r == OCAL_STG3_INC) stg3_tap_cnt_less_oclkdelay_init_val <= #TCQ (stg3_tap_cnt <= oclkdelay_init_val-2); end // else: !if((rst || (ocal_state_r == OCAL_IDLE)) begin... end // always @ (posedge clk) // setting stg3_incdec_limit == 15 always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEXT_DQS) || (ocal_state_r == OCAL_DONE)) begin stg3_limit <= #TCQ 1'b0; end else if ((ocal_state_r == OCAL_STG3_WAIT) || (ocal_state_r == OCAL_STG2_WAIT)) begin stg3_limit <= #TCQ (stg3_incdec_limit == 'd14); end end // Registers feeding into the ocal_final_cnt_r computation // Equation is in the form of ((A-B)/2) + C + D where the values taken are // A = ocal_fall_edge_taps, ocal_rise_right_edge, stg3_tap_cnt or ocal_fall_edge2_taps // B = ocal_fall_edge1_taps, ocal_rise_edge1_taps or '0' // C = (stg3_tap_cnt - ocal_rise_right_edge), '0' or '1' // D = '32' or '0' always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEXT_DQS) || (ocal_state_r == OCAL_DONE)) ocal_final_cnt_r_mux_a <= #TCQ 'd0; else if (|ocal_rise_right_edge) begin if (ocal_fall_edge2_found && ocal_fall_edge1_found) ocal_final_cnt_r_mux_a <= #TCQ ocal_fall_edge2_taps; else ocal_final_cnt_r_mux_a <= #TCQ ocal_rise_right_edge; end else if (ocal_rise_edge2_found) ocal_final_cnt_r_mux_a <= #TCQ ocal_rise_edge2_taps; else if (~ocal_rise_edge2_found && ocal_rise_edge1_found) ocal_final_cnt_r_mux_a <= #TCQ stg3_tap_cnt; else if (ocal_fall_edge2_found && ocal_fall_edge1_found) ocal_final_cnt_r_mux_a <= #TCQ ocal_fall_edge2_taps; end always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEXT_DQS) || (ocal_state_r == OCAL_DONE)) ocal_final_cnt_r_mux_b <= #TCQ 'd0; else if (|ocal_rise_right_edge) begin if (ocal_fall_edge2_found && ocal_fall_edge1_found) ocal_final_cnt_r_mux_b <= #TCQ ocal_fall_edge1_taps; else ocal_final_cnt_r_mux_b <= #TCQ ocal_rise_edge1_taps; end else if (ocal_rise_edge2_found && ocal_rise_edge1_found) ocal_final_cnt_r_mux_b <= #TCQ ocal_rise_edge1_taps; else if (ocal_rise_edge2_found && ~ocal_rise_edge1_found) ocal_final_cnt_r_mux_b <= #TCQ 'd0; else if (~ocal_rise_edge2_found && ocal_rise_edge1_found) ocal_final_cnt_r_mux_b <= #TCQ ocal_rise_edge1_taps; else if (ocal_fall_edge2_found && ocal_fall_edge1_found) ocal_final_cnt_r_mux_b <= #TCQ ocal_fall_edge1_taps; end always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEXT_DQS) || (ocal_state_r == OCAL_DONE)) ocal_final_cnt_r_mux_c <= #TCQ 'd0; else if (|ocal_rise_right_edge) begin if (ocal_fall_edge2_found && ocal_fall_edge1_found) ocal_final_cnt_r_mux_c <= #TCQ 'd1; else ocal_final_cnt_r_mux_c <= #TCQ (stg3_tap_cnt - ocal_rise_right_edge); end else if (~ocal_rise_edge2_found && ocal_rise_edge1_found) ocal_final_cnt_r_mux_c <= #TCQ 'd0; else ocal_final_cnt_r_mux_c <= #TCQ 'd1; end always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEXT_DQS) || (ocal_state_r == OCAL_DONE)) ocal_final_cnt_r_mux_d <= #TCQ 'd0; else if (((|ocal_rise_right_edge) && (ocal_fall_edge2_found && ocal_fall_edge1_found)) || (ocal_fall_edge2_found && ocal_fall_edge1_found)) ocal_final_cnt_r_mux_d <= #TCQ 'd32; else ocal_final_cnt_r_mux_d <= #TCQ 'd0; end always @(posedge clk) begin if (rst || (ocal_state_r == OCAL_NEXT_DQS) || (ocal_state_r == OCAL_DONE)) ocal_final_cnt_r <= #TCQ 'd0; else if (ocal_state_r == OCAL_STG3_CALC) ocal_final_cnt_r <= #TCQ ((ocal_final_cnt_r_mux_a - ocal_final_cnt_r_mux_b)>>1) + ocal_final_cnt_r_mux_c + ocal_final_cnt_r_mux_d; end genvar dqs_q; generate for (dqs_q=0; dqs_q < DQS_WIDTH; dqs_q = dqs_q + 1) begin: tap_cnt_split assign wl_po_fine_cnt_w[dqs_q] = wl_po_fine_cnt[6*dqs_q+:6]; end endgenerate // State Machine always @(posedge clk) begin if (rst) begin ocal_state_r <= #TCQ OCAL_IDLE; cnt_dqs_r <= #TCQ 'd0; stg3_tap_cnt <= #TCQ oclkdelay_init_val; stg3_incdec_limit <= #TCQ 'd0; stg3_dec2inc <= #TCQ 1'b0; stg2_tap_cnt <= #TCQ 'd0; stg2_inc2_cnt <= #TCQ 2'b00; stg2_dec2_cnt <= #TCQ 2'b00; stg2_dec_cnt <= #TCQ 'd0; stg3_dec <= #TCQ 1'b0; wrlvl_final <= #TCQ 1'b0; oclk_calib_resume <= #TCQ 1'b0; oclk_prech_req <= #TCQ 1'b0; ocal_inc_cnt <= #TCQ 'd0; ocal_dec_cnt <= #TCQ 'd0; ocal_stg3_inc_en <= #TCQ 1'b0; ocal_rise_edge1_found <= #TCQ 1'b0; ocal_rise_edge2_found <= #TCQ 1'b0; ocal_rise_edge1_found_timing <= #TCQ 1'b0; ocal_rise_edge2_found_timing <= #TCQ 1'b0; ocal_rise_right_edge <= #TCQ 'd0; ocal_rise_edge1_taps <= #TCQ 'd0; ocal_rise_edge2_taps <= #TCQ 'd0; ocal_fall_edge1_found <= #TCQ 1'b0; ocal_fall_edge2_found <= #TCQ 1'b0; ocal_fall_edge1_taps <= #TCQ 'd0; ocal_fall_edge2_taps <= #TCQ 'd0; ocal_byte_done <= #TCQ 1'b0; ocal_wrlvl_done <= #TCQ 1'b0; ocal_done_r <= #TCQ 1'b0; po_stg23_sel <= #TCQ 1'b0; po_en_stg23 <= #TCQ 1'b0; po_stg23_incdec <= #TCQ 1'b0; ocal_final_cnt_r_calc <= #TCQ 1'b0; end else begin case (ocal_state_r) OCAL_IDLE: begin if (oclkdelay_calib_start && ~oclkdelay_calib_start_r) begin ocal_state_r <= #TCQ OCAL_NEW_DQS_WAIT; stg3_tap_cnt <= #TCQ oclkdelay_init_val; stg2_tap_cnt <= #TCQ wl_po_fine_cnt_w[cnt_dqs_r]; end end OCAL_NEW_DQS_READ: begin oclk_prech_req <= #TCQ 1'b0; oclk_calib_resume <= #TCQ 1'b0; if (pat_data_match_valid_r) ocal_state_r <= #TCQ OCAL_NEW_DQS_WAIT; end OCAL_NEW_DQS_WAIT: begin oclk_calib_resume <= #TCQ 1'b0; oclk_prech_req <= #TCQ 1'b0; po_en_stg23 <= #TCQ 1'b0; po_stg23_incdec <= #TCQ 1'b0; if (pat_data_match_valid_r && !stg3_tap_cnt_eq_oclkdelay_init_val) begin if ((stg3_limit && ~ocal_stg3_inc_en) || stg3_tap_cnt == 'd0) begin // No write levling performed to avoid stage 2 coarse dec. // Therefore stage 3 taps can only be decremented by an // additional 15 taps after stage 2 taps reach 63. ocal_state_r <= #TCQ OCAL_STG3_SEL; ocal_stg3_inc_en <= #TCQ 1'b1; stg3_incdec_limit <= #TCQ 'd0; // An edge was detected end else if (~pat_data_match_r) begin // Sticky bit - asserted after we encounter an edge, although // the current edge may not be considered the "first edge" this // just means we found at least one edge if (~ocal_stg3_inc_en) begin if (|stable_fall_stg3_cnt && ~ocal_fall_edge1_found) begin ocal_fall_edge1_found <= #TCQ 1'b1; ocal_fall_edge1_taps <= #TCQ stg3_tap_cnt + 1; end else begin ocal_rise_edge1_found <= #TCQ 1'b1; ocal_rise_edge1_found_timing <= #TCQ 1'b1; end end // Sarting point was in the jitter region close to the right edge if (~stable_rise_eye_r && ~ocal_stg3_inc_en) begin ocal_rise_right_edge <= #TCQ stg3_tap_cnt; ocal_state_r <= #TCQ OCAL_STG3_SEL; // Starting point was in the valid window close to the right edge // Or away from the right edge hence no stable_eye_r condition // Or starting point was in the right jitter region and ocal_rise_right_edge // is detected end else if (ocal_stg3_inc_en) begin // Both edges found if (stable_fall_eye_r) begin ocal_state_r <= #TCQ OCAL_STG3_CALC; ocal_fall_edge2_found <= #TCQ 1'b1; ocal_fall_edge2_taps <= #TCQ stg3_tap_cnt - 1; end else begin ocal_state_r <= #TCQ OCAL_STG3_CALC; ocal_rise_edge2_found <= #TCQ 1'b1; ocal_rise_edge2_found_timing <= #TCQ 1'b1; ocal_rise_edge2_taps <= #TCQ stg3_tap_cnt - 1; end // Starting point in the valid window away from left edge // Assuming starting point will not be in valid window close to // left edge end else if (stable_rise_eye_r) begin ocal_rise_edge1_taps <= #TCQ stg3_tap_cnt + 1; ocal_state_r <= #TCQ OCAL_STG3_SEL; ocal_stg3_inc_en <= #TCQ 1'b1; stg3_incdec_limit <= #TCQ 'd0; end else ocal_state_r <= #TCQ OCAL_STG3_SEL; end else ocal_state_r <= #TCQ OCAL_STG3_SEL; end else if (stg3_tap_cnt_eq_oclkdelay_init_val) ocal_state_r <= #TCQ OCAL_STG3_SEL; else if ((stg3_limit && ocal_stg3_inc_en) || (stg3_tap_cnt_eq_63)) begin ocal_state_r <= #TCQ OCAL_STG3_CALC; stg3_incdec_limit <= #TCQ 'd0; end end OCAL_STG3_SEL: begin po_stg23_sel <= #TCQ 1'b1; ocal_wrlvl_done <= #TCQ 1'b0; ocal_state_r <= #TCQ OCAL_STG3_SEL_WAIT; ocal_final_cnt_r_calc <= #TCQ 1'b0; end OCAL_STG3_SEL_WAIT: begin if (cnt_next_state) begin ocal_state_r <= #TCQ OCAL_STG3_EN_WAIT; if (ocal_stg3_inc_en) begin po_stg23_incdec <= #TCQ 1'b1; if (stg3_tap_cnt_less_oclkdelay_init_val) begin ocal_inc_cnt <= #TCQ oclkdelay_init_val - stg3_tap_cnt; stg3_dec2inc <= #TCQ 1'b1; oclk_prech_req <= #TCQ 1'b1; end end else begin po_stg23_incdec <= #TCQ 1'b0; if (stg3_dec) ocal_dec_cnt <= #TCQ ocal_final_cnt_r; end end end OCAL_STG3_EN_WAIT: begin if (cnt_next_state) begin if (ocal_stg3_inc_en) ocal_state_r <= #TCQ OCAL_STG3_INC; else ocal_state_r <= #TCQ OCAL_STG3_DEC; end end OCAL_STG3_DEC: begin po_en_stg23 <= #TCQ 1'b1; stg3_tap_cnt <= #TCQ stg3_tap_cnt - 1; if (ocal_dec_cnt == 1) begin ocal_byte_done <= #TCQ 1'b1; ocal_state_r <= #TCQ OCAL_DEC_DONE_WAIT; ocal_dec_cnt <= #TCQ ocal_dec_cnt - 1; end else if (ocal_dec_cnt > 'd0) begin ocal_state_r <= #TCQ OCAL_STG3_DEC_WAIT; ocal_dec_cnt <= #TCQ ocal_dec_cnt - 1; end else ocal_state_r <= #TCQ OCAL_STG3_WAIT; end OCAL_STG3_DEC_WAIT: begin po_en_stg23 <= #TCQ 1'b0; if (cnt_next_state) begin if (ocal_dec_cnt > 'd0) ocal_state_r <= #TCQ OCAL_STG3_DEC; else ocal_state_r <= #TCQ OCAL_DEC_DONE_WAIT; end end OCAL_DEC_DONE_WAIT: begin // Required to make sure that po_stg23_incdec // de-asserts some time after de-assertion of // po_en_stg23 po_en_stg23 <= #TCQ 1'b0; if (cnt_next_state) begin // Final stage 3 decrement completed, proceed // to stage 2 tap decrement ocal_state_r <= #TCQ OCAL_STG2_SEL; po_stg23_incdec <= #TCQ 1'b0; stg3_dec <= #TCQ 1'b0; end end OCAL_STG3_WAIT: begin po_en_stg23 <= #TCQ 1'b0; if (cnt_next_state) begin po_stg23_incdec <= #TCQ 1'b0; if ((stg2_tap_cnt != 6'd63) || (stg2_tap_cnt != 6'd0)) ocal_state_r <= #TCQ OCAL_STG2_SEL; else begin oclk_calib_resume <= #TCQ 1'b1; ocal_state_r <= #TCQ OCAL_NEW_DQS_WAIT; stg3_incdec_limit <= #TCQ stg3_incdec_limit + 1; end end end OCAL_STG2_SEL: begin po_stg23_sel <= #TCQ 1'b0; po_en_stg23 <= #TCQ 1'b0; po_stg23_incdec <= #TCQ 1'b0; ocal_state_r <= #TCQ OCAL_STG2_WAIT; stg2_inc2_cnt <= #TCQ 2'b01; stg2_dec2_cnt <= #TCQ 2'b01; end OCAL_STG2_WAIT: begin po_en_stg23 <= #TCQ 1'b0; po_stg23_incdec <= #TCQ 1'b0; if (cnt_next_state) begin if (ocal_byte_done) begin if (stg2_tap_cnt > 'd0) begin // Decrement stage 2 taps to '0' before // final write level is performed ocal_state_r <= #TCQ OCAL_STG2_DEC; stg2_dec_cnt <= #TCQ stg2_tap_cnt; end else begin ocal_state_r <= #TCQ OCAL_NEXT_DQS; ocal_byte_done <= #TCQ 1'b0; end end else if (stg3_dec2inc && (stg2_tap_cnt > 'd0)) begin // Decrement stage 2 tap to initial value before // edge 2 detection begins ocal_state_r <= #TCQ OCAL_STG2_DEC; stg2_dec_cnt <= #TCQ stg2_tap_cnt - wl_po_fine_cnt_w[cnt_dqs_r]; end else if (~ocal_stg3_inc_en && (stg2_tap_cnt < 6'd63)) begin // Increment stage 2 taps by 2 for every stage 3 tap decrement // as part of edge 1 detection to avoid tDQSS violation between // write DQS and CK ocal_state_r <= #TCQ OCAL_STG2_INC; end else if (ocal_stg3_inc_en && (stg2_tap_cnt > 6'd0)) begin // Decrement stage 2 taps by 2 for every stage 3 tap increment // as part of edge 2 detection to avoid tDQSS violation between // write DQS and CK ocal_state_r <= #TCQ OCAL_STG2_DEC; end else begin oclk_calib_resume <= #TCQ 1'b1; ocal_state_r <= #TCQ OCAL_NEW_DQS_WAIT; stg3_incdec_limit <= #TCQ stg3_incdec_limit + 1; end end end OCAL_STG2_INC: begin po_en_stg23 <= #TCQ 1'b1; po_stg23_incdec <= #TCQ 1'b1; stg2_tap_cnt <= #TCQ stg2_tap_cnt + 1; if (stg2_inc2_cnt > 2'b00) begin stg2_inc2_cnt <= stg2_inc2_cnt - 1; ocal_state_r <= #TCQ OCAL_STG2_WAIT; end else if (stg2_tap_cnt == 6'd62) begin ocal_state_r <= #TCQ OCAL_STG2_WAIT; end else begin oclk_calib_resume <= #TCQ 1'b1; ocal_state_r <= #TCQ OCAL_NEW_DQS_WAIT; end end OCAL_STG2_DEC: begin po_en_stg23 <= #TCQ 1'b1; po_stg23_incdec <= #TCQ 1'b0; stg2_tap_cnt <= #TCQ stg2_tap_cnt - 1; if (stg2_dec_cnt > 6'd0) begin stg2_dec_cnt <= #TCQ stg2_dec_cnt - 1; ocal_state_r <= #TCQ OCAL_STG2_DEC_WAIT; end else if (stg2_dec2_cnt > 2'b00) begin stg2_dec2_cnt <= stg2_dec2_cnt - 1; ocal_state_r <= #TCQ OCAL_STG2_WAIT; end else if (stg2_tap_cnt == 6'd1) ocal_state_r <= #TCQ OCAL_STG2_WAIT; else begin oclk_calib_resume <= #TCQ 1'b1; ocal_state_r <= #TCQ OCAL_NEW_DQS_WAIT; end end OCAL_STG2_DEC_WAIT: begin po_en_stg23 <= #TCQ 1'b0; po_stg23_incdec <= #TCQ 1'b0; if (cnt_next_state) begin if (stg2_dec_cnt > 6'd0) begin ocal_state_r <= #TCQ OCAL_STG2_DEC; end else if (ocal_byte_done) begin ocal_state_r <= #TCQ OCAL_NEXT_DQS; ocal_byte_done <= #TCQ 1'b0; end else if (prech_done_r && stg3_dec2inc) begin stg3_dec2inc <= #TCQ 1'b0; if (stg3_tap_cnt_eq_63) ocal_state_r <= #TCQ OCAL_STG3_CALC; else begin ocal_state_r <= #TCQ OCAL_NEW_DQS_READ; oclk_calib_resume <= #TCQ 1'b1; end end end end OCAL_STG3_CALC: begin if (ocal_final_cnt_r_calc) begin ocal_state_r <= #TCQ OCAL_STG3_SEL; stg3_dec <= #TCQ 1'b1; ocal_stg3_inc_en <= #TCQ 1'b0; end else ocal_final_cnt_r_calc <= #TCQ 1'b1; end OCAL_STG3_INC: begin po_en_stg23 <= #TCQ 1'b1; stg3_tap_cnt <= #TCQ stg3_tap_cnt + 1; if (ocal_inc_cnt > 'd0) ocal_inc_cnt <= #TCQ ocal_inc_cnt - 1; if (ocal_inc_cnt == 1) ocal_state_r <= #TCQ OCAL_INC_DONE_WAIT; else ocal_state_r <= #TCQ OCAL_STG3_INC_WAIT; end OCAL_STG3_INC_WAIT: begin po_en_stg23 <= #TCQ 1'b0; po_stg23_incdec <= #TCQ 1'b1; if (cnt_next_state) begin if (ocal_inc_cnt > 'd0) ocal_state_r <= #TCQ OCAL_STG3_INC; else begin ocal_state_r <= #TCQ OCAL_STG2_SEL; po_stg23_incdec <= #TCQ 1'b0; end end end OCAL_INC_DONE_WAIT: begin // Required to make sure that po_stg23_incdec // de-asserts some time after de-assertion of // po_en_stg23 po_en_stg23 <= #TCQ 1'b0; oclk_prech_req <= #TCQ 1'b0; if (cnt_next_state) begin ocal_state_r <= #TCQ OCAL_STG2_SEL; po_stg23_incdec <= #TCQ 1'b0; end end OCAL_NEXT_DQS: begin ocal_final_cnt_r_calc <= #TCQ 1'b0; po_en_stg23 <= #TCQ 1'b0; po_stg23_incdec <= #TCQ 1'b0; stg3_tap_cnt <= #TCQ 6'd0; ocal_rise_edge1_found <= #TCQ 1'b0; ocal_rise_edge2_found <= #TCQ 1'b0; ocal_rise_edge1_found_timing <= #TCQ 1'b0; ocal_rise_edge2_found_timing <= #TCQ 1'b0; ocal_rise_edge1_taps <= #TCQ 'd0; ocal_rise_edge2_taps <= #TCQ 'd0; ocal_rise_right_edge <= #TCQ 'd0; ocal_fall_edge1_found <= #TCQ 1'b0; ocal_fall_edge2_found <= #TCQ 1'b0; ocal_fall_edge1_taps <= #TCQ 'd0; ocal_fall_edge2_taps <= #TCQ 'd0; stg3_incdec_limit <= #TCQ 'd0; oclk_prech_req <= #TCQ 1'b1; if (cnt_dqs_r == DQS_WIDTH-1) wrlvl_final <= #TCQ 1'b1; if (prech_done) begin if (cnt_dqs_r == DQS_WIDTH-1) // If the last DQS group was just finished, // then end of calibration ocal_state_r <= #TCQ OCAL_DONE; else begin // Continue to next DQS group cnt_dqs_r <= #TCQ cnt_dqs_r + 1; ocal_state_r <= #TCQ OCAL_NEW_DQS_READ; stg3_tap_cnt <= #TCQ oclkdelay_init_val; stg2_tap_cnt <= #TCQ wl_po_fine_cnt_w[cnt_dqs_r + 1'b1]; end end end OCAL_DONE: begin ocal_final_cnt_r_calc <= #TCQ 1'b0; oclk_prech_req <= #TCQ 1'b0; po_stg23_sel <= #TCQ 1'b0; ocal_done_r <= #TCQ 1'b1; end endcase end end endmodule
(** * Smallstep: Small-step Operational Semantics *) Require Export Imp. (** The evaluators we have seen so far (e.g., the ones for [aexp]s, [bexp]s, and commands) have been formulated in a "big-step" style -- they specify how a given expression can be evaluated to its final value (or a command plus a store to a final store) "all in one big step." This style is simple and natural for many purposes -- indeed, Gilles Kahn, who popularized its use, called it _natural semantics_. But there are some things it does not do well. In particular, it does not give us a natural way of talking about _concurrent_ programming languages, where the "semantics" of a program -- i.e., the essence of how it behaves -- is not just which input states get mapped to which output states, but also includes the intermediate states that it passes through along the way, since these states can also be observed by concurrently executing code. Another shortcoming of the big-step style is more technical, but critical in some situations. To see the issue, suppose we wanted to define a variant of Imp where variables could hold _either_ numbers _or_ lists of numbers (see the [HoareList] chapter for details). In the syntax of this extended language, it will be possible to write strange expressions like [2 + nil], and our semantics for arithmetic expressions will then need to say something about how such expressions behave. One possibility (explored in the [HoareList] chapter) is to maintain the convention that every arithmetic expressions evaluates to some number by choosing some way of viewing a list as a number -- e.g., by specifying that a list should be interpreted as [0] when it occurs in a context expecting a number. But this is really a bit of a hack. A much more natural approach is simply to say that the behavior of an expression like [2+nil] is _undefined_ -- it doesn't evaluate to any result at all. And we can easily do this: we just have to formulate [aeval] and [beval] as [Inductive] propositions rather than Fixpoints, so that we can make them partial functions instead of total ones. However, now we encounter a serious deficiency. In this language, a command might _fail_ to map a given starting state to any ending state for two quite different reasons: either because the execution gets into an infinite loop or because, at some point, the program tries to do an operation that makes no sense, such as adding a number to a list, and none of the evaluation rules can be applied. These two outcomes -- nontermination vs. getting stuck in an erroneous configuration -- are quite different. In particular, we want to allow the first (permitting the possibility of infinite loops is the price we pay for the convenience of programming with general looping constructs like [while]) but prevent the second (which is just wrong), for example by adding some form of _typechecking_ to the language. Indeed, this will be a major topic for the rest of the course. As a first step, we need a different way of presenting the semantics that allows us to distinguish nontermination from erroneous "stuck states." So, for lots of reasons, we'd like to have a finer-grained way of defining and reasoning about program behaviors. This is the topic of the present chapter. We replace the "big-step" [eval] relation with a "small-step" relation that specifies, for a given program, how the "atomic steps" of computation are performed. *) (* ########################################################### *) (** * A Toy Language *) (** To save space in the discussion, let's go back to an incredibly simple language containing just constants and addition. (We use single letters -- [C] and [P] -- for the constructor names, for brevity.) At the end of the chapter, we'll see how to apply the same techniques to the full Imp language. *) Inductive tm : Type := | C : nat -> tm (* Constant *) | P : tm -> tm -> tm. (* Plus *) Tactic Notation "tm_cases" tactic(first) ident(c) := first; [ Case_aux c "C" | Case_aux c "P" ]. (** Here is a standard evaluator for this language, written in the same (big-step) style as we've been using up to this point. *) Fixpoint evalF (t : tm) : nat := match t with | C n => n | P a1 a2 => evalF a1 + evalF a2 end. (** Now, here is the same evaluator, written in exactly the same style, but formulated as an inductively defined relation. Again, we use the notation [t || n] for "[t] evaluates to [n]." *) (** -------- (E_Const) C n || n t1 || n1 t2 || n2 ---------------------- (E_Plus) P t1 t2 || C (n1 + n2) *) Reserved Notation " t '||' n " (at level 50, left associativity). Inductive eval : tm -> nat -> Prop := | E_Const : forall n, C n || n | E_Plus : forall t1 t2 n1 n2, t1 || n1 -> t2 || n2 -> P t1 t2 || (n1 + n2) where " t '||' n " := (eval t n). Tactic Notation "eval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Const" | Case_aux c "E_Plus" ]. Module SimpleArith1. (** Now, here is a small-step version. *) (** ------------------------------- (ST_PlusConstConst) P (C n1) (C n2) ==> C (n1 + n2) t1 ==> t1' -------------------- (ST_Plus1) P t1 t2 ==> P t1' t2 t2 ==> t2' --------------------------- (ST_Plus2) P (C n1) t2 ==> P (C n1) t2' *) Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_PlusConstConst : forall n1 n2, P (C n1) (C n2) ==> C (n1 + n2) | ST_Plus1 : forall t1 t1' t2, t1 ==> t1' -> P t1 t2 ==> P t1' t2 | ST_Plus2 : forall n1 t2 t2', t2 ==> t2' -> P (C n1) t2 ==> P (C n1) t2' where " t '==>' t' " := (step t t'). Tactic Notation "step_cases" tactic(first) ident(c) := first; [ Case_aux c "ST_PlusConstConst" | Case_aux c "ST_Plus1" | Case_aux c "ST_Plus2" ]. (** Things to notice: - We are defining just a single reduction step, in which one [P] node is replaced by its value. - Each step finds the _leftmost_ [P] node that is ready to go (both of its operands are constants) and rewrites it in place. The first rule tells how to rewrite this [P] node itself; the other two rules tell how to find it. - A term that is just a constant cannot take a step. *) (** Let's pause and check a couple of examples of reasoning with the [step] relation... *) (** If [t1] can take a step to [t1'], then [P t1 t2] steps to [P t1' t2]: *) Example test_step_1 : P (P (C 0) (C 3)) (P (C 2) (C 4)) ==> P (C (0 + 3)) (P (C 2) (C 4)). Proof. apply ST_Plus1. apply ST_PlusConstConst. Qed. (** **** Exercise: 1 star (test_step_2) *) (** Right-hand sides of sums can take a step only when the left-hand side is finished: if [t2] can take a step to [t2'], then [P (C n) t2] steps to [P (C n) t2']: *) Example test_step_2 : P (C 0) (P (C 2) (P (C 0) (C 3))) ==> P (C 0) (P (C 2) (C (0 + 3))). Proof. (* FILL IN HERE *) Admitted. (** [] *) (* ########################################################### *) (** * Relations *) (** We will be using several different step relations, so it is helpful to generalize a bit and state a few definitions and theorems about relations in general. (The optional chapter [Rel.v] develops some of these ideas in a bit more detail; it may be useful if the treatment here is too dense.) *) (** A (binary) _relation_ on a set [X] is a family of propositions parameterized by two elements of [X] -- i.e., a proposition about pairs of elements of [X]. *) Definition relation (X: Type) := X->X->Prop. (** Our main examples of such relations in this chapter will be the single-step and multi-step reduction relations on terms, [==>] and [==>*], but there are many other examples -- some that come to mind are the "equals," "less than," "less than or equal to," and "is the square of" relations on numbers, and the "prefix of" relation on lists and strings. *) (** One simple property of the [==>] relation is that, like the evaluation relation for our language of Imp programs, it is _deterministic_. _Theorem_: For each [t], there is at most one [t'] such that [t] steps to [t'] ([t ==> t'] is provable). Formally, this is the same as saying that [==>] is deterministic. *) (** _Proof sketch_: We show that if [x] steps to both [y1] and [y2] then [y1] and [y2] are equal, by induction on a derivation of [step x y1]. There are several cases to consider, depending on the last rule used in this derivation and in the given derivation of [step x y2]. - If both are [ST_PlusConstConst], the result is immediate. - The cases when both derivations end with [ST_Plus1] or [ST_Plus2] follow by the induction hypothesis. - It cannot happen that one is [ST_PlusConstConst] and the other is [ST_Plus1] or [ST_Plus2], since this would imply that [x] has the form [P t1 t2] where both [t1] and [t2] are constants (by [ST_PlusConstConst]) _and_ one of [t1] or [t2] has the form [P ...]. - Similarly, it cannot happen that one is [ST_Plus1] and the other is [ST_Plus2], since this would imply that [x] has the form [P t1 t2] where [t1] has both the form [P t1 t2] and the form [C n]. [] *) Definition deterministic {X: Type} (R: relation X) := forall x y1 y2 : X, R x y1 -> R x y2 -> y1 = y2. Theorem step_deterministic: deterministic step. Proof. unfold deterministic. intros x y1 y2 Hy1 Hy2. generalize dependent y2. step_cases (induction Hy1) Case; intros y2 Hy2. Case "ST_PlusConstConst". step_cases (inversion Hy2) SCase. SCase "ST_PlusConstConst". reflexivity. SCase "ST_Plus1". inversion H2. SCase "ST_Plus2". inversion H2. Case "ST_Plus1". step_cases (inversion Hy2) SCase. SCase "ST_PlusConstConst". rewrite <- H0 in Hy1. inversion Hy1. SCase "ST_Plus1". rewrite <- (IHHy1 t1'0). reflexivity. assumption. SCase "ST_Plus2". rewrite <- H in Hy1. inversion Hy1. Case "ST_Plus2". step_cases (inversion Hy2) SCase. SCase "ST_PlusConstConst". rewrite <- H1 in Hy1. inversion Hy1. SCase "ST_Plus1". inversion H2. SCase "ST_Plus2". rewrite <- (IHHy1 t2'0). reflexivity. assumption. Qed. (** There is some annoying repetition in this proof. Each use of [inversion Hy2] results in three subcases, only one of which is relevant (the one which matches the current case in the induction on [Hy1]). The other two subcases need to be dismissed by finding the contradiction among the hypotheses and doing inversion on it. There is a tactic called [solve by inversion] defined in [SfLib.v] that can be of use in such cases. It will solve the goal if it can be solved by inverting some hypothesis; otherwise, it fails. (There are variants [solve by inversion 2] and [solve by inversion 3] that work if two or three consecutive inversions will solve the goal.) The example below shows how a proof of the previous theorem can be simplified using this tactic. *) Theorem step_deterministic_alt: deterministic step. Proof. intros x y1 y2 Hy1 Hy2. generalize dependent y2. step_cases (induction Hy1) Case; intros y2 Hy2; inversion Hy2; subst; try (solve by inversion). Case "ST_PlusConstConst". reflexivity. Case "ST_Plus1". apply IHHy1 in H2. rewrite H2. reflexivity. Case "ST_Plus2". apply IHHy1 in H2. rewrite H2. reflexivity. Qed. End SimpleArith1. (* ########################################################### *) (** ** Values *) (** Let's take a moment to slightly generalize the way we state the definition of single-step reduction. *) (** It is useful to think of the [==>] relation as defining an _abstract machine_: - At any moment, the _state_ of the machine is a term. - A _step_ of the machine is an atomic unit of computation -- here, a single "add" operation. - The _halting states_ of the machine are ones where there is no more computation to be done. *) (** We can then execute a term [t] as follows: - Take [t] as the starting state of the machine. - Repeatedly use the [==>] relation to find a sequence of machine states, starting with [t], where each state steps to the next. - When no more reduction is possible, "read out" the final state of the machine as the result of execution. *) (** Intuitively, it is clear that the final states of the machine are always terms of the form [C n] for some [n]. We call such terms _values_. *) Inductive value : tm -> Prop := v_const : forall n, value (C n). (** Having introduced the idea of values, we can use it in the definition of the [==>] relation to write [ST_Plus2] rule in a slightly more elegant way: *) (** ------------------------------- (ST_PlusConstConst) P (C n1) (C n2) ==> C (n1 + n2) t1 ==> t1' -------------------- (ST_Plus1) P t1 t2 ==> P t1' t2 value v1 t2 ==> t2' -------------------- (ST_Plus2) P v1 t2 ==> P v1 t2' *) (** Again, the variable names here carry important information: by convention, [v1] ranges only over values, while [t1] and [t2] range over arbitrary terms. (Given this convention, the explicit [value] hypothesis is arguably redundant. We'll keep it for now, to maintain a close correspondence between the informal and Coq versions of the rules, but later on we'll drop it in informal rules, for the sake of brevity.) *) (** Here are the formal rules: *) Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_PlusConstConst : forall n1 n2, P (C n1) (C n2) ==> C (n1 + n2) | ST_Plus1 : forall t1 t1' t2, t1 ==> t1' -> P t1 t2 ==> P t1' t2 | ST_Plus2 : forall v1 t2 t2', value v1 -> (* <----- n.b. *) t2 ==> t2' -> P v1 t2 ==> P v1 t2' where " t '==>' t' " := (step t t'). Tactic Notation "step_cases" tactic(first) ident(c) := first; [ Case_aux c "ST_PlusConstConst" | Case_aux c "ST_Plus1" | Case_aux c "ST_Plus2" ]. (** **** Exercise: 3 stars (redo_determinism) *) (** As a sanity check on this change, let's re-verify determinism Proof sketch: We must show that if [x] steps to both [y1] and [y2] then [y1] and [y2] are equal. Consider the final rules used in the derivations of [step x y1] and [step x y2]. - If both are [ST_PlusConstConst], the result is immediate. - It cannot happen that one is [ST_PlusConstConst] and the other is [ST_Plus1] or [ST_Plus2], since this would imply that [x] has the form [P t1 t2] where both [t1] and [t2] are constants (by [ST_PlusConstConst]) AND one of [t1] or [t2] has the form [P ...]. - Similarly, it cannot happen that one is [ST_Plus1] and the other is [ST_Plus2], since this would imply that [x] has the form [P t1 t2] where [t1] both has the form [P t1 t2] and is a value (hence has the form [C n]). - The cases when both derivations end with [ST_Plus1] or [ST_Plus2] follow by the induction hypothesis. [] *) (** Most of this proof is the same as the one above. But to get maximum benefit from the exercise you should try to write it from scratch and just use the earlier one if you get stuck. *) Theorem step_deterministic : deterministic step. Proof. (* FILL IN HERE *) Admitted. (** [] *) (* ########################################################### *) (** ** Strong Progress and Normal Forms *) (** The definition of single-step reduction for our toy language is fairly simple, but for a larger language it would be pretty easy to forget one of the rules and create a situation where some term cannot take a step even though it has not been completely reduced to a value. The following theorem shows that we did not, in fact, make such a mistake here. *) (** _Theorem_ (_Strong Progress_): If [t] is a term, then either [t] is a value, or there exists a term [t'] such that [t ==> t']. *) (** _Proof_: By induction on [t]. - Suppose [t = C n]. Then [t] is a [value]. - Suppose [t = P t1 t2], where (by the IH) [t1] is either a value or can step to some [t1'], and where [t2] is either a value or can step to some [t2']. We must show [P t1 t2] is either a value or steps to some [t']. - If [t1] and [t2] are both values, then [t] can take a step, by [ST_PlusConstConst]. - If [t1] is a value and [t2] can take a step, then so can [t], by [ST_Plus2]. - If [t1] can take a step, then so can [t], by [ST_Plus1]. [] *) Theorem strong_progress : forall t, value t \/ (exists t', t ==> t'). Proof. tm_cases (induction t) Case. Case "C". left. apply v_const. Case "P". right. inversion IHt1. SCase "l". inversion IHt2. SSCase "l". inversion H. inversion H0. exists (C (n + n0)). apply ST_PlusConstConst. SSCase "r". inversion H0 as [t' H1]. exists (P t1 t'). apply ST_Plus2. apply H. apply H1. SCase "r". inversion H as [t' H0]. exists (P t' t2). apply ST_Plus1. apply H0. Qed. (** This important property is called _strong progress_, because every term either is a value or can "make progress" by stepping to some other term. (The qualifier "strong" distinguishes it from a more refined version that we'll see in later chapters, called simply "progress.") *) (** The idea of "making progress" can be extended to tell us something interesting about [value]s: in this language [value]s are exactly the terms that _cannot_ make progress in this sense. To state this observation formally, let's begin by giving a name to terms that cannot make progress. We'll call them _normal forms_. *) Definition normal_form {X:Type} (R:relation X) (t:X) : Prop := ~ exists t', R t t'. (** This definition actually specifies what it is to be a normal form for an _arbitrary_ relation [R] over an arbitrary set [X], not just for the particular single-step reduction relation over terms that we are interested in at the moment. We'll re-use the same terminology for talking about other relations later in the course. *) (** We can use this terminology to generalize the observation we made in the strong progress theorem: in this language, normal forms and values are actually the same thing. *) Lemma value_is_nf : forall v, value v -> normal_form step v. Proof. unfold normal_form. intros v H. inversion H. intros contra. inversion contra. inversion H1. Qed. Lemma nf_is_value : forall t, normal_form step t -> value t. Proof. (* a corollary of [strong_progress]... *) unfold normal_form. intros t H. assert (G : value t \/ exists t', t ==> t'). SCase "Proof of assertion". apply strong_progress. inversion G. SCase "l". apply H0. SCase "r". apply ex_falso_quodlibet. apply H. assumption. Qed. Corollary nf_same_as_value : forall t, normal_form step t <-> value t. Proof. split. apply nf_is_value. apply value_is_nf. Qed. (** Why is this interesting? Because [value] is a syntactic concept -- it is defined by looking at the form of a term -- while [normal_form] is a semantic one -- it is defined by looking at how the term steps. It is not obvious that these concepts should coincide! Indeed, we could easily have written the definitions so that they would not coincide... *) (* ##################################################### *) (** We might, for example, mistakenly define [value] so that it includes some terms that are not finished reducing. *) Module Temp1. (* Open an inner module so we can redefine value and step. *) Inductive value : tm -> Prop := | v_const : forall n, value (C n) | v_funny : forall t1 n2, (* <---- *) value (P t1 (C n2)). Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_PlusConstConst : forall n1 n2, P (C n1) (C n2) ==> C (n1 + n2) | ST_Plus1 : forall t1 t1' t2, t1 ==> t1' -> P t1 t2 ==> P t1' t2 | ST_Plus2 : forall v1 t2 t2', value v1 -> t2 ==> t2' -> P v1 t2 ==> P v1 t2' where " t '==>' t' " := (step t t'). (** **** Exercise: 3 stars, advanced (value_not_same_as_normal_form) *) Lemma value_not_same_as_normal_form : exists v, value v /\ ~ normal_form step v. Proof. (* FILL IN HERE *) Admitted. (** [] *) End Temp1. (* ##################################################### *) (** Alternatively, we might mistakenly define [step] so that it permits something designated as a value to reduce further. *) Module Temp2. Inductive value : tm -> Prop := | v_const : forall n, value (C n). Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_Funny : forall n, (* <---- *) C n ==> P (C n) (C 0) | ST_PlusConstConst : forall n1 n2, P (C n1) (C n2) ==> C (n1 + n2) | ST_Plus1 : forall t1 t1' t2, t1 ==> t1' -> P t1 t2 ==> P t1' t2 | ST_Plus2 : forall v1 t2 t2', value v1 -> t2 ==> t2' -> P v1 t2 ==> P v1 t2' where " t '==>' t' " := (step t t'). (** **** Exercise: 2 stars, advanced (value_not_same_as_normal_form) *) Lemma value_not_same_as_normal_form : exists v, value v /\ ~ normal_form step v. Proof. (* FILL IN HERE *) Admitted. (** [] *) End Temp2. (* ########################################################### *) (** Finally, we might define [value] and [step] so that there is some term that is not a value but that cannot take a step in the [step] relation. Such terms are said to be _stuck_. In this case this is caused by a mistake in the semantics, but we will also see situations where, even in a correct language definition, it makes sense to allow some terms to be stuck. *) Module Temp3. Inductive value : tm -> Prop := | v_const : forall n, value (C n). Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_PlusConstConst : forall n1 n2, P (C n1) (C n2) ==> C (n1 + n2) | ST_Plus1 : forall t1 t1' t2, t1 ==> t1' -> P t1 t2 ==> P t1' t2 where " t '==>' t' " := (step t t'). (** (Note that [ST_Plus2] is missing.) *) (** **** Exercise: 3 stars, advanced (value_not_same_as_normal_form') *) Lemma value_not_same_as_normal_form : exists t, ~ value t /\ normal_form step t. Proof. (* FILL IN HERE *) Admitted. (** [] *) End Temp3. (* ########################################################### *) (** *** Additional Exercises *) Module Temp4. (** Here is another very simple language whose terms, instead of being just plus and numbers, are just the booleans true and false and a conditional expression... *) Inductive tm : Type := | ttrue : tm | tfalse : tm | tif : tm -> tm -> tm -> tm. Inductive value : tm -> Prop := | v_true : value ttrue | v_false : value tfalse. Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_IfTrue : forall t1 t2, tif ttrue t1 t2 ==> t1 | ST_IfFalse : forall t1 t2, tif tfalse t1 t2 ==> t2 | ST_If : forall t1 t1' t2 t3, t1 ==> t1' -> tif t1 t2 t3 ==> tif t1' t2 t3 where " t '==>' t' " := (step t t'). (** **** Exercise: 1 star (smallstep_bools) *) (** Which of the following propositions are provable? (This is just a thought exercise, but for an extra challenge feel free to prove your answers in Coq.) *) Definition bool_step_prop1 := tfalse ==> tfalse. (* FILL IN HERE *) Definition bool_step_prop2 := tif ttrue (tif ttrue ttrue ttrue) (tif tfalse tfalse tfalse) ==> ttrue. (* FILL IN HERE *) Definition bool_step_prop3 := tif (tif ttrue ttrue ttrue) (tif ttrue ttrue ttrue) tfalse ==> tif ttrue (tif ttrue ttrue ttrue) tfalse. (* FILL IN HERE *) (** [] *) (** **** Exercise: 3 stars, optional (progress_bool) *) (** Just as we proved a progress theorem for plus expressions, we can do so for boolean expressions, as well. *) Theorem strong_progress : forall t, value t \/ (exists t', t ==> t'). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 2 stars, optional (step_deterministic) *) Theorem step_deterministic : deterministic step. Proof. (* FILL IN HERE *) Admitted. (** [] *) Module Temp5. (** **** Exercise: 2 stars (smallstep_bool_shortcut) *) (** Suppose we want to add a "short circuit" to the step relation for boolean expressions, so that it can recognize when the [then] and [else] branches of a conditional are the same value (either [ttrue] or [tfalse]) and reduce the whole conditional to this value in a single step, even if the guard has not yet been reduced to a value. For example, we would like this proposition to be provable: tif (tif ttrue ttrue ttrue) tfalse tfalse ==> tfalse. *) (** Write an extra clause for the step relation that achieves this effect and prove [bool_step_prop4]. *) Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_IfTrue : forall t1 t2, tif ttrue t1 t2 ==> t1 | ST_IfFalse : forall t1 t2, tif tfalse t1 t2 ==> t2 | ST_If : forall t1 t1' t2 t3, t1 ==> t1' -> tif t1 t2 t3 ==> tif t1' t2 t3 (* FILL IN HERE *) where " t '==>' t' " := (step t t'). Definition bool_step_prop4 := tif (tif ttrue ttrue ttrue) tfalse tfalse ==> tfalse. Example bool_step_prop4_holds : bool_step_prop4. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars, optional (properties_of_altered_step) *) (** It can be shown that the determinism and strong progress theorems for the step relation in the lecture notes also hold for the definition of step given above. After we add the clause [ST_ShortCircuit]... - Is the [step] relation still deterministic? Write yes or no and briefly (1 sentence) explain your answer. Optional: prove your answer correct in Coq. *) (* FILL IN HERE *) (** - Does a strong progress theorem hold? Write yes or no and briefly (1 sentence) explain your answer. Optional: prove your answer correct in Coq. *) (* FILL IN HERE *) (** - In general, is there any way we could cause strong progress to fail if we took away one or more constructors from the original step relation? Write yes or no and briefly (1 sentence) explain your answer. (* FILL IN HERE *) *) (** [] *) End Temp5. End Temp4. (* ########################################################### *) (** * Multi-Step Reduction *) (** Until now, we've been working with the _single-step reduction_ relation [==>], which formalizes the individual steps of an _abstract machine_ for executing programs. We can also use this machine to reduce programs to completion -- to find out what final result they yield. This can be formalized as follows: - First, we define a _multi-step reduction relation_ [==>*], which relates terms [t] and [t'] if [t] can reach [t'] by any number of single reduction steps (including zero steps!). - Then we define a "result" of a term [t] as a normal form that [t] can reach by multi-step reduction. *) (* ########################################################### *) (** Since we'll want to reuse the idea of multi-step reduction many times in this and future chapters, let's take a little extra trouble here and define it generically. Given a relation [R], we define a relation [multi R], called the _multi-step closure of [R]_ as follows: *) Inductive multi {X:Type} (R: relation X) : relation X := | multi_refl : forall (x : X), multi R x x | multi_step : forall (x y z : X), R x y -> multi R y z -> multi R x z. (** The effect of this definition is that [multi R] relates two elements [x] and [y] if either - [x = y], or else - there is some sequence [z1], [z2], ..., [zn] such that R x z1 R z1 z2 ... R zn y. Thus, if [R] describes a single-step of computation, [z1], ... [zn] is the sequence of intermediate steps of computation between [x] and [y]. *) Tactic Notation "multi_cases" tactic(first) ident(c) := first; [ Case_aux c "multi_refl" | Case_aux c "multi_step" ]. (** We write [==>*] for the [multi step] relation -- i.e., the relation that relates two terms [t] and [t'] if we can get from [t] to [t'] using the [step] relation zero or more times. *) Notation " t '==>*' t' " := (multi step t t') (at level 40). (** The relation [multi R] has several crucial properties. First, it is obviously _reflexive_ (that is, [forall x, multi R x x]). In the case of the [==>*] (i.e. [multi step]) relation, the intuition is that a term can execute to itself by taking zero steps of execution. Second, it contains [R] -- that is, single-step executions are a particular case of multi-step executions. (It is this fact that justifies the word "closure" in the term "multi-step closure of [R].") *) Theorem multi_R : forall (X:Type) (R:relation X) (x y : X), R x y -> (multi R) x y. Proof. intros X R x y H. apply multi_step with y. apply H. apply multi_refl. Qed. (** Third, [multi R] is _transitive_. *) Theorem multi_trans : forall (X:Type) (R: relation X) (x y z : X), multi R x y -> multi R y z -> multi R x z. Proof. intros X R x y z G H. multi_cases (induction G) Case. Case "multi_refl". assumption. Case "multi_step". apply multi_step with y. assumption. apply IHG. assumption. Qed. (** That is, if [t1==>*t2] and [t2==>*t3], then [t1==>*t3]. *) (* ########################################################### *) (** ** Examples *) Lemma test_multistep_1: P (P (C 0) (C 3)) (P (C 2) (C 4)) ==>* C ((0 + 3) + (2 + 4)). Proof. apply multi_step with (P (C (0 + 3)) (P (C 2) (C 4))). apply ST_Plus1. apply ST_PlusConstConst. apply multi_step with (P (C (0 + 3)) (C (2 + 4))). apply ST_Plus2. apply v_const. apply ST_PlusConstConst. apply multi_R. apply ST_PlusConstConst. Qed. (** Here's an alternate proof that uses [eapply] to avoid explicitly constructing all the intermediate terms. *) Lemma test_multistep_1': P (P (C 0) (C 3)) (P (C 2) (C 4)) ==>* C ((0 + 3) + (2 + 4)). Proof. eapply multi_step. apply ST_Plus1. apply ST_PlusConstConst. eapply multi_step. apply ST_Plus2. apply v_const. apply ST_PlusConstConst. eapply multi_step. apply ST_PlusConstConst. apply multi_refl. Qed. (** **** Exercise: 1 star, optional (test_multistep_2) *) Lemma test_multistep_2: C 3 ==>* C 3. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 1 star, optional (test_multistep_3) *) Lemma test_multistep_3: P (C 0) (C 3) ==>* P (C 0) (C 3). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 2 stars (test_multistep_4) *) Lemma test_multistep_4: P (C 0) (P (C 2) (P (C 0) (C 3))) ==>* P (C 0) (C (2 + (0 + 3))). Proof. (* FILL IN HERE *) Admitted. (** [] *) (* ########################################################### *) (** ** Normal Forms Again *) (** If [t] reduces to [t'] in zero or more steps and [t'] is a normal form, we say that "[t'] is a normal form of [t]." *) Definition step_normal_form := normal_form step. Definition normal_form_of (t t' : tm) := (t ==>* t' /\ step_normal_form t'). (** We have already seen that, for our language, single-step reduction is deterministic -- i.e., a given term can take a single step in at most one way. It follows from this that, if [t] can reach a normal form, then this normal form is unique. In other words, we can actually pronounce [normal_form t t'] as "[t'] is _the_ normal form of [t]." *) (** **** Exercise: 3 stars, optional (normal_forms_unique) *) Theorem normal_forms_unique: deterministic normal_form_of. Proof. unfold deterministic. unfold normal_form_of. intros x y1 y2 P1 P2. inversion P1 as [P11 P12]; clear P1. inversion P2 as [P21 P22]; clear P2. generalize dependent y2. (* We recommend using this initial setup as-is! *) (* FILL IN HERE *) Admitted. (** [] *) (** Indeed, something stronger is true for this language (though not for all languages): the reduction of _any_ term [t] will eventually reach a normal form -- i.e., [normal_form_of] is a _total_ function. Formally, we say the [step] relation is _normalizing_. *) Definition normalizing {X:Type} (R:relation X) := forall t, exists t', (multi R) t t' /\ normal_form R t'. (** To prove that [step] is normalizing, we need a couple of lemmas. First, we observe that, if [t] reduces to [t'] in many steps, then the same sequence of reduction steps within [t] is also possible when [t] appears as the left-hand child of a [P] node, and similarly when [t] appears as the right-hand child of a [P] node whose left-hand child is a value. *) Lemma multistep_congr_1 : forall t1 t1' t2, t1 ==>* t1' -> P t1 t2 ==>* P t1' t2. Proof. intros t1 t1' t2 H. multi_cases (induction H) Case. Case "multi_refl". apply multi_refl. Case "multi_step". apply multi_step with (P y t2). apply ST_Plus1. apply H. apply IHmulti. Qed. (** **** Exercise: 2 stars (multistep_congr_2) *) Lemma multistep_congr_2 : forall t1 t2 t2', value t1 -> t2 ==>* t2' -> P t1 t2 ==>* P t1 t2'. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** _Theorem_: The [step] function is normalizing -- i.e., for every [t] there exists some [t'] such that [t] steps to [t'] and [t'] is a normal form. _Proof sketch_: By induction on terms. There are two cases to consider: - [t = C n] for some [n]. Here [t] doesn't take a step, and we have [t' = t]. We can derive the left-hand side by reflexivity and the right-hand side by observing (a) that values are normal forms (by [nf_same_as_value]) and (b) that [t] is a value (by [v_const]). - [t = P t1 t2] for some [t1] and [t2]. By the IH, [t1] and [t2] have normal forms [t1'] and [t2']. Recall that normal forms are values (by [nf_same_as_value]); we know that [t1' = C n1] and [t2' = C n2], for some [n1] and [n2]. We can combine the [==>*] derivations for [t1] and [t2] to prove that [P t1 t2] reduces in many steps to [C (n1 + n2)]. It is clear that our choice of [t' = C (n1 + n2)] is a value, which is in turn a normal form. [] *) Theorem step_normalizing : normalizing step. Proof. unfold normalizing. tm_cases (induction t) Case. Case "C". exists (C n). split. SCase "l". apply multi_refl. SCase "r". (* We can use [rewrite] with "iff" statements, not just equalities: *) rewrite nf_same_as_value. apply v_const. Case "P". inversion IHt1 as [t1' H1]; clear IHt1. inversion IHt2 as [t2' H2]; clear IHt2. inversion H1 as [H11 H12]; clear H1. inversion H2 as [H21 H22]; clear H2. rewrite nf_same_as_value in H12. rewrite nf_same_as_value in H22. inversion H12 as [n1]. inversion H22 as [n2]. rewrite <- H in H11. rewrite <- H0 in H21. exists (C (n1 + n2)). split. SCase "l". apply multi_trans with (P (C n1) t2). apply multistep_congr_1. apply H11. apply multi_trans with (P (C n1) (C n2)). apply multistep_congr_2. apply v_const. apply H21. apply multi_R. apply ST_PlusConstConst. SCase "r". rewrite nf_same_as_value. apply v_const. Qed. (* ########################################################### *) (** ** Equivalence of Big-Step and Small-Step Reduction *) (** Having defined the operational semantics of our tiny programming language in two different styles, it makes sense to ask whether these definitions actually define the same thing! They do, though it takes a little work to show it. (The details are left as an exercise). *) (** **** Exercise: 3 stars (eval__multistep) *) Theorem eval__multistep : forall t n, t || n -> t ==>* C n. (** The key idea behind the proof comes from the following picture: P t1 t2 ==> (by ST_Plus1) P t1' t2 ==> (by ST_Plus1) P t1'' t2 ==> (by ST_Plus1) ... P (C n1) t2 ==> (by ST_Plus2) P (C n1) t2' ==> (by ST_Plus2) P (C n1) t2'' ==> (by ST_Plus2) ... P (C n1) (C n2) ==> (by ST_PlusConstConst) C (n1 + n2) That is, the multistep reduction of a term of the form [P t1 t2] proceeds in three phases: - First, we use [ST_Plus1] some number of times to reduce [t1] to a normal form, which must (by [nf_same_as_value]) be a term of the form [C n1] for some [n1]. - Next, we use [ST_Plus2] some number of times to reduce [t2] to a normal form, which must again be a term of the form [C n2] for some [n2]. - Finally, we use [ST_PlusConstConst] one time to reduce [P (C n1) (C n2)] to [C (n1 + n2)]. *) (** To formalize this intuition, you'll need to use the congruence lemmas from above (you might want to review them now, so that you'll be able to recognize when they are useful), plus some basic properties of [==>*]: that it is reflexive, transitive, and includes [==>]. *) Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars, advanced (eval__multistep_inf) *) (** Write a detailed informal version of the proof of [eval__multistep]. (* FILL IN HERE *) [] *) (** For the other direction, we need one lemma, which establishes a relation between single-step reduction and big-step evaluation. *) (** **** Exercise: 3 stars (step__eval) *) Lemma step__eval : forall t t' n, t ==> t' -> t' || n -> t || n. Proof. intros t t' n Hs. generalize dependent n. (* FILL IN HERE *) Admitted. (** [] *) (** The fact that small-step reduction implies big-step is now straightforward to prove, once it is stated correctly. The proof proceeds by induction on the multi-step reduction sequence that is buried in the hypothesis [normal_form_of t t']. *) (** Make sure you understand the statement before you start to work on the proof. *) (** **** Exercise: 3 stars (multistep__eval) *) Theorem multistep__eval : forall t t', normal_form_of t t' -> exists n, t' = C n /\ t || n. Proof. (* FILL IN HERE *) Admitted. (** [] *) (* ########################################################### *) (** ** Additional Exercises *) (** **** Exercise: 3 stars, optional (interp_tm) *) (** Remember that we also defined big-step evaluation of [tm]s as a function [evalF]. Prove that it is equivalent to the existing semantics. Hint: we just proved that [eval] and [multistep] are equivalent, so logically it doesn't matter which you choose. One will be easier than the other, though! *) Theorem evalF_eval : forall t n, evalF t = n <-> t || n. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 4 stars (combined_properties) *) (** We've considered the arithmetic and conditional expressions separately. This exercise explores how the two interact. *) Module Combined. Inductive tm : Type := | C : nat -> tm | P : tm -> tm -> tm | ttrue : tm | tfalse : tm | tif : tm -> tm -> tm -> tm. Tactic Notation "tm_cases" tactic(first) ident(c) := first; [ Case_aux c "C" | Case_aux c "P" | Case_aux c "ttrue" | Case_aux c "tfalse" | Case_aux c "tif" ]. Inductive value : tm -> Prop := | v_const : forall n, value (C n) | v_true : value ttrue | v_false : value tfalse. Reserved Notation " t '==>' t' " (at level 40). Inductive step : tm -> tm -> Prop := | ST_PlusConstConst : forall n1 n2, P (C n1) (C n2) ==> C (n1 + n2) | ST_Plus1 : forall t1 t1' t2, t1 ==> t1' -> P t1 t2 ==> P t1' t2 | ST_Plus2 : forall v1 t2 t2', value v1 -> t2 ==> t2' -> P v1 t2 ==> P v1 t2' | ST_IfTrue : forall t1 t2, tif ttrue t1 t2 ==> t1 | ST_IfFalse : forall t1 t2, tif tfalse t1 t2 ==> t2 | ST_If : forall t1 t1' t2 t3, t1 ==> t1' -> tif t1 t2 t3 ==> tif t1' t2 t3 where " t '==>' t' " := (step t t'). Tactic Notation "step_cases" tactic(first) ident(c) := first; [ Case_aux c "ST_PlusConstConst" | Case_aux c "ST_Plus1" | Case_aux c "ST_Plus2" | Case_aux c "ST_IfTrue" | Case_aux c "ST_IfFalse" | Case_aux c "ST_If" ]. (** Earlier, we separately proved for both plus- and if-expressions... - that the step relation was deterministic, and - a strong progress lemma, stating that every term is either a value or can take a step. Prove or disprove these two properties for the combined language. *) (* FILL IN HERE *) (** [] *) End Combined. (* ########################################################### *) (** * Small-Step Imp *) (** For a more serious example, here is the small-step version of the Imp operational semantics. *) (** The small-step evaluation relations for arithmetic and boolean expressions are straightforward extensions of the tiny language we've been working up to now. To make them easier to read, we introduce the symbolic notations [==>a] and [==>b], respectively, for the arithmetic and boolean step relations. *) Inductive aval : aexp -> Prop := av_num : forall n, aval (ANum n). (** We are not actually going to bother to define boolean values, since they aren't needed in the definition of [==>b] below (why?), though they might be if our language were a bit larger (why?). *) Reserved Notation " t '/' st '==>a' t' " (at level 40, st at level 39). Inductive astep : state -> aexp -> aexp -> Prop := | AS_Id : forall st i, AId i / st ==>a ANum (st i) | AS_Plus : forall st n1 n2, APlus (ANum n1) (ANum n2) / st ==>a ANum (n1 + n2) | AS_Plus1 : forall st a1 a1' a2, a1 / st ==>a a1' -> (APlus a1 a2) / st ==>a (APlus a1' a2) | AS_Plus2 : forall st v1 a2 a2', aval v1 -> a2 / st ==>a a2' -> (APlus v1 a2) / st ==>a (APlus v1 a2') | AS_Minus : forall st n1 n2, (AMinus (ANum n1) (ANum n2)) / st ==>a (ANum (minus n1 n2)) | AS_Minus1 : forall st a1 a1' a2, a1 / st ==>a a1' -> (AMinus a1 a2) / st ==>a (AMinus a1' a2) | AS_Minus2 : forall st v1 a2 a2', aval v1 -> a2 / st ==>a a2' -> (AMinus v1 a2) / st ==>a (AMinus v1 a2') | AS_Mult : forall st n1 n2, (AMult (ANum n1) (ANum n2)) / st ==>a (ANum (mult n1 n2)) | AS_Mult1 : forall st a1 a1' a2, a1 / st ==>a a1' -> (AMult (a1) (a2)) / st ==>a (AMult (a1') (a2)) | AS_Mult2 : forall st v1 a2 a2', aval v1 -> a2 / st ==>a a2' -> (AMult v1 a2) / st ==>a (AMult v1 a2') where " t '/' st '==>a' t' " := (astep st t t'). Reserved Notation " t '/' st '==>b' t' " (at level 40, st at level 39). Inductive bstep : state -> bexp -> bexp -> Prop := | BS_Eq : forall st n1 n2, (BEq (ANum n1) (ANum n2)) / st ==>b (if (beq_nat n1 n2) then BTrue else BFalse) | BS_Eq1 : forall st a1 a1' a2, a1 / st ==>a a1' -> (BEq a1 a2) / st ==>b (BEq a1' a2) | BS_Eq2 : forall st v1 a2 a2', aval v1 -> a2 / st ==>a a2' -> (BEq v1 a2) / st ==>b (BEq v1 a2') | BS_LtEq : forall st n1 n2, (BLe (ANum n1) (ANum n2)) / st ==>b (if (ble_nat n1 n2) then BTrue else BFalse) | BS_LtEq1 : forall st a1 a1' a2, a1 / st ==>a a1' -> (BLe a1 a2) / st ==>b (BLe a1' a2) | BS_LtEq2 : forall st v1 a2 a2', aval v1 -> a2 / st ==>a a2' -> (BLe v1 a2) / st ==>b (BLe v1 (a2')) | BS_NotTrue : forall st, (BNot BTrue) / st ==>b BFalse | BS_NotFalse : forall st, (BNot BFalse) / st ==>b BTrue | BS_NotStep : forall st b1 b1', b1 / st ==>b b1' -> (BNot b1) / st ==>b (BNot b1') | BS_AndTrueTrue : forall st, (BAnd BTrue BTrue) / st ==>b BTrue | BS_AndTrueFalse : forall st, (BAnd BTrue BFalse) / st ==>b BFalse | BS_AndFalse : forall st b2, (BAnd BFalse b2) / st ==>b BFalse | BS_AndTrueStep : forall st b2 b2', b2 / st ==>b b2' -> (BAnd BTrue b2) / st ==>b (BAnd BTrue b2') | BS_AndStep : forall st b1 b1' b2, b1 / st ==>b b1' -> (BAnd b1 b2) / st ==>b (BAnd b1' b2) where " t '/' st '==>b' t' " := (bstep st t t'). (** The semantics of commands is the interesting part. We need two small tricks to make it work: - We use [SKIP] as a "command value" -- i.e., a command that has reached a normal form. - An assignment command reduces to [SKIP] (and an updated state). - The sequencing command waits until its left-hand subcommand has reduced to [SKIP], then throws it away so that reduction can continue with the right-hand subcommand. - We reduce a [WHILE] command by transforming it into a conditional followed by the same [WHILE]. *) (** (There are other ways of achieving the effect of the latter trick, but they all share the feature that the original [WHILE] command needs to be saved somewhere while a single copy of the loop body is being evaluated.) *) Reserved Notation " t '/' st '==>' t' '/' st' " (at level 40, st at level 39, t' at level 39). Inductive cstep : (com * state) -> (com * state) -> Prop := | CS_AssStep : forall st i a a', a / st ==>a a' -> (i ::= a) / st ==> (i ::= a') / st | CS_Ass : forall st i n, (i ::= (ANum n)) / st ==> SKIP / (update st i n) | CS_SeqStep : forall st c1 c1' st' c2, c1 / st ==> c1' / st' -> (c1 ;; c2) / st ==> (c1' ;; c2) / st' | CS_SeqFinish : forall st c2, (SKIP ;; c2) / st ==> c2 / st | CS_IfTrue : forall st c1 c2, IFB BTrue THEN c1 ELSE c2 FI / st ==> c1 / st | CS_IfFalse : forall st c1 c2, IFB BFalse THEN c1 ELSE c2 FI / st ==> c2 / st | CS_IfStep : forall st b b' c1 c2, b / st ==>b b' -> IFB b THEN c1 ELSE c2 FI / st ==> (IFB b' THEN c1 ELSE c2 FI) / st | CS_While : forall st b c1, (WHILE b DO c1 END) / st ==> (IFB b THEN (c1;; (WHILE b DO c1 END)) ELSE SKIP FI) / st where " t '/' st '==>' t' '/' st' " := (cstep (t,st) (t',st')). (* ########################################################### *) (** * Concurrent Imp *) (** Finally, to show the power of this definitional style, let's enrich Imp with a new form of command that runs two subcommands in parallel and terminates when both have terminated. To reflect the unpredictability of scheduling, the actions of the subcommands may be interleaved in any order, but they share the same memory and can communicate by reading and writing the same variables. *) Module CImp. Inductive com : Type := | CSkip : com | CAss : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com (* New: *) | CPar : com -> com -> com. Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "PAR" ]. Notation "'SKIP'" := CSkip. Notation "x '::=' a" := (CAss x a) (at level 60). Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' b 'THEN' c1 'ELSE' c2 'FI'" := (CIf b c1 c2) (at level 80, right associativity). Notation "'PAR' c1 'WITH' c2 'END'" := (CPar c1 c2) (at level 80, right associativity). Inductive cstep : (com * state) -> (com * state) -> Prop := (* Old part *) | CS_AssStep : forall st i a a', a / st ==>a a' -> (i ::= a) / st ==> (i ::= a') / st | CS_Ass : forall st i n, (i ::= (ANum n)) / st ==> SKIP / (update st i n) | CS_SeqStep : forall st c1 c1' st' c2, c1 / st ==> c1' / st' -> (c1 ;; c2) / st ==> (c1' ;; c2) / st' | CS_SeqFinish : forall st c2, (SKIP ;; c2) / st ==> c2 / st | CS_IfTrue : forall st c1 c2, (IFB BTrue THEN c1 ELSE c2 FI) / st ==> c1 / st | CS_IfFalse : forall st c1 c2, (IFB BFalse THEN c1 ELSE c2 FI) / st ==> c2 / st | CS_IfStep : forall st b b' c1 c2, b /st ==>b b' -> (IFB b THEN c1 ELSE c2 FI) / st ==> (IFB b' THEN c1 ELSE c2 FI) / st | CS_While : forall st b c1, (WHILE b DO c1 END) / st ==> (IFB b THEN (c1;; (WHILE b DO c1 END)) ELSE SKIP FI) / st (* New part: *) | CS_Par1 : forall st c1 c1' c2 st', c1 / st ==> c1' / st' -> (PAR c1 WITH c2 END) / st ==> (PAR c1' WITH c2 END) / st' | CS_Par2 : forall st c1 c2 c2' st', c2 / st ==> c2' / st' -> (PAR c1 WITH c2 END) / st ==> (PAR c1 WITH c2' END) / st' | CS_ParDone : forall st, (PAR SKIP WITH SKIP END) / st ==> SKIP / st where " t '/' st '==>' t' '/' st' " := (cstep (t,st) (t',st')). Definition cmultistep := multi cstep. Notation " t '/' st '==>*' t' '/' st' " := (multi cstep (t,st) (t',st')) (at level 40, st at level 39, t' at level 39). (** Among the many interesting properties of this language is the fact that the following program can terminate with the variable [X] set to any value... *) Definition par_loop : com := PAR Y ::= ANum 1 WITH WHILE BEq (AId Y) (ANum 0) DO X ::= APlus (AId X) (ANum 1) END END. (** In particular, it can terminate with [X] set to [0]: *) Example par_loop_example_0: exists st', par_loop / empty_state ==>* SKIP / st' /\ st' X = 0. Proof. eapply ex_intro. split. unfold par_loop. eapply multi_step. apply CS_Par1. apply CS_Ass. eapply multi_step. apply CS_Par2. apply CS_While. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq1. apply AS_Id. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq. simpl. eapply multi_step. apply CS_Par2. apply CS_IfFalse. eapply multi_step. apply CS_ParDone. eapply multi_refl. reflexivity. Qed. (** It can also terminate with [X] set to [2]: *) Example par_loop_example_2: exists st', par_loop / empty_state ==>* SKIP / st' /\ st' X = 2. Proof. eapply ex_intro. split. eapply multi_step. apply CS_Par2. apply CS_While. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq1. apply AS_Id. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq. simpl. eapply multi_step. apply CS_Par2. apply CS_IfTrue. eapply multi_step. apply CS_Par2. apply CS_SeqStep. apply CS_AssStep. apply AS_Plus1. apply AS_Id. eapply multi_step. apply CS_Par2. apply CS_SeqStep. apply CS_AssStep. apply AS_Plus. eapply multi_step. apply CS_Par2. apply CS_SeqStep. apply CS_Ass. eapply multi_step. apply CS_Par2. apply CS_SeqFinish. eapply multi_step. apply CS_Par2. apply CS_While. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq1. apply AS_Id. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq. simpl. eapply multi_step. apply CS_Par2. apply CS_IfTrue. eapply multi_step. apply CS_Par2. apply CS_SeqStep. apply CS_AssStep. apply AS_Plus1. apply AS_Id. eapply multi_step. apply CS_Par2. apply CS_SeqStep. apply CS_AssStep. apply AS_Plus. eapply multi_step. apply CS_Par2. apply CS_SeqStep. apply CS_Ass. eapply multi_step. apply CS_Par1. apply CS_Ass. eapply multi_step. apply CS_Par2. apply CS_SeqFinish. eapply multi_step. apply CS_Par2. apply CS_While. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq1. apply AS_Id. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq. simpl. eapply multi_step. apply CS_Par2. apply CS_IfFalse. eapply multi_step. apply CS_ParDone. eapply multi_refl. reflexivity. Qed. (** More generally... *) (** **** Exercise: 3 stars, optional *) Lemma par_body_n__Sn : forall n st, st X = n /\ st Y = 0 -> par_loop / st ==>* par_loop / (update st X (S n)). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars, optional *) Lemma par_body_n : forall n st, st X = 0 /\ st Y = 0 -> exists st', par_loop / st ==>* par_loop / st' /\ st' X = n /\ st' Y = 0. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** ... the above loop can exit with [X] having any value whatsoever. *) Theorem par_loop_any_X: forall n, exists st', par_loop / empty_state ==>* SKIP / st' /\ st' X = n. Proof. intros n. destruct (par_body_n n empty_state). split; unfold update; reflexivity. rename x into st. inversion H as [H' [HX HY]]; clear H. exists (update st Y 1). split. eapply multi_trans with (par_loop,st). apply H'. eapply multi_step. apply CS_Par1. apply CS_Ass. eapply multi_step. apply CS_Par2. apply CS_While. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq1. apply AS_Id. rewrite update_eq. eapply multi_step. apply CS_Par2. apply CS_IfStep. apply BS_Eq. simpl. eapply multi_step. apply CS_Par2. apply CS_IfFalse. eapply multi_step. apply CS_ParDone. apply multi_refl. rewrite update_neq. assumption. intro X; inversion X. Qed. End CImp. (* ########################################################### *) (** * A Small-Step Stack Machine *) (** Last example: a small-step semantics for the stack machine example from Imp.v. *) Definition stack := list nat. Definition prog := list sinstr. Inductive stack_step : state -> prog * stack -> prog * stack -> Prop := | SS_Push : forall st stk n p', stack_step st (SPush n :: p', stk) (p', n :: stk) | SS_Load : forall st stk i p', stack_step st (SLoad i :: p', stk) (p', st i :: stk) | SS_Plus : forall st stk n m p', stack_step st (SPlus :: p', n::m::stk) (p', (m+n)::stk) | SS_Minus : forall st stk n m p', stack_step st (SMinus :: p', n::m::stk) (p', (m-n)::stk) | SS_Mult : forall st stk n m p', stack_step st (SMult :: p', n::m::stk) (p', (m*n)::stk). Theorem stack_step_deterministic : forall st, deterministic (stack_step st). Proof. unfold deterministic. intros st x y1 y2 H1 H2. induction H1; inversion H2; reflexivity. Qed. Definition stack_multistep st := multi (stack_step st). (** **** Exercise: 3 stars, advanced (compiler_is_correct) *) (** Remember the definition of [compile] for [aexp] given in the [Imp] chapter. We want now to prove [compile] correct with respect to the stack machine. State what it means for the compiler to be correct according to the stack machine small step semantics and then prove it. *) Definition compiler_is_correct_statement : Prop := (* FILL IN HERE *) admit. Theorem compiler_is_correct : compiler_is_correct_statement. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** $Date: 2014-12-31 15:16:58 -0500 (Wed, 31 Dec 2014) $ *)
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : ecc_merge_enc.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_ecc_merge_enc #( parameter TCQ = 100, parameter PAYLOAD_WIDTH = 64, parameter CODE_WIDTH = 72, parameter DATA_BUF_ADDR_WIDTH = 4, parameter DATA_BUF_OFFSET_WIDTH = 1, parameter DATA_WIDTH = 64, parameter DQ_WIDTH = 72, parameter ECC_WIDTH = 8, parameter nCK_PER_CLK = 4 ) ( /*AUTOARG*/ // Outputs mc_wrdata, mc_wrdata_mask, // Inputs clk, rst, wr_data, wr_data_mask, rd_merge_data, h_rows, raw_not_ecc ); input clk; input rst; input [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data; input [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask; input [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data; reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data_r; reg [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask_r; reg [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data_r; always @(posedge clk) wr_data_r <= #TCQ wr_data; always @(posedge clk) wr_data_mask_r <= #TCQ wr_data_mask; always @(posedge clk) rd_merge_data_r <= #TCQ rd_merge_data; // Merge new data with memory read data. wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] merged_data; genvar h; genvar i; generate for (h=0; h<2*nCK_PER_CLK; h=h+1) begin : merge_data_outer for (i=0; i<DATA_WIDTH/8; i=i+1) begin : merge_data_inner assign merged_data[h*PAYLOAD_WIDTH+i*8+:8] = wr_data_mask[h*DATA_WIDTH/8+i] ? rd_merge_data[h*DATA_WIDTH+i*8+:8] : wr_data[h*PAYLOAD_WIDTH+i*8+:8]; end if (PAYLOAD_WIDTH > DATA_WIDTH) assign merged_data[(h+1)*PAYLOAD_WIDTH-1-:PAYLOAD_WIDTH-DATA_WIDTH]= wr_data[(h+1)*PAYLOAD_WIDTH-1-:PAYLOAD_WIDTH-DATA_WIDTH]; end endgenerate // Generate ECC and overlay onto mc_wrdata. input [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; input [2*nCK_PER_CLK-1:0] raw_not_ecc; reg [2*nCK_PER_CLK-1:0] raw_not_ecc_r; always @(posedge clk) raw_not_ecc_r <= #TCQ raw_not_ecc; output reg [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata; reg [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata_c; genvar j; integer k; generate for (j=0; j<2*nCK_PER_CLK; j=j+1) begin : ecc_word always @(/*AS*/h_rows or merged_data or raw_not_ecc_r) begin mc_wrdata_c[j*DQ_WIDTH+:DQ_WIDTH] = {{DQ_WIDTH-PAYLOAD_WIDTH{1'b0}}, merged_data[j*PAYLOAD_WIDTH+:PAYLOAD_WIDTH]}; for (k=0; k<ECC_WIDTH; k=k+1) if (~raw_not_ecc_r[j]) mc_wrdata_c[j*DQ_WIDTH+CODE_WIDTH-k-1] = ^(merged_data[j*PAYLOAD_WIDTH+:DATA_WIDTH] & h_rows[k*CODE_WIDTH+:DATA_WIDTH]); end end endgenerate always @(posedge clk) mc_wrdata <= mc_wrdata_c; // Set all DRAM masks to zero. output wire[2*nCK_PER_CLK*DQ_WIDTH/8-1:0] mc_wrdata_mask; assign mc_wrdata_mask = {2*nCK_PER_CLK*DQ_WIDTH/8{1'b0}}; endmodule
module main_pll (inclk0, c0); input inclk0; output c0; wire [4:0] sub_wire0; wire [0:0] sub_wire4 = 1'h0; wire [0:0] sub_wire1 = sub_wire0[0:0]; wire c0 = sub_wire1; wire sub_wire2 = inclk0; wire [1:0] sub_wire3 = {sub_wire4, sub_wire2}; altpll altpll_component ( .inclk (sub_wire3), .clk (sub_wire0), .activeclock (), .areset (1'b0), .clkbad (), .clkena ({6{1'b1}}), .clkloss (), .clkswitch (1'b0), .configupdate (1'b0), .enable0 (), .enable1 (), .extclk (), .extclkena ({4{1'b1}}), .fbin (1'b1), .fbmimicbidir (), .fbout (), // synopsys translate_off .fref (), .icdrclk (), // synopsys translate_on .locked (), .pfdena (1'b1), .phasecounterselect ({4{1'b1}}), .phasedone (), .phasestep (1'b1), .phaseupdown (1'b1), .pllena (1'b1), .scanaclr (1'b0), .scanclk (1'b0), .scanclkena (1'b1), .scandata (1'b0), .scandataout (), .scandone (), .scanread (1'b0), .scanwrite (1'b0), .sclkout0 (), .sclkout1 (), .vcooverrange (), .vcounderrange ()); defparam altpll_component.bandwidth_type = "AUTO", altpll_component.clk0_divide_by = 5, altpll_component.clk0_duty_cycle = 50, altpll_component.clk0_multiply_by = 5, altpll_component.clk0_phase_shift = "0", altpll_component.compensate_clock = "CLK0", altpll_component.inclk0_input_frequency = 20000, altpll_component.intended_device_family = "Cyclone III", altpll_component.lpm_hint = "CBX_MODULE_PREFIX=main_pll", altpll_component.lpm_type = "altpll", altpll_component.operation_mode = "NORMAL", altpll_component.pll_type = "AUTO", altpll_component.port_activeclock = "PORT_UNUSED", altpll_component.port_areset = "PORT_UNUSED", altpll_component.port_clkbad0 = "PORT_UNUSED", altpll_component.port_clkbad1 = "PORT_UNUSED", altpll_component.port_clkloss = "PORT_UNUSED", altpll_component.port_clkswitch = "PORT_UNUSED", altpll_component.port_configupdate = "PORT_UNUSED", altpll_component.port_fbin = "PORT_UNUSED", altpll_component.port_inclk0 = "PORT_USED", altpll_component.port_inclk1 = "PORT_UNUSED", altpll_component.port_locked = "PORT_UNUSED", altpll_component.port_pfdena = "PORT_UNUSED", altpll_component.port_phasecounterselect = "PORT_UNUSED", altpll_component.port_phasedone = "PORT_UNUSED", altpll_component.port_phasestep = "PORT_UNUSED", altpll_component.port_phaseupdown = "PORT_UNUSED", altpll_component.port_pllena = "PORT_UNUSED", altpll_component.port_scanaclr = "PORT_UNUSED", altpll_component.port_scanclk = "PORT_UNUSED", altpll_component.port_scanclkena = "PORT_UNUSED", altpll_component.port_scandata = "PORT_UNUSED", altpll_component.port_scandataout = "PORT_UNUSED", altpll_component.port_scandone = "PORT_UNUSED", altpll_component.port_scanread = "PORT_UNUSED", altpll_component.port_scanwrite = "PORT_UNUSED", altpll_component.port_clk0 = "PORT_USED", altpll_component.port_clk1 = "PORT_UNUSED", altpll_component.port_clk2 = "PORT_UNUSED", altpll_component.port_clk3 = "PORT_UNUSED", altpll_component.port_clk4 = "PORT_UNUSED", altpll_component.port_clk5 = "PORT_UNUSED", altpll_component.port_clkena0 = "PORT_UNUSED", altpll_component.port_clkena1 = "PORT_UNUSED", altpll_component.port_clkena2 = "PORT_UNUSED", altpll_component.port_clkena3 = "PORT_UNUSED", altpll_component.port_clkena4 = "PORT_UNUSED", altpll_component.port_clkena5 = "PORT_UNUSED", altpll_component.port_extclk0 = "PORT_UNUSED", altpll_component.port_extclk1 = "PORT_UNUSED", altpll_component.port_extclk2 = "PORT_UNUSED", altpll_component.port_extclk3 = "PORT_UNUSED", altpll_component.width_clock = 5; endmodule
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Export NumPrelude NZAxioms. Require Import NZBase NZOrder NZAddOrder Plus Minus. (** In this file, we investigate the shape of domains satisfying the [NZDomainSig] interface. In particular, we define a translation from Peano numbers [nat] into NZ. *) Local Notation "f ^ n" := (fun x => nat_rect _ x (fun _ => f) n). Instance nat_rect_wd n {A} (R:relation A) : Proper (R==>(R==>R)==>R) (fun x f => nat_rect (fun _ => _) x (fun _ => f) n). Proof. intros x y eq_xy f g eq_fg; induction n; [assumption | now apply eq_fg]. Qed. Module NZDomainProp (Import NZ:NZDomainSig'). Include NZBaseProp NZ. (** * Relationship between points thanks to [succ] and [pred]. *) (** For any two points, one is an iterated successor of the other. *) Lemma itersucc_or_itersucc n m : exists k, n == (S^k) m \/ m == (S^k) n. Proof. revert n. apply central_induction with (z:=m). { intros x y eq_xy; apply ex_iff_morphism. intros n; apply or_iff_morphism. + split; intros; etransitivity; try eassumption; now symmetry. + split; intros; (etransitivity; [eassumption|]); [|symmetry]; (eapply nat_rect_wd; [eassumption|apply succ_wd]). } exists 0%nat. now left. intros n. split; intros [k [L|R]]. exists (Datatypes.S k). left. now apply succ_wd. destruct k as [|k]. simpl in R. exists 1%nat. left. now apply succ_wd. rewrite nat_rect_succ_r in R. exists k. now right. destruct k as [|k]; simpl in L. exists 1%nat. now right. apply succ_inj in L. exists k. now left. exists (Datatypes.S k). right. now rewrite nat_rect_succ_r. Qed. (** Generalized version of [pred_succ] when iterating *) Lemma succ_swap_pred : forall k n m, n == (S^k) m -> m == (P^k) n. Proof. induction k. simpl; auto with *. simpl; intros. apply pred_wd in H. rewrite pred_succ in H. apply IHk in H; auto. rewrite <- nat_rect_succ_r in H; auto. Qed. (** From a given point, all others are iterated successors or iterated predecessors. *) Lemma itersucc_or_iterpred : forall n m, exists k, n == (S^k) m \/ n == (P^k) m. Proof. intros n m. destruct (itersucc_or_itersucc n m) as (k,[H|H]). exists k; left; auto. exists k; right. apply succ_swap_pred; auto. Qed. (** In particular, all points are either iterated successors of [0] or iterated predecessors of [0] (or both). *) Lemma itersucc0_or_iterpred0 : forall n, exists p:nat, n == (S^p) 0 \/ n == (P^p) 0. Proof. intros n. exact (itersucc_or_iterpred n 0). Qed. (** * Study of initial point w.r.t. [succ] (if any). *) Definition initial n := forall m, n ~= S m. Lemma initial_alt : forall n, initial n <-> S (P n) ~= n. Proof. split. intros Bn EQ. symmetry in EQ. destruct (Bn _ EQ). intros NEQ m EQ. apply NEQ. rewrite EQ, pred_succ; auto with *. Qed. Lemma initial_alt2 : forall n, initial n <-> ~exists m, n == S m. Proof. firstorder. Qed. (** First case: let's assume such an initial point exists (i.e. [S] isn't surjective)... *) Section InitialExists. Hypothesis init : t. Hypothesis Initial : initial init. (** ... then we have unicity of this initial point. *) Lemma initial_unique : forall m, initial m -> m == init. Proof. intros m Im. destruct (itersucc_or_itersucc init m) as (p,[H|H]). destruct p. now simpl in *. destruct (Initial _ H). destruct p. now simpl in *. destruct (Im _ H). Qed. (** ... then all other points are descendant of it. *) Lemma initial_ancestor : forall m, exists p, m == (S^p) init. Proof. intros m. destruct (itersucc_or_itersucc init m) as (p,[H|H]). destruct p; simpl in *; auto. exists O; auto with *. destruct (Initial _ H). exists p; auto. Qed. (** NB : We would like to have [pred n == n] for the initial element, but nothing forces that. For instance we can have -3 as initial point, and P(-3) = 2. A bit odd indeed, but legal according to [NZDomainSig]. We can hence have [n == (P^k) m] without [exists k', m == (S^k') n]. *) (** We need decidability of [eq] (or classical reasoning) for this: *) Section SuccPred. Hypothesis eq_decidable : forall n m, n==m \/ n~=m. Lemma succ_pred_approx : forall n, ~initial n -> S (P n) == n. Proof. intros n NB. rewrite initial_alt in NB. destruct (eq_decidable (S (P n)) n); auto. elim NB; auto. Qed. End SuccPred. End InitialExists. (** Second case : let's suppose now [S] surjective, i.e. no initial point. *) Section InitialDontExists. Hypothesis succ_onto : forall n, exists m, n == S m. Lemma succ_onto_gives_succ_pred : forall n, S (P n) == n. Proof. intros n. destruct (succ_onto n) as (m,H). rewrite H, pred_succ; auto with *. Qed. Lemma succ_onto_pred_injective : forall n m, P n == P m -> n == m. Proof. intros n m. intros H; apply succ_wd in H. rewrite !succ_onto_gives_succ_pred in H; auto. Qed. End InitialDontExists. (** To summarize: S is always injective, P is always surjective (thanks to [pred_succ]). I) If S is not surjective, we have an initial point, which is unique. This bottom is below zero: we have N shifted (or not) to the left. P cannot be injective: P init = P (S (P init)). (P init) can be arbitrary. II) If S is surjective, we have [forall n, S (P n) = n], S and P are bijective and reciprocal. IIa) if [exists k<>O, 0 == S^k 0], then we have a cyclic structure Z/nZ IIb) otherwise, we have Z *) (** * An alternative induction principle using [S] and [P]. *) (** It is weaker than [bi_induction]. For instance it cannot prove that we can go from one point by many [S] _or_ many [P], but only by many [S] mixed with many [P]. Think of a model with two copies of N: 0, 1=S 0, 2=S 1, ... 0', 1'=S 0', 2'=S 1', ... and P 0 = 0' and P 0' = 0. *) Lemma bi_induction_pred : forall A : t -> Prop, Proper (eq==>iff) A -> A 0 -> (forall n, A n -> A (S n)) -> (forall n, A n -> A (P n)) -> forall n, A n. Proof. intros. apply bi_induction; auto. clear n. intros n; split; auto. intros G; apply H2 in G. rewrite pred_succ in G; auto. Qed. Lemma central_induction_pred : forall A : t -> Prop, Proper (eq==>iff) A -> forall n0, A n0 -> (forall n, A n -> A (S n)) -> (forall n, A n -> A (P n)) -> forall n, A n. Proof. intros. assert (A 0). destruct (itersucc_or_iterpred 0 n0) as (k,[Hk|Hk]); rewrite Hk; clear Hk. clear H2. induction k; simpl in *; auto. clear H1. induction k; simpl in *; auto. apply bi_induction_pred; auto. Qed. End NZDomainProp. (** We now focus on the translation from [nat] into [NZ]. First, relationship with [0], [succ], [pred]. *) Module NZOfNat (Import NZ:NZDomainSig'). Definition ofnat (n : nat) : t := (S^n) 0. Notation "[ n ]" := (ofnat n) (at level 7) : ofnat. Local Open Scope ofnat. Lemma ofnat_zero : [O] == 0. Proof. reflexivity. Qed. Lemma ofnat_succ : forall n, [Datatypes.S n] == succ [n]. Proof. now unfold ofnat. Qed. Lemma ofnat_pred : forall n, n<>O -> [Peano.pred n] == P [n]. Proof. unfold ofnat. destruct n. destruct 1; auto. intros _. simpl. symmetry. apply pred_succ. Qed. (** Since [P 0] can be anything in NZ (either [-1], [0], or even other numbers, we cannot state previous lemma for [n=O]. *) End NZOfNat. (** If we require in addition a strict order on NZ, we can prove that [ofnat] is injective, and hence that NZ is infinite (i.e. we ban Z/nZ models) *) Module NZOfNatOrd (Import NZ:NZOrdSig'). Include NZOfNat NZ. Include NZBaseProp NZ <+ NZOrderProp NZ. Local Open Scope ofnat. Theorem ofnat_S_gt_0 : forall n : nat, 0 < [Datatypes.S n]. Proof. unfold ofnat. intros n; induction n as [| n IH]; simpl in *. apply lt_succ_diag_r. apply lt_trans with (S 0). apply lt_succ_diag_r. now rewrite <- succ_lt_mono. Qed. Theorem ofnat_S_neq_0 : forall n : nat, 0 ~= [Datatypes.S n]. Proof. intros. apply lt_neq, ofnat_S_gt_0. Qed. Lemma ofnat_injective : forall n m, [n]==[m] -> n = m. Proof. induction n as [|n IH]; destruct m; auto. intros H; elim (ofnat_S_neq_0 _ H). intros H; symmetry in H; elim (ofnat_S_neq_0 _ H). intros. f_equal. apply IH. now rewrite <- succ_inj_wd. Qed. Lemma ofnat_eq : forall n m, [n]==[m] <-> n = m. Proof. split. apply ofnat_injective. intros; now subst. Qed. (* In addition, we can prove that [ofnat] preserves order. *) Lemma ofnat_lt : forall n m : nat, [n]<[m] <-> (n<m)%nat. Proof. induction n as [|n IH]; destruct m; repeat rewrite ofnat_zero; split. intro H; elim (lt_irrefl _ H). inversion 1. auto with arith. intros; apply ofnat_S_gt_0. intro H; elim (lt_asymm _ _ H); apply ofnat_S_gt_0. inversion 1. rewrite !ofnat_succ, <- succ_lt_mono, IH; auto with arith. rewrite !ofnat_succ, <- succ_lt_mono, IH; auto with arith. Qed. Lemma ofnat_le : forall n m : nat, [n]<=[m] <-> (n<=m)%nat. Proof. intros. rewrite lt_eq_cases, ofnat_lt, ofnat_eq. split. destruct 1; subst; auto with arith. apply Lt.le_lt_or_eq. Qed. End NZOfNatOrd. (** For basic operations, we can prove correspondance with their counterpart in [nat]. *) Module NZOfNatOps (Import NZ:NZAxiomsSig'). Include NZOfNat NZ. Local Open Scope ofnat. Lemma ofnat_add_l : forall n m, [n]+m == (S^n) m. Proof. induction n; intros. apply add_0_l. rewrite ofnat_succ, add_succ_l. simpl. now f_equiv. Qed. Lemma ofnat_add : forall n m, [n+m] == [n]+[m]. Proof. intros. rewrite ofnat_add_l. induction n; simpl. reflexivity. now f_equiv. Qed. Lemma ofnat_mul : forall n m, [n*m] == [n]*[m]. Proof. induction n; simpl; intros. symmetry. apply mul_0_l. rewrite plus_comm. rewrite ofnat_add, mul_succ_l. now f_equiv. Qed. Lemma ofnat_sub_r : forall n m, n-[m] == (P^m) n. Proof. induction m; simpl; intros. apply sub_0_r. rewrite sub_succ_r. now f_equiv. Qed. Lemma ofnat_sub : forall n m, m<=n -> [n-m] == [n]-[m]. Proof. intros n m H. rewrite ofnat_sub_r. revert n H. induction m. intros. rewrite <- minus_n_O. now simpl. intros. destruct n. inversion H. rewrite nat_rect_succ_r. simpl. etransitivity. apply IHm. auto with arith. eapply nat_rect_wd; [symmetry;apply pred_succ|apply pred_wd]. Qed. End NZOfNatOps.
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Export NumPrelude NZAxioms. Require Import NZBase NZOrder NZAddOrder Plus Minus. (** In this file, we investigate the shape of domains satisfying the [NZDomainSig] interface. In particular, we define a translation from Peano numbers [nat] into NZ. *) Local Notation "f ^ n" := (fun x => nat_rect _ x (fun _ => f) n). Instance nat_rect_wd n {A} (R:relation A) : Proper (R==>(R==>R)==>R) (fun x f => nat_rect (fun _ => _) x (fun _ => f) n). Proof. intros x y eq_xy f g eq_fg; induction n; [assumption | now apply eq_fg]. Qed. Module NZDomainProp (Import NZ:NZDomainSig'). Include NZBaseProp NZ. (** * Relationship between points thanks to [succ] and [pred]. *) (** For any two points, one is an iterated successor of the other. *) Lemma itersucc_or_itersucc n m : exists k, n == (S^k) m \/ m == (S^k) n. Proof. revert n. apply central_induction with (z:=m). { intros x y eq_xy; apply ex_iff_morphism. intros n; apply or_iff_morphism. + split; intros; etransitivity; try eassumption; now symmetry. + split; intros; (etransitivity; [eassumption|]); [|symmetry]; (eapply nat_rect_wd; [eassumption|apply succ_wd]). } exists 0%nat. now left. intros n. split; intros [k [L|R]]. exists (Datatypes.S k). left. now apply succ_wd. destruct k as [|k]. simpl in R. exists 1%nat. left. now apply succ_wd. rewrite nat_rect_succ_r in R. exists k. now right. destruct k as [|k]; simpl in L. exists 1%nat. now right. apply succ_inj in L. exists k. now left. exists (Datatypes.S k). right. now rewrite nat_rect_succ_r. Qed. (** Generalized version of [pred_succ] when iterating *) Lemma succ_swap_pred : forall k n m, n == (S^k) m -> m == (P^k) n. Proof. induction k. simpl; auto with *. simpl; intros. apply pred_wd in H. rewrite pred_succ in H. apply IHk in H; auto. rewrite <- nat_rect_succ_r in H; auto. Qed. (** From a given point, all others are iterated successors or iterated predecessors. *) Lemma itersucc_or_iterpred : forall n m, exists k, n == (S^k) m \/ n == (P^k) m. Proof. intros n m. destruct (itersucc_or_itersucc n m) as (k,[H|H]). exists k; left; auto. exists k; right. apply succ_swap_pred; auto. Qed. (** In particular, all points are either iterated successors of [0] or iterated predecessors of [0] (or both). *) Lemma itersucc0_or_iterpred0 : forall n, exists p:nat, n == (S^p) 0 \/ n == (P^p) 0. Proof. intros n. exact (itersucc_or_iterpred n 0). Qed. (** * Study of initial point w.r.t. [succ] (if any). *) Definition initial n := forall m, n ~= S m. Lemma initial_alt : forall n, initial n <-> S (P n) ~= n. Proof. split. intros Bn EQ. symmetry in EQ. destruct (Bn _ EQ). intros NEQ m EQ. apply NEQ. rewrite EQ, pred_succ; auto with *. Qed. Lemma initial_alt2 : forall n, initial n <-> ~exists m, n == S m. Proof. firstorder. Qed. (** First case: let's assume such an initial point exists (i.e. [S] isn't surjective)... *) Section InitialExists. Hypothesis init : t. Hypothesis Initial : initial init. (** ... then we have unicity of this initial point. *) Lemma initial_unique : forall m, initial m -> m == init. Proof. intros m Im. destruct (itersucc_or_itersucc init m) as (p,[H|H]). destruct p. now simpl in *. destruct (Initial _ H). destruct p. now simpl in *. destruct (Im _ H). Qed. (** ... then all other points are descendant of it. *) Lemma initial_ancestor : forall m, exists p, m == (S^p) init. Proof. intros m. destruct (itersucc_or_itersucc init m) as (p,[H|H]). destruct p; simpl in *; auto. exists O; auto with *. destruct (Initial _ H). exists p; auto. Qed. (** NB : We would like to have [pred n == n] for the initial element, but nothing forces that. For instance we can have -3 as initial point, and P(-3) = 2. A bit odd indeed, but legal according to [NZDomainSig]. We can hence have [n == (P^k) m] without [exists k', m == (S^k') n]. *) (** We need decidability of [eq] (or classical reasoning) for this: *) Section SuccPred. Hypothesis eq_decidable : forall n m, n==m \/ n~=m. Lemma succ_pred_approx : forall n, ~initial n -> S (P n) == n. Proof. intros n NB. rewrite initial_alt in NB. destruct (eq_decidable (S (P n)) n); auto. elim NB; auto. Qed. End SuccPred. End InitialExists. (** Second case : let's suppose now [S] surjective, i.e. no initial point. *) Section InitialDontExists. Hypothesis succ_onto : forall n, exists m, n == S m. Lemma succ_onto_gives_succ_pred : forall n, S (P n) == n. Proof. intros n. destruct (succ_onto n) as (m,H). rewrite H, pred_succ; auto with *. Qed. Lemma succ_onto_pred_injective : forall n m, P n == P m -> n == m. Proof. intros n m. intros H; apply succ_wd in H. rewrite !succ_onto_gives_succ_pred in H; auto. Qed. End InitialDontExists. (** To summarize: S is always injective, P is always surjective (thanks to [pred_succ]). I) If S is not surjective, we have an initial point, which is unique. This bottom is below zero: we have N shifted (or not) to the left. P cannot be injective: P init = P (S (P init)). (P init) can be arbitrary. II) If S is surjective, we have [forall n, S (P n) = n], S and P are bijective and reciprocal. IIa) if [exists k<>O, 0 == S^k 0], then we have a cyclic structure Z/nZ IIb) otherwise, we have Z *) (** * An alternative induction principle using [S] and [P]. *) (** It is weaker than [bi_induction]. For instance it cannot prove that we can go from one point by many [S] _or_ many [P], but only by many [S] mixed with many [P]. Think of a model with two copies of N: 0, 1=S 0, 2=S 1, ... 0', 1'=S 0', 2'=S 1', ... and P 0 = 0' and P 0' = 0. *) Lemma bi_induction_pred : forall A : t -> Prop, Proper (eq==>iff) A -> A 0 -> (forall n, A n -> A (S n)) -> (forall n, A n -> A (P n)) -> forall n, A n. Proof. intros. apply bi_induction; auto. clear n. intros n; split; auto. intros G; apply H2 in G. rewrite pred_succ in G; auto. Qed. Lemma central_induction_pred : forall A : t -> Prop, Proper (eq==>iff) A -> forall n0, A n0 -> (forall n, A n -> A (S n)) -> (forall n, A n -> A (P n)) -> forall n, A n. Proof. intros. assert (A 0). destruct (itersucc_or_iterpred 0 n0) as (k,[Hk|Hk]); rewrite Hk; clear Hk. clear H2. induction k; simpl in *; auto. clear H1. induction k; simpl in *; auto. apply bi_induction_pred; auto. Qed. End NZDomainProp. (** We now focus on the translation from [nat] into [NZ]. First, relationship with [0], [succ], [pred]. *) Module NZOfNat (Import NZ:NZDomainSig'). Definition ofnat (n : nat) : t := (S^n) 0. Notation "[ n ]" := (ofnat n) (at level 7) : ofnat. Local Open Scope ofnat. Lemma ofnat_zero : [O] == 0. Proof. reflexivity. Qed. Lemma ofnat_succ : forall n, [Datatypes.S n] == succ [n]. Proof. now unfold ofnat. Qed. Lemma ofnat_pred : forall n, n<>O -> [Peano.pred n] == P [n]. Proof. unfold ofnat. destruct n. destruct 1; auto. intros _. simpl. symmetry. apply pred_succ. Qed. (** Since [P 0] can be anything in NZ (either [-1], [0], or even other numbers, we cannot state previous lemma for [n=O]. *) End NZOfNat. (** If we require in addition a strict order on NZ, we can prove that [ofnat] is injective, and hence that NZ is infinite (i.e. we ban Z/nZ models) *) Module NZOfNatOrd (Import NZ:NZOrdSig'). Include NZOfNat NZ. Include NZBaseProp NZ <+ NZOrderProp NZ. Local Open Scope ofnat. Theorem ofnat_S_gt_0 : forall n : nat, 0 < [Datatypes.S n]. Proof. unfold ofnat. intros n; induction n as [| n IH]; simpl in *. apply lt_succ_diag_r. apply lt_trans with (S 0). apply lt_succ_diag_r. now rewrite <- succ_lt_mono. Qed. Theorem ofnat_S_neq_0 : forall n : nat, 0 ~= [Datatypes.S n]. Proof. intros. apply lt_neq, ofnat_S_gt_0. Qed. Lemma ofnat_injective : forall n m, [n]==[m] -> n = m. Proof. induction n as [|n IH]; destruct m; auto. intros H; elim (ofnat_S_neq_0 _ H). intros H; symmetry in H; elim (ofnat_S_neq_0 _ H). intros. f_equal. apply IH. now rewrite <- succ_inj_wd. Qed. Lemma ofnat_eq : forall n m, [n]==[m] <-> n = m. Proof. split. apply ofnat_injective. intros; now subst. Qed. (* In addition, we can prove that [ofnat] preserves order. *) Lemma ofnat_lt : forall n m : nat, [n]<[m] <-> (n<m)%nat. Proof. induction n as [|n IH]; destruct m; repeat rewrite ofnat_zero; split. intro H; elim (lt_irrefl _ H). inversion 1. auto with arith. intros; apply ofnat_S_gt_0. intro H; elim (lt_asymm _ _ H); apply ofnat_S_gt_0. inversion 1. rewrite !ofnat_succ, <- succ_lt_mono, IH; auto with arith. rewrite !ofnat_succ, <- succ_lt_mono, IH; auto with arith. Qed. Lemma ofnat_le : forall n m : nat, [n]<=[m] <-> (n<=m)%nat. Proof. intros. rewrite lt_eq_cases, ofnat_lt, ofnat_eq. split. destruct 1; subst; auto with arith. apply Lt.le_lt_or_eq. Qed. End NZOfNatOrd. (** For basic operations, we can prove correspondance with their counterpart in [nat]. *) Module NZOfNatOps (Import NZ:NZAxiomsSig'). Include NZOfNat NZ. Local Open Scope ofnat. Lemma ofnat_add_l : forall n m, [n]+m == (S^n) m. Proof. induction n; intros. apply add_0_l. rewrite ofnat_succ, add_succ_l. simpl. now f_equiv. Qed. Lemma ofnat_add : forall n m, [n+m] == [n]+[m]. Proof. intros. rewrite ofnat_add_l. induction n; simpl. reflexivity. now f_equiv. Qed. Lemma ofnat_mul : forall n m, [n*m] == [n]*[m]. Proof. induction n; simpl; intros. symmetry. apply mul_0_l. rewrite plus_comm. rewrite ofnat_add, mul_succ_l. now f_equiv. Qed. Lemma ofnat_sub_r : forall n m, n-[m] == (P^m) n. Proof. induction m; simpl; intros. apply sub_0_r. rewrite sub_succ_r. now f_equiv. Qed. Lemma ofnat_sub : forall n m, m<=n -> [n-m] == [n]-[m]. Proof. intros n m H. rewrite ofnat_sub_r. revert n H. induction m. intros. rewrite <- minus_n_O. now simpl. intros. destruct n. inversion H. rewrite nat_rect_succ_r. simpl. etransitivity. apply IHm. auto with arith. eapply nat_rect_wd; [symmetry;apply pred_succ|apply pred_wd]. Qed. End NZOfNatOps.
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2009 by Iztok Jeras. module t (/*AUTOARG*/ // Inputs clk ); input clk; `define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0); // parameters for array sizes localparam WA = 4; localparam WB = 6; localparam WC = 8; // 2D packed arrays logic [WA+1:2] [WB+1:2] [WC+1:2] array_bg; // big endian array /* verilator lint_off LITENDIAN */ logic [2:WA+1] [2:WB+1] [2:WC+1] array_lt; // little endian array /* verilator lint_on LITENDIAN */ logic [1:0] array_unpk [3:2][1:0]; integer cnt = 0; integer slc = 0; // slice type integer dim = 0; // dimension integer wdt = 0; // width initial begin `checkh($dimensions (array_unpk), 3); `ifndef VCS `checkh($unpacked_dimensions (array_unpk), 2); // IEEE 2009 `endif `checkh($bits (array_unpk), 2*2*2); `checkh($low (array_unpk), 2); `checkh($high (array_unpk), 3); `checkh($left (array_unpk), 3); `checkh($right(array_unpk), 2); `checkh($increment(array_unpk), 1); `checkh($size (array_unpk), 2); end // event counter always @ (posedge clk) begin cnt <= cnt + 1; end // finish report always @ (posedge clk) if ( (cnt[30:4]==3) && (cnt[3:2]==2'd3) && (cnt[1:0]==2'd3) ) begin $write("*-* All Finished *-*\n"); $finish; end integer slc_next; // calculation of dimention sizes always @ (posedge clk) begin // slicing type counter case (cnt[3:2]) 2'd0 : begin slc_next = 0; end // full array 2'd1 : begin slc_next = 1; end // single array element 2'd2 : begin slc_next = 2; end // half array default: begin slc_next = 0; end endcase slc <= slc_next; // dimension counter case (cnt[1:0]) 2'd0 : begin dim <= 1; wdt <= (slc_next==1) ? WA/2 : (slc_next==2) ? WA/2 : WA; end 2'd1 : begin dim <= 2; wdt <= WB; end 2'd2 : begin dim <= 3; wdt <= WC; end default: begin dim <= 0; wdt <= 0; end endcase end always @ (posedge clk) begin `ifdef TEST_VERBOSE $write("cnt[30:4]=%0d slc=%0d dim=%0d wdt=%0d\n", cnt[30:4], slc, dim, wdt); `endif if (cnt[30:4]==1) begin // big endian if (slc==0) begin // full array `checkh($dimensions (array_bg), 3); `checkh($bits (array_bg), WA*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_bg, dim), wdt+1); `checkh($right (array_bg, dim), 2 ); `checkh($low (array_bg, dim), 2 ); `checkh($high (array_bg, dim), wdt+1); `checkh($increment (array_bg, dim), 1 ); `checkh($size (array_bg, dim), wdt ); end end else if (slc==1) begin // single array element `checkh($dimensions (array_bg[2]), 2); `checkh($bits (array_bg[2]), WB*WC); if ((dim>=2)&&(dim<=3)) begin `checkh($left (array_bg[2], dim-1), wdt+1); `checkh($right (array_bg[2], dim-1), 2 ); `checkh($low (array_bg[2], dim-1), 2 ); `checkh($high (array_bg[2], dim-1), wdt+1); `checkh($increment (array_bg[2], dim-1), 1 ); `checkh($size (array_bg[2], dim-1), wdt ); end `ifndef VERILATOR // Unsupported slices don't maintain size correctly end else if (slc==2) begin // half array `checkh($dimensions (array_bg[WA/2+1:2]), 3); `checkh($bits (array_bg[WA/2+1:2]), WA/2*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_bg[WA/2+1:2], dim), wdt+1); `checkh($right (array_bg[WA/2+1:2], dim), 2 ); `checkh($low (array_bg[WA/2+1:2], dim), 2 ); `checkh($high (array_bg[WA/2+1:2], dim), wdt+1); `checkh($increment (array_bg[WA/2+1:2], dim), 1 ); `checkh($size (array_bg[WA/2+1:2], dim), wdt); end `endif end end else if (cnt[30:4]==2) begin // little endian if (slc==0) begin // full array `checkh($dimensions (array_lt), 3); `checkh($bits (array_lt), WA*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_lt, dim), 2 ); `checkh($right (array_lt, dim), wdt+1); `checkh($low (array_lt, dim), 2 ); `checkh($high (array_lt, dim), wdt+1); `checkh($increment (array_lt, dim), -1 ); `checkh($size (array_lt, dim), wdt ); end end else if (slc==1) begin // single array element `checkh($dimensions (array_lt[2]), 2); `checkh($bits (array_lt[2]), WB*WC); if ((dim>=2)&&(dim<=3)) begin `checkh($left (array_lt[2], dim-1), 2 ); `checkh($right (array_lt[2], dim-1), wdt+1); `checkh($low (array_lt[2], dim-1), 2 ); `checkh($high (array_lt[2], dim-1), wdt+1); `checkh($increment (array_lt[2], dim-1), -1 ); `checkh($size (array_lt[2], dim-1), wdt ); end `ifndef VERILATOR // Unsupported slices don't maintain size correctly end else if (slc==2) begin // half array `checkh($dimensions (array_lt[2:WA/2+1]), 3); `checkh($bits (array_lt[2:WA/2+1]), WA/2*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_lt[2:WA/2+1], dim), 2 ); `checkh($right (array_lt[2:WA/2+1], dim), wdt+1); `checkh($low (array_lt[2:WA/2+1], dim), 2 ); `checkh($high (array_lt[2:WA/2+1], dim), wdt+1); `checkh($increment (array_lt[2:WA/2+1], dim), -1 ); `checkh($size (array_lt[2:WA/2+1], dim), wdt ); end `endif end end end endmodule
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2009 by Iztok Jeras. module t (/*AUTOARG*/ // Inputs clk ); input clk; `define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0); // parameters for array sizes localparam WA = 4; localparam WB = 6; localparam WC = 8; // 2D packed arrays logic [WA+1:2] [WB+1:2] [WC+1:2] array_bg; // big endian array /* verilator lint_off LITENDIAN */ logic [2:WA+1] [2:WB+1] [2:WC+1] array_lt; // little endian array /* verilator lint_on LITENDIAN */ logic [1:0] array_unpk [3:2][1:0]; integer cnt = 0; integer slc = 0; // slice type integer dim = 0; // dimension integer wdt = 0; // width initial begin `checkh($dimensions (array_unpk), 3); `ifndef VCS `checkh($unpacked_dimensions (array_unpk), 2); // IEEE 2009 `endif `checkh($bits (array_unpk), 2*2*2); `checkh($low (array_unpk), 2); `checkh($high (array_unpk), 3); `checkh($left (array_unpk), 3); `checkh($right(array_unpk), 2); `checkh($increment(array_unpk), 1); `checkh($size (array_unpk), 2); end // event counter always @ (posedge clk) begin cnt <= cnt + 1; end // finish report always @ (posedge clk) if ( (cnt[30:4]==3) && (cnt[3:2]==2'd3) && (cnt[1:0]==2'd3) ) begin $write("*-* All Finished *-*\n"); $finish; end integer slc_next; // calculation of dimention sizes always @ (posedge clk) begin // slicing type counter case (cnt[3:2]) 2'd0 : begin slc_next = 0; end // full array 2'd1 : begin slc_next = 1; end // single array element 2'd2 : begin slc_next = 2; end // half array default: begin slc_next = 0; end endcase slc <= slc_next; // dimension counter case (cnt[1:0]) 2'd0 : begin dim <= 1; wdt <= (slc_next==1) ? WA/2 : (slc_next==2) ? WA/2 : WA; end 2'd1 : begin dim <= 2; wdt <= WB; end 2'd2 : begin dim <= 3; wdt <= WC; end default: begin dim <= 0; wdt <= 0; end endcase end always @ (posedge clk) begin `ifdef TEST_VERBOSE $write("cnt[30:4]=%0d slc=%0d dim=%0d wdt=%0d\n", cnt[30:4], slc, dim, wdt); `endif if (cnt[30:4]==1) begin // big endian if (slc==0) begin // full array `checkh($dimensions (array_bg), 3); `checkh($bits (array_bg), WA*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_bg, dim), wdt+1); `checkh($right (array_bg, dim), 2 ); `checkh($low (array_bg, dim), 2 ); `checkh($high (array_bg, dim), wdt+1); `checkh($increment (array_bg, dim), 1 ); `checkh($size (array_bg, dim), wdt ); end end else if (slc==1) begin // single array element `checkh($dimensions (array_bg[2]), 2); `checkh($bits (array_bg[2]), WB*WC); if ((dim>=2)&&(dim<=3)) begin `checkh($left (array_bg[2], dim-1), wdt+1); `checkh($right (array_bg[2], dim-1), 2 ); `checkh($low (array_bg[2], dim-1), 2 ); `checkh($high (array_bg[2], dim-1), wdt+1); `checkh($increment (array_bg[2], dim-1), 1 ); `checkh($size (array_bg[2], dim-1), wdt ); end `ifndef VERILATOR // Unsupported slices don't maintain size correctly end else if (slc==2) begin // half array `checkh($dimensions (array_bg[WA/2+1:2]), 3); `checkh($bits (array_bg[WA/2+1:2]), WA/2*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_bg[WA/2+1:2], dim), wdt+1); `checkh($right (array_bg[WA/2+1:2], dim), 2 ); `checkh($low (array_bg[WA/2+1:2], dim), 2 ); `checkh($high (array_bg[WA/2+1:2], dim), wdt+1); `checkh($increment (array_bg[WA/2+1:2], dim), 1 ); `checkh($size (array_bg[WA/2+1:2], dim), wdt); end `endif end end else if (cnt[30:4]==2) begin // little endian if (slc==0) begin // full array `checkh($dimensions (array_lt), 3); `checkh($bits (array_lt), WA*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_lt, dim), 2 ); `checkh($right (array_lt, dim), wdt+1); `checkh($low (array_lt, dim), 2 ); `checkh($high (array_lt, dim), wdt+1); `checkh($increment (array_lt, dim), -1 ); `checkh($size (array_lt, dim), wdt ); end end else if (slc==1) begin // single array element `checkh($dimensions (array_lt[2]), 2); `checkh($bits (array_lt[2]), WB*WC); if ((dim>=2)&&(dim<=3)) begin `checkh($left (array_lt[2], dim-1), 2 ); `checkh($right (array_lt[2], dim-1), wdt+1); `checkh($low (array_lt[2], dim-1), 2 ); `checkh($high (array_lt[2], dim-1), wdt+1); `checkh($increment (array_lt[2], dim-1), -1 ); `checkh($size (array_lt[2], dim-1), wdt ); end `ifndef VERILATOR // Unsupported slices don't maintain size correctly end else if (slc==2) begin // half array `checkh($dimensions (array_lt[2:WA/2+1]), 3); `checkh($bits (array_lt[2:WA/2+1]), WA/2*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_lt[2:WA/2+1], dim), 2 ); `checkh($right (array_lt[2:WA/2+1], dim), wdt+1); `checkh($low (array_lt[2:WA/2+1], dim), 2 ); `checkh($high (array_lt[2:WA/2+1], dim), wdt+1); `checkh($increment (array_lt[2:WA/2+1], dim), -1 ); `checkh($size (array_lt[2:WA/2+1], dim), wdt ); end `endif end end end endmodule
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2009 by Iztok Jeras. module t (/*AUTOARG*/ // Inputs clk ); input clk; `define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0); // parameters for array sizes localparam WA = 4; localparam WB = 6; localparam WC = 8; // 2D packed arrays logic [WA+1:2] [WB+1:2] [WC+1:2] array_bg; // big endian array /* verilator lint_off LITENDIAN */ logic [2:WA+1] [2:WB+1] [2:WC+1] array_lt; // little endian array /* verilator lint_on LITENDIAN */ logic [1:0] array_unpk [3:2][1:0]; integer cnt = 0; integer slc = 0; // slice type integer dim = 0; // dimension integer wdt = 0; // width initial begin `checkh($dimensions (array_unpk), 3); `ifndef VCS `checkh($unpacked_dimensions (array_unpk), 2); // IEEE 2009 `endif `checkh($bits (array_unpk), 2*2*2); `checkh($low (array_unpk), 2); `checkh($high (array_unpk), 3); `checkh($left (array_unpk), 3); `checkh($right(array_unpk), 2); `checkh($increment(array_unpk), 1); `checkh($size (array_unpk), 2); end // event counter always @ (posedge clk) begin cnt <= cnt + 1; end // finish report always @ (posedge clk) if ( (cnt[30:4]==3) && (cnt[3:2]==2'd3) && (cnt[1:0]==2'd3) ) begin $write("*-* All Finished *-*\n"); $finish; end integer slc_next; // calculation of dimention sizes always @ (posedge clk) begin // slicing type counter case (cnt[3:2]) 2'd0 : begin slc_next = 0; end // full array 2'd1 : begin slc_next = 1; end // single array element 2'd2 : begin slc_next = 2; end // half array default: begin slc_next = 0; end endcase slc <= slc_next; // dimension counter case (cnt[1:0]) 2'd0 : begin dim <= 1; wdt <= (slc_next==1) ? WA/2 : (slc_next==2) ? WA/2 : WA; end 2'd1 : begin dim <= 2; wdt <= WB; end 2'd2 : begin dim <= 3; wdt <= WC; end default: begin dim <= 0; wdt <= 0; end endcase end always @ (posedge clk) begin `ifdef TEST_VERBOSE $write("cnt[30:4]=%0d slc=%0d dim=%0d wdt=%0d\n", cnt[30:4], slc, dim, wdt); `endif if (cnt[30:4]==1) begin // big endian if (slc==0) begin // full array `checkh($dimensions (array_bg), 3); `checkh($bits (array_bg), WA*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_bg, dim), wdt+1); `checkh($right (array_bg, dim), 2 ); `checkh($low (array_bg, dim), 2 ); `checkh($high (array_bg, dim), wdt+1); `checkh($increment (array_bg, dim), 1 ); `checkh($size (array_bg, dim), wdt ); end end else if (slc==1) begin // single array element `checkh($dimensions (array_bg[2]), 2); `checkh($bits (array_bg[2]), WB*WC); if ((dim>=2)&&(dim<=3)) begin `checkh($left (array_bg[2], dim-1), wdt+1); `checkh($right (array_bg[2], dim-1), 2 ); `checkh($low (array_bg[2], dim-1), 2 ); `checkh($high (array_bg[2], dim-1), wdt+1); `checkh($increment (array_bg[2], dim-1), 1 ); `checkh($size (array_bg[2], dim-1), wdt ); end `ifndef VERILATOR // Unsupported slices don't maintain size correctly end else if (slc==2) begin // half array `checkh($dimensions (array_bg[WA/2+1:2]), 3); `checkh($bits (array_bg[WA/2+1:2]), WA/2*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_bg[WA/2+1:2], dim), wdt+1); `checkh($right (array_bg[WA/2+1:2], dim), 2 ); `checkh($low (array_bg[WA/2+1:2], dim), 2 ); `checkh($high (array_bg[WA/2+1:2], dim), wdt+1); `checkh($increment (array_bg[WA/2+1:2], dim), 1 ); `checkh($size (array_bg[WA/2+1:2], dim), wdt); end `endif end end else if (cnt[30:4]==2) begin // little endian if (slc==0) begin // full array `checkh($dimensions (array_lt), 3); `checkh($bits (array_lt), WA*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_lt, dim), 2 ); `checkh($right (array_lt, dim), wdt+1); `checkh($low (array_lt, dim), 2 ); `checkh($high (array_lt, dim), wdt+1); `checkh($increment (array_lt, dim), -1 ); `checkh($size (array_lt, dim), wdt ); end end else if (slc==1) begin // single array element `checkh($dimensions (array_lt[2]), 2); `checkh($bits (array_lt[2]), WB*WC); if ((dim>=2)&&(dim<=3)) begin `checkh($left (array_lt[2], dim-1), 2 ); `checkh($right (array_lt[2], dim-1), wdt+1); `checkh($low (array_lt[2], dim-1), 2 ); `checkh($high (array_lt[2], dim-1), wdt+1); `checkh($increment (array_lt[2], dim-1), -1 ); `checkh($size (array_lt[2], dim-1), wdt ); end `ifndef VERILATOR // Unsupported slices don't maintain size correctly end else if (slc==2) begin // half array `checkh($dimensions (array_lt[2:WA/2+1]), 3); `checkh($bits (array_lt[2:WA/2+1]), WA/2*WB*WC); if ((dim>=1)&&(dim<=3)) begin `checkh($left (array_lt[2:WA/2+1], dim), 2 ); `checkh($right (array_lt[2:WA/2+1], dim), wdt+1); `checkh($low (array_lt[2:WA/2+1], dim), 2 ); `checkh($high (array_lt[2:WA/2+1], dim), wdt+1); `checkh($increment (array_lt[2:WA/2+1], dim), -1 ); `checkh($size (array_lt[2:WA/2+1], dim), wdt ); end `endif end end end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: fifo_packer_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Packs 32 or 64 bit received data into a 64 bit wide FIFO. // Assumes the FIFO always has room to accommodate the data. // Author: Matt Jacobsen // History: @mattj: Version 2.0 // Additional Comments: //----------------------------------------------------------------------------- `timescale 1ns/1ns module fifo_packer_64 ( input CLK, input RST, input [63:0] DATA_IN, // Incoming data input [1:0] DATA_IN_EN, // Incoming data enable input DATA_IN_DONE, // Incoming data packet end input DATA_IN_ERR, // Incoming data error input DATA_IN_FLUSH, // End of incoming data output [63:0] PACKED_DATA, // Outgoing data output PACKED_WEN, // Outgoing data write enable output PACKED_DATA_DONE, // End of outgoing data packet output PACKED_DATA_ERR, // Error in outgoing data output PACKED_DATA_FLUSHED // End of outgoing data ); reg [1:0] rPackedCount=0, _rPackedCount=0; reg rPackedDone=0, _rPackedDone=0; reg rPackedErr=0, _rPackedErr=0; reg rPackedFlush=0, _rPackedFlush=0; reg rPackedFlushed=0, _rPackedFlushed=0; reg [95:0] rPackedData=96'd0, _rPackedData=96'd0; reg [63:0] rDataIn=64'd0, _rDataIn=64'd0; reg [1:0] rDataInEn=0, _rDataInEn=0; reg [63:0] rDataMasked=64'd0, _rDataMasked=64'd0; reg [1:0] rDataMaskedEn=0, _rDataMaskedEn=0; assign PACKED_DATA = rPackedData[63:0]; assign PACKED_WEN = rPackedCount[1]; assign PACKED_DATA_DONE = rPackedDone; assign PACKED_DATA_ERR = rPackedErr; assign PACKED_DATA_FLUSHED = rPackedFlushed; // Buffers input data until 2 words are available, then writes 2 words out. wire [63:0] wMask = {64{1'b1}}<<(32*rDataInEn); wire [63:0] wDataMasked = ~wMask & rDataIn; always @ (posedge CLK) begin rPackedCount <= #1 (RST ? 2'd0 : _rPackedCount); rPackedDone <= #1 (RST ? 1'd0 : _rPackedDone); rPackedErr <= #1 (RST ? 1'd0 : _rPackedErr); rPackedFlush <= #1 (RST ? 1'd0 : _rPackedFlush); rPackedFlushed <= #1 (RST ? 1'd0 : _rPackedFlushed); rPackedData <= #1 (RST ? 96'd0 : _rPackedData); rDataIn <= #1 _rDataIn; rDataInEn <= #1 (RST ? 2'd0 : _rDataInEn); rDataMasked <= #1 _rDataMasked; rDataMaskedEn <= #1 (RST ? 2'd0 : _rDataMaskedEn); end always @ (*) begin // Buffer and mask the input data. _rDataIn = DATA_IN; _rDataInEn = DATA_IN_EN; _rDataMasked = wDataMasked; _rDataMaskedEn = rDataInEn; // Count what's in our buffer. When we reach 2 words, 2 words will be written // out. If flush is requested, write out whatever remains. if (rPackedFlush && rPackedCount[0]) _rPackedCount = 2; else _rPackedCount = rPackedCount + rDataMaskedEn - {rPackedCount[1], 1'd0}; // Shift data into and out of our buffer as we receive and write out data. if (rDataMaskedEn != 2'd0) _rPackedData = ((rPackedData>>(32*{rPackedCount[1], 1'd0})) | (rDataMasked<<(32*rPackedCount[0]))); else _rPackedData = (rPackedData>>(32*{rPackedCount[1], 1'd0})); // Track done/error/flush signals. _rPackedDone = DATA_IN_DONE; _rPackedErr = DATA_IN_ERR; _rPackedFlush = DATA_IN_FLUSH; _rPackedFlushed = rPackedFlush; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_32.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Receives data from the rx_engine and buffers the output // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_32 #( parameter C_DATA_WIDTH = 9'd32, parameter C_MAIN_FIFO_DEPTH = 1024, parameter C_SG_FIFO_DEPTH = 512, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_MAIN_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_MAIN_FIFO_DEPTH))+1), parameter C_SG_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_SG_FIFO_DEPTH))+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B output SG_RX_BUF_RECVD, // Scatter gather RX buffer completely read (ready for next if applicable) input [31:0] SG_RX_BUF_DATA, // Scatter gather RX buffer data input SG_RX_BUF_LEN_VALID, // Scatter gather RX buffer length valid input SG_RX_BUF_ADDR_HI_VALID, // Scatter gather RX buffer high address valid input SG_RX_BUF_ADDR_LO_VALID, // Scatter gather RX buffer low address valid output SG_TX_BUF_RECVD, // Scatter gather TX buffer completely read (ready for next if applicable) input [31:0] SG_TX_BUF_DATA, // Scatter gather TX buffer data input SG_TX_BUF_LEN_VALID, // Scatter gather TX buffer length valid input SG_TX_BUF_ADDR_HI_VALID, // Scatter gather TX buffer high address valid input SG_TX_BUF_ADDR_LO_VALID, // Scatter gather TX buffer low address valid output [C_DATA_WIDTH-1:0] SG_DATA, // Scatter gather TX buffer data output SG_DATA_EMPTY, // Scatter gather TX buffer data empty input SG_DATA_REN, // Scatter gather TX buffer data read enable input SG_RST, // Scatter gather TX buffer data reset output SG_ERR, // Scatter gather TX encountered an error input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done input TXN_DONE_ACK, // Read transaction actual transfer length read output RX_REQ, // Read request input RX_REQ_ACK, // Read request accepted output [1:0] RX_REQ_TAG, // Read request data tag output [63:0] RX_REQ_ADDR, // Read request address output [9:0] RX_REQ_LEN, // Read request length input [C_DATA_WIDTH-1:0] MAIN_DATA, // Main incoming data input [C_DATA_WORD_WIDTH-1:0] MAIN_DATA_EN, // Main incoming data enable input MAIN_DONE, // Main incoming data complete input MAIN_ERR, // Main incoming data completed with error input [C_DATA_WIDTH-1:0] SG_RX_DATA, // Scatter gather for RX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_RX_DATA_EN, // Scatter gather for RX incoming data enable input SG_RX_DONE, // Scatter gather for RX incoming data complete input SG_RX_ERR, // Scatter gather for RX incoming data completed with error input [C_DATA_WIDTH-1:0] SG_TX_DATA, // Scatter gather for TX incoming data input [C_DATA_WORD_WIDTH-1:0] SG_TX_DATA_EN, // Scatter gather for TX incoming data enable input SG_TX_DONE, // Scatter gather for TX incoming data complete input SG_TX_ERR, // Scatter gather for TX incoming data completed with error input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal input CHNL_RX_ACK, // Channle read received signal output CHNL_RX_LAST, // Channel last read output [31:0] CHNL_RX_LEN, // Channel read length output [30:0] CHNL_RX_OFF, // Channel read offset output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data output CHNL_RX_DATA_VALID, // Channel read data valid input CHNL_RX_DATA_REN // Channel read data has been recieved ); `include "functions.vh" wire [C_DATA_WIDTH-1:0] wPackedMainData; wire wPackedMainWen; wire wPackedMainDone; wire wPackedMainErr; wire wMainFlush; wire wMainFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgRxData; wire wPackedSgRxWen; wire wPackedSgRxDone; wire wPackedSgRxErr; wire wSgRxFlush; wire wSgRxFlushed; wire [C_DATA_WIDTH-1:0] wPackedSgTxData; wire wPackedSgTxWen; wire wPackedSgTxDone; wire wPackedSgTxErr; wire wSgTxFlush; wire wSgTxFlushed; wire wMainDataRen; wire wMainDataEmpty; wire [C_DATA_WIDTH-1:0] wMainData; wire wSgRxRst; wire wSgRxDataRen; wire wSgRxDataEmpty; wire [C_DATA_WIDTH-1:0] wSgRxData; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgRxFifoCount; wire wSgTxRst; wire [C_SG_FIFO_DEPTH_WIDTH-1:0] wSgTxFifoCount; wire wSgRxReq; wire [63:0] wSgRxReqAddr; wire [9:0] wSgRxReqLen; wire wSgTxReq; wire [63:0] wSgTxReqAddr; wire [9:0] wSgTxReqLen; wire wSgRxReqProc; wire wSgTxReqProc; wire wMainReqProc; wire wReqAck; wire wSgElemRdy; wire wSgElemRen; wire [63:0] wSgElemAddr; wire [31:0] wSgElemLen; wire wSgRst; wire wMainReq; wire [63:0] wMainReqAddr; wire [9:0] wMainReqLen; wire wTxnErr; wire wChnlRx; wire wChnlRxRecvd; wire wChnlRxAckRecvd; wire wChnlRxLast; wire [31:0] wChnlRxLen; wire [30:0] wChnlRxOff; wire [31:0] wChnlRxConsumed; reg [4:0] rWideRst=0; reg rRst=0; assign SG_ERR = (wPackedSgTxDone & wPackedSgTxErr); // Generate a wide reset from the input reset. always @ (posedge CLK) begin rRst <= #1 rWideRst[4]; if (RST) rWideRst <= #1 5'b11111; else rWideRst <= (rWideRst<<1); end // Pack received data tightly into our FIFOs fifo_packer_32 mainFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(MAIN_DATA), .DATA_IN_EN(MAIN_DATA_EN), .DATA_IN_DONE(MAIN_DONE), .DATA_IN_ERR(MAIN_ERR), .DATA_IN_FLUSH(wMainFlush), .PACKED_DATA(wPackedMainData), .PACKED_WEN(wPackedMainWen), .PACKED_DATA_DONE(wPackedMainDone), .PACKED_DATA_ERR(wPackedMainErr), .PACKED_DATA_FLUSHED(wMainFlushed) ); fifo_packer_32 sgRxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_RX_DATA), .DATA_IN_EN(SG_RX_DATA_EN), .DATA_IN_DONE(SG_RX_DONE), .DATA_IN_ERR(SG_RX_ERR), .DATA_IN_FLUSH(wSgRxFlush), .PACKED_DATA(wPackedSgRxData), .PACKED_WEN(wPackedSgRxWen), .PACKED_DATA_DONE(wPackedSgRxDone), .PACKED_DATA_ERR(wPackedSgRxErr), .PACKED_DATA_FLUSHED(wSgRxFlushed) ); fifo_packer_32 sgTxFifoPacker ( .CLK(CLK), .RST(rRst), .DATA_IN(SG_TX_DATA), .DATA_IN_EN(SG_TX_DATA_EN), .DATA_IN_DONE(SG_TX_DONE), .DATA_IN_ERR(SG_TX_ERR), .DATA_IN_FLUSH(wSgTxFlush), .PACKED_DATA(wPackedSgTxData), .PACKED_WEN(wPackedSgTxWen), .PACKED_DATA_DONE(wPackedSgTxDone), .PACKED_DATA_ERR(wPackedSgTxErr), .PACKED_DATA_FLUSHED(wSgTxFlushed) ); // FIFOs for storing received data for the channel. (* RAM_STYLE="BLOCK" *) async_fifo_fwft #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_MAIN_FIFO_DEPTH)) mainFifo ( .WR_CLK(CLK), .WR_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .WR_EN(wPackedMainWen), .WR_DATA(wPackedMainData), .WR_FULL(), .RD_CLK(CHNL_CLK), .RD_RST(rRst | (wTxnErr & TXN_DONE) | wSgRst), .RD_EN(wMainDataRen), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgRxFifo ( .RST(rRst | wSgRxRst), .CLK(CLK), .WR_EN(wPackedSgRxWen), .WR_DATA(wPackedSgRxData), .FULL(), .RD_EN(wSgRxDataRen), .RD_DATA(wSgRxData), .EMPTY(wSgRxDataEmpty), .COUNT(wSgRxFifoCount) ); (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_DATA_WIDTH), .C_DEPTH(C_SG_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) sgTxFifo ( .RST(rRst | wSgTxRst), .CLK(CLK), .WR_EN(wPackedSgTxWen), .WR_DATA(wPackedSgTxData), .FULL(), .RD_EN(SG_DATA_REN), .RD_DATA(SG_DATA), .EMPTY(SG_DATA_EMPTY), .COUNT(wSgTxFifoCount) ); // Manage requesting and acknowledging scatter gather data. Note that // these modules will share the main requestor's RX channel. They will // take priority over the main logic's use of the RX channel. sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgRxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(wSgRst), .BUF_RECVD(SG_RX_BUF_RECVD), .BUF_DATA(SG_RX_BUF_DATA), .BUF_LEN_VALID(SG_RX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_RX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_RX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgRxFifoCount), .FIFO_FLUSH(wSgRxFlush), .FIFO_FLUSHED(wSgRxFlushed), .FIFO_RST(wSgRxRst), .RX_REQ(wSgRxReq), .RX_ADDR(wSgRxReqAddr), .RX_LEN(wSgRxReqLen), .RX_REQ_ACK(wReqAck & wSgRxReqProc), .RX_DONE(wPackedSgRxDone) ); sg_list_requester #(.C_FIFO_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_SG_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) sgTxReq ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .USER_RST(SG_RST), .BUF_RECVD(SG_TX_BUF_RECVD), .BUF_DATA(SG_TX_BUF_DATA), .BUF_LEN_VALID(SG_TX_BUF_LEN_VALID), .BUF_ADDR_HI_VALID(SG_TX_BUF_ADDR_HI_VALID), .BUF_ADDR_LO_VALID(SG_TX_BUF_ADDR_LO_VALID), .FIFO_COUNT(wSgTxFifoCount), .FIFO_FLUSH(wSgTxFlush), .FIFO_FLUSHED(wSgTxFlushed), .FIFO_RST(wSgTxRst), .RX_REQ(wSgTxReq), .RX_ADDR(wSgTxReqAddr), .RX_LEN(wSgTxReqLen), .RX_REQ_ACK(wReqAck & wSgTxReqProc), .RX_DONE(wPackedSgTxDone) ); // A read requester for the channel and scatter gather requesters. rx_port_requester_mux requesterMux ( .RST(rRst), .CLK(CLK), .SG_RX_REQ(wSgRxReq), .SG_RX_LEN(wSgRxReqLen), .SG_RX_ADDR(wSgRxReqAddr), .SG_RX_REQ_PROC(wSgRxReqProc), .SG_TX_REQ(wSgTxReq), .SG_TX_LEN(wSgTxReqLen), .SG_TX_ADDR(wSgTxReqAddr), .SG_TX_REQ_PROC(wSgTxReqProc), .MAIN_REQ(wMainReq), .MAIN_LEN(wMainReqLen), .MAIN_ADDR(wMainReqAddr), .MAIN_REQ_PROC(wMainReqProc), .RX_REQ(RX_REQ), .RX_REQ_ACK(RX_REQ_ACK), .RX_REQ_TAG(RX_REQ_TAG), .RX_REQ_ADDR(RX_REQ_ADDR), .RX_REQ_LEN(RX_REQ_LEN), .REQ_ACK(wReqAck) ); // Read the scatter gather buffer address and length, continuously so that // we have it ready whenever the next buffer is needed. sg_list_reader_32 #(.C_DATA_WIDTH(C_DATA_WIDTH)) sgListReader ( .CLK(CLK), .RST(rRst | wSgRst), .BUF_DATA(wSgRxData), .BUF_DATA_EMPTY(wSgRxDataEmpty), .BUF_DATA_REN(wSgRxDataRen), .VALID(wSgElemRdy), .EMPTY(), .REN(wSgElemRen), .ADDR(wSgElemAddr), .LEN(wSgElemLen) ); // Main port reader logic rx_port_reader #(.C_DATA_WIDTH(C_DATA_WIDTH), .C_FIFO_DEPTH(C_MAIN_FIFO_DEPTH), .C_MAX_READ_REQ(C_MAX_READ_REQ)) reader ( .CLK(CLK), .RST(rRst), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .TXN_DATA(TXN_DATA), .TXN_LEN_VALID(TXN_LEN_VALID), .TXN_OFF_LAST_VALID(TXN_OFF_LAST_VALID), .TXN_DONE_LEN(TXN_DONE_LEN), .TXN_DONE(TXN_DONE), .TXN_ERR(wTxnErr), .TXN_DONE_ACK(TXN_DONE_ACK), .TXN_DATA_FLUSH(wMainFlush), .TXN_DATA_FLUSHED(wMainFlushed), .RX_REQ(wMainReq), .RX_ADDR(wMainReqAddr), .RX_LEN(wMainReqLen), .RX_REQ_ACK(wReqAck & wMainReqProc), .RX_DATA_EN(MAIN_DATA_EN), .RX_DONE(wPackedMainDone), .RX_ERR(wPackedMainErr), .SG_DONE(wPackedSgRxDone), .SG_ERR(wPackedSgRxErr), .SG_ELEM_ADDR(wSgElemAddr), .SG_ELEM_LEN(wSgElemLen), .SG_ELEM_RDY(wSgElemRdy), .SG_ELEM_REN(wSgElemRen), .SG_RST(wSgRst), .CHNL_RX(wChnlRx), .CHNL_RX_LEN(wChnlRxLen), .CHNL_RX_LAST(wChnlRxLast), .CHNL_RX_OFF(wChnlRxOff), .CHNL_RX_RECVD(wChnlRxRecvd), .CHNL_RX_ACK_RECVD(wChnlRxAckRecvd), .CHNL_RX_CONSUMED(wChnlRxConsumed) ); // Manage the CHNL_RX* signals in the CHNL_CLK domain. rx_port_channel_gate #(.C_DATA_WIDTH(C_DATA_WIDTH)) gate ( .RST(rRst), .CLK(CLK), .RX(wChnlRx), .RX_RECVD(wChnlRxRecvd), .RX_ACK_RECVD(wChnlRxAckRecvd), .RX_LAST(wChnlRxLast), .RX_LEN(wChnlRxLen), .RX_OFF(wChnlRxOff), .RX_CONSUMED(wChnlRxConsumed), .RD_DATA(wMainData), .RD_EMPTY(wMainDataEmpty), .RD_EN(wMainDataRen), .CHNL_CLK(CHNL_CLK), .CHNL_RX(CHNL_RX), .CHNL_RX_ACK(CHNL_RX_ACK), .CHNL_RX_LAST(CHNL_RX_LAST), .CHNL_RX_LEN(CHNL_RX_LEN), .CHNL_RX_OFF(CHNL_RX_OFF), .CHNL_RX_DATA(CHNL_RX_DATA), .CHNL_RX_DATA_VALID(CHNL_RX_DATA_VALID), .CHNL_RX_DATA_REN(CHNL_RX_DATA_REN) ); /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({SG_RX_DATA_EN != 0, wSgElemRen, wMainReq | wSgRxReq | wSgTxReq, RX_REQ, SG_RX_BUF_ADDR_LO_VALID | SG_RX_BUF_ADDR_HI_VALID | SG_RX_BUF_LEN_VALID, wSgRst, wTxnErr | wPackedSgRxDone | wSgRxFlush | wSgRxFlushed, TXN_OFF_LAST_VALID | TXN_LEN_VALID}), .DATA({ wPackedSgRxErr, // 1 wPackedSgRxDone, // 1 wPackedSgRxWen, // 1 wPackedSgRxData, // 64 SG_RX_ERR, // 1 SG_RX_DONE, // 1 SG_RX_DATA_EN, // 2 SG_RX_DATA, // 64 wSgRxDataRen, // 1 wSgRxDataEmpty, // 1 wSgRxData, // 64 wSgRst, // 1 SG_RST, // 1 wPackedSgRxDone, // 1 wSgRxRst, // 1 wSgRxFlushed, // 1 wSgRxFlush, // 1 SG_RX_BUF_ADDR_LO_VALID, // 1 SG_RX_BUF_ADDR_HI_VALID, // 1 SG_RX_BUF_LEN_VALID, // 1 SG_RX_BUF_DATA, // 32 RX_REQ_ADDR, // 64 RX_REQ_TAG, // 2 RX_REQ_ACK, // 1 RX_REQ, // 1 wSgTxReqProc, // 1 wSgTxReqAddr, // 64 wSgTxReq, // 1 wSgRxReqProc, // 1 wSgRxReqAddr, // 64 wSgRxReq, // 1 wMainReqProc, // 1 wMainReqAddr, // 64 wMainReq, // 1 wReqAck, // 1 wTxnErr, // 1 TXN_OFF_LAST_VALID, // 1 TXN_LEN_VALID}) // 1 ); */ endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : ecc_gen.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** `timescale 1ps/1ps // Generate the ecc code. Note that the synthesizer should // generate this as a static logic. Code in this block should // never run during simulation phase, or directly impact timing. // // The code generated is a single correct, double detect code. // It is the classic Hamming code. Instead, the code is // optimized for minimal/balanced tree depth and size. See // Hsiao IBM Technial Journal 1970. // // The code is returned as a single bit vector, h_rows. This was // the only way to "subroutinize" this with the restrictions of // disallowed include files and that matrices cannot be passed // in ports. // // Factorial and the combos functions are defined. Combos // simply computes the number of combinations from the set // size and elements at a time. // // The function next_combo computes the next combination in // lexicographical order given the "current" combination. Its // output is undefined if given the last combination in the // lexicographical order. // // next_combo is insensitive to the number of elements in the // combinations. // // An H transpose matrix is generated because that's the easiest // way to do it. The H transpose matrix is generated by taking // the one at a time combinations, then the 3 at a time, then // the 5 at a time. The number combinations used is equal to // the width of the code (CODE_WIDTH). The boundaries between // the 1, 3 and 5 groups are hardcoded in the for loop. // // At the same time the h_rows vector is generated from the // H transpose matrix. module mig_7series_v1_9_ecc_gen #( parameter CODE_WIDTH = 72, parameter ECC_WIDTH = 8, parameter DATA_WIDTH = 64 ) ( /*AUTOARG*/ // Outputs h_rows ); function integer factorial (input integer i); integer index; if (i == 1) factorial = 1; else begin factorial = 1; for (index=2; index<=i; index=index+1) factorial = factorial * index; end endfunction // factorial function integer combos (input integer n, k); combos = factorial(n)/(factorial(k)*factorial(n-k)); endfunction // combinations // function next_combo // Given a combination, return the next combo in lexicographical // order. Scans from right to left. Assumes the first combination // is k ones all of the way to the left. // // Upon entry, initialize seen0, trig1, and ones. "seen0" means // that a zero has been observed while scanning from right to left. // "trig1" means that a one have been observed _after_ seen0 is set. // "ones" counts the number of ones observed while scanning the input. // // If trig1 is one, just copy the input bit to the output and increment // to the next bit. Otherwise set the the output bit to zero, if the // input is a one, increment ones. If the input bit is a one and seen0 // is true, dump out the accumulated ones. Set seen0 to the complement // of the input bit. Note that seen0 is not used subsequent to trig1 // getting set. function [ECC_WIDTH-1:0] next_combo (input [ECC_WIDTH-1:0] i); integer index; integer dump_index; reg seen0; reg trig1; // integer ones; reg [ECC_WIDTH-1:0] ones; begin seen0 = 1'b0; trig1 = 1'b0; ones = 0; for (index=0; index<ECC_WIDTH; index=index+1) begin // The "== 1'bx" is so this will converge at time zero. // XST assumes false, which should be OK. if ((&i == 1'bx) || trig1) next_combo[index] = i[index]; else begin next_combo[index] = 1'b0; ones = ones + i[index]; if (i[index] && seen0) begin trig1 = 1'b1; for (dump_index=index-1; dump_index>=0;dump_index=dump_index-1) if (dump_index>=index-ones) next_combo[dump_index] = 1'b1; end seen0 = ~i[index]; end // else: !if(trig1) end end // function endfunction // next_combo wire [ECC_WIDTH-1:0] ht_matrix [CODE_WIDTH-1:0]; output wire [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; localparam COMBOS_3 = combos(ECC_WIDTH, 3); localparam COMBOS_5 = combos(ECC_WIDTH, 5); genvar n; genvar s; generate for (n=0; n<CODE_WIDTH; n=n+1) begin : ht if (n == 0) assign ht_matrix[n] = {{3{1'b1}}, {ECC_WIDTH-3{1'b0}}}; else if (n == COMBOS_3 && n < DATA_WIDTH) assign ht_matrix[n] = {{5{1'b1}}, {ECC_WIDTH-5{1'b0}}}; else if ((n == COMBOS_3+COMBOS_5) && n < DATA_WIDTH) assign ht_matrix[n] = {{7{1'b1}}, {ECC_WIDTH-7{1'b0}}}; else if (n == DATA_WIDTH) assign ht_matrix[n] = {{1{1'b1}}, {ECC_WIDTH-1{1'b0}}}; else assign ht_matrix[n] = next_combo(ht_matrix[n-1]); for (s=0; s<ECC_WIDTH; s=s+1) begin : h_row assign h_rows[s*CODE_WIDTH+n] = ht_matrix[n][s]; end end endgenerate endmodule // ecc_gen
/*********************************************************** -- (c) Copyright 2010 - 2013 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). A Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. // // // Owner: Gary Martin // Revision: $Id: //depot/icm/proj/common/head/rtl/v32_cmt/rtl/phy/byte_lane.v#4 $ // $Author: gary $ // $DateTime: 2010/05/11 18:05:17 $ // $Change: 490882 $ // Description: // This verilog file is a parameterizable single 10 or 12 bit byte lane. // // History: // Date Engineer Description // 04/01/2010 G. Martin Initial Checkin. // //////////////////////////////////////////////////////////// ***********************************************************/ `timescale 1ps/1ps //`include "phy.vh" module mig_7series_v1_9_ddr_byte_lane #( // these are used to scale the index into phaser,calib,scan,mc vectors // to access fields used in this instance parameter ABCD = "A", // A,B,C, or D parameter PO_DATA_CTL = "FALSE", parameter BITLANES = 12'b1111_1111_1111, parameter BITLANES_OUTONLY = 12'b1111_1111_1111, parameter BYTELANES_DDR_CK = 24'b0010_0010_0010_0010_0010_0010, parameter RCLK_SELECT_LANE = "B", parameter PC_CLK_RATIO = 4, parameter USE_PRE_POST_FIFO = "FALSE", //OUT_FIFO parameter OF_ALMOST_EMPTY_VALUE = 1, parameter OF_ALMOST_FULL_VALUE = 1, parameter OF_ARRAY_MODE = "UNDECLARED", parameter OF_OUTPUT_DISABLE = "FALSE", parameter OF_SYNCHRONOUS_MODE = "TRUE", //IN_FIFO parameter IF_ALMOST_EMPTY_VALUE = 1, parameter IF_ALMOST_FULL_VALUE = 1, parameter IF_ARRAY_MODE = "UNDECLARED", parameter IF_SYNCHRONOUS_MODE = "TRUE", //PHASER_IN parameter PI_BURST_MODE = "TRUE", parameter PI_CLKOUT_DIV = 2, parameter PI_FREQ_REF_DIV = "NONE", parameter PI_FINE_DELAY = 1, parameter PI_OUTPUT_CLK_SRC = "DELAYED_REF" , //"DELAYED_REF", parameter PI_SEL_CLK_OFFSET = 0, parameter PI_SYNC_IN_DIV_RST = "FALSE", //PHASER_OUT parameter PO_CLKOUT_DIV = (PO_DATA_CTL == "FALSE") ? 4 : 2, parameter PO_FINE_DELAY = 0, parameter PO_COARSE_BYPASS = "FALSE", parameter PO_COARSE_DELAY = 0, parameter PO_OCLK_DELAY = 0, parameter PO_OCLKDELAY_INV = "TRUE", parameter PO_OUTPUT_CLK_SRC = "DELAYED_REF", parameter PO_SYNC_IN_DIV_RST = "FALSE", // OSERDES parameter OSERDES_DATA_RATE = "DDR", parameter OSERDES_DATA_WIDTH = 4, //IDELAY parameter IDELAYE2_IDELAY_TYPE = "VARIABLE", parameter IDELAYE2_IDELAY_VALUE = 00, parameter IODELAY_GRP = "IODELAY_MIG", parameter BANK_TYPE = "HP_IO", // # = "HP_IO", "HPL_IO", "HR_IO", "HRL_IO" parameter real TCK = 0.00, parameter SYNTHESIS = "FALSE", // local constants, do not pass in from above parameter BUS_WIDTH = 12, parameter MSB_BURST_PEND_PO = 3, parameter MSB_BURST_PEND_PI = 7, parameter MSB_RANK_SEL_I = MSB_BURST_PEND_PI + 8, parameter PHASER_CTL_BUS_WIDTH = MSB_RANK_SEL_I + 1 ,parameter CKE_ODT_AUX = "FALSE" )( input rst, input phy_clk, input freq_refclk, input mem_refclk, input idelayctrl_refclk, input sync_pulse, output [BUS_WIDTH-1:0] mem_dq_out, output [BUS_WIDTH-1:0] mem_dq_ts, input [9:0] mem_dq_in, output mem_dqs_out, output mem_dqs_ts, input mem_dqs_in, output [11:0] ddr_ck_out, output rclk, input if_empty_def, output if_a_empty, output if_empty, output if_a_full, output if_full, output of_a_empty, output of_empty, output of_a_full, output of_full, output pre_fifo_a_full, output [79:0] phy_din, input [79:0] phy_dout, input phy_cmd_wr_en, input phy_data_wr_en, input phy_rd_en, input [PHASER_CTL_BUS_WIDTH-1:0] phaser_ctl_bus, input idelay_inc, input idelay_ce, input idelay_ld, input if_rst, input [2:0] byte_rd_en_oth_lanes, input [1:0] byte_rd_en_oth_banks, output byte_rd_en, output po_coarse_overflow, output po_fine_overflow, output [8:0] po_counter_read_val, input po_fine_enable, input po_coarse_enable, input [1:0] po_en_calib, input po_fine_inc, input po_coarse_inc, input po_counter_load_en, input po_counter_read_en, input po_sel_fine_oclk_delay, input [8:0] po_counter_load_val, input [1:0] pi_en_calib, input pi_rst_dqs_find, input pi_fine_enable, input pi_fine_inc, input pi_counter_load_en, input pi_counter_read_en, input [5:0] pi_counter_load_val, output wire pi_iserdes_rst, output pi_phase_locked, output pi_fine_overflow, output [5:0] pi_counter_read_val, output wire pi_dqs_found, output dqs_out_of_range ); localparam PHASER_INDEX = (ABCD=="B" ? 1 : (ABCD == "C") ? 2 : (ABCD == "D" ? 3 : 0)); localparam L_OF_ARRAY_MODE = (OF_ARRAY_MODE != "UNDECLARED") ? OF_ARRAY_MODE : (PO_DATA_CTL == "FALSE" || PC_CLK_RATIO == 2) ? "ARRAY_MODE_4_X_4" : "ARRAY_MODE_8_X_4"; localparam L_IF_ARRAY_MODE = (IF_ARRAY_MODE != "UNDECLARED") ? IF_ARRAY_MODE : (PC_CLK_RATIO == 2) ? "ARRAY_MODE_4_X_4" : "ARRAY_MODE_4_X_8"; localparam L_OSERDES_DATA_RATE = (OSERDES_DATA_RATE != "UNDECLARED") ? OSERDES_DATA_RATE : ((PO_DATA_CTL == "FALSE" && PC_CLK_RATIO == 4) ? "SDR" : "DDR") ; localparam L_OSERDES_DATA_WIDTH = (OSERDES_DATA_WIDTH != "UNDECLARED") ? OSERDES_DATA_WIDTH : 4; localparam real L_FREQ_REF_PERIOD_NS = TCK > 2500.0 ? (TCK/(PI_FREQ_REF_DIV == "DIV2" ? 2 : 1)/1000.0) : TCK/1000.0; localparam real L_MEM_REF_PERIOD_NS = TCK/1000.0; localparam real L_PHASE_REF_PERIOD_NS = TCK/1000.0; localparam ODDR_CLK_EDGE = "SAME_EDGE"; localparam PO_DCD_CORRECTION = "ON"; localparam [2:0] PO_DCD_SETTING = (PO_DCD_CORRECTION == "ON") ? 3'b111 : 3'b000; localparam DQS_AUTO_RECAL = (BANK_TYPE == "HR_IO" || BANK_TYPE == "HRL_IO" || (BANK_TYPE == "HPL_IO" && TCK > 2500)) ? 1 : 0; localparam DQS_FIND_PATTERN = (BANK_TYPE == "HR_IO" || BANK_TYPE == "HRL_IO" || (BANK_TYPE == "HPL_IO" && TCK > 2500)) ? "001" : "000"; wire [1:0] oserdes_dqs; wire [1:0] oserdes_dqs_ts; wire [1:0] oserdes_dq_ts; wire [3:0] of_q9; wire [3:0] of_q8; wire [3:0] of_q7; wire [7:0] of_q6; wire [7:0] of_q5; wire [3:0] of_q4; wire [3:0] of_q3; wire [3:0] of_q2; wire [3:0] of_q1; wire [3:0] of_q0; wire [7:0] of_d9; wire [7:0] of_d8; wire [7:0] of_d7; wire [7:0] of_d6; wire [7:0] of_d5; wire [7:0] of_d4; wire [7:0] of_d3; wire [7:0] of_d2; wire [7:0] of_d1; wire [7:0] of_d0; wire [7:0] if_q9; wire [7:0] if_q8; wire [7:0] if_q7; wire [7:0] if_q6; wire [7:0] if_q5; wire [7:0] if_q4; wire [7:0] if_q3; wire [7:0] if_q2; wire [7:0] if_q1; wire [7:0] if_q0; wire [3:0] if_d9; wire [3:0] if_d8; wire [3:0] if_d7; wire [3:0] if_d6; wire [3:0] if_d5; wire [3:0] if_d4; wire [3:0] if_d3; wire [3:0] if_d2; wire [3:0] if_d1; wire [3:0] if_d0; wire [3:0] dummy_i5; wire [3:0] dummy_i6; wire [48-1:0] of_dqbus; wire [10*4-1:0] iserdes_dout; wire iserdes_clk; wire iserdes_clkdiv; wire ififo_wr_enable; wire phy_rd_en_; wire dqs_to_phaser; wire phy_wr_en = ( PO_DATA_CTL == "FALSE" ) ? phy_cmd_wr_en : phy_data_wr_en; wire if_empty_; wire if_a_empty_; wire if_full_; wire if_a_full_; wire po_oserdes_rst; wire empty_post_fifo; (* keep = "true", max_fanout = 3 *) reg [3:0] if_empty_r /* synthesis syn_maxfan = 3 */; wire [79:0] rd_data; reg [79:0] rd_data_r; ///////////////////////////////////////////////////////////////////////// ///This is a temporary fix until we get a proper fix for CR#638064/////// ///////////////////////////////////////////////////////////////////////// reg ififo_rst = 1'b1; reg ofifo_rst = 1'b1; ///////////////////////////////////////////////////////////////////////// wire of_wren_pre; wire [79:0] pre_fifo_dout; wire pre_fifo_full; wire pre_fifo_rden; wire [5:0] ddr_ck_out_q; (* keep = "true", max_fanout = 10 *) wire ififo_rd_en_in /* synthesis syn_maxfan = 10 */; always @(posedge phy_clk) begin ififo_rst <= #1 pi_rst_dqs_find | if_rst ; // reset only data o-fifos on reset of dqs_found ofifo_rst <= #1 (pi_rst_dqs_find & PO_DATA_CTL == "TRUE") | rst; end // IN_FIFO EMPTY->RDEN TIMING FIX: // Always read from IN_FIFO - it doesn't hurt to read from an empty FIFO // since the IN_FIFO read pointers are not incr'ed when the FIFO is empty assign #(25) phy_rd_en_ = 1'b1; //assign #(25) phy_rd_en_ = phy_rd_en; generate if ( PO_DATA_CTL == "FALSE" ) begin : if_empty_null assign if_empty = 0; assign if_a_empty = 0; assign if_full = 0; assign if_a_full = 0; end else begin : if_empty_gen assign if_empty = empty_post_fifo; assign if_a_empty = if_a_empty_; assign if_full = if_full_; assign if_a_full = if_a_full_; end endgenerate generate if ( PO_DATA_CTL == "FALSE" ) begin : dq_gen_48 assign of_dqbus[48-1:0] = {of_q6[7:4], of_q5[7:4], of_q9, of_q8, of_q7, of_q6[3:0], of_q5[3:0], of_q4, of_q3, of_q2, of_q1, of_q0}; assign phy_din = 80'h0; assign byte_rd_en = 1'b1; end else begin : dq_gen_40 assign of_dqbus[40-1:0] = {of_q9, of_q8, of_q7, of_q6[3:0], of_q5[3:0], of_q4, of_q3, of_q2, of_q1, of_q0}; assign ififo_rd_en_in = !if_empty_def ? ((&byte_rd_en_oth_banks) && (&byte_rd_en_oth_lanes) && byte_rd_en) : ((|byte_rd_en_oth_banks) || (|byte_rd_en_oth_lanes) || byte_rd_en); if (USE_PRE_POST_FIFO == "TRUE") begin : if_post_fifo_gen // IN_FIFO EMPTY->RDEN TIMING FIX: assign rd_data = {if_q9, if_q8, if_q7, if_q6, if_q5, if_q4, if_q3, if_q2, if_q1, if_q0}; always @(posedge phy_clk) begin rd_data_r <= #(025) rd_data; if_empty_r[0] <= #(025) if_empty_; if_empty_r[1] <= #(025) if_empty_; if_empty_r[2] <= #(025) if_empty_; if_empty_r[3] <= #(025) if_empty_; end mig_7series_v1_9_ddr_if_post_fifo # ( .TCQ (25), // simulation CK->Q delay .DEPTH (4), //2 // depth - account for up to 2 cycles of skew .WIDTH (80) // width ) u_ddr_if_post_fifo ( .clk (phy_clk), .rst (ififo_rst), .empty_in (if_empty_r), .rd_en_in (ififo_rd_en_in), .d_in (rd_data_r), .empty_out (empty_post_fifo), .byte_rd_en (byte_rd_en), .d_out (phy_din) ); end else begin : phy_din_gen assign phy_din = {if_q9, if_q8, if_q7, if_q6, if_q5, if_q4, if_q3, if_q2, if_q1, if_q0}; assign empty_post_fifo = if_empty_; end end endgenerate assign { if_d9, if_d8, if_d7, if_d6, if_d5, if_d4, if_d3, if_d2, if_d1, if_d0} = iserdes_dout; wire [1:0] rank_sel_i = ((phaser_ctl_bus[MSB_RANK_SEL_I :MSB_RANK_SEL_I -7] >> (PHASER_INDEX << 1)) & 2'b11); generate if ( USE_PRE_POST_FIFO == "TRUE" ) begin : of_pre_fifo_gen assign {of_d9, of_d8, of_d7, of_d6, of_d5, of_d4, of_d3, of_d2, of_d1, of_d0} = pre_fifo_dout; mig_7series_v1_9_ddr_of_pre_fifo # ( .TCQ (25), // simulation CK->Q delay .DEPTH (9), // depth - set to 9 to accommodate flow control .WIDTH (80) // width ) u_ddr_of_pre_fifo ( .clk (phy_clk), ///////////////////////////////////////////////////////////////////////// ///This is a temporary fix until we get a proper fix for CR#638064/////// ///////////////////////////////////////////////////////////////////////// .rst (ofifo_rst), ///////////////////////////////////////////////////////////////////////// .full_in (of_full), .wr_en_in (phy_wr_en), .d_in (phy_dout), .wr_en_out (of_wren_pre), .d_out (pre_fifo_dout), .afull (pre_fifo_a_full) ); end else begin // wire direct to ofifo assign {of_d9, of_d8, of_d7, of_d6, of_d5, of_d4, of_d3, of_d2, of_d1, of_d0} = phy_dout; assign of_wren_pre = phy_wr_en; end endgenerate generate if ( PO_DATA_CTL == "TRUE" || ((RCLK_SELECT_LANE==ABCD) && (CKE_ODT_AUX =="TRUE"))) begin : phaser_in_gen PHASER_IN_PHY #( .BURST_MODE ( PI_BURST_MODE), .CLKOUT_DIV ( PI_CLKOUT_DIV), .DQS_AUTO_RECAL ( DQS_AUTO_RECAL), .DQS_FIND_PATTERN ( DQS_FIND_PATTERN), .SEL_CLK_OFFSET ( PI_SEL_CLK_OFFSET), .FINE_DELAY ( PI_FINE_DELAY), .FREQ_REF_DIV ( PI_FREQ_REF_DIV), .OUTPUT_CLK_SRC ( PI_OUTPUT_CLK_SRC), .SYNC_IN_DIV_RST ( PI_SYNC_IN_DIV_RST), .REFCLK_PERIOD ( L_FREQ_REF_PERIOD_NS), .MEMREFCLK_PERIOD ( L_MEM_REF_PERIOD_NS), .PHASEREFCLK_PERIOD ( L_PHASE_REF_PERIOD_NS) ) phaser_in ( .DQSFOUND (pi_dqs_found), .DQSOUTOFRANGE (dqs_out_of_range), .FINEOVERFLOW (pi_fine_overflow), .PHASELOCKED (pi_phase_locked), .ISERDESRST (pi_iserdes_rst), .ICLKDIV (iserdes_clkdiv), .ICLK (iserdes_clk), .COUNTERREADVAL (pi_counter_read_val), .RCLK (rclk), .WRENABLE (ififo_wr_enable), .BURSTPENDINGPHY (phaser_ctl_bus[MSB_BURST_PEND_PI - 3 + PHASER_INDEX]), .ENCALIBPHY (pi_en_calib), .FINEENABLE (pi_fine_enable), .FREQREFCLK (freq_refclk), .MEMREFCLK (mem_refclk), .RANKSELPHY (rank_sel_i), .PHASEREFCLK (dqs_to_phaser), .RSTDQSFIND (pi_rst_dqs_find), .RST (rst), .FINEINC (pi_fine_inc), .COUNTERLOADEN (pi_counter_load_en), .COUNTERREADEN (pi_counter_read_en), .COUNTERLOADVAL (pi_counter_load_val), .SYNCIN (sync_pulse), .SYSCLK (phy_clk) ); end else begin assign pi_dqs_found = 1'b1; assign pi_dqs_out_of_range = 1'b0; assign pi_phase_locked = 1'b1; end endgenerate wire #0 phase_ref = freq_refclk; wire oserdes_clk; PHASER_OUT_PHY #( .CLKOUT_DIV ( PO_CLKOUT_DIV), .DATA_CTL_N ( PO_DATA_CTL ), .FINE_DELAY ( PO_FINE_DELAY), .COARSE_BYPASS ( PO_COARSE_BYPASS ), .COARSE_DELAY ( PO_COARSE_DELAY), .OCLK_DELAY ( PO_OCLK_DELAY), .OCLKDELAY_INV ( PO_OCLKDELAY_INV), .OUTPUT_CLK_SRC ( PO_OUTPUT_CLK_SRC), .SYNC_IN_DIV_RST ( PO_SYNC_IN_DIV_RST), .REFCLK_PERIOD ( L_FREQ_REF_PERIOD_NS), .PHASEREFCLK_PERIOD ( 1), // dummy, not used .PO ( PO_DCD_SETTING ), .MEMREFCLK_PERIOD ( L_MEM_REF_PERIOD_NS) ) phaser_out ( .COARSEOVERFLOW (po_coarse_overflow), .CTSBUS (oserdes_dqs_ts), .DQSBUS (oserdes_dqs), .DTSBUS (oserdes_dq_ts), .FINEOVERFLOW (po_fine_overflow), .OCLKDIV (oserdes_clkdiv), .OCLK (oserdes_clk), .OCLKDELAYED (oserdes_clk_delayed), .COUNTERREADVAL (po_counter_read_val), .BURSTPENDINGPHY (phaser_ctl_bus[MSB_BURST_PEND_PO -3 + PHASER_INDEX]), .ENCALIBPHY (po_en_calib), .RDENABLE (po_rd_enable), .FREQREFCLK (freq_refclk), .MEMREFCLK (mem_refclk), .PHASEREFCLK (/*phase_ref*/), .RST (rst), .OSERDESRST (po_oserdes_rst), .COARSEENABLE (po_coarse_enable), .FINEENABLE (po_fine_enable), .COARSEINC (po_coarse_inc), .FINEINC (po_fine_inc), .SELFINEOCLKDELAY (po_sel_fine_oclk_delay), .COUNTERLOADEN (po_counter_load_en), .COUNTERREADEN (po_counter_read_en), .COUNTERLOADVAL (po_counter_load_val), .SYNCIN (sync_pulse), .SYSCLK (phy_clk) ); generate if (PO_DATA_CTL == "TRUE") begin : in_fifo_gen IN_FIFO #( .ALMOST_EMPTY_VALUE ( IF_ALMOST_EMPTY_VALUE ), .ALMOST_FULL_VALUE ( IF_ALMOST_FULL_VALUE ), .ARRAY_MODE ( L_IF_ARRAY_MODE), .SYNCHRONOUS_MODE ( IF_SYNCHRONOUS_MODE) ) in_fifo ( .ALMOSTEMPTY (if_a_empty_), .ALMOSTFULL (if_a_full_), .EMPTY (if_empty_), .FULL (if_full_), .Q0 (if_q0), .Q1 (if_q1), .Q2 (if_q2), .Q3 (if_q3), .Q4 (if_q4), .Q5 (if_q5), .Q6 (if_q6), .Q7 (if_q7), .Q8 (if_q8), .Q9 (if_q9), //=== .D0 (if_d0), .D1 (if_d1), .D2 (if_d2), .D3 (if_d3), .D4 (if_d4), .D5 ({dummy_i5,if_d5}), .D6 ({dummy_i6,if_d6}), .D7 (if_d7), .D8 (if_d8), .D9 (if_d9), .RDCLK (phy_clk), .RDEN (phy_rd_en_), .RESET (ififo_rst), .WRCLK (iserdes_clkdiv), .WREN (ififo_wr_enable) ); end endgenerate OUT_FIFO #( .ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .ARRAY_MODE (L_OF_ARRAY_MODE), .OUTPUT_DISABLE (OF_OUTPUT_DISABLE), .SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE) ) out_fifo ( .ALMOSTEMPTY (of_a_empty), .ALMOSTFULL (of_a_full), .EMPTY (of_empty), .FULL (of_full), .Q0 (of_q0), .Q1 (of_q1), .Q2 (of_q2), .Q3 (of_q3), .Q4 (of_q4), .Q5 (of_q5), .Q6 (of_q6), .Q7 (of_q7), .Q8 (of_q8), .Q9 (of_q9), .D0 (of_d0), .D1 (of_d1), .D2 (of_d2), .D3 (of_d3), .D4 (of_d4), .D5 (of_d5), .D6 (of_d6), .D7 (of_d7), .D8 (of_d8), .D9 (of_d9), .RDCLK (oserdes_clkdiv), .RDEN (po_rd_enable), .RESET (ofifo_rst), .WRCLK (phy_clk), .WREN (of_wren_pre) ); mig_7series_v1_9_ddr_byte_group_io # ( .PO_DATA_CTL (PO_DATA_CTL), .BITLANES (BITLANES), .BITLANES_OUTONLY (BITLANES_OUTONLY), .OSERDES_DATA_RATE (L_OSERDES_DATA_RATE), .OSERDES_DATA_WIDTH (L_OSERDES_DATA_WIDTH), .IODELAY_GRP (IODELAY_GRP), .IDELAYE2_IDELAY_TYPE (IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (IDELAYE2_IDELAY_VALUE), .SYNTHESIS (SYNTHESIS) ) ddr_byte_group_io ( .mem_dq_out (mem_dq_out), .mem_dq_ts (mem_dq_ts), .mem_dq_in (mem_dq_in), .mem_dqs_in (mem_dqs_in), .mem_dqs_out (mem_dqs_out), .mem_dqs_ts (mem_dqs_ts), .rst (rst), .oserdes_rst (po_oserdes_rst), .iserdes_rst (pi_iserdes_rst ), .iserdes_dout (iserdes_dout), .dqs_to_phaser (dqs_to_phaser), .phy_clk (phy_clk), .iserdes_clk (iserdes_clk), .iserdes_clkb (!iserdes_clk), .iserdes_clkdiv (iserdes_clkdiv), .idelay_inc (idelay_inc), .idelay_ce (idelay_ce), .idelay_ld (idelay_ld), .idelayctrl_refclk (idelayctrl_refclk), .oserdes_clk (oserdes_clk), .oserdes_clk_delayed (oserdes_clk_delayed), .oserdes_clkdiv (oserdes_clkdiv), .oserdes_dqs ({oserdes_dqs[1], oserdes_dqs[0]}), .oserdes_dqsts ({oserdes_dqs_ts[1], oserdes_dqs_ts[0]}), .oserdes_dq (of_dqbus), .oserdes_dqts ({oserdes_dq_ts[1], oserdes_dq_ts[0]}) ); genvar i; generate for (i = 0; i <= 5; i = i+1) begin : ddr_ck_gen_loop if (PO_DATA_CTL== "FALSE" && (BYTELANES_DDR_CK[i*4+PHASER_INDEX])) begin : ddr_ck_gen ODDR #(.DDR_CLK_EDGE (ODDR_CLK_EDGE)) ddr_ck ( .C (oserdes_clk), .R (1'b0), .S (), .D1 (1'b0), .D2 (1'b1), .CE (1'b1), .Q (ddr_ck_out_q[i]) ); OBUFDS ddr_ck_obuf (.I(ddr_ck_out_q[i]), .O(ddr_ck_out[i*2]), .OB(ddr_ck_out[i*2+1])); end // ddr_ck_gen else begin : ddr_ck_null assign ddr_ck_out[i*2+1:i*2] = 2'b0; end end // ddr_ck_gen_loop endgenerate endmodule // byte_lane
/*********************************************************** -- (c) Copyright 2010 - 2013 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). A Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. // // // Owner: Gary Martin // Revision: $Id: //depot/icm/proj/common/head/rtl/v32_cmt/rtl/phy/byte_lane.v#4 $ // $Author: gary $ // $DateTime: 2010/05/11 18:05:17 $ // $Change: 490882 $ // Description: // This verilog file is a parameterizable single 10 or 12 bit byte lane. // // History: // Date Engineer Description // 04/01/2010 G. Martin Initial Checkin. // //////////////////////////////////////////////////////////// ***********************************************************/ `timescale 1ps/1ps //`include "phy.vh" module mig_7series_v1_9_ddr_byte_lane #( // these are used to scale the index into phaser,calib,scan,mc vectors // to access fields used in this instance parameter ABCD = "A", // A,B,C, or D parameter PO_DATA_CTL = "FALSE", parameter BITLANES = 12'b1111_1111_1111, parameter BITLANES_OUTONLY = 12'b1111_1111_1111, parameter BYTELANES_DDR_CK = 24'b0010_0010_0010_0010_0010_0010, parameter RCLK_SELECT_LANE = "B", parameter PC_CLK_RATIO = 4, parameter USE_PRE_POST_FIFO = "FALSE", //OUT_FIFO parameter OF_ALMOST_EMPTY_VALUE = 1, parameter OF_ALMOST_FULL_VALUE = 1, parameter OF_ARRAY_MODE = "UNDECLARED", parameter OF_OUTPUT_DISABLE = "FALSE", parameter OF_SYNCHRONOUS_MODE = "TRUE", //IN_FIFO parameter IF_ALMOST_EMPTY_VALUE = 1, parameter IF_ALMOST_FULL_VALUE = 1, parameter IF_ARRAY_MODE = "UNDECLARED", parameter IF_SYNCHRONOUS_MODE = "TRUE", //PHASER_IN parameter PI_BURST_MODE = "TRUE", parameter PI_CLKOUT_DIV = 2, parameter PI_FREQ_REF_DIV = "NONE", parameter PI_FINE_DELAY = 1, parameter PI_OUTPUT_CLK_SRC = "DELAYED_REF" , //"DELAYED_REF", parameter PI_SEL_CLK_OFFSET = 0, parameter PI_SYNC_IN_DIV_RST = "FALSE", //PHASER_OUT parameter PO_CLKOUT_DIV = (PO_DATA_CTL == "FALSE") ? 4 : 2, parameter PO_FINE_DELAY = 0, parameter PO_COARSE_BYPASS = "FALSE", parameter PO_COARSE_DELAY = 0, parameter PO_OCLK_DELAY = 0, parameter PO_OCLKDELAY_INV = "TRUE", parameter PO_OUTPUT_CLK_SRC = "DELAYED_REF", parameter PO_SYNC_IN_DIV_RST = "FALSE", // OSERDES parameter OSERDES_DATA_RATE = "DDR", parameter OSERDES_DATA_WIDTH = 4, //IDELAY parameter IDELAYE2_IDELAY_TYPE = "VARIABLE", parameter IDELAYE2_IDELAY_VALUE = 00, parameter IODELAY_GRP = "IODELAY_MIG", parameter BANK_TYPE = "HP_IO", // # = "HP_IO", "HPL_IO", "HR_IO", "HRL_IO" parameter real TCK = 0.00, parameter SYNTHESIS = "FALSE", // local constants, do not pass in from above parameter BUS_WIDTH = 12, parameter MSB_BURST_PEND_PO = 3, parameter MSB_BURST_PEND_PI = 7, parameter MSB_RANK_SEL_I = MSB_BURST_PEND_PI + 8, parameter PHASER_CTL_BUS_WIDTH = MSB_RANK_SEL_I + 1 ,parameter CKE_ODT_AUX = "FALSE" )( input rst, input phy_clk, input freq_refclk, input mem_refclk, input idelayctrl_refclk, input sync_pulse, output [BUS_WIDTH-1:0] mem_dq_out, output [BUS_WIDTH-1:0] mem_dq_ts, input [9:0] mem_dq_in, output mem_dqs_out, output mem_dqs_ts, input mem_dqs_in, output [11:0] ddr_ck_out, output rclk, input if_empty_def, output if_a_empty, output if_empty, output if_a_full, output if_full, output of_a_empty, output of_empty, output of_a_full, output of_full, output pre_fifo_a_full, output [79:0] phy_din, input [79:0] phy_dout, input phy_cmd_wr_en, input phy_data_wr_en, input phy_rd_en, input [PHASER_CTL_BUS_WIDTH-1:0] phaser_ctl_bus, input idelay_inc, input idelay_ce, input idelay_ld, input if_rst, input [2:0] byte_rd_en_oth_lanes, input [1:0] byte_rd_en_oth_banks, output byte_rd_en, output po_coarse_overflow, output po_fine_overflow, output [8:0] po_counter_read_val, input po_fine_enable, input po_coarse_enable, input [1:0] po_en_calib, input po_fine_inc, input po_coarse_inc, input po_counter_load_en, input po_counter_read_en, input po_sel_fine_oclk_delay, input [8:0] po_counter_load_val, input [1:0] pi_en_calib, input pi_rst_dqs_find, input pi_fine_enable, input pi_fine_inc, input pi_counter_load_en, input pi_counter_read_en, input [5:0] pi_counter_load_val, output wire pi_iserdes_rst, output pi_phase_locked, output pi_fine_overflow, output [5:0] pi_counter_read_val, output wire pi_dqs_found, output dqs_out_of_range ); localparam PHASER_INDEX = (ABCD=="B" ? 1 : (ABCD == "C") ? 2 : (ABCD == "D" ? 3 : 0)); localparam L_OF_ARRAY_MODE = (OF_ARRAY_MODE != "UNDECLARED") ? OF_ARRAY_MODE : (PO_DATA_CTL == "FALSE" || PC_CLK_RATIO == 2) ? "ARRAY_MODE_4_X_4" : "ARRAY_MODE_8_X_4"; localparam L_IF_ARRAY_MODE = (IF_ARRAY_MODE != "UNDECLARED") ? IF_ARRAY_MODE : (PC_CLK_RATIO == 2) ? "ARRAY_MODE_4_X_4" : "ARRAY_MODE_4_X_8"; localparam L_OSERDES_DATA_RATE = (OSERDES_DATA_RATE != "UNDECLARED") ? OSERDES_DATA_RATE : ((PO_DATA_CTL == "FALSE" && PC_CLK_RATIO == 4) ? "SDR" : "DDR") ; localparam L_OSERDES_DATA_WIDTH = (OSERDES_DATA_WIDTH != "UNDECLARED") ? OSERDES_DATA_WIDTH : 4; localparam real L_FREQ_REF_PERIOD_NS = TCK > 2500.0 ? (TCK/(PI_FREQ_REF_DIV == "DIV2" ? 2 : 1)/1000.0) : TCK/1000.0; localparam real L_MEM_REF_PERIOD_NS = TCK/1000.0; localparam real L_PHASE_REF_PERIOD_NS = TCK/1000.0; localparam ODDR_CLK_EDGE = "SAME_EDGE"; localparam PO_DCD_CORRECTION = "ON"; localparam [2:0] PO_DCD_SETTING = (PO_DCD_CORRECTION == "ON") ? 3'b111 : 3'b000; localparam DQS_AUTO_RECAL = (BANK_TYPE == "HR_IO" || BANK_TYPE == "HRL_IO" || (BANK_TYPE == "HPL_IO" && TCK > 2500)) ? 1 : 0; localparam DQS_FIND_PATTERN = (BANK_TYPE == "HR_IO" || BANK_TYPE == "HRL_IO" || (BANK_TYPE == "HPL_IO" && TCK > 2500)) ? "001" : "000"; wire [1:0] oserdes_dqs; wire [1:0] oserdes_dqs_ts; wire [1:0] oserdes_dq_ts; wire [3:0] of_q9; wire [3:0] of_q8; wire [3:0] of_q7; wire [7:0] of_q6; wire [7:0] of_q5; wire [3:0] of_q4; wire [3:0] of_q3; wire [3:0] of_q2; wire [3:0] of_q1; wire [3:0] of_q0; wire [7:0] of_d9; wire [7:0] of_d8; wire [7:0] of_d7; wire [7:0] of_d6; wire [7:0] of_d5; wire [7:0] of_d4; wire [7:0] of_d3; wire [7:0] of_d2; wire [7:0] of_d1; wire [7:0] of_d0; wire [7:0] if_q9; wire [7:0] if_q8; wire [7:0] if_q7; wire [7:0] if_q6; wire [7:0] if_q5; wire [7:0] if_q4; wire [7:0] if_q3; wire [7:0] if_q2; wire [7:0] if_q1; wire [7:0] if_q0; wire [3:0] if_d9; wire [3:0] if_d8; wire [3:0] if_d7; wire [3:0] if_d6; wire [3:0] if_d5; wire [3:0] if_d4; wire [3:0] if_d3; wire [3:0] if_d2; wire [3:0] if_d1; wire [3:0] if_d0; wire [3:0] dummy_i5; wire [3:0] dummy_i6; wire [48-1:0] of_dqbus; wire [10*4-1:0] iserdes_dout; wire iserdes_clk; wire iserdes_clkdiv; wire ififo_wr_enable; wire phy_rd_en_; wire dqs_to_phaser; wire phy_wr_en = ( PO_DATA_CTL == "FALSE" ) ? phy_cmd_wr_en : phy_data_wr_en; wire if_empty_; wire if_a_empty_; wire if_full_; wire if_a_full_; wire po_oserdes_rst; wire empty_post_fifo; (* keep = "true", max_fanout = 3 *) reg [3:0] if_empty_r /* synthesis syn_maxfan = 3 */; wire [79:0] rd_data; reg [79:0] rd_data_r; ///////////////////////////////////////////////////////////////////////// ///This is a temporary fix until we get a proper fix for CR#638064/////// ///////////////////////////////////////////////////////////////////////// reg ififo_rst = 1'b1; reg ofifo_rst = 1'b1; ///////////////////////////////////////////////////////////////////////// wire of_wren_pre; wire [79:0] pre_fifo_dout; wire pre_fifo_full; wire pre_fifo_rden; wire [5:0] ddr_ck_out_q; (* keep = "true", max_fanout = 10 *) wire ififo_rd_en_in /* synthesis syn_maxfan = 10 */; always @(posedge phy_clk) begin ififo_rst <= #1 pi_rst_dqs_find | if_rst ; // reset only data o-fifos on reset of dqs_found ofifo_rst <= #1 (pi_rst_dqs_find & PO_DATA_CTL == "TRUE") | rst; end // IN_FIFO EMPTY->RDEN TIMING FIX: // Always read from IN_FIFO - it doesn't hurt to read from an empty FIFO // since the IN_FIFO read pointers are not incr'ed when the FIFO is empty assign #(25) phy_rd_en_ = 1'b1; //assign #(25) phy_rd_en_ = phy_rd_en; generate if ( PO_DATA_CTL == "FALSE" ) begin : if_empty_null assign if_empty = 0; assign if_a_empty = 0; assign if_full = 0; assign if_a_full = 0; end else begin : if_empty_gen assign if_empty = empty_post_fifo; assign if_a_empty = if_a_empty_; assign if_full = if_full_; assign if_a_full = if_a_full_; end endgenerate generate if ( PO_DATA_CTL == "FALSE" ) begin : dq_gen_48 assign of_dqbus[48-1:0] = {of_q6[7:4], of_q5[7:4], of_q9, of_q8, of_q7, of_q6[3:0], of_q5[3:0], of_q4, of_q3, of_q2, of_q1, of_q0}; assign phy_din = 80'h0; assign byte_rd_en = 1'b1; end else begin : dq_gen_40 assign of_dqbus[40-1:0] = {of_q9, of_q8, of_q7, of_q6[3:0], of_q5[3:0], of_q4, of_q3, of_q2, of_q1, of_q0}; assign ififo_rd_en_in = !if_empty_def ? ((&byte_rd_en_oth_banks) && (&byte_rd_en_oth_lanes) && byte_rd_en) : ((|byte_rd_en_oth_banks) || (|byte_rd_en_oth_lanes) || byte_rd_en); if (USE_PRE_POST_FIFO == "TRUE") begin : if_post_fifo_gen // IN_FIFO EMPTY->RDEN TIMING FIX: assign rd_data = {if_q9, if_q8, if_q7, if_q6, if_q5, if_q4, if_q3, if_q2, if_q1, if_q0}; always @(posedge phy_clk) begin rd_data_r <= #(025) rd_data; if_empty_r[0] <= #(025) if_empty_; if_empty_r[1] <= #(025) if_empty_; if_empty_r[2] <= #(025) if_empty_; if_empty_r[3] <= #(025) if_empty_; end mig_7series_v1_9_ddr_if_post_fifo # ( .TCQ (25), // simulation CK->Q delay .DEPTH (4), //2 // depth - account for up to 2 cycles of skew .WIDTH (80) // width ) u_ddr_if_post_fifo ( .clk (phy_clk), .rst (ififo_rst), .empty_in (if_empty_r), .rd_en_in (ififo_rd_en_in), .d_in (rd_data_r), .empty_out (empty_post_fifo), .byte_rd_en (byte_rd_en), .d_out (phy_din) ); end else begin : phy_din_gen assign phy_din = {if_q9, if_q8, if_q7, if_q6, if_q5, if_q4, if_q3, if_q2, if_q1, if_q0}; assign empty_post_fifo = if_empty_; end end endgenerate assign { if_d9, if_d8, if_d7, if_d6, if_d5, if_d4, if_d3, if_d2, if_d1, if_d0} = iserdes_dout; wire [1:0] rank_sel_i = ((phaser_ctl_bus[MSB_RANK_SEL_I :MSB_RANK_SEL_I -7] >> (PHASER_INDEX << 1)) & 2'b11); generate if ( USE_PRE_POST_FIFO == "TRUE" ) begin : of_pre_fifo_gen assign {of_d9, of_d8, of_d7, of_d6, of_d5, of_d4, of_d3, of_d2, of_d1, of_d0} = pre_fifo_dout; mig_7series_v1_9_ddr_of_pre_fifo # ( .TCQ (25), // simulation CK->Q delay .DEPTH (9), // depth - set to 9 to accommodate flow control .WIDTH (80) // width ) u_ddr_of_pre_fifo ( .clk (phy_clk), ///////////////////////////////////////////////////////////////////////// ///This is a temporary fix until we get a proper fix for CR#638064/////// ///////////////////////////////////////////////////////////////////////// .rst (ofifo_rst), ///////////////////////////////////////////////////////////////////////// .full_in (of_full), .wr_en_in (phy_wr_en), .d_in (phy_dout), .wr_en_out (of_wren_pre), .d_out (pre_fifo_dout), .afull (pre_fifo_a_full) ); end else begin // wire direct to ofifo assign {of_d9, of_d8, of_d7, of_d6, of_d5, of_d4, of_d3, of_d2, of_d1, of_d0} = phy_dout; assign of_wren_pre = phy_wr_en; end endgenerate generate if ( PO_DATA_CTL == "TRUE" || ((RCLK_SELECT_LANE==ABCD) && (CKE_ODT_AUX =="TRUE"))) begin : phaser_in_gen PHASER_IN_PHY #( .BURST_MODE ( PI_BURST_MODE), .CLKOUT_DIV ( PI_CLKOUT_DIV), .DQS_AUTO_RECAL ( DQS_AUTO_RECAL), .DQS_FIND_PATTERN ( DQS_FIND_PATTERN), .SEL_CLK_OFFSET ( PI_SEL_CLK_OFFSET), .FINE_DELAY ( PI_FINE_DELAY), .FREQ_REF_DIV ( PI_FREQ_REF_DIV), .OUTPUT_CLK_SRC ( PI_OUTPUT_CLK_SRC), .SYNC_IN_DIV_RST ( PI_SYNC_IN_DIV_RST), .REFCLK_PERIOD ( L_FREQ_REF_PERIOD_NS), .MEMREFCLK_PERIOD ( L_MEM_REF_PERIOD_NS), .PHASEREFCLK_PERIOD ( L_PHASE_REF_PERIOD_NS) ) phaser_in ( .DQSFOUND (pi_dqs_found), .DQSOUTOFRANGE (dqs_out_of_range), .FINEOVERFLOW (pi_fine_overflow), .PHASELOCKED (pi_phase_locked), .ISERDESRST (pi_iserdes_rst), .ICLKDIV (iserdes_clkdiv), .ICLK (iserdes_clk), .COUNTERREADVAL (pi_counter_read_val), .RCLK (rclk), .WRENABLE (ififo_wr_enable), .BURSTPENDINGPHY (phaser_ctl_bus[MSB_BURST_PEND_PI - 3 + PHASER_INDEX]), .ENCALIBPHY (pi_en_calib), .FINEENABLE (pi_fine_enable), .FREQREFCLK (freq_refclk), .MEMREFCLK (mem_refclk), .RANKSELPHY (rank_sel_i), .PHASEREFCLK (dqs_to_phaser), .RSTDQSFIND (pi_rst_dqs_find), .RST (rst), .FINEINC (pi_fine_inc), .COUNTERLOADEN (pi_counter_load_en), .COUNTERREADEN (pi_counter_read_en), .COUNTERLOADVAL (pi_counter_load_val), .SYNCIN (sync_pulse), .SYSCLK (phy_clk) ); end else begin assign pi_dqs_found = 1'b1; assign pi_dqs_out_of_range = 1'b0; assign pi_phase_locked = 1'b1; end endgenerate wire #0 phase_ref = freq_refclk; wire oserdes_clk; PHASER_OUT_PHY #( .CLKOUT_DIV ( PO_CLKOUT_DIV), .DATA_CTL_N ( PO_DATA_CTL ), .FINE_DELAY ( PO_FINE_DELAY), .COARSE_BYPASS ( PO_COARSE_BYPASS ), .COARSE_DELAY ( PO_COARSE_DELAY), .OCLK_DELAY ( PO_OCLK_DELAY), .OCLKDELAY_INV ( PO_OCLKDELAY_INV), .OUTPUT_CLK_SRC ( PO_OUTPUT_CLK_SRC), .SYNC_IN_DIV_RST ( PO_SYNC_IN_DIV_RST), .REFCLK_PERIOD ( L_FREQ_REF_PERIOD_NS), .PHASEREFCLK_PERIOD ( 1), // dummy, not used .PO ( PO_DCD_SETTING ), .MEMREFCLK_PERIOD ( L_MEM_REF_PERIOD_NS) ) phaser_out ( .COARSEOVERFLOW (po_coarse_overflow), .CTSBUS (oserdes_dqs_ts), .DQSBUS (oserdes_dqs), .DTSBUS (oserdes_dq_ts), .FINEOVERFLOW (po_fine_overflow), .OCLKDIV (oserdes_clkdiv), .OCLK (oserdes_clk), .OCLKDELAYED (oserdes_clk_delayed), .COUNTERREADVAL (po_counter_read_val), .BURSTPENDINGPHY (phaser_ctl_bus[MSB_BURST_PEND_PO -3 + PHASER_INDEX]), .ENCALIBPHY (po_en_calib), .RDENABLE (po_rd_enable), .FREQREFCLK (freq_refclk), .MEMREFCLK (mem_refclk), .PHASEREFCLK (/*phase_ref*/), .RST (rst), .OSERDESRST (po_oserdes_rst), .COARSEENABLE (po_coarse_enable), .FINEENABLE (po_fine_enable), .COARSEINC (po_coarse_inc), .FINEINC (po_fine_inc), .SELFINEOCLKDELAY (po_sel_fine_oclk_delay), .COUNTERLOADEN (po_counter_load_en), .COUNTERREADEN (po_counter_read_en), .COUNTERLOADVAL (po_counter_load_val), .SYNCIN (sync_pulse), .SYSCLK (phy_clk) ); generate if (PO_DATA_CTL == "TRUE") begin : in_fifo_gen IN_FIFO #( .ALMOST_EMPTY_VALUE ( IF_ALMOST_EMPTY_VALUE ), .ALMOST_FULL_VALUE ( IF_ALMOST_FULL_VALUE ), .ARRAY_MODE ( L_IF_ARRAY_MODE), .SYNCHRONOUS_MODE ( IF_SYNCHRONOUS_MODE) ) in_fifo ( .ALMOSTEMPTY (if_a_empty_), .ALMOSTFULL (if_a_full_), .EMPTY (if_empty_), .FULL (if_full_), .Q0 (if_q0), .Q1 (if_q1), .Q2 (if_q2), .Q3 (if_q3), .Q4 (if_q4), .Q5 (if_q5), .Q6 (if_q6), .Q7 (if_q7), .Q8 (if_q8), .Q9 (if_q9), //=== .D0 (if_d0), .D1 (if_d1), .D2 (if_d2), .D3 (if_d3), .D4 (if_d4), .D5 ({dummy_i5,if_d5}), .D6 ({dummy_i6,if_d6}), .D7 (if_d7), .D8 (if_d8), .D9 (if_d9), .RDCLK (phy_clk), .RDEN (phy_rd_en_), .RESET (ififo_rst), .WRCLK (iserdes_clkdiv), .WREN (ififo_wr_enable) ); end endgenerate OUT_FIFO #( .ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .ARRAY_MODE (L_OF_ARRAY_MODE), .OUTPUT_DISABLE (OF_OUTPUT_DISABLE), .SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE) ) out_fifo ( .ALMOSTEMPTY (of_a_empty), .ALMOSTFULL (of_a_full), .EMPTY (of_empty), .FULL (of_full), .Q0 (of_q0), .Q1 (of_q1), .Q2 (of_q2), .Q3 (of_q3), .Q4 (of_q4), .Q5 (of_q5), .Q6 (of_q6), .Q7 (of_q7), .Q8 (of_q8), .Q9 (of_q9), .D0 (of_d0), .D1 (of_d1), .D2 (of_d2), .D3 (of_d3), .D4 (of_d4), .D5 (of_d5), .D6 (of_d6), .D7 (of_d7), .D8 (of_d8), .D9 (of_d9), .RDCLK (oserdes_clkdiv), .RDEN (po_rd_enable), .RESET (ofifo_rst), .WRCLK (phy_clk), .WREN (of_wren_pre) ); mig_7series_v1_9_ddr_byte_group_io # ( .PO_DATA_CTL (PO_DATA_CTL), .BITLANES (BITLANES), .BITLANES_OUTONLY (BITLANES_OUTONLY), .OSERDES_DATA_RATE (L_OSERDES_DATA_RATE), .OSERDES_DATA_WIDTH (L_OSERDES_DATA_WIDTH), .IODELAY_GRP (IODELAY_GRP), .IDELAYE2_IDELAY_TYPE (IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (IDELAYE2_IDELAY_VALUE), .SYNTHESIS (SYNTHESIS) ) ddr_byte_group_io ( .mem_dq_out (mem_dq_out), .mem_dq_ts (mem_dq_ts), .mem_dq_in (mem_dq_in), .mem_dqs_in (mem_dqs_in), .mem_dqs_out (mem_dqs_out), .mem_dqs_ts (mem_dqs_ts), .rst (rst), .oserdes_rst (po_oserdes_rst), .iserdes_rst (pi_iserdes_rst ), .iserdes_dout (iserdes_dout), .dqs_to_phaser (dqs_to_phaser), .phy_clk (phy_clk), .iserdes_clk (iserdes_clk), .iserdes_clkb (!iserdes_clk), .iserdes_clkdiv (iserdes_clkdiv), .idelay_inc (idelay_inc), .idelay_ce (idelay_ce), .idelay_ld (idelay_ld), .idelayctrl_refclk (idelayctrl_refclk), .oserdes_clk (oserdes_clk), .oserdes_clk_delayed (oserdes_clk_delayed), .oserdes_clkdiv (oserdes_clkdiv), .oserdes_dqs ({oserdes_dqs[1], oserdes_dqs[0]}), .oserdes_dqsts ({oserdes_dqs_ts[1], oserdes_dqs_ts[0]}), .oserdes_dq (of_dqbus), .oserdes_dqts ({oserdes_dq_ts[1], oserdes_dq_ts[0]}) ); genvar i; generate for (i = 0; i <= 5; i = i+1) begin : ddr_ck_gen_loop if (PO_DATA_CTL== "FALSE" && (BYTELANES_DDR_CK[i*4+PHASER_INDEX])) begin : ddr_ck_gen ODDR #(.DDR_CLK_EDGE (ODDR_CLK_EDGE)) ddr_ck ( .C (oserdes_clk), .R (1'b0), .S (), .D1 (1'b0), .D2 (1'b1), .CE (1'b1), .Q (ddr_ck_out_q[i]) ); OBUFDS ddr_ck_obuf (.I(ddr_ck_out_q[i]), .O(ddr_ck_out[i*2]), .OB(ddr_ck_out[i*2+1])); end // ddr_ck_gen else begin : ddr_ck_null assign ddr_ck_out[i*2+1:i*2] = 2'b0; end end // ddr_ck_gen_loop endgenerate endmodule // byte_lane
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Import ZAxioms ZMulOrder ZSgnAbs ZGcd ZDivTrunc ZDivFloor. (** * Least Common Multiple *) (** Unlike other functions around, we will define lcm below instead of axiomatizing it. Indeed, there is no "prior art" about lcm in the standard library to be compliant with, and the generic definition of lcm via gcd is quite reasonable. By the way, we also state here some combined properties of div/mod and quot/rem and gcd. *) Module Type ZLcmProp (Import A : ZAxiomsSig') (Import B : ZMulOrderProp A) (Import C : ZSgnAbsProp A B) (Import D : ZDivProp A B C) (Import E : ZQuotProp A B C) (Import F : ZGcdProp A B C). (** The two notions of division are equal on non-negative numbers *) Lemma quot_div_nonneg : forall a b, 0<=a -> 0<b -> a÷b == a/b. Proof. intros. apply div_unique_pos with (a rem b). now apply rem_bound_pos. apply quot_rem. order. Qed. Lemma rem_mod_nonneg : forall a b, 0<=a -> 0<b -> a rem b == a mod b. Proof. intros. apply mod_unique_pos with (a÷b). now apply rem_bound_pos. apply quot_rem. order. Qed. (** We can use the sign rule to have an relation between divisions. *) Lemma quot_div : forall a b, b~=0 -> a÷b == (sgn a)*(sgn b)*(abs a / abs b). Proof. assert (AUX : forall a b, 0<b -> a÷b == (sgn a)*(sgn b)*(abs a / abs b)). intros a b Hb. rewrite (sgn_pos b), (abs_eq b), mul_1_r by order. destruct (lt_trichotomy 0 a) as [Ha|[Ha|Ha]]. rewrite sgn_pos, abs_eq, mul_1_l, quot_div_nonneg; order. rewrite <- Ha, abs_0, sgn_0, quot_0_l, div_0_l, mul_0_l; order. rewrite sgn_neg, abs_neq, mul_opp_l, mul_1_l, eq_opp_r, <-quot_opp_l by order. apply quot_div_nonneg; trivial. apply opp_nonneg_nonpos; order. (* main *) intros a b Hb. apply neg_pos_cases in Hb. destruct Hb as [Hb|Hb]; [|now apply AUX]. rewrite <- (opp_involutive b) at 1. rewrite quot_opp_r. rewrite AUX, abs_opp, sgn_opp, mul_opp_r, mul_opp_l, opp_involutive. reflexivity. now apply opp_pos_neg. rewrite eq_opp_l, opp_0; order. Qed. Lemma rem_mod : forall a b, b~=0 -> a rem b == (sgn a) * ((abs a) mod (abs b)). Proof. intros a b Hb. rewrite <- rem_abs_r by trivial. assert (Hb' := proj2 (abs_pos b) Hb). destruct (lt_trichotomy 0 a) as [Ha|[Ha|Ha]]. rewrite (abs_eq a), sgn_pos, mul_1_l, rem_mod_nonneg; order. rewrite <- Ha, abs_0, sgn_0, mod_0_l, rem_0_l, mul_0_l; order. rewrite sgn_neg, (abs_neq a), mul_opp_l, mul_1_l, eq_opp_r, <-rem_opp_l by order. apply rem_mod_nonneg; trivial. apply opp_nonneg_nonpos; order. Qed. (** Modulo and remainder are null at the same place, and this correspond to the divisibility relation. *) Lemma mod_divide : forall a b, b~=0 -> (a mod b == 0 <-> (b|a)). Proof. intros a b Hb. split. intros Hab. exists (a/b). rewrite mul_comm. rewrite (div_mod a b Hb) at 1. rewrite Hab; now nzsimpl. intros (c,Hc). rewrite Hc. now apply mod_mul. Qed. Lemma rem_divide : forall a b, b~=0 -> (a rem b == 0 <-> (b|a)). Proof. intros a b Hb. split. intros Hab. exists (a÷b). rewrite mul_comm. rewrite (quot_rem a b Hb) at 1. rewrite Hab; now nzsimpl. intros (c,Hc). rewrite Hc. now apply rem_mul. Qed. Lemma rem_mod_eq_0 : forall a b, b~=0 -> (a rem b == 0 <-> a mod b == 0). Proof. intros a b Hb. now rewrite mod_divide, rem_divide. Qed. (** When division is exact, div and quot agree *) Lemma quot_div_exact : forall a b, b~=0 -> (b|a) -> a÷b == a/b. Proof. intros a b Hb H. apply mul_cancel_l with b; trivial. assert (H':=H). apply rem_divide, quot_exact in H; trivial. apply mod_divide, div_exact in H'; trivial. now rewrite <-H,<-H'. Qed. Lemma divide_div_mul_exact : forall a b c, b~=0 -> (b|a) -> (c*a)/b == c*(a/b). Proof. intros a b c Hb H. apply mul_cancel_l with b; trivial. rewrite mul_assoc, mul_shuffle0. assert (H':=H). apply mod_divide, div_exact in H'; trivial. rewrite <- H', (mul_comm a c). symmetry. apply div_exact; trivial. apply mod_divide; trivial. now apply divide_mul_r. Qed. Lemma divide_quot_mul_exact : forall a b c, b~=0 -> (b|a) -> (c*a)÷b == c*(a÷b). Proof. intros a b c Hb H. rewrite 2 quot_div_exact; trivial. apply divide_div_mul_exact; trivial. now apply divide_mul_r. Qed. (** Gcd of divided elements, for exact divisions *) Lemma gcd_div_factor : forall a b c, 0<c -> (c|a) -> (c|b) -> gcd (a/c) (b/c) == (gcd a b)/c. Proof. intros a b c Hc Ha Hb. apply mul_cancel_l with c; try order. assert (H:=gcd_greatest _ _ _ Ha Hb). apply mod_divide, div_exact in H; try order. rewrite <- H. rewrite <- gcd_mul_mono_l_nonneg; try order. f_equiv; symmetry; apply div_exact; try order; apply mod_divide; trivial; try order. Qed. Lemma gcd_quot_factor : forall a b c, 0<c -> (c|a) -> (c|b) -> gcd (a÷c) (b÷c) == (gcd a b)÷c. Proof. intros a b c Hc Ha Hb. rewrite !quot_div_exact; trivial; try order. now apply gcd_div_factor. now apply gcd_greatest. Qed. Lemma gcd_div_gcd : forall a b g, g~=0 -> g == gcd a b -> gcd (a/g) (b/g) == 1. Proof. intros a b g NZ EQ. rewrite gcd_div_factor. now rewrite <- EQ, div_same. generalize (gcd_nonneg a b); order. rewrite EQ; apply gcd_divide_l. rewrite EQ; apply gcd_divide_r. Qed. Lemma gcd_quot_gcd : forall a b g, g~=0 -> g == gcd a b -> gcd (a÷g) (b÷g) == 1. Proof. intros a b g NZ EQ. rewrite !quot_div_exact; trivial. now apply gcd_div_gcd. rewrite EQ; apply gcd_divide_r. rewrite EQ; apply gcd_divide_l. Qed. (** The following equality is crucial for Euclid algorithm *) Lemma gcd_mod : forall a b, b~=0 -> gcd (a mod b) b == gcd b a. Proof. intros a b Hb. rewrite mod_eq; trivial. rewrite <- add_opp_r, mul_comm, <- mul_opp_l. rewrite (gcd_comm _ b). apply gcd_add_mult_diag_r. Qed. Lemma gcd_rem : forall a b, b~=0 -> gcd (a rem b) b == gcd b a. Proof. intros a b Hb. rewrite rem_eq; trivial. rewrite <- add_opp_r, mul_comm, <- mul_opp_l. rewrite (gcd_comm _ b). apply gcd_add_mult_diag_r. Qed. (** We now define lcm thanks to gcd: lcm a b = a * (b / gcd a b) = (a / gcd a b) * b = (a*b) / gcd a b We had an abs in order to have an always-nonnegative lcm, in the spirit of gcd. Nota: [lcm 0 0] should be 0, which isn't garantee with the third equation above. *) Definition lcm a b := abs (a*(b/gcd a b)). Instance lcm_wd : Proper (eq==>eq==>eq) lcm. Proof. unfold lcm. solve_proper. Qed. Lemma lcm_equiv1 : forall a b, gcd a b ~= 0 -> a * (b / gcd a b) == (a*b)/gcd a b. Proof. intros a b H. rewrite divide_div_mul_exact; try easy. apply gcd_divide_r. Qed. Lemma lcm_equiv2 : forall a b, gcd a b ~= 0 -> (a / gcd a b) * b == (a*b)/gcd a b. Proof. intros a b H. rewrite 2 (mul_comm _ b). rewrite divide_div_mul_exact; try easy. apply gcd_divide_l. Qed. Lemma gcd_div_swap : forall a b, (a / gcd a b) * b == a * (b / gcd a b). Proof. intros a b. destruct (eq_decidable (gcd a b) 0) as [EQ|NEQ]. apply gcd_eq_0 in EQ. destruct EQ as (EQ,EQ'). rewrite EQ, EQ'. now nzsimpl. now rewrite lcm_equiv1, <-lcm_equiv2. Qed. Lemma divide_lcm_l : forall a b, (a | lcm a b). Proof. unfold lcm. intros a b. apply divide_abs_r, divide_factor_l. Qed. Lemma divide_lcm_r : forall a b, (b | lcm a b). Proof. unfold lcm. intros a b. apply divide_abs_r. rewrite <- gcd_div_swap. apply divide_factor_r. Qed. Lemma divide_div : forall a b c, a~=0 -> (a|b) -> (b|c) -> (b/a|c/a). Proof. intros a b c Ha Hb (c',Hc). exists c'. now rewrite <- divide_div_mul_exact, <- Hc. Qed. Lemma lcm_least : forall a b c, (a | c) -> (b | c) -> (lcm a b | c). Proof. intros a b c Ha Hb. unfold lcm. apply divide_abs_l. destruct (eq_decidable (gcd a b) 0) as [EQ|NEQ]. apply gcd_eq_0 in EQ. destruct EQ as (EQ,EQ'). rewrite EQ in *. now nzsimpl. assert (Ga := gcd_divide_l a b). assert (Gb := gcd_divide_r a b). set (g:=gcd a b) in *. assert (Ha' := divide_div g a c NEQ Ga Ha). assert (Hb' := divide_div g b c NEQ Gb Hb). destruct Ha' as (a',Ha'). rewrite Ha', mul_comm in Hb'. apply gauss in Hb'; [|apply gcd_div_gcd; unfold g; trivial using gcd_comm]. destruct Hb' as (b',Hb'). exists b'. rewrite mul_shuffle3, <- Hb'. rewrite (proj2 (div_exact c g NEQ)). rewrite Ha', mul_shuffle3, (mul_comm a a'). f_equiv. symmetry. apply div_exact; trivial. apply mod_divide; trivial. apply mod_divide; trivial. transitivity a; trivial. Qed. Lemma lcm_nonneg : forall a b, 0 <= lcm a b. Proof. intros a b. unfold lcm. apply abs_nonneg. Qed. Lemma lcm_comm : forall a b, lcm a b == lcm b a. Proof. intros a b. unfold lcm. rewrite (gcd_comm b), (mul_comm b). now rewrite <- gcd_div_swap. Qed. Lemma lcm_divide_iff : forall n m p, (lcm n m | p) <-> (n | p) /\ (m | p). Proof. intros. split. split. transitivity (lcm n m); trivial using divide_lcm_l. transitivity (lcm n m); trivial using divide_lcm_r. intros (H,H'). now apply lcm_least. Qed. Lemma lcm_unique : forall n m p, 0<=p -> (n|p) -> (m|p) -> (forall q, (n|q) -> (m|q) -> (p|q)) -> lcm n m == p. Proof. intros n m p Hp Hn Hm H. apply divide_antisym_nonneg; trivial. apply lcm_nonneg. now apply lcm_least. apply H. apply divide_lcm_l. apply divide_lcm_r. Qed. Lemma lcm_unique_alt : forall n m p, 0<=p -> (forall q, (p|q) <-> (n|q) /\ (m|q)) -> lcm n m == p. Proof. intros n m p Hp H. apply lcm_unique; trivial. apply H, divide_refl. apply H, divide_refl. intros. apply H. now split. Qed. Lemma lcm_assoc : forall n m p, lcm n (lcm m p) == lcm (lcm n m) p. Proof. intros. apply lcm_unique_alt; try apply lcm_nonneg. intros. now rewrite !lcm_divide_iff, and_assoc. Qed. Lemma lcm_0_l : forall n, lcm 0 n == 0. Proof. intros. apply lcm_unique; trivial. order. apply divide_refl. apply divide_0_r. Qed. Lemma lcm_0_r : forall n, lcm n 0 == 0. Proof. intros. now rewrite lcm_comm, lcm_0_l. Qed. Lemma lcm_1_l_nonneg : forall n, 0<=n -> lcm 1 n == n. Proof. intros. apply lcm_unique; trivial using divide_1_l, le_0_1, divide_refl. Qed. Lemma lcm_1_r_nonneg : forall n, 0<=n -> lcm n 1 == n. Proof. intros. now rewrite lcm_comm, lcm_1_l_nonneg. Qed. Lemma lcm_diag_nonneg : forall n, 0<=n -> lcm n n == n. Proof. intros. apply lcm_unique; trivial using divide_refl. Qed. Lemma lcm_eq_0 : forall n m, lcm n m == 0 <-> n == 0 \/ m == 0. Proof. intros. split. intros EQ. apply eq_mul_0. apply divide_0_l. rewrite <- EQ. apply lcm_least. apply divide_factor_l. apply divide_factor_r. destruct 1 as [EQ|EQ]; rewrite EQ. apply lcm_0_l. apply lcm_0_r. Qed. Lemma divide_lcm_eq_r : forall n m, 0<=m -> (n|m) -> lcm n m == m. Proof. intros n m Hm H. apply lcm_unique_alt; trivial. intros q. split. split; trivial. now transitivity m. now destruct 1. Qed. Lemma divide_lcm_iff : forall n m, 0<=m -> ((n|m) <-> lcm n m == m). Proof. intros n m Hn. split. now apply divide_lcm_eq_r. intros EQ. rewrite <- EQ. apply divide_lcm_l. Qed. Lemma lcm_opp_l : forall n m, lcm (-n) m == lcm n m. Proof. intros. apply lcm_unique_alt; try apply lcm_nonneg. intros. rewrite divide_opp_l. apply lcm_divide_iff. Qed. Lemma lcm_opp_r : forall n m, lcm n (-m) == lcm n m. Proof. intros. now rewrite lcm_comm, lcm_opp_l, lcm_comm. Qed. Lemma lcm_abs_l : forall n m, lcm (abs n) m == lcm n m. Proof. intros. destruct (abs_eq_or_opp n) as [H|H]; rewrite H. easy. apply lcm_opp_l. Qed. Lemma lcm_abs_r : forall n m, lcm n (abs m) == lcm n m. Proof. intros. now rewrite lcm_comm, lcm_abs_l, lcm_comm. Qed. Lemma lcm_1_l : forall n, lcm 1 n == abs n. Proof. intros. rewrite <- lcm_abs_r. apply lcm_1_l_nonneg, abs_nonneg. Qed. Lemma lcm_1_r : forall n, lcm n 1 == abs n. Proof. intros. now rewrite lcm_comm, lcm_1_l. Qed. Lemma lcm_diag : forall n, lcm n n == abs n. Proof. intros. rewrite <- lcm_abs_l, <- lcm_abs_r. apply lcm_diag_nonneg, abs_nonneg. Qed. Lemma lcm_mul_mono_l : forall n m p, lcm (p * n) (p * m) == abs p * lcm n m. Proof. intros n m p. destruct (eq_decidable p 0) as [Hp|Hp]. rewrite Hp. nzsimpl. rewrite lcm_0_l, abs_0. now nzsimpl. destruct (eq_decidable (gcd n m) 0) as [Hg|Hg]. apply gcd_eq_0 in Hg. destruct Hg as (Hn,Hm); rewrite Hn, Hm. nzsimpl. rewrite lcm_0_l. now nzsimpl. unfold lcm. rewrite gcd_mul_mono_l. rewrite !abs_mul, mul_assoc. f_equiv. rewrite <- (abs_sgn p) at 1. rewrite <- mul_assoc. rewrite div_mul_cancel_l; trivial. rewrite divide_div_mul_exact; trivial. rewrite abs_mul. rewrite <- (sgn_abs (sgn p)), sgn_sgn. destruct (sgn_spec p) as [(_,EQ)|[(EQ,_)|(_,EQ)]]. rewrite EQ. now nzsimpl. order. rewrite EQ. rewrite mul_opp_l, mul_opp_r, opp_involutive. now nzsimpl. apply gcd_divide_r. contradict Hp. now apply abs_0_iff. Qed. Lemma lcm_mul_mono_l_nonneg : forall n m p, 0<=p -> lcm (p*n) (p*m) == p * lcm n m. Proof. intros. rewrite <- (abs_eq p) at 3; trivial. apply lcm_mul_mono_l. Qed. Lemma lcm_mul_mono_r : forall n m p, lcm (n * p) (m * p) == lcm n m * abs p. Proof. intros n m p. now rewrite !(mul_comm _ p), lcm_mul_mono_l, mul_comm. Qed. Lemma lcm_mul_mono_r_nonneg : forall n m p, 0<=p -> lcm (n*p) (m*p) == lcm n m * p. Proof. intros. rewrite <- (abs_eq p) at 3; trivial. apply lcm_mul_mono_r. Qed. Lemma gcd_1_lcm_mul : forall n m, n~=0 -> m~=0 -> (gcd n m == 1 <-> lcm n m == abs (n*m)). Proof. intros n m Hn Hm. split; intros H. unfold lcm. rewrite H. now rewrite div_1_r. unfold lcm in *. rewrite !abs_mul in H. apply mul_cancel_l in H; [|now rewrite abs_0_iff]. assert (H' := gcd_divide_r n m). assert (Hg : gcd n m ~= 0) by (red; rewrite gcd_eq_0; destruct 1; order). apply mod_divide in H'; trivial. apply div_exact in H'; trivial. assert (m / gcd n m ~=0) by (contradict Hm; rewrite H', Hm; now nzsimpl). rewrite <- (mul_1_l (abs (_/_))) in H. rewrite H' in H at 3. rewrite abs_mul in H. apply mul_cancel_r in H; [|now rewrite abs_0_iff]. rewrite abs_eq in H. order. apply gcd_nonneg. Qed. End ZLcmProp.
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : ui_cmd.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** `timescale 1 ps / 1 ps // User interface command port. module mig_7series_v1_9_ui_cmd # ( parameter TCQ = 100, parameter ADDR_WIDTH = 33, parameter BANK_WIDTH = 3, parameter COL_WIDTH = 12, parameter DATA_BUF_ADDR_WIDTH = 5, parameter RANK_WIDTH = 2, parameter ROW_WIDTH = 16, parameter RANKS = 4, parameter MEM_ADDR_ORDER = "BANK_ROW_COLUMN" ) (/*AUTOARG*/ // Outputs app_rdy, use_addr, rank, bank, row, col, size, cmd, hi_priority, rd_accepted, wr_accepted, data_buf_addr, // Inputs rst, clk, accept_ns, rd_buf_full, wr_req_16, app_addr, app_cmd, app_sz, app_hi_pri, app_en, wr_data_buf_addr, rd_data_buf_addr_r ); input rst; input clk; input accept_ns; input rd_buf_full; input wr_req_16; wire app_rdy_ns = accept_ns && ~rd_buf_full && ~wr_req_16; (* keep = "true", max_fanout = 10 *) reg app_rdy_r = 1'b0 /* synthesis syn_maxfan = 10 */; always @(posedge clk) app_rdy_r <= #TCQ app_rdy_ns; output wire app_rdy; assign app_rdy = app_rdy_r; input [ADDR_WIDTH-1:0] app_addr; input [2:0] app_cmd; input app_sz; input app_hi_pri; input app_en; reg [ADDR_WIDTH-1:0] app_addr_r1 = {ADDR_WIDTH{1'b0}}; reg [ADDR_WIDTH-1:0] app_addr_r2 = {ADDR_WIDTH{1'b0}}; reg [2:0] app_cmd_r1; reg [2:0] app_cmd_r2; reg app_sz_r1; reg app_sz_r2; reg app_hi_pri_r1; reg app_hi_pri_r2; reg app_en_r1; reg app_en_r2; wire [ADDR_WIDTH-1:0] app_addr_ns1 = app_rdy_r && app_en ? app_addr : app_addr_r1; wire [ADDR_WIDTH-1:0] app_addr_ns2 = app_rdy_r ? app_addr_r1 : app_addr_r2; wire [2:0] app_cmd_ns1 = app_rdy_r ? app_cmd : app_cmd_r1; wire [2:0] app_cmd_ns2 = app_rdy_r ? app_cmd_r1 : app_cmd_r2; wire app_sz_ns1 = app_rdy_r ? app_sz : app_sz_r1; wire app_sz_ns2 = app_rdy_r ? app_sz_r1 : app_sz_r2; wire app_hi_pri_ns1 = app_rdy_r ? app_hi_pri : app_hi_pri_r1; wire app_hi_pri_ns2 = app_rdy_r ? app_hi_pri_r1 : app_hi_pri_r2; wire app_en_ns1 = ~rst && (app_rdy_r ? app_en : app_en_r1); wire app_en_ns2 = ~rst && (app_rdy_r ? app_en_r1 : app_en_r2); always @(posedge clk) begin if (rst) begin app_addr_r1 <= #TCQ {ADDR_WIDTH{1'b0}}; app_addr_r2 <= #TCQ {ADDR_WIDTH{1'b0}}; end else begin app_addr_r1 <= #TCQ app_addr_ns1; app_addr_r2 <= #TCQ app_addr_ns2; end app_cmd_r1 <= #TCQ app_cmd_ns1; app_cmd_r2 <= #TCQ app_cmd_ns2; app_sz_r1 <= #TCQ app_sz_ns1; app_sz_r2 <= #TCQ app_sz_ns2; app_hi_pri_r1 <= #TCQ app_hi_pri_ns1; app_hi_pri_r2 <= #TCQ app_hi_pri_ns2; app_en_r1 <= #TCQ app_en_ns1; app_en_r2 <= #TCQ app_en_ns2; end // always @ (posedge clk) wire use_addr_lcl = app_en_r2 && app_rdy_r; output wire use_addr; assign use_addr = use_addr_lcl; output wire [RANK_WIDTH-1:0] rank; output wire [BANK_WIDTH-1:0] bank; output wire [ROW_WIDTH-1:0] row; output wire [COL_WIDTH-1:0] col; output wire size; output wire [2:0] cmd; output wire hi_priority; /* assign col = app_rdy_r ? app_addr_r1[0+:COL_WIDTH] : app_addr_r2[0+:COL_WIDTH];*/ generate begin if (MEM_ADDR_ORDER == "TG_TEST") begin assign col[4:0] = app_rdy_r ? app_addr_r1[0+:5] : app_addr_r2[0+:5]; if (RANKS==1) begin assign col[COL_WIDTH-1:COL_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+:2] : app_addr_r2[5+3+BANK_WIDTH+:2]; assign col[COL_WIDTH-3:5] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+2+2+:COL_WIDTH-7] : app_addr_r2[5+3+BANK_WIDTH+2+2+:COL_WIDTH-7]; end else begin assign col[COL_WIDTH-1:COL_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+:2] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+:2]; assign col[COL_WIDTH-3:5] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+2+2+:COL_WIDTH-7] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+2+2+:COL_WIDTH-7]; end assign row[2:0] = app_rdy_r ? app_addr_r1[5+:3] : app_addr_r2[5+:3]; if (RANKS==1) begin assign row[ROW_WIDTH-1:ROW_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+2+:2] : app_addr_r2[5+3+BANK_WIDTH+2+:2]; assign row[ROW_WIDTH-3:3] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5] : app_addr_r2[5+3+BANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5]; end else begin assign row[ROW_WIDTH-1:ROW_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+2+:2] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+2+:2]; assign row[ROW_WIDTH-3:3] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5]; end assign bank = app_rdy_r ? app_addr_r1[5+3+:BANK_WIDTH] : app_addr_r2[5+3+:BANK_WIDTH]; assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[5+3+BANK_WIDTH+:RANK_WIDTH]; end else if (MEM_ADDR_ORDER == "ROW_BANK_COLUMN") begin assign col = app_rdy_r ? app_addr_r1[0+:COL_WIDTH] : app_addr_r2[0+:COL_WIDTH]; assign row = app_rdy_r ? app_addr_r1[COL_WIDTH+BANK_WIDTH+:ROW_WIDTH] : app_addr_r2[COL_WIDTH+BANK_WIDTH+:ROW_WIDTH]; assign bank = app_rdy_r ? app_addr_r1[COL_WIDTH+:BANK_WIDTH] : app_addr_r2[COL_WIDTH+:BANK_WIDTH]; assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH]; end else begin assign col = app_rdy_r ? app_addr_r1[0+:COL_WIDTH] : app_addr_r2[0+:COL_WIDTH]; assign row = app_rdy_r ? app_addr_r1[COL_WIDTH+:ROW_WIDTH] : app_addr_r2[COL_WIDTH+:ROW_WIDTH]; assign bank = app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+:BANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+:BANK_WIDTH]; assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH]; end end endgenerate /* assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH];*/ assign size = app_rdy_r ? app_sz_r1 : app_sz_r2; assign cmd = app_rdy_r ? app_cmd_r1 : app_cmd_r2; assign hi_priority = app_rdy_r ? app_hi_pri_r1 : app_hi_pri_r2; wire request_accepted = use_addr_lcl && app_rdy_r; wire rd = app_cmd_r2[1:0] == 2'b01; wire wr = app_cmd_r2[1:0] == 2'b00; wire wr_bytes = app_cmd_r2[1:0] == 2'b11; wire write = wr || wr_bytes; output wire rd_accepted; assign rd_accepted = request_accepted && rd; output wire wr_accepted; assign wr_accepted = request_accepted && write; input [DATA_BUF_ADDR_WIDTH-1:0] wr_data_buf_addr; input [DATA_BUF_ADDR_WIDTH-1:0] rd_data_buf_addr_r; output wire [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr; assign data_buf_addr = ~write ? rd_data_buf_addr_r : wr_data_buf_addr; endmodule // ui_cmd // Local Variables: // verilog-library-directories:(".") // End:
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : ui_cmd.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** `timescale 1 ps / 1 ps // User interface command port. module mig_7series_v1_9_ui_cmd # ( parameter TCQ = 100, parameter ADDR_WIDTH = 33, parameter BANK_WIDTH = 3, parameter COL_WIDTH = 12, parameter DATA_BUF_ADDR_WIDTH = 5, parameter RANK_WIDTH = 2, parameter ROW_WIDTH = 16, parameter RANKS = 4, parameter MEM_ADDR_ORDER = "BANK_ROW_COLUMN" ) (/*AUTOARG*/ // Outputs app_rdy, use_addr, rank, bank, row, col, size, cmd, hi_priority, rd_accepted, wr_accepted, data_buf_addr, // Inputs rst, clk, accept_ns, rd_buf_full, wr_req_16, app_addr, app_cmd, app_sz, app_hi_pri, app_en, wr_data_buf_addr, rd_data_buf_addr_r ); input rst; input clk; input accept_ns; input rd_buf_full; input wr_req_16; wire app_rdy_ns = accept_ns && ~rd_buf_full && ~wr_req_16; (* keep = "true", max_fanout = 10 *) reg app_rdy_r = 1'b0 /* synthesis syn_maxfan = 10 */; always @(posedge clk) app_rdy_r <= #TCQ app_rdy_ns; output wire app_rdy; assign app_rdy = app_rdy_r; input [ADDR_WIDTH-1:0] app_addr; input [2:0] app_cmd; input app_sz; input app_hi_pri; input app_en; reg [ADDR_WIDTH-1:0] app_addr_r1 = {ADDR_WIDTH{1'b0}}; reg [ADDR_WIDTH-1:0] app_addr_r2 = {ADDR_WIDTH{1'b0}}; reg [2:0] app_cmd_r1; reg [2:0] app_cmd_r2; reg app_sz_r1; reg app_sz_r2; reg app_hi_pri_r1; reg app_hi_pri_r2; reg app_en_r1; reg app_en_r2; wire [ADDR_WIDTH-1:0] app_addr_ns1 = app_rdy_r && app_en ? app_addr : app_addr_r1; wire [ADDR_WIDTH-1:0] app_addr_ns2 = app_rdy_r ? app_addr_r1 : app_addr_r2; wire [2:0] app_cmd_ns1 = app_rdy_r ? app_cmd : app_cmd_r1; wire [2:0] app_cmd_ns2 = app_rdy_r ? app_cmd_r1 : app_cmd_r2; wire app_sz_ns1 = app_rdy_r ? app_sz : app_sz_r1; wire app_sz_ns2 = app_rdy_r ? app_sz_r1 : app_sz_r2; wire app_hi_pri_ns1 = app_rdy_r ? app_hi_pri : app_hi_pri_r1; wire app_hi_pri_ns2 = app_rdy_r ? app_hi_pri_r1 : app_hi_pri_r2; wire app_en_ns1 = ~rst && (app_rdy_r ? app_en : app_en_r1); wire app_en_ns2 = ~rst && (app_rdy_r ? app_en_r1 : app_en_r2); always @(posedge clk) begin if (rst) begin app_addr_r1 <= #TCQ {ADDR_WIDTH{1'b0}}; app_addr_r2 <= #TCQ {ADDR_WIDTH{1'b0}}; end else begin app_addr_r1 <= #TCQ app_addr_ns1; app_addr_r2 <= #TCQ app_addr_ns2; end app_cmd_r1 <= #TCQ app_cmd_ns1; app_cmd_r2 <= #TCQ app_cmd_ns2; app_sz_r1 <= #TCQ app_sz_ns1; app_sz_r2 <= #TCQ app_sz_ns2; app_hi_pri_r1 <= #TCQ app_hi_pri_ns1; app_hi_pri_r2 <= #TCQ app_hi_pri_ns2; app_en_r1 <= #TCQ app_en_ns1; app_en_r2 <= #TCQ app_en_ns2; end // always @ (posedge clk) wire use_addr_lcl = app_en_r2 && app_rdy_r; output wire use_addr; assign use_addr = use_addr_lcl; output wire [RANK_WIDTH-1:0] rank; output wire [BANK_WIDTH-1:0] bank; output wire [ROW_WIDTH-1:0] row; output wire [COL_WIDTH-1:0] col; output wire size; output wire [2:0] cmd; output wire hi_priority; /* assign col = app_rdy_r ? app_addr_r1[0+:COL_WIDTH] : app_addr_r2[0+:COL_WIDTH];*/ generate begin if (MEM_ADDR_ORDER == "TG_TEST") begin assign col[4:0] = app_rdy_r ? app_addr_r1[0+:5] : app_addr_r2[0+:5]; if (RANKS==1) begin assign col[COL_WIDTH-1:COL_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+:2] : app_addr_r2[5+3+BANK_WIDTH+:2]; assign col[COL_WIDTH-3:5] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+2+2+:COL_WIDTH-7] : app_addr_r2[5+3+BANK_WIDTH+2+2+:COL_WIDTH-7]; end else begin assign col[COL_WIDTH-1:COL_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+:2] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+:2]; assign col[COL_WIDTH-3:5] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+2+2+:COL_WIDTH-7] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+2+2+:COL_WIDTH-7]; end assign row[2:0] = app_rdy_r ? app_addr_r1[5+:3] : app_addr_r2[5+:3]; if (RANKS==1) begin assign row[ROW_WIDTH-1:ROW_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+2+:2] : app_addr_r2[5+3+BANK_WIDTH+2+:2]; assign row[ROW_WIDTH-3:3] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5] : app_addr_r2[5+3+BANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5]; end else begin assign row[ROW_WIDTH-1:ROW_WIDTH-2] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+2+:2] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+2+:2]; assign row[ROW_WIDTH-3:3] = app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+RANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5] : app_addr_r2[5+3+BANK_WIDTH+RANK_WIDTH+2+2+COL_WIDTH-7+:ROW_WIDTH-5]; end assign bank = app_rdy_r ? app_addr_r1[5+3+:BANK_WIDTH] : app_addr_r2[5+3+:BANK_WIDTH]; assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[5+3+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[5+3+BANK_WIDTH+:RANK_WIDTH]; end else if (MEM_ADDR_ORDER == "ROW_BANK_COLUMN") begin assign col = app_rdy_r ? app_addr_r1[0+:COL_WIDTH] : app_addr_r2[0+:COL_WIDTH]; assign row = app_rdy_r ? app_addr_r1[COL_WIDTH+BANK_WIDTH+:ROW_WIDTH] : app_addr_r2[COL_WIDTH+BANK_WIDTH+:ROW_WIDTH]; assign bank = app_rdy_r ? app_addr_r1[COL_WIDTH+:BANK_WIDTH] : app_addr_r2[COL_WIDTH+:BANK_WIDTH]; assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH]; end else begin assign col = app_rdy_r ? app_addr_r1[0+:COL_WIDTH] : app_addr_r2[0+:COL_WIDTH]; assign row = app_rdy_r ? app_addr_r1[COL_WIDTH+:ROW_WIDTH] : app_addr_r2[COL_WIDTH+:ROW_WIDTH]; assign bank = app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+:BANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+:BANK_WIDTH]; assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH]; end end endgenerate /* assign rank = (RANKS == 1) ? 1'b0 : app_rdy_r ? app_addr_r1[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH] : app_addr_r2[COL_WIDTH+ROW_WIDTH+BANK_WIDTH+:RANK_WIDTH];*/ assign size = app_rdy_r ? app_sz_r1 : app_sz_r2; assign cmd = app_rdy_r ? app_cmd_r1 : app_cmd_r2; assign hi_priority = app_rdy_r ? app_hi_pri_r1 : app_hi_pri_r2; wire request_accepted = use_addr_lcl && app_rdy_r; wire rd = app_cmd_r2[1:0] == 2'b01; wire wr = app_cmd_r2[1:0] == 2'b00; wire wr_bytes = app_cmd_r2[1:0] == 2'b11; wire write = wr || wr_bytes; output wire rd_accepted; assign rd_accepted = request_accepted && rd; output wire wr_accepted; assign wr_accepted = request_accepted && write; input [DATA_BUF_ADDR_WIDTH-1:0] wr_data_buf_addr; input [DATA_BUF_ADDR_WIDTH-1:0] rd_data_buf_addr_r; output wire [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr; assign data_buf_addr = ~write ? rd_data_buf_addr_r : wr_data_buf_addr; endmodule // ui_cmd // Local Variables: // verilog-library-directories:(".") // End:
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : mc.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** //***************************************************************************** // Top level memory sequencer structural block. This block // instantiates the rank, bank, and column machines. //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_mc # ( parameter TCQ = 100, // clk->out delay(sim only) parameter ADDR_CMD_MODE = "1T", // registered or // 1Tfered mem? parameter BANK_WIDTH = 3, // bank address width parameter BM_CNT_WIDTH = 2, // # BM counter width // i.e., log2(nBANK_MACHS) parameter BURST_MODE = "8", // Burst length parameter CL = 5, // Read CAS latency // (in clk cyc) parameter CMD_PIPE_PLUS1 = "ON", // add register stage // between MC and PHY parameter COL_WIDTH = 12, // column address width parameter CS_WIDTH = 4, // # of unique CS outputs parameter CWL = 5, // Write CAS latency // (in clk cyc) parameter DATA_BUF_ADDR_WIDTH = 8, // User request tag (e.g. // user src/dest buf addr) parameter DATA_BUF_OFFSET_WIDTH = 1, // User buffer offset width parameter DATA_WIDTH = 64, // Data bus width parameter DQ_WIDTH = 64, // # of DQ (data) parameter DQS_WIDTH = 8, // # of DQS (strobe) parameter DRAM_TYPE = "DDR3", // Memory I/F type: // "DDR3", "DDR2" parameter ECC = "OFF", // ECC ON/OFF? parameter ECC_WIDTH = 8, // # of ECC bits parameter MAINT_PRESCALER_PERIOD= 200000, // maintenance period (ps) parameter MC_ERR_ADDR_WIDTH = 31, // # of error address bits parameter nBANK_MACHS = 4, // # of bank machines (BM) parameter nCK_PER_CLK = 4, // DRAM clock : MC clock // frequency ratio parameter nCS_PER_RANK = 1, // # of unique CS outputs // per rank parameter nREFRESH_BANK = 1, // # of REF cmds to pull-in parameter nSLOTS = 1, // # DIMM slots in system parameter ORDERING = "NORM", // request ordering mode parameter PAYLOAD_WIDTH = 64, // Width of data payload // from PHY parameter RANK_WIDTH = 2, // # of bits to count ranks parameter RANKS = 4, // # of ranks of DRAM parameter REG_CTRL = "ON", // "ON" for registered DIMM parameter ROW_WIDTH = 16, // row address width parameter RTT_NOM = "40", // Nominal ODT value parameter RTT_WR = "120", // Write ODT value parameter SLOT_0_CONFIG = 8'b0000_0101, // ranks allowed in slot 0 parameter SLOT_1_CONFIG = 8'b0000_1010, // ranks allowed in slot 1 parameter STARVE_LIMIT = 2, // max # of times a user // request is allowed to // lose arbitration when // reordering is enabled parameter tCK = 2500, // memory clk period(ps) parameter tCKE = 10000, // CKE minimum pulse (ps) parameter tFAW = 40000, // four activate window(ps) parameter tRAS = 37500, // ACT->PRE cmd period (ps) parameter tRCD = 12500, // ACT->R/W delay (ps) parameter tREFI = 7800000, // average periodic // refresh interval(ps) parameter CKE_ODT_AUX = "FALSE", //Parameter to turn on/off the aux_out signal parameter tRFC = 110000, // REF->ACT/REF delay (ps) parameter tRP = 12500, // PRE cmd period (ps) parameter tRRD = 10000, // ACT->ACT period (ps) parameter tRTP = 7500, // Read->PRE cmd delay (ps) parameter tWTR = 7500, // Internal write->read // delay (ps) // requiring DLL lock (CKs) parameter tZQCS = 64, // ZQCS cmd period (CKs) parameter tZQI = 128_000_000, // ZQCS interval (ps) parameter tPRDI = 1_000_000, // pS parameter USER_REFRESH = "OFF" // Whether user manages REF ) ( // System inputs input clk, input rst, // Physical memory slot presence input [7:0] slot_0_present, input [7:0] slot_1_present, // Native Interface input [2:0] cmd, input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr, input hi_priority, input size, input [BANK_WIDTH-1:0] bank, input [COL_WIDTH-1:0] col, input [RANK_WIDTH-1:0] rank, input [ROW_WIDTH-1:0] row, input use_addr, input [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data, input [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask, output accept, output accept_ns, output [BM_CNT_WIDTH-1:0] bank_mach_next, output wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] rd_data, output [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr, output rd_data_en, output rd_data_end, output [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr /* synthesis syn_maxfan = 30 */, output reg wr_data_en, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset /* synthesis syn_maxfan = 30 */, output mc_read_idle, output mc_ref_zq_wip, // ECC interface input correct_en, input [2*nCK_PER_CLK-1:0] raw_not_ecc, output [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr, output [2*nCK_PER_CLK-1:0] ecc_single, output [2*nCK_PER_CLK-1:0] ecc_multiple, // User maintenance requests input app_periodic_rd_req, input app_ref_req, input app_zq_req, input app_sr_req, output app_sr_active, output app_ref_ack, output app_zq_ack, // MC <==> PHY Interface output reg [nCK_PER_CLK-1:0] mc_ras_n, output reg [nCK_PER_CLK-1:0] mc_cas_n, output reg [nCK_PER_CLK-1:0] mc_we_n, output reg [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address, output reg [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank, output reg [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n, output reg [1:0] mc_odt, output reg [nCK_PER_CLK-1:0] mc_cke, output wire mc_reset_n, output wire [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata, output wire [2*nCK_PER_CLK*DQ_WIDTH/8-1:0]mc_wrdata_mask, output reg mc_wrdata_en, output wire mc_cmd_wren, output wire mc_ctl_wren, output reg [2:0] mc_cmd, output reg [5:0] mc_data_offset, output reg [5:0] mc_data_offset_1, output reg [5:0] mc_data_offset_2, output reg [1:0] mc_cas_slot, output reg [3:0] mc_aux_out0, output reg [3:0] mc_aux_out1, output reg [1:0] mc_rank_cnt, input phy_mc_ctl_full, input phy_mc_cmd_full, input phy_mc_data_full, input [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_rd_data, input phy_rddata_valid, input init_calib_complete, input [6*RANKS-1:0] calib_rd_data_offset, input [6*RANKS-1:0] calib_rd_data_offset_1, input [6*RANKS-1:0] calib_rd_data_offset_2 ); assign mc_reset_n = 1'b1; // never reset memory assign mc_cmd_wren = 1'b1; // always write CMD FIFO(issue DSEL when idle) assign mc_ctl_wren = 1'b1; // always write CTL FIFO(issue nondata when idle) // Ensure there is always at least one rank present during operation `ifdef MC_SVA ranks_present: assert property (@(posedge clk) (rst || (|(slot_0_present | slot_1_present)))); `endif // Reserved. Do not change. localparam nPHY_WRLAT = 2; // always delay write data control unless ECC mode is enabled localparam DELAY_WR_DATA_CNTRL = ECC == "ON" ? 0 : 1; // Ensure that write control is delayed for appropriate CWL /*`ifdef MC_SVA delay_wr_data_zero_CWL_le_6: assert property (@(posedge clk) ((CWL > 6) || (DELAY_WR_DATA_CNTRL == 0))); `endif*/ // Never retrieve WR_DATA_ADDR early localparam EARLY_WR_DATA_ADDR = "OFF"; //*************************************************************************** // Convert timing parameters from time to clock cycles //*************************************************************************** localparam nCKE = cdiv(tCKE, tCK); localparam nRP = cdiv(tRP, tCK); localparam nRCD = cdiv(tRCD, tCK); localparam nRAS = cdiv(tRAS, tCK); localparam nFAW = cdiv(tFAW, tCK); localparam nRFC = cdiv(tRFC, tCK); // Convert tWR. As per specification, write recover for autoprecharge // cycles doesn't support values of 9 and 11. Round up 9 to 10 and 11 to 12 localparam nWR_CK = cdiv(15000, tCK) ; localparam nWR = (nWR_CK == 9) ? 10 : (nWR_CK == 11) ? 12 : nWR_CK; // tRRD, tWTR at tRTP have a 4 cycle floor in DDR3 and 2 cycle floor in DDR2 localparam nRRD_CK = cdiv(tRRD, tCK); localparam nRRD = (DRAM_TYPE == "DDR3") ? (nRRD_CK < 4) ? 4 : nRRD_CK : (nRRD_CK < 2) ? 2 : nRRD_CK; localparam nWTR_CK = cdiv(tWTR, tCK); localparam nWTR = (DRAM_TYPE == "DDR3") ? (nWTR_CK < 4) ? 4 : nWTR_CK : (nWTR_CK < 2) ? 2 : nWTR_CK; localparam nRTP_CK = cdiv(tRTP, tCK); localparam nRTP = (DRAM_TYPE == "DDR3") ? (nRTP_CK < 4) ? 4 : nRTP_CK : (nRTP_CK < 2) ? 2 : nRTP_CK; // Add a cycle to CL/CWL for the register in RDIMM devices localparam CWL_M = (REG_CTRL == "ON") ? CWL + 1 : CWL; localparam CL_M = (REG_CTRL == "ON") ? CL + 1 : CL; // Tuneable delay between read and write data on the DQ bus localparam DQRD2DQWR_DLY = 4; // CKE minimum pulse width for self-refresh (SRE->SRX minimum time) localparam nCKESR = nCKE + 1; // Delay from SRE to command requiring locked DLL. Currently fixed at 512 for // all devices per JEDEC spec. localparam tXSDLL = 512; //*************************************************************************** // Set up maintenance counter dividers //*************************************************************************** // CK clock divisor to generate maintenance prescaler period (round down) localparam MAINT_PRESCALER_DIV = MAINT_PRESCALER_PERIOD / (tCK*nCK_PER_CLK); // Maintenance prescaler divisor for refresh timer. Essentially, this is // just (tREFI / MAINT_PRESCALER_PERIOD), but we must account for the worst // case delay from the time we get a tick from the refresh counter to the // time that we can actually issue the REF command. Thus, subtract tRCD, CL, // data burst time and tRP for each implemented bank machine to ensure that // all transactions can complete before tREFI expires localparam REFRESH_TIMER_DIV = USER_REFRESH == "ON" ? 0 : (tREFI-((tRCD+((CL+4)*tCK)+tRP)*nBANK_MACHS)) / MAINT_PRESCALER_PERIOD; // Periodic read (RESERVED - not currently required or supported in 7 series) // tPRDI should only be set to 0 // localparam tPRDI = 0; // Do NOT change. localparam PERIODIC_RD_TIMER_DIV = tPRDI / MAINT_PRESCALER_PERIOD; // Convert maintenance prescaler from ps to ns localparam MAINT_PRESCALER_PERIOD_NS = MAINT_PRESCALER_PERIOD / 1000; // Maintenance prescaler divisor for ZQ calibration (ZQCS) timer localparam ZQ_TIMER_DIV = tZQI / MAINT_PRESCALER_PERIOD_NS; // Bus width required to broadcast a single bit rank signal among all the // bank machines - 1 bit per rank, per bank localparam RANK_BM_BV_WIDTH = nBANK_MACHS * RANKS; //*************************************************************************** // Define 2T, CWL-even mode to enable multi-fabric-cycle 2T commands //*************************************************************************** localparam EVEN_CWL_2T_MODE = ((ADDR_CMD_MODE == "2T") && (!(CWL % 2))) ? "ON" : "OFF"; //*************************************************************************** // Reserved feature control. //*************************************************************************** // Open page wait mode is reserved. // nOP_WAIT is the number of states a bank machine will park itself // on an otherwise inactive open page before closing the page. If // nOP_WAIT == 0, open page wait mode is disabled. If nOP_WAIT == -1, // the bank machine will remain parked until the pool of idle bank machines // are less than LOW_IDLE_CNT. At which point parked bank machines // are selected to exit until the number of idle bank machines exceeds the // LOW_IDLE_CNT. localparam nOP_WAIT = 0; // Open page mode localparam LOW_IDLE_CNT = 0; // Low idle bank machine threshold //*************************************************************************** // Internal wires //*************************************************************************** wire [RANK_BM_BV_WIDTH-1:0] act_this_rank_r; wire [ROW_WIDTH-1:0] col_a; wire [BANK_WIDTH-1:0] col_ba; wire [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr; wire col_periodic_rd; wire [RANK_WIDTH-1:0] col_ra; wire col_rmw; wire col_rd_wr; wire [ROW_WIDTH-1:0] col_row; wire col_size; wire [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr; wire dq_busy_data; wire ecc_status_valid; wire [RANKS-1:0] inhbt_act_faw_r; wire [RANKS-1:0] inhbt_rd; wire [RANKS-1:0] inhbt_wr; wire insert_maint_r1; wire [RANK_WIDTH-1:0] maint_rank_r; wire maint_req_r; wire maint_wip_r; wire maint_zq_r; wire maint_sre_r; wire maint_srx_r; wire periodic_rd_ack_r; wire periodic_rd_r; wire [RANK_WIDTH-1:0] periodic_rd_rank_r; wire [(RANKS*nBANK_MACHS)-1:0] rank_busy_r; wire rd_rmw; wire [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r; wire [nBANK_MACHS-1:0] sending_col; wire [nBANK_MACHS-1:0] sending_row; wire sent_col; wire sent_col_r; wire wr_ecc_buf; wire [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r; // MC/PHY optional pipeline stage support wire [nCK_PER_CLK-1:0] mc_ras_n_ns; wire [nCK_PER_CLK-1:0] mc_cas_n_ns; wire [nCK_PER_CLK-1:0] mc_we_n_ns; wire [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address_ns; wire [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank_ns; wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n_ns; wire [1:0] mc_odt_ns; wire [nCK_PER_CLK-1:0] mc_cke_ns; wire [3:0] mc_aux_out0_ns; wire [3:0] mc_aux_out1_ns; wire [1:0] mc_rank_cnt_ns = col_ra; wire [2:0] mc_cmd_ns; wire [5:0] mc_data_offset_ns; wire [5:0] mc_data_offset_1_ns; wire [5:0] mc_data_offset_2_ns; wire [1:0] mc_cas_slot_ns; wire mc_wrdata_en_ns; wire [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr_ns; wire wr_data_en_ns; wire [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset_ns; integer i; // MC Read idle support wire col_read_fifo_empty; wire mc_read_idle_ns; reg mc_read_idle_r; // MC Maintenance in progress with bus idle indication wire maint_ref_zq_wip; wire mc_ref_zq_wip_ns; reg mc_ref_zq_wip_r; //*************************************************************************** // Function cdiv // Description: // This function performs ceiling division (divide and round-up) // Inputs: // num: integer to be divided // div: divisor // Outputs: // cdiv: result of ceiling division (num/div, rounded up) //*************************************************************************** function integer cdiv (input integer num, input integer div); begin // perform division, then add 1 if and only if remainder is non-zero cdiv = (num/div) + (((num%div)>0) ? 1 : 0); end endfunction // cdiv //*************************************************************************** // Optional pipeline register stage on MC/PHY interface //*************************************************************************** generate if (CMD_PIPE_PLUS1 == "ON") begin : cmd_pipe_plus // register interface always @(posedge clk) begin mc_address <= #TCQ mc_address_ns; mc_bank <= #TCQ mc_bank_ns; mc_cas_n <= #TCQ mc_cas_n_ns; mc_cs_n <= #TCQ mc_cs_n_ns; mc_odt <= #TCQ mc_odt_ns; mc_cke <= #TCQ mc_cke_ns; mc_aux_out0 <= #TCQ mc_aux_out0_ns; mc_aux_out1 <= #TCQ mc_aux_out1_ns; mc_cmd <= #TCQ mc_cmd_ns; mc_ras_n <= #TCQ mc_ras_n_ns; mc_we_n <= #TCQ mc_we_n_ns; mc_data_offset <= #TCQ mc_data_offset_ns; mc_data_offset_1 <= #TCQ mc_data_offset_1_ns; mc_data_offset_2 <= #TCQ mc_data_offset_2_ns; mc_cas_slot <= #TCQ mc_cas_slot_ns; mc_wrdata_en <= #TCQ mc_wrdata_en_ns; mc_rank_cnt <= #TCQ mc_rank_cnt_ns; wr_data_addr <= #TCQ wr_data_addr_ns; wr_data_en <= #TCQ wr_data_en_ns; wr_data_offset <= #TCQ wr_data_offset_ns; end // always @ (posedge clk) end // block: cmd_pipe_plus else begin : cmd_pipe_plus0 // don't register interface always @( mc_address_ns or mc_aux_out0_ns or mc_aux_out1_ns or mc_bank_ns or mc_cas_n_ns or mc_cmd_ns or mc_cs_n_ns or mc_odt_ns or mc_cke_ns or mc_data_offset_ns or mc_data_offset_1_ns or mc_data_offset_2_ns or mc_rank_cnt_ns or mc_ras_n_ns or mc_we_n_ns or mc_wrdata_en_ns or wr_data_addr_ns or wr_data_en_ns or wr_data_offset_ns or mc_cas_slot_ns) begin mc_address = #TCQ mc_address_ns; mc_bank = #TCQ mc_bank_ns; mc_cas_n = #TCQ mc_cas_n_ns; mc_cs_n = #TCQ mc_cs_n_ns; mc_odt = #TCQ mc_odt_ns; mc_cke = #TCQ mc_cke_ns; mc_aux_out0 = #TCQ mc_aux_out0_ns; mc_aux_out1 = #TCQ mc_aux_out1_ns; mc_cmd = #TCQ mc_cmd_ns; mc_ras_n = #TCQ mc_ras_n_ns; mc_we_n = #TCQ mc_we_n_ns; mc_data_offset = #TCQ mc_data_offset_ns; mc_data_offset_1 = #TCQ mc_data_offset_1_ns; mc_data_offset_2 = #TCQ mc_data_offset_2_ns; mc_cas_slot = #TCQ mc_cas_slot_ns; mc_wrdata_en = #TCQ mc_wrdata_en_ns; mc_rank_cnt = #TCQ mc_rank_cnt_ns; wr_data_addr = #TCQ wr_data_addr_ns; wr_data_en = #TCQ wr_data_en_ns; wr_data_offset = #TCQ wr_data_offset_ns; end // always @ (... end // block: cmd_pipe_plus0 endgenerate //*************************************************************************** // Indicate when there are no pending reads so that input features can be // powered down //*************************************************************************** assign mc_read_idle_ns = col_read_fifo_empty & init_calib_complete; always @(posedge clk) mc_read_idle_r <= #TCQ mc_read_idle_ns; assign mc_read_idle = mc_read_idle_r; //*************************************************************************** // Indicate when there is a refresh in progress and the bus is idle so that // tap adjustments can be made //*************************************************************************** assign mc_ref_zq_wip_ns = maint_ref_zq_wip && col_read_fifo_empty; always @(posedge clk) mc_ref_zq_wip_r <= mc_ref_zq_wip_ns; assign mc_ref_zq_wip = mc_ref_zq_wip_r; //*************************************************************************** // Manage rank-level timing and maintanence //*************************************************************************** mig_7series_v1_9_rank_mach # ( // Parameters .BURST_MODE (BURST_MODE), .CL (CL), .CWL (CWL), .CS_WIDTH (CS_WIDTH), .DQRD2DQWR_DLY (DQRD2DQWR_DLY), .DRAM_TYPE (DRAM_TYPE), .MAINT_PRESCALER_DIV (MAINT_PRESCALER_DIV), .nBANK_MACHS (nBANK_MACHS), .nCKESR (nCKESR), .nCK_PER_CLK (nCK_PER_CLK), .nFAW (nFAW), .nREFRESH_BANK (nREFRESH_BANK), .nRRD (nRRD), .nWTR (nWTR), .PERIODIC_RD_TIMER_DIV (PERIODIC_RD_TIMER_DIV), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .REFRESH_TIMER_DIV (REFRESH_TIMER_DIV), .ZQ_TIMER_DIV (ZQ_TIMER_DIV) ) rank_mach0 ( // Outputs .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .maint_ref_zq_wip (maint_ref_zq_wip), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), // Inputs .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .app_periodic_rd_req (app_periodic_rd_req), .app_ref_req (app_ref_req), .app_ref_ack (app_ref_ack), .app_zq_req (app_zq_req), .app_zq_ack (app_zq_ack), .app_sr_req (app_sr_req), .app_sr_active (app_sr_active), .col_rd_wr (col_rd_wr), .clk (clk), .init_calib_complete (init_calib_complete), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .rst (rst), .sending_col (sending_col[nBANK_MACHS-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]) ); //*************************************************************************** // Manage requests, reordering and bank timing //*************************************************************************** mig_7series_v1_9_bank_mach # ( // Parameters .TCQ (TCQ), .EVEN_CWL_2T_MODE (EVEN_CWL_2T_MODE), .ADDR_CMD_MODE (ADDR_CMD_MODE), .BANK_WIDTH (BANK_WIDTH), .BM_CNT_WIDTH (BM_CNT_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .CL (CL_M), .CWL (CWL_M), .CKE_ODT_AUX (CKE_ODT_AUX), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .LOW_IDLE_CNT (LOW_IDLE_CNT), .nBANK_MACHS (nBANK_MACHS), .nCK_PER_CLK (nCK_PER_CLK), .nCS_PER_RANK (nCS_PER_RANK), .nOP_WAIT (nOP_WAIT), .nRAS (nRAS), .nRCD (nRCD), .nRFC (nRFC), .nRP (nRP), .nRTP (nRTP), .nSLOTS (nSLOTS), .nWR (nWR), .nXSDLL (tXSDLL), .ORDERING (ORDERING), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .ROW_WIDTH (ROW_WIDTH), .RTT_NOM (RTT_NOM), .RTT_WR (RTT_WR), .SLOT_0_CONFIG (SLOT_0_CONFIG), .SLOT_1_CONFIG (SLOT_1_CONFIG), .STARVE_LIMIT (STARVE_LIMIT), .tZQCS (tZQCS) ) bank_mach0 ( // Outputs .accept (accept), .accept_ns (accept_ns), .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .bank_mach_next (bank_mach_next[BM_CNT_WIDTH-1:0]), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .mc_bank (mc_bank_ns), .mc_address (mc_address_ns), .mc_ras_n (mc_ras_n_ns), .mc_cas_n (mc_cas_n_ns), .mc_we_n (mc_we_n_ns), .mc_cs_n (mc_cs_n_ns), .mc_odt (mc_odt_ns), .mc_cke (mc_cke_ns), .mc_aux_out0 (mc_aux_out0_ns), .mc_aux_out1 (mc_aux_out1_ns), .mc_cmd (mc_cmd_ns), .mc_data_offset (mc_data_offset_ns), .mc_data_offset_1 (mc_data_offset_1_ns), .mc_data_offset_2 (mc_data_offset_2_ns), .mc_cas_slot (mc_cas_slot_ns), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .sending_col (sending_col[nBANK_MACHS-1:0]), .sent_col (sent_col), .sent_col_r (sent_col_r), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]), // Inputs .bank (bank[BANK_WIDTH-1:0]), .calib_rddata_offset (calib_rd_data_offset), .calib_rddata_offset_1 (calib_rd_data_offset_1), .calib_rddata_offset_2 (calib_rd_data_offset_2), .clk (clk), .cmd (cmd[2:0]), .col (col[COL_WIDTH-1:0]), .data_buf_addr (data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .init_calib_complete (init_calib_complete), .phy_rddata_valid (phy_rddata_valid), .dq_busy_data (dq_busy_data), .hi_priority (hi_priority), .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), .phy_mc_cmd_full (phy_mc_cmd_full), .phy_mc_ctl_full (phy_mc_ctl_full), .phy_mc_data_full (phy_mc_data_full), .rank (rank[RANK_WIDTH-1:0]), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_rmw (rd_rmw), .row (row[ROW_WIDTH-1:0]), .rst (rst), .size (size), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .use_addr (use_addr) ); //*************************************************************************** // Manage DQ bus //*************************************************************************** mig_7series_v1_9_col_mach # ( // Parameters .TCQ (TCQ), .BANK_WIDTH (BANK_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DELAY_WR_DATA_CNTRL (DELAY_WR_DATA_CNTRL), .DQS_WIDTH (DQS_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .MC_ERR_ADDR_WIDTH (MC_ERR_ADDR_WIDTH), .nCK_PER_CLK (nCK_PER_CLK), .nPHY_WRLAT (nPHY_WRLAT), .RANK_WIDTH (RANK_WIDTH), .ROW_WIDTH (ROW_WIDTH) ) col_mach0 ( // Outputs .mc_wrdata_en (mc_wrdata_en_ns), .dq_busy_data (dq_busy_data), .ecc_err_addr (ecc_err_addr[MC_ERR_ADDR_WIDTH-1:0]), .ecc_status_valid (ecc_status_valid), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_data_en (rd_data_en), .rd_data_end (rd_data_end), .rd_data_offset (rd_data_offset), .rd_rmw (rd_rmw), .wr_data_addr (wr_data_addr_ns), .wr_data_en (wr_data_en_ns), .wr_data_offset (wr_data_offset_ns), .wr_ecc_buf (wr_ecc_buf), .col_read_fifo_empty (col_read_fifo_empty), // Inputs .clk (clk), .rst (rst), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .phy_rddata_valid (phy_rddata_valid), .sent_col (EVEN_CWL_2T_MODE == "ON" ? sent_col_r : sent_col) ); //*************************************************************************** // Implement ECC //*************************************************************************** // Total ECC word length = ECC code width + Data width localparam CODE_WIDTH = DATA_WIDTH + ECC_WIDTH; generate if (ECC == "OFF") begin : ecc_off assign rd_data = phy_rd_data; assign mc_wrdata = wr_data; assign mc_wrdata_mask = wr_data_mask; assign ecc_single = 4'b0; assign ecc_multiple = 4'b0; end else begin : ecc_on wire [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; wire [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data; // Merge and encode mig_7series_v1_9_ecc_merge_enc # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_merge_enc0 ( // Outputs .mc_wrdata (mc_wrdata), .mc_wrdata_mask (mc_wrdata_mask), // Inputs .clk (clk), .rst (rst), .h_rows (h_rows), .rd_merge_data (rd_merge_data), .raw_not_ecc (raw_not_ecc), .wr_data (wr_data), .wr_data_mask (wr_data_mask) ); // Decode and fix mig_7series_v1_9_ecc_dec_fix # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_dec_fix0 ( // Outputs .ecc_multiple (ecc_multiple), .ecc_single (ecc_single), .rd_data (rd_data), // Inputs .clk (clk), .rst (rst), .correct_en (correct_en), .phy_rddata (phy_rd_data), .ecc_status_valid (ecc_status_valid), .h_rows (h_rows) ); // ECC Buffer mig_7series_v1_9_ecc_buf # ( // Parameters .TCQ (TCQ), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DATA_WIDTH (DATA_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_buf0 ( // Outputs .rd_merge_data (rd_merge_data), // Inputs .clk (clk), .rst (rst), .rd_data (rd_data), .rd_data_addr (rd_data_addr), .rd_data_offset (rd_data_offset), .wr_data_addr (wr_data_addr), .wr_data_offset (wr_data_offset), .wr_ecc_buf (wr_ecc_buf) ); // Generate ECC table mig_7series_v1_9_ecc_gen # ( // Parameters .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .ECC_WIDTH (ECC_WIDTH) ) ecc_gen0 ( // Outputs .h_rows (h_rows) ); `ifdef DISPLAY_H_MATRIX integer i; always @(negedge rst) begin $display ("**********************************************"); $display ("H Matrix:"); for (i=0; i<ECC_WIDTH; i=i+1) $display ("%b", h_rows[i*CODE_WIDTH+:CODE_WIDTH]); $display ("**********************************************"); end `endif end endgenerate endmodule // mc
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : mc.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** //***************************************************************************** // Top level memory sequencer structural block. This block // instantiates the rank, bank, and column machines. //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_mc # ( parameter TCQ = 100, // clk->out delay(sim only) parameter ADDR_CMD_MODE = "1T", // registered or // 1Tfered mem? parameter BANK_WIDTH = 3, // bank address width parameter BM_CNT_WIDTH = 2, // # BM counter width // i.e., log2(nBANK_MACHS) parameter BURST_MODE = "8", // Burst length parameter CL = 5, // Read CAS latency // (in clk cyc) parameter CMD_PIPE_PLUS1 = "ON", // add register stage // between MC and PHY parameter COL_WIDTH = 12, // column address width parameter CS_WIDTH = 4, // # of unique CS outputs parameter CWL = 5, // Write CAS latency // (in clk cyc) parameter DATA_BUF_ADDR_WIDTH = 8, // User request tag (e.g. // user src/dest buf addr) parameter DATA_BUF_OFFSET_WIDTH = 1, // User buffer offset width parameter DATA_WIDTH = 64, // Data bus width parameter DQ_WIDTH = 64, // # of DQ (data) parameter DQS_WIDTH = 8, // # of DQS (strobe) parameter DRAM_TYPE = "DDR3", // Memory I/F type: // "DDR3", "DDR2" parameter ECC = "OFF", // ECC ON/OFF? parameter ECC_WIDTH = 8, // # of ECC bits parameter MAINT_PRESCALER_PERIOD= 200000, // maintenance period (ps) parameter MC_ERR_ADDR_WIDTH = 31, // # of error address bits parameter nBANK_MACHS = 4, // # of bank machines (BM) parameter nCK_PER_CLK = 4, // DRAM clock : MC clock // frequency ratio parameter nCS_PER_RANK = 1, // # of unique CS outputs // per rank parameter nREFRESH_BANK = 1, // # of REF cmds to pull-in parameter nSLOTS = 1, // # DIMM slots in system parameter ORDERING = "NORM", // request ordering mode parameter PAYLOAD_WIDTH = 64, // Width of data payload // from PHY parameter RANK_WIDTH = 2, // # of bits to count ranks parameter RANKS = 4, // # of ranks of DRAM parameter REG_CTRL = "ON", // "ON" for registered DIMM parameter ROW_WIDTH = 16, // row address width parameter RTT_NOM = "40", // Nominal ODT value parameter RTT_WR = "120", // Write ODT value parameter SLOT_0_CONFIG = 8'b0000_0101, // ranks allowed in slot 0 parameter SLOT_1_CONFIG = 8'b0000_1010, // ranks allowed in slot 1 parameter STARVE_LIMIT = 2, // max # of times a user // request is allowed to // lose arbitration when // reordering is enabled parameter tCK = 2500, // memory clk period(ps) parameter tCKE = 10000, // CKE minimum pulse (ps) parameter tFAW = 40000, // four activate window(ps) parameter tRAS = 37500, // ACT->PRE cmd period (ps) parameter tRCD = 12500, // ACT->R/W delay (ps) parameter tREFI = 7800000, // average periodic // refresh interval(ps) parameter CKE_ODT_AUX = "FALSE", //Parameter to turn on/off the aux_out signal parameter tRFC = 110000, // REF->ACT/REF delay (ps) parameter tRP = 12500, // PRE cmd period (ps) parameter tRRD = 10000, // ACT->ACT period (ps) parameter tRTP = 7500, // Read->PRE cmd delay (ps) parameter tWTR = 7500, // Internal write->read // delay (ps) // requiring DLL lock (CKs) parameter tZQCS = 64, // ZQCS cmd period (CKs) parameter tZQI = 128_000_000, // ZQCS interval (ps) parameter tPRDI = 1_000_000, // pS parameter USER_REFRESH = "OFF" // Whether user manages REF ) ( // System inputs input clk, input rst, // Physical memory slot presence input [7:0] slot_0_present, input [7:0] slot_1_present, // Native Interface input [2:0] cmd, input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr, input hi_priority, input size, input [BANK_WIDTH-1:0] bank, input [COL_WIDTH-1:0] col, input [RANK_WIDTH-1:0] rank, input [ROW_WIDTH-1:0] row, input use_addr, input [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data, input [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask, output accept, output accept_ns, output [BM_CNT_WIDTH-1:0] bank_mach_next, output wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] rd_data, output [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr, output rd_data_en, output rd_data_end, output [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr /* synthesis syn_maxfan = 30 */, output reg wr_data_en, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset /* synthesis syn_maxfan = 30 */, output mc_read_idle, output mc_ref_zq_wip, // ECC interface input correct_en, input [2*nCK_PER_CLK-1:0] raw_not_ecc, output [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr, output [2*nCK_PER_CLK-1:0] ecc_single, output [2*nCK_PER_CLK-1:0] ecc_multiple, // User maintenance requests input app_periodic_rd_req, input app_ref_req, input app_zq_req, input app_sr_req, output app_sr_active, output app_ref_ack, output app_zq_ack, // MC <==> PHY Interface output reg [nCK_PER_CLK-1:0] mc_ras_n, output reg [nCK_PER_CLK-1:0] mc_cas_n, output reg [nCK_PER_CLK-1:0] mc_we_n, output reg [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address, output reg [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank, output reg [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n, output reg [1:0] mc_odt, output reg [nCK_PER_CLK-1:0] mc_cke, output wire mc_reset_n, output wire [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata, output wire [2*nCK_PER_CLK*DQ_WIDTH/8-1:0]mc_wrdata_mask, output reg mc_wrdata_en, output wire mc_cmd_wren, output wire mc_ctl_wren, output reg [2:0] mc_cmd, output reg [5:0] mc_data_offset, output reg [5:0] mc_data_offset_1, output reg [5:0] mc_data_offset_2, output reg [1:0] mc_cas_slot, output reg [3:0] mc_aux_out0, output reg [3:0] mc_aux_out1, output reg [1:0] mc_rank_cnt, input phy_mc_ctl_full, input phy_mc_cmd_full, input phy_mc_data_full, input [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_rd_data, input phy_rddata_valid, input init_calib_complete, input [6*RANKS-1:0] calib_rd_data_offset, input [6*RANKS-1:0] calib_rd_data_offset_1, input [6*RANKS-1:0] calib_rd_data_offset_2 ); assign mc_reset_n = 1'b1; // never reset memory assign mc_cmd_wren = 1'b1; // always write CMD FIFO(issue DSEL when idle) assign mc_ctl_wren = 1'b1; // always write CTL FIFO(issue nondata when idle) // Ensure there is always at least one rank present during operation `ifdef MC_SVA ranks_present: assert property (@(posedge clk) (rst || (|(slot_0_present | slot_1_present)))); `endif // Reserved. Do not change. localparam nPHY_WRLAT = 2; // always delay write data control unless ECC mode is enabled localparam DELAY_WR_DATA_CNTRL = ECC == "ON" ? 0 : 1; // Ensure that write control is delayed for appropriate CWL /*`ifdef MC_SVA delay_wr_data_zero_CWL_le_6: assert property (@(posedge clk) ((CWL > 6) || (DELAY_WR_DATA_CNTRL == 0))); `endif*/ // Never retrieve WR_DATA_ADDR early localparam EARLY_WR_DATA_ADDR = "OFF"; //*************************************************************************** // Convert timing parameters from time to clock cycles //*************************************************************************** localparam nCKE = cdiv(tCKE, tCK); localparam nRP = cdiv(tRP, tCK); localparam nRCD = cdiv(tRCD, tCK); localparam nRAS = cdiv(tRAS, tCK); localparam nFAW = cdiv(tFAW, tCK); localparam nRFC = cdiv(tRFC, tCK); // Convert tWR. As per specification, write recover for autoprecharge // cycles doesn't support values of 9 and 11. Round up 9 to 10 and 11 to 12 localparam nWR_CK = cdiv(15000, tCK) ; localparam nWR = (nWR_CK == 9) ? 10 : (nWR_CK == 11) ? 12 : nWR_CK; // tRRD, tWTR at tRTP have a 4 cycle floor in DDR3 and 2 cycle floor in DDR2 localparam nRRD_CK = cdiv(tRRD, tCK); localparam nRRD = (DRAM_TYPE == "DDR3") ? (nRRD_CK < 4) ? 4 : nRRD_CK : (nRRD_CK < 2) ? 2 : nRRD_CK; localparam nWTR_CK = cdiv(tWTR, tCK); localparam nWTR = (DRAM_TYPE == "DDR3") ? (nWTR_CK < 4) ? 4 : nWTR_CK : (nWTR_CK < 2) ? 2 : nWTR_CK; localparam nRTP_CK = cdiv(tRTP, tCK); localparam nRTP = (DRAM_TYPE == "DDR3") ? (nRTP_CK < 4) ? 4 : nRTP_CK : (nRTP_CK < 2) ? 2 : nRTP_CK; // Add a cycle to CL/CWL for the register in RDIMM devices localparam CWL_M = (REG_CTRL == "ON") ? CWL + 1 : CWL; localparam CL_M = (REG_CTRL == "ON") ? CL + 1 : CL; // Tuneable delay between read and write data on the DQ bus localparam DQRD2DQWR_DLY = 4; // CKE minimum pulse width for self-refresh (SRE->SRX minimum time) localparam nCKESR = nCKE + 1; // Delay from SRE to command requiring locked DLL. Currently fixed at 512 for // all devices per JEDEC spec. localparam tXSDLL = 512; //*************************************************************************** // Set up maintenance counter dividers //*************************************************************************** // CK clock divisor to generate maintenance prescaler period (round down) localparam MAINT_PRESCALER_DIV = MAINT_PRESCALER_PERIOD / (tCK*nCK_PER_CLK); // Maintenance prescaler divisor for refresh timer. Essentially, this is // just (tREFI / MAINT_PRESCALER_PERIOD), but we must account for the worst // case delay from the time we get a tick from the refresh counter to the // time that we can actually issue the REF command. Thus, subtract tRCD, CL, // data burst time and tRP for each implemented bank machine to ensure that // all transactions can complete before tREFI expires localparam REFRESH_TIMER_DIV = USER_REFRESH == "ON" ? 0 : (tREFI-((tRCD+((CL+4)*tCK)+tRP)*nBANK_MACHS)) / MAINT_PRESCALER_PERIOD; // Periodic read (RESERVED - not currently required or supported in 7 series) // tPRDI should only be set to 0 // localparam tPRDI = 0; // Do NOT change. localparam PERIODIC_RD_TIMER_DIV = tPRDI / MAINT_PRESCALER_PERIOD; // Convert maintenance prescaler from ps to ns localparam MAINT_PRESCALER_PERIOD_NS = MAINT_PRESCALER_PERIOD / 1000; // Maintenance prescaler divisor for ZQ calibration (ZQCS) timer localparam ZQ_TIMER_DIV = tZQI / MAINT_PRESCALER_PERIOD_NS; // Bus width required to broadcast a single bit rank signal among all the // bank machines - 1 bit per rank, per bank localparam RANK_BM_BV_WIDTH = nBANK_MACHS * RANKS; //*************************************************************************** // Define 2T, CWL-even mode to enable multi-fabric-cycle 2T commands //*************************************************************************** localparam EVEN_CWL_2T_MODE = ((ADDR_CMD_MODE == "2T") && (!(CWL % 2))) ? "ON" : "OFF"; //*************************************************************************** // Reserved feature control. //*************************************************************************** // Open page wait mode is reserved. // nOP_WAIT is the number of states a bank machine will park itself // on an otherwise inactive open page before closing the page. If // nOP_WAIT == 0, open page wait mode is disabled. If nOP_WAIT == -1, // the bank machine will remain parked until the pool of idle bank machines // are less than LOW_IDLE_CNT. At which point parked bank machines // are selected to exit until the number of idle bank machines exceeds the // LOW_IDLE_CNT. localparam nOP_WAIT = 0; // Open page mode localparam LOW_IDLE_CNT = 0; // Low idle bank machine threshold //*************************************************************************** // Internal wires //*************************************************************************** wire [RANK_BM_BV_WIDTH-1:0] act_this_rank_r; wire [ROW_WIDTH-1:0] col_a; wire [BANK_WIDTH-1:0] col_ba; wire [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr; wire col_periodic_rd; wire [RANK_WIDTH-1:0] col_ra; wire col_rmw; wire col_rd_wr; wire [ROW_WIDTH-1:0] col_row; wire col_size; wire [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr; wire dq_busy_data; wire ecc_status_valid; wire [RANKS-1:0] inhbt_act_faw_r; wire [RANKS-1:0] inhbt_rd; wire [RANKS-1:0] inhbt_wr; wire insert_maint_r1; wire [RANK_WIDTH-1:0] maint_rank_r; wire maint_req_r; wire maint_wip_r; wire maint_zq_r; wire maint_sre_r; wire maint_srx_r; wire periodic_rd_ack_r; wire periodic_rd_r; wire [RANK_WIDTH-1:0] periodic_rd_rank_r; wire [(RANKS*nBANK_MACHS)-1:0] rank_busy_r; wire rd_rmw; wire [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r; wire [nBANK_MACHS-1:0] sending_col; wire [nBANK_MACHS-1:0] sending_row; wire sent_col; wire sent_col_r; wire wr_ecc_buf; wire [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r; // MC/PHY optional pipeline stage support wire [nCK_PER_CLK-1:0] mc_ras_n_ns; wire [nCK_PER_CLK-1:0] mc_cas_n_ns; wire [nCK_PER_CLK-1:0] mc_we_n_ns; wire [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address_ns; wire [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank_ns; wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n_ns; wire [1:0] mc_odt_ns; wire [nCK_PER_CLK-1:0] mc_cke_ns; wire [3:0] mc_aux_out0_ns; wire [3:0] mc_aux_out1_ns; wire [1:0] mc_rank_cnt_ns = col_ra; wire [2:0] mc_cmd_ns; wire [5:0] mc_data_offset_ns; wire [5:0] mc_data_offset_1_ns; wire [5:0] mc_data_offset_2_ns; wire [1:0] mc_cas_slot_ns; wire mc_wrdata_en_ns; wire [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr_ns; wire wr_data_en_ns; wire [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset_ns; integer i; // MC Read idle support wire col_read_fifo_empty; wire mc_read_idle_ns; reg mc_read_idle_r; // MC Maintenance in progress with bus idle indication wire maint_ref_zq_wip; wire mc_ref_zq_wip_ns; reg mc_ref_zq_wip_r; //*************************************************************************** // Function cdiv // Description: // This function performs ceiling division (divide and round-up) // Inputs: // num: integer to be divided // div: divisor // Outputs: // cdiv: result of ceiling division (num/div, rounded up) //*************************************************************************** function integer cdiv (input integer num, input integer div); begin // perform division, then add 1 if and only if remainder is non-zero cdiv = (num/div) + (((num%div)>0) ? 1 : 0); end endfunction // cdiv //*************************************************************************** // Optional pipeline register stage on MC/PHY interface //*************************************************************************** generate if (CMD_PIPE_PLUS1 == "ON") begin : cmd_pipe_plus // register interface always @(posedge clk) begin mc_address <= #TCQ mc_address_ns; mc_bank <= #TCQ mc_bank_ns; mc_cas_n <= #TCQ mc_cas_n_ns; mc_cs_n <= #TCQ mc_cs_n_ns; mc_odt <= #TCQ mc_odt_ns; mc_cke <= #TCQ mc_cke_ns; mc_aux_out0 <= #TCQ mc_aux_out0_ns; mc_aux_out1 <= #TCQ mc_aux_out1_ns; mc_cmd <= #TCQ mc_cmd_ns; mc_ras_n <= #TCQ mc_ras_n_ns; mc_we_n <= #TCQ mc_we_n_ns; mc_data_offset <= #TCQ mc_data_offset_ns; mc_data_offset_1 <= #TCQ mc_data_offset_1_ns; mc_data_offset_2 <= #TCQ mc_data_offset_2_ns; mc_cas_slot <= #TCQ mc_cas_slot_ns; mc_wrdata_en <= #TCQ mc_wrdata_en_ns; mc_rank_cnt <= #TCQ mc_rank_cnt_ns; wr_data_addr <= #TCQ wr_data_addr_ns; wr_data_en <= #TCQ wr_data_en_ns; wr_data_offset <= #TCQ wr_data_offset_ns; end // always @ (posedge clk) end // block: cmd_pipe_plus else begin : cmd_pipe_plus0 // don't register interface always @( mc_address_ns or mc_aux_out0_ns or mc_aux_out1_ns or mc_bank_ns or mc_cas_n_ns or mc_cmd_ns or mc_cs_n_ns or mc_odt_ns or mc_cke_ns or mc_data_offset_ns or mc_data_offset_1_ns or mc_data_offset_2_ns or mc_rank_cnt_ns or mc_ras_n_ns or mc_we_n_ns or mc_wrdata_en_ns or wr_data_addr_ns or wr_data_en_ns or wr_data_offset_ns or mc_cas_slot_ns) begin mc_address = #TCQ mc_address_ns; mc_bank = #TCQ mc_bank_ns; mc_cas_n = #TCQ mc_cas_n_ns; mc_cs_n = #TCQ mc_cs_n_ns; mc_odt = #TCQ mc_odt_ns; mc_cke = #TCQ mc_cke_ns; mc_aux_out0 = #TCQ mc_aux_out0_ns; mc_aux_out1 = #TCQ mc_aux_out1_ns; mc_cmd = #TCQ mc_cmd_ns; mc_ras_n = #TCQ mc_ras_n_ns; mc_we_n = #TCQ mc_we_n_ns; mc_data_offset = #TCQ mc_data_offset_ns; mc_data_offset_1 = #TCQ mc_data_offset_1_ns; mc_data_offset_2 = #TCQ mc_data_offset_2_ns; mc_cas_slot = #TCQ mc_cas_slot_ns; mc_wrdata_en = #TCQ mc_wrdata_en_ns; mc_rank_cnt = #TCQ mc_rank_cnt_ns; wr_data_addr = #TCQ wr_data_addr_ns; wr_data_en = #TCQ wr_data_en_ns; wr_data_offset = #TCQ wr_data_offset_ns; end // always @ (... end // block: cmd_pipe_plus0 endgenerate //*************************************************************************** // Indicate when there are no pending reads so that input features can be // powered down //*************************************************************************** assign mc_read_idle_ns = col_read_fifo_empty & init_calib_complete; always @(posedge clk) mc_read_idle_r <= #TCQ mc_read_idle_ns; assign mc_read_idle = mc_read_idle_r; //*************************************************************************** // Indicate when there is a refresh in progress and the bus is idle so that // tap adjustments can be made //*************************************************************************** assign mc_ref_zq_wip_ns = maint_ref_zq_wip && col_read_fifo_empty; always @(posedge clk) mc_ref_zq_wip_r <= mc_ref_zq_wip_ns; assign mc_ref_zq_wip = mc_ref_zq_wip_r; //*************************************************************************** // Manage rank-level timing and maintanence //*************************************************************************** mig_7series_v1_9_rank_mach # ( // Parameters .BURST_MODE (BURST_MODE), .CL (CL), .CWL (CWL), .CS_WIDTH (CS_WIDTH), .DQRD2DQWR_DLY (DQRD2DQWR_DLY), .DRAM_TYPE (DRAM_TYPE), .MAINT_PRESCALER_DIV (MAINT_PRESCALER_DIV), .nBANK_MACHS (nBANK_MACHS), .nCKESR (nCKESR), .nCK_PER_CLK (nCK_PER_CLK), .nFAW (nFAW), .nREFRESH_BANK (nREFRESH_BANK), .nRRD (nRRD), .nWTR (nWTR), .PERIODIC_RD_TIMER_DIV (PERIODIC_RD_TIMER_DIV), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .REFRESH_TIMER_DIV (REFRESH_TIMER_DIV), .ZQ_TIMER_DIV (ZQ_TIMER_DIV) ) rank_mach0 ( // Outputs .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .maint_ref_zq_wip (maint_ref_zq_wip), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), // Inputs .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .app_periodic_rd_req (app_periodic_rd_req), .app_ref_req (app_ref_req), .app_ref_ack (app_ref_ack), .app_zq_req (app_zq_req), .app_zq_ack (app_zq_ack), .app_sr_req (app_sr_req), .app_sr_active (app_sr_active), .col_rd_wr (col_rd_wr), .clk (clk), .init_calib_complete (init_calib_complete), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .rst (rst), .sending_col (sending_col[nBANK_MACHS-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]) ); //*************************************************************************** // Manage requests, reordering and bank timing //*************************************************************************** mig_7series_v1_9_bank_mach # ( // Parameters .TCQ (TCQ), .EVEN_CWL_2T_MODE (EVEN_CWL_2T_MODE), .ADDR_CMD_MODE (ADDR_CMD_MODE), .BANK_WIDTH (BANK_WIDTH), .BM_CNT_WIDTH (BM_CNT_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .CL (CL_M), .CWL (CWL_M), .CKE_ODT_AUX (CKE_ODT_AUX), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .LOW_IDLE_CNT (LOW_IDLE_CNT), .nBANK_MACHS (nBANK_MACHS), .nCK_PER_CLK (nCK_PER_CLK), .nCS_PER_RANK (nCS_PER_RANK), .nOP_WAIT (nOP_WAIT), .nRAS (nRAS), .nRCD (nRCD), .nRFC (nRFC), .nRP (nRP), .nRTP (nRTP), .nSLOTS (nSLOTS), .nWR (nWR), .nXSDLL (tXSDLL), .ORDERING (ORDERING), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .ROW_WIDTH (ROW_WIDTH), .RTT_NOM (RTT_NOM), .RTT_WR (RTT_WR), .SLOT_0_CONFIG (SLOT_0_CONFIG), .SLOT_1_CONFIG (SLOT_1_CONFIG), .STARVE_LIMIT (STARVE_LIMIT), .tZQCS (tZQCS) ) bank_mach0 ( // Outputs .accept (accept), .accept_ns (accept_ns), .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .bank_mach_next (bank_mach_next[BM_CNT_WIDTH-1:0]), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .mc_bank (mc_bank_ns), .mc_address (mc_address_ns), .mc_ras_n (mc_ras_n_ns), .mc_cas_n (mc_cas_n_ns), .mc_we_n (mc_we_n_ns), .mc_cs_n (mc_cs_n_ns), .mc_odt (mc_odt_ns), .mc_cke (mc_cke_ns), .mc_aux_out0 (mc_aux_out0_ns), .mc_aux_out1 (mc_aux_out1_ns), .mc_cmd (mc_cmd_ns), .mc_data_offset (mc_data_offset_ns), .mc_data_offset_1 (mc_data_offset_1_ns), .mc_data_offset_2 (mc_data_offset_2_ns), .mc_cas_slot (mc_cas_slot_ns), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .sending_col (sending_col[nBANK_MACHS-1:0]), .sent_col (sent_col), .sent_col_r (sent_col_r), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]), // Inputs .bank (bank[BANK_WIDTH-1:0]), .calib_rddata_offset (calib_rd_data_offset), .calib_rddata_offset_1 (calib_rd_data_offset_1), .calib_rddata_offset_2 (calib_rd_data_offset_2), .clk (clk), .cmd (cmd[2:0]), .col (col[COL_WIDTH-1:0]), .data_buf_addr (data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .init_calib_complete (init_calib_complete), .phy_rddata_valid (phy_rddata_valid), .dq_busy_data (dq_busy_data), .hi_priority (hi_priority), .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), .phy_mc_cmd_full (phy_mc_cmd_full), .phy_mc_ctl_full (phy_mc_ctl_full), .phy_mc_data_full (phy_mc_data_full), .rank (rank[RANK_WIDTH-1:0]), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_rmw (rd_rmw), .row (row[ROW_WIDTH-1:0]), .rst (rst), .size (size), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .use_addr (use_addr) ); //*************************************************************************** // Manage DQ bus //*************************************************************************** mig_7series_v1_9_col_mach # ( // Parameters .TCQ (TCQ), .BANK_WIDTH (BANK_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DELAY_WR_DATA_CNTRL (DELAY_WR_DATA_CNTRL), .DQS_WIDTH (DQS_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .MC_ERR_ADDR_WIDTH (MC_ERR_ADDR_WIDTH), .nCK_PER_CLK (nCK_PER_CLK), .nPHY_WRLAT (nPHY_WRLAT), .RANK_WIDTH (RANK_WIDTH), .ROW_WIDTH (ROW_WIDTH) ) col_mach0 ( // Outputs .mc_wrdata_en (mc_wrdata_en_ns), .dq_busy_data (dq_busy_data), .ecc_err_addr (ecc_err_addr[MC_ERR_ADDR_WIDTH-1:0]), .ecc_status_valid (ecc_status_valid), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_data_en (rd_data_en), .rd_data_end (rd_data_end), .rd_data_offset (rd_data_offset), .rd_rmw (rd_rmw), .wr_data_addr (wr_data_addr_ns), .wr_data_en (wr_data_en_ns), .wr_data_offset (wr_data_offset_ns), .wr_ecc_buf (wr_ecc_buf), .col_read_fifo_empty (col_read_fifo_empty), // Inputs .clk (clk), .rst (rst), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .phy_rddata_valid (phy_rddata_valid), .sent_col (EVEN_CWL_2T_MODE == "ON" ? sent_col_r : sent_col) ); //*************************************************************************** // Implement ECC //*************************************************************************** // Total ECC word length = ECC code width + Data width localparam CODE_WIDTH = DATA_WIDTH + ECC_WIDTH; generate if (ECC == "OFF") begin : ecc_off assign rd_data = phy_rd_data; assign mc_wrdata = wr_data; assign mc_wrdata_mask = wr_data_mask; assign ecc_single = 4'b0; assign ecc_multiple = 4'b0; end else begin : ecc_on wire [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; wire [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data; // Merge and encode mig_7series_v1_9_ecc_merge_enc # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_merge_enc0 ( // Outputs .mc_wrdata (mc_wrdata), .mc_wrdata_mask (mc_wrdata_mask), // Inputs .clk (clk), .rst (rst), .h_rows (h_rows), .rd_merge_data (rd_merge_data), .raw_not_ecc (raw_not_ecc), .wr_data (wr_data), .wr_data_mask (wr_data_mask) ); // Decode and fix mig_7series_v1_9_ecc_dec_fix # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_dec_fix0 ( // Outputs .ecc_multiple (ecc_multiple), .ecc_single (ecc_single), .rd_data (rd_data), // Inputs .clk (clk), .rst (rst), .correct_en (correct_en), .phy_rddata (phy_rd_data), .ecc_status_valid (ecc_status_valid), .h_rows (h_rows) ); // ECC Buffer mig_7series_v1_9_ecc_buf # ( // Parameters .TCQ (TCQ), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DATA_WIDTH (DATA_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_buf0 ( // Outputs .rd_merge_data (rd_merge_data), // Inputs .clk (clk), .rst (rst), .rd_data (rd_data), .rd_data_addr (rd_data_addr), .rd_data_offset (rd_data_offset), .wr_data_addr (wr_data_addr), .wr_data_offset (wr_data_offset), .wr_ecc_buf (wr_ecc_buf) ); // Generate ECC table mig_7series_v1_9_ecc_gen # ( // Parameters .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .ECC_WIDTH (ECC_WIDTH) ) ecc_gen0 ( // Outputs .h_rows (h_rows) ); `ifdef DISPLAY_H_MATRIX integer i; always @(negedge rst) begin $display ("**********************************************"); $display ("H Matrix:"); for (i=0; i<ECC_WIDTH; i=i+1) $display ("%b", h_rows[i*CODE_WIDTH+:CODE_WIDTH]); $display ("**********************************************"); end `endif end endgenerate endmodule // mc
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : mc.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** //***************************************************************************** // Top level memory sequencer structural block. This block // instantiates the rank, bank, and column machines. //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_mc # ( parameter TCQ = 100, // clk->out delay(sim only) parameter ADDR_CMD_MODE = "1T", // registered or // 1Tfered mem? parameter BANK_WIDTH = 3, // bank address width parameter BM_CNT_WIDTH = 2, // # BM counter width // i.e., log2(nBANK_MACHS) parameter BURST_MODE = "8", // Burst length parameter CL = 5, // Read CAS latency // (in clk cyc) parameter CMD_PIPE_PLUS1 = "ON", // add register stage // between MC and PHY parameter COL_WIDTH = 12, // column address width parameter CS_WIDTH = 4, // # of unique CS outputs parameter CWL = 5, // Write CAS latency // (in clk cyc) parameter DATA_BUF_ADDR_WIDTH = 8, // User request tag (e.g. // user src/dest buf addr) parameter DATA_BUF_OFFSET_WIDTH = 1, // User buffer offset width parameter DATA_WIDTH = 64, // Data bus width parameter DQ_WIDTH = 64, // # of DQ (data) parameter DQS_WIDTH = 8, // # of DQS (strobe) parameter DRAM_TYPE = "DDR3", // Memory I/F type: // "DDR3", "DDR2" parameter ECC = "OFF", // ECC ON/OFF? parameter ECC_WIDTH = 8, // # of ECC bits parameter MAINT_PRESCALER_PERIOD= 200000, // maintenance period (ps) parameter MC_ERR_ADDR_WIDTH = 31, // # of error address bits parameter nBANK_MACHS = 4, // # of bank machines (BM) parameter nCK_PER_CLK = 4, // DRAM clock : MC clock // frequency ratio parameter nCS_PER_RANK = 1, // # of unique CS outputs // per rank parameter nREFRESH_BANK = 1, // # of REF cmds to pull-in parameter nSLOTS = 1, // # DIMM slots in system parameter ORDERING = "NORM", // request ordering mode parameter PAYLOAD_WIDTH = 64, // Width of data payload // from PHY parameter RANK_WIDTH = 2, // # of bits to count ranks parameter RANKS = 4, // # of ranks of DRAM parameter REG_CTRL = "ON", // "ON" for registered DIMM parameter ROW_WIDTH = 16, // row address width parameter RTT_NOM = "40", // Nominal ODT value parameter RTT_WR = "120", // Write ODT value parameter SLOT_0_CONFIG = 8'b0000_0101, // ranks allowed in slot 0 parameter SLOT_1_CONFIG = 8'b0000_1010, // ranks allowed in slot 1 parameter STARVE_LIMIT = 2, // max # of times a user // request is allowed to // lose arbitration when // reordering is enabled parameter tCK = 2500, // memory clk period(ps) parameter tCKE = 10000, // CKE minimum pulse (ps) parameter tFAW = 40000, // four activate window(ps) parameter tRAS = 37500, // ACT->PRE cmd period (ps) parameter tRCD = 12500, // ACT->R/W delay (ps) parameter tREFI = 7800000, // average periodic // refresh interval(ps) parameter CKE_ODT_AUX = "FALSE", //Parameter to turn on/off the aux_out signal parameter tRFC = 110000, // REF->ACT/REF delay (ps) parameter tRP = 12500, // PRE cmd period (ps) parameter tRRD = 10000, // ACT->ACT period (ps) parameter tRTP = 7500, // Read->PRE cmd delay (ps) parameter tWTR = 7500, // Internal write->read // delay (ps) // requiring DLL lock (CKs) parameter tZQCS = 64, // ZQCS cmd period (CKs) parameter tZQI = 128_000_000, // ZQCS interval (ps) parameter tPRDI = 1_000_000, // pS parameter USER_REFRESH = "OFF" // Whether user manages REF ) ( // System inputs input clk, input rst, // Physical memory slot presence input [7:0] slot_0_present, input [7:0] slot_1_present, // Native Interface input [2:0] cmd, input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr, input hi_priority, input size, input [BANK_WIDTH-1:0] bank, input [COL_WIDTH-1:0] col, input [RANK_WIDTH-1:0] rank, input [ROW_WIDTH-1:0] row, input use_addr, input [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data, input [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask, output accept, output accept_ns, output [BM_CNT_WIDTH-1:0] bank_mach_next, output wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] rd_data, output [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr, output rd_data_en, output rd_data_end, output [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr /* synthesis syn_maxfan = 30 */, output reg wr_data_en, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset /* synthesis syn_maxfan = 30 */, output mc_read_idle, output mc_ref_zq_wip, // ECC interface input correct_en, input [2*nCK_PER_CLK-1:0] raw_not_ecc, output [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr, output [2*nCK_PER_CLK-1:0] ecc_single, output [2*nCK_PER_CLK-1:0] ecc_multiple, // User maintenance requests input app_periodic_rd_req, input app_ref_req, input app_zq_req, input app_sr_req, output app_sr_active, output app_ref_ack, output app_zq_ack, // MC <==> PHY Interface output reg [nCK_PER_CLK-1:0] mc_ras_n, output reg [nCK_PER_CLK-1:0] mc_cas_n, output reg [nCK_PER_CLK-1:0] mc_we_n, output reg [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address, output reg [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank, output reg [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n, output reg [1:0] mc_odt, output reg [nCK_PER_CLK-1:0] mc_cke, output wire mc_reset_n, output wire [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata, output wire [2*nCK_PER_CLK*DQ_WIDTH/8-1:0]mc_wrdata_mask, output reg mc_wrdata_en, output wire mc_cmd_wren, output wire mc_ctl_wren, output reg [2:0] mc_cmd, output reg [5:0] mc_data_offset, output reg [5:0] mc_data_offset_1, output reg [5:0] mc_data_offset_2, output reg [1:0] mc_cas_slot, output reg [3:0] mc_aux_out0, output reg [3:0] mc_aux_out1, output reg [1:0] mc_rank_cnt, input phy_mc_ctl_full, input phy_mc_cmd_full, input phy_mc_data_full, input [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_rd_data, input phy_rddata_valid, input init_calib_complete, input [6*RANKS-1:0] calib_rd_data_offset, input [6*RANKS-1:0] calib_rd_data_offset_1, input [6*RANKS-1:0] calib_rd_data_offset_2 ); assign mc_reset_n = 1'b1; // never reset memory assign mc_cmd_wren = 1'b1; // always write CMD FIFO(issue DSEL when idle) assign mc_ctl_wren = 1'b1; // always write CTL FIFO(issue nondata when idle) // Ensure there is always at least one rank present during operation `ifdef MC_SVA ranks_present: assert property (@(posedge clk) (rst || (|(slot_0_present | slot_1_present)))); `endif // Reserved. Do not change. localparam nPHY_WRLAT = 2; // always delay write data control unless ECC mode is enabled localparam DELAY_WR_DATA_CNTRL = ECC == "ON" ? 0 : 1; // Ensure that write control is delayed for appropriate CWL /*`ifdef MC_SVA delay_wr_data_zero_CWL_le_6: assert property (@(posedge clk) ((CWL > 6) || (DELAY_WR_DATA_CNTRL == 0))); `endif*/ // Never retrieve WR_DATA_ADDR early localparam EARLY_WR_DATA_ADDR = "OFF"; //*************************************************************************** // Convert timing parameters from time to clock cycles //*************************************************************************** localparam nCKE = cdiv(tCKE, tCK); localparam nRP = cdiv(tRP, tCK); localparam nRCD = cdiv(tRCD, tCK); localparam nRAS = cdiv(tRAS, tCK); localparam nFAW = cdiv(tFAW, tCK); localparam nRFC = cdiv(tRFC, tCK); // Convert tWR. As per specification, write recover for autoprecharge // cycles doesn't support values of 9 and 11. Round up 9 to 10 and 11 to 12 localparam nWR_CK = cdiv(15000, tCK) ; localparam nWR = (nWR_CK == 9) ? 10 : (nWR_CK == 11) ? 12 : nWR_CK; // tRRD, tWTR at tRTP have a 4 cycle floor in DDR3 and 2 cycle floor in DDR2 localparam nRRD_CK = cdiv(tRRD, tCK); localparam nRRD = (DRAM_TYPE == "DDR3") ? (nRRD_CK < 4) ? 4 : nRRD_CK : (nRRD_CK < 2) ? 2 : nRRD_CK; localparam nWTR_CK = cdiv(tWTR, tCK); localparam nWTR = (DRAM_TYPE == "DDR3") ? (nWTR_CK < 4) ? 4 : nWTR_CK : (nWTR_CK < 2) ? 2 : nWTR_CK; localparam nRTP_CK = cdiv(tRTP, tCK); localparam nRTP = (DRAM_TYPE == "DDR3") ? (nRTP_CK < 4) ? 4 : nRTP_CK : (nRTP_CK < 2) ? 2 : nRTP_CK; // Add a cycle to CL/CWL for the register in RDIMM devices localparam CWL_M = (REG_CTRL == "ON") ? CWL + 1 : CWL; localparam CL_M = (REG_CTRL == "ON") ? CL + 1 : CL; // Tuneable delay between read and write data on the DQ bus localparam DQRD2DQWR_DLY = 4; // CKE minimum pulse width for self-refresh (SRE->SRX minimum time) localparam nCKESR = nCKE + 1; // Delay from SRE to command requiring locked DLL. Currently fixed at 512 for // all devices per JEDEC spec. localparam tXSDLL = 512; //*************************************************************************** // Set up maintenance counter dividers //*************************************************************************** // CK clock divisor to generate maintenance prescaler period (round down) localparam MAINT_PRESCALER_DIV = MAINT_PRESCALER_PERIOD / (tCK*nCK_PER_CLK); // Maintenance prescaler divisor for refresh timer. Essentially, this is // just (tREFI / MAINT_PRESCALER_PERIOD), but we must account for the worst // case delay from the time we get a tick from the refresh counter to the // time that we can actually issue the REF command. Thus, subtract tRCD, CL, // data burst time and tRP for each implemented bank machine to ensure that // all transactions can complete before tREFI expires localparam REFRESH_TIMER_DIV = USER_REFRESH == "ON" ? 0 : (tREFI-((tRCD+((CL+4)*tCK)+tRP)*nBANK_MACHS)) / MAINT_PRESCALER_PERIOD; // Periodic read (RESERVED - not currently required or supported in 7 series) // tPRDI should only be set to 0 // localparam tPRDI = 0; // Do NOT change. localparam PERIODIC_RD_TIMER_DIV = tPRDI / MAINT_PRESCALER_PERIOD; // Convert maintenance prescaler from ps to ns localparam MAINT_PRESCALER_PERIOD_NS = MAINT_PRESCALER_PERIOD / 1000; // Maintenance prescaler divisor for ZQ calibration (ZQCS) timer localparam ZQ_TIMER_DIV = tZQI / MAINT_PRESCALER_PERIOD_NS; // Bus width required to broadcast a single bit rank signal among all the // bank machines - 1 bit per rank, per bank localparam RANK_BM_BV_WIDTH = nBANK_MACHS * RANKS; //*************************************************************************** // Define 2T, CWL-even mode to enable multi-fabric-cycle 2T commands //*************************************************************************** localparam EVEN_CWL_2T_MODE = ((ADDR_CMD_MODE == "2T") && (!(CWL % 2))) ? "ON" : "OFF"; //*************************************************************************** // Reserved feature control. //*************************************************************************** // Open page wait mode is reserved. // nOP_WAIT is the number of states a bank machine will park itself // on an otherwise inactive open page before closing the page. If // nOP_WAIT == 0, open page wait mode is disabled. If nOP_WAIT == -1, // the bank machine will remain parked until the pool of idle bank machines // are less than LOW_IDLE_CNT. At which point parked bank machines // are selected to exit until the number of idle bank machines exceeds the // LOW_IDLE_CNT. localparam nOP_WAIT = 0; // Open page mode localparam LOW_IDLE_CNT = 0; // Low idle bank machine threshold //*************************************************************************** // Internal wires //*************************************************************************** wire [RANK_BM_BV_WIDTH-1:0] act_this_rank_r; wire [ROW_WIDTH-1:0] col_a; wire [BANK_WIDTH-1:0] col_ba; wire [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr; wire col_periodic_rd; wire [RANK_WIDTH-1:0] col_ra; wire col_rmw; wire col_rd_wr; wire [ROW_WIDTH-1:0] col_row; wire col_size; wire [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr; wire dq_busy_data; wire ecc_status_valid; wire [RANKS-1:0] inhbt_act_faw_r; wire [RANKS-1:0] inhbt_rd; wire [RANKS-1:0] inhbt_wr; wire insert_maint_r1; wire [RANK_WIDTH-1:0] maint_rank_r; wire maint_req_r; wire maint_wip_r; wire maint_zq_r; wire maint_sre_r; wire maint_srx_r; wire periodic_rd_ack_r; wire periodic_rd_r; wire [RANK_WIDTH-1:0] periodic_rd_rank_r; wire [(RANKS*nBANK_MACHS)-1:0] rank_busy_r; wire rd_rmw; wire [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r; wire [nBANK_MACHS-1:0] sending_col; wire [nBANK_MACHS-1:0] sending_row; wire sent_col; wire sent_col_r; wire wr_ecc_buf; wire [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r; // MC/PHY optional pipeline stage support wire [nCK_PER_CLK-1:0] mc_ras_n_ns; wire [nCK_PER_CLK-1:0] mc_cas_n_ns; wire [nCK_PER_CLK-1:0] mc_we_n_ns; wire [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address_ns; wire [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank_ns; wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n_ns; wire [1:0] mc_odt_ns; wire [nCK_PER_CLK-1:0] mc_cke_ns; wire [3:0] mc_aux_out0_ns; wire [3:0] mc_aux_out1_ns; wire [1:0] mc_rank_cnt_ns = col_ra; wire [2:0] mc_cmd_ns; wire [5:0] mc_data_offset_ns; wire [5:0] mc_data_offset_1_ns; wire [5:0] mc_data_offset_2_ns; wire [1:0] mc_cas_slot_ns; wire mc_wrdata_en_ns; wire [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr_ns; wire wr_data_en_ns; wire [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset_ns; integer i; // MC Read idle support wire col_read_fifo_empty; wire mc_read_idle_ns; reg mc_read_idle_r; // MC Maintenance in progress with bus idle indication wire maint_ref_zq_wip; wire mc_ref_zq_wip_ns; reg mc_ref_zq_wip_r; //*************************************************************************** // Function cdiv // Description: // This function performs ceiling division (divide and round-up) // Inputs: // num: integer to be divided // div: divisor // Outputs: // cdiv: result of ceiling division (num/div, rounded up) //*************************************************************************** function integer cdiv (input integer num, input integer div); begin // perform division, then add 1 if and only if remainder is non-zero cdiv = (num/div) + (((num%div)>0) ? 1 : 0); end endfunction // cdiv //*************************************************************************** // Optional pipeline register stage on MC/PHY interface //*************************************************************************** generate if (CMD_PIPE_PLUS1 == "ON") begin : cmd_pipe_plus // register interface always @(posedge clk) begin mc_address <= #TCQ mc_address_ns; mc_bank <= #TCQ mc_bank_ns; mc_cas_n <= #TCQ mc_cas_n_ns; mc_cs_n <= #TCQ mc_cs_n_ns; mc_odt <= #TCQ mc_odt_ns; mc_cke <= #TCQ mc_cke_ns; mc_aux_out0 <= #TCQ mc_aux_out0_ns; mc_aux_out1 <= #TCQ mc_aux_out1_ns; mc_cmd <= #TCQ mc_cmd_ns; mc_ras_n <= #TCQ mc_ras_n_ns; mc_we_n <= #TCQ mc_we_n_ns; mc_data_offset <= #TCQ mc_data_offset_ns; mc_data_offset_1 <= #TCQ mc_data_offset_1_ns; mc_data_offset_2 <= #TCQ mc_data_offset_2_ns; mc_cas_slot <= #TCQ mc_cas_slot_ns; mc_wrdata_en <= #TCQ mc_wrdata_en_ns; mc_rank_cnt <= #TCQ mc_rank_cnt_ns; wr_data_addr <= #TCQ wr_data_addr_ns; wr_data_en <= #TCQ wr_data_en_ns; wr_data_offset <= #TCQ wr_data_offset_ns; end // always @ (posedge clk) end // block: cmd_pipe_plus else begin : cmd_pipe_plus0 // don't register interface always @( mc_address_ns or mc_aux_out0_ns or mc_aux_out1_ns or mc_bank_ns or mc_cas_n_ns or mc_cmd_ns or mc_cs_n_ns or mc_odt_ns or mc_cke_ns or mc_data_offset_ns or mc_data_offset_1_ns or mc_data_offset_2_ns or mc_rank_cnt_ns or mc_ras_n_ns or mc_we_n_ns or mc_wrdata_en_ns or wr_data_addr_ns or wr_data_en_ns or wr_data_offset_ns or mc_cas_slot_ns) begin mc_address = #TCQ mc_address_ns; mc_bank = #TCQ mc_bank_ns; mc_cas_n = #TCQ mc_cas_n_ns; mc_cs_n = #TCQ mc_cs_n_ns; mc_odt = #TCQ mc_odt_ns; mc_cke = #TCQ mc_cke_ns; mc_aux_out0 = #TCQ mc_aux_out0_ns; mc_aux_out1 = #TCQ mc_aux_out1_ns; mc_cmd = #TCQ mc_cmd_ns; mc_ras_n = #TCQ mc_ras_n_ns; mc_we_n = #TCQ mc_we_n_ns; mc_data_offset = #TCQ mc_data_offset_ns; mc_data_offset_1 = #TCQ mc_data_offset_1_ns; mc_data_offset_2 = #TCQ mc_data_offset_2_ns; mc_cas_slot = #TCQ mc_cas_slot_ns; mc_wrdata_en = #TCQ mc_wrdata_en_ns; mc_rank_cnt = #TCQ mc_rank_cnt_ns; wr_data_addr = #TCQ wr_data_addr_ns; wr_data_en = #TCQ wr_data_en_ns; wr_data_offset = #TCQ wr_data_offset_ns; end // always @ (... end // block: cmd_pipe_plus0 endgenerate //*************************************************************************** // Indicate when there are no pending reads so that input features can be // powered down //*************************************************************************** assign mc_read_idle_ns = col_read_fifo_empty & init_calib_complete; always @(posedge clk) mc_read_idle_r <= #TCQ mc_read_idle_ns; assign mc_read_idle = mc_read_idle_r; //*************************************************************************** // Indicate when there is a refresh in progress and the bus is idle so that // tap adjustments can be made //*************************************************************************** assign mc_ref_zq_wip_ns = maint_ref_zq_wip && col_read_fifo_empty; always @(posedge clk) mc_ref_zq_wip_r <= mc_ref_zq_wip_ns; assign mc_ref_zq_wip = mc_ref_zq_wip_r; //*************************************************************************** // Manage rank-level timing and maintanence //*************************************************************************** mig_7series_v1_9_rank_mach # ( // Parameters .BURST_MODE (BURST_MODE), .CL (CL), .CWL (CWL), .CS_WIDTH (CS_WIDTH), .DQRD2DQWR_DLY (DQRD2DQWR_DLY), .DRAM_TYPE (DRAM_TYPE), .MAINT_PRESCALER_DIV (MAINT_PRESCALER_DIV), .nBANK_MACHS (nBANK_MACHS), .nCKESR (nCKESR), .nCK_PER_CLK (nCK_PER_CLK), .nFAW (nFAW), .nREFRESH_BANK (nREFRESH_BANK), .nRRD (nRRD), .nWTR (nWTR), .PERIODIC_RD_TIMER_DIV (PERIODIC_RD_TIMER_DIV), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .REFRESH_TIMER_DIV (REFRESH_TIMER_DIV), .ZQ_TIMER_DIV (ZQ_TIMER_DIV) ) rank_mach0 ( // Outputs .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .maint_ref_zq_wip (maint_ref_zq_wip), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), // Inputs .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .app_periodic_rd_req (app_periodic_rd_req), .app_ref_req (app_ref_req), .app_ref_ack (app_ref_ack), .app_zq_req (app_zq_req), .app_zq_ack (app_zq_ack), .app_sr_req (app_sr_req), .app_sr_active (app_sr_active), .col_rd_wr (col_rd_wr), .clk (clk), .init_calib_complete (init_calib_complete), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .rst (rst), .sending_col (sending_col[nBANK_MACHS-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]) ); //*************************************************************************** // Manage requests, reordering and bank timing //*************************************************************************** mig_7series_v1_9_bank_mach # ( // Parameters .TCQ (TCQ), .EVEN_CWL_2T_MODE (EVEN_CWL_2T_MODE), .ADDR_CMD_MODE (ADDR_CMD_MODE), .BANK_WIDTH (BANK_WIDTH), .BM_CNT_WIDTH (BM_CNT_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .CL (CL_M), .CWL (CWL_M), .CKE_ODT_AUX (CKE_ODT_AUX), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .LOW_IDLE_CNT (LOW_IDLE_CNT), .nBANK_MACHS (nBANK_MACHS), .nCK_PER_CLK (nCK_PER_CLK), .nCS_PER_RANK (nCS_PER_RANK), .nOP_WAIT (nOP_WAIT), .nRAS (nRAS), .nRCD (nRCD), .nRFC (nRFC), .nRP (nRP), .nRTP (nRTP), .nSLOTS (nSLOTS), .nWR (nWR), .nXSDLL (tXSDLL), .ORDERING (ORDERING), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .ROW_WIDTH (ROW_WIDTH), .RTT_NOM (RTT_NOM), .RTT_WR (RTT_WR), .SLOT_0_CONFIG (SLOT_0_CONFIG), .SLOT_1_CONFIG (SLOT_1_CONFIG), .STARVE_LIMIT (STARVE_LIMIT), .tZQCS (tZQCS) ) bank_mach0 ( // Outputs .accept (accept), .accept_ns (accept_ns), .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .bank_mach_next (bank_mach_next[BM_CNT_WIDTH-1:0]), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .mc_bank (mc_bank_ns), .mc_address (mc_address_ns), .mc_ras_n (mc_ras_n_ns), .mc_cas_n (mc_cas_n_ns), .mc_we_n (mc_we_n_ns), .mc_cs_n (mc_cs_n_ns), .mc_odt (mc_odt_ns), .mc_cke (mc_cke_ns), .mc_aux_out0 (mc_aux_out0_ns), .mc_aux_out1 (mc_aux_out1_ns), .mc_cmd (mc_cmd_ns), .mc_data_offset (mc_data_offset_ns), .mc_data_offset_1 (mc_data_offset_1_ns), .mc_data_offset_2 (mc_data_offset_2_ns), .mc_cas_slot (mc_cas_slot_ns), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .sending_col (sending_col[nBANK_MACHS-1:0]), .sent_col (sent_col), .sent_col_r (sent_col_r), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]), // Inputs .bank (bank[BANK_WIDTH-1:0]), .calib_rddata_offset (calib_rd_data_offset), .calib_rddata_offset_1 (calib_rd_data_offset_1), .calib_rddata_offset_2 (calib_rd_data_offset_2), .clk (clk), .cmd (cmd[2:0]), .col (col[COL_WIDTH-1:0]), .data_buf_addr (data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .init_calib_complete (init_calib_complete), .phy_rddata_valid (phy_rddata_valid), .dq_busy_data (dq_busy_data), .hi_priority (hi_priority), .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), .phy_mc_cmd_full (phy_mc_cmd_full), .phy_mc_ctl_full (phy_mc_ctl_full), .phy_mc_data_full (phy_mc_data_full), .rank (rank[RANK_WIDTH-1:0]), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_rmw (rd_rmw), .row (row[ROW_WIDTH-1:0]), .rst (rst), .size (size), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .use_addr (use_addr) ); //*************************************************************************** // Manage DQ bus //*************************************************************************** mig_7series_v1_9_col_mach # ( // Parameters .TCQ (TCQ), .BANK_WIDTH (BANK_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DELAY_WR_DATA_CNTRL (DELAY_WR_DATA_CNTRL), .DQS_WIDTH (DQS_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .MC_ERR_ADDR_WIDTH (MC_ERR_ADDR_WIDTH), .nCK_PER_CLK (nCK_PER_CLK), .nPHY_WRLAT (nPHY_WRLAT), .RANK_WIDTH (RANK_WIDTH), .ROW_WIDTH (ROW_WIDTH) ) col_mach0 ( // Outputs .mc_wrdata_en (mc_wrdata_en_ns), .dq_busy_data (dq_busy_data), .ecc_err_addr (ecc_err_addr[MC_ERR_ADDR_WIDTH-1:0]), .ecc_status_valid (ecc_status_valid), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_data_en (rd_data_en), .rd_data_end (rd_data_end), .rd_data_offset (rd_data_offset), .rd_rmw (rd_rmw), .wr_data_addr (wr_data_addr_ns), .wr_data_en (wr_data_en_ns), .wr_data_offset (wr_data_offset_ns), .wr_ecc_buf (wr_ecc_buf), .col_read_fifo_empty (col_read_fifo_empty), // Inputs .clk (clk), .rst (rst), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .phy_rddata_valid (phy_rddata_valid), .sent_col (EVEN_CWL_2T_MODE == "ON" ? sent_col_r : sent_col) ); //*************************************************************************** // Implement ECC //*************************************************************************** // Total ECC word length = ECC code width + Data width localparam CODE_WIDTH = DATA_WIDTH + ECC_WIDTH; generate if (ECC == "OFF") begin : ecc_off assign rd_data = phy_rd_data; assign mc_wrdata = wr_data; assign mc_wrdata_mask = wr_data_mask; assign ecc_single = 4'b0; assign ecc_multiple = 4'b0; end else begin : ecc_on wire [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; wire [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data; // Merge and encode mig_7series_v1_9_ecc_merge_enc # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_merge_enc0 ( // Outputs .mc_wrdata (mc_wrdata), .mc_wrdata_mask (mc_wrdata_mask), // Inputs .clk (clk), .rst (rst), .h_rows (h_rows), .rd_merge_data (rd_merge_data), .raw_not_ecc (raw_not_ecc), .wr_data (wr_data), .wr_data_mask (wr_data_mask) ); // Decode and fix mig_7series_v1_9_ecc_dec_fix # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_dec_fix0 ( // Outputs .ecc_multiple (ecc_multiple), .ecc_single (ecc_single), .rd_data (rd_data), // Inputs .clk (clk), .rst (rst), .correct_en (correct_en), .phy_rddata (phy_rd_data), .ecc_status_valid (ecc_status_valid), .h_rows (h_rows) ); // ECC Buffer mig_7series_v1_9_ecc_buf # ( // Parameters .TCQ (TCQ), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DATA_WIDTH (DATA_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_buf0 ( // Outputs .rd_merge_data (rd_merge_data), // Inputs .clk (clk), .rst (rst), .rd_data (rd_data), .rd_data_addr (rd_data_addr), .rd_data_offset (rd_data_offset), .wr_data_addr (wr_data_addr), .wr_data_offset (wr_data_offset), .wr_ecc_buf (wr_ecc_buf) ); // Generate ECC table mig_7series_v1_9_ecc_gen # ( // Parameters .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .ECC_WIDTH (ECC_WIDTH) ) ecc_gen0 ( // Outputs .h_rows (h_rows) ); `ifdef DISPLAY_H_MATRIX integer i; always @(negedge rst) begin $display ("**********************************************"); $display ("H Matrix:"); for (i=0; i<ECC_WIDTH; i=i+1) $display ("%b", h_rows[i*CODE_WIDTH+:CODE_WIDTH]); $display ("**********************************************"); end `endif end endgenerate endmodule // mc
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : mc.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** //***************************************************************************** // Top level memory sequencer structural block. This block // instantiates the rank, bank, and column machines. //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_mc # ( parameter TCQ = 100, // clk->out delay(sim only) parameter ADDR_CMD_MODE = "1T", // registered or // 1Tfered mem? parameter BANK_WIDTH = 3, // bank address width parameter BM_CNT_WIDTH = 2, // # BM counter width // i.e., log2(nBANK_MACHS) parameter BURST_MODE = "8", // Burst length parameter CL = 5, // Read CAS latency // (in clk cyc) parameter CMD_PIPE_PLUS1 = "ON", // add register stage // between MC and PHY parameter COL_WIDTH = 12, // column address width parameter CS_WIDTH = 4, // # of unique CS outputs parameter CWL = 5, // Write CAS latency // (in clk cyc) parameter DATA_BUF_ADDR_WIDTH = 8, // User request tag (e.g. // user src/dest buf addr) parameter DATA_BUF_OFFSET_WIDTH = 1, // User buffer offset width parameter DATA_WIDTH = 64, // Data bus width parameter DQ_WIDTH = 64, // # of DQ (data) parameter DQS_WIDTH = 8, // # of DQS (strobe) parameter DRAM_TYPE = "DDR3", // Memory I/F type: // "DDR3", "DDR2" parameter ECC = "OFF", // ECC ON/OFF? parameter ECC_WIDTH = 8, // # of ECC bits parameter MAINT_PRESCALER_PERIOD= 200000, // maintenance period (ps) parameter MC_ERR_ADDR_WIDTH = 31, // # of error address bits parameter nBANK_MACHS = 4, // # of bank machines (BM) parameter nCK_PER_CLK = 4, // DRAM clock : MC clock // frequency ratio parameter nCS_PER_RANK = 1, // # of unique CS outputs // per rank parameter nREFRESH_BANK = 1, // # of REF cmds to pull-in parameter nSLOTS = 1, // # DIMM slots in system parameter ORDERING = "NORM", // request ordering mode parameter PAYLOAD_WIDTH = 64, // Width of data payload // from PHY parameter RANK_WIDTH = 2, // # of bits to count ranks parameter RANKS = 4, // # of ranks of DRAM parameter REG_CTRL = "ON", // "ON" for registered DIMM parameter ROW_WIDTH = 16, // row address width parameter RTT_NOM = "40", // Nominal ODT value parameter RTT_WR = "120", // Write ODT value parameter SLOT_0_CONFIG = 8'b0000_0101, // ranks allowed in slot 0 parameter SLOT_1_CONFIG = 8'b0000_1010, // ranks allowed in slot 1 parameter STARVE_LIMIT = 2, // max # of times a user // request is allowed to // lose arbitration when // reordering is enabled parameter tCK = 2500, // memory clk period(ps) parameter tCKE = 10000, // CKE minimum pulse (ps) parameter tFAW = 40000, // four activate window(ps) parameter tRAS = 37500, // ACT->PRE cmd period (ps) parameter tRCD = 12500, // ACT->R/W delay (ps) parameter tREFI = 7800000, // average periodic // refresh interval(ps) parameter CKE_ODT_AUX = "FALSE", //Parameter to turn on/off the aux_out signal parameter tRFC = 110000, // REF->ACT/REF delay (ps) parameter tRP = 12500, // PRE cmd period (ps) parameter tRRD = 10000, // ACT->ACT period (ps) parameter tRTP = 7500, // Read->PRE cmd delay (ps) parameter tWTR = 7500, // Internal write->read // delay (ps) // requiring DLL lock (CKs) parameter tZQCS = 64, // ZQCS cmd period (CKs) parameter tZQI = 128_000_000, // ZQCS interval (ps) parameter tPRDI = 1_000_000, // pS parameter USER_REFRESH = "OFF" // Whether user manages REF ) ( // System inputs input clk, input rst, // Physical memory slot presence input [7:0] slot_0_present, input [7:0] slot_1_present, // Native Interface input [2:0] cmd, input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr, input hi_priority, input size, input [BANK_WIDTH-1:0] bank, input [COL_WIDTH-1:0] col, input [RANK_WIDTH-1:0] rank, input [ROW_WIDTH-1:0] row, input use_addr, input [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data, input [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask, output accept, output accept_ns, output [BM_CNT_WIDTH-1:0] bank_mach_next, output wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] rd_data, output [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr, output rd_data_en, output rd_data_end, output [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr /* synthesis syn_maxfan = 30 */, output reg wr_data_en, (* keep = "true", max_fanout = 30 *) output reg [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset /* synthesis syn_maxfan = 30 */, output mc_read_idle, output mc_ref_zq_wip, // ECC interface input correct_en, input [2*nCK_PER_CLK-1:0] raw_not_ecc, output [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr, output [2*nCK_PER_CLK-1:0] ecc_single, output [2*nCK_PER_CLK-1:0] ecc_multiple, // User maintenance requests input app_periodic_rd_req, input app_ref_req, input app_zq_req, input app_sr_req, output app_sr_active, output app_ref_ack, output app_zq_ack, // MC <==> PHY Interface output reg [nCK_PER_CLK-1:0] mc_ras_n, output reg [nCK_PER_CLK-1:0] mc_cas_n, output reg [nCK_PER_CLK-1:0] mc_we_n, output reg [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address, output reg [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank, output reg [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n, output reg [1:0] mc_odt, output reg [nCK_PER_CLK-1:0] mc_cke, output wire mc_reset_n, output wire [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata, output wire [2*nCK_PER_CLK*DQ_WIDTH/8-1:0]mc_wrdata_mask, output reg mc_wrdata_en, output wire mc_cmd_wren, output wire mc_ctl_wren, output reg [2:0] mc_cmd, output reg [5:0] mc_data_offset, output reg [5:0] mc_data_offset_1, output reg [5:0] mc_data_offset_2, output reg [1:0] mc_cas_slot, output reg [3:0] mc_aux_out0, output reg [3:0] mc_aux_out1, output reg [1:0] mc_rank_cnt, input phy_mc_ctl_full, input phy_mc_cmd_full, input phy_mc_data_full, input [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_rd_data, input phy_rddata_valid, input init_calib_complete, input [6*RANKS-1:0] calib_rd_data_offset, input [6*RANKS-1:0] calib_rd_data_offset_1, input [6*RANKS-1:0] calib_rd_data_offset_2 ); assign mc_reset_n = 1'b1; // never reset memory assign mc_cmd_wren = 1'b1; // always write CMD FIFO(issue DSEL when idle) assign mc_ctl_wren = 1'b1; // always write CTL FIFO(issue nondata when idle) // Ensure there is always at least one rank present during operation `ifdef MC_SVA ranks_present: assert property (@(posedge clk) (rst || (|(slot_0_present | slot_1_present)))); `endif // Reserved. Do not change. localparam nPHY_WRLAT = 2; // always delay write data control unless ECC mode is enabled localparam DELAY_WR_DATA_CNTRL = ECC == "ON" ? 0 : 1; // Ensure that write control is delayed for appropriate CWL /*`ifdef MC_SVA delay_wr_data_zero_CWL_le_6: assert property (@(posedge clk) ((CWL > 6) || (DELAY_WR_DATA_CNTRL == 0))); `endif*/ // Never retrieve WR_DATA_ADDR early localparam EARLY_WR_DATA_ADDR = "OFF"; //*************************************************************************** // Convert timing parameters from time to clock cycles //*************************************************************************** localparam nCKE = cdiv(tCKE, tCK); localparam nRP = cdiv(tRP, tCK); localparam nRCD = cdiv(tRCD, tCK); localparam nRAS = cdiv(tRAS, tCK); localparam nFAW = cdiv(tFAW, tCK); localparam nRFC = cdiv(tRFC, tCK); // Convert tWR. As per specification, write recover for autoprecharge // cycles doesn't support values of 9 and 11. Round up 9 to 10 and 11 to 12 localparam nWR_CK = cdiv(15000, tCK) ; localparam nWR = (nWR_CK == 9) ? 10 : (nWR_CK == 11) ? 12 : nWR_CK; // tRRD, tWTR at tRTP have a 4 cycle floor in DDR3 and 2 cycle floor in DDR2 localparam nRRD_CK = cdiv(tRRD, tCK); localparam nRRD = (DRAM_TYPE == "DDR3") ? (nRRD_CK < 4) ? 4 : nRRD_CK : (nRRD_CK < 2) ? 2 : nRRD_CK; localparam nWTR_CK = cdiv(tWTR, tCK); localparam nWTR = (DRAM_TYPE == "DDR3") ? (nWTR_CK < 4) ? 4 : nWTR_CK : (nWTR_CK < 2) ? 2 : nWTR_CK; localparam nRTP_CK = cdiv(tRTP, tCK); localparam nRTP = (DRAM_TYPE == "DDR3") ? (nRTP_CK < 4) ? 4 : nRTP_CK : (nRTP_CK < 2) ? 2 : nRTP_CK; // Add a cycle to CL/CWL for the register in RDIMM devices localparam CWL_M = (REG_CTRL == "ON") ? CWL + 1 : CWL; localparam CL_M = (REG_CTRL == "ON") ? CL + 1 : CL; // Tuneable delay between read and write data on the DQ bus localparam DQRD2DQWR_DLY = 4; // CKE minimum pulse width for self-refresh (SRE->SRX minimum time) localparam nCKESR = nCKE + 1; // Delay from SRE to command requiring locked DLL. Currently fixed at 512 for // all devices per JEDEC spec. localparam tXSDLL = 512; //*************************************************************************** // Set up maintenance counter dividers //*************************************************************************** // CK clock divisor to generate maintenance prescaler period (round down) localparam MAINT_PRESCALER_DIV = MAINT_PRESCALER_PERIOD / (tCK*nCK_PER_CLK); // Maintenance prescaler divisor for refresh timer. Essentially, this is // just (tREFI / MAINT_PRESCALER_PERIOD), but we must account for the worst // case delay from the time we get a tick from the refresh counter to the // time that we can actually issue the REF command. Thus, subtract tRCD, CL, // data burst time and tRP for each implemented bank machine to ensure that // all transactions can complete before tREFI expires localparam REFRESH_TIMER_DIV = USER_REFRESH == "ON" ? 0 : (tREFI-((tRCD+((CL+4)*tCK)+tRP)*nBANK_MACHS)) / MAINT_PRESCALER_PERIOD; // Periodic read (RESERVED - not currently required or supported in 7 series) // tPRDI should only be set to 0 // localparam tPRDI = 0; // Do NOT change. localparam PERIODIC_RD_TIMER_DIV = tPRDI / MAINT_PRESCALER_PERIOD; // Convert maintenance prescaler from ps to ns localparam MAINT_PRESCALER_PERIOD_NS = MAINT_PRESCALER_PERIOD / 1000; // Maintenance prescaler divisor for ZQ calibration (ZQCS) timer localparam ZQ_TIMER_DIV = tZQI / MAINT_PRESCALER_PERIOD_NS; // Bus width required to broadcast a single bit rank signal among all the // bank machines - 1 bit per rank, per bank localparam RANK_BM_BV_WIDTH = nBANK_MACHS * RANKS; //*************************************************************************** // Define 2T, CWL-even mode to enable multi-fabric-cycle 2T commands //*************************************************************************** localparam EVEN_CWL_2T_MODE = ((ADDR_CMD_MODE == "2T") && (!(CWL % 2))) ? "ON" : "OFF"; //*************************************************************************** // Reserved feature control. //*************************************************************************** // Open page wait mode is reserved. // nOP_WAIT is the number of states a bank machine will park itself // on an otherwise inactive open page before closing the page. If // nOP_WAIT == 0, open page wait mode is disabled. If nOP_WAIT == -1, // the bank machine will remain parked until the pool of idle bank machines // are less than LOW_IDLE_CNT. At which point parked bank machines // are selected to exit until the number of idle bank machines exceeds the // LOW_IDLE_CNT. localparam nOP_WAIT = 0; // Open page mode localparam LOW_IDLE_CNT = 0; // Low idle bank machine threshold //*************************************************************************** // Internal wires //*************************************************************************** wire [RANK_BM_BV_WIDTH-1:0] act_this_rank_r; wire [ROW_WIDTH-1:0] col_a; wire [BANK_WIDTH-1:0] col_ba; wire [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr; wire col_periodic_rd; wire [RANK_WIDTH-1:0] col_ra; wire col_rmw; wire col_rd_wr; wire [ROW_WIDTH-1:0] col_row; wire col_size; wire [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr; wire dq_busy_data; wire ecc_status_valid; wire [RANKS-1:0] inhbt_act_faw_r; wire [RANKS-1:0] inhbt_rd; wire [RANKS-1:0] inhbt_wr; wire insert_maint_r1; wire [RANK_WIDTH-1:0] maint_rank_r; wire maint_req_r; wire maint_wip_r; wire maint_zq_r; wire maint_sre_r; wire maint_srx_r; wire periodic_rd_ack_r; wire periodic_rd_r; wire [RANK_WIDTH-1:0] periodic_rd_rank_r; wire [(RANKS*nBANK_MACHS)-1:0] rank_busy_r; wire rd_rmw; wire [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r; wire [nBANK_MACHS-1:0] sending_col; wire [nBANK_MACHS-1:0] sending_row; wire sent_col; wire sent_col_r; wire wr_ecc_buf; wire [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r; // MC/PHY optional pipeline stage support wire [nCK_PER_CLK-1:0] mc_ras_n_ns; wire [nCK_PER_CLK-1:0] mc_cas_n_ns; wire [nCK_PER_CLK-1:0] mc_we_n_ns; wire [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address_ns; wire [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank_ns; wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n_ns; wire [1:0] mc_odt_ns; wire [nCK_PER_CLK-1:0] mc_cke_ns; wire [3:0] mc_aux_out0_ns; wire [3:0] mc_aux_out1_ns; wire [1:0] mc_rank_cnt_ns = col_ra; wire [2:0] mc_cmd_ns; wire [5:0] mc_data_offset_ns; wire [5:0] mc_data_offset_1_ns; wire [5:0] mc_data_offset_2_ns; wire [1:0] mc_cas_slot_ns; wire mc_wrdata_en_ns; wire [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr_ns; wire wr_data_en_ns; wire [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset_ns; integer i; // MC Read idle support wire col_read_fifo_empty; wire mc_read_idle_ns; reg mc_read_idle_r; // MC Maintenance in progress with bus idle indication wire maint_ref_zq_wip; wire mc_ref_zq_wip_ns; reg mc_ref_zq_wip_r; //*************************************************************************** // Function cdiv // Description: // This function performs ceiling division (divide and round-up) // Inputs: // num: integer to be divided // div: divisor // Outputs: // cdiv: result of ceiling division (num/div, rounded up) //*************************************************************************** function integer cdiv (input integer num, input integer div); begin // perform division, then add 1 if and only if remainder is non-zero cdiv = (num/div) + (((num%div)>0) ? 1 : 0); end endfunction // cdiv //*************************************************************************** // Optional pipeline register stage on MC/PHY interface //*************************************************************************** generate if (CMD_PIPE_PLUS1 == "ON") begin : cmd_pipe_plus // register interface always @(posedge clk) begin mc_address <= #TCQ mc_address_ns; mc_bank <= #TCQ mc_bank_ns; mc_cas_n <= #TCQ mc_cas_n_ns; mc_cs_n <= #TCQ mc_cs_n_ns; mc_odt <= #TCQ mc_odt_ns; mc_cke <= #TCQ mc_cke_ns; mc_aux_out0 <= #TCQ mc_aux_out0_ns; mc_aux_out1 <= #TCQ mc_aux_out1_ns; mc_cmd <= #TCQ mc_cmd_ns; mc_ras_n <= #TCQ mc_ras_n_ns; mc_we_n <= #TCQ mc_we_n_ns; mc_data_offset <= #TCQ mc_data_offset_ns; mc_data_offset_1 <= #TCQ mc_data_offset_1_ns; mc_data_offset_2 <= #TCQ mc_data_offset_2_ns; mc_cas_slot <= #TCQ mc_cas_slot_ns; mc_wrdata_en <= #TCQ mc_wrdata_en_ns; mc_rank_cnt <= #TCQ mc_rank_cnt_ns; wr_data_addr <= #TCQ wr_data_addr_ns; wr_data_en <= #TCQ wr_data_en_ns; wr_data_offset <= #TCQ wr_data_offset_ns; end // always @ (posedge clk) end // block: cmd_pipe_plus else begin : cmd_pipe_plus0 // don't register interface always @( mc_address_ns or mc_aux_out0_ns or mc_aux_out1_ns or mc_bank_ns or mc_cas_n_ns or mc_cmd_ns or mc_cs_n_ns or mc_odt_ns or mc_cke_ns or mc_data_offset_ns or mc_data_offset_1_ns or mc_data_offset_2_ns or mc_rank_cnt_ns or mc_ras_n_ns or mc_we_n_ns or mc_wrdata_en_ns or wr_data_addr_ns or wr_data_en_ns or wr_data_offset_ns or mc_cas_slot_ns) begin mc_address = #TCQ mc_address_ns; mc_bank = #TCQ mc_bank_ns; mc_cas_n = #TCQ mc_cas_n_ns; mc_cs_n = #TCQ mc_cs_n_ns; mc_odt = #TCQ mc_odt_ns; mc_cke = #TCQ mc_cke_ns; mc_aux_out0 = #TCQ mc_aux_out0_ns; mc_aux_out1 = #TCQ mc_aux_out1_ns; mc_cmd = #TCQ mc_cmd_ns; mc_ras_n = #TCQ mc_ras_n_ns; mc_we_n = #TCQ mc_we_n_ns; mc_data_offset = #TCQ mc_data_offset_ns; mc_data_offset_1 = #TCQ mc_data_offset_1_ns; mc_data_offset_2 = #TCQ mc_data_offset_2_ns; mc_cas_slot = #TCQ mc_cas_slot_ns; mc_wrdata_en = #TCQ mc_wrdata_en_ns; mc_rank_cnt = #TCQ mc_rank_cnt_ns; wr_data_addr = #TCQ wr_data_addr_ns; wr_data_en = #TCQ wr_data_en_ns; wr_data_offset = #TCQ wr_data_offset_ns; end // always @ (... end // block: cmd_pipe_plus0 endgenerate //*************************************************************************** // Indicate when there are no pending reads so that input features can be // powered down //*************************************************************************** assign mc_read_idle_ns = col_read_fifo_empty & init_calib_complete; always @(posedge clk) mc_read_idle_r <= #TCQ mc_read_idle_ns; assign mc_read_idle = mc_read_idle_r; //*************************************************************************** // Indicate when there is a refresh in progress and the bus is idle so that // tap adjustments can be made //*************************************************************************** assign mc_ref_zq_wip_ns = maint_ref_zq_wip && col_read_fifo_empty; always @(posedge clk) mc_ref_zq_wip_r <= mc_ref_zq_wip_ns; assign mc_ref_zq_wip = mc_ref_zq_wip_r; //*************************************************************************** // Manage rank-level timing and maintanence //*************************************************************************** mig_7series_v1_9_rank_mach # ( // Parameters .BURST_MODE (BURST_MODE), .CL (CL), .CWL (CWL), .CS_WIDTH (CS_WIDTH), .DQRD2DQWR_DLY (DQRD2DQWR_DLY), .DRAM_TYPE (DRAM_TYPE), .MAINT_PRESCALER_DIV (MAINT_PRESCALER_DIV), .nBANK_MACHS (nBANK_MACHS), .nCKESR (nCKESR), .nCK_PER_CLK (nCK_PER_CLK), .nFAW (nFAW), .nREFRESH_BANK (nREFRESH_BANK), .nRRD (nRRD), .nWTR (nWTR), .PERIODIC_RD_TIMER_DIV (PERIODIC_RD_TIMER_DIV), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .REFRESH_TIMER_DIV (REFRESH_TIMER_DIV), .ZQ_TIMER_DIV (ZQ_TIMER_DIV) ) rank_mach0 ( // Outputs .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .maint_ref_zq_wip (maint_ref_zq_wip), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), // Inputs .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .app_periodic_rd_req (app_periodic_rd_req), .app_ref_req (app_ref_req), .app_ref_ack (app_ref_ack), .app_zq_req (app_zq_req), .app_zq_ack (app_zq_ack), .app_sr_req (app_sr_req), .app_sr_active (app_sr_active), .col_rd_wr (col_rd_wr), .clk (clk), .init_calib_complete (init_calib_complete), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .rst (rst), .sending_col (sending_col[nBANK_MACHS-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]) ); //*************************************************************************** // Manage requests, reordering and bank timing //*************************************************************************** mig_7series_v1_9_bank_mach # ( // Parameters .TCQ (TCQ), .EVEN_CWL_2T_MODE (EVEN_CWL_2T_MODE), .ADDR_CMD_MODE (ADDR_CMD_MODE), .BANK_WIDTH (BANK_WIDTH), .BM_CNT_WIDTH (BM_CNT_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .CL (CL_M), .CWL (CWL_M), .CKE_ODT_AUX (CKE_ODT_AUX), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .LOW_IDLE_CNT (LOW_IDLE_CNT), .nBANK_MACHS (nBANK_MACHS), .nCK_PER_CLK (nCK_PER_CLK), .nCS_PER_RANK (nCS_PER_RANK), .nOP_WAIT (nOP_WAIT), .nRAS (nRAS), .nRCD (nRCD), .nRFC (nRFC), .nRP (nRP), .nRTP (nRTP), .nSLOTS (nSLOTS), .nWR (nWR), .nXSDLL (tXSDLL), .ORDERING (ORDERING), .RANK_BM_BV_WIDTH (RANK_BM_BV_WIDTH), .RANK_WIDTH (RANK_WIDTH), .RANKS (RANKS), .ROW_WIDTH (ROW_WIDTH), .RTT_NOM (RTT_NOM), .RTT_WR (RTT_WR), .SLOT_0_CONFIG (SLOT_0_CONFIG), .SLOT_1_CONFIG (SLOT_1_CONFIG), .STARVE_LIMIT (STARVE_LIMIT), .tZQCS (tZQCS) ) bank_mach0 ( // Outputs .accept (accept), .accept_ns (accept_ns), .act_this_rank_r (act_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .bank_mach_next (bank_mach_next[BM_CNT_WIDTH-1:0]), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .mc_bank (mc_bank_ns), .mc_address (mc_address_ns), .mc_ras_n (mc_ras_n_ns), .mc_cas_n (mc_cas_n_ns), .mc_we_n (mc_we_n_ns), .mc_cs_n (mc_cs_n_ns), .mc_odt (mc_odt_ns), .mc_cke (mc_cke_ns), .mc_aux_out0 (mc_aux_out0_ns), .mc_aux_out1 (mc_aux_out1_ns), .mc_cmd (mc_cmd_ns), .mc_data_offset (mc_data_offset_ns), .mc_data_offset_1 (mc_data_offset_1_ns), .mc_data_offset_2 (mc_data_offset_2_ns), .mc_cas_slot (mc_cas_slot_ns), .insert_maint_r1 (insert_maint_r1), .maint_wip_r (maint_wip_r), .periodic_rd_ack_r (periodic_rd_ack_r), .rank_busy_r (rank_busy_r[(RANKS*nBANK_MACHS)-1:0]), .rd_this_rank_r (rd_this_rank_r[RANK_BM_BV_WIDTH-1:0]), .sending_row (sending_row[nBANK_MACHS-1:0]), .sending_col (sending_col[nBANK_MACHS-1:0]), .sent_col (sent_col), .sent_col_r (sent_col_r), .wr_this_rank_r (wr_this_rank_r[RANK_BM_BV_WIDTH-1:0]), // Inputs .bank (bank[BANK_WIDTH-1:0]), .calib_rddata_offset (calib_rd_data_offset), .calib_rddata_offset_1 (calib_rd_data_offset_1), .calib_rddata_offset_2 (calib_rd_data_offset_2), .clk (clk), .cmd (cmd[2:0]), .col (col[COL_WIDTH-1:0]), .data_buf_addr (data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .init_calib_complete (init_calib_complete), .phy_rddata_valid (phy_rddata_valid), .dq_busy_data (dq_busy_data), .hi_priority (hi_priority), .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]), .inhbt_rd (inhbt_rd[RANKS-1:0]), .inhbt_wr (inhbt_wr[RANKS-1:0]), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .maint_req_r (maint_req_r), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .periodic_rd_r (periodic_rd_r), .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]), .phy_mc_cmd_full (phy_mc_cmd_full), .phy_mc_ctl_full (phy_mc_ctl_full), .phy_mc_data_full (phy_mc_data_full), .rank (rank[RANK_WIDTH-1:0]), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_rmw (rd_rmw), .row (row[ROW_WIDTH-1:0]), .rst (rst), .size (size), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0]), .use_addr (use_addr) ); //*************************************************************************** // Manage DQ bus //*************************************************************************** mig_7series_v1_9_col_mach # ( // Parameters .TCQ (TCQ), .BANK_WIDTH (BANK_WIDTH), .BURST_MODE (BURST_MODE), .COL_WIDTH (COL_WIDTH), .CS_WIDTH (CS_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DELAY_WR_DATA_CNTRL (DELAY_WR_DATA_CNTRL), .DQS_WIDTH (DQS_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .MC_ERR_ADDR_WIDTH (MC_ERR_ADDR_WIDTH), .nCK_PER_CLK (nCK_PER_CLK), .nPHY_WRLAT (nPHY_WRLAT), .RANK_WIDTH (RANK_WIDTH), .ROW_WIDTH (ROW_WIDTH) ) col_mach0 ( // Outputs .mc_wrdata_en (mc_wrdata_en_ns), .dq_busy_data (dq_busy_data), .ecc_err_addr (ecc_err_addr[MC_ERR_ADDR_WIDTH-1:0]), .ecc_status_valid (ecc_status_valid), .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]), .rd_data_en (rd_data_en), .rd_data_end (rd_data_end), .rd_data_offset (rd_data_offset), .rd_rmw (rd_rmw), .wr_data_addr (wr_data_addr_ns), .wr_data_en (wr_data_en_ns), .wr_data_offset (wr_data_offset_ns), .wr_ecc_buf (wr_ecc_buf), .col_read_fifo_empty (col_read_fifo_empty), // Inputs .clk (clk), .rst (rst), .col_a (col_a[ROW_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_row (col_row[ROW_WIDTH-1:0]), .col_size (col_size), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .phy_rddata_valid (phy_rddata_valid), .sent_col (EVEN_CWL_2T_MODE == "ON" ? sent_col_r : sent_col) ); //*************************************************************************** // Implement ECC //*************************************************************************** // Total ECC word length = ECC code width + Data width localparam CODE_WIDTH = DATA_WIDTH + ECC_WIDTH; generate if (ECC == "OFF") begin : ecc_off assign rd_data = phy_rd_data; assign mc_wrdata = wr_data; assign mc_wrdata_mask = wr_data_mask; assign ecc_single = 4'b0; assign ecc_multiple = 4'b0; end else begin : ecc_on wire [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; wire [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data; // Merge and encode mig_7series_v1_9_ecc_merge_enc # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_merge_enc0 ( // Outputs .mc_wrdata (mc_wrdata), .mc_wrdata_mask (mc_wrdata_mask), // Inputs .clk (clk), .rst (rst), .h_rows (h_rows), .rd_merge_data (rd_merge_data), .raw_not_ecc (raw_not_ecc), .wr_data (wr_data), .wr_data_mask (wr_data_mask) ); // Decode and fix mig_7series_v1_9_ecc_dec_fix # ( // Parameters .TCQ (TCQ), .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .DQ_WIDTH (DQ_WIDTH), .ECC_WIDTH (ECC_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_dec_fix0 ( // Outputs .ecc_multiple (ecc_multiple), .ecc_single (ecc_single), .rd_data (rd_data), // Inputs .clk (clk), .rst (rst), .correct_en (correct_en), .phy_rddata (phy_rd_data), .ecc_status_valid (ecc_status_valid), .h_rows (h_rows) ); // ECC Buffer mig_7series_v1_9_ecc_buf # ( // Parameters .TCQ (TCQ), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH), .DATA_WIDTH (DATA_WIDTH), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .nCK_PER_CLK (nCK_PER_CLK) ) ecc_buf0 ( // Outputs .rd_merge_data (rd_merge_data), // Inputs .clk (clk), .rst (rst), .rd_data (rd_data), .rd_data_addr (rd_data_addr), .rd_data_offset (rd_data_offset), .wr_data_addr (wr_data_addr), .wr_data_offset (wr_data_offset), .wr_ecc_buf (wr_ecc_buf) ); // Generate ECC table mig_7series_v1_9_ecc_gen # ( // Parameters .CODE_WIDTH (CODE_WIDTH), .DATA_WIDTH (DATA_WIDTH), .ECC_WIDTH (ECC_WIDTH) ) ecc_gen0 ( // Outputs .h_rows (h_rows) ); `ifdef DISPLAY_H_MATRIX integer i; always @(negedge rst) begin $display ("**********************************************"); $display ("H Matrix:"); for (i=0; i<ECC_WIDTH; i=i+1) $display ("%b", h_rows[i*CODE_WIDTH+:CODE_WIDTH]); $display ("**********************************************"); end `endif end endgenerate endmodule // mc
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: async_fifo_fwft.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: An asynchronous capable parameterized FIFO. As with all // first word fall through FIFOs, the RD_DATA will be valid when RD_EMPTY is // low. Asserting RD_EN will consume the current RD_DATA value and cause the // next value (if it exists) to appear on RD_DATA on the following cycle. Be sure // to check if RD_EMPTY is low each cycle to determine if RD_DATA is valid. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module async_fifo_fwft #( parameter C_WIDTH = 32, // Data bus width parameter C_DEPTH = 1024, // Depth of the FIFO // Local parameters parameter C_REAL_DEPTH = 2**clog2(C_DEPTH), parameter C_DEPTH_BITS = clog2s(C_REAL_DEPTH), parameter C_DEPTH_P1_BITS = clog2s(C_REAL_DEPTH+1) ) ( input RD_CLK, // Read clock input RD_RST, // Read synchronous reset input WR_CLK, // Write clock input WR_RST, // Write synchronous reset input [C_WIDTH-1:0] WR_DATA, // Write data input (WR_CLK) input WR_EN, // Write enable, high active (WR_CLK) output [C_WIDTH-1:0] RD_DATA, // Read data output (RD_CLK) input RD_EN, // Read enable, high active (RD_CLK) output WR_FULL, // Full condition (WR_CLK) output RD_EMPTY // Empty condition (RD_CLK) ); `include "functions.vh" reg [C_WIDTH-1:0] rData=0; reg [C_WIDTH-1:0] rCache=0; reg [1:0] rCount=0; reg rFifoDataValid=0; reg rDataValid=0; reg rCacheValid=0; wire [C_WIDTH-1:0] wData; wire wEmpty; wire wRen = RD_EN || (rCount < 2'd2); assign RD_DATA = rData; assign RD_EMPTY = !rDataValid; // Wrapped non-FWFT FIFO (synthesis attributes applied to this module will // determine the memory option). async_fifo #(.C_WIDTH(C_WIDTH), .C_DEPTH(C_DEPTH)) fifo ( .WR_CLK(WR_CLK), .WR_RST(WR_RST), .RD_CLK(RD_CLK), .RD_RST(RD_RST), .WR_EN(WR_EN), .WR_DATA(WR_DATA), .WR_FULL(WR_FULL), .RD_EN(wRen), .RD_DATA(wData), .RD_EMPTY(wEmpty) ); always @ (posedge RD_CLK) begin if (RD_RST) begin rCount <= #1 0; rDataValid <= #1 0; rCacheValid <= #1 0; rFifoDataValid <= #1 0; end else begin // Keep track of the count rCount <= #1 rCount + (wRen & !wEmpty) - (!RD_EMPTY & RD_EN); // Signals when wData from FIFO is valid rFifoDataValid <= #1 (wRen & !wEmpty); // Keep rData up to date if (rFifoDataValid) begin if (RD_EN | !rDataValid) begin rData <= #1 wData; rDataValid <= #1 1'd1; rCacheValid <= #1 1'd0; end else begin rCacheValid <= #1 1'd1; end rCache <= #1 wData; end else begin if (RD_EN | !rDataValid) begin rData <= #1 rCache; rDataValid <= #1 rCacheValid; rCacheValid <= #1 1'd0; end end end end endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : ecc_dec_fix.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_ecc_dec_fix #( parameter TCQ = 100, parameter PAYLOAD_WIDTH = 64, parameter CODE_WIDTH = 72, parameter DATA_WIDTH = 64, parameter DQ_WIDTH = 72, parameter ECC_WIDTH = 8, parameter nCK_PER_CLK = 4 ) ( /*AUTOARG*/ // Outputs rd_data, ecc_single, ecc_multiple, // Inputs clk, rst, h_rows, phy_rddata, correct_en, ecc_status_valid ); input clk; input rst; // Compute syndromes. input [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; input [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_rddata; wire [2*nCK_PER_CLK*ECC_WIDTH-1:0] syndrome_ns; genvar k; genvar m; generate for (k=0; k<2*nCK_PER_CLK; k=k+1) begin : ecc_word for (m=0; m<ECC_WIDTH; m=m+1) begin : ecc_bit assign syndrome_ns[k*ECC_WIDTH+m] = ^(phy_rddata[k*DQ_WIDTH+:CODE_WIDTH] & h_rows[m*CODE_WIDTH+:CODE_WIDTH]); end end endgenerate reg [2*nCK_PER_CLK*ECC_WIDTH-1:0] syndrome_r; always @(posedge clk) syndrome_r <= #TCQ syndrome_ns; // Extract payload bits from raw DRAM bits and register. wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] ecc_rddata_ns; genvar i; generate for (i=0; i<2*nCK_PER_CLK; i=i+1) begin : extract_payload assign ecc_rddata_ns[i*PAYLOAD_WIDTH+:PAYLOAD_WIDTH] = phy_rddata[i*DQ_WIDTH+:PAYLOAD_WIDTH]; end endgenerate reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] ecc_rddata_r; always @(posedge clk) ecc_rddata_r <= #TCQ ecc_rddata_ns; // Regenerate h_matrix from h_rows leaving out the identity part // since we're not going to correct the ECC bits themselves. genvar n; genvar p; wire [ECC_WIDTH-1:0] h_matrix [DATA_WIDTH-1:0]; generate for (n=0; n<DATA_WIDTH; n=n+1) begin : h_col for (p=0; p<ECC_WIDTH; p=p+1) begin : h_bit assign h_matrix [n][p] = h_rows [p*CODE_WIDTH+n]; end end endgenerate // Compute flip bits. wire [2*nCK_PER_CLK*DATA_WIDTH-1:0] flip_bits; genvar q; genvar r; generate for (q=0; q<2*nCK_PER_CLK; q=q+1) begin : flip_word for (r=0; r<DATA_WIDTH; r=r+1) begin : flip_bit assign flip_bits[q*DATA_WIDTH+r] = h_matrix[r] == syndrome_r[q*ECC_WIDTH+:ECC_WIDTH]; end end endgenerate // Correct data. output reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] rd_data; input correct_en; integer s; always @(/*AS*/correct_en or ecc_rddata_r or flip_bits) for (s=0; s<2*nCK_PER_CLK; s=s+1) if (correct_en) rd_data[s*PAYLOAD_WIDTH+:DATA_WIDTH] = ecc_rddata_r[s*PAYLOAD_WIDTH+:DATA_WIDTH] ^ flip_bits[s*DATA_WIDTH+:DATA_WIDTH]; else rd_data[s*PAYLOAD_WIDTH+:DATA_WIDTH] = ecc_rddata_r[s*PAYLOAD_WIDTH+:DATA_WIDTH]; // Copy raw payload bits if ECC_TEST is ON. localparam RAW_BIT_WIDTH = PAYLOAD_WIDTH - DATA_WIDTH; genvar t; generate if (RAW_BIT_WIDTH > 0) for (t=0; t<2*nCK_PER_CLK; t=t+1) begin : copy_raw_bits always @(/*AS*/ecc_rddata_r) rd_data[(t+1)*PAYLOAD_WIDTH-1-:RAW_BIT_WIDTH] = ecc_rddata_r[(t+1)*PAYLOAD_WIDTH-1-:RAW_BIT_WIDTH]; end endgenerate // Generate status information. input ecc_status_valid; output wire [2*nCK_PER_CLK-1:0] ecc_single; output wire [2*nCK_PER_CLK-1:0] ecc_multiple; genvar v; generate for (v=0; v<2*nCK_PER_CLK; v=v+1) begin : compute_status wire zero = ~|syndrome_r[v*ECC_WIDTH+:ECC_WIDTH]; wire odd = ^syndrome_r[v*ECC_WIDTH+:ECC_WIDTH]; assign ecc_single[v] = ecc_status_valid && ~zero && odd; assign ecc_multiple[v] = ecc_status_valid && ~zero && ~odd; end endgenerate endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : ecc_dec_fix.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_ecc_dec_fix #( parameter TCQ = 100, parameter PAYLOAD_WIDTH = 64, parameter CODE_WIDTH = 72, parameter DATA_WIDTH = 64, parameter DQ_WIDTH = 72, parameter ECC_WIDTH = 8, parameter nCK_PER_CLK = 4 ) ( /*AUTOARG*/ // Outputs rd_data, ecc_single, ecc_multiple, // Inputs clk, rst, h_rows, phy_rddata, correct_en, ecc_status_valid ); input clk; input rst; // Compute syndromes. input [CODE_WIDTH*ECC_WIDTH-1:0] h_rows; input [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_rddata; wire [2*nCK_PER_CLK*ECC_WIDTH-1:0] syndrome_ns; genvar k; genvar m; generate for (k=0; k<2*nCK_PER_CLK; k=k+1) begin : ecc_word for (m=0; m<ECC_WIDTH; m=m+1) begin : ecc_bit assign syndrome_ns[k*ECC_WIDTH+m] = ^(phy_rddata[k*DQ_WIDTH+:CODE_WIDTH] & h_rows[m*CODE_WIDTH+:CODE_WIDTH]); end end endgenerate reg [2*nCK_PER_CLK*ECC_WIDTH-1:0] syndrome_r; always @(posedge clk) syndrome_r <= #TCQ syndrome_ns; // Extract payload bits from raw DRAM bits and register. wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] ecc_rddata_ns; genvar i; generate for (i=0; i<2*nCK_PER_CLK; i=i+1) begin : extract_payload assign ecc_rddata_ns[i*PAYLOAD_WIDTH+:PAYLOAD_WIDTH] = phy_rddata[i*DQ_WIDTH+:PAYLOAD_WIDTH]; end endgenerate reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] ecc_rddata_r; always @(posedge clk) ecc_rddata_r <= #TCQ ecc_rddata_ns; // Regenerate h_matrix from h_rows leaving out the identity part // since we're not going to correct the ECC bits themselves. genvar n; genvar p; wire [ECC_WIDTH-1:0] h_matrix [DATA_WIDTH-1:0]; generate for (n=0; n<DATA_WIDTH; n=n+1) begin : h_col for (p=0; p<ECC_WIDTH; p=p+1) begin : h_bit assign h_matrix [n][p] = h_rows [p*CODE_WIDTH+n]; end end endgenerate // Compute flip bits. wire [2*nCK_PER_CLK*DATA_WIDTH-1:0] flip_bits; genvar q; genvar r; generate for (q=0; q<2*nCK_PER_CLK; q=q+1) begin : flip_word for (r=0; r<DATA_WIDTH; r=r+1) begin : flip_bit assign flip_bits[q*DATA_WIDTH+r] = h_matrix[r] == syndrome_r[q*ECC_WIDTH+:ECC_WIDTH]; end end endgenerate // Correct data. output reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] rd_data; input correct_en; integer s; always @(/*AS*/correct_en or ecc_rddata_r or flip_bits) for (s=0; s<2*nCK_PER_CLK; s=s+1) if (correct_en) rd_data[s*PAYLOAD_WIDTH+:DATA_WIDTH] = ecc_rddata_r[s*PAYLOAD_WIDTH+:DATA_WIDTH] ^ flip_bits[s*DATA_WIDTH+:DATA_WIDTH]; else rd_data[s*PAYLOAD_WIDTH+:DATA_WIDTH] = ecc_rddata_r[s*PAYLOAD_WIDTH+:DATA_WIDTH]; // Copy raw payload bits if ECC_TEST is ON. localparam RAW_BIT_WIDTH = PAYLOAD_WIDTH - DATA_WIDTH; genvar t; generate if (RAW_BIT_WIDTH > 0) for (t=0; t<2*nCK_PER_CLK; t=t+1) begin : copy_raw_bits always @(/*AS*/ecc_rddata_r) rd_data[(t+1)*PAYLOAD_WIDTH-1-:RAW_BIT_WIDTH] = ecc_rddata_r[(t+1)*PAYLOAD_WIDTH-1-:RAW_BIT_WIDTH]; end endgenerate // Generate status information. input ecc_status_valid; output wire [2*nCK_PER_CLK-1:0] ecc_single; output wire [2*nCK_PER_CLK-1:0] ecc_multiple; genvar v; generate for (v=0; v<2*nCK_PER_CLK; v=v+1) begin : compute_status wire zero = ~|syndrome_r[v*ECC_WIDTH+:ECC_WIDTH]; wire odd = ^syndrome_r[v*ECC_WIDTH+:ECC_WIDTH]; assign ecc_single[v] = ecc_status_valid && ~zero && odd; assign ecc_multiple[v] = ecc_status_valid && ~zero && ~odd; end endgenerate endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : col_mach.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** // The column machine manages the dq bus. Since there is a single DQ // bus, and the column part of the DRAM is tightly coupled to this DQ // bus, conceptually, the DQ bus and all of the column hardware in // a multi rank DRAM array are managed as a single unit. // // // The column machine does not "enforce" the column timing directly. // It generates information and sends it to the bank machines. If the // bank machines incorrectly make a request, the column machine will // simply overwrite the existing request with the new request even // if this would result in a timing or protocol violation. // // The column machine // hosts the block that controls read and write data transfer // to and from the dq bus. // // And if configured, there is provision for tracking the address // of a command as it moves through the column pipeline. This // address will be logged for detected ECC errors. `timescale 1 ps / 1 ps module mig_7series_v1_9_col_mach # ( parameter TCQ = 100, parameter BANK_WIDTH = 3, parameter BURST_MODE = "8", parameter COL_WIDTH = 12, parameter CS_WIDTH = 4, parameter DATA_BUF_ADDR_WIDTH = 8, parameter DATA_BUF_OFFSET_WIDTH = 1, parameter DELAY_WR_DATA_CNTRL = 0, parameter DQS_WIDTH = 8, parameter DRAM_TYPE = "DDR3", parameter EARLY_WR_DATA_ADDR = "OFF", parameter ECC = "OFF", parameter MC_ERR_ADDR_WIDTH = 31, parameter nCK_PER_CLK = 2, parameter nPHY_WRLAT = 0, parameter RANK_WIDTH = 2, parameter ROW_WIDTH = 16 ) (/*AUTOARG*/ // Outputs dq_busy_data, wr_data_offset, mc_wrdata_en, wr_data_en, wr_data_addr, rd_rmw, ecc_err_addr, ecc_status_valid, wr_ecc_buf, rd_data_end, rd_data_addr, rd_data_offset, rd_data_en, col_read_fifo_empty, // Inputs clk, rst, sent_col, col_size, col_wr_data_buf_addr, phy_rddata_valid, col_periodic_rd, col_data_buf_addr, col_rmw, col_rd_wr, col_ra, col_ba, col_row, col_a ); input clk; input rst; input sent_col; input col_rd_wr; output reg dq_busy_data = 1'b0; // The following generates a column command disable based mostly on the type // of DRAM and the fabric to DRAM CK ratio. generate if ((nCK_PER_CLK == 1) && ((BURST_MODE == "8") || (DRAM_TYPE == "DDR3"))) begin : three_bumps reg [1:0] granted_col_d_r; wire [1:0] granted_col_d_ns = {sent_col, granted_col_d_r[1]}; always @(posedge clk) granted_col_d_r <= #TCQ granted_col_d_ns; always @(/*AS*/granted_col_d_r or sent_col) dq_busy_data = sent_col || |granted_col_d_r; end if (((nCK_PER_CLK == 2) && ((BURST_MODE == "8") || (DRAM_TYPE == "DDR3"))) || ((nCK_PER_CLK == 1) && ((BURST_MODE == "4") || (DRAM_TYPE == "DDR2")))) begin : one_bump always @(/*AS*/sent_col) dq_busy_data = sent_col; end endgenerate // This generates a data offset based on fabric clock to DRAM CK ratio and // the size bit. Note that this is different that the dq_busy_data signal // generated above. reg [1:0] offset_r = 2'b0; reg [1:0] offset_ns = 2'b0; input col_size; wire data_end; generate if(nCK_PER_CLK == 4) begin : data_valid_4_1 // For 4:1 mode all data is transfered in a single beat so the default // values of 0 for offset_r/offset_ns suffice - just tie off data_end assign data_end = 1'b1; end else begin if(DATA_BUF_OFFSET_WIDTH == 2) begin : data_valid_1_1 always @(col_size or offset_r or rst or sent_col) begin if (rst) offset_ns = 2'b0; else begin offset_ns = offset_r; if (sent_col) offset_ns = 2'b1; else if (|offset_r && (offset_r != {col_size, 1'b1})) offset_ns = offset_r + 2'b1; else offset_ns = 2'b0; end end always @(posedge clk) offset_r <= #TCQ offset_ns; assign data_end = col_size ? (offset_r == 2'b11) : offset_r[0]; end else begin : data_valid_2_1 always @(col_size or rst or sent_col) offset_ns[0] = rst ? 1'b0 : sent_col && col_size; always @(posedge clk) offset_r[0] <= #TCQ offset_ns[0]; assign data_end = col_size ? offset_r[0] : 1'b1; end end endgenerate reg [DATA_BUF_OFFSET_WIDTH-1:0] offset_r1 = {DATA_BUF_OFFSET_WIDTH{1'b0}}; reg [DATA_BUF_OFFSET_WIDTH-1:0] offset_r2 = {DATA_BUF_OFFSET_WIDTH{1'b0}}; reg col_rd_wr_r1; reg col_rd_wr_r2; generate if ((nPHY_WRLAT >= 1) || (DELAY_WR_DATA_CNTRL == 1)) begin : offset_pipe_0 always @(posedge clk) offset_r1 <= #TCQ offset_r[DATA_BUF_OFFSET_WIDTH-1:0]; always @(posedge clk) col_rd_wr_r1 <= #TCQ col_rd_wr; end if(nPHY_WRLAT == 2) begin : offset_pipe_1 always @(posedge clk) offset_r2 <= #TCQ offset_r1[DATA_BUF_OFFSET_WIDTH-1:0]; always @(posedge clk) col_rd_wr_r2 <= #TCQ col_rd_wr_r1; end endgenerate output wire [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset; assign wr_data_offset = (DELAY_WR_DATA_CNTRL == 1) ? offset_r1[DATA_BUF_OFFSET_WIDTH-1:0] : (EARLY_WR_DATA_ADDR == "OFF") ? offset_r[DATA_BUF_OFFSET_WIDTH-1:0] : offset_ns[DATA_BUF_OFFSET_WIDTH-1:0]; reg sent_col_r1; reg sent_col_r2; always @(posedge clk) sent_col_r1 <= #TCQ sent_col; always @(posedge clk) sent_col_r2 <= #TCQ sent_col_r1; wire wrdata_en = (nPHY_WRLAT == 0) ? (sent_col || |offset_r) & ~col_rd_wr : (nPHY_WRLAT == 1) ? (sent_col_r1 || |offset_r1) & ~col_rd_wr_r1 : //(nPHY_WRLAT >= 2) ? (sent_col_r2 || |offset_r2) & ~col_rd_wr_r2; output wire mc_wrdata_en; assign mc_wrdata_en = wrdata_en; output wire wr_data_en; assign wr_data_en = (DELAY_WR_DATA_CNTRL == 1) ? ((sent_col_r1 || |offset_r1) && ~col_rd_wr_r1) : ((sent_col || |offset_r) && ~col_rd_wr); input [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr; output wire [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr; generate if (DELAY_WR_DATA_CNTRL == 1) begin : delay_wr_data_cntrl_eq_1 reg [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr_r; always @(posedge clk) col_wr_data_buf_addr_r <= #TCQ col_wr_data_buf_addr; assign wr_data_addr = col_wr_data_buf_addr_r; end else begin : delay_wr_data_cntrl_ne_1 assign wr_data_addr = col_wr_data_buf_addr; end endgenerate // CAS-RD to mc_rddata_en wire read_data_valid = (sent_col || |offset_r) && col_rd_wr; function integer clogb2 (input integer size); // ceiling logb2 begin size = size - 1; for (clogb2=1; size>1; clogb2=clogb2+1) size = size >> 1; end endfunction // clogb2 // Implement FIFO that records reads as they are sent to the DRAM. // When phy_rddata_valid is returned some unknown time later, the // FIFO output is used to control how the data is interpreted. input phy_rddata_valid; output wire rd_rmw; output reg [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr; output reg ecc_status_valid; output reg wr_ecc_buf; output reg rd_data_end; output reg [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr; output reg [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset; (* keep = "true", max_fanout = 10 *) output reg rd_data_en /* synthesis syn_maxfan = 10 */; output col_read_fifo_empty; input col_periodic_rd; input [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr; input col_rmw; input [RANK_WIDTH-1:0] col_ra; input [BANK_WIDTH-1:0] col_ba; input [ROW_WIDTH-1:0] col_row; input [ROW_WIDTH-1:0] col_a; // Real column address (skip A10/AP and A12/BC#). The maximum width is 12; // the width will be tailored for the target DRAM downstream. wire [11:0] col_a_full; // Minimum row width is 12; take remaining 11 bits after omitting A10/AP assign col_a_full[10:0] = {col_a[11], col_a[9:0]}; // Get the 12th bit when row address width accommodates it; omit A12/BC# generate if (ROW_WIDTH >= 14) begin : COL_A_FULL_11_1 assign col_a_full[11] = col_a[13]; end else begin : COL_A_FULL_11_0 assign col_a_full[11] = 0; end endgenerate // Extract only the width of the target DRAM wire [COL_WIDTH-1:0] col_a_extracted = col_a_full[COL_WIDTH-1:0]; localparam MC_ERR_LINE_WIDTH = MC_ERR_ADDR_WIDTH-DATA_BUF_OFFSET_WIDTH; localparam FIFO_WIDTH = 1 /*data_end*/ + 1 /*periodic_rd*/ + DATA_BUF_ADDR_WIDTH + DATA_BUF_OFFSET_WIDTH + ((ECC == "OFF") ? 0 : 1+MC_ERR_LINE_WIDTH); localparam FULL_RAM_CNT = (FIFO_WIDTH/6); localparam REMAINDER = FIFO_WIDTH % 6; localparam RAM_CNT = FULL_RAM_CNT + ((REMAINDER == 0 ) ? 0 : 1); localparam RAM_WIDTH = (RAM_CNT*6); generate begin : read_fifo wire [MC_ERR_LINE_WIDTH:0] ecc_line; if (CS_WIDTH == 1) assign ecc_line = {col_rmw, col_ba, col_row, col_a_extracted}; else assign ecc_line = {col_rmw, col_ra, col_ba, col_row, col_a_extracted}; wire [FIFO_WIDTH-1:0] real_fifo_data; if (ECC == "OFF") assign real_fifo_data = {data_end, col_periodic_rd, col_data_buf_addr, offset_r[DATA_BUF_OFFSET_WIDTH-1:0]}; else assign real_fifo_data = {data_end, col_periodic_rd, col_data_buf_addr, offset_r[DATA_BUF_OFFSET_WIDTH-1:0], ecc_line}; wire [RAM_WIDTH-1:0] fifo_in_data; if (REMAINDER == 0) assign fifo_in_data = real_fifo_data; else assign fifo_in_data = {{6-REMAINDER{1'b0}}, real_fifo_data}; wire [RAM_WIDTH-1:0] fifo_out_data_ns; reg [4:0] head_r; wire [4:0] head_ns = rst ? 5'b0 : read_data_valid ? (head_r + 5'b1) : head_r; always @(posedge clk) head_r <= #TCQ head_ns; reg [4:0] tail_r; wire [4:0] tail_ns = rst ? 5'b0 : phy_rddata_valid ? (tail_r + 5'b1) : tail_r; always @(posedge clk) tail_r <= #TCQ tail_ns; assign col_read_fifo_empty = head_r == tail_r ? 1'b1 : 1'b0; genvar i; for (i=0; i<RAM_CNT; i=i+1) begin : fifo_ram RAM32M #(.INIT_A(64'h0000000000000000), .INIT_B(64'h0000000000000000), .INIT_C(64'h0000000000000000), .INIT_D(64'h0000000000000000) ) RAM32M0 ( .DOA(fifo_out_data_ns[((i*6)+4)+:2]), .DOB(fifo_out_data_ns[((i*6)+2)+:2]), .DOC(fifo_out_data_ns[((i*6)+0)+:2]), .DOD(), .DIA(fifo_in_data[((i*6)+4)+:2]), .DIB(fifo_in_data[((i*6)+2)+:2]), .DIC(fifo_in_data[((i*6)+0)+:2]), .DID(2'b0), .ADDRA(tail_ns), .ADDRB(tail_ns), .ADDRC(tail_ns), .ADDRD(head_r), .WE(1'b1), .WCLK(clk) ); end // block: fifo_ram reg [RAM_WIDTH-1:0] fifo_out_data_r; always @(posedge clk) fifo_out_data_r <= #TCQ fifo_out_data_ns; // When ECC is ON, most of the FIFO output is delayed // by one state. if (ECC == "OFF") begin reg periodic_rd; always @(/*AS*/phy_rddata_valid or fifo_out_data_r) begin {rd_data_end, periodic_rd, rd_data_addr, rd_data_offset} = fifo_out_data_r[FIFO_WIDTH-1:0]; ecc_err_addr = {MC_ERR_ADDR_WIDTH{1'b0}}; rd_data_en = phy_rddata_valid && ~periodic_rd; ecc_status_valid = 1'b0; wr_ecc_buf = 1'b0; end assign rd_rmw = 1'b0; end else begin wire rd_data_end_ns; wire periodic_rd; wire [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr_ns; wire [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset_ns; wire [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr_ns; assign {rd_data_end_ns, periodic_rd, rd_data_addr_ns, rd_data_offset_ns, rd_rmw, ecc_err_addr_ns[DATA_BUF_OFFSET_WIDTH+:MC_ERR_LINE_WIDTH]} = {fifo_out_data_r[FIFO_WIDTH-1:0]}; assign ecc_err_addr_ns[0+:DATA_BUF_OFFSET_WIDTH] = rd_data_offset_ns; always @(posedge clk) rd_data_end <= #TCQ rd_data_end_ns; always @(posedge clk) rd_data_addr <= #TCQ rd_data_addr_ns; always @(posedge clk) rd_data_offset <= #TCQ rd_data_offset_ns; always @(posedge clk) ecc_err_addr <= #TCQ ecc_err_addr_ns; wire rd_data_en_ns = phy_rddata_valid && ~(periodic_rd || rd_rmw); always @(posedge clk) rd_data_en <= rd_data_en_ns; wire ecc_status_valid_ns = phy_rddata_valid && ~periodic_rd; always @(posedge clk) ecc_status_valid <= #TCQ ecc_status_valid_ns; wire wr_ecc_buf_ns = phy_rddata_valid && ~periodic_rd && rd_rmw; always @(posedge clk) wr_ecc_buf <= #TCQ wr_ecc_buf_ns; end end endgenerate endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : col_mach.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** // The column machine manages the dq bus. Since there is a single DQ // bus, and the column part of the DRAM is tightly coupled to this DQ // bus, conceptually, the DQ bus and all of the column hardware in // a multi rank DRAM array are managed as a single unit. // // // The column machine does not "enforce" the column timing directly. // It generates information and sends it to the bank machines. If the // bank machines incorrectly make a request, the column machine will // simply overwrite the existing request with the new request even // if this would result in a timing or protocol violation. // // The column machine // hosts the block that controls read and write data transfer // to and from the dq bus. // // And if configured, there is provision for tracking the address // of a command as it moves through the column pipeline. This // address will be logged for detected ECC errors. `timescale 1 ps / 1 ps module mig_7series_v1_9_col_mach # ( parameter TCQ = 100, parameter BANK_WIDTH = 3, parameter BURST_MODE = "8", parameter COL_WIDTH = 12, parameter CS_WIDTH = 4, parameter DATA_BUF_ADDR_WIDTH = 8, parameter DATA_BUF_OFFSET_WIDTH = 1, parameter DELAY_WR_DATA_CNTRL = 0, parameter DQS_WIDTH = 8, parameter DRAM_TYPE = "DDR3", parameter EARLY_WR_DATA_ADDR = "OFF", parameter ECC = "OFF", parameter MC_ERR_ADDR_WIDTH = 31, parameter nCK_PER_CLK = 2, parameter nPHY_WRLAT = 0, parameter RANK_WIDTH = 2, parameter ROW_WIDTH = 16 ) (/*AUTOARG*/ // Outputs dq_busy_data, wr_data_offset, mc_wrdata_en, wr_data_en, wr_data_addr, rd_rmw, ecc_err_addr, ecc_status_valid, wr_ecc_buf, rd_data_end, rd_data_addr, rd_data_offset, rd_data_en, col_read_fifo_empty, // Inputs clk, rst, sent_col, col_size, col_wr_data_buf_addr, phy_rddata_valid, col_periodic_rd, col_data_buf_addr, col_rmw, col_rd_wr, col_ra, col_ba, col_row, col_a ); input clk; input rst; input sent_col; input col_rd_wr; output reg dq_busy_data = 1'b0; // The following generates a column command disable based mostly on the type // of DRAM and the fabric to DRAM CK ratio. generate if ((nCK_PER_CLK == 1) && ((BURST_MODE == "8") || (DRAM_TYPE == "DDR3"))) begin : three_bumps reg [1:0] granted_col_d_r; wire [1:0] granted_col_d_ns = {sent_col, granted_col_d_r[1]}; always @(posedge clk) granted_col_d_r <= #TCQ granted_col_d_ns; always @(/*AS*/granted_col_d_r or sent_col) dq_busy_data = sent_col || |granted_col_d_r; end if (((nCK_PER_CLK == 2) && ((BURST_MODE == "8") || (DRAM_TYPE == "DDR3"))) || ((nCK_PER_CLK == 1) && ((BURST_MODE == "4") || (DRAM_TYPE == "DDR2")))) begin : one_bump always @(/*AS*/sent_col) dq_busy_data = sent_col; end endgenerate // This generates a data offset based on fabric clock to DRAM CK ratio and // the size bit. Note that this is different that the dq_busy_data signal // generated above. reg [1:0] offset_r = 2'b0; reg [1:0] offset_ns = 2'b0; input col_size; wire data_end; generate if(nCK_PER_CLK == 4) begin : data_valid_4_1 // For 4:1 mode all data is transfered in a single beat so the default // values of 0 for offset_r/offset_ns suffice - just tie off data_end assign data_end = 1'b1; end else begin if(DATA_BUF_OFFSET_WIDTH == 2) begin : data_valid_1_1 always @(col_size or offset_r or rst or sent_col) begin if (rst) offset_ns = 2'b0; else begin offset_ns = offset_r; if (sent_col) offset_ns = 2'b1; else if (|offset_r && (offset_r != {col_size, 1'b1})) offset_ns = offset_r + 2'b1; else offset_ns = 2'b0; end end always @(posedge clk) offset_r <= #TCQ offset_ns; assign data_end = col_size ? (offset_r == 2'b11) : offset_r[0]; end else begin : data_valid_2_1 always @(col_size or rst or sent_col) offset_ns[0] = rst ? 1'b0 : sent_col && col_size; always @(posedge clk) offset_r[0] <= #TCQ offset_ns[0]; assign data_end = col_size ? offset_r[0] : 1'b1; end end endgenerate reg [DATA_BUF_OFFSET_WIDTH-1:0] offset_r1 = {DATA_BUF_OFFSET_WIDTH{1'b0}}; reg [DATA_BUF_OFFSET_WIDTH-1:0] offset_r2 = {DATA_BUF_OFFSET_WIDTH{1'b0}}; reg col_rd_wr_r1; reg col_rd_wr_r2; generate if ((nPHY_WRLAT >= 1) || (DELAY_WR_DATA_CNTRL == 1)) begin : offset_pipe_0 always @(posedge clk) offset_r1 <= #TCQ offset_r[DATA_BUF_OFFSET_WIDTH-1:0]; always @(posedge clk) col_rd_wr_r1 <= #TCQ col_rd_wr; end if(nPHY_WRLAT == 2) begin : offset_pipe_1 always @(posedge clk) offset_r2 <= #TCQ offset_r1[DATA_BUF_OFFSET_WIDTH-1:0]; always @(posedge clk) col_rd_wr_r2 <= #TCQ col_rd_wr_r1; end endgenerate output wire [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset; assign wr_data_offset = (DELAY_WR_DATA_CNTRL == 1) ? offset_r1[DATA_BUF_OFFSET_WIDTH-1:0] : (EARLY_WR_DATA_ADDR == "OFF") ? offset_r[DATA_BUF_OFFSET_WIDTH-1:0] : offset_ns[DATA_BUF_OFFSET_WIDTH-1:0]; reg sent_col_r1; reg sent_col_r2; always @(posedge clk) sent_col_r1 <= #TCQ sent_col; always @(posedge clk) sent_col_r2 <= #TCQ sent_col_r1; wire wrdata_en = (nPHY_WRLAT == 0) ? (sent_col || |offset_r) & ~col_rd_wr : (nPHY_WRLAT == 1) ? (sent_col_r1 || |offset_r1) & ~col_rd_wr_r1 : //(nPHY_WRLAT >= 2) ? (sent_col_r2 || |offset_r2) & ~col_rd_wr_r2; output wire mc_wrdata_en; assign mc_wrdata_en = wrdata_en; output wire wr_data_en; assign wr_data_en = (DELAY_WR_DATA_CNTRL == 1) ? ((sent_col_r1 || |offset_r1) && ~col_rd_wr_r1) : ((sent_col || |offset_r) && ~col_rd_wr); input [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr; output wire [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr; generate if (DELAY_WR_DATA_CNTRL == 1) begin : delay_wr_data_cntrl_eq_1 reg [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr_r; always @(posedge clk) col_wr_data_buf_addr_r <= #TCQ col_wr_data_buf_addr; assign wr_data_addr = col_wr_data_buf_addr_r; end else begin : delay_wr_data_cntrl_ne_1 assign wr_data_addr = col_wr_data_buf_addr; end endgenerate // CAS-RD to mc_rddata_en wire read_data_valid = (sent_col || |offset_r) && col_rd_wr; function integer clogb2 (input integer size); // ceiling logb2 begin size = size - 1; for (clogb2=1; size>1; clogb2=clogb2+1) size = size >> 1; end endfunction // clogb2 // Implement FIFO that records reads as they are sent to the DRAM. // When phy_rddata_valid is returned some unknown time later, the // FIFO output is used to control how the data is interpreted. input phy_rddata_valid; output wire rd_rmw; output reg [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr; output reg ecc_status_valid; output reg wr_ecc_buf; output reg rd_data_end; output reg [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr; output reg [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset; (* keep = "true", max_fanout = 10 *) output reg rd_data_en /* synthesis syn_maxfan = 10 */; output col_read_fifo_empty; input col_periodic_rd; input [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr; input col_rmw; input [RANK_WIDTH-1:0] col_ra; input [BANK_WIDTH-1:0] col_ba; input [ROW_WIDTH-1:0] col_row; input [ROW_WIDTH-1:0] col_a; // Real column address (skip A10/AP and A12/BC#). The maximum width is 12; // the width will be tailored for the target DRAM downstream. wire [11:0] col_a_full; // Minimum row width is 12; take remaining 11 bits after omitting A10/AP assign col_a_full[10:0] = {col_a[11], col_a[9:0]}; // Get the 12th bit when row address width accommodates it; omit A12/BC# generate if (ROW_WIDTH >= 14) begin : COL_A_FULL_11_1 assign col_a_full[11] = col_a[13]; end else begin : COL_A_FULL_11_0 assign col_a_full[11] = 0; end endgenerate // Extract only the width of the target DRAM wire [COL_WIDTH-1:0] col_a_extracted = col_a_full[COL_WIDTH-1:0]; localparam MC_ERR_LINE_WIDTH = MC_ERR_ADDR_WIDTH-DATA_BUF_OFFSET_WIDTH; localparam FIFO_WIDTH = 1 /*data_end*/ + 1 /*periodic_rd*/ + DATA_BUF_ADDR_WIDTH + DATA_BUF_OFFSET_WIDTH + ((ECC == "OFF") ? 0 : 1+MC_ERR_LINE_WIDTH); localparam FULL_RAM_CNT = (FIFO_WIDTH/6); localparam REMAINDER = FIFO_WIDTH % 6; localparam RAM_CNT = FULL_RAM_CNT + ((REMAINDER == 0 ) ? 0 : 1); localparam RAM_WIDTH = (RAM_CNT*6); generate begin : read_fifo wire [MC_ERR_LINE_WIDTH:0] ecc_line; if (CS_WIDTH == 1) assign ecc_line = {col_rmw, col_ba, col_row, col_a_extracted}; else assign ecc_line = {col_rmw, col_ra, col_ba, col_row, col_a_extracted}; wire [FIFO_WIDTH-1:0] real_fifo_data; if (ECC == "OFF") assign real_fifo_data = {data_end, col_periodic_rd, col_data_buf_addr, offset_r[DATA_BUF_OFFSET_WIDTH-1:0]}; else assign real_fifo_data = {data_end, col_periodic_rd, col_data_buf_addr, offset_r[DATA_BUF_OFFSET_WIDTH-1:0], ecc_line}; wire [RAM_WIDTH-1:0] fifo_in_data; if (REMAINDER == 0) assign fifo_in_data = real_fifo_data; else assign fifo_in_data = {{6-REMAINDER{1'b0}}, real_fifo_data}; wire [RAM_WIDTH-1:0] fifo_out_data_ns; reg [4:0] head_r; wire [4:0] head_ns = rst ? 5'b0 : read_data_valid ? (head_r + 5'b1) : head_r; always @(posedge clk) head_r <= #TCQ head_ns; reg [4:0] tail_r; wire [4:0] tail_ns = rst ? 5'b0 : phy_rddata_valid ? (tail_r + 5'b1) : tail_r; always @(posedge clk) tail_r <= #TCQ tail_ns; assign col_read_fifo_empty = head_r == tail_r ? 1'b1 : 1'b0; genvar i; for (i=0; i<RAM_CNT; i=i+1) begin : fifo_ram RAM32M #(.INIT_A(64'h0000000000000000), .INIT_B(64'h0000000000000000), .INIT_C(64'h0000000000000000), .INIT_D(64'h0000000000000000) ) RAM32M0 ( .DOA(fifo_out_data_ns[((i*6)+4)+:2]), .DOB(fifo_out_data_ns[((i*6)+2)+:2]), .DOC(fifo_out_data_ns[((i*6)+0)+:2]), .DOD(), .DIA(fifo_in_data[((i*6)+4)+:2]), .DIB(fifo_in_data[((i*6)+2)+:2]), .DIC(fifo_in_data[((i*6)+0)+:2]), .DID(2'b0), .ADDRA(tail_ns), .ADDRB(tail_ns), .ADDRC(tail_ns), .ADDRD(head_r), .WE(1'b1), .WCLK(clk) ); end // block: fifo_ram reg [RAM_WIDTH-1:0] fifo_out_data_r; always @(posedge clk) fifo_out_data_r <= #TCQ fifo_out_data_ns; // When ECC is ON, most of the FIFO output is delayed // by one state. if (ECC == "OFF") begin reg periodic_rd; always @(/*AS*/phy_rddata_valid or fifo_out_data_r) begin {rd_data_end, periodic_rd, rd_data_addr, rd_data_offset} = fifo_out_data_r[FIFO_WIDTH-1:0]; ecc_err_addr = {MC_ERR_ADDR_WIDTH{1'b0}}; rd_data_en = phy_rddata_valid && ~periodic_rd; ecc_status_valid = 1'b0; wr_ecc_buf = 1'b0; end assign rd_rmw = 1'b0; end else begin wire rd_data_end_ns; wire periodic_rd; wire [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr_ns; wire [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset_ns; wire [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr_ns; assign {rd_data_end_ns, periodic_rd, rd_data_addr_ns, rd_data_offset_ns, rd_rmw, ecc_err_addr_ns[DATA_BUF_OFFSET_WIDTH+:MC_ERR_LINE_WIDTH]} = {fifo_out_data_r[FIFO_WIDTH-1:0]}; assign ecc_err_addr_ns[0+:DATA_BUF_OFFSET_WIDTH] = rd_data_offset_ns; always @(posedge clk) rd_data_end <= #TCQ rd_data_end_ns; always @(posedge clk) rd_data_addr <= #TCQ rd_data_addr_ns; always @(posedge clk) rd_data_offset <= #TCQ rd_data_offset_ns; always @(posedge clk) ecc_err_addr <= #TCQ ecc_err_addr_ns; wire rd_data_en_ns = phy_rddata_valid && ~(periodic_rd || rd_rmw); always @(posedge clk) rd_data_en <= rd_data_en_ns; wire ecc_status_valid_ns = phy_rddata_valid && ~periodic_rd; always @(posedge clk) ecc_status_valid <= #TCQ ecc_status_valid_ns; wire wr_ecc_buf_ns = phy_rddata_valid && ~periodic_rd && rd_rmw; always @(posedge clk) wr_ecc_buf <= #TCQ wr_ecc_buf_ns; end end endgenerate endmodule
//***************************************************************************** // (c) Copyright 2009 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor: Xilinx // \ \ \/ Version: // \ \ Application: MIG // / / Filename: ddr_phy_prbs_rdlvl.v // /___/ /\ Date Last Modified: $Date: 2011/06/24 14:49:00 $ // \ \ / \ Date Created: // \___\/\___\ // //Device: 7 Series //Design Name: DDR3 SDRAM //Purpose: // PRBS Read leveling calibration logic // NOTES: // 1. Window detection with PRBS pattern. //Reference: //Revision History: //***************************************************************************** /****************************************************************************** **$Id: ddr_phy_prbs_rdlvl.v,v 1.2 2011/06/24 14:49:00 mgeorge Exp $ **$Date: 2011/06/24 14:49:00 $ **$Author: mgeorge $ **$Revision: 1.2 $ **$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_7series_v1_3/data/dlib/7series/ddr3_sdram/verilog/rtl/phy/ddr_phy_prbs_rdlvl.v,v $ ******************************************************************************/ `timescale 1ps/1ps module mig_7series_v1_9_ddr_phy_prbs_rdlvl # ( parameter TCQ = 100, // clk->out delay (sim only) parameter nCK_PER_CLK = 2, // # of memory clocks per CLK parameter DQ_WIDTH = 64, // # of DQ (data) parameter DQS_CNT_WIDTH = 3, // = ceil(log2(DQS_WIDTH)) parameter DQS_WIDTH = 8, // # of DQS (strobe) parameter DRAM_WIDTH = 8, // # of DQ per DQS parameter RANKS = 1, // # of DRAM ranks parameter SIM_CAL_OPTION = "NONE", // Skip various calibration steps parameter PRBS_WIDTH = 8 // PRBS generator output width ) ( input clk, input rst, // Calibration status, control signals input prbs_rdlvl_start, output reg prbs_rdlvl_done, output reg prbs_last_byte_done, output reg prbs_rdlvl_prech_req, input prech_done, input phy_if_empty, // Captured data in fabric clock domain input [2*nCK_PER_CLK*DQ_WIDTH-1:0] rd_data, //Expected data from PRBS generator input [2*nCK_PER_CLK*PRBS_WIDTH-1:0] compare_data, // Decrement initial Phaser_IN Fine tap delay input [5:0] pi_counter_read_val, // Stage 1 calibration outputs output reg pi_en_stg2_f, output reg pi_stg2_f_incdec, output [255:0] dbg_prbs_rdlvl, output [DQS_CNT_WIDTH:0] pi_stg2_prbs_rdlvl_cnt ); localparam [5:0] PRBS_IDLE = 6'h00; localparam [5:0] PRBS_NEW_DQS_WAIT = 6'h01; localparam [5:0] PRBS_PAT_COMPARE = 6'h02; localparam [5:0] PRBS_DEC_DQS = 6'h03; localparam [5:0] PRBS_DEC_DQS_WAIT = 6'h04; localparam [5:0] PRBS_INC_DQS = 6'h05; localparam [5:0] PRBS_INC_DQS_WAIT = 6'h06; localparam [5:0] PRBS_CALC_TAPS = 6'h07; localparam [5:0] PRBS_TAP_CHECK = 6'h08; localparam [5:0] PRBS_NEXT_DQS = 6'h09; localparam [5:0] PRBS_NEW_DQS_PREWAIT = 6'h0A; localparam [5:0] PRBS_DONE = 6'h0B; localparam [11:0] NUM_SAMPLES_CNT = (SIM_CAL_OPTION == "NONE") ? 12'hFFF : 12'h001; localparam [11:0] NUM_SAMPLES_CNT1 = (SIM_CAL_OPTION == "NONE") ? 12'hFFF : 12'h001; localparam [11:0] NUM_SAMPLES_CNT2 = (SIM_CAL_OPTION == "NONE") ? 12'hFFF : 12'h001; wire [DQS_CNT_WIDTH+2:0]prbs_dqs_cnt_timing; reg [DQS_CNT_WIDTH+2:0] prbs_dqs_cnt_timing_r; reg [DQS_CNT_WIDTH:0] prbs_dqs_cnt_r; reg prbs_prech_req_r; reg [5:0] prbs_state_r; reg [5:0] prbs_state_r1; reg wait_state_cnt_en_r; reg [3:0] wait_state_cnt_r; reg cnt_wait_state; reg found_edge_r; reg prbs_found_1st_edge_r; reg prbs_found_2nd_edge_r; reg [5:0] prbs_1st_edge_taps_r; reg found_stable_eye_r; reg [5:0] prbs_dqs_tap_cnt_r; reg [5:0] prbs_dec_tap_calc_plus_3; reg [5:0] prbs_dec_tap_calc_minus_3; reg prbs_dqs_tap_limit_r; reg [5:0] prbs_inc_tap_cnt; reg [5:0] prbs_dec_tap_cnt; reg [DRAM_WIDTH-1:0] mux_rd_fall0_r1; reg [DRAM_WIDTH-1:0] mux_rd_fall1_r1; reg [DRAM_WIDTH-1:0] mux_rd_rise0_r1; reg [DRAM_WIDTH-1:0] mux_rd_rise1_r1; reg [DRAM_WIDTH-1:0] mux_rd_fall2_r1; reg [DRAM_WIDTH-1:0] mux_rd_fall3_r1; reg [DRAM_WIDTH-1:0] mux_rd_rise2_r1; reg [DRAM_WIDTH-1:0] mux_rd_rise3_r1; reg [DRAM_WIDTH-1:0] mux_rd_fall0_r2; reg [DRAM_WIDTH-1:0] mux_rd_fall1_r2; reg [DRAM_WIDTH-1:0] mux_rd_rise0_r2; reg [DRAM_WIDTH-1:0] mux_rd_rise1_r2; reg [DRAM_WIDTH-1:0] mux_rd_fall2_r2; reg [DRAM_WIDTH-1:0] mux_rd_fall3_r2; reg [DRAM_WIDTH-1:0] mux_rd_rise2_r2; reg [DRAM_WIDTH-1:0] mux_rd_rise3_r2; reg mux_rd_valid_r; reg rd_valid_r1; reg rd_valid_r2; reg rd_valid_r3; reg new_cnt_dqs_r; reg prbs_tap_en_r; reg prbs_tap_inc_r; reg pi_en_stg2_f_timing; reg pi_stg2_f_incdec_timing; wire [DQ_WIDTH-1:0] rd_data_rise0; wire [DQ_WIDTH-1:0] rd_data_fall0; wire [DQ_WIDTH-1:0] rd_data_rise1; wire [DQ_WIDTH-1:0] rd_data_fall1; wire [DQ_WIDTH-1:0] rd_data_rise2; wire [DQ_WIDTH-1:0] rd_data_fall2; wire [DQ_WIDTH-1:0] rd_data_rise3; wire [DQ_WIDTH-1:0] rd_data_fall3; wire [PRBS_WIDTH-1:0] compare_data_r0; wire [PRBS_WIDTH-1:0] compare_data_f0; wire [PRBS_WIDTH-1:0] compare_data_r1; wire [PRBS_WIDTH-1:0] compare_data_f1; wire [PRBS_WIDTH-1:0] compare_data_r2; wire [PRBS_WIDTH-1:0] compare_data_f2; wire [PRBS_WIDTH-1:0] compare_data_r3; wire [PRBS_WIDTH-1:0] compare_data_f3; reg [DQS_CNT_WIDTH:0] rd_mux_sel_r; reg [5:0] prbs_2nd_edge_taps_r; reg [6*DQS_WIDTH*RANKS-1:0] prbs_final_dqs_tap_cnt_r; reg [1:0] rnk_cnt_r; reg [5:0] rdlvl_cpt_tap_cnt; reg prbs_rdlvl_start_r; reg compare_err; reg compare_err_r0; reg compare_err_f0; reg compare_err_r1; reg compare_err_f1; reg compare_err_r2; reg compare_err_f2; reg compare_err_r3; reg compare_err_f3; reg samples_cnt1_en_r; reg samples_cnt2_en_r; reg [11:0] samples_cnt_r; reg num_samples_done_r; reg [DQS_WIDTH-1:0] prbs_tap_mod; //************************************************************************** // DQS count to hard PHY during write calibration using Phaser_OUT Stage2 // coarse delay //************************************************************************** // assign pi_stg2_prbs_rdlvl_cnt = prbs_dqs_cnt_r; // assign dbg_prbs_rdlvl = {prbs_tap_mod, prbs_2nd_edge_taps_r, prbs_1st_edge_taps_r, rdlvl_cpt_tap_cnt, prbs_dqs_cnt_r, // prbs_rdlvl_done, prbs_rdlvl_start, phy_if_empty, compare_err, prbs_found_2nd_edge_r, prbs_found_1st_edge_r, prbs_dqs_tap_cnt_r, pi_counter_read_val, // mux_rd_fall3_r2, mux_rd_rise3_r2, mux_rd_fall2_r2, mux_rd_rise2_r2, mux_rd_fall1_r2, mux_rd_rise1_r2, mux_rd_fall0_r2, mux_rd_rise0_r2, // compare_data_f3, compare_data_r3, compare_data_f2, compare_data_r2, compare_data_f1, compare_data_r1, compare_data_f0, compare_data_r0}; assign dbg_prbs_rdlvl[0+:8] = compare_data_r0; assign dbg_prbs_rdlvl[8+:8] = compare_data_f0; assign dbg_prbs_rdlvl[16+:8] = compare_data_r1; assign dbg_prbs_rdlvl[24+:8] = compare_data_f1; assign dbg_prbs_rdlvl[32+:8] = compare_data_r2; assign dbg_prbs_rdlvl[40+:8] = compare_data_f2; assign dbg_prbs_rdlvl[48+:8] = compare_data_r3; assign dbg_prbs_rdlvl[56+:8] = compare_data_f3; assign dbg_prbs_rdlvl[64+:8] = mux_rd_rise0_r2; assign dbg_prbs_rdlvl[72+:8] = mux_rd_fall0_r2; assign dbg_prbs_rdlvl[80+:8] = mux_rd_rise1_r2; assign dbg_prbs_rdlvl[88+:8] = mux_rd_fall1_r2; assign dbg_prbs_rdlvl[96+:8] = mux_rd_rise2_r2; assign dbg_prbs_rdlvl[104+:8] = mux_rd_fall2_r2; assign dbg_prbs_rdlvl[112+:8] = mux_rd_rise3_r2; assign dbg_prbs_rdlvl[120+:8] = mux_rd_fall3_r2; assign dbg_prbs_rdlvl[128+:6] = pi_counter_read_val; assign dbg_prbs_rdlvl[134+:6] = prbs_dqs_tap_cnt_r; assign dbg_prbs_rdlvl[140] = prbs_found_1st_edge_r; assign dbg_prbs_rdlvl[141] = prbs_found_2nd_edge_r; assign dbg_prbs_rdlvl[142] = compare_err; assign dbg_prbs_rdlvl[143] = phy_if_empty; assign dbg_prbs_rdlvl[144] = prbs_rdlvl_start; assign dbg_prbs_rdlvl[145] = prbs_rdlvl_done; assign dbg_prbs_rdlvl[146+:5] = prbs_dqs_cnt_r; assign dbg_prbs_rdlvl[151+:6] = rdlvl_cpt_tap_cnt; assign dbg_prbs_rdlvl[157+:6] = prbs_1st_edge_taps_r; assign dbg_prbs_rdlvl[163+:6] = prbs_2nd_edge_taps_r; assign dbg_prbs_rdlvl[169+:9] = prbs_tap_mod; assign dbg_prbs_rdlvl[255:178]= 'b0;//reserved //*************************************************************************** //*************************************************************************** // Data mux to route appropriate bit to calibration logic - i.e. calibration // is done sequentially, one bit (or DQS group) at a time //*************************************************************************** generate if (nCK_PER_CLK == 4) begin: rd_data_div4_logic_clk assign rd_data_rise0 = rd_data[DQ_WIDTH-1:0]; assign rd_data_fall0 = rd_data[2*DQ_WIDTH-1:DQ_WIDTH]; assign rd_data_rise1 = rd_data[3*DQ_WIDTH-1:2*DQ_WIDTH]; assign rd_data_fall1 = rd_data[4*DQ_WIDTH-1:3*DQ_WIDTH]; assign rd_data_rise2 = rd_data[5*DQ_WIDTH-1:4*DQ_WIDTH]; assign rd_data_fall2 = rd_data[6*DQ_WIDTH-1:5*DQ_WIDTH]; assign rd_data_rise3 = rd_data[7*DQ_WIDTH-1:6*DQ_WIDTH]; assign rd_data_fall3 = rd_data[8*DQ_WIDTH-1:7*DQ_WIDTH]; assign compare_data_r0 = compare_data[PRBS_WIDTH-1:0]; assign compare_data_f0 = compare_data[2*PRBS_WIDTH-1:PRBS_WIDTH]; assign compare_data_r1 = compare_data[3*PRBS_WIDTH-1:2*PRBS_WIDTH]; assign compare_data_f1 = compare_data[4*PRBS_WIDTH-1:3*PRBS_WIDTH]; assign compare_data_r2 = compare_data[5*PRBS_WIDTH-1:4*PRBS_WIDTH]; assign compare_data_f2 = compare_data[6*PRBS_WIDTH-1:5*PRBS_WIDTH]; assign compare_data_r3 = compare_data[7*PRBS_WIDTH-1:6*PRBS_WIDTH]; assign compare_data_f3 = compare_data[8*PRBS_WIDTH-1:7*PRBS_WIDTH]; end else begin: rd_data_div2_logic_clk assign rd_data_rise0 = rd_data[DQ_WIDTH-1:0]; assign rd_data_fall0 = rd_data[2*DQ_WIDTH-1:DQ_WIDTH]; assign rd_data_rise1 = rd_data[3*DQ_WIDTH-1:2*DQ_WIDTH]; assign rd_data_fall1 = rd_data[4*DQ_WIDTH-1:3*DQ_WIDTH]; assign compare_data_r0 = compare_data[PRBS_WIDTH-1:0]; assign compare_data_f0 = compare_data[2*PRBS_WIDTH-1:PRBS_WIDTH]; assign compare_data_r1 = compare_data[3*PRBS_WIDTH-1:2*PRBS_WIDTH]; assign compare_data_f1 = compare_data[4*PRBS_WIDTH-1:3*PRBS_WIDTH]; end endgenerate always @(posedge clk) begin rd_mux_sel_r <= #TCQ prbs_dqs_cnt_r; end // Register outputs for improved timing. // NOTE: Will need to change when per-bit DQ deskew is supported. // Currenly all bits in DQS group are checked in aggregate generate genvar mux_i; for (mux_i = 0; mux_i < DRAM_WIDTH; mux_i = mux_i + 1) begin: gen_mux_rd always @(posedge clk) begin mux_rd_rise0_r1[mux_i] <= #TCQ rd_data_rise0[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall0_r1[mux_i] <= #TCQ rd_data_fall0[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_rise1_r1[mux_i] <= #TCQ rd_data_rise1[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall1_r1[mux_i] <= #TCQ rd_data_fall1[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_rise2_r1[mux_i] <= #TCQ rd_data_rise2[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall2_r1[mux_i] <= #TCQ rd_data_fall2[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_rise3_r1[mux_i] <= #TCQ rd_data_rise3[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall3_r1[mux_i] <= #TCQ rd_data_fall3[DRAM_WIDTH*rd_mux_sel_r + mux_i]; end end endgenerate generate genvar muxr2_i; if (nCK_PER_CLK == 4) begin: gen_mux_div4 for (muxr2_i = 0; muxr2_i < DRAM_WIDTH; muxr2_i = muxr2_i + 1) begin: gen_rd_4 always @(posedge clk) begin if (mux_rd_valid_r) begin mux_rd_rise0_r2[muxr2_i] <= #TCQ mux_rd_rise0_r1[muxr2_i]; mux_rd_fall0_r2[muxr2_i] <= #TCQ mux_rd_fall0_r1[muxr2_i]; mux_rd_rise1_r2[muxr2_i] <= #TCQ mux_rd_rise1_r1[muxr2_i]; mux_rd_fall1_r2[muxr2_i] <= #TCQ mux_rd_fall1_r1[muxr2_i]; mux_rd_rise2_r2[muxr2_i] <= #TCQ mux_rd_rise2_r1[muxr2_i]; mux_rd_fall2_r2[muxr2_i] <= #TCQ mux_rd_fall2_r1[muxr2_i]; mux_rd_rise3_r2[muxr2_i] <= #TCQ mux_rd_rise3_r1[muxr2_i]; mux_rd_fall3_r2[muxr2_i] <= #TCQ mux_rd_fall3_r1[muxr2_i]; end end end end else if (nCK_PER_CLK == 2) begin: gen_mux_div2 for (muxr2_i = 0; muxr2_i < DRAM_WIDTH; muxr2_i = muxr2_i + 1) begin: gen_rd_2 always @(posedge clk) begin if (mux_rd_valid_r) begin mux_rd_rise0_r2[muxr2_i] <= #TCQ mux_rd_rise0_r1[muxr2_i]; mux_rd_fall0_r2[muxr2_i] <= #TCQ mux_rd_fall0_r1[muxr2_i]; mux_rd_rise1_r2[muxr2_i] <= #TCQ mux_rd_rise1_r1[muxr2_i]; mux_rd_fall1_r2[muxr2_i] <= #TCQ mux_rd_fall1_r1[muxr2_i]; end end end end endgenerate // Registered signal indicates when mux_rd_rise/fall_r is valid always @(posedge clk) begin mux_rd_valid_r <= #TCQ ~phy_if_empty && prbs_rdlvl_start; rd_valid_r1 <= #TCQ mux_rd_valid_r; rd_valid_r2 <= #TCQ rd_valid_r1; end // Counter counts # of samples compared // Reset sample counter when not "sampling" // Otherwise, count # of samples compared // Same counter is shared for three samples checked always @(posedge clk) if (rst) samples_cnt_r <= #TCQ 'b0; else begin if (!rd_valid_r1 || (prbs_state_r == PRBS_DEC_DQS_WAIT) || (prbs_state_r == PRBS_INC_DQS_WAIT) || (prbs_state_r == PRBS_DEC_DQS) || (prbs_state_r == PRBS_INC_DQS) || (samples_cnt_r == NUM_SAMPLES_CNT) || (samples_cnt_r == NUM_SAMPLES_CNT1)) samples_cnt_r <= #TCQ 'b0; else if (rd_valid_r1 && (((samples_cnt_r < NUM_SAMPLES_CNT) && ~samples_cnt1_en_r) || ((samples_cnt_r < NUM_SAMPLES_CNT1) && ~samples_cnt2_en_r) || ((samples_cnt_r < NUM_SAMPLES_CNT2) && samples_cnt2_en_r))) samples_cnt_r <= #TCQ samples_cnt_r + 1; end // Count #2 enable generation // Assert when correct number of samples compared always @(posedge clk) if (rst) samples_cnt1_en_r <= #TCQ 1'b0; else begin if ((prbs_state_r == PRBS_IDLE) || (prbs_state_r == PRBS_DEC_DQS) || (prbs_state_r == PRBS_INC_DQS) || (prbs_state_r == PRBS_NEW_DQS_PREWAIT)) samples_cnt1_en_r <= #TCQ 1'b0; else if ((samples_cnt_r == NUM_SAMPLES_CNT) && rd_valid_r1) samples_cnt1_en_r <= #TCQ 1'b1; end // Counter #3 enable generation // Assert when correct number of samples compared always @(posedge clk) if (rst) samples_cnt2_en_r <= #TCQ 1'b0; else begin if ((prbs_state_r == PRBS_IDLE) || (prbs_state_r == PRBS_DEC_DQS) || (prbs_state_r == PRBS_INC_DQS) || (prbs_state_r == PRBS_NEW_DQS_PREWAIT)) samples_cnt2_en_r <= #TCQ 1'b0; else if ((samples_cnt_r == NUM_SAMPLES_CNT1) && rd_valid_r1 && samples_cnt1_en_r) samples_cnt2_en_r <= #TCQ 1'b1; end // Assert when all the three sample counts are done always @(posedge clk) if (rst) num_samples_done_r <= #TCQ 1'b0; else begin if (!rd_valid_r1 || (prbs_state_r == PRBS_DEC_DQS) || (prbs_state_r == PRBS_INC_DQS)) num_samples_done_r <= #TCQ 'b0; else begin if ((samples_cnt_r == NUM_SAMPLES_CNT2-1) && samples_cnt2_en_r) num_samples_done_r <= #TCQ 1'b1; end end //*************************************************************************** // Compare Read Data for the byte being Leveled with Expected data from PRBS // generator. Resulting compare_err signal used to determine read data valid // edge. //*************************************************************************** generate if (nCK_PER_CLK == 4) begin: cmp_err_4to1 always @ (posedge clk) begin if (rst || new_cnt_dqs_r) begin compare_err <= #TCQ 1'b0; compare_err_r0 <= #TCQ 1'b0; compare_err_f0 <= #TCQ 1'b0; compare_err_r1 <= #TCQ 1'b0; compare_err_f1 <= #TCQ 1'b0; compare_err_r2 <= #TCQ 1'b0; compare_err_f2 <= #TCQ 1'b0; compare_err_r3 <= #TCQ 1'b0; compare_err_f3 <= #TCQ 1'b0; end else if (rd_valid_r1) begin compare_err_r0 <= #TCQ (mux_rd_rise0_r2 != compare_data_r0); compare_err_f0 <= #TCQ (mux_rd_fall0_r2 != compare_data_f0); compare_err_r1 <= #TCQ (mux_rd_rise1_r2 != compare_data_r1); compare_err_f1 <= #TCQ (mux_rd_fall1_r2 != compare_data_f1); compare_err_r2 <= #TCQ (mux_rd_rise2_r2 != compare_data_r2); compare_err_f2 <= #TCQ (mux_rd_fall2_r2 != compare_data_f2); compare_err_r3 <= #TCQ (mux_rd_rise3_r2 != compare_data_r3); compare_err_f3 <= #TCQ (mux_rd_fall3_r2 != compare_data_f3); compare_err <= #TCQ (compare_err_r0 | compare_err_f0 | compare_err_r1 | compare_err_f1 | compare_err_r2 | compare_err_f2 | compare_err_r3 | compare_err_f3); end end end else begin: cmp_err_2to1 always @ (posedge clk) begin if (rst || new_cnt_dqs_r) begin compare_err <= #TCQ 1'b0; compare_err_r0 <= #TCQ 1'b0; compare_err_f0 <= #TCQ 1'b0; compare_err_r1 <= #TCQ 1'b0; compare_err_f1 <= #TCQ 1'b0; end else if (rd_valid_r1) begin compare_err_r0 <= #TCQ (mux_rd_rise0_r2 != compare_data_r0); compare_err_f0 <= #TCQ (mux_rd_fall0_r2 != compare_data_f0); compare_err_r1 <= #TCQ (mux_rd_rise1_r2 != compare_data_r1); compare_err_f1 <= #TCQ (mux_rd_fall1_r2 != compare_data_f1); compare_err <= #TCQ (compare_err_r0 | compare_err_f0 | compare_err_r1 | compare_err_f1); end end end endgenerate //*************************************************************************** // Decrement initial Phaser_IN fine delay value before proceeding with // read calibration //*************************************************************************** //*************************************************************************** // Demultiplexor to control Phaser_IN delay values //*************************************************************************** // Read DQS always @(posedge clk) begin if (rst) begin pi_en_stg2_f_timing <= #TCQ 'b0; pi_stg2_f_incdec_timing <= #TCQ 'b0; end else if (prbs_tap_en_r) begin // Change only specified DQS pi_en_stg2_f_timing <= #TCQ 1'b1; pi_stg2_f_incdec_timing <= #TCQ prbs_tap_inc_r; end else begin pi_en_stg2_f_timing <= #TCQ 'b0; pi_stg2_f_incdec_timing <= #TCQ 'b0; end end // registered for timing always @(posedge clk) begin pi_en_stg2_f <= #TCQ pi_en_stg2_f_timing; pi_stg2_f_incdec <= #TCQ pi_stg2_f_incdec_timing; end //*************************************************************************** // generate request to PHY_INIT logic to issue precharged. Required when // calibration can take a long time (during which there are only constant // reads present on this bus). In this case need to issue perioidic // precharges to avoid tRAS violation. This signal must meet the following // requirements: (1) only transition from 0->1 when prech is first needed, // (2) stay at 1 and only transition 1->0 when RDLVL_PRECH_DONE asserted //*************************************************************************** always @(posedge clk) if (rst) prbs_rdlvl_prech_req <= #TCQ 1'b0; else prbs_rdlvl_prech_req <= #TCQ prbs_prech_req_r; //***************************************************************** // keep track of edge tap counts found, and current capture clock // tap count //***************************************************************** always @(posedge clk) if (rst) begin prbs_dqs_tap_cnt_r <= #TCQ 'b0; rdlvl_cpt_tap_cnt <= #TCQ 'b0; end else if (new_cnt_dqs_r) begin prbs_dqs_tap_cnt_r <= #TCQ pi_counter_read_val; rdlvl_cpt_tap_cnt <= #TCQ pi_counter_read_val; end else if (prbs_tap_en_r) begin if (prbs_tap_inc_r) prbs_dqs_tap_cnt_r <= #TCQ prbs_dqs_tap_cnt_r + 1; else if (prbs_dqs_tap_cnt_r != 'd0) prbs_dqs_tap_cnt_r <= #TCQ prbs_dqs_tap_cnt_r - 1; end always @(posedge clk) if (rst) begin prbs_dec_tap_calc_plus_3 <= #TCQ 'b0; prbs_dec_tap_calc_minus_3 <= #TCQ 'b0; end else if (new_cnt_dqs_r) begin prbs_dec_tap_calc_plus_3 <= #TCQ 'b000011; prbs_dec_tap_calc_minus_3 <= #TCQ 'b111100; end else begin prbs_dec_tap_calc_plus_3 <= #TCQ (prbs_dqs_tap_cnt_r - rdlvl_cpt_tap_cnt + 3); prbs_dec_tap_calc_minus_3 <= #TCQ (prbs_dqs_tap_cnt_r - rdlvl_cpt_tap_cnt - 3); end always @(posedge clk) if (rst || new_cnt_dqs_r) prbs_dqs_tap_limit_r <= #TCQ 1'b0; else if (prbs_dqs_tap_cnt_r == 6'd63) prbs_dqs_tap_limit_r <= #TCQ 1'b1; // Temp wire for timing. // The following in the always block below causes timing issues // due to DSP block inference // 6*prbs_dqs_cnt_r. // replacing this with two left shifts + one left shift to avoid // DSP multiplier. assign prbs_dqs_cnt_timing = {2'd0, prbs_dqs_cnt_r}; always @(posedge clk) prbs_dqs_cnt_timing_r <= #TCQ prbs_dqs_cnt_timing; // Storing DQS tap values at the end of each DQS read leveling always @(posedge clk) begin if (rst) begin prbs_final_dqs_tap_cnt_r <= #TCQ 'b0; end else if ((prbs_state_r == PRBS_NEXT_DQS) && (prbs_state_r1 != PRBS_NEXT_DQS)) begin prbs_final_dqs_tap_cnt_r[(((prbs_dqs_cnt_timing_r <<2) + (prbs_dqs_cnt_timing_r <<1)) +(rnk_cnt_r*DQS_WIDTH*6))+:6] <= #TCQ prbs_dqs_tap_cnt_r; end end //***************************************************************** always @(posedge clk) begin prbs_state_r1 <= #TCQ prbs_state_r; prbs_rdlvl_start_r <= #TCQ prbs_rdlvl_start; end // Wait counter for wait states always @(posedge clk) if ((prbs_state_r == PRBS_NEW_DQS_WAIT) || (prbs_state_r == PRBS_INC_DQS_WAIT) || (prbs_state_r == PRBS_DEC_DQS_WAIT) || (prbs_state_r == PRBS_NEW_DQS_PREWAIT)) wait_state_cnt_en_r <= #TCQ 1'b1; else wait_state_cnt_en_r <= #TCQ 1'b0; always @(posedge clk) if (!wait_state_cnt_en_r) begin wait_state_cnt_r <= #TCQ 'b0; cnt_wait_state <= #TCQ 1'b0; end else begin if (wait_state_cnt_r < 'd15) begin wait_state_cnt_r <= #TCQ wait_state_cnt_r + 1; cnt_wait_state <= #TCQ 1'b0; end else begin // Need to reset to 0 to handle the case when there are two // different WAIT states back-to-back wait_state_cnt_r <= #TCQ 'b0; cnt_wait_state <= #TCQ 1'b1; end end //***************************************************************** // PRBS Read Level State Machine //***************************************************************** always @(posedge clk) if (rst) begin prbs_dqs_cnt_r <= #TCQ 'b0; prbs_tap_en_r <= #TCQ 1'b0; prbs_tap_inc_r <= #TCQ 1'b0; prbs_prech_req_r <= #TCQ 1'b0; prbs_state_r <= #TCQ PRBS_IDLE; prbs_found_1st_edge_r <= #TCQ 1'b0; prbs_found_2nd_edge_r <= #TCQ 1'b0; prbs_1st_edge_taps_r <= #TCQ 6'bxxxxxx; prbs_inc_tap_cnt <= #TCQ 'b0; prbs_dec_tap_cnt <= #TCQ 'b0; new_cnt_dqs_r <= #TCQ 1'b0; if (SIM_CAL_OPTION == "FAST_CAL") prbs_rdlvl_done <= #TCQ 1'b1; else prbs_rdlvl_done <= #TCQ 1'b0; prbs_2nd_edge_taps_r <= #TCQ 6'bxxxxxx; prbs_last_byte_done <= #TCQ 1'b0; rnk_cnt_r <= #TCQ 2'b00; prbs_tap_mod <= #TCQ 'd0; end else begin case (prbs_state_r) PRBS_IDLE: begin prbs_last_byte_done <= #TCQ 1'b0; prbs_prech_req_r <= #TCQ 1'b0; if (prbs_rdlvl_start && ~prbs_rdlvl_start_r) begin if (SIM_CAL_OPTION == "SKIP_CAL") prbs_state_r <= #TCQ PRBS_DONE; else begin new_cnt_dqs_r <= #TCQ 1'b1; prbs_state_r <= #TCQ PRBS_NEW_DQS_WAIT; end end end // Wait for the new DQS group to change // also gives time for the read data IN_FIFO to // output the updated data for the new DQS group PRBS_NEW_DQS_WAIT: begin prbs_last_byte_done <= #TCQ 1'b0; prbs_prech_req_r <= #TCQ 1'b0; if (cnt_wait_state) begin new_cnt_dqs_r <= #TCQ 1'b0; prbs_state_r <= #TCQ PRBS_PAT_COMPARE; end end // Check for presence of data eye edge. During this state, we // sample the read data multiple times, and look for changes // in the read data, specifically: // 1. A change in the read data compared with the value of // read data from the previous delay tap. This indicates // that the most recent tap delay increment has moved us // into either a new window, or moved/kept us in the // transition/jitter region between windows. Note that this // condition only needs to be checked for once, and for // logistical purposes, we check this soon after entering // this state (see comment in PRBS_PAT_COMPARE below for // why this is done) // 2. A change in the read data while we are in this state // (i.e. in the absence of a tap delay increment). This // indicates that we're close enough to a window edge that // jitter will cause the read data to change even in the // absence of a tap delay change PRBS_PAT_COMPARE: begin // Continue to sample read data and look for edges until the // appropriate time interval (shorter for simulation-only, // much, much longer for actual h/w) has elapsed if (num_samples_done_r || compare_err) begin if (prbs_dqs_tap_limit_r) // Only one edge detected and ran out of taps since only one // bit time worth of taps available for window detection. This // can happen if at tap 0 DQS is in previous window which results // in only left edge being detected. Or at tap 0 DQS is in the // current window resulting in only right edge being detected. // Depending on the frequency this case can also happen if at // tap 0 DQS is in the left noise region resulting in only left // edge being detected. prbs_state_r <= #TCQ PRBS_CALC_TAPS; else if (compare_err || (prbs_dqs_tap_cnt_r == 'd0)) begin // Sticky bit - asserted after we encounter an edge, although // the current edge may not be considered the "first edge" this // just means we found at least one edge prbs_found_1st_edge_r <= #TCQ 1'b1; // Both edges of data valid window found: // If we've found a second edge after a region of stability // then we must have just passed the second ("right" edge of // the window. Record this second_edge_taps = current tap-1, // because we're one past the actual second edge tap, where // the edge taps represent the extremes of the data valid // window (i.e. smallest & largest taps where data still valid if (prbs_found_1st_edge_r) begin prbs_found_2nd_edge_r <= #TCQ 1'b1; prbs_2nd_edge_taps_r <= #TCQ prbs_dqs_tap_cnt_r - 1; prbs_state_r <= #TCQ PRBS_CALC_TAPS; end else begin // Otherwise, an edge was found (just not the "second" edge) // Assuming DQS is in the correct window at tap 0 of Phaser IN // fine tap. The first edge found is the right edge of the valid // window and is the beginning of the jitter region hence done! if (compare_err) prbs_1st_edge_taps_r <= #TCQ prbs_dqs_tap_cnt_r + 1; else prbs_1st_edge_taps_r <= #TCQ 'd0; prbs_inc_tap_cnt <= #TCQ rdlvl_cpt_tap_cnt - prbs_dqs_tap_cnt_r; prbs_state_r <= #TCQ PRBS_INC_DQS; end end else begin // Otherwise, if we haven't found an edge.... // If we still have taps left to use, then keep incrementing if (prbs_found_1st_edge_r) prbs_state_r <= #TCQ PRBS_INC_DQS; else prbs_state_r <= #TCQ PRBS_DEC_DQS; end end end // Increment Phaser_IN delay for DQS PRBS_INC_DQS: begin prbs_state_r <= #TCQ PRBS_INC_DQS_WAIT; if (prbs_inc_tap_cnt > 'd0) prbs_inc_tap_cnt <= #TCQ prbs_inc_tap_cnt - 1; if (~prbs_dqs_tap_limit_r) begin prbs_tap_en_r <= #TCQ 1'b1; prbs_tap_inc_r <= #TCQ 1'b1; end else begin prbs_tap_en_r <= #TCQ 1'b0; prbs_tap_inc_r <= #TCQ 1'b0; end end // Wait for Phaser_In to settle, before checking again for an edge PRBS_INC_DQS_WAIT: begin prbs_tap_en_r <= #TCQ 1'b0; prbs_tap_inc_r <= #TCQ 1'b0; if (cnt_wait_state) begin if (prbs_inc_tap_cnt > 'd0) prbs_state_r <= #TCQ PRBS_INC_DQS; else prbs_state_r <= #TCQ PRBS_PAT_COMPARE; end end // Calculate final value of Phaser_IN taps. At this point, one or both // edges of data eye have been found, and/or all taps have been // exhausted looking for the edges // NOTE: The amount to be decrement by is calculated, not the // absolute setting for DQS. PRBS_CALC_TAPS: begin if (prbs_found_2nd_edge_r && prbs_found_1st_edge_r) // Both edges detected prbs_dec_tap_cnt <= #TCQ ((prbs_2nd_edge_taps_r - prbs_1st_edge_taps_r)>>1) + 1; else if (~prbs_found_2nd_edge_r && prbs_found_1st_edge_r) // Only left edge detected prbs_dec_tap_cnt <= #TCQ ((prbs_dqs_tap_cnt_r - prbs_1st_edge_taps_r)>>1); else // No edges detected prbs_dec_tap_cnt <= #TCQ (prbs_dqs_tap_cnt_r>>1); // Now use the value we just calculated to decrement CPT taps // to the desired calibration point prbs_state_r <= #TCQ PRBS_TAP_CHECK; //PRBS_DEC_DQS; end PRBS_TAP_CHECK: begin // Fix for CR690798 - limit PRBS tap to +/- 3 taps of rdlvl_cpt_tap_cnt if (prbs_dec_tap_calc_minus_3 > prbs_dec_tap_cnt) begin // proposing a re-order of the condition prbs_tap_mod[prbs_dqs_cnt_timing_r] <= #TCQ 1'b1; prbs_dec_tap_cnt <= #TCQ prbs_dec_tap_calc_minus_3; end else if (prbs_dec_tap_calc_plus_3 < prbs_dec_tap_cnt) begin // proposing a re-order of the condition prbs_tap_mod[prbs_dqs_cnt_timing_r] <= #TCQ 1'b1; prbs_dec_tap_cnt <= #TCQ prbs_dec_tap_calc_plus_3; end prbs_state_r <= #TCQ PRBS_DEC_DQS; end // decrement capture clock for final adjustment - center // capture clock in middle of data eye. This adjustment will occur // only when both the edges are found usign CPT taps. Must do this // incrementally to avoid clock glitching (since CPT drives clock // divider within each ISERDES) PRBS_DEC_DQS: begin prbs_tap_en_r <= #TCQ 1'b1; prbs_tap_inc_r <= #TCQ 1'b0; // once adjustment is complete, we're done with calibration for // this DQS, repeat for next DQS if (prbs_dec_tap_cnt > 'd0) prbs_dec_tap_cnt <= #TCQ prbs_dec_tap_cnt - 1; if (prbs_dec_tap_cnt == 6'b000001) prbs_state_r <= #TCQ PRBS_NEXT_DQS; else prbs_state_r <= #TCQ PRBS_DEC_DQS_WAIT; end PRBS_DEC_DQS_WAIT: begin prbs_tap_en_r <= #TCQ 1'b0; prbs_tap_inc_r <= #TCQ 1'b0; if (cnt_wait_state) begin if (prbs_dec_tap_cnt > 'd0) prbs_state_r <= #TCQ PRBS_DEC_DQS; else prbs_state_r <= #TCQ PRBS_PAT_COMPARE; end end // Determine whether we're done, or have more DQS's to calibrate // Also request precharge after every byte, as appropriate PRBS_NEXT_DQS: begin prbs_prech_req_r <= #TCQ 1'b1; prbs_tap_en_r <= #TCQ 1'b0; prbs_tap_inc_r <= #TCQ 1'b0; // Prepare for another iteration with next DQS group prbs_found_1st_edge_r <= #TCQ 1'b0; prbs_found_2nd_edge_r <= #TCQ 1'b0; prbs_1st_edge_taps_r <= #TCQ 'd0; prbs_2nd_edge_taps_r <= #TCQ 'd0; if (prbs_dqs_cnt_r >= DQS_WIDTH-1) begin prbs_last_byte_done <= #TCQ 1'b1; end // Wait until precharge that occurs in between calibration of // DQS groups is finished if (prech_done) begin prbs_prech_req_r <= #TCQ 1'b0; if (prbs_dqs_cnt_r >= DQS_WIDTH-1) begin if (rnk_cnt_r == RANKS-1) begin // All DQS groups in all ranks done prbs_state_r <= #TCQ PRBS_DONE; end else begin // Process DQS groups in next rank rnk_cnt_r <= #TCQ rnk_cnt_r + 1; new_cnt_dqs_r <= #TCQ 1'b1; prbs_dqs_cnt_r <= #TCQ 'b0; prbs_state_r <= #TCQ PRBS_IDLE; end end else begin // Process next DQS group new_cnt_dqs_r <= #TCQ 1'b1; prbs_dqs_cnt_r <= #TCQ prbs_dqs_cnt_r + 1; prbs_state_r <= #TCQ PRBS_NEW_DQS_PREWAIT; end end end PRBS_NEW_DQS_PREWAIT: begin if (cnt_wait_state) begin prbs_state_r <= #TCQ PRBS_NEW_DQS_WAIT; end end // Done with this stage of calibration PRBS_DONE: begin prbs_prech_req_r <= #TCQ 1'b0; prbs_last_byte_done <= #TCQ 1'b0; prbs_rdlvl_done <= #TCQ 1'b1; end endcase end endmodule
/***************************************************************** -- (c) Copyright 2011 - 2013 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). A Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. // // // Owner: Gary Martin // Revision: $Id: //depot/icm/proj/common/head/rtl/v32_cmt/rtl/phy/byte_group_io.v#4 $ // $Author: $ // $DateTime: $ // $Change: $ // Description: // This verilog file is a paramertizable I/O termination for // the single byte lane. // to create a N byte-lane wide phy. // // History: // Date Engineer Description // 04/01/2010 G. Martin Initial Checkin. // ////////////////////////////////////////////////////////////////// *****************************************************************/ `timescale 1ps/1ps module mig_7series_v1_9_ddr_byte_group_io #( // bit lane existance parameter BITLANES = 12'b1111_1111_1111, parameter BITLANES_OUTONLY = 12'b0000_0000_0000, parameter PO_DATA_CTL = "FALSE", parameter OSERDES_DATA_RATE = "DDR", parameter OSERDES_DATA_WIDTH = 4, parameter IDELAYE2_IDELAY_TYPE = "VARIABLE", parameter IDELAYE2_IDELAY_VALUE = 00, parameter IODELAY_GRP = "IODELAY_MIG", // local usage only, don't pass down parameter BUS_WIDTH = 12, parameter SYNTHESIS = "FALSE" ) ( input [9:0] mem_dq_in, output [BUS_WIDTH-1:0] mem_dq_out, output [BUS_WIDTH-1:0] mem_dq_ts, input mem_dqs_in, output mem_dqs_out, output mem_dqs_ts, output [(4*10)-1:0] iserdes_dout, // 2 extra 12-bit lanes not used output dqs_to_phaser, input iserdes_clk, input iserdes_clkb, input iserdes_clkdiv, input phy_clk, input rst, input oserdes_rst, input iserdes_rst, input [1:0] oserdes_dqs, input [1:0] oserdes_dqsts, input [(4*BUS_WIDTH)-1:0] oserdes_dq, input [1:0] oserdes_dqts, input oserdes_clk, input oserdes_clk_delayed, input oserdes_clkdiv, input idelay_inc, input idelay_ce, input idelay_ld, input idelayctrl_refclk ); /// INSTANCES localparam ISERDES_DQ_DATA_RATE = "DDR"; localparam ISERDES_DQ_DATA_WIDTH = 4; localparam ISERDES_DQ_DYN_CLKDIV_INV_EN = "FALSE"; localparam ISERDES_DQ_DYN_CLK_INV_EN = "FALSE"; localparam ISERDES_DQ_INIT_Q1 = 1'b0; localparam ISERDES_DQ_INIT_Q2 = 1'b0; localparam ISERDES_DQ_INIT_Q3 = 1'b0; localparam ISERDES_DQ_INIT_Q4 = 1'b0; localparam ISERDES_DQ_INTERFACE_TYPE = "MEMORY_DDR3"; localparam ISERDES_NUM_CE = 2; localparam ISERDES_DQ_IOBDELAY = "IFD"; localparam ISERDES_DQ_OFB_USED = "FALSE"; localparam ISERDES_DQ_SERDES_MODE = "MASTER"; localparam ISERDES_DQ_SRVAL_Q1 = 1'b0; localparam ISERDES_DQ_SRVAL_Q2 = 1'b0; localparam ISERDES_DQ_SRVAL_Q3 = 1'b0; localparam ISERDES_DQ_SRVAL_Q4 = 1'b0; wire [BUS_WIDTH-1:0] data_in_dly; wire [BUS_WIDTH-1:0] oserdes_dq_buf; wire [BUS_WIDTH-1:0] oserdes_dqts_buf; wire oserdes_dqs_buf; wire oserdes_dqsts_buf; wire [9:0] data_in; wire tbyte_out; assign mem_dq_out = oserdes_dq_buf; assign mem_dq_ts = oserdes_dqts_buf; assign data_in = mem_dq_in; assign mem_dqs_out = oserdes_dqs_buf; assign mem_dqs_ts = oserdes_dqsts_buf; assign dqs_to_phaser = mem_dqs_in; reg iserdes_clk_d; always @(*) iserdes_clk_d <= #(025) iserdes_clk; reg idelay_ld_rst; reg rst_r1; reg rst_r2; reg rst_r3; reg rst_r4; always @(posedge phy_clk) begin rst_r1 <= #1 rst; rst_r2 <= #1 rst_r1; rst_r3 <= #1 rst_r2; rst_r4 <= #1 rst_r3; end always @(posedge phy_clk) begin if (rst) idelay_ld_rst <= #1 1'b1; else if (rst_r4) idelay_ld_rst <= #1 1'b0; end genvar i; generate for ( i = 0; i != 10 && PO_DATA_CTL == "TRUE" ; i=i+1) begin : input_ if ( BITLANES[i] && !BITLANES_OUTONLY[i]) begin : iserdes_dq_ ISERDESE2 #( .DATA_RATE ( ISERDES_DQ_DATA_RATE), .DATA_WIDTH ( ISERDES_DQ_DATA_WIDTH), .DYN_CLKDIV_INV_EN ( ISERDES_DQ_DYN_CLKDIV_INV_EN), .DYN_CLK_INV_EN ( ISERDES_DQ_DYN_CLK_INV_EN), .INIT_Q1 ( ISERDES_DQ_INIT_Q1), .INIT_Q2 ( ISERDES_DQ_INIT_Q2), .INIT_Q3 ( ISERDES_DQ_INIT_Q3), .INIT_Q4 ( ISERDES_DQ_INIT_Q4), .INTERFACE_TYPE ( ISERDES_DQ_INTERFACE_TYPE), .NUM_CE ( ISERDES_NUM_CE), .IOBDELAY ( ISERDES_DQ_IOBDELAY), .OFB_USED ( ISERDES_DQ_OFB_USED), .SERDES_MODE ( ISERDES_DQ_SERDES_MODE), .SRVAL_Q1 ( ISERDES_DQ_SRVAL_Q1), .SRVAL_Q2 ( ISERDES_DQ_SRVAL_Q2), .SRVAL_Q3 ( ISERDES_DQ_SRVAL_Q3), .SRVAL_Q4 ( ISERDES_DQ_SRVAL_Q4) ) iserdesdq ( .O (), .Q1 (iserdes_dout[4*i + 3]), .Q2 (iserdes_dout[4*i + 2]), .Q3 (iserdes_dout[4*i + 1]), .Q4 (iserdes_dout[4*i + 0]), .Q5 (), .Q6 (), .SHIFTOUT1 (), .SHIFTOUT2 (), .BITSLIP (1'b0), .CE1 (1'b1), .CE2 (1'b1), .CLK (iserdes_clk_d), .CLKB (!iserdes_clk_d), .CLKDIVP (iserdes_clkdiv), .CLKDIV (), .DDLY (data_in_dly[i]), .D (data_in[i]), // dedicated route to iob for debugging // or as needed, select with IOBDELAY .DYNCLKDIVSEL (1'b0), .DYNCLKSEL (1'b0), // NOTE: OCLK is not used in this design, but is required to meet // a design rule check in map and bitgen. Do not disconnect it. .OCLK (oserdes_clk), .OFB (), .RST (1'b0), // .RST (iserdes_rst), .SHIFTIN1 (1'b0), .SHIFTIN2 (1'b0) ); localparam IDELAYE2_CINVCTRL_SEL = "FALSE"; localparam IDELAYE2_DELAY_SRC = "IDATAIN"; localparam IDELAYE2_HIGH_PERFORMANCE_MODE = "TRUE"; localparam IDELAYE2_PIPE_SEL = "FALSE"; localparam IDELAYE2_ODELAY_TYPE = "FIXED"; localparam IDELAYE2_REFCLK_FREQUENCY = 200.0; localparam IDELAYE2_SIGNAL_PATTERN = "DATA"; (* IODELAY_GROUP = IODELAY_GRP *) IDELAYE2 #( .CINVCTRL_SEL ( IDELAYE2_CINVCTRL_SEL), .DELAY_SRC ( IDELAYE2_DELAY_SRC), .HIGH_PERFORMANCE_MODE ( IDELAYE2_HIGH_PERFORMANCE_MODE), .IDELAY_TYPE ( IDELAYE2_IDELAY_TYPE), .IDELAY_VALUE ( IDELAYE2_IDELAY_VALUE), .PIPE_SEL ( IDELAYE2_PIPE_SEL), .REFCLK_FREQUENCY ( IDELAYE2_REFCLK_FREQUENCY ), .SIGNAL_PATTERN ( IDELAYE2_SIGNAL_PATTERN) ) idelaye2 ( .CNTVALUEOUT (), .DATAOUT (data_in_dly[i]), .C (phy_clk), // automatically wired by ISE .CE (idelay_ce), .CINVCTRL (), .CNTVALUEIN (5'b00000), .DATAIN (1'b0), .IDATAIN (data_in[i]), .INC (idelay_inc), .LD (idelay_ld | idelay_ld_rst), .LDPIPEEN (1'b0), .REGRST (rst) ); end // iserdes_dq else begin assign iserdes_dout[4*i + 3] = 0; assign iserdes_dout[4*i + 2] = 0; assign iserdes_dout[4*i + 1] = 0; assign iserdes_dout[4*i + 0] = 0; end end // input_ endgenerate // iserdes_dq_ localparam OSERDES_DQ_DATA_RATE_OQ = OSERDES_DATA_RATE; localparam OSERDES_DQ_DATA_RATE_TQ = OSERDES_DQ_DATA_RATE_OQ; localparam OSERDES_DQ_DATA_WIDTH = OSERDES_DATA_WIDTH; localparam OSERDES_DQ_INIT_OQ = 1'b1; localparam OSERDES_DQ_INIT_TQ = 1'b1; localparam OSERDES_DQ_INTERFACE_TYPE = "DEFAULT"; localparam OSERDES_DQ_ODELAY_USED = 0; localparam OSERDES_DQ_SERDES_MODE = "MASTER"; localparam OSERDES_DQ_SRVAL_OQ = 1'b1; localparam OSERDES_DQ_SRVAL_TQ = 1'b1; // note: obuf used in control path case, no ts input so width irrelevant localparam OSERDES_DQ_TRISTATE_WIDTH = (OSERDES_DQ_DATA_RATE_OQ == "DDR") ? 4 : 1; localparam OSERDES_DQS_DATA_RATE_OQ = "DDR"; localparam OSERDES_DQS_DATA_RATE_TQ = "DDR"; localparam OSERDES_DQS_TRISTATE_WIDTH = 4; // this is always ddr localparam OSERDES_DQS_DATA_WIDTH = 4; localparam ODDR_CLK_EDGE = "SAME_EDGE"; localparam OSERDES_TBYTE_CTL = "TRUE"; generate localparam NUM_BITLANES = PO_DATA_CTL == "TRUE" ? 10 : BUS_WIDTH; if ( PO_DATA_CTL == "TRUE" ) begin : slave_ts OSERDESE2 #( .DATA_RATE_OQ (OSERDES_DQ_DATA_RATE_OQ), .DATA_RATE_TQ (OSERDES_DQ_DATA_RATE_TQ), .DATA_WIDTH (OSERDES_DQ_DATA_WIDTH), .INIT_OQ (OSERDES_DQ_INIT_OQ), .INIT_TQ (OSERDES_DQ_INIT_TQ), .SERDES_MODE (OSERDES_DQ_SERDES_MODE), .SRVAL_OQ (OSERDES_DQ_SRVAL_OQ), .SRVAL_TQ (OSERDES_DQ_SRVAL_TQ), .TRISTATE_WIDTH (OSERDES_DQ_TRISTATE_WIDTH), .TBYTE_CTL ("TRUE"), .TBYTE_SRC ("TRUE") ) oserdes_slave_ts ( .OFB (), .OQ (), .SHIFTOUT1 (), // not extended .SHIFTOUT2 (), // not extended .TFB (), .TQ (), .CLK (oserdes_clk), .CLKDIV (oserdes_clkdiv), .D1 (), .D2 (), .D3 (), .D4 (), .D5 (), .D6 (), .OCE (1'b1), .RST (oserdes_rst), .SHIFTIN1 (), // not extended .SHIFTIN2 (), // not extended .T1 (oserdes_dqts[0]), .T2 (oserdes_dqts[0]), .T3 (oserdes_dqts[1]), .T4 (oserdes_dqts[1]), .TCE (1'b1), .TBYTEOUT (tbyte_out), .TBYTEIN (tbyte_out) ); end // slave_ts for (i = 0; i != NUM_BITLANES; i=i+1) begin : output_ if ( BITLANES[i]) begin : oserdes_dq_ if ( PO_DATA_CTL == "TRUE" ) begin : ddr OSERDESE2 #( .DATA_RATE_OQ (OSERDES_DQ_DATA_RATE_OQ), .DATA_RATE_TQ (OSERDES_DQ_DATA_RATE_TQ), .DATA_WIDTH (OSERDES_DQ_DATA_WIDTH), .INIT_OQ (OSERDES_DQ_INIT_OQ), .INIT_TQ (OSERDES_DQ_INIT_TQ), .SERDES_MODE (OSERDES_DQ_SERDES_MODE), .SRVAL_OQ (OSERDES_DQ_SRVAL_OQ), .SRVAL_TQ (OSERDES_DQ_SRVAL_TQ), .TRISTATE_WIDTH (OSERDES_DQ_TRISTATE_WIDTH), .TBYTE_CTL (OSERDES_TBYTE_CTL), .TBYTE_SRC ("FALSE") ) oserdes_dq_i ( .OFB (), .OQ (oserdes_dq_buf[i]), .SHIFTOUT1 (), // not extended .SHIFTOUT2 (), // not extended .TFB (), .TQ (oserdes_dqts_buf[i]), .CLK (oserdes_clk), .CLKDIV (oserdes_clkdiv), .D1 (oserdes_dq[4 * i + 0]), .D2 (oserdes_dq[4 * i + 1]), .D3 (oserdes_dq[4 * i + 2]), .D4 (oserdes_dq[4 * i + 3]), .D5 (), .D6 (), .OCE (1'b1), .RST (oserdes_rst), .SHIFTIN1 (), // not extended .SHIFTIN2 (), // not extended .T1 (/*oserdes_dqts[0]*/), .T2 (/*oserdes_dqts[0]*/), .T3 (/*oserdes_dqts[1]*/), .T4 (/*oserdes_dqts[1]*/), .TCE (1'b1), .TBYTEIN (tbyte_out) ); end else begin : sdr OSERDESE2 #( .DATA_RATE_OQ (OSERDES_DQ_DATA_RATE_OQ), .DATA_RATE_TQ (OSERDES_DQ_DATA_RATE_TQ), .DATA_WIDTH (OSERDES_DQ_DATA_WIDTH), .INIT_OQ (1'b0 /*OSERDES_DQ_INIT_OQ*/), .INIT_TQ (OSERDES_DQ_INIT_TQ), .SERDES_MODE (OSERDES_DQ_SERDES_MODE), .SRVAL_OQ (1'b0 /*OSERDES_DQ_SRVAL_OQ*/), .SRVAL_TQ (OSERDES_DQ_SRVAL_TQ), .TRISTATE_WIDTH (OSERDES_DQ_TRISTATE_WIDTH) ) oserdes_dq_i ( .OFB (), .OQ (oserdes_dq_buf[i]), .SHIFTOUT1 (), // not extended .SHIFTOUT2 (), // not extended .TFB (), .TQ (), .CLK (oserdes_clk), .CLKDIV (oserdes_clkdiv), .D1 (oserdes_dq[4 * i + 0]), .D2 (oserdes_dq[4 * i + 1]), .D3 (oserdes_dq[4 * i + 2]), .D4 (oserdes_dq[4 * i + 3]), .D5 (), .D6 (), .OCE (1'b1), .RST (oserdes_rst), .SHIFTIN1 (), // not extended .SHIFTIN2 (), // not extended .T1 (), .T2 (), .T3 (), .T4 (), .TCE (1'b1) ); end // ddr end // oserdes_dq_ end // output_ endgenerate generate if ( PO_DATA_CTL == "TRUE" ) begin : dqs_gen ODDR #(.DDR_CLK_EDGE (ODDR_CLK_EDGE)) oddr_dqs ( .Q (oserdes_dqs_buf), .D1 (oserdes_dqs[0]), .D2 (oserdes_dqs[1]), .C (oserdes_clk_delayed), .R (1'b0), .S (), .CE (1'b1) ); ODDR #(.DDR_CLK_EDGE (ODDR_CLK_EDGE)) oddr_dqsts ( .Q (oserdes_dqsts_buf), .D1 (oserdes_dqsts[0]), .D2 (oserdes_dqsts[0]), .C (oserdes_clk_delayed), .R (), .S (1'b0), .CE (1'b1) ); end // sdr rate else begin:null_dqs end endgenerate endmodule // byte_group_io
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: async_fifo.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Asynchronous capable parameterized FIFO. As with all // traditional FIFOs, the RD_DATA will be valid one cycle following a RD_EN // assertion. RD_EMPTY will remain low until the cycle following the last RD_EN // assertion. Note, that RD_EMPTY may actually be high on the same cycle that // RD_DATA contains valid data. // Author: Matt Jacobsen // History: @mattj: Version 2.0 // Additional Comments: Based on design by CE Cummings in Simulation and // Synthesis Techniques for Asynchronous FIFO Design with Asynchronous Pointer // Comparisons //----------------------------------------------------------------------------- `timescale 1ns/1ns module async_fifo #( parameter C_WIDTH = 32, // Data bus width parameter C_DEPTH = 1024, // Depth of the FIFO // Local parameters parameter C_REAL_DEPTH = 2**clog2(C_DEPTH), parameter C_DEPTH_BITS = clog2(C_REAL_DEPTH), parameter C_DEPTH_P1_BITS = clog2(C_REAL_DEPTH+1) ) ( input RD_CLK, // Read clock input RD_RST, // Read synchronous reset input WR_CLK, // Write clock input WR_RST, // Write synchronous reset input [C_WIDTH-1:0] WR_DATA, // Write data input (WR_CLK) input WR_EN, // Write enable, high active (WR_CLK) output [C_WIDTH-1:0] RD_DATA, // Read data output (RD_CLK) input RD_EN, // Read enable, high active (RD_CLK) output WR_FULL, // Full condition (WR_CLK) output RD_EMPTY // Empty condition (RD_CLK) ); `include "functions.vh" wire wCmpEmpty; wire wCmpFull; wire [C_DEPTH_BITS-1:0] wWrPtr; wire [C_DEPTH_BITS-1:0] wRdPtr; wire [C_DEPTH_BITS-1:0] wWrPtrP1; wire [C_DEPTH_BITS-1:0] wRdPtrP1; // Memory block (synthesis attributes applied to this module will // determine the memory option). ram_2clk_1w_1r #(.C_RAM_WIDTH(C_WIDTH), .C_RAM_DEPTH(C_REAL_DEPTH)) mem ( .CLKA(WR_CLK), .ADDRA(wWrPtr), .WEA(WR_EN & !WR_FULL), .DINA(WR_DATA), .CLKB(RD_CLK), .ADDRB(wRdPtr), .DOUTB(RD_DATA) ); // Compare the pointers. async_cmp #(.C_DEPTH_BITS(C_DEPTH_BITS)) asyncCompare ( .WR_RST(WR_RST), .WR_CLK(WR_CLK), .RD_RST(RD_RST), .RD_CLK(RD_CLK), .RD_VALID(RD_EN & !RD_EMPTY), .WR_VALID(WR_EN & !WR_FULL), .EMPTY(wCmpEmpty), .FULL(wCmpFull), .WR_PTR(wWrPtr), .WR_PTR_P1(wWrPtrP1), .RD_PTR(wRdPtr), .RD_PTR_P1(wRdPtrP1) ); // Calculate empty rd_ptr_empty #(.C_DEPTH_BITS(C_DEPTH_BITS)) rdPtrEmpty ( .RD_EMPTY(RD_EMPTY), .RD_PTR(wRdPtr), .RD_PTR_P1(wRdPtrP1), .CMP_EMPTY(wCmpEmpty), .RD_EN(RD_EN), .RD_CLK(RD_CLK), .RD_RST(RD_RST) ); // Calculate full wr_ptr_full #(.C_DEPTH_BITS(C_DEPTH_BITS)) wrPtrFull ( .WR_CLK(WR_CLK), .WR_RST(WR_RST), .WR_EN(WR_EN), .WR_FULL(WR_FULL), .WR_PTR(wWrPtr), .WR_PTR_P1(wWrPtrP1), .CMP_FULL(wCmpFull) ); endmodule module async_cmp #( parameter C_DEPTH_BITS = 4, // Local parameters parameter N = C_DEPTH_BITS-1 ) ( input WR_RST, input WR_CLK, input RD_RST, input RD_CLK, input RD_VALID, input WR_VALID, output EMPTY, output FULL, input [C_DEPTH_BITS-1:0] WR_PTR, input [C_DEPTH_BITS-1:0] RD_PTR, input [C_DEPTH_BITS-1:0] WR_PTR_P1, input [C_DEPTH_BITS-1:0] RD_PTR_P1 ); reg rDir=0; wire wDirSet = ( (WR_PTR[N]^RD_PTR[N-1]) & ~(WR_PTR[N-1]^RD_PTR[N])); wire wDirClr = ((~(WR_PTR[N]^RD_PTR[N-1]) & (WR_PTR[N-1]^RD_PTR[N])) | WR_RST); reg rRdValid=0; reg rEmpty=1; reg rFull=0; wire wATBEmpty = ((WR_PTR == RD_PTR_P1) && (RD_VALID | rRdValid)); wire wATBFull = ((WR_PTR_P1 == RD_PTR) && WR_VALID); wire wEmpty = ((WR_PTR == RD_PTR) && !rDir); wire wFull = ((WR_PTR == RD_PTR) && rDir); assign EMPTY = wATBEmpty || rEmpty; assign FULL = wATBFull || rFull; always @(posedge wDirSet or posedge wDirClr) if (wDirClr) rDir <= 1'b0; else rDir <= 1'b1; always @(posedge RD_CLK) begin rEmpty <= (RD_RST ? 1'd1 : wEmpty); rRdValid <= (RD_RST ? 1'd0 : RD_VALID); end always @(posedge WR_CLK) begin rFull <= (WR_RST ? 1'd0 : wFull); end endmodule module rd_ptr_empty #( parameter C_DEPTH_BITS = 4 ) ( input RD_CLK, input RD_RST, input RD_EN, output RD_EMPTY, output [C_DEPTH_BITS-1:0] RD_PTR, output [C_DEPTH_BITS-1:0] RD_PTR_P1, input CMP_EMPTY ); reg rEmpty=1; reg rEmpty2=1; reg [C_DEPTH_BITS-1:0] rRdPtr=0; reg [C_DEPTH_BITS-1:0] rRdPtrP1=0; reg [C_DEPTH_BITS-1:0] rBin=0; reg [C_DEPTH_BITS-1:0] rBinP1=1; wire [C_DEPTH_BITS-1:0] wGrayNext; wire [C_DEPTH_BITS-1:0] wGrayNextP1; wire [C_DEPTH_BITS-1:0] wBinNext; wire [C_DEPTH_BITS-1:0] wBinNextP1; assign RD_EMPTY = rEmpty; assign RD_PTR = rRdPtr; assign RD_PTR_P1 = rRdPtrP1; // Gray coded pointer always @(posedge RD_CLK or posedge RD_RST) begin if (RD_RST) begin rBin <= #1 0; rBinP1 <= #1 1; rRdPtr <= #1 0; rRdPtrP1 <= #1 0; end else begin rBin <= #1 wBinNext; rBinP1 <= #1 wBinNextP1; rRdPtr <= #1 wGrayNext; rRdPtrP1 <= #1 wGrayNextP1; end end // Increment the binary count if not empty assign wBinNext = (!rEmpty ? rBin + RD_EN : rBin); assign wBinNextP1 = (!rEmpty ? rBinP1 + RD_EN : rBinP1); assign wGrayNext = ((wBinNext>>1) ^ wBinNext); // binary-to-gray conversion assign wGrayNextP1 = ((wBinNextP1>>1) ^ wBinNextP1); // binary-to-gray conversion always @(posedge RD_CLK) begin if (CMP_EMPTY) {rEmpty, rEmpty2} <= #1 2'b11; else {rEmpty, rEmpty2} <= #1 {rEmpty2, CMP_EMPTY}; end endmodule module wr_ptr_full #( parameter C_DEPTH_BITS = 4 ) ( input WR_CLK, input WR_RST, input WR_EN, output WR_FULL, output [C_DEPTH_BITS-1:0] WR_PTR, output [C_DEPTH_BITS-1:0] WR_PTR_P1, input CMP_FULL ); reg rFull=0; reg rFull2=0; reg [C_DEPTH_BITS-1:0] rPtr=0; reg [C_DEPTH_BITS-1:0] rPtrP1=0; reg [C_DEPTH_BITS-1:0] rBin=0; reg [C_DEPTH_BITS-1:0] rBinP1=1; wire [C_DEPTH_BITS-1:0] wGrayNext; wire [C_DEPTH_BITS-1:0] wGrayNextP1; wire [C_DEPTH_BITS-1:0] wBinNext; wire [C_DEPTH_BITS-1:0] wBinNextP1; assign WR_FULL = rFull; assign WR_PTR = rPtr; assign WR_PTR_P1 = rPtrP1; // Gray coded pointer always @(posedge WR_CLK or posedge WR_RST) begin if (WR_RST) begin rBin <= #1 0; rBinP1 <= #1 1; rPtr <= #1 0; rPtrP1 <= #1 0; end else begin rBin <= #1 wBinNext; rBinP1 <= #1 wBinNextP1; rPtr <= #1 wGrayNext; rPtrP1 <= #1 wGrayNextP1; end end // Increment the binary count if not full assign wBinNext = (!rFull ? rBin + WR_EN : rBin); assign wBinNextP1 = (!rFull ? rBinP1 + WR_EN : rBinP1); assign wGrayNext = ((wBinNext>>1) ^ wBinNext); // binary-to-gray conversion assign wGrayNextP1 = ((wBinNextP1>>1) ^ wBinNextP1); // binary-to-gray conversion always @(posedge WR_CLK) begin if (WR_RST) {rFull, rFull2} <= #1 2'b00; else if (CMP_FULL) {rFull, rFull2} <= #1 2'b11; else {rFull, rFull2} <= #1 {rFull2, CMP_FULL}; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: async_fifo.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Asynchronous capable parameterized FIFO. As with all // traditional FIFOs, the RD_DATA will be valid one cycle following a RD_EN // assertion. RD_EMPTY will remain low until the cycle following the last RD_EN // assertion. Note, that RD_EMPTY may actually be high on the same cycle that // RD_DATA contains valid data. // Author: Matt Jacobsen // History: @mattj: Version 2.0 // Additional Comments: Based on design by CE Cummings in Simulation and // Synthesis Techniques for Asynchronous FIFO Design with Asynchronous Pointer // Comparisons //----------------------------------------------------------------------------- `timescale 1ns/1ns module async_fifo #( parameter C_WIDTH = 32, // Data bus width parameter C_DEPTH = 1024, // Depth of the FIFO // Local parameters parameter C_REAL_DEPTH = 2**clog2(C_DEPTH), parameter C_DEPTH_BITS = clog2(C_REAL_DEPTH), parameter C_DEPTH_P1_BITS = clog2(C_REAL_DEPTH+1) ) ( input RD_CLK, // Read clock input RD_RST, // Read synchronous reset input WR_CLK, // Write clock input WR_RST, // Write synchronous reset input [C_WIDTH-1:0] WR_DATA, // Write data input (WR_CLK) input WR_EN, // Write enable, high active (WR_CLK) output [C_WIDTH-1:0] RD_DATA, // Read data output (RD_CLK) input RD_EN, // Read enable, high active (RD_CLK) output WR_FULL, // Full condition (WR_CLK) output RD_EMPTY // Empty condition (RD_CLK) ); `include "functions.vh" wire wCmpEmpty; wire wCmpFull; wire [C_DEPTH_BITS-1:0] wWrPtr; wire [C_DEPTH_BITS-1:0] wRdPtr; wire [C_DEPTH_BITS-1:0] wWrPtrP1; wire [C_DEPTH_BITS-1:0] wRdPtrP1; // Memory block (synthesis attributes applied to this module will // determine the memory option). ram_2clk_1w_1r #(.C_RAM_WIDTH(C_WIDTH), .C_RAM_DEPTH(C_REAL_DEPTH)) mem ( .CLKA(WR_CLK), .ADDRA(wWrPtr), .WEA(WR_EN & !WR_FULL), .DINA(WR_DATA), .CLKB(RD_CLK), .ADDRB(wRdPtr), .DOUTB(RD_DATA) ); // Compare the pointers. async_cmp #(.C_DEPTH_BITS(C_DEPTH_BITS)) asyncCompare ( .WR_RST(WR_RST), .WR_CLK(WR_CLK), .RD_RST(RD_RST), .RD_CLK(RD_CLK), .RD_VALID(RD_EN & !RD_EMPTY), .WR_VALID(WR_EN & !WR_FULL), .EMPTY(wCmpEmpty), .FULL(wCmpFull), .WR_PTR(wWrPtr), .WR_PTR_P1(wWrPtrP1), .RD_PTR(wRdPtr), .RD_PTR_P1(wRdPtrP1) ); // Calculate empty rd_ptr_empty #(.C_DEPTH_BITS(C_DEPTH_BITS)) rdPtrEmpty ( .RD_EMPTY(RD_EMPTY), .RD_PTR(wRdPtr), .RD_PTR_P1(wRdPtrP1), .CMP_EMPTY(wCmpEmpty), .RD_EN(RD_EN), .RD_CLK(RD_CLK), .RD_RST(RD_RST) ); // Calculate full wr_ptr_full #(.C_DEPTH_BITS(C_DEPTH_BITS)) wrPtrFull ( .WR_CLK(WR_CLK), .WR_RST(WR_RST), .WR_EN(WR_EN), .WR_FULL(WR_FULL), .WR_PTR(wWrPtr), .WR_PTR_P1(wWrPtrP1), .CMP_FULL(wCmpFull) ); endmodule module async_cmp #( parameter C_DEPTH_BITS = 4, // Local parameters parameter N = C_DEPTH_BITS-1 ) ( input WR_RST, input WR_CLK, input RD_RST, input RD_CLK, input RD_VALID, input WR_VALID, output EMPTY, output FULL, input [C_DEPTH_BITS-1:0] WR_PTR, input [C_DEPTH_BITS-1:0] RD_PTR, input [C_DEPTH_BITS-1:0] WR_PTR_P1, input [C_DEPTH_BITS-1:0] RD_PTR_P1 ); reg rDir=0; wire wDirSet = ( (WR_PTR[N]^RD_PTR[N-1]) & ~(WR_PTR[N-1]^RD_PTR[N])); wire wDirClr = ((~(WR_PTR[N]^RD_PTR[N-1]) & (WR_PTR[N-1]^RD_PTR[N])) | WR_RST); reg rRdValid=0; reg rEmpty=1; reg rFull=0; wire wATBEmpty = ((WR_PTR == RD_PTR_P1) && (RD_VALID | rRdValid)); wire wATBFull = ((WR_PTR_P1 == RD_PTR) && WR_VALID); wire wEmpty = ((WR_PTR == RD_PTR) && !rDir); wire wFull = ((WR_PTR == RD_PTR) && rDir); assign EMPTY = wATBEmpty || rEmpty; assign FULL = wATBFull || rFull; always @(posedge wDirSet or posedge wDirClr) if (wDirClr) rDir <= 1'b0; else rDir <= 1'b1; always @(posedge RD_CLK) begin rEmpty <= (RD_RST ? 1'd1 : wEmpty); rRdValid <= (RD_RST ? 1'd0 : RD_VALID); end always @(posedge WR_CLK) begin rFull <= (WR_RST ? 1'd0 : wFull); end endmodule module rd_ptr_empty #( parameter C_DEPTH_BITS = 4 ) ( input RD_CLK, input RD_RST, input RD_EN, output RD_EMPTY, output [C_DEPTH_BITS-1:0] RD_PTR, output [C_DEPTH_BITS-1:0] RD_PTR_P1, input CMP_EMPTY ); reg rEmpty=1; reg rEmpty2=1; reg [C_DEPTH_BITS-1:0] rRdPtr=0; reg [C_DEPTH_BITS-1:0] rRdPtrP1=0; reg [C_DEPTH_BITS-1:0] rBin=0; reg [C_DEPTH_BITS-1:0] rBinP1=1; wire [C_DEPTH_BITS-1:0] wGrayNext; wire [C_DEPTH_BITS-1:0] wGrayNextP1; wire [C_DEPTH_BITS-1:0] wBinNext; wire [C_DEPTH_BITS-1:0] wBinNextP1; assign RD_EMPTY = rEmpty; assign RD_PTR = rRdPtr; assign RD_PTR_P1 = rRdPtrP1; // Gray coded pointer always @(posedge RD_CLK or posedge RD_RST) begin if (RD_RST) begin rBin <= #1 0; rBinP1 <= #1 1; rRdPtr <= #1 0; rRdPtrP1 <= #1 0; end else begin rBin <= #1 wBinNext; rBinP1 <= #1 wBinNextP1; rRdPtr <= #1 wGrayNext; rRdPtrP1 <= #1 wGrayNextP1; end end // Increment the binary count if not empty assign wBinNext = (!rEmpty ? rBin + RD_EN : rBin); assign wBinNextP1 = (!rEmpty ? rBinP1 + RD_EN : rBinP1); assign wGrayNext = ((wBinNext>>1) ^ wBinNext); // binary-to-gray conversion assign wGrayNextP1 = ((wBinNextP1>>1) ^ wBinNextP1); // binary-to-gray conversion always @(posedge RD_CLK) begin if (CMP_EMPTY) {rEmpty, rEmpty2} <= #1 2'b11; else {rEmpty, rEmpty2} <= #1 {rEmpty2, CMP_EMPTY}; end endmodule module wr_ptr_full #( parameter C_DEPTH_BITS = 4 ) ( input WR_CLK, input WR_RST, input WR_EN, output WR_FULL, output [C_DEPTH_BITS-1:0] WR_PTR, output [C_DEPTH_BITS-1:0] WR_PTR_P1, input CMP_FULL ); reg rFull=0; reg rFull2=0; reg [C_DEPTH_BITS-1:0] rPtr=0; reg [C_DEPTH_BITS-1:0] rPtrP1=0; reg [C_DEPTH_BITS-1:0] rBin=0; reg [C_DEPTH_BITS-1:0] rBinP1=1; wire [C_DEPTH_BITS-1:0] wGrayNext; wire [C_DEPTH_BITS-1:0] wGrayNextP1; wire [C_DEPTH_BITS-1:0] wBinNext; wire [C_DEPTH_BITS-1:0] wBinNextP1; assign WR_FULL = rFull; assign WR_PTR = rPtr; assign WR_PTR_P1 = rPtrP1; // Gray coded pointer always @(posedge WR_CLK or posedge WR_RST) begin if (WR_RST) begin rBin <= #1 0; rBinP1 <= #1 1; rPtr <= #1 0; rPtrP1 <= #1 0; end else begin rBin <= #1 wBinNext; rBinP1 <= #1 wBinNextP1; rPtr <= #1 wGrayNext; rPtrP1 <= #1 wGrayNextP1; end end // Increment the binary count if not full assign wBinNext = (!rFull ? rBin + WR_EN : rBin); assign wBinNextP1 = (!rFull ? rBinP1 + WR_EN : rBinP1); assign wGrayNext = ((wBinNext>>1) ^ wBinNext); // binary-to-gray conversion assign wGrayNextP1 = ((wBinNextP1>>1) ^ wBinNextP1); // binary-to-gray conversion always @(posedge WR_CLK) begin if (WR_RST) {rFull, rFull2} <= #1 2'b00; else if (CMP_FULL) {rFull, rFull2} <= #1 2'b11; else {rFull, rFull2} <= #1 {rFull2, CMP_FULL}; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: async_fifo.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Asynchronous capable parameterized FIFO. As with all // traditional FIFOs, the RD_DATA will be valid one cycle following a RD_EN // assertion. RD_EMPTY will remain low until the cycle following the last RD_EN // assertion. Note, that RD_EMPTY may actually be high on the same cycle that // RD_DATA contains valid data. // Author: Matt Jacobsen // History: @mattj: Version 2.0 // Additional Comments: Based on design by CE Cummings in Simulation and // Synthesis Techniques for Asynchronous FIFO Design with Asynchronous Pointer // Comparisons //----------------------------------------------------------------------------- `timescale 1ns/1ns module async_fifo #( parameter C_WIDTH = 32, // Data bus width parameter C_DEPTH = 1024, // Depth of the FIFO // Local parameters parameter C_REAL_DEPTH = 2**clog2(C_DEPTH), parameter C_DEPTH_BITS = clog2(C_REAL_DEPTH), parameter C_DEPTH_P1_BITS = clog2(C_REAL_DEPTH+1) ) ( input RD_CLK, // Read clock input RD_RST, // Read synchronous reset input WR_CLK, // Write clock input WR_RST, // Write synchronous reset input [C_WIDTH-1:0] WR_DATA, // Write data input (WR_CLK) input WR_EN, // Write enable, high active (WR_CLK) output [C_WIDTH-1:0] RD_DATA, // Read data output (RD_CLK) input RD_EN, // Read enable, high active (RD_CLK) output WR_FULL, // Full condition (WR_CLK) output RD_EMPTY // Empty condition (RD_CLK) ); `include "functions.vh" wire wCmpEmpty; wire wCmpFull; wire [C_DEPTH_BITS-1:0] wWrPtr; wire [C_DEPTH_BITS-1:0] wRdPtr; wire [C_DEPTH_BITS-1:0] wWrPtrP1; wire [C_DEPTH_BITS-1:0] wRdPtrP1; // Memory block (synthesis attributes applied to this module will // determine the memory option). ram_2clk_1w_1r #(.C_RAM_WIDTH(C_WIDTH), .C_RAM_DEPTH(C_REAL_DEPTH)) mem ( .CLKA(WR_CLK), .ADDRA(wWrPtr), .WEA(WR_EN & !WR_FULL), .DINA(WR_DATA), .CLKB(RD_CLK), .ADDRB(wRdPtr), .DOUTB(RD_DATA) ); // Compare the pointers. async_cmp #(.C_DEPTH_BITS(C_DEPTH_BITS)) asyncCompare ( .WR_RST(WR_RST), .WR_CLK(WR_CLK), .RD_RST(RD_RST), .RD_CLK(RD_CLK), .RD_VALID(RD_EN & !RD_EMPTY), .WR_VALID(WR_EN & !WR_FULL), .EMPTY(wCmpEmpty), .FULL(wCmpFull), .WR_PTR(wWrPtr), .WR_PTR_P1(wWrPtrP1), .RD_PTR(wRdPtr), .RD_PTR_P1(wRdPtrP1) ); // Calculate empty rd_ptr_empty #(.C_DEPTH_BITS(C_DEPTH_BITS)) rdPtrEmpty ( .RD_EMPTY(RD_EMPTY), .RD_PTR(wRdPtr), .RD_PTR_P1(wRdPtrP1), .CMP_EMPTY(wCmpEmpty), .RD_EN(RD_EN), .RD_CLK(RD_CLK), .RD_RST(RD_RST) ); // Calculate full wr_ptr_full #(.C_DEPTH_BITS(C_DEPTH_BITS)) wrPtrFull ( .WR_CLK(WR_CLK), .WR_RST(WR_RST), .WR_EN(WR_EN), .WR_FULL(WR_FULL), .WR_PTR(wWrPtr), .WR_PTR_P1(wWrPtrP1), .CMP_FULL(wCmpFull) ); endmodule module async_cmp #( parameter C_DEPTH_BITS = 4, // Local parameters parameter N = C_DEPTH_BITS-1 ) ( input WR_RST, input WR_CLK, input RD_RST, input RD_CLK, input RD_VALID, input WR_VALID, output EMPTY, output FULL, input [C_DEPTH_BITS-1:0] WR_PTR, input [C_DEPTH_BITS-1:0] RD_PTR, input [C_DEPTH_BITS-1:0] WR_PTR_P1, input [C_DEPTH_BITS-1:0] RD_PTR_P1 ); reg rDir=0; wire wDirSet = ( (WR_PTR[N]^RD_PTR[N-1]) & ~(WR_PTR[N-1]^RD_PTR[N])); wire wDirClr = ((~(WR_PTR[N]^RD_PTR[N-1]) & (WR_PTR[N-1]^RD_PTR[N])) | WR_RST); reg rRdValid=0; reg rEmpty=1; reg rFull=0; wire wATBEmpty = ((WR_PTR == RD_PTR_P1) && (RD_VALID | rRdValid)); wire wATBFull = ((WR_PTR_P1 == RD_PTR) && WR_VALID); wire wEmpty = ((WR_PTR == RD_PTR) && !rDir); wire wFull = ((WR_PTR == RD_PTR) && rDir); assign EMPTY = wATBEmpty || rEmpty; assign FULL = wATBFull || rFull; always @(posedge wDirSet or posedge wDirClr) if (wDirClr) rDir <= 1'b0; else rDir <= 1'b1; always @(posedge RD_CLK) begin rEmpty <= (RD_RST ? 1'd1 : wEmpty); rRdValid <= (RD_RST ? 1'd0 : RD_VALID); end always @(posedge WR_CLK) begin rFull <= (WR_RST ? 1'd0 : wFull); end endmodule module rd_ptr_empty #( parameter C_DEPTH_BITS = 4 ) ( input RD_CLK, input RD_RST, input RD_EN, output RD_EMPTY, output [C_DEPTH_BITS-1:0] RD_PTR, output [C_DEPTH_BITS-1:0] RD_PTR_P1, input CMP_EMPTY ); reg rEmpty=1; reg rEmpty2=1; reg [C_DEPTH_BITS-1:0] rRdPtr=0; reg [C_DEPTH_BITS-1:0] rRdPtrP1=0; reg [C_DEPTH_BITS-1:0] rBin=0; reg [C_DEPTH_BITS-1:0] rBinP1=1; wire [C_DEPTH_BITS-1:0] wGrayNext; wire [C_DEPTH_BITS-1:0] wGrayNextP1; wire [C_DEPTH_BITS-1:0] wBinNext; wire [C_DEPTH_BITS-1:0] wBinNextP1; assign RD_EMPTY = rEmpty; assign RD_PTR = rRdPtr; assign RD_PTR_P1 = rRdPtrP1; // Gray coded pointer always @(posedge RD_CLK or posedge RD_RST) begin if (RD_RST) begin rBin <= #1 0; rBinP1 <= #1 1; rRdPtr <= #1 0; rRdPtrP1 <= #1 0; end else begin rBin <= #1 wBinNext; rBinP1 <= #1 wBinNextP1; rRdPtr <= #1 wGrayNext; rRdPtrP1 <= #1 wGrayNextP1; end end // Increment the binary count if not empty assign wBinNext = (!rEmpty ? rBin + RD_EN : rBin); assign wBinNextP1 = (!rEmpty ? rBinP1 + RD_EN : rBinP1); assign wGrayNext = ((wBinNext>>1) ^ wBinNext); // binary-to-gray conversion assign wGrayNextP1 = ((wBinNextP1>>1) ^ wBinNextP1); // binary-to-gray conversion always @(posedge RD_CLK) begin if (CMP_EMPTY) {rEmpty, rEmpty2} <= #1 2'b11; else {rEmpty, rEmpty2} <= #1 {rEmpty2, CMP_EMPTY}; end endmodule module wr_ptr_full #( parameter C_DEPTH_BITS = 4 ) ( input WR_CLK, input WR_RST, input WR_EN, output WR_FULL, output [C_DEPTH_BITS-1:0] WR_PTR, output [C_DEPTH_BITS-1:0] WR_PTR_P1, input CMP_FULL ); reg rFull=0; reg rFull2=0; reg [C_DEPTH_BITS-1:0] rPtr=0; reg [C_DEPTH_BITS-1:0] rPtrP1=0; reg [C_DEPTH_BITS-1:0] rBin=0; reg [C_DEPTH_BITS-1:0] rBinP1=1; wire [C_DEPTH_BITS-1:0] wGrayNext; wire [C_DEPTH_BITS-1:0] wGrayNextP1; wire [C_DEPTH_BITS-1:0] wBinNext; wire [C_DEPTH_BITS-1:0] wBinNextP1; assign WR_FULL = rFull; assign WR_PTR = rPtr; assign WR_PTR_P1 = rPtrP1; // Gray coded pointer always @(posedge WR_CLK or posedge WR_RST) begin if (WR_RST) begin rBin <= #1 0; rBinP1 <= #1 1; rPtr <= #1 0; rPtrP1 <= #1 0; end else begin rBin <= #1 wBinNext; rBinP1 <= #1 wBinNextP1; rPtr <= #1 wGrayNext; rPtrP1 <= #1 wGrayNextP1; end end // Increment the binary count if not full assign wBinNext = (!rFull ? rBin + WR_EN : rBin); assign wBinNextP1 = (!rFull ? rBinP1 + WR_EN : rBinP1); assign wGrayNext = ((wBinNext>>1) ^ wBinNext); // binary-to-gray conversion assign wGrayNextP1 = ((wBinNextP1>>1) ^ wBinNextP1); // binary-to-gray conversion always @(posedge WR_CLK) begin if (WR_RST) {rFull, rFull2} <= #1 2'b00; else if (CMP_FULL) {rFull, rFull2} <= #1 2'b11; else {rFull, rFull2} <= #1 {rFull2, CMP_FULL}; end endmodule
/********************************************************** -- (c) Copyright 2011 - 2013 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). A Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. // // THIS NOTICE MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES. // // // Owner: Gary Martin // Revision: $Id: //depot/icm/proj/common/head/rtl/v32_cmt/rtl/phy/phy_4lanes.v#6 $ // $Author: gary $ // $DateTime: 2010/05/11 18:05:17 $ // $Change: 490882 $ // Description: // This verilog file is the parameterizable 4-byte lane phy primitive top // This module may be ganged to create an N-lane phy. // // History: // Date Engineer Description // 04/01/2010 G. Martin Initial Checkin. // /////////////////////////////////////////////////////////// **********************************************************/ `timescale 1ps/1ps `define PC_DATA_OFFSET_RANGE 22:17 module mig_7series_v1_9_ddr_phy_4lanes #( parameter GENERATE_IDELAYCTRL = "TRUE", parameter IODELAY_GRP = "IODELAY_MIG", parameter BANK_TYPE = "HP_IO", // # = "HP_IO", "HPL_IO", "HR_IO", "HRL_IO" parameter BYTELANES_DDR_CK = 24'b0010_0010_0010_0010_0010_0010, parameter NUM_DDR_CK = 1, // next three parameter fields correspond to byte lanes for lane order DCBA parameter BYTE_LANES = 4'b1111, // lane existence, one per lane parameter DATA_CTL_N = 4'b1111, // data or control, per lane parameter BITLANES = 48'hffff_ffff_ffff, parameter BITLANES_OUTONLY = 48'h0000_0000_0000, parameter LANE_REMAP = 16'h3210,// 4-bit index // used to rewire to one of four // input/output buss lanes // example: 0321 remaps lanes as: // D->A // C->D // B->C // A->B parameter LAST_BANK = "FALSE", parameter USE_PRE_POST_FIFO = "FALSE", parameter RCLK_SELECT_LANE = "B", parameter real TCK = 0.00, parameter SYNTHESIS = "FALSE", parameter PO_CTL_COARSE_BYPASS = "FALSE", parameter PO_FINE_DELAY = 0, parameter PI_SEL_CLK_OFFSET = 0, // phy_control paramter used in other paramsters parameter PC_CLK_RATIO = 4, //phaser_in parameters parameter A_PI_FREQ_REF_DIV = "NONE", parameter A_PI_CLKOUT_DIV = 2, parameter A_PI_BURST_MODE = "TRUE", parameter A_PI_OUTPUT_CLK_SRC = "DELAYED_REF" , //"DELAYED_REF", parameter A_PI_FINE_DELAY = 60, parameter A_PI_SYNC_IN_DIV_RST = "TRUE", parameter B_PI_FREQ_REF_DIV = A_PI_FREQ_REF_DIV, parameter B_PI_CLKOUT_DIV = A_PI_CLKOUT_DIV, parameter B_PI_BURST_MODE = A_PI_BURST_MODE, parameter B_PI_OUTPUT_CLK_SRC = A_PI_OUTPUT_CLK_SRC, parameter B_PI_FINE_DELAY = A_PI_FINE_DELAY, parameter B_PI_SYNC_IN_DIV_RST = A_PI_SYNC_IN_DIV_RST, parameter C_PI_FREQ_REF_DIV = A_PI_FREQ_REF_DIV, parameter C_PI_CLKOUT_DIV = A_PI_CLKOUT_DIV, parameter C_PI_BURST_MODE = A_PI_BURST_MODE, parameter C_PI_OUTPUT_CLK_SRC = A_PI_OUTPUT_CLK_SRC, parameter C_PI_FINE_DELAY = 0, parameter C_PI_SYNC_IN_DIV_RST = A_PI_SYNC_IN_DIV_RST, parameter D_PI_FREQ_REF_DIV = A_PI_FREQ_REF_DIV, parameter D_PI_CLKOUT_DIV = A_PI_CLKOUT_DIV, parameter D_PI_BURST_MODE = A_PI_BURST_MODE, parameter D_PI_OUTPUT_CLK_SRC = A_PI_OUTPUT_CLK_SRC, parameter D_PI_FINE_DELAY = 0, parameter D_PI_SYNC_IN_DIV_RST = A_PI_SYNC_IN_DIV_RST, //phaser_out parameters parameter A_PO_CLKOUT_DIV = (DATA_CTL_N[0] == 0) ? PC_CLK_RATIO : 2, parameter A_PO_FINE_DELAY = PO_FINE_DELAY, parameter A_PO_COARSE_DELAY = 0, parameter A_PO_OCLK_DELAY = 0, parameter A_PO_OCLKDELAY_INV = "FALSE", parameter A_PO_OUTPUT_CLK_SRC = "DELAYED_REF", parameter A_PO_SYNC_IN_DIV_RST = "TRUE", //parameter A_PO_SYNC_IN_DIV_RST = "FALSE", parameter B_PO_CLKOUT_DIV = (DATA_CTL_N[1] == 0) ? PC_CLK_RATIO : 2, parameter B_PO_FINE_DELAY = PO_FINE_DELAY, parameter B_PO_COARSE_DELAY = A_PO_COARSE_DELAY, parameter B_PO_OCLK_DELAY = A_PO_OCLK_DELAY, parameter B_PO_OCLKDELAY_INV = A_PO_OCLKDELAY_INV, parameter B_PO_OUTPUT_CLK_SRC = A_PO_OUTPUT_CLK_SRC, parameter B_PO_SYNC_IN_DIV_RST = A_PO_SYNC_IN_DIV_RST, parameter C_PO_CLKOUT_DIV = (DATA_CTL_N[2] == 0) ? PC_CLK_RATIO : 2, parameter C_PO_FINE_DELAY = PO_FINE_DELAY, parameter C_PO_COARSE_DELAY = A_PO_COARSE_DELAY, parameter C_PO_OCLK_DELAY = A_PO_OCLK_DELAY, parameter C_PO_OCLKDELAY_INV = A_PO_OCLKDELAY_INV, parameter C_PO_OUTPUT_CLK_SRC = A_PO_OUTPUT_CLK_SRC, parameter C_PO_SYNC_IN_DIV_RST = A_PO_SYNC_IN_DIV_RST, parameter D_PO_CLKOUT_DIV = (DATA_CTL_N[3] == 0) ? PC_CLK_RATIO : 2, parameter D_PO_FINE_DELAY = PO_FINE_DELAY, parameter D_PO_COARSE_DELAY = A_PO_COARSE_DELAY, parameter D_PO_OCLK_DELAY = A_PO_OCLK_DELAY, parameter D_PO_OCLKDELAY_INV = A_PO_OCLKDELAY_INV, parameter D_PO_OUTPUT_CLK_SRC = A_PO_OUTPUT_CLK_SRC, parameter D_PO_SYNC_IN_DIV_RST = A_PO_SYNC_IN_DIV_RST, parameter A_IDELAYE2_IDELAY_TYPE = "VARIABLE", parameter A_IDELAYE2_IDELAY_VALUE = 00, parameter B_IDELAYE2_IDELAY_TYPE = A_IDELAYE2_IDELAY_TYPE, parameter B_IDELAYE2_IDELAY_VALUE = A_IDELAYE2_IDELAY_VALUE, parameter C_IDELAYE2_IDELAY_TYPE = A_IDELAYE2_IDELAY_TYPE, parameter C_IDELAYE2_IDELAY_VALUE = A_IDELAYE2_IDELAY_VALUE, parameter D_IDELAYE2_IDELAY_TYPE = A_IDELAYE2_IDELAY_TYPE, parameter D_IDELAYE2_IDELAY_VALUE = A_IDELAYE2_IDELAY_VALUE, // phy_control parameters parameter PC_BURST_MODE = "TRUE", parameter PC_DATA_CTL_N = DATA_CTL_N, parameter PC_CMD_OFFSET = 0, parameter PC_RD_CMD_OFFSET_0 = 0, parameter PC_RD_CMD_OFFSET_1 = 0, parameter PC_RD_CMD_OFFSET_2 = 0, parameter PC_RD_CMD_OFFSET_3 = 0, parameter PC_CO_DURATION = 1, parameter PC_DI_DURATION = 1, parameter PC_DO_DURATION = 1, parameter PC_RD_DURATION_0 = 0, parameter PC_RD_DURATION_1 = 0, parameter PC_RD_DURATION_2 = 0, parameter PC_RD_DURATION_3 = 0, parameter PC_WR_CMD_OFFSET_0 = 5, parameter PC_WR_CMD_OFFSET_1 = 5, parameter PC_WR_CMD_OFFSET_2 = 5, parameter PC_WR_CMD_OFFSET_3 = 5, parameter PC_WR_DURATION_0 = 6, parameter PC_WR_DURATION_1 = 6, parameter PC_WR_DURATION_2 = 6, parameter PC_WR_DURATION_3 = 6, parameter PC_AO_WRLVL_EN = 0, parameter PC_AO_TOGGLE = 4'b0101, // odd bits are toggle (CKE) parameter PC_FOUR_WINDOW_CLOCKS = 63, parameter PC_EVENTS_DELAY = 18, parameter PC_PHY_COUNT_EN = "TRUE", parameter PC_SYNC_MODE = "TRUE", parameter PC_DISABLE_SEQ_MATCH = "TRUE", parameter PC_MULTI_REGION = "FALSE", // io fifo parameters parameter A_OF_ARRAY_MODE = (DATA_CTL_N[0] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter B_OF_ARRAY_MODE = (DATA_CTL_N[1] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter C_OF_ARRAY_MODE = (DATA_CTL_N[2] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter D_OF_ARRAY_MODE = (DATA_CTL_N[3] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter OF_ALMOST_EMPTY_VALUE = 1, parameter OF_ALMOST_FULL_VALUE = 1, parameter OF_OUTPUT_DISABLE = "TRUE", parameter OF_SYNCHRONOUS_MODE = PC_SYNC_MODE, parameter A_OS_DATA_RATE = "DDR", parameter A_OS_DATA_WIDTH = 4, parameter B_OS_DATA_RATE = A_OS_DATA_RATE, parameter B_OS_DATA_WIDTH = A_OS_DATA_WIDTH, parameter C_OS_DATA_RATE = A_OS_DATA_RATE, parameter C_OS_DATA_WIDTH = A_OS_DATA_WIDTH, parameter D_OS_DATA_RATE = A_OS_DATA_RATE, parameter D_OS_DATA_WIDTH = A_OS_DATA_WIDTH, parameter A_IF_ARRAY_MODE = "ARRAY_MODE_4_X_8", parameter B_IF_ARRAY_MODE = A_IF_ARRAY_MODE, parameter C_IF_ARRAY_MODE = A_IF_ARRAY_MODE, parameter D_IF_ARRAY_MODE = A_IF_ARRAY_MODE, parameter IF_ALMOST_EMPTY_VALUE = 1, parameter IF_ALMOST_FULL_VALUE = 1, parameter IF_SYNCHRONOUS_MODE = PC_SYNC_MODE, // this is used locally, not for external pushdown // NOTE: the 0+ is needed in each to coerce to integer for addition. // otherwise 4x 1'b values are added producing a 1'b value. parameter HIGHEST_LANE = LAST_BANK == "FALSE" ? 4 : (BYTE_LANES[3] ? 4 : BYTE_LANES[2] ? 3 : BYTE_LANES[1] ? 2 : 1), parameter N_CTL_LANES = ((0+(!DATA_CTL_N[0]) & BYTE_LANES[0]) + (0+(!DATA_CTL_N[1]) & BYTE_LANES[1]) + (0+(!DATA_CTL_N[2]) & BYTE_LANES[2]) + (0+(!DATA_CTL_N[3]) & BYTE_LANES[3])), parameter N_BYTE_LANES = (0+BYTE_LANES[0]) + (0+BYTE_LANES[1]) + (0+BYTE_LANES[2]) + (0+BYTE_LANES[3]), parameter N_DATA_LANES = N_BYTE_LANES - N_CTL_LANES, // assume odt per rank + any declared cke's parameter AUXOUT_WIDTH = 4, parameter LP_DDR_CK_WIDTH = 2 ,parameter CKE_ODT_AUX = "FALSE" ) ( //`include "phy.vh" input rst, input phy_clk, input phy_ctl_clk, input freq_refclk, input mem_refclk, input mem_refclk_div4, input pll_lock, input sync_pulse, input idelayctrl_refclk, input [HIGHEST_LANE*80-1:0] phy_dout, input phy_cmd_wr_en, input phy_data_wr_en, input phy_rd_en, input phy_ctl_mstr_empty, input [31:0] phy_ctl_wd, input [`PC_DATA_OFFSET_RANGE] data_offset, input phy_ctl_wr, input if_empty_def, input phyGo, input input_sink, output [(LP_DDR_CK_WIDTH*24)-1:0] ddr_clk, // to memory output rclk, output if_a_empty, output if_empty, output byte_rd_en, output if_empty_or, output if_empty_and, output of_ctl_a_full, output of_data_a_full, output of_ctl_full, output of_data_full, output pre_data_a_full, output [HIGHEST_LANE*80-1:0]phy_din, // assume input bus same size as output bus output phy_ctl_empty, output phy_ctl_a_full, output phy_ctl_full, output [HIGHEST_LANE*12-1:0]mem_dq_out, output [HIGHEST_LANE*12-1:0]mem_dq_ts, input [HIGHEST_LANE*10-1:0]mem_dq_in, output [HIGHEST_LANE-1:0] mem_dqs_out, output [HIGHEST_LANE-1:0] mem_dqs_ts, input [HIGHEST_LANE-1:0] mem_dqs_in, input [1:0] byte_rd_en_oth_banks, output [AUXOUT_WIDTH-1:0] aux_out, output reg rst_out = 0, output reg mcGo=0, output phy_ctl_ready, output ref_dll_lock, input if_rst, input phy_read_calib, input phy_write_calib, input idelay_inc, input idelay_ce, input idelay_ld, input [2:0] calib_sel, input calib_zero_ctrl, input [HIGHEST_LANE-1:0] calib_zero_lanes, input calib_in_common, input po_fine_enable, input po_coarse_enable, input po_fine_inc, input po_coarse_inc, input po_counter_load_en, input po_counter_read_en, input [8:0] po_counter_load_val, input po_sel_fine_oclk_delay, output reg po_coarse_overflow, output reg po_fine_overflow, output reg [8:0] po_counter_read_val, input pi_rst_dqs_find, input pi_fine_enable, input pi_fine_inc, input pi_counter_load_en, input pi_counter_read_en, input [5:0] pi_counter_load_val, output reg pi_fine_overflow, output reg [5:0] pi_counter_read_val, output reg pi_dqs_found, output pi_dqs_found_all, output pi_dqs_found_any, output [HIGHEST_LANE-1:0] pi_phase_locked_lanes, output [HIGHEST_LANE-1:0] pi_dqs_found_lanes, output reg pi_dqs_out_of_range, output reg pi_phase_locked, output pi_phase_locked_all ); localparam DATA_CTL_A = (~DATA_CTL_N[0]); localparam DATA_CTL_B = (~DATA_CTL_N[1]); localparam DATA_CTL_C = (~DATA_CTL_N[2]); localparam DATA_CTL_D = (~DATA_CTL_N[3]); localparam PRESENT_CTL_A = BYTE_LANES[0] && ! DATA_CTL_N[0]; localparam PRESENT_CTL_B = BYTE_LANES[1] && ! DATA_CTL_N[1]; localparam PRESENT_CTL_C = BYTE_LANES[2] && ! DATA_CTL_N[2]; localparam PRESENT_CTL_D = BYTE_LANES[3] && ! DATA_CTL_N[3]; localparam PRESENT_DATA_A = BYTE_LANES[0] && DATA_CTL_N[0]; localparam PRESENT_DATA_B = BYTE_LANES[1] && DATA_CTL_N[1]; localparam PRESENT_DATA_C = BYTE_LANES[2] && DATA_CTL_N[2]; localparam PRESENT_DATA_D = BYTE_LANES[3] && DATA_CTL_N[3]; localparam PC_DATA_CTL_A = (DATA_CTL_A) ? "FALSE" : "TRUE"; localparam PC_DATA_CTL_B = (DATA_CTL_B) ? "FALSE" : "TRUE"; localparam PC_DATA_CTL_C = (DATA_CTL_C) ? "FALSE" : "TRUE"; localparam PC_DATA_CTL_D = (DATA_CTL_D) ? "FALSE" : "TRUE"; localparam A_PO_COARSE_BYPASS = (DATA_CTL_A) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam B_PO_COARSE_BYPASS = (DATA_CTL_B) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam C_PO_COARSE_BYPASS = (DATA_CTL_C) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam D_PO_COARSE_BYPASS = (DATA_CTL_D) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam IO_A_START = 41; localparam IO_A_END = 40; localparam IO_B_START = 43; localparam IO_B_END = 42; localparam IO_C_START = 45; localparam IO_C_END = 44; localparam IO_D_START = 47; localparam IO_D_END = 46; localparam IO_A_X_START = (HIGHEST_LANE * 10) + 1; localparam IO_A_X_END = (IO_A_X_START-1); localparam IO_B_X_START = (IO_A_X_START + 2); localparam IO_B_X_END = (IO_B_X_START -1); localparam IO_C_X_START = (IO_B_X_START + 2); localparam IO_C_X_END = (IO_C_X_START -1); localparam IO_D_X_START = (IO_C_X_START + 2); localparam IO_D_X_END = (IO_D_X_START -1); localparam MSB_BURST_PEND_PO = 3; localparam MSB_BURST_PEND_PI = 7; localparam MSB_RANK_SEL_I = MSB_BURST_PEND_PI + 8; localparam PHASER_CTL_BUS_WIDTH = MSB_RANK_SEL_I + 1; wire [1:0] oserdes_dqs; wire [1:0] oserdes_dqs_ts; wire [1:0] oserdes_dq_ts; wire [PHASER_CTL_BUS_WIDTH-1:0] phaser_ctl_bus; wire [7:0] in_rank; wire [11:0] IO_A; wire [11:0] IO_B; wire [11:0] IO_C; wire [11:0] IO_D; wire [319:0] phy_din_remap; reg A_po_counter_read_en; wire [8:0] A_po_counter_read_val; reg A_pi_counter_read_en; wire [5:0] A_pi_counter_read_val; wire A_pi_fine_overflow; wire A_po_coarse_overflow; wire A_po_fine_overflow; wire A_pi_dqs_found; wire A_pi_dqs_out_of_range; wire A_pi_phase_locked; wire A_pi_iserdes_rst; reg A_pi_fine_enable; reg A_pi_fine_inc; reg A_pi_counter_load_en; reg [5:0] A_pi_counter_load_val; reg A_pi_rst_dqs_find; reg A_po_fine_enable; reg A_po_coarse_enable; (* keep = "true", max_fanout = 3 *) reg A_po_fine_inc /* synthesis syn_maxfan = 3 */; reg A_po_sel_fine_oclk_delay; reg A_po_coarse_inc; reg A_po_counter_load_en; reg [8:0] A_po_counter_load_val; wire A_rclk; reg A_idelay_ce; reg A_idelay_ld; reg B_po_counter_read_en; wire [8:0] B_po_counter_read_val; reg B_pi_counter_read_en; wire [5:0] B_pi_counter_read_val; wire B_pi_fine_overflow; wire B_po_coarse_overflow; wire B_po_fine_overflow; wire B_pi_phase_locked; wire B_pi_iserdes_rst; wire B_pi_dqs_found; wire B_pi_dqs_out_of_range; reg B_pi_fine_enable; reg B_pi_fine_inc; reg B_pi_counter_load_en; reg [5:0] B_pi_counter_load_val; reg B_pi_rst_dqs_find; reg B_po_fine_enable; reg B_po_coarse_enable; (* keep = "true", max_fanout = 3 *) reg B_po_fine_inc /* synthesis syn_maxfan = 3 */; reg B_po_coarse_inc; reg B_po_sel_fine_oclk_delay; reg B_po_counter_load_en; reg [8:0] B_po_counter_load_val; wire B_rclk; reg B_idelay_ce; reg B_idelay_ld; reg C_pi_fine_inc; reg D_pi_fine_inc; reg C_pi_fine_enable; reg D_pi_fine_enable; reg C_po_counter_load_en; reg D_po_counter_load_en; reg C_po_coarse_inc; reg D_po_coarse_inc; (* keep = "true", max_fanout = 3 *) reg C_po_fine_inc /* synthesis syn_maxfan = 3 */; (* keep = "true", max_fanout = 3 *) reg D_po_fine_inc /* synthesis syn_maxfan = 3 */; reg C_po_sel_fine_oclk_delay; reg D_po_sel_fine_oclk_delay; reg [5:0] C_pi_counter_load_val; reg [5:0] D_pi_counter_load_val; reg [8:0] C_po_counter_load_val; reg [8:0] D_po_counter_load_val; reg C_po_coarse_enable; reg D_po_coarse_enable; reg C_po_fine_enable; reg D_po_fine_enable; wire C_po_coarse_overflow; wire D_po_coarse_overflow; wire C_po_fine_overflow; wire D_po_fine_overflow; wire [8:0] C_po_counter_read_val; wire [8:0] D_po_counter_read_val; reg C_po_counter_read_en; reg D_po_counter_read_en; wire C_pi_dqs_found; wire D_pi_dqs_found; wire C_pi_fine_overflow; wire D_pi_fine_overflow; reg C_pi_counter_read_en; reg D_pi_counter_read_en; reg C_pi_counter_load_en; reg D_pi_counter_load_en; wire C_pi_phase_locked; wire C_pi_iserdes_rst; wire D_pi_phase_locked; wire D_pi_iserdes_rst; wire C_pi_dqs_out_of_range; wire D_pi_dqs_out_of_range; wire [5:0] C_pi_counter_read_val; wire [5:0] D_pi_counter_read_val; wire C_rclk; wire D_rclk; reg C_idelay_ce; reg D_idelay_ce; reg C_idelay_ld; reg D_idelay_ld; reg C_pi_rst_dqs_find; reg D_pi_rst_dqs_find; wire pi_iserdes_rst; wire A_if_empty; wire B_if_empty; wire C_if_empty; wire D_if_empty; wire A_byte_rd_en; wire B_byte_rd_en; wire C_byte_rd_en; wire D_byte_rd_en; wire A_if_a_empty; wire B_if_a_empty; wire C_if_a_empty; wire D_if_a_empty; wire A_if_full; wire B_if_full; wire C_if_full; wire D_if_full; wire A_of_empty; wire B_of_empty; wire C_of_empty; wire D_of_empty; wire A_of_full; wire B_of_full; wire C_of_full; wire D_of_full; wire A_of_ctl_full; wire B_of_ctl_full; wire C_of_ctl_full; wire D_of_ctl_full; wire A_of_data_full; wire B_of_data_full; wire C_of_data_full; wire D_of_data_full; wire A_of_a_full; wire B_of_a_full; wire C_of_a_full; wire D_of_a_full; wire A_pre_fifo_a_full; wire B_pre_fifo_a_full; wire C_pre_fifo_a_full; wire D_pre_fifo_a_full; wire A_of_ctl_a_full; wire B_of_ctl_a_full; wire C_of_ctl_a_full; wire D_of_ctl_a_full; wire A_of_data_a_full; wire B_of_data_a_full; wire C_of_data_a_full; wire D_of_data_a_full; wire A_pre_data_a_full; wire B_pre_data_a_full; wire C_pre_data_a_full; wire D_pre_data_a_full; wire [LP_DDR_CK_WIDTH*6-1:0] A_ddr_clk; // for generation wire [LP_DDR_CK_WIDTH*6-1:0] B_ddr_clk; // wire [LP_DDR_CK_WIDTH*6-1:0] C_ddr_clk; // wire [LP_DDR_CK_WIDTH*6-1:0] D_ddr_clk; // wire [3:0] dummy_data; wire [31:0] _phy_ctl_wd; wire [1:0] phy_encalib; assign pi_dqs_found_all = (! PRESENT_DATA_A | A_pi_dqs_found) & (! PRESENT_DATA_B | B_pi_dqs_found) & (! PRESENT_DATA_C | C_pi_dqs_found) & (! PRESENT_DATA_D | D_pi_dqs_found) ; assign pi_dqs_found_any = ( PRESENT_DATA_A & A_pi_dqs_found) | ( PRESENT_DATA_B & B_pi_dqs_found) | ( PRESENT_DATA_C & C_pi_dqs_found) | ( PRESENT_DATA_D & D_pi_dqs_found) ; assign pi_phase_locked_all = (! PRESENT_DATA_A | A_pi_phase_locked) & (! PRESENT_DATA_B | B_pi_phase_locked) & (! PRESENT_DATA_C | C_pi_phase_locked) & (! PRESENT_DATA_D | D_pi_phase_locked); wire dangling_inputs = (& dummy_data) & input_sink & 1'b0; // this reduces all constant 0 values to 1 signal // which is combined into another signals such that // the other signal isn't changed. The purpose // is to fake the tools into ignoring dangling inputs. // Because it is anded with 1'b0, the contributing signals // are folded as constants or trimmed. assign if_empty = !if_empty_def ? (A_if_empty | B_if_empty | C_if_empty | D_if_empty) : (A_if_empty & B_if_empty & C_if_empty & D_if_empty); assign byte_rd_en = !if_empty_def ? (A_byte_rd_en & B_byte_rd_en & C_byte_rd_en & D_byte_rd_en) : (A_byte_rd_en | B_byte_rd_en | C_byte_rd_en | D_byte_rd_en); assign if_empty_or = (A_if_empty | B_if_empty | C_if_empty | D_if_empty); assign if_empty_and = (A_if_empty & B_if_empty & C_if_empty & D_if_empty); assign if_a_empty = A_if_a_empty | B_if_a_empty | C_if_a_empty | D_if_a_empty; assign if_full = A_if_full | B_if_full | C_if_full | D_if_full ; assign of_empty = A_of_empty & B_of_empty & C_of_empty & D_of_empty; assign of_ctl_full = A_of_ctl_full | B_of_ctl_full | C_of_ctl_full | D_of_ctl_full ; assign of_data_full = A_of_data_full | B_of_data_full | C_of_data_full | D_of_data_full ; assign of_ctl_a_full = A_of_ctl_a_full | B_of_ctl_a_full | C_of_ctl_a_full | D_of_ctl_a_full ; assign of_data_a_full = A_of_data_a_full | B_of_data_a_full | C_of_data_a_full | D_of_data_a_full | dangling_inputs ; assign pre_data_a_full = A_pre_data_a_full | B_pre_data_a_full | C_pre_data_a_full | D_pre_data_a_full; function [79:0] part_select_80; input [319:0] vector; input [1:0] select; begin case (select) 2'b00 : part_select_80[79:0] = vector[1*80-1:0*80]; 2'b01 : part_select_80[79:0] = vector[2*80-1:1*80]; 2'b10 : part_select_80[79:0] = vector[3*80-1:2*80]; 2'b11 : part_select_80[79:0] = vector[4*80-1:3*80]; endcase end endfunction wire [319:0] phy_dout_remap; reg rst_out_trig = 1'b0; reg [31:0] rclk_delay; reg rst_edge1 = 1'b0; reg rst_edge2 = 1'b0; reg rst_edge3 = 1'b0; reg rst_edge_detect = 1'b0; wire rclk_; reg rst_out_start = 1'b0 ; reg rst_primitives=0; reg A_rst_primitives=0; reg B_rst_primitives=0; reg C_rst_primitives=0; reg D_rst_primitives=0; `ifdef USE_PHY_CONTROL_TEST wire [15:0] test_output; wire [15:0] test_input; wire [2:0] test_select=0; wire scan_enable = 0; `endif generate genvar i; if (RCLK_SELECT_LANE == "A") begin assign rclk_ = A_rclk; assign pi_iserdes_rst = A_pi_iserdes_rst; end else if (RCLK_SELECT_LANE == "B") begin assign rclk_ = B_rclk; assign pi_iserdes_rst = B_pi_iserdes_rst; end else if (RCLK_SELECT_LANE == "C") begin assign rclk_ = C_rclk; assign pi_iserdes_rst = C_pi_iserdes_rst; end else if (RCLK_SELECT_LANE == "D") begin assign rclk_ = D_rclk; assign pi_iserdes_rst = D_pi_iserdes_rst; end else begin assign rclk_ = B_rclk; // default end endgenerate assign ddr_clk[LP_DDR_CK_WIDTH*6-1:0] = A_ddr_clk; assign ddr_clk[LP_DDR_CK_WIDTH*12-1:LP_DDR_CK_WIDTH*6] = B_ddr_clk; assign ddr_clk[LP_DDR_CK_WIDTH*18-1:LP_DDR_CK_WIDTH*12] = C_ddr_clk; assign ddr_clk[LP_DDR_CK_WIDTH*24-1:LP_DDR_CK_WIDTH*18] = D_ddr_clk; assign pi_phase_locked_lanes = {(! PRESENT_DATA_A[0] | A_pi_phase_locked), (! PRESENT_DATA_B[0] | B_pi_phase_locked) , (! PRESENT_DATA_C[0] | C_pi_phase_locked) , (! PRESENT_DATA_D[0] | D_pi_phase_locked)}; assign pi_dqs_found_lanes = {D_pi_dqs_found, C_pi_dqs_found, B_pi_dqs_found, A_pi_dqs_found}; // this block scrubs X from rclk_delay[11] reg rclk_delay_11; always @(rclk_delay[11]) begin : rclk_delay_11_blk if ( rclk_delay[11]) rclk_delay_11 = 1; else rclk_delay_11 = 0; end always @(posedge phy_clk or posedge rst ) begin // scrub 4-state values from rclk_delay[11] if ( rst) begin rst_out <= #1 0; end else begin if ( rclk_delay_11) rst_out <= #1 1; end end always @(posedge phy_clk ) begin // phy_ctl_ready drives reset of the system rst_primitives <= !phy_ctl_ready ; A_rst_primitives <= rst_primitives ; B_rst_primitives <= rst_primitives ; C_rst_primitives <= rst_primitives ; D_rst_primitives <= rst_primitives ; rclk_delay <= #1 (rclk_delay << 1) | (!rst_primitives && phyGo); mcGo <= #1 rst_out ; end generate if (BYTE_LANES[0]) begin assign dummy_data[0] = 0; end else begin assign dummy_data[0] = &phy_dout_remap[1*80-1:0*80]; end if (BYTE_LANES[1]) begin assign dummy_data[1] = 0; end else begin assign dummy_data[1] = &phy_dout_remap[2*80-1:1*80]; end if (BYTE_LANES[2]) begin assign dummy_data[2] = 0; end else begin assign dummy_data[2] = &phy_dout_remap[3*80-1:2*80]; end if (BYTE_LANES[3]) begin assign dummy_data[3] = 0; end else begin assign dummy_data[3] = &phy_dout_remap[4*80-1:3*80]; end if (PRESENT_DATA_A) begin assign A_of_data_full = A_of_full; assign A_of_ctl_full = 0; assign A_of_data_a_full = A_of_a_full; assign A_of_ctl_a_full = 0; assign A_pre_data_a_full = A_pre_fifo_a_full; end else begin assign A_of_ctl_full = A_of_full; assign A_of_data_full = 0; assign A_of_ctl_a_full = A_of_a_full; assign A_of_data_a_full = 0; assign A_pre_data_a_full = 0; end if (PRESENT_DATA_B) begin assign B_of_data_full = B_of_full; assign B_of_ctl_full = 0; assign B_of_data_a_full = B_of_a_full; assign B_of_ctl_a_full = 0; assign B_pre_data_a_full = B_pre_fifo_a_full; end else begin assign B_of_ctl_full = B_of_full; assign B_of_data_full = 0; assign B_of_ctl_a_full = B_of_a_full; assign B_of_data_a_full = 0; assign B_pre_data_a_full = 0; end if (PRESENT_DATA_C) begin assign C_of_data_full = C_of_full; assign C_of_ctl_full = 0; assign C_of_data_a_full = C_of_a_full; assign C_of_ctl_a_full = 0; assign C_pre_data_a_full = C_pre_fifo_a_full; end else begin assign C_of_ctl_full = C_of_full; assign C_of_data_full = 0; assign C_of_ctl_a_full = C_of_a_full; assign C_of_data_a_full = 0; assign C_pre_data_a_full = 0; end if (PRESENT_DATA_D) begin assign D_of_data_full = D_of_full; assign D_of_ctl_full = 0; assign D_of_data_a_full = D_of_a_full; assign D_of_ctl_a_full = 0; assign D_pre_data_a_full = D_pre_fifo_a_full; end else begin assign D_of_ctl_full = D_of_full; assign D_of_data_full = 0; assign D_of_ctl_a_full = D_of_a_full; assign D_of_data_a_full = 0; assign D_pre_data_a_full = 0; end // byte lane must exist and be data lane. if (PRESENT_DATA_A ) case ( LANE_REMAP[1:0] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[79:0]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[79:0]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[79:0]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[79:0]; endcase else case ( LANE_REMAP[1:0] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (PRESENT_DATA_B ) case ( LANE_REMAP[5:4] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[159:80]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[159:80]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[159:80]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[159:80]; endcase else if (HIGHEST_LANE > 1) case ( LANE_REMAP[5:4] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (PRESENT_DATA_C) case ( LANE_REMAP[9:8] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[239:160]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[239:160]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[239:160]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[239:160]; endcase else if (HIGHEST_LANE > 2) case ( LANE_REMAP[9:8] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (PRESENT_DATA_D ) case ( LANE_REMAP[13:12] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[319:240]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[319:240]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[319:240]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[319:240]; endcase else if (HIGHEST_LANE > 3) case ( LANE_REMAP[13:12] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (HIGHEST_LANE > 1) assign _phy_ctl_wd = {phy_ctl_wd[31:23], data_offset, phy_ctl_wd[16:0]}; if (HIGHEST_LANE == 1) assign _phy_ctl_wd_ = phy_ctl_wd; //BUFR #(.BUFR_DIVIDE ("1")) rclk_buf(.I(rclk_), .O(rclk), .CE (1'b1), .CLR (pi_iserdes_rst)); BUFIO rclk_buf(.I(rclk_), .O(rclk) ); if ( BYTE_LANES[0] ) begin : ddr_byte_lane_A assign phy_dout_remap[79:0] = part_select_80(phy_dout, (LANE_REMAP[1:0])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("A"), .PO_DATA_CTL (PC_DATA_CTL_N[0] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[11:0]), .BITLANES_OUTONLY (BITLANES_OUTONLY[11:0]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (A_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (A_PI_BURST_MODE), .PI_CLKOUT_DIV (A_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (A_PI_FREQ_REF_DIV), .PI_FINE_DELAY (A_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (A_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (A_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (A_PO_CLKOUT_DIV), .PO_FINE_DELAY (A_PO_FINE_DELAY), .PO_COARSE_BYPASS (A_PO_COARSE_BYPASS), .PO_COARSE_DELAY (A_PO_COARSE_DELAY), .PO_OCLK_DELAY (A_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (A_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (A_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (A_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (A_OS_DATA_RATE), .OSERDES_DATA_WIDTH (A_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (A_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (A_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_A( .mem_dq_out (mem_dq_out[11:0]), .mem_dq_ts (mem_dq_ts[11:0]), .mem_dq_in (mem_dq_in[9:0]), .mem_dqs_out (mem_dqs_out[0]), .mem_dqs_ts (mem_dqs_ts[0]), .mem_dqs_in (mem_dqs_in[0]), .rst (A_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (A_ddr_clk), .rclk (A_rclk), .pi_dqs_found (A_pi_dqs_found), .dqs_out_of_range (A_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (A_if_a_empty), .if_empty (A_if_empty), .if_a_full (if_a_full), .if_full (A_if_full), .of_a_empty (of_a_empty), .of_empty (A_of_empty), .of_a_full (A_of_a_full), .of_full (A_of_full), .pre_fifo_a_full (A_pre_fifo_a_full), .phy_din (phy_din_remap[79:0]), .phy_dout (phy_dout_remap[79:0]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .if_rst (if_rst), .byte_rd_en_oth_lanes ({B_byte_rd_en,C_byte_rd_en,D_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (A_byte_rd_en), // calibration signals .idelay_inc (idelay_inc), .idelay_ce (A_idelay_ce), .idelay_ld (A_idelay_ld), .pi_rst_dqs_find (A_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (A_po_fine_enable), .po_coarse_enable (A_po_coarse_enable), .po_fine_inc (A_po_fine_inc), .po_coarse_inc (A_po_coarse_inc), .po_counter_load_en (A_po_counter_load_en), .po_counter_read_en (A_po_counter_read_en), .po_counter_load_val (A_po_counter_load_val), .po_coarse_overflow (A_po_coarse_overflow), .po_fine_overflow (A_po_fine_overflow), .po_counter_read_val (A_po_counter_read_val), .po_sel_fine_oclk_delay(A_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (A_pi_fine_enable), .pi_fine_inc (A_pi_fine_inc), .pi_counter_load_en (A_pi_counter_load_en), .pi_counter_read_en (A_pi_counter_read_en), .pi_counter_load_val (A_pi_counter_load_val), .pi_fine_overflow (A_pi_fine_overflow), .pi_counter_read_val (A_pi_counter_read_val), .pi_iserdes_rst (A_pi_iserdes_rst), .pi_phase_locked (A_pi_phase_locked) ); end else begin : no_ddr_byte_lane_A assign A_of_a_full = 1'b0; assign A_of_full = 1'b0; assign A_pre_fifo_a_full = 1'b0; assign A_if_empty = 1'b0; assign A_byte_rd_en = 1'b1; assign A_if_a_empty = 1'b0; assign A_pi_phase_locked = 1; assign A_pi_dqs_found = 1; assign A_rclk = 0; assign A_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign A_pi_counter_read_val = 0; assign A_po_counter_read_val = 0; assign A_pi_fine_overflow = 0; assign A_po_coarse_overflow = 0; assign A_po_fine_overflow = 0; end if ( BYTE_LANES[1] ) begin : ddr_byte_lane_B assign phy_dout_remap[159:80] = part_select_80(phy_dout, (LANE_REMAP[5:4])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("B"), .PO_DATA_CTL (PC_DATA_CTL_N[1] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[23:12]), .BITLANES_OUTONLY (BITLANES_OUTONLY[23:12]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (B_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (B_PI_BURST_MODE), .PI_CLKOUT_DIV (B_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (B_PI_FREQ_REF_DIV), .PI_FINE_DELAY (B_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (B_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (B_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (B_PO_CLKOUT_DIV), .PO_FINE_DELAY (B_PO_FINE_DELAY), .PO_COARSE_BYPASS (B_PO_COARSE_BYPASS), .PO_COARSE_DELAY (B_PO_COARSE_DELAY), .PO_OCLK_DELAY (B_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (B_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (B_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (B_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (B_OS_DATA_RATE), .OSERDES_DATA_WIDTH (B_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (B_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (B_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_B( .mem_dq_out (mem_dq_out[23:12]), .mem_dq_ts (mem_dq_ts[23:12]), .mem_dq_in (mem_dq_in[19:10]), .mem_dqs_out (mem_dqs_out[1]), .mem_dqs_ts (mem_dqs_ts[1]), .mem_dqs_in (mem_dqs_in[1]), .rst (B_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (B_ddr_clk), .rclk (B_rclk), .pi_dqs_found (B_pi_dqs_found), .dqs_out_of_range (B_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (B_if_a_empty), .if_empty (B_if_empty), .if_a_full (/*if_a_full*/), .if_full (B_if_full), .of_a_empty (/*of_a_empty*/), .of_empty (B_of_empty), .of_a_full (B_of_a_full), .of_full (B_of_full), .pre_fifo_a_full (B_pre_fifo_a_full), .phy_din (phy_din_remap[159:80]), .phy_dout (phy_dout_remap[159:80]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .if_rst (if_rst), .byte_rd_en_oth_lanes ({A_byte_rd_en,C_byte_rd_en,D_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (B_byte_rd_en), // calibration signals .idelay_inc (idelay_inc), .idelay_ce (B_idelay_ce), .idelay_ld (B_idelay_ld), .pi_rst_dqs_find (B_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (B_po_fine_enable), .po_coarse_enable (B_po_coarse_enable), .po_fine_inc (B_po_fine_inc), .po_coarse_inc (B_po_coarse_inc), .po_counter_load_en (B_po_counter_load_en), .po_counter_read_en (B_po_counter_read_en), .po_counter_load_val (B_po_counter_load_val), .po_coarse_overflow (B_po_coarse_overflow), .po_fine_overflow (B_po_fine_overflow), .po_counter_read_val (B_po_counter_read_val), .po_sel_fine_oclk_delay(B_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (B_pi_fine_enable), .pi_fine_inc (B_pi_fine_inc), .pi_counter_load_en (B_pi_counter_load_en), .pi_counter_read_en (B_pi_counter_read_en), .pi_counter_load_val (B_pi_counter_load_val), .pi_fine_overflow (B_pi_fine_overflow), .pi_counter_read_val (B_pi_counter_read_val), .pi_iserdes_rst (B_pi_iserdes_rst), .pi_phase_locked (B_pi_phase_locked) ); end else begin : no_ddr_byte_lane_B assign B_of_a_full = 1'b0; assign B_of_full = 1'b0; assign B_pre_fifo_a_full = 1'b0; assign B_if_empty = 1'b0; assign B_if_a_empty = 1'b0; assign B_byte_rd_en = 1'b1; assign B_pi_phase_locked = 1; assign B_pi_dqs_found = 1; assign B_rclk = 0; assign B_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign B_pi_counter_read_val = 0; assign B_po_counter_read_val = 0; assign B_pi_fine_overflow = 0; assign B_po_coarse_overflow = 0; assign B_po_fine_overflow = 0; end if ( BYTE_LANES[2] ) begin : ddr_byte_lane_C assign phy_dout_remap[239:160] = part_select_80(phy_dout, (LANE_REMAP[9:8])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("C"), .PO_DATA_CTL (PC_DATA_CTL_N[2] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[35:24]), .BITLANES_OUTONLY (BITLANES_OUTONLY[35:24]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (C_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (C_PI_BURST_MODE), .PI_CLKOUT_DIV (C_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (C_PI_FREQ_REF_DIV), .PI_FINE_DELAY (C_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (C_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (C_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (C_PO_CLKOUT_DIV), .PO_FINE_DELAY (C_PO_FINE_DELAY), .PO_COARSE_BYPASS (C_PO_COARSE_BYPASS), .PO_COARSE_DELAY (C_PO_COARSE_DELAY), .PO_OCLK_DELAY (C_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (C_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (C_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (C_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (C_OS_DATA_RATE), .OSERDES_DATA_WIDTH (C_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (C_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (C_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_C( .mem_dq_out (mem_dq_out[35:24]), .mem_dq_ts (mem_dq_ts[35:24]), .mem_dq_in (mem_dq_in[29:20]), .mem_dqs_out (mem_dqs_out[2]), .mem_dqs_ts (mem_dqs_ts[2]), .mem_dqs_in (mem_dqs_in[2]), .rst (C_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (C_ddr_clk), .rclk (C_rclk), .pi_dqs_found (C_pi_dqs_found), .dqs_out_of_range (C_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (C_if_a_empty), .if_empty (C_if_empty), .if_a_full (/*if_a_full*/), .if_full (C_if_full), .of_a_empty (/*of_a_empty*/), .of_empty (C_of_empty), .of_a_full (C_of_a_full), .of_full (C_of_full), .pre_fifo_a_full (C_pre_fifo_a_full), .phy_din (phy_din_remap[239:160]), .phy_dout (phy_dout_remap[239:160]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .if_rst (if_rst), .byte_rd_en_oth_lanes ({A_byte_rd_en,B_byte_rd_en,D_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (C_byte_rd_en), // calibration signals .idelay_inc (idelay_inc), .idelay_ce (C_idelay_ce), .idelay_ld (C_idelay_ld), .pi_rst_dqs_find (C_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (C_po_fine_enable), .po_coarse_enable (C_po_coarse_enable), .po_fine_inc (C_po_fine_inc), .po_coarse_inc (C_po_coarse_inc), .po_counter_load_en (C_po_counter_load_en), .po_counter_read_en (C_po_counter_read_en), .po_counter_load_val (C_po_counter_load_val), .po_coarse_overflow (C_po_coarse_overflow), .po_fine_overflow (C_po_fine_overflow), .po_counter_read_val (C_po_counter_read_val), .po_sel_fine_oclk_delay(C_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (C_pi_fine_enable), .pi_fine_inc (C_pi_fine_inc), .pi_counter_load_en (C_pi_counter_load_en), .pi_counter_read_en (C_pi_counter_read_en), .pi_counter_load_val (C_pi_counter_load_val), .pi_fine_overflow (C_pi_fine_overflow), .pi_counter_read_val (C_pi_counter_read_val), .pi_iserdes_rst (C_pi_iserdes_rst), .pi_phase_locked (C_pi_phase_locked) ); end else begin : no_ddr_byte_lane_C assign C_of_a_full = 1'b0; assign C_of_full = 1'b0; assign C_pre_fifo_a_full = 1'b0; assign C_if_empty = 1'b0; assign C_byte_rd_en = 1'b1; assign C_if_a_empty = 1'b0; assign C_pi_phase_locked = 1; assign C_pi_dqs_found = 1; assign C_rclk = 0; assign C_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign C_pi_counter_read_val = 0; assign C_po_counter_read_val = 0; assign C_pi_fine_overflow = 0; assign C_po_coarse_overflow = 0; assign C_po_fine_overflow = 0; end if ( BYTE_LANES[3] ) begin : ddr_byte_lane_D assign phy_dout_remap[319:240] = part_select_80(phy_dout, (LANE_REMAP[13:12])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("D"), .PO_DATA_CTL (PC_DATA_CTL_N[3] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[47:36]), .BITLANES_OUTONLY (BITLANES_OUTONLY[47:36]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (D_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (D_PI_BURST_MODE), .PI_CLKOUT_DIV (D_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (D_PI_FREQ_REF_DIV), .PI_FINE_DELAY (D_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (D_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (D_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (D_PO_CLKOUT_DIV), .PO_FINE_DELAY (D_PO_FINE_DELAY), .PO_COARSE_BYPASS (D_PO_COARSE_BYPASS), .PO_COARSE_DELAY (D_PO_COARSE_DELAY), .PO_OCLK_DELAY (D_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (D_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (D_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (D_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (D_OS_DATA_RATE), .OSERDES_DATA_WIDTH (D_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (D_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (D_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_D( .mem_dq_out (mem_dq_out[47:36]), .mem_dq_ts (mem_dq_ts[47:36]), .mem_dq_in (mem_dq_in[39:30]), .mem_dqs_out (mem_dqs_out[3]), .mem_dqs_ts (mem_dqs_ts[3]), .mem_dqs_in (mem_dqs_in[3]), .rst (D_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (D_ddr_clk), .rclk (D_rclk), .pi_dqs_found (D_pi_dqs_found), .dqs_out_of_range (D_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (D_if_a_empty), .if_empty (D_if_empty), .if_a_full (/*if_a_full*/), .if_full (D_if_full), .of_a_empty (/*of_a_empty*/), .of_empty (D_of_empty), .of_a_full (D_of_a_full), .of_full (D_of_full), .pre_fifo_a_full (D_pre_fifo_a_full), .phy_din (phy_din_remap[319:240]), .phy_dout (phy_dout_remap[319:240]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .idelay_inc (idelay_inc), .idelay_ce (D_idelay_ce), .idelay_ld (D_idelay_ld), .if_rst (if_rst), .byte_rd_en_oth_lanes ({A_byte_rd_en,B_byte_rd_en,C_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (D_byte_rd_en), // calibration signals .pi_rst_dqs_find (D_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (D_po_fine_enable), .po_coarse_enable (D_po_coarse_enable), .po_fine_inc (D_po_fine_inc), .po_coarse_inc (D_po_coarse_inc), .po_counter_load_en (D_po_counter_load_en), .po_counter_read_en (D_po_counter_read_en), .po_counter_load_val (D_po_counter_load_val), .po_coarse_overflow (D_po_coarse_overflow), .po_fine_overflow (D_po_fine_overflow), .po_counter_read_val (D_po_counter_read_val), .po_sel_fine_oclk_delay(D_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (D_pi_fine_enable), .pi_fine_inc (D_pi_fine_inc), .pi_counter_load_en (D_pi_counter_load_en), .pi_counter_read_en (D_pi_counter_read_en), .pi_counter_load_val (D_pi_counter_load_val), .pi_fine_overflow (D_pi_fine_overflow), .pi_counter_read_val (D_pi_counter_read_val), .pi_iserdes_rst (D_pi_iserdes_rst), .pi_phase_locked (D_pi_phase_locked) ); end else begin : no_ddr_byte_lane_D assign D_of_a_full = 1'b0; assign D_of_full = 1'b0; assign D_pre_fifo_a_full = 1'b0; assign D_if_empty = 1'b0; assign D_byte_rd_en = 1'b1; assign D_if_a_empty = 1'b0; assign D_rclk = 0; assign D_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign D_pi_dqs_found = 1; assign D_pi_phase_locked = 1; assign D_pi_counter_read_val = 0; assign D_po_counter_read_val = 0; assign D_pi_fine_overflow = 0; assign D_po_coarse_overflow = 0; assign D_po_fine_overflow = 0; end endgenerate assign phaser_ctl_bus[MSB_RANK_SEL_I : MSB_RANK_SEL_I - 7] = in_rank; PHY_CONTROL #( .AO_WRLVL_EN ( PC_AO_WRLVL_EN), .AO_TOGGLE ( PC_AO_TOGGLE), .BURST_MODE ( PC_BURST_MODE), .CO_DURATION ( PC_CO_DURATION ), .CLK_RATIO ( PC_CLK_RATIO), .DATA_CTL_A_N ( PC_DATA_CTL_A), .DATA_CTL_B_N ( PC_DATA_CTL_B), .DATA_CTL_C_N ( PC_DATA_CTL_C), .DATA_CTL_D_N ( PC_DATA_CTL_D), .DI_DURATION ( PC_DI_DURATION ), .DO_DURATION ( PC_DO_DURATION ), .EVENTS_DELAY ( PC_EVENTS_DELAY), .FOUR_WINDOW_CLOCKS ( PC_FOUR_WINDOW_CLOCKS), .MULTI_REGION ( PC_MULTI_REGION ), .PHY_COUNT_ENABLE ( PC_PHY_COUNT_EN), .DISABLE_SEQ_MATCH ( PC_DISABLE_SEQ_MATCH), .SYNC_MODE ( PC_SYNC_MODE), .CMD_OFFSET ( PC_CMD_OFFSET), .RD_CMD_OFFSET_0 ( PC_RD_CMD_OFFSET_0), .RD_CMD_OFFSET_1 ( PC_RD_CMD_OFFSET_1), .RD_CMD_OFFSET_2 ( PC_RD_CMD_OFFSET_2), .RD_CMD_OFFSET_3 ( PC_RD_CMD_OFFSET_3), .RD_DURATION_0 ( PC_RD_DURATION_0), .RD_DURATION_1 ( PC_RD_DURATION_1), .RD_DURATION_2 ( PC_RD_DURATION_2), .RD_DURATION_3 ( PC_RD_DURATION_3), .WR_CMD_OFFSET_0 ( PC_WR_CMD_OFFSET_0), .WR_CMD_OFFSET_1 ( PC_WR_CMD_OFFSET_1), .WR_CMD_OFFSET_2 ( PC_WR_CMD_OFFSET_2), .WR_CMD_OFFSET_3 ( PC_WR_CMD_OFFSET_3), .WR_DURATION_0 ( PC_WR_DURATION_0), .WR_DURATION_1 ( PC_WR_DURATION_1), .WR_DURATION_2 ( PC_WR_DURATION_2), .WR_DURATION_3 ( PC_WR_DURATION_3) ) phy_control_i ( .AUXOUTPUT (aux_out), .INBURSTPENDING (phaser_ctl_bus[MSB_BURST_PEND_PI:MSB_BURST_PEND_PI-3]), .INRANKA (in_rank[1:0]), .INRANKB (in_rank[3:2]), .INRANKC (in_rank[5:4]), .INRANKD (in_rank[7:6]), .OUTBURSTPENDING (phaser_ctl_bus[MSB_BURST_PEND_PO:MSB_BURST_PEND_PO-3]), .PCENABLECALIB (phy_encalib), .PHYCTLALMOSTFULL (phy_ctl_a_full), .PHYCTLEMPTY (phy_ctl_empty), .PHYCTLFULL (phy_ctl_full), .PHYCTLREADY (phy_ctl_ready), .MEMREFCLK (mem_refclk), .PHYCLK (phy_ctl_clk), .PHYCTLMSTREMPTY (phy_ctl_mstr_empty), .PHYCTLWD (_phy_ctl_wd), .PHYCTLWRENABLE (phy_ctl_wr), .PLLLOCK (pll_lock), .REFDLLLOCK (ref_dll_lock), // is reset while !locked .RESET (rst), .SYNCIN (sync_pulse), .READCALIBENABLE (phy_read_calib), .WRITECALIBENABLE (phy_write_calib) `ifdef USE_PHY_CONTROL_TEST , .TESTINPUT (16'b0), .TESTOUTPUT (test_output), .TESTSELECT (test_select), .SCANENABLEN (scan_enable) `endif ); // register outputs to give extra slack in timing always @(posedge phy_clk ) begin case (calib_sel[1:0]) 2'h0: begin po_coarse_overflow <= #1 A_po_coarse_overflow; po_fine_overflow <= #1 A_po_fine_overflow; po_counter_read_val <= #1 A_po_counter_read_val; pi_fine_overflow <= #1 A_pi_fine_overflow; pi_counter_read_val<= #1 A_pi_counter_read_val; pi_phase_locked <= #1 A_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 A_pi_dqs_found; pi_dqs_out_of_range <= #1 A_pi_dqs_out_of_range; end 2'h1: begin po_coarse_overflow <= #1 B_po_coarse_overflow; po_fine_overflow <= #1 B_po_fine_overflow; po_counter_read_val <= #1 B_po_counter_read_val; pi_fine_overflow <= #1 B_pi_fine_overflow; pi_counter_read_val <= #1 B_pi_counter_read_val; pi_phase_locked <= #1 B_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 B_pi_dqs_found; pi_dqs_out_of_range <= #1 B_pi_dqs_out_of_range; end 2'h2: begin po_coarse_overflow <= #1 C_po_coarse_overflow; po_fine_overflow <= #1 C_po_fine_overflow; po_counter_read_val <= #1 C_po_counter_read_val; pi_fine_overflow <= #1 C_pi_fine_overflow; pi_counter_read_val <= #1 C_pi_counter_read_val; pi_phase_locked <= #1 C_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 C_pi_dqs_found; pi_dqs_out_of_range <= #1 C_pi_dqs_out_of_range; end 2'h3: begin po_coarse_overflow <= #1 D_po_coarse_overflow; po_fine_overflow <= #1 D_po_fine_overflow; po_counter_read_val <= #1 D_po_counter_read_val; pi_fine_overflow <= #1 D_pi_fine_overflow; pi_counter_read_val <= #1 D_pi_counter_read_val; pi_phase_locked <= #1 D_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 D_pi_dqs_found; pi_dqs_out_of_range <= #1 D_pi_dqs_out_of_range; end default: begin po_coarse_overflow <= po_coarse_overflow; end endcase end wire B_mux_ctrl; wire C_mux_ctrl; wire D_mux_ctrl; generate if (HIGHEST_LANE > 1) assign B_mux_ctrl = ( !calib_zero_lanes[1] && ( ! calib_zero_ctrl || DATA_CTL_N[1])); else assign B_mux_ctrl = 0; if (HIGHEST_LANE > 2) assign C_mux_ctrl = ( !calib_zero_lanes[2] && (! calib_zero_ctrl || DATA_CTL_N[2])); else assign C_mux_ctrl = 0; if (HIGHEST_LANE > 3) assign D_mux_ctrl = ( !calib_zero_lanes[3] && ( ! calib_zero_ctrl || DATA_CTL_N[3])); else assign D_mux_ctrl = 0; endgenerate always @(*) begin A_pi_fine_enable = 0; A_pi_fine_inc = 0; A_pi_counter_load_en = 0; A_pi_counter_read_en = 0; A_pi_counter_load_val = 0; A_pi_rst_dqs_find = 0; A_po_fine_enable = 0; A_po_coarse_enable = 0; A_po_fine_inc = 0; A_po_coarse_inc = 0; A_po_counter_load_en = 0; A_po_counter_read_en = 0; A_po_counter_load_val = 0; A_po_sel_fine_oclk_delay = 0; A_idelay_ce = 0; A_idelay_ld = 0; B_pi_fine_enable = 0; B_pi_fine_inc = 0; B_pi_counter_load_en = 0; B_pi_counter_read_en = 0; B_pi_counter_load_val = 0; B_pi_rst_dqs_find = 0; B_po_fine_enable = 0; B_po_coarse_enable = 0; B_po_fine_inc = 0; B_po_coarse_inc = 0; B_po_counter_load_en = 0; B_po_counter_read_en = 0; B_po_counter_load_val = 0; B_po_sel_fine_oclk_delay = 0; B_idelay_ce = 0; B_idelay_ld = 0; C_pi_fine_enable = 0; C_pi_fine_inc = 0; C_pi_counter_load_en = 0; C_pi_counter_read_en = 0; C_pi_counter_load_val = 0; C_pi_rst_dqs_find = 0; C_po_fine_enable = 0; C_po_coarse_enable = 0; C_po_fine_inc = 0; C_po_coarse_inc = 0; C_po_counter_load_en = 0; C_po_counter_read_en = 0; C_po_counter_load_val = 0; C_po_sel_fine_oclk_delay = 0; C_idelay_ce = 0; C_idelay_ld = 0; D_pi_fine_enable = 0; D_pi_fine_inc = 0; D_pi_counter_load_en = 0; D_pi_counter_read_en = 0; D_pi_counter_load_val = 0; D_pi_rst_dqs_find = 0; D_po_fine_enable = 0; D_po_coarse_enable = 0; D_po_fine_inc = 0; D_po_coarse_inc = 0; D_po_counter_load_en = 0; D_po_counter_read_en = 0; D_po_counter_load_val = 0; D_po_sel_fine_oclk_delay = 0; D_idelay_ce = 0; D_idelay_ld = 0; if ( calib_sel[2]) begin // if this is asserted, all calib signals are deasserted A_pi_fine_enable = 0; A_pi_fine_inc = 0; A_pi_counter_load_en = 0; A_pi_counter_read_en = 0; A_pi_counter_load_val = 0; A_pi_rst_dqs_find = 0; A_po_fine_enable = 0; A_po_coarse_enable = 0; A_po_fine_inc = 0; A_po_coarse_inc = 0; A_po_counter_load_en = 0; A_po_counter_read_en = 0; A_po_counter_load_val = 0; A_po_sel_fine_oclk_delay = 0; A_idelay_ce = 0; A_idelay_ld = 0; B_pi_fine_enable = 0; B_pi_fine_inc = 0; B_pi_counter_load_en = 0; B_pi_counter_read_en = 0; B_pi_counter_load_val = 0; B_pi_rst_dqs_find = 0; B_po_fine_enable = 0; B_po_coarse_enable = 0; B_po_fine_inc = 0; B_po_coarse_inc = 0; B_po_counter_load_en = 0; B_po_counter_read_en = 0; B_po_counter_load_val = 0; B_po_sel_fine_oclk_delay = 0; B_idelay_ce = 0; B_idelay_ld = 0; C_pi_fine_enable = 0; C_pi_fine_inc = 0; C_pi_counter_load_en = 0; C_pi_counter_read_en = 0; C_pi_counter_load_val = 0; C_pi_rst_dqs_find = 0; C_po_fine_enable = 0; C_po_coarse_enable = 0; C_po_fine_inc = 0; C_po_coarse_inc = 0; C_po_counter_load_en = 0; C_po_counter_read_en = 0; C_po_counter_load_val = 0; C_po_sel_fine_oclk_delay = 0; C_idelay_ce = 0; C_idelay_ld = 0; D_pi_fine_enable = 0; D_pi_fine_inc = 0; D_pi_counter_load_en = 0; D_pi_counter_read_en = 0; D_pi_counter_load_val = 0; D_pi_rst_dqs_find = 0; D_po_fine_enable = 0; D_po_coarse_enable = 0; D_po_fine_inc = 0; D_po_coarse_inc = 0; D_po_counter_load_en = 0; D_po_counter_read_en = 0; D_po_counter_load_val = 0; D_po_sel_fine_oclk_delay = 0; D_idelay_ce = 0; D_idelay_ld = 0; end else if (calib_in_common) begin // if this is asserted, each signal is broadcast to all phasers // in common if ( !calib_zero_lanes[0] && (! calib_zero_ctrl || DATA_CTL_N[0])) begin A_pi_fine_enable = pi_fine_enable; A_pi_fine_inc = pi_fine_inc; A_pi_counter_load_en = pi_counter_load_en; A_pi_counter_read_en = pi_counter_read_en; A_pi_counter_load_val = pi_counter_load_val; A_pi_rst_dqs_find = pi_rst_dqs_find; A_po_fine_enable = po_fine_enable; A_po_coarse_enable = po_coarse_enable; A_po_fine_inc = po_fine_inc; A_po_coarse_inc = po_coarse_inc; A_po_counter_load_en = po_counter_load_en; A_po_counter_read_en = po_counter_read_en; A_po_counter_load_val = po_counter_load_val; A_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; A_idelay_ce = idelay_ce; A_idelay_ld = idelay_ld; end if ( B_mux_ctrl) begin B_pi_fine_enable = pi_fine_enable; B_pi_fine_inc = pi_fine_inc; B_pi_counter_load_en = pi_counter_load_en; B_pi_counter_read_en = pi_counter_read_en; B_pi_counter_load_val = pi_counter_load_val; B_pi_rst_dqs_find = pi_rst_dqs_find; B_po_fine_enable = po_fine_enable; B_po_coarse_enable = po_coarse_enable; B_po_fine_inc = po_fine_inc; B_po_coarse_inc = po_coarse_inc; B_po_counter_load_en = po_counter_load_en; B_po_counter_read_en = po_counter_read_en; B_po_counter_load_val = po_counter_load_val; B_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; B_idelay_ce = idelay_ce; B_idelay_ld = idelay_ld; end if ( C_mux_ctrl) begin C_pi_fine_enable = pi_fine_enable; C_pi_fine_inc = pi_fine_inc; C_pi_counter_load_en = pi_counter_load_en; C_pi_counter_read_en = pi_counter_read_en; C_pi_counter_load_val = pi_counter_load_val; C_pi_rst_dqs_find = pi_rst_dqs_find; C_po_fine_enable = po_fine_enable; C_po_coarse_enable = po_coarse_enable; C_po_fine_inc = po_fine_inc; C_po_coarse_inc = po_coarse_inc; C_po_counter_load_en = po_counter_load_en; C_po_counter_read_en = po_counter_read_en; C_po_counter_load_val = po_counter_load_val; C_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; C_idelay_ce = idelay_ce; C_idelay_ld = idelay_ld; end if ( D_mux_ctrl) begin D_pi_fine_enable = pi_fine_enable; D_pi_fine_inc = pi_fine_inc; D_pi_counter_load_en = pi_counter_load_en; D_pi_counter_read_en = pi_counter_read_en; D_pi_counter_load_val = pi_counter_load_val; D_pi_rst_dqs_find = pi_rst_dqs_find; D_po_fine_enable = po_fine_enable; D_po_coarse_enable = po_coarse_enable; D_po_fine_inc = po_fine_inc; D_po_coarse_inc = po_coarse_inc; D_po_counter_load_en = po_counter_load_en; D_po_counter_read_en = po_counter_read_en; D_po_counter_load_val = po_counter_load_val; D_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; D_idelay_ce = idelay_ce; D_idelay_ld = idelay_ld; end end else begin // otherwise, only a single phaser is selected case (calib_sel[1:0]) 0: begin A_pi_fine_enable = pi_fine_enable; A_pi_fine_inc = pi_fine_inc; A_pi_counter_load_en = pi_counter_load_en; A_pi_counter_read_en = pi_counter_read_en; A_pi_counter_load_val = pi_counter_load_val; A_pi_rst_dqs_find = pi_rst_dqs_find; A_po_fine_enable = po_fine_enable; A_po_coarse_enable = po_coarse_enable; A_po_fine_inc = po_fine_inc; A_po_coarse_inc = po_coarse_inc; A_po_counter_load_en = po_counter_load_en; A_po_counter_read_en = po_counter_read_en; A_po_counter_load_val = po_counter_load_val; A_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; A_idelay_ce = idelay_ce; A_idelay_ld = idelay_ld; end 1: begin B_pi_fine_enable = pi_fine_enable; B_pi_fine_inc = pi_fine_inc; B_pi_counter_load_en = pi_counter_load_en; B_pi_counter_read_en = pi_counter_read_en; B_pi_counter_load_val = pi_counter_load_val; B_pi_rst_dqs_find = pi_rst_dqs_find; B_po_fine_enable = po_fine_enable; B_po_coarse_enable = po_coarse_enable; B_po_fine_inc = po_fine_inc; B_po_coarse_inc = po_coarse_inc; B_po_counter_load_en = po_counter_load_en; B_po_counter_read_en = po_counter_read_en; B_po_counter_load_val = po_counter_load_val; B_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; B_idelay_ce = idelay_ce; B_idelay_ld = idelay_ld; end 2: begin C_pi_fine_enable = pi_fine_enable; C_pi_fine_inc = pi_fine_inc; C_pi_counter_load_en = pi_counter_load_en; C_pi_counter_read_en = pi_counter_read_en; C_pi_counter_load_val = pi_counter_load_val; C_pi_rst_dqs_find = pi_rst_dqs_find; C_po_fine_enable = po_fine_enable; C_po_coarse_enable = po_coarse_enable; C_po_fine_inc = po_fine_inc; C_po_coarse_inc = po_coarse_inc; C_po_counter_load_en = po_counter_load_en; C_po_counter_read_en = po_counter_read_en; C_po_counter_load_val = po_counter_load_val; C_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; C_idelay_ce = idelay_ce; C_idelay_ld = idelay_ld; end 3: begin D_pi_fine_enable = pi_fine_enable; D_pi_fine_inc = pi_fine_inc; D_pi_counter_load_en = pi_counter_load_en; D_pi_counter_read_en = pi_counter_read_en; D_pi_counter_load_val = pi_counter_load_val; D_pi_rst_dqs_find = pi_rst_dqs_find; D_po_fine_enable = po_fine_enable; D_po_coarse_enable = po_coarse_enable; D_po_fine_inc = po_fine_inc; D_po_coarse_inc = po_coarse_inc; D_po_counter_load_en = po_counter_load_en; D_po_counter_load_val = po_counter_load_val; D_po_counter_read_en = po_counter_read_en; D_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; D_idelay_ce = idelay_ce; D_idelay_ld = idelay_ld; end endcase end end //obligatory phaser-ref PHASER_REF phaser_ref_i( .LOCKED (ref_dll_lock), .CLKIN (freq_refclk), .PWRDWN (1'b0), .RST ( ! pll_lock) ); // optional idelay_ctrl generate if ( GENERATE_IDELAYCTRL == "TRUE") IDELAYCTRL idelayctrl ( .RDY (/*idelayctrl_rdy*/), .REFCLK (idelayctrl_refclk), .RST (rst) ); endgenerate endmodule
/********************************************************** -- (c) Copyright 2011 - 2013 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). A Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. // // THIS NOTICE MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES. // // // Owner: Gary Martin // Revision: $Id: //depot/icm/proj/common/head/rtl/v32_cmt/rtl/phy/phy_4lanes.v#6 $ // $Author: gary $ // $DateTime: 2010/05/11 18:05:17 $ // $Change: 490882 $ // Description: // This verilog file is the parameterizable 4-byte lane phy primitive top // This module may be ganged to create an N-lane phy. // // History: // Date Engineer Description // 04/01/2010 G. Martin Initial Checkin. // /////////////////////////////////////////////////////////// **********************************************************/ `timescale 1ps/1ps `define PC_DATA_OFFSET_RANGE 22:17 module mig_7series_v1_9_ddr_phy_4lanes #( parameter GENERATE_IDELAYCTRL = "TRUE", parameter IODELAY_GRP = "IODELAY_MIG", parameter BANK_TYPE = "HP_IO", // # = "HP_IO", "HPL_IO", "HR_IO", "HRL_IO" parameter BYTELANES_DDR_CK = 24'b0010_0010_0010_0010_0010_0010, parameter NUM_DDR_CK = 1, // next three parameter fields correspond to byte lanes for lane order DCBA parameter BYTE_LANES = 4'b1111, // lane existence, one per lane parameter DATA_CTL_N = 4'b1111, // data or control, per lane parameter BITLANES = 48'hffff_ffff_ffff, parameter BITLANES_OUTONLY = 48'h0000_0000_0000, parameter LANE_REMAP = 16'h3210,// 4-bit index // used to rewire to one of four // input/output buss lanes // example: 0321 remaps lanes as: // D->A // C->D // B->C // A->B parameter LAST_BANK = "FALSE", parameter USE_PRE_POST_FIFO = "FALSE", parameter RCLK_SELECT_LANE = "B", parameter real TCK = 0.00, parameter SYNTHESIS = "FALSE", parameter PO_CTL_COARSE_BYPASS = "FALSE", parameter PO_FINE_DELAY = 0, parameter PI_SEL_CLK_OFFSET = 0, // phy_control paramter used in other paramsters parameter PC_CLK_RATIO = 4, //phaser_in parameters parameter A_PI_FREQ_REF_DIV = "NONE", parameter A_PI_CLKOUT_DIV = 2, parameter A_PI_BURST_MODE = "TRUE", parameter A_PI_OUTPUT_CLK_SRC = "DELAYED_REF" , //"DELAYED_REF", parameter A_PI_FINE_DELAY = 60, parameter A_PI_SYNC_IN_DIV_RST = "TRUE", parameter B_PI_FREQ_REF_DIV = A_PI_FREQ_REF_DIV, parameter B_PI_CLKOUT_DIV = A_PI_CLKOUT_DIV, parameter B_PI_BURST_MODE = A_PI_BURST_MODE, parameter B_PI_OUTPUT_CLK_SRC = A_PI_OUTPUT_CLK_SRC, parameter B_PI_FINE_DELAY = A_PI_FINE_DELAY, parameter B_PI_SYNC_IN_DIV_RST = A_PI_SYNC_IN_DIV_RST, parameter C_PI_FREQ_REF_DIV = A_PI_FREQ_REF_DIV, parameter C_PI_CLKOUT_DIV = A_PI_CLKOUT_DIV, parameter C_PI_BURST_MODE = A_PI_BURST_MODE, parameter C_PI_OUTPUT_CLK_SRC = A_PI_OUTPUT_CLK_SRC, parameter C_PI_FINE_DELAY = 0, parameter C_PI_SYNC_IN_DIV_RST = A_PI_SYNC_IN_DIV_RST, parameter D_PI_FREQ_REF_DIV = A_PI_FREQ_REF_DIV, parameter D_PI_CLKOUT_DIV = A_PI_CLKOUT_DIV, parameter D_PI_BURST_MODE = A_PI_BURST_MODE, parameter D_PI_OUTPUT_CLK_SRC = A_PI_OUTPUT_CLK_SRC, parameter D_PI_FINE_DELAY = 0, parameter D_PI_SYNC_IN_DIV_RST = A_PI_SYNC_IN_DIV_RST, //phaser_out parameters parameter A_PO_CLKOUT_DIV = (DATA_CTL_N[0] == 0) ? PC_CLK_RATIO : 2, parameter A_PO_FINE_DELAY = PO_FINE_DELAY, parameter A_PO_COARSE_DELAY = 0, parameter A_PO_OCLK_DELAY = 0, parameter A_PO_OCLKDELAY_INV = "FALSE", parameter A_PO_OUTPUT_CLK_SRC = "DELAYED_REF", parameter A_PO_SYNC_IN_DIV_RST = "TRUE", //parameter A_PO_SYNC_IN_DIV_RST = "FALSE", parameter B_PO_CLKOUT_DIV = (DATA_CTL_N[1] == 0) ? PC_CLK_RATIO : 2, parameter B_PO_FINE_DELAY = PO_FINE_DELAY, parameter B_PO_COARSE_DELAY = A_PO_COARSE_DELAY, parameter B_PO_OCLK_DELAY = A_PO_OCLK_DELAY, parameter B_PO_OCLKDELAY_INV = A_PO_OCLKDELAY_INV, parameter B_PO_OUTPUT_CLK_SRC = A_PO_OUTPUT_CLK_SRC, parameter B_PO_SYNC_IN_DIV_RST = A_PO_SYNC_IN_DIV_RST, parameter C_PO_CLKOUT_DIV = (DATA_CTL_N[2] == 0) ? PC_CLK_RATIO : 2, parameter C_PO_FINE_DELAY = PO_FINE_DELAY, parameter C_PO_COARSE_DELAY = A_PO_COARSE_DELAY, parameter C_PO_OCLK_DELAY = A_PO_OCLK_DELAY, parameter C_PO_OCLKDELAY_INV = A_PO_OCLKDELAY_INV, parameter C_PO_OUTPUT_CLK_SRC = A_PO_OUTPUT_CLK_SRC, parameter C_PO_SYNC_IN_DIV_RST = A_PO_SYNC_IN_DIV_RST, parameter D_PO_CLKOUT_DIV = (DATA_CTL_N[3] == 0) ? PC_CLK_RATIO : 2, parameter D_PO_FINE_DELAY = PO_FINE_DELAY, parameter D_PO_COARSE_DELAY = A_PO_COARSE_DELAY, parameter D_PO_OCLK_DELAY = A_PO_OCLK_DELAY, parameter D_PO_OCLKDELAY_INV = A_PO_OCLKDELAY_INV, parameter D_PO_OUTPUT_CLK_SRC = A_PO_OUTPUT_CLK_SRC, parameter D_PO_SYNC_IN_DIV_RST = A_PO_SYNC_IN_DIV_RST, parameter A_IDELAYE2_IDELAY_TYPE = "VARIABLE", parameter A_IDELAYE2_IDELAY_VALUE = 00, parameter B_IDELAYE2_IDELAY_TYPE = A_IDELAYE2_IDELAY_TYPE, parameter B_IDELAYE2_IDELAY_VALUE = A_IDELAYE2_IDELAY_VALUE, parameter C_IDELAYE2_IDELAY_TYPE = A_IDELAYE2_IDELAY_TYPE, parameter C_IDELAYE2_IDELAY_VALUE = A_IDELAYE2_IDELAY_VALUE, parameter D_IDELAYE2_IDELAY_TYPE = A_IDELAYE2_IDELAY_TYPE, parameter D_IDELAYE2_IDELAY_VALUE = A_IDELAYE2_IDELAY_VALUE, // phy_control parameters parameter PC_BURST_MODE = "TRUE", parameter PC_DATA_CTL_N = DATA_CTL_N, parameter PC_CMD_OFFSET = 0, parameter PC_RD_CMD_OFFSET_0 = 0, parameter PC_RD_CMD_OFFSET_1 = 0, parameter PC_RD_CMD_OFFSET_2 = 0, parameter PC_RD_CMD_OFFSET_3 = 0, parameter PC_CO_DURATION = 1, parameter PC_DI_DURATION = 1, parameter PC_DO_DURATION = 1, parameter PC_RD_DURATION_0 = 0, parameter PC_RD_DURATION_1 = 0, parameter PC_RD_DURATION_2 = 0, parameter PC_RD_DURATION_3 = 0, parameter PC_WR_CMD_OFFSET_0 = 5, parameter PC_WR_CMD_OFFSET_1 = 5, parameter PC_WR_CMD_OFFSET_2 = 5, parameter PC_WR_CMD_OFFSET_3 = 5, parameter PC_WR_DURATION_0 = 6, parameter PC_WR_DURATION_1 = 6, parameter PC_WR_DURATION_2 = 6, parameter PC_WR_DURATION_3 = 6, parameter PC_AO_WRLVL_EN = 0, parameter PC_AO_TOGGLE = 4'b0101, // odd bits are toggle (CKE) parameter PC_FOUR_WINDOW_CLOCKS = 63, parameter PC_EVENTS_DELAY = 18, parameter PC_PHY_COUNT_EN = "TRUE", parameter PC_SYNC_MODE = "TRUE", parameter PC_DISABLE_SEQ_MATCH = "TRUE", parameter PC_MULTI_REGION = "FALSE", // io fifo parameters parameter A_OF_ARRAY_MODE = (DATA_CTL_N[0] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter B_OF_ARRAY_MODE = (DATA_CTL_N[1] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter C_OF_ARRAY_MODE = (DATA_CTL_N[2] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter D_OF_ARRAY_MODE = (DATA_CTL_N[3] == 1) ? "ARRAY_MODE_8_X_4" : "ARRAY_MODE_4_X_4", parameter OF_ALMOST_EMPTY_VALUE = 1, parameter OF_ALMOST_FULL_VALUE = 1, parameter OF_OUTPUT_DISABLE = "TRUE", parameter OF_SYNCHRONOUS_MODE = PC_SYNC_MODE, parameter A_OS_DATA_RATE = "DDR", parameter A_OS_DATA_WIDTH = 4, parameter B_OS_DATA_RATE = A_OS_DATA_RATE, parameter B_OS_DATA_WIDTH = A_OS_DATA_WIDTH, parameter C_OS_DATA_RATE = A_OS_DATA_RATE, parameter C_OS_DATA_WIDTH = A_OS_DATA_WIDTH, parameter D_OS_DATA_RATE = A_OS_DATA_RATE, parameter D_OS_DATA_WIDTH = A_OS_DATA_WIDTH, parameter A_IF_ARRAY_MODE = "ARRAY_MODE_4_X_8", parameter B_IF_ARRAY_MODE = A_IF_ARRAY_MODE, parameter C_IF_ARRAY_MODE = A_IF_ARRAY_MODE, parameter D_IF_ARRAY_MODE = A_IF_ARRAY_MODE, parameter IF_ALMOST_EMPTY_VALUE = 1, parameter IF_ALMOST_FULL_VALUE = 1, parameter IF_SYNCHRONOUS_MODE = PC_SYNC_MODE, // this is used locally, not for external pushdown // NOTE: the 0+ is needed in each to coerce to integer for addition. // otherwise 4x 1'b values are added producing a 1'b value. parameter HIGHEST_LANE = LAST_BANK == "FALSE" ? 4 : (BYTE_LANES[3] ? 4 : BYTE_LANES[2] ? 3 : BYTE_LANES[1] ? 2 : 1), parameter N_CTL_LANES = ((0+(!DATA_CTL_N[0]) & BYTE_LANES[0]) + (0+(!DATA_CTL_N[1]) & BYTE_LANES[1]) + (0+(!DATA_CTL_N[2]) & BYTE_LANES[2]) + (0+(!DATA_CTL_N[3]) & BYTE_LANES[3])), parameter N_BYTE_LANES = (0+BYTE_LANES[0]) + (0+BYTE_LANES[1]) + (0+BYTE_LANES[2]) + (0+BYTE_LANES[3]), parameter N_DATA_LANES = N_BYTE_LANES - N_CTL_LANES, // assume odt per rank + any declared cke's parameter AUXOUT_WIDTH = 4, parameter LP_DDR_CK_WIDTH = 2 ,parameter CKE_ODT_AUX = "FALSE" ) ( //`include "phy.vh" input rst, input phy_clk, input phy_ctl_clk, input freq_refclk, input mem_refclk, input mem_refclk_div4, input pll_lock, input sync_pulse, input idelayctrl_refclk, input [HIGHEST_LANE*80-1:0] phy_dout, input phy_cmd_wr_en, input phy_data_wr_en, input phy_rd_en, input phy_ctl_mstr_empty, input [31:0] phy_ctl_wd, input [`PC_DATA_OFFSET_RANGE] data_offset, input phy_ctl_wr, input if_empty_def, input phyGo, input input_sink, output [(LP_DDR_CK_WIDTH*24)-1:0] ddr_clk, // to memory output rclk, output if_a_empty, output if_empty, output byte_rd_en, output if_empty_or, output if_empty_and, output of_ctl_a_full, output of_data_a_full, output of_ctl_full, output of_data_full, output pre_data_a_full, output [HIGHEST_LANE*80-1:0]phy_din, // assume input bus same size as output bus output phy_ctl_empty, output phy_ctl_a_full, output phy_ctl_full, output [HIGHEST_LANE*12-1:0]mem_dq_out, output [HIGHEST_LANE*12-1:0]mem_dq_ts, input [HIGHEST_LANE*10-1:0]mem_dq_in, output [HIGHEST_LANE-1:0] mem_dqs_out, output [HIGHEST_LANE-1:0] mem_dqs_ts, input [HIGHEST_LANE-1:0] mem_dqs_in, input [1:0] byte_rd_en_oth_banks, output [AUXOUT_WIDTH-1:0] aux_out, output reg rst_out = 0, output reg mcGo=0, output phy_ctl_ready, output ref_dll_lock, input if_rst, input phy_read_calib, input phy_write_calib, input idelay_inc, input idelay_ce, input idelay_ld, input [2:0] calib_sel, input calib_zero_ctrl, input [HIGHEST_LANE-1:0] calib_zero_lanes, input calib_in_common, input po_fine_enable, input po_coarse_enable, input po_fine_inc, input po_coarse_inc, input po_counter_load_en, input po_counter_read_en, input [8:0] po_counter_load_val, input po_sel_fine_oclk_delay, output reg po_coarse_overflow, output reg po_fine_overflow, output reg [8:0] po_counter_read_val, input pi_rst_dqs_find, input pi_fine_enable, input pi_fine_inc, input pi_counter_load_en, input pi_counter_read_en, input [5:0] pi_counter_load_val, output reg pi_fine_overflow, output reg [5:0] pi_counter_read_val, output reg pi_dqs_found, output pi_dqs_found_all, output pi_dqs_found_any, output [HIGHEST_LANE-1:0] pi_phase_locked_lanes, output [HIGHEST_LANE-1:0] pi_dqs_found_lanes, output reg pi_dqs_out_of_range, output reg pi_phase_locked, output pi_phase_locked_all ); localparam DATA_CTL_A = (~DATA_CTL_N[0]); localparam DATA_CTL_B = (~DATA_CTL_N[1]); localparam DATA_CTL_C = (~DATA_CTL_N[2]); localparam DATA_CTL_D = (~DATA_CTL_N[3]); localparam PRESENT_CTL_A = BYTE_LANES[0] && ! DATA_CTL_N[0]; localparam PRESENT_CTL_B = BYTE_LANES[1] && ! DATA_CTL_N[1]; localparam PRESENT_CTL_C = BYTE_LANES[2] && ! DATA_CTL_N[2]; localparam PRESENT_CTL_D = BYTE_LANES[3] && ! DATA_CTL_N[3]; localparam PRESENT_DATA_A = BYTE_LANES[0] && DATA_CTL_N[0]; localparam PRESENT_DATA_B = BYTE_LANES[1] && DATA_CTL_N[1]; localparam PRESENT_DATA_C = BYTE_LANES[2] && DATA_CTL_N[2]; localparam PRESENT_DATA_D = BYTE_LANES[3] && DATA_CTL_N[3]; localparam PC_DATA_CTL_A = (DATA_CTL_A) ? "FALSE" : "TRUE"; localparam PC_DATA_CTL_B = (DATA_CTL_B) ? "FALSE" : "TRUE"; localparam PC_DATA_CTL_C = (DATA_CTL_C) ? "FALSE" : "TRUE"; localparam PC_DATA_CTL_D = (DATA_CTL_D) ? "FALSE" : "TRUE"; localparam A_PO_COARSE_BYPASS = (DATA_CTL_A) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam B_PO_COARSE_BYPASS = (DATA_CTL_B) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam C_PO_COARSE_BYPASS = (DATA_CTL_C) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam D_PO_COARSE_BYPASS = (DATA_CTL_D) ? PO_CTL_COARSE_BYPASS : "FALSE"; localparam IO_A_START = 41; localparam IO_A_END = 40; localparam IO_B_START = 43; localparam IO_B_END = 42; localparam IO_C_START = 45; localparam IO_C_END = 44; localparam IO_D_START = 47; localparam IO_D_END = 46; localparam IO_A_X_START = (HIGHEST_LANE * 10) + 1; localparam IO_A_X_END = (IO_A_X_START-1); localparam IO_B_X_START = (IO_A_X_START + 2); localparam IO_B_X_END = (IO_B_X_START -1); localparam IO_C_X_START = (IO_B_X_START + 2); localparam IO_C_X_END = (IO_C_X_START -1); localparam IO_D_X_START = (IO_C_X_START + 2); localparam IO_D_X_END = (IO_D_X_START -1); localparam MSB_BURST_PEND_PO = 3; localparam MSB_BURST_PEND_PI = 7; localparam MSB_RANK_SEL_I = MSB_BURST_PEND_PI + 8; localparam PHASER_CTL_BUS_WIDTH = MSB_RANK_SEL_I + 1; wire [1:0] oserdes_dqs; wire [1:0] oserdes_dqs_ts; wire [1:0] oserdes_dq_ts; wire [PHASER_CTL_BUS_WIDTH-1:0] phaser_ctl_bus; wire [7:0] in_rank; wire [11:0] IO_A; wire [11:0] IO_B; wire [11:0] IO_C; wire [11:0] IO_D; wire [319:0] phy_din_remap; reg A_po_counter_read_en; wire [8:0] A_po_counter_read_val; reg A_pi_counter_read_en; wire [5:0] A_pi_counter_read_val; wire A_pi_fine_overflow; wire A_po_coarse_overflow; wire A_po_fine_overflow; wire A_pi_dqs_found; wire A_pi_dqs_out_of_range; wire A_pi_phase_locked; wire A_pi_iserdes_rst; reg A_pi_fine_enable; reg A_pi_fine_inc; reg A_pi_counter_load_en; reg [5:0] A_pi_counter_load_val; reg A_pi_rst_dqs_find; reg A_po_fine_enable; reg A_po_coarse_enable; (* keep = "true", max_fanout = 3 *) reg A_po_fine_inc /* synthesis syn_maxfan = 3 */; reg A_po_sel_fine_oclk_delay; reg A_po_coarse_inc; reg A_po_counter_load_en; reg [8:0] A_po_counter_load_val; wire A_rclk; reg A_idelay_ce; reg A_idelay_ld; reg B_po_counter_read_en; wire [8:0] B_po_counter_read_val; reg B_pi_counter_read_en; wire [5:0] B_pi_counter_read_val; wire B_pi_fine_overflow; wire B_po_coarse_overflow; wire B_po_fine_overflow; wire B_pi_phase_locked; wire B_pi_iserdes_rst; wire B_pi_dqs_found; wire B_pi_dqs_out_of_range; reg B_pi_fine_enable; reg B_pi_fine_inc; reg B_pi_counter_load_en; reg [5:0] B_pi_counter_load_val; reg B_pi_rst_dqs_find; reg B_po_fine_enable; reg B_po_coarse_enable; (* keep = "true", max_fanout = 3 *) reg B_po_fine_inc /* synthesis syn_maxfan = 3 */; reg B_po_coarse_inc; reg B_po_sel_fine_oclk_delay; reg B_po_counter_load_en; reg [8:0] B_po_counter_load_val; wire B_rclk; reg B_idelay_ce; reg B_idelay_ld; reg C_pi_fine_inc; reg D_pi_fine_inc; reg C_pi_fine_enable; reg D_pi_fine_enable; reg C_po_counter_load_en; reg D_po_counter_load_en; reg C_po_coarse_inc; reg D_po_coarse_inc; (* keep = "true", max_fanout = 3 *) reg C_po_fine_inc /* synthesis syn_maxfan = 3 */; (* keep = "true", max_fanout = 3 *) reg D_po_fine_inc /* synthesis syn_maxfan = 3 */; reg C_po_sel_fine_oclk_delay; reg D_po_sel_fine_oclk_delay; reg [5:0] C_pi_counter_load_val; reg [5:0] D_pi_counter_load_val; reg [8:0] C_po_counter_load_val; reg [8:0] D_po_counter_load_val; reg C_po_coarse_enable; reg D_po_coarse_enable; reg C_po_fine_enable; reg D_po_fine_enable; wire C_po_coarse_overflow; wire D_po_coarse_overflow; wire C_po_fine_overflow; wire D_po_fine_overflow; wire [8:0] C_po_counter_read_val; wire [8:0] D_po_counter_read_val; reg C_po_counter_read_en; reg D_po_counter_read_en; wire C_pi_dqs_found; wire D_pi_dqs_found; wire C_pi_fine_overflow; wire D_pi_fine_overflow; reg C_pi_counter_read_en; reg D_pi_counter_read_en; reg C_pi_counter_load_en; reg D_pi_counter_load_en; wire C_pi_phase_locked; wire C_pi_iserdes_rst; wire D_pi_phase_locked; wire D_pi_iserdes_rst; wire C_pi_dqs_out_of_range; wire D_pi_dqs_out_of_range; wire [5:0] C_pi_counter_read_val; wire [5:0] D_pi_counter_read_val; wire C_rclk; wire D_rclk; reg C_idelay_ce; reg D_idelay_ce; reg C_idelay_ld; reg D_idelay_ld; reg C_pi_rst_dqs_find; reg D_pi_rst_dqs_find; wire pi_iserdes_rst; wire A_if_empty; wire B_if_empty; wire C_if_empty; wire D_if_empty; wire A_byte_rd_en; wire B_byte_rd_en; wire C_byte_rd_en; wire D_byte_rd_en; wire A_if_a_empty; wire B_if_a_empty; wire C_if_a_empty; wire D_if_a_empty; wire A_if_full; wire B_if_full; wire C_if_full; wire D_if_full; wire A_of_empty; wire B_of_empty; wire C_of_empty; wire D_of_empty; wire A_of_full; wire B_of_full; wire C_of_full; wire D_of_full; wire A_of_ctl_full; wire B_of_ctl_full; wire C_of_ctl_full; wire D_of_ctl_full; wire A_of_data_full; wire B_of_data_full; wire C_of_data_full; wire D_of_data_full; wire A_of_a_full; wire B_of_a_full; wire C_of_a_full; wire D_of_a_full; wire A_pre_fifo_a_full; wire B_pre_fifo_a_full; wire C_pre_fifo_a_full; wire D_pre_fifo_a_full; wire A_of_ctl_a_full; wire B_of_ctl_a_full; wire C_of_ctl_a_full; wire D_of_ctl_a_full; wire A_of_data_a_full; wire B_of_data_a_full; wire C_of_data_a_full; wire D_of_data_a_full; wire A_pre_data_a_full; wire B_pre_data_a_full; wire C_pre_data_a_full; wire D_pre_data_a_full; wire [LP_DDR_CK_WIDTH*6-1:0] A_ddr_clk; // for generation wire [LP_DDR_CK_WIDTH*6-1:0] B_ddr_clk; // wire [LP_DDR_CK_WIDTH*6-1:0] C_ddr_clk; // wire [LP_DDR_CK_WIDTH*6-1:0] D_ddr_clk; // wire [3:0] dummy_data; wire [31:0] _phy_ctl_wd; wire [1:0] phy_encalib; assign pi_dqs_found_all = (! PRESENT_DATA_A | A_pi_dqs_found) & (! PRESENT_DATA_B | B_pi_dqs_found) & (! PRESENT_DATA_C | C_pi_dqs_found) & (! PRESENT_DATA_D | D_pi_dqs_found) ; assign pi_dqs_found_any = ( PRESENT_DATA_A & A_pi_dqs_found) | ( PRESENT_DATA_B & B_pi_dqs_found) | ( PRESENT_DATA_C & C_pi_dqs_found) | ( PRESENT_DATA_D & D_pi_dqs_found) ; assign pi_phase_locked_all = (! PRESENT_DATA_A | A_pi_phase_locked) & (! PRESENT_DATA_B | B_pi_phase_locked) & (! PRESENT_DATA_C | C_pi_phase_locked) & (! PRESENT_DATA_D | D_pi_phase_locked); wire dangling_inputs = (& dummy_data) & input_sink & 1'b0; // this reduces all constant 0 values to 1 signal // which is combined into another signals such that // the other signal isn't changed. The purpose // is to fake the tools into ignoring dangling inputs. // Because it is anded with 1'b0, the contributing signals // are folded as constants or trimmed. assign if_empty = !if_empty_def ? (A_if_empty | B_if_empty | C_if_empty | D_if_empty) : (A_if_empty & B_if_empty & C_if_empty & D_if_empty); assign byte_rd_en = !if_empty_def ? (A_byte_rd_en & B_byte_rd_en & C_byte_rd_en & D_byte_rd_en) : (A_byte_rd_en | B_byte_rd_en | C_byte_rd_en | D_byte_rd_en); assign if_empty_or = (A_if_empty | B_if_empty | C_if_empty | D_if_empty); assign if_empty_and = (A_if_empty & B_if_empty & C_if_empty & D_if_empty); assign if_a_empty = A_if_a_empty | B_if_a_empty | C_if_a_empty | D_if_a_empty; assign if_full = A_if_full | B_if_full | C_if_full | D_if_full ; assign of_empty = A_of_empty & B_of_empty & C_of_empty & D_of_empty; assign of_ctl_full = A_of_ctl_full | B_of_ctl_full | C_of_ctl_full | D_of_ctl_full ; assign of_data_full = A_of_data_full | B_of_data_full | C_of_data_full | D_of_data_full ; assign of_ctl_a_full = A_of_ctl_a_full | B_of_ctl_a_full | C_of_ctl_a_full | D_of_ctl_a_full ; assign of_data_a_full = A_of_data_a_full | B_of_data_a_full | C_of_data_a_full | D_of_data_a_full | dangling_inputs ; assign pre_data_a_full = A_pre_data_a_full | B_pre_data_a_full | C_pre_data_a_full | D_pre_data_a_full; function [79:0] part_select_80; input [319:0] vector; input [1:0] select; begin case (select) 2'b00 : part_select_80[79:0] = vector[1*80-1:0*80]; 2'b01 : part_select_80[79:0] = vector[2*80-1:1*80]; 2'b10 : part_select_80[79:0] = vector[3*80-1:2*80]; 2'b11 : part_select_80[79:0] = vector[4*80-1:3*80]; endcase end endfunction wire [319:0] phy_dout_remap; reg rst_out_trig = 1'b0; reg [31:0] rclk_delay; reg rst_edge1 = 1'b0; reg rst_edge2 = 1'b0; reg rst_edge3 = 1'b0; reg rst_edge_detect = 1'b0; wire rclk_; reg rst_out_start = 1'b0 ; reg rst_primitives=0; reg A_rst_primitives=0; reg B_rst_primitives=0; reg C_rst_primitives=0; reg D_rst_primitives=0; `ifdef USE_PHY_CONTROL_TEST wire [15:0] test_output; wire [15:0] test_input; wire [2:0] test_select=0; wire scan_enable = 0; `endif generate genvar i; if (RCLK_SELECT_LANE == "A") begin assign rclk_ = A_rclk; assign pi_iserdes_rst = A_pi_iserdes_rst; end else if (RCLK_SELECT_LANE == "B") begin assign rclk_ = B_rclk; assign pi_iserdes_rst = B_pi_iserdes_rst; end else if (RCLK_SELECT_LANE == "C") begin assign rclk_ = C_rclk; assign pi_iserdes_rst = C_pi_iserdes_rst; end else if (RCLK_SELECT_LANE == "D") begin assign rclk_ = D_rclk; assign pi_iserdes_rst = D_pi_iserdes_rst; end else begin assign rclk_ = B_rclk; // default end endgenerate assign ddr_clk[LP_DDR_CK_WIDTH*6-1:0] = A_ddr_clk; assign ddr_clk[LP_DDR_CK_WIDTH*12-1:LP_DDR_CK_WIDTH*6] = B_ddr_clk; assign ddr_clk[LP_DDR_CK_WIDTH*18-1:LP_DDR_CK_WIDTH*12] = C_ddr_clk; assign ddr_clk[LP_DDR_CK_WIDTH*24-1:LP_DDR_CK_WIDTH*18] = D_ddr_clk; assign pi_phase_locked_lanes = {(! PRESENT_DATA_A[0] | A_pi_phase_locked), (! PRESENT_DATA_B[0] | B_pi_phase_locked) , (! PRESENT_DATA_C[0] | C_pi_phase_locked) , (! PRESENT_DATA_D[0] | D_pi_phase_locked)}; assign pi_dqs_found_lanes = {D_pi_dqs_found, C_pi_dqs_found, B_pi_dqs_found, A_pi_dqs_found}; // this block scrubs X from rclk_delay[11] reg rclk_delay_11; always @(rclk_delay[11]) begin : rclk_delay_11_blk if ( rclk_delay[11]) rclk_delay_11 = 1; else rclk_delay_11 = 0; end always @(posedge phy_clk or posedge rst ) begin // scrub 4-state values from rclk_delay[11] if ( rst) begin rst_out <= #1 0; end else begin if ( rclk_delay_11) rst_out <= #1 1; end end always @(posedge phy_clk ) begin // phy_ctl_ready drives reset of the system rst_primitives <= !phy_ctl_ready ; A_rst_primitives <= rst_primitives ; B_rst_primitives <= rst_primitives ; C_rst_primitives <= rst_primitives ; D_rst_primitives <= rst_primitives ; rclk_delay <= #1 (rclk_delay << 1) | (!rst_primitives && phyGo); mcGo <= #1 rst_out ; end generate if (BYTE_LANES[0]) begin assign dummy_data[0] = 0; end else begin assign dummy_data[0] = &phy_dout_remap[1*80-1:0*80]; end if (BYTE_LANES[1]) begin assign dummy_data[1] = 0; end else begin assign dummy_data[1] = &phy_dout_remap[2*80-1:1*80]; end if (BYTE_LANES[2]) begin assign dummy_data[2] = 0; end else begin assign dummy_data[2] = &phy_dout_remap[3*80-1:2*80]; end if (BYTE_LANES[3]) begin assign dummy_data[3] = 0; end else begin assign dummy_data[3] = &phy_dout_remap[4*80-1:3*80]; end if (PRESENT_DATA_A) begin assign A_of_data_full = A_of_full; assign A_of_ctl_full = 0; assign A_of_data_a_full = A_of_a_full; assign A_of_ctl_a_full = 0; assign A_pre_data_a_full = A_pre_fifo_a_full; end else begin assign A_of_ctl_full = A_of_full; assign A_of_data_full = 0; assign A_of_ctl_a_full = A_of_a_full; assign A_of_data_a_full = 0; assign A_pre_data_a_full = 0; end if (PRESENT_DATA_B) begin assign B_of_data_full = B_of_full; assign B_of_ctl_full = 0; assign B_of_data_a_full = B_of_a_full; assign B_of_ctl_a_full = 0; assign B_pre_data_a_full = B_pre_fifo_a_full; end else begin assign B_of_ctl_full = B_of_full; assign B_of_data_full = 0; assign B_of_ctl_a_full = B_of_a_full; assign B_of_data_a_full = 0; assign B_pre_data_a_full = 0; end if (PRESENT_DATA_C) begin assign C_of_data_full = C_of_full; assign C_of_ctl_full = 0; assign C_of_data_a_full = C_of_a_full; assign C_of_ctl_a_full = 0; assign C_pre_data_a_full = C_pre_fifo_a_full; end else begin assign C_of_ctl_full = C_of_full; assign C_of_data_full = 0; assign C_of_ctl_a_full = C_of_a_full; assign C_of_data_a_full = 0; assign C_pre_data_a_full = 0; end if (PRESENT_DATA_D) begin assign D_of_data_full = D_of_full; assign D_of_ctl_full = 0; assign D_of_data_a_full = D_of_a_full; assign D_of_ctl_a_full = 0; assign D_pre_data_a_full = D_pre_fifo_a_full; end else begin assign D_of_ctl_full = D_of_full; assign D_of_data_full = 0; assign D_of_ctl_a_full = D_of_a_full; assign D_of_data_a_full = 0; assign D_pre_data_a_full = 0; end // byte lane must exist and be data lane. if (PRESENT_DATA_A ) case ( LANE_REMAP[1:0] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[79:0]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[79:0]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[79:0]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[79:0]; endcase else case ( LANE_REMAP[1:0] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (PRESENT_DATA_B ) case ( LANE_REMAP[5:4] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[159:80]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[159:80]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[159:80]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[159:80]; endcase else if (HIGHEST_LANE > 1) case ( LANE_REMAP[5:4] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (PRESENT_DATA_C) case ( LANE_REMAP[9:8] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[239:160]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[239:160]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[239:160]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[239:160]; endcase else if (HIGHEST_LANE > 2) case ( LANE_REMAP[9:8] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (PRESENT_DATA_D ) case ( LANE_REMAP[13:12] ) 2'b00 : assign phy_din[1*80-1:0] = phy_din_remap[319:240]; 2'b01 : assign phy_din[2*80-1:80] = phy_din_remap[319:240]; 2'b10 : assign phy_din[3*80-1:160] = phy_din_remap[319:240]; 2'b11 : assign phy_din[4*80-1:240] = phy_din_remap[319:240]; endcase else if (HIGHEST_LANE > 3) case ( LANE_REMAP[13:12] ) 2'b00 : assign phy_din[1*80-1:0] = 80'h0; 2'b01 : assign phy_din[2*80-1:80] = 80'h0; 2'b10 : assign phy_din[3*80-1:160] = 80'h0; 2'b11 : assign phy_din[4*80-1:240] = 80'h0; endcase if (HIGHEST_LANE > 1) assign _phy_ctl_wd = {phy_ctl_wd[31:23], data_offset, phy_ctl_wd[16:0]}; if (HIGHEST_LANE == 1) assign _phy_ctl_wd_ = phy_ctl_wd; //BUFR #(.BUFR_DIVIDE ("1")) rclk_buf(.I(rclk_), .O(rclk), .CE (1'b1), .CLR (pi_iserdes_rst)); BUFIO rclk_buf(.I(rclk_), .O(rclk) ); if ( BYTE_LANES[0] ) begin : ddr_byte_lane_A assign phy_dout_remap[79:0] = part_select_80(phy_dout, (LANE_REMAP[1:0])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("A"), .PO_DATA_CTL (PC_DATA_CTL_N[0] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[11:0]), .BITLANES_OUTONLY (BITLANES_OUTONLY[11:0]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (A_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (A_PI_BURST_MODE), .PI_CLKOUT_DIV (A_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (A_PI_FREQ_REF_DIV), .PI_FINE_DELAY (A_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (A_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (A_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (A_PO_CLKOUT_DIV), .PO_FINE_DELAY (A_PO_FINE_DELAY), .PO_COARSE_BYPASS (A_PO_COARSE_BYPASS), .PO_COARSE_DELAY (A_PO_COARSE_DELAY), .PO_OCLK_DELAY (A_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (A_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (A_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (A_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (A_OS_DATA_RATE), .OSERDES_DATA_WIDTH (A_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (A_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (A_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_A( .mem_dq_out (mem_dq_out[11:0]), .mem_dq_ts (mem_dq_ts[11:0]), .mem_dq_in (mem_dq_in[9:0]), .mem_dqs_out (mem_dqs_out[0]), .mem_dqs_ts (mem_dqs_ts[0]), .mem_dqs_in (mem_dqs_in[0]), .rst (A_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (A_ddr_clk), .rclk (A_rclk), .pi_dqs_found (A_pi_dqs_found), .dqs_out_of_range (A_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (A_if_a_empty), .if_empty (A_if_empty), .if_a_full (if_a_full), .if_full (A_if_full), .of_a_empty (of_a_empty), .of_empty (A_of_empty), .of_a_full (A_of_a_full), .of_full (A_of_full), .pre_fifo_a_full (A_pre_fifo_a_full), .phy_din (phy_din_remap[79:0]), .phy_dout (phy_dout_remap[79:0]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .if_rst (if_rst), .byte_rd_en_oth_lanes ({B_byte_rd_en,C_byte_rd_en,D_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (A_byte_rd_en), // calibration signals .idelay_inc (idelay_inc), .idelay_ce (A_idelay_ce), .idelay_ld (A_idelay_ld), .pi_rst_dqs_find (A_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (A_po_fine_enable), .po_coarse_enable (A_po_coarse_enable), .po_fine_inc (A_po_fine_inc), .po_coarse_inc (A_po_coarse_inc), .po_counter_load_en (A_po_counter_load_en), .po_counter_read_en (A_po_counter_read_en), .po_counter_load_val (A_po_counter_load_val), .po_coarse_overflow (A_po_coarse_overflow), .po_fine_overflow (A_po_fine_overflow), .po_counter_read_val (A_po_counter_read_val), .po_sel_fine_oclk_delay(A_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (A_pi_fine_enable), .pi_fine_inc (A_pi_fine_inc), .pi_counter_load_en (A_pi_counter_load_en), .pi_counter_read_en (A_pi_counter_read_en), .pi_counter_load_val (A_pi_counter_load_val), .pi_fine_overflow (A_pi_fine_overflow), .pi_counter_read_val (A_pi_counter_read_val), .pi_iserdes_rst (A_pi_iserdes_rst), .pi_phase_locked (A_pi_phase_locked) ); end else begin : no_ddr_byte_lane_A assign A_of_a_full = 1'b0; assign A_of_full = 1'b0; assign A_pre_fifo_a_full = 1'b0; assign A_if_empty = 1'b0; assign A_byte_rd_en = 1'b1; assign A_if_a_empty = 1'b0; assign A_pi_phase_locked = 1; assign A_pi_dqs_found = 1; assign A_rclk = 0; assign A_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign A_pi_counter_read_val = 0; assign A_po_counter_read_val = 0; assign A_pi_fine_overflow = 0; assign A_po_coarse_overflow = 0; assign A_po_fine_overflow = 0; end if ( BYTE_LANES[1] ) begin : ddr_byte_lane_B assign phy_dout_remap[159:80] = part_select_80(phy_dout, (LANE_REMAP[5:4])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("B"), .PO_DATA_CTL (PC_DATA_CTL_N[1] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[23:12]), .BITLANES_OUTONLY (BITLANES_OUTONLY[23:12]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (B_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (B_PI_BURST_MODE), .PI_CLKOUT_DIV (B_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (B_PI_FREQ_REF_DIV), .PI_FINE_DELAY (B_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (B_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (B_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (B_PO_CLKOUT_DIV), .PO_FINE_DELAY (B_PO_FINE_DELAY), .PO_COARSE_BYPASS (B_PO_COARSE_BYPASS), .PO_COARSE_DELAY (B_PO_COARSE_DELAY), .PO_OCLK_DELAY (B_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (B_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (B_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (B_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (B_OS_DATA_RATE), .OSERDES_DATA_WIDTH (B_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (B_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (B_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_B( .mem_dq_out (mem_dq_out[23:12]), .mem_dq_ts (mem_dq_ts[23:12]), .mem_dq_in (mem_dq_in[19:10]), .mem_dqs_out (mem_dqs_out[1]), .mem_dqs_ts (mem_dqs_ts[1]), .mem_dqs_in (mem_dqs_in[1]), .rst (B_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (B_ddr_clk), .rclk (B_rclk), .pi_dqs_found (B_pi_dqs_found), .dqs_out_of_range (B_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (B_if_a_empty), .if_empty (B_if_empty), .if_a_full (/*if_a_full*/), .if_full (B_if_full), .of_a_empty (/*of_a_empty*/), .of_empty (B_of_empty), .of_a_full (B_of_a_full), .of_full (B_of_full), .pre_fifo_a_full (B_pre_fifo_a_full), .phy_din (phy_din_remap[159:80]), .phy_dout (phy_dout_remap[159:80]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .if_rst (if_rst), .byte_rd_en_oth_lanes ({A_byte_rd_en,C_byte_rd_en,D_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (B_byte_rd_en), // calibration signals .idelay_inc (idelay_inc), .idelay_ce (B_idelay_ce), .idelay_ld (B_idelay_ld), .pi_rst_dqs_find (B_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (B_po_fine_enable), .po_coarse_enable (B_po_coarse_enable), .po_fine_inc (B_po_fine_inc), .po_coarse_inc (B_po_coarse_inc), .po_counter_load_en (B_po_counter_load_en), .po_counter_read_en (B_po_counter_read_en), .po_counter_load_val (B_po_counter_load_val), .po_coarse_overflow (B_po_coarse_overflow), .po_fine_overflow (B_po_fine_overflow), .po_counter_read_val (B_po_counter_read_val), .po_sel_fine_oclk_delay(B_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (B_pi_fine_enable), .pi_fine_inc (B_pi_fine_inc), .pi_counter_load_en (B_pi_counter_load_en), .pi_counter_read_en (B_pi_counter_read_en), .pi_counter_load_val (B_pi_counter_load_val), .pi_fine_overflow (B_pi_fine_overflow), .pi_counter_read_val (B_pi_counter_read_val), .pi_iserdes_rst (B_pi_iserdes_rst), .pi_phase_locked (B_pi_phase_locked) ); end else begin : no_ddr_byte_lane_B assign B_of_a_full = 1'b0; assign B_of_full = 1'b0; assign B_pre_fifo_a_full = 1'b0; assign B_if_empty = 1'b0; assign B_if_a_empty = 1'b0; assign B_byte_rd_en = 1'b1; assign B_pi_phase_locked = 1; assign B_pi_dqs_found = 1; assign B_rclk = 0; assign B_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign B_pi_counter_read_val = 0; assign B_po_counter_read_val = 0; assign B_pi_fine_overflow = 0; assign B_po_coarse_overflow = 0; assign B_po_fine_overflow = 0; end if ( BYTE_LANES[2] ) begin : ddr_byte_lane_C assign phy_dout_remap[239:160] = part_select_80(phy_dout, (LANE_REMAP[9:8])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("C"), .PO_DATA_CTL (PC_DATA_CTL_N[2] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[35:24]), .BITLANES_OUTONLY (BITLANES_OUTONLY[35:24]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (C_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (C_PI_BURST_MODE), .PI_CLKOUT_DIV (C_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (C_PI_FREQ_REF_DIV), .PI_FINE_DELAY (C_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (C_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (C_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (C_PO_CLKOUT_DIV), .PO_FINE_DELAY (C_PO_FINE_DELAY), .PO_COARSE_BYPASS (C_PO_COARSE_BYPASS), .PO_COARSE_DELAY (C_PO_COARSE_DELAY), .PO_OCLK_DELAY (C_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (C_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (C_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (C_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (C_OS_DATA_RATE), .OSERDES_DATA_WIDTH (C_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (C_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (C_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_C( .mem_dq_out (mem_dq_out[35:24]), .mem_dq_ts (mem_dq_ts[35:24]), .mem_dq_in (mem_dq_in[29:20]), .mem_dqs_out (mem_dqs_out[2]), .mem_dqs_ts (mem_dqs_ts[2]), .mem_dqs_in (mem_dqs_in[2]), .rst (C_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (C_ddr_clk), .rclk (C_rclk), .pi_dqs_found (C_pi_dqs_found), .dqs_out_of_range (C_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (C_if_a_empty), .if_empty (C_if_empty), .if_a_full (/*if_a_full*/), .if_full (C_if_full), .of_a_empty (/*of_a_empty*/), .of_empty (C_of_empty), .of_a_full (C_of_a_full), .of_full (C_of_full), .pre_fifo_a_full (C_pre_fifo_a_full), .phy_din (phy_din_remap[239:160]), .phy_dout (phy_dout_remap[239:160]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .if_rst (if_rst), .byte_rd_en_oth_lanes ({A_byte_rd_en,B_byte_rd_en,D_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (C_byte_rd_en), // calibration signals .idelay_inc (idelay_inc), .idelay_ce (C_idelay_ce), .idelay_ld (C_idelay_ld), .pi_rst_dqs_find (C_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (C_po_fine_enable), .po_coarse_enable (C_po_coarse_enable), .po_fine_inc (C_po_fine_inc), .po_coarse_inc (C_po_coarse_inc), .po_counter_load_en (C_po_counter_load_en), .po_counter_read_en (C_po_counter_read_en), .po_counter_load_val (C_po_counter_load_val), .po_coarse_overflow (C_po_coarse_overflow), .po_fine_overflow (C_po_fine_overflow), .po_counter_read_val (C_po_counter_read_val), .po_sel_fine_oclk_delay(C_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (C_pi_fine_enable), .pi_fine_inc (C_pi_fine_inc), .pi_counter_load_en (C_pi_counter_load_en), .pi_counter_read_en (C_pi_counter_read_en), .pi_counter_load_val (C_pi_counter_load_val), .pi_fine_overflow (C_pi_fine_overflow), .pi_counter_read_val (C_pi_counter_read_val), .pi_iserdes_rst (C_pi_iserdes_rst), .pi_phase_locked (C_pi_phase_locked) ); end else begin : no_ddr_byte_lane_C assign C_of_a_full = 1'b0; assign C_of_full = 1'b0; assign C_pre_fifo_a_full = 1'b0; assign C_if_empty = 1'b0; assign C_byte_rd_en = 1'b1; assign C_if_a_empty = 1'b0; assign C_pi_phase_locked = 1; assign C_pi_dqs_found = 1; assign C_rclk = 0; assign C_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign C_pi_counter_read_val = 0; assign C_po_counter_read_val = 0; assign C_pi_fine_overflow = 0; assign C_po_coarse_overflow = 0; assign C_po_fine_overflow = 0; end if ( BYTE_LANES[3] ) begin : ddr_byte_lane_D assign phy_dout_remap[319:240] = part_select_80(phy_dout, (LANE_REMAP[13:12])); mig_7series_v1_9_ddr_byte_lane # ( .ABCD ("D"), .PO_DATA_CTL (PC_DATA_CTL_N[3] ? "TRUE" : "FALSE"), .BITLANES (BITLANES[47:36]), .BITLANES_OUTONLY (BITLANES_OUTONLY[47:36]), .OF_ALMOST_EMPTY_VALUE (OF_ALMOST_EMPTY_VALUE), .OF_ALMOST_FULL_VALUE (OF_ALMOST_FULL_VALUE), .OF_SYNCHRONOUS_MODE (OF_SYNCHRONOUS_MODE), //.OF_OUTPUT_DISABLE (OF_OUTPUT_DISABLE), //.OF_ARRAY_MODE (D_OF_ARRAY_MODE), //.IF_ARRAY_MODE (IF_ARRAY_MODE), .IF_ALMOST_EMPTY_VALUE (IF_ALMOST_EMPTY_VALUE), .IF_ALMOST_FULL_VALUE (IF_ALMOST_FULL_VALUE), .IF_SYNCHRONOUS_MODE (IF_SYNCHRONOUS_MODE), .IODELAY_GRP (IODELAY_GRP), .BANK_TYPE (BANK_TYPE), .BYTELANES_DDR_CK (BYTELANES_DDR_CK), .RCLK_SELECT_LANE (RCLK_SELECT_LANE), .USE_PRE_POST_FIFO (USE_PRE_POST_FIFO), .SYNTHESIS (SYNTHESIS), .TCK (TCK), .PC_CLK_RATIO (PC_CLK_RATIO), .PI_BURST_MODE (D_PI_BURST_MODE), .PI_CLKOUT_DIV (D_PI_CLKOUT_DIV), .PI_FREQ_REF_DIV (D_PI_FREQ_REF_DIV), .PI_FINE_DELAY (D_PI_FINE_DELAY), .PI_OUTPUT_CLK_SRC (D_PI_OUTPUT_CLK_SRC), .PI_SYNC_IN_DIV_RST (D_PI_SYNC_IN_DIV_RST), .PI_SEL_CLK_OFFSET (PI_SEL_CLK_OFFSET), .PO_CLKOUT_DIV (D_PO_CLKOUT_DIV), .PO_FINE_DELAY (D_PO_FINE_DELAY), .PO_COARSE_BYPASS (D_PO_COARSE_BYPASS), .PO_COARSE_DELAY (D_PO_COARSE_DELAY), .PO_OCLK_DELAY (D_PO_OCLK_DELAY), .PO_OCLKDELAY_INV (D_PO_OCLKDELAY_INV), .PO_OUTPUT_CLK_SRC (D_PO_OUTPUT_CLK_SRC), .PO_SYNC_IN_DIV_RST (D_PO_SYNC_IN_DIV_RST), .OSERDES_DATA_RATE (D_OS_DATA_RATE), .OSERDES_DATA_WIDTH (D_OS_DATA_WIDTH), .IDELAYE2_IDELAY_TYPE (D_IDELAYE2_IDELAY_TYPE), .IDELAYE2_IDELAY_VALUE (D_IDELAYE2_IDELAY_VALUE) ,.CKE_ODT_AUX (CKE_ODT_AUX) ) ddr_byte_lane_D( .mem_dq_out (mem_dq_out[47:36]), .mem_dq_ts (mem_dq_ts[47:36]), .mem_dq_in (mem_dq_in[39:30]), .mem_dqs_out (mem_dqs_out[3]), .mem_dqs_ts (mem_dqs_ts[3]), .mem_dqs_in (mem_dqs_in[3]), .rst (D_rst_primitives), .phy_clk (phy_clk), .freq_refclk (freq_refclk), .mem_refclk (mem_refclk), .idelayctrl_refclk (idelayctrl_refclk), .sync_pulse (sync_pulse), .ddr_ck_out (D_ddr_clk), .rclk (D_rclk), .pi_dqs_found (D_pi_dqs_found), .dqs_out_of_range (D_pi_dqs_out_of_range), .if_empty_def (if_empty_def), .if_a_empty (D_if_a_empty), .if_empty (D_if_empty), .if_a_full (/*if_a_full*/), .if_full (D_if_full), .of_a_empty (/*of_a_empty*/), .of_empty (D_of_empty), .of_a_full (D_of_a_full), .of_full (D_of_full), .pre_fifo_a_full (D_pre_fifo_a_full), .phy_din (phy_din_remap[319:240]), .phy_dout (phy_dout_remap[319:240]), .phy_cmd_wr_en (phy_cmd_wr_en), .phy_data_wr_en (phy_data_wr_en), .phy_rd_en (phy_rd_en), .phaser_ctl_bus (phaser_ctl_bus), .idelay_inc (idelay_inc), .idelay_ce (D_idelay_ce), .idelay_ld (D_idelay_ld), .if_rst (if_rst), .byte_rd_en_oth_lanes ({A_byte_rd_en,B_byte_rd_en,C_byte_rd_en}), .byte_rd_en_oth_banks (byte_rd_en_oth_banks), .byte_rd_en (D_byte_rd_en), // calibration signals .pi_rst_dqs_find (D_pi_rst_dqs_find), .po_en_calib (phy_encalib), .po_fine_enable (D_po_fine_enable), .po_coarse_enable (D_po_coarse_enable), .po_fine_inc (D_po_fine_inc), .po_coarse_inc (D_po_coarse_inc), .po_counter_load_en (D_po_counter_load_en), .po_counter_read_en (D_po_counter_read_en), .po_counter_load_val (D_po_counter_load_val), .po_coarse_overflow (D_po_coarse_overflow), .po_fine_overflow (D_po_fine_overflow), .po_counter_read_val (D_po_counter_read_val), .po_sel_fine_oclk_delay(D_po_sel_fine_oclk_delay), .pi_en_calib (phy_encalib), .pi_fine_enable (D_pi_fine_enable), .pi_fine_inc (D_pi_fine_inc), .pi_counter_load_en (D_pi_counter_load_en), .pi_counter_read_en (D_pi_counter_read_en), .pi_counter_load_val (D_pi_counter_load_val), .pi_fine_overflow (D_pi_fine_overflow), .pi_counter_read_val (D_pi_counter_read_val), .pi_iserdes_rst (D_pi_iserdes_rst), .pi_phase_locked (D_pi_phase_locked) ); end else begin : no_ddr_byte_lane_D assign D_of_a_full = 1'b0; assign D_of_full = 1'b0; assign D_pre_fifo_a_full = 1'b0; assign D_if_empty = 1'b0; assign D_byte_rd_en = 1'b1; assign D_if_a_empty = 1'b0; assign D_rclk = 0; assign D_ddr_clk = {LP_DDR_CK_WIDTH*6{1'b0}}; assign D_pi_dqs_found = 1; assign D_pi_phase_locked = 1; assign D_pi_counter_read_val = 0; assign D_po_counter_read_val = 0; assign D_pi_fine_overflow = 0; assign D_po_coarse_overflow = 0; assign D_po_fine_overflow = 0; end endgenerate assign phaser_ctl_bus[MSB_RANK_SEL_I : MSB_RANK_SEL_I - 7] = in_rank; PHY_CONTROL #( .AO_WRLVL_EN ( PC_AO_WRLVL_EN), .AO_TOGGLE ( PC_AO_TOGGLE), .BURST_MODE ( PC_BURST_MODE), .CO_DURATION ( PC_CO_DURATION ), .CLK_RATIO ( PC_CLK_RATIO), .DATA_CTL_A_N ( PC_DATA_CTL_A), .DATA_CTL_B_N ( PC_DATA_CTL_B), .DATA_CTL_C_N ( PC_DATA_CTL_C), .DATA_CTL_D_N ( PC_DATA_CTL_D), .DI_DURATION ( PC_DI_DURATION ), .DO_DURATION ( PC_DO_DURATION ), .EVENTS_DELAY ( PC_EVENTS_DELAY), .FOUR_WINDOW_CLOCKS ( PC_FOUR_WINDOW_CLOCKS), .MULTI_REGION ( PC_MULTI_REGION ), .PHY_COUNT_ENABLE ( PC_PHY_COUNT_EN), .DISABLE_SEQ_MATCH ( PC_DISABLE_SEQ_MATCH), .SYNC_MODE ( PC_SYNC_MODE), .CMD_OFFSET ( PC_CMD_OFFSET), .RD_CMD_OFFSET_0 ( PC_RD_CMD_OFFSET_0), .RD_CMD_OFFSET_1 ( PC_RD_CMD_OFFSET_1), .RD_CMD_OFFSET_2 ( PC_RD_CMD_OFFSET_2), .RD_CMD_OFFSET_3 ( PC_RD_CMD_OFFSET_3), .RD_DURATION_0 ( PC_RD_DURATION_0), .RD_DURATION_1 ( PC_RD_DURATION_1), .RD_DURATION_2 ( PC_RD_DURATION_2), .RD_DURATION_3 ( PC_RD_DURATION_3), .WR_CMD_OFFSET_0 ( PC_WR_CMD_OFFSET_0), .WR_CMD_OFFSET_1 ( PC_WR_CMD_OFFSET_1), .WR_CMD_OFFSET_2 ( PC_WR_CMD_OFFSET_2), .WR_CMD_OFFSET_3 ( PC_WR_CMD_OFFSET_3), .WR_DURATION_0 ( PC_WR_DURATION_0), .WR_DURATION_1 ( PC_WR_DURATION_1), .WR_DURATION_2 ( PC_WR_DURATION_2), .WR_DURATION_3 ( PC_WR_DURATION_3) ) phy_control_i ( .AUXOUTPUT (aux_out), .INBURSTPENDING (phaser_ctl_bus[MSB_BURST_PEND_PI:MSB_BURST_PEND_PI-3]), .INRANKA (in_rank[1:0]), .INRANKB (in_rank[3:2]), .INRANKC (in_rank[5:4]), .INRANKD (in_rank[7:6]), .OUTBURSTPENDING (phaser_ctl_bus[MSB_BURST_PEND_PO:MSB_BURST_PEND_PO-3]), .PCENABLECALIB (phy_encalib), .PHYCTLALMOSTFULL (phy_ctl_a_full), .PHYCTLEMPTY (phy_ctl_empty), .PHYCTLFULL (phy_ctl_full), .PHYCTLREADY (phy_ctl_ready), .MEMREFCLK (mem_refclk), .PHYCLK (phy_ctl_clk), .PHYCTLMSTREMPTY (phy_ctl_mstr_empty), .PHYCTLWD (_phy_ctl_wd), .PHYCTLWRENABLE (phy_ctl_wr), .PLLLOCK (pll_lock), .REFDLLLOCK (ref_dll_lock), // is reset while !locked .RESET (rst), .SYNCIN (sync_pulse), .READCALIBENABLE (phy_read_calib), .WRITECALIBENABLE (phy_write_calib) `ifdef USE_PHY_CONTROL_TEST , .TESTINPUT (16'b0), .TESTOUTPUT (test_output), .TESTSELECT (test_select), .SCANENABLEN (scan_enable) `endif ); // register outputs to give extra slack in timing always @(posedge phy_clk ) begin case (calib_sel[1:0]) 2'h0: begin po_coarse_overflow <= #1 A_po_coarse_overflow; po_fine_overflow <= #1 A_po_fine_overflow; po_counter_read_val <= #1 A_po_counter_read_val; pi_fine_overflow <= #1 A_pi_fine_overflow; pi_counter_read_val<= #1 A_pi_counter_read_val; pi_phase_locked <= #1 A_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 A_pi_dqs_found; pi_dqs_out_of_range <= #1 A_pi_dqs_out_of_range; end 2'h1: begin po_coarse_overflow <= #1 B_po_coarse_overflow; po_fine_overflow <= #1 B_po_fine_overflow; po_counter_read_val <= #1 B_po_counter_read_val; pi_fine_overflow <= #1 B_pi_fine_overflow; pi_counter_read_val <= #1 B_pi_counter_read_val; pi_phase_locked <= #1 B_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 B_pi_dqs_found; pi_dqs_out_of_range <= #1 B_pi_dqs_out_of_range; end 2'h2: begin po_coarse_overflow <= #1 C_po_coarse_overflow; po_fine_overflow <= #1 C_po_fine_overflow; po_counter_read_val <= #1 C_po_counter_read_val; pi_fine_overflow <= #1 C_pi_fine_overflow; pi_counter_read_val <= #1 C_pi_counter_read_val; pi_phase_locked <= #1 C_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 C_pi_dqs_found; pi_dqs_out_of_range <= #1 C_pi_dqs_out_of_range; end 2'h3: begin po_coarse_overflow <= #1 D_po_coarse_overflow; po_fine_overflow <= #1 D_po_fine_overflow; po_counter_read_val <= #1 D_po_counter_read_val; pi_fine_overflow <= #1 D_pi_fine_overflow; pi_counter_read_val <= #1 D_pi_counter_read_val; pi_phase_locked <= #1 D_pi_phase_locked; if ( calib_in_common) pi_dqs_found <= #1 pi_dqs_found_any; else pi_dqs_found <= #1 D_pi_dqs_found; pi_dqs_out_of_range <= #1 D_pi_dqs_out_of_range; end default: begin po_coarse_overflow <= po_coarse_overflow; end endcase end wire B_mux_ctrl; wire C_mux_ctrl; wire D_mux_ctrl; generate if (HIGHEST_LANE > 1) assign B_mux_ctrl = ( !calib_zero_lanes[1] && ( ! calib_zero_ctrl || DATA_CTL_N[1])); else assign B_mux_ctrl = 0; if (HIGHEST_LANE > 2) assign C_mux_ctrl = ( !calib_zero_lanes[2] && (! calib_zero_ctrl || DATA_CTL_N[2])); else assign C_mux_ctrl = 0; if (HIGHEST_LANE > 3) assign D_mux_ctrl = ( !calib_zero_lanes[3] && ( ! calib_zero_ctrl || DATA_CTL_N[3])); else assign D_mux_ctrl = 0; endgenerate always @(*) begin A_pi_fine_enable = 0; A_pi_fine_inc = 0; A_pi_counter_load_en = 0; A_pi_counter_read_en = 0; A_pi_counter_load_val = 0; A_pi_rst_dqs_find = 0; A_po_fine_enable = 0; A_po_coarse_enable = 0; A_po_fine_inc = 0; A_po_coarse_inc = 0; A_po_counter_load_en = 0; A_po_counter_read_en = 0; A_po_counter_load_val = 0; A_po_sel_fine_oclk_delay = 0; A_idelay_ce = 0; A_idelay_ld = 0; B_pi_fine_enable = 0; B_pi_fine_inc = 0; B_pi_counter_load_en = 0; B_pi_counter_read_en = 0; B_pi_counter_load_val = 0; B_pi_rst_dqs_find = 0; B_po_fine_enable = 0; B_po_coarse_enable = 0; B_po_fine_inc = 0; B_po_coarse_inc = 0; B_po_counter_load_en = 0; B_po_counter_read_en = 0; B_po_counter_load_val = 0; B_po_sel_fine_oclk_delay = 0; B_idelay_ce = 0; B_idelay_ld = 0; C_pi_fine_enable = 0; C_pi_fine_inc = 0; C_pi_counter_load_en = 0; C_pi_counter_read_en = 0; C_pi_counter_load_val = 0; C_pi_rst_dqs_find = 0; C_po_fine_enable = 0; C_po_coarse_enable = 0; C_po_fine_inc = 0; C_po_coarse_inc = 0; C_po_counter_load_en = 0; C_po_counter_read_en = 0; C_po_counter_load_val = 0; C_po_sel_fine_oclk_delay = 0; C_idelay_ce = 0; C_idelay_ld = 0; D_pi_fine_enable = 0; D_pi_fine_inc = 0; D_pi_counter_load_en = 0; D_pi_counter_read_en = 0; D_pi_counter_load_val = 0; D_pi_rst_dqs_find = 0; D_po_fine_enable = 0; D_po_coarse_enable = 0; D_po_fine_inc = 0; D_po_coarse_inc = 0; D_po_counter_load_en = 0; D_po_counter_read_en = 0; D_po_counter_load_val = 0; D_po_sel_fine_oclk_delay = 0; D_idelay_ce = 0; D_idelay_ld = 0; if ( calib_sel[2]) begin // if this is asserted, all calib signals are deasserted A_pi_fine_enable = 0; A_pi_fine_inc = 0; A_pi_counter_load_en = 0; A_pi_counter_read_en = 0; A_pi_counter_load_val = 0; A_pi_rst_dqs_find = 0; A_po_fine_enable = 0; A_po_coarse_enable = 0; A_po_fine_inc = 0; A_po_coarse_inc = 0; A_po_counter_load_en = 0; A_po_counter_read_en = 0; A_po_counter_load_val = 0; A_po_sel_fine_oclk_delay = 0; A_idelay_ce = 0; A_idelay_ld = 0; B_pi_fine_enable = 0; B_pi_fine_inc = 0; B_pi_counter_load_en = 0; B_pi_counter_read_en = 0; B_pi_counter_load_val = 0; B_pi_rst_dqs_find = 0; B_po_fine_enable = 0; B_po_coarse_enable = 0; B_po_fine_inc = 0; B_po_coarse_inc = 0; B_po_counter_load_en = 0; B_po_counter_read_en = 0; B_po_counter_load_val = 0; B_po_sel_fine_oclk_delay = 0; B_idelay_ce = 0; B_idelay_ld = 0; C_pi_fine_enable = 0; C_pi_fine_inc = 0; C_pi_counter_load_en = 0; C_pi_counter_read_en = 0; C_pi_counter_load_val = 0; C_pi_rst_dqs_find = 0; C_po_fine_enable = 0; C_po_coarse_enable = 0; C_po_fine_inc = 0; C_po_coarse_inc = 0; C_po_counter_load_en = 0; C_po_counter_read_en = 0; C_po_counter_load_val = 0; C_po_sel_fine_oclk_delay = 0; C_idelay_ce = 0; C_idelay_ld = 0; D_pi_fine_enable = 0; D_pi_fine_inc = 0; D_pi_counter_load_en = 0; D_pi_counter_read_en = 0; D_pi_counter_load_val = 0; D_pi_rst_dqs_find = 0; D_po_fine_enable = 0; D_po_coarse_enable = 0; D_po_fine_inc = 0; D_po_coarse_inc = 0; D_po_counter_load_en = 0; D_po_counter_read_en = 0; D_po_counter_load_val = 0; D_po_sel_fine_oclk_delay = 0; D_idelay_ce = 0; D_idelay_ld = 0; end else if (calib_in_common) begin // if this is asserted, each signal is broadcast to all phasers // in common if ( !calib_zero_lanes[0] && (! calib_zero_ctrl || DATA_CTL_N[0])) begin A_pi_fine_enable = pi_fine_enable; A_pi_fine_inc = pi_fine_inc; A_pi_counter_load_en = pi_counter_load_en; A_pi_counter_read_en = pi_counter_read_en; A_pi_counter_load_val = pi_counter_load_val; A_pi_rst_dqs_find = pi_rst_dqs_find; A_po_fine_enable = po_fine_enable; A_po_coarse_enable = po_coarse_enable; A_po_fine_inc = po_fine_inc; A_po_coarse_inc = po_coarse_inc; A_po_counter_load_en = po_counter_load_en; A_po_counter_read_en = po_counter_read_en; A_po_counter_load_val = po_counter_load_val; A_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; A_idelay_ce = idelay_ce; A_idelay_ld = idelay_ld; end if ( B_mux_ctrl) begin B_pi_fine_enable = pi_fine_enable; B_pi_fine_inc = pi_fine_inc; B_pi_counter_load_en = pi_counter_load_en; B_pi_counter_read_en = pi_counter_read_en; B_pi_counter_load_val = pi_counter_load_val; B_pi_rst_dqs_find = pi_rst_dqs_find; B_po_fine_enable = po_fine_enable; B_po_coarse_enable = po_coarse_enable; B_po_fine_inc = po_fine_inc; B_po_coarse_inc = po_coarse_inc; B_po_counter_load_en = po_counter_load_en; B_po_counter_read_en = po_counter_read_en; B_po_counter_load_val = po_counter_load_val; B_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; B_idelay_ce = idelay_ce; B_idelay_ld = idelay_ld; end if ( C_mux_ctrl) begin C_pi_fine_enable = pi_fine_enable; C_pi_fine_inc = pi_fine_inc; C_pi_counter_load_en = pi_counter_load_en; C_pi_counter_read_en = pi_counter_read_en; C_pi_counter_load_val = pi_counter_load_val; C_pi_rst_dqs_find = pi_rst_dqs_find; C_po_fine_enable = po_fine_enable; C_po_coarse_enable = po_coarse_enable; C_po_fine_inc = po_fine_inc; C_po_coarse_inc = po_coarse_inc; C_po_counter_load_en = po_counter_load_en; C_po_counter_read_en = po_counter_read_en; C_po_counter_load_val = po_counter_load_val; C_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; C_idelay_ce = idelay_ce; C_idelay_ld = idelay_ld; end if ( D_mux_ctrl) begin D_pi_fine_enable = pi_fine_enable; D_pi_fine_inc = pi_fine_inc; D_pi_counter_load_en = pi_counter_load_en; D_pi_counter_read_en = pi_counter_read_en; D_pi_counter_load_val = pi_counter_load_val; D_pi_rst_dqs_find = pi_rst_dqs_find; D_po_fine_enable = po_fine_enable; D_po_coarse_enable = po_coarse_enable; D_po_fine_inc = po_fine_inc; D_po_coarse_inc = po_coarse_inc; D_po_counter_load_en = po_counter_load_en; D_po_counter_read_en = po_counter_read_en; D_po_counter_load_val = po_counter_load_val; D_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; D_idelay_ce = idelay_ce; D_idelay_ld = idelay_ld; end end else begin // otherwise, only a single phaser is selected case (calib_sel[1:0]) 0: begin A_pi_fine_enable = pi_fine_enable; A_pi_fine_inc = pi_fine_inc; A_pi_counter_load_en = pi_counter_load_en; A_pi_counter_read_en = pi_counter_read_en; A_pi_counter_load_val = pi_counter_load_val; A_pi_rst_dqs_find = pi_rst_dqs_find; A_po_fine_enable = po_fine_enable; A_po_coarse_enable = po_coarse_enable; A_po_fine_inc = po_fine_inc; A_po_coarse_inc = po_coarse_inc; A_po_counter_load_en = po_counter_load_en; A_po_counter_read_en = po_counter_read_en; A_po_counter_load_val = po_counter_load_val; A_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; A_idelay_ce = idelay_ce; A_idelay_ld = idelay_ld; end 1: begin B_pi_fine_enable = pi_fine_enable; B_pi_fine_inc = pi_fine_inc; B_pi_counter_load_en = pi_counter_load_en; B_pi_counter_read_en = pi_counter_read_en; B_pi_counter_load_val = pi_counter_load_val; B_pi_rst_dqs_find = pi_rst_dqs_find; B_po_fine_enable = po_fine_enable; B_po_coarse_enable = po_coarse_enable; B_po_fine_inc = po_fine_inc; B_po_coarse_inc = po_coarse_inc; B_po_counter_load_en = po_counter_load_en; B_po_counter_read_en = po_counter_read_en; B_po_counter_load_val = po_counter_load_val; B_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; B_idelay_ce = idelay_ce; B_idelay_ld = idelay_ld; end 2: begin C_pi_fine_enable = pi_fine_enable; C_pi_fine_inc = pi_fine_inc; C_pi_counter_load_en = pi_counter_load_en; C_pi_counter_read_en = pi_counter_read_en; C_pi_counter_load_val = pi_counter_load_val; C_pi_rst_dqs_find = pi_rst_dqs_find; C_po_fine_enable = po_fine_enable; C_po_coarse_enable = po_coarse_enable; C_po_fine_inc = po_fine_inc; C_po_coarse_inc = po_coarse_inc; C_po_counter_load_en = po_counter_load_en; C_po_counter_read_en = po_counter_read_en; C_po_counter_load_val = po_counter_load_val; C_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; C_idelay_ce = idelay_ce; C_idelay_ld = idelay_ld; end 3: begin D_pi_fine_enable = pi_fine_enable; D_pi_fine_inc = pi_fine_inc; D_pi_counter_load_en = pi_counter_load_en; D_pi_counter_read_en = pi_counter_read_en; D_pi_counter_load_val = pi_counter_load_val; D_pi_rst_dqs_find = pi_rst_dqs_find; D_po_fine_enable = po_fine_enable; D_po_coarse_enable = po_coarse_enable; D_po_fine_inc = po_fine_inc; D_po_coarse_inc = po_coarse_inc; D_po_counter_load_en = po_counter_load_en; D_po_counter_load_val = po_counter_load_val; D_po_counter_read_en = po_counter_read_en; D_po_sel_fine_oclk_delay = po_sel_fine_oclk_delay; D_idelay_ce = idelay_ce; D_idelay_ld = idelay_ld; end endcase end end //obligatory phaser-ref PHASER_REF phaser_ref_i( .LOCKED (ref_dll_lock), .CLKIN (freq_refclk), .PWRDWN (1'b0), .RST ( ! pll_lock) ); // optional idelay_ctrl generate if ( GENERATE_IDELAYCTRL == "TRUE") IDELAYCTRL idelayctrl ( .RDY (/*idelayctrl_rdy*/), .REFCLK (idelayctrl_refclk), .RST (rst) ); endgenerate endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : mig_7series_v1_x_ddr_if_post_fifo.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Feb 08 2011 // \___\/\___\ // //Device : 7 Series //Design Name : DDR3 SDRAM //Purpose : Extends the depth of a PHASER IN_FIFO up to 4 entries //Reference : //Revision History : //***************************************************************************** `timescale 1 ps / 1 ps module mig_7series_v1_9_ddr_if_post_fifo # ( parameter TCQ = 100, // clk->out delay (sim only) parameter DEPTH = 4, // # of entries parameter WIDTH = 32 // data bus width ) ( input clk, // clock input rst, // synchronous reset input [3:0] empty_in, input rd_en_in, input [WIDTH-1:0] d_in, // write data from controller output empty_out, output byte_rd_en, output [WIDTH-1:0] d_out // write data to OUT_FIFO ); // # of bits used to represent read/write pointers localparam PTR_BITS = (DEPTH == 2) ? 1 : (((DEPTH == 3) || (DEPTH == 4)) ? 2 : 'bx); integer i; reg [WIDTH-1:0] mem[0:DEPTH-1]; (* keep = "true", max_fanout = 3 *) reg [4:0] my_empty /* synthesis syn_maxfan = 3 */; (* keep = "true", max_fanout = 3 *) reg [1:0] my_full /* synthesis syn_maxfan = 3 */; (* keep = "true", max_fanout = 10 *) reg [PTR_BITS-1:0] rd_ptr /* synthesis syn_maxfan = 10 */; (* keep = "true", max_fanout = 10 *) reg [PTR_BITS-1:0] wr_ptr /* synthesis syn_maxfan = 10 */; wire [WIDTH-1:0] mem_out; (* keep = "true", max_fanout = 10 *) wire wr_en /* synthesis syn_maxfan = 10 */; task updt_ptrs; input rd; input wr; reg [1:0] next_rd_ptr; reg [1:0] next_wr_ptr; begin next_rd_ptr = (rd_ptr + 1'b1)%DEPTH; next_wr_ptr = (wr_ptr + 1'b1)%DEPTH; casez ({rd, wr, my_empty[1], my_full[1]}) 4'b00zz: ; // No access, do nothing 4'b0100: begin // Write when neither empty, nor full; check for full wr_ptr <= #TCQ next_wr_ptr; my_full[0] <= #TCQ (next_wr_ptr == rd_ptr); my_full[1] <= #TCQ (next_wr_ptr == rd_ptr); //mem[wr_ptr] <= #TCQ d_in; end 4'b0110: begin // Write when empty; no need to check for full wr_ptr <= #TCQ next_wr_ptr; my_empty <= #TCQ 5'b00000; //mem[wr_ptr] <= #TCQ d_in; end 4'b1000: begin // Read when neither empty, nor full; check for empty rd_ptr <= #TCQ next_rd_ptr; my_empty[0] <= #TCQ (next_rd_ptr == wr_ptr); my_empty[1] <= #TCQ (next_rd_ptr == wr_ptr); my_empty[2] <= #TCQ (next_rd_ptr == wr_ptr); my_empty[3] <= #TCQ (next_rd_ptr == wr_ptr); my_empty[4] <= #TCQ (next_rd_ptr == wr_ptr); end 4'b1001: begin // Read when full; no need to check for empty rd_ptr <= #TCQ next_rd_ptr; my_full[0] <= #TCQ 1'b0; my_full[1] <= #TCQ 1'b0; end 4'b1100, 4'b1101, 4'b1110: begin // Read and write when empty, full, or neither empty/full; no need // to check for empty or full conditions rd_ptr <= #TCQ next_rd_ptr; wr_ptr <= #TCQ next_wr_ptr; //mem[wr_ptr] <= #TCQ d_in; end 4'b0101, 4'b1010: ; // Read when empty, Write when full; Keep all pointers the same // and don't change any of the flags (i.e. ignore the read/write). // This might happen because a faulty DQS_FOUND calibration could // result in excessive skew between when the various IN_FIFO's // first become not empty. In this case, the data going to each // post-FIFO/IN_FIFO should be read out and discarded // synthesis translate_off default: begin // Covers any other cases, in particular for simulation if // any signals are X's $display("ERR %m @%t: Bad access: rd:%b,wr:%b,empty:%b,full:%b", $time, rd, wr, my_empty[1], my_full[1]); rd_ptr <= #TCQ 2'bxx; wr_ptr <= #TCQ 2'bxx; end // synthesis translate_on endcase end endtask assign d_out = my_empty[4] ? d_in : mem_out;//mem[rd_ptr]; // The combined IN_FIFO + post FIFO is only "empty" when both are empty assign empty_out = empty_in[0] & my_empty[0]; assign byte_rd_en = !empty_in[3] || !my_empty[3]; always @(posedge clk) if (rst) begin my_empty <= #TCQ 5'b11111; my_full <= #TCQ 2'b00; rd_ptr <= #TCQ 'b0; wr_ptr <= #TCQ 'b0; end else begin // Special mode: If IN_FIFO has data, and controller is reading at // the same time, then operate post-FIFO in "passthrough" mode (i.e. // don't update any of the read/write pointers, and route IN_FIFO // data to post-FIFO data) if (my_empty[1] && !my_full[1] && rd_en_in && !empty_in[1]) ; else // Otherwise, we're writing to FIFO when IN_FIFO is not empty, // and reading from the FIFO based on the rd_en_in signal (read // enable from controller). The functino updt_ptrs should catch // an illegal conditions. updt_ptrs(rd_en_in, !empty_in[1]); end assign wr_en = (!empty_in[2] & ((!rd_en_in & !my_full[0]) | (rd_en_in & !my_empty[2]))); always @ (posedge clk) begin if (wr_en) mem[wr_ptr] <= #TCQ d_in; end assign mem_out = mem[rd_ptr]; endmodule
//***************************************************************************** // (c) Copyright 2009 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor: Xilinx // \ \ \/ Version: // \ \ Application: MIG // / / Filename: ddr_phy_rdlvl.v // /___/ /\ Date Last Modified: $Date: 2011/06/24 14:49:00 $ // \ \ / \ Date Created: // \___\/\___\ // //Device: 7 Series //Design Name: DDR3 SDRAM //Purpose: // Read leveling Stage1 calibration logic // NOTES: // 1. Window detection with PRBS pattern. //Reference: //Revision History: //***************************************************************************** /****************************************************************************** **$Id: ddr_phy_rdlvl.v,v 1.2 2011/06/24 14:49:00 mgeorge Exp $ **$Date: 2011/06/24 14:49:00 $ **$Author: mgeorge $ **$Revision: 1.2 $ **$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_7series_v1_3/data/dlib/7series/ddr3_sdram/verilog/rtl/phy/ddr_phy_rdlvl.v,v $ ******************************************************************************/ `timescale 1ps/1ps (* use_dsp48 = "no" *) module mig_7series_v1_9_ddr_phy_rdlvl # ( parameter TCQ = 100, // clk->out delay (sim only) parameter nCK_PER_CLK = 2, // # of memory clocks per CLK parameter CLK_PERIOD = 3333, // Internal clock period (in ps) parameter DQ_WIDTH = 64, // # of DQ (data) parameter DQS_CNT_WIDTH = 3, // = ceil(log2(DQS_WIDTH)) parameter DQS_WIDTH = 8, // # of DQS (strobe) parameter DRAM_WIDTH = 8, // # of DQ per DQS parameter RANKS = 1, // # of DRAM ranks parameter PER_BIT_DESKEW = "ON", // Enable per-bit DQ deskew parameter SIM_CAL_OPTION = "NONE", // Skip various calibration steps parameter DEBUG_PORT = "OFF", // Enable debug port parameter DRAM_TYPE = "DDR3", // Memory I/F type: "DDR3", "DDR2" parameter OCAL_EN = "ON" ) ( input clk, input rst, // Calibration status, control signals input mpr_rdlvl_start, output mpr_rdlvl_done, output reg mpr_last_byte_done, output mpr_rnk_done, input rdlvl_stg1_start, (* keep = "true", max_fanout = 30 *) output reg rdlvl_stg1_done /* synthesis syn_maxfan = 30 */, output rdlvl_stg1_rnk_done, output reg rdlvl_stg1_err, output mpr_rdlvl_err, output rdlvl_err, output reg rdlvl_prech_req, output reg rdlvl_last_byte_done, output reg rdlvl_assrt_common, input prech_done, input phy_if_empty, input [4:0] idelaye2_init_val, // Captured data in fabric clock domain input [2*nCK_PER_CLK*DQ_WIDTH-1:0] rd_data, // Decrement initial Phaser_IN Fine tap delay input dqs_po_dec_done, input [5:0] pi_counter_read_val, // Stage 1 calibration outputs output reg pi_fine_dly_dec_done, output reg pi_en_stg2_f, output reg pi_stg2_f_incdec, output reg pi_stg2_load, output reg [5:0] pi_stg2_reg_l, output [DQS_CNT_WIDTH:0] pi_stg2_rdlvl_cnt, // To DQ IDELAY required to find left edge of // valid window output idelay_ce, output idelay_inc, input idelay_ld, input [DQS_CNT_WIDTH:0] wrcal_cnt, // Only output if Per-bit de-skew enabled output reg [5*RANKS*DQ_WIDTH-1:0] dlyval_dq, // Debug Port output [6*DQS_WIDTH*RANKS-1:0] dbg_cpt_first_edge_cnt, output [6*DQS_WIDTH*RANKS-1:0] dbg_cpt_second_edge_cnt, output [6*DQS_WIDTH*RANKS-1:0] dbg_cpt_tap_cnt, output [5*DQS_WIDTH*RANKS-1:0] dbg_dq_idelay_tap_cnt, input dbg_idel_up_all, input dbg_idel_down_all, input dbg_idel_up_cpt, input dbg_idel_down_cpt, input [DQS_CNT_WIDTH-1:0] dbg_sel_idel_cpt, input dbg_sel_all_idel_cpt, output [255:0] dbg_phy_rdlvl ); // minimum time (in IDELAY taps) for which capture data must be stable for // algorithm to consider a valid data eye to be found. The read leveling // logic will ignore any window found smaller than this value. Limitations // on how small this number can be is determined by: (1) the algorithmic // limitation of how many taps wide the data eye can be (3 taps), and (2) // how wide regions of "instability" that occur around the edges of the // read valid window can be (i.e. need to be able to filter out "false" // windows that occur for a short # of taps around the edges of the true // data window, although with multi-sampling during read leveling, this is // not as much a concern) - the larger the value, the more protection // against "false" windows localparam MIN_EYE_SIZE = 16; // Length of calibration sequence (in # of words) localparam CAL_PAT_LEN = 8; // Read data shift register length localparam RD_SHIFT_LEN = CAL_PAT_LEN / (2*nCK_PER_CLK); // # of cycles required to perform read data shift register compare // This is defined as from the cycle the new data is loaded until // signal found_edge_r is valid localparam RD_SHIFT_COMP_DELAY = 5; // worst-case # of cycles to wait to ensure that both the SR and // PREV_SR shift registers have valid data, and that the comparison // of the two shift register values is valid. The "+1" at the end of // this equation is a fudge factor, I freely admit that localparam SR_VALID_DELAY = (2 * RD_SHIFT_LEN) + RD_SHIFT_COMP_DELAY + 1; // # of clock cycles to wait after changing tap value or read data MUX // to allow: (1) tap chain to settle, (2) for delayed input to propagate // thru ISERDES, (3) for the read data comparison logic to have time to // output the comparison of two consecutive samples of the settled read data // The minimum delay is 16 cycles, which should be good enough to handle all // three of the above conditions for the simulation-only case with a short // training pattern. For H/W (or for simulation with longer training // pattern), it will take longer to store and compare two consecutive // samples, and the value of this parameter will reflect that localparam PIPE_WAIT_CNT = (SR_VALID_DELAY < 8) ? 16 : (SR_VALID_DELAY + 8); // # of read data samples to examine when detecting whether an edge has // occured during stage 1 calibration. Width of local param must be // changed as appropriate. Note that there are two counters used, each // counter can be changed independently of the other - they are used in // cascade to create a larger counter localparam [11:0] DETECT_EDGE_SAMPLE_CNT0 = 12'h001; //12'hFFF; localparam [11:0] DETECT_EDGE_SAMPLE_CNT1 = 12'h001; // 12'h1FF Must be > 0 localparam [5:0] CAL1_IDLE = 6'h00; localparam [5:0] CAL1_NEW_DQS_WAIT = 6'h01; localparam [5:0] CAL1_STORE_FIRST_WAIT = 6'h02; localparam [5:0] CAL1_PAT_DETECT = 6'h03; localparam [5:0] CAL1_DQ_IDEL_TAP_INC = 6'h04; localparam [5:0] CAL1_DQ_IDEL_TAP_INC_WAIT = 6'h05; localparam [5:0] CAL1_DQ_IDEL_TAP_DEC = 6'h06; localparam [5:0] CAL1_DQ_IDEL_TAP_DEC_WAIT = 6'h07; localparam [5:0] CAL1_DETECT_EDGE = 6'h08; localparam [5:0] CAL1_IDEL_INC_CPT = 6'h09; localparam [5:0] CAL1_IDEL_INC_CPT_WAIT = 6'h0A; localparam [5:0] CAL1_CALC_IDEL = 6'h0B; localparam [5:0] CAL1_IDEL_DEC_CPT = 6'h0C; localparam [5:0] CAL1_IDEL_DEC_CPT_WAIT = 6'h0D; localparam [5:0] CAL1_NEXT_DQS = 6'h0E; localparam [5:0] CAL1_DONE = 6'h0F; localparam [5:0] CAL1_PB_STORE_FIRST_WAIT = 6'h10; localparam [5:0] CAL1_PB_DETECT_EDGE = 6'h11; localparam [5:0] CAL1_PB_INC_CPT = 6'h12; localparam [5:0] CAL1_PB_INC_CPT_WAIT = 6'h13; localparam [5:0] CAL1_PB_DEC_CPT_LEFT = 6'h14; localparam [5:0] CAL1_PB_DEC_CPT_LEFT_WAIT = 6'h15; localparam [5:0] CAL1_PB_DETECT_EDGE_DQ = 6'h16; localparam [5:0] CAL1_PB_INC_DQ = 6'h17; localparam [5:0] CAL1_PB_INC_DQ_WAIT = 6'h18; localparam [5:0] CAL1_PB_DEC_CPT = 6'h19; localparam [5:0] CAL1_PB_DEC_CPT_WAIT = 6'h1A; localparam [5:0] CAL1_REGL_LOAD = 6'h1B; localparam [5:0] CAL1_RDLVL_ERR = 6'h1C; localparam [5:0] CAL1_MPR_NEW_DQS_WAIT = 6'h1D; localparam [5:0] CAL1_VALID_WAIT = 6'h1E; localparam [5:0] CAL1_MPR_PAT_DETECT = 6'h1F; localparam [5:0] CAL1_NEW_DQS_PREWAIT = 6'h20; integer a; integer b; integer d; integer e; integer f; integer h; integer g; integer i; integer j; integer k; integer l; integer m; integer n; integer r; integer p; integer q; integer s; integer t; integer u; integer w; integer ce_i; integer ce_rnk_i; integer aa; integer bb; integer cc; integer dd; genvar x; genvar z; reg [DQS_CNT_WIDTH:0] cal1_cnt_cpt_r; wire [DQS_CNT_WIDTH+2:0]cal1_cnt_cpt_timing; reg [DQS_CNT_WIDTH:0] cal1_cnt_cpt_timing_r; reg cal1_dq_idel_ce; reg cal1_dq_idel_inc; reg cal1_dlyce_cpt_r; reg cal1_dlyinc_cpt_r; reg cal1_dlyce_dq_r; reg cal1_dlyinc_dq_r; reg cal1_wait_cnt_en_r; reg [4:0] cal1_wait_cnt_r; reg cal1_wait_r; reg [DQ_WIDTH-1:0] dlyce_dq_r; reg dlyinc_dq_r; reg [4:0] dlyval_dq_reg_r [0:RANKS-1][0:DQ_WIDTH-1]; reg cal1_prech_req_r; reg [5:0] cal1_state_r; reg [5:0] cal1_state_r1; reg [5:0] cnt_idel_dec_cpt_r; reg [3:0] cnt_shift_r; reg detect_edge_done_r; reg [5:0] right_edge_taps_r; reg [5:0] first_edge_taps_r; reg found_edge_r; reg found_first_edge_r; reg found_second_edge_r; reg found_stable_eye_r; reg found_stable_eye_last_r; reg found_edge_all_r; reg [5:0] tap_cnt_cpt_r; reg tap_limit_cpt_r; reg [4:0] idel_tap_cnt_dq_pb_r; reg idel_tap_limit_dq_pb_r; reg [DRAM_WIDTH-1:0] mux_rd_fall0_r; reg [DRAM_WIDTH-1:0] mux_rd_fall1_r; reg [DRAM_WIDTH-1:0] mux_rd_rise0_r; reg [DRAM_WIDTH-1:0] mux_rd_rise1_r; reg [DRAM_WIDTH-1:0] mux_rd_fall2_r; reg [DRAM_WIDTH-1:0] mux_rd_fall3_r; reg [DRAM_WIDTH-1:0] mux_rd_rise2_r; reg [DRAM_WIDTH-1:0] mux_rd_rise3_r; reg mux_rd_valid_r; reg new_cnt_cpt_r; reg [RD_SHIFT_LEN-1:0] old_sr_fall0_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] old_sr_fall1_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] old_sr_rise0_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] old_sr_rise1_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] old_sr_fall2_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] old_sr_fall3_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] old_sr_rise2_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] old_sr_rise3_r [DRAM_WIDTH-1:0]; reg [DRAM_WIDTH-1:0] old_sr_match_fall0_r; reg [DRAM_WIDTH-1:0] old_sr_match_fall1_r; reg [DRAM_WIDTH-1:0] old_sr_match_rise0_r; reg [DRAM_WIDTH-1:0] old_sr_match_rise1_r; reg [DRAM_WIDTH-1:0] old_sr_match_fall2_r; reg [DRAM_WIDTH-1:0] old_sr_match_fall3_r; reg [DRAM_WIDTH-1:0] old_sr_match_rise2_r; reg [DRAM_WIDTH-1:0] old_sr_match_rise3_r; reg [4:0] pb_cnt_eye_size_r [DRAM_WIDTH-1:0]; reg [DRAM_WIDTH-1:0] pb_detect_edge_done_r; reg [DRAM_WIDTH-1:0] pb_found_edge_last_r; reg [DRAM_WIDTH-1:0] pb_found_edge_r; reg [DRAM_WIDTH-1:0] pb_found_first_edge_r; reg [DRAM_WIDTH-1:0] pb_found_stable_eye_r; reg [DRAM_WIDTH-1:0] pb_last_tap_jitter_r; reg pi_en_stg2_f_timing; reg pi_stg2_f_incdec_timing; reg pi_stg2_load_timing; reg [5:0] pi_stg2_reg_l_timing; reg [DRAM_WIDTH-1:0] prev_sr_diff_r; reg [RD_SHIFT_LEN-1:0] prev_sr_fall0_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] prev_sr_fall1_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] prev_sr_rise0_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] prev_sr_rise1_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] prev_sr_fall2_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] prev_sr_fall3_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] prev_sr_rise2_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] prev_sr_rise3_r [DRAM_WIDTH-1:0]; reg [DRAM_WIDTH-1:0] prev_sr_match_cyc2_r; reg [DRAM_WIDTH-1:0] prev_sr_match_fall0_r; reg [DRAM_WIDTH-1:0] prev_sr_match_fall1_r; reg [DRAM_WIDTH-1:0] prev_sr_match_rise0_r; reg [DRAM_WIDTH-1:0] prev_sr_match_rise1_r; reg [DRAM_WIDTH-1:0] prev_sr_match_fall2_r; reg [DRAM_WIDTH-1:0] prev_sr_match_fall3_r; reg [DRAM_WIDTH-1:0] prev_sr_match_rise2_r; reg [DRAM_WIDTH-1:0] prev_sr_match_rise3_r; wire [DQ_WIDTH-1:0] rd_data_rise0; wire [DQ_WIDTH-1:0] rd_data_fall0; wire [DQ_WIDTH-1:0] rd_data_rise1; wire [DQ_WIDTH-1:0] rd_data_fall1; wire [DQ_WIDTH-1:0] rd_data_rise2; wire [DQ_WIDTH-1:0] rd_data_fall2; wire [DQ_WIDTH-1:0] rd_data_rise3; wire [DQ_WIDTH-1:0] rd_data_fall3; reg samp_cnt_done_r; reg samp_edge_cnt0_en_r; reg [11:0] samp_edge_cnt0_r; reg samp_edge_cnt1_en_r; reg [11:0] samp_edge_cnt1_r; reg [DQS_CNT_WIDTH:0] rd_mux_sel_r; reg [5:0] second_edge_taps_r; reg [RD_SHIFT_LEN-1:0] sr_fall0_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] sr_fall1_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] sr_rise0_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] sr_rise1_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] sr_fall2_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] sr_fall3_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] sr_rise2_r [DRAM_WIDTH-1:0]; reg [RD_SHIFT_LEN-1:0] sr_rise3_r [DRAM_WIDTH-1:0]; reg store_sr_r; reg store_sr_req_pulsed_r; reg store_sr_req_r; reg sr_valid_r; reg sr_valid_r1; reg sr_valid_r2; reg [DRAM_WIDTH-1:0] old_sr_diff_r; reg [DRAM_WIDTH-1:0] old_sr_match_cyc2_r; reg pat0_data_match_r; reg pat1_data_match_r; wire pat_data_match_r; wire [RD_SHIFT_LEN-1:0] pat0_fall0 [3:0]; wire [RD_SHIFT_LEN-1:0] pat0_fall1 [3:0]; wire [RD_SHIFT_LEN-1:0] pat0_fall2 [3:0]; wire [RD_SHIFT_LEN-1:0] pat0_fall3 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_fall0 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_fall1 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_fall2 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_fall3 [3:0]; reg [DRAM_WIDTH-1:0] pat0_match_fall0_r; reg pat0_match_fall0_and_r; reg [DRAM_WIDTH-1:0] pat0_match_fall1_r; reg pat0_match_fall1_and_r; reg [DRAM_WIDTH-1:0] pat0_match_fall2_r; reg pat0_match_fall2_and_r; reg [DRAM_WIDTH-1:0] pat0_match_fall3_r; reg pat0_match_fall3_and_r; reg [DRAM_WIDTH-1:0] pat0_match_rise0_r; reg pat0_match_rise0_and_r; reg [DRAM_WIDTH-1:0] pat0_match_rise1_r; reg pat0_match_rise1_and_r; reg [DRAM_WIDTH-1:0] pat0_match_rise2_r; reg pat0_match_rise2_and_r; reg [DRAM_WIDTH-1:0] pat0_match_rise3_r; reg pat0_match_rise3_and_r; reg [DRAM_WIDTH-1:0] pat1_match_fall0_r; reg pat1_match_fall0_and_r; reg [DRAM_WIDTH-1:0] pat1_match_fall1_r; reg pat1_match_fall1_and_r; reg [DRAM_WIDTH-1:0] pat1_match_fall2_r; reg pat1_match_fall2_and_r; reg [DRAM_WIDTH-1:0] pat1_match_fall3_r; reg pat1_match_fall3_and_r; reg [DRAM_WIDTH-1:0] pat1_match_rise0_r; reg pat1_match_rise0_and_r; reg [DRAM_WIDTH-1:0] pat1_match_rise1_r; reg pat1_match_rise1_and_r; reg [DRAM_WIDTH-1:0] pat1_match_rise2_r; reg pat1_match_rise2_and_r; reg [DRAM_WIDTH-1:0] pat1_match_rise3_r; reg pat1_match_rise3_and_r; reg [4:0] idelay_tap_cnt_r [0:RANKS-1][0:DQS_WIDTH-1]; reg [5*DQS_WIDTH*RANKS-1:0] idelay_tap_cnt_w; reg [4:0] idelay_tap_cnt_slice_r; reg idelay_tap_limit_r; wire [RD_SHIFT_LEN-1:0] pat0_rise0 [3:0]; wire [RD_SHIFT_LEN-1:0] pat0_rise1 [3:0]; wire [RD_SHIFT_LEN-1:0] pat0_rise2 [3:0]; wire [RD_SHIFT_LEN-1:0] pat0_rise3 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_rise0 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_rise1 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_rise2 [3:0]; wire [RD_SHIFT_LEN-1:0] pat1_rise3 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_rise0 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_fall0 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_rise1 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_fall1 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_rise2 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_fall2 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_rise3 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat0_fall3 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_rise0 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_fall0 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_rise1 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_fall1 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_rise2 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_fall2 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_rise3 [3:0]; wire [RD_SHIFT_LEN-1:0] idel_pat1_fall3 [3:0]; reg [DRAM_WIDTH-1:0] idel_pat0_match_rise0_r; reg [DRAM_WIDTH-1:0] idel_pat0_match_fall0_r; reg [DRAM_WIDTH-1:0] idel_pat0_match_rise1_r; reg [DRAM_WIDTH-1:0] idel_pat0_match_fall1_r; reg [DRAM_WIDTH-1:0] idel_pat0_match_rise2_r; reg [DRAM_WIDTH-1:0] idel_pat0_match_fall2_r; reg [DRAM_WIDTH-1:0] idel_pat0_match_rise3_r; reg [DRAM_WIDTH-1:0] idel_pat0_match_fall3_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_rise0_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_fall0_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_rise1_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_fall1_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_rise2_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_fall2_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_rise3_r; reg [DRAM_WIDTH-1:0] idel_pat1_match_fall3_r; reg idel_pat0_match_rise0_and_r; reg idel_pat0_match_fall0_and_r; reg idel_pat0_match_rise1_and_r; reg idel_pat0_match_fall1_and_r; reg idel_pat0_match_rise2_and_r; reg idel_pat0_match_fall2_and_r; reg idel_pat0_match_rise3_and_r; reg idel_pat0_match_fall3_and_r; reg idel_pat1_match_rise0_and_r; reg idel_pat1_match_fall0_and_r; reg idel_pat1_match_rise1_and_r; reg idel_pat1_match_fall1_and_r; reg idel_pat1_match_rise2_and_r; reg idel_pat1_match_fall2_and_r; reg idel_pat1_match_rise3_and_r; reg idel_pat1_match_fall3_and_r; reg idel_pat0_data_match_r; reg idel_pat1_data_match_r; reg idel_pat_data_match; reg idel_pat_data_match_r; reg [4:0] idel_dec_cnt; reg [5:0] rdlvl_dqs_tap_cnt_r [0:RANKS-1][0:DQS_WIDTH-1]; reg [1:0] rnk_cnt_r; reg rdlvl_rank_done_r; reg [3:0] done_cnt; reg [1:0] regl_rank_cnt; reg [DQS_CNT_WIDTH:0] regl_dqs_cnt; reg [DQS_CNT_WIDTH:0] regl_dqs_cnt_r; wire [DQS_CNT_WIDTH+2:0]regl_dqs_cnt_timing; reg regl_rank_done_r; reg rdlvl_stg1_start_r; reg dqs_po_dec_done_r1; reg dqs_po_dec_done_r2; reg fine_dly_dec_done_r1; reg fine_dly_dec_done_r2; reg [3:0] wait_cnt_r; reg [5:0] pi_rdval_cnt; reg pi_cnt_dec; reg mpr_valid_r; reg mpr_valid_r1; reg mpr_valid_r2; reg mpr_rd_rise0_prev_r; reg mpr_rd_fall0_prev_r; reg mpr_rd_rise1_prev_r; reg mpr_rd_fall1_prev_r; reg mpr_rd_rise2_prev_r; reg mpr_rd_fall2_prev_r; reg mpr_rd_rise3_prev_r; reg mpr_rd_fall3_prev_r; reg mpr_rdlvl_done_r; reg mpr_rdlvl_done_r1; reg mpr_rdlvl_done_r2; reg mpr_rdlvl_start_r; reg mpr_rank_done_r; reg [2:0] stable_idel_cnt; reg inhibit_edge_detect_r; reg idel_pat_detect_valid_r; reg idel_mpr_pat_detect_r; reg mpr_pat_detect_r; reg mpr_dec_cpt_r; // Debug reg [6*DQS_WIDTH*RANKS-1:0] dbg_cpt_first_edge_taps; reg [6*DQS_WIDTH*RANKS-1:0] dbg_cpt_second_edge_taps; reg [6*DQS_WIDTH*RANKS-1:0] dbg_cpt_tap_cnt_w; //*************************************************************************** // Debug //*************************************************************************** always @(*) begin for (d = 0; d < RANKS; d = d + 1) begin for (e = 0; e < DQS_WIDTH; e = e + 1) begin idelay_tap_cnt_w[(5*e+5*DQS_WIDTH*d)+:5] <= #TCQ idelay_tap_cnt_r[d][e]; dbg_cpt_tap_cnt_w[(6*e+6*DQS_WIDTH*d)+:6] <= #TCQ rdlvl_dqs_tap_cnt_r[d][e]; end end end assign mpr_rdlvl_err = rdlvl_stg1_err & (!mpr_rdlvl_done); assign rdlvl_err = rdlvl_stg1_err & (mpr_rdlvl_done); assign dbg_phy_rdlvl[0] = rdlvl_stg1_start; assign dbg_phy_rdlvl[1] = pat_data_match_r; assign dbg_phy_rdlvl[2] = mux_rd_valid_r; assign dbg_phy_rdlvl[3] = idelay_tap_limit_r; assign dbg_phy_rdlvl[8:4] = 'b0; assign dbg_phy_rdlvl[14:9] = cal1_state_r[5:0]; assign dbg_phy_rdlvl[20:15] = cnt_idel_dec_cpt_r; assign dbg_phy_rdlvl[21] = found_first_edge_r; assign dbg_phy_rdlvl[22] = found_second_edge_r; assign dbg_phy_rdlvl[23] = found_edge_r; assign dbg_phy_rdlvl[24] = store_sr_r; // [40:25] previously used for sr, old_sr shift registers. If connecting // these signals again, don't forget to parameterize based on RD_SHIFT_LEN assign dbg_phy_rdlvl[40:25] = 'b0; assign dbg_phy_rdlvl[41] = sr_valid_r; assign dbg_phy_rdlvl[42] = found_stable_eye_r; assign dbg_phy_rdlvl[48:43] = tap_cnt_cpt_r; assign dbg_phy_rdlvl[54:49] = first_edge_taps_r; assign dbg_phy_rdlvl[60:55] = second_edge_taps_r; assign dbg_phy_rdlvl[64:61] = cal1_cnt_cpt_timing_r; assign dbg_phy_rdlvl[65] = cal1_dlyce_cpt_r; assign dbg_phy_rdlvl[66] = cal1_dlyinc_cpt_r; assign dbg_phy_rdlvl[67] = found_edge_r; assign dbg_phy_rdlvl[68] = found_first_edge_r; assign dbg_phy_rdlvl[73:69] = 'b0; assign dbg_phy_rdlvl[74] = idel_pat_data_match; assign dbg_phy_rdlvl[75] = idel_pat0_data_match_r; assign dbg_phy_rdlvl[76] = idel_pat1_data_match_r; assign dbg_phy_rdlvl[77] = pat0_data_match_r; assign dbg_phy_rdlvl[78] = pat1_data_match_r; assign dbg_phy_rdlvl[79+:5*DQS_WIDTH*RANKS] = idelay_tap_cnt_w; assign dbg_phy_rdlvl[170+:8] = mux_rd_rise0_r; assign dbg_phy_rdlvl[178+:8] = mux_rd_fall0_r; assign dbg_phy_rdlvl[186+:8] = mux_rd_rise1_r; assign dbg_phy_rdlvl[194+:8] = mux_rd_fall1_r; assign dbg_phy_rdlvl[202+:8] = mux_rd_rise2_r; assign dbg_phy_rdlvl[210+:8] = mux_rd_fall2_r; assign dbg_phy_rdlvl[218+:8] = mux_rd_rise3_r; assign dbg_phy_rdlvl[226+:8] = mux_rd_fall3_r; //*************************************************************************** // Debug output //*************************************************************************** // CPT taps assign dbg_cpt_first_edge_cnt = dbg_cpt_first_edge_taps; assign dbg_cpt_second_edge_cnt = dbg_cpt_second_edge_taps; assign dbg_cpt_tap_cnt = dbg_cpt_tap_cnt_w; assign dbg_dq_idelay_tap_cnt = idelay_tap_cnt_w; // Record first and second edges found during CPT calibration generate always @(posedge clk) if (rst) begin dbg_cpt_first_edge_taps <= #TCQ 'b0; dbg_cpt_second_edge_taps <= #TCQ 'b0; end else if ((SIM_CAL_OPTION == "FAST_CAL") & (cal1_state_r1 == CAL1_CALC_IDEL)) begin for (ce_rnk_i = 0; ce_rnk_i < RANKS; ce_rnk_i = ce_rnk_i + 1) begin: gen_dbg_cpt_rnk for (ce_i = 0; ce_i < DQS_WIDTH; ce_i = ce_i + 1) begin: gen_dbg_cpt_edge if (found_first_edge_r) dbg_cpt_first_edge_taps[((6*ce_i)+(ce_rnk_i*DQS_WIDTH*6))+:6] <= #TCQ first_edge_taps_r; if (found_second_edge_r) dbg_cpt_second_edge_taps[((6*ce_i)+(ce_rnk_i*DQS_WIDTH*6))+:6] <= #TCQ second_edge_taps_r; end end end else if (cal1_state_r == CAL1_CALC_IDEL) begin // Record tap counts of first and second edge edges during // CPT calibration for each DQS group. If neither edge has // been found, then those taps will remain 0 if (found_first_edge_r) dbg_cpt_first_edge_taps[(((cal1_cnt_cpt_timing <<2) + (cal1_cnt_cpt_timing <<1)) +(rnk_cnt_r*DQS_WIDTH*6))+:6] <= #TCQ first_edge_taps_r; if (found_second_edge_r) dbg_cpt_second_edge_taps[(((cal1_cnt_cpt_timing <<2) + (cal1_cnt_cpt_timing <<1)) +(rnk_cnt_r*DQS_WIDTH*6))+:6] <= #TCQ second_edge_taps_r; end endgenerate assign rdlvl_stg1_rnk_done = rdlvl_rank_done_r;// || regl_rank_done_r; assign mpr_rnk_done = mpr_rank_done_r; assign mpr_rdlvl_done = ((DRAM_TYPE == "DDR3") && (OCAL_EN == "ON")) ? //&& (SIM_CAL_OPTION == "NONE") mpr_rdlvl_done_r : 1'b1; //************************************************************************** // DQS count to hard PHY during write calibration using Phaser_OUT Stage2 // coarse delay //************************************************************************** assign pi_stg2_rdlvl_cnt = (cal1_state_r == CAL1_REGL_LOAD) ? regl_dqs_cnt_r : cal1_cnt_cpt_r; assign idelay_ce = cal1_dq_idel_ce; assign idelay_inc = cal1_dq_idel_inc; //*************************************************************************** // Assert calib_in_common in FAST_CAL mode for IDELAY tap increments to all // DQs simultaneously //*************************************************************************** always @(posedge clk) begin if (rst) rdlvl_assrt_common <= #TCQ 1'b0; else if ((SIM_CAL_OPTION == "FAST_CAL") & rdlvl_stg1_start & !rdlvl_stg1_start_r) rdlvl_assrt_common <= #TCQ 1'b1; else if (!idel_pat_data_match_r & idel_pat_data_match) rdlvl_assrt_common <= #TCQ 1'b0; end //*************************************************************************** // Data mux to route appropriate bit to calibration logic - i.e. calibration // is done sequentially, one bit (or DQS group) at a time //*************************************************************************** generate if (nCK_PER_CLK == 4) begin: rd_data_div4_logic_clk assign rd_data_rise0 = rd_data[DQ_WIDTH-1:0]; assign rd_data_fall0 = rd_data[2*DQ_WIDTH-1:DQ_WIDTH]; assign rd_data_rise1 = rd_data[3*DQ_WIDTH-1:2*DQ_WIDTH]; assign rd_data_fall1 = rd_data[4*DQ_WIDTH-1:3*DQ_WIDTH]; assign rd_data_rise2 = rd_data[5*DQ_WIDTH-1:4*DQ_WIDTH]; assign rd_data_fall2 = rd_data[6*DQ_WIDTH-1:5*DQ_WIDTH]; assign rd_data_rise3 = rd_data[7*DQ_WIDTH-1:6*DQ_WIDTH]; assign rd_data_fall3 = rd_data[8*DQ_WIDTH-1:7*DQ_WIDTH]; end else begin: rd_data_div2_logic_clk assign rd_data_rise0 = rd_data[DQ_WIDTH-1:0]; assign rd_data_fall0 = rd_data[2*DQ_WIDTH-1:DQ_WIDTH]; assign rd_data_rise1 = rd_data[3*DQ_WIDTH-1:2*DQ_WIDTH]; assign rd_data_fall1 = rd_data[4*DQ_WIDTH-1:3*DQ_WIDTH]; end endgenerate always @(posedge clk) begin rd_mux_sel_r <= #TCQ cal1_cnt_cpt_r; end // Register outputs for improved timing. // NOTE: Will need to change when per-bit DQ deskew is supported. // Currenly all bits in DQS group are checked in aggregate generate genvar mux_i; for (mux_i = 0; mux_i < DRAM_WIDTH; mux_i = mux_i + 1) begin: gen_mux_rd always @(posedge clk) begin mux_rd_rise0_r[mux_i] <= #TCQ rd_data_rise0[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall0_r[mux_i] <= #TCQ rd_data_fall0[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_rise1_r[mux_i] <= #TCQ rd_data_rise1[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall1_r[mux_i] <= #TCQ rd_data_fall1[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_rise2_r[mux_i] <= #TCQ rd_data_rise2[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall2_r[mux_i] <= #TCQ rd_data_fall2[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_rise3_r[mux_i] <= #TCQ rd_data_rise3[DRAM_WIDTH*rd_mux_sel_r + mux_i]; mux_rd_fall3_r[mux_i] <= #TCQ rd_data_fall3[DRAM_WIDTH*rd_mux_sel_r + mux_i]; end end endgenerate //*************************************************************************** // MPR Read Leveling //*************************************************************************** // storing the previous read data for checking later. Only bit 0 is used // since MPR contents (01010101) are available generally on DQ[0] per // JEDEC spec. always @(posedge clk)begin if ((cal1_state_r == CAL1_MPR_NEW_DQS_WAIT) || ((cal1_state_r == CAL1_MPR_PAT_DETECT) && (idel_pat_detect_valid_r)))begin mpr_rd_rise0_prev_r <= #TCQ mux_rd_rise0_r[0]; mpr_rd_fall0_prev_r <= #TCQ mux_rd_fall0_r[0]; mpr_rd_rise1_prev_r <= #TCQ mux_rd_rise1_r[0]; mpr_rd_fall1_prev_r <= #TCQ mux_rd_fall1_r[0]; mpr_rd_rise2_prev_r <= #TCQ mux_rd_rise2_r[0]; mpr_rd_fall2_prev_r <= #TCQ mux_rd_fall2_r[0]; mpr_rd_rise3_prev_r <= #TCQ mux_rd_rise3_r[0]; mpr_rd_fall3_prev_r <= #TCQ mux_rd_fall3_r[0]; end end generate if (nCK_PER_CLK == 4) begin: mpr_4to1 // changed stable count of 2 IDELAY taps at 78 ps resolution always @(posedge clk) begin if (rst | (cal1_state_r == CAL1_NEW_DQS_PREWAIT) | //(cal1_state_r == CAL1_DETECT_EDGE) | (mpr_rd_rise0_prev_r != mux_rd_rise0_r[0]) | (mpr_rd_fall0_prev_r != mux_rd_fall0_r[0]) | (mpr_rd_rise1_prev_r != mux_rd_rise1_r[0]) | (mpr_rd_fall1_prev_r != mux_rd_fall1_r[0]) | (mpr_rd_rise2_prev_r != mux_rd_rise2_r[0]) | (mpr_rd_fall2_prev_r != mux_rd_fall2_r[0]) | (mpr_rd_rise3_prev_r != mux_rd_rise3_r[0]) | (mpr_rd_fall3_prev_r != mux_rd_fall3_r[0])) stable_idel_cnt <= #TCQ 3'd0; else if ((|idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing]) & ((cal1_state_r == CAL1_MPR_PAT_DETECT) & (idel_pat_detect_valid_r))) begin if ((mpr_rd_rise0_prev_r == mux_rd_rise0_r[0]) & (mpr_rd_fall0_prev_r == mux_rd_fall0_r[0]) & (mpr_rd_rise1_prev_r == mux_rd_rise1_r[0]) & (mpr_rd_fall1_prev_r == mux_rd_fall1_r[0]) & (mpr_rd_rise2_prev_r == mux_rd_rise2_r[0]) & (mpr_rd_fall2_prev_r == mux_rd_fall2_r[0]) & (mpr_rd_rise3_prev_r == mux_rd_rise3_r[0]) & (mpr_rd_fall3_prev_r == mux_rd_fall3_r[0]) & (stable_idel_cnt < 3'd2)) stable_idel_cnt <= #TCQ stable_idel_cnt + 1; end end always @(posedge clk) begin if (rst | (mpr_rd_rise0_prev_r & ~mpr_rd_fall0_prev_r & mpr_rd_rise1_prev_r & ~mpr_rd_fall1_prev_r & mpr_rd_rise2_prev_r & ~mpr_rd_fall2_prev_r & mpr_rd_rise3_prev_r & ~mpr_rd_fall3_prev_r)) inhibit_edge_detect_r <= 1'b1; // Wait for settling time after idelay tap increment before // de-asserting inhibit_edge_detect_r else if ((cal1_state_r == CAL1_MPR_PAT_DETECT) & (idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing] > 5'd1) & (~mpr_rd_rise0_prev_r & mpr_rd_fall0_prev_r & ~mpr_rd_rise1_prev_r & mpr_rd_fall1_prev_r & ~mpr_rd_rise2_prev_r & mpr_rd_fall2_prev_r & ~mpr_rd_rise3_prev_r & mpr_rd_fall3_prev_r)) inhibit_edge_detect_r <= 1'b0; end //checking for transition from 01010101 to 10101010 always @(posedge clk)begin if (rst | (cal1_state_r == CAL1_MPR_NEW_DQS_WAIT) | inhibit_edge_detect_r) idel_mpr_pat_detect_r <= #TCQ 1'b0; // 10101010 is not the correct pattern else if ((mpr_rd_rise0_prev_r & ~mpr_rd_fall0_prev_r & mpr_rd_rise1_prev_r & ~mpr_rd_fall1_prev_r & mpr_rd_rise2_prev_r & ~mpr_rd_fall2_prev_r & mpr_rd_rise3_prev_r & ~mpr_rd_fall3_prev_r) || ((stable_idel_cnt < 3'd2) & (cal1_state_r == CAL1_MPR_PAT_DETECT) && (idel_pat_detect_valid_r))) //|| (idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing] < 5'd2)) idel_mpr_pat_detect_r <= #TCQ 1'b0; // 01010101 to 10101010 is the correct transition else if ((~mpr_rd_rise0_prev_r & mpr_rd_fall0_prev_r & ~mpr_rd_rise1_prev_r & mpr_rd_fall1_prev_r & ~mpr_rd_rise2_prev_r & mpr_rd_fall2_prev_r & ~mpr_rd_rise3_prev_r & mpr_rd_fall3_prev_r) & (stable_idel_cnt == 3'd2) & ((mpr_rd_rise0_prev_r != mux_rd_rise0_r[0]) || (mpr_rd_fall0_prev_r != mux_rd_fall0_r[0]) || (mpr_rd_rise1_prev_r != mux_rd_rise1_r[0]) || (mpr_rd_fall1_prev_r != mux_rd_fall1_r[0]) || (mpr_rd_rise2_prev_r != mux_rd_rise2_r[0]) || (mpr_rd_fall2_prev_r != mux_rd_fall2_r[0]) || (mpr_rd_rise3_prev_r != mux_rd_rise3_r[0]) || (mpr_rd_fall3_prev_r != mux_rd_fall3_r[0]))) idel_mpr_pat_detect_r <= #TCQ 1'b1; end end else if (nCK_PER_CLK == 2) begin: mpr_2to1 // changed stable count of 2 IDELAY taps at 78 ps resolution always @(posedge clk) begin if (rst | (cal1_state_r == CAL1_MPR_NEW_DQS_WAIT) | (mpr_rd_rise0_prev_r != mux_rd_rise0_r[0]) | (mpr_rd_fall0_prev_r != mux_rd_fall0_r[0]) | (mpr_rd_rise1_prev_r != mux_rd_rise1_r[0]) | (mpr_rd_fall1_prev_r != mux_rd_fall1_r[0])) stable_idel_cnt <= #TCQ 3'd0; else if ((idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing] > 5'd0) & ((cal1_state_r == CAL1_MPR_PAT_DETECT) & (idel_pat_detect_valid_r))) begin if ((mpr_rd_rise0_prev_r == mux_rd_rise0_r[0]) & (mpr_rd_fall0_prev_r == mux_rd_fall0_r[0]) & (mpr_rd_rise1_prev_r == mux_rd_rise1_r[0]) & (mpr_rd_fall1_prev_r == mux_rd_fall1_r[0]) & (stable_idel_cnt < 3'd2)) stable_idel_cnt <= #TCQ stable_idel_cnt + 1; end end always @(posedge clk) begin if (rst | (mpr_rd_rise0_prev_r & ~mpr_rd_fall0_prev_r & mpr_rd_rise1_prev_r & ~mpr_rd_fall1_prev_r)) inhibit_edge_detect_r <= 1'b1; else if ((cal1_state_r == CAL1_MPR_PAT_DETECT) & (idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing] > 5'd1) & (~mpr_rd_rise0_prev_r & mpr_rd_fall0_prev_r & ~mpr_rd_rise1_prev_r & mpr_rd_fall1_prev_r)) inhibit_edge_detect_r <= 1'b0; end //checking for transition from 01010101 to 10101010 always @(posedge clk)begin if (rst | (cal1_state_r == CAL1_MPR_NEW_DQS_WAIT) | inhibit_edge_detect_r) idel_mpr_pat_detect_r <= #TCQ 1'b0; // 1010 is not the correct pattern else if ((mpr_rd_rise0_prev_r & ~mpr_rd_fall0_prev_r & mpr_rd_rise1_prev_r & ~mpr_rd_fall1_prev_r) || ((stable_idel_cnt < 3'd2) & (cal1_state_r == CAL1_MPR_PAT_DETECT) & (idel_pat_detect_valid_r))) // ||(idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing] < 5'd2)) idel_mpr_pat_detect_r <= #TCQ 1'b0; // 0101 to 1010 is the correct transition else if ((~mpr_rd_rise0_prev_r & mpr_rd_fall0_prev_r & ~mpr_rd_rise1_prev_r & mpr_rd_fall1_prev_r) & (stable_idel_cnt == 3'd2) & ((mpr_rd_rise0_prev_r != mux_rd_rise0_r[0]) || (mpr_rd_fall0_prev_r != mux_rd_fall0_r[0]) || (mpr_rd_rise1_prev_r != mux_rd_rise1_r[0]) || (mpr_rd_fall1_prev_r != mux_rd_fall1_r[0]))) idel_mpr_pat_detect_r <= #TCQ 1'b1; end end endgenerate // Registered signal indicates when mux_rd_rise/fall_r is valid always @(posedge clk) mux_rd_valid_r <= #TCQ ~phy_if_empty; //*************************************************************************** // Decrement initial Phaser_IN fine delay value before proceeding with // read calibration //*************************************************************************** always @(posedge clk) begin dqs_po_dec_done_r1 <= #TCQ dqs_po_dec_done; dqs_po_dec_done_r2 <= #TCQ dqs_po_dec_done_r1; fine_dly_dec_done_r2 <= #TCQ fine_dly_dec_done_r1; pi_fine_dly_dec_done <= #TCQ fine_dly_dec_done_r2; end always @(posedge clk) begin if (rst || pi_cnt_dec) wait_cnt_r <= #TCQ 'd8; else if (dqs_po_dec_done_r2 && (wait_cnt_r > 'd0)) wait_cnt_r <= #TCQ wait_cnt_r - 1; end always @(posedge clk) begin if (rst) begin pi_rdval_cnt <= #TCQ 'd0; end else if (dqs_po_dec_done_r1 && ~dqs_po_dec_done_r2) begin pi_rdval_cnt <= #TCQ pi_counter_read_val; end else if (pi_rdval_cnt > 'd0) begin if (pi_cnt_dec) pi_rdval_cnt <= #TCQ pi_rdval_cnt - 1; else pi_rdval_cnt <= #TCQ pi_rdval_cnt; end else if (pi_rdval_cnt == 'd0) begin pi_rdval_cnt <= #TCQ pi_rdval_cnt; end end always @(posedge clk) begin if (rst || (pi_rdval_cnt == 'd0)) pi_cnt_dec <= #TCQ 1'b0; else if (dqs_po_dec_done_r2 && (pi_rdval_cnt > 'd0) && (wait_cnt_r == 'd1)) pi_cnt_dec <= #TCQ 1'b1; else pi_cnt_dec <= #TCQ 1'b0; end always @(posedge clk) begin if (rst) begin fine_dly_dec_done_r1 <= #TCQ 1'b0; end else if (((pi_cnt_dec == 'd1) && (pi_rdval_cnt == 'd1)) || (dqs_po_dec_done_r2 && (pi_rdval_cnt == 'd0))) begin fine_dly_dec_done_r1 <= #TCQ 1'b1; end end //*************************************************************************** // Demultiplexor to control Phaser_IN delay values //*************************************************************************** // Read DQS always @(posedge clk) begin if (rst) begin pi_en_stg2_f_timing <= #TCQ 'b0; pi_stg2_f_incdec_timing <= #TCQ 'b0; end else if (pi_cnt_dec) begin pi_en_stg2_f_timing <= #TCQ 'b1; pi_stg2_f_incdec_timing <= #TCQ 'b0; end else if (cal1_dlyce_cpt_r) begin if ((SIM_CAL_OPTION == "NONE") || (SIM_CAL_OPTION == "FAST_WIN_DETECT")) begin // Change only specified DQS pi_en_stg2_f_timing <= #TCQ 1'b1; pi_stg2_f_incdec_timing <= #TCQ cal1_dlyinc_cpt_r; end else if (SIM_CAL_OPTION == "FAST_CAL") begin // if simulating, and "shortcuts" for calibration enabled, apply // results to all DQSs (i.e. assume same delay on all // DQSs). pi_en_stg2_f_timing <= #TCQ 1'b1; pi_stg2_f_incdec_timing <= #TCQ cal1_dlyinc_cpt_r; end end else begin pi_en_stg2_f_timing <= #TCQ 'b0; pi_stg2_f_incdec_timing <= #TCQ 'b0; end end // registered for timing always @(posedge clk) begin pi_en_stg2_f <= #TCQ pi_en_stg2_f_timing; pi_stg2_f_incdec <= #TCQ pi_stg2_f_incdec_timing; end // This counter used to implement settling time between // Phaser_IN rank register loads to different DQSs always @(posedge clk) begin if (rst) done_cnt <= #TCQ 'b0; else if (((cal1_state_r == CAL1_REGL_LOAD) && (cal1_state_r1 == CAL1_NEXT_DQS)) || ((done_cnt == 4'd1) && (cal1_state_r != CAL1_DONE))) done_cnt <= #TCQ 4'b1010; else if (done_cnt > 'b0) done_cnt <= #TCQ done_cnt - 1; end // During rank register loading the rank count must be sent to // Phaser_IN via the phy_ctl_wd?? If so phy_init will have to // issue NOPs during rank register loading with the appropriate // rank count always @(posedge clk) begin if (rst || (regl_rank_done_r == 1'b1)) regl_rank_done_r <= #TCQ 1'b0; else if ((regl_dqs_cnt == DQS_WIDTH-1) && (regl_rank_cnt != RANKS-1) && (done_cnt == 4'd1)) regl_rank_done_r <= #TCQ 1'b1; end // Temp wire for timing. // The following in the always block below causes timing issues // due to DSP block inference // 6*regl_dqs_cnt. // replacing this with two left shifts + 1 left shift to avoid // DSP multiplier. assign regl_dqs_cnt_timing = {2'd0, regl_dqs_cnt}; // Load Phaser_OUT rank register with rdlvl delay value // for each DQS per rank. always @(posedge clk) begin if (rst || (done_cnt == 4'd0)) begin pi_stg2_load_timing <= #TCQ 'b0; pi_stg2_reg_l_timing <= #TCQ 'b0; end else if ((cal1_state_r == CAL1_REGL_LOAD) && (regl_dqs_cnt <= DQS_WIDTH-1) && (done_cnt == 4'd1)) begin pi_stg2_load_timing <= #TCQ 'b1; pi_stg2_reg_l_timing <= #TCQ rdlvl_dqs_tap_cnt_r[rnk_cnt_r][regl_dqs_cnt]; end else begin pi_stg2_load_timing <= #TCQ 'b0; pi_stg2_reg_l_timing <= #TCQ 'b0; end end // registered for timing always @(posedge clk) begin pi_stg2_load <= #TCQ pi_stg2_load_timing; pi_stg2_reg_l <= #TCQ pi_stg2_reg_l_timing; end always @(posedge clk) begin if (rst || (done_cnt == 4'd0) || (mpr_rdlvl_done_r1 && ~mpr_rdlvl_done_r2)) regl_rank_cnt <= #TCQ 2'b00; else if ((cal1_state_r == CAL1_REGL_LOAD) && (regl_dqs_cnt == DQS_WIDTH-1) && (done_cnt == 4'd1)) begin if (regl_rank_cnt == RANKS-1) regl_rank_cnt <= #TCQ regl_rank_cnt; else regl_rank_cnt <= #TCQ regl_rank_cnt + 1; end end always @(posedge clk) begin if (rst || (done_cnt == 4'd0) || (mpr_rdlvl_done_r1 && ~mpr_rdlvl_done_r2)) regl_dqs_cnt <= #TCQ {DQS_CNT_WIDTH+1{1'b0}}; else if ((cal1_state_r == CAL1_REGL_LOAD) && (regl_dqs_cnt == DQS_WIDTH-1) && (done_cnt == 4'd1)) begin if (regl_rank_cnt == RANKS-1) regl_dqs_cnt <= #TCQ regl_dqs_cnt; else regl_dqs_cnt <= #TCQ 'b0; end else if ((cal1_state_r == CAL1_REGL_LOAD) && (regl_dqs_cnt != DQS_WIDTH-1) && (done_cnt == 4'd1)) regl_dqs_cnt <= #TCQ regl_dqs_cnt + 1; else regl_dqs_cnt <= #TCQ regl_dqs_cnt; end always @(posedge clk) regl_dqs_cnt_r <= #TCQ regl_dqs_cnt; //***************************************************************** // DQ Stage 1 CALIBRATION INCREMENT/DECREMENT LOGIC: // The actual IDELAY elements for each of the DQ bits is set via the // DLYVAL parallel load port. However, the stage 1 calibration // algorithm (well most of it) only needs to increment or decrement the DQ // IDELAY value by 1 at any one time. //***************************************************************** // Chip-select generation for each of the individual counters tracking // IDELAY tap values for each DQ generate for (z = 0; z < DQS_WIDTH; z = z + 1) begin: gen_dlyce_dq always @(posedge clk) if (rst) dlyce_dq_r[DRAM_WIDTH*z+:DRAM_WIDTH] <= #TCQ 'b0; else if (SIM_CAL_OPTION == "SKIP_CAL") // If skipping calibration altogether (only for simulation), no // need to set DQ IODELAY values - they are hardcoded dlyce_dq_r[DRAM_WIDTH*z+:DRAM_WIDTH] <= #TCQ 'b0; else if (SIM_CAL_OPTION == "FAST_CAL") begin // If fast calibration option (simulation only) selected, DQ // IODELAYs across all bytes are updated simultaneously // (although per-bit deskew within DQS[0] is still supported) for (h = 0; h < DRAM_WIDTH; h = h + 1) begin dlyce_dq_r[DRAM_WIDTH*z + h] <= #TCQ cal1_dlyce_dq_r; end end else if ((SIM_CAL_OPTION == "NONE") || (SIM_CAL_OPTION == "FAST_WIN_DETECT")) begin if (cal1_cnt_cpt_r == z) begin for (g = 0; g < DRAM_WIDTH; g = g + 1) begin dlyce_dq_r[DRAM_WIDTH*z + g] <= #TCQ cal1_dlyce_dq_r; end end else dlyce_dq_r[DRAM_WIDTH*z+:DRAM_WIDTH] <= #TCQ 'b0; end end endgenerate // Also delay increment/decrement control to match delay on DLYCE always @(posedge clk) if (rst) dlyinc_dq_r <= #TCQ 1'b0; else dlyinc_dq_r <= #TCQ cal1_dlyinc_dq_r; // Each DQ has a counter associated with it to record current read-leveling // delay value always @(posedge clk) // Reset or skipping calibration all together if (rst | (SIM_CAL_OPTION == "SKIP_CAL")) begin for (aa = 0; aa < RANKS; aa = aa + 1) begin: rst_dlyval_dq_reg_r for (bb = 0; bb < DQ_WIDTH; bb = bb + 1) dlyval_dq_reg_r[aa][bb] <= #TCQ 'b0; end end else if (SIM_CAL_OPTION == "FAST_CAL") begin for (n = 0; n < RANKS; n = n + 1) begin: gen_dlyval_dq_reg_rnk for (r = 0; r < DQ_WIDTH; r = r + 1) begin: gen_dlyval_dq_reg if (dlyce_dq_r[r]) begin if (dlyinc_dq_r) dlyval_dq_reg_r[n][r] <= #TCQ dlyval_dq_reg_r[n][r] + 5'h01; else dlyval_dq_reg_r[n][r] <= #TCQ dlyval_dq_reg_r[n][r] - 5'h01; end end end end else begin if (dlyce_dq_r[cal1_cnt_cpt_r]) begin if (dlyinc_dq_r) dlyval_dq_reg_r[rnk_cnt_r][cal1_cnt_cpt_r] <= #TCQ dlyval_dq_reg_r[rnk_cnt_r][cal1_cnt_cpt_r] + 5'h01; else dlyval_dq_reg_r[rnk_cnt_r][cal1_cnt_cpt_r] <= #TCQ dlyval_dq_reg_r[rnk_cnt_r][cal1_cnt_cpt_r] - 5'h01; end end // Register for timing (help with logic placement) always @(posedge clk) begin for (cc = 0; cc < RANKS; cc = cc + 1) begin: dlyval_dq_assgn for (dd = 0; dd < DQ_WIDTH; dd = dd + 1) dlyval_dq[((5*dd)+(cc*DQ_WIDTH*5))+:5] <= #TCQ dlyval_dq_reg_r[cc][dd]; end end //*************************************************************************** // Generate signal used to delay calibration state machine - used when: // (1) IDELAY value changed // (2) RD_MUX_SEL value changed // Use when a delay is necessary to give the change time to propagate // through the data pipeline (through IDELAY and ISERDES, and fabric // pipeline stages) //*************************************************************************** // List all the stage 1 calibration wait states here. always @(posedge clk) if ((cal1_state_r == CAL1_NEW_DQS_WAIT) || (cal1_state_r == CAL1_MPR_NEW_DQS_WAIT) || (cal1_state_r == CAL1_NEW_DQS_PREWAIT) || (cal1_state_r == CAL1_VALID_WAIT) || (cal1_state_r == CAL1_PB_STORE_FIRST_WAIT) || (cal1_state_r == CAL1_PB_INC_CPT_WAIT) || (cal1_state_r == CAL1_PB_DEC_CPT_LEFT_WAIT) || (cal1_state_r == CAL1_PB_INC_DQ_WAIT) || (cal1_state_r == CAL1_PB_DEC_CPT_WAIT) || (cal1_state_r == CAL1_IDEL_INC_CPT_WAIT) || (cal1_state_r == CAL1_IDEL_DEC_CPT_WAIT) || (cal1_state_r == CAL1_STORE_FIRST_WAIT) || (cal1_state_r == CAL1_DQ_IDEL_TAP_INC_WAIT) || (cal1_state_r == CAL1_DQ_IDEL_TAP_DEC_WAIT)) cal1_wait_cnt_en_r <= #TCQ 1'b1; else cal1_wait_cnt_en_r <= #TCQ 1'b0; always @(posedge clk) if (!cal1_wait_cnt_en_r) begin cal1_wait_cnt_r <= #TCQ 5'b00000; cal1_wait_r <= #TCQ 1'b1; end else begin if (cal1_wait_cnt_r != PIPE_WAIT_CNT - 1) begin cal1_wait_cnt_r <= #TCQ cal1_wait_cnt_r + 1; cal1_wait_r <= #TCQ 1'b1; end else begin // Need to reset to 0 to handle the case when there are two // different WAIT states back-to-back cal1_wait_cnt_r <= #TCQ 5'b00000; cal1_wait_r <= #TCQ 1'b0; end end //*************************************************************************** // generate request to PHY_INIT logic to issue precharged. Required when // calibration can take a long time (during which there are only constant // reads present on this bus). In this case need to issue perioidic // precharges to avoid tRAS violation. This signal must meet the following // requirements: (1) only transition from 0->1 when prech is first needed, // (2) stay at 1 and only transition 1->0 when RDLVL_PRECH_DONE asserted //*************************************************************************** always @(posedge clk) if (rst) rdlvl_prech_req <= #TCQ 1'b0; else rdlvl_prech_req <= #TCQ cal1_prech_req_r; //*************************************************************************** // Serial-to-parallel register to store last RDDATA_SHIFT_LEN cycles of // data from ISERDES. The value of this register is also stored, so that // previous and current values of the ISERDES data can be compared while // varying the IODELAY taps to see if an "edge" of the data valid window // has been encountered since the last IODELAY tap adjustment //*************************************************************************** //*************************************************************************** // Shift register to store last RDDATA_SHIFT_LEN cycles of data from ISERDES // NOTE: Written using discrete flops, but SRL can be used if the matching // logic does the comparison sequentially, rather than parallel //*************************************************************************** generate genvar rd_i; if (nCK_PER_CLK == 4) begin: gen_sr_div4 if (RD_SHIFT_LEN == 1) begin: gen_sr_len_eq1 for (rd_i = 0; rd_i < DRAM_WIDTH; rd_i = rd_i + 1) begin: gen_sr always @(posedge clk) begin if (mux_rd_valid_r) begin sr_rise0_r[rd_i] <= #TCQ mux_rd_rise0_r[rd_i]; sr_fall0_r[rd_i] <= #TCQ mux_rd_fall0_r[rd_i]; sr_rise1_r[rd_i] <= #TCQ mux_rd_rise1_r[rd_i]; sr_fall1_r[rd_i] <= #TCQ mux_rd_fall1_r[rd_i]; sr_rise2_r[rd_i] <= #TCQ mux_rd_rise2_r[rd_i]; sr_fall2_r[rd_i] <= #TCQ mux_rd_fall2_r[rd_i]; sr_rise3_r[rd_i] <= #TCQ mux_rd_rise3_r[rd_i]; sr_fall3_r[rd_i] <= #TCQ mux_rd_fall3_r[rd_i]; end end end end else if (RD_SHIFT_LEN > 1) begin: gen_sr_len_gt1 for (rd_i = 0; rd_i < DRAM_WIDTH; rd_i = rd_i + 1) begin: gen_sr always @(posedge clk) begin if (mux_rd_valid_r) begin sr_rise0_r[rd_i] <= #TCQ {sr_rise0_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_rise0_r[rd_i]}; sr_fall0_r[rd_i] <= #TCQ {sr_fall0_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_fall0_r[rd_i]}; sr_rise1_r[rd_i] <= #TCQ {sr_rise1_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_rise1_r[rd_i]}; sr_fall1_r[rd_i] <= #TCQ {sr_fall1_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_fall1_r[rd_i]}; sr_rise2_r[rd_i] <= #TCQ {sr_rise2_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_rise2_r[rd_i]}; sr_fall2_r[rd_i] <= #TCQ {sr_fall2_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_fall2_r[rd_i]}; sr_rise3_r[rd_i] <= #TCQ {sr_rise3_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_rise3_r[rd_i]}; sr_fall3_r[rd_i] <= #TCQ {sr_fall3_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_fall3_r[rd_i]}; end end end end end else if (nCK_PER_CLK == 2) begin: gen_sr_div2 if (RD_SHIFT_LEN == 1) begin: gen_sr_len_eq1 for (rd_i = 0; rd_i < DRAM_WIDTH; rd_i = rd_i + 1) begin: gen_sr always @(posedge clk) begin if (mux_rd_valid_r) begin sr_rise0_r[rd_i] <= #TCQ {mux_rd_rise0_r[rd_i]}; sr_fall0_r[rd_i] <= #TCQ {mux_rd_fall0_r[rd_i]}; sr_rise1_r[rd_i] <= #TCQ {mux_rd_rise1_r[rd_i]}; sr_fall1_r[rd_i] <= #TCQ {mux_rd_fall1_r[rd_i]}; end end end end else if (RD_SHIFT_LEN > 1) begin: gen_sr_len_gt1 for (rd_i = 0; rd_i < DRAM_WIDTH; rd_i = rd_i + 1) begin: gen_sr always @(posedge clk) begin if (mux_rd_valid_r) begin sr_rise0_r[rd_i] <= #TCQ {sr_rise0_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_rise0_r[rd_i]}; sr_fall0_r[rd_i] <= #TCQ {sr_fall0_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_fall0_r[rd_i]}; sr_rise1_r[rd_i] <= #TCQ {sr_rise1_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_rise1_r[rd_i]}; sr_fall1_r[rd_i] <= #TCQ {sr_fall1_r[rd_i][RD_SHIFT_LEN-2:0], mux_rd_fall1_r[rd_i]}; end end end end end endgenerate //*************************************************************************** // Conversion to pattern calibration //*************************************************************************** // Pattern for DQ IDELAY calibration //***************************************************************** // Expected data pattern when DQ shifted to the right such that // DQS before the left edge of the DVW: // Based on pattern of ({rise,fall}) = // 0x1, 0xB, 0x4, 0x4, 0xB, 0x9 // Each nibble will look like: // bit3: 0, 1, 0, 0, 1, 1 // bit2: 0, 0, 1, 1, 0, 0 // bit1: 0, 1, 0, 0, 1, 0 // bit0: 1, 1, 0, 0, 1, 1 // Or if the write is early it could look like: // 0x4, 0x4, 0xB, 0x9, 0x6, 0xE // bit3: 0, 0, 1, 1, 0, 1 // bit2: 1, 1, 0, 0, 1, 1 // bit1: 0, 0, 1, 0, 1, 1 // bit0: 0, 0, 1, 1, 0, 0 // Change the hard-coded pattern below accordingly as RD_SHIFT_LEN // and the actual training pattern contents change //***************************************************************** generate if (nCK_PER_CLK == 4) begin: gen_pat_div4 // Pattern for DQ IDELAY increment // Target pattern for "early write" assign {idel_pat0_rise0[3], idel_pat0_rise0[2], idel_pat0_rise0[1], idel_pat0_rise0[0]} = 4'h1; assign {idel_pat0_fall0[3], idel_pat0_fall0[2], idel_pat0_fall0[1], idel_pat0_fall0[0]} = 4'h7; assign {idel_pat0_rise1[3], idel_pat0_rise1[2], idel_pat0_rise1[1], idel_pat0_rise1[0]} = 4'hE; assign {idel_pat0_fall1[3], idel_pat0_fall1[2], idel_pat0_fall1[1], idel_pat0_fall1[0]} = 4'hC; assign {idel_pat0_rise2[3], idel_pat0_rise2[2], idel_pat0_rise2[1], idel_pat0_rise2[0]} = 4'h9; assign {idel_pat0_fall2[3], idel_pat0_fall2[2], idel_pat0_fall2[1], idel_pat0_fall2[0]} = 4'h2; assign {idel_pat0_rise3[3], idel_pat0_rise3[2], idel_pat0_rise3[1], idel_pat0_rise3[0]} = 4'h4; assign {idel_pat0_fall3[3], idel_pat0_fall3[2], idel_pat0_fall3[1], idel_pat0_fall3[0]} = 4'hB; // Target pattern for "on-time write" assign {idel_pat1_rise0[3], idel_pat1_rise0[2], idel_pat1_rise0[1], idel_pat1_rise0[0]} = 4'h4; assign {idel_pat1_fall0[3], idel_pat1_fall0[2], idel_pat1_fall0[1], idel_pat1_fall0[0]} = 4'h9; assign {idel_pat1_rise1[3], idel_pat1_rise1[2], idel_pat1_rise1[1], idel_pat1_rise1[0]} = 4'h3; assign {idel_pat1_fall1[3], idel_pat1_fall1[2], idel_pat1_fall1[1], idel_pat1_fall1[0]} = 4'h7; assign {idel_pat1_rise2[3], idel_pat1_rise2[2], idel_pat1_rise2[1], idel_pat1_rise2[0]} = 4'hE; assign {idel_pat1_fall2[3], idel_pat1_fall2[2], idel_pat1_fall2[1], idel_pat1_fall2[0]} = 4'hC; assign {idel_pat1_rise3[3], idel_pat1_rise3[2], idel_pat1_rise3[1], idel_pat1_rise3[0]} = 4'h9; assign {idel_pat1_fall3[3], idel_pat1_fall3[2], idel_pat1_fall3[1], idel_pat1_fall3[0]} = 4'h2; // Correct data valid window for "early write" assign {pat0_rise0[3], pat0_rise0[2], pat0_rise0[1], pat0_rise0[0]} = 4'h7; assign {pat0_fall0[3], pat0_fall0[2], pat0_fall0[1], pat0_fall0[0]} = 4'hE; assign {pat0_rise1[3], pat0_rise1[2], pat0_rise1[1], pat0_rise1[0]} = 4'hC; assign {pat0_fall1[3], pat0_fall1[2], pat0_fall1[1], pat0_fall1[0]} = 4'h9; assign {pat0_rise2[3], pat0_rise2[2], pat0_rise2[1], pat0_rise2[0]} = 4'h2; assign {pat0_fall2[3], pat0_fall2[2], pat0_fall2[1], pat0_fall2[0]} = 4'h4; assign {pat0_rise3[3], pat0_rise3[2], pat0_rise3[1], pat0_rise3[0]} = 4'hB; assign {pat0_fall3[3], pat0_fall3[2], pat0_fall3[1], pat0_fall3[0]} = 4'h1; // Correct data valid window for "on-time write" assign {pat1_rise0[3], pat1_rise0[2], pat1_rise0[1], pat1_rise0[0]} = 4'h9; assign {pat1_fall0[3], pat1_fall0[2], pat1_fall0[1], pat1_fall0[0]} = 4'h3; assign {pat1_rise1[3], pat1_rise1[2], pat1_rise1[1], pat1_rise1[0]} = 4'h7; assign {pat1_fall1[3], pat1_fall1[2], pat1_fall1[1], pat1_fall1[0]} = 4'hE; assign {pat1_rise2[3], pat1_rise2[2], pat1_rise2[1], pat1_rise2[0]} = 4'hC; assign {pat1_fall2[3], pat1_fall2[2], pat1_fall2[1], pat1_fall2[0]} = 4'h9; assign {pat1_rise3[3], pat1_rise3[2], pat1_rise3[1], pat1_rise3[0]} = 4'h2; assign {pat1_fall3[3], pat1_fall3[2], pat1_fall3[1], pat1_fall3[0]} = 4'h4; end else if (nCK_PER_CLK == 2) begin: gen_pat_div2 // Pattern for DQ IDELAY increment // Target pattern for "early write" assign idel_pat0_rise0[3] = 2'b01; assign idel_pat0_fall0[3] = 2'b00; assign idel_pat0_rise1[3] = 2'b10; assign idel_pat0_fall1[3] = 2'b11; assign idel_pat0_rise0[2] = 2'b00; assign idel_pat0_fall0[2] = 2'b10; assign idel_pat0_rise1[2] = 2'b11; assign idel_pat0_fall1[2] = 2'b10; assign idel_pat0_rise0[1] = 2'b00; assign idel_pat0_fall0[1] = 2'b11; assign idel_pat0_rise1[1] = 2'b10; assign idel_pat0_fall1[1] = 2'b01; assign idel_pat0_rise0[0] = 2'b11; assign idel_pat0_fall0[0] = 2'b10; assign idel_pat0_rise1[0] = 2'b00; assign idel_pat0_fall1[0] = 2'b01; // Target pattern for "on-time write" assign idel_pat1_rise0[3] = 2'b01; assign idel_pat1_fall0[3] = 2'b11; assign idel_pat1_rise1[3] = 2'b01; assign idel_pat1_fall1[3] = 2'b00; assign idel_pat1_rise0[2] = 2'b11; assign idel_pat1_fall0[2] = 2'b01; assign idel_pat1_rise1[2] = 2'b00; assign idel_pat1_fall1[2] = 2'b10; assign idel_pat1_rise0[1] = 2'b01; assign idel_pat1_fall0[1] = 2'b00; assign idel_pat1_rise1[1] = 2'b10; assign idel_pat1_fall1[1] = 2'b11; assign idel_pat1_rise0[0] = 2'b00; assign idel_pat1_fall0[0] = 2'b10; assign idel_pat1_rise1[0] = 2'b11; assign idel_pat1_fall1[0] = 2'b10; // Correct data valid window for "early write" assign pat0_rise0[3] = 2'b00; assign pat0_fall0[3] = 2'b10; assign pat0_rise1[3] = 2'b11; assign pat0_fall1[3] = 2'b10; assign pat0_rise0[2] = 2'b10; assign pat0_fall0[2] = 2'b11; assign pat0_rise1[2] = 2'b10; assign pat0_fall1[2] = 2'b00; assign pat0_rise0[1] = 2'b11; assign pat0_fall0[1] = 2'b10; assign pat0_rise1[1] = 2'b01; assign pat0_fall1[1] = 2'b00; assign pat0_rise0[0] = 2'b10; assign pat0_fall0[0] = 2'b00; assign pat0_rise1[0] = 2'b01; assign pat0_fall1[0] = 2'b11; // Correct data valid window for "on-time write" assign pat1_rise0[3] = 2'b11; assign pat1_fall0[3] = 2'b01; assign pat1_rise1[3] = 2'b00; assign pat1_fall1[3] = 2'b10; assign pat1_rise0[2] = 2'b01; assign pat1_fall0[2] = 2'b00; assign pat1_rise1[2] = 2'b10; assign pat1_fall1[2] = 2'b11; assign pat1_rise0[1] = 2'b00; assign pat1_fall0[1] = 2'b10; assign pat1_rise1[1] = 2'b11; assign pat1_fall1[1] = 2'b10; assign pat1_rise0[0] = 2'b10; assign pat1_fall0[0] = 2'b11; assign pat1_rise1[0] = 2'b10; assign pat1_fall1[0] = 2'b00; end endgenerate // Each bit of each byte is compared to expected pattern. // This was done to prevent (and "drastically decrease") the chance that // invalid data clocked in when the DQ bus is tri-state (along with a // combination of the correct data) will resemble the expected data // pattern. A better fix for this is to change the training pattern and/or // make the pattern longer. generate genvar pt_i; if (nCK_PER_CLK == 4) begin: gen_pat_match_div4 for (pt_i = 0; pt_i < DRAM_WIDTH; pt_i = pt_i + 1) begin: gen_pat_match // DQ IDELAY pattern detection always @(posedge clk) begin if (sr_rise0_r[pt_i] == idel_pat0_rise0[pt_i%4]) idel_pat0_match_rise0_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == idel_pat0_fall0[pt_i%4]) idel_pat0_match_fall0_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == idel_pat0_rise1[pt_i%4]) idel_pat0_match_rise1_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == idel_pat0_fall1[pt_i%4]) idel_pat0_match_fall1_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_fall1_r[pt_i] <= #TCQ 1'b0; if (sr_rise2_r[pt_i] == idel_pat0_rise2[pt_i%4]) idel_pat0_match_rise2_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_rise2_r[pt_i] <= #TCQ 1'b0; if (sr_fall2_r[pt_i] == idel_pat0_fall2[pt_i%4]) idel_pat0_match_fall2_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_fall2_r[pt_i] <= #TCQ 1'b0; if (sr_rise3_r[pt_i] == idel_pat0_rise3[pt_i%4]) idel_pat0_match_rise3_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_rise3_r[pt_i] <= #TCQ 1'b0; if (sr_fall3_r[pt_i] == idel_pat0_fall3[pt_i%4]) idel_pat0_match_fall3_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_fall3_r[pt_i] <= #TCQ 1'b0; end always @(posedge clk) begin if (sr_rise0_r[pt_i] == idel_pat1_rise0[pt_i%4]) idel_pat1_match_rise0_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == idel_pat1_fall0[pt_i%4]) idel_pat1_match_fall0_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == idel_pat1_rise1[pt_i%4]) idel_pat1_match_rise1_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == idel_pat1_fall1[pt_i%4]) idel_pat1_match_fall1_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_fall1_r[pt_i] <= #TCQ 1'b0; if (sr_rise2_r[pt_i] == idel_pat1_rise2[pt_i%4]) idel_pat1_match_rise2_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_rise2_r[pt_i] <= #TCQ 1'b0; if (sr_fall2_r[pt_i] == idel_pat1_fall2[pt_i%4]) idel_pat1_match_fall2_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_fall2_r[pt_i] <= #TCQ 1'b0; if (sr_rise3_r[pt_i] == idel_pat1_rise3[pt_i%4]) idel_pat1_match_rise3_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_rise3_r[pt_i] <= #TCQ 1'b0; if (sr_fall3_r[pt_i] == idel_pat1_fall3[pt_i%4]) idel_pat1_match_fall3_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_fall3_r[pt_i] <= #TCQ 1'b0; end // DQS DVW pattern detection always @(posedge clk) begin if (sr_rise0_r[pt_i] == pat0_rise0[pt_i%4]) pat0_match_rise0_r[pt_i] <= #TCQ 1'b1; else pat0_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == pat0_fall0[pt_i%4]) pat0_match_fall0_r[pt_i] <= #TCQ 1'b1; else pat0_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == pat0_rise1[pt_i%4]) pat0_match_rise1_r[pt_i] <= #TCQ 1'b1; else pat0_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == pat0_fall1[pt_i%4]) pat0_match_fall1_r[pt_i] <= #TCQ 1'b1; else pat0_match_fall1_r[pt_i] <= #TCQ 1'b0; if (sr_rise2_r[pt_i] == pat0_rise2[pt_i%4]) pat0_match_rise2_r[pt_i] <= #TCQ 1'b1; else pat0_match_rise2_r[pt_i] <= #TCQ 1'b0; if (sr_fall2_r[pt_i] == pat0_fall2[pt_i%4]) pat0_match_fall2_r[pt_i] <= #TCQ 1'b1; else pat0_match_fall2_r[pt_i] <= #TCQ 1'b0; if (sr_rise3_r[pt_i] == pat0_rise3[pt_i%4]) pat0_match_rise3_r[pt_i] <= #TCQ 1'b1; else pat0_match_rise3_r[pt_i] <= #TCQ 1'b0; if (sr_fall3_r[pt_i] == pat0_fall3[pt_i%4]) pat0_match_fall3_r[pt_i] <= #TCQ 1'b1; else pat0_match_fall3_r[pt_i] <= #TCQ 1'b0; end always @(posedge clk) begin if (sr_rise0_r[pt_i] == pat1_rise0[pt_i%4]) pat1_match_rise0_r[pt_i] <= #TCQ 1'b1; else pat1_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == pat1_fall0[pt_i%4]) pat1_match_fall0_r[pt_i] <= #TCQ 1'b1; else pat1_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == pat1_rise1[pt_i%4]) pat1_match_rise1_r[pt_i] <= #TCQ 1'b1; else pat1_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == pat1_fall1[pt_i%4]) pat1_match_fall1_r[pt_i] <= #TCQ 1'b1; else pat1_match_fall1_r[pt_i] <= #TCQ 1'b0; if (sr_rise2_r[pt_i] == pat1_rise2[pt_i%4]) pat1_match_rise2_r[pt_i] <= #TCQ 1'b1; else pat1_match_rise2_r[pt_i] <= #TCQ 1'b0; if (sr_fall2_r[pt_i] == pat1_fall2[pt_i%4]) pat1_match_fall2_r[pt_i] <= #TCQ 1'b1; else pat1_match_fall2_r[pt_i] <= #TCQ 1'b0; if (sr_rise3_r[pt_i] == pat1_rise3[pt_i%4]) pat1_match_rise3_r[pt_i] <= #TCQ 1'b1; else pat1_match_rise3_r[pt_i] <= #TCQ 1'b0; if (sr_fall3_r[pt_i] == pat1_fall3[pt_i%4]) pat1_match_fall3_r[pt_i] <= #TCQ 1'b1; else pat1_match_fall3_r[pt_i] <= #TCQ 1'b0; end end // Combine pattern match "subterms" for DQ-IDELAY stage always @(posedge clk) begin idel_pat0_match_rise0_and_r <= #TCQ &idel_pat0_match_rise0_r; idel_pat0_match_fall0_and_r <= #TCQ &idel_pat0_match_fall0_r; idel_pat0_match_rise1_and_r <= #TCQ &idel_pat0_match_rise1_r; idel_pat0_match_fall1_and_r <= #TCQ &idel_pat0_match_fall1_r; idel_pat0_match_rise2_and_r <= #TCQ &idel_pat0_match_rise2_r; idel_pat0_match_fall2_and_r <= #TCQ &idel_pat0_match_fall2_r; idel_pat0_match_rise3_and_r <= #TCQ &idel_pat0_match_rise3_r; idel_pat0_match_fall3_and_r <= #TCQ &idel_pat0_match_fall3_r; idel_pat0_data_match_r <= #TCQ (idel_pat0_match_rise0_and_r && idel_pat0_match_fall0_and_r && idel_pat0_match_rise1_and_r && idel_pat0_match_fall1_and_r && idel_pat0_match_rise2_and_r && idel_pat0_match_fall2_and_r && idel_pat0_match_rise3_and_r && idel_pat0_match_fall3_and_r); end always @(posedge clk) begin idel_pat1_match_rise0_and_r <= #TCQ &idel_pat1_match_rise0_r; idel_pat1_match_fall0_and_r <= #TCQ &idel_pat1_match_fall0_r; idel_pat1_match_rise1_and_r <= #TCQ &idel_pat1_match_rise1_r; idel_pat1_match_fall1_and_r <= #TCQ &idel_pat1_match_fall1_r; idel_pat1_match_rise2_and_r <= #TCQ &idel_pat1_match_rise2_r; idel_pat1_match_fall2_and_r <= #TCQ &idel_pat1_match_fall2_r; idel_pat1_match_rise3_and_r <= #TCQ &idel_pat1_match_rise3_r; idel_pat1_match_fall3_and_r <= #TCQ &idel_pat1_match_fall3_r; idel_pat1_data_match_r <= #TCQ (idel_pat1_match_rise0_and_r && idel_pat1_match_fall0_and_r && idel_pat1_match_rise1_and_r && idel_pat1_match_fall1_and_r && idel_pat1_match_rise2_and_r && idel_pat1_match_fall2_and_r && idel_pat1_match_rise3_and_r && idel_pat1_match_fall3_and_r); end always @(idel_pat0_data_match_r or idel_pat1_data_match_r) idel_pat_data_match <= #TCQ idel_pat0_data_match_r | idel_pat1_data_match_r; always @(posedge clk) idel_pat_data_match_r <= #TCQ idel_pat_data_match; // Combine pattern match "subterms" for DQS-PHASER_IN stage always @(posedge clk) begin pat0_match_rise0_and_r <= #TCQ &pat0_match_rise0_r; pat0_match_fall0_and_r <= #TCQ &pat0_match_fall0_r; pat0_match_rise1_and_r <= #TCQ &pat0_match_rise1_r; pat0_match_fall1_and_r <= #TCQ &pat0_match_fall1_r; pat0_match_rise2_and_r <= #TCQ &pat0_match_rise2_r; pat0_match_fall2_and_r <= #TCQ &pat0_match_fall2_r; pat0_match_rise3_and_r <= #TCQ &pat0_match_rise3_r; pat0_match_fall3_and_r <= #TCQ &pat0_match_fall3_r; pat0_data_match_r <= #TCQ (pat0_match_rise0_and_r && pat0_match_fall0_and_r && pat0_match_rise1_and_r && pat0_match_fall1_and_r && pat0_match_rise2_and_r && pat0_match_fall2_and_r && pat0_match_rise3_and_r && pat0_match_fall3_and_r); end always @(posedge clk) begin pat1_match_rise0_and_r <= #TCQ &pat1_match_rise0_r; pat1_match_fall0_and_r <= #TCQ &pat1_match_fall0_r; pat1_match_rise1_and_r <= #TCQ &pat1_match_rise1_r; pat1_match_fall1_and_r <= #TCQ &pat1_match_fall1_r; pat1_match_rise2_and_r <= #TCQ &pat1_match_rise2_r; pat1_match_fall2_and_r <= #TCQ &pat1_match_fall2_r; pat1_match_rise3_and_r <= #TCQ &pat1_match_rise3_r; pat1_match_fall3_and_r <= #TCQ &pat1_match_fall3_r; pat1_data_match_r <= #TCQ (pat1_match_rise0_and_r && pat1_match_fall0_and_r && pat1_match_rise1_and_r && pat1_match_fall1_and_r && pat1_match_rise2_and_r && pat1_match_fall2_and_r && pat1_match_rise3_and_r && pat1_match_fall3_and_r); end assign pat_data_match_r = pat0_data_match_r | pat1_data_match_r; end else if (nCK_PER_CLK == 2) begin: gen_pat_match_div2 for (pt_i = 0; pt_i < DRAM_WIDTH; pt_i = pt_i + 1) begin: gen_pat_match // DQ IDELAY pattern detection always @(posedge clk) begin if (sr_rise0_r[pt_i] == idel_pat0_rise0[pt_i%4]) idel_pat0_match_rise0_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == idel_pat0_fall0[pt_i%4]) idel_pat0_match_fall0_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == idel_pat0_rise1[pt_i%4]) idel_pat0_match_rise1_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == idel_pat0_fall1[pt_i%4]) idel_pat0_match_fall1_r[pt_i] <= #TCQ 1'b1; else idel_pat0_match_fall1_r[pt_i] <= #TCQ 1'b0; end always @(posedge clk) begin if (sr_rise0_r[pt_i] == idel_pat1_rise0[pt_i%4]) idel_pat1_match_rise0_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == idel_pat1_fall0[pt_i%4]) idel_pat1_match_fall0_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == idel_pat1_rise1[pt_i%4]) idel_pat1_match_rise1_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == idel_pat1_fall1[pt_i%4]) idel_pat1_match_fall1_r[pt_i] <= #TCQ 1'b1; else idel_pat1_match_fall1_r[pt_i] <= #TCQ 1'b0; end // DQS DVW pattern detection always @(posedge clk) begin if (sr_rise0_r[pt_i] == pat0_rise0[pt_i%4]) pat0_match_rise0_r[pt_i] <= #TCQ 1'b1; else pat0_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == pat0_fall0[pt_i%4]) pat0_match_fall0_r[pt_i] <= #TCQ 1'b1; else pat0_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == pat0_rise1[pt_i%4]) pat0_match_rise1_r[pt_i] <= #TCQ 1'b1; else pat0_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == pat0_fall1[pt_i%4]) pat0_match_fall1_r[pt_i] <= #TCQ 1'b1; else pat0_match_fall1_r[pt_i] <= #TCQ 1'b0; end always @(posedge clk) begin if (sr_rise0_r[pt_i] == pat1_rise0[pt_i%4]) pat1_match_rise0_r[pt_i] <= #TCQ 1'b1; else pat1_match_rise0_r[pt_i] <= #TCQ 1'b0; if (sr_fall0_r[pt_i] == pat1_fall0[pt_i%4]) pat1_match_fall0_r[pt_i] <= #TCQ 1'b1; else pat1_match_fall0_r[pt_i] <= #TCQ 1'b0; if (sr_rise1_r[pt_i] == pat1_rise1[pt_i%4]) pat1_match_rise1_r[pt_i] <= #TCQ 1'b1; else pat1_match_rise1_r[pt_i] <= #TCQ 1'b0; if (sr_fall1_r[pt_i] == pat1_fall1[pt_i%4]) pat1_match_fall1_r[pt_i] <= #TCQ 1'b1; else pat1_match_fall1_r[pt_i] <= #TCQ 1'b0; end end // Combine pattern match "subterms" for DQ-IDELAY stage always @(posedge clk) begin idel_pat0_match_rise0_and_r <= #TCQ &idel_pat0_match_rise0_r; idel_pat0_match_fall0_and_r <= #TCQ &idel_pat0_match_fall0_r; idel_pat0_match_rise1_and_r <= #TCQ &idel_pat0_match_rise1_r; idel_pat0_match_fall1_and_r <= #TCQ &idel_pat0_match_fall1_r; idel_pat0_data_match_r <= #TCQ (idel_pat0_match_rise0_and_r && idel_pat0_match_fall0_and_r && idel_pat0_match_rise1_and_r && idel_pat0_match_fall1_and_r); end always @(posedge clk) begin idel_pat1_match_rise0_and_r <= #TCQ &idel_pat1_match_rise0_r; idel_pat1_match_fall0_and_r <= #TCQ &idel_pat1_match_fall0_r; idel_pat1_match_rise1_and_r <= #TCQ &idel_pat1_match_rise1_r; idel_pat1_match_fall1_and_r <= #TCQ &idel_pat1_match_fall1_r; idel_pat1_data_match_r <= #TCQ (idel_pat1_match_rise0_and_r && idel_pat1_match_fall0_and_r && idel_pat1_match_rise1_and_r && idel_pat1_match_fall1_and_r); end always @(posedge clk) begin if (sr_valid_r2) idel_pat_data_match <= #TCQ idel_pat0_data_match_r | idel_pat1_data_match_r; end //assign idel_pat_data_match = idel_pat0_data_match_r | // idel_pat1_data_match_r; always @(posedge clk) idel_pat_data_match_r <= #TCQ idel_pat_data_match; // Combine pattern match "subterms" for DQS-PHASER_IN stage always @(posedge clk) begin pat0_match_rise0_and_r <= #TCQ &pat0_match_rise0_r; pat0_match_fall0_and_r <= #TCQ &pat0_match_fall0_r; pat0_match_rise1_and_r <= #TCQ &pat0_match_rise1_r; pat0_match_fall1_and_r <= #TCQ &pat0_match_fall1_r; pat0_data_match_r <= #TCQ (pat0_match_rise0_and_r && pat0_match_fall0_and_r && pat0_match_rise1_and_r && pat0_match_fall1_and_r); end always @(posedge clk) begin pat1_match_rise0_and_r <= #TCQ &pat1_match_rise0_r; pat1_match_fall0_and_r <= #TCQ &pat1_match_fall0_r; pat1_match_rise1_and_r <= #TCQ &pat1_match_rise1_r; pat1_match_fall1_and_r <= #TCQ &pat1_match_fall1_r; pat1_data_match_r <= #TCQ (pat1_match_rise0_and_r && pat1_match_fall0_and_r && pat1_match_rise1_and_r && pat1_match_fall1_and_r); end assign pat_data_match_r = pat0_data_match_r | pat1_data_match_r; end endgenerate always @(posedge clk) begin rdlvl_stg1_start_r <= #TCQ rdlvl_stg1_start; mpr_rdlvl_done_r1 <= #TCQ mpr_rdlvl_done_r; mpr_rdlvl_done_r2 <= #TCQ mpr_rdlvl_done_r1; mpr_rdlvl_start_r <= #TCQ mpr_rdlvl_start; end //*************************************************************************** // First stage calibration: Capture clock //*************************************************************************** //***************************************************************** // Keep track of how many samples have been written to shift registers // Every time RD_SHIFT_LEN samples have been written, then we have a // full read training pattern loaded into the sr_* registers. Then assert // sr_valid_r to indicate that: (1) comparison between the sr_* and // old_sr_* and prev_sr_* registers can take place, (2) transfer of // the contents of sr_* to old_sr_* and prev_sr_* registers can also // take place //***************************************************************** always @(posedge clk) if (rst || (mpr_rdlvl_done_r && ~rdlvl_stg1_start)) begin cnt_shift_r <= #TCQ 'b1; sr_valid_r <= #TCQ 1'b0; mpr_valid_r <= #TCQ 1'b0; end else begin if (mux_rd_valid_r && mpr_rdlvl_start && ~mpr_rdlvl_done_r) begin if (cnt_shift_r == 'b0) mpr_valid_r <= #TCQ 1'b1; else begin mpr_valid_r <= #TCQ 1'b0; cnt_shift_r <= #TCQ cnt_shift_r + 1; end end else mpr_valid_r <= #TCQ 1'b0; if (mux_rd_valid_r && rdlvl_stg1_start) begin if (cnt_shift_r == RD_SHIFT_LEN-1) begin sr_valid_r <= #TCQ 1'b1; cnt_shift_r <= #TCQ 'b0; end else begin sr_valid_r <= #TCQ 1'b0; cnt_shift_r <= #TCQ cnt_shift_r + 1; end end else // When the current mux_rd_* contents are not valid, then // retain the current value of cnt_shift_r, and make sure // that sr_valid_r = 0 to prevent any downstream loads or // comparisons sr_valid_r <= #TCQ 1'b0; end //***************************************************************** // Logic to determine when either edge of the data eye encountered // Pre- and post-IDELAY update data pattern is compared, if they // differ, than an edge has been encountered. Currently no attempt // made to determine if the data pattern itself is "correct", only // whether it changes after incrementing the IDELAY (possible // future enhancement) //***************************************************************** // One-way control for ensuring that state machine request to store // current read data into OLD SR shift register only occurs on a // valid clock cycle. The FSM provides a one-cycle request pulse. // It is the responsibility of the FSM to wait the worst-case time // before relying on any downstream results of this load. always @(posedge clk) if (rst) store_sr_r <= #TCQ 1'b0; else begin if (store_sr_req_r) store_sr_r <= #TCQ 1'b1; else if ((sr_valid_r || mpr_valid_r) && store_sr_r) store_sr_r <= #TCQ 1'b0; end // Transfer current data to old data, prior to incrementing delay // Also store data from current sampling window - so that we can detect // if the current delay tap yields data that is "jittery" generate if (nCK_PER_CLK == 4) begin: gen_old_sr_div4 for (z = 0; z < DRAM_WIDTH; z = z + 1) begin: gen_old_sr always @(posedge clk) begin if (sr_valid_r || mpr_valid_r) begin // Load last sample (i.e. from current sampling interval) prev_sr_rise0_r[z] <= #TCQ sr_rise0_r[z]; prev_sr_fall0_r[z] <= #TCQ sr_fall0_r[z]; prev_sr_rise1_r[z] <= #TCQ sr_rise1_r[z]; prev_sr_fall1_r[z] <= #TCQ sr_fall1_r[z]; prev_sr_rise2_r[z] <= #TCQ sr_rise2_r[z]; prev_sr_fall2_r[z] <= #TCQ sr_fall2_r[z]; prev_sr_rise3_r[z] <= #TCQ sr_rise3_r[z]; prev_sr_fall3_r[z] <= #TCQ sr_fall3_r[z]; end if ((sr_valid_r || mpr_valid_r) && store_sr_r) begin old_sr_rise0_r[z] <= #TCQ sr_rise0_r[z]; old_sr_fall0_r[z] <= #TCQ sr_fall0_r[z]; old_sr_rise1_r[z] <= #TCQ sr_rise1_r[z]; old_sr_fall1_r[z] <= #TCQ sr_fall1_r[z]; old_sr_rise2_r[z] <= #TCQ sr_rise2_r[z]; old_sr_fall2_r[z] <= #TCQ sr_fall2_r[z]; old_sr_rise3_r[z] <= #TCQ sr_rise3_r[z]; old_sr_fall3_r[z] <= #TCQ sr_fall3_r[z]; end end end end else if (nCK_PER_CLK == 2) begin: gen_old_sr_div2 for (z = 0; z < DRAM_WIDTH; z = z + 1) begin: gen_old_sr always @(posedge clk) begin if (sr_valid_r || mpr_valid_r) begin prev_sr_rise0_r[z] <= #TCQ sr_rise0_r[z]; prev_sr_fall0_r[z] <= #TCQ sr_fall0_r[z]; prev_sr_rise1_r[z] <= #TCQ sr_rise1_r[z]; prev_sr_fall1_r[z] <= #TCQ sr_fall1_r[z]; end if ((sr_valid_r || mpr_valid_r) && store_sr_r) begin old_sr_rise0_r[z] <= #TCQ sr_rise0_r[z]; old_sr_fall0_r[z] <= #TCQ sr_fall0_r[z]; old_sr_rise1_r[z] <= #TCQ sr_rise1_r[z]; old_sr_fall1_r[z] <= #TCQ sr_fall1_r[z]; end end end end endgenerate //******************************************************* // Match determination occurs over 3 cycles - pipelined for better timing //******************************************************* // Match valid with # of cycles of pipelining in match determination always @(posedge clk) begin sr_valid_r1 <= #TCQ sr_valid_r; sr_valid_r2 <= #TCQ sr_valid_r1; mpr_valid_r1 <= #TCQ mpr_valid_r; mpr_valid_r2 <= #TCQ mpr_valid_r1; end generate if (nCK_PER_CLK == 4) begin: gen_sr_match_div4 for (z = 0; z < DRAM_WIDTH; z = z + 1) begin: gen_sr_match always @(posedge clk) begin // CYCLE1: Compare all bits in DQS grp, generate separate term for // each bit over four bit times. For example, if there are 8-bits // per DQS group, 32 terms are generated on cycle 1 // NOTE: Structure HDL such that X on data bus will result in a // mismatch. This is required for memory models that can drive the // bus with X's to model uncertainty regions (e.g. Denali) if ((pat_data_match_r || mpr_valid_r1) && (sr_rise0_r[z] == old_sr_rise0_r[z])) old_sr_match_rise0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_rise0_r[z] <= #TCQ old_sr_match_rise0_r[z]; else old_sr_match_rise0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall0_r[z] == old_sr_fall0_r[z])) old_sr_match_fall0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_fall0_r[z] <= #TCQ old_sr_match_fall0_r[z]; else old_sr_match_fall0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise1_r[z] == old_sr_rise1_r[z])) old_sr_match_rise1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_rise1_r[z] <= #TCQ old_sr_match_rise1_r[z]; else old_sr_match_rise1_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall1_r[z] == old_sr_fall1_r[z])) old_sr_match_fall1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_fall1_r[z] <= #TCQ old_sr_match_fall1_r[z]; else old_sr_match_fall1_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise2_r[z] == old_sr_rise2_r[z])) old_sr_match_rise2_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_rise2_r[z] <= #TCQ old_sr_match_rise2_r[z]; else old_sr_match_rise2_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall2_r[z] == old_sr_fall2_r[z])) old_sr_match_fall2_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_fall2_r[z] <= #TCQ old_sr_match_fall2_r[z]; else old_sr_match_fall2_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise3_r[z] == old_sr_rise3_r[z])) old_sr_match_rise3_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_rise3_r[z] <= #TCQ old_sr_match_rise3_r[z]; else old_sr_match_rise3_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall3_r[z] == old_sr_fall3_r[z])) old_sr_match_fall3_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_fall3_r[z] <= #TCQ old_sr_match_fall3_r[z]; else old_sr_match_fall3_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise0_r[z] == prev_sr_rise0_r[z])) prev_sr_match_rise0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_rise0_r[z] <= #TCQ prev_sr_match_rise0_r[z]; else prev_sr_match_rise0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall0_r[z] == prev_sr_fall0_r[z])) prev_sr_match_fall0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_fall0_r[z] <= #TCQ prev_sr_match_fall0_r[z]; else prev_sr_match_fall0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise1_r[z] == prev_sr_rise1_r[z])) prev_sr_match_rise1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_rise1_r[z] <= #TCQ prev_sr_match_rise1_r[z]; else prev_sr_match_rise1_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall1_r[z] == prev_sr_fall1_r[z])) prev_sr_match_fall1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_fall1_r[z] <= #TCQ prev_sr_match_fall1_r[z]; else prev_sr_match_fall1_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise2_r[z] == prev_sr_rise2_r[z])) prev_sr_match_rise2_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_rise2_r[z] <= #TCQ prev_sr_match_rise2_r[z]; else prev_sr_match_rise2_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall2_r[z] == prev_sr_fall2_r[z])) prev_sr_match_fall2_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_fall2_r[z] <= #TCQ prev_sr_match_fall2_r[z]; else prev_sr_match_fall2_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise3_r[z] == prev_sr_rise3_r[z])) prev_sr_match_rise3_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_rise3_r[z] <= #TCQ prev_sr_match_rise3_r[z]; else prev_sr_match_rise3_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall3_r[z] == prev_sr_fall3_r[z])) prev_sr_match_fall3_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_fall3_r[z] <= #TCQ prev_sr_match_fall3_r[z]; else prev_sr_match_fall3_r[z] <= #TCQ 1'b0; // CYCLE2: Combine all the comparisons for every 8 words (rise0, // fall0,rise1, fall1) in the calibration sequence. Now we're down // to DRAM_WIDTH terms old_sr_match_cyc2_r[z] <= #TCQ old_sr_match_rise0_r[z] & old_sr_match_fall0_r[z] & old_sr_match_rise1_r[z] & old_sr_match_fall1_r[z] & old_sr_match_rise2_r[z] & old_sr_match_fall2_r[z] & old_sr_match_rise3_r[z] & old_sr_match_fall3_r[z]; prev_sr_match_cyc2_r[z] <= #TCQ prev_sr_match_rise0_r[z] & prev_sr_match_fall0_r[z] & prev_sr_match_rise1_r[z] & prev_sr_match_fall1_r[z] & prev_sr_match_rise2_r[z] & prev_sr_match_fall2_r[z] & prev_sr_match_rise3_r[z] & prev_sr_match_fall3_r[z]; // CYCLE3: Invert value (i.e. assert when DIFFERENCE in value seen), // and qualify with pipelined valid signal) - probably don't need // a cycle just do do this.... if (sr_valid_r2 || mpr_valid_r2) begin old_sr_diff_r[z] <= #TCQ ~old_sr_match_cyc2_r[z]; prev_sr_diff_r[z] <= #TCQ ~prev_sr_match_cyc2_r[z]; end else begin old_sr_diff_r[z] <= #TCQ 'b0; prev_sr_diff_r[z] <= #TCQ 'b0; end end end end if (nCK_PER_CLK == 2) begin: gen_sr_match_div2 for (z = 0; z < DRAM_WIDTH; z = z + 1) begin: gen_sr_match always @(posedge clk) begin if ((pat_data_match_r || mpr_valid_r1) && (sr_rise0_r[z] == old_sr_rise0_r[z])) old_sr_match_rise0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_rise0_r[z] <= #TCQ old_sr_match_rise0_r[z]; else old_sr_match_rise0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall0_r[z] == old_sr_fall0_r[z])) old_sr_match_fall0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_fall0_r[z] <= #TCQ old_sr_match_fall0_r[z]; else old_sr_match_fall0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise1_r[z] == old_sr_rise1_r[z])) old_sr_match_rise1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_rise1_r[z] <= #TCQ old_sr_match_rise1_r[z]; else old_sr_match_rise1_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall1_r[z] == old_sr_fall1_r[z])) old_sr_match_fall1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) old_sr_match_fall1_r[z] <= #TCQ old_sr_match_fall1_r[z]; else old_sr_match_fall1_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise0_r[z] == prev_sr_rise0_r[z])) prev_sr_match_rise0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_rise0_r[z] <= #TCQ prev_sr_match_rise0_r[z]; else prev_sr_match_rise0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall0_r[z] == prev_sr_fall0_r[z])) prev_sr_match_fall0_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_fall0_r[z] <= #TCQ prev_sr_match_fall0_r[z]; else prev_sr_match_fall0_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_rise1_r[z] == prev_sr_rise1_r[z])) prev_sr_match_rise1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_rise1_r[z] <= #TCQ prev_sr_match_rise1_r[z]; else prev_sr_match_rise1_r[z] <= #TCQ 1'b0; if ((pat_data_match_r || mpr_valid_r1) && (sr_fall1_r[z] == prev_sr_fall1_r[z])) prev_sr_match_fall1_r[z] <= #TCQ 1'b1; else if (~mpr_valid_r1 && mpr_rdlvl_start && ~mpr_rdlvl_done_r) prev_sr_match_fall1_r[z] <= #TCQ prev_sr_match_fall1_r[z]; else prev_sr_match_fall1_r[z] <= #TCQ 1'b0; old_sr_match_cyc2_r[z] <= #TCQ old_sr_match_rise0_r[z] & old_sr_match_fall0_r[z] & old_sr_match_rise1_r[z] & old_sr_match_fall1_r[z]; prev_sr_match_cyc2_r[z] <= #TCQ prev_sr_match_rise0_r[z] & prev_sr_match_fall0_r[z] & prev_sr_match_rise1_r[z] & prev_sr_match_fall1_r[z]; // CYCLE3: Invert value (i.e. assert when DIFFERENCE in value seen), // and qualify with pipelined valid signal) - probably don't need // a cycle just do do this.... if (sr_valid_r2 || mpr_valid_r2) begin old_sr_diff_r[z] <= #TCQ ~old_sr_match_cyc2_r[z]; prev_sr_diff_r[z] <= #TCQ ~prev_sr_match_cyc2_r[z]; end else begin old_sr_diff_r[z] <= #TCQ 'b0; prev_sr_diff_r[z] <= #TCQ 'b0; end end end end endgenerate //*************************************************************************** // First stage calibration: DQS Capture //*************************************************************************** //******************************************************* // Counters for tracking # of samples compared // For each comparision point (i.e. to determine if an edge has // occurred after each IODELAY increment when read leveling), // multiple samples are compared in order to average out the effects // of jitter. If any one of these samples is different than the "old" // sample corresponding to the previous IODELAY value, then an edge // is declared to be detected. //******************************************************* // Two cascaded counters are used to keep track of # of samples compared, // in order to make it easier to meeting timing on these paths. Once // optimal sampling interval is determined, it may be possible to remove // the second counter always @(posedge clk) samp_edge_cnt0_en_r <= #TCQ (cal1_state_r == CAL1_PAT_DETECT) || (cal1_state_r == CAL1_DETECT_EDGE) || (cal1_state_r == CAL1_PB_DETECT_EDGE) || (cal1_state_r == CAL1_PB_DETECT_EDGE_DQ); // First counter counts # of samples compared always @(posedge clk) if (rst) samp_edge_cnt0_r <= #TCQ 'b0; else begin if (!samp_edge_cnt0_en_r) // Reset sample counter when not in any of the "sampling" states samp_edge_cnt0_r <= #TCQ 'b0; else if (sr_valid_r2 || mpr_valid_r2) // Otherwise, count # of samples compared samp_edge_cnt0_r <= #TCQ samp_edge_cnt0_r + 1; end // Counter #2 enable generation always @(posedge clk) if (rst) samp_edge_cnt1_en_r <= #TCQ 1'b0; else begin // Assert pulse when correct number of samples compared if ((samp_edge_cnt0_r == DETECT_EDGE_SAMPLE_CNT0) && (sr_valid_r2 || mpr_valid_r2)) samp_edge_cnt1_en_r <= #TCQ 1'b1; else samp_edge_cnt1_en_r <= #TCQ 1'b0; end // Counter #2 always @(posedge clk) if (rst) samp_edge_cnt1_r <= #TCQ 'b0; else if (!samp_edge_cnt0_en_r) samp_edge_cnt1_r <= #TCQ 'b0; else if (samp_edge_cnt1_en_r) samp_edge_cnt1_r <= #TCQ samp_edge_cnt1_r + 1; always @(posedge clk) if (rst) samp_cnt_done_r <= #TCQ 1'b0; else begin if (!samp_edge_cnt0_en_r) samp_cnt_done_r <= #TCQ 'b0; else if ((SIM_CAL_OPTION == "FAST_CAL") || (SIM_CAL_OPTION == "FAST_WIN_DETECT")) begin if (samp_edge_cnt0_r == SR_VALID_DELAY-1) // For simulation only, stay in edge detection mode a minimum // amount of time - just enough for two data compares to finish samp_cnt_done_r <= #TCQ 1'b1; end else begin if (samp_edge_cnt1_r == DETECT_EDGE_SAMPLE_CNT1) samp_cnt_done_r <= #TCQ 1'b1; end end //***************************************************************** // Logic to keep track of (on per-bit basis): // 1. When a region of stability preceded by a known edge occurs // 2. If for the current tap, the read data jitters // 3. If an edge occured between the current and previous tap // 4. When the current edge detection/sampling interval can end // Essentially, these are a series of status bits - the stage 1 // calibration FSM monitors these to determine when an edge is // found. Additional information is provided to help the FSM // determine if a left or right edge has been found. //**************************************************************** assign pb_detect_edge_setup = (cal1_state_r == CAL1_STORE_FIRST_WAIT) || (cal1_state_r == CAL1_PB_STORE_FIRST_WAIT) || (cal1_state_r == CAL1_PB_DEC_CPT_LEFT_WAIT); assign pb_detect_edge = (cal1_state_r == CAL1_PAT_DETECT) || (cal1_state_r == CAL1_DETECT_EDGE) || (cal1_state_r == CAL1_PB_DETECT_EDGE) || (cal1_state_r == CAL1_PB_DETECT_EDGE_DQ); generate for (z = 0; z < DRAM_WIDTH; z = z + 1) begin: gen_track_left_edge always @(posedge clk) begin if (pb_detect_edge_setup) begin // Reset eye size, stable eye marker, and jitter marker before // starting new edge detection iteration pb_cnt_eye_size_r[z] <= #TCQ 5'd0; pb_detect_edge_done_r[z] <= #TCQ 1'b0; pb_found_stable_eye_r[z] <= #TCQ 1'b0; pb_last_tap_jitter_r[z] <= #TCQ 1'b0; pb_found_edge_last_r[z] <= #TCQ 1'b0; pb_found_edge_r[z] <= #TCQ 1'b0; pb_found_first_edge_r[z] <= #TCQ 1'b0; end else if (pb_detect_edge) begin // Save information on which DQ bits are already out of the // data valid window - those DQ bits will later not have their // IDELAY tap value incremented pb_found_edge_last_r[z] <= #TCQ pb_found_edge_r[z]; if (!pb_detect_edge_done_r[z]) begin if (samp_cnt_done_r) begin // If we've reached end of sampling interval, no jitter on // current tap has been found (although an edge could have // been found between the current and previous taps), and // the sampling interval is complete. Increment the stable // eye counter if no edge found, and always clear the jitter // flag in preparation for the next tap. pb_last_tap_jitter_r[z] <= #TCQ 1'b0; pb_detect_edge_done_r[z] <= #TCQ 1'b1; if (!pb_found_edge_r[z] && !pb_last_tap_jitter_r[z]) begin // If the data was completely stable during this tap and // no edge was found between this and the previous tap // then increment the stable eye counter "as appropriate" if (pb_cnt_eye_size_r[z] != MIN_EYE_SIZE-1) pb_cnt_eye_size_r[z] <= #TCQ pb_cnt_eye_size_r[z] + 1; else //if (pb_found_first_edge_r[z]) // We've reached minimum stable eye width pb_found_stable_eye_r[z] <= #TCQ 1'b1; end else begin // Otherwise, an edge was found, either because of a // difference between this and the previous tap's read // data, and/or because the previous tap's data jittered // (but not the current tap's data), then just set the // edge found flag, and enable the stable eye counter pb_cnt_eye_size_r[z] <= #TCQ 5'd0; pb_found_stable_eye_r[z] <= #TCQ 1'b0; pb_found_edge_r[z] <= #TCQ 1'b1; pb_detect_edge_done_r[z] <= #TCQ 1'b1; end end else if (prev_sr_diff_r[z]) begin // If we find that the current tap read data jitters, then // set edge and jitter found flags, "enable" the eye size // counter, and stop sampling interval for this bit pb_cnt_eye_size_r[z] <= #TCQ 5'd0; pb_found_stable_eye_r[z] <= #TCQ 1'b0; pb_last_tap_jitter_r[z] <= #TCQ 1'b1; pb_found_edge_r[z] <= #TCQ 1'b1; pb_found_first_edge_r[z] <= #TCQ 1'b1; pb_detect_edge_done_r[z] <= #TCQ 1'b1; end else if (old_sr_diff_r[z] || pb_last_tap_jitter_r[z]) begin // If either an edge was found (i.e. difference between // current tap and previous tap read data), or the previous // tap exhibited jitter (which means by definition that the // current tap cannot match the previous tap because the // previous tap gave unstable data), then set the edge found // flag, and "enable" eye size counter. But do not stop // sampling interval - we still need to check if the current // tap exhibits jitter pb_cnt_eye_size_r[z] <= #TCQ 5'd0; pb_found_stable_eye_r[z] <= #TCQ 1'b0; pb_found_edge_r[z] <= #TCQ 1'b1; pb_found_first_edge_r[z] <= #TCQ 1'b1; end end end else begin // Before every edge detection interval, reset "intra-tap" flags pb_found_edge_r[z] <= #TCQ 1'b0; pb_detect_edge_done_r[z] <= #TCQ 1'b0; end end end endgenerate // Combine the above per-bit status flags into combined terms when // performing deskew on the aggregate data window always @(posedge clk) begin detect_edge_done_r <= #TCQ &pb_detect_edge_done_r; found_edge_r <= #TCQ |pb_found_edge_r; found_edge_all_r <= #TCQ &pb_found_edge_r; found_stable_eye_r <= #TCQ &pb_found_stable_eye_r; end // last IODELAY "stable eye" indicator is updated only after // detect_edge_done_r is asserted - so that when we do find the "right edge" // of the data valid window, found_edge_r = 1, AND found_stable_eye_r = 1 // when detect_edge_done_r = 1 (otherwise, if found_stable_eye_r updates // immediately, then it never possible to have found_stable_eye_r = 1 // when we detect an edge - and we'll never know whether we've found // a "right edge") always @(posedge clk) if (pb_detect_edge_setup) found_stable_eye_last_r <= #TCQ 1'b0; else if (detect_edge_done_r) found_stable_eye_last_r <= #TCQ found_stable_eye_r; //***************************************************************** // Keep track of DQ IDELAYE2 taps used //***************************************************************** // Added additional register stage to improve timing always @(posedge clk) if (rst) idelay_tap_cnt_slice_r <= 5'h0; else idelay_tap_cnt_slice_r <= idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing]; always @(posedge clk) if (rst || (SIM_CAL_OPTION == "SKIP_CAL")) begin //|| new_cnt_cpt_r for (s = 0; s < RANKS; s = s + 1) begin for (t = 0; t < DQS_WIDTH; t = t + 1) begin idelay_tap_cnt_r[s][t] <= #TCQ idelaye2_init_val; end end end else if (SIM_CAL_OPTION == "FAST_CAL") begin for (u = 0; u < RANKS; u = u + 1) begin for (w = 0; w < DQS_WIDTH; w = w + 1) begin if (cal1_dq_idel_ce) begin if (cal1_dq_idel_inc) idelay_tap_cnt_r[u][w] <= #TCQ idelay_tap_cnt_r[u][w] + 1; else idelay_tap_cnt_r[u][w] <= #TCQ idelay_tap_cnt_r[u][w] - 1; end end end end else if ((rnk_cnt_r == RANKS-1) && (RANKS == 2) && rdlvl_rank_done_r && (cal1_state_r == CAL1_IDLE)) begin for (f = 0; f < DQS_WIDTH; f = f + 1) begin idelay_tap_cnt_r[rnk_cnt_r][f] <= #TCQ idelay_tap_cnt_r[(rnk_cnt_r-1)][f]; end end else if (cal1_dq_idel_ce) begin if (cal1_dq_idel_inc) idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing] <= #TCQ idelay_tap_cnt_slice_r + 5'h1; else idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing] <= #TCQ idelay_tap_cnt_slice_r - 5'h1; end else if (idelay_ld) idelay_tap_cnt_r[0][wrcal_cnt] <= #TCQ 5'b00000; always @(posedge clk) if (rst || new_cnt_cpt_r) idelay_tap_limit_r <= #TCQ 1'b0; else if (idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_r] == 'd31) idelay_tap_limit_r <= #TCQ 1'b1; //***************************************************************** // keep track of edge tap counts found, and current capture clock // tap count //***************************************************************** always @(posedge clk) if (rst || new_cnt_cpt_r || (mpr_rdlvl_done_r1 && ~mpr_rdlvl_done_r2)) tap_cnt_cpt_r <= #TCQ 'b0; else if (cal1_dlyce_cpt_r) begin if (cal1_dlyinc_cpt_r) tap_cnt_cpt_r <= #TCQ tap_cnt_cpt_r + 1; else if (tap_cnt_cpt_r != 'd0) tap_cnt_cpt_r <= #TCQ tap_cnt_cpt_r - 1; end always @(posedge clk) if (rst || new_cnt_cpt_r || (cal1_state_r1 == CAL1_DQ_IDEL_TAP_INC) || (mpr_rdlvl_done_r1 && ~mpr_rdlvl_done_r2)) tap_limit_cpt_r <= #TCQ 1'b0; else if (tap_cnt_cpt_r == 6'd63) tap_limit_cpt_r <= #TCQ 1'b1; always @(posedge clk) cal1_cnt_cpt_timing_r <= #TCQ cal1_cnt_cpt_r; assign cal1_cnt_cpt_timing = {2'b00, cal1_cnt_cpt_r}; // Storing DQS tap values at the end of each DQS read leveling always @(posedge clk) begin if (rst) begin for (a = 0; a < RANKS; a = a + 1) begin: rst_rdlvl_dqs_tap_count_loop for (b = 0; b < DQS_WIDTH; b = b + 1) rdlvl_dqs_tap_cnt_r[a][b] <= #TCQ 'b0; end end else if ((SIM_CAL_OPTION == "FAST_CAL") & (cal1_state_r1 == CAL1_NEXT_DQS)) begin for (p = 0; p < RANKS; p = p +1) begin: rdlvl_dqs_tap_rank_cnt for(q = 0; q < DQS_WIDTH; q = q +1) begin: rdlvl_dqs_tap_cnt rdlvl_dqs_tap_cnt_r[p][q] <= #TCQ tap_cnt_cpt_r; end end end else if (SIM_CAL_OPTION == "SKIP_CAL") begin for (j = 0; j < RANKS; j = j +1) begin: rdlvl_dqs_tap_rnk_cnt for(i = 0; i < DQS_WIDTH; i = i +1) begin: rdlvl_dqs_cnt rdlvl_dqs_tap_cnt_r[j][i] <= #TCQ 6'd31; end end end else if (cal1_state_r1 == CAL1_NEXT_DQS) begin rdlvl_dqs_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing_r] <= #TCQ tap_cnt_cpt_r; end end // Counter to track maximum DQ IODELAY tap usage during the per-bit // deskew portion of stage 1 calibration always @(posedge clk) if (rst) begin idel_tap_cnt_dq_pb_r <= #TCQ 'b0; idel_tap_limit_dq_pb_r <= #TCQ 1'b0; end else if (new_cnt_cpt_r) begin idel_tap_cnt_dq_pb_r <= #TCQ 'b0; idel_tap_limit_dq_pb_r <= #TCQ 1'b0; end else if (|cal1_dlyce_dq_r) begin if (cal1_dlyinc_dq_r) idel_tap_cnt_dq_pb_r <= #TCQ idel_tap_cnt_dq_pb_r + 1; else idel_tap_cnt_dq_pb_r <= #TCQ idel_tap_cnt_dq_pb_r - 1; if (idel_tap_cnt_dq_pb_r == 31) idel_tap_limit_dq_pb_r <= #TCQ 1'b1; else idel_tap_limit_dq_pb_r <= #TCQ 1'b0; end //***************************************************************** always @(posedge clk) cal1_state_r1 <= #TCQ cal1_state_r; always @(posedge clk) if (rst) begin cal1_cnt_cpt_r <= #TCQ 'b0; cal1_dlyce_cpt_r <= #TCQ 1'b0; cal1_dlyinc_cpt_r <= #TCQ 1'b0; cal1_dq_idel_ce <= #TCQ 1'b0; cal1_dq_idel_inc <= #TCQ 1'b0; cal1_prech_req_r <= #TCQ 1'b0; cal1_state_r <= #TCQ CAL1_IDLE; cnt_idel_dec_cpt_r <= #TCQ 6'bxxxxxx; found_first_edge_r <= #TCQ 1'b0; found_second_edge_r <= #TCQ 1'b0; right_edge_taps_r <= #TCQ 6'bxxxxxx; first_edge_taps_r <= #TCQ 6'bxxxxxx; new_cnt_cpt_r <= #TCQ 1'b0; rdlvl_stg1_done <= #TCQ 1'b0; rdlvl_stg1_err <= #TCQ 1'b0; second_edge_taps_r <= #TCQ 6'bxxxxxx; store_sr_req_pulsed_r <= #TCQ 1'b0; store_sr_req_r <= #TCQ 1'b0; rnk_cnt_r <= #TCQ 2'b00; rdlvl_rank_done_r <= #TCQ 1'b0; idel_dec_cnt <= #TCQ 'd0; rdlvl_last_byte_done <= #TCQ 1'b0; idel_pat_detect_valid_r <= #TCQ 1'b0; mpr_rank_done_r <= #TCQ 1'b0; mpr_last_byte_done <= #TCQ 1'b0; if (OCAL_EN == "ON") mpr_rdlvl_done_r <= #TCQ 1'b0; else mpr_rdlvl_done_r <= #TCQ 1'b1; mpr_dec_cpt_r <= #TCQ 1'b0; end else begin // default (inactive) states for all "pulse" outputs cal1_prech_req_r <= #TCQ 1'b0; cal1_dlyce_cpt_r <= #TCQ 1'b0; cal1_dlyinc_cpt_r <= #TCQ 1'b0; cal1_dq_idel_ce <= #TCQ 1'b0; cal1_dq_idel_inc <= #TCQ 1'b0; new_cnt_cpt_r <= #TCQ 1'b0; store_sr_req_pulsed_r <= #TCQ 1'b0; store_sr_req_r <= #TCQ 1'b0; case (cal1_state_r) CAL1_IDLE: begin rdlvl_rank_done_r <= #TCQ 1'b0; rdlvl_last_byte_done <= #TCQ 1'b0; mpr_rank_done_r <= #TCQ 1'b0; mpr_last_byte_done <= #TCQ 1'b0; if (mpr_rdlvl_start && ~mpr_rdlvl_start_r) begin cal1_state_r <= #TCQ CAL1_MPR_NEW_DQS_WAIT; end else if (rdlvl_stg1_start && ~rdlvl_stg1_start_r) begin if (SIM_CAL_OPTION == "SKIP_CAL") cal1_state_r <= #TCQ CAL1_REGL_LOAD; else if (SIM_CAL_OPTION == "FAST_CAL") cal1_state_r <= #TCQ CAL1_NEXT_DQS; else begin new_cnt_cpt_r <= #TCQ 1'b1; cal1_state_r <= #TCQ CAL1_NEW_DQS_WAIT; end end end CAL1_MPR_NEW_DQS_WAIT: begin cal1_prech_req_r <= #TCQ 1'b0; if (!cal1_wait_r && mpr_valid_r) cal1_state_r <= #TCQ CAL1_MPR_PAT_DETECT; end // Wait for the new DQS group to change // also gives time for the read data IN_FIFO to // output the updated data for the new DQS group CAL1_NEW_DQS_WAIT: begin rdlvl_rank_done_r <= #TCQ 1'b0; rdlvl_last_byte_done <= #TCQ 1'b0; mpr_rank_done_r <= #TCQ 1'b0; mpr_last_byte_done <= #TCQ 1'b0; cal1_prech_req_r <= #TCQ 1'b0; if (|pi_counter_read_val) begin //VK_REVIEW mpr_dec_cpt_r <= #TCQ 1'b1; cal1_state_r <= #TCQ CAL1_IDEL_DEC_CPT; cnt_idel_dec_cpt_r <= #TCQ pi_counter_read_val; end else if (!cal1_wait_r) begin //if (!cal1_wait_r) begin // Store "previous tap" read data. Technically there is no // "previous" read data, since we are starting a new DQS // group, so we'll never find an edge at tap 0 unless the // data is fluctuating/jittering store_sr_req_r <= #TCQ 1'b1; // If per-bit deskew is disabled, then skip the first // portion of stage 1 calibration if (PER_BIT_DESKEW == "OFF") cal1_state_r <= #TCQ CAL1_STORE_FIRST_WAIT; else if (PER_BIT_DESKEW == "ON") cal1_state_r <= #TCQ CAL1_PB_STORE_FIRST_WAIT; end end //***************************************************************** // Per-bit deskew states //***************************************************************** // Wait state following storage of initial read data CAL1_PB_STORE_FIRST_WAIT: if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_PB_DETECT_EDGE; // Look for an edge on all DQ bits in current DQS group CAL1_PB_DETECT_EDGE: if (detect_edge_done_r) begin if (found_stable_eye_r) begin // If we've found the left edge for all bits (or more precisely, // we've found the left edge, and then part of the stable // window thereafter), then proceed to positioning the CPT clock // right before the left margin cnt_idel_dec_cpt_r <= #TCQ MIN_EYE_SIZE + 1; cal1_state_r <= #TCQ CAL1_PB_DEC_CPT_LEFT; end else begin // If we've reached the end of the sampling time, and haven't // yet found the left margin of all the DQ bits, then: if (!tap_limit_cpt_r) begin // If we still have taps left to use, then store current value // of read data, increment the capture clock, and continue to // look for (left) edges store_sr_req_r <= #TCQ 1'b1; cal1_state_r <= #TCQ CAL1_PB_INC_CPT; end else begin // If we ran out of taps moving the capture clock, and we // haven't finished edge detection, then reset the capture // clock taps to 0 (gradually, one tap at a time... // then exit the per-bit portion of the algorithm - // i.e. proceed to adjust the capture clock and DQ IODELAYs as cnt_idel_dec_cpt_r <= #TCQ 6'd63; cal1_state_r <= #TCQ CAL1_PB_DEC_CPT; end end end // Increment delay for DQS CAL1_PB_INC_CPT: begin cal1_dlyce_cpt_r <= #TCQ 1'b1; cal1_dlyinc_cpt_r <= #TCQ 1'b1; cal1_state_r <= #TCQ CAL1_PB_INC_CPT_WAIT; end // Wait for IODELAY for both capture and internal nodes within // ISERDES to settle, before checking again for an edge CAL1_PB_INC_CPT_WAIT: begin cal1_dlyce_cpt_r <= #TCQ 1'b0; cal1_dlyinc_cpt_r <= #TCQ 1'b0; if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_PB_DETECT_EDGE; end // We've found the left edges of the windows for all DQ bits // (actually, we found it MIN_EYE_SIZE taps ago) Decrement capture // clock IDELAY to position just outside left edge of data window CAL1_PB_DEC_CPT_LEFT: if (cnt_idel_dec_cpt_r == 6'b000000) cal1_state_r <= #TCQ CAL1_PB_DEC_CPT_LEFT_WAIT; else begin cal1_dlyce_cpt_r <= #TCQ 1'b1; cal1_dlyinc_cpt_r <= #TCQ 1'b0; cnt_idel_dec_cpt_r <= #TCQ cnt_idel_dec_cpt_r - 1; end CAL1_PB_DEC_CPT_LEFT_WAIT: if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_PB_DETECT_EDGE_DQ; // If there is skew between individual DQ bits, then after we've // positioned the CPT clock, we will be "in the window" for some // DQ bits ("early" DQ bits), and "out of the window" for others // ("late" DQ bits). Increase DQ taps until we are out of the // window for all DQ bits CAL1_PB_DETECT_EDGE_DQ: if (detect_edge_done_r) if (found_edge_all_r) begin // We're out of the window for all DQ bits in this DQS group // We're done with per-bit deskew for this group - now decr // capture clock IODELAY tap count back to 0, and proceed // with the rest of stage 1 calibration for this DQS group cnt_idel_dec_cpt_r <= #TCQ tap_cnt_cpt_r; cal1_state_r <= #TCQ CAL1_PB_DEC_CPT; end else if (!idel_tap_limit_dq_pb_r) // If we still have DQ taps available for deskew, keep // incrementing IODELAY tap count for the appropriate DQ bits cal1_state_r <= #TCQ CAL1_PB_INC_DQ; else begin // Otherwise, stop immediately (we've done the best we can) // and proceed with rest of stage 1 calibration cnt_idel_dec_cpt_r <= #TCQ tap_cnt_cpt_r; cal1_state_r <= #TCQ CAL1_PB_DEC_CPT; end CAL1_PB_INC_DQ: begin // Increment only those DQ for which an edge hasn't been found yet cal1_dlyce_dq_r <= #TCQ ~pb_found_edge_last_r; cal1_dlyinc_dq_r <= #TCQ 1'b1; cal1_state_r <= #TCQ CAL1_PB_INC_DQ_WAIT; end CAL1_PB_INC_DQ_WAIT: if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_PB_DETECT_EDGE_DQ; // Decrement capture clock taps back to initial value CAL1_PB_DEC_CPT: if (cnt_idel_dec_cpt_r == 6'b000000) cal1_state_r <= #TCQ CAL1_PB_DEC_CPT_WAIT; else begin cal1_dlyce_cpt_r <= #TCQ 1'b1; cal1_dlyinc_cpt_r <= #TCQ 1'b0; cnt_idel_dec_cpt_r <= #TCQ cnt_idel_dec_cpt_r - 1; end // Wait for capture clock to settle, then proceed to rest of // state 1 calibration for this DQS group CAL1_PB_DEC_CPT_WAIT: if (!cal1_wait_r) begin store_sr_req_r <= #TCQ 1'b1; cal1_state_r <= #TCQ CAL1_STORE_FIRST_WAIT; end // When first starting calibration for a DQS group, save the // current value of the read data shift register, and use this // as a reference. Note that for the first iteration of the // edge detection loop, we will in effect be checking for an edge // at IODELAY taps = 0 - normally, we are comparing the read data // for IODELAY taps = N, with the read data for IODELAY taps = N-1 // An edge can only be found at IODELAY taps = 0 if the read data // is changing during this time (possible due to jitter) CAL1_STORE_FIRST_WAIT: begin mpr_dec_cpt_r <= #TCQ 1'b0; if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_PAT_DETECT; end CAL1_VALID_WAIT: begin if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_MPR_PAT_DETECT; end CAL1_MPR_PAT_DETECT: begin // MPR read leveling for centering DQS in valid window before // OCLKDELAYED calibration begins in order to eliminate read issues if (idel_pat_detect_valid_r == 1'b0) begin cal1_state_r <= #TCQ CAL1_VALID_WAIT; idel_pat_detect_valid_r <= #TCQ 1'b1; end else if (idel_pat_detect_valid_r && idel_mpr_pat_detect_r) begin cal1_state_r <= #TCQ CAL1_DETECT_EDGE; idel_dec_cnt <= #TCQ 'd0; end else if (!idelay_tap_limit_r) cal1_state_r <= #TCQ CAL1_DQ_IDEL_TAP_INC; else cal1_state_r <= #TCQ CAL1_RDLVL_ERR; end CAL1_PAT_DETECT: begin // All DQ bits associated with a DQS are pushed to the right one IDELAY // tap at a time until first rising DQS is in the tri-state region // before first rising edge window. // The detect_edge_done_r condition included to support averaging // during IDELAY tap increments if (detect_edge_done_r) begin if (idel_pat_data_match) begin cal1_state_r <= #TCQ CAL1_DETECT_EDGE; idel_dec_cnt <= #TCQ 'd0; end else if (!idelay_tap_limit_r) begin cal1_state_r <= #TCQ CAL1_DQ_IDEL_TAP_INC; end else begin cal1_state_r <= #TCQ CAL1_RDLVL_ERR; end end end // Increment IDELAY tap by 1 for DQ bits in the byte being calibrated // until left edge of valid window detected CAL1_DQ_IDEL_TAP_INC: begin cal1_dq_idel_ce <= #TCQ 1'b1; cal1_dq_idel_inc <= #TCQ 1'b1; cal1_state_r <= #TCQ CAL1_DQ_IDEL_TAP_INC_WAIT; idel_pat_detect_valid_r <= #TCQ 1'b0; end CAL1_DQ_IDEL_TAP_INC_WAIT: begin cal1_dq_idel_ce <= #TCQ 1'b0; cal1_dq_idel_inc <= #TCQ 1'b0; if (!cal1_wait_r) begin if (~mpr_rdlvl_done_r & (DRAM_TYPE == "DDR3")) cal1_state_r <= #TCQ CAL1_MPR_PAT_DETECT; else cal1_state_r <= #TCQ CAL1_PAT_DETECT; end end // Decrement by 2 IDELAY taps once idel_pat_data_match detected CAL1_DQ_IDEL_TAP_DEC: begin cal1_dq_idel_inc <= #TCQ 1'b0; cal1_state_r <= #TCQ CAL1_DQ_IDEL_TAP_DEC_WAIT; if (idel_dec_cnt >= 'd0) cal1_dq_idel_ce <= #TCQ 1'b1; else cal1_dq_idel_ce <= #TCQ 1'b0; if (idel_dec_cnt > 'd0) idel_dec_cnt <= #TCQ idel_dec_cnt - 1; else idel_dec_cnt <= #TCQ idel_dec_cnt; end CAL1_DQ_IDEL_TAP_DEC_WAIT: begin cal1_dq_idel_ce <= #TCQ 1'b0; cal1_dq_idel_inc <= #TCQ 1'b0; if (!cal1_wait_r) begin if ((idel_dec_cnt > 'd0) || (pi_rdval_cnt > 'd0)) cal1_state_r <= #TCQ CAL1_DQ_IDEL_TAP_DEC; else if (mpr_dec_cpt_r) cal1_state_r <= #TCQ CAL1_STORE_FIRST_WAIT; else cal1_state_r <= #TCQ CAL1_DETECT_EDGE; end end // Check for presence of data eye edge. During this state, we // sample the read data multiple times, and look for changes // in the read data, specifically: // 1. A change in the read data compared with the value of // read data from the previous delay tap. This indicates // that the most recent tap delay increment has moved us // into either a new window, or moved/kept us in the // transition/jitter region between windows. Note that this // condition only needs to be checked for once, and for // logistical purposes, we check this soon after entering // this state (see comment in CAL1_DETECT_EDGE below for // why this is done) // 2. A change in the read data while we are in this state // (i.e. in the absence of a tap delay increment). This // indicates that we're close enough to a window edge that // jitter will cause the read data to change even in the // absence of a tap delay change CAL1_DETECT_EDGE: begin // Essentially wait for the first comparision to finish, then // store current data into "old" data register. This store // happens now, rather than later (e.g. when we've have already // left this state) in order to avoid the situation the data that // is stored as "old" data has not been used in an "active // comparison" - i.e. data is stored after the last comparison // of this state. In this case, we can miss an edge if the // following sequence occurs: // 1. Comparison completes in this state - no edge found // 2. "Momentary jitter" occurs which "pushes" the data out the // equivalent of one delay tap // 3. We store this jittered data as the "old" data // 4. "Jitter" no longer present // 5. We increment the delay tap by one // 6. Now we compare the current with the "old" data - they're // the same, and no edge is detected // NOTE: Given the large # of comparisons done in this state, it's // highly unlikely the above sequence will occur in actual H/W // Wait for the first load of read data into the comparison // shift register to finish, then load the current read data // into the "old" data register. This allows us to do one // initial comparision between the current read data, and // stored data corresponding to the previous delay tap idel_pat_detect_valid_r <= #TCQ 1'b0; if (!store_sr_req_pulsed_r) begin // Pulse store_sr_req_r only once in this state store_sr_req_r <= #TCQ 1'b1; store_sr_req_pulsed_r <= #TCQ 1'b1; end else begin store_sr_req_r <= #TCQ 1'b0; store_sr_req_pulsed_r <= #TCQ 1'b1; end // Continue to sample read data and look for edges until the // appropriate time interval (shorter for simulation-only, // much, much longer for actual h/w) has elapsed if (detect_edge_done_r) begin if (tap_limit_cpt_r) // Only one edge detected and ran out of taps since only one // bit time worth of taps available for window detection. This // can happen if at tap 0 DQS is in previous window which results // in only left edge being detected. Or at tap 0 DQS is in the // current window resulting in only right edge being detected. // Depending on the frequency this case can also happen if at // tap 0 DQS is in the left noise region resulting in only left // edge being detected. cal1_state_r <= #TCQ CAL1_CALC_IDEL; else if (found_edge_r) begin // Sticky bit - asserted after we encounter an edge, although // the current edge may not be considered the "first edge" this // just means we found at least one edge found_first_edge_r <= #TCQ 1'b1; // Only the right edge of the data valid window is found // Record the inner right edge tap value if (!found_first_edge_r && found_stable_eye_last_r) begin if (tap_cnt_cpt_r == 'd0) right_edge_taps_r <= #TCQ 'd0; else right_edge_taps_r <= #TCQ tap_cnt_cpt_r; end // Both edges of data valid window found: // If we've found a second edge after a region of stability // then we must have just passed the second ("right" edge of // the window. Record this second_edge_taps = current tap-1, // because we're one past the actual second edge tap, where // the edge taps represent the extremes of the data valid // window (i.e. smallest & largest taps where data still valid if (found_first_edge_r && found_stable_eye_last_r) begin found_second_edge_r <= #TCQ 1'b1; second_edge_taps_r <= #TCQ tap_cnt_cpt_r - 1; cal1_state_r <= #TCQ CAL1_CALC_IDEL; end else begin // Otherwise, an edge was found (just not the "second" edge) // Assuming DQS is in the correct window at tap 0 of Phaser IN // fine tap. The first edge found is the right edge of the valid // window and is the beginning of the jitter region hence done! first_edge_taps_r <= #TCQ tap_cnt_cpt_r; cal1_state_r <= #TCQ CAL1_IDEL_INC_CPT; end end else // Otherwise, if we haven't found an edge.... // If we still have taps left to use, then keep incrementing cal1_state_r <= #TCQ CAL1_IDEL_INC_CPT; end end // Increment Phaser_IN delay for DQS CAL1_IDEL_INC_CPT: begin cal1_state_r <= #TCQ CAL1_IDEL_INC_CPT_WAIT; if (~tap_limit_cpt_r) begin cal1_dlyce_cpt_r <= #TCQ 1'b1; cal1_dlyinc_cpt_r <= #TCQ 1'b1; end else begin cal1_dlyce_cpt_r <= #TCQ 1'b0; cal1_dlyinc_cpt_r <= #TCQ 1'b0; end end // Wait for Phaser_In to settle, before checking again for an edge CAL1_IDEL_INC_CPT_WAIT: begin cal1_dlyce_cpt_r <= #TCQ 1'b0; cal1_dlyinc_cpt_r <= #TCQ 1'b0; if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_DETECT_EDGE; end // Calculate final value of Phaser_IN taps. At this point, one or both // edges of data eye have been found, and/or all taps have been // exhausted looking for the edges // NOTE: We're calculating the amount to decrement by, not the // absolute setting for DQS. CAL1_CALC_IDEL: begin // CASE1: If 2 edges found. if (found_second_edge_r) cnt_idel_dec_cpt_r <= #TCQ ((second_edge_taps_r - first_edge_taps_r)>>1) + 1; else if (right_edge_taps_r > 6'd0) // Only right edge detected // right_edge_taps_r is the inner right edge tap value // hence used for calculation cnt_idel_dec_cpt_r <= #TCQ (tap_cnt_cpt_r - (right_edge_taps_r>>1)); else if (found_first_edge_r) // Only left edge detected cnt_idel_dec_cpt_r <= #TCQ ((tap_cnt_cpt_r - first_edge_taps_r)>>1); else cnt_idel_dec_cpt_r <= #TCQ (tap_cnt_cpt_r>>1); // Now use the value we just calculated to decrement CPT taps // to the desired calibration point cal1_state_r <= #TCQ CAL1_IDEL_DEC_CPT; end // decrement capture clock for final adjustment - center // capture clock in middle of data eye. This adjustment will occur // only when both the edges are found usign CPT taps. Must do this // incrementally to avoid clock glitching (since CPT drives clock // divider within each ISERDES) CAL1_IDEL_DEC_CPT: begin cal1_dlyce_cpt_r <= #TCQ 1'b1; cal1_dlyinc_cpt_r <= #TCQ 1'b0; // once adjustment is complete, we're done with calibration for // this DQS, repeat for next DQS cnt_idel_dec_cpt_r <= #TCQ cnt_idel_dec_cpt_r - 1; if (cnt_idel_dec_cpt_r == 6'b000001) begin if (mpr_dec_cpt_r) begin if (|idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing]) begin idel_dec_cnt <= #TCQ idelay_tap_cnt_r[rnk_cnt_r][cal1_cnt_cpt_timing]; cal1_state_r <= #TCQ CAL1_DQ_IDEL_TAP_DEC; end else cal1_state_r <= #TCQ CAL1_STORE_FIRST_WAIT; end else cal1_state_r <= #TCQ CAL1_NEXT_DQS; end else cal1_state_r <= #TCQ CAL1_IDEL_DEC_CPT_WAIT; end CAL1_IDEL_DEC_CPT_WAIT: begin cal1_dlyce_cpt_r <= #TCQ 1'b0; cal1_dlyinc_cpt_r <= #TCQ 1'b0; if (!cal1_wait_r) cal1_state_r <= #TCQ CAL1_IDEL_DEC_CPT; end // Determine whether we're done, or have more DQS's to calibrate // Also request precharge after every byte, as appropriate CAL1_NEXT_DQS: begin //if (mpr_rdlvl_done_r || (DRAM_TYPE == "DDR2")) cal1_prech_req_r <= #TCQ 1'b1; //else // cal1_prech_req_r <= #TCQ 1'b0; cal1_dlyce_cpt_r <= #TCQ 1'b0; cal1_dlyinc_cpt_r <= #TCQ 1'b0; // Prepare for another iteration with next DQS group found_first_edge_r <= #TCQ 1'b0; found_second_edge_r <= #TCQ 1'b0; first_edge_taps_r <= #TCQ 'd0; second_edge_taps_r <= #TCQ 'd0; if ((SIM_CAL_OPTION == "FAST_CAL") || (cal1_cnt_cpt_r >= DQS_WIDTH-1)) begin if (mpr_rdlvl_done_r) begin rdlvl_last_byte_done <= #TCQ 1'b1; mpr_last_byte_done <= #TCQ 1'b0; end else begin rdlvl_last_byte_done <= #TCQ 1'b0; mpr_last_byte_done <= #TCQ 1'b1; end end // Wait until precharge that occurs in between calibration of // DQS groups is finished if (prech_done) begin // || (~mpr_rdlvl_done_r & (DRAM_TYPE == "DDR3"))) begin if (SIM_CAL_OPTION == "FAST_CAL") begin //rdlvl_rank_done_r <= #TCQ 1'b1; rdlvl_last_byte_done <= #TCQ 1'b0; mpr_last_byte_done <= #TCQ 1'b0; cal1_state_r <= #TCQ CAL1_DONE; //CAL1_REGL_LOAD; end else if (cal1_cnt_cpt_r >= DQS_WIDTH-1) begin if (~mpr_rdlvl_done_r) begin mpr_rank_done_r <= #TCQ 1'b1; // if (rnk_cnt_r == RANKS-1) begin // All DQS groups in all ranks done cal1_state_r <= #TCQ CAL1_DONE; cal1_cnt_cpt_r <= #TCQ 'b0; // end else begin // // Process DQS groups in next rank // rnk_cnt_r <= #TCQ rnk_cnt_r + 1; // new_cnt_cpt_r <= #TCQ 1'b1; // cal1_cnt_cpt_r <= #TCQ 'b0; // cal1_state_r <= #TCQ CAL1_IDLE; // end end else begin // All DQS groups in a rank done rdlvl_rank_done_r <= #TCQ 1'b1; if (rnk_cnt_r == RANKS-1) begin // All DQS groups in all ranks done cal1_state_r <= #TCQ CAL1_REGL_LOAD; end else begin // Process DQS groups in next rank rnk_cnt_r <= #TCQ rnk_cnt_r + 1; new_cnt_cpt_r <= #TCQ 1'b1; cal1_cnt_cpt_r <= #TCQ 'b0; cal1_state_r <= #TCQ CAL1_IDLE; end end end else begin // Process next DQS group new_cnt_cpt_r <= #TCQ 1'b1; cal1_cnt_cpt_r <= #TCQ cal1_cnt_cpt_r + 1; cal1_state_r <= #TCQ CAL1_NEW_DQS_PREWAIT; end end end CAL1_NEW_DQS_PREWAIT: begin if (!cal1_wait_r) begin if (~mpr_rdlvl_done_r & (DRAM_TYPE == "DDR3")) cal1_state_r <= #TCQ CAL1_MPR_NEW_DQS_WAIT; else cal1_state_r <= #TCQ CAL1_NEW_DQS_WAIT; end end // Load rank registers in Phaser_IN CAL1_REGL_LOAD: begin rdlvl_rank_done_r <= #TCQ 1'b0; mpr_rank_done_r <= #TCQ 1'b0; cal1_prech_req_r <= #TCQ 1'b0; cal1_cnt_cpt_r <= #TCQ 'b0; rnk_cnt_r <= #TCQ 2'b00; if ((regl_rank_cnt == RANKS-1) && ((regl_dqs_cnt == DQS_WIDTH-1) && (done_cnt == 4'd1))) begin cal1_state_r <= #TCQ CAL1_DONE; rdlvl_last_byte_done <= #TCQ 1'b0; mpr_last_byte_done <= #TCQ 1'b0; end else cal1_state_r <= #TCQ CAL1_REGL_LOAD; end CAL1_RDLVL_ERR: begin rdlvl_stg1_err <= #TCQ 1'b1; end // Done with this stage of calibration // if used, allow DEBUG_PORT to control taps CAL1_DONE: begin mpr_rdlvl_done_r <= #TCQ 1'b1; cal1_prech_req_r <= #TCQ 1'b0; if (~mpr_rdlvl_done_r && (OCAL_EN=="ON") && (DRAM_TYPE == "DDR3")) begin rdlvl_stg1_done <= #TCQ 1'b0; cal1_state_r <= #TCQ CAL1_IDLE; end else rdlvl_stg1_done <= #TCQ 1'b1; end endcase end endmodule
//***************************************************************************** // (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. // // This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and // international copyright and other intellectual property // laws. // // DISCLAIMER // This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of // liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage // (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was // reasonably foreseeable or Xilinx had been advised of the // possibility of the same. // // CRITICAL APPLICATIONS // Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, "Critical // Applications"). Customer assumes the sole risk and // liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and // regulations governing limitations on product liability. // // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES. // //***************************************************************************** // ____ ____ // / /\/ / // /___/ \ / Vendor : Xilinx // \ \ \/ Version : %version // \ \ Application : MIG // / / Filename : arb_mux.v // /___/ /\ Date Last Modified : $date$ // \ \ / \ Date Created : Tue Jun 30 2009 // \___\/\___\ // //Device : 7-Series //Design Name : DDR3 SDRAM //Purpose : //Reference : //Revision History : //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_arb_mux # ( parameter TCQ = 100, parameter EVEN_CWL_2T_MODE = "OFF", parameter ADDR_CMD_MODE = "1T", parameter BANK_VECT_INDX = 11, parameter BANK_WIDTH = 3, parameter BURST_MODE = "8", parameter CS_WIDTH = 4, parameter CL = 5, parameter CWL = 5, parameter DATA_BUF_ADDR_VECT_INDX = 31, parameter DATA_BUF_ADDR_WIDTH = 8, parameter DRAM_TYPE = "DDR3", parameter CKE_ODT_AUX = "FALSE", //Parameter to turn on/off the aux_out signal parameter EARLY_WR_DATA_ADDR = "OFF", parameter ECC = "OFF", parameter nBANK_MACHS = 4, parameter nCK_PER_CLK = 2, // # DRAM CKs per fabric CLKs parameter nCS_PER_RANK = 1, parameter nRAS = 37500, // ACT->PRE cmd period (CKs) parameter nRCD = 12500, // ACT->R/W delay (CKs) parameter nSLOTS = 2, parameter nWR = 6, // Write recovery (CKs) parameter RANKS = 1, parameter RANK_VECT_INDX = 15, parameter RANK_WIDTH = 2, parameter ROW_VECT_INDX = 63, parameter ROW_WIDTH = 16, parameter RTT_NOM = "40", parameter RTT_WR = "120", parameter SLOT_0_CONFIG = 8'b0000_0101, parameter SLOT_1_CONFIG = 8'b0000_1010 ) (/*AUTOARG*/ // Outputs output [ROW_WIDTH-1:0] col_a, // From arb_select0 of arb_select.v output [BANK_WIDTH-1:0] col_ba, // From arb_select0 of arb_select.v output [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr,// From arb_select0 of arb_select.v output col_periodic_rd, // From arb_select0 of arb_select.v output [RANK_WIDTH-1:0] col_ra, // From arb_select0 of arb_select.v output col_rmw, // From arb_select0 of arb_select.v output col_rd_wr, output [ROW_WIDTH-1:0] col_row, // From arb_select0 of arb_select.v output col_size, // From arb_select0 of arb_select.v output [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr,// From arb_select0 of arb_select.v output wire [nCK_PER_CLK-1:0] mc_ras_n, output wire [nCK_PER_CLK-1:0] mc_cas_n, output wire [nCK_PER_CLK-1:0] mc_we_n, output wire [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address, output wire [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank, output wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n, output wire [1:0] mc_odt, output wire [nCK_PER_CLK-1:0] mc_cke, output wire [3:0] mc_aux_out0, output wire [3:0] mc_aux_out1, output [2:0] mc_cmd, output [5:0] mc_data_offset, output [5:0] mc_data_offset_1, output [5:0] mc_data_offset_2, output [1:0] mc_cas_slot, output [RANK_WIDTH-1:0] rnk_config, // From arb_select0 of arb_select.v output rnk_config_valid_r, // From arb_row_col0 of arb_row_col.v output [nBANK_MACHS-1:0] sending_row, // From arb_row_col0 of arb_row_col.v output [nBANK_MACHS-1:0] sending_pre, output sent_col, // From arb_row_col0 of arb_row_col.v output sent_col_r, // From arb_row_col0 of arb_row_col.v output sent_row, // From arb_row_col0 of arb_row_col.v output [nBANK_MACHS-1:0] sending_col, output rnk_config_strobe, output insert_maint_r1, output rnk_config_kill_rts_col, // Inputs input clk, input rst, input init_calib_complete, input [6*RANKS-1:0] calib_rddata_offset, input [6*RANKS-1:0] calib_rddata_offset_1, input [6*RANKS-1:0] calib_rddata_offset_2, input [ROW_VECT_INDX:0] col_addr, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] col_rdy_wr, // To arb_row_col0 of arb_row_col.v input insert_maint_r, // To arb_row_col0 of arb_row_col.v input [RANK_WIDTH-1:0] maint_rank_r, // To arb_select0 of arb_select.v input maint_zq_r, // To arb_select0 of arb_select.v input maint_sre_r, // To arb_select0 of arb_select.v input maint_srx_r, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] rd_wr_r, // To arb_select0 of arb_select.v input [BANK_VECT_INDX:0] req_bank_r, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] req_cas, // To arb_select0 of arb_select.v input [DATA_BUF_ADDR_VECT_INDX:0] req_data_buf_addr_r,// To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] req_periodic_rd_r, // To arb_select0 of arb_select.v input [RANK_VECT_INDX:0] req_rank_r, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] req_ras, // To arb_select0 of arb_select.v input [ROW_VECT_INDX:0] req_row_r, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] req_size_r, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] req_wr_r, // To arb_select0 of arb_select.v input [ROW_VECT_INDX:0] row_addr, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] row_cmd_wr, // To arb_select0 of arb_select.v input [nBANK_MACHS-1:0] rtc, // To arb_row_col0 of arb_row_col.v input [nBANK_MACHS-1:0] rts_col, // To arb_row_col0 of arb_row_col.v input [nBANK_MACHS-1:0] rts_row, // To arb_row_col0 of arb_row_col.v input [nBANK_MACHS-1:0] rts_pre, // To arb_row_col0 of arb_row_col.v input [7:0] slot_0_present, // To arb_select0 of arb_select.v input [7:0] slot_1_present // To arb_select0 of arb_select.v ); /*AUTOINPUT*/ // Beginning of automatic inputs (from unused autoinst inputs) // End of automatics /*AUTOOUTPUT*/ // Beginning of automatic outputs (from unused autoinst outputs) // End of automatics /*AUTOWIRE*/ // Beginning of automatic wires (for undeclared instantiated-module outputs) wire cs_en0; // From arb_row_col0 of arb_row_col.v wire cs_en1; // From arb_row_col0 of arb_row_col.v wire [nBANK_MACHS-1:0] grant_col_r; // From arb_row_col0 of arb_row_col.v wire [nBANK_MACHS-1:0] grant_col_wr; // From arb_row_col0 of arb_row_col.v wire [nBANK_MACHS-1:0] grant_config_r; // From arb_row_col0 of arb_row_col.v wire [nBANK_MACHS-1:0] grant_row_r; // From arb_row_col0 of arb_row_col.v wire [nBANK_MACHS-1:0] grant_pre_r; // From arb_row_col0 of arb_row_col.v wire send_cmd0_row; // From arb_row_col0 of arb_row_col.v wire send_cmd0_col; // From arb_row_col0 of arb_row_col.v wire send_cmd1_row; // From arb_row_col0 of arb_row_col.v wire send_cmd1_col; wire send_cmd2_row; wire send_cmd2_col; wire send_cmd2_pre; wire send_cmd3_col; wire [5:0] col_channel_offset; // End of automatics wire sent_col_i; assign sent_col = sent_col_i; mig_7series_v1_9_arb_row_col # (/*AUTOINSTPARAM*/ // Parameters .TCQ (TCQ), .ADDR_CMD_MODE (ADDR_CMD_MODE), .CWL (CWL), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .nBANK_MACHS (nBANK_MACHS), .nCK_PER_CLK (nCK_PER_CLK), .nRAS (nRAS), .nRCD (nRCD), .nWR (nWR)) arb_row_col0 (/*AUTOINST*/ // Outputs .grant_row_r (grant_row_r[nBANK_MACHS-1:0]), .grant_pre_r (grant_pre_r[nBANK_MACHS-1:0]), .sent_row (sent_row), .sending_row (sending_row[nBANK_MACHS-1:0]), .sending_pre (sending_pre[nBANK_MACHS-1:0]), .grant_config_r (grant_config_r[nBANK_MACHS-1:0]), .rnk_config_strobe (rnk_config_strobe), .rnk_config_kill_rts_col (rnk_config_kill_rts_col), .rnk_config_valid_r (rnk_config_valid_r), .grant_col_r (grant_col_r[nBANK_MACHS-1:0]), .sending_col (sending_col[nBANK_MACHS-1:0]), .sent_col (sent_col_i), .sent_col_r (sent_col_r), .grant_col_wr (grant_col_wr[nBANK_MACHS-1:0]), .send_cmd0_row (send_cmd0_row), .send_cmd0_col (send_cmd0_col), .send_cmd1_row (send_cmd1_row), .send_cmd1_col (send_cmd1_col), .send_cmd2_row (send_cmd2_row), .send_cmd2_col (send_cmd2_col), .send_cmd2_pre (send_cmd2_pre), .send_cmd3_col (send_cmd3_col), .col_channel_offset (col_channel_offset), .cs_en0 (cs_en0), .cs_en1 (cs_en1), .cs_en2 (cs_en2), .cs_en3 (cs_en3), .insert_maint_r1 (insert_maint_r1), // Inputs .clk (clk), .rst (rst), .rts_row (rts_row[nBANK_MACHS-1:0]), .rts_pre (rts_pre[nBANK_MACHS-1:0]), .insert_maint_r (insert_maint_r), .rts_col (rts_col[nBANK_MACHS-1:0]), .rtc (rtc[nBANK_MACHS-1:0]), .col_rdy_wr (col_rdy_wr[nBANK_MACHS-1:0])); mig_7series_v1_9_arb_select # (/*AUTOINSTPARAM*/ // Parameters .TCQ (TCQ), .EVEN_CWL_2T_MODE (EVEN_CWL_2T_MODE), .ADDR_CMD_MODE (ADDR_CMD_MODE), .BANK_VECT_INDX (BANK_VECT_INDX), .BANK_WIDTH (BANK_WIDTH), .BURST_MODE (BURST_MODE), .CS_WIDTH (CS_WIDTH), .CL (CL), .CWL (CWL), .DATA_BUF_ADDR_VECT_INDX (DATA_BUF_ADDR_VECT_INDX), .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH), .DRAM_TYPE (DRAM_TYPE), .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR), .ECC (ECC), .CKE_ODT_AUX (CKE_ODT_AUX), .nBANK_MACHS (nBANK_MACHS), .nCK_PER_CLK (nCK_PER_CLK), .nCS_PER_RANK (nCS_PER_RANK), .nSLOTS (nSLOTS), .RANKS (RANKS), .RANK_VECT_INDX (RANK_VECT_INDX), .RANK_WIDTH (RANK_WIDTH), .ROW_VECT_INDX (ROW_VECT_INDX), .ROW_WIDTH (ROW_WIDTH), .RTT_NOM (RTT_NOM), .RTT_WR (RTT_WR), .SLOT_0_CONFIG (SLOT_0_CONFIG), .SLOT_1_CONFIG (SLOT_1_CONFIG)) arb_select0 (/*AUTOINST*/ // Outputs .col_periodic_rd (col_periodic_rd), .col_ra (col_ra[RANK_WIDTH-1:0]), .col_ba (col_ba[BANK_WIDTH-1:0]), .col_a (col_a[ROW_WIDTH-1:0]), .col_rmw (col_rmw), .col_rd_wr (col_rd_wr), .col_size (col_size), .col_row (col_row[ROW_WIDTH-1:0]), .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]), .mc_bank (mc_bank), .mc_address (mc_address), .mc_ras_n (mc_ras_n), .mc_cas_n (mc_cas_n), .mc_we_n (mc_we_n), .mc_cs_n (mc_cs_n), .mc_odt (mc_odt), .mc_cke (mc_cke), .mc_aux_out0 (mc_aux_out0), .mc_aux_out1 (mc_aux_out1), .mc_cmd (mc_cmd), .mc_data_offset (mc_data_offset), .mc_data_offset_1 (mc_data_offset_1), .mc_data_offset_2 (mc_data_offset_2), .mc_cas_slot (mc_cas_slot), .col_channel_offset (col_channel_offset), .rnk_config (rnk_config), // Inputs .clk (clk), .rst (rst), .init_calib_complete (init_calib_complete), .calib_rddata_offset (calib_rddata_offset), .calib_rddata_offset_1 (calib_rddata_offset_1), .calib_rddata_offset_2 (calib_rddata_offset_2), .req_rank_r (req_rank_r[RANK_VECT_INDX:0]), .req_bank_r (req_bank_r[BANK_VECT_INDX:0]), .req_ras (req_ras[nBANK_MACHS-1:0]), .req_cas (req_cas[nBANK_MACHS-1:0]), .req_wr_r (req_wr_r[nBANK_MACHS-1:0]), .grant_row_r (grant_row_r[nBANK_MACHS-1:0]), .grant_pre_r (grant_pre_r[nBANK_MACHS-1:0]), .row_addr (row_addr[ROW_VECT_INDX:0]), .row_cmd_wr (row_cmd_wr[nBANK_MACHS-1:0]), .insert_maint_r1 (insert_maint_r1), .maint_zq_r (maint_zq_r), .maint_sre_r (maint_sre_r), .maint_srx_r (maint_srx_r), .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]), .req_periodic_rd_r (req_periodic_rd_r[nBANK_MACHS-1:0]), .req_size_r (req_size_r[nBANK_MACHS-1:0]), .rd_wr_r (rd_wr_r[nBANK_MACHS-1:0]), .req_row_r (req_row_r[ROW_VECT_INDX:0]), .col_addr (col_addr[ROW_VECT_INDX:0]), .req_data_buf_addr_r (req_data_buf_addr_r[DATA_BUF_ADDR_VECT_INDX:0]), .grant_col_r (grant_col_r[nBANK_MACHS-1:0]), .grant_col_wr (grant_col_wr[nBANK_MACHS-1:0]), .send_cmd0_row (send_cmd0_row), .send_cmd0_col (send_cmd0_col), .send_cmd1_row (send_cmd1_row), .send_cmd1_col (send_cmd1_col), .send_cmd2_row (send_cmd2_row), .send_cmd2_col (send_cmd2_col), .send_cmd2_pre (send_cmd2_pre), .send_cmd3_col (send_cmd3_col), .sent_col (EVEN_CWL_2T_MODE == "ON" ? sent_col_r : sent_col), .cs_en0 (cs_en0), .cs_en1 (cs_en1), .cs_en2 (cs_en2), .cs_en3 (cs_en3), .grant_config_r (grant_config_r[nBANK_MACHS-1:0]), .rnk_config_strobe (rnk_config_strobe), .slot_0_present (slot_0_present[7:0]), .slot_1_present (slot_1_present[7:0])); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_reader.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Handles the RX lifecycle and issuing requests for receiving // data input. // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_RXPORTRD_MAIN_IDLE 6'b00_0001 `define S_RXPORTRD_MAIN_CHECK 6'b00_0010 `define S_RXPORTRD_MAIN_READ 6'b00_0100 `define S_RXPORTRD_MAIN_FLUSH 6'b00_1000 `define S_RXPORTRD_MAIN_DONE 6'b01_0000 `define S_RXPORTRD_MAIN_RESET 6'b10_0000 `define S_RXPORTRD_RX_IDLE 8'b0000_0001 `define S_RXPORTRD_RX_BUF 8'b0000_0010 `define S_RXPORTRD_RX_ADJ_0 8'b0000_0100 `define S_RXPORTRD_RX_ADJ_1 8'b0000_1000 `define S_RXPORTRD_RX_ISSUE 8'b0001_0000 `define S_RXPORTRD_RX_WAIT_0 8'b0010_0000 `define S_RXPORTRD_RX_WAIT_1 8'b0100_0000 `define S_RXPORTRD_RX_DONE 8'b1000_0000 `timescale 1ns/1ns module rx_port_reader #( parameter C_DATA_WIDTH = 9'd64, parameter C_FIFO_DEPTH = 1024, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_FIFO_WORDS = (C_DATA_WIDTH/32)*C_FIFO_DEPTH ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done output TXN_ERR, // Read transaction completed with error input TXN_DONE_ACK, // Read transaction actual transfer length read output TXN_DATA_FLUSH, // Request that all data in the packer be flushed input TXN_DATA_FLUSHED, // All data in the packer has been flushed output RX_REQ, // Issue a read request output [63:0] RX_ADDR, // Request address output [9:0] RX_LEN, // Request length input RX_REQ_ACK, // Request has been accepted input [C_DATA_WORD_WIDTH-1:0] RX_DATA_EN, // Incoming read data enable input RX_DONE, // Incoming read completed input RX_ERR, // Incoming read completed with error input SG_DONE, // Incoming scatter gather read completed input SG_ERR, // Incoming scatter gather read completed with error input [63:0] SG_ELEM_ADDR, // Scatter gather element address input [31:0] SG_ELEM_LEN, // Scatter gather element length (in words) input SG_ELEM_RDY, // Scatter gather element ready output SG_ELEM_REN, // Scatter gather element read enable output SG_RST, // Scatter gather reset output CHNL_RX, // Signal channel RX output [31:0] CHNL_RX_LEN, // Channel RX length output CHNL_RX_LAST, // Channel RX last output [30:0] CHNL_RX_OFF, // Channel RX offset input CHNL_RX_RECVD, // Channel RX received input CHNL_RX_ACK_RECVD, // Channel RX acknowledgment received input [31:0] CHNL_RX_CONSUMED // Channel words consumed in current RX ); `include "functions.vh" reg [31:0] rTxnData=0, _rTxnData=0; reg rTxnOffLastValid=0, _rTxnOffLastValid=0; reg rTxnLenValid=0, _rTxnLenValid=0; reg [C_DATA_WORD_WIDTH-1:0] rRxDataEn=0, _rRxDataEn=0; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [5:0] rMainState=`S_RXPORTRD_MAIN_IDLE, _rMainState=`S_RXPORTRD_MAIN_IDLE; reg [31:0] rOffLast=0, _rOffLast=0; reg [31:0] rReadWords=0, _rReadWords=0; reg rReadWordsZero=0, _rReadWordsZero=0; reg [0:0] rStart=0, _rStart=0; reg [3:0] rFlushed=0, _rFlushed=0; reg [31:0] rDoneLen=0, _rDoneLen=0; reg rTxnDone=0, _rTxnDone=0; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [7:0] rRxState=`S_RXPORTRD_RX_IDLE, _rRxState=`S_RXPORTRD_RX_IDLE; reg rSgRen=0, _rSgRen=0; reg [31:0] rWords=0, _rWords=0; reg [31:0] rBufWords=0, _rBufWords=0; reg [31:0] rBufWordsInit=0, _rBufWordsInit=0; reg rLargeBuf=0, _rLargeBuf=0; reg [63:0] rAddr=64'd0, _rAddr=64'd0; reg [3:0] rValsProp=0, _rValsProp=0; reg [2:0] rCarry=0, _rCarry=0; reg rCopyBufWords=0, _rCopyBufWords=0; reg rUseInit=0, _rUseInit=0; reg [10:0] rPageRem=0, _rPageRem=0; reg rPageSpill=0, _rPageSpill=0; reg rPageSpillInit=0, _rPageSpillInit=0; reg [10:0] rPreLen=0, _rPreLen=0; reg [2:0] rMaxPayloadTrain=0, _rMaxPayloadTrain=0; reg [2:0] rMaxPayloadShift=0, _rMaxPayloadShift=0; reg [9:0] rMaxPayload=0, _rMaxPayload=0; reg rPayloadSpill=0, _rPayloadSpill=0; reg rMaxLen=0, _rMaxLen=0; reg [9:0] rLen=0, _rLen=0; reg rLenEQWordsHi=0, _rLenEQWordsHi=0; reg rLenEQWordsLo=0, _rLenEQWordsLo=0; reg rLenEQBufWordsHi=0, _rLenEQBufWordsHi=0; reg rLenEQBufWordsLo=0, _rLenEQBufWordsLo=0; reg [31:0] rRecvdWords=0, _rRecvdWords=0; reg [31:0] rReqdWords=0, _rReqdWords=0; reg [31:0] rRequestingWords=0, _rRequestingWords=0; reg [31:0] rAvailWords=0, _rAvailWords=0; reg [31:0] rPartWords=0, _rPartWords=0; reg [10:0] rAckCount=0, _rAckCount=0; reg rAckCountEQ0=0, _rAckCountEQ0=0; reg rLastDoneRead=1, _rLastDoneRead=1; reg rTxnDoneAck=0, _rTxnDoneAck=0; reg rPartWordsRecvd=0, _rPartWordsRecvd=0; reg rCarryInv=0, _rCarryInv=0; reg rSpaceAvail=0, _rSpaceAvail=0; reg rPartialDone=0, _rPartialDone=0; reg rReqPartialDone=0, _rReqPartialDone=0; reg rErr=0, _rErr=0; assign TXN_DONE_LEN = rDoneLen; assign TXN_DONE = (rTxnDone | rPartialDone); assign TXN_ERR = rErr; assign TXN_DATA_FLUSH = rMainState[3]; // S_RXPORTRD_MAIN_FLUSH assign RX_REQ = (rRxState[4] & rSpaceAvail); // S_RXPORTRD_RX_ISSUE assign RX_ADDR = rAddr; assign RX_LEN = rLen; assign SG_ELEM_REN = rSgRen; assign SG_RST = rMainState[1]; // S_RXPORTRD_MAIN_CHECK assign CHNL_RX = (rMainState[2] | rMainState[3] | rMainState[4]); // S_RXPORTRD_MAIN_READ | S_RXPORTRD_MAIN_FLUSH | S_RXPORTRD_MAIN_DONE assign CHNL_RX_LEN = rReadWords; assign CHNL_RX_LAST = rOffLast[0]; assign CHNL_RX_OFF = rOffLast[31:1]; // Buffer signals that come from outside the rx_port. always @ (posedge CLK) begin rTxnData <= #1 _rTxnData; rTxnOffLastValid <= #1 _rTxnOffLastValid; rTxnLenValid <= #1 _rTxnLenValid; rTxnDoneAck <= #1 (RST ? 1'd0 : _rTxnDoneAck); rRxDataEn <= #1 _rRxDataEn; end always @ (*) begin _rTxnData = TXN_DATA; _rTxnOffLastValid = TXN_OFF_LAST_VALID; _rTxnLenValid = TXN_LEN_VALID; _rTxnDoneAck = TXN_DONE_ACK; _rRxDataEn = RX_DATA_EN; end // Handle RX lifecycle. always @ (posedge CLK) begin rMainState <= #1 (RST ? `S_RXPORTRD_MAIN_IDLE : _rMainState); rOffLast <= #1 _rOffLast; rReadWords <= #1 _rReadWords; rReadWordsZero <= #1 _rReadWordsZero; rStart <= #1 _rStart; rFlushed <= #1 _rFlushed; rDoneLen <= #1 (RST ? 0 : _rDoneLen); rTxnDone <= #1 _rTxnDone; end always @ (*) begin _rMainState = rMainState; _rDoneLen = rDoneLen; _rTxnDone = rTxnDone; _rOffLast = (rTxnOffLastValid ? rTxnData : rOffLast); _rReadWords = (rMainState[0] & rTxnLenValid ? rTxnData : rReadWords); _rReadWordsZero = (rReadWords == 0); _rStart = ((rStart<<1) | rTxnLenValid); _rFlushed = ((rFlushed<<1) | TXN_DATA_FLUSHED); case (rMainState) `S_RXPORTRD_MAIN_IDLE: begin // Wait for new read transaction offset/last & length _rTxnDone = 0; if (rStart[0]) _rMainState = `S_RXPORTRD_MAIN_CHECK; end `S_RXPORTRD_MAIN_CHECK: begin // See if we should start a transaction if (!rReadWordsZero) _rMainState = `S_RXPORTRD_MAIN_READ; else if (rOffLast[0]) _rMainState = `S_RXPORTRD_MAIN_FLUSH; else _rMainState = `S_RXPORTRD_MAIN_IDLE; end `S_RXPORTRD_MAIN_READ: begin // Issue read transfers, wait for data to arrive if (rRxState[7] & rLastDoneRead) begin // S_RXPORTRD_RX_DONE _rDoneLen = rRecvdWords; _rMainState = `S_RXPORTRD_MAIN_FLUSH; end end `S_RXPORTRD_MAIN_FLUSH: begin // Wait for data to be flushed if (rFlushed[3]) _rMainState = `S_RXPORTRD_MAIN_DONE; end `S_RXPORTRD_MAIN_DONE: begin // Wait for RX to be received and ackd in the channel if (CHNL_RX_RECVD & CHNL_RX_ACK_RECVD) _rMainState = `S_RXPORTRD_MAIN_RESET; end `S_RXPORTRD_MAIN_RESET: begin // Wait until RX has dropped in the channel if (!CHNL_RX_RECVD) begin _rTxnDone = 1; _rMainState = `S_RXPORTRD_MAIN_IDLE; end end default: begin _rMainState = `S_RXPORTRD_MAIN_IDLE; end endcase end // Issue the read requests at the buffer level. Decrement the amount requested // after every request. Continue until all words have been requested. wire [9:0] wAddrLoInv = ~rAddr[11:2]; always @ (posedge CLK) begin rRxState <= #1 (RST ? `S_RXPORTRD_RX_IDLE : _rRxState); rSgRen <= #1 (RST ? 1'd0: _rSgRen); rWords <= #1 _rWords; rBufWords <= #1 _rBufWords; rBufWordsInit <= #1 _rBufWordsInit; rLargeBuf <= #1 _rLargeBuf; rAddr <= #1 _rAddr; rCarry <= #1 _rCarry; rValsProp <= #1 _rValsProp; rPageRem <= #1 _rPageRem; rPageSpill <= #1 _rPageSpill; rPageSpillInit <= #1 _rPageSpillInit; rCopyBufWords <= #1 _rCopyBufWords; rUseInit <= #1 _rUseInit; rPreLen <= #1 _rPreLen; rMaxPayloadTrain <= #1 _rMaxPayloadTrain; rMaxPayloadShift <= #1 _rMaxPayloadShift; rMaxPayload <= #1 _rMaxPayload; rPayloadSpill <= #1 _rPayloadSpill; rMaxLen <= #1 _rMaxLen; rLen <= #1 _rLen; rLenEQWordsHi <= #1 _rLenEQWordsHi; rLenEQWordsLo <= #1 _rLenEQWordsLo; rLenEQBufWordsHi <= #1 _rLenEQBufWordsHi; rLenEQBufWordsLo <= #1 _rLenEQBufWordsLo; end always @ (*) begin _rRxState = rRxState; _rCopyBufWords = rCopyBufWords; _rUseInit = rUseInit; _rSgRen = rSgRen; _rValsProp = ((rValsProp<<1) | rRxState[2]); // S_RXPORTRD_RX_ADJ_0 _rLargeBuf = (SG_ELEM_LEN > rWords); {_rCarry[0], _rAddr[15:0]} = (rRxState[1] ? SG_ELEM_ADDR[15:0] : (rAddr[15:0] + ({12{RX_REQ_ACK}} & {rLen,2'd0}))); {_rCarry[1], _rAddr[31:16]} = (rRxState[1] ? SG_ELEM_ADDR[31:16] : (rAddr[31:16] + rCarry[0])); {_rCarry[2], _rAddr[47:32]} = (rRxState[1] ? SG_ELEM_ADDR[47:32] : (rAddr[47:32] + rCarry[1])); _rAddr[63:48] = (rRxState[1] ? SG_ELEM_ADDR[63:48] : (rAddr[63:48] + rCarry[2])); _rWords = (rRxState[0] ? rReadWords : (rWords - ({10{RX_REQ_ACK}} & rLen))); _rBufWordsInit = (rLargeBuf ? rWords : SG_ELEM_LEN); _rBufWords = (rCopyBufWords ? rBufWordsInit : rBufWords) - ({10{RX_REQ_ACK}} & rLen); _rPageRem = (wAddrLoInv + 1'd1); _rPageSpillInit = (rBufWordsInit > rPageRem); _rPageSpill = (rBufWords > rPageRem); _rPreLen = ((rPageSpillInit & rUseInit) | (rPageSpill & !rUseInit) ? rPageRem : rBufWords[10:0]); _rMaxPayloadTrain = (CONFIG_MAX_READ_REQUEST_SIZE > 3'd4 ? 3'd4 : CONFIG_MAX_READ_REQUEST_SIZE); _rMaxPayloadShift = (C_MAX_READ_REQ[2:0] < rMaxPayloadTrain ? C_MAX_READ_REQ[2:0] : rMaxPayloadTrain); _rMaxPayload = (6'd32<<rMaxPayloadShift); _rPayloadSpill = (rPreLen > rMaxPayload); _rMaxLen = ((rMaxLen & !rValsProp[2]) | RX_REQ_ACK); _rLen = (rPayloadSpill | rMaxLen ? rMaxPayload : rPreLen[9:0]); _rLenEQWordsHi = (16'd0 == rWords[31:16]); _rLenEQWordsLo = ({6'd0, rLen} == rWords[15:0]); _rLenEQBufWordsHi = (16'd0 == rBufWords[31:16]); _rLenEQBufWordsLo = ({6'd0, rLen} == rBufWords[15:0]); case (rRxState) `S_RXPORTRD_RX_IDLE: begin // Wait for a new read transaction if (rMainState[2]) // S_RXPORTRD_MAIN_READ _rRxState = `S_RXPORTRD_RX_BUF; end `S_RXPORTRD_RX_BUF: begin // Wait for buffer length and address if (SG_ELEM_RDY) begin _rSgRen = 1; _rRxState = `S_RXPORTRD_RX_ADJ_0; end else if (rErr) begin _rRxState = `S_RXPORTRD_RX_WAIT_0; end end `S_RXPORTRD_RX_ADJ_0: begin // Fix for large buffer _rSgRen = 0; _rCopyBufWords = rSgRen; _rRxState = `S_RXPORTRD_RX_ADJ_1; end // (bufwords and pagerem valid here) `S_RXPORTRD_RX_ADJ_1: begin // Wait for the value to propagate // Check for page boundary crossing // Fix for page boundary crossing // Check for max read payload // Fix for max read payload _rCopyBufWords = 0; _rUseInit = rCopyBufWords; if (rValsProp[3]) _rRxState = `S_RXPORTRD_RX_ISSUE; end `S_RXPORTRD_RX_ISSUE: begin // Wait for the request to be accepted if (RX_REQ_ACK) begin if (rErr | (rLenEQWordsHi & rLenEQWordsLo)) _rRxState = `S_RXPORTRD_RX_WAIT_0; else if (rLenEQBufWordsHi & rLenEQBufWordsLo) _rRxState = `S_RXPORTRD_RX_BUF; else _rRxState = `S_RXPORTRD_RX_ADJ_0; end end `S_RXPORTRD_RX_WAIT_0: begin // Wait for rAckCount to update _rRxState = `S_RXPORTRD_RX_WAIT_1; end `S_RXPORTRD_RX_WAIT_1: begin // Wait for requested data to arrive if (rAckCountEQ0) _rRxState = `S_RXPORTRD_RX_DONE; end `S_RXPORTRD_RX_DONE: begin // Signal done if (rMainState[3]) // S_RXPORTRD_MAIN_FLUSH _rRxState = `S_RXPORTRD_RX_IDLE; end default: begin _rRxState = `S_RXPORTRD_RX_IDLE; end endcase end // Count the data. always @ (posedge CLK) begin rRecvdWords <= #1 _rRecvdWords; rReqdWords <= #1 _rReqdWords; rPartWords <= #1 _rPartWords; rAckCount <= #1 _rAckCount; rAckCountEQ0 <= #1 _rAckCountEQ0; rPartWordsRecvd <= #1 _rPartWordsRecvd; rRequestingWords <= #1 _rRequestingWords; rAvailWords <= #1 _rAvailWords; rCarryInv <= #1 _rCarryInv; rSpaceAvail <= #1 _rSpaceAvail; rLastDoneRead <= #1 (RST ? 1'd1 : _rLastDoneRead); end always @ (*) begin // Count words as they arrive (words from the rx_engine directly). if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rRecvdWords = #1 0; else _rRecvdWords = #1 rRecvdWords + rRxDataEn; // Count words as they are requested. if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rReqdWords = #1 0; else _rReqdWords = #1 rReqdWords + ({10{RX_REQ_ACK}} & rLen); // Track outstanding requests if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rAckCount = 0; else _rAckCount = rAckCount + RX_REQ_ACK - RX_DONE; _rAckCountEQ0 = (rAckCount == 11'd0); // Track when the user reads the actual transfer amount. _rLastDoneRead = (rTxnDone ? 1'd0 : (rLastDoneRead | rTxnDoneAck)); // Track the amount of words that are expected to arrive. _rPartWords = #1 (rTxnLenValid ? rTxnData : rPartWords); // Compare counts. _rPartWordsRecvd = (rRecvdWords >= rPartWords); _rRequestingWords = rReqdWords + rLen; {_rCarryInv, _rAvailWords[15:0]} = {1'd1, rRequestingWords[15:0]} - CHNL_RX_CONSUMED[15:0]; _rAvailWords[31:16] = rRequestingWords[31:16] - CHNL_RX_CONSUMED[31:16] - !rCarryInv; _rSpaceAvail = (rAvailWords <= C_FIFO_WORDS); end // Facilitate sending a TXN_DONE when we receive a TXN_ACK after the transaction // has begun sending. This will happen when the workstation detects that it has // sent/used all its currently mapped scatter gather elements, but it's not enough // to complete the transaction. The TXN_DONE will let the workstation know it can // release the current scatter gather mappings and allocate new ones. always @ (posedge CLK) begin rPartialDone <= #1 _rPartialDone; rReqPartialDone <= #1 (RST ? 1'd0 : _rReqPartialDone); end always @ (*) begin // Signal TXN_DONE after we've recieved the (seemingly superfluous) TXN_ACK // and received the corresponding amount of words. _rPartialDone = (rReqPartialDone & rPartWordsRecvd); // Keep track of (seemingly superfluous) TXN_ACK requests. if ((rReqPartialDone & rPartWordsRecvd) | rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rReqPartialDone = 0; else _rReqPartialDone = (rReqPartialDone | rTxnLenValid); end // Handle errors in the main data or scatter gather data. always @ (posedge CLK) begin rErr <= #1 (RST ? 1'd0 : _rErr); end always @ (*) begin // Keep track of errors if we encounter them. if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rErr = 0; else _rErr = (rErr | (RX_DONE & RX_ERR) | (SG_DONE & SG_ERR)); end /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({TXN_LEN_VALID | TXN_DONE_ACK | TXN_DONE | TXN_ERR, 1'd0, rMainState}), .DATA({176'd0, 64'd0, // 64 rAddr, // 64 SG_ELEM_RDY, // 1 1'd0, // 1 1'd0, // 1 1'd0, // 1 rSgRen, // 1 1'd0, // 1 rLastDoneRead, // 1 rLen, // 10 rWords, // 32 rAckCount, // 11 rPartWords, // 32 rPartWordsRecvd, // 1 rReqPartialDone, // 1 rPartialDone, // 1 rTxnDone, // 1 rRxState, // 8 rRecvdWords, // 32 rReadWords, // 32 TXN_LEN_VALID, // 1 TXN_DONE_ACK, // 1 rDoneLen, // 32 rMainState}) // 6 ); */ endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_reader.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Handles the RX lifecycle and issuing requests for receiving // data input. // for the RIFFA channel. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_RXPORTRD_MAIN_IDLE 6'b00_0001 `define S_RXPORTRD_MAIN_CHECK 6'b00_0010 `define S_RXPORTRD_MAIN_READ 6'b00_0100 `define S_RXPORTRD_MAIN_FLUSH 6'b00_1000 `define S_RXPORTRD_MAIN_DONE 6'b01_0000 `define S_RXPORTRD_MAIN_RESET 6'b10_0000 `define S_RXPORTRD_RX_IDLE 8'b0000_0001 `define S_RXPORTRD_RX_BUF 8'b0000_0010 `define S_RXPORTRD_RX_ADJ_0 8'b0000_0100 `define S_RXPORTRD_RX_ADJ_1 8'b0000_1000 `define S_RXPORTRD_RX_ISSUE 8'b0001_0000 `define S_RXPORTRD_RX_WAIT_0 8'b0010_0000 `define S_RXPORTRD_RX_WAIT_1 8'b0100_0000 `define S_RXPORTRD_RX_DONE 8'b1000_0000 `timescale 1ns/1ns module rx_port_reader #( parameter C_DATA_WIDTH = 9'd64, parameter C_FIFO_DEPTH = 1024, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B // Local parameters parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1), parameter C_FIFO_WORDS = (C_DATA_WIDTH/32)*C_FIFO_DEPTH ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B input [31:0] TXN_DATA, // Read transaction data input TXN_LEN_VALID, // Read transaction length valid input TXN_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_DONE_LEN, // Read transaction actual transfer length output TXN_DONE, // Read transaction done output TXN_ERR, // Read transaction completed with error input TXN_DONE_ACK, // Read transaction actual transfer length read output TXN_DATA_FLUSH, // Request that all data in the packer be flushed input TXN_DATA_FLUSHED, // All data in the packer has been flushed output RX_REQ, // Issue a read request output [63:0] RX_ADDR, // Request address output [9:0] RX_LEN, // Request length input RX_REQ_ACK, // Request has been accepted input [C_DATA_WORD_WIDTH-1:0] RX_DATA_EN, // Incoming read data enable input RX_DONE, // Incoming read completed input RX_ERR, // Incoming read completed with error input SG_DONE, // Incoming scatter gather read completed input SG_ERR, // Incoming scatter gather read completed with error input [63:0] SG_ELEM_ADDR, // Scatter gather element address input [31:0] SG_ELEM_LEN, // Scatter gather element length (in words) input SG_ELEM_RDY, // Scatter gather element ready output SG_ELEM_REN, // Scatter gather element read enable output SG_RST, // Scatter gather reset output CHNL_RX, // Signal channel RX output [31:0] CHNL_RX_LEN, // Channel RX length output CHNL_RX_LAST, // Channel RX last output [30:0] CHNL_RX_OFF, // Channel RX offset input CHNL_RX_RECVD, // Channel RX received input CHNL_RX_ACK_RECVD, // Channel RX acknowledgment received input [31:0] CHNL_RX_CONSUMED // Channel words consumed in current RX ); `include "functions.vh" reg [31:0] rTxnData=0, _rTxnData=0; reg rTxnOffLastValid=0, _rTxnOffLastValid=0; reg rTxnLenValid=0, _rTxnLenValid=0; reg [C_DATA_WORD_WIDTH-1:0] rRxDataEn=0, _rRxDataEn=0; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [5:0] rMainState=`S_RXPORTRD_MAIN_IDLE, _rMainState=`S_RXPORTRD_MAIN_IDLE; reg [31:0] rOffLast=0, _rOffLast=0; reg [31:0] rReadWords=0, _rReadWords=0; reg rReadWordsZero=0, _rReadWordsZero=0; reg [0:0] rStart=0, _rStart=0; reg [3:0] rFlushed=0, _rFlushed=0; reg [31:0] rDoneLen=0, _rDoneLen=0; reg rTxnDone=0, _rTxnDone=0; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [7:0] rRxState=`S_RXPORTRD_RX_IDLE, _rRxState=`S_RXPORTRD_RX_IDLE; reg rSgRen=0, _rSgRen=0; reg [31:0] rWords=0, _rWords=0; reg [31:0] rBufWords=0, _rBufWords=0; reg [31:0] rBufWordsInit=0, _rBufWordsInit=0; reg rLargeBuf=0, _rLargeBuf=0; reg [63:0] rAddr=64'd0, _rAddr=64'd0; reg [3:0] rValsProp=0, _rValsProp=0; reg [2:0] rCarry=0, _rCarry=0; reg rCopyBufWords=0, _rCopyBufWords=0; reg rUseInit=0, _rUseInit=0; reg [10:0] rPageRem=0, _rPageRem=0; reg rPageSpill=0, _rPageSpill=0; reg rPageSpillInit=0, _rPageSpillInit=0; reg [10:0] rPreLen=0, _rPreLen=0; reg [2:0] rMaxPayloadTrain=0, _rMaxPayloadTrain=0; reg [2:0] rMaxPayloadShift=0, _rMaxPayloadShift=0; reg [9:0] rMaxPayload=0, _rMaxPayload=0; reg rPayloadSpill=0, _rPayloadSpill=0; reg rMaxLen=0, _rMaxLen=0; reg [9:0] rLen=0, _rLen=0; reg rLenEQWordsHi=0, _rLenEQWordsHi=0; reg rLenEQWordsLo=0, _rLenEQWordsLo=0; reg rLenEQBufWordsHi=0, _rLenEQBufWordsHi=0; reg rLenEQBufWordsLo=0, _rLenEQBufWordsLo=0; reg [31:0] rRecvdWords=0, _rRecvdWords=0; reg [31:0] rReqdWords=0, _rReqdWords=0; reg [31:0] rRequestingWords=0, _rRequestingWords=0; reg [31:0] rAvailWords=0, _rAvailWords=0; reg [31:0] rPartWords=0, _rPartWords=0; reg [10:0] rAckCount=0, _rAckCount=0; reg rAckCountEQ0=0, _rAckCountEQ0=0; reg rLastDoneRead=1, _rLastDoneRead=1; reg rTxnDoneAck=0, _rTxnDoneAck=0; reg rPartWordsRecvd=0, _rPartWordsRecvd=0; reg rCarryInv=0, _rCarryInv=0; reg rSpaceAvail=0, _rSpaceAvail=0; reg rPartialDone=0, _rPartialDone=0; reg rReqPartialDone=0, _rReqPartialDone=0; reg rErr=0, _rErr=0; assign TXN_DONE_LEN = rDoneLen; assign TXN_DONE = (rTxnDone | rPartialDone); assign TXN_ERR = rErr; assign TXN_DATA_FLUSH = rMainState[3]; // S_RXPORTRD_MAIN_FLUSH assign RX_REQ = (rRxState[4] & rSpaceAvail); // S_RXPORTRD_RX_ISSUE assign RX_ADDR = rAddr; assign RX_LEN = rLen; assign SG_ELEM_REN = rSgRen; assign SG_RST = rMainState[1]; // S_RXPORTRD_MAIN_CHECK assign CHNL_RX = (rMainState[2] | rMainState[3] | rMainState[4]); // S_RXPORTRD_MAIN_READ | S_RXPORTRD_MAIN_FLUSH | S_RXPORTRD_MAIN_DONE assign CHNL_RX_LEN = rReadWords; assign CHNL_RX_LAST = rOffLast[0]; assign CHNL_RX_OFF = rOffLast[31:1]; // Buffer signals that come from outside the rx_port. always @ (posedge CLK) begin rTxnData <= #1 _rTxnData; rTxnOffLastValid <= #1 _rTxnOffLastValid; rTxnLenValid <= #1 _rTxnLenValid; rTxnDoneAck <= #1 (RST ? 1'd0 : _rTxnDoneAck); rRxDataEn <= #1 _rRxDataEn; end always @ (*) begin _rTxnData = TXN_DATA; _rTxnOffLastValid = TXN_OFF_LAST_VALID; _rTxnLenValid = TXN_LEN_VALID; _rTxnDoneAck = TXN_DONE_ACK; _rRxDataEn = RX_DATA_EN; end // Handle RX lifecycle. always @ (posedge CLK) begin rMainState <= #1 (RST ? `S_RXPORTRD_MAIN_IDLE : _rMainState); rOffLast <= #1 _rOffLast; rReadWords <= #1 _rReadWords; rReadWordsZero <= #1 _rReadWordsZero; rStart <= #1 _rStart; rFlushed <= #1 _rFlushed; rDoneLen <= #1 (RST ? 0 : _rDoneLen); rTxnDone <= #1 _rTxnDone; end always @ (*) begin _rMainState = rMainState; _rDoneLen = rDoneLen; _rTxnDone = rTxnDone; _rOffLast = (rTxnOffLastValid ? rTxnData : rOffLast); _rReadWords = (rMainState[0] & rTxnLenValid ? rTxnData : rReadWords); _rReadWordsZero = (rReadWords == 0); _rStart = ((rStart<<1) | rTxnLenValid); _rFlushed = ((rFlushed<<1) | TXN_DATA_FLUSHED); case (rMainState) `S_RXPORTRD_MAIN_IDLE: begin // Wait for new read transaction offset/last & length _rTxnDone = 0; if (rStart[0]) _rMainState = `S_RXPORTRD_MAIN_CHECK; end `S_RXPORTRD_MAIN_CHECK: begin // See if we should start a transaction if (!rReadWordsZero) _rMainState = `S_RXPORTRD_MAIN_READ; else if (rOffLast[0]) _rMainState = `S_RXPORTRD_MAIN_FLUSH; else _rMainState = `S_RXPORTRD_MAIN_IDLE; end `S_RXPORTRD_MAIN_READ: begin // Issue read transfers, wait for data to arrive if (rRxState[7] & rLastDoneRead) begin // S_RXPORTRD_RX_DONE _rDoneLen = rRecvdWords; _rMainState = `S_RXPORTRD_MAIN_FLUSH; end end `S_RXPORTRD_MAIN_FLUSH: begin // Wait for data to be flushed if (rFlushed[3]) _rMainState = `S_RXPORTRD_MAIN_DONE; end `S_RXPORTRD_MAIN_DONE: begin // Wait for RX to be received and ackd in the channel if (CHNL_RX_RECVD & CHNL_RX_ACK_RECVD) _rMainState = `S_RXPORTRD_MAIN_RESET; end `S_RXPORTRD_MAIN_RESET: begin // Wait until RX has dropped in the channel if (!CHNL_RX_RECVD) begin _rTxnDone = 1; _rMainState = `S_RXPORTRD_MAIN_IDLE; end end default: begin _rMainState = `S_RXPORTRD_MAIN_IDLE; end endcase end // Issue the read requests at the buffer level. Decrement the amount requested // after every request. Continue until all words have been requested. wire [9:0] wAddrLoInv = ~rAddr[11:2]; always @ (posedge CLK) begin rRxState <= #1 (RST ? `S_RXPORTRD_RX_IDLE : _rRxState); rSgRen <= #1 (RST ? 1'd0: _rSgRen); rWords <= #1 _rWords; rBufWords <= #1 _rBufWords; rBufWordsInit <= #1 _rBufWordsInit; rLargeBuf <= #1 _rLargeBuf; rAddr <= #1 _rAddr; rCarry <= #1 _rCarry; rValsProp <= #1 _rValsProp; rPageRem <= #1 _rPageRem; rPageSpill <= #1 _rPageSpill; rPageSpillInit <= #1 _rPageSpillInit; rCopyBufWords <= #1 _rCopyBufWords; rUseInit <= #1 _rUseInit; rPreLen <= #1 _rPreLen; rMaxPayloadTrain <= #1 _rMaxPayloadTrain; rMaxPayloadShift <= #1 _rMaxPayloadShift; rMaxPayload <= #1 _rMaxPayload; rPayloadSpill <= #1 _rPayloadSpill; rMaxLen <= #1 _rMaxLen; rLen <= #1 _rLen; rLenEQWordsHi <= #1 _rLenEQWordsHi; rLenEQWordsLo <= #1 _rLenEQWordsLo; rLenEQBufWordsHi <= #1 _rLenEQBufWordsHi; rLenEQBufWordsLo <= #1 _rLenEQBufWordsLo; end always @ (*) begin _rRxState = rRxState; _rCopyBufWords = rCopyBufWords; _rUseInit = rUseInit; _rSgRen = rSgRen; _rValsProp = ((rValsProp<<1) | rRxState[2]); // S_RXPORTRD_RX_ADJ_0 _rLargeBuf = (SG_ELEM_LEN > rWords); {_rCarry[0], _rAddr[15:0]} = (rRxState[1] ? SG_ELEM_ADDR[15:0] : (rAddr[15:0] + ({12{RX_REQ_ACK}} & {rLen,2'd0}))); {_rCarry[1], _rAddr[31:16]} = (rRxState[1] ? SG_ELEM_ADDR[31:16] : (rAddr[31:16] + rCarry[0])); {_rCarry[2], _rAddr[47:32]} = (rRxState[1] ? SG_ELEM_ADDR[47:32] : (rAddr[47:32] + rCarry[1])); _rAddr[63:48] = (rRxState[1] ? SG_ELEM_ADDR[63:48] : (rAddr[63:48] + rCarry[2])); _rWords = (rRxState[0] ? rReadWords : (rWords - ({10{RX_REQ_ACK}} & rLen))); _rBufWordsInit = (rLargeBuf ? rWords : SG_ELEM_LEN); _rBufWords = (rCopyBufWords ? rBufWordsInit : rBufWords) - ({10{RX_REQ_ACK}} & rLen); _rPageRem = (wAddrLoInv + 1'd1); _rPageSpillInit = (rBufWordsInit > rPageRem); _rPageSpill = (rBufWords > rPageRem); _rPreLen = ((rPageSpillInit & rUseInit) | (rPageSpill & !rUseInit) ? rPageRem : rBufWords[10:0]); _rMaxPayloadTrain = (CONFIG_MAX_READ_REQUEST_SIZE > 3'd4 ? 3'd4 : CONFIG_MAX_READ_REQUEST_SIZE); _rMaxPayloadShift = (C_MAX_READ_REQ[2:0] < rMaxPayloadTrain ? C_MAX_READ_REQ[2:0] : rMaxPayloadTrain); _rMaxPayload = (6'd32<<rMaxPayloadShift); _rPayloadSpill = (rPreLen > rMaxPayload); _rMaxLen = ((rMaxLen & !rValsProp[2]) | RX_REQ_ACK); _rLen = (rPayloadSpill | rMaxLen ? rMaxPayload : rPreLen[9:0]); _rLenEQWordsHi = (16'd0 == rWords[31:16]); _rLenEQWordsLo = ({6'd0, rLen} == rWords[15:0]); _rLenEQBufWordsHi = (16'd0 == rBufWords[31:16]); _rLenEQBufWordsLo = ({6'd0, rLen} == rBufWords[15:0]); case (rRxState) `S_RXPORTRD_RX_IDLE: begin // Wait for a new read transaction if (rMainState[2]) // S_RXPORTRD_MAIN_READ _rRxState = `S_RXPORTRD_RX_BUF; end `S_RXPORTRD_RX_BUF: begin // Wait for buffer length and address if (SG_ELEM_RDY) begin _rSgRen = 1; _rRxState = `S_RXPORTRD_RX_ADJ_0; end else if (rErr) begin _rRxState = `S_RXPORTRD_RX_WAIT_0; end end `S_RXPORTRD_RX_ADJ_0: begin // Fix for large buffer _rSgRen = 0; _rCopyBufWords = rSgRen; _rRxState = `S_RXPORTRD_RX_ADJ_1; end // (bufwords and pagerem valid here) `S_RXPORTRD_RX_ADJ_1: begin // Wait for the value to propagate // Check for page boundary crossing // Fix for page boundary crossing // Check for max read payload // Fix for max read payload _rCopyBufWords = 0; _rUseInit = rCopyBufWords; if (rValsProp[3]) _rRxState = `S_RXPORTRD_RX_ISSUE; end `S_RXPORTRD_RX_ISSUE: begin // Wait for the request to be accepted if (RX_REQ_ACK) begin if (rErr | (rLenEQWordsHi & rLenEQWordsLo)) _rRxState = `S_RXPORTRD_RX_WAIT_0; else if (rLenEQBufWordsHi & rLenEQBufWordsLo) _rRxState = `S_RXPORTRD_RX_BUF; else _rRxState = `S_RXPORTRD_RX_ADJ_0; end end `S_RXPORTRD_RX_WAIT_0: begin // Wait for rAckCount to update _rRxState = `S_RXPORTRD_RX_WAIT_1; end `S_RXPORTRD_RX_WAIT_1: begin // Wait for requested data to arrive if (rAckCountEQ0) _rRxState = `S_RXPORTRD_RX_DONE; end `S_RXPORTRD_RX_DONE: begin // Signal done if (rMainState[3]) // S_RXPORTRD_MAIN_FLUSH _rRxState = `S_RXPORTRD_RX_IDLE; end default: begin _rRxState = `S_RXPORTRD_RX_IDLE; end endcase end // Count the data. always @ (posedge CLK) begin rRecvdWords <= #1 _rRecvdWords; rReqdWords <= #1 _rReqdWords; rPartWords <= #1 _rPartWords; rAckCount <= #1 _rAckCount; rAckCountEQ0 <= #1 _rAckCountEQ0; rPartWordsRecvd <= #1 _rPartWordsRecvd; rRequestingWords <= #1 _rRequestingWords; rAvailWords <= #1 _rAvailWords; rCarryInv <= #1 _rCarryInv; rSpaceAvail <= #1 _rSpaceAvail; rLastDoneRead <= #1 (RST ? 1'd1 : _rLastDoneRead); end always @ (*) begin // Count words as they arrive (words from the rx_engine directly). if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rRecvdWords = #1 0; else _rRecvdWords = #1 rRecvdWords + rRxDataEn; // Count words as they are requested. if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rReqdWords = #1 0; else _rReqdWords = #1 rReqdWords + ({10{RX_REQ_ACK}} & rLen); // Track outstanding requests if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rAckCount = 0; else _rAckCount = rAckCount + RX_REQ_ACK - RX_DONE; _rAckCountEQ0 = (rAckCount == 11'd0); // Track when the user reads the actual transfer amount. _rLastDoneRead = (rTxnDone ? 1'd0 : (rLastDoneRead | rTxnDoneAck)); // Track the amount of words that are expected to arrive. _rPartWords = #1 (rTxnLenValid ? rTxnData : rPartWords); // Compare counts. _rPartWordsRecvd = (rRecvdWords >= rPartWords); _rRequestingWords = rReqdWords + rLen; {_rCarryInv, _rAvailWords[15:0]} = {1'd1, rRequestingWords[15:0]} - CHNL_RX_CONSUMED[15:0]; _rAvailWords[31:16] = rRequestingWords[31:16] - CHNL_RX_CONSUMED[31:16] - !rCarryInv; _rSpaceAvail = (rAvailWords <= C_FIFO_WORDS); end // Facilitate sending a TXN_DONE when we receive a TXN_ACK after the transaction // has begun sending. This will happen when the workstation detects that it has // sent/used all its currently mapped scatter gather elements, but it's not enough // to complete the transaction. The TXN_DONE will let the workstation know it can // release the current scatter gather mappings and allocate new ones. always @ (posedge CLK) begin rPartialDone <= #1 _rPartialDone; rReqPartialDone <= #1 (RST ? 1'd0 : _rReqPartialDone); end always @ (*) begin // Signal TXN_DONE after we've recieved the (seemingly superfluous) TXN_ACK // and received the corresponding amount of words. _rPartialDone = (rReqPartialDone & rPartWordsRecvd); // Keep track of (seemingly superfluous) TXN_ACK requests. if ((rReqPartialDone & rPartWordsRecvd) | rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rReqPartialDone = 0; else _rReqPartialDone = (rReqPartialDone | rTxnLenValid); end // Handle errors in the main data or scatter gather data. always @ (posedge CLK) begin rErr <= #1 (RST ? 1'd0 : _rErr); end always @ (*) begin // Keep track of errors if we encounter them. if (rMainState[0]) // S_RXPORTRD_MAIN_IDLE _rErr = 0; else _rErr = (rErr | (RX_DONE & RX_ERR) | (SG_DONE & SG_ERR)); end /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({TXN_LEN_VALID | TXN_DONE_ACK | TXN_DONE | TXN_ERR, 1'd0, rMainState}), .DATA({176'd0, 64'd0, // 64 rAddr, // 64 SG_ELEM_RDY, // 1 1'd0, // 1 1'd0, // 1 1'd0, // 1 rSgRen, // 1 1'd0, // 1 rLastDoneRead, // 1 rLen, // 10 rWords, // 32 rAckCount, // 11 rPartWords, // 32 rPartWordsRecvd, // 1 rReqPartialDone, // 1 rPartialDone, // 1 rTxnDone, // 1 rRxState, // 8 rRecvdWords, // 32 rReadWords, // 32 TXN_LEN_VALID, // 1 TXN_DONE_ACK, // 1 rDoneLen, // 32 rMainState}) // 6 ); */ endmodule
// (C) 2001-2016 Altera Corporation. All rights reserved. // Your use of Altera Corporation's design tools, logic functions and other // software and tools, and its AMPP partner logic functions, and any output // files any of the foregoing (including device programming or simulation // files), and any associated documentation or information are expressly subject // to the terms and conditions of the Altera Program License Subscription // Agreement, Altera MegaCore Function License Agreement, or other applicable // license agreement, including, without limitation, that your use is for the // sole purpose of programming logic devices manufactured by Altera and sold by // Altera or its authorized distributors. Please refer to the applicable // agreement for further details. // THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS // IN THIS FILE. /****************************************************************************** * * * This module writes data to the RS232 UART Port. * * * ******************************************************************************/ module altera_up_rs232_out_serializer ( // Inputs clk, reset, transmit_data, transmit_data_en, // Bidirectionals // Outputs fifo_write_space, serial_data_out ); /***************************************************************************** * Parameter Declarations * *****************************************************************************/ parameter CW = 9; // Baud counter width parameter BAUD_TICK_COUNT = 433; parameter HALF_BAUD_TICK_COUNT = 216; parameter TDW = 11; // Total data width parameter DW = 9; // Data width /***************************************************************************** * Port Declarations * *****************************************************************************/ // Inputs input clk; input reset; input [DW: 0] transmit_data; input transmit_data_en; // Bidirectionals // Outputs output reg [ 7: 0] fifo_write_space; output reg serial_data_out; /***************************************************************************** * Constant Declarations * *****************************************************************************/ /***************************************************************************** * Internal Wires and Registers Declarations * *****************************************************************************/ // Internal Wires wire shift_data_reg_en; wire all_bits_transmitted; wire read_fifo_en; wire fifo_is_empty; wire fifo_is_full; wire [ 6: 0] fifo_used; wire [DW: 0] data_from_fifo; // Internal Registers reg transmitting_data; reg [DW+1:0] data_out_shift_reg; // State Machine Registers /***************************************************************************** * Finite State Machine(s) * *****************************************************************************/ /***************************************************************************** * Sequential Logic * *****************************************************************************/ always @(posedge clk) begin if (reset) fifo_write_space <= 8'h00; else fifo_write_space <= 8'h80 - {fifo_is_full, fifo_used}; end always @(posedge clk) begin if (reset) serial_data_out <= 1'b1; else serial_data_out <= data_out_shift_reg[0]; end always @(posedge clk) begin if (reset) transmitting_data <= 1'b0; else if (all_bits_transmitted) transmitting_data <= 1'b0; else if (fifo_is_empty == 1'b0) transmitting_data <= 1'b1; end always @(posedge clk) begin if (reset) data_out_shift_reg <= {(DW + 2){1'b1}}; else if (read_fifo_en) data_out_shift_reg <= {data_from_fifo, 1'b0}; else if (shift_data_reg_en) data_out_shift_reg <= {1'b1, data_out_shift_reg[DW+1:1]}; end /***************************************************************************** * Combinational Logic * *****************************************************************************/ assign read_fifo_en = ~transmitting_data & ~fifo_is_empty & ~all_bits_transmitted; /***************************************************************************** * Internal Modules * *****************************************************************************/ altera_up_rs232_counters RS232_Out_Counters ( // Inputs .clk (clk), .reset (reset), .reset_counters (~transmitting_data), // Bidirectionals // Outputs .baud_clock_rising_edge (shift_data_reg_en), .baud_clock_falling_edge (), .all_bits_transmitted (all_bits_transmitted) ); defparam RS232_Out_Counters.CW = CW, RS232_Out_Counters.BAUD_TICK_COUNT = BAUD_TICK_COUNT, RS232_Out_Counters.HALF_BAUD_TICK_COUNT = HALF_BAUD_TICK_COUNT, RS232_Out_Counters.TDW = TDW; altera_up_sync_fifo RS232_Out_FIFO ( // Inputs .clk (clk), .reset (reset), .write_en (transmit_data_en & ~fifo_is_full), .write_data (transmit_data), .read_en (read_fifo_en), // Bidirectionals // Outputs .fifo_is_empty (fifo_is_empty), .fifo_is_full (fifo_is_full), .words_used (fifo_used), .read_data (data_from_fifo) ); defparam RS232_Out_FIFO.DW = DW, RS232_Out_FIFO.DATA_DEPTH = 128, RS232_Out_FIFO.AW = 6; endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: fifo_packer_128.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Packs 32, 64, or 96 bit received data into a 128 bit wide // FIFO. Assumes the FIFO always has room to accommodate the data. // Author: Matt Jacobsen // History: @mattj: Version 2.0 // Additional Comments: //----------------------------------------------------------------------------- `timescale 1ns/1ns module fifo_packer_128 ( input CLK, input RST, input [127:0] DATA_IN, // Incoming data input [2:0] DATA_IN_EN, // Incoming data enable input DATA_IN_DONE, // Incoming data packet end input DATA_IN_ERR, // Incoming data error input DATA_IN_FLUSH, // End of incoming data output [127:0] PACKED_DATA, // Outgoing data output PACKED_WEN, // Outgoing data write enable output PACKED_DATA_DONE, // End of outgoing data packet output PACKED_DATA_ERR, // Error in outgoing data output PACKED_DATA_FLUSHED // End of outgoing data ); reg [2:0] rPackedCount=0, _rPackedCount=0; reg rPackedDone=0, _rPackedDone=0; reg rPackedErr=0, _rPackedErr=0; reg rPackedFlush=0, _rPackedFlush=0; reg rPackedFlushed=0, _rPackedFlushed=0; reg [223:0] rPackedData=224'd0, _rPackedData=224'd0; reg [127:0] rDataIn=128'd0, _rDataIn=128'd0; reg [2:0] rDataInEn=0, _rDataInEn=0; reg [127:0] rDataMasked=128'd0, _rDataMasked=128'd0; reg [2:0] rDataMaskedEn=0, _rDataMaskedEn=0; assign PACKED_DATA = rPackedData[127:0]; assign PACKED_WEN = rPackedCount[2]; assign PACKED_DATA_DONE = rPackedDone; assign PACKED_DATA_ERR = rPackedErr; assign PACKED_DATA_FLUSHED = rPackedFlushed; // Buffers input data until 4 words are available, then writes 4 words out. wire [127:0] wMask = {128{1'b1}}<<(32*rDataInEn); wire [127:0] wDataMasked = ~wMask & rDataIn; always @ (posedge CLK) begin rPackedCount <= #1 (RST ? 3'd0 : _rPackedCount); rPackedDone <= #1 (RST ? 1'd0 : _rPackedDone); rPackedErr <= #1 (RST ? 1'd0 : _rPackedErr); rPackedFlush <= #1 (RST ? 1'd0 : _rPackedFlush); rPackedFlushed <= #1 (RST ? 1'd0 : _rPackedFlushed); rPackedData <= #1 (RST ? 224'd0 : _rPackedData); rDataIn <= #1 _rDataIn; rDataInEn <= #1 (RST ? 3'd0 : _rDataInEn); rDataMasked <= #1 _rDataMasked; rDataMaskedEn <= #1 (RST ? 3'd0 : _rDataMaskedEn); end always @ (*) begin // Buffer and mask the input data. _rDataIn = DATA_IN; _rDataInEn = DATA_IN_EN; _rDataMasked = wDataMasked; _rDataMaskedEn = rDataInEn; // Count what's in our buffer. When we reach 4 words, 4 words will be written // out. If flush is requested, write out whatever remains. if (rPackedFlush && (rPackedCount[1] | rPackedCount[0])) _rPackedCount = 4; else _rPackedCount = rPackedCount + rDataMaskedEn - {rPackedCount[2], 2'd0}; // Shift data into and out of our buffer as we receive and write out data. if (rDataMaskedEn != 3'd0) _rPackedData = ((rPackedData>>(32*{rPackedCount[2], 2'd0})) | (rDataMasked<<(32*rPackedCount[1:0]))); else _rPackedData = (rPackedData>>(32*{rPackedCount[2], 2'd0})); // Track done/error/flush signals. _rPackedDone = DATA_IN_DONE; _rPackedErr = DATA_IN_ERR; _rPackedFlush = DATA_IN_FLUSH; _rPackedFlushed = rPackedFlush; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_channel_gate.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Provides cross domain synchronization for the CHNL_RX* // signals between the CHNL_CLK and CLK domains. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_channel_gate #( parameter C_DATA_WIDTH = 9'd64 ) ( input RST, input CLK, input RX, // Channel read signal (CLK) output RX_RECVD, // Channel read received signal (CLK) output RX_ACK_RECVD, // Channel read acknowledgment received signal (CLK) input RX_LAST, // Channel last read (CLK) input [31:0] RX_LEN, // Channel read length (CLK) input [30:0] RX_OFF, // Channel read offset (CLK) output [31:0] RX_CONSUMED, // Channel words consumed (CLK) input [C_DATA_WIDTH-1:0] RD_DATA, // FIFO read data (CHNL_CLK) input RD_EMPTY, // FIFO is empty (CHNL_CLK) output RD_EN, // FIFO read enable (CHNL_CLK) input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal (CHNL_CLK) input CHNL_RX_ACK, // Channle read received signal (CHNL_CLK) output CHNL_RX_LAST, // Channel last read (CHNL_CLK) output [31:0] CHNL_RX_LEN, // Channel read length (CHNL_CLK) output [30:0] CHNL_RX_OFF, // Channel read offset (CHNL_CLK) output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data (CHNL_CLK) output CHNL_RX_DATA_VALID, // Channel read data valid (CHNL_CLK) input CHNL_RX_DATA_REN // Channel read data has been recieved (CHNL_CLK) ); reg rAckd=0, _rAckd=0; reg rChnlRxAck=0, _rChnlRxAck=0; reg [31:0] rConsumed=0, _rConsumed=0; reg [31:0] rConsumedStable=0, _rConsumedStable=0; reg [31:0] rConsumedSample=0, _rConsumedSample=0; reg rCountRead=0, _rCountRead=0; wire wCountRead; wire wCountStable; wire wDataRead = (CHNL_RX_DATA_REN & CHNL_RX_DATA_VALID); assign RX_CONSUMED = rConsumedSample; assign RD_EN = CHNL_RX_DATA_REN; assign CHNL_RX_LAST = RX_LAST; assign CHNL_RX_LEN = RX_LEN; assign CHNL_RX_OFF = RX_OFF; assign CHNL_RX_DATA = RD_DATA; assign CHNL_RX_DATA_VALID = !RD_EMPTY; // Buffer the input signals that come from outside the rx_port. always @ (posedge CHNL_CLK) begin rChnlRxAck <= #1 (RST ? 1'd0 : _rChnlRxAck); end always @ (*) begin _rChnlRxAck = CHNL_RX_ACK; end // Signal receive into the channel domain. cross_domain_signal rxSig ( .CLK_A(CLK), .CLK_A_SEND(RX), .CLK_A_RECV(RX_RECVD), .CLK_B(CHNL_CLK), .CLK_B_RECV(CHNL_RX), .CLK_B_SEND(CHNL_RX) ); // Signal acknowledgment of receive into the CLK domain. syncff rxAckSig (.CLK(CLK), .IN_ASYNC(rAckd), .OUT_SYNC(RX_ACK_RECVD)); // Capture CHNL_RX_ACK and reset only after the CHNL_RX drops. always @ (posedge CHNL_CLK) begin rAckd <= #1 (RST ? 1'd0 : _rAckd); end always @ (*) begin _rAckd = (CHNL_RX & (rAckd | rChnlRxAck)); end // Count the words consumed by the channel and pass it into the CLK domain. always @ (posedge CHNL_CLK) begin rConsumed <= #1 _rConsumed; rConsumedStable <= #1 _rConsumedStable; rCountRead <= #1 (RST ? 1'd0 : _rCountRead); end always @ (*) begin _rConsumed = (!CHNL_RX ? 0 : rConsumed + (wDataRead*(C_DATA_WIDTH/32))); _rConsumedStable = (wCountRead | rCountRead ? rConsumedStable : rConsumed); _rCountRead = !wCountRead; end always @ (posedge CLK) begin rConsumedSample <= #1 _rConsumedSample; end always @ (*) begin _rConsumedSample = (wCountStable ? rConsumedStable : rConsumedSample); end // Determine when it's safe to update the count in the CLK domain. cross_domain_signal countSync ( .CLK_A(CHNL_CLK), .CLK_A_SEND(rCountRead), .CLK_A_RECV(wCountRead), .CLK_B(CLK), .CLK_B_RECV(wCountStable), .CLK_B_SEND(wCountStable) ); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_port_channel_gate.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Provides cross domain synchronization for the CHNL_RX* // signals between the CHNL_CLK and CLK domains. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module rx_port_channel_gate #( parameter C_DATA_WIDTH = 9'd64 ) ( input RST, input CLK, input RX, // Channel read signal (CLK) output RX_RECVD, // Channel read received signal (CLK) output RX_ACK_RECVD, // Channel read acknowledgment received signal (CLK) input RX_LAST, // Channel last read (CLK) input [31:0] RX_LEN, // Channel read length (CLK) input [30:0] RX_OFF, // Channel read offset (CLK) output [31:0] RX_CONSUMED, // Channel words consumed (CLK) input [C_DATA_WIDTH-1:0] RD_DATA, // FIFO read data (CHNL_CLK) input RD_EMPTY, // FIFO is empty (CHNL_CLK) output RD_EN, // FIFO read enable (CHNL_CLK) input CHNL_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal (CHNL_CLK) input CHNL_RX_ACK, // Channle read received signal (CHNL_CLK) output CHNL_RX_LAST, // Channel last read (CHNL_CLK) output [31:0] CHNL_RX_LEN, // Channel read length (CHNL_CLK) output [30:0] CHNL_RX_OFF, // Channel read offset (CHNL_CLK) output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data (CHNL_CLK) output CHNL_RX_DATA_VALID, // Channel read data valid (CHNL_CLK) input CHNL_RX_DATA_REN // Channel read data has been recieved (CHNL_CLK) ); reg rAckd=0, _rAckd=0; reg rChnlRxAck=0, _rChnlRxAck=0; reg [31:0] rConsumed=0, _rConsumed=0; reg [31:0] rConsumedStable=0, _rConsumedStable=0; reg [31:0] rConsumedSample=0, _rConsumedSample=0; reg rCountRead=0, _rCountRead=0; wire wCountRead; wire wCountStable; wire wDataRead = (CHNL_RX_DATA_REN & CHNL_RX_DATA_VALID); assign RX_CONSUMED = rConsumedSample; assign RD_EN = CHNL_RX_DATA_REN; assign CHNL_RX_LAST = RX_LAST; assign CHNL_RX_LEN = RX_LEN; assign CHNL_RX_OFF = RX_OFF; assign CHNL_RX_DATA = RD_DATA; assign CHNL_RX_DATA_VALID = !RD_EMPTY; // Buffer the input signals that come from outside the rx_port. always @ (posedge CHNL_CLK) begin rChnlRxAck <= #1 (RST ? 1'd0 : _rChnlRxAck); end always @ (*) begin _rChnlRxAck = CHNL_RX_ACK; end // Signal receive into the channel domain. cross_domain_signal rxSig ( .CLK_A(CLK), .CLK_A_SEND(RX), .CLK_A_RECV(RX_RECVD), .CLK_B(CHNL_CLK), .CLK_B_RECV(CHNL_RX), .CLK_B_SEND(CHNL_RX) ); // Signal acknowledgment of receive into the CLK domain. syncff rxAckSig (.CLK(CLK), .IN_ASYNC(rAckd), .OUT_SYNC(RX_ACK_RECVD)); // Capture CHNL_RX_ACK and reset only after the CHNL_RX drops. always @ (posedge CHNL_CLK) begin rAckd <= #1 (RST ? 1'd0 : _rAckd); end always @ (*) begin _rAckd = (CHNL_RX & (rAckd | rChnlRxAck)); end // Count the words consumed by the channel and pass it into the CLK domain. always @ (posedge CHNL_CLK) begin rConsumed <= #1 _rConsumed; rConsumedStable <= #1 _rConsumedStable; rCountRead <= #1 (RST ? 1'd0 : _rCountRead); end always @ (*) begin _rConsumed = (!CHNL_RX ? 0 : rConsumed + (wDataRead*(C_DATA_WIDTH/32))); _rConsumedStable = (wCountRead | rCountRead ? rConsumedStable : rConsumed); _rCountRead = !wCountRead; end always @ (posedge CLK) begin rConsumedSample <= #1 _rConsumedSample; end always @ (*) begin _rConsumedSample = (wCountStable ? rConsumedStable : rConsumedSample); end // Determine when it's safe to update the count in the CLK domain. cross_domain_signal countSync ( .CLK_A(CHNL_CLK), .CLK_A_SEND(rCountRead), .CLK_A_RECV(wCountRead), .CLK_B(CLK), .CLK_B_RECV(wCountStable), .CLK_B_SEND(wCountStable) ); endmodule
////////////////////////////////////////////////////////////////////// //// //// //// spi_clgen.v //// //// //// //// This file is part of the SPI IP core project //// //// http://www.opencores.org/projects/spi/ //// //// //// //// Author(s): //// //// - Simon Srot ([email protected]) //// //// //// //// All additional information is avaliable in the Readme.txt //// //// file. //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2002 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// `include "spi_defines.v" `include "timescale.v" module spi_clgen (clk_in, rst, go, enable, last_clk, divider, clk_out, pos_edge, neg_edge); parameter Tp = 1; input clk_in; // input clock (system clock) input rst; // reset input enable; // clock enable input go; // start transfer input last_clk; // last clock input [`SPI_DIVIDER_LEN-1:0] divider; // clock divider (output clock is divided by this value) output clk_out; // output clock output pos_edge; // pulse marking positive edge of clk_out output neg_edge; // pulse marking negative edge of clk_out reg clk_out; reg pos_edge; reg neg_edge; reg [`SPI_DIVIDER_LEN-1:0] cnt; // clock counter wire cnt_zero; // conter is equal to zero wire cnt_one; // conter is equal to one assign cnt_zero = cnt == {`SPI_DIVIDER_LEN{1'b0}}; assign cnt_one = cnt == {{`SPI_DIVIDER_LEN-1{1'b0}}, 1'b1}; // Counter counts half period always @(posedge clk_in or posedge rst) begin if(rst) cnt <= #Tp {`SPI_DIVIDER_LEN{1'b1}}; else begin if(!enable || cnt_zero) cnt <= #Tp divider; else cnt <= #Tp cnt - {{`SPI_DIVIDER_LEN-1{1'b0}}, 1'b1}; end end // clk_out is asserted every other half period always @(posedge clk_in or posedge rst) begin if(rst) clk_out <= #Tp 1'b0; else clk_out <= #Tp (enable && cnt_zero && (!last_clk || clk_out)) ? ~clk_out : clk_out; end // Pos and neg edge signals always @(posedge clk_in or posedge rst) begin if(rst) begin pos_edge <= #Tp 1'b0; neg_edge <= #Tp 1'b0; end else begin pos_edge <= #Tp (enable && !clk_out && cnt_one) || (!(|divider) && clk_out) || (!(|divider) && go && !enable); neg_edge <= #Tp (enable && clk_out && cnt_one) || (!(|divider) && !clk_out && enable); end end endmodule
////////////////////////////////////////////////////////////////////// //// //// //// spi_clgen.v //// //// //// //// This file is part of the SPI IP core project //// //// http://www.opencores.org/projects/spi/ //// //// //// //// Author(s): //// //// - Simon Srot ([email protected]) //// //// //// //// All additional information is avaliable in the Readme.txt //// //// file. //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2002 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// `include "spi_defines.v" `include "timescale.v" module spi_clgen (clk_in, rst, go, enable, last_clk, divider, clk_out, pos_edge, neg_edge); parameter Tp = 1; input clk_in; // input clock (system clock) input rst; // reset input enable; // clock enable input go; // start transfer input last_clk; // last clock input [`SPI_DIVIDER_LEN-1:0] divider; // clock divider (output clock is divided by this value) output clk_out; // output clock output pos_edge; // pulse marking positive edge of clk_out output neg_edge; // pulse marking negative edge of clk_out reg clk_out; reg pos_edge; reg neg_edge; reg [`SPI_DIVIDER_LEN-1:0] cnt; // clock counter wire cnt_zero; // conter is equal to zero wire cnt_one; // conter is equal to one assign cnt_zero = cnt == {`SPI_DIVIDER_LEN{1'b0}}; assign cnt_one = cnt == {{`SPI_DIVIDER_LEN-1{1'b0}}, 1'b1}; // Counter counts half period always @(posedge clk_in or posedge rst) begin if(rst) cnt <= #Tp {`SPI_DIVIDER_LEN{1'b1}}; else begin if(!enable || cnt_zero) cnt <= #Tp divider; else cnt <= #Tp cnt - {{`SPI_DIVIDER_LEN-1{1'b0}}, 1'b1}; end end // clk_out is asserted every other half period always @(posedge clk_in or posedge rst) begin if(rst) clk_out <= #Tp 1'b0; else clk_out <= #Tp (enable && cnt_zero && (!last_clk || clk_out)) ? ~clk_out : clk_out; end // Pos and neg edge signals always @(posedge clk_in or posedge rst) begin if(rst) begin pos_edge <= #Tp 1'b0; neg_edge <= #Tp 1'b0; end else begin pos_edge <= #Tp (enable && !clk_out && cnt_one) || (!(|divider) && clk_out) || (!(|divider) && go && !enable); neg_edge <= #Tp (enable && clk_out && cnt_one) || (!(|divider) && !clk_out && enable); end end endmodule
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 04/27/2016 08:14:07 AM // Design Name: // Module Name: FPU_UART // Project Name: // Target Devices: // Tool Versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module FPU_UART #(parameter W = 32, parameter EW = 8, parameter SW = 23, parameter SWR=26, parameter EWR = 5)//-- Single Precision*/ /*#(parameter W = 64, parameter EW = 11, parameter SW = 52, parameter SWR = 55, parameter EWR = 6) //-- Double Precision */ ( input wire clk, input wire rst, output wire TX ); //local parameters localparam shift_region = 2'b00; localparam N = 2; //2 para 32 bits, 3 para 64 bits localparam op = 1'b0; localparam d = 0; localparam r_mode=2'b00; //signal declaration wire ready_op; wire max_tick_address; wire max_tick_ch; wire TX_DONE; wire beg_op; wire ack_op; wire load_address; wire enab_address; wire enab_ch; wire load_ch; wire TX_START; wire [W-1:0] Data_X; wire [W-1:0] Data_Y; wire [W-1:0] final_result_ieee; wire [7:0] TX_DATA; wire [9:0] cont_address_sig; wire [N-1:0] cont_ch; FSM_test fsm_test_uart ( .clk(clk), .rst(rst), .ready_op(ready_op), .max_tick_address(max_tick_address), .max_tick_ch(max_tick_ch), .TX_DONE(TX_DONE), .beg_op(beg_op), .ack_op(ack_op), .load_address(load_address), .enab_address(enab_address), .enab_ch(enab_ch), .load_ch(load_ch), .TX_START(TX_START) ); //Adder-Subtract////////////////////////////////////////////////////////////////////////////// FPU_Add_Subtract_Function #(.W(W),.EW(EW),.SW(SW),.SWR(SWR),.EWR(EWR)) Add_Subt_uart( .clk(clk), //System clock .rst(rst), //System reset .beg_FSM(beg_op), //Start operation control signal .ack_FSM(ack_op), //Acknoledge control signal .Data_X(Data_X), //Data_X .Data_Y(Data_Y), //Data_Y .add_subt(op), //1'b0 =Adder, 1'b1=Substract .r_mode(r_mode), //Rounding control signal. 2'b00=no round, 2'b01= -infinite round , 2'b10 +infinite round //.overflow_flag, //.underflow_flag, .ready(ready_op), //Ready flag .final_result_ieee(final_result_ieee) //Result of the operation );//*/ //Multiplication /*FPU_Multiplication_Function #(.W(W),.EW(EW),.SW(SW)) Multiplication_uart( .clk(clk), .rst(rst), .beg_FSM(beg_op), .ack_FSM(ack_op), .Data_MX(Data_X), .Data_MY(Data_Y), .round_mode(r_mode), //.overflow_flag, //.underflow_flag, .ready(ready_op), .final_result_ieee(final_result_ieee) ); //*/ Uart uart_mod ( .RST(rst), .CLK(clk), .TX_START(TX_START), .TX_DATA(TX_DATA), .TX(TX), .TX_DONE(TX_DONE) ); ///Data file ROM ROM_test #(.W(W),.N(0)) rom_test_uart_X ( .address(cont_address_sig), .data(Data_X) ); ROM_test #(.W(W),.N(1)) rom_test_uart_Y ( .address(cont_address_sig), .data(Data_Y) ); cont_test #(.W(10)) cont_address ( .clk(clk), .rst(rst), .load(load_address), .enable(enab_address), .d(d), .max_tick(max_tick_address), .q(cont_address_sig) ); cont_test #(.W(N)) con_mux_data ( .clk(clk), .rst(rst), .load(load_ch), .enable(enab_ch), .d(d), .max_tick(max_tick_ch), .q(cont_ch) ); generate case(W) 32: begin Mux_4x1 mux_32_uart ( .select(cont_ch), .ch_0(final_result_ieee[7:0]), .ch_1(final_result_ieee[15:8]), .ch_2(final_result_ieee[23:16]), .ch_3(final_result_ieee[31:24]), .data_out(TX_DATA) ); end 64: begin Mux_8x1 mux_64_uart ( .select(cont_ch), .ch_0(final_result_ieee[7:0]), .ch_1(final_result_ieee[15:8]), .ch_2(final_result_ieee[23:16]), .ch_3(final_result_ieee[31:24]), .ch_4(final_result_ieee[39:32]), .ch_5(final_result_ieee[47:40]), .ch_6(final_result_ieee[55:48]), .ch_7(final_result_ieee[63:56]), .data_out(TX_DATA) ); end default: begin Mux_4x1 mux_32_uart ( .select(cont_ch), .ch_0(final_result_ieee[7:0]), .ch_1(final_result_ieee[15:8]), .ch_2(final_result_ieee[23:16]), .ch_3(final_result_ieee[31:24]), .data_out(TX_DATA) ); end endcase endgenerate endmodule
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 22:36:46 09/06/2015 // Design Name: // Module Name: FPU_Multiplication_Function // Project Name: // Target Devices: // Tool versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module FPU_Multiplication_Function //SINGLE PRECISION PARAMETERS /*# (parameter W = 32, parameter EW = 8, parameter SW = 23) // */ //DOUBLE PRECISION PARAMETERS # (parameter W = 64, parameter EW = 11, parameter SW = 52) // */ ( input wire clk, input wire rst, input wire beg_FSM, input wire ack_FSM, input wire [W-1:0] Data_MX, input wire [W-1:0] Data_MY, input wire [1:0] round_mode, output wire overflow_flag, output wire underflow_flag, output wire ready, output wire [W-1:0] final_result_ieee ); //GENERAL wire rst_int; //** //FSM_load_signals wire FSM_first_phase_load; //** wire FSM_load_first_step; /*Zero flag, Exp operation underflow, Sgf operation first reg, sign result reg*/ wire FSM_exp_operation_load_result; //Exp operation result, wire FSM_load_second_step; //Exp operation Overflow, Sgf operation second reg wire FSM_barrel_shifter_load; wire FSM_adder_round_norm_load; wire FSM_final_result_load; //ZERO FLAG //Op_MX; //Op_MY wire zero_flag; //FIRST PHASE wire [W-1:0] Op_MX; wire [W-1:0] Op_MY; //Mux S-> exp_operation OPER_A_i////////// wire FSM_selector_A; //D0=Op_MX[W-2:W-EW-1] //D1=exp_oper_result wire [EW:0] S_Oper_A_exp; //Mux S-> exp_operation OPER_B_i////////// wire [1:0] FSM_selector_B; //D0=Op_MY[W-2:W-EW-1] //D1=LZA_output //D2=1 wire [EW-1:0] S_Oper_B_exp; ///////////exp_operation/////////////////////////// wire FSM_exp_operation_A_S; //oper_A= S_Oper_A_exp //oper_B= S_Oper_B_exp wire [EW:0] exp_oper_result; //Sgf operation////////////////// //Op_A={1'b1, Op_MX[SW-1:0]} //Op_B={1'b1, Op_MY[SW-1:0]} wire [2*SW+1:0] P_Sgf; wire[SW:0] significand; wire[SW:0] non_significand; //Sign Operation wire sign_final_result; //barrel shifter multiplexers wire [SW:0] S_Data_Shift; //barrel shifter wire [SW:0] Sgf_normalized_result; //adder rounding wire FSM_add_overflow_flag; //Oper_A_i=norm result //Oper_B_i=1 wire [SW:0] Add_result; //round decoder wire FSM_round_flag; //Selecto moltiplexers wire selector_A; wire [1:0] selector_B; wire load_b; wire selector_C; //Barrel shifter multiplexer /////////////////////////////////////////FSM//////////////////////////////////////////// FSM_Mult_Function FS_Module ( .clk(clk), //** .rst(rst), //** .beg_FSM(beg_FSM), //** .ack_FSM(ack_FSM), //** .zero_flag_i(zero_flag), .Mult_shift_i(P_Sgf[2*SW+1]), .round_flag_i(FSM_round_flag), .Add_Overflow_i(FSM_add_overflow_flag), .load_0_o(FSM_first_phase_load), .load_1_o(FSM_load_first_step), .load_2_o(FSM_exp_operation_load_result), .load_3_o(FSM_load_second_step), .load_4_o(FSM_adder_round_norm_load), .load_5_o(FSM_final_result_load), .load_6_o(FSM_barrel_shifter_load), .ctrl_select_a_o(selector_A), .ctrl_select_b_o(load_b), .selector_b_o(selector_B), .ctrl_select_c_o(selector_C), .exp_op_o(FSM_exp_operation_A_S), .shift_value_o(FSM_Shift_Value), .rst_int(rst_int), // .ready(ready) ); /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////Selector's registers////////////////////////////// RegisterAdd #(.W(1)) Sel_A ( //Selector_A register .clk(clk), .rst(rst_int), .load(selector_A), .D(1'b1), .Q(FSM_selector_A) ); RegisterAdd #(.W(1)) Sel_C ( //Selector_C register .clk(clk), .rst(rst_int), .load(selector_C), .D(1'b1), .Q(FSM_selector_C) ); RegisterAdd #(.W(2)) Sel_B ( //Selector_B register .clk(clk), .rst(rst_int), .load(load_b), .D(selector_B), .Q(FSM_selector_B) ); /////////////////////////////////////////////////////////////////////////////////////////// First_Phase_M #(.W(W)) Operands_load_reg ( // .clk(clk), //** .rst(rst_int), //** .load(FSM_first_phase_load), //** .Data_MX(Data_MX), //** .Data_MY(Data_MY), //** .Op_MX(Op_MX), .Op_MY(Op_MY) ); Zero_InfMult_Unit #(.W(W)) Zero_Result_Detect ( .clk(clk), .rst(rst_int), .load(FSM_load_first_step), .Data_A(Op_MX [W-2:0]), .Data_B(Op_MY [W-2:0]), .zero_m_flag(zero_flag) ); ///////////Mux exp_operation OPER_A_i////////// Multiplexer_AC #(.W(EW+1)) Exp_Oper_A_mux( .ctrl(FSM_selector_A), .D0 ({1'b0,Op_MX[W-2:W-EW-1]}), .D1 (exp_oper_result), .S (S_Oper_A_exp) ); ///////////Mux exp_operation OPER_B_i////////// wire [EW-1:0] Exp_oper_B_D1, Exp_oper_B_D2; Mux_3x1 #(.W(EW)) Exp_Oper_B_mux( .ctrl(FSM_selector_B), .D0 (Op_MY[W-2:W-EW-1]), .D1 (Exp_oper_B_D1), .D2 (Exp_oper_B_D2), .S(S_Oper_B_exp) ); generate case(EW) 8:begin assign Exp_oper_B_D1 = 8'd127; assign Exp_oper_B_D2 = 8'd1; end default:begin assign Exp_oper_B_D1 = 11'd1023; assign Exp_oper_B_D2 = 11'd1; end endcase endgenerate ///////////exp_operation/////////////////////////// Exp_Operation_m #(.EW(EW)) Exp_module ( .clk(clk), .rst(rst_int), .load_a_i(FSM_load_first_step), .load_b_i(FSM_load_second_step), .load_c_i(FSM_exp_operation_load_result), .Data_A_i(S_Oper_A_exp), .Data_B_i({1'b0,S_Oper_B_exp}), .Add_Subt_i(FSM_exp_operation_A_S), .Data_Result_o(exp_oper_result), .Overflow_flag_o(overflow_flag), .Underflow_flag_o(underflow_flag) ); ////////Sign_operation////////////////////////////// XOR_M Sign_operation ( .Sgn_X(Op_MX[W-1]), .Sgn_Y(Op_MY[W-1]), .Sgn_Info(sign_final_result) ); /////Significant_Operation////////////////////////// Sgf_Multiplication #(.SW(SW+1)) Sgf_operation ( .clk(clk), .rst(rst), .load_b_i(FSM_load_second_step), .Data_A_i({1'b1,Op_MX[SW-1:0]}), .Data_B_i({1'b1,Op_MY[SW-1:0]}), .sgf_result_o(P_Sgf) ); //////////Mux Barrel shifter shift_Value///////////////// assign significand = P_Sgf [2*SW:SW]; assign non_significand = P_Sgf [SW-1:0]; ///////////Mux Barrel shifter Data_in////// Multiplexer_AC #(.W(SW+1)) Barrel_Shifter_D_I_mux( .ctrl(FSM_selector_C), .D0 (significand), .D1 (Add_result), .S (S_Data_Shift) ); ///////////Barrel_Shifter////////////////////////// Barrel_Shifter_M #(.SW(SW+1)) Barrel_Shifter_module ( .clk(clk), .rst(rst_int), .load_i(FSM_barrel_shifter_load), .Shift_Value_i(FSM_Shift_Value), .Shift_Data_i(S_Data_Shift), .N_mant_o(Sgf_normalized_result) ); ////Round decoder///////////////////////////////// Round_decoder_M #(.SW(SW)) Round_Decoder ( .Round_Bits_i(non_significand), .Round_Mode_i(round_mode), .Sign_Result_i(sign_final_result), .Round_Flag_o(FSM_round_flag) ); //rounding_adder wire [SW:0] Add_Sgf_Oper_B; assign Add_Sgf_Oper_B = (SW)*1'b1; Adder_Round #(.SW(SW+1)) Adder_M ( .clk(clk), .rst(rst_int), .load_i(FSM_adder_round_norm_load), .Data_A_i(Sgf_normalized_result), .Data_B_i(Add_Sgf_Oper_B), .Data_Result_o(Add_result), .FSM_C_o(FSM_add_overflow_flag) ); ////Final Result/////////////////////////////// Tenth_Phase #(.W(W),.EW(EW),.SW(SW)) final_result_ieee_Module( .clk(clk), .rst(rst_int), .load_i(FSM_final_result_load), .sel_a_i(overflow_flag), .sel_b_i(underflow_flag), .sign_i(sign_final_result), .exp_ieee_i(exp_oper_result[EW-1:0]), .sgf_ieee_i(Sgf_normalized_result[SW-1:0]), .final_result_ieee_o(final_result_ieee) ); endmodule
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 22:36:46 09/06/2015 // Design Name: // Module Name: FPU_Multiplication_Function // Project Name: // Target Devices: // Tool versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module FPU_Multiplication_Function //SINGLE PRECISION PARAMETERS /*# (parameter W = 32, parameter EW = 8, parameter SW = 23) // */ //DOUBLE PRECISION PARAMETERS # (parameter W = 64, parameter EW = 11, parameter SW = 52) // */ ( input wire clk, input wire rst, input wire beg_FSM, input wire ack_FSM, input wire [W-1:0] Data_MX, input wire [W-1:0] Data_MY, input wire [1:0] round_mode, output wire overflow_flag, output wire underflow_flag, output wire ready, output wire [W-1:0] final_result_ieee ); //GENERAL wire rst_int; //** //FSM_load_signals wire FSM_first_phase_load; //** wire FSM_load_first_step; /*Zero flag, Exp operation underflow, Sgf operation first reg, sign result reg*/ wire FSM_exp_operation_load_result; //Exp operation result, wire FSM_load_second_step; //Exp operation Overflow, Sgf operation second reg wire FSM_barrel_shifter_load; wire FSM_adder_round_norm_load; wire FSM_final_result_load; //ZERO FLAG //Op_MX; //Op_MY wire zero_flag; //FIRST PHASE wire [W-1:0] Op_MX; wire [W-1:0] Op_MY; //Mux S-> exp_operation OPER_A_i////////// wire FSM_selector_A; //D0=Op_MX[W-2:W-EW-1] //D1=exp_oper_result wire [EW:0] S_Oper_A_exp; //Mux S-> exp_operation OPER_B_i////////// wire [1:0] FSM_selector_B; //D0=Op_MY[W-2:W-EW-1] //D1=LZA_output //D2=1 wire [EW-1:0] S_Oper_B_exp; ///////////exp_operation/////////////////////////// wire FSM_exp_operation_A_S; //oper_A= S_Oper_A_exp //oper_B= S_Oper_B_exp wire [EW:0] exp_oper_result; //Sgf operation////////////////// //Op_A={1'b1, Op_MX[SW-1:0]} //Op_B={1'b1, Op_MY[SW-1:0]} wire [2*SW+1:0] P_Sgf; wire[SW:0] significand; wire[SW:0] non_significand; //Sign Operation wire sign_final_result; //barrel shifter multiplexers wire [SW:0] S_Data_Shift; //barrel shifter wire [SW:0] Sgf_normalized_result; //adder rounding wire FSM_add_overflow_flag; //Oper_A_i=norm result //Oper_B_i=1 wire [SW:0] Add_result; //round decoder wire FSM_round_flag; //Selecto moltiplexers wire selector_A; wire [1:0] selector_B; wire load_b; wire selector_C; //Barrel shifter multiplexer /////////////////////////////////////////FSM//////////////////////////////////////////// FSM_Mult_Function FS_Module ( .clk(clk), //** .rst(rst), //** .beg_FSM(beg_FSM), //** .ack_FSM(ack_FSM), //** .zero_flag_i(zero_flag), .Mult_shift_i(P_Sgf[2*SW+1]), .round_flag_i(FSM_round_flag), .Add_Overflow_i(FSM_add_overflow_flag), .load_0_o(FSM_first_phase_load), .load_1_o(FSM_load_first_step), .load_2_o(FSM_exp_operation_load_result), .load_3_o(FSM_load_second_step), .load_4_o(FSM_adder_round_norm_load), .load_5_o(FSM_final_result_load), .load_6_o(FSM_barrel_shifter_load), .ctrl_select_a_o(selector_A), .ctrl_select_b_o(load_b), .selector_b_o(selector_B), .ctrl_select_c_o(selector_C), .exp_op_o(FSM_exp_operation_A_S), .shift_value_o(FSM_Shift_Value), .rst_int(rst_int), // .ready(ready) ); /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////Selector's registers////////////////////////////// RegisterAdd #(.W(1)) Sel_A ( //Selector_A register .clk(clk), .rst(rst_int), .load(selector_A), .D(1'b1), .Q(FSM_selector_A) ); RegisterAdd #(.W(1)) Sel_C ( //Selector_C register .clk(clk), .rst(rst_int), .load(selector_C), .D(1'b1), .Q(FSM_selector_C) ); RegisterAdd #(.W(2)) Sel_B ( //Selector_B register .clk(clk), .rst(rst_int), .load(load_b), .D(selector_B), .Q(FSM_selector_B) ); /////////////////////////////////////////////////////////////////////////////////////////// First_Phase_M #(.W(W)) Operands_load_reg ( // .clk(clk), //** .rst(rst_int), //** .load(FSM_first_phase_load), //** .Data_MX(Data_MX), //** .Data_MY(Data_MY), //** .Op_MX(Op_MX), .Op_MY(Op_MY) ); Zero_InfMult_Unit #(.W(W)) Zero_Result_Detect ( .clk(clk), .rst(rst_int), .load(FSM_load_first_step), .Data_A(Op_MX [W-2:0]), .Data_B(Op_MY [W-2:0]), .zero_m_flag(zero_flag) ); ///////////Mux exp_operation OPER_A_i////////// Multiplexer_AC #(.W(EW+1)) Exp_Oper_A_mux( .ctrl(FSM_selector_A), .D0 ({1'b0,Op_MX[W-2:W-EW-1]}), .D1 (exp_oper_result), .S (S_Oper_A_exp) ); ///////////Mux exp_operation OPER_B_i////////// wire [EW-1:0] Exp_oper_B_D1, Exp_oper_B_D2; Mux_3x1 #(.W(EW)) Exp_Oper_B_mux( .ctrl(FSM_selector_B), .D0 (Op_MY[W-2:W-EW-1]), .D1 (Exp_oper_B_D1), .D2 (Exp_oper_B_D2), .S(S_Oper_B_exp) ); generate case(EW) 8:begin assign Exp_oper_B_D1 = 8'd127; assign Exp_oper_B_D2 = 8'd1; end default:begin assign Exp_oper_B_D1 = 11'd1023; assign Exp_oper_B_D2 = 11'd1; end endcase endgenerate ///////////exp_operation/////////////////////////// Exp_Operation_m #(.EW(EW)) Exp_module ( .clk(clk), .rst(rst_int), .load_a_i(FSM_load_first_step), .load_b_i(FSM_load_second_step), .load_c_i(FSM_exp_operation_load_result), .Data_A_i(S_Oper_A_exp), .Data_B_i({1'b0,S_Oper_B_exp}), .Add_Subt_i(FSM_exp_operation_A_S), .Data_Result_o(exp_oper_result), .Overflow_flag_o(overflow_flag), .Underflow_flag_o(underflow_flag) ); ////////Sign_operation////////////////////////////// XOR_M Sign_operation ( .Sgn_X(Op_MX[W-1]), .Sgn_Y(Op_MY[W-1]), .Sgn_Info(sign_final_result) ); /////Significant_Operation////////////////////////// Sgf_Multiplication #(.SW(SW+1)) Sgf_operation ( .clk(clk), .rst(rst), .load_b_i(FSM_load_second_step), .Data_A_i({1'b1,Op_MX[SW-1:0]}), .Data_B_i({1'b1,Op_MY[SW-1:0]}), .sgf_result_o(P_Sgf) ); //////////Mux Barrel shifter shift_Value///////////////// assign significand = P_Sgf [2*SW:SW]; assign non_significand = P_Sgf [SW-1:0]; ///////////Mux Barrel shifter Data_in////// Multiplexer_AC #(.W(SW+1)) Barrel_Shifter_D_I_mux( .ctrl(FSM_selector_C), .D0 (significand), .D1 (Add_result), .S (S_Data_Shift) ); ///////////Barrel_Shifter////////////////////////// Barrel_Shifter_M #(.SW(SW+1)) Barrel_Shifter_module ( .clk(clk), .rst(rst_int), .load_i(FSM_barrel_shifter_load), .Shift_Value_i(FSM_Shift_Value), .Shift_Data_i(S_Data_Shift), .N_mant_o(Sgf_normalized_result) ); ////Round decoder///////////////////////////////// Round_decoder_M #(.SW(SW)) Round_Decoder ( .Round_Bits_i(non_significand), .Round_Mode_i(round_mode), .Sign_Result_i(sign_final_result), .Round_Flag_o(FSM_round_flag) ); //rounding_adder wire [SW:0] Add_Sgf_Oper_B; assign Add_Sgf_Oper_B = (SW)*1'b1; Adder_Round #(.SW(SW+1)) Adder_M ( .clk(clk), .rst(rst_int), .load_i(FSM_adder_round_norm_load), .Data_A_i(Sgf_normalized_result), .Data_B_i(Add_Sgf_Oper_B), .Data_Result_o(Add_result), .FSM_C_o(FSM_add_overflow_flag) ); ////Final Result/////////////////////////////// Tenth_Phase #(.W(W),.EW(EW),.SW(SW)) final_result_ieee_Module( .clk(clk), .rst(rst_int), .load_i(FSM_final_result_load), .sel_a_i(overflow_flag), .sel_b_i(underflow_flag), .sign_i(sign_final_result), .exp_ieee_i(exp_oper_result[EW-1:0]), .sgf_ieee_i(Sgf_normalized_result[SW-1:0]), .final_result_ieee_o(final_result_ieee) ); endmodule
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 22:36:46 09/06/2015 // Design Name: // Module Name: FPU_Multiplication_Function // Project Name: // Target Devices: // Tool versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module FPU_Multiplication_Function //SINGLE PRECISION PARAMETERS /*# (parameter W = 32, parameter EW = 8, parameter SW = 23) // */ //DOUBLE PRECISION PARAMETERS # (parameter W = 64, parameter EW = 11, parameter SW = 52) // */ ( input wire clk, input wire rst, input wire beg_FSM, input wire ack_FSM, input wire [W-1:0] Data_MX, input wire [W-1:0] Data_MY, input wire [1:0] round_mode, output wire overflow_flag, output wire underflow_flag, output wire ready, output wire [W-1:0] final_result_ieee ); //GENERAL wire rst_int; //** //FSM_load_signals wire FSM_first_phase_load; //** wire FSM_load_first_step; /*Zero flag, Exp operation underflow, Sgf operation first reg, sign result reg*/ wire FSM_exp_operation_load_result; //Exp operation result, wire FSM_load_second_step; //Exp operation Overflow, Sgf operation second reg wire FSM_barrel_shifter_load; wire FSM_adder_round_norm_load; wire FSM_final_result_load; //ZERO FLAG //Op_MX; //Op_MY wire zero_flag; //FIRST PHASE wire [W-1:0] Op_MX; wire [W-1:0] Op_MY; //Mux S-> exp_operation OPER_A_i////////// wire FSM_selector_A; //D0=Op_MX[W-2:W-EW-1] //D1=exp_oper_result wire [EW:0] S_Oper_A_exp; //Mux S-> exp_operation OPER_B_i////////// wire [1:0] FSM_selector_B; //D0=Op_MY[W-2:W-EW-1] //D1=LZA_output //D2=1 wire [EW-1:0] S_Oper_B_exp; ///////////exp_operation/////////////////////////// wire FSM_exp_operation_A_S; //oper_A= S_Oper_A_exp //oper_B= S_Oper_B_exp wire [EW:0] exp_oper_result; //Sgf operation////////////////// //Op_A={1'b1, Op_MX[SW-1:0]} //Op_B={1'b1, Op_MY[SW-1:0]} wire [2*SW+1:0] P_Sgf; wire[SW:0] significand; wire[SW:0] non_significand; //Sign Operation wire sign_final_result; //barrel shifter multiplexers wire [SW:0] S_Data_Shift; //barrel shifter wire [SW:0] Sgf_normalized_result; //adder rounding wire FSM_add_overflow_flag; //Oper_A_i=norm result //Oper_B_i=1 wire [SW:0] Add_result; //round decoder wire FSM_round_flag; //Selecto moltiplexers wire selector_A; wire [1:0] selector_B; wire load_b; wire selector_C; //Barrel shifter multiplexer /////////////////////////////////////////FSM//////////////////////////////////////////// FSM_Mult_Function FS_Module ( .clk(clk), //** .rst(rst), //** .beg_FSM(beg_FSM), //** .ack_FSM(ack_FSM), //** .zero_flag_i(zero_flag), .Mult_shift_i(P_Sgf[2*SW+1]), .round_flag_i(FSM_round_flag), .Add_Overflow_i(FSM_add_overflow_flag), .load_0_o(FSM_first_phase_load), .load_1_o(FSM_load_first_step), .load_2_o(FSM_exp_operation_load_result), .load_3_o(FSM_load_second_step), .load_4_o(FSM_adder_round_norm_load), .load_5_o(FSM_final_result_load), .load_6_o(FSM_barrel_shifter_load), .ctrl_select_a_o(selector_A), .ctrl_select_b_o(load_b), .selector_b_o(selector_B), .ctrl_select_c_o(selector_C), .exp_op_o(FSM_exp_operation_A_S), .shift_value_o(FSM_Shift_Value), .rst_int(rst_int), // .ready(ready) ); /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////Selector's registers////////////////////////////// RegisterAdd #(.W(1)) Sel_A ( //Selector_A register .clk(clk), .rst(rst_int), .load(selector_A), .D(1'b1), .Q(FSM_selector_A) ); RegisterAdd #(.W(1)) Sel_C ( //Selector_C register .clk(clk), .rst(rst_int), .load(selector_C), .D(1'b1), .Q(FSM_selector_C) ); RegisterAdd #(.W(2)) Sel_B ( //Selector_B register .clk(clk), .rst(rst_int), .load(load_b), .D(selector_B), .Q(FSM_selector_B) ); /////////////////////////////////////////////////////////////////////////////////////////// First_Phase_M #(.W(W)) Operands_load_reg ( // .clk(clk), //** .rst(rst_int), //** .load(FSM_first_phase_load), //** .Data_MX(Data_MX), //** .Data_MY(Data_MY), //** .Op_MX(Op_MX), .Op_MY(Op_MY) ); Zero_InfMult_Unit #(.W(W)) Zero_Result_Detect ( .clk(clk), .rst(rst_int), .load(FSM_load_first_step), .Data_A(Op_MX [W-2:0]), .Data_B(Op_MY [W-2:0]), .zero_m_flag(zero_flag) ); ///////////Mux exp_operation OPER_A_i////////// Multiplexer_AC #(.W(EW+1)) Exp_Oper_A_mux( .ctrl(FSM_selector_A), .D0 ({1'b0,Op_MX[W-2:W-EW-1]}), .D1 (exp_oper_result), .S (S_Oper_A_exp) ); ///////////Mux exp_operation OPER_B_i////////// wire [EW-1:0] Exp_oper_B_D1, Exp_oper_B_D2; Mux_3x1 #(.W(EW)) Exp_Oper_B_mux( .ctrl(FSM_selector_B), .D0 (Op_MY[W-2:W-EW-1]), .D1 (Exp_oper_B_D1), .D2 (Exp_oper_B_D2), .S(S_Oper_B_exp) ); generate case(EW) 8:begin assign Exp_oper_B_D1 = 8'd127; assign Exp_oper_B_D2 = 8'd1; end default:begin assign Exp_oper_B_D1 = 11'd1023; assign Exp_oper_B_D2 = 11'd1; end endcase endgenerate ///////////exp_operation/////////////////////////// Exp_Operation_m #(.EW(EW)) Exp_module ( .clk(clk), .rst(rst_int), .load_a_i(FSM_load_first_step), .load_b_i(FSM_load_second_step), .load_c_i(FSM_exp_operation_load_result), .Data_A_i(S_Oper_A_exp), .Data_B_i({1'b0,S_Oper_B_exp}), .Add_Subt_i(FSM_exp_operation_A_S), .Data_Result_o(exp_oper_result), .Overflow_flag_o(overflow_flag), .Underflow_flag_o(underflow_flag) ); ////////Sign_operation////////////////////////////// XOR_M Sign_operation ( .Sgn_X(Op_MX[W-1]), .Sgn_Y(Op_MY[W-1]), .Sgn_Info(sign_final_result) ); /////Significant_Operation////////////////////////// Sgf_Multiplication #(.SW(SW+1)) Sgf_operation ( .clk(clk), .rst(rst), .load_b_i(FSM_load_second_step), .Data_A_i({1'b1,Op_MX[SW-1:0]}), .Data_B_i({1'b1,Op_MY[SW-1:0]}), .sgf_result_o(P_Sgf) ); //////////Mux Barrel shifter shift_Value///////////////// assign significand = P_Sgf [2*SW:SW]; assign non_significand = P_Sgf [SW-1:0]; ///////////Mux Barrel shifter Data_in////// Multiplexer_AC #(.W(SW+1)) Barrel_Shifter_D_I_mux( .ctrl(FSM_selector_C), .D0 (significand), .D1 (Add_result), .S (S_Data_Shift) ); ///////////Barrel_Shifter////////////////////////// Barrel_Shifter_M #(.SW(SW+1)) Barrel_Shifter_module ( .clk(clk), .rst(rst_int), .load_i(FSM_barrel_shifter_load), .Shift_Value_i(FSM_Shift_Value), .Shift_Data_i(S_Data_Shift), .N_mant_o(Sgf_normalized_result) ); ////Round decoder///////////////////////////////// Round_decoder_M #(.SW(SW)) Round_Decoder ( .Round_Bits_i(non_significand), .Round_Mode_i(round_mode), .Sign_Result_i(sign_final_result), .Round_Flag_o(FSM_round_flag) ); //rounding_adder wire [SW:0] Add_Sgf_Oper_B; assign Add_Sgf_Oper_B = (SW)*1'b1; Adder_Round #(.SW(SW+1)) Adder_M ( .clk(clk), .rst(rst_int), .load_i(FSM_adder_round_norm_load), .Data_A_i(Sgf_normalized_result), .Data_B_i(Add_Sgf_Oper_B), .Data_Result_o(Add_result), .FSM_C_o(FSM_add_overflow_flag) ); ////Final Result/////////////////////////////// Tenth_Phase #(.W(W),.EW(EW),.SW(SW)) final_result_ieee_Module( .clk(clk), .rst(rst_int), .load_i(FSM_final_result_load), .sel_a_i(overflow_flag), .sel_b_i(underflow_flag), .sign_i(sign_final_result), .exp_ieee_i(exp_oper_result[EW-1:0]), .sgf_ieee_i(Sgf_normalized_result[SW-1:0]), .final_result_ieee_o(final_result_ieee) ); endmodule
// megafunction wizard: %ALTMULT_ADD% // GENERATION: STANDARD // VERSION: WM1.0 // MODULE: ALTMULT_ADD // ============================================================ // File Name: sv_mult27.v // Megafunction Name(s): // ALTMULT_ADD // // Simulation Library Files(s): // altera_lnsim // ============================================================ // ************************************************************ // THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! // // 12.1 Build 177 11/07/2012 SJ Full Version // ************************************************************ //Copyright (C) 1991-2012 Altera Corporation //Your use of Altera Corporation's design tools, logic functions //and other software and tools, and its AMPP partner logic //functions, and any output files from any of the foregoing //(including device programming or simulation files), and any //associated documentation or information are expressly subject //to the terms and conditions of the Altera Program License //Subscription Agreement, Altera MegaCore Function License //Agreement, or other applicable license agreement, including, //without limitation, that your use is for the sole purpose of //programming logic devices manufactured by Altera and sold by //Altera or its authorized distributors. Please refer to the //applicable agreement for further details. //altmult_add ACCUM_SLOAD_REGISTER="UNREGISTERED" ADDNSUB_MULTIPLIER_PIPELINE_REGISTER1="UNREGISTERED" ADDNSUB_MULTIPLIER_REGISTER1="CLOCK0" CBX_AUTO_BLACKBOX="ALL" COEF0_0=0 COEF0_1=0 COEF0_2=0 COEF0_3=0 COEF0_4=0 COEF0_5=0 COEF0_6=0 COEF0_7=0 COEF1_0=0 COEF1_1=0 COEF1_2=0 COEF1_3=0 COEF1_4=0 COEF1_5=0 COEF1_6=0 COEF1_7=0 COEF2_0=0 COEF2_1=0 COEF2_2=0 COEF2_3=0 COEF2_4=0 COEF2_5=0 COEF2_6=0 COEF2_7=0 COEF3_0=0 COEF3_1=0 COEF3_2=0 COEF3_3=0 COEF3_4=0 COEF3_5=0 COEF3_6=0 COEF3_7=0 COEFSEL0_REGISTER="UNREGISTERED" DEDICATED_MULTIPLIER_CIRCUITRY="AUTO" DEVICE_FAMILY="Stratix V" INPUT_REGISTER_A0="CLOCK0" INPUT_REGISTER_B0="CLOCK0" INPUT_REGISTER_C0="UNREGISTERED" INPUT_SOURCE_A0="DATAA" INPUT_SOURCE_B0="DATAB" LOADCONST_VALUE=64 MULTIPLIER1_DIRECTION="ADD" MULTIPLIER_REGISTER0="UNREGISTERED" NUMBER_OF_MULTIPLIERS=1 OUTPUT_REGISTER="CLOCK0" port_addnsub1="PORT_UNUSED" port_signa="PORT_UNUSED" port_signb="PORT_UNUSED" PREADDER_DIRECTION_0="ADD" PREADDER_DIRECTION_1="ADD" PREADDER_DIRECTION_2="ADD" PREADDER_DIRECTION_3="ADD" PREADDER_MODE="SIMPLE" REPRESENTATION_A="UNSIGNED" REPRESENTATION_B="UNSIGNED" SIGNED_PIPELINE_REGISTER_A="UNREGISTERED" SIGNED_PIPELINE_REGISTER_B="UNREGISTERED" SIGNED_REGISTER_A="CLOCK0" SIGNED_REGISTER_B="CLOCK0" SYSTOLIC_DELAY1="UNREGISTERED" SYSTOLIC_DELAY3="UNREGISTERED" WIDTH_A=27 WIDTH_B=27 WIDTH_RESULT=54 clock0 dataa datab result //VERSION_BEGIN 12.1 cbx_alt_ded_mult_y 2012:11:07:18:03:20:SJ cbx_altera_mult_add 2012:11:07:18:03:20:SJ cbx_altmult_add 2012:11:07:18:03:20:SJ cbx_cycloneii 2012:11:07:18:03:20:SJ cbx_lpm_add_sub 2012:11:07:18:03:20:SJ cbx_lpm_mult 2012:11:07:18:03:20:SJ cbx_mgl 2012:11:07:18:50:05:SJ cbx_padd 2012:11:07:18:03:20:SJ cbx_parallel_add 2012:11:07:18:03:20:SJ cbx_stratix 2012:11:07:18:03:20:SJ cbx_stratixii 2012:11:07:18:03:20:SJ cbx_util_mgl 2012:11:07:18:03:20:SJ VERSION_END // synthesis VERILOG_INPUT_VERSION VERILOG_2001 // altera message_off 10463 //synthesis_resources = altera_mult_add 1 dsp_mac 1 //synopsys translate_off `timescale 1 ps / 1 ps //synopsys translate_on module sv_mult27_mult_add_cfq3 ( clock0, ena0, dataa, datab, result) ; input clock0; input ena0; input [26:0] dataa; input [26:0] datab; output [53:0] result; `ifndef ALTERA_RESERVED_QIS // synopsys translate_off `endif tri1 clock0; tri0 [26:0] dataa; tri0 [26:0] datab; `ifndef ALTERA_RESERVED_QIS // synopsys translate_on `endif wire [53:0] wire_altera_mult_add1_result; wire ena1; wire ena2; wire ena3; altera_mult_add altera_mult_add1 ( .chainout_sat_overflow(), .clock0(clock0), .dataa(dataa), .datab(datab), .ena0(ena0), .ena1(ena1), .ena2(ena2), .ena3(ena3), .mult0_is_saturated(), .mult1_is_saturated(), .mult2_is_saturated(), .mult3_is_saturated(), .overflow(), .result(wire_altera_mult_add1_result), .scanouta(), .scanoutb(), .accum_sload(1'b0), .aclr0(1'b0), .aclr1(1'b0), .aclr2(1'b0), .aclr3(1'b0), .addnsub1(1'b1), .addnsub1_round(1'b0), .addnsub3(1'b1), .addnsub3_round(1'b0), .chainin({1{1'b0}}), .chainout_round(1'b0), .chainout_saturate(1'b0), .clock1(1'b1), .clock2(1'b1), .clock3(1'b1), .coefsel0({3{1'b0}}), .coefsel1({3{1'b0}}), .coefsel2({3{1'b0}}), .coefsel3({3{1'b0}}), .datac({22{1'b0}}), .mult01_round(1'b0), .mult01_saturation(1'b0), .mult23_round(1'b0), .mult23_saturation(1'b0), .output_round(1'b0), .output_saturate(1'b0), .rotate(1'b0), .scanina({27{1'b0}}), .scaninb({27{1'b0}}), .shift_right(1'b0), .signa(1'b0), .signb(1'b0), .sourcea({1{1'b0}}), .sourceb({1{1'b0}}), .zero_chainout(1'b0), .zero_loopback(1'b0) ); defparam altera_mult_add1.accum_direction = "ADD", altera_mult_add1.accum_sload_aclr = "ACLR0", altera_mult_add1.accum_sload_pipeline_aclr = "ACLR0", altera_mult_add1.accum_sload_pipeline_register = "CLOCK0", altera_mult_add1.accum_sload_register = "UNREGISTERED", altera_mult_add1.accumulator = "NO", altera_mult_add1.adder1_rounding = "NO", altera_mult_add1.adder3_rounding = "NO", altera_mult_add1.addnsub1_round_aclr = "ACLR0", altera_mult_add1.addnsub1_round_pipeline_aclr = "ACLR0", altera_mult_add1.addnsub1_round_pipeline_register = "CLOCK0", altera_mult_add1.addnsub1_round_register = "CLOCK0", altera_mult_add1.addnsub3_round_aclr = "ACLR0", altera_mult_add1.addnsub3_round_pipeline_aclr = "ACLR0", altera_mult_add1.addnsub3_round_pipeline_register = "CLOCK0", altera_mult_add1.addnsub3_round_register = "CLOCK0", altera_mult_add1.addnsub_multiplier_aclr1 = "ACLR0", altera_mult_add1.addnsub_multiplier_aclr3 = "ACLR0", altera_mult_add1.addnsub_multiplier_pipeline_aclr1 = "ACLR0", altera_mult_add1.addnsub_multiplier_pipeline_aclr3 = "ACLR0", altera_mult_add1.addnsub_multiplier_pipeline_register1 = "UNREGISTERED", altera_mult_add1.addnsub_multiplier_pipeline_register3 = "CLOCK0", altera_mult_add1.addnsub_multiplier_register1 = "CLOCK0", altera_mult_add1.addnsub_multiplier_register3 = "CLOCK0", altera_mult_add1.chainout_aclr = "ACLR0", altera_mult_add1.chainout_adder = "NO", altera_mult_add1.chainout_register = "CLOCK0", altera_mult_add1.chainout_round_aclr = "ACLR0", altera_mult_add1.chainout_round_output_aclr = "ACLR0", altera_mult_add1.chainout_round_output_register = "CLOCK0", altera_mult_add1.chainout_round_pipeline_aclr = "ACLR0", altera_mult_add1.chainout_round_pipeline_register = "CLOCK0", altera_mult_add1.chainout_round_register = "CLOCK0", altera_mult_add1.chainout_rounding = "NO", altera_mult_add1.chainout_saturate_aclr = "ACLR0", altera_mult_add1.chainout_saturate_output_aclr = "ACLR0", altera_mult_add1.chainout_saturate_output_register = "CLOCK0", altera_mult_add1.chainout_saturate_pipeline_aclr = "ACLR0", altera_mult_add1.chainout_saturate_pipeline_register = "CLOCK0", altera_mult_add1.chainout_saturate_register = "CLOCK0", altera_mult_add1.chainout_saturation = "NO", altera_mult_add1.coef0_0 = 0, altera_mult_add1.coef0_1 = 0, altera_mult_add1.coef0_2 = 0, altera_mult_add1.coef0_3 = 0, altera_mult_add1.coef0_4 = 0, altera_mult_add1.coef0_5 = 0, altera_mult_add1.coef0_6 = 0, altera_mult_add1.coef0_7 = 0, altera_mult_add1.coef1_0 = 0, altera_mult_add1.coef1_1 = 0, altera_mult_add1.coef1_2 = 0, altera_mult_add1.coef1_3 = 0, altera_mult_add1.coef1_4 = 0, altera_mult_add1.coef1_5 = 0, altera_mult_add1.coef1_6 = 0, altera_mult_add1.coef1_7 = 0, altera_mult_add1.coef2_0 = 0, altera_mult_add1.coef2_1 = 0, altera_mult_add1.coef2_2 = 0, altera_mult_add1.coef2_3 = 0, altera_mult_add1.coef2_4 = 0, altera_mult_add1.coef2_5 = 0, altera_mult_add1.coef2_6 = 0, altera_mult_add1.coef2_7 = 0, altera_mult_add1.coef3_0 = 0, altera_mult_add1.coef3_1 = 0, altera_mult_add1.coef3_2 = 0, altera_mult_add1.coef3_3 = 0, altera_mult_add1.coef3_4 = 0, altera_mult_add1.coef3_5 = 0, altera_mult_add1.coef3_6 = 0, altera_mult_add1.coef3_7 = 0, altera_mult_add1.coefsel0_aclr = "ACLR0", altera_mult_add1.coefsel0_register = "UNREGISTERED", altera_mult_add1.coefsel1_aclr = "ACLR0", altera_mult_add1.coefsel1_register = "CLOCK0", altera_mult_add1.coefsel2_aclr = "ACLR0", altera_mult_add1.coefsel2_register = "CLOCK0", altera_mult_add1.coefsel3_aclr = "ACLR0", altera_mult_add1.coefsel3_register = "CLOCK0", altera_mult_add1.dedicated_multiplier_circuitry = "AUTO", altera_mult_add1.double_accum = "NO", altera_mult_add1.dsp_block_balancing = "Auto", altera_mult_add1.extra_latency = 0, altera_mult_add1.input_aclr_a0 = "ACLR0", altera_mult_add1.input_aclr_a1 = "ACLR0", altera_mult_add1.input_aclr_a2 = "ACLR0", altera_mult_add1.input_aclr_a3 = "ACLR0", altera_mult_add1.input_aclr_b0 = "ACLR0", altera_mult_add1.input_aclr_b1 = "ACLR0", altera_mult_add1.input_aclr_b2 = "ACLR0", altera_mult_add1.input_aclr_b3 = "ACLR0", altera_mult_add1.input_aclr_c0 = "ACLR0", altera_mult_add1.input_aclr_c1 = "ACLR0", altera_mult_add1.input_aclr_c2 = "ACLR0", altera_mult_add1.input_aclr_c3 = "ACLR0", altera_mult_add1.input_register_a0 = "CLOCK0", altera_mult_add1.input_register_a1 = "CLOCK0", altera_mult_add1.input_register_a2 = "CLOCK0", altera_mult_add1.input_register_a3 = "CLOCK0", altera_mult_add1.input_register_b0 = "CLOCK0", altera_mult_add1.input_register_b1 = "CLOCK0", altera_mult_add1.input_register_b2 = "CLOCK0", altera_mult_add1.input_register_b3 = "CLOCK0", altera_mult_add1.input_register_c0 = "UNREGISTERED", altera_mult_add1.input_register_c1 = "CLOCK0", altera_mult_add1.input_register_c2 = "CLOCK0", altera_mult_add1.input_register_c3 = "CLOCK0", altera_mult_add1.input_source_a0 = "DATAA", altera_mult_add1.input_source_a1 = "DATAA", altera_mult_add1.input_source_a2 = "DATAA", altera_mult_add1.input_source_a3 = "DATAA", altera_mult_add1.input_source_b0 = "DATAB", altera_mult_add1.input_source_b1 = "DATAB", altera_mult_add1.input_source_b2 = "DATAB", altera_mult_add1.input_source_b3 = "DATAB", altera_mult_add1.loadconst_control_aclr = "ACLR0", altera_mult_add1.loadconst_control_register = "CLOCK0", altera_mult_add1.loadconst_value = 64, altera_mult_add1.mult01_round_aclr = "ACLR0", altera_mult_add1.mult01_round_register = "CLOCK0", altera_mult_add1.mult01_saturation_aclr = "ACLR1", altera_mult_add1.mult01_saturation_register = "CLOCK0", altera_mult_add1.mult23_round_aclr = "ACLR0", altera_mult_add1.mult23_round_register = "CLOCK0", altera_mult_add1.mult23_saturation_aclr = "ACLR0", altera_mult_add1.mult23_saturation_register = "CLOCK0", altera_mult_add1.multiplier01_rounding = "NO", altera_mult_add1.multiplier01_saturation = "NO", altera_mult_add1.multiplier1_direction = "ADD", altera_mult_add1.multiplier23_rounding = "NO", altera_mult_add1.multiplier23_saturation = "NO", altera_mult_add1.multiplier3_direction = "ADD", altera_mult_add1.multiplier_aclr0 = "ACLR0", altera_mult_add1.multiplier_aclr1 = "ACLR0", altera_mult_add1.multiplier_aclr2 = "ACLR0", altera_mult_add1.multiplier_aclr3 = "ACLR0", altera_mult_add1.multiplier_register0 = "UNREGISTERED", altera_mult_add1.multiplier_register1 = "CLOCK0", altera_mult_add1.multiplier_register2 = "CLOCK0", altera_mult_add1.multiplier_register3 = "CLOCK0", altera_mult_add1.number_of_multipliers = 1, altera_mult_add1.output_aclr = "ACLR0", altera_mult_add1.output_register = "CLOCK0", altera_mult_add1.output_round_aclr = "ACLR0", altera_mult_add1.output_round_pipeline_aclr = "ACLR0", altera_mult_add1.output_round_pipeline_register = "CLOCK0", altera_mult_add1.output_round_register = "CLOCK0", altera_mult_add1.output_round_type = "NEAREST_INTEGER", altera_mult_add1.output_rounding = "NO", altera_mult_add1.output_saturate_aclr = "ACLR0", altera_mult_add1.output_saturate_pipeline_aclr = "ACLR0", altera_mult_add1.output_saturate_pipeline_register = "CLOCK0", altera_mult_add1.output_saturate_register = "CLOCK0", altera_mult_add1.output_saturate_type = "ASYMMETRIC", altera_mult_add1.output_saturation = "NO", altera_mult_add1.port_addnsub1 = "PORT_UNUSED", altera_mult_add1.port_addnsub3 = "PORT_UNUSED", altera_mult_add1.port_chainout_sat_is_overflow = "PORT_UNUSED", altera_mult_add1.port_output_is_overflow = "PORT_UNUSED", altera_mult_add1.port_signa = "PORT_UNUSED", altera_mult_add1.port_signb = "PORT_UNUSED", altera_mult_add1.preadder_direction_0 = "ADD", altera_mult_add1.preadder_direction_1 = "ADD", altera_mult_add1.preadder_direction_2 = "ADD", altera_mult_add1.preadder_direction_3 = "ADD", altera_mult_add1.preadder_mode = "SIMPLE", altera_mult_add1.representation_a = "UNSIGNED", altera_mult_add1.representation_b = "UNSIGNED", altera_mult_add1.rotate_aclr = "ACLR0", altera_mult_add1.rotate_output_aclr = "ACLR0", altera_mult_add1.rotate_output_register = "CLOCK0", altera_mult_add1.rotate_pipeline_aclr = "ACLR0", altera_mult_add1.rotate_pipeline_register = "CLOCK0", altera_mult_add1.rotate_register = "CLOCK0", altera_mult_add1.scanouta_aclr = "ACLR0", altera_mult_add1.scanouta_register = "UNREGISTERED", altera_mult_add1.selected_device_family = "Stratix V", altera_mult_add1.shift_mode = "NO", altera_mult_add1.shift_right_aclr = "ACLR0", altera_mult_add1.shift_right_output_aclr = "ACLR0", altera_mult_add1.shift_right_output_register = "CLOCK0", altera_mult_add1.shift_right_pipeline_aclr = "ACLR0", altera_mult_add1.shift_right_pipeline_register = "CLOCK0", altera_mult_add1.shift_right_register = "CLOCK0", altera_mult_add1.signed_aclr_a = "ACLR0", altera_mult_add1.signed_aclr_b = "ACLR0", altera_mult_add1.signed_pipeline_aclr_a = "ACLR0", altera_mult_add1.signed_pipeline_aclr_b = "ACLR0", altera_mult_add1.signed_pipeline_register_a = "UNREGISTERED", altera_mult_add1.signed_pipeline_register_b = "UNREGISTERED", altera_mult_add1.signed_register_a = "CLOCK0", altera_mult_add1.signed_register_b = "CLOCK0", altera_mult_add1.systolic_aclr1 = "ACLR0", altera_mult_add1.systolic_aclr3 = "ACLR0", altera_mult_add1.systolic_delay1 = "UNREGISTERED", altera_mult_add1.systolic_delay3 = "UNREGISTERED", altera_mult_add1.width_a = 27, altera_mult_add1.width_b = 27, altera_mult_add1.width_c = 22, altera_mult_add1.width_chainin = 1, altera_mult_add1.width_coef = 18, altera_mult_add1.width_msb = 17, altera_mult_add1.width_result = 54, altera_mult_add1.width_saturate_sign = 1, altera_mult_add1.zero_chainout_output_aclr = "ACLR0", altera_mult_add1.zero_chainout_output_register = "CLOCK0", altera_mult_add1.zero_loopback_aclr = "ACLR0", altera_mult_add1.zero_loopback_output_aclr = "ACLR0", altera_mult_add1.zero_loopback_output_register = "CLOCK0", altera_mult_add1.zero_loopback_pipeline_aclr = "ACLR0", altera_mult_add1.zero_loopback_pipeline_register = "CLOCK0", altera_mult_add1.zero_loopback_register = "CLOCK0", altera_mult_add1.lpm_type = "altera_mult_add"; assign ena1 = 1'b1, ena2 = 1'b1, ena3 = 1'b1, result = wire_altera_mult_add1_result; endmodule //sv_mult27_mult_add_cfq3 //VALID FILE // synopsys translate_off `timescale 1 ps / 1 ps // synopsys translate_on module sv_mult27 ( clock0, ena0, dataa_0, datab_0, result); input clock0; input ena0; input [26:0] dataa_0; input [26:0] datab_0; output [53:0] result; `ifndef ALTERA_RESERVED_QIS // synopsys translate_off `endif tri1 clock0; tri0 [26:0] dataa_0; tri0 [26:0] datab_0; `ifndef ALTERA_RESERVED_QIS // synopsys translate_on `endif wire [53:0] sub_wire0; wire [53:0] result = sub_wire0[53:0]; sv_mult27_mult_add_cfq3 sv_mult27_mult_add_cfq3_component ( .clock0 (clock0), .ena0(ena0), .dataa (dataa_0), .datab (datab_0), .result (sub_wire0)); endmodule // ============================================================ // CNX file retrieval info // ============================================================ // Retrieval info: PRIVATE: ACCUM_SLOAD_ACLR_SRC_MULT0 NUMERIC "3" // Retrieval info: PRIVATE: ACCUM_SLOAD_CLK_SRC_MULT0 NUMERIC "0" // Retrieval info: PRIVATE: ADDNSUB1_ACLR_SRC NUMERIC "2" // Retrieval info: PRIVATE: ADDNSUB1_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: ADDNSUB1_PIPE_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: ADDNSUB1_PIPE_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: ADDNSUB1_PIPE_REG STRING "0" // Retrieval info: PRIVATE: ADDNSUB1_REG STRING "1" // Retrieval info: PRIVATE: ADDNSUB3_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: ADDNSUB3_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: ADDNSUB3_PIPE_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: ADDNSUB3_PIPE_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: ADDNSUB3_PIPE_REG STRING "0" // Retrieval info: PRIVATE: ADDNSUB3_REG STRING "1" // Retrieval info: PRIVATE: ADD_ENABLE NUMERIC "0" // Retrieval info: PRIVATE: ALL_REG_ACLR NUMERIC "0" // Retrieval info: PRIVATE: A_ACLR_SRC_MULT0 NUMERIC "2" // Retrieval info: PRIVATE: A_CLK_SRC_MULT0 NUMERIC "0" // Retrieval info: PRIVATE: B_ACLR_SRC_MULT0 NUMERIC "3" // Retrieval info: PRIVATE: B_CLK_SRC_MULT0 NUMERIC "0" // Retrieval info: PRIVATE: C_ACLR_SRC_MULT0 NUMERIC "3" // Retrieval info: PRIVATE: C_CLK_SRC_MULT0 NUMERIC "0" // Retrieval info: PRIVATE: ENABLE_PRELOAD_CONSTANT NUMERIC "0" // Retrieval info: PRIVATE: HAS_MAC STRING "0" // Retrieval info: PRIVATE: HAS_SAT_ROUND STRING "0" // Retrieval info: PRIVATE: IMPL_STYLE_DEDICATED NUMERIC "0" // Retrieval info: PRIVATE: IMPL_STYLE_DEFAULT NUMERIC "1" // Retrieval info: PRIVATE: IMPL_STYLE_LCELL NUMERIC "0" // Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Stratix V" // Retrieval info: PRIVATE: MULT_COEFSEL STRING "0" // Retrieval info: PRIVATE: MULT_REGA0 NUMERIC "1" // Retrieval info: PRIVATE: MULT_REGB0 NUMERIC "1" // Retrieval info: PRIVATE: MULT_REGC NUMERIC "0" // Retrieval info: PRIVATE: MULT_REGOUT0 NUMERIC "0" // Retrieval info: PRIVATE: MULT_REG_ACCUM_SLOAD NUMERIC "0" // Retrieval info: PRIVATE: MULT_REG_SYSTOLIC_DELAY NUMERIC "0" // Retrieval info: PRIVATE: NUM_MULT STRING "1" // Retrieval info: PRIVATE: OP1 STRING "Add" // Retrieval info: PRIVATE: OP3 STRING "Add" // Retrieval info: PRIVATE: OUTPUT_EXTRA_LAT NUMERIC "0" // Retrieval info: PRIVATE: OUTPUT_REG_ACLR_SRC NUMERIC "2" // Retrieval info: PRIVATE: OUTPUT_REG_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: Q_ACLR_SRC_MULT0 NUMERIC "3" // Retrieval info: PRIVATE: Q_CLK_SRC_MULT0 NUMERIC "0" // Retrieval info: PRIVATE: REG_OUT NUMERIC "1" // Retrieval info: PRIVATE: RNFORMAT STRING "54" // Retrieval info: PRIVATE: RQFORMAT STRING "Q1.15" // Retrieval info: PRIVATE: RTS_WIDTH STRING "54" // Retrieval info: PRIVATE: SAME_CONFIG NUMERIC "1" // Retrieval info: PRIVATE: SAME_CONTROL_SRC_A0 NUMERIC "1" // Retrieval info: PRIVATE: SAME_CONTROL_SRC_B0 NUMERIC "1" // Retrieval info: PRIVATE: SCANOUTA NUMERIC "0" // Retrieval info: PRIVATE: SCANOUTB NUMERIC "0" // Retrieval info: PRIVATE: SHIFTOUTA_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: SHIFTOUTA_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: SHIFTOUTA_REG STRING "0" // Retrieval info: PRIVATE: SIGNA STRING "UNSIGNED" // Retrieval info: PRIVATE: SIGNA_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: SIGNA_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: SIGNA_PIPE_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: SIGNA_PIPE_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: SIGNA_PIPE_REG STRING "0" // Retrieval info: PRIVATE: SIGNA_REG STRING "1" // Retrieval info: PRIVATE: SIGNB STRING "UNSIGNED" // Retrieval info: PRIVATE: SIGNB_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: SIGNB_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: SIGNB_PIPE_ACLR_SRC NUMERIC "3" // Retrieval info: PRIVATE: SIGNB_PIPE_CLK_SRC NUMERIC "0" // Retrieval info: PRIVATE: SIGNB_PIPE_REG STRING "0" // Retrieval info: PRIVATE: SIGNB_REG STRING "1" // Retrieval info: PRIVATE: SRCA0 STRING "Multiplier input" // Retrieval info: PRIVATE: SRCB0 STRING "Multiplier input" // Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0" // Retrieval info: PRIVATE: SYSTOLIC_ACLR_SRC_MULT0 NUMERIC "3" // Retrieval info: PRIVATE: SYSTOLIC_CLK_SRC_MULT0 NUMERIC "0" // Retrieval info: PRIVATE: WIDTHA STRING "27" // Retrieval info: PRIVATE: WIDTHB STRING "27" // Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all // Retrieval info: CONSTANT: ACCUM_SLOAD_REGISTER STRING "UNREGISTERED" // Retrieval info: CONSTANT: ADDNSUB_MULTIPLIER_ACLR1 STRING "UNUSED" // Retrieval info: CONSTANT: ADDNSUB_MULTIPLIER_PIPELINE_REGISTER1 STRING "UNREGISTERED" // Retrieval info: CONSTANT: ADDNSUB_MULTIPLIER_REGISTER1 STRING "CLOCK0" // Retrieval info: CONSTANT: COEF0_0 NUMERIC "0" // Retrieval info: CONSTANT: COEF0_1 NUMERIC "0" // Retrieval info: CONSTANT: COEF0_2 NUMERIC "0" // Retrieval info: CONSTANT: COEF0_3 NUMERIC "0" // Retrieval info: CONSTANT: COEF0_4 NUMERIC "0" // Retrieval info: CONSTANT: COEF0_5 NUMERIC "0" // Retrieval info: CONSTANT: COEF0_6 NUMERIC "0" // Retrieval info: CONSTANT: COEF0_7 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_0 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_1 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_2 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_3 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_4 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_5 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_6 NUMERIC "0" // Retrieval info: CONSTANT: COEF1_7 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_0 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_1 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_2 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_3 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_4 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_5 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_6 NUMERIC "0" // Retrieval info: CONSTANT: COEF2_7 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_0 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_1 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_2 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_3 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_4 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_5 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_6 NUMERIC "0" // Retrieval info: CONSTANT: COEF3_7 NUMERIC "0" // Retrieval info: CONSTANT: COEFSEL0_REGISTER STRING "UNREGISTERED" // Retrieval info: CONSTANT: DEDICATED_MULTIPLIER_CIRCUITRY STRING "AUTO" // Retrieval info: CONSTANT: INPUT_ACLR_A0 STRING "UNUSED" // Retrieval info: CONSTANT: INPUT_ACLR_B0 STRING "UNUSED" // Retrieval info: CONSTANT: INPUT_REGISTER_A0 STRING "CLOCK0" // Retrieval info: CONSTANT: INPUT_REGISTER_B0 STRING "CLOCK0" // Retrieval info: CONSTANT: INPUT_REGISTER_C0 STRING "UNREGISTERED" // Retrieval info: CONSTANT: INPUT_SOURCE_A0 STRING "DATAA" // Retrieval info: CONSTANT: INPUT_SOURCE_B0 STRING "DATAB" // Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Stratix V" // Retrieval info: CONSTANT: LOADCONST_VALUE NUMERIC "64" // Retrieval info: CONSTANT: LPM_TYPE STRING "altmult_add" // Retrieval info: CONSTANT: MULTIPLIER1_DIRECTION STRING "ADD" // Retrieval info: CONSTANT: MULTIPLIER_ACLR0 STRING "UNUSED" // Retrieval info: CONSTANT: MULTIPLIER_REGISTER0 STRING "UNREGISTERED" // Retrieval info: CONSTANT: NUMBER_OF_MULTIPLIERS NUMERIC "1" // Retrieval info: CONSTANT: OUTPUT_ACLR STRING "UNUSED" // Retrieval info: CONSTANT: OUTPUT_REGISTER STRING "CLOCK0" // Retrieval info: CONSTANT: PORT_ADDNSUB1 STRING "PORT_UNUSED" // Retrieval info: CONSTANT: PORT_SIGNA STRING "PORT_UNUSED" // Retrieval info: CONSTANT: PORT_SIGNB STRING "PORT_UNUSED" // Retrieval info: CONSTANT: PREADDER_DIRECTION_0 STRING "ADD" // Retrieval info: CONSTANT: PREADDER_DIRECTION_1 STRING "ADD" // Retrieval info: CONSTANT: PREADDER_DIRECTION_2 STRING "ADD" // Retrieval info: CONSTANT: PREADDER_DIRECTION_3 STRING "ADD" // Retrieval info: CONSTANT: PREADDER_MODE STRING "SIMPLE" // Retrieval info: CONSTANT: REPRESENTATION_A STRING "UNSIGNED" // Retrieval info: CONSTANT: REPRESENTATION_B STRING "UNSIGNED" // Retrieval info: CONSTANT: SIGNED_ACLR_A STRING "UNUSED" // Retrieval info: CONSTANT: SIGNED_ACLR_B STRING "UNUSED" // Retrieval info: CONSTANT: SIGNED_PIPELINE_REGISTER_A STRING "UNREGISTERED" // Retrieval info: CONSTANT: SIGNED_PIPELINE_REGISTER_B STRING "UNREGISTERED" // Retrieval info: CONSTANT: SIGNED_REGISTER_A STRING "CLOCK0" // Retrieval info: CONSTANT: SIGNED_REGISTER_B STRING "CLOCK0" // Retrieval info: CONSTANT: SYSTOLIC_DELAY1 STRING "UNREGISTERED" // Retrieval info: CONSTANT: SYSTOLIC_DELAY3 STRING "UNREGISTERED" // Retrieval info: CONSTANT: WIDTH_A NUMERIC "27" // Retrieval info: CONSTANT: WIDTH_B NUMERIC "27" // Retrieval info: CONSTANT: WIDTH_RESULT NUMERIC "54" // Retrieval info: USED_PORT: clock0 0 0 0 0 INPUT VCC "clock0" // Retrieval info: USED_PORT: dataa_0 0 0 27 0 INPUT GND "dataa_0[26..0]" // Retrieval info: USED_PORT: datab_0 0 0 27 0 INPUT GND "datab_0[26..0]" // Retrieval info: USED_PORT: result 0 0 54 0 OUTPUT GND "result[53..0]" // Retrieval info: CONNECT: @clock0 0 0 0 0 clock0 0 0 0 0 // Retrieval info: CONNECT: @dataa 0 0 27 0 dataa_0 0 0 27 0 // Retrieval info: CONNECT: @datab 0 0 27 0 datab_0 0 0 27 0 // Retrieval info: CONNECT: result 0 0 54 0 @result 0 0 54 0 // Retrieval info: GEN_FILE: TYPE_NORMAL sv_mult27.v TRUE // Retrieval info: GEN_FILE: TYPE_NORMAL sv_mult27.inc FALSE // Retrieval info: GEN_FILE: TYPE_NORMAL sv_mult27.cmp FALSE // Retrieval info: GEN_FILE: TYPE_NORMAL sv_mult27.bsf FALSE // Retrieval info: GEN_FILE: TYPE_NORMAL sv_mult27_inst.v FALSE // Retrieval info: GEN_FILE: TYPE_NORMAL sv_mult27_bb.v TRUE // Retrieval info: LIB_FILE: altera_lnsim
/* * * Copyright (c) 2011-2013 [email protected] * * * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ /* * When tx_ready is high, uart_transmitter is ready to send a new byte. Drive * rx_new_byte high for one cycle, and the byte to transmit on rx_byte for one * cycle. */ module uart_transmitter # ( parameter comm_clk_frequency = 100000000, parameter baud_rate = 115200 ) ( input clk, // UART interface output uart_tx, // Data to send input rx_new_byte, input [7:0] rx_byte, // Status output tx_ready ); localparam [15:0] baud_delay = (comm_clk_frequency / baud_rate) - 1; reg [15:0] delay_cnt = 16'd0; reg [9:0] state = 10'd1023, outgoing = 10'd1023; assign uart_tx = outgoing[0]; assign tx_ready = state[0] & ~rx_new_byte; always @ (posedge clk) begin delay_cnt <= delay_cnt + 16'd1; if (delay_cnt >= baud_delay) begin delay_cnt <= 16'd0; state <= {1'b1, state[9:1]}; outgoing <= {1'b1, outgoing[9:1]}; end if (rx_new_byte && state[0]) begin delay_cnt <= 16'd0; state <= 10'd0; outgoing <= {1'b1, rx_byte, 1'b0}; end end endmodule
// (C) 2001-2016 Altera Corporation. All rights reserved. // Your use of Altera Corporation's design tools, logic functions and other // software and tools, and its AMPP partner logic functions, and any output // files any of the foregoing (including device programming or simulation // files), and any associated documentation or information are expressly subject // to the terms and conditions of the Altera Program License Subscription // Agreement, Altera MegaCore Function License Agreement, or other applicable // license agreement, including, without limitation, that your use is for the // sole purpose of programming logic devices manufactured by Altera and sold by // Altera or its authorized distributors. Please refer to the applicable // agreement for further details. // THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS // IN THIS FILE. /****************************************************************************** * * * This module reads and writes data to the RS232 connectpr on Altera's * * DE1 and DE2 Development and Education Boards. * * * ******************************************************************************/ module altera_up_rs232_counters ( // Inputs clk, reset, reset_counters, // Bidirectionals // Outputs baud_clock_rising_edge, baud_clock_falling_edge, all_bits_transmitted ); /***************************************************************************** * Parameter Declarations * *****************************************************************************/ parameter CW = 9; // BAUD COUNTER WIDTH parameter BAUD_TICK_COUNT = 433; parameter HALF_BAUD_TICK_COUNT = 216; parameter TDW = 11; // TOTAL DATA WIDTH /***************************************************************************** * Port Declarations * *****************************************************************************/ // Inputs input clk; input reset; input reset_counters; // Bidirectionals // Outputs output reg baud_clock_rising_edge; output reg baud_clock_falling_edge; output reg all_bits_transmitted; /***************************************************************************** * Constant Declarations * *****************************************************************************/ /***************************************************************************** * Internal Wires and Registers Declarations * *****************************************************************************/ // Internal Wires // Internal Registers reg [(CW-1):0] baud_counter; reg [ 3: 0] bit_counter; // State Machine Registers /***************************************************************************** * Finite State Machine(s) * *****************************************************************************/ /***************************************************************************** * Sequential Logic * *****************************************************************************/ always @(posedge clk) begin if (reset) baud_counter <= {CW{1'b0}}; else if (reset_counters) baud_counter <= {CW{1'b0}}; else if (baud_counter == BAUD_TICK_COUNT) baud_counter <= {CW{1'b0}}; else baud_counter <= baud_counter + 1; end always @(posedge clk) begin if (reset) baud_clock_rising_edge <= 1'b0; else if (baud_counter == BAUD_TICK_COUNT) baud_clock_rising_edge <= 1'b1; else baud_clock_rising_edge <= 1'b0; end always @(posedge clk) begin if (reset) baud_clock_falling_edge <= 1'b0; else if (baud_counter == HALF_BAUD_TICK_COUNT) baud_clock_falling_edge <= 1'b1; else baud_clock_falling_edge <= 1'b0; end always @(posedge clk) begin if (reset) bit_counter <= 4'h0; else if (reset_counters) bit_counter <= 4'h0; else if (bit_counter == TDW) bit_counter <= 4'h0; else if (baud_counter == BAUD_TICK_COUNT) bit_counter <= bit_counter + 4'h1; end always @(posedge clk) begin if (reset) all_bits_transmitted <= 1'b0; else if (bit_counter == TDW) all_bits_transmitted <= 1'b1; else all_bits_transmitted <= 1'b0; end /***************************************************************************** * Combinational Logic * *****************************************************************************/ /***************************************************************************** * Internal Modules * *****************************************************************************/ endmodule
// (C) 2001-2016 Altera Corporation. All rights reserved. // Your use of Altera Corporation's design tools, logic functions and other // software and tools, and its AMPP partner logic functions, and any output // files any of the foregoing (including device programming or simulation // files), and any associated documentation or information are expressly subject // to the terms and conditions of the Altera Program License Subscription // Agreement, Altera MegaCore Function License Agreement, or other applicable // license agreement, including, without limitation, that your use is for the // sole purpose of programming logic devices manufactured by Altera and sold by // Altera or its authorized distributors. Please refer to the applicable // agreement for further details. // THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS // IN THIS FILE. /****************************************************************************** * * * This module reads and writes data to the RS232 connectpr on Altera's * * DE1 and DE2 Development and Education Boards. * * * ******************************************************************************/ module altera_up_rs232_counters ( // Inputs clk, reset, reset_counters, // Bidirectionals // Outputs baud_clock_rising_edge, baud_clock_falling_edge, all_bits_transmitted ); /***************************************************************************** * Parameter Declarations * *****************************************************************************/ parameter CW = 9; // BAUD COUNTER WIDTH parameter BAUD_TICK_COUNT = 433; parameter HALF_BAUD_TICK_COUNT = 216; parameter TDW = 11; // TOTAL DATA WIDTH /***************************************************************************** * Port Declarations * *****************************************************************************/ // Inputs input clk; input reset; input reset_counters; // Bidirectionals // Outputs output reg baud_clock_rising_edge; output reg baud_clock_falling_edge; output reg all_bits_transmitted; /***************************************************************************** * Constant Declarations * *****************************************************************************/ /***************************************************************************** * Internal Wires and Registers Declarations * *****************************************************************************/ // Internal Wires // Internal Registers reg [(CW-1):0] baud_counter; reg [ 3: 0] bit_counter; // State Machine Registers /***************************************************************************** * Finite State Machine(s) * *****************************************************************************/ /***************************************************************************** * Sequential Logic * *****************************************************************************/ always @(posedge clk) begin if (reset) baud_counter <= {CW{1'b0}}; else if (reset_counters) baud_counter <= {CW{1'b0}}; else if (baud_counter == BAUD_TICK_COUNT) baud_counter <= {CW{1'b0}}; else baud_counter <= baud_counter + 1; end always @(posedge clk) begin if (reset) baud_clock_rising_edge <= 1'b0; else if (baud_counter == BAUD_TICK_COUNT) baud_clock_rising_edge <= 1'b1; else baud_clock_rising_edge <= 1'b0; end always @(posedge clk) begin if (reset) baud_clock_falling_edge <= 1'b0; else if (baud_counter == HALF_BAUD_TICK_COUNT) baud_clock_falling_edge <= 1'b1; else baud_clock_falling_edge <= 1'b0; end always @(posedge clk) begin if (reset) bit_counter <= 4'h0; else if (reset_counters) bit_counter <= 4'h0; else if (bit_counter == TDW) bit_counter <= 4'h0; else if (baud_counter == BAUD_TICK_COUNT) bit_counter <= bit_counter + 4'h1; end always @(posedge clk) begin if (reset) all_bits_transmitted <= 1'b0; else if (bit_counter == TDW) all_bits_transmitted <= 1'b1; else all_bits_transmitted <= 1'b0; end /***************************************************************************** * Combinational Logic * *****************************************************************************/ /***************************************************************************** * Internal Modules * *****************************************************************************/ endmodule
// (C) 2001-2016 Altera Corporation. All rights reserved. // Your use of Altera Corporation's design tools, logic functions and other // software and tools, and its AMPP partner logic functions, and any output // files any of the foregoing (including device programming or simulation // files), and any associated documentation or information are expressly subject // to the terms and conditions of the Altera Program License Subscription // Agreement, Altera MegaCore Function License Agreement, or other applicable // license agreement, including, without limitation, that your use is for the // sole purpose of programming logic devices manufactured by Altera and sold by // Altera or its authorized distributors. Please refer to the applicable // agreement for further details. // THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS // IN THIS FILE. /****************************************************************************** * * * This module reads and writes data to the RS232 connectpr on Altera's * * DE1 and DE2 Development and Education Boards. * * * ******************************************************************************/ module altera_up_rs232_counters ( // Inputs clk, reset, reset_counters, // Bidirectionals // Outputs baud_clock_rising_edge, baud_clock_falling_edge, all_bits_transmitted ); /***************************************************************************** * Parameter Declarations * *****************************************************************************/ parameter CW = 9; // BAUD COUNTER WIDTH parameter BAUD_TICK_COUNT = 433; parameter HALF_BAUD_TICK_COUNT = 216; parameter TDW = 11; // TOTAL DATA WIDTH /***************************************************************************** * Port Declarations * *****************************************************************************/ // Inputs input clk; input reset; input reset_counters; // Bidirectionals // Outputs output reg baud_clock_rising_edge; output reg baud_clock_falling_edge; output reg all_bits_transmitted; /***************************************************************************** * Constant Declarations * *****************************************************************************/ /***************************************************************************** * Internal Wires and Registers Declarations * *****************************************************************************/ // Internal Wires // Internal Registers reg [(CW-1):0] baud_counter; reg [ 3: 0] bit_counter; // State Machine Registers /***************************************************************************** * Finite State Machine(s) * *****************************************************************************/ /***************************************************************************** * Sequential Logic * *****************************************************************************/ always @(posedge clk) begin if (reset) baud_counter <= {CW{1'b0}}; else if (reset_counters) baud_counter <= {CW{1'b0}}; else if (baud_counter == BAUD_TICK_COUNT) baud_counter <= {CW{1'b0}}; else baud_counter <= baud_counter + 1; end always @(posedge clk) begin if (reset) baud_clock_rising_edge <= 1'b0; else if (baud_counter == BAUD_TICK_COUNT) baud_clock_rising_edge <= 1'b1; else baud_clock_rising_edge <= 1'b0; end always @(posedge clk) begin if (reset) baud_clock_falling_edge <= 1'b0; else if (baud_counter == HALF_BAUD_TICK_COUNT) baud_clock_falling_edge <= 1'b1; else baud_clock_falling_edge <= 1'b0; end always @(posedge clk) begin if (reset) bit_counter <= 4'h0; else if (reset_counters) bit_counter <= 4'h0; else if (bit_counter == TDW) bit_counter <= 4'h0; else if (baud_counter == BAUD_TICK_COUNT) bit_counter <= bit_counter + 4'h1; end always @(posedge clk) begin if (reset) all_bits_transmitted <= 1'b0; else if (bit_counter == TDW) all_bits_transmitted <= 1'b1; else all_bits_transmitted <= 1'b0; end /***************************************************************************** * Combinational Logic * *****************************************************************************/ /***************************************************************************** * Internal Modules * *****************************************************************************/ endmodule
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2010 by Wilson Snyder. module t (/*AUTOARG*/ // Outputs data_out, // Inputs wr, wa, rst_l, rd, ra, data_in, clk ); input clk; /*AUTOINPUT*/ // Beginning of automatic inputs (from unused autoinst inputs) input [31:0] data_in; // To sub of reg_1r1w.v input [7:0] ra; // To sub of reg_1r1w.v input rd; // To sub of reg_1r1w.v input rst_l; // To sub of reg_1r1w.v input [7:0] wa; // To sub of reg_1r1w.v input wr; // To sub of reg_1r1w.v // End of automatics /*AUTOOUTPUT*/ // Beginning of automatic outputs (from unused autoinst outputs) output [31:0] data_out; // From sub of reg_1r1w.v // End of automatics reg_1r1w #(.WIDTH(32), .DEPTH(256), .ADRWID(8)) sub (/*AUTOINST*/ // Outputs .data_out (data_out[31:0]), // Inputs .data_in (data_in[31:0]), .ra (ra[7:0]), .wa (wa[7:0]), .wr (wr), .rd (rd), .clk (clk), .rst_l (rst_l)); endmodule module reg_1r1w #( parameter WIDTH=32, parameter ADRWID=10, parameter DEPTH=1024, parameter RST=0 ) (/*AUTOARG*/ // Outputs data_out, // Inputs data_in, ra, wa, wr, rd, clk, rst_l ); input [WIDTH-1:0] data_in; input [ADRWID-1:0] ra; input [ADRWID-1:0] wa; input wr; input rd; input clk; input rst_l; output [WIDTH-1:0] data_out; reg [WIDTH-1:0] array [DEPTH-1:0]; reg [ADRWID-1:0] ra_r, wa_r; reg [WIDTH-1:0] data_in_r; reg wr_r; reg rd_r; integer x; // Message 679 always @(posedge clk) begin int tmp = x + 1; if (tmp !== x + 1) $stop; end always @(posedge clk or negedge rst_l) begin if (!rst_l) begin for (x=0; x<DEPTH; x=x+1) begin // <== VERILATOR FLAGS THIS LINE if (RST == 1) begin array[x] <= 0; end end ra_r <= 0; wa_r <= 0; wr_r <= 0; rd_r <= 0; data_in_r <= 0; end else begin ra_r <= ra; wa_r <= wa; wr_r <= wr; rd_r <= rd; data_in_r <= data_in; if (wr_r) array[wa_r] <= data_in_r; end end endmodule // Local Variables: // verilog-auto-inst-param-value: t // End:
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2010 by Wilson Snyder. module t (/*AUTOARG*/ // Outputs data_out, // Inputs wr, wa, rst_l, rd, ra, data_in, clk ); input clk; /*AUTOINPUT*/ // Beginning of automatic inputs (from unused autoinst inputs) input [31:0] data_in; // To sub of reg_1r1w.v input [7:0] ra; // To sub of reg_1r1w.v input rd; // To sub of reg_1r1w.v input rst_l; // To sub of reg_1r1w.v input [7:0] wa; // To sub of reg_1r1w.v input wr; // To sub of reg_1r1w.v // End of automatics /*AUTOOUTPUT*/ // Beginning of automatic outputs (from unused autoinst outputs) output [31:0] data_out; // From sub of reg_1r1w.v // End of automatics reg_1r1w #(.WIDTH(32), .DEPTH(256), .ADRWID(8)) sub (/*AUTOINST*/ // Outputs .data_out (data_out[31:0]), // Inputs .data_in (data_in[31:0]), .ra (ra[7:0]), .wa (wa[7:0]), .wr (wr), .rd (rd), .clk (clk), .rst_l (rst_l)); endmodule module reg_1r1w #( parameter WIDTH=32, parameter ADRWID=10, parameter DEPTH=1024, parameter RST=0 ) (/*AUTOARG*/ // Outputs data_out, // Inputs data_in, ra, wa, wr, rd, clk, rst_l ); input [WIDTH-1:0] data_in; input [ADRWID-1:0] ra; input [ADRWID-1:0] wa; input wr; input rd; input clk; input rst_l; output [WIDTH-1:0] data_out; reg [WIDTH-1:0] array [DEPTH-1:0]; reg [ADRWID-1:0] ra_r, wa_r; reg [WIDTH-1:0] data_in_r; reg wr_r; reg rd_r; integer x; // Message 679 always @(posedge clk) begin int tmp = x + 1; if (tmp !== x + 1) $stop; end always @(posedge clk or negedge rst_l) begin if (!rst_l) begin for (x=0; x<DEPTH; x=x+1) begin // <== VERILATOR FLAGS THIS LINE if (RST == 1) begin array[x] <= 0; end end ra_r <= 0; wa_r <= 0; wr_r <= 0; rd_r <= 0; data_in_r <= 0; end else begin ra_r <= ra; wa_r <= wa; wr_r <= wr; rd_r <= rd; data_in_r <= data_in; if (wr_r) array[wa_r] <= data_in_r; end end endmodule // Local Variables: // verilog-auto-inst-param-value: t // End:
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2010 by Wilson Snyder. module t (/*AUTOARG*/ // Outputs data_out, // Inputs wr, wa, rst_l, rd, ra, data_in, clk ); input clk; /*AUTOINPUT*/ // Beginning of automatic inputs (from unused autoinst inputs) input [31:0] data_in; // To sub of reg_1r1w.v input [7:0] ra; // To sub of reg_1r1w.v input rd; // To sub of reg_1r1w.v input rst_l; // To sub of reg_1r1w.v input [7:0] wa; // To sub of reg_1r1w.v input wr; // To sub of reg_1r1w.v // End of automatics /*AUTOOUTPUT*/ // Beginning of automatic outputs (from unused autoinst outputs) output [31:0] data_out; // From sub of reg_1r1w.v // End of automatics reg_1r1w #(.WIDTH(32), .DEPTH(256), .ADRWID(8)) sub (/*AUTOINST*/ // Outputs .data_out (data_out[31:0]), // Inputs .data_in (data_in[31:0]), .ra (ra[7:0]), .wa (wa[7:0]), .wr (wr), .rd (rd), .clk (clk), .rst_l (rst_l)); endmodule module reg_1r1w #( parameter WIDTH=32, parameter ADRWID=10, parameter DEPTH=1024, parameter RST=0 ) (/*AUTOARG*/ // Outputs data_out, // Inputs data_in, ra, wa, wr, rd, clk, rst_l ); input [WIDTH-1:0] data_in; input [ADRWID-1:0] ra; input [ADRWID-1:0] wa; input wr; input rd; input clk; input rst_l; output [WIDTH-1:0] data_out; reg [WIDTH-1:0] array [DEPTH-1:0]; reg [ADRWID-1:0] ra_r, wa_r; reg [WIDTH-1:0] data_in_r; reg wr_r; reg rd_r; integer x; // Message 679 always @(posedge clk) begin int tmp = x + 1; if (tmp !== x + 1) $stop; end always @(posedge clk or negedge rst_l) begin if (!rst_l) begin for (x=0; x<DEPTH; x=x+1) begin // <== VERILATOR FLAGS THIS LINE if (RST == 1) begin array[x] <= 0; end end ra_r <= 0; wa_r <= 0; wr_r <= 0; rd_r <= 0; data_in_r <= 0; end else begin ra_r <= ra; wa_r <= wa; wr_r <= wr; rd_r <= rd; data_in_r <= data_in; if (wr_r) array[wa_r] <= data_in_r; end end endmodule // Local Variables: // verilog-auto-inst-param-value: t // End:
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2010 by Wilson Snyder. module t (/*AUTOARG*/ // Outputs data_out, // Inputs wr, wa, rst_l, rd, ra, data_in, clk ); input clk; /*AUTOINPUT*/ // Beginning of automatic inputs (from unused autoinst inputs) input [31:0] data_in; // To sub of reg_1r1w.v input [7:0] ra; // To sub of reg_1r1w.v input rd; // To sub of reg_1r1w.v input rst_l; // To sub of reg_1r1w.v input [7:0] wa; // To sub of reg_1r1w.v input wr; // To sub of reg_1r1w.v // End of automatics /*AUTOOUTPUT*/ // Beginning of automatic outputs (from unused autoinst outputs) output [31:0] data_out; // From sub of reg_1r1w.v // End of automatics reg_1r1w #(.WIDTH(32), .DEPTH(256), .ADRWID(8)) sub (/*AUTOINST*/ // Outputs .data_out (data_out[31:0]), // Inputs .data_in (data_in[31:0]), .ra (ra[7:0]), .wa (wa[7:0]), .wr (wr), .rd (rd), .clk (clk), .rst_l (rst_l)); endmodule module reg_1r1w #( parameter WIDTH=32, parameter ADRWID=10, parameter DEPTH=1024, parameter RST=0 ) (/*AUTOARG*/ // Outputs data_out, // Inputs data_in, ra, wa, wr, rd, clk, rst_l ); input [WIDTH-1:0] data_in; input [ADRWID-1:0] ra; input [ADRWID-1:0] wa; input wr; input rd; input clk; input rst_l; output [WIDTH-1:0] data_out; reg [WIDTH-1:0] array [DEPTH-1:0]; reg [ADRWID-1:0] ra_r, wa_r; reg [WIDTH-1:0] data_in_r; reg wr_r; reg rd_r; integer x; // Message 679 always @(posedge clk) begin int tmp = x + 1; if (tmp !== x + 1) $stop; end always @(posedge clk or negedge rst_l) begin if (!rst_l) begin for (x=0; x<DEPTH; x=x+1) begin // <== VERILATOR FLAGS THIS LINE if (RST == 1) begin array[x] <= 0; end end ra_r <= 0; wa_r <= 0; wr_r <= 0; rd_r <= 0; data_in_r <= 0; end else begin ra_r <= ra; wa_r <= wa; wr_r <= wr; rd_r <= rd; data_in_r <= data_in; if (wr_r) array[wa_r] <= data_in_r; end end endmodule // Local Variables: // verilog-auto-inst-param-value: t // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: pipeline.v // Version: 1.00 // Verilog Standard: Verilog-2001 // Description: Standard 0-delay pipeline implementation. Takes WR_DATA on // WR_READY and WR_VALID. RD_DATA is read on RD_READY and // RD_VALID. C_DEPTH specifies the latency between RD and WR ports // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns module pipeline #( parameter C_DEPTH = 10, parameter C_WIDTH = 10, parameter C_USE_MEMORY = 1 ) ( input CLK, input RST_IN, input [C_WIDTH-1:0] WR_DATA, input WR_DATA_VALID, output WR_DATA_READY, output [C_WIDTH-1:0] RD_DATA, output RD_DATA_VALID, input RD_DATA_READY ); generate if (C_USE_MEMORY & C_DEPTH > 2) begin mem_pipeline #( .C_PIPELINE_INPUT (1), .C_PIPELINE_OUTPUT (1), /*AUTOINSTPARAM*/ // Parameters .C_DEPTH (C_DEPTH), .C_WIDTH (C_WIDTH)) pipeline_inst (/*AUTOINST*/ // Outputs .WR_DATA_READY (WR_DATA_READY), .RD_DATA (RD_DATA[C_WIDTH-1:0]), .RD_DATA_VALID (RD_DATA_VALID), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_DATA (WR_DATA[C_WIDTH-1:0]), .WR_DATA_VALID (WR_DATA_VALID), .RD_DATA_READY (RD_DATA_READY)); end else begin reg_pipeline #(/*AUTOINSTPARAM*/ // Parameters .C_DEPTH (C_DEPTH), .C_WIDTH (C_WIDTH)) pipeline_inst (/*AUTOINST*/ // Outputs .WR_DATA_READY (WR_DATA_READY), .RD_DATA (RD_DATA[C_WIDTH-1:0]), .RD_DATA_VALID (RD_DATA_VALID), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_DATA (WR_DATA[C_WIDTH-1:0]), .WR_DATA_VALID (WR_DATA_VALID), .RD_DATA_READY (RD_DATA_READY)); end endgenerate endmodule // pipeline module mem_pipeline #( parameter C_DEPTH = 10, parameter C_WIDTH = 10, parameter C_PIPELINE_INPUT = 0, parameter C_PIPELINE_OUTPUT = 1 ) ( input CLK, input RST_IN, input [C_WIDTH-1:0] WR_DATA, input WR_DATA_VALID, output WR_DATA_READY, output [C_WIDTH-1:0] RD_DATA, output RD_DATA_VALID, input RD_DATA_READY ); localparam C_INPUT_REGISTERS = C_PIPELINE_INPUT?1:0; localparam C_OUTPUT_REGISTERS = C_PIPELINE_OUTPUT?1:0; wire RST; wire [C_WIDTH-1:0] wRdData; wire wRdDataValid; wire wRdDataReady; wire [C_WIDTH-1:0] wWrData; wire wWrDataValid; wire wWrDataReady; assign RST = RST_IN; reg_pipeline #( // Parameters .C_DEPTH (C_INPUT_REGISTERS), /*AUTOINSTPARAM*/ // Parameters .C_WIDTH (C_WIDTH)) reg_in ( // Outputs .RD_DATA (wRdData), .RD_DATA_VALID (wRdDataValid), // Inputs .RD_DATA_READY (wRdDataReady), /*AUTOINST*/ // Outputs .WR_DATA_READY (WR_DATA_READY), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_DATA (WR_DATA[C_WIDTH-1:0]), .WR_DATA_VALID (WR_DATA_VALID)); fifo #( // Parameters .C_WIDTH (C_WIDTH), .C_DEPTH (C_DEPTH - C_PIPELINE_INPUT - C_PIPELINE_OUTPUT), .C_DELAY (C_DEPTH - C_PIPELINE_INPUT - C_PIPELINE_OUTPUT) /*AUTOINSTPARAM*/) fifo_inst ( // Outputs .RD_DATA (wWrData), .WR_READY (wRdDataReady), .RD_VALID (wWrDataValid), // Inputs .WR_DATA (wRdData), .WR_VALID (wRdDataValid), .RD_READY (wWrDataReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST (RST)); reg_pipeline #( // Parameters .C_DEPTH (C_OUTPUT_REGISTERS), .C_WIDTH (C_WIDTH) /*AUTOINSTPARAM*/) reg_OUT ( // Outputs .WR_DATA_READY (wWrDataReady), // Inputs .WR_DATA (wWrData), .WR_DATA_VALID (wWrDataValid), /*AUTOINST*/ // Outputs .RD_DATA (RD_DATA[C_WIDTH-1:0]), .RD_DATA_VALID (RD_DATA_VALID), // Inputs .CLK (CLK), .RST_IN (RST_IN), .RD_DATA_READY (RD_DATA_READY)); endmodule // mem_pipeline /* verilator lint_off UNOPTFLAT */ module reg_pipeline #( parameter C_DEPTH = 10, parameter C_WIDTH = 10 ) ( input CLK, input RST_IN, input [C_WIDTH-1:0] WR_DATA, input WR_DATA_VALID, output WR_DATA_READY, output [C_WIDTH-1:0] RD_DATA, output RD_DATA_VALID, input RD_DATA_READY ); genvar i; wire wReady [C_DEPTH:0]; reg [C_WIDTH-1:0] _rData [C_DEPTH:1], rData [C_DEPTH:0]; reg _rValid [C_DEPTH:1], rValid [C_DEPTH:0]; // Read interface assign wReady[C_DEPTH] = RD_DATA_READY; assign RD_DATA = rData[C_DEPTH]; assign RD_DATA_VALID = rValid[C_DEPTH]; // Write interface assign WR_DATA_READY = wReady[0]; always @(*) begin rData[0] = WR_DATA; rValid[0] = WR_DATA_VALID; end generate for( i = 1 ; i <= C_DEPTH; i = i + 1 ) begin : gen_stages assign #1 wReady[i-1] = ~rValid[i] | wReady[i]; // Data Registers always @(*) begin _rData[i] = rData[i-1]; end // Enable the data register when the corresponding stage is ready always @(posedge CLK) begin if(wReady[i-1]) begin rData[i] <= #1 _rData[i]; end end // Valid Registers always @(*) begin if(RST_IN) begin _rValid[i] = 1'b0; end else begin _rValid[i] = rValid[i-1] | (rValid[i] & ~wReady[i]); end end // Always enable the valid registers always @(posedge CLK) begin rValid[i] <= #1 _rValid[i]; end end endgenerate endmodule /* verilator lint_on UNOPTFLAT */
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: pipeline.v // Version: 1.00 // Verilog Standard: Verilog-2001 // Description: Standard 0-delay pipeline implementation. Takes WR_DATA on // WR_READY and WR_VALID. RD_DATA is read on RD_READY and // RD_VALID. C_DEPTH specifies the latency between RD and WR ports // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns module pipeline #( parameter C_DEPTH = 10, parameter C_WIDTH = 10, parameter C_USE_MEMORY = 1 ) ( input CLK, input RST_IN, input [C_WIDTH-1:0] WR_DATA, input WR_DATA_VALID, output WR_DATA_READY, output [C_WIDTH-1:0] RD_DATA, output RD_DATA_VALID, input RD_DATA_READY ); generate if (C_USE_MEMORY & C_DEPTH > 2) begin mem_pipeline #( .C_PIPELINE_INPUT (1), .C_PIPELINE_OUTPUT (1), /*AUTOINSTPARAM*/ // Parameters .C_DEPTH (C_DEPTH), .C_WIDTH (C_WIDTH)) pipeline_inst (/*AUTOINST*/ // Outputs .WR_DATA_READY (WR_DATA_READY), .RD_DATA (RD_DATA[C_WIDTH-1:0]), .RD_DATA_VALID (RD_DATA_VALID), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_DATA (WR_DATA[C_WIDTH-1:0]), .WR_DATA_VALID (WR_DATA_VALID), .RD_DATA_READY (RD_DATA_READY)); end else begin reg_pipeline #(/*AUTOINSTPARAM*/ // Parameters .C_DEPTH (C_DEPTH), .C_WIDTH (C_WIDTH)) pipeline_inst (/*AUTOINST*/ // Outputs .WR_DATA_READY (WR_DATA_READY), .RD_DATA (RD_DATA[C_WIDTH-1:0]), .RD_DATA_VALID (RD_DATA_VALID), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_DATA (WR_DATA[C_WIDTH-1:0]), .WR_DATA_VALID (WR_DATA_VALID), .RD_DATA_READY (RD_DATA_READY)); end endgenerate endmodule // pipeline module mem_pipeline #( parameter C_DEPTH = 10, parameter C_WIDTH = 10, parameter C_PIPELINE_INPUT = 0, parameter C_PIPELINE_OUTPUT = 1 ) ( input CLK, input RST_IN, input [C_WIDTH-1:0] WR_DATA, input WR_DATA_VALID, output WR_DATA_READY, output [C_WIDTH-1:0] RD_DATA, output RD_DATA_VALID, input RD_DATA_READY ); localparam C_INPUT_REGISTERS = C_PIPELINE_INPUT?1:0; localparam C_OUTPUT_REGISTERS = C_PIPELINE_OUTPUT?1:0; wire RST; wire [C_WIDTH-1:0] wRdData; wire wRdDataValid; wire wRdDataReady; wire [C_WIDTH-1:0] wWrData; wire wWrDataValid; wire wWrDataReady; assign RST = RST_IN; reg_pipeline #( // Parameters .C_DEPTH (C_INPUT_REGISTERS), /*AUTOINSTPARAM*/ // Parameters .C_WIDTH (C_WIDTH)) reg_in ( // Outputs .RD_DATA (wRdData), .RD_DATA_VALID (wRdDataValid), // Inputs .RD_DATA_READY (wRdDataReady), /*AUTOINST*/ // Outputs .WR_DATA_READY (WR_DATA_READY), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_DATA (WR_DATA[C_WIDTH-1:0]), .WR_DATA_VALID (WR_DATA_VALID)); fifo #( // Parameters .C_WIDTH (C_WIDTH), .C_DEPTH (C_DEPTH - C_PIPELINE_INPUT - C_PIPELINE_OUTPUT), .C_DELAY (C_DEPTH - C_PIPELINE_INPUT - C_PIPELINE_OUTPUT) /*AUTOINSTPARAM*/) fifo_inst ( // Outputs .RD_DATA (wWrData), .WR_READY (wRdDataReady), .RD_VALID (wWrDataValid), // Inputs .WR_DATA (wRdData), .WR_VALID (wRdDataValid), .RD_READY (wWrDataReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST (RST)); reg_pipeline #( // Parameters .C_DEPTH (C_OUTPUT_REGISTERS), .C_WIDTH (C_WIDTH) /*AUTOINSTPARAM*/) reg_OUT ( // Outputs .WR_DATA_READY (wWrDataReady), // Inputs .WR_DATA (wWrData), .WR_DATA_VALID (wWrDataValid), /*AUTOINST*/ // Outputs .RD_DATA (RD_DATA[C_WIDTH-1:0]), .RD_DATA_VALID (RD_DATA_VALID), // Inputs .CLK (CLK), .RST_IN (RST_IN), .RD_DATA_READY (RD_DATA_READY)); endmodule // mem_pipeline /* verilator lint_off UNOPTFLAT */ module reg_pipeline #( parameter C_DEPTH = 10, parameter C_WIDTH = 10 ) ( input CLK, input RST_IN, input [C_WIDTH-1:0] WR_DATA, input WR_DATA_VALID, output WR_DATA_READY, output [C_WIDTH-1:0] RD_DATA, output RD_DATA_VALID, input RD_DATA_READY ); genvar i; wire wReady [C_DEPTH:0]; reg [C_WIDTH-1:0] _rData [C_DEPTH:1], rData [C_DEPTH:0]; reg _rValid [C_DEPTH:1], rValid [C_DEPTH:0]; // Read interface assign wReady[C_DEPTH] = RD_DATA_READY; assign RD_DATA = rData[C_DEPTH]; assign RD_DATA_VALID = rValid[C_DEPTH]; // Write interface assign WR_DATA_READY = wReady[0]; always @(*) begin rData[0] = WR_DATA; rValid[0] = WR_DATA_VALID; end generate for( i = 1 ; i <= C_DEPTH; i = i + 1 ) begin : gen_stages assign #1 wReady[i-1] = ~rValid[i] | wReady[i]; // Data Registers always @(*) begin _rData[i] = rData[i-1]; end // Enable the data register when the corresponding stage is ready always @(posedge CLK) begin if(wReady[i-1]) begin rData[i] <= #1 _rData[i]; end end // Valid Registers always @(*) begin if(RST_IN) begin _rValid[i] = 1'b0; end else begin _rValid[i] = rValid[i-1] | (rValid[i] & ~wReady[i]); end end // Always enable the valid registers always @(posedge CLK) begin rValid[i] <= #1 _rValid[i]; end end endgenerate endmodule /* verilator lint_on UNOPTFLAT */
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: sg_list_reader_32.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Reads data from the scatter gather list buffer. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_SGR32_RD_0 3'b000 `define S_SGR32_RD_1 3'b001 `define S_SGR32_RD_2 3'b010 `define S_SGR32_RD_3 3'b011 `define S_SGR32_RD_WAIT 3'b100 `define S_SGR32_CAP_0 3'b000 `define S_SGR32_CAP_1 3'b001 `define S_SGR32_CAP_2 3'b010 `define S_SGR32_CAP_3 3'b011 `define S_SGR32_CAP_RDY 3'b100 `timescale 1ns/1ns module sg_list_reader_32 #( parameter C_DATA_WIDTH = 9'd32 ) ( input CLK, input RST, input [C_DATA_WIDTH-1:0] BUF_DATA, // Scatter gather buffer data input BUF_DATA_EMPTY, // Scatter gather buffer data empty output BUF_DATA_REN, // Scatter gather buffer data read enable output VALID, // Scatter gather element data is valid output EMPTY, // Scatter gather elements empty input REN, // Scatter gather element data read enable output [63:0] ADDR, // Scatter gather element address output [31:0] LEN // Scatter gather element length (in words) ); (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [2:0] rRdState=`S_SGR32_RD_0, _rRdState=`S_SGR32_RD_0; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [2:0] rCapState=`S_SGR32_CAP_0, _rCapState=`S_SGR32_CAP_0; reg [C_DATA_WIDTH-1:0] rData={C_DATA_WIDTH{1'd0}}, _rData={C_DATA_WIDTH{1'd0}}; reg [63:0] rAddr=64'd0, _rAddr=64'd0; reg [31:0] rLen=0, _rLen=0; reg rFifoValid=0, _rFifoValid=0; reg rDataValid=0, _rDataValid=0; assign BUF_DATA_REN = !rRdState[2]; // Not S_SGR32_RD_0 assign VALID = rCapState[2]; // S_SGR32_CAP_RDY assign EMPTY = (BUF_DATA_EMPTY & !rRdState[2]); // Not S_SGR32_RD_0 assign ADDR = rAddr; assign LEN = rLen; // Capture address and length as it comes out of the FIFO always @ (posedge CLK) begin rRdState <= #1 (RST ? `S_SGR32_RD_0 : _rRdState); rCapState <= #1 (RST ? `S_SGR32_CAP_0 : _rCapState); rData <= #1 _rData; rFifoValid <= #1 (RST ? 1'd0 : _rFifoValid); rDataValid <= #1 (RST ? 1'd0 : _rDataValid); rAddr <= #1 _rAddr; rLen <= #1 _rLen; end always @ (*) begin _rRdState = rRdState; _rCapState = rCapState; _rAddr = rAddr; _rLen = rLen; _rData = BUF_DATA; _rFifoValid = (BUF_DATA_REN & !BUF_DATA_EMPTY); _rDataValid = rFifoValid; case (rCapState) `S_SGR32_CAP_0: begin if (rDataValid) begin _rAddr[31:0] = rData; _rCapState = `S_SGR32_CAP_1; end end `S_SGR32_CAP_1: begin if (rDataValid) begin _rAddr[63:32] = rData; _rCapState = `S_SGR32_CAP_2; end end `S_SGR32_CAP_2: begin if (rDataValid) begin _rLen = rData; _rCapState = `S_SGR32_CAP_3; end end `S_SGR32_CAP_3: begin if (rDataValid) _rCapState = `S_SGR32_CAP_RDY; end `S_SGR32_CAP_RDY: begin if (REN) _rCapState = `S_SGR32_CAP_0; end default: begin _rCapState = `S_SGR32_CAP_0; end endcase case (rRdState) `S_SGR32_RD_0: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR32_RD_1; end `S_SGR32_RD_1: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR32_RD_2; end `S_SGR32_RD_2: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR32_RD_3; end `S_SGR32_RD_3: begin // Read from the sg data FIFO if (!BUF_DATA_EMPTY) _rRdState = `S_SGR32_RD_WAIT; end `S_SGR32_RD_WAIT: begin // Wait for the data to be consumed if (REN) _rRdState = `S_SGR32_RD_0; end default: begin _rRdState = `S_SGR32_RD_0; end endcase end endmodule
// This file ONLY is placed into the Public Domain, for any use, // without warranty, 2013. module t ( input logic clk, input logic daten, input logic [8:0] datval, output logic signed [3:0][3:0][35:0] datao ); logic signed [3:0][3:0][3:0][8:0] datat; genvar i; generate for (i=0; i<4; i++)begin testio dut(.clk(clk), .arr3d_in(datat[i]), .arr2d_out(datao[i])); end endgenerate genvar j; generate for (i=0; i<4; i++) begin for (j=0; j<4; j++) begin always_comb datat[i][j][0] = daten ? 9'h0 : datval; always_comb datat[i][j][1] = daten ? 9'h1 : datval; always_comb datat[i][j][2] = daten ? 9'h2 : datval; always_comb datat[i][j][3] = daten ? 9'h3 : datval; end end endgenerate endmodule module testio ( input clk, input logic signed [3:0] [3:0] [8:0] arr3d_in, output logic signed [3:0] [35:0] arr2d_out ); logic signed [3:0] [35:0] ar2d_out_pre; always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]}; always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]}; always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]}; always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]}; always_ff @(posedge clk) begin if (clk) arr2d_out <= ar2d_out_pre; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_buffer_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Wraps a FIFO for saving channel data and provides a // registered read output. Retains unread words from reads that are a length // which is not a multiple of the data bus width (C_FIFO_DATA_WIDTH). Data is // available 5 cycles after RD_EN is asserted (not 1, like a traditional FIFO). // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module tx_port_buffer_64 #( parameter C_FIFO_DATA_WIDTH = 9'd64, parameter C_FIFO_DEPTH = 512, // Local parameters parameter C_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_FIFO_DEPTH))+1), parameter C_RD_EN_HIST = 2, parameter C_FIFO_RD_EN_HIST = 2, parameter C_CONSUME_HIST = 3, parameter C_COUNT_HIST = 3, parameter C_LEN_LAST_HIST = 1 ) ( input RST, input CLK, input LEN_VALID, // Transfer length is valid input [0:0] LEN_LSB, // LSBs of transfer length input LEN_LAST, // Last transfer in transaction input [C_FIFO_DATA_WIDTH-1:0] WR_DATA, // Input data input WR_EN, // Input data write enable output [C_FIFO_DEPTH_WIDTH-1:0] WR_COUNT, // Input data FIFO is full output [C_FIFO_DATA_WIDTH-1:0] RD_DATA, // Output data input RD_EN // Output data read enable ); `include "functions.vh" reg [1:0] rRdPtr=0, _rRdPtr=0; reg [1:0] rWrPtr=0, _rWrPtr=0; reg [3:0] rLenLSB=0, _rLenLSB=0; reg [3:0] rLenLast=0, _rLenLast=0; reg rLenValid=0, _rLenValid=0; reg rRen=0, _rRen=0; reg [1:0] rCount=0, _rCount=0; reg [(C_COUNT_HIST*2)-1:0] rCountHist={C_COUNT_HIST{2'd0}}, _rCountHist={C_COUNT_HIST{2'd0}}; reg [C_LEN_LAST_HIST-1:0] rLenLastHist={C_LEN_LAST_HIST{1'd0}}, _rLenLastHist={C_LEN_LAST_HIST{1'd0}}; reg [C_RD_EN_HIST-1:0] rRdEnHist={C_RD_EN_HIST{1'd0}}, _rRdEnHist={C_RD_EN_HIST{1'd0}}; reg rFifoRdEn=0, _rFifoRdEn=0; reg [C_FIFO_RD_EN_HIST-1:0] rFifoRdEnHist={C_FIFO_RD_EN_HIST{1'd0}}, _rFifoRdEnHist={C_FIFO_RD_EN_HIST{1'd0}}; reg [(C_CONSUME_HIST*2)-1:0] rConsumedHist={C_CONSUME_HIST{2'd0}}, _rConsumedHist={C_CONSUME_HIST{2'd0}}; reg [C_FIFO_DATA_WIDTH-1:0] rFifoData={C_FIFO_DATA_WIDTH{1'd0}}, _rFifoData={C_FIFO_DATA_WIDTH{1'd0}}; reg [95:0] rData=96'd0, _rData=96'd0; wire [C_FIFO_DATA_WIDTH-1:0] wFifoData; assign RD_DATA = rData[0 +:C_FIFO_DATA_WIDTH]; // Buffer the input signals that come from outside the tx_port. always @ (posedge CLK) begin rLenValid <= #1 (RST ? 1'd0 : _rLenValid); rRen <= #1 (RST ? 1'd0 : _rRen); end always @ (*) begin _rLenValid = LEN_VALID; _rRen = RD_EN; end // FIFO for storing data from the channel. (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_FIFO_DATA_WIDTH), .C_DEPTH(C_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) fifo ( .CLK(CLK), .RST(RST), .WR_EN(WR_EN), .WR_DATA(WR_DATA), .FULL(), .COUNT(WR_COUNT), .RD_EN(rFifoRdEn), .RD_DATA(wFifoData), .EMPTY() ); // Manage shifting of data in from the FIFO and shifting of data out once // it is consumed. We'll keep 3 words of output registers to hold an input // packet with up to 1 extra word of unread data. wire wLenOdd = rLenLSB[rRdPtr]; wire wLenLast = rLenLast[rRdPtr]; wire wAfterEnd = (!rRen & rRdEnHist[0]); wire [1:0] wConsumed = ({(rRdEnHist[0] | (!rRdEnHist[0] & rRdEnHist[1] & rLenLastHist[0])), 1'd0}) - (wAfterEnd & wLenOdd); always @ (posedge CLK) begin rCount <= #1 (RST ? 2'd0 : _rCount); rCountHist <= #1 _rCountHist; rRdEnHist <= #1 (RST ? {C_RD_EN_HIST{1'd0}} : _rRdEnHist); rFifoRdEn <= #1 (RST ? 1'd0 : _rFifoRdEn); rFifoRdEnHist <= #1 (RST ? {C_FIFO_RD_EN_HIST{1'd0}} : _rFifoRdEnHist); rConsumedHist <= #1 _rConsumedHist; rLenLastHist <= #1 (RST ? {C_LEN_LAST_HIST{1'd0}} : _rLenLastHist); rFifoData <= #1 _rFifoData; rData <= #1 _rData; end always @ (*) begin // Keep track of words in our buffer. Subtract 2 when we reach 2 on RD_EN. // Add 1 when we finish a sequence of RD_EN that read an odd number of words. _rCount = rCount + (wAfterEnd & wLenOdd & !wLenLast) - ({rRen & rCount[1], 1'd0}) - ({(wAfterEnd & wLenLast)&rCount[1], (wAfterEnd & wLenLast)&rCount[0]}); _rCountHist = ((rCountHist<<2) | rCount); // Track read enables in the pipeline. _rRdEnHist = ((rRdEnHist<<1) | rRen); _rFifoRdEnHist = ((rFifoRdEnHist<<1) | rFifoRdEn); // Track delayed length last value _rLenLastHist = ((rLenLastHist<<1) | wLenLast); // Calculate the amount to shift out each RD_EN. This is always 2 unless // it's the last RD_EN in the sequence and the read words length is odd. _rConsumedHist = ((rConsumedHist<<2) | wConsumed); // Read from the FIFO unless we have 2 words cached. _rFifoRdEn = (!rCount[1] & rRen); // Buffer the FIFO data. _rFifoData = wFifoData; // Shift the buffered FIFO data into and the consumed data out of the output register. if (rFifoRdEnHist[1]) _rData = ((rData>>({rConsumedHist[5:4], 5'd0})) | (rFifoData<<({rCountHist[4], 5'd0}))); else _rData = (rData>>({rConsumedHist[5:4], 5'd0})); end // Buffer up to 4 length LSB values for use to detect unread data that was // part of a consumed packet. Should only need 2. This is basically a FIFO. always @ (posedge CLK) begin rRdPtr <= #1 (RST ? 2'd0 : _rRdPtr); rWrPtr <= #1 (RST ? 2'd0 : _rWrPtr); rLenLSB <= #1 _rLenLSB; rLenLast <= #1 _rLenLast; end always @ (*) begin _rRdPtr = (wAfterEnd ? rRdPtr + 1'd1 : rRdPtr); _rWrPtr = (rLenValid ? rWrPtr + 1'd1 : rWrPtr); _rLenLSB = rLenLSB; _rLenLSB[rWrPtr] = (rLenValid ? (~LEN_LSB + 1'd1) : rLenLSB[rWrPtr]); _rLenLast = rLenLast; _rLenLast[rWrPtr] = (rLenValid ? LEN_LAST : rLenLast[rWrPtr]); end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_buffer_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Wraps a FIFO for saving channel data and provides a // registered read output. Retains unread words from reads that are a length // which is not a multiple of the data bus width (C_FIFO_DATA_WIDTH). Data is // available 5 cycles after RD_EN is asserted (not 1, like a traditional FIFO). // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module tx_port_buffer_64 #( parameter C_FIFO_DATA_WIDTH = 9'd64, parameter C_FIFO_DEPTH = 512, // Local parameters parameter C_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_FIFO_DEPTH))+1), parameter C_RD_EN_HIST = 2, parameter C_FIFO_RD_EN_HIST = 2, parameter C_CONSUME_HIST = 3, parameter C_COUNT_HIST = 3, parameter C_LEN_LAST_HIST = 1 ) ( input RST, input CLK, input LEN_VALID, // Transfer length is valid input [0:0] LEN_LSB, // LSBs of transfer length input LEN_LAST, // Last transfer in transaction input [C_FIFO_DATA_WIDTH-1:0] WR_DATA, // Input data input WR_EN, // Input data write enable output [C_FIFO_DEPTH_WIDTH-1:0] WR_COUNT, // Input data FIFO is full output [C_FIFO_DATA_WIDTH-1:0] RD_DATA, // Output data input RD_EN // Output data read enable ); `include "functions.vh" reg [1:0] rRdPtr=0, _rRdPtr=0; reg [1:0] rWrPtr=0, _rWrPtr=0; reg [3:0] rLenLSB=0, _rLenLSB=0; reg [3:0] rLenLast=0, _rLenLast=0; reg rLenValid=0, _rLenValid=0; reg rRen=0, _rRen=0; reg [1:0] rCount=0, _rCount=0; reg [(C_COUNT_HIST*2)-1:0] rCountHist={C_COUNT_HIST{2'd0}}, _rCountHist={C_COUNT_HIST{2'd0}}; reg [C_LEN_LAST_HIST-1:0] rLenLastHist={C_LEN_LAST_HIST{1'd0}}, _rLenLastHist={C_LEN_LAST_HIST{1'd0}}; reg [C_RD_EN_HIST-1:0] rRdEnHist={C_RD_EN_HIST{1'd0}}, _rRdEnHist={C_RD_EN_HIST{1'd0}}; reg rFifoRdEn=0, _rFifoRdEn=0; reg [C_FIFO_RD_EN_HIST-1:0] rFifoRdEnHist={C_FIFO_RD_EN_HIST{1'd0}}, _rFifoRdEnHist={C_FIFO_RD_EN_HIST{1'd0}}; reg [(C_CONSUME_HIST*2)-1:0] rConsumedHist={C_CONSUME_HIST{2'd0}}, _rConsumedHist={C_CONSUME_HIST{2'd0}}; reg [C_FIFO_DATA_WIDTH-1:0] rFifoData={C_FIFO_DATA_WIDTH{1'd0}}, _rFifoData={C_FIFO_DATA_WIDTH{1'd0}}; reg [95:0] rData=96'd0, _rData=96'd0; wire [C_FIFO_DATA_WIDTH-1:0] wFifoData; assign RD_DATA = rData[0 +:C_FIFO_DATA_WIDTH]; // Buffer the input signals that come from outside the tx_port. always @ (posedge CLK) begin rLenValid <= #1 (RST ? 1'd0 : _rLenValid); rRen <= #1 (RST ? 1'd0 : _rRen); end always @ (*) begin _rLenValid = LEN_VALID; _rRen = RD_EN; end // FIFO for storing data from the channel. (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_FIFO_DATA_WIDTH), .C_DEPTH(C_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) fifo ( .CLK(CLK), .RST(RST), .WR_EN(WR_EN), .WR_DATA(WR_DATA), .FULL(), .COUNT(WR_COUNT), .RD_EN(rFifoRdEn), .RD_DATA(wFifoData), .EMPTY() ); // Manage shifting of data in from the FIFO and shifting of data out once // it is consumed. We'll keep 3 words of output registers to hold an input // packet with up to 1 extra word of unread data. wire wLenOdd = rLenLSB[rRdPtr]; wire wLenLast = rLenLast[rRdPtr]; wire wAfterEnd = (!rRen & rRdEnHist[0]); wire [1:0] wConsumed = ({(rRdEnHist[0] | (!rRdEnHist[0] & rRdEnHist[1] & rLenLastHist[0])), 1'd0}) - (wAfterEnd & wLenOdd); always @ (posedge CLK) begin rCount <= #1 (RST ? 2'd0 : _rCount); rCountHist <= #1 _rCountHist; rRdEnHist <= #1 (RST ? {C_RD_EN_HIST{1'd0}} : _rRdEnHist); rFifoRdEn <= #1 (RST ? 1'd0 : _rFifoRdEn); rFifoRdEnHist <= #1 (RST ? {C_FIFO_RD_EN_HIST{1'd0}} : _rFifoRdEnHist); rConsumedHist <= #1 _rConsumedHist; rLenLastHist <= #1 (RST ? {C_LEN_LAST_HIST{1'd0}} : _rLenLastHist); rFifoData <= #1 _rFifoData; rData <= #1 _rData; end always @ (*) begin // Keep track of words in our buffer. Subtract 2 when we reach 2 on RD_EN. // Add 1 when we finish a sequence of RD_EN that read an odd number of words. _rCount = rCount + (wAfterEnd & wLenOdd & !wLenLast) - ({rRen & rCount[1], 1'd0}) - ({(wAfterEnd & wLenLast)&rCount[1], (wAfterEnd & wLenLast)&rCount[0]}); _rCountHist = ((rCountHist<<2) | rCount); // Track read enables in the pipeline. _rRdEnHist = ((rRdEnHist<<1) | rRen); _rFifoRdEnHist = ((rFifoRdEnHist<<1) | rFifoRdEn); // Track delayed length last value _rLenLastHist = ((rLenLastHist<<1) | wLenLast); // Calculate the amount to shift out each RD_EN. This is always 2 unless // it's the last RD_EN in the sequence and the read words length is odd. _rConsumedHist = ((rConsumedHist<<2) | wConsumed); // Read from the FIFO unless we have 2 words cached. _rFifoRdEn = (!rCount[1] & rRen); // Buffer the FIFO data. _rFifoData = wFifoData; // Shift the buffered FIFO data into and the consumed data out of the output register. if (rFifoRdEnHist[1]) _rData = ((rData>>({rConsumedHist[5:4], 5'd0})) | (rFifoData<<({rCountHist[4], 5'd0}))); else _rData = (rData>>({rConsumedHist[5:4], 5'd0})); end // Buffer up to 4 length LSB values for use to detect unread data that was // part of a consumed packet. Should only need 2. This is basically a FIFO. always @ (posedge CLK) begin rRdPtr <= #1 (RST ? 2'd0 : _rRdPtr); rWrPtr <= #1 (RST ? 2'd0 : _rWrPtr); rLenLSB <= #1 _rLenLSB; rLenLast <= #1 _rLenLast; end always @ (*) begin _rRdPtr = (wAfterEnd ? rRdPtr + 1'd1 : rRdPtr); _rWrPtr = (rLenValid ? rWrPtr + 1'd1 : rWrPtr); _rLenLSB = rLenLSB; _rLenLSB[rWrPtr] = (rLenValid ? (~LEN_LSB + 1'd1) : rLenLSB[rWrPtr]); _rLenLast = rLenLast; _rLenLast[rWrPtr] = (rLenValid ? LEN_LAST : rLenLast[rWrPtr]); end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_buffer_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Wraps a FIFO for saving channel data and provides a // registered read output. Retains unread words from reads that are a length // which is not a multiple of the data bus width (C_FIFO_DATA_WIDTH). Data is // available 5 cycles after RD_EN is asserted (not 1, like a traditional FIFO). // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module tx_port_buffer_64 #( parameter C_FIFO_DATA_WIDTH = 9'd64, parameter C_FIFO_DEPTH = 512, // Local parameters parameter C_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_FIFO_DEPTH))+1), parameter C_RD_EN_HIST = 2, parameter C_FIFO_RD_EN_HIST = 2, parameter C_CONSUME_HIST = 3, parameter C_COUNT_HIST = 3, parameter C_LEN_LAST_HIST = 1 ) ( input RST, input CLK, input LEN_VALID, // Transfer length is valid input [0:0] LEN_LSB, // LSBs of transfer length input LEN_LAST, // Last transfer in transaction input [C_FIFO_DATA_WIDTH-1:0] WR_DATA, // Input data input WR_EN, // Input data write enable output [C_FIFO_DEPTH_WIDTH-1:0] WR_COUNT, // Input data FIFO is full output [C_FIFO_DATA_WIDTH-1:0] RD_DATA, // Output data input RD_EN // Output data read enable ); `include "functions.vh" reg [1:0] rRdPtr=0, _rRdPtr=0; reg [1:0] rWrPtr=0, _rWrPtr=0; reg [3:0] rLenLSB=0, _rLenLSB=0; reg [3:0] rLenLast=0, _rLenLast=0; reg rLenValid=0, _rLenValid=0; reg rRen=0, _rRen=0; reg [1:0] rCount=0, _rCount=0; reg [(C_COUNT_HIST*2)-1:0] rCountHist={C_COUNT_HIST{2'd0}}, _rCountHist={C_COUNT_HIST{2'd0}}; reg [C_LEN_LAST_HIST-1:0] rLenLastHist={C_LEN_LAST_HIST{1'd0}}, _rLenLastHist={C_LEN_LAST_HIST{1'd0}}; reg [C_RD_EN_HIST-1:0] rRdEnHist={C_RD_EN_HIST{1'd0}}, _rRdEnHist={C_RD_EN_HIST{1'd0}}; reg rFifoRdEn=0, _rFifoRdEn=0; reg [C_FIFO_RD_EN_HIST-1:0] rFifoRdEnHist={C_FIFO_RD_EN_HIST{1'd0}}, _rFifoRdEnHist={C_FIFO_RD_EN_HIST{1'd0}}; reg [(C_CONSUME_HIST*2)-1:0] rConsumedHist={C_CONSUME_HIST{2'd0}}, _rConsumedHist={C_CONSUME_HIST{2'd0}}; reg [C_FIFO_DATA_WIDTH-1:0] rFifoData={C_FIFO_DATA_WIDTH{1'd0}}, _rFifoData={C_FIFO_DATA_WIDTH{1'd0}}; reg [95:0] rData=96'd0, _rData=96'd0; wire [C_FIFO_DATA_WIDTH-1:0] wFifoData; assign RD_DATA = rData[0 +:C_FIFO_DATA_WIDTH]; // Buffer the input signals that come from outside the tx_port. always @ (posedge CLK) begin rLenValid <= #1 (RST ? 1'd0 : _rLenValid); rRen <= #1 (RST ? 1'd0 : _rRen); end always @ (*) begin _rLenValid = LEN_VALID; _rRen = RD_EN; end // FIFO for storing data from the channel. (* RAM_STYLE="BLOCK" *) sync_fifo #(.C_WIDTH(C_FIFO_DATA_WIDTH), .C_DEPTH(C_FIFO_DEPTH), .C_PROVIDE_COUNT(1)) fifo ( .CLK(CLK), .RST(RST), .WR_EN(WR_EN), .WR_DATA(WR_DATA), .FULL(), .COUNT(WR_COUNT), .RD_EN(rFifoRdEn), .RD_DATA(wFifoData), .EMPTY() ); // Manage shifting of data in from the FIFO and shifting of data out once // it is consumed. We'll keep 3 words of output registers to hold an input // packet with up to 1 extra word of unread data. wire wLenOdd = rLenLSB[rRdPtr]; wire wLenLast = rLenLast[rRdPtr]; wire wAfterEnd = (!rRen & rRdEnHist[0]); wire [1:0] wConsumed = ({(rRdEnHist[0] | (!rRdEnHist[0] & rRdEnHist[1] & rLenLastHist[0])), 1'd0}) - (wAfterEnd & wLenOdd); always @ (posedge CLK) begin rCount <= #1 (RST ? 2'd0 : _rCount); rCountHist <= #1 _rCountHist; rRdEnHist <= #1 (RST ? {C_RD_EN_HIST{1'd0}} : _rRdEnHist); rFifoRdEn <= #1 (RST ? 1'd0 : _rFifoRdEn); rFifoRdEnHist <= #1 (RST ? {C_FIFO_RD_EN_HIST{1'd0}} : _rFifoRdEnHist); rConsumedHist <= #1 _rConsumedHist; rLenLastHist <= #1 (RST ? {C_LEN_LAST_HIST{1'd0}} : _rLenLastHist); rFifoData <= #1 _rFifoData; rData <= #1 _rData; end always @ (*) begin // Keep track of words in our buffer. Subtract 2 when we reach 2 on RD_EN. // Add 1 when we finish a sequence of RD_EN that read an odd number of words. _rCount = rCount + (wAfterEnd & wLenOdd & !wLenLast) - ({rRen & rCount[1], 1'd0}) - ({(wAfterEnd & wLenLast)&rCount[1], (wAfterEnd & wLenLast)&rCount[0]}); _rCountHist = ((rCountHist<<2) | rCount); // Track read enables in the pipeline. _rRdEnHist = ((rRdEnHist<<1) | rRen); _rFifoRdEnHist = ((rFifoRdEnHist<<1) | rFifoRdEn); // Track delayed length last value _rLenLastHist = ((rLenLastHist<<1) | wLenLast); // Calculate the amount to shift out each RD_EN. This is always 2 unless // it's the last RD_EN in the sequence and the read words length is odd. _rConsumedHist = ((rConsumedHist<<2) | wConsumed); // Read from the FIFO unless we have 2 words cached. _rFifoRdEn = (!rCount[1] & rRen); // Buffer the FIFO data. _rFifoData = wFifoData; // Shift the buffered FIFO data into and the consumed data out of the output register. if (rFifoRdEnHist[1]) _rData = ((rData>>({rConsumedHist[5:4], 5'd0})) | (rFifoData<<({rCountHist[4], 5'd0}))); else _rData = (rData>>({rConsumedHist[5:4], 5'd0})); end // Buffer up to 4 length LSB values for use to detect unread data that was // part of a consumed packet. Should only need 2. This is basically a FIFO. always @ (posedge CLK) begin rRdPtr <= #1 (RST ? 2'd0 : _rRdPtr); rWrPtr <= #1 (RST ? 2'd0 : _rWrPtr); rLenLSB <= #1 _rLenLSB; rLenLast <= #1 _rLenLast; end always @ (*) begin _rRdPtr = (wAfterEnd ? rRdPtr + 1'd1 : rRdPtr); _rWrPtr = (rLenValid ? rWrPtr + 1'd1 : rWrPtr); _rLenLSB = rLenLSB; _rLenLSB[rWrPtr] = (rLenValid ? (~LEN_LSB + 1'd1) : rLenLSB[rWrPtr]); _rLenLast = rLenLast; _rLenLast[rWrPtr] = (rLenValid ? LEN_LAST : rLenLast[rWrPtr]); end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: ff.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: A D/Q flip flop. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module ff ( input CLK, input D, output reg Q ); always @ (posedge CLK) begin Q <= #1 D; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REGENTS OF THE // UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH // DAMAGE. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: ff.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: A D/Q flip flop. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `timescale 1ns/1ns module ff ( input CLK, input D, output reg Q ); always @ (posedge CLK) begin Q <= #1 D; end endmodule