Jump to content
jsmith125x

interactive simulation

Recommended Posts

I'm trying to implement an interactive digital simulator using SystemC. The user can place switches, gates etc. and can simulate the circuit.

 

I have some problem with switches. Assume there is a circuit containing a "clock" an "and gate" and a "switch". The switch can switch from the H and L states to the output. By default it is low state, when the user press the switch its output goes to the high state. The and gate's inputs connected to the clock and to the switch. The circuit is converted to its SystemC representation (except the switch). The simulation runs endless, because of the clock.

 

How to handle pressing the switch in the SystemC engine? I assume I have to send an event manually to the kernel. How to do that?

Im running the SystemC simulation through a dll (the SystemC representation of the circuit is compiled to a dll). 

 

Share this post


Link to post
Share on other sites

Hi. 

 

I think, you should think about synchronization first. SystemC runs in its logical/simulation time and the switch is pressed in physical/wall-clock time. 

Once you synchronized simulation time and wall-clock time, you can write to signals and generate SystemC events actually originated from the 'outer world' at every synchronization point. 

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Hi. 

 

I think, you should think about synchronization first. SystemC runs in its logical/simulation time and the switch is pressed in physical/wall-clock time. 

Once you synchronized simulation time and wall-clock time, you can write to signals and generate SystemC events actually originated from the 'outer world' at every synchronization point. 

 

Greetings

Ralph

This is an extremely valuable insight that the OP must consider very carefully.

Share this post


Link to post
Share on other sites

My first idea on this is: by changing the value of a signal.

My very raw idea is: 

sc_main(int,char*[])
{
  my_sc_design design("design");
  my_environment env;
  sc_signal<bool> switch;
  //connect switch signal to sc design
  design.evnironment_switch_in(switch);

  //start simulation once to run elaboration
  sc_start(SC_ZERO_TIME);

  while(true)
  {
    // wait for wall-clock time
    wait_one_second_in_wall_clock_time();
   //set switch signal accordig to actual switch
    if (env.switch_enabled())
    {
      switch.write(true);
    }
    else
    {
      switch.write(false);
    }
    sc_start(1,SC_SEC);
  }
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×