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 |
|
|
/* Initialize the program. Put the initialization message afterwards, or it
|
177 |
|
|
will get swamped by the Or1ksim header. */
|
178 |
|
|
if (0 == or1ksim_init (argv[1], argv[2], NULL, &read_upcall, &write_upcall))
|
179 |
|
|
{
|
180 |
|
|
printf ("Initalization succeeded.\n");
|
181 |
|
|
}
|
182 |
|
|
else
|
183 |
|
|
{
|
184 |
|
|
printf ("Initalization failed.\n");
|
185 |
|
|
return 1;
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
/* Do each interrupt in turn. Set up the shared pointer to the interrupts
|
189 |
|
|
and counter. */
|
190 |
|
|
intv = &(argv[4]);
|
191 |
|
|
intc = argc - 4;
|
192 |
|
|
|
193 |
|
|
do
|
194 |
|
|
{
|
195 |
|
|
/* Run the code */
|
196 |
|
|
if (OR1KSIM_RC_OK != or1ksim_run (duration))
|
197 |
|
|
{
|
198 |
|
|
printf ("ERROR: run failed\n");
|
199 |
|
|
return 1;
|
200 |
|
|
}
|
201 |
|
|
}
|
202 |
|
|
while (do_next_int ());
|
203 |
|
|
|
204 |
|
|
/* One more run, to allow interrupt handler enough time to finish
|
205 |
|
|
processing. */
|
206 |
|
|
if (OR1KSIM_RC_OK != or1ksim_run (duration))
|
207 |
|
|
{
|
208 |
|
|
printf ("ERROR: run failed\n");
|
209 |
|
|
return 1;
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
/* All interrupts should have been handled. */
|
213 |
|
|
printf ("Test completed successfully.\n");
|
214 |
|
|
return 0;
|
215 |
|
|
|
216 |
|
|
} /* main () */
|