1 benyamin@mehr.sharif.edu
Chapter 5 Structural Specification of Hardware Part2 1 - - PowerPoint PPT Presentation
Chapter 5 Structural Specification of Hardware Part2 1 - - PowerPoint PPT Presentation
Chapter 5 Structural Specification of Hardware Part2 1 benyamin@mehr.sharif.edu 4-Bit Comparator Design b3 a3 b0 a0 b2 a2 b1 a1 A A A A A>B A>B A>B A>B B B B B A=B A=B A=B A=B > > > > = = = =
2 benyamin@mehr.sharif.edu
4-Bit Comparator Design
A B > = < A>B A=B A<B A B > = < A>B A=B A<B A B > = < A>B A=B A<B A B > = < A>B A=B A<B b3 a3 b2 a2 b1 a1 b0 a0
3 benyamin@mehr.sharif.edu
4-Bit Comparator Entity Declaration
Entity nibble_comparator IS PORT( a,b:IN BIT_VECTOR(3 downto 0); gt,eq,lt: IN BIT; a_gt_b, a_eq_b, a_lt_b : OUT BIT ); END;
4 benyamin@mehr.sharif.edu
4-Bit Comparator Architecture Declaration
Architecture iterative1 OF nibble_comparator IS SIGNAL im:BIT_VECTOR(0 TO 8); BEGIN
c0:ENTITY WORK.bit_comparator PORT MAP (a(3),b(3),gt,eq,lt,im(0),im(1),im(2)); c1TOc2:FOR i in 1 to 2 GENERATE c:ENTITY WORK.bit_comparator PORT MAP (a(i),b(i),im(3*i-3),im(3*i-2),im(3*i-1),im(3*i+0),im(3*i+1),im(3*i+2)); END GENERATE; c3:ENTITY WORK.bit_comparator PORT MAP (a(0),b(0),im(6),im(7),im(8),a_gt_b,a_eq_b,a_lt_b);
END;
5 benyamin@mehr.sharif.edu
Association List of Generate Statement
PORT MAP ( a(i) , b(i) ,im(3*i-3),im(3*i-2),im(3*i-1),im(3*i+0),im(3*i+1),im(3*i+2) ); a(1) b(1) im(0) im(1) im(2) im(3) im(4) im(5) a(2) b(2) im(3) im(4) im(5) im(6) im(7) im(8) i=1 i=2
6 benyamin@mehr.sharif.edu
Generate Statement Syntax Detail
c1TOc2: FOR i IN 1 TO 2 GENERATE c:ENTITY WORK.bit_comparator PORT MAP ((a(i),b(i),im(3*i-3),im(3*i-2),im(3*i- 1),im(3*i+0),im(3*i+1),im(3*i+2)); END GENERATE;
generate_lable : FOR generation_scheme GENERATE concurrent_statements END GENERATE;
generation lable Generation scheme id IN x TO y Id IN y DOWNTO x concurrent statement
7 benyamin@mehr.sharif.edu
More on Iterative Hardware
Architecture iterative2 OF nibble_comparator IS CONSTANT n : INTEGER:=4; SIGNAL im:BIT_VECTOR(0 TO 3*(n-1)-1 ); BEGIN call:FOR i in n-1 downto 0 GENERATE IF i=n-1 GENERATE most:ENTITY WORK.bit_comparator PORT MAP (a(i),b(i),gt,eq,lt,im(0),im(1),im(2)); END GENERATE; IF i>0 AND i<n-1 GENERATE rest:ENTITY WORK.bit_comparator PORT MAP (a(i),b(i),im(3*i-3),im(3*i-2),im(3*i-1),im(3*i+0),im(3*i+1),im(3*i+2)); END GENERATE; IF i=0 GENERATE least:ENTITY WORK.bit_comparator PORT MAP (a(i),b(i), im(3*(n-1)-3),im(3*(n-1)-2),im(3*(n-1)-1),a_gt_b,a_eq_b,a_lt_b); END GENERATE; END GENERATE; END;
Constant Declaration
8 benyamin@mehr.sharif.edu
IF Generate Syntax Detail
IF condition GENERATE concurrent statements END GENERATE
IF i=n-1 GENERATE most:ENTITY WORK.bit_comparator PORT MAP (a(i),b(i),gt,eq,lt,im(0),im(1),im(2)); END GENERATE;
9 benyamin@mehr.sharif.edu
More On Iterative Hardware
Entity reg8 IS
PORT(di:IN BIT_VECTOR(7 downto0); clk:IN BIT;qo:OUT BIT_VECTOR(7 downto 0)); END; ARCHITECTURE iterative OF reg8 IS BEGIN g: FOR I in di’RANGE GENERATE g07:ENTITY WORK.latch PORT MAP(di(i),clk,qo(i)); END GENERATE; END;
‘RANGE is an attribute for signals that returns 7 downto 0
10 benyamin@mehr.sharif.edu
Modeling a Test Bench
- 1. Provides stimuli to the input ports of the
entity
- 2. Test bench must contain the circuit under
test
11 benyamin@mehr.sharif.edu
nibble_comparator Test Bench
ENTITY Test IS END; ARCHITECTURE test OF test IS SIGNAL a,b,gtr,less,eql:BIT; SIGNAL gnd:BIT:=‘0’; SIGNAL vdd:BIT:=‘1’; BEGIN comp:ENTITY WORK.nibble_comparator(iterative2) PORT MAP (a,b,gnd,vdd,’0’,gtr,eql,lss); a<=“0000”,”1111” AFTER 50 ns, “1110” AFTER 150 ns; b<=“0000”,”1110” AFTER 150 ns, “1111” AFTER 250 ns; END;
12 benyamin@mehr.sharif.edu
OPEN Keyword
- outputs of a component could be OPEN
A B > = < A>B A=B A<B
OPEN
comp:ENTITY WORK.nibble_comparator(iterative2) PORT MAP (a,b,gnd,vdd,’0’,OPEN,eql,lss);
13 benyamin@mehr.sharif.edu
OUT vs. BUFFER
Entity ex IS PORT( a: IN BIT; m: IN BIT; b: OUT BIT; c: BUFFER BIT; ); END; ARCHITECTURE sample OF ex IS BEGIN c<=m AND a; b<= NOT a WHEN c=‘1’; END;
BUFFER OUT
14 benyamin@mehr.sharif.edu
Formal Specification Details
FOR lables : compe_name USE ENTITY Library.EntityName(ArchName) PORT MAP (association_list);
Component COMPONENT n2 IS PORT(m,n:IN BIT;s:OUT BIT); END COMPONENT; FOR ALL:n2 USE Entity WORK.nand2(single) PORT MAP (x,y,z); C0: n2 port map (a,b,z);
15 benyamin@mehr.sharif.edu
m n s x y z
Formal Specification Details
i1 i2 o1 a b c Actual signals Local ports Component ports Formal ports
16 benyamin@mehr.sharif.edu
Chapter 6
Design Organization and Parameterization
17 benyamin@mehr.sharif.edu
Design Organization and Parameterization
- Subprograms
- Parameterizing and customizing design
- Definition and usage of library packages
- Generic design
- Design configuration
18 benyamin@mehr.sharif.edu
Definition and Usage of Subprograms
- Simplify coding
- Modularity
- Readability
- Functions
– Cannot alter the values of their parameters – Return a value
- Procedures
– Used as a statement – Can alter the values of its parameters
19 benyamin@mehr.sharif.edu
Function Declaration
- Subprograms can be declared in architecture
declarative part or packages
- Each function must have return expression
- All formal parameters are considered IN mode
FUNCTION func_name (formal_parameter_list) RETURN return_type IS function_declarative_part variable and constant declaration
BEGIN sequential statements –including RETURN statement; END func_name;
20 benyamin@mehr.sharif.edu
Functional Single-Bit Comparator
Architecture functional OF bit_comparator IS
FUNCTION fgl(w,x,gl:BIT) RETURN BIT IS BEGIN RETURN (w AND gl) OR (NOT x AND gl) OR (w AND NOT x); END fgl; FUNCTION feq(w,x,eq:BIT) RETURN BIT IS BEGIN RETURN (w AND x AND eq) OR (NOT w AND NOT x AND eq); END feq; BEGIN a_gt_b<=fgl(a,b,gt) AFTER 12 NS; a_eq_b<=feq(a,b,eq) AFTER 12 NS; a_lt_b <=fgl(b,a,lt) AFTER 12 NS; END;
21 benyamin@mehr.sharif.edu
Concurrent Statements
Signal assignment Component instantiation
- Process statement
Concurrent procedure call
- Block statement
Generate statement
- Assertion statement
22 benyamin@mehr.sharif.edu
Sequential Statements
Signal assignment statement Variable assignment statement
- Wait statement
If,case,loop statement
- Procedure call statement
- Exit,return statement
- Assertion statement
23 benyamin@mehr.sharif.edu
Variable Declaration
Examples:
VARIABLE a :BIT ; VARIABLE x : BIT := ‘1’; VARIABLE x,y,z : BIT_VECTOR(1 to 4) := “1011” ; VARIABLE b,i :INTEGER := -10; VARIABLE flag : BOOLEAN := TRUE;
VARIABLE identifier_list : type [:= init_value] ;
24 benyamin@mehr.sharif.edu
Variable Assignment
Target_variable := expression A := b AND c; A := c; X := (b and c) XOR b; i := i+1; Z := a*b+c/2-(w*t);
25 benyamin@mehr.sharif.edu
Control Statements
If-else statement
- Case statement
For-loop statement While-loop statement
- Exit statement
- Next statement
26 benyamin@mehr.sharif.edu
IF Statement
IF condition THEN sequential statements; END IF; IF condition THEN statements; ELSE statements; END IF; IF condition THEN statements; ELSIF condition THEN statements; ELSIF condition THEN statements; ELSE statements; END IF;
27 benyamin@mehr.sharif.edu
IF Statement Example
IF sel=‘1’ THEN z<=i1; ELSE z<=i2; END IF; IF sel=‘1’ THEN z<=i1; ELSIF sel=‘0’ THEN z<=i2; ELSE w<=‘0’ END IF;
28 benyamin@mehr.sharif.edu
FOR LOOP Statement
Range ::= x TO y x<y | y DOWNTO x x<y | id’RANGE id is signal
FOR loop_counter IN Range LOOP sequential statements; END LOOP;
29 benyamin@mehr.sharif.edu
FOR LOOP Example
SIGNAL a:BIT_VECTOR(10 downto 0); SIGNAL b:BIT_VECTOR(0 to 10); …. b’RANGE FOR k IN 0 to 10 LOOP a(k)<=b(10-k); END LOOP;
30 benyamin@mehr.sharif.edu
WHILE LOOP Statement
WHILE condition LOOP sequential statements; END LOOP;
- Loop will continue until condition becomes FALSE
31 benyamin@mehr.sharif.edu
WHILE LOOP Example
WHILE Enable=‘1’ LOOP z<=‘1’; WAIT for 10 ns; z<=‘0’; WAIT for 10 ns; END LOOP; PULSE Generator Enable z
20 ns
32 benyamin@mehr.sharif.edu
Procedure Call Declaration
- Default class for inputs of subprograms are CONSTANT
- Default class for outputs of subprograms are VARIABLE
- In procedure declaration all input and outputs must be
declared explicitly
PROCEDURE proc_name (formal_parameter_list) IS procedure_declarative_part
BEGIN sequential statements END proc_name;
33 benyamin@mehr.sharif.edu
Procedure Call Example
PROCEDURE bin2int(bin:IN BIT_VECTOR(7 downto 0); int:OUT INTEGER) IS VARIABLE result:INTEGER; BEGIN result:=0; FOR i IN bin’RANGE LOOP IF bin(i)=‘1’ THEN result:=result+2**I; END IF; END FOR; END bin2int;
34 benyamin@mehr.sharif.edu
Unconstrained Array
- Range section of an array can be omitted
- Range will be determined in compiled time
when an actual parameter is used
PROCEDURE bin2int(bin:IN BIT_VECTOR;int:OUT INTEGER) IS …. END; … SIGNAL i:INTEGER; SIGNAL a:BIT_VECTOR(12 DOWNTO 1); … bin2int( a , I );
35 benyamin@mehr.sharif.edu
General bin2int Procedure
PROCEDURE bin2int(bin:IN BIT_VECTOR;int:OUT INTEGER) IS
VARIABLE result:INTEGER; BEGIN result:=0; FOR i IN bin’RANGE LOOP IF bin(i)=‘1’ THEN result:=result+2**I; END IF; END FOR; END bin2int;
36 benyamin@mehr.sharif.edu
ApplyData Procedure Call
TYPE integers IS ARRAY (0 to 12) OF INTEGER; PROCEDURE apply_data(SIGNAL target:OUT BIT_VECTOR(3 downto 0); CONSTANT values: IN integers;CONSTANT period: IN TIME) IS VARIABLE j:INTEGER; VARIABLE tmp,pos:INTEGER:=0; VARIBALE buf:BIT_VECTOR(3 DOWNTO 0); BEGIN FOR I IN 0 TO 12 LOOP tmp:=values(i); j:=0; WHILE j<=3 LOOP IF(tmp MOD 2 =1) THEN buf(j):=‘1’; ELSE buf(j):=‘0’; END IF; tmp:=tmp/2; j:=j+1; END LOOP; target<=TRANSPORT buf AFTER i*period; END LOOP; END apply_data;
37 benyamin@mehr.sharif.edu
nibble_comparator Test Bench Using apply_data
ARCHITECTURE procedural OF nibble_comparator IS TYPE integers IS ARRAY (0 to 12) OF INTEGER; PROCEDURE apply_data(SIGNAL target:OUT BIT_VECTOR(3 downto 0); CONSTANT values: IN integers;CONSTANT period: IN TIME) IS … END apply_data; SIGNAL a,b:BIT_VECTOR(3 DOWNTO 0); SIGNAL eql,lss,gtr:BIT; BEGIN a1:ENTITY WORK.nibble_comparator PORT MAP(a,b,’0’,’1’,’0’,gtr,eql,lss); apply_data(a,00&15&15&14&14&14&14&10&00&15&00&00&15,50 NS); apply_data(b,(00,14,14,15,15,12,,12,12,15,15,15,00,00),50 NS);
END;