typedef bit [31:0] u_int32;
class myTrans;
rand u_int32 addr;
rand u_int32 data;
constraint c_addr { addr inside {[0:100]}; }
endclass // myTrans
import "DPI-C" function chandle model_new();
import "DPI-C" function void model_process(input chandle inst, inout u_int32 addr, data);
class Model;
chandle inst;
function new();
this.inst = model_new();
endfunction : new
function void proc(myTrans trans); // "process" is reserved keyword
model_process(this.inst, trans.addr, trans.data);
endfunction : proc
endclass : Model
class stimGen;
myTrans trans;
Model model;
function new();
model = new();
endfunction : new
task run();
trans = new();
trans.randomize();
$display("SV : pre_process : trans.addr=%x, trans.data=%x", trans.addr, trans.data);
model.proc(trans);
$display("SV : post_process: trans.addr=%x, trans.data=%x", trans.addr, trans.data);
endtask // run
endclass // stimGen
module test();
stimGen sg;
initial begin
sg = new();
sg.run();
end
endmodule
#include
#include
#include "systemc.h"
//#include
//#include "vc_hdrs.h" // VCS specific header
typedef unsigned int u_int32;
class myTrans {
public:
u_int32 addr;
u_int32 data;
};
class model {
public:
model();
void process(u_int32* addr, u_int32* data);
};
model::model()
{
printf("C++: Constructing a model\n");
}
void model::process(u_int32* addr, u_int32* data)
{
printf("C++: processing %x %x\n", addr, data);
*addr = *addr + 1;
*data = *data + 2;
}
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////
// The DPI needs a static C routine to communicate with.
// This one constructs the model object and returns a handle
void* model_new()
{
return new model;
}
////////////////////////////////////////////////////////////////////////
// Tell the model to process a transaction
void model_process(void* inst, u_int32* addr, u_int32* data)
{
model* m = (model *) inst;
/* Pass the individual trans properties over.
You could also construct a trans and pass it instead */
m->process(addr, data);
}
#ifdef __cplusplus
}
#endif
沒有留言:
張貼留言