1 /*=================================================================
5 // Kernel C API Intr test 0
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: dsm, jlarmour
46 // Description: Very basic test of interrupt objects
48 // CYGIMP_KERNEL_INTERRUPTS_DSRS_TABLE
49 // CYGNUM_KERNEL_INTERRUPTS_DSRS_TABLE_SIZE
50 // CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
51 // CYGSEM_KERNEL_INTERRUPTS_DSRS_LIST_FIFO
52 //####DESCRIPTIONEND####
55 #include <cyg/kernel/kapi.h>
56 #include <cyg/hal/hal_intr.h>
58 #include <cyg/infra/testcase.h>
60 #ifdef CYGFUN_KERNEL_API_C
64 #ifdef HAL_INTR_TEST_PRIO_A
65 # define PRIO_A HAL_INTR_TEST_PRIO_A
70 #ifdef HAL_INTR_TEST_PRIO_B
71 # define PRIO_B HAL_INTR_TEST_PRIO_B
76 #ifdef HAL_INTR_TEST_PRIO_C
77 # define PRIO_C HAL_INTR_TEST_PRIO_C
82 static cyg_interrupt intr_obj[2];
84 static cyg_handle_t intr0, intr1;
87 static cyg_ISR_t isr0, isr1;
88 static cyg_DSR_t dsr0, dsr1;
90 static cyg_uint32 isr0(cyg_vector_t vector, cyg_addrword_t data)
92 CYG_UNUSED_PARAM(cyg_addrword_t, data);
94 cyg_interrupt_acknowledge(vector);
98 static void dsr0(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
100 CYG_UNUSED_PARAM(cyg_vector_t, vector);
101 CYG_UNUSED_PARAM(cyg_ucount32, count);
102 CYG_UNUSED_PARAM(cyg_addrword_t, data);
105 static cyg_uint32 isr1(cyg_vector_t vector, cyg_addrword_t data)
107 CYG_UNUSED_PARAM(cyg_vector_t, vector);
108 CYG_UNUSED_PARAM(cyg_addrword_t, data);
112 static void dsr1(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
114 CYG_UNUSED_PARAM(cyg_vector_t, vector);
115 CYG_UNUSED_PARAM(cyg_ucount32, count);
116 CYG_UNUSED_PARAM(cyg_addrword_t, data);
119 static bool flash( void )
124 cyg_interrupt_create(CYGNUM_HAL_ISR_MIN, PRIO_A, (cyg_addrword_t)333,
125 isr0, dsr0, &handle, &intr );
126 cyg_interrupt_delete(handle);
131 /* IMPORTANT: The calling convention for VSRs is target dependent. It is
132 * unlikely that a plain C or C++ routine would function correctly on any
133 * particular platform, even if it could correctly access the system
134 * resources necessary to handle the event that caused it to be called.
135 * VSRs usually must be written in assembly language.
137 * This is just a test program. The routine vsr0() below is defined simply
138 * to define an address that will be in executable memory. If an event
139 * causes this VSR to be called, all bets are off. If it is accidentally
140 * installed in the vector for the realtime clock, the system will likely
144 static cyg_VSR_t vsr0;
150 void kintr0_main( void )
152 cyg_vector_t v = (CYGNUM_HAL_VSR_MIN + 11) % CYGNUM_HAL_VSR_COUNT;
154 cyg_vector_t lvl1 = CYGNUM_HAL_ISR_MIN + (1 % CYGNUM_HAL_ISR_COUNT);
155 cyg_vector_t lvl2 = CYGNUM_HAL_ISR_MIN + (15 % CYGNUM_HAL_ISR_COUNT);
158 cyg_VSR_t *old_vsr, *new_vsr;
162 #ifdef CYGPKG_HAL_MIPS_TX39
163 // This can be removed when PR 17831 is fixed
164 if ( cyg_test_is_simulator )
165 v1 = 12 % CYGNUM_HAL_ISR_COUNT;
166 else /* NOTE TRAILING ELSE... */
168 v1 = CYGNUM_HAL_ISR_MIN + ( 6 % CYGNUM_HAL_ISR_COUNT);
173 // Make sure the chosen levels are not already in use.
174 HAL_INTERRUPT_IN_USE( lvl1, in_use );
177 cyg_interrupt_create(lvl1, PRIO_B, (cyg_addrword_t)777,
178 isr0, dsr0, &intr0, &intr_obj[0]);
180 HAL_INTERRUPT_IN_USE( lvl2, in_use );
182 if (!in_use && lvl1 != lvl2)
183 cyg_interrupt_create(lvl2, PRIO_C, 888,
184 isr1, dsr1, &intr1, &intr_obj[1]);
186 // Check these functions at least exist
188 cyg_interrupt_disable();
189 cyg_interrupt_enable();
192 cyg_interrupt_attach(intr0);
194 cyg_interrupt_attach(intr1);
196 cyg_interrupt_detach(intr0);
198 cyg_interrupt_detach(intr1);
200 // If this attaching interrupt replaces the previous interrupt
201 // instead of adding to it we could be in a big mess if the
202 // vector is being used by something important.
204 cyg_interrupt_get_vsr( v, &old_vsr );
205 cyg_interrupt_set_vsr( v, vsr0 );
206 cyg_interrupt_get_vsr( v, &new_vsr );
207 CHECK( vsr0 == new_vsr );
210 cyg_interrupt_get_vsr( v, &new_vsr );
211 cyg_interrupt_set_vsr( v, old_vsr );
212 CHECK( new_vsr == vsr0 );
214 cyg_interrupt_set_vsr( v, new_vsr );
216 cyg_interrupt_get_vsr( v, &new_vsr );
217 CHECK( vsr0 == new_vsr );
219 cyg_interrupt_set_vsr( v, old_vsr );
220 CHECK( vsr0 == new_vsr );
222 cyg_interrupt_get_vsr( v, &new_vsr );
223 CHECK( old_vsr == new_vsr );
225 CHECK( NULL != vsr0 );
227 cyg_interrupt_mask(v1);
228 cyg_interrupt_unmask(v1);
230 cyg_interrupt_configure(v1, true, true);
232 CYG_TEST_PASS_FINISH("Kernel C API Intr 0 OK");
241 #else /* def CYGFUN_KERNEL_API_C */
246 CYG_TEST_NA("Kernel C API layer disabled");
248 #endif /* def CYGFUN_KERNEL_API_C */