Docsity

VHDL Generic Constants: Writing Parameterized Models, Slides of Computer Science

Partial preview of the text

Download VHDL Generic Constants: Writing Parameterized Models and more Slides Computer Science in PDF only on Docsity!

Generic Constants

Generic Constants

• VHDL provides programmers with a generic

mechanism for writing parameterized

models

• Generic Mechanism

  • Generic Entity Declaration
  • Generic Component Instantiation

entity and2 is

generic ( Tpd : time );

port ( a, b : in bit; y : out bit );

end entity and2;

architecture simple of and2 is

begin

and2_function :

y <= a and b after Tpd;

end architecture simple;

Parameterized Behavior

• A generic constant is given an actual value

when the entity is used in a component

instantiation by using “generic map”

• EBNF: see page 311

• Example

Fig 12. entity control_unit is generic ( Tpd_clk_out, Tpw_clk : delay_length; debug : boolean := false ); port ( clk : in bit; ready : in bit; control1, control2 : out bit ); end entity control_unit;


dut1 : entity work.control_unit generic map ( 200 ps, 1500 ps, false ) port map ( clk, ready, open, open ); dut2 : entity work.control_unit generic map ( Tpd_clk_out => 200 ps, Tpw_clk => 1500 ps ) port map ( clk, ready, open, open ); dut3 : entity work.control_unit generic map ( 200 ps, 1500 ps, debug => open ) port map ( clk, ready, open, open );

Fig 12. entity D_flipflop is generic ( Tpd_clk_q, Tsu_d_clk, Th_d_clk : delay_length ); port ( clk, d : in bit; q : out bit ); end entity D_flipflop;


architecture basic of D_flipflop is begin behavior : q <= d after Tpd_clk_q when clk = '1' and clk'event; check_setup : process is begin wait until clk = '1'; assert d'last_event >= Tsu_d_clk report "setup violation"; end process check_setup; check_hold : process is begin wait until clk'delayed(Th_d_clk) = '1'; assert d'delayed'last_event >= Th_d_clk report "hold violation"; end process check_hold; end architecture basic;

Parameterized Structure

• Generic Constant can be used to specify the

size of an array port

  • That is to parameterize structure

• Example: reg in next page

entity reg is generic ( width : positive ); port ( d : in bit_vector(0 to width - 1); q : out bit_vector(0 to width - 1); --... ); ….


architecture test of ch_12_03 is constant bus_size : positive := 16; signal in_data, out_data : bit_vector(0 to bus_size - 1); Begin … ok_reg : entity work.reg generic map ( width => bus_size ) port map ( d => in_data, q => out_data, --... ); … END .. Docsity.com

Fig 12. word_reg : entity work.reg(behavioral) generic map ( width => 32 ) port map ( --... );


subtype state_vector is bit_vector(1 to 5); state_reg : entity work.reg(behavioral) generic map ( width => state_vector'length ) port map ( --... );