//! @return  The clock rate in Hz of the underlying Or1ksim ISS
// ----------------------------------------------------------------------------
unsigned long int
Or1ksimSyncSC::getClockRate()
{
  return or1ksim_clock_rate();

}	// getClockRate()
Beispiel #2
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 () */