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 728

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
extern int cycles;
46
 
47 91 lampret
/* Reset. It initializes TTCR register. */
48
void tick_reset()
49
{
50 728 markom
  if (config.sim.verbose)
51
    printf("Resetting Tick Timer.\n");
52
  mtspr(SPR_TTCR, 0);
53
  mtspr(SPR_TTMR, 0);
54 91 lampret
}
55
 
56 728 markom
/* Job handler for tick timer */
57
void tick_job (int param)
58 91 lampret
{
59 728 markom
  int mode = (ttmr & SPR_TTMR_M) >> 30;
60
  /*debug (7, "tick_job%i, param %i\n", param, mode);*/
61
  switch (mode) {
62
  case 1:
63
    sprs[SPR_TTCR] = ttcr = 0;
64
  case 2:
65
    if (ttmr & SPR_TTMR_IE) {
66 133 markom
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
67 728 markom
      if ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE)
68
        except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
69
    }
70
    break;
71
  }
72
}
73 189 chris
 
74 728 markom
/* Starts the tick timer.  This function is called by a write to ttcr spr register */
75
void spr_write_ttcr (unsigned long value)
76
{
77
  unsigned mode = (ttmr & SPR_TTMR_M) >> 30;
78
  /*debug (7, "ttcr = %08x\n", value);*/
79
  ttcr = value;
80
  /* Remove previous if it exists */
81
  SCHED_FIND_REMOVE(tick_job, 0);
82
  if (mode == 1 || mode == 2) {
83
    SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
84
    cycles_start = cycles - ttcr;
85 133 markom
  }
86 728 markom
}
87 611 simons
 
88 728 markom
void spr_write_ttmr (unsigned long value)
89
{
90
  /*debug (7, "ttmr = %08x\n", value);*/
91
  ttmr = value;
92
  /* Handle the modes properly. */
93
  switch((ttmr & SPR_TTMR_M) >> 30) {
94
    case 0:    /* Timer is disabled */
95
      break;
96
    case 1:    /* Timer should auto restart */
97
      sprs[SPR_TTCR] = ttcr = 0;
98
      cycles_start = cycles;
99
      SCHED_FIND_REMOVE(tick_job, 0);
100
      SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
101
      break;
102
    case 2:    /* Stop the timer when match */
103
      SCHED_FIND_REMOVE(tick_job, 0);
104
      break;
105
    case 3:    /* Timer keeps running -- do nothing*/
106
      break;
107
  }
108
}
109 611 simons
 
110 728 markom
unsigned long spr_read_ttcr ()
111
{
112
  /*debug (7, "ttcr ---- %08x\n", cycles - cycles_start);*/
113
  return cycles - cycles_start;
114 91 lampret
}

powered by: WebSVN 2.1.0

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