GEZEL Java Cosimulation

From Gezel2

Jump to: navigation, search

Contents

Cosimulating GEZEL with JAVA

GEZEL supports cosimulation with JAVA, by means of a few native interface classes. This is useful if you need to integrate GEZEL into a JAVA-based simulation environment.

In this chapter, the native interface classes are presented, as well as a few examples. Before you start working with JAVA, make sure you have correctly set up a working JAVA environment, and that you have enabled to JAVA cosimulation capabilities of GEZEL (See Installing GEZEL).

The GEZEL JAVA Native Interface

In JAVA, the interface between GEZEL and JAVA is based in three classes. GezelModule enables to load GEZEL code, and GezelInport and GezelOutport enable communication for writing to GEZEL and reading from GEZEL respectively.

In GEZEL, the interface between GEZEL and JAVA is based on two library blocks, one that will attach to a GezelInport class and another one that will attach to a GezelOutport class. GEZEL is assumed to be configured as a slave simulator, i.e. the GEZEL clock will be controlled out of JAVA.

  • A GezelModule is initialized using a GEZEL source file as argument. This file is parsed during instantiation of the JAVA object. Once the object is instantiated, the GEZEL simulation can be advanced one clock cycle by calling tick(). In the present implementation of the cosimulation interface, only a single GezelModule class is allowed per JAVA program. This class can of course contain multiple FSMD modules that each have their own interface to the JAVA program.
 class GezelModule {
     public native void loadfile(String filename);
     public native void tick();
     GezelModule(String filename) {
         loadfile(filename);
     }
 }
  • A GezelInport is a communication channel from JAVA to GEZEL. During construction of such a port, a symbolic name must be given to this part. This symbolic name can be referred to from within GEZEL to link up to corresponding library block. Once the port class is created, data can be send to GEZEL using the write() method. Communication is always immediate and will be available to GEZEL during the next clock cycle.
 class GezelInport {
     int portId;
     static int glbPortId;    
     public native void portname(String portname);
     public native void write(int n);
     GezelInport(String _portname) {
         portId = glbPortId++;
         portname(_portname);
     }
 }
  • A GezelOutport is a communication channel from GEZEL to JAVA. During construction of this object, a symbolic name must be given that can be referred to from within GEZEL. Once the object is created, data can be read from GEZEL using the read() method. Communication is immediate, and will return the value evaluated by GEZEL in the present clock cycle.
 class GezelOutport {
     int portId;
     static int glbPortId;
     public native void portname(String _portname);
     public native int read( );
     GezelOutport(String _portname) {
         portId = glbPortId++;
         portname(_portname);
     }
 }

A small example

We present the case of a counter in GEZEL, integrated into a JAVA simulation. The increment value of the counter will be programmed out of JAVA. First, consider the GEZEL description of the counter.

A GEZEL counter interfacing to JAVA

 dp mycounter(in v : ns(32)) {
   reg a : ns(5);
   always run {
    a = a + v;
    $display("counter = ", a);
   }
 } 
 
 ipblock myjavasource(out data : ns(32)) {
   iptype "javasource";
   ipparm "var=myinput";
 }
 
 dp syscounter {
   sig a : ns(32);
   use mycounter(a);
   use myjavasource(a);
 }
 
 system S {
   syscounter;
 }

A counter block (Lines 1—8) is attached to a library block that represents the JAVA interface (Lines 10—13). The javasource library block transports data from JAVA to GEZEL. This particular block has the symbolic variable name myinput (Line 12). The JAVA code that uses this counter block is shown next.

JAVA driver for GEZEL counter

 class counter3 {
     public static void main(String[] args) {
         System.loadLibrary("gzljava"); // gezel-java interface
         GezelModule  m = new GezelModule("counter3.fdl");
         GezelInport  p = new GezelInport("myinput");
 
         p.write(5);
         for (int i=0; i< 10; i++) {
             m.tick();
         }
     }
 }

The JAVA-GEZEL interface makes use of native class implementations, which must be read in and linked at runtime. A shared library gzljava is loaded for this purpose at line 3. Lines 4 and 5 illustrate how a GEZEL module is instantiated, and a communication channel is established. The GEZEL file is parsed during construction of the GezelModule class. Lines 4—10 give a small example how the GEZEL counter is exercised. An increment value of 5 is provided, and the GEZEL simulation is run for 10 clock cycles.

To compile and run this cosimulation, first compile the JAVA code into a class file. The class path is set up to point to the location of the native classes for the GEZEL interface. This path will vary depending on the location where you have installed the GEZEL environment.

 javac -classpath build/share counter3.java

You are now ready to run. You need to make sure the JAVA virtual machine will be able to find the GEZEL-JAVA shared library that contains the GEZEL simulator. This can be done through the environment variable LD_LIBRARY_PATH. You also need to make sure the native classes for the GEZEL interface can be found, by selecting an appropriate classpath parameter. With these two paths correctly set, the simulation generates the following output.

 > export LD_LIBRARY_PATH=build/lib; \
   java -classpath build/share:. counter3
 javasource: set variable myinput
 counter = 0/5
 counter = 5/a
 counter = a/f
 counter = f/14
 counter = 14/19
 counter = 19/1e
 counter = 1e/3
 counter = 3/8
 counter = 8/d
 counter = d/12

Cosimulation with AVRORA

The JAVA cosimulation interface can be used to cosimulate GEZEL with the AVRORA simulator, an instruction-set simulator for the Atmel AVR developed by B. Titzer at UCLA (http://compilers.cs.ucla.edu/avrora/). Some examples of AVR-GEZEL cosimulation are provided in the examples directory of GEZEL (test/java/arvorax). In order to use the AVR cosimulator, you will need to download and configure the AVRORA tools, as well as a cross-compiler for the AVR.