當(dāng)使用庫(kù)時(shí),需要說(shuō)明使用的庫(kù)名稱(chēng),同時(shí)需要說(shuō)明庫(kù)中包集合的名稱(chēng)及范圍; 每個(gè)實(shí)體都應(yīng)獨(dú)立進(jìn)行庫(kù)的說(shuō)明;庫(kù)的說(shuō)明應(yīng)該在實(shí)體之前;經(jīng)過(guò)說(shuō)明后,實(shí)體和結(jié)構(gòu)體就可以自動(dòng)調(diào)用庫(kù)中的資源.
首先說(shuō)明總庫(kù),語(yǔ)句格式 library 庫(kù)名,例如 : library ieee;
其次調(diào)用總庫(kù)中的子庫(kù),用 use調(diào)取,格式:USE 庫(kù)名范圍(或項(xiàng)目名); 如use ieee.std_logic_1164.all。
VHDL中庫(kù)的主要種類(lèi): IEEE庫(kù) 、STD庫(kù) 、ASIC庫(kù)、 work庫(kù) 、用戶(hù)定義庫(kù) 和IEEE庫(kù): 含有IEEE的標(biāo)準(zhǔn)包集合“STD_LOGIC_1164”以及一些大公司提供的包集合;使用前必須說(shuō)明; 例: library ieee; use ieee.std_logic_1164.all; 使用標(biāo)準(zhǔn)邏輯量的定義和運(yùn)算; use ieee.std_logic_unsigned.all; 無(wú)符號(hào)數(shù)算術(shù)運(yùn)算的定義; use ieee.std_logic_arith.all; 使用符號(hào)數(shù)算術(shù)運(yùn)算的定義。
STD庫(kù): 含有“STANDARD”包集合和“TEXTIO”包集合,使用前者時(shí)無(wú)需說(shuō)明;
ASIC庫(kù): 由各公司提供,存放與邏輯門(mén)一一對(duì)應(yīng)的實(shí)體,用于ASIC設(shè)計(jì)的門(mén)級(jí)仿真,使用時(shí)需加以說(shuō)明; 例 library altera; use altera.maxplus2.all; library lpm; use lpm.lpm_components.all;
WORK庫(kù): WORK庫(kù)為現(xiàn)行作業(yè)庫(kù),位于當(dāng)前使用時(shí)設(shè)計(jì)文件的指定保存目錄; WORK使用時(shí)通常無(wú)須說(shuō)明;但在結(jié)構(gòu)設(shè)計(jì)中進(jìn)行元件的宏調(diào)用時(shí)需要說(shuō)明; 例:use work.all;
用戶(hù)定義庫(kù): 由用戶(hù)自定義生成,使用時(shí)需說(shuō)明(指定庫(kù)所在的路徑);
package 包集合:用于羅列VHDL語(yǔ)言中使用的類(lèi)型定義、信號(hào)定義、常數(shù)定義、元件定義、函數(shù)定義和過(guò)程定義等(類(lèi)似于C語(yǔ)言中的include語(yǔ)句),方便不同模塊的設(shè)計(jì)中公共定義的共享。
數(shù)字電路設(shè)計(jì)中經(jīng)常使用的包集合: ieee.std_logic_1164 .all;邏輯量的定義 ieee.std_logic_arith.all; 數(shù)據(jù)轉(zhuǎn)換,邏輯判斷 ieee.std_logic_unsigned ;算術(shù)運(yùn)算 std.textio ;
文本數(shù)據(jù)輸入/輸出格式 包集合在使用前必須采用use語(yǔ)句進(jìn)行說(shuō)明(在設(shè)計(jì)程序的最前面); 包集合可以由用戶(hù)自定義; 包的結(jié)構(gòu)與定義:(用戶(hù)自定義的包集合) 包集合標(biāo)題+(包集合體) 包集合標(biāo)題: package 包集合名 is 說(shuō)明語(yǔ)句; (只有名稱(chēng)) end 包集合名; 包集合體: package body包集合名 is 說(shuō)明語(yǔ)句; (完整定義) end 包集合名; 例:( 函數(shù)取自p.279 表4-38 ) library ieee; use ieee.std_logic_1164.all; packge upac is constant k: integer := 4; subtype cpu_bus is std_logic_vector(k-1downto 0); function conv_integer (x:std_logic_vector) return integer; end upac; packge body upac is function conv_integer (x: std_logic_vector) return integer is variable result: integer; begin result := 0; for I in x'range loop result :=result*2; case x(i) is when '0'|'L' => null; when '1'|'H' => result := result+1; when others => null; end case; end loop; return result; end conv_integer; end upac; 用戶(hù)自行編寫(xiě)的包集合將自動(dòng)存放于WORK庫(kù)中,使用時(shí)可采用下列語(yǔ)句調(diào)用 use work.upac.all; configuration 配置 在一個(gè)實(shí)體內(nèi)可以編寫(xiě)多種不同的構(gòu)造體,通過(guò)配置語(yǔ)句來(lái)進(jìn)行選擇; 配置語(yǔ)句格式: configuration 配置名 of 實(shí)體名 is for 選擇的構(gòu)造體名 end for; end 配置名; 此語(yǔ)句可以為設(shè)計(jì)增加更大的靈活性,可以對(duì)不同構(gòu)造體進(jìn)行比較。