如何連結systemC 與 verilog
現在惟一的限制在只能針對simulator作設定
如VCS 有其專用之法
IUS也有專用之法
這樣要寫大型的model會被限制住
top.v
`define W 31
module my_top();
parameter PERIOD = 20;
reg clock;
reg [`W:0] value1;
reg [`W:0] value2;
wire [`W:0] add_wire;
reg [`W:0] systemc_signal;
wire [`W:0] sub_wire;
wire [`W:0] control_out;
reg [`W:0] control_out_reg;
integer counter;
integer direction;
integer cycle;
// SystemC model
sc_top_w add1(value1, value2, add_wire); //當作是一個verilog block
// SystemC model
sc_subtracter sub1(value2, value1, sub_wire);//當作是一個verilog block
// 要記得將wire 接好
// Verilog model
v_controller controller1(value1, value2, control_out);
initial begin
value1 = 32'b010; // starts at 2
value2 = 32'b000; // starts at 0
counter = 0;
direction = 1;
cycle = 0;
end
// clock generator
always begin
clock = 1'b0;
#PERIOD
forever begin
#(PERIOD/2) clock = 1'b1;
#(PERIOD/2) clock = 1'b0;
end
end
// stimulus generator
always @(posedge clock) begin
value1 <= counter+2;
value2 <= 32'b010; // stays at 2 after here.
control_out_reg <= control_out;
if (direction == 1) // incrementing...
if (counter == 9) begin
counter = counter - 1;
direction = 0;
end
else
counter = counter + 1;
else // decrementing...
if (counter == 0) begin
counter = counter + 1;
direction = 1;
end
else
counter = counter - 1;
end
// display generator
always @(posedge clock) begin
$display("--------------------------------");
$display("Cycle %0d for values A=%0d and B=%0d", cycle, value1, value2);
$display("Res: A+/-B=%0d A-B=%0d \nController=%0d Systemc_signal=%0d",
add_wire, sub_wire, control_out,systemc_signal);
$display("--------------------------------");
// end after 100 cycles are executed
cycle = cycle + 1;
if (cycle == 100)
$finish;
end
endmodule
module v_controller(ina, inb, outx);
input [31:0] ina;
input [31:0] inb;
output [31:0] outx;
reg [31:0] outx_reg;
always @(ina or inb) begin
outx_reg <= ina * inb;
end
assign outx = outx_reg;
endmodule
#include "systemc.h"
#include "hdl_connect.h"
SC_MODULE(sc_addsub)
{
public:
sc_in
sc_in
sc_out
sc_signal
sc_signal
SC_CTOR(sc_addsub):ina("ina"), inb("inb"), outx("outx"),outM("outM"),sc_control_sig("sc_control_sig")
{
SC_METHOD(sc_addsub_action);
sensitive << ina << inb << sc_control_sig;
}
void sc_addsub_action() {
if((( sc_control_sig ).read() %3) == 0) {
outx.write(ina.read().get_word(0) + inb.read().get_word(0));
outM.write(ina.read().get_word(0) + inb.read().get_word(0));
} else {
outx.write(ina.read().get_word(0) - inb.read().get_word(0));
outM.write(ina.read().get_word(0) + inb.read().get_word(0));
}
}
};
#endif
SC_MODULE(sc_subtracter)
{
public:
sc_in
sc_in
sc_out
SC_CTOR(sc_subtracter):ina("ina"),inb ("inb"), outx("outx")
{
SC_METHOD(sc_subtracter_action);
sensitive << ina << inb;
}
void sc_subtracter_action() {
sc_lv<32> val;
val = ina.read();
val = val.get_word(0) - inb.read().get_word(0);
outx.write( val );
}
};
SC_MODULE(sc_top_w)
{
public:
sc_in
sc_in
sc_out
sc_addsub *m_add1;
SC_CTOR(sc_top_w): ina ("ina"), inb ("inb"), outx ("Outx")
{
m_add1 = new sc_addsub("add1");
m_add1->ina(ina);
m_add1->inb(inb);
m_add1->outx(outx);
hdl_connect_v(m_add1->sc_control_sig, "my_top.controller1.outx_reg", HDL_INPUT, 1);
hdl_connect_v(m_add1->outM, "my_top.systemc_signal", HDL_OUTPUT,1);
}
};
沒有留言:
張貼留言