OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [or1ksim/] [or1ksim-0.4.0rc1/] [testsuite/] [test-code-or1k/] [int-logger/] [int-logger-level.c] - Blame information for rev 105

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 93 jeremybenn
/* int-logger-level.c. Test of Or1ksim handling of level triggered interrupts
2
 
3
   Copyright (C) 2010 Embecosm Limited
4
 
5
   Contributors various OpenCores participants
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
22
 
23
/* ----------------------------------------------------------------------------
24
   This code is commented throughout for use with Doxygen.
25
   --------------------------------------------------------------------------*/
26
 
27
#include "support.h"
28
#include "spr-defs.h"
29
#include "board.h"
30
 
31
 
32
/* --------------------------------------------------------------------------*/
33
/*!Write a memory mapped register
34
 
35
   @param[in] addr   Memory mapped address
36
   @param[in] value  Value to set                                            */
37
/* --------------------------------------------------------------------------*/
38
static void
39
setreg (unsigned long addr,
40
        unsigned char value)
41
{
42
  *((volatile unsigned char *) addr) = value;
43
 
44
}       /* setreg () */
45
 
46
 
47
/* --------------------------------------------------------------------------*/
48
/*!Read a memory mapped register
49
 
50
   @param[in] addr   Memory mapped address
51
 
52
   @return  Value read                                                       */
53
/* --------------------------------------------------------------------------*/
54
unsigned long
55
getreg (unsigned long addr)
56
{
57
  return *((volatile unsigned char *) addr);
58
 
59
}       /* getreg () */
60
 
61
 
62
/* --------------------------------------------------------------------------*/
63
/*!Generic interrupt handler
64
 
65
   This should receive the interrupt exception. Report the value in
66
   PICSR. Clearing will be done externally.                                  */
67
/* --------------------------------------------------------------------------*/
68
static void
69
interrupt_handler ()
70
{
71
  unsigned long int  picsr = mfspr (SPR_PICSR);
72
 
73
  /* Report the interrupt */
74
  printf ("PICSR = 0x%08lx\n", picsr);
75
 
76
  /* Request the interrupt be cleared with a write upcall. */
77
  setreg (GENERIC_BASE, 0);
78
 
79
}       /* interrupt_handler () */
80
 
81
 
82
/* --------------------------------------------------------------------------*/
83
/*!Main program to set up interrupt handler
84
 
85
   @return  The return code from the program (always zero).                  */
86
/* --------------------------------------------------------------------------*/
87
int
88
main ()
89
{
90
  printf ("Starting interrupt handler\n");
91
  excpt_int = (unsigned long)interrupt_handler;
92
 
93
  /* Enable interrupts */
94
  printf ("Enabling interrupts.\n");
95
  mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
96
  mtspr (SPR_PICMR, 0xffffffff);
97
 
98
  /* Loop forever, upcalling reads every 500us to generate interrupts. */
99
  unsigned long int  start = read_timer ();
100
 
101
  while (1)
102
    {
103
      static long int  end_time  = 500;
104
 
105
      while ((read_timer () - start) < end_time)
106
        {
107
        }
108
 
109
      /* Do our memory mapped upcall read to generate an interrupt. */
110
      (void)getreg (GENERIC_BASE);
111
    }
112
 
113
  /* We don't actually ever return */
114
  return 0;
115
 
116
}       /* main () */

powered by: WebSVN 2.1.0

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