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

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

Line No. Rev Author Line
1 93 jeremybenn
/* lib-inttest-edge.c. Test of Or1ksim library edge 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 <stdlib.h>
29
#include <stdio.h>
30
 
31
#include "or1ksim.h"
32
 
33
 
34
/*! Number of interrupts in PIC */
35
#define  NUM_INTS  32
36
 
37
/*! Globally shared pointer to the interrupts */
38
char **intv;
39
 
40
/*! Number of interrupts to process */
41
int  intc;
42
 
43
 
44
/* --------------------------------------------------------------------------*/
45
/*!Trigger the next interrupt
46
 
47
   Generate the next edge triggered interrupt. Put out a message if doing so,
48
   and warn if the interrupt would be invalid.
49
 
50
   @return  1 (true) if an interrupt was triggered, 0 (false) otherwise.     */
51
/* --------------------------------------------------------------------------*/
52
static int
53
do_next_int ()
54
{
55
  static int  next_int = 0;              /* Next interrupt to process */
56
 
57
  while (next_int < intc)
58
    {
59
      int  inum = atoi (intv[next_int++]);
60
 
61
      if ((0 <= inum) && (inum < NUM_INTS))
62
        {
63
          printf ("Triggering interrupt %d\n", inum);
64
          or1ksim_interrupt (inum);
65
          return  1;
66
        }
67
      else
68
        {
69
          printf ("Warning: Invalid interrupt # %d - ignored\n", inum);
70
        }
71
    }
72
 
73
  return  0;                             /* No more interrupts to trigger */
74
 
75
}       /* do_next_int () */
76
 
77
 
78
/* --------------------------------------------------------------------------*/
79
/*!Read upcall
80
 
81
   Upcall from Or1ksim to read a word from an external peripheral. If called
82
   this will trigger an interrupt.
83
 
84
   @param[in]  class_ptr  A handle pass back from the initalization. Intended
85
                          for C++ callers, not used here.
86
   @param[in]  addr       Address to read from. Ignored here.
87
   @param[in]  mask       Byte mask for the read. Ignored here.
88
   @param[out] rdata      Buffer for the data read. Ignored here.
89
   @param[in]  data_len   Number of bytes in mask and rdata.
90
 
91
   @return  Zero on success, non-zero on failure. Always zero here.          */
92
/* --------------------------------------------------------------------------*/
93
static int
94
read_upcall (void              *class_ptr,
95
             unsigned long int  addr,
96
             unsigned char      mask[],
97
             unsigned char      rdata[],
98
             int                data_len)
99
{
100
  do_next_int ();
101
 
102
  return  0;                     /* Success */
103
 
104
}       /* read_upcall () */
105
 
106
 
107
/* --------------------------------------------------------------------------*/
108
/*!Write upcall
109
 
110
   Upcall from Or1ksim to write a word to an external peripheral. If called
111
   this will trigger an interrupt.
112
 
113
   @param[in] class_ptr  A handle pass back from the initalization. Intended
114
                         for C++ callers, not used here.
115
   @param[in] addr       Address to write to. Ignored here.
116
   @param[in] mask       Byte mask for the write. Ignored here.
117
   @param[in] wdata      The data to write. Ignored here.
118
   @param[in] data_len   Number of bytes in mask and rdata.
119
 
120
   @return  Zero on success, non-zero on failure. Always zero here.          */
121
/* --------------------------------------------------------------------------*/
122
static int
123
write_upcall (void              *class_ptr,
124
              unsigned long int  addr,
125
              unsigned char      mask[],
126
              unsigned char      wdata[],
127
              int                data_len)
128
{
129
  do_next_int ();
130
 
131
  return  0;                     /* Success */
132
 
133
}       /* write_upcall () */
134
 
135
 
136
/* --------------------------------------------------------------------------*/
137
/*!Main program
138
 
139
   Build an or1ksim program using the library which loads a program and config
140
   from the command line, and then drives interrupts. Usage:
141
 
142
   lib-inttest-edge <config-file> <image> <duration_ms> <int #> <int #> ...
143
 
144
   <image> is run for repeated perios of <duration_ms>, during which it
145
   will make upcalls. Between each period and during each upcall an edge based
146
   interrupt will be triggered, until all interrupts listed have been
147
   triggered.
148
 
149
   @param[in] argc  Number of elements in argv
150
   @param[in] argv  Vector of program name and arguments
151
 
152
   @return  Return code for the program.                                     */
153
/* --------------------------------------------------------------------------*/
154
int
155
main (int   argc,
156
      char *argv[])
157
{
158
  /* Parse args */
159
  if (argc < 5)
160
    {
161
      fprintf (stderr,
162
               "usage: lib-inttest-edge <config-file> <image> <duration_ms> "
163
               "<int #> <int #> ...\n");
164
      return  1;
165
    }
166
 
167
  int     duration_ms = atoi (argv[3]);
168
  double  duration    = (double) duration_ms / 1.0e3;
169
 
170
  if (duration_ms <= 0)
171
    {
172
      fprintf (stderr, "ERROR. Duration must be positive number of ms\n");
173
      return  1;
174
    }
175
 
176 220 jeremybenn
  /* Dummy argv array to pass arguments to or1ksim_init. Varies depending on
177
     whether an image file is specified. */
178
  int   dummy_argc;
179
  char *dummy_argv[5];
180
 
181
  dummy_argv[0] = "libsim";
182
  dummy_argv[1] = "-q";
183
  dummy_argv[2] = "-f";
184
  dummy_argv[3] = argv[1];
185
  dummy_argv[4] = argv[2];
186
 
187
  dummy_argc = 5;
188
 
189 93 jeremybenn
  /* Initialize the program. Put the initialization message afterwards, or it
190
     will get swamped by the Or1ksim header. */
191 220 jeremybenn
  if (0 == or1ksim_init (dummy_argc, dummy_argv, NULL, &read_upcall,
192
                         &write_upcall))
193 93 jeremybenn
    {
194
      printf ("Initalization succeeded.\n");
195
    }
196
  else
197
    {
198
      printf ("Initalization failed.\n");
199
      return  1;
200
    }
201
 
202
  /* Do each interrupt in turn. Set up the shared pointer to the interrupts
203
     and counter. */
204
  intv = &(argv[4]);
205
  intc = argc - 4;
206
 
207
  do
208
    {
209
      /* Run the code */
210
      if (OR1KSIM_RC_OK != or1ksim_run (duration))
211
        {
212
          printf ("ERROR: run failed\n");
213
          return  1;
214
        }
215
    }
216
  while (do_next_int ());
217
 
218
  /* One more run, to allow interrupt handler enough time to finish
219
     processing. */
220
  if (OR1KSIM_RC_OK != or1ksim_run (duration))
221
    {
222
      printf ("ERROR: run failed\n");
223
      return  1;
224
    }
225
 
226
  /* All interrupts should have been handled. */
227
  printf ("Test completed successfully.\n");
228
  return  0;
229
 
230
}       /* main () */

powered by: WebSVN 2.1.0

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