来源:systemverilog验证 测试平台编写指南(书籍)
1 新建invert.c文件
vi invert.c
typedef struct {
unsigned char b, g, r;
} *p_rgb;
void invert (p_rgb rgb) {
rgb->r = ~rgb->r;
rgb->g = ~rgb->g;
rgb->b = ~rgb->b;
io_printf("C: Invert rgb = %02x, %02x, %02x\n",rgb->r, rgb->g, rgb->b);
}
2 新建test.sv
vi test.sv
typedef struct packed {bit[7:0] r, g, b;} RGB_T;
import "DPI-C" function void invert (inout RGB_T pstruct);
program automatic test;
class RGB;
rand bit [7:0] r, g,