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-edge.c] - Blame information for rev 105

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 93 jeremybenn
/* int-logger-edge.c. Test of Or1ksim handling of edge 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 PICSR,
66
   then clear the interrupt and reporting it again                           */
67
/* --------------------------------------------------------------------------*/
68
static void
69
interrupt_handler ()
70
{
71
  unsigned long int  old_picsr = mfspr (SPR_PICSR);
72
  mtspr (SPR_PICSR, 0);
73
  unsigned long int  new_picsr = mfspr (SPR_PICSR);
74
 
75
  printf ("PICSR 0x%08lx -> 0x%08lx\n", old_picsr, new_picsr);
76
 
77
}       /* interrupt_handler () */
78
 
79
 
80
/* --------------------------------------------------------------------------*/
81
/*!Main program to set up interrupt handler
82
 
83
   We make a series of upcalls, after 500 us and then every 1000us, which
84
   prompt some interrupts. By doing this, our upcalls should always be well
85
   clear of any calling function interrupt generation, which is on millisecond
86
   boundaries.
87
 
88
   @return  The return code from the program (always zero).                  */
89
/* --------------------------------------------------------------------------*/
90
int
91
main ()
92
{
93
  printf ("Starting interrupt handler\n");
94
  excpt_int = (unsigned long)interrupt_handler;
95
 
96
  /* Enable interrupts */
97
  printf ("Enabling interrupts.\n");
98
  mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
99
  mtspr (SPR_PICMR, 0xffffffff);
100
 
101
  /* Loop forever, upcalling at the desired intervals. */
102
  unsigned long int  start = read_timer ();
103
 
104
  while (1)
105
    {
106
      static int       do_read_p = 1;
107
      static long int  end_time  = 500;
108
 
109
      while ((read_timer () - start) < end_time)
110
        {
111
        }
112
 
113
      /* Do our memory mapped upcall, alternating reads and writes. */
114
      if (do_read_p)
115
        {
116
          (void)getreg (GENERIC_BASE);
117
          do_read_p = 0;
118
        }
119
      else
120
        {
121
          setreg (GENERIC_BASE, 0);
122
          do_read_p = 1;
123
        }
124
 
125
      /* Wait 1000us before next upcall. */
126
      end_time += 1000;
127
    }
128
 
129
  /* We don't actually ever return */
130
  return 0;
131
 
132
}       /* main () */

powered by: WebSVN 2.1.0

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