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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_1_x/] [or1ksim/] [tick/] [tick.c] - Blame information for rev 167

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 167 markom
#include "../cpu/or1k/sprs.h"
31 102 lampret
#include "pic.h"
32 91 lampret
 
33 133 markom
/* For mode 10 only: timer stops until we write into TTCR.  */
34
int tt_stopped = 0;
35
 
36 91 lampret
/* Reset. It initializes TTCR register. */
37
void tick_reset()
38
{
39 133 markom
  printf("Resetting Tick Timer.\n");
40
  mtspr(SPR_TTCR, 0);
41
  mtspr(SPR_TTMR, 0);
42
  tt_stopped = 0;
43 91 lampret
}
44
 
45
/* Simulation hook. Must be called every clock cycle to simulate tick
46
   timer. It does internal functional tick timer simulation. */
47
void tick_clock()
48
{
49 133 markom
  unsigned long ttcr;
50
  unsigned long ttmr;
51
 
52
  ttcr = mfspr(SPR_TTCR);
53
  ttmr = mfspr(SPR_TTMR);
54
 
55
  if (!(ttmr & SPR_TTMR_M) || tt_stopped)
56
    return;
57
 
58
  if ((ttcr & SPR_TTCR_PERIOD) == (ttmr & SPR_TTMR_PERIOD)) {
59
    if (ttmr & SPR_TTMR_IE) {
60
      setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
61
      report_interrupt(INT_TICK);
62
    }
63
 
64 167 markom
    if ((ttmr & SPR_TTMR_M) >> 30 == 1) {
65 133 markom
      /* Mode 01: Restart timer.  */
66
      ttcr = 0;
67
      mtspr(SPR_TTCR, ttcr);
68
      return;
69 167 markom
     } else if ((ttmr & SPR_TTMR_M) >> 30 == 2) {
70 133 markom
      /* Mode 10: Temporarly stop timer.  */
71
      tt_stopped = 1;
72
      return;
73
    }
74
  }
75
  if (!tt_stopped)
76
    ttcr++;
77
  mtspr(SPR_TTCR, ttcr);
78 91 lampret
}

powered by: WebSVN 2.1.0

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