Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A chapter from the book 'vhdl in action' by martin, covering packages and libraries in vhdl. The chapter explains the motivation for using packages and libraries, the concept of packages and their declaration and body, and the use of packages in vhdl. It also introduces textio, a package for file i/o in vhdl. Examples of package declarations and bodies, as well as the use of textio for reading data from a file.
Typology: Study notes
1 / 6
Martin 2003 (^2)
Martin 2003 (^3)
Martin 2003 (^4)
Martin 2003 (^7)
Martin 2003 (^8)
Martin 2003 (^9)
PACKAGE sub_std_logic_1164 IS TYPE std_ulogic IS ( 'U', --uninitialized 'X', -- forcing unknown '0', -- forcing 0 '1', -- forcing 1 'Z', -- high impedance 'W', -- weak unknown 'L', -- weak low 'H', -- weak high '-' -- don't care ); Martin 2003 (^10)
TYPE std_ulogic_vector IS ARRAY (Natural RANGE <>) OF std_ulogic;
FUNCTION "AND" ( l, r : std_ulogic) RETURN std_ulogic; FUNCTION "AND" ( l, r : std_ulogic_vector) RETURN std_ulogic_vector; FUNCTION "AND" ( l : std_ulogic_vector, r : std_ulogic) RETURN std_ulogic_vector; COMPONENT dff PORT ( d, clk : IN std_ulogic; q : OUT std_ulogic); END COMPONENT; END sub_std_logic_1164;
PACKAGE BODY sub_std_logic_1164 IS FUNCTION "AND" ( l, r : std_ulogic) RETURN std_ulogic IS VARIABLE tmp : std_ulogic; BEGIN tmp := ‘1’ WHEN l = ‘1’ AND r=‘1’ ELSE ‘0’ WHEN l=‘0’ OR r=‘0’ ELSE ‘X’; RETURN( tmp); END “AND”; o o
FUNCTION "AND" ( l, r : std_ulogic_vector) RETURN std_ulogic_vector IS VARIABLE tmp : std_ulogic_vector; BEGIN ASSERT l’range = r’range; REPORT “Ranges must be equal for vector AND”; SEVERITY ERROR; FOR k in l’range LOOP tmp(k) := l(k) AND r(k); END LOOP; RETURN tmp; END “AND”;
Martin 2003 (^13)
FUNCTION "AND" ( l: std_ulogic_vector; r: std_ulogic) RETURN std_ulogic_vector IS VARIABLE tmp : std_ulogic_vector; BEGIN FOR k in l’range LOOP tmp(k) := l(k) AND r; END LOOP; RETURN tmp; END “AND”;
END sub_std_logic_1164;
Martin 2003 (^14)
Martin 2003 (^15)
Martin 2003 (^16)
z Design units are analyzed (compiled) and placed in libraries z Logical library names map to physical directories z Libraries STD and WORK are implicitly declared, i.e. don't have to have "LIBRARY WORK;" in file
z When multiple design units are in the same file, visibility of libraries and packages must be established for each primary design unit (entity, package header, configuration) separately! z The use clause may selectively establish visibility, e.g., only the function rising_ edge() is visible within entity design-
library IEEE; entity test_libs is port (clk : in bit; data_out : out bit); end test_libs; architecture oh_no of test_libs is -- use ieee.std_logic_1164.all; signal s1 : std_logic; begin s1 <= '0'; end oh_no;
Uncomment this line to compile correctly
Martin 2003 (^19)
entity test_libs2 is port (clk : in bit; data_out : out bit); end test_libs2;
architecture oh_no of test_libs2 is library ieee; use ieee.std_logic_1164.all; signal s1 : std_logic; begin s1 <= '0'; end oh_no;
With this, a hierarchy of packages can be created.
Martin 2003 (^21)
Martin 2003 (^22)
PACKAGE sig IS SIGNAL x : Integer := 1; END sig;
USE work.sig; -- Package sig made visible ENTITY y IS SIGNAL x : Integer := 2; END y;
ARCHITECTURE z OF y IS SIGNAL z1, z2, z3, z4, z5 : Integer := 0; FUNCTION R RETURN INTEGER IS VARIABLE x : Integer := 3; BEGIN RETURN x; -- When R called, 3 returned END R;
VARIABLE x : Integer := 5; BEGIN z5 <= x; -- z5 = 5 WAIT; END PROCESS; z1 <= WORK.SIG.x; -- z1 = 1 z2 <= x; -- z2 = 2 z3 <= R; -- z3 = 3 z4 <= B.x; -- z4 = 4 END z;
Martin 2003 (^25)
Martin 2003 (^27)
Martin 2003 (^28)
include $CDS_INST_DIR/tools/inca/files/cds.lib define work C:/tom/courses/4514f03/other_code/work
DEFINE std ./STD DEFINE synopsys ./SYNOPSYS DEFINE ieee ./IEEE DEFINE ambit ./AMBIT
LIBRARY WORK; -- Automatic in all VHDL models LIBRARY IEEE;
USE IEEE.Std_Logic_1164.ALL; -- In the library IEEE, make the package -- STD_LOGIC_1164 visible to the -- following entity.
Martin 2003 (^31)
Martin 2003 (^32)
Martin 2003 (^33)
procedure read_v1d(variable f:in text; v:out std_logic_vector) is variable buf : line; variable c : character ; begin -- do not forget appropriate library declarations readline (f , buf ); --read a line from the file. for i in v ’range loop read( buf , c ) ; --read a character from the line. case c is when ‘X’ => v (i) := ‘X’ ; when ‘U’ => v (i) := ‘U’ ; when ‘Z’ => v (i) := ‘Z’ ; when ‘0’ => v (i) := ‘0’ ; when ‘1’ => v (i) := ‘1’ ; when ‘-’ => v (i) := ‘-’ ; when ‘W’ => v (i) := ‘W’ ; when ‘L’ => v (i) := ‘L’ ; when ‘H’ => v (i) := ‘H’ ; when others => v (i) := ‘0 ’; end case; end loop; end; (From Yalamanchili) Martin 2003 (^34)
Martin 2003 (^35)