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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [tick/] [tick.c] - Diff between revs 600 and 611

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

Rev 600 Rev 611
/* tick.c -- Simulation of OpenRISC 1000 tick timer
/* tick.c -- Simulation of OpenRISC 1000 tick timer
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
 
 
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
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
/* This is functional simulation of OpenRISC 1000 architectural
/* This is functional simulation of OpenRISC 1000 architectural
   tick timer.
   tick timer.
*/
*/
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
 
 
#include "except.h"
#include "except.h"
#include "tick.h"
#include "tick.h"
#include "../cpu/or1k/spr_defs.h"
#include "../cpu/or1k/spr_defs.h"
#include "pic.h"
#include "pic.h"
#include "sprs.h"
#include "sprs.h"
#include "sim-config.h"
#include "sim-config.h"
 
 
/* For mode 10 only: timer stops until we write into TTCR.  */
/* For mode 10 only: timer stops until we write into TTCR.  */
int tt_stopped = 0;
int tt_stopped = 0;
 
 
/* Reset. It initializes TTCR register. */
/* Reset. It initializes TTCR register. */
void tick_reset()
void tick_reset()
{
{
  if (config.tick.enabled) {
  if (config.tick.enabled) {
    if (config.sim.verbose)
    if (config.sim.verbose)
      printf("Resetting Tick Timer.\n");
      printf("Resetting Tick Timer.\n");
    mtspr(SPR_TTCR, 0);
    mtspr(SPR_TTCR, 0);
    mtspr(SPR_TTMR, 0);
    mtspr(SPR_TTMR, 0);
    tt_stopped = 0;
    tt_stopped = 0;
  } else
  } else
    tt_stopped = 1;
    tt_stopped = 1;
}
}
 
 
/* Simulation hook. Must be called every clock cycle to simulate tick
/* Simulation hook. Must be called every clock cycle to simulate tick
   timer. It does internal functional tick timer simulation. */
   timer. It does internal functional tick timer simulation. */
inline void tick_clock()
inline void tick_clock()
{
{
  unsigned long ttcr;
  unsigned long ttcr;
  unsigned long ttmr;
  unsigned long ttmr;
 
 
  if (tt_stopped)
  if (tt_stopped)
    return;
    return;
 
 
  ttcr = mfspr(SPR_TTCR);
  ttcr = mfspr(SPR_TTCR);
  ttmr = mfspr(SPR_TTMR);
  ttmr = mfspr(SPR_TTMR);
 
 
  if (!(ttmr & SPR_TTMR_M))
  if (!(ttmr & SPR_TTMR_M))
    return;
    return;
 
 
  if ((ttcr & SPR_TTCR_PERIOD) == (ttmr & SPR_TTMR_PERIOD)) {
  if ((ttcr & SPR_TTCR_PERIOD) == (ttmr & SPR_TTMR_PERIOD)) {
    int mode = (ttmr & SPR_TTMR_M) >> 30; /* CZ 04/09/01 */
    int mode = (ttmr & SPR_TTMR_M) >> 30; /* CZ 04/09/01 */
 
 
    if (ttmr & SPR_TTMR_IE) {
    if (ttmr & SPR_TTMR_IE)
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
      if ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE)
 
        except_handle(EXCEPT_TICK, 0);
 
    }
 
 
 
    /* Handle the modes properly.. CZ 04/09/01 */
    /* Handle the modes properly.. CZ 04/09/01 */
    switch(mode)
    switch(mode)
      {
      {
      case 0:    /* Timer is disabled */
      case 0:    /* Timer is disabled */
        tt_stopped = 1;
        tt_stopped = 1;
        break;
        break;
      case 1:    /* Timer should auto restart */
      case 1:    /* Timer should auto restart */
        ttcr = 0;
        ttcr = 0;
        mtspr(SPR_TTCR,ttcr);
        mtspr(SPR_TTCR,ttcr);
        break;
        break;
      case 2:    /* Pause the timer */
      case 2:    /* Pause the timer */
        tt_stopped = 1;
        tt_stopped = 1;
        break;
        break;
      case 3:    /* Timer keeps running */
      case 3:    /* Timer keeps running */
        break;
        break;
      }
      }
  }
  }
 
 
 
  if ((ttmr & SPR_TTMR_IP) && ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE))
 
    except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
 
 
  if (!tt_stopped)
  if (!tt_stopped)
    ttcr++;
    ttcr++;
  mtspr(SPR_TTCR, ttcr);
  mtspr(SPR_TTCR, ttcr);
}
}
 
 

powered by: WebSVN 2.1.0

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