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 // CYGIMP_KERNEL_INTERRUPTS_DSRS_TABLE_MAX
50 // CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
51 //####DESCRIPTIONEND####
54 #include <cyg/kernel/kapi.h>
55 #include <cyg/hal/hal_intr.h>
57 #include <cyg/infra/testcase.h>
59 #ifdef CYGFUN_KERNEL_API_C
63 static cyg_interrupt intr_obj[2];
65 static cyg_handle_t intr0, intr1;
68 static cyg_ISR_t isr0, isr1;
69 static cyg_DSR_t dsr0, dsr1;
71 static cyg_uint32 isr0(cyg_vector_t vector, cyg_addrword_t data)
73 CYG_UNUSED_PARAM(cyg_addrword_t, data);
75 cyg_interrupt_acknowledge(vector);
79 static void dsr0(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
81 CYG_UNUSED_PARAM(cyg_vector_t, vector);
82 CYG_UNUSED_PARAM(cyg_ucount32, count);
83 CYG_UNUSED_PARAM(cyg_addrword_t, data);
86 static cyg_uint32 isr1(cyg_vector_t vector, cyg_addrword_t data)
88 CYG_UNUSED_PARAM(cyg_vector_t, vector);
89 CYG_UNUSED_PARAM(cyg_addrword_t, data);
93 static void dsr1(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
95 CYG_UNUSED_PARAM(cyg_vector_t, vector);
96 CYG_UNUSED_PARAM(cyg_ucount32, count);
97 CYG_UNUSED_PARAM(cyg_addrword_t, data);
100 static bool flash( void )
105 cyg_interrupt_create(CYGNUM_HAL_ISR_MIN, 0, (cyg_addrword_t)333,
106 isr0, dsr0, &handle, &intr );
107 cyg_interrupt_delete(handle);
112 /* IMPORTANT: The calling convention for VSRs is target dependent. It is
113 * unlikely that a plain C or C++ routine would function correctly on any
114 * particular platform, even if it could correctly access the system
115 * resources necessary to handle the event that caused it to be called.
116 * VSRs usually must be written in assembly language.
118 * This is just a test program. The routine vsr0() below is defined simply
119 * to define an address that will be in executable memory. If an event
120 * causes this VSR to be called, all bets are off. If it is accidentally
121 * installed in the vector for the realtime clock, the system will likely
125 static cyg_VSR_t vsr0;
131 void kintr0_main( void )
133 cyg_vector_t v = (CYGNUM_HAL_VSR_MIN + 11) % CYGNUM_HAL_VSR_COUNT;
135 cyg_vector_t lvl1 = CYGNUM_HAL_ISR_MIN + (1 % CYGNUM_HAL_ISR_COUNT);
136 cyg_vector_t lvl2 = CYGNUM_HAL_ISR_MIN + (15 % CYGNUM_HAL_ISR_COUNT);
139 cyg_VSR_t *old_vsr, *new_vsr;
143 #ifdef CYGPKG_HAL_MIPS_TX39
144 // This can be removed when PR 17831 is fixed
145 if ( cyg_test_is_simulator )
146 v1 = 12 % CYGNUM_HAL_ISR_COUNT;
147 else /* NOTE TRAILING ELSE... */
149 v1 = CYGNUM_HAL_ISR_MIN + ( 6 % CYGNUM_HAL_ISR_COUNT);
154 // Make sure the chosen levels are not already in use.
155 HAL_INTERRUPT_IN_USE( lvl1, in_use );
158 cyg_interrupt_create(lvl1, 1, (cyg_addrword_t)777, isr0, dsr0,
159 &intr0, &intr_obj[0]);
161 HAL_INTERRUPT_IN_USE( lvl2, in_use );
163 if (!in_use && lvl1 != lvl2)
164 cyg_interrupt_create(lvl2, 1, 888, isr1, dsr1, &intr1, &intr_obj[1]);
166 // Check these functions at least exist
168 cyg_interrupt_disable();
169 cyg_interrupt_enable();
172 cyg_interrupt_attach(intr0);
174 cyg_interrupt_attach(intr1);
176 cyg_interrupt_detach(intr0);
178 cyg_interrupt_detach(intr1);
180 // If this attaching interrupt replaces the previous interrupt
181 // instead of adding to it we could be in a big mess if the
182 // vector is being used by something important.
184 cyg_interrupt_get_vsr( v, &old_vsr );
185 cyg_interrupt_set_vsr( v, vsr0 );
186 cyg_interrupt_get_vsr( v, &new_vsr );
187 CHECK( vsr0 == new_vsr );
190 cyg_interrupt_get_vsr( v, &new_vsr );
191 cyg_interrupt_set_vsr( v, old_vsr );
192 CHECK( new_vsr == vsr0 );
194 cyg_interrupt_set_vsr( v, new_vsr );
196 cyg_interrupt_get_vsr( v, &new_vsr );
197 CHECK( vsr0 == new_vsr );
199 cyg_interrupt_set_vsr( v, old_vsr );
200 CHECK( vsr0 == new_vsr );
202 cyg_interrupt_get_vsr( v, &new_vsr );
203 CHECK( old_vsr == new_vsr );
205 CHECK( NULL != vsr0 );
207 cyg_interrupt_mask(v1);
208 cyg_interrupt_unmask(v1);
210 cyg_interrupt_configure(v1, true, true);
212 CYG_TEST_PASS_FINISH("Kernel C API Intr 0 OK");
221 #else /* def CYGFUN_KERNEL_API_C */
226 CYG_TEST_NA("Kernel C API layer disabled");
228 #endif /* def CYGFUN_KERNEL_API_C */