views:

65

answers:

3

I am running System Verilog inside of an ASIC simulator. SV has an import/export mechanism to call C functions from SV, and for SV functions to be called from within C.

I'd like to send realtime-ish (a very slow stream) data from the simulation to a charting program that I will write in Java. What is the best way to call the Java with periodic updates from the simulator/C program?

+1  A: 

There is the java native interface which allows C programs to interact with java objects. But you need to write some C code to get this integrated into the ASIC simulator.

nhnb
This looks like it wants to run as a part of the java program? Using JNI, can main() reside in c instead of in java?
SDGator
Yes, you can embed java in a c program as a lib. The example in my link assumes that the java main() method will be called from your c-program, but you can call any static method directly in the same way.
KarlP
+4  A: 

After a quick glance here : http://java.sun.com/docs/books/jni/html/invoke.html, ...

Then consider this:

The simplest way is to write the data to a file, and write a java program to read from the file as it grows. See this answer: http://stackoverflow.com/questions/557844/java-io-implementation-of-unix-linux-tail-f

Start them both separately, or use system() to start the java program from your plugin, passing the filename as an argument.

KarlP
+1 for old-school way.
Marty
On second thought, system is syncronous, but you get the idea... To start the java program from Your plugin, you would either need to do as the jni link suggests, or find out how to do a fork, exec,spawn on Your platform...
KarlP
This seems a lot simpler than JNI. And safer, too.
SDGator
+2  A: 

The best way would be to have the Java program listen on a TCP socket for updates from the C program which can send them. Have the C program connect to the Java program when it begins, and whenever there's an update, it can pass it along the connected socket. The Java program can then take the data and update whatever it needs to update.

This also has the nice advantage that the two programs don't even have to run on the same machine.

Erick Robertson