OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [pic/] [pic.c] - Diff between revs 430 and 432

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 430 Rev 432
Line 43... Line 43...
#include "sprs.h"
#include "sprs.h"
#include "sim-config.h"
#include "sim-config.h"
#include "sched.h"
#include "sched.h"
 
 
 
 
/* FIXME: This ugly hack will be removed once the bus architecture gets written
/* -------------------------------------------------------------------------- */
 */
/* Reset the PIC.
struct pic pic_state_int = { 1, 1 };
 
 
 
struct pic *pic_state = &pic_state_int;
 
 
 
/* Reset. It initializes PIC registers. */
   Sets registers to consistent values.                                       */
 
/* -------------------------------------------------------------------------- */
void
void
pic_reset (void)
pic_reset (void)
{
{
  PRINTFQ ("Resetting PIC.\n");
  PRINTFQ ("Resetting PIC.\n");
  cpu_state.sprs[SPR_PICMR] = 0;
  cpu_state.sprs[SPR_PICMR] = config.pic.use_nmi ? 0x00000003 : 0x00000000;
  cpu_state.sprs[SPR_PICPR] = 0;
  cpu_state.sprs[SPR_PICSR] = 0x00000000;
  cpu_state.sprs[SPR_PICSR] = 0;
 
}
}       /* pic_reset () */
 
 
 
 
 
/* -------------------------------------------------------------------------- */
 
/* Handle the reporting of an interrupt
 
 
/* Handles the reporting of an interrupt if it had to be delayed */
   PIC interrupts are scheduled to take place after the current instruction
 
   has completed execution.
 
 
 
   @param[in] dat  Data associated with the exception (not used)              */
 
/* -------------------------------------------------------------------------- */
static void
static void
pic_rep_int (void *dat)
pic_rep_int (void *dat)
{
{
 
  /* printf ("Handling interrupt PICSR: 0x%08x\n", cpu_state.sprs[SPR_PICSR]);
 
   */
 
 
  if (cpu_state.sprs[SPR_PICSR])
  if (cpu_state.sprs[SPR_PICSR])
    {
    {
      except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
      except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
    }
    }
}
}       /* pic_rep_int () */
 
 
 
 
/* Called whenever interrupts get enabled */
/* -------------------------------------------------------------------------- */
 
/* Enable interrupts.
 
 
 
   Called whenever interrupts get enabled, or when PICMR is written.
 
 
 
   @todo Not sure if calling whenever PICMR is written is a good
 
         idea. However, so long as interrupts are properly cleared, it should
 
         not be a problem.                                                    */
 
/* -------------------------------------------------------------------------- */
void
void
pic_ints_en (void)
pic_ints_en (void)
{
{
  if ((cpu_state.sprs[SPR_PICMR] & cpu_state.sprs[SPR_PICSR]))
  if ((cpu_state.sprs[SPR_PICMR] & cpu_state.sprs[SPR_PICSR]))
 
    {
    SCHED_ADD (pic_rep_int, NULL, 0);
    SCHED_ADD (pic_rep_int, NULL, 0);
}
}
 
}       /* pic_ints_en () */
 
 
 
 
 
/* -------------------------------------------------------------------------- */
 
/*!Assert an interrupt to the PIC
 
 
 
   OpenRISC supports both edge and level triggered interrupt. The only
 
   difference is how the interrupt is cleared. For edge triggered, it is by
 
   clearing the corresponding bit in PICSR. For level triggered it is by
 
   deasserting the interrupt line.
 
 
/* Asserts interrupt to the PIC. */
   For integrated peripherals, these amount to the same thing (using
/* WARNING: If this is called during a simulated instruction (ie. from a read/
   clear_interrupt ()). For external peripherals, the library provides two
 * write mem callback), the interrupt will be delivered after the instruction
   distinct interfaces.
 * has finished executeing */
 
 
   An interrupt disables any power management activity.
 
 
 
   We warn if an interrupt is received on a line that already has an interrupt
 
   pending.
 
 
 
   @note If this is called during a simulated instruction (ie. from a read/
 
         write mem callback), the interrupt will be delivered after the
 
         instruction has finished executing.
 
 
 
   @param[in] line  The interrupt being asserted.                             */
 
/* -------------------------------------------------------------------------- */
void
void
report_interrupt (int line)
report_interrupt (int line)
{
{
  uint32_t lmask = 1 << line;
  uint32_t lmask = 1 << line;
 
 
 
  /* printf ("Interrupt reported on line %d\n", line); */
 
 
  /* Disable doze and sleep mode */
  /* Disable doze and sleep mode */
  cpu_state.sprs[SPR_PMR] &= ~(SPR_PMR_DME | SPR_PMR_SME);
  cpu_state.sprs[SPR_PMR] &= ~(SPR_PMR_DME | SPR_PMR_SME);
 
 
  /* If PIC is disabled, don't set any register, just raise EXCEPT_INT */
  /* If PIC is disabled, don't set any register, just raise EXCEPT_INT */
  if (!config.pic.enabled)
  if (!config.pic.enabled)
Line 97... Line 139...
      if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE)
      if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE)
        except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
        except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
      return;
      return;
    }
    }
 
 
 
  /* We can't take another interrupt if the previous one has not been
 
     cleared. */
  if (cpu_state.sprs[SPR_PICSR] & lmask)
  if (cpu_state.sprs[SPR_PICSR] & lmask)
    {
    {
      /* Interrupt already signaled and pending */
      /* Interrupt already signaled and pending */
      fprintf (stderr, "Warning: Int line %d did not change state\n", line);
      PRINTF ("Warning: Int on line %d pending: ignored\n", line);
      return;
      return;
    }
    }
 
 
  cpu_state.sprs[SPR_PICSR] |= lmask;
  cpu_state.sprs[SPR_PICSR] |= lmask;
 
 
  if ((cpu_state.sprs[SPR_PICMR] & lmask) || line < 2)
  /* If we are enabled in the mask, and interrupts are globally enabled in the
    if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE)
     SR, schedule the interrupt to take place after the next instruction. */
 
  if ((cpu_state.sprs[SPR_PICMR] & lmask) &&
 
      (cpu_state.sprs[SPR_SR] & SPR_SR_IEE))
 
    {
 
      /* printf ("Scheduling interrupt on line %d\n", line); */
      SCHED_ADD (pic_rep_int, NULL, 0);
      SCHED_ADD (pic_rep_int, NULL, 0);
}
}
 
}       /* report_interrupt () */
 
 
 
 
 
/* -------------------------------------------------------------------------- */
 
/* Clear an interrupt on a PIC line.
 
 
 
   Logically this is different for a level sensitive interrupt (it lowers the
 
   input line) and an edge sensitive interrupt (it clears the PICSR bit).
 
 
 
   However within Or1ksim, these are implemented through the same operation -
 
   clearing the bit in PICSR.
 
 
/* Clears an int on a pic line */
   @param[in] line  The interrupt being cleared.                              */
 
/* -------------------------------------------------------------------------- */
void
void
clear_interrupt (int line)
clear_interrupt (int line)
{
{
  /* When level triggered, clear corresponding bit in PICSR */
 
  if (!config.pic.edge_trigger)
 
    {
 
      cpu_state.sprs[SPR_PICSR] &= ~(1 << line);
      cpu_state.sprs[SPR_PICSR] &= ~(1 << line);
    }
 
}
}       /* clear_interrupt */
 
 
 
 
/*----------------------------------------------------[ PIC configuration ]---*/
/*----------------------------------------------------[ PIC configuration ]---*/
 
 
 
 
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Line 167... Line 225...
 
 
}       /* pic_edge_trigger() */
}       /* pic_edge_trigger() */
 
 
 
 
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
 
/*!Enable or disable non-maskable interrupts
 
 
 
   @param[in] val  The value to use
 
   @param[in] dat  The config data structure (not used here)                 */
 
/*---------------------------------------------------------------------------*/
 
static void
 
pic_use_nmi (union param_val  val,
 
                  void            *dat)
 
{
 
  config.pic.use_nmi = val.int_val;
 
 
 
}       /* pic_use_nmi() */
 
 
 
 
 
/*---------------------------------------------------------------------------*/
/*!Initialize a new interrupt controller configuration
/*!Initialize a new interrupt controller configuration
 
 
   ALL parameters are set explicitly to default values in init_defconfig()   */
   ALL parameters are set explicitly to default values in init_defconfig()   */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
void
void
Line 178... Line 251...
{
{
  struct config_section *sec = reg_config_sec ("pic", NULL, NULL);
  struct config_section *sec = reg_config_sec ("pic", NULL, NULL);
 
 
  reg_config_param (sec, "enabled",      PARAMT_INT, pic_enabled);
  reg_config_param (sec, "enabled",      PARAMT_INT, pic_enabled);
  reg_config_param (sec, "edge_trigger", PARAMT_INT, pic_edge_trigger);
  reg_config_param (sec, "edge_trigger", PARAMT_INT, pic_edge_trigger);
 
  reg_config_param (sec, "use_nmi",      PARAMT_INT, pic_use_nmi);
 
 
}       /* reg_pic_sec() */
}       /* reg_pic_sec() */
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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