//! @param name        SystemC module name
//! @param configFile  Config file for the underlying ISS
//! @param imageFile   Binary image to run on the ISS
// ----------------------------------------------------------------------------
Or1ksimSyncSC::Or1ksimSyncSC ( sc_core::sc_module_name  name,
		       const char              *configFile,
		       const char              *imageFile ) :
  Or1ksimExtSC( name, configFile, imageFile )
{
  or1ksim_set_time_point();		// Mark the start time

}	/* Or1ksimSyncSC() */
//! @param trans  The transaction payload
// ----------------------------------------------------------------------------
void
Or1ksimSyncSC::doTrans( tlm::tlm_generic_payload &trans )
{
  // Synchronize with SystemC for the amount of time that the ISS has used
  // since the last upcall.
  wait( sc_core::sc_time( or1ksim_get_time_period(), sc_core::SC_SEC ));

  // Call the transport. Since this is a synchronous model, the target should
  // have synchronized, and no additional delay be added on return.

  sc_core::sc_time  delay = sc_core::SC_ZERO_TIME;
  dataBus->b_transport( trans, delay );
  or1ksim_set_time_point();		// Mark start of new time point in ISS

}	// doTrans()
//! There are upcalls for read and write to peripherals (@see
//! ::staticReadUpcall(), ::staticWriteUpcall, ::readUpcall(),
//! ::writeUpcall()), which provide opportunities for the thread to yield, and
//! so not block the simulation.
// ----------------------------------------------------------------------------
void
Or1ksimDecoupSC::run()
{
  while( true ) {
    sc_core::sc_time  timeLeft =
      tgq->compute_local_quantum() - issQk.get_local_time();

    // Mark the start of the ISS timing point, set a desired run duration and
    // run for that duration (either of these may be changed by the read/write
    // upcalls). On return advance the local time according to how much time
    // has been used since the last ISS timing point, and if necessary
    // synchronize.
    or1ksim_set_time_point();
    (void)or1ksim_run( timeLeft.to_seconds() );
    issQk.inc( sc_core::sc_time( or1ksim_get_time_period(), sc_core::SC_SEC ));

    // Sync if needed
    if( issQk.need_sync() ) {
      issQk.sync();
    }
  }

}	// Or1ksimSC()
//! @param trans  The transaction payload
// ----------------------------------------------------------------------------
void
Or1ksimDecoupSC::doTrans( tlm::tlm_generic_payload &trans )
{
  issQk.inc( sc_core::sc_time( or1ksim_get_time_period(), sc_core::SC_SEC ));
  or1ksim_set_time_point();

  // Call the transport. Since this is a temporally decoupled model, the
  // current local time is set in the delay.

  sc_core::sc_time  delay = issQk.get_local_time();
  dataBus->b_transport( trans, delay );
  issQk.set( delay );			// Updated

  // This may have pushed us into needing to synchronize.
  if( issQk.need_sync() ) {
    issQk.sync();
  }

  // Reset the time the ISS is allowed to continue running
  sc_core::sc_time  timeLeft      =
    tgq->compute_local_quantum() - issQk.get_local_time();
  or1ksim_reset_duration ( timeLeft.to_seconds() );

}	// doTrans()
Example #5
0
/* --------------------------------------------------------------------------*/
int
main (int   argc,
      char *argv[])
{
  /* Parse args */
  if (4 != argc)
    {
      fprintf (stderr,
	       "usage: lib-iftest <config-file> <image> <duration_ms>\n");
      return  1;
    }

  int     duration_ms = atoi (argv[3]);
  double  duration    = (double) duration_ms / 1.0e3;

  if (duration_ms <= 0)
    {
      fprintf (stderr, "ERROR. Duration must be positive number of ms\n");
      return  1;
    }

  /* Dummy argv array to pass arguments to or1ksim_init. Varies depending on
     whether an image file is specified. */
  int   dummy_argc;
  char *dummy_argv[5];

  dummy_argv[0] = "libsim";
  dummy_argv[1] = "-q";
  dummy_argv[2] = "-f";
  dummy_argv[3] = argv[1];
  dummy_argv[4] = argv[2];

  dummy_argc = 5;

  /* Put the initialization message afterwards, or it will get swamped by the
     Or1ksim header. */
  if (0 == or1ksim_init (dummy_argc, dummy_argv, NULL, NULL, NULL))
    {
      printf ("Initalization succeeded.\n");
    }
  else
    {
      printf ("Initalization failed.\n");
      return  1;
    }

  /* Test of running */
  printf ("Running code...");
  switch (or1ksim_run (duration))
    {
    case OR1KSIM_RC_OK:    printf ("done.\n");           break;
    case OR1KSIM_RC_BRKPT: printf ("hit breakpoint.\n"); break;
    default:               printf ("failed.\n");         return  1;
    }


  /* Test of timing. Set a time point, run for the duration, then check the
     timing matches. */
  or1ksim_set_time_point ();
  printf ("Set time point.\n");
  printf ("Running code...");
  switch (or1ksim_run (duration))
    {
    case OR1KSIM_RC_OK:    printf ("done.\n");           break;
    case OR1KSIM_RC_BRKPT: printf ("hit breakpoint.\n"); break;
    default:               printf ("failed.\n");         return  1;
    }
  /* All done OK (within 1ps) */
  double measured_duration = or1ksim_get_time_period ();

  if (fabs (duration - measured_duration) < 1e-12)
    {
      printf ("Measured time period correctly.\n");
    }
  else
    {
      printf ("Failed. Requested period %.12f, but measured %.12f\n", duration,
	      measured_duration);
      return  1;
    }

  /* Test endianness */
  if (or1ksim_is_le ())
    {
      printf ("Little endian architecture.\n");
    }
  else
    {
      printf ("Big endian architecture.\n");
    }

  /* Check for clock rate */
  unsigned long int  clock_rate = or1ksim_clock_rate ();

  if (clock_rate > 0)
    {
      printf ("Clock rate %ld Hz.\n", clock_rate);
    }
  else
    {
      printf ("Invalid clock rate %ld Hz.\n", clock_rate);
      return  1;
    }

  printf ("Test completed successfully.\n");
  return  0;

}	/* main () */