Tasks and Functions Programmable Logic Design (40-493) Fall 2001 Computer Engineering Department Sharif University of Technology Maziar Gudarzi.

Slides:



Advertisements
Similar presentations
CS 3850 Lecture 6 Tasks and Functions. 6.1 Tasks and Functions Tasks are like procedures in other programming languages. e. g., tasks may have zero or.
Advertisements

Simulation executable (simv)
Synchronous Sequential Logic
Combinational Logic.
Chap. 6 Dataflow Modeling
Reconfigurable Computing S. Reda, Brown University Reconfigurable Computing (EN2911X, Fall07) Lecture 07: Verilog (3/3) Prof. Sherief Reda Division of.
Chapter 11 Verilog HDL Application-Specific Integrated Circuits Michael John Sebastian Smith Addison Wesley, 1997.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Introduction to Verilog
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
ELEN 468 Lecture 91 ELEN 468 Advanced Logic Design Lecture 9 Behavioral Descriptions III.
ENEE 408C Lab Capstone Project: Digital System Design Verilog Tutorial Class Web Site:
Silicon Programming--Intro. to HDLs1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities.
CSE241 R1 Verilog.1Kahng & Cichy, UCSD ©2003 CSE241 VLSI Digital Circuits Winter 2003 Recitation 1: Verilog Introduction.
Reconfigurable Computing (EN2911X, Fall07) Lecture 05: Verilog (1/3) Prof. Sherief Reda Division of Engineering, Brown University
ECEN ECEN475 Introduction to VLSI System Design Verilog HDL.
Digital System Design Verilog ® HDL Tasks and Functions Maziar Goudarzi.
Digital System Design Verilog ® HDL Behavioral Modeling (1) Maziar Goudarzi.
2/3/03ΗΥ220 - Μαυροειδής Ιάκωβος1 Delays in Behavioral Verilog - Interassignment Delay  Key idea: unlike blocking delay, RHS is evaluated before delay.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 6 - Behavioral Modeling.
Digital System Design EEE344 Lecture 3 Introduction to Verilog HDL Prepared by: Engr. Qazi Zia, Assistant Professor EED, COMSATS Attock1.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
Design Synopsys System Verilog API Donations to Accellera João Geada.
Overview Logistics Last lecture Today HW5 due today
Module : TASKS, Functions and UDPs in Verilog. Functions Functions are declared with the keywords function and endfunction. Functions are used if all.
1 VERILOG Fundamentals Workshop סמסטר א ' תשע " ה מרצה : משה דורון הפקולטה להנדסה Workshop Objectives: Gain basic understanding of the essential concepts.
ECE 2372 Modern Digital System Design
MODULE 1.3 VERILOG BASICS UNIT 1 : INTRODUCTION TO VERILOG TOPIC : System Tasks and Compiler directive.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Verilog Language Concepts
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
CS 3850 Lecture 3 The Verilog Language. 3.1 Lexical Conventions The lexical conventions are close to the programming language C++. Comments are designated.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Module 2.1 Gate-Level/Structural Modeling UNIT 2: Modeling in Verilog.
Module 1.2 Introduction to Verilog
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Chap. 4 Modules and Ports. 2 Modules and Ports Modules Ports Hierarchical Names Summary.
Digital System Design Verilog ® HDL Behavioral Modeling Maziar Goudarzi.
1 Verilog Digital System Design Z. Navabi, 2006 Verilog Language Concepts.
M.Mohajjel. Structured Procedures Two basic structured procedure statements always initial All behavioral statements appear only inside these blocks Each.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Introduction to ASIC flow and Verilog HDL
Sharif University of Technology Department of Computer Engineering Verilog ® HDL Basic Concepts Alireza Ejlali.
Timing Controls in Behavioral Modeling Programmable Logic Design (40-493) Fall 2001 Computer Engineering Department Sharif University of Technology Maziar.
Verilog® HDL Behavioral Modeling (2)
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Chapter 3: Dataflow Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 3-1 Chapter 3: Dataflow Modeling.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
Chapter1: Introduction Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 1-1 Chapter 1: Introduction Prof. Ming-Bo.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
Dept of CSE, IIT Kharagpur 1 1 The Verilog Week Debdeep Mukhopadhyay Associate Professor Dept of Computer Science and Engineering NYU Shanghai and IIT.
EMT 351/4 DIGITAL IC DESIGN Verilog Behavioral Modeling  Constructs for Activity Flow Control  Task & Function  System Tasks for Timing Checks.
Structural Description
Hardware Description Languages: Verilog
Reg and Wire:.
Verilog Introduction Fall
Behavioral Modeling Structural modeling Behavioral modeling
Hardware Description Languages: Verilog
Introduction To Verilog-HDL
Introduction to Digital System and Microprocessor Design
The Verilog Hardware Description Language
CS 153 Logic Design Lab Professor Ian G. Harris
COE 202 Introduction to Verilog
Reconfigurable Computing (EN2911X, Fall07)
Reconfigurable Computing (EN2911X, Fall07)
Presentation transcript:

Tasks and Functions Programmable Logic Design (40-493) Fall 2001 Computer Engineering Department Sharif University of Technology Maziar Gudarzi

Introduction Procedures/Subroutines/Functions in SW programming languages Procedures/Subroutines/Functions in SW programming languages The same functionality, in different places The same functionality, in different places Verilog equivalence: Verilog equivalence: Tasks and Functions Tasks and Functions Used in behavioral modeling Used in behavioral modeling Part of design hierarchy  Hierarchical name Part of design hierarchy  Hierarchical name

Contents Differences between tasks and functions Differences between tasks and functions Tasks Tasks Functions Functions

Differences between Tasks and Functions Tasks and Functions

Differences between... Functions Functions Can enable (call) just another function (not task) Can enable (call) just another function (not task) Execute in 0 simulation time Execute in 0 simulation time No timing control statements allowed No timing control statements allowed At lease one input At lease one input Return only a single value Return only a single value Tasks Can enable other tasks and functions May execute in non-zero simulation time May contain any timing control statements May have arbitrary input, output, or inouts Do not return any value

Differences between… (cont’d) Both Both are defined in a module are defined in a module are local to the module are local to the module can have local variables (registers, but not nets) and events can have local variables (registers, but not nets) and events contain only behavioral statements contain only behavioral statements do not contain initial or always statements do not contain initial or always statements are called from initial or always statements or other tasks or functions are called from initial or always statements or other tasks or functions

Differences between… (cont’d) Tasks can be used for common Verilog code Tasks can be used for common Verilog code Function are used when the common code Function are used when the common code is purely combinational is purely combinational executes in 0 simulation time executes in 0 simulation time provides exactly one output provides exactly one output Functions are typically used for conversions and commonly used calculations Functions are typically used for conversions and commonly used calculations

Tasks Tasks and Functions

Tasks Keywords: task, endtask Keywords: task, endtask Must be used if the procedure has Must be used if the procedure has any timing control constructs any timing control constructs zero or more than one output arguments zero or more than one output arguments no input arguments no input arguments

Tasks (cont’d) Task declaration and invocation Task declaration and invocation Declaration syntax Declaration syntax task ; begin // if more than one statement needed end // if begin used! endtask

Tasks (cont’d) Task declaration and invocation Task declaration and invocation Task invocation syntax Task invocation syntax<task_name>; ( ); ( ); input and inout arguments are passed into the task input and inout arguments are passed into the task output and inout arguments are passed back to the invoking statement when task is completed output and inout arguments are passed back to the invoking statement when task is completed

Tasks (cont’d) I/O declaration in modules vs. tasks I/O declaration in modules vs. tasks Both used keywords: input, output, inout Both used keywords: input, output, inout In modules, represent ports In modules, represent ports connect to external signals connect to external signals In tasks, represent arguments In tasks, represent arguments pass values to and from the task pass values to and from the task

Task Examples Use of input and output arguments module operation; parameter delay = 10; reg [15:0] A, B; reg [15:0] AB_AND, AB_OR, AB_XOR; initial $monitor( …); initialbegin…end or B) begin bitwise_oper(AB_AND, AB_OR, AB_XOR, A, B); end task bitwise_oper; output [15:0] ab_and, ab_or, ab_xor; input [15:0] a, b; begin #delay ab_and = a & b; ab_or = a | b; ab_xor = a ^ b; end endtask endmodule

Task Examples Use of module local variables module sequence; reg clock; initialbegin…endinitialinit_sequence;alwaysasymmetric_sequence; task init_sequence; begin clock = 1'b0; clock = 1'b0;endendtask task asymmetric_sequence; begin #12 clock = 1'b0; #12 clock = 1'b0; #5 clock = 1'b1; #5 clock = 1'b1; #3 clock = 1'b0; #3 clock = 1'b0; #10 clock = 1'b1; #10 clock = 1'b1;endendtaskendmodule

Functions Tasks and Functions

Functions Keyword: function, endfunction Keyword: function, endfunction Can be used if the procedure Can be used if the procedure does not have any timing control constructs does not have any timing control constructs returns exactly a single value returns exactly a single value has at least one input argument has at least one input argument

Functions (cont’d) Function Declaration and Invocation Function Declaration and Invocation Declaration syntax: Declaration syntax: function ; <variable_declaration(s)> begin // if more than one statement needed end // if begin used endfunction

Functions (cont’d) Function Declaration and Invocation Function Declaration and Invocation Invocation syntax: Invocation syntax: ( ); ( );

Functions (cont’d) Semantics Semantics much like function in Pascal much like function in Pascal An internal implicit reg is declared inside the function with the same name An internal implicit reg is declared inside the function with the same name The return value is specified by setting that implicit reg The return value is specified by setting that implicit reg defines width and type of the implicit reg defines width and type of the implicit reg type can be integer or real type can be integer or real default bit width is 1 default bit width is 1

Function Examples Parity Generator module parity; reg [31:0] addr; reg parity; Initial begin …end begin parity = calc_parity(addr); parity = calc_parity(addr); $display( "Parity calculated = %b", calc_parity(addr) ); $display( "Parity calculated = %b", calc_parity(addr) );end function calc_parity; input [31:0] address; begin calc_parity = ^address; endendfunctionendmodule

Function Examples Controllable Shifter module shifter; `define LEFT_SHIFT 1'b0 `define RIGHT_SHIFT 1'b1 reg [31:0] addr, left_addr, right_addr; reg control; initialbegin…end left_addr =shift( addr, `LEFT_SHIFT ); left_addr =shift( addr, `LEFT_SHIFT ); right_addr =shift( addr,`RIGHT_SHIFT ); right_addr =shift( addr,`RIGHT_SHIFT );end function [31:0] shift; input [31:0] address; input control; begin shift = (control==`LEFT_SHIFT) ?(address >1); shift = (control==`LEFT_SHIFT) ?(address >1);endendfunctionendmodule

Today Summary Tasks and functions in behavioral modeling Tasks and functions in behavioral modeling The same purpose as subroutines in SW The same purpose as subroutines in SW Provide more readability, easier code management Provide more readability, easier code management Are part of design hierarchy Are part of design hierarchy Tasks are more general than functions Tasks are more general than functions Can represent almost any common Verilog code Can represent almost any common Verilog code Functions can only model purely combinational calculations Functions can only model purely combinational calculations