Embedded Systems 1: Hardware Description Languages (HDLs) for Verification

Similar documents
Synthesizable Verilog

Logic Verification 13-1

Verilog Nonblocking Assignments with Delays - Myths & Mysteries

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

Department of Computer Science and Electrical Engineering. CMPE 415 Verilog Events Timing and Testbenches Prof. Ryan Robucci

Lecture 15: System Modeling and Verilog

ECE 353 Lab 3 (Verilog Design Approach)

Spiral 1 / Unit 4 Verilog HDL. Digital Circuit Design Steps. Digital Circuit Design OVERVIEW. Mark Redekopp. Description. Verification.

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb With material by Professor Moritz and Kundu UMass Amherst Fall 2016

Subject: Scheduling Region Questions and Problems of new SystemVerilog commands

VERILOG. Deepjyoti Borah, Diwahar Jawahar

Synthesis of Combinational and Sequential Circuits with Verilog

SystemVerilog HDL - a programming language

Introduction to Verilog

This Lecture. Some components (useful for the homework) Verilog HDL (will continue next lecture)

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

CSE140L: Components and Design Techniques for Digital Systems Lab

Introduction To Verilog Design. Chun-Hung Chou

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

A Brief Introduction to Verilog Hardware Definition Language (HDL)

CSE140L: Components and Design

ECEN 468 Advanced Logic Design

Verilog. What is Verilog? VHDL vs. Verilog. Hardware description language: Two major languages. Many EDA tools support HDL-based design

Sunburst Design - Verilog-2001 Design & Best Coding Practices by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

Lab 7 (All Sections) Prelab: Introduction to Verilog

Nikhil Gupta. FPGA Challenge Takneek 2012

Verilog Overview. Verilog Overview. Simple Example. Simple Example. Simple Example. Simple Example

Verilog introduction. Embedded and Ambient Systems Lab

Testbench and Simulation

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb UMass Amherst Fall 2017

Chapter 2 Using Hardware Description Language Verilog. Overview

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

UVM for VHDL. Fast-track Verilog for VHDL Users. Cont.

Introduction to Verilog HDL

SystemVerilog Event Regions, Race Avoidance & Guidelines

EEL 4783: HDL in Digital System Design

Nonblocking Assignments in Verilog Synthesis; Coding Styles That Kill!

Politecnico di Milano FACOLTÀ DI INGEGNERIA DELL INFORMAZIONE. Sistemi Embedded 1 A.A Exam date: September 5 th, 2017

EE 4755 Digital Design Using Hardware Description Languages

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

N-input EX-NOR gate. N-output inverter. N-input NOR gate

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

ECE 4514 Digital Design II. Spring Lecture 13: Logic Synthesis

Modular SystemVerilog

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

LSN 1 Digital Design Flow for PLDs

HDL. Hardware Description Languages extensively used for:

Introduction to Verilog/System Verilog

Nonblocking Assignments in Verilog Synthesis, Coding Styles That Kill!

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

Outline. EECS Components and Design Techniques for Digital Systems. Lec 11 Putting it all together Where are we now?

SoC Verification Methodology. Prof. Chien-Nan Liu TEL: ext:

Sunburst Design - Comprehensive SystemVerilog Design & Synthesis by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

Digital Integrated Circuits

Computer Aided Design Basic Syntax Gate Level Modeling Behavioral Modeling. Verilog

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

Overview. Design flow. Principles of logic synthesis. Logic Synthesis with the common tools. Conclusions

תכן חומרה בשפת VERILOG הפקולטה להנדסה

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay Dept of CSE, IIT Madras 1

Register Transfer Level in Verilog: Part I

World Class Verilog & SystemVerilog Training

The Verilog Language COMS W Prof. Stephen A. Edwards Fall 2002 Columbia University Department of Computer Science

HDLs and SystemVerilog. Digital Computer Design

Lab #1. Topics. 3. Introduction to Verilog 2/8/ Programmable logic. 2. Design Flow. 3. Verilog --- A Hardware Description Language

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

HW1 Modeling Concepts

Speaker: Shao-Wei Feng Adviser: Prof. An-Yeu Wu Date: 2010/09/28

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Lecture 32: SystemVerilog

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

The Verilog Hardware Description Language Testing the Design Overview

VERILOG HDL. (and C) 1 ENGN3213: Digital Systems and Microprocessors L#5-6

Sunburst Design - Advanced SystemVerilog for Design & Verification by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

CSE 591: Advanced Hardware Design and Verification (2012 Spring) LAB #0

EE 4755 Digital Design Using Hardware Description Languages

Chapter 4 :: Topics. Introduction. SystemVerilog. Hardware description language (HDL): allows designer to specify logic function only.

Quick Introduction to SystemVerilog: Sequental Logic

Chap 4 Connecting the Testbench and. Design. Interfaces Clocking blocks Program blocks The end of simulation Top level scope Assertions

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

Digital Design with FPGAs. By Neeraj Kulkarni

Techniques for Digital Systems Lab. Verilog HDL. Tajana Simunic Rosing. Source: Eric Crabill, Xilinx

Algorithmic C synthesis (High-level synthesis)

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

Hardware Description Language (HDL)

EECS 270 Verilog Reference: Sequential Logic

Module 4. Design of Embedded Processors. Version 2 EE IIT, Kharagpur 1

TKT-1212 Digitaalijärjestelmien toteutus. Lecture 7: VHDL Testbenches Ari Kulmala, Erno Salminen 2008

Applying Stimulus & Sampling Outputs UVM Verification Testing Techniques

Verilog HDL Introduction

MODELING LANGUAGES AND ABSTRACT MODELS. Giovanni De Micheli Stanford University. Chapter 3 in book, please read it.

Verilog Coding Guideline

EECS150 - Digital Design Lecture 6 - Logic Simulation

Topics. Verilog. Verilog vs. VHDL (2) Verilog vs. VHDL (1)

EECS150 - Digital Design Lecture 7 - Computer Aided Design (CAD) - Part II (Logic Simulation) Finite State Machine Review

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog

Introduction to Verilog. Garrison W. Greenwood, Ph.D, P.E.

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

Transcription:

November 2017 Embedded Systems 1: Hardware Description Languages (HDLs) for Verification Davide Zoni PhD email: davide.zoni@polimi.it webpage: home.deib.polimi.it/zoni

Outline 2 How to test an RTL design Verification vs Validation Simulation based Verification Formal Verification Assertion based Verification Verilog for Simulation based Verification System tasks: $display, $monitor, $write,$display, $finish Procedural Blocks: initial blocks, always blocks Simulation Delay Models Tools: Simulation, Synthesis, Implementation Xilinx Vivado Overview Hands on and Examples Combinatorial, Sequential, FSM Embedded Processor: An OpenRisc1000 Implementation Embedded Systems 1 Davide Zoni

References 3 Material on the website Writing Testbenches using SystemVerilog, Bergeron, Janick, Springer 2006 Hardware Verification with System Verilog, Mike Mintz and Robert Ekendahl, Springer 2007 NOTE: The two classes related to Introduction to Hardware Design and Verification with SystemVerilog within the ES1 MSc course are intended as an off the ground presentation of the topic. Several advances topics are left aside and not covered. These more advanced topics are not part of the written exam and will be introduced to those students involved with the ES1 project.

Recap: Essential Verilog for design 4 Module is the basic building block for the hardware description Input output interface (how to connect with the rest of the hierarchy) Body (description of the semantic) Everything is parallel Always blocks and continuous assignments (their order is irrelevant) NOTE: within an always block order of the statements matters! Different types of assignments Non procedural assignments (Outside the always block) Continuous assignments (keyword assign) Procedural assignments (Only within an always block) Non blocking assignments (<=) Blocking assignments (=) Two types to represents the information Wire (net type), reg (variable type) in the form of bit vectors 4 value logic (0,1,X,Z) Embedded Systems 1 Davide Zoni

Verification VS Validation 5 Verification: set of techniques to check if the design satisfies the specification. Are we correctly building the system? Are we building the system right? Internal process: from the early design stages till post implementation It has to comply with a set of specifications that can eventually be ambiguous or incomplete, then leading to errors/bugs Validation: it answers the question: is the design fulfill with the customer s expectations? Are we building the right system? It is an external process The fact that the design is doing something does not mean it is satisfactory Verification Real Problem / Customer's needs Specification Document Implementation Embedded Systems 1 Davide Zoni Validation

Verification 6 The goal of verification Ensure correct timing and functional behavior for the Design Under Test (DUT) Usually 50% / 70% of the whole design project Verification team is usually twice as big as the design team Functional Verification Simulation Formal proof Timing Verification (NOT COVERED IN THIS CLASS) Dynamic Timing Simulation (DTS) Static Timing Analysis (STA)

Functional Verification 7 Simulation Based Verification Direct Random Constrained Random Formal Verification Model Checking Equivalence Checking Theorem Proving Assertion Based Verification Dynamic Formal Verification

Coverage Analysis 8 Traditionally, the quality of the verification was measured with the help of code coverage tools. The code coverage reflects the executed/visited HDL code. Structural/Code Coverage: This will give information about how many lines/statements of the HDL code are stressed, in terms of how many times they are visited. This coverage is collected by the simulation tools Almost useless to verify the semantic of the HDL description Functional coverage: This coverage is user defined User will define the coverage points for the functions to be covered in DUT This is under user control It is made of two parts: what to visit and how to generate test vectors to reach the modules/functionalities of the design to be tested. Embedded Systems 1 Davide Zoni

Coverage Analysis: Check Points 9 Test generator input DUT output checker F1 F2 F3 F4 F1: sample the generated tests. The coverage stats are updated even if the test is not actually sent to the DUT F2: sample the input vector at the DUT input. Collect DUT input coverage information F3: sample intermediate values within the DUT. Traditionally assertion based techniques are used to test this portion of the design space F4: sample the output vector at the DUT output. Collect DUT output coverage information

We are here The (Simplified) Hardware Design Flow Flow Verilog Code Code Transformations input a,b; output [1:0]; assign sum={1 b0,a}+{1b 0,b}; Behavioral simulation 10 Possible Actions Semantic and syntax checks No physical net/gate propagation delays Target independent Post Synthesis Code synthesis mapping G1 and n1 n2 n5 G2 and n3 n4 n6 G3 or n5 n6 n7 Post synthesis simulation Semantic of the synthesized code No physical net/gate propagation delays Target dependent Post Mapped Code G1 and_tlib n1 n2 n5 G2 and_tlib n3 n4 n6 G3 or_tlib n5 n6 n7 Post mapped simulation Semantic of the synthesized code Physical gate propagation delays No net propagation delays placing Post Place&Route Code Netlist + accurate propagation delays Ready to go! [ FPGA, ASIC ] Post place and route simulation Semantic of the synthesized code Physical gate propagation delays No net propagation delays

The Simulation Flow (Verilog 2001) 11 Blocking assignments From previous time slot Any order between different always blocks Fixed order within begin/end in the same always Evaluate Right Hand Side (RHS) of Non blocking assignments (NBAs) Continuous assignments $display Current time slot Active Inactive NBA #0 blocking assignments (do not use #0 delays. Most of the time they are useless and the same semantic can be modeled with a different description) Update Left Hand Side of Nonblocking assignments (NBAs) $monitor, $strobe system tasks Postponed NOTE: No fixed evaluation order To next time slot Source: IEEE Std 1364 2001, i.e. Verilog 2001 (see link at http://home.deib.polimi.it/zoni/teaching_es1_2017_2018.html) Embedded Systems 1 Davide Zoni

Verilog for Simulation Based Verification 12 tb signal generator input design under test (dut) output testbench tb monitor pass/fail The testbench is the infrastructure for testing. It is made of 3 parts: design under test (dut): the RTL design that you want to test tb_signal_generator: it generates the stimuli for the dut. [It contains the semantic of the test!!!] tb_monitor: checks the output of the dut to report semantic/functional errors Embedded Systems 1 Davide Zoni

The testbench module 13 `timescale [timeunit]/[timeprecision] module minimal_tb_template(); always #5 clk=~clk; //clock generation timescale directive specifies the unit of time and the precision to be used during the simulation Example: `timescale 1ns/10ps NOTE: Inherited from the last processed module if not specified in the.v file reg in1,in2; wire out1; //in/out to the dut initial //initial block (even more than one) begin clk <= 0; //init clk /*init var + procedures to generate input signals to dut */ end //dut instance dut #(parameter.p1(...),...) dut0(.in1(in1),.in2(in2),.out1(out1)); //tb_monitor to check the dut output endmodule The testbench module has no primary inputs and outputs, but can have parameters Verilog comments have the same C/C++ syntax // comment until the end of the line /* multi line comment */ Input to the dut are reg Output from the dut are wire The initial block is a procedural block that is executed once at the simulation startup Not synthesizable

14 Clock, Reset and Maintainability

Behavioral Verilog: Clock Signal 15 reg clk; initial begin clk <= 1 b0; forever #10 clk = ~ clk; end reg clk; initial clk <= 1 b0; always #10 clk = ~ clk; reg clk; initial clk <= 1 b0; always begin #5 clk = 1 b0; #5 clk = 1 b1; end The clock signal is made of nonsynthesizable Verilog statements, i.e. delays [RULE of THUMB] Use blocking assignments to update the clock [in a synchronous design]: Avoid races with other signals that are updated in the same time step Eventually use non blocking assignments for all the other signals The use of non blocking clock update assignment is possible even if it is considered improper

Behavioral Verilog: Reset Signal 16 always #5 clk=~clk initial begin //can race!!! clk<=0; rst=1; #5 rst=0; end IMPROPER DESIGN The clock [clk] and the reset [rst] are updated during the same time step We can observe simulation misbehaviors NOTE: the description can be used ONLY if an asynchronous reset signal is used always #5 clk=~clk initial begin //no races!!! clk<=0; rst=1; #5 rst<=0; end CORRECT DESIGN The clock [clk] and the reset [rst] are updated during the same time step However, we assume clock has precedence to avoid races in the simulation. NOTE: all the signals in the TB that are synchronous to the clock must be updated using NBAs. Embedded Systems 1 Davide Zoni

The `timescale directive: rounding and truncation errors 17 Truncation `timescale 1ns/1ns reg clk; parameter clk_period=25; always #(clk_period/2) clk=~clk; Rounding `timescale 1ns/1ns reg clk; parameter clk_period=25; always #(clk_period/2.0) clk=~clk; Correct Implementation `timescale 1ns/100ps reg clk; parameter clk_period=25; always #(clk_period/2.0) clk=~clk; The design is simulated using an event driven simulation approach timeunit: the unit of time for any kind of delay timeprecision: how many events the simulator can generate at most between two timeunits. Also named time steps timeunit always bigger than timeprecision They can be equal, while rounding and truncation errors can arise Different simulators allow you to specify both timeunit and timeprecision directives without cluttering the hardware source files Rounding errors: due to the precision of the used computing machine Truncation errors: due to the used arithmetic

Behavioral Verilog: Maintainability 1 18 always #5 clk=~clk initial begin //can race!!! clk<=0; rst=1; #5 rst<=0; end IMPROPER DESIGN Use parameter and `define to increase the reusability and maintainability of your testbenches parameter clk_period `define CLK_PERIOD parameter clk_period = 10; parameter rst_delay=10;... always #(clk_period/2) clk=~clk initial begin //no races!!! clk<=0; rst=1; #(rst_delay) rst<=0; end CORRECT DESIGN Parameters are better than defines: parameters are properties of the module defines are just placeholders

Behavioral Verilog: Maintainability 2 19 parameter clk_period = 10; parameter rst_delay=10;... always #(clk_period/2) clk=~clk initial begin //no races!!! clk<=0; rst=1; #(rst_delay) rst<=0; end parameter clk_period = 10; parameter n_cycle=10;... always #(clk_period/2) clk=~clk initial begin //no races!!! clk<=0; rst=1; repeat(n_cycle) @(posedge clk) rst<=0; end Embedded Systems 1 Davide Zoni IMPROPER DESIGN Use the clk to synchronize the update of your design synchronous inputs CORRECT DESIGN The reset (rst) signal is clear after n_cycle of the clock (clk) NOTE: maybe not the best choice if the reset is asynchronous with respect to the clock!!! @(posedge clk) is a nonsynthesizable delay construct @(posedge clk) doesn t mean anything from the physical viewpoint

20 Delay Models in Verilog

Behavioral Verilog Delay Models: Basics 21 Verilog allows to model delays in the hardware description as well as in the testbenches for behavioral simulations Inertial delay model: the inertia of a circuit node to change value. It abstractly models the RC circuit seen by the node ALTERNATIVE DEFINITION: measure of the input hold time to get a change in the output. NOTE: A pulse of duration less than the inertial delay does not contain enough energy to cause the device to switch Transport delay model: the propagation time of signals from module inputs to its outputs NOTE: Time taken by the signal to propagate through the net, also known as time of flight Input Output (inertial delay) Output (transport delay) Source: Correct methods for Adding Delays to Verilog Behavioral Models, Clifford E. Cummings, HDLCON 1999 Embedded Systems 1 Davide Zoni

Behavioral Verilog Delay Models: Blocking Assignments (BA) Adding RHS or LHS delays to model combinatorial logic is common while flawed: always@(a) y=~a always@(a) #5 y=~a The behavioral delay is not synthesizable: it does not have a physical counterpart Depends on the timescale directive Functional Implications No delay Left hand side delay the delay is imposed by the gate from the technology library used to map the NB statement (post synthesis) Correct Implementation for any synthesizable Verilog description 22 Evaluate Right Hand Side (RHS) then update the Left Hand Side (LHS) after 5 timeunit. The time of the LHS update is independent from any further change in the RHS What if an update happens at 2.5timeunits? The first value is lost (single LHS update event is created) always@(a) y= #5 ~a Right hand side delay Immediately evaluate the RHS, then wait 5 timeunit before updating the LHS of the statement What if an update happens at 2.5timeunits? The first value is kept, since RHS is immediately evaluated (single LHS update event is created) Do not use LHS or RHS delays in syntehsizable combinatorial logic Use LHS only for testbench statements to separate series of stimuli

Behavioral Verilog Delay Models: Non Blocking Assignments Adding RHS or LHS delays is also possible for NBAs. While the same implications discussed for BAs are still valid, the RHS delay can be used to model the transport delay in combinatorial logic. Still not synthesizable! 23 always@(a) y<=~a always@(a) #5 y<=~a No delay (correct) Left hand side delay (HW nonsense) the delay is imposed by the gate from the technology library used to map the NB statement (post synthesis) Correct Implementation for any synthesizable Verilog description Evaluate Right Hand Side (RHS) then update the Left Hand Side (LHS) after 5 timeunit What if an update happens at 2.5timeunits? The first value is lost!!! NBA are less efficient to simulate, thus LHS delay for NBA is also discouraged for testbenches. always@(a) y <= #5 ~a Right hand side delay (correct for transport delay modeling) Immediately evaluate the RHS, then wait 5 timeunit before updating the LHS of the statement What if an update happens at 2.5timeunits? The first value is kept and the following are queued. (multiple LHS update events are generated) Do not use LHS delays to model combinatorial logic using NBA (HW nonsense ) Use RHS delays to model the transport delay in combinatorial logic using NBA (new output is queued) Embedded Systems 1 Davide Zoni

Behavioral Verilog Delay Models: Continuous Assignments Adding RHS or LHS delays to continuous assignments is also possible. It makes them not synthesizable Used to model the inertial delay in combinatorial logic to prevent undesired glitches 24 assign y = ~a No delay (correct) the delay is imposed by the gate from the technology library used to map the statement (post synthesis) assign #5 y = ~a assign y = #5 ~a Embedded Systems 1 Davide Zoni Left hand side delay (correct for inertial delay modeling) Right hand side delay (illegal syntax) LHS delay in continuous assignment models the inertial delay of the logic If multiple event updates a within the delay period, only the generated update event is kept NOTE: continuous assignments do not queue new values, while keep the last within the #5 delay to model the inertial delay Question: why don t BAs model the inertial delay? Hint: LHS delay with continuous assignments reschedule the event in the future, if any, while LHS delay with BA just update the LHS value

25 Design Under Test (DUT) Observability: System tasks

$monitor, $display, $write, $strobe 26 Unsynthesizable system tasks to print out useful information on the simulated design. $strobe : print the values at the end of the current timestep. Executed in the postponed region Example: $strobe( %t %b, time,signal); $display : print the immediate values Executed in the active region Example: $display( %t %b, time,signal); $monitor : print the values at the end of the current timestep if any values changed. $monitor can only be called once; sequential calls will override the previous Executed in the postponed region Example: $monitor( %t %b,$time,signal); $write : same as $display but doesn't terminate with a newline (\n) Executed in the active region Example: $write( %t %b\n, time,signal);

The simulation time 27 Verilog allows to report the simulation time by accessing to specific system variables The time value is always scaled to the timeunit The time value can be stored in a variable of proper size if not directly printed Examples real time=$realtime; integer=$stime; integer=$time; $display( %t,$time); $realtime returns a 64 bit floating point value scaled to the time precision $stime return a 32 bit unsigned integer value If current value is bigger than 32 bit, the lower 32 bit only are returned $time return 64 bit integer value scaled to the timeunit, i.e., truncation of fractional timeunit delays The $timeformat(<units>, <precision>, <suffix>,<minimum field width>) allows to specify the $time, $realtime, $stime return value If not specified the default values: <units>: <precision>: 0 <suffix>: null string <minimum field width>: Embedded Systems 1 Davide Zoni

28 Design Under Test (DUT) Observability with VCD

Value Change Dump (VCD) File Extraction 29 The Value Change Dump file can store all the transitions for all the signals in the design during the entire simulation Verilog offers system tasks to instruct the simulator on the vcd dump procedure. Several simulators allow a specific, tool dependant solution for the VCD file dump without affecting the.v files The VCD can be read using a waveform visualizer: Gtkwave [opensource] Simvision [cadence] Xsim waveform [xilinx, free*] Embedded Systems 1 Davide Zoni From within the testbench.v file $dumpfile( file.vcd ); $dumpvars(level,<module_instance/variable>); 0 dump all variable in the module and all of its submodules 1 dump all variables in the module <level> dump all variables in the module and all the variables in the children up to level = <level> 1