Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Create an account
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
wafer.jpg

Import Methods

E-mail Print PDF

Import Methods

Methods implemented in C and given import declarations in SystemVerilog can be called from SystemVerilog, such methods are referred to as imported methods.Imported tasks or functions are similar to SystemVerilog tasks or functions.

Imported tasks or functions can have zero or more formal input, output, and inout arguments.

Imported tasks always return an int result as part of the DPI-C disable protocol and, thus, are declared in foreign code as int functions. We will discusses about the DPI-C disable protocol in following sections.

Imported functions can return a result or be defined as void functions.

The syntax import method:

import {"DPI" | "DPI-C"} [context | pure] [c_identifier =] [function|task] [function_identifier|task_identifier] ([tf_port_list]);

Steps To Write Import Metyhods

In SV Code

Step1 : Import the C function

import "DPI-C" string_sv2c=task string_sv2c();

Step2 : Invoke the Importted C function

initial

begin

string_sv2c();

end

In C code:

Step3: Define the Imported function

void string_sv2c(){

printf(" C: Hellow from C ");

}

Full Example:

CODE: SV_file

program main;

string str;

import "DPI-C" string_sv2c=task string_sv2c();

initial

begin

string_sv2c();

end

endprogram

CODE: C_file

#include "svdpi.h"

void string_sv2c(){

printf(" C: Hellow from C ");

}

RESULTS

C: Hellow from C

EXAMPLE: optional default arguments

Standard C Functions

Users can also call the standared C functions.

EXAMPLE:

import "DPI" function chandle malloc(int size);

import "DPI" function void free(chandle ptr);

Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

Last Updated ( Tuesday, 17 August 2021 14:27 )  

Related Articles

Chat Zalo