Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

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
340
Helped
26
Reputation
52
Reaction score
8
Trophy points
1,298
Location
China
Activity points
4,162
%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?
 

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...
 

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.
 

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
 

Re: PLI problem

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

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
 

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!!
 

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
 

Re: PLI problem

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

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top