What's wrong with my random value generating task using PLI

Guest
Hi, all
I applied PLI to set value to my design's input ports. The
process in testbench is following:

always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
a_in <= 16'b0;
b_in <= 16'b0;
c_in <= 1'b0;
end
else
begin
$mytry(a_in,0.0);
$mytry(b_in,0.0);
c_in <= b_in[0];
end
end

And part of the C program is:

int mytry()
{
handle net_handle;
long int i;
time_t t;

acc_initialize();
acc_configure(accDevelopmentVersion, "IEEE 1364 PLI");
net_handle = acc_handle_tfarg(1);
t = time(NULL);

srand((unsigned)t);
i = rand();
io_printf("i = %h\n", i);
my_set_value(net_handle, i, 4.0);

return 0;
}

int my_set_value()
{
static s_setval_delay delay_s = {{accRealTime}, accInertialDelay};
static s_setval_value value_s = {accIntVal};
handle reg = acc_handle_tfarg(1);
value_s.value.integer = acc_handle_tfarg(2);
delay_s.time.real = acc_fetch_tfarg(3);
acc_set_value(reg, &value_s, &delay_s);

return 0;
}

The bat file I got the dll file is:
cl -c -I D:\Modeltech_6.0\include mytry.c
link -dll -export:init_usertfs mytry.obj
D:\Modeltech_6.0\win32\mtipli.lib

simulating:
vsim -c -pli mytry adder_tb

The result is that I only can get a pair values for the a_in and b_in.
The values didn't refreshed when another clock posedge arrived. After
struglling for 2 days, I don't know what's wrong with the c program or
the testbench.

Waiting for help! Thank you in advance!
 
I don't know enough about PLI to comment on that part. But if you
re-seed the random number generator with the value of time each time
you call mytry, and time isn't changing between calls, then you are
going to get the same value back every time. You should only be
seeding it the first time you call mytry, and then leave the RNG alone
to generate a sequence. Otherwise you are effectively using time as
your random number every time, and it isn't changing very fast.
 

Welcome to EDABoard.com

Sponsor

Back
Top