Az előadás letöltése folymat van. Kérjük, várjon

Az előadás letöltése folymat van. Kérjük, várjon

Könyvtár, csomag és alprogramokVHDL Könyvtár, csomag és alprogram n Library és use n Package n Alprogramok –Procedure –Function –Resolution function Egy.

Hasonló előadás


Az előadások a következő témára: "Könyvtár, csomag és alprogramokVHDL Könyvtár, csomag és alprogram n Library és use n Package n Alprogramok –Procedure –Function –Resolution function Egy."— Előadás másolata:

1 Könyvtár, csomag és alprogramokVHDL Könyvtár, csomag és alprogram n Library és use n Package n Alprogramok –Procedure –Function –Resolution function Egy mintacsomag és alkalmazása Egy mintacsomag és alkalmazása

2 Könyvtár, csomag és alprogramokVHDL Use utasítás n use_clause ::= use selected name {, selected_name } ; n Examples: –USE work.my_package. ALL ; »All elements of the package my_package from the library work are integrated. –USE work.my_package.my_function ; »The function my_function from the package my_package in the library work is integrated.

3 Könyvtár, csomag és alprogramokVHDL Csomagok (packages) Its purpose to create shared modules. n Type and Subtype Declarations n Subprograms (functions and procedures) n Constants n Signals

4 Könyvtár, csomag és alprogramokVHDL

5 Könyvtár, csomag és alprogramokVHDL Placing a library clause at the end of the design file entity to identify a logical name for each referenced library designating a logical-to-physical map to identify where in the directory structure the physical library resides. (Each VHDL implementation has a specific method of making this map) Putting the use clause where the specific package contents are required. Syntax: LIBRARY logical_name_list ; USE prefix.suffix,prefix.suffix… ; Egy csomag láthatóvá tétele

6 Könyvtár, csomag és alprogramokVHDL Kérdések a csomagokról n Az std könyvtárban és a standard csomagban n Melyik könyvtárban és csomagban definiálják a bit típust? n Melyik könyvtár(ak) és csomag(ok) látható(k) állandóan? A work és az std könyvtárak és az std.standard.ALL; csomag n A következőket lehet csomagokban tárolni: Függvények, eljárások (procedure, típus deklarációk és állandók n Egy csomag felhasználásához a következőket kell megadni: Library ; Use..ALL;

7 Könyvtár, csomag és alprogramokVHDL Alprogram típusok n FUNCTIONS –Produce no side-effects –Only accept input (in) parameters –Return just one value –Always use the reserved word return n PROCEDURES –Can produce side-effects –Accept input (in), output (out) and input/output (inout) parameters –Do not have to return any value or can return multiple values –Do not require return

8 Könyvtár, csomag és alprogramokVHDL Egyidejű procedure hívás utasítás n concurrent_procedure_call ::= [ label : ] [ postponed ] procedure_call ; n Examples: –a_proc ; –Procedure call without transfer parameters –lab : my_proc( sig_1, sig_2, sig_3 ) ; –Named procedure call with transfer parameters which are linked by position.

9 Könyvtár, csomag és alprogramokVHDL Sorrendi procedure hívás utasítás n procedure_call_statement ::= n [ label : ] procedure_call ; n Examples: –a_proc ; –The procedure a_proc is called; it does not have any transfer parameters. –my_proc( sig_1, sig_2, var_3 ) ; –The procedure my_proc is called with the transfer parameters sig_1, sig_2, var_3.

10 Könyvtár, csomag és alprogramokVHDL Return utasítás n return_statement ::= [ label : ] return [ expression ] ; n Examples: –RETURN ; »No value is returned. –RETURN value ; »The return value is that of value. –RETURN my_function( data, 5 pF ) ; »The return value is the result of the function my_function –RETURN a + b + 5 ns ; »The return value is the sum a + b + 5 ns. –RETURN "author name : " & name ; »The return value is a chained string.

11 Könyvtár, csomag és alprogramokVHDL Függvény meghatározása n Egy példa: function f(signal a,b: std_logic) return std_logic is begin if a’event then if a’event then return b; return b; else else return a; return a; end if; end if; end; n A függvény meghatározásban (ahogy a példa is mutatja) lehet több return utasítás is, a feltétel az, hogy csak egy hajtódik végre n A példában azért kellett a “signal” jelölés, mert ki kellett zárni, hogy változók (variable) legyenek a paraméterek, amelyek nem megengedettek pl. egyidejű függvény hívásban n Hol lehet meghatározni egy függvényt? Csomagban, építményben és folyamatban, ezek közül a csomagban meghatározottat máshol újra fel lehet használni

12 Könyvtár, csomag és alprogramokVHDL Függvény meghatározása csomagban package mypack is function max (a,b: in std_logic_vector) return std_logic_vector; function max (a,b: in std_logic_vector) return std_logic_vector;end; package body mypack is function max (a,b: in std_logic_vector) return std_logic_vector is function max (a,b: in std_logic_vector) return std_logic_vector is begin begin if a>b then if a>b then return a; return a; else else return b; return b; end if; end if; end; end;end;

13 Könyvtár, csomag és alprogramokVHDL A csomagbeli függvény alkalmazása Use work.mypack.ALL; Entity ex is port(... port(...end; Architecture rtl of ex is begin...... q<=max(d1,d2);-- Egyidejű függvényhívás q<=max(d1,d2);-- Egyidejű függvényhívás process (data,g) process (data,g) begin begin data_out<=max(data,g);-- Sorrendi függvényhívás data_out<=max(data,g);-- Sorrendi függvényhívás end process; end process;end;

14 Könyvtár, csomag és alprogramokVHDL Függvény megadása építményben Architecture rtl of ex2 is function max (a,b: in std_logic_vector) return std_logic_vector is function max (a,b: in std_logic_vector) return std_logic_vector is begin begin if a>b then if a>b then return a; return a; else else return b; return b; end max;......begin q<=max(d1,d2);-- Egyidejű függvényhívás q<=max(d1,d2);-- Egyidejű függvényhívás process(data,g) process(data,g) begin begin data_out<=max(data,g)-- Sorrendi függvényhívás data_out<=max(data,g)-- Sorrendi függvényhívás end process; end process;......end;

15 Könyvtár, csomag és alprogramokVHDL Függvény megadása folyamatban Architecture rtl of ex3 is begin-- Építmény test kezdete process(data,g) process(data,g) function max (a,b: in std_logic_vector) return std_logic_vector is function max (a,b: in std_logic_vector) return std_logic_vector is begin begin if a>b then if a>b then return a; return a; else else return b; return b; end max; begin-- A folyamat kezdete data_out<=max(data,g); data_out<=max(data,g); end process;......end;

16 Könyvtár, csomag és alprogramokVHDL A függvénymegadás paraméterezése n A függvényeket és az eljárásokat rendszerint úgy határozzák meg, hogy a be/kimenetei paraméterek vektorhosszait nem adják meg n Így tetszőleges vektor hosszúságú adatokkal felhasználhatók Library ieee; use ieee.std_logic_1164.ALL; use work.mypack.ALL; Entity ex is port (a,b: in std_logic_vector(3 downto0); c,d: in std_logic_vector(5 downto 0); port (a,b: in std_logic_vector(3 downto0); c,d: in std_logic_vector(5 downto 0); q1: out std_logic_vector(3 downto0); q2: out std_logic_vector(5 downto 0)); q1: out std_logic_vector(3 downto0); q2: out std_logic_vector(5 downto 0));end; Architecture rtl of ex is begin q1<=max(a,b);-- A vektor hosszúság 4 bit q1<=max(a,b);-- A vektor hosszúság 4 bit q2<=max(c,d);-- A vektor hosszúság 6 bit q2<=max(c,d);-- A vektor hosszúság 6 bitend;

17 Könyvtár, csomag és alprogramokVHDL  It is possible that a model contains more than one signal assignment statement that attempts to assign different values to the same signal at the same time.  When this happens, the model must provide a resolution function that specifies how to resolve the assignment.  Each signal that requires a resolution function, makes reference to the appropriate function in the signal declaration. Example: SIGNAL total : wired_or integer; This signal declaration refers to a resolution function named “wired_or” Egy jelérték feloldása, amikor több hozzárendelés utasítás hajtja meg

18 Könyvtár, csomag és alprogramokVHDL Egy mintacsomag és alkalmazása n Average és Sum függvényeket tartalmazó csomag n A csomagbeli függvények használata

19 Könyvtár, csomag és alprogramokVHDL 1. példa n Egy csomag megtervezése, amely két függvényt tartalmaz: average és sum n Az average függvény visszatér két szám átlagával (lefelé kerekítve) n A sum függvény a két szám összegével tér vissza n A két függvényt meg kell határozni mind integer, mind std_logic_vector adattípusra

20 Könyvtár, csomag és alprogramokVHDL 1. példa megoldása Library ieee; Use ieee.std_logic_1164.ALL; Use ieee.std_logic_unsigned.ALL; Package mypack is function average1(a,b: in integer) return integer; function average2(a,b: in std_logic_vector) return std_logic_vector; function sum1(a,b: in integer) return integer; function sum2(a,b: in std_logic_vector) return std_logic_vector; end; Package body of mypack is function average1(a,b: in integer) return integer is begin return (a+b)/2; return (a+b)/2;end;

21 Könyvtár, csomag és alprogramokVHDL 1. példa megoldása (folyt.) function average2(a,b: in std_logic_vector) return std_logic_vector is variable int: std_logic_vector(a’range); begin int:=a+b; int:=a+b; return shr(int,”1”); return shr(int,”1”);end; function sum1(a,b: in integer) return integer is begin return (a+b); return (a+b);end; function sum2(a,b: in std_logic_vector) return std_logic_vector is begin return (a+b); return (a+b);end;end;

22 Könyvtár, csomag és alprogramokVHDL 2. példa n Tervezni kell egy c1 összetevőt, amely az előző feladatbeli függvényeket (average és sum) használja n Az összetevőnek legyen 4 bemenete: a, b, c, d n Az a és b bemenetek integer(0 to 127) típusúak, a c és d bemeneti jelek típusa pedig std_logic_vector(7 downto 0) n Az összetevő kimenetei: average1, average2, sum1, sum2, az egyes függvényeknek megfelelően n Az average1 és a sum1 integer(0 to 127), az average2 és sum2 pedig std_logic_vector(7 downto 0) típusúak

23 Könyvtár, csomag és alprogramokVHDL 2. példa megoldása Library ieee; Use ieee.std_logic_1164.ALL; Use work.mypack.ALL; Entity c1 is port (a,b: in integer range 0 to 127; c,d: in std_logic_vector(7 downto 0); port (a,b: in integer range 0 to 127; c,d: in std_logic_vector(7 downto 0); q1,q2: out integer range 0 to 127; q3,q4: out std_logic_vector(7 downto 0)); q1,q2: out integer range 0 to 127; q3,q4: out std_logic_vector(7 downto 0)); end; end; Architecture rtl of c1 is begin q1 <= average1(a,b); q1 <= average1(a,b); q2 <= sum1(a,b); q2 <= sum1(a,b); q3 <= average2(c,d); q3 <= average2(c,d); q4 <= sum2(c,d); q4 <= sum2(c,d);end;


Letölteni ppt "Könyvtár, csomag és alprogramokVHDL Könyvtár, csomag és alprogram n Library és use n Package n Alprogramok –Procedure –Function –Resolution function Egy."

Hasonló előadás


Google Hirdetések