1 |
786 |
skrzyp |
/*=================================================================
|
2 |
|
|
//
|
3 |
|
|
// kintr0.c
|
4 |
|
|
//
|
5 |
|
|
// Kernel C API Intr test 0
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): dsm
|
43 |
|
|
// Contributors: dsm, jlarmour
|
44 |
|
|
// Date: 1999-02-16
|
45 |
|
|
// Description: Very basic test of interrupt objects
|
46 |
|
|
// Options:
|
47 |
|
|
// CYGIMP_KERNEL_INTERRUPTS_DSRS_TABLE
|
48 |
|
|
// CYGNUM_KERNEL_INTERRUPTS_DSRS_TABLE_SIZE
|
49 |
|
|
// CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
|
50 |
|
|
// CYGSEM_KERNEL_INTERRUPTS_DSRS_LIST_FIFO
|
51 |
|
|
//####DESCRIPTIONEND####
|
52 |
|
|
*/
|
53 |
|
|
|
54 |
|
|
#include <cyg/kernel/kapi.h>
|
55 |
|
|
#include <cyg/hal/hal_intr.h>
|
56 |
|
|
|
57 |
|
|
#include <cyg/infra/testcase.h>
|
58 |
|
|
|
59 |
|
|
#ifdef CYGFUN_KERNEL_API_C
|
60 |
|
|
|
61 |
|
|
#include "testaux.h"
|
62 |
|
|
|
63 |
|
|
#ifdef HAL_INTR_TEST_PRIO_A
|
64 |
|
|
# define PRIO_A HAL_INTR_TEST_PRIO_A
|
65 |
|
|
#else
|
66 |
|
|
# define PRIO_A 0
|
67 |
|
|
#endif
|
68 |
|
|
|
69 |
|
|
#ifdef HAL_INTR_TEST_PRIO_B
|
70 |
|
|
# define PRIO_B HAL_INTR_TEST_PRIO_B
|
71 |
|
|
#else
|
72 |
|
|
# define PRIO_B 1
|
73 |
|
|
#endif
|
74 |
|
|
|
75 |
|
|
#ifdef HAL_INTR_TEST_PRIO_C
|
76 |
|
|
# define PRIO_C HAL_INTR_TEST_PRIO_C
|
77 |
|
|
#else
|
78 |
|
|
# define PRIO_C 1
|
79 |
|
|
#endif
|
80 |
|
|
|
81 |
|
|
static cyg_interrupt intr_obj[2];
|
82 |
|
|
|
83 |
|
|
static cyg_handle_t intr0, intr1;
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
static cyg_ISR_t isr0, isr1;
|
87 |
|
|
static cyg_DSR_t dsr0, dsr1;
|
88 |
|
|
|
89 |
|
|
static cyg_uint32 isr0(cyg_vector_t vector, cyg_addrword_t data)
|
90 |
|
|
{
|
91 |
|
|
CYG_UNUSED_PARAM(cyg_addrword_t, data);
|
92 |
|
|
|
93 |
|
|
cyg_interrupt_acknowledge(vector);
|
94 |
|
|
return 0;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
static void dsr0(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
|
98 |
|
|
{
|
99 |
|
|
CYG_UNUSED_PARAM(cyg_vector_t, vector);
|
100 |
|
|
CYG_UNUSED_PARAM(cyg_ucount32, count);
|
101 |
|
|
CYG_UNUSED_PARAM(cyg_addrword_t, data);
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
static cyg_uint32 isr1(cyg_vector_t vector, cyg_addrword_t data)
|
105 |
|
|
{
|
106 |
|
|
CYG_UNUSED_PARAM(cyg_vector_t, vector);
|
107 |
|
|
CYG_UNUSED_PARAM(cyg_addrword_t, data);
|
108 |
|
|
return 0;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
static void dsr1(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
|
112 |
|
|
{
|
113 |
|
|
CYG_UNUSED_PARAM(cyg_vector_t, vector);
|
114 |
|
|
CYG_UNUSED_PARAM(cyg_ucount32, count);
|
115 |
|
|
CYG_UNUSED_PARAM(cyg_addrword_t, data);
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
static bool flash( void )
|
119 |
|
|
{
|
120 |
|
|
cyg_handle_t handle;
|
121 |
|
|
cyg_interrupt intr;
|
122 |
|
|
|
123 |
|
|
cyg_interrupt_create(CYGNUM_HAL_ISR_MIN, PRIO_A, (cyg_addrword_t)333,
|
124 |
|
|
isr0, dsr0, &handle, &intr );
|
125 |
|
|
cyg_interrupt_delete(handle);
|
126 |
|
|
|
127 |
|
|
return true;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
/* IMPORTANT: The calling convention for VSRs is target dependent. It is
|
131 |
|
|
* unlikely that a plain C or C++ routine would function correctly on any
|
132 |
|
|
* particular platform, even if it could correctly access the system
|
133 |
|
|
* resources necessary to handle the event that caused it to be called.
|
134 |
|
|
* VSRs usually must be written in assembly language.
|
135 |
|
|
*
|
136 |
|
|
* This is just a test program. The routine vsr0() below is defined simply
|
137 |
|
|
* to define an address that will be in executable memory. If an event
|
138 |
|
|
* causes this VSR to be called, all bets are off. If it is accidentally
|
139 |
|
|
* installed in the vector for the realtime clock, the system will likely
|
140 |
|
|
* freeze.
|
141 |
|
|
*/
|
142 |
|
|
|
143 |
|
|
static cyg_VSR_t vsr0;
|
144 |
|
|
|
145 |
|
|
static void vsr0()
|
146 |
|
|
{
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
void kintr0_main( void )
|
150 |
|
|
{
|
151 |
|
|
cyg_vector_t v = (CYGNUM_HAL_VSR_MIN + 11) % CYGNUM_HAL_VSR_COUNT;
|
152 |
|
|
cyg_vector_t v1;
|
153 |
|
|
cyg_vector_t lvl1 = CYGNUM_HAL_ISR_MIN + (1 % CYGNUM_HAL_ISR_COUNT);
|
154 |
|
|
cyg_vector_t lvl2 = CYGNUM_HAL_ISR_MIN + (15 % CYGNUM_HAL_ISR_COUNT);
|
155 |
|
|
int in_use;
|
156 |
|
|
|
157 |
|
|
cyg_VSR_t *old_vsr, *new_vsr;
|
158 |
|
|
|
159 |
|
|
CYG_TEST_INIT();
|
160 |
|
|
|
161 |
|
|
#ifdef CYGPKG_HAL_MIPS_TX39
|
162 |
|
|
// This can be removed when PR 17831 is fixed
|
163 |
|
|
if ( cyg_test_is_simulator )
|
164 |
|
|
v1 = 12 % CYGNUM_HAL_ISR_COUNT;
|
165 |
|
|
else /* NOTE TRAILING ELSE... */
|
166 |
|
|
#endif
|
167 |
|
|
v1 = CYGNUM_HAL_ISR_MIN + ( 6 % CYGNUM_HAL_ISR_COUNT);
|
168 |
|
|
|
169 |
|
|
CHECK(flash());
|
170 |
|
|
CHECK(flash());
|
171 |
|
|
|
172 |
|
|
// Make sure the chosen levels are not already in use.
|
173 |
|
|
HAL_INTERRUPT_IN_USE( lvl1, in_use );
|
174 |
|
|
intr0 = 0;
|
175 |
|
|
if (!in_use)
|
176 |
|
|
cyg_interrupt_create(lvl1, PRIO_B, (cyg_addrword_t)777,
|
177 |
|
|
isr0, dsr0, &intr0, &intr_obj[0]);
|
178 |
|
|
|
179 |
|
|
HAL_INTERRUPT_IN_USE( lvl2, in_use );
|
180 |
|
|
intr1 = 0;
|
181 |
|
|
if (!in_use && lvl1 != lvl2)
|
182 |
|
|
cyg_interrupt_create(lvl2, PRIO_C, 888,
|
183 |
|
|
isr1, dsr1, &intr1, &intr_obj[1]);
|
184 |
|
|
|
185 |
|
|
// Check these functions at least exist
|
186 |
|
|
|
187 |
|
|
cyg_interrupt_disable();
|
188 |
|
|
cyg_interrupt_enable();
|
189 |
|
|
|
190 |
|
|
if (intr0)
|
191 |
|
|
cyg_interrupt_attach(intr0);
|
192 |
|
|
if (intr1)
|
193 |
|
|
cyg_interrupt_attach(intr1);
|
194 |
|
|
if (intr0)
|
195 |
|
|
cyg_interrupt_detach(intr0);
|
196 |
|
|
if (intr1)
|
197 |
|
|
cyg_interrupt_detach(intr1);
|
198 |
|
|
|
199 |
|
|
// If this attaching interrupt replaces the previous interrupt
|
200 |
|
|
// instead of adding to it we could be in a big mess if the
|
201 |
|
|
// vector is being used by something important.
|
202 |
|
|
|
203 |
|
|
cyg_interrupt_get_vsr( v, &old_vsr );
|
204 |
|
|
cyg_interrupt_set_vsr( v, vsr0 );
|
205 |
|
|
cyg_interrupt_get_vsr( v, &new_vsr );
|
206 |
|
|
CHECK( vsr0 == new_vsr );
|
207 |
|
|
|
208 |
|
|
new_vsr = NULL;
|
209 |
|
|
cyg_interrupt_get_vsr( v, &new_vsr );
|
210 |
|
|
cyg_interrupt_set_vsr( v, old_vsr );
|
211 |
|
|
CHECK( new_vsr == vsr0 );
|
212 |
|
|
|
213 |
|
|
cyg_interrupt_set_vsr( v, new_vsr );
|
214 |
|
|
new_vsr = NULL;
|
215 |
|
|
cyg_interrupt_get_vsr( v, &new_vsr );
|
216 |
|
|
CHECK( vsr0 == new_vsr );
|
217 |
|
|
|
218 |
|
|
cyg_interrupt_set_vsr( v, old_vsr );
|
219 |
|
|
CHECK( vsr0 == new_vsr );
|
220 |
|
|
new_vsr = NULL;
|
221 |
|
|
cyg_interrupt_get_vsr( v, &new_vsr );
|
222 |
|
|
CHECK( old_vsr == new_vsr );
|
223 |
|
|
|
224 |
|
|
CHECK( NULL != vsr0 );
|
225 |
|
|
|
226 |
|
|
cyg_interrupt_mask(v1);
|
227 |
|
|
cyg_interrupt_unmask(v1);
|
228 |
|
|
|
229 |
|
|
cyg_interrupt_configure(v1, true, true);
|
230 |
|
|
|
231 |
|
|
CYG_TEST_PASS_FINISH("Kernel C API Intr 0 OK");
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
externC void
|
235 |
|
|
cyg_start( void )
|
236 |
|
|
{
|
237 |
|
|
kintr0_main();
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
#else /* def CYGFUN_KERNEL_API_C */
|
241 |
|
|
externC void
|
242 |
|
|
cyg_start( void )
|
243 |
|
|
{
|
244 |
|
|
CYG_TEST_INIT();
|
245 |
|
|
CYG_TEST_NA("Kernel C API layer disabled");
|
246 |
|
|
}
|
247 |
|
|
#endif /* def CYGFUN_KERNEL_API_C */
|
248 |
|
|
|
249 |
|
|
/* EOF kintr0.c */
|