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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_38/] [or1ksim/] [tick/] [tick.c] - Blame information for rev 1765

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 1350 nogj
#include "config.h"
29
 
30
#ifdef HAVE_INTTYPES_H
31
#include <inttypes.h>
32
#endif
33
 
34
#include "port.h"
35
#include "arch.h"
36
#include "abstract.h"
37 561 simons
#include "except.h"
38 91 lampret
#include "tick.h"
39 728 markom
#include "spr_defs.h"
40 102 lampret
#include "pic.h"
41 189 chris
#include "sprs.h"
42 333 markom
#include "sim-config.h"
43 728 markom
#include "sched.h"
44 91 lampret
 
45 728 markom
/* When did the timer start to count */
46
int cycles_start = 0;
47 133 markom
 
48 728 markom
/* TT Count Register */
49
unsigned long ttcr;
50
 
51
/* TT Mode Register */
52
unsigned long ttmr;
53
 
54 91 lampret
/* Reset. It initializes TTCR register. */
55
void tick_reset()
56
{
57 728 markom
  if (config.sim.verbose)
58 997 markom
    PRINTF("Resetting Tick Timer.\n");
59 728 markom
  mtspr(SPR_TTCR, 0);
60
  mtspr(SPR_TTMR, 0);
61 91 lampret
}
62
 
63 728 markom
/* Job handler for tick timer */
64 1365 nogj
void tick_job (void *param)
65 91 lampret
{
66 728 markom
  int mode = (ttmr & SPR_TTMR_M) >> 30;
67
  /*debug (7, "tick_job%i, param %i\n", param, mode);*/
68
  switch (mode) {
69
  case 1:
70 802 simons
    if (!param) {
71
      sprs[SPR_TTCR] = ttcr = 0;
72 884 markom
      cycles_start = runtime.sim.cycles - ttcr;
73 1390 nogj
      SCHED_ADD(tick_job, (void *)0, (ttmr & SPR_TTMR_PERIOD) - ttcr);
74 802 simons
    }
75 728 markom
  case 2:
76
    if (ttmr & SPR_TTMR_IE) {
77 133 markom
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
78 1319 phoenix
      /* be sure not to issue timer exception if an exception occured before it */
79 1386 nogj
      if ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE)
80 728 markom
        except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
81 802 simons
      else
82
        /* If TEE is currently not set we have to pend tick exception
83
           by rescheduling. */
84 1390 nogj
        SCHED_ADD(tick_job, (void *)1, 1);
85 728 markom
    }
86
    break;
87
  }
88
}
89 189 chris
 
90 728 markom
/* Starts the tick timer.  This function is called by a write to ttcr spr register */
91
void spr_write_ttcr (unsigned long value)
92
{
93
  unsigned mode = (ttmr & SPR_TTMR_M) >> 30;
94
  /*debug (7, "ttcr = %08x\n", value);*/
95
  ttcr = value;
96
  /* Remove previous if it exists */
97 1365 nogj
  SCHED_FIND_REMOVE(tick_job, (void *)0);
98
  SCHED_FIND_REMOVE(tick_job, (void *)1);
99 728 markom
  if (mode == 1 || mode == 2) {
100 1390 nogj
    SCHED_ADD(tick_job, (void *)0, (ttmr & SPR_TTMR_PERIOD) - ttcr);
101 884 markom
    cycles_start = runtime.sim.cycles - ttcr;
102 133 markom
  }
103 728 markom
}
104 611 simons
 
105 728 markom
void spr_write_ttmr (unsigned long value)
106
{
107
  /*debug (7, "ttmr = %08x\n", value);*/
108
  ttmr = value;
109
  /* Handle the modes properly. */
110
  switch((ttmr & SPR_TTMR_M) >> 30) {
111
    case 0:    /* Timer is disabled */
112 1365 nogj
      SCHED_FIND_REMOVE(tick_job, (void *)0);
113
      SCHED_FIND_REMOVE(tick_job, (void *)1);
114 728 markom
      break;
115
    case 1:    /* Timer should auto restart */
116
      sprs[SPR_TTCR] = ttcr = 0;
117 884 markom
      cycles_start = runtime.sim.cycles;
118 1365 nogj
      SCHED_FIND_REMOVE(tick_job, (void *)0);
119
      SCHED_FIND_REMOVE(tick_job, (void *)1);
120 1390 nogj
      SCHED_ADD(tick_job, (void *)0, (ttmr & SPR_TTMR_PERIOD) - ttcr);
121 728 markom
      break;
122
    case 2:    /* Stop the timer when match */
123 1365 nogj
      SCHED_FIND_REMOVE(tick_job, (void *)0);
124
      SCHED_FIND_REMOVE(tick_job, (void *)1);
125 728 markom
      break;
126
    case 3:    /* Timer keeps running -- do nothing*/
127
      break;
128
  }
129
}
130 611 simons
 
131 728 markom
unsigned long spr_read_ttcr ()
132
{
133 884 markom
  /*debug (7, "ttcr ---- %08x\n", runtime.sim.cycles - cycles_start);*/
134
  return runtime.sim.cycles - cycles_start;
135 91 lampret
}

powered by: WebSVN 2.1.0

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