Top Banner
Programming Language Interface (PLI) Pedram A. Riahi Test Seminar August 11 th , 2004
35
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ProgrammingLanguageInterface(PLI)

Programming Language Interface (PLI)

Pedram A. Riahi

Test Seminar

August 11th, 2004

Page 2: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 2

Contents

PLI HistoryVerilog PLI OverviewVerilog VPI RoutinesCadence VPI EnvironmentMentor Graphics VPI

EnvironmentReferences

Page 3: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 3

PLI History

1985 - The PLI was developed by Gateway Design Automation as part of the proprietary Verilog-XL simulator

1990 - The PLI standard was released to the public domain along with the Verilog HDL and Verilog SDF standards by Cadence Design System

1990 - Open Verilog International (OVI) “owned” the Verilog HDL, the OVI version of the PLI was called PLI 1.0

1993 - OVI released PLI 2.0, a completely new interface, intended to replace PLI 1.0

1993 - OVI submitted Verilog to the IEEE for standardization

1995 -The IEEE-1364-1995 Verilog PLI standard was released

2001 -The IEEE-1364-2001 Verilog HDL & PLI standard updated with many new language features many new language features

Page 4: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 4

Verilog PLI Overview

IEEE Std Verilog HDL LRM Clauses 20-27 and Appendices E-G

Verilog PLI Generations:Task/Function Routines

(TF Routines, “tf_”)Access Routines

(ACC Routines, “acc_”) Verilog Procedural Interface

Routines

(VPI Routines, “vpi_”)

Page 5: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 5

Verilog PLI Overview

User-Defined System Tasks and Functions Names ($) Types Overriding User-Supplied PLI Applications Arguments

Interface Mechanism Include Files

acc_user.h veriuser.h vpi_user.h

Memory Restriction

Page 6: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 6

Verilog VPI Routines

System Tasks and Functionsvpi_register_systf()vlog_startup_routines[]

InterfaceCall-backs

vpi_register_cb()Access to HDL and Simulation

Objectsmodule m, wire w: m1.w, m2.w

Error HandlingFunction AvailabilityTraversing Expressions

Page 7: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 7

Verilog VPI Routines

Call-backsSimulation Call-backs

Simulation Action and FeaturesSimulation TimesSimulation Events

Statement Call-backsRemoving Call-backs

Time Queue

Page 8: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 8

Verilog VPI Routines

Diagram Key for Objects and Classes

Object Definition

Object Reference

Class Definition

Class Reference

Unnamed Class

Page 9: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 9

Verilog VPI Routines

Diagram Key for Traversing Relationships

obj_h = vpi_handle (obj, ref_h);

obj_h = vpi_handle (Tag, ref_h);

obj_h = vpi_handle (obj, NULL);

Page 10: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 10

Verilog VPI Routines

Diagram Key for Traversing Relationships

itr = vpi_iterate (obj, ref_h);

while (obj_h = vpi_scan (itr))

{ process obj_h}

itr = vpi_iterate (Tag, ref_h);

while (obj_h = vpi_scan (itr))

{ process obj_h}

itr = vpi_iterate (obj, NULL);

while (obj_h = vpi_scan (itr))

{ process obj_h}

Page 11: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 11

Verilog VPI Routines

Diagram Key for Accessing Properties

PLI_INT32 vect_flag =

vpi_get (vpiVector, obj_h);

PLI_INT32 size =

vpi_get (vpiSize, obj_h);

PLI_INT8 *name =

vpi_get_str (vpiName, obj_h);

Identified Routines

Page 12: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 12

Verilog VPI Routines

Object Relationships and Properties

modH = vpi_handle (vpiModule, netH);

Page 13: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 13

Verilog VPI Routines

Object Relationships and Properties

vpiHandle net, mod;net = vpiHandle_by_name (top.m1.w, NULL);mod = vpi_handle (vpiModule, net);

vpi_handle (vpiExpr, partH);

Page 14: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 14

Verilog VPI Routines

Object Relationships and Properties

PLI_BYTE8 *name =

vpi_get_str (vpiFullName, mod);

vpiHandle itr;

itr = vpi_iterate(vpiNet, mod);

while (net = vpi_scan (itr))

vpi_printf(‘‘%s\n’’,

vpi_get_str (vpiFullName, net));

Page 15: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 15

Verilog VPI Routines

Object Relationships and Properties

void traverseExpr (vpiHandle expr) { vpiHandle subExprI, subExprH; switch (vpi_get (vpiExpr, expr)) { case vpiOperation: subExprI = vpi_iterate (vpiOperand,

expr); if (subExprI)

while (subExprH = vpi_scan (subExprI))

traverseExpr (subExprH); default: break; }}

Page 16: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 16

Verilog VPI Routines

Object Relationships and PropertiesType Properties

-> typeint: vpiType

vpi_get (vpiType, H);vpi_get_str (vpiType, H);

File and Line Properties-> location

int: vpiLineNostr: vpiFile

Delays and Values

Page 17: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 17

Verilog VPI Routines

VPI Routines for Simulation Related Call-backsvpi_register_cb():

Register a simulation-related call-back

vpi_remove_cb():

Remove a simulation-related call-back

vpi_get_cb_info():

Get information about a simulation-related call-back

Page 18: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 18

Verilog VPI Routines

VPI Routines for System Task/Function Call-backsvpi_register_systf():

Register a system task/function call-back

vpi_get_systf_info():

Get information about a system task/function call-back

Page 19: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 19

Verilog VPI Routines

VPI Routines for Traversing Verilog HDL Hierarchyvpi_handle():

Obtain a handle for an object with a one-to-one relationship

vpi_iterate(), vpi_scan():

Obtain handles for objects in a one-to-many relationship

vpi_handle_multi():

Obtain a handle for an object in a many-to-one relationship

Page 20: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 20

Verilog VPI Routines

VPI Routines for Accessing Properties of Objectsvpi_get():

Get the value of objects with types of int or bool

vpi_get_str():

Get the value of objects with types of string

Page 21: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 21

Verilog VPI Routines

VPI Routines for Accessing Objects from Propertiesvpi_handle_by_name():

Obtain a handle for a named object

vpi_handle_by_index():

Obtain a handle for an indexed object

vpi_handle_by_multi_index():

Obtain a handle to a word or bit in an array

Page 22: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 22

Verilog VPI Routines

VPI Routines for Delay Processingvpi_get_delays():

Retrieve delays or timing limits of an object

vpi_put_delays():

Write delays or timing limits to an object

Page 23: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 23

Verilog VPI Routines

VPI Routines for Logic and Strength Value Processingvpi_get_value():

Retrieve logic value or strength value of an object

vpi_put_value():

Write logic value or strength value to an object

Page 24: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 24

Verilog VPI Routines

VPI Routines for Simulation Time Processingvpi_get_time():

Find the current simulation time or the scheduled time of future events

Page 25: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 25

Verilog VPI Routines

VPI Routines for Miscellaneous Utilities vpi_printf() vpi_vprintf() vpi_flush() vpi_mcd_open() vpi_mcd_close() vpi_mcd_printf() vpi_mcd_vprintf() vpi_mcd_flush() vpi_mcd_name() vpi_get_vlog_info() vpi_compare_objects() vpi_chk_error() vpi_free_object() vpi_put_data() vpi_get_data() vpi_put_userdata() vpi_get_userdata() vpi_sim_control()

Page 26: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 26

Verilog VPI Routines

Module Data Model

Page 27: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 27

Verilog VPI Routines

Net Data Model

Page 28: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 28

Verilog VPI Routines

Reg Data Model

Page 29: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 29

Verilog VPI Routines

Cadence PLI Environment

Page 30: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 30

Verilog VPI Routines

Cadence PLI Environment Creating a C Function

#include <stdio.h>

#include vpi_user.h

int hello_task () {

vpi_printf (Hello from a new VPI task \n);}

Creating a C++ Function

extern C void ncmain (int, char **);

main(argc, argv)

int argc;

char* argv[];

{ ncmain(argc, argv); }

Page 31: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 31

Verilog VPI Routines

Cadence PLI EnvironmentAssociating C Function with a new System Task

void register_my_systfs () {

s_vpi_systf_data task_data_s;

p_vpi_systf_data task_data_p = &task_data_s;

task_data_p->type = vpiSysTask;

task_data_p->tfname = $hello ;

task_data_p->calltf = (int(*)()) hello_task;

task_data_p->compiletf = NULL;

vpi_register_systf (task_data_p); }

Page 32: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 32

Verilog VPI Routines

Cadence PLI EnvironmentRegistering Users’ New System Task

/* vpi_user.c */

#include vpi_user.h

#include vpi_user_cds.h

void (*vlog_startup_routines[]) () =

{register_my_systfs, 0};

Invoking Users’ System Task

module top;

Initial begin $hello; end

endmodule

Page 33: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 33

Verilog VPI Routines

Cadence PLI EnvironmentCompiling C Files (vconfig)

Static/Dynamic

cc -KPIC -c ~/vpi_user.c -I<InstDir>/include

cc -KPIC -c ~/hello.c -I<InstDir>/include

ld -G vpi_user.o hello.o -o libvpi.so

… executable file

Compiling and Simulating Verilog File

setenv LD_LIBRARY_PATH \ ~/<LibDir>:$LD_LIBRARY_PATH

ncelab –access+rwc worklib.top:v

ncverilog +ncaccess+rwc +plinowarn hello.v

Page 34: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 34

Verilog VPI Routines

Mentor Graphics PLI EnvironmentCompiling C Files

cc -c ~/vpi_user.c -I<InstDir>/include

cc -c ~/hello.c -I<InstDir>/include

ld -G vpi_user.o hello.o -o vpi_lib.so

Compiling and Simulating Verilog File (modelsim.ini)

vlib work

vlog hello.v

vsim -c -pli vpi_lib.so top

Page 35: ProgrammingLanguageInterface(PLI)

Aug. 11th, 2004 Test Seminar 35

References

Cadence Design Systems, Inc., “VPI User Guide and Reference,“ Product Version 3.2, Dec. 2000.

Cadence Design Systems, Inc., “NC-Verilog Simulator Help,” Product Version 3.2, Dec. 2000.

Cadence Design Systems, Inc., “Verilog-XL User Guide and Reference,” Product Version 2.8, Aug. 1999.

Mentor Graphics, “ModelSim SE User's Manual,” Version 5.7a, Jan. 2003

Stuart Sutherland, “The Verilog PLI Handbook,” Kluwer Academic Publishers, 2002.

Swapnajit Mittra, “Principles of Verilog PLI,” Kluwer Academic Publishers, 1999.