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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...