|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



DATA TYPES




The SystemVerilog DPI supports only SystemVerilog data types, which are the data types that can cross the boundary between SystemVerilog and a foreign language in both the direction. On the other hand, the data types used in C code shall be C types. A value that is passed through the DPI is specified in SystemVerilog code as a value of SystemVerilog data type, while the same value is declared C code as a value of C data type. Therefore, a pair of matching type definitions is required to pass a value through DPI, the SystemVerilog definition and the C definition.

The following SystemVerilog types are the only permitted types for formal arguments of import and export tasks or functions:

void, byte, shortint, int, longint, real, shortreal, chandle, and string
Scalar values of type bit and logic
Packed arrays, structs, and unions composed of types bit and logic. Every packed type is eventually equivalent to a packed one-dimensional array. On the foreign language side of the DPI, all packed types are perceived as packed one-dimensional arrays regardless of their declaration in the SystemVerilog code.
Enumeration types interpreted as the type associated with that enumeration
Types constructed from the supported types with the help of the constructs: struct , union , Unpacked array , typedef

Mapping data types





Passing Logic Datatype



The DPI defines the canonical representation of packed 2-state (type svBitVecVal) and 4-state arrays (type svBitVecVal). svLogicVecVal is fully equivalent to type s_vpi_vecval, which is used to represent 4-state logic in VPI.




CODE:SV_file.sv
program main;
logic a;
import "DPI" function void show(logic a);
initial begin
a = 1'b0;
show(a);
a = 1'b1;
show(a);
a = 1'bX;
show(a);
a = 1'bZ;
show(a);
end
endprogram

CODE: C_file.v
#include <stdio.h>
#include <svdpi.h>

void show(svLogic a){
if(a == 0)
printf(" a is 0 \n");
else if(a == 1)
printf(" a is 1 \n");
else if(a == 2)
printf(" a is x \n");
else if(a == 3)
printf(" a is z \n");

}
RESULTS

a is 0
a is 1
a is z
a is x


Index
Introductions
Layers
Import
Naming
Export
Pure And Context
Data Types
Arrays
Passing Structs And Unions
Arguments Type
Disablie

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer