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 802

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 802 simons
    if (!param) {
64
      sprs[SPR_TTCR] = ttcr = 0;
65
      cycles_start = cycles - ttcr;
66
      SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
67
    }
68 728 markom
  case 2:
69
    if (ttmr & SPR_TTMR_IE) {
70 133 markom
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
71 728 markom
      if ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE)
72
        except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
73 802 simons
      else
74
        /* If TEE is currently not set we have to pend tick exception
75
           by rescheduling. */
76
        SCHED_ADD(tick_job, 1, cycles + 1);
77 728 markom
    }
78
    break;
79
  }
80
}
81 189 chris
 
82 728 markom
/* Starts the tick timer.  This function is called by a write to ttcr spr register */
83
void spr_write_ttcr (unsigned long value)
84
{
85
  unsigned mode = (ttmr & SPR_TTMR_M) >> 30;
86
  /*debug (7, "ttcr = %08x\n", value);*/
87
  ttcr = value;
88
  /* Remove previous if it exists */
89
  SCHED_FIND_REMOVE(tick_job, 0);
90 802 simons
  SCHED_FIND_REMOVE(tick_job, 1);
91 728 markom
  if (mode == 1 || mode == 2) {
92
    SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
93
    cycles_start = cycles - ttcr;
94 133 markom
  }
95 728 markom
}
96 611 simons
 
97 728 markom
void spr_write_ttmr (unsigned long value)
98
{
99
  /*debug (7, "ttmr = %08x\n", value);*/
100
  ttmr = value;
101
  /* Handle the modes properly. */
102
  switch((ttmr & SPR_TTMR_M) >> 30) {
103
    case 0:    /* Timer is disabled */
104 802 simons
      SCHED_FIND_REMOVE(tick_job, 0);
105
      SCHED_FIND_REMOVE(tick_job, 1);
106 728 markom
      break;
107
    case 1:    /* Timer should auto restart */
108
      sprs[SPR_TTCR] = ttcr = 0;
109
      cycles_start = cycles;
110
      SCHED_FIND_REMOVE(tick_job, 0);
111 802 simons
      SCHED_FIND_REMOVE(tick_job, 1);
112 728 markom
      SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
113
      break;
114
    case 2:    /* Stop the timer when match */
115
      SCHED_FIND_REMOVE(tick_job, 0);
116 802 simons
      SCHED_FIND_REMOVE(tick_job, 1);
117 728 markom
      break;
118
    case 3:    /* Timer keeps running -- do nothing*/
119
      break;
120
  }
121
}
122 611 simons
 
123 728 markom
unsigned long spr_read_ttcr ()
124
{
125
  /*debug (7, "ttcr ---- %08x\n", cycles - cycles_start);*/
126
  return cycles - cycles_start;
127 91 lampret
}

powered by: WebSVN 2.1.0

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