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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_36/] [or1ksim/] [tick/] [tick.c] - Diff between revs 611 and 728

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

Rev 611 Rev 728
/* 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 "spr_defs.h"
#include "pic.h"
#include "pic.h"
#include "sprs.h"
#include "sprs.h"
#include "sim-config.h"
#include "sim-config.h"
 
#include "sched.h"
 
 
/* For mode 10 only: timer stops until we write into TTCR.  */
/* When did the timer start to count */
int tt_stopped = 0;
int cycles_start = 0;
 
 
 
/* TT Count Register */
 
unsigned long ttcr;
 
 
 
/* TT Mode Register */
 
unsigned long ttmr;
 
 
 
extern int cycles;
 
 
/* Reset. It initializes TTCR register. */
/* Reset. It initializes TTCR register. */
void tick_reset()
void tick_reset()
{
{
  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;
 
  } else
 
    tt_stopped = 1;
 
}
}
 
 
/* Simulation hook. Must be called every clock cycle to simulate tick
/* Job handler for tick timer */
   timer. It does internal functional tick timer simulation. */
void tick_job (int param)
inline void tick_clock()
 
{
{
  unsigned long ttcr;
  int mode = (ttmr & SPR_TTMR_M) >> 30;
  unsigned long ttmr;
  /*debug (7, "tick_job%i, param %i\n", param, mode);*/
 
  switch (mode) {
  if (tt_stopped)
  case 1:
    return;
    sprs[SPR_TTCR] = ttcr = 0;
 
  case 2:
  ttcr = mfspr(SPR_TTCR);
    if (ttmr & SPR_TTMR_IE) {
  ttmr = mfspr(SPR_TTMR);
 
 
 
  if (!(ttmr & SPR_TTMR_M))
 
    return;
 
 
 
  if ((ttcr & SPR_TTCR_PERIOD) == (ttmr & SPR_TTMR_PERIOD)) {
 
    int mode = (ttmr & SPR_TTMR_M) >> 30; /* CZ 04/09/01 */
 
 
 
    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, mfspr(SPR_EEAR_BASE));
 
    }
 
    break;
 
  }
 
}
 
 
 
/* Starts the tick timer.  This function is called by a write to ttcr spr register */
 
void spr_write_ttcr (unsigned long value)
 
{
 
  unsigned mode = (ttmr & SPR_TTMR_M) >> 30;
 
  /*debug (7, "ttcr = %08x\n", value);*/
 
  ttcr = value;
 
  /* Remove previous if it exists */
 
  SCHED_FIND_REMOVE(tick_job, 0);
 
  if (mode == 1 || mode == 2) {
 
    SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
 
    cycles_start = cycles - ttcr;
 
  }
 
}
 
 
    /* Handle the modes properly.. CZ 04/09/01 */
void spr_write_ttmr (unsigned long value)
    switch(mode)
 
      {
      {
 
  /*debug (7, "ttmr = %08x\n", value);*/
 
  ttmr = value;
 
  /* Handle the modes properly. */
 
  switch((ttmr & SPR_TTMR_M) >> 30) {
      case 0:    /* Timer is disabled */
      case 0:    /* Timer is disabled */
        tt_stopped = 1;
 
        break;
        break;
      case 1:    /* Timer should auto restart */
      case 1:    /* Timer should auto restart */
        ttcr = 0;
      sprs[SPR_TTCR] = ttcr = 0;
        mtspr(SPR_TTCR,ttcr);
      cycles_start = cycles;
 
      SCHED_FIND_REMOVE(tick_job, 0);
 
      SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
        break;
        break;
      case 2:    /* Pause the timer */
    case 2:    /* Stop the timer when match */
        tt_stopped = 1;
      SCHED_FIND_REMOVE(tick_job, 0);
        break;
        break;
      case 3:    /* Timer keeps running */
    case 3:    /* Timer keeps running -- do nothing*/
        break;
        break;
      }
  }
  }
}
 
 
  if ((ttmr & SPR_TTMR_IP) && ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE))
unsigned long spr_read_ttcr ()
    except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
{
 
  /*debug (7, "ttcr ---- %08x\n", cycles - cycles_start);*/
  if (!tt_stopped)
  return cycles - cycles_start;
    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.