In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to call C function in SV, the content is very detailed, interested friends can refer to, hope to be helpful to you.
The first way is not the docking of SV and C in the strict sense, but just executes the C program through the command line. For example, we wrote a hello world c program:
Int main () {
Printf ("hello world!\ n")
Return 0
}
We compiled it into an executable file gcc-o hello hello.c
We can execute this directly in our SV function:
Function void exe ()
$system (". / hello")
Endfunction
In addition to this way, SV also provides a direct interface to CumberCraft + DPI. The DPI interface allows users to write programs in C and connect with SV. They can also write programs in SV and export SV programs to C. The two call each other. How to use self-defined C functions in SV, you need to import functions in SV. For example:
Module Bus (input In1, output Out1)
Import "DPI" function void slave_write (input int address
Input int data)
Export "DPI" function write; / / Note-not a function prototype
/ / This SystemVerilog function could be called from C
Function void write (int address, int data)
/ / Call C function
Slave_write (address, data); / / Arguments passed by copy
Endfunction
...
Endmodule
In C are:
# include "svdpi.h"
Extern void write (int, int); / / Imported from SystemVerilog
Void slave_write (const int I1, const int I2)
{
Buff [I1] = I2
...
}
The C function slave_write is called in SV, which has two parameters, address and data. Two header files are usually included in the C function: svdpi.h and svdpi_src.h.
The data types of C and SV correspond to the following:
We need to note that there are two ways to pass parameters between SV and C, one is value transfer, such as byte-char,shortint-short int, and the other is through pointers. For example, the arrays of packed and unpacked in SV are passed to C by reference, so C uses pointers to receive. For example, bit [n: 0] is passed to C as a packed array, which is received by svBitVecVal*. SvBitVecVal is a macro definition, which is actually 32bit data. It should be noted here that the SV data of n bit is stored as 32bit data in C, arranged at the small end. For example, the corresponding data svBitVecVal* b of bit [127 0] an in C has the following correspondence:
A [31:0] = b [0]
A [63:32] = b [1]
...
It's easy for beginners to fall into a trap. When I first passed this variable, I thought it was a svBitVecVal to store 1bit data. Multi-dimensional data measured in SV can also be received using a 1-dimensional pointer in C, such as the following functions:
Void write (svBitVecVal* data) {
}
In SV, you can:
Import "DPI-C" function void write (bit [127 function void write 0] data [16] [16])
In this way, when reading and writing data data in C, you need to use a pointer to confirm the location of the data. The pointer points to the first 32bit data of the data data, that is, data [0] [0] [31:0], and then the data can be obtained by increasing the pointer later.
The array data of unpacked can be accessed directly by pointer in C, but the data in packed can only be read and written using defined functions. These functions are:
SvBit svGetSelectBit (const svBitPackedArrRef s, int I)
SvLogic svGetSelectLogic (const svLogicPackedArrRef s, int I)
Void svPutSelectBit (svBitPackedArrRef d, int I, svBit s)
Void svPutSelectLogic (svLogicPackedArrRef d, int I, svLogic s)
/ * canonical
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.