Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
intro_example:standard_sim [2025/05/14 18:24] rajitintro_example:standard_sim [2025/05/14 18:40] (current) rajit
Line 1: Line 1:
-====== Standard simulation environments ======+====== 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 [[sim:start|simulation library]] that has some common functionality that can be used for this purpose. 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 [[sim:start|simulation library]] that has some common functionality that can be used for this purpose.
  
-<code act>+<file act etest.act>
 import sim; import sim;
  
Line 19: Line 19:
  
   sim::source_sequence<32 /* 32-bit test */,    sim::source_sequence<32 /* 32-bit test */, 
-                                            4 /* 4 data values */,  +                       4 /* 4 data values */,  
-                                            {1,5,8,53} /* data values */,  +                       {1,5,8,53} /* data values */,  
-                                            false /* repeat these data values forever */,  +                       false /* repeat these data values forever */,  
-                                            0 /* source ID for log messages */, +                       0 /* source ID for log messages */, 
-                                             false /* detailed log messages turned off */ >  +                       false /* detailed log messages turned off */ >  
-                                             t1(b.I);+              t1(b.I);
   sim::sink<32 /* 32-bit data */,    sim::sink<32 /* 32-bit data */, 
-                    0 /* sink ID for log messages */, +            0 /* sink ID for log messages */, 
-                    true /* detailed log messages turned on */>  +            true /* detailed log messages turned on */>  
-                    t2(b.O);+       t2(b.O);
 } }
 +</file>
 +
 +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:
 +<code>
 +$ 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)
 </code> </code>
  
 +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:
 +<code act>
 +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);
 +</code>
 +instead of a ''source_sequence'', gets the data values from a file ''_infile_.0'' (0 is the file ID).
 +
 +<file txt _infile_.0>
 +0x493
 +0x29
 +0x3
 +4
 +</file>
 +
 +The result is:
 +<code>
 +$ 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)
 +</code>