OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [or1ksim/] [or1ksim-0.5.0rc2/] [testsuite/] [test-code/] [lib-inttest/] [lib-inttest-edge.c] - Diff between revs 93 and 220

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 93 Rev 220
/* lib-inttest-edge.c. Test of Or1ksim library edge triggered interrupt funcs.
/* lib-inttest-edge.c. Test of Or1ksim library edge triggered interrupt funcs.
 
 
   Copyright (C) 1999-2006 OpenCores
   Copyright (C) 1999-2006 OpenCores
   Copyright (C) 2010 Embecosm Limited
   Copyright (C) 2010 Embecosm Limited
 
 
   Contributors various OpenCores participants
   Contributors various OpenCores participants
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
 
 
   This file is part of OpenRISC 1000 Architectural Simulator.
   This file is part of OpenRISC 1000 Architectural Simulator.
 
 
   This program is free software; you can redistribute it and/or modify it
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the Free
   under the terms of the GNU General Public License as published by the Free
   Software Foundation; either version 3 of the License, or (at your option)
   Software Foundation; either version 3 of the License, or (at your option)
   any later version.
   any later version.
 
 
   This program is distributed in the hope that it will be useful, but WITHOUT
   This program is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
   more details.
 
 
   You should have received a copy of the GNU General Public License along
   You should have received a copy of the GNU General Public License along
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
 
 
/* ----------------------------------------------------------------------------
/* ----------------------------------------------------------------------------
   This code is commented throughout for use with Doxygen.
   This code is commented throughout for use with Doxygen.
   --------------------------------------------------------------------------*/
   --------------------------------------------------------------------------*/
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
 
 
#include "or1ksim.h"
#include "or1ksim.h"
 
 
 
 
/*! Number of interrupts in PIC */
/*! Number of interrupts in PIC */
#define  NUM_INTS  32
#define  NUM_INTS  32
 
 
/*! Globally shared pointer to the interrupts */
/*! Globally shared pointer to the interrupts */
char **intv;
char **intv;
 
 
/*! Number of interrupts to process */
/*! Number of interrupts to process */
int  intc;
int  intc;
 
 
 
 
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
/*!Trigger the next interrupt
/*!Trigger the next interrupt
 
 
   Generate the next edge triggered interrupt. Put out a message if doing so,
   Generate the next edge triggered interrupt. Put out a message if doing so,
   and warn if the interrupt would be invalid.
   and warn if the interrupt would be invalid.
 
 
   @return  1 (true) if an interrupt was triggered, 0 (false) otherwise.     */
   @return  1 (true) if an interrupt was triggered, 0 (false) otherwise.     */
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
static int
static int
do_next_int ()
do_next_int ()
{
{
  static int  next_int = 0;              /* Next interrupt to process */
  static int  next_int = 0;              /* Next interrupt to process */
 
 
  while (next_int < intc)
  while (next_int < intc)
    {
    {
      int  inum = atoi (intv[next_int++]);
      int  inum = atoi (intv[next_int++]);
 
 
      if ((0 <= inum) && (inum < NUM_INTS))
      if ((0 <= inum) && (inum < NUM_INTS))
        {
        {
          printf ("Triggering interrupt %d\n", inum);
          printf ("Triggering interrupt %d\n", inum);
          or1ksim_interrupt (inum);
          or1ksim_interrupt (inum);
          return  1;
          return  1;
        }
        }
      else
      else
        {
        {
          printf ("Warning: Invalid interrupt # %d - ignored\n", inum);
          printf ("Warning: Invalid interrupt # %d - ignored\n", inum);
        }
        }
    }
    }
 
 
  return  0;                             /* No more interrupts to trigger */
  return  0;                             /* No more interrupts to trigger */
 
 
}       /* do_next_int () */
}       /* do_next_int () */
 
 
 
 
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
/*!Read upcall
/*!Read upcall
 
 
   Upcall from Or1ksim to read a word from an external peripheral. If called
   Upcall from Or1ksim to read a word from an external peripheral. If called
   this will trigger an interrupt.
   this will trigger an interrupt.
 
 
   @param[in]  class_ptr  A handle pass back from the initalization. Intended
   @param[in]  class_ptr  A handle pass back from the initalization. Intended
                          for C++ callers, not used here.
                          for C++ callers, not used here.
   @param[in]  addr       Address to read from. Ignored here.
   @param[in]  addr       Address to read from. Ignored here.
   @param[in]  mask       Byte mask for the read. Ignored here.
   @param[in]  mask       Byte mask for the read. Ignored here.
   @param[out] rdata      Buffer for the data read. Ignored here.
   @param[out] rdata      Buffer for the data read. Ignored here.
   @param[in]  data_len   Number of bytes in mask and rdata.
   @param[in]  data_len   Number of bytes in mask and rdata.
 
 
   @return  Zero on success, non-zero on failure. Always zero here.          */
   @return  Zero on success, non-zero on failure. Always zero here.          */
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
static int
static int
read_upcall (void              *class_ptr,
read_upcall (void              *class_ptr,
             unsigned long int  addr,
             unsigned long int  addr,
             unsigned char      mask[],
             unsigned char      mask[],
             unsigned char      rdata[],
             unsigned char      rdata[],
             int                data_len)
             int                data_len)
{
{
  do_next_int ();
  do_next_int ();
 
 
  return  0;                     /* Success */
  return  0;                     /* Success */
 
 
}       /* read_upcall () */
}       /* read_upcall () */
 
 
 
 
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
/*!Write upcall
/*!Write upcall
 
 
   Upcall from Or1ksim to write a word to an external peripheral. If called
   Upcall from Or1ksim to write a word to an external peripheral. If called
   this will trigger an interrupt.
   this will trigger an interrupt.
 
 
   @param[in] class_ptr  A handle pass back from the initalization. Intended
   @param[in] class_ptr  A handle pass back from the initalization. Intended
                         for C++ callers, not used here.
                         for C++ callers, not used here.
   @param[in] addr       Address to write to. Ignored here.
   @param[in] addr       Address to write to. Ignored here.
   @param[in] mask       Byte mask for the write. Ignored here.
   @param[in] mask       Byte mask for the write. Ignored here.
   @param[in] wdata      The data to write. Ignored here.
   @param[in] wdata      The data to write. Ignored here.
   @param[in] data_len   Number of bytes in mask and rdata.
   @param[in] data_len   Number of bytes in mask and rdata.
 
 
   @return  Zero on success, non-zero on failure. Always zero here.          */
   @return  Zero on success, non-zero on failure. Always zero here.          */
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
static int
static int
write_upcall (void              *class_ptr,
write_upcall (void              *class_ptr,
              unsigned long int  addr,
              unsigned long int  addr,
              unsigned char      mask[],
              unsigned char      mask[],
              unsigned char      wdata[],
              unsigned char      wdata[],
              int                data_len)
              int                data_len)
{
{
  do_next_int ();
  do_next_int ();
 
 
  return  0;                     /* Success */
  return  0;                     /* Success */
 
 
}       /* write_upcall () */
}       /* write_upcall () */
 
 
 
 
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
/*!Main program
/*!Main program
 
 
   Build an or1ksim program using the library which loads a program and config
   Build an or1ksim program using the library which loads a program and config
   from the command line, and then drives interrupts. Usage:
   from the command line, and then drives interrupts. Usage:
 
 
   lib-inttest-edge <config-file> <image> <duration_ms> <int #> <int #> ...
   lib-inttest-edge <config-file> <image> <duration_ms> <int #> <int #> ...
 
 
   <image> is run for repeated perios of <duration_ms>, during which it
   <image> is run for repeated perios of <duration_ms>, during which it
   will make upcalls. Between each period and during each upcall an edge based
   will make upcalls. Between each period and during each upcall an edge based
   interrupt will be triggered, until all interrupts listed have been
   interrupt will be triggered, until all interrupts listed have been
   triggered.
   triggered.
 
 
   @param[in] argc  Number of elements in argv
   @param[in] argc  Number of elements in argv
   @param[in] argv  Vector of program name and arguments
   @param[in] argv  Vector of program name and arguments
 
 
   @return  Return code for the program.                                     */
   @return  Return code for the program.                                     */
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
int
int
main (int   argc,
main (int   argc,
      char *argv[])
      char *argv[])
{
{
  /* Parse args */
  /* Parse args */
  if (argc < 5)
  if (argc < 5)
    {
    {
      fprintf (stderr,
      fprintf (stderr,
               "usage: lib-inttest-edge <config-file> <image> <duration_ms> "
               "usage: lib-inttest-edge <config-file> <image> <duration_ms> "
               "<int #> <int #> ...\n");
               "<int #> <int #> ...\n");
      return  1;
      return  1;
    }
    }
 
 
  int     duration_ms = atoi (argv[3]);
  int     duration_ms = atoi (argv[3]);
  double  duration    = (double) duration_ms / 1.0e3;
  double  duration    = (double) duration_ms / 1.0e3;
 
 
  if (duration_ms <= 0)
  if (duration_ms <= 0)
    {
    {
      fprintf (stderr, "ERROR. Duration must be positive number of ms\n");
      fprintf (stderr, "ERROR. Duration must be positive number of ms\n");
      return  1;
      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;
 
 
  /* Initialize the program. Put the initialization message afterwards, or it
  /* Initialize the program. Put the initialization message afterwards, or it
     will get swamped by the Or1ksim header. */
     will get swamped by the Or1ksim header. */
  if (0 == or1ksim_init (argv[1], argv[2], NULL, &read_upcall, &write_upcall))
  if (0 == or1ksim_init (dummy_argc, dummy_argv, NULL, &read_upcall,
 
                         &write_upcall))
    {
    {
      printf ("Initalization succeeded.\n");
      printf ("Initalization succeeded.\n");
    }
    }
  else
  else
    {
    {
      printf ("Initalization failed.\n");
      printf ("Initalization failed.\n");
      return  1;
      return  1;
    }
    }
 
 
  /* Do each interrupt in turn. Set up the shared pointer to the interrupts
  /* Do each interrupt in turn. Set up the shared pointer to the interrupts
     and counter. */
     and counter. */
  intv = &(argv[4]);
  intv = &(argv[4]);
  intc = argc - 4;
  intc = argc - 4;
 
 
  do
  do
    {
    {
      /* Run the code */
      /* Run the code */
      if (OR1KSIM_RC_OK != or1ksim_run (duration))
      if (OR1KSIM_RC_OK != or1ksim_run (duration))
        {
        {
          printf ("ERROR: run failed\n");
          printf ("ERROR: run failed\n");
          return  1;
          return  1;
        }
        }
    }
    }
  while (do_next_int ());
  while (do_next_int ());
 
 
  /* One more run, to allow interrupt handler enough time to finish
  /* One more run, to allow interrupt handler enough time to finish
     processing. */
     processing. */
  if (OR1KSIM_RC_OK != or1ksim_run (duration))
  if (OR1KSIM_RC_OK != or1ksim_run (duration))
    {
    {
      printf ("ERROR: run failed\n");
      printf ("ERROR: run failed\n");
      return  1;
      return  1;
    }
    }
 
 
  /* All interrupts should have been handled. */
  /* All interrupts should have been handled. */
  printf ("Test completed successfully.\n");
  printf ("Test completed successfully.\n");
  return  0;
  return  0;
 
 
}       /* main () */
}       /* main () */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.