Using standard environments

Simulating CHP programs often requires creating an environment to inject data into the circuit being tested, and an environment that reads the outputs of the circuit to check their values. actsim comes with a simulation library that has some common functionality that can be used for this purpose.

etest.act
import sim;
 
defproc buffer(chan?(int) I; chan!(int) O)
{
  int x;
  chp {
    *[ I?x; O!(x+2) ]
  }
}
 
defproc test()
{
  buffer b;
 
  sim::source_sequence<32 /* 32-bit test */, 
                       4 /* 4 data values */, 
                       {1,5,8,53} /* data values */, 
                       false /* repeat these data values forever */, 
                       0 /* source ID for log messages */,
                       false /* detailed log messages turned off */ > 
              t1(b.I);
  sim::sink<32 /* 32-bit data */, 
            0 /* sink ID for log messages */,
            true /* detailed log messages turned on */> 
       t2(b.O);
}

In this example, we use the source_sequence component from the standard simulation library. This component can be used to generate a sequence of data outputs whose values are provided by an array passed as a template parameter.

Running this produces the following result:

$ actsim -p test etest.act
WARNING: source_sequence<32,4,{1,5,8,53},f,0,f>: substituting chp model (requested prs, not found)
WARNING: buffer<>: substituting chp model (requested prs, not found)
WARNING: sink<32,0,t>: substituting chp model (requested prs, not found)
actsim> cycle
[                  50] <t2>  Sink 0: Received value 3 (0x3)
[                  80] <t2>  Sink 0: Received value 7 (0x7)
[                 110] <t2>  Sink 0: Received value 10 (0xa)
[                 140] <t1>  Source 0: Sequence ended.
[                 140] <t2>  Sink 0: Received value 55 (0x37)

Instead of using a hard-coded set of values in the the test environment, the standard simulation library also provides a mechanism to read values from a file. Using:

sim::source_file<32 /* bit-width */, 
                    0 /* file ID */,
                    false /* don't loop file contents */,
                    0 /* source ID */,
                    false /* turn off verbose logs */>
            t1(b.I);

instead of a source_sequence, gets the data values from a file _infile_.0 (0 is the file ID).

_infile_.0
0x493
0x29
0x3
4

The result is:

$ actsim -p test etest.act
WARNING: source_file<32,0,f,0,f>: substituting chp model (requested prs, not found)
WARNING: buffer<>: substituting chp model (requested prs, not found)
WARNING: sink<32,0,t>: substituting chp model (requested prs, not found)
actsim> cycle
[                  50] <t2>  Sink 0: Received value 1173 (0x495)
[                  70] <t2>  Sink 0: Received value 43 (0x2b)
[                  90] <t2>  Sink 0: Received value 5 (0x5)
[                 110] <t1>  Source 0: Input file #0 ended.
[                 110] <t2>  Sink 0: Received value 6 (0x6)