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 333

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

powered by: WebSVN 2.1.0

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