H2 Simple Channel Communication Example

Source Code

// channels.h2
// H2 simple channel comms demo.
//
interface srcsink()
{
  channel [7:0]: binker;
  protocol vanilla_source : source;
  protocol vanilla_sink : sink(binker);
}


protocol vanilla_sink(arg)
{
  node [15:0]: k;
  {
    k =  ?arg;
    printf("Received %i\n", k);
  }
}

protocol vanilla_source()
{
  node [15:0]: data;
  {
    data = 100;
    while(1) // this while(1) is implied anyway.
    {
    data += 11;
    printf("Sending data %i\n", data);
    binker ! data;
    }
  }
}
// eof

Simulation using builtin H2 simulator

The H2 tool has a builtin simulator which is run using the 'sim' command line flag, with events plotted to a plot file if requested.

./h2comp ../examples/channels.h2 -root srcsink -sim 80 -plot chanout.plt
Sending data 111
Received 111
Sending data 122
Received 122
Sending data 133
Received 133
Sending data 144
Received 144
Sending data 155
Received 155
Sending data 166
Simulation cycle limit reached at 80
h2comp done
diogif -o chanout.gif -x chanout.plt

Plot Output File

The plot file can be rendered under X windows or converted to a gif using the diogif program.


UP.