spin is an experimental project and far from beeing available for commercial usage. If you are interrested in spin: mailto://spin@toem.de.

Introducing Spin 1 - Modules

Like in systemC, modules are the basic building blocks of a design hierarchy. A model usually consists of several modules which communicate via connectors (ports).

A module contains:

  • Connectors

  • Processes

  • Any other java code

Instantiating modules

Modules are created like any other java object with the new command. To create a top-level module and start simulation:

Modules modules = new Modules(); // toplevel module
Spin.run();

The parameter set for a new modules constructor should contain the parameters "name" and the modules "parent". Additional parameters are left open to the developer.

AModule module1 = new AModule(null, this);// default name
AModule module2 = new AModule("myName", this);// explicit name
AModule module3 = new AModule("myName", this,Scale.b12);// scale parameter

If the name is not given (null), a default name is applied (derived from the class name).

Defining modules

From java point of view, a module is a  java class that implements the IModule interface.

public class ACompleteOwnModule implements IModule {

	@Override
	public IElement getParent() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return null;
	} 
......

Instead of using intefaces, it is more convinient to derive the class 'Module' from the existing IModule implementation:

	
public class AModule extends Module {

	// Connectors
	public IIn<Integer> in1, in2;
	public IOut<Integer> out;
.....

Top-level classes vs inner classes

Java classes can be definied as top-level class or inner class. In the given examples, inner-classes are often used to help keeping the example compact.

  • Using inner classes makes sense if you use the new module only within the context of the outer class (like in the examples).
  • If you want to use a module in different contexts (as a kind of library module), you need to use top-level classes.

Unlike C++, in java it is not possible to instantiate an inner class outside the context of the outer class in java.

package de.toem.spin.examples.doc;

import java.util.List;
....

public class Modules extends Module { // the top-level class/module


	public class AModule extends Module {  // an inner class/module

		// Connectors
		public IIn<Integer> in1, in2;
		public IOut<Integer> out;

A complete module

	
// a new module class
public class AModule extends Module {

	// Connectors
	public IIn<Integer> in1, in2; // 2 in-ports
	public IOut<Integer> out; // 1 out-port

	// Constructor
	public AModule(String name, IModule parent) {
		this(name, parent,Scale.b16);
	}

	// Constructor
	public AModule(String name, IModule parent, Scale scale) {
		super(name, parent, scale);
		scale.applyTo(in1,in2,out);

		// Process
		new Process(null, this,scale) {

			public void initialize() {
				out.init(0);
				sensitive(in1.changed(), in2.changed());
			}

			public void run(IRunInfo info) {
				log("run");
				out.write(((in1.read() + in2.read()) & scale.intMask));
			}
		};
	}
}

 

 

Print

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive