Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Help me with my C code - error: $myrandom is not defined

Status
Not open for further replies.

tarkyss

Full Member level 6
Joined
Aug 1, 2005
Messages
345
Helped
26
Reputation
52
Reaction score
9
Trophy points
1,298
Location
China
Activity points
4,187
%mti_home%

I wrote a simple c program
#include "./veriuser.h"
#include "acc_user.h"
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int myrandom() {

time_t *nowtime;
time(nowtime);
srand((*nowtime));
printf("the time is %d\nthe random is %d\n", (*nowtime), rand()%128);

}
s_tfcell veriusertfs[] = {
{usertask, 0, 0, 0, myrandom, 0, "$myrandom"},
{0} // last entry must be 0
};

when running gcc and ld, no warning no error
but when i run
vsim -c test -pli myrandom.sl
it said, system task $myrandom is not defined.
why?
 

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
892
Helped
174
Reputation
348
Reaction score
51
Trophy points
1,308
Activity points
6,803
Re: PLI problem

Checkout the following code .....

filename: testme.c
Code:
#include "vpi_user.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void myrandom() {
 time_t *nowtime;
 time(nowtime);
 srand((*nowtime));
 io_printf("The time is %d\nthe random is %d\n", (*nowtime), rand()%128);
}

// Associate C Function with a New System Task
void registermyrandom() {
  s_vpi_systf_data task_data_s;
  p_vpi_systf_data task_data_p = &task_data_s;
  task_data_p->type = vpiSysTask;
  task_data_p->tfname = "$myrandom";
  task_data_p->calltf = myrandom;
  task_data_p->compiletf = 0;

  vpi_register_systf(task_data_p);
}

// Register the new system task here
void (*vlog_startup_routines[ ] ) () = {
   registermyrandom,
   0  // last entry must be 0 
};
verilog code : test.v
Code:
module test();
   initial begin
      $display ("Runing PLI task now....");
      #10;
      $myrandom;
   end
endmodule // test
run following commands....

gcc -c -I${MTI_HOME}/include testme.c
ld -shared -o testme.so testme.o
vlog test.v
vsim -do run.do -c -pli testme.so work.test

I am using ModelSim SE VLOG 5.5d on Linux 2.4.20-28.7 x86 machine.
Hope this helps...
 

anjali

Full Member level 3
Joined
Aug 16, 2005
Messages
173
Helped
14
Reputation
28
Reaction score
6
Trophy points
1,298
Activity points
3,033
Re: PLI problem

register the PLI function in veriuser.c file, which will be used by the simulator at the time of linking. there will be one array named "veriusertfs" in that file. there we need to add an entry regarding the pli fn.
 

tarkyss

Full Member level 6
Joined
Aug 1, 2005
Messages
345
Helped
26
Reputation
52
Reaction score
9
Trophy points
1,298
Location
China
Activity points
4,187
PLI problem

nand_gates
thanks, but when i run
gcc -c -I${MTI_HOME}/include testme.c
the following is displayed
testme.c: In function `registermyrandom':
testme.c:18: warning: assignment from incompatible pointer type
 

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
892
Helped
174
Reputation
348
Reaction score
51
Trophy points
1,308
Activity points
6,803
Re: PLI problem

Change this
Code:
void myrandom()
to
Code:
int myrandom()
 

tarkyss

Full Member level 6
Joined
Aug 1, 2005
Messages
345
Helped
26
Reputation
52
Reaction score
9
Trophy points
1,298
Location
China
Activity points
4,187
PLI problem

nand_gates thanks
now, gcc and ld is correct
but when i run
vsim -c -pli testme.so work.test
and then
run 1000
# Runing PLI task now....
# ** Fatal: (SIGSEGV) Bad pointer access.
# Time: 10 ns Iteration: 0 Process: /test/#INITIAL#2 File: test.v
# Fatal error at test.v line 5
#
# Stopped at test.v line 5
 

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
892
Helped
174
Reputation
348
Reaction score
51
Trophy points
1,308
Activity points
6,803
Re: PLI problem

Check with this ....
Replace
Code:
int  myrandom()
with
Code:
PLI_INT32  myrandom()
For me its working ....
Code:
# 5.5d

# vsim -do run.do -pli testme.so -c work.test 
# Loading ./testme.so
# //  ModelSim SE VLOG 5.5d Aug 17 2001 Linux 2.4.20-28.7
# //
# //  Copyright (c) Mentor Graphics Corporation, 1982-2001, All Rights Reserved.
# //                       UNPUBLISHED, LICENSED SOFTWARE.
# //            CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
# //          PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS.
# //
# //  Copyright (c) Model Technology Incorporated 1990-2001, All Rights Reserved.
# //
# Loading work.test
# do run.do 
# Runing PLI task now....
# The time is 1138003341
# the random is 62
Hope this time it works!!
 

tarkyss

Full Member level 6
Joined
Aug 1, 2005
Messages
345
Helped
26
Reputation
52
Reaction score
9
Trophy points
1,298
Location
China
Activity points
4,187
PLI problem

nand_gates
thank you very much
it can not work yet, the error message is the same with the previous
do you think what is the possible reason? the env conf ?
# Runing PLI task now....
# ** Fatal: (SIGSEGV) Bad pointer access.
# Time: 10 ns Iteration: 0 Process: /test/#INITIAL#2 File: test.v
# Fatal error at test.v line 5
#
# Stopped at test.v line 5
 

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
892
Helped
174
Reputation
348
Reaction score
51
Trophy points
1,308
Activity points
6,803
Re: PLI problem

Which modelsim version you are using??? on which platfoem and what OS with version??
 

tarkyss

Full Member level 6
Joined
Aug 1, 2005
Messages
345
Helped
26
Reputation
52
Reaction score
9
Trophy points
1,298
Location
China
Activity points
4,187
PLI problem

my os is sunos5.8
and the version of modelsim i tried are 5.8b, 6.1a, and 6.1c
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top