Subprograms Procedures, functions. Subprograms subprogram_body <= procedure designator [ ( formal_parameter_list ) ] | function designator [ ( formal_parameter_list.

Slides:



Advertisements
Similar presentations
Mridula Allani Fall 2010 (Refer to the comments if required) ELEC Fall 2010, Nov 21(Adopted from Profs. Nelson and Stroud)
Advertisements

VHDL ELEC 418 Advanced Digital Systems Dr. Ron Hayne Images Courtesy of Thomson Engineering.
Decoders and Encoders Lecture L4.2. Decoders and Encoders Binary Decoders Binary Encoders Priority Encoders.
Sequential Statements Module F3.2. Sequential Statements Statements executed sequentially within a process If Statements Case Statements Loop Statements.
ECE C03 Lecture 18ECE C03 Lecture 61 Lecture 18 VHDL Modeling of Sequential Machines Prith Banerjee ECE C03 Advanced Digital Design Spring 1998.
Dr. Turki F. Al-Somani VHDL synthesis and simulation – Part 3 Microcomputer Systems Design (Embedded Systems)
SubprogramsSubprograms. SubprogramsSubprograms ä Similar to subprograms found in other languages ä Allow repeatedly used code to be referenced multiple.
ELEN 468 Lecture 191 ELEN 468 Advanced Logic Design Lecture 19 VHDL.
Topics of Lecture Structural Model Procedures Functions Overloading.
ECE C03 Lecture 141 Lecture 14 VHDL Modeling of Sequential Machines Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
VHDL. What is VHDL? VHDL: VHSIC Hardware Description Language  VHSIC: Very High Speed Integrated Circuit 7/2/ R.H.Khade.
Introduction to VHDL (part 2)
1 Part V: VHDL CODING. 2 Design StructureData TypesOperators and AttributesConcurrent DesignSequential DesignSignals and VariablesState Machines A VHDL.
1 H ardware D escription L anguages Modeling Complex Systems.
A VHDL Tutorial ENG2410. ENG241/VHDL Tutorial2 Goals Introduce the students to the following: –VHDL as Hardware description language. –How to describe.
ECE 368 CAD-Based Logic Design Shantanu Dutt Lecture 11 File I/O and Textio in VHDL (courtesy of Karam Chatha, ASU)
ELEC / Computer Architecture and Design Fall 2009 ELEC / Computer Architecture and Design Fall 2009 Modeling for Synthesis.
VHDL in 1h Martin Schöberl. AK: JVMHWVHDL2 VHDL /= C, Java,… Think in hardware All constructs run concurrent Different from software programming Forget.
Digital Design with VHDL Presented by: Amir Masoud Gharehbaghi
L16 – VHDL for State Machines with binary encoding.
Packages and Use Clauses Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHDL – Basic Language Elements  Identifiers: –basic identifier: composed of a sequence of one or more.
1 ECE 545 – Introduction to VHDL Dataflow Modeling of Combinational Logic Simple Testbenches ECE 656. Lecture 2.
Copyright(c) 1996 W. B. Ligon III1 Getting Started with VHDL VHDL code is composed of a number of entities Entities describe the interface of the component.
VHDL Very High Speed Integrated Circuit Hardware Description Language Shiraz University of shiraz spring 2011.
INTRO TO VLSI DESIGN (CPE 448) (VHDL Tutorial ) Prof: Asuif Mahmood.
Topics AliasesSubprograms Generics & Configurations.
Discussed in class and on Fridays n FSMs (only synchronous, with asynchronous reset) –Moore –Mealy –Rabin-Scott n Generalized register: –With D FFs, –With.
SUBPROGRAMAS PROCEDIMENTOS procedure average_samples is variable total : real := 0.0; begin assert samples'length > 0 severity failure; for index in samples'range.
Aliases Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Lecture 9 Chap 11: Subprograms Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
15-Dec-15EE5141 Chapter 4 Sequential Statements ä Variable assignment statement ä Signal assignment statement ä If statement ä Case statement ä Loop statement.
Finite state machines Modelling FSM in VHDL. Types of automata (FSM) A sequential automaton has: –Inputs –States (a finite number of states) –Outputs.
16/11/2006DSD,USIT,GGSIPU1 Packages The primary purpose of a package is to encapsulate elements that can be shared (globally) among two or more design.
Digital System Projects
Digital Design with VHDL Presented by: Amir Masoud Gharehbaghi
8-Jan-16EE5141 Chapter 6 Subprograms & Packages Subprogram declaration Subprogram body Package declaration Package body Resolution function Subprogram.
04/26/20031 ECE 551: Digital System Design & Synthesis Lecture Set : Introduction to VHDL 12.2: VHDL versus Verilog (Separate File)
Subprograms Lecture 6. Subprograms A subprogram defines a sequential algorithm that performs some computations. Subprograms can be: –1. functions –2.
Subprograms Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Relational Operators Result is boolean: greater than (>) less than (=) less than or equal to (
Sequential Statements Multi-valued logic systems Bus example Case Statement Looping statement Assert statement Finite State machines.
Case Study: Xilinx Synthesis Tool (XST). Arrays & Records 2.
Dataflow modelling Lecture 4. Dataflow modelling Specifies the functioning of a circuit without explicitly refer to its structure Functioning is described.
QUIZ What Circuit is this ?. Entity (The Object) -- Entity informs about the circuit’s interface -- signals entity my_circuit is port (L0, L1, L2, L3.
Composite Data Types and Operations Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
EGRE 6311 LHO 04 - Subprograms, Packages, and Libraries EGRE 631 1/26/09.
CprE / ComS 583 Reconfigurable Computing Prof. Joseph Zambreno Department of Electrical and Computer Engineering Iowa State University Lecture #19 –VHDL.
1 Introduction to Engineering Spring 2007 Lecture 19: Digital Tools 3.
Sequential statements (1) process
Introduction To VHDL 홍 원 의.
Introduction Introduction to VHDL Entities Signals Data & Scalar Types
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
Some VHDL Details 10/8/08 ECE Lecture 8.
Chapter 2. Introduction To VHDL
CPE 528: Session #7 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
ECE 434 Advanced Digital System L17
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
Sequential Statements
ECE 434 Advanced Digital System L9
VHDL (VHSIC Hardware Description Language)
CPE/EE 422/522 Advanced Logic Design L11
ECE 434 Advanced Digital System L10
CPE 528: Lecture #5 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
Figure 8.1. The general form of a sequential circuit.
Lesson 3 Advanced Topics in VHDL
Modeling Complex Behavior
Finite state machines Modelling FSM in VHDL.
Design of Networks for Arithmetic Operation
EEL4712 Digital Design (VHDL Tutorial).
Presentation transcript:

Subprograms Procedures, functions

Subprograms subprogram_body <= procedure designator [ ( formal_parameter_list ) ] | function designator [ ( formal_parameter_list ) ] return type_mark subprogram_declarative_part begin subprogram_statement_part end [ designator ] ;

Procedure example entity fg_07_01 is end entity fg_07_01; architecture test of fg_07_01 is procedure average_test is variable average : real := 0.0; type sample_array is array (positive range <>) of real; constant samples : sample_array := ( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ); procedure average_samples is variable total : real := 0.0; begin assert samples'length > 0 severity failure; for index in samples'range loop total := total + samples(index); end loop; average := total / real(samples'length); end procedure average_samples; begin average_samples; end procedure average_test; begin average_test; end architecture test;

Procedure parameters interface_declaration ::= interface_constant_declaration | interface_signal_declaration | interface_variable_declaration interface_constant_declaration ::= [ constant ] identifier_list : [ in ] subtype_indication [ := static_expression ] interface_signal_declaration ::= [ signal ] identifier_list : [ mode ] subtype_indication [ := static_expression ] interface_variable_declaration ::= [ variable ] identifier_list : [ mode ] subtype_indication [ := static_expression ] mode ::= in | out | inout

Example procedure addu ( a, b : in word32; result : out word32; overflow : out boolean ) is variable sum : word32; variable carry : bit := '0'; begin for index in sum'reverse_range loop sum(index) := a(index) xor b(index) xor carry; carry := ( a(index) and b(index) ) or ( carry and ( a(index) xor b(index) ) ); end loop; result := sum; overflow := carry = '1'; end procedure addu;

Signal parameters Mode: in –singal passed as a reference –if the procedure executes a wait statement the signal value may be different Mode: out –reference to the driver of the signal is passed Mode: inout –both the signal and its driver is passed as a reference

Concurrent procedure call procedure p ( signal s1, s2 : in bit; val1 : in integer ); call_proc : process is begin p ( s1, s2, val1 ); wait on s1, s2; end process call_proc; call_proc : p ( s1, s2, val1 );

Example function architecture test of fg_07_17 is function bv_to_natural ( bv : in bit_vector ) return natural is variable result : natural := 0; begin for index in bv'range loop result := result * 2 + bit'pos(bv(index)); end loop; return result; end function bv_to_natural; signal data : bit_vector(0 to 7); constant address : bit_vector(0 to 3) := "0101"; constant Taccess : delay_length := 80 ns; begin tester : process is constant rom_size : natural := 8; constant word_size : natural := 8; type rom_array is array (natural range 0 to rom_size-1) of bit_vector(0 to word_size-1); variable rom_data : rom_array; begin rom_data := (X"00", X"01", X"02", X"03", X"04", X"05", X"06", X"07"); data <= rom_data ( bv_to_natural(address) ) after Taccess; wait; end process tester; end architecture test;

Overloading Two distinct subprograms with –same name –different numbers or –different types of formal parameters

Example architecture test of ch_07_05 is begin process_07_5_a : process is procedure increment ( a : inout integer; n : in integer := 1 ) is begin a := a + n; end procedure increment; procedure increment ( a : inout bit_vector; n : in bit_vector := B"1" ) is begin a := bit_vector(signed(a) + signed(n)); end procedure increment; procedure increment ( a : inout bit_vector; n : in integer := 1 ) is begin a := bit_vector(signed(a) + to_signed(n, a'length)); end procedure increment; variable count_int : integer := 2; variable count_bv : bit_vector (15 downto 0) := X"0002"; begin increment ( count_int, 2 ); increment ( count_int ); increment ( count_bv, X"0002"); increment ( count_bv, 1 ); -- increment ( count_bv ); -- Illegal!!! wait; end process process_07_5_a; end architecture test;

Overloading Operator Symbols architecture test of ch_07_06 is begin process_07_5_b : process is function "+" ( left, right : in bit_vector ) return bit_vector is begin return bit_vector( "+"(signed(left), signed(right)) ); end function "+"; variable addr_reg : bit_vector(31 downto 0); function "abs" ( right : in bit_vector ) return bit_vector is begin if right(right'left) = '0' then return right; else return bit_vector( "-"(signed(right)) ); end if; end function "abs"; variable accumulator : bit_vector(31 downto 0); begin addr_reg := addr_reg + X"0000_0004"; accumulator := X"000000FF"; accumulator := abs accumulator; accumulator := X"FFFFFFFE"; accumulator := abs accumulator; wait; end process process_07_5_b; end architecture test;

State machine types Mealy State-MachineMoore State-Machine

State encoding One-hot –Each state is associated with a unique bit S1 <= ”0001” S2 <= ”0010” S3 <= ”0100” S4 <= ”1000” –large state register –easy to decode state Binary Encoding –Each state is associated with a unique number S1 <= ”00” S2 <= ”01” S3 <= ”10” S4 <= ”11” –small state register –harder to decode state

Mealy State-Machine type state_type is (st1_, st2_,...); signal state, next_state : state_type; signal _i : std_logic; SYNC_PROC: process ( ) begin if ( 'event and = '1') then if ( = '1') then state ; <= '0'; else state <= next_state; _i; end if; end process; OUTPUT_DECODE: process (state,,,...) begin if (state = st3_ and = '1') then _i <= '1'; else _i <= '0'; end if; end process; NEXT_STATE_DECODE: process (state,,,...) begin next_state <= state; case (state) is when st1_ => if = '1' then next_state ; end if; when st2_ => if = '1' then next_state ; end if; when st3_ => next_state ; when others => next_state ; end case; end process;

Moore State-Machine type state_type is (st1_, st2_,...); signal state, next_state : state_type; signal _i : std_logic; SYNC_PROC: process ( ) begin if ( 'event and = '1') then if ( = '1') then state ; <= '0'; else state <= next_state; _i; end if; end process; OUTPUT_DECODE: process (state) begin if state = st3_ then _i <= '1'; else _i <= '0'; end if; end process; NEXT_STATE_DECODE: process (state,,,...) begin next_state <= state; case (state) is when st1_ => if = '1' then next_state ; end if; when st2_ => if = '1' then next_state ; end if; when st3_ => next_state ; when others => next_state ; end case; end process;