当前位置:文档之家› system verilog 初探

system verilog 初探

system verilog 初探
system verilog 初探

system verilog 初探

转载地址:https://www.doczj.com/doc/5d13936295.html,/windzjy/310477/Message.aspx#

转载请声明:

https://www.doczj.com/doc/5d13936295.html,/Blog/post.aspx?id=310477

这是一个sv的验证平台的基本框架,自己画的,对错待证!

1,关于clocking block

举例如下:

待证设计

module COUNTER (input Clock, Reset, Enable, Load, UpDn, input [7:0] Data, output reg[7:0] Q); always @(posedge Clock or posedge Reset)

if (Reset)

Q <= 0;

else if (Enable)

begin

if (Load)

Q <= Data;

else if (UpDn)

Q <= Q + 1;

else

Q <= Q - 1;

end

endmodule

testbench:

module Test_Counter_w_clocking;

timeunit 1ns;

reg Clock = 0, Reset, Enable, Load, UpDn;

reg [7:0] Data;

wire [7:0] Q;

// Clock generator

always

begin

#5 Clock = 1;

#5 Clock = 0;

end

// Test program

program test_counter;

// SystemVerilog "clocking block"

// Clocking outputs are DUT inputs and vice versa

clocking cb_counter @(posedge Clock);

default input #1step output #4;

output negedge Reset;

output Enable, Load, UpDn, Data;

input Q;

endclocking // Apply the test stimulus

initial begin

// Set all inputs at the beginning

Enable = 0;

Load = 0;

UpDn = 1;

Reset = 1;

##1 cb_counter.Reset <= 0; // Will be applied 4ns after the clock!

##1 cb_counter.Enable <= 1;

##2 cb_counter.UpDn <= 0;

##4 cb_counter.UpDn <= 1;

// etc. ...

end

// Check the results - could combine with stimulus block

initial

begin

##1 // Sampled 1ps (or whatever the precision is) before posedge clock

##1 assert (cb_counter.Q == 8'b00000000);

##1 assert (cb_counter.Q == 8'b00000000);

##2 assert (cb_counter.Q == 8'b00000010);

##4 assert (cb_counter.Q == 8'b11111110);

// etc. ... end // Simulation stops automatically when both initials have been completed endprogram

// Instance the counter

COUNTER G1 (Clock, Reset, Enable, Load, UpDn, Data, Q);

// Instance the test program - not required, because program will be

// instanced implicitly.

// test_COUNTER T1 ();

endmodule

自己分析的时序,如下图所示:

1,接口

interface chip_bus; // 定义接口

wire read_request, read_grant;

wire [7:0] address, data;

endinterface: chip_bus

module RAM (chip_bus io, // 使用接口

input clk);

// 可以使用io.read_request引用接口中的一个信号

endmodule

module CPU(chip_bus io, input clk);

...

endmodule

就像一个数据类型一样,可以用它来定义,或者说引用?

2,如果某些变量、函数或其它信息被设计中的所有模块共享,

那么我们就可以将它们作为全局声明和语句。全局声明和语句的一个使用实例如下:reg error _flag; // 全局变量

function compare (...); // 全局函数

always @(error_flag) // 全局语句

...

module test;

chip1 u1 (...)

endmodule

module chip1 (...);

FSM u2 (...);

always @(data)

error_flag = compare(data, expected);

endmodule

module FSM (...);

...

always @(state)

error_flag = compare(state, expected);

endmodule

3,抽象数据类型

char

int

shortint

longint

byte

bit

logic,4 states

shortreal

void

logic类型能够以下面的任何一种方法赋值:

a,通过任意数目的过程赋值语句赋值,能够替代Verilog的reg类型;

b,通过单一的连续赋值语句赋值,能够有限制地替代Verilog的wire类型;

c,连接到一个单一原语的输出,能够有限制地替代Verilog的wire类型;

4,用户定义的数据类型

SystemVerilog通过使用typedef提供了一种方法来定义新的数据类型,

这一点与C语言类似。用户定义的类型可以与其它数据类型一样地使用在声明当中。例如:

typedef unsigned int uint;

uint a, b;

5,枚举类型

值从初始值0开始递增,但是我们可以显式地指定初始值。枚举类型的例子如下:

enum {red, yellow, green} RGB;

enum {WAIT=2’b01, LOAD, DONE} states;

我们还可以使用typedef为枚举类型指定一个名字,从而允许这个枚举类型可以在许多地方使用。例如:typedef enum {FALSE=1’b0, TRUE} boolean;

boolean ready;

boolean test_complete;

6,结构体和联合体

在Verilog语言中不存在结构体或联合体,而结构体或联合体在将几个声明组合在一起的时候

非常有用。SystemVerilog增加了结构体和联合体,它们的声明语法类似于C。

struct {

reg [15:0] opcode;

reg [23:0] addr;

} IR;

union {

int I;

shortreal f;

} N;

结构体或联合体中的域可以通过在变量名和域名字之间插入句点(.)来引用:

IR.opcode = 1; // 设置IR变量中的opcode域

N.f = 0.0; // 将N设置成浮点数的值

我们可以使用typedef为结构体或联合体的定义指定一个名字。

typedef struct {

reg [7:0] opcode;

reg [23:0] addr;

} instruction; // 命名的结构体

instruction IR; // 结构体实例

一个结构体可以使用值的级联来完整地赋值,例如:

instruction = {5, 200}; //IR = {5,200}???jyz

结构体可以作为一个整体传递到函数或任务,也可以从函数或任务传递过来,也可以作为模块端口进行传递。

7,数组

8,assertions

assert (A == B); // Asserts that A equals B; if not, an error is generated

就是如果在这个时候A不等于B的话,那么就会报出一个错误的信息供你debug。

9,A class is a user-defined data type. Classes consist of data (called properties) and tasks

and functions to access the data (called methods). Classes are used in object-oriented programming.

In SystemVerilog, classes support the following aspects of object-orientation – encapsulation, data hiding, inheritance and polymorphism.

10,Classes may be parameterised in the same way that modules may.

class #(parameter int N = 1) Register;

It is also possible to pass a data type to a class:

class #(parameter type T = int) Register; T data; ... endclass Register Rint;

// data is int Register #(bit [7:0]) Rint; // data is bit [7:0]

11,One of the key features of object-oriented programming is the ability to create new classes that are based on existing classes. A derived class by default inherits the properties and methods of its parent or base class. However, the derived class may add new properties and methods, or modify the inherited properties and methods. In other words, the new class is a more specialised version of the original class. In SystemVerilog the syntax for deriving or inheriting one class from another is this:

class Derived extends BaseClass; // New and overridden property and method declarations. endclass 12,vitual class

Sometimes, it is useful to create a class without intending to create any objects of the class. The class exists simply as a base class from which other classes can be derived. In SystemVerilog this is called an abstract class and is declared by using the word virtual:

virtual class Register; ... endclass

13,Traditionally, simulation-based verification has used a directed testing approach. In other words,

a testbench implements tests using specific data values.

14,struct packed { bit [10:0] ID; // 11-bit identifier bit RTR; // reply required? bit [1:0] rsvd; // "reserved for expansion" bits bit [3:0] DLC; // 4-bit Data Length Code byte data[]; // data payload bit [14:0] CRC; //

15-bit checksum } message;

We have used struct packed to define a packed data structure. This means that the data structure can be packed into a single vector,

15,Constraints direct the random generator to choose values that satisfy the properties you specify in your constraints. Within the limits of your constraints, the values are still randomly chosen. The process of choosing values that satisfy the constraints is called solving. The verification tool that

does this is called the solver;

16,

SystemVerilog 3.1a adds important new constructs to Verilog-2001, including:

a, New data types: byte, shortint, int, longint, bit, logic, string, chandle.

b, Typedef, struct, union, tagged union, enum

c, Dynamic and associative arrays; queues

d, Classes

e, Automatic/static specification on a per variable instance basis

f, Packages and support for Compilation Units

g, Extensions to Always blocks for modelling combinational, latched or clocked processes

h, Jump Statements (return, break and continue)

i, Extensions to fork-join, disable and wait to support dynamic processes.

j, Interfaces to encapsulate communication

k, Clocking blocks to support cycle-based methodologies

l, Program blocks for describing tests

m, Randomization and constraints for random and directed-random verification

n, Procedural and concurrent assertions and Coverage for verification

o, Enhancements to events and new Mailbox and Semaphore built-in classes for inter-process communication.

p, The Direct Programming Interface, which allows C functions to be called directly from SystemVerilog (and vice versa) without using the PLI.

q, Assertions and Coverage Application Programming Interfaces (APIs) and extensions to the Verilog Procedural Interface

(VPI) – details of these are outside the scope of the SystemVerilog Golden Reference Guide

17,The clocking event of a clocking block can be accessed directly by using the clocking block name, e.g. @(cb) is equivalent to @(posedge Clk).

18,将设计的端口和测试的端口放在同一个interface中,引用的时候可以只引用内部的一个modport 19,The program block can read and write all signals in modules, and can call

routines in modules, but a module has no visibility into a program.

用于模块之间进行交互的。

20,However, using a module to

hold the testbench often causes timing problems around driving and sampling,

so SystemVerilog introduces the program block to separate the testbench,

both logically and temporally.

21,The simplest interface is just a bundle of nondirectional signals. Use

logic so you can drive the signals from procedural statements.

22,The modport construct

in an interface lets you group signals and specify directions.仅仅是interface的一个子集而已。

23,you should always declare your

program block as automatic so that it behaves more like the

routines in stack-based languages you may have worked with,

such as C.

24,In SystemVerilog you can put tasks, functions, classes, and initial

blocks in a program, but not always blocks.

25,fork join_none指的是到了该执行这个语句块的是,不执行,然后执行,该语句块后面的语句。然后再执行该语句块。

fork join_any,执行完第一个以后

fork...join_none is non-blocking, so all processes in the

fork...join_none start at the same time as the code following the

fork......join_none and the following code continues on.

fork

task_that_may_lock_up;

begin

repeat(10000)

begin

@(posedge clk);

end

$display("Error: Possible lock-up in task_that_may_lock_up");

end

join_any

// Finish will be called even if task_that_may_lock_up never completes

$finish;

最新理解:

fork join;指的是fork join这个语句块和外面的begin end其他的语句串行执行,fork join内部的执行完毕才执行之后的语句。

fork join_none:指的是,这个fork join_none语句块和其后的其他语句块是并行的,也就是说这个fork

join_none并不影响其后的语句的执行。

而fork join_any:要执行了fork join_any语句块中的第一个语句,然后fork join_any后面的语句开始执行,同时fork join_any之内的其他语句也开始并行的执行。

reg[5:0] a ;

initial

a = 6'd0;

#1;

begin

fork

#1 a = 6'd1;#2 a = 6'd2;#3 a = 6'd3; #4 a = 6'd4;

join

#5 a = 6'd5;

# 7 a = 6'd6;

#10 a = 6'd7;

end

结果:0 2 3 4 5 10 17 27

0 1 2 3 4 5 6 7

initial

a = 6'd0;

#1;

begin

fork

#1 a = 6'd1;#2 a = 6'd2;#3 a = 6'd3; #4 a = 6'd4;

join_none

#5 a = 6'd5;

# 7 a = 6'd6;

#10 a = 6'd7;

end

结果:0 2 3 4 5 6 13 23

0 1 2 3 4 5 6 7

initial

a = 6'd0;

#1;

begin

fork

#1 a = 6'd1;#2 a = 6'd2;#3 a = 6'd3; #4 a = 6'd4;

join_any

#5 a = 6'd5;

# 7 a = 6'd6;

#10 a = 6'd7;

end

结果:0 2 3 4 5 7 14 24

0 1 2 3 4 5 6 7

26,How do you pass information between two threads?

The solution is a SystemVerilog mailbox.

From a hardware point of view,

the easiest way to think about a mailbox is that it is just a FIFO, with a source

and sink. The source puts data into the mailbox, and the sink gets values from the mailbox. Mailboxes can have a maximum size or can be unlimited.

27,Consider what happens if a block of code is missing from the

design. Code coverage cannot catch this mistake, but functional coverage can. 28,All storage is static, meaning that

all variables are alive for the entire simulation and routines cannot use a stack to hold arguments and local values.

the classic reg data type so that it can be driven by

continuous assignments, gates and modules,

SystemVerilog stores each element on a longword (32-bit) boundary. So a byte, shortint, and int are all stored in a single longword,

The unpacked array of bytes, b_unpacked, is stored in three longwords. Figure 2-1 Unpacked array storage,浪费了72bits的空间。

VCS对systemverilog 编译的时候要加上选项-sverilog 才可以。

动态数组,可以改变数组的大小。

int dyn[], d2[]; // Empty dynamic arrays

initial begin

dyn = new[5]; // Allocate 5 elements

foreach (dyn[j])

dyn[j] = j; // Initialize the elements

d2 = dyn; // Copy a dynamic array

d2[0] = 5; // Modify the copy

$display(dyn[0],d2[0]); // See both values (0 & 5)

dyn = new[20](dyn); // Expand and copy

dyn = new[100]; // Allocate 100 new integers

// Old values are lost

dyn.delete; // Delete all elements

end

When you copy a fixed-size array to a dynamic array, SystemVerilog calls new[] constructor to allocate space, and then copies the values.

29,You can take even more shortcuts with declaring routine arguments. The direction and type default to ―input logic‖ and are sticky, so you don’t have to repeat these for similar arguments.

task T3;

input a, b;

logic a, b;

output [15:0] u, v;

bit [15:0] u, v;

...

endtask

You could rewrite this as follows.

Example 3-9 Routine arguments with sticky types

task T3(a, b, output bit [15:0] u, v);

主要就是task,function,program class等。

class BusTran;

endclass: BusTran

BusTran b; // Declare a handle

b = new; // Allocate a BusTran object

30,

by using a virtual interface that is merely a handle to

a physical interface.

在verilog中,tb和设计之间的连接是通过net来连接的,但是有的时候接口上有重复的定义,或者说很多具有相同性质的

接口,这样连接的时候就会很麻烦,这个时候就可以通过虚拟的接口来省事。

A SystemVerilog interface is more than just signals — you can put executable

code inside.

?? Class – a basic building block containing routines(methods) and variables(properties). The analogue in Verilog is a module.

?? Object – an instance of a class. In Verilog, you need to instantiate a

module to use it.

?? Handle – a pointer to an object. In Verilog, you use the name of an

instance when you refer to signals and methods from outside the

module. An OOP handle is like the address of the object, but is stored

in a pointer that can only refer to one type.

?? Property – a variable that holds data. In Verilog, this is a signal such

as a register or wire.

?? Method – the procedural code that manipulates variables, contained

in tasks and functions. Verilog modules have tasks and functions plus

initial and always blocks.

?? Prototype – the header of a routine that shows the name, type, and

argument list. The body of the routine contains the executable code.

How does SystemVerilog know which new function to call? It looks at the

type of the handle on the left side of the assignment.

1,顶层的虚拟接口传递给program,然后再通过class的new函数传给class,然后开始对接口做一些动作。2,A scope is a block of code such as a module, program, task, function,

class, or begin-end block.

A name can be relative to the current scope or absolute starting with

$root.

3,

In Example 4-16, the keyword ―this‖

removes the ambiguity to let SystemVerilog know that you are assigning the

local variable, oname, to the class variable, oname.

class Scoping;

string oname;

function new(string oname);

this.oname = oname; // class oname = local oname

endfunction

endclass

Either way,

when you call the routine, you pass a handle to the object, not the object itself.

A common coding mistake is to forget to use ref on routine

arguments that you want to modify, especially handles.

如果想在routing中改变handles,必须将此routing的argument 生命为ref

The core of OOP is to encapsulate(压缩)data and related routines into a class.

The calc_crc

function in the extended class calls calc_crc in the base class using the

super prefix. You can call

terms. As explained in Chapter 4, the OOP

term for a variable in a class is ―property,‖ and a task or function is called a

―method.‖

clocking block 中的input delay 和outputdelay:

inputdelay:就是说我testbench需要你design在active edge 之前的这个delay输出有效的结果,我好进行分析比较。

outputdelay:就是在active edge之后的delay输出给design的信号。

module COUNTER (input Clock, Reset, Enable, Load, UpDn, input [7:0] Data, output reg[7:0] Q); always @(posedge Clock or posedge Reset)

if (Reset)

Q <= 0;

else if (Enable)

begin

if (Load)

Q <= Data;

else if (UpDn)

Q <= Q + 1;

else

Q <= Q - 1;

end

endmodule

module Test_Counter_w_clocking;

timeunit 1ns;

reg Clock = 0, Reset, Enable, Load, UpDn;

reg [7:0] Data;

wire [7:0] Q;

// Clock generator

always

begin

#5 Clock = 1;

#5 Clock = 0;

end

// Test program

program test_counter;

// SystemVerilog "clocking block"

// Clocking outputs are DUT inputs and vice versa

clocking cb_counter @(posedge Clock);

default input #1step output #4;

output negedge Reset;

output Enable, Load, UpDn, Data;

input Q;

endclocking // Apply the test stimulus

initial begin

// Set all inputs at the beginning

Enable = 0;

Load = 0;

UpDn = 1;

Reset = 1;

##1 cb_counter.Reset <= 0; // Will be applied 4ns after the clock!

##1 cb_counter.Enable <= 1;

##2 cb_counter.UpDn <= 0;

##4 cb_counter.UpDn <= 1;

// etc. ...

end

// Check the results - could combine with stimulus block

initial

begin

##1 // Sampled 1ps (or whatever the precision is) before posedge clock

##1 assert (cb_counter.Q == 8'b00000000);

##1 assert (cb_counter.Q == 8'b00000000);

##2 assert (cb_counter.Q == 8'b00000010);

##4 assert (cb_counter.Q == 8'b11111110);

// etc. ... end // Simulation stops automatically when both initials have been completed endprogram

// Instance the counter

COUNTER G1 (Clock, Reset, Enable, Load, UpDn, Data, Q);

// Instance the test program - not required, because program will be

// instanced implicitly.

// test_COUNTER T1 ();

endmodule

1,为什么要用virtual?

In SystemVerilog, most methods should be declared virtual to give

the possibility of being adapted to the extensions of each derived

class and maintain the behavior expected by existing code that uses

the original base class.

我们自己的验证主要是基于functional verification

test 和verification 这两个概念还是有很大区别的。

VMM的介绍:

The SystemVerilog class construct deserves some explanation because classes are core to the

VMM methodology.

VMM represents a methodology supported by a standard library

that consists of a set of base and utility classes to implement a VMM-compliant verification environment and verification components.

channel 的概念:其实就是一个fifo的意思,先进先出。

-----------------------------

put() |nthput ......2sedput 1stput| get()

-----------------------------

Transactor is a term used to define and identify component of verification that acts upon or executes and observes transactions over various paths and cycle time in dynamic verificaiton environments.

class内部的函数和任务不会设计到具体的东西,当对其进行例化的时候说明才真正的要用它了。

class Packet;

// The random variables

rand bit [31:0] src, dst, data[8];

randc bit [7:0] kind;

// Limit the values for src

constraint c {src > 10;

src < 15;}

endclass

Packet p;

initial begin

p = new; // Create a packet

assert (p.randomize());

transmit(p);

end

This class has four random variables. The first three use the rand modifier,

so that every time you randomize the class, the variables are assigned a

value.

每次调用class object.randomize就可以随机产生一些数据。

scoreboard:

used to hold the expected data for ease of comparison against the monitored output values.Each scoreboard is designed to

meet the needs of the self-checking requirements.

SystemVerilog

SystemVerilog 语言简介 SystemVerilog 是一种硬件描述和验证语言(HDVL),它基于 IEEE 1364-2001 Verilog 硬件描述语言 (HDL) 并对其进行了扩展, , 包括扩充了 C 语言数据类型、结构、压缩和非压缩数组、 接口、断 言等等, 这些都使得 SystemVerilog 在一个更高的抽象层次上提高了 设计建模的能力。SystemVerilog 由 Accellera 开发,它主要定位在 芯片的实现和验证流程上, 并为系统级的设计流程提供了强大的连接 能力。 下面我们从几个方面对 SystemVerilog 所作的增强进行简要的 介绍, 期望能够通过这个介绍使大家对 SystemVerilog 有一个概括性 的了解。 1. 接口(Interface) Verilog 模块之间的连接是通过模块端口进行的。为了给组成设 计的各个模块定义端口, 我们必须对期望的硬件设计有一个详细的认 识。不幸的是,在设计的早期,我们很难把握设计的细节。而且,一 旦模块的端口定义完成后,我们也很难改变端口的配置。另外,一个 设计中的许多模块往往具有相同的端口定义,在 Verilog 中,我们必 须在每个模块中进行相同的定义,这为我们增加了无谓的工作量。 SystemVerilog 提供了一个新的、高层抽象的模块连接,这个连 接被称为接口(Interface)。接口在关键字 interface 和 endinterface 之间定义,它独立于模块。接口在模块中就像一个单一的端口一样使 用。在最简单的形式下,一个接口可以认为是一组线网。例如,可以 将 PCI 总线的所有信号绑定在一起组成一个接口。通过使用接口, 我们在进行一个设计的时候可以不需要首先建立各个模块间的互连。 随着设计的深入,各个设计细节也会变得越来越清晰,而接口内的信 号也会很容易地表示出来。当接口发生变化时,这些变化也会在使用 该接口的所有模块中反映出来,而无需更改每一个模块。 下面是一个 接口的使用实例: interface chip_bus; // 定义接口 wire read_request, read_grant; wire [7:0] address, data; endinterface: chip_bus
更多免费资料下载请进: https://www.doczj.com/doc/5d13936295.html, 中国最大的免费课件资料库

system verilog教程

SystemVerilog Tutorials 下面的手册会帮助你了解一些SystemVerilog中最重要的新特点。手册还提供了一些代码样本和例子使你可以对语言有更好"感觉"。这些辅导假设你们已经了解了一些Verilog语言。如果没有,你可以先去看看Verilog设计者指南(V erilog Designer’s Guide)。 * Data types * RTL design * Interfaces * Clocking * Assertion-based verification * Classes * Testbench automation and constraints * The Direct Programming Interface (DPI) SystemVerilog 的数据类型 这个手册将描述Systemverilog新引进的数据类型。他们大多数都是可以综合的,并且可以使RTL级描述更易于理解和书写。 整型和实型 SystemVerilog引进了几种新的数据类型。C语言程序员会熟悉其中的大多数。引进新的数据类型构思是这样的,如果C语言和SystemVerilog有相同的数据类型可以使C语言算法模型更容易的转化为SystemVerilog模型。 Verilog的变量类型有四态:既是0,1,X,Z。SystemVerilog引进了新的两态数据类型,每一位只可以是0或是1。当你不需要使用的X和Z值时,譬如在写Testbench和做为for语句的循环变量。使用两态变量的RTL级模型,可以使模拟器更有效率。并且使用得当的话将不会对综合结果产生影响。 二态整型 类型描述例子 Bit user-defined size bit [3:0] a_nibble; Byte 8 bits, unsigned byte a, b; Shortint 16 bits, signed shortint c, d; Int 32 bits, signed int i,j; Longint 64 bits, signed longint lword;

SystemVerilog语言简介(doc 26页)

SystemVerilog语言简介(doc 26页)

SystemVerilog语言简介 SystemVerilog是一种硬件描述和验证语言(HDVL),它基于IEEE 1364-2001 Verilog硬件描述语言(HDL),并对其进行了扩展,包括扩充了C语言数据类型、结构、压缩和非压缩数组、接口、断言等等,这些都使得SystemVerilog在一个更高的抽象层次上提高了设计建模的能力。SystemVerilog由Accellera 开发,它主要定位在芯片的实现和验证流程上,并为系统级的设计流程提供了强大的连接能力。下面我们从几个方面对SystemV erilog所作的增强进行简要的介绍,期望能够通过这个介绍使大家对SystemVerilog有一个概括性的了解。 1. 接口(Interface) Verilog模块之间的连接是通过模块端口进行的。为了给组成设计的各个模块定义端口,我们必须对期望的硬件设计有一个详细的认识。不幸的是,在设计的早期,我们很难把握设计的细节。而且,一旦模块的端口定义完成后,我们也很难改变端口的配置。另外,一个设计中的许多模块往往具有相同的端口定义,在Verilog中,我们必须在每个模块中进行相同的定义,这为我们增加了无谓的工作量。 SystemVerilog提供了一个新的、高层抽象的模块连接,这个连接被称为接口(Interface)。接口在关键字interface和e ndinterface之间定义,它独立于模块。接口在模块中就像一个

单一的端口一样使用。在最简单的形式下,一个接口可以认为是一组线网。例如,可以将PCI总线的所有信号绑定在一起组成一个接口。通过使用接口,我们在进行一个设计的时候可以不需要首先建立各个模块间的互连。随着设计的深入,各个设计细节也会变得越来越清晰,而接口内的信号也会很容易地表示出来。当接口发生变化时,这些变化也会在使用该接口的所有模块中反映出来,而无需更改每一个模块。下面是一个接口的使用实例:

FPGA学习指南

PS:笔者强烈建议诸位注册一个EETOP的账号,每天签到或者发贴、回贴就有积分了,里面的资源非常丰富,各种软件、资料都能找到。 一、入门首先要掌握HDL(HDL=verilog+VHDL)。 第一句话是:还没学数电的先学数电。然后你可以选择verilog或者VHDL,有C语言基础的,建议选择VHDL。因为verilog太像C了,很容易混淆,最后你会发现,你花了大量时间去区分这两种语言,而不是在学习如何使用它。当然,你思维能转得过来,也可以选verilog,毕竟在国内verilog用得比较多。 接下来,首先找本实例抄代码。抄代码的意义在于熟悉语法规则和编译器(这里的编译器是硅编译器又叫综合器,常用的编译器有:Quartus、ISE、Vivado、Design Compiler、Synopsys的VCS、iverilog、Lattice的Diamond、Microsemi/Actel的Libero、Synplify pro),然后再模仿着写,最后不看书也能写出来。编译完代码,就打开RTL图,看一下综合出来是什么样的电路。 HDL是硬件描述语言,突出硬件这一特点,所以要用数电的思维去思考HDL,而不是用C语言或者其它高级语言,如果不能理解这句话的,可以看《什么是硬件以及什么是软件》。在这一阶段,推荐的教材是《Verilog传奇》、《Verilog HDL高级数字设计》或者是《用于逻辑综合的VHDL》。不看书也能写出个三段式状态机就可以进入下一阶段了。 此外,你手上必须准备Verilog或者VHDL的官方文档,《verilog_IEEE官方标准手册-2005_IEEE_P1364》、《IEEE Standard VHDL Language_2008》,以便遇到一些语法问题的时候能查一下。 二、独立完成中小规模的数字电路设计。 现在,你可以设计一些数字电路了,像交通灯、电子琴、DDS等等,推荐的教材是《Verilog HDL应用程序设计实例精讲》。在这一阶段,你要做到的是:给你一个指标要求或者时序图,你能用HDL设计电路去实现它。这里你需要一块开发板,可以选Altera的cyclone IV系列,或者Xilinx的Spantan 6。还没掌握HDL之前千万不要买开发板,因为你买回来也没用。这里你没必要每次编译通过就下载代码,咱们用modelsim仿真(此外还有QuestaSim、NC verilog、Diamond的Active-HDL、VCS、Debussy/Verdi等仿真工具),如果仿真都不能通过那就不用下载了,肯定不行的。在这里先掌握简单的testbench就可以了。推荐的教材是《WRITING TESTBENCHES Functional Verification of HDL Models》。 三、掌握设计方法和设计原则。 你可能发现你综合出来的电路尽管没错,但有很多警告。这个时候,你得学会同步设计原则、优化电路,是速度优先还是面积优先,时钟树应该怎样设计,怎样同步两个异频时钟 《Altera FPGA/CPLD 等等。推荐的教材是《FPGA权威指南》、《IP核芯志-数字逻辑设计思想》、 设计》第二版的基础篇和高级篇两本。学会加快编译速度(增量式编译、LogicLock),静态时序分析(timequest),嵌入式逻辑分析仪(signaltap)就算是通关了。如果有不懂的地方可以暂时跳过,因为这部分还需要足量的实践,才能有较深刻的理解。 四、学会提高开发效率。 因为Quartus和ISE的编辑器功能太弱,影响了开发效率。所以建议使用Sublime text 编辑器中代码片段的功能,以减少重复性劳动。Modelsim也是常用的仿真工具,学会TCL/TK 以编写适合自己的DO文件,使得仿真变得自动化,推荐的教材是《TCL/TK入门经典》。你可能会手动备份代码,但是专业人士都是用版本控制器的,所以,为了提高工作效率,必须掌握GIT。文件比较器Beyond Compare也是个比较常用的工具。此外,你也可以使用System Verilog来替代testbench,这样效率会更高一些。如果你是做IC验证的,就必须掌

Systemverilog的一个牛人总结

转一篇Systemverilog的一个牛人总结 (2012-12-12 16:47:06) 转载▼ 标签: 分类:Dreamywork systemverilog 验证 面向对象 杂谈 Systemverilog 数据类型 l 合并数组和非合并数组 1)合并数组: 存储方式是连续的,中间没有闲置空间。 例如,32bit的寄存器,可以看成是4个8bit的数据,或者也可以看成是1个32bit的数据。 表示方法: 数组大小和位,必须在变量名前指定,数组大小必须是【msb:lsb】 Bit[3:0] [7:0] bytes ; 2)二维数组和合并数组识别: 合并数组: bit [3:0] [7:0] arrys; 大小在变量名前面放得,且降序 二维数组: int arrays[0:7] [0:3] ; 大小在变量名后面放得,可降序可升序 位宽在变量名前面,用于识别合并和非合并数组,位宽在后面,用于识别数组中元素个数。 3)非合并数组 一般仿真器存放数组元素时使用32bit的字边界,byte、shortint、int都放在一个字中。 非合并数组:字的地位存放变量,高位不用。 表示方法: Bit [7:0] bytes; 4)合并数组和非合并数组的选择 (1)当需要以字节或字为单位对存储单元操作。 (2)当需要等待数组中变化的,则必须使用合并数组。例如测试平台需要通过存储器数据的变化来唤醒,需要用到@,@只能用于标量或者合并数组。

Bit[3:0] [7:0] barray[3] ; 表示合并数组,合并数组中有3个元素,每个元素时8bit,4个元素可以组成合并数组 可以使用barry[0]作敏感信号。 l 动态数组 随机事物不确定大小。 使用方法:数组在开始是空的,同时使用new[]来分配空间,在new[n]指定元素的个数。 Int dyn[]; Dyn = new[5]; //分配5个元素空间 Dyn.delete() ; //释放空间 l 队列 在队列中增加或删除元素比较方便。 l 关联数组 当你需要建立一个超大容量的数组。关联数组,存放稀疏矩阵中的值。 表示方法: 采用在方括号中放置数据类型的形式声明: Bit[63:0] assoc[bit[63:0]]; l 常量: 1)Verilog 推荐使用文本宏。 好处:全局作用范围,且可以用于位段或类型定义 缺点:当需要局部常量时,可能引起冲突。 2)Parameter 作用范围仅限于单个module 3)Systemverilog: 参数可以在多个模块里共同使用,可以用typedef 代替单调乏味的宏。 过程语句 l 可以在for循环中定义变量,作用范围仅在循环内部 for(int i=0;i<10;i++) array[i] =i; l 任务、函数及void函数 1)区别:

Systemverilog的数据类型教程

本教程将介绍新引入Systemverilog的数据类型。他们大多数是可综合的,而且使得RTL级描述更易于被编写和理解。 整型和实型 SystemVerilog 引入了几种新的数据类型。C语言程序员会熟悉其中的大多数。引进新的数据类型构思是这样的,如果C语言和SystemVeri log有相同的数据类型的话可以使C语言算法模型更容易的转化为Syst emVerilog模型。 Verilog的变量类型是四态类型:即0,1,X(未知值)和Z(高阻值)。SystemVerilog新引入了两态的数据类型,每一位只可以是0或者1。当你不需要使用的X和Z值时,譬如在写Testbench和做为For 语句的循环变量时。使用两态变量的RTL级模型,可以使仿真器效率更高。而且使用得当的话将不会对综合结果产生任何的影响。 注意:和C语言不一样,SystemVerilog指定了一些固定宽度的数据类型。 logic是一种比reg型更好更完善的数据类型。我们将会看到,你可

以使用logic型来替代过去您有可能使用reg型或wire型的地方。 数组 在Verilog-1995中,你可以定义标量或是矢量类型的线网和变量。你也可以定义一维数组变量类型的存储器数组。在Verilog-2001中允许多维的线网和变量数组存在,并且取消了部分存储器数组用法的限制。 SystemVerilog进一步完善了数组的概念,并对数组重新进行了定义,从而允许对数组进行更多的操作。 在SystemVerilog中,数组可以有压缩尺寸或是非压缩尺寸的属性,也可以同时具有两种属性。考虑下面的例子: reg [3:0][7:0] register [0:9]; 压缩尺寸是[3:0]和[7:0],非压缩尺寸是[0:9] 。(只要你喜欢可以有任意大小的压缩尺寸和非压缩尺寸) 压缩尺寸: 1)保证将在存储器中产生连续的数据 2)可以复制到任何其他的压缩对象中 3)可切片("部分选取") 4)仅限于位类型(bit, logic, int等),其中有些(如int)有固定的 尺寸 相比之下,非压缩数组在内存中的排列方式由仿真器任意选定。我们可以可靠地复制非压缩数组到另一个具有相同数据类型的数组中。对于不同数据类型的数组,你必须使用强制类型转换(有几个非压缩数组转换到压缩数组的规则)。其中非压缩数组可以是任意的类型,如实数数组。

system verilog 类的继承

类的继承 SystemVerilog支持单继承(类似Java,而不像C++). 有一个让SystemVerilog支持多重继承的提案[1], 但是短期内不会看到曙光。 目录 ? 1 什么是继承? ? 2 有什么好处 ? 3 开-关定律 ? 4 参考资料 什么是继承? 继承是面向对象编程范式的关键概念。类用来创建用户自定义类型. 继承使得用户可以用非常安全,非侵入的方式对类的行为进行增加或者修改。 使用继承可以定义子类型,在子类型中增加新的方法和数据。被继承的类一般称为基类(SystemVerilog中的超类),得到的新类一般称为引申类(或子类)。 为什么继承如此重要? 因为它使得复用得以实现。让我们通过实例来说明. 假设我们对一个图像模块进行建模. 对其中一部分,我们写了一个代表颜色的类: class Color; byte unsigned red; byte unsigned green; byte unsigned blue; function new(byte unsigned red_=255, byte unsigned green_=255, byte unsigned blue_=255); red=red_; green=green_; blue=blue_; endfunction:new function mix(Color other); function brighter(float percent); task draw_pixel(int x,int y);

Now现在它的下一个版本希望能够处理部分透明的图像。为此,我们给Color类增加了一个alpha成员,。alpha代表图像的透明度。alpha越大,图像的像素越结实(不透明)。'0'代表完全透明,使得图片的背景全部可见。因此,我们修改color类如下: class Color; byte unsigned red; byte unsigned green; byte unsigned blue; byte unsigned alpha; function new(byte unsigned red_=255, byte unsigned green_=255, byte unsigned blue_=255, byte unsigned alpha_=255); red=red_; green=green_; blue=blue_; alpha=alpha_; endfunction:new function mix(Color other);// new implementation -- would depend on // alpha values for both the colors function brighter(float percent);// original implementation good enough task draw_pixel(int x,int y);// new implementation // Other functions ... endclass:Color 注意,即使许多代码是由之前版本的Color类复制而来,我们还是需要单独维护两个版本的代码。这时继承就可以发挥作用,使用继承,我们可以简单的从原始的Color类继承出新类,来添加alpha成员。 class ColorWithAlpha extends Color; byte unsigned alpha; function new(byte unsigned red_=255, byte unsigned green_=255, byte unsigned blue_=255, byte unsigned alpha_=255);

system_verilog教程

基于断言的验证技术 SystemVerilog Tutorials 下面的手册会帮助你了解一些SystemVerilog中最重要的新特点。手册还提供了一些代码样本和例子使你可以对语言有更好"感觉"。这些辅导假设你们已经了解了一些Verilog语言。如果没有,你可以先去看看Verilog设计者指南(V erilog Designer’s Guide)。 * Data types * RTL design * Interfaces * Clocking * Assertion-based verification * Classes * Testbench automation and constraints * The Direct Programming Interface (DPI) SystemVerilog 的数据类型 这个手册将描述Systemverilog新引进的数据类型。他们大多数都是可以综合的,并且可以使RTL级描述更易于理解和书写。 整型和实型 SystemVerilog引进了几种新的数据类型。C语言程序员会熟悉其中的大多数。引进新的数据类型构思是这样的,如果C语言和SystemVerilog有相同的数据类型可以使C语言算法模型更容易的转化为SystemVerilog模型。 Verilog的变量类型有四态:既是0,1,X,Z。SystemVerilog引进了新的两态数据类型,每一位只可以是0或是1。当你不需要使用的X和Z值时,譬如在写Testbench和做为for语句的循环变量。使用两态变量的RTL级模型,可以使模拟器更有效率。并且使用得当的话将不会对综合结果产生影响。 二态整型 类型描述例子 Bit user-defined size bit [3:0] a_nibble;

systemverilog面试

Qi1)What is callback (Qi2)What is factory pattern (Qi3)Explain the difference between data types logic and reg and wire . (Qi4)What is the need of clocking blocks (Qi5)What are the ways to avoid race condition between testbench and RTL using SystemVerilog (Qi6)Explain Event regions in SV. (Qi7)What are the types of coverages available in SV (Qi8)What is OOPS (Qi9)What is inheritance and polymorphism (Qi10)What is the need of virtual interfaces (Qi11)Explain about the virtual task and methods . (Qi12)What is the use of the abstract class (Qi13)What is the difference between mailbox and queue

(Qi14)What data structure you used to build scoreboard (Qi15)What are the advantages of linkedlist over the queue (Qi16)How parallel case and full cases problems are avoided in SV (Qi17)What is the difference between pure function and cordinary function (Qi18)What is the difference between $random and $urandom (Qi19)What is scope randomization (Qi20)List the predefined randomization methods. (Qi21)What is the dfference between always_combo and always@(*)c (Qi22)What is the use of packagess (Qi23)What is the use of $cast (Qi24)How to call the task which is defined in parent object into derived class (Qi25)What is the difference between rand and randc (Qi26)What is $root (Qi27)What is $unit

systemverilog 实验

INTRODUCTION In this tutorial, we will verify the Switch RTL core. Following are the steps we follow to verify the Switch RTL core. 1) Understand the specification 2) Developing Verification Plan 3) Building the Verification Environment. We will build the Environment in Multiple phases, so it will be easy for you to learn step by step. Phase 1) We will develop the testcase and interfaces, and integrate them in these with the DUT in top module. Phase 2) We will Develop the Environment class. Phase 3) We will develop reset and configuration methods in Environment class. Then using these methods, we will reset the DUT and configure the port address. Phase 4) We will develop a packet class based on the stimulus plan. We will also write a small code to test the packet class implementation. Phase 5) We will develop a driver class. Packets are generated and sent to DUT using driver. Phase 6) We will develop receiver class. Receiver collects the packets coming from the output port of the DUT. Phase 7) We will develop scoreboard class which does the comparison of the expected packet with the actual packet received from the DUT. Phase 8) We will develop coverage class based on the coverage plan. Phase 9) In this phase , we will write testcases and analyze the coverage report.

SystemVerilog 中的随机化激励

SystemVerilog中的随机化激励 神州龙芯集成电路设计公司 杨鑫 徐伟俊 陈先勇 夏宇闻 [摘要]:随着集成电路的验证工作日渐复杂,对验证的可靠性提出了越来越高的要求。传统的验证工作中也使用随机化激励以便减轻测试代码编写的工作量,以提升验证的可靠性。在SystemVerilog更强调了利用随机化激励函数以提高验证代码的效率和验证可靠性的重要性。本文以VMM库为例,阐述了如何在SystemVerilog中使用随机化函数来编写高效率的测试代码,重点介绍了可重用验证函数库的使用方法,以帮助读者理解如何使用SystemVerilog高效率地完成复杂的设计验证。 关键字:VMM SystemVerilog 激励随机化 1. 前言 随着电路工艺设计技术的不断发展,集成电路的逻辑设计变得越来越复杂,随之对验证工作提出了更高的要求。由于投片(tip-out)的费用较高,很有必要在投片前对芯片设计进行全面、可信的验证,以尽量减少“设计——测试——投片——调试——发现Bug修改设计”这一流程的迭代次数。因此在集成电路芯片的设计中,尤其是复杂逻辑设计中,对测试工作的效率和可靠性提出了更高的要求。 在传统的验证方法中,也有将激励随机化的方法,这样可以用较少的测试代码生成较多、较全面的测试激励。这些方法减少了人为因素的干扰,能有效地提高验证的工作效率和可靠性。 在SystemVerilog中,强调在验证中使用可重用的验证IP,包括如何生成随机化激励。对于如何尽可能地使用已有的验证IP,以及编写符合标准的可重用验证组件,SystemVerilog提供了一整套的工作机制,这使得符合规范的随机化激励组件能够很好地在多个设计间复用,这更进一步地提高了验证工作的效率和可靠性。 2. 在验证中使用随机化激励 在验证中,可以依照DUT(Design Under Test,被测设计,以下简称DUT)的验证要求来设计定向的激励,并对照DUT的预期响应,用人工的方法来判断设计是否正确。但也可以使用随机化激励来驱动DUT,并使用特定的机制来完成响应的自检测。 利用随机化来产生激励可以看作一种近似的自动化激励产生,因为随机化足够长的时间后,所生成的激励可以覆盖绝大部分的待验证特性。但是纯粹的随机化激励效率并不高,因为其中正确的,或是有意义的激励只占很少一部分。必须使用一定的约束条件限制随机化的范围,从而产生大量随机而有意义的激励。

System Verilog笔记总结

Systemverilog 数据类型 l 合并数组和非合并数组 1)合并数组: 存储方式是连续的,中间没有闲置空间。 例如,32bit的寄存器,可以看成是4个8bit的数据,或者也可以看成是1个32bit的数据。 表示方法: 数组大小和位,必须在变量名前指定,数组大小必须是【msb:lsb】 Bit[3:0] [7:0] bytes ; 2)二维数组和合并数组识别: 合并数组: bit [3:0] [7:0] arrys; 大小在变量名前面放得,且降序 二维数组: int arrays[0:7] [0:3] ; 大小在变量名后面放得,可降序可升序 位宽在变量名前面,用于识别合并和非合并数组,位宽在后面,用于识别数组中元素个数。 3)非合并数组 一般仿真器存放数组元素时使用32bit的字边界,byte、shortint、int都放在一个字中。 非合并数组:字的地位存放变量,高位不用。 表示方法: Bit [7:0] bytes; 4)合并数组和非合并数组的选择 (1)当需要以字节或字为单位对存储单元操作。 (2)当需要等待数组中变化的,则必须使用合并数组。例如测试平台需要通过存储器数据的变化来唤醒,需要用到@,@只能用于标量或者合并数组。 Bit[3:0] [7:0] barray[3] ; 表示合并数组,合并数组中有3个元素,每个元素时8bit,4个元素可以组成合并数组 可以使用barry[0]作敏感信号。 l 动态数组 随机事物不确定大小。 使用方法:数组在开始是空的,同时使用new[]来分配空间,在new[n]指定元素的个数。 Int dyn[]; Dyn = new[5]; //分配5个元素空间 Dyn.delete() ; //释放空间

systemverilog验证学习笔记

=阻塞串行 <=非阻塞并行 1)时序逻辑----使用非阻塞赋值 2)锁存器----使用非阻塞赋值 3)用always块生成的组合逻辑----用阻塞赋值 4)在同一个always块中既有时序逻辑又有组合逻辑--- 用非阻塞赋值 5)在同一个always块中不要既用阻塞赋值又用非阻塞赋值 6)不要在一个以上的always块中对同一个变量赋值 7)用$strobe显示用非阻塞赋值指定的变量值 8)不要用#0 过程性赋值Modport将信号分组并指明方向 函数不能消耗时间,不能有#100@(posedge clk)wait之类的阻塞语句 Interface arb_if(input bit clk); Logic [1:0] a,b; Logic rst; Modport test(output a,rst, Input b,clk); Endinterface

Module arb(arb_if.test arbif); ………… Endmodule 数组定位 Int tq[$],d[]=’{9,1,8,3,4,4}; Tq=d.find_index(x) with (item>3); //{0,2,4,5}得到的是脚标 Tq=d.find with (item>3); //{9,8,4,4} 数组求和 Int count,total; Count=d.sum with(item>7); //2:{9,8} 返回结果为元素与7比较表达式返回1为真或者零这里面返回,{1,0,1,0,0,0}求和得2 Total=d.sum with ((item>7)*item) ; //{1,0,1,0,0,0}和对应元素相乘求和得17=9加8 数组排序 d.reverse(); //逆序 d.sort(); //从小到大 d.rsotr(); //从大到小 d.shuffle();

最新整理Systemverilog语言简介.doc

SystemVerilog语言简介 SystemVerilog是一种硬件描述和验证语言(HDVL),它基于IEEE 1364-20 xx Verilog硬件描述语言(HDL),并对其进行了扩展,包括扩充了C语言数据类型、结构、压缩和非压缩数组、接口、断言等等,这些都使得SystemVerilo g在一个更高的抽象层次上提高了设计建模的能力。SystemVerilog由Acceller a开发,它主要定位在芯片的实现和验证流程上,并为系统级的设计流程提供了强大的连接能力。下面我们从几个方面对SystemVerilog所作的增强进行简要的介绍,期望能够通过这个介绍使大家对SystemVerilog有一个概括性的了解。 1. 接口(Interface) Verilog模块之间的连接是通过模块端口进行的。为了给组成设计的各个模块定义端口,我们必须对期望的硬件设计有一个详细的认识。不幸的是,在设计的早期,我们很难把握设计的细节。而且,一旦模块的端口定义完成后,我们也很难改变端口的配置。另外,一个设计中的许多模块往往具有相同的端口定义,在Verilog中,我们必须在每个模块中进行相同的定义,这为我们增加了无谓的工作量。 SystemVerilog提供了一个新的、高层抽象的模块连接,这个连接被称为接口(Interface)。接口在关键字interface和endinterface之间定义,它独立于模块。接口在模块中就像一个单一的端口一样使用。在最简单的形式下,一个接口可以认为是一组线网。例如,可以将PCI总线的所有信号绑定在一起组成一个接口。通过使用接口,我们在进行一个设计的时候可以不需要首先建立各个模块间的互连。随着设计的深入,各个设计细节也会变得越来越清晰,而接口内的信号也会很容易地表示出来。当接口发生变化时,这些变化也会在使用该接口的所有模块中反映出来,而无需更改每一个模块。下面是一个接口的使用实例:interface chip_bus; // 定义接口 wire read_request, read_grant; wire [7:0] address, data; endinterface: chip_bus module RAM (chip_bus io, // 使用接口 input clk); // 可以使用io.read_request引用接口中的一个信号 endmodule module CPU(chip_bus io, input clk); ...

System verilog概述

SystemVerilog断言及其应用 神州龙芯集成电路设计公司 陈先勇 徐伟俊 杨鑫 夏宇闻 [摘要]:在介绍SystemVerilog断言的概念、使用断言的好处、断言的分类、断言的组成以及断言如何被插入到被测设计(DUT)的基础上,本文详细地介绍了如何使用不同的断言语句对信号之间的复杂时序关系进行严格的检查,并针对每个例子展示了在ModelSim 6.1b仿真环境中所显示的波形。本文旨在帮助读者理解如何使用断言对设计中信号间复杂时序关系进行验证的方法,并由此介绍一些基本的SystemVerilog断言、操作符、代码段和断言验证方法学。 关键字:SystemVerilog,断言, DUT, SVA,Assertion 1.前言 当今,数字电路的规模和复杂度在不断增长,这使得对设计进行彻底的验证将成为一项巨大的挑战。在整个芯片设计过程中,验证工作所需的时间将占去设计周期的70%~80%,验证工程师的人数将是设计工程师的两倍。这就迫切需要提高验证工作的效率,以解决验证瓶颈问题。 传统上,对被测设计(DUT)的验证都是通过在DUT的输入端口加上具有特定时序激励,然后观察DUT的内部状态变化和最后的输出信号,以确定DUT工作是否正确。这种方法对简单的小规模的设计很有用。但当设计规模变大时,要想使用这种方法来验证DUT是不现实的。因为对于规模大的设计,要想遍历设计将遇到的各种情况,验证其正确性,需要成千上万的特定时序激励。并且如果设计稍有一点变动,这些时序激励就得重新编写。设计的复杂性迫使验证工程师使用随机测试平台来生成更多的验证激励。高级验证语言,如OVA,PSL等,便在创建复杂测试平台时得到了广泛的应用。但这些验证语言和RTL级的编码语言不一致,使得验证很容易出现错误,造成调试工作的不方便。 SystemVerilog的出现可以解决这些问题。 SystemVerilog是在Verilog语言的基础上发展而来的,用SystemVerilog语言可以很容易地生成复杂的随机测试激励,并能方便地编写断言和测试代码覆盖率的代码。断言在验证过程中的用途如下图所示:

利用Systemverilog+UVM搭建SOC及ASIC的RTL验证环境

基于SV+UVM搭建SOC/ASIC验证平台 UVM-1.1中提供了一个UBUS的例子,但是该例子对于刚刚入门的人来说还是需要一定时间去消化的,本文对该例子进行一步一步的简化,可以帮助理解。 [1-11]如何顺序的写UVM平台(1)-Basic [1- 1.平台可以在前期规划好,但是对于搭建平台的人来说,调试永远是最大的问题,如果都 将一个个component都写完了,调试起来还是有点痛苦的,所以我更倾向于一步一步的调试平台;先写一个可以pass的基本平台,然后在不断的扩展该平台,最后在各个component中加入所需要的function或者task。当然,当对搭建平台数量以后,现在基本对平台中的component一次性搭建完成,然后调试并添加需要的function或者task即可。 2.最简单的UVM平台,一个interface,一个DUT,一个TOP,一个test,一个ENV就 可以工作了,然后慢慢的添加各个component; 3.写interface 4.写top module,在top中例化DUT,interface和DUT在top中include uvm_config_db#(virtual ubus_if)::set(uvm_root::get(),"*","vif",vif);

run_test(); 5.写Makefile,此时编译可以通过 6.写自定义的package,然后在top中include该package typedef uvm_config_db#(virtual ubus_if)ubus_vif_config; typedef virtual ubus_if ubus_vif; 后来证明,这两句话在ubus的env中根本没有用上; 7.定义Environment,并将该文件加入到自定义的package中,这个时候编译不能通过 此处的get和top中的set是一对,如果top中没有set则会报告·uvm_fatal中的错误if(!uvm_config_db#(virtual ubus_if)::get(this,"","vif",vif)) `uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"}); 8.定义base_test,需要在top中include该test文件,并在makefile中加入编译该test的 命令;此时可以再次编译通过,并运行最basic的testcase

system verilog 初探

system verilog 初探 转载地址:https://www.doczj.com/doc/5d13936295.html,/windzjy/310477/Message.aspx# 转载请声明: https://www.doczj.com/doc/5d13936295.html,/Blog/post.aspx?id=310477 这是一个sv的验证平台的基本框架,自己画的,对错待证! 1,关于clocking block 举例如下: 待证设计 module COUNTER (input Clock, Reset, Enable, Load, UpDn, input [7:0] Data, output reg[7:0] Q); always @(posedge Clock or posedge Reset) if (Reset) Q <= 0; else if (Enable) begin if (Load) Q <= Data; else if (UpDn) Q <= Q + 1; else Q <= Q - 1; end endmodule

testbench: module Test_Counter_w_clocking; timeunit 1ns; reg Clock = 0, Reset, Enable, Load, UpDn; reg [7:0] Data; wire [7:0] Q; // Clock generator always begin #5 Clock = 1; #5 Clock = 0; end // Test program program test_counter; // SystemVerilog "clocking block" // Clocking outputs are DUT inputs and vice versa clocking cb_counter @(posedge Clock); default input #1step output #4; output negedge Reset; output Enable, Load, UpDn, Data; input Q; endclocking // Apply the test stimulus initial begin // Set all inputs at the beginning Enable = 0; Load = 0; UpDn = 1; Reset = 1; ##1 cb_counter.Reset <= 0; // Will be applied 4ns after the clock! ##1 cb_counter.Enable <= 1; ##2 cb_counter.UpDn <= 0; ##4 cb_counter.UpDn <= 1; // etc. ... end // Check the results - could combine with stimulus block initial begin ##1 // Sampled 1ps (or whatever the precision is) before posedge clock ##1 assert (cb_counter.Q == 8'b00000000); ##1 assert (cb_counter.Q == 8'b00000000); ##2 assert (cb_counter.Q == 8'b00000010); ##4 assert (cb_counter.Q == 8'b11111110); // etc. ... end // Simulation stops automatically when both initials have been completed endprogram

相关主题
文本预览
相关文档 最新文档