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.5.0rc1/] [testsuite/] [test-code/] [lib-inttest/] [lib-inttest-level.c] - Blame information for rev 93

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 93 jeremybenn
/* lib-inttest-level.c. Test of Or1ksim library level triggered interrupt funcs.
2
 
3
   Copyright (C) 1999-2006 OpenCores
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributors various OpenCores participants
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
23
 
24
/* ----------------------------------------------------------------------------
25
   This code is commented throughout for use with Doxygen.
26
   --------------------------------------------------------------------------*/
27
 
28
#include <stddef.h>
29
#include <stdlib.h>
30
#include <stdio.h>
31
 
32
#include "or1ksim.h"
33
 
34
 
35
/*! Number of interrupts in PIC */
36
#define  NUM_INTS  32
37
 
38
/*! Vector of interrupts to be raised */
39
static int *raisev;
40
 
41
/*! Count of interrupts to be raised */
42
static int  raisec = 0;
43
 
44
/*! Next interrupt to be raised */
45
static int  next_raise = 0;
46
 
47
/*! Vector of interrupts to be cleared */
48
static int *clearv;
49
 
50
/*! Count of interrupts to be cleared */
51
static int  clearc = 0;
52
 
53
/*! Next interrupt to be cleared */
54
static int  next_clear = 0;
55
 
56
 
57
/* --------------------------------------------------------------------------*/
58
/*!Read upcall
59
 
60
   Upcall from Or1ksim to read a word from an external peripheral. If called
61
   this will raise the next interrupt.
62
 
63
   @param[in]  class_ptr  A handle pass back from the initalization. Intended
64
                          for C++ callers, not used here.
65
   @param[in]  addr       Address to read from. Ignored here.
66
   @param[in]  mask       Byte mask for the read. Ignored here.
67
   @param[out] rdata      Buffer for the data read. Ignored here.
68
   @param[in]  data_len   Number of bytes in mask and rdata.
69
 
70
   @return  Zero on success, non-zero on failure. Always zero here.          */
71
/* --------------------------------------------------------------------------*/
72
static int
73
read_upcall (void              *class_ptr,
74
             unsigned long int  addr,
75
             unsigned char      mask[],
76
             unsigned char      rdata[],
77
             int                data_len)
78
{
79
  /* Raise an interrupt if there is one left to raise. */
80
  if ((NULL != raisev) && (next_raise < raisec))
81
    {
82
      printf ("Raising interrupt %d\n", raisev[next_raise]);
83
      or1ksim_interrupt_set (raisev[next_raise++]);
84
    }
85
 
86
  return  0;                     /* Success */
87
 
88
}       /* read_upcall () */
89
 
90
 
91
/* --------------------------------------------------------------------------*/
92
/*!Write upcall
93
 
94
   Upcall from Or1ksim to write a word to an external peripheral. If called
95
   this will clear the next interrupt.
96
 
97
   @param[in] class_ptr  A handle pass back from the initalization. Intended
98
                         for C++ callers, not used here.
99
   @param[in] addr       Address to write to. Ignored here.
100
   @param[in] mask       Byte mask for the write. Ignored here.
101
   @param[in] wdata      The data to write. Ignored here.
102
   @param[in] data_len   Number of bytes in mask and rdata.
103
 
104
   @return  Zero on success, non-zero on failure. Always zero here.          */
105
/* --------------------------------------------------------------------------*/
106
static int
107
write_upcall (void              *class_ptr,
108
              unsigned long int  addr,
109
              unsigned char      mask[],
110
              unsigned char      wdata[],
111
              int                data_len)
112
{
113
  /* Clear an interrupt if there is one left to clear. */
114
  if ((NULL != clearv) && (next_clear < clearc))
115
    {
116
      printf ("Clearing interrupt %d\n", clearv[next_clear]);
117
      or1ksim_interrupt_clear (clearv[next_clear++]);
118
    }
119
 
120
  return  0;                     /* Success */
121
 
122
}       /* write_upcall () */
123
 
124
 
125
/* --------------------------------------------------------------------------*/
126
/*!Main program
127
 
128
   Build an or1ksim program using the library which loads a program and config
129
   from the command line, and then drives interrupts. Usage:
130
 
131
   lib-inttest-level <config-file> <image> +|-<int #> +|-<int #> ...
132
 
133
   <image> is run continuously. It requests that an interrupt be raised by a
134
   read upcall and cleared by a write upcall. The sequence of interrupts is
135
   specified to be raised (if preceded by '+') or cleared (if preceded by
136
   '-'). This allows the program to test the effect of clearing the wrong
137
   interrupt.
138
 
139
   @param[in] argc  Number of elements in argv
140
   @param[in] argv  Vector of program name and arguments
141
 
142
   @return  Return code for the program.                                     */
143
/* --------------------------------------------------------------------------*/
144
int
145
main (int   argc,
146
      char *argv[])
147
{
148
  /* Parse args */
149
  if (argc < 4)
150
    {
151
      fprintf (stderr,
152
               "usage: lib-inttest-level <config-file> <image> "
153
               "+|-<int #> +|-<int #> ...\n");
154
      return  1;
155
    }
156
 
157
  /* Get all the interrupts sorted out. Count them, then place them in a
158
     vector. */
159
  int  i;
160
 
161
  for (i = 3; i < argc; i++)
162
    {
163
      int  inum;
164
 
165
      switch (argv[i][0])
166
        {
167
        case '+':
168
          inum = atoi (&(argv[i][1]));
169
 
170
          if ((0 <= inum) && (inum < NUM_INTS))
171
            {
172
              raisec++;
173
            }
174
          else
175
            {
176
              printf ("Warning: Invalid interrupt # %d to raise.\n", inum);
177
            }
178
 
179
          break;
180
 
181
        case '-':
182
          inum = atoi (&(argv[i][1]));
183
 
184
          if ((0 <= inum) && (inum < NUM_INTS))
185
            {
186
              clearc++;
187
            }
188
          else
189
            {
190
              printf ("Warning: Invalid interrupt # %d to clear.\n", inum);
191
            }
192
 
193
          break;
194
 
195
 
196
        default:
197
          printf ("Warning: No raise/clear specified - ignored\n");
198
          break;
199
        }
200
    }
201
 
202
  if ((0 == raisec) && (0 == clearc))
203
    {
204
      printf ("ERROR: No interrupts specified.\n");
205
      return  1;
206
    }
207
 
208
  /* Allocate space and populate the vectors. */
209
  raisev = (raisec > 0) ? calloc (raisec, sizeof (int)) : NULL;
210
  clearv = (clearc > 0) ? calloc (clearc, sizeof (int)) : NULL;
211
 
212
  raisec = 0;
213
  clearc = 0;
214
 
215
  for (i = 3; i < argc; i++)
216
    {
217
      int  inum;
218
 
219
      switch (argv[i][0])
220
        {
221
        case '+':
222
          inum = atoi (&(argv[i][1]));
223
 
224
          if ((0 <= inum) && (inum < NUM_INTS))
225
            {
226
              raisev[raisec++] = inum;
227
            }
228
 
229
          break;
230
 
231
        case '-':
232
          inum = atoi (&(argv[i][1]));
233
 
234
          if ((0 <= inum) && (inum < NUM_INTS))
235
            {
236
              clearv[clearc++] = inum;
237
            }
238
 
239
          break;
240
 
241
 
242
        default:
243
          printf ("Warning: No raise/clear specified - ignored\n");
244
          break;
245
        }
246
    }
247
 
248
  /* Start the counts */
249
  next_raise = 0;
250
  next_clear = 0;
251
 
252
  /* Initialize the program. Put the initialization message afterwards, or it
253
     will get swamped by the Or1ksim header. */
254
  if (0 == or1ksim_init (argv[1], argv[2], NULL, &read_upcall, &write_upcall))
255
    {
256
      printf ("Initalization succeeded.\n");
257
    }
258
  else
259
    {
260
      printf ("Initalization failed.\n");
261
      free (raisev);
262
      free (clearv);
263
      return  1;
264
    }
265
 
266
  /* Run in bursts of 1ms until all interrupts have been set and cleared. */
267
  do
268
    {
269
      if (OR1KSIM_RC_OK != or1ksim_run (1.0e-3))
270
        {
271
          printf ("ERROR: run failed\n");
272
          free (raisev);
273
          free (clearv);
274
          return  1;
275
        }
276
    }
277
  while ((next_raise < raisec) || (next_clear < clearc));
278
 
279
  /* One more burst to allow the device driver time to complete. */
280
  if (OR1KSIM_RC_OK != or1ksim_run (1.0e-3))
281
    {
282
      printf ("ERROR: run failed\n");
283
      free (raisev);
284
      free (clearv);
285
      return  1;
286
    }
287
 
288
  /* All interrupts should have been handled. */
289
  free (raisev);
290
  free (clearv);
291
 
292
  printf ("Test completed successfully.\n");
293
  return  0;
294
 
295
}       /* main () */

powered by: WebSVN 2.1.0

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