Hardware Modeling. VHDL Syntax. Vienna University of Technology Department of Computer Engineering ECS Group

Similar documents
Design units can NOT be split across different files

Synthesis from VHDL. Krzysztof Kuchcinski Department of Computer Science Lund Institute of Technology Sweden

!"#$%&&"'(')"*+"%,%-".#"'/"'.001$$"

ECE 3401 Lecture 10. More on VHDL

BASIC VHDL LANGUAGE ELEMENTS AND SEMANTICS. Lecture 7 & 8 Dr. Tayab Din Memon

5. 0 VHDL OPERATORS. The above classes are arranged in increasing priority when parentheses are not used.

VHDL BASIC ELEMENTS INTRODUCTION

Contents. Appendix D VHDL Summary Page 1 of 23

Hardware Description Language VHDL (1) Introduction

Logic and Computer Design Fundamentals VHDL. Part 1 Chapter 4 Basics and Constructs

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

Basic Language Concepts

CSCI Lab 3. VHDL Syntax. Due: Tuesday, week6 Submit to: \\fs2\csci250\lab-3\

ECOM4311 Digital Systems Design

C-Based Hardware Design

EECE-4740/5740 Advanced VHDL and FPGA Design. Lecture 3 Concurrent and sequential statements

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

ELCT 501: Digital System Design

VHDL: skaitmeninių įtaisų projektavimo kalba. 2 paskaita Pradmenys

VHDL Part 2. What is on the agenda? Basic VHDL Constructs. Examples. Data types Objects Packages and libraries Attributes Predefined operators

Declarations. Lexical elements. Type declaration Subtype declaration Constant declaration Signal declaration Variable declaration.

IT T35 Digital system desigm y - ii /s - iii

Review of Digital Design with VHDL

Introduction to VHDL. Main language concepts

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 4 Introduction to VHDL

VHDL. Official Definition: VHSIC Hardware Description Language VHISC Very High Speed Integrated Circuit

Summary of basic structures

Getting Started with VHDL

Outline CPE 626. Advanced VLSI Design. Lecture 4: VHDL Recapitulation (Part 2) Signals. Variables. Constants. Variables vs.

VHDL. ELEC 418 Advanced Digital Systems Dr. Ron Hayne. Images Courtesy of Cengage Learning

ECOM 4311 Digital System Design using VHDL. Chapter 7

Subprograms, Packages, and Libraries

Building Blocks. Entity Declaration. Entity Declaration with Generics. Architecture Body. entity entity_name is. entity register8 is

Hardware Modeling. VHDL Architectures. Vienna University of Technology Department of Computer Engineering ECS Group

ECE4401 / CSE3350 ECE280 / CSE280 Digital Design Laboratory

Outline. CPE/EE 422/522 Advanced Logic Design L07. Review: JK Flip-Flop Model. Review: VHDL Program Structure. Review: VHDL Models for a MUX

Lecture 10 Subprograms & Overloading

CPE/EE 422/522. Chapter 8 - Additional Topics in VHDL. Dr. Rhonda Kay Gaede UAH. 8.1 Attributes - Signal Attributes that return a value

COE 405 Design Methodology Based on VHDL

Inthis lecture we will cover the following material:

Lecture 12 VHDL Synthesis

Lecture 4. VHDL Fundamentals. Required reading. Example: NAND Gate. Design Entity. Example VHDL Code. Design Entity

Multi-valued Logic. Standard Logic IEEE 1164 Type std_ulogic is ( U, uninitialized

Lecture 4. VHDL Fundamentals. George Mason University

VHDL And Synthesis Review

Department of Electronics & Communication Engineering Lab Manual E-CAD Lab

A bird s eye view on VHDL!

VHDL Packages for Synthesis Base Types Standard bit types may be used Typically IEEE 1164 Std. types are used. CPE 528: Session #9

Hardware Modeling. VHDL Basics. ECS Group, TU Wien

Lecture 9. VHDL, part IV. Hierarchical and parameterized design. Section 1 HIERARCHICAL DESIGN

1 ST SUMMER SCHOOL: VHDL BOOTCAMP PISA, JULY 2013

Advanced Training Course on FPGA Design and VHDL for Hardware Simulation and Synthesis. 26 October - 20 November, 2009

Introduction to VHDL #1

ECE U530 Digital Hardware Synthesis. Course Accounts and Tools

ECE 545 Lecture 5. Data Flow Modeling in VHDL. George Mason University

HDL. Hardware Description Languages extensively used for:

Performance Engineering of Real-Time and Embedded Systems. Introduction to VHDL

[1] Douglas L. Perry, VHDL, third edition, ISBN , McRaw- Hill Series on Computer Engineering.

What Is VHDL? VHSIC (Very High Speed Integrated Circuit) Hardware Description Language IEEE 1076 standard (1987, 1993)

310/ ICTP-INFN Advanced Tranining Course on FPGA and VHDL for Hardware Simulation and Synthesis 27 November - 22 December 2006

EEL 4783: Hardware/Software Co-design with FPGAs

Sequential VHDL. Katarzyna Radecka. DSD COEN 313

Lab # 5. Subprograms. Introduction

Introduction to VHDL

VHDL 200X: The Future of VHDL

Lecture 3 Introduction to VHDL

Assignment. Last time. Last time. ECE 4514 Digital Design II. Back to the big picture. Back to the big picture

VHDL 3 BASIC OPERATORS AND ARCHITECTURE BODY. Design descriptions & design constructions examples are taken from foundation series examples

JUNE, JULY 2013 Fundamentals of HDL (10EC45) PART A

Elektrotechnik und Informationstechnik, Stiftungsprofessur hochparallele VLSI Systeme und Neuromikroelektronik. Oberseminar Informationstechnik

VHDL Structural Modeling II

Lecture 1: VHDL Quick Start. Digital Systems Design. Fall 10, Dec 17 Lecture 1 1

VHDL: Code Structure. 1

VHDL Objects. Lecture 8: VHDL (2) Variables. VHDL Objects - Constant. Files. EE3109 Gopi K. Manne Fall 2007

The University of Alabama in Huntsville ECE Department CPE Midterm Exam February 26, 2003

Outline CPE 626. Advanced VLSI Design. Lecture 3: VHDL Recapitulation. Intro to VHDL. Intro to VHDL. Entity-Architecture Pair

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 3

Digital Systems Design

Digitaalsüsteemide disain

VHDL for Complex Designs

VHDL for FPGA Design. by : Mohamed Samy

Introduction to VHDL. Yvonne Avilés Colaboration: Irvin Ortiz Flores Rapid System Prototyping Laboratory (RASP) University of Puerto Rico at Mayaguez

Modeling Complex Behavior

Digital Design Using VHDL Using Xilinx s Tool for Synthesis and ModelSim for Verification Part II

Very High Speed Integrated Circuit Har dware Description Language

Computer-Aided Digital System Design VHDL

Fixed and Floating Point Packages

Basic Language Constructs of VHDL

Lecture 5: State Machines, Arrays, Loops. EE 3610 Digital Systems

Hardware Description Languages. Modeling Complex Systems

Concurrent & Sequential Stmts. (Review)

VHDL Synthesis Reference

VHDL kod yerleşimi. kütüphaneler. Dış görünüş (entity: varlık) İşleyişi, yapısı (architecture: mimari)

CprE 583 Reconfigurable Computing

5. VHDL - Introduction - 5. VHDL - Design flow - 5. VHDL - Entities and Architectures (1) - 5. VHDL - Entities and Architectures (2) -

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 3

VHDL: A Crash Course

Lattice VHDL Training

Assignment 01 Computer Architecture Lab ECSE

The University of Alabama in Huntsville ECE Department CPE Midterm Exam Solution Spring 2016

Transcription:

Hardware Modeling VHDL Syntax Vienna University of Technology Department of Computer Engineering ECS Group

Contents Identifiers Types & Attributes Operators Sequential Statements Subroutines 2

Identifiers 3 Consists of characters, digits and underscores Case insensitive First letter must be a character! Underscores not allowed at the beginning/end No two underscores in a row

Identifiers - Examples 4 Valid identifiers state, name, stage1, cpu2, memory_3 Invalid identifiers: _state, _memory 2stage cpu_ my name $name

Contents Identifiers Types & Attributes Operators Sequential Statements Subroutines 5

VHDL Types bit [0,1], bit_vector std_logic, std_ulogic std_logic_vector, std_ulogic_vector integer, real Enumerations boolean character, string 6

IEEE 1164 Logic System std_logic: can have one of the following nine values: U, X, 0, 1, Z, W, L, H, - Difference std_ulogic and std_logic? unresolved Only a single driver possible 7

Vectors Collection of multiple elements of the same type Increasing/decreasing index range possible (to/downto) Positional binding on assignments Concatenation possible 8 Bit-vectors have no numerical meaning ( 1001 smaller than 111 )

Vector Examples signal a_bus: bit_vector(3 downto 0); signal b_bus: bit_vector(0 to 3); signal c_bus: bit_vector(15 downto 0); signal A,B,C: bit; a_bus <= b_bus; a_bus(3) <= b_bus(0); a_bus(2) <= b_bus(1); a_bus(1) <= b_bus(2); a_bus(0) <= b_bus(3); a_bus(2) <= 1 ; a_bus(1 downto 0) <= 10 ; b_bus(0 to 1) <= 01 ; a_bus(2 downto 0) <= b_bus(1 to 3); b_bus <= (A, 0,C, 0 ); c_bus <= a_bus & b_bus & 00000000 ; c_bus <= (7 => B,15 downto 8 => 1,others => 0 ); 9

Integers 10 Integers are defined in the range of - 2 31 + 1 to +2 31 1 (32 bit) May be restricted using a range specifier Predefined integer arithmetic Examples: signal i : integer; signal counter : integer range 0 to 255; signal a, b, c : integer range 10 to 20;

Signed and Unsigned 11 Package: numeric_std signed / unsigned are special versions of std_logic_vectors Explicit casting required to_signed, to_unsigned, to_integer unsigned, signed, std_logic_vector Arithmetics only defined for signed and unsigned but not for std_logic_vector!

Enumerations type TYPE NAME is (NAME1, NAME2,...); Examples: 12 type MEM_OP_TYPE is (NONE, READ, WRITE); type STATE_TYPE is (STATE_IDLE, STATE_RUNNING, STATE_SLEEP); type CACHE_ROW_TYPE is (MODIFIED, EXCLUSIVE, SHARED, INVALID); Encoding examples: NONE= 00, READ= 01, WRITE= 10 STATE_IDLE= 001, STATE_RUNNING= 010, STATE_SLEEP= 100 MODIFIED = 0001, EXCLUSIVE= 0010, SHARED= = 0100, INVALID= 1000 MODIFIED = 00, EXCLUSIVE= 01, SHARED= = 10, INVALID= 11

Constant Values 13 Enumeration items STATE_IDLE, EXCLUSIVE Integers and Reals 2, 250_000, 3E6, 2.0, 2.6E-5, 3_123.56 Characters `x`, `1` Strings a string & another one Bits and Bit-Strings `0`, `1`, 11001, b 11001, x 1A, o 31

14 Attributes Range based attributes (examples) a left, a right a low, a high a range a length Signal bases attributes (example) s event s stable

Attributes Examples signal a : std_logic_vector(3 downto 0); signal b : std_logic_vector(0 to 3); a left 3 a right 0 a high 3 a low 0 b left 0 b right 3 b high 3 b low 0 a range 3 downto 0 a length 4 b range 3 to 0 b length 4 15

Contents Identifiers Types & Attributes Operators Sequential Statements Subroutines 16

Operators (1) Logical operators (and, or, xor, nand, nor, xnor) Comparison operators (=, /=, <,<=,>,>=) Shift operators (sll, srl, sla, sra, rol, ror) Addition operators (+, -, &) Signs (+, -) Multiplication operators (*, /, mod, rem) Other operators (**, abs, not) 17 Operators given in ascending priority!

Operators (2) Keep implementation complexity in mind! Especially for mult, div, mod, rem Operators may be overloaded Comparison of std_logic_vector with different length: 110 > 1010 18

Contents Identifiers Types & Attributes Operators Sequential Statements Subroutines 19

Sequential Statements 20 Signal assignments Variable assignments Wait statements If-Then-Else statements Case statements Loop statements Assert statements

Variables Comparable to the variables of a C program Declared within processes Immediate assignment of values (in difference to signal assignments) Variables keep the value between different iterations of a process 21

Variables - Example process (A,B,C) variable X,Y : bit; begin X := A; Y := B; Z <= X and Y; Y := C; R <= X and Y: end process; Declared within the process Immediate assignments 22

Constants 23 Comparable to constants in C Value defined at declaration Value not changeable Declaration possible in packages, architectures or processes Examples: architecture beh of xyz is constant CNT_MAX : integer := 1000; constant INST_ADD : std_logic_vector(3 downto 0) := x A ; begin...

Difference Signal - Variable Signal Constant Variable Changeable Yes No Yes Assignment operator Assignment executed Visibility <= ------ := At next wait statement Whole architecture ------ Immedeatly Depending on definition Process locally 24

Variable-/Signal-Assignment architecture beh of abc is begin process(a, B, C) variable X, Y : bit; begin X := A; Y := B; Z <= X and Y; Y := C; R <= X and Y; end process; end architecture beh; architecture beh of abc is signal X, Y : bit; begin process(a, B, C, X, Y) begin X <= A; Y <= B; Z <= X and Y; Y <= C; R <= X and Y; end process; end architecture beh; 25

Variable-/Signal-Assignment 26 architecture beh of abc is begin process(a, B, C) variable X, Y : bit; begin X := A; Y := B; Z <= X and Y; Y := C; R <= X and Y; end process; end architecture beh; architecture beh of abc is signal X, Y : bit; begin process(a, B, C, X, Y) begin X <= A; Y <= B; Z <= X and Y; Y <= C; R <= X and Y; end process; end architecture beh; Iteration Left Process Right Process First Z = A and B R = A and C Z = X old AND Y old R = X old AND Y old Second No second iteration Z = A AND C R = A AND C

Shared Variables Introduced in VHDL 93 Visible in multiple processes Immediate assignment Attention: may lead to indeterministic behavior 27 Only synthesizable in special cases (e.g. memory with multiple write ports in different clock domains)

Wait Statements Four variants: 28 wait on signal list; wait until condition; wait for time; wait; Examples: wait on clk; wait until clk = 1 and clk event; wait for 10 ns;

If-Then-Else Syntax: [label :] if boolean expression then {sequential statement} [{elsif boolean expression then {sequential statement}}] [else {sequential statement}] end if [label]; 29

If-Then-Else Example 1 process (in1, in2, in3) begin if in1 = '0' then out1 <= '0'; else if in2 = '1' then out1 <= in3; else out1 <= not in3; end if; end if; end process; in3 in2 in1 out1 30

If-Then-Else Example 2 process (in1, in2, in3) begin if in1 = '0' then out1 <= '0'; elsif in2 = '1' then out1 <= in3; else out1 <= not in3; end if; end process; in3 in1 in2 out1 31

Case Statement Syntax: [case_label :] case expression is {when choices => {sequential statement}} [when others => {sequential statement}] end case [case_label]; 32

Case Example process (sel, in3) Begin case sel is when "11" => out1 <= in3; when "10 => out1 <= not in3; when others => out1 <= '0'; end case; end process; in3 sel out1 33

Loop Statement [label :] [iteration scheme] loop {sequential statement} end loop [label]; Iteration scheme: while condition for range 34

Example: Parity Check 35 Input: 16 bit data word as std_logic_vector, most significant bit on highest index ( 15 downto 0) Output: Single parity bit (std_logic) 1 if number of 1 s in data word is odd 0 otherwise Implementation as a process Using different forms of loops

Example: Parity Check (Signal) architecture beh_sig of parity is signal parity : std_logic; begin process (in_vec) begin parity <= '0'; for i in 15 downto 0 loop parity <= parity xor in_vec(i); end loop; out1 <= parity; end process; end beh_sig; 36

Example: Parity Check (Signal) Synthesis result: 0 37

Example: Parity Check (Signal) Synthesis result: 0 Not quite what we expected, isn t it? 38

Example: Parity Check (Variable) architecture beh_var of parity is begin process (in_vec) variable parity : std_logic; begin parity := '0'; for i in 15 downto 0 loop parity := parity xor in_vec(i); end loop; out1 <= parity; end process; end beh_var; 39

Example: Parity Check (Variable) Synthesis result: 40

Example: Parity Check (while) 41 architecture beh_while of parity is begin process (in_vec) variable parity : std_logic; variable i : integer range 0 to 16; begin parity := '0'; i := 0; while i < 16 loop parity := parity xor in_vec(i); i := i + 1; end loop; out1 <= parity; end process; end beh_while;

Assert Statement assert condition [report string] [severity level]; Activated, if the condition evaluates to false string is printed to simulation console severity level: note, warning, error or failure Abort: level dependents on used simulator Is widely used as abort condition for testbenches Simplifies circuit validation 42

Contents Identifiers Types & Attributes Operators Sequential Statements Subroutines 43

Subroutines (1) 44 Functions No, one or multiple arguments Returns exactly one value Can be used in places where the return type may be used Explicit return statement necessary Procedures List of bidirectional arguments Can be used in places where a statement may be used Terminates either at a return statement or at the end of the function

Subroutines (2) Function Procedure Argument direction INPUT INPUT, OUTPUT or BIDIRECTIONAL Argument types Constants, signals Constants, signals, variables Return value Exactly one Abitrary count Usable in Places the return type may be used Return statement Necassary Optional Places a statement may be used 45

Function Declaration function name [ ( {[class] name {, name} : [in] type [:=default value] ;} [class] name {, name} : [in] type [:=default value] ) ] return type; Class: constant signal 46

Function Definition function name [ ( {[class] name {, name} : [in] type [:=default value] ;} [class] name {, name} : [in] type [:=default value] ) ] return type is Declarations begin Sequential statements return statement necessary No WAIT-Statements allowed! end [function] [name]; 47

Function - Example function count_ones(a : bit_vector) return integer is variable count : integer := 0; begin for c in a'range loop if a(c) = '1' then count := count+1; end if; end loop; return count; end function count_ones; 48 Note: The bit_vector has a variable width Actual width is set at compile time

Function Call (1) Positional argument binding name [(argument {,argument})] Named argument binding name [(name=>argument {, name=>argument})] If a parameter is omitted, its default value is assumed! 49

Function Call (2) Each function call is replaced by a hardware instance. Resource sharing possible Examples: signal my_vector : bit_vector(7 downto 0); signal second_vector : bit_vector(31 downto 0); num_ones <= count_ones(my_vector); 50 if count_ones(a=>second_vector) > 5 then... end if;

Procedure Declaration procedure name [ ( {[class] name {,name} : [mode] type [:=default value] ;} [class] name {,name} : [mode] type [:=default value] ) ]; 51 Class: constant signal variable Mode: in out inout

Procedure Definition procedure name [ ( {[class] name {,name} : [mode] type [:=default value] ;} [class] name {,name} : [mode] type [:=default value] ) ] is Declarations begin sequential statements optional return statement end [procedure] [name]; 52

Procedure - Example procedure d_ff ( constant delay : in time:=2ns; signal d, clk : in bit; signal q, q_bar: out bit) is begin if clk = 1 and clk event then q <= d after delay; q_bar <= not d after delay; end if; end procedure d_ff; Delays not synthesizable! 53

Procedure Call (1) Positional argument binding name [(argument {,argument})] Named argument binding name [(name=>argument {, name=>argument})] If a parameter is omitted, its default value is assumed! 54

Procedure Call (2) Each procedure call is replaced by a hardware instance. Resource sharing possible Examples: signal c : bit; signal d1, q1, q1_n : bit; signal d2, q2, q2_n : bit; d_ff(delay=>10 ps, d=>d, clk=>c, q=>q, q_bar=>q_n); d_ff(5 ps, d2, c, q2, q2_n); 55

Summary Identifiers VHDL type system Scalar types 9-valued logic (std_logic) Arithmetic on std_logic Vectors 56

Summary 57 Operators Keep hardware costs in mind (e.g., /, mod) Sequential statements Effects of else and others clause Subroutines Procedure Function