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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [tick/] [tick.c] - Blame information for rev 997

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 91 lampret
/* tick.c -- Simulation of OpenRISC 1000 tick timer
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* This is functional simulation of OpenRISC 1000 architectural
21
   tick timer.
22
*/
23
 
24
#include <stdlib.h>
25
#include <stdio.h>
26
#include <string.h>
27
 
28 561 simons
#include "except.h"
29 91 lampret
#include "tick.h"
30 728 markom
#include "spr_defs.h"
31 102 lampret
#include "pic.h"
32 189 chris
#include "sprs.h"
33 333 markom
#include "sim-config.h"
34 728 markom
#include "sched.h"
35 91 lampret
 
36 728 markom
/* When did the timer start to count */
37
int cycles_start = 0;
38 133 markom
 
39 728 markom
/* TT Count Register */
40
unsigned long ttcr;
41
 
42
/* TT Mode Register */
43
unsigned long ttmr;
44
 
45 91 lampret
/* Reset. It initializes TTCR register. */
46
void tick_reset()
47
{
48 728 markom
  if (config.sim.verbose)
49 997 markom
    PRINTF("Resetting Tick Timer.\n");
50 728 markom
  mtspr(SPR_TTCR, 0);
51
  mtspr(SPR_TTMR, 0);
52 91 lampret
}
53
 
54 728 markom
/* Job handler for tick timer */
55
void tick_job (int param)
56 91 lampret
{
57 728 markom
  int mode = (ttmr & SPR_TTMR_M) >> 30;
58
  /*debug (7, "tick_job%i, param %i\n", param, mode);*/
59
  switch (mode) {
60
  case 1:
61 802 simons
    if (!param) {
62
      sprs[SPR_TTCR] = ttcr = 0;
63 884 markom
      cycles_start = runtime.sim.cycles - ttcr;
64
      SCHED_ADD(tick_job, 0, runtime.sim.cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
65 802 simons
    }
66 728 markom
  case 2:
67
    if (ttmr & SPR_TTMR_IE) {
68 133 markom
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
69 728 markom
      if ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE)
70
        except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
71 802 simons
      else
72
        /* If TEE is currently not set we have to pend tick exception
73
           by rescheduling. */
74 884 markom
        SCHED_ADD(tick_job, 1, runtime.sim.cycles + 1);
75 728 markom
    }
76
    break;
77
  }
78
}
79 189 chris
 
80 728 markom
/* Starts the tick timer.  This function is called by a write to ttcr spr register */
81
void spr_write_ttcr (unsigned long value)
82
{
83
  unsigned mode = (ttmr & SPR_TTMR_M) >> 30;
84
  /*debug (7, "ttcr = %08x\n", value);*/
85
  ttcr = value;
86
  /* Remove previous if it exists */
87
  SCHED_FIND_REMOVE(tick_job, 0);
88 802 simons
  SCHED_FIND_REMOVE(tick_job, 1);
89 728 markom
  if (mode == 1 || mode == 2) {
90 884 markom
    SCHED_ADD(tick_job, 0, runtime.sim.cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
91
    cycles_start = runtime.sim.cycles - ttcr;
92 133 markom
  }
93 728 markom
}
94 611 simons
 
95 728 markom
void spr_write_ttmr (unsigned long value)
96
{
97
  /*debug (7, "ttmr = %08x\n", value);*/
98
  ttmr = value;
99
  /* Handle the modes properly. */
100
  switch((ttmr & SPR_TTMR_M) >> 30) {
101
    case 0:    /* Timer is disabled */
102 802 simons
      SCHED_FIND_REMOVE(tick_job, 0);
103
      SCHED_FIND_REMOVE(tick_job, 1);
104 728 markom
      break;
105
    case 1:    /* Timer should auto restart */
106
      sprs[SPR_TTCR] = ttcr = 0;
107 884 markom
      cycles_start = runtime.sim.cycles;
108 728 markom
      SCHED_FIND_REMOVE(tick_job, 0);
109 802 simons
      SCHED_FIND_REMOVE(tick_job, 1);
110 884 markom
      SCHED_ADD(tick_job, 0, runtime.sim.cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
111 728 markom
      break;
112
    case 2:    /* Stop the timer when match */
113
      SCHED_FIND_REMOVE(tick_job, 0);
114 802 simons
      SCHED_FIND_REMOVE(tick_job, 1);
115 728 markom
      break;
116
    case 3:    /* Timer keeps running -- do nothing*/
117
      break;
118
  }
119
}
120 611 simons
 
121 728 markom
unsigned long spr_read_ttcr ()
122
{
123 884 markom
  /*debug (7, "ttcr ---- %08x\n", runtime.sim.cycles - cycles_start);*/
124
  return runtime.sim.cycles - cycles_start;
125 91 lampret
}

powered by: WebSVN 2.1.0

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