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 600

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
#include "../cpu/or1k/spr_defs.h"
31 102 lampret
#include "pic.h"
32 189 chris
#include "sprs.h"
33 333 markom
#include "sim-config.h"
34 91 lampret
 
35 133 markom
/* For mode 10 only: timer stops until we write into TTCR.  */
36
int tt_stopped = 0;
37
 
38 91 lampret
/* Reset. It initializes TTCR register. */
39
void tick_reset()
40
{
41 332 markom
  if (config.tick.enabled) {
42
    if (config.sim.verbose)
43
      printf("Resetting Tick Timer.\n");
44
    mtspr(SPR_TTCR, 0);
45
    mtspr(SPR_TTMR, 0);
46
    tt_stopped = 0;
47
  } else
48
    tt_stopped = 1;
49 91 lampret
}
50
 
51
/* Simulation hook. Must be called every clock cycle to simulate tick
52
   timer. It does internal functional tick timer simulation. */
53 332 markom
inline void tick_clock()
54 91 lampret
{
55 133 markom
  unsigned long ttcr;
56
  unsigned long ttmr;
57 332 markom
 
58
  if (tt_stopped)
59
    return;
60
 
61 133 markom
  ttcr = mfspr(SPR_TTCR);
62
  ttmr = mfspr(SPR_TTMR);
63
 
64 332 markom
  if (!(ttmr & SPR_TTMR_M))
65 133 markom
    return;
66
 
67
  if ((ttcr & SPR_TTCR_PERIOD) == (ttmr & SPR_TTMR_PERIOD)) {
68 189 chris
    int mode = (ttmr & SPR_TTMR_M) >> 30; /* CZ 04/09/01 */
69
 
70 133 markom
    if (ttmr & SPR_TTMR_IE) {
71
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
72 600 simons
      if ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE)
73
        except_handle(EXCEPT_TICK, 0);
74 133 markom
    }
75 189 chris
 
76
    /* Handle the modes properly.. CZ 04/09/01 */
77
    switch(mode)
78
      {
79
      case 0:    /* Timer is disabled */
80 600 simons
        tt_stopped = 1;
81
        break;
82 189 chris
      case 1:    /* Timer should auto restart */
83 600 simons
        ttcr = 0;
84
        mtspr(SPR_TTCR,ttcr);
85
        break;
86 189 chris
      case 2:    /* Pause the timer */
87 600 simons
        tt_stopped = 1;
88
        break;
89 189 chris
      case 3:    /* Timer keeps running */
90 600 simons
        break;
91 189 chris
      }
92 133 markom
  }
93
  if (!tt_stopped)
94
    ttcr++;
95
  mtspr(SPR_TTCR, ttcr);
96 91 lampret
}

powered by: WebSVN 2.1.0

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