1 //=================================================================
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_SIZE
50 // CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
51 //####DESCRIPTIONEND####
53 #include <pkgconf/kernel.h>
55 #include <cyg/kernel/intr.hxx>
56 #include <cyg/hal/hal_intr.h>
58 #include <cyg/infra/testcase.h>
60 #include "testaux.hxx"
62 static cyg_ISR isr0, isr1;
63 static cyg_DSR dsr0, dsr1;
65 static char intr0_obj[sizeof(Cyg_Interrupt)];
66 static char intr1_obj[sizeof(Cyg_Interrupt)];
68 static cyg_uint32 isr0(cyg_vector vector, CYG_ADDRWORD data)
70 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
72 Cyg_Interrupt::acknowledge_interrupt(vector);
76 static void dsr0(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
78 CYG_UNUSED_PARAM(cyg_vector, vector);
79 CYG_UNUSED_PARAM(cyg_ucount32, count);
80 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
83 static cyg_uint32 isr1(cyg_vector vector, CYG_ADDRWORD data)
85 CYG_UNUSED_PARAM(cyg_vector, vector);
86 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
90 static void dsr1(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
92 CYG_UNUSED_PARAM(cyg_vector, vector);
93 CYG_UNUSED_PARAM(cyg_ucount32, count);
94 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
97 static bool flash( void )
99 Cyg_Interrupt intr0 = Cyg_Interrupt(CYGNUM_HAL_ISR_MIN, 0, (CYG_ADDRWORD)333, isr0, dsr0 );
104 /* IMPORTANT: The calling convention for VSRs is target dependent. It is
105 * unlikely that a plain C or C++ routine would function correctly on any
106 * particular platform, even if it could correctly access the system
107 * resources necessary to handle the event that caused it to be called.
108 * VSRs usually must be written in assembly language.
110 * This is just a test program. The routine vsr0() below is defined simply
111 * to define an address that will be in executable memory. If an event
112 * causes this VSR to be called, all bets are off. If it is accidentally
113 * installed in the vector for the realtime clock, the system will likely
123 void intr0_main( void )
130 // Make sure the chosen levels are not already in use.
132 cyg_vector lvl1 = CYGNUM_HAL_ISR_MIN + (1 % CYGNUM_HAL_ISR_COUNT);
133 HAL_INTERRUPT_IN_USE( lvl1, in_use );
134 Cyg_Interrupt* intr0 = NULL;
136 intr0 = new((void *)&intr0_obj[0]) Cyg_Interrupt( lvl1, 1, (CYG_ADDRWORD)777, isr0, dsr0 );
138 cyg_vector lvl2 = CYGNUM_HAL_ISR_MIN + ( 15 % CYGNUM_HAL_ISR_COUNT);
139 HAL_INTERRUPT_IN_USE( lvl2, in_use );
140 Cyg_Interrupt* intr1 = NULL;
141 if (!in_use && lvl1 != lvl2)
142 intr1 = new((void *)&intr1_obj[0]) Cyg_Interrupt( lvl2, 1, 888, isr1, dsr1 );
144 // Check these functions at least exist
145 Cyg_Interrupt::disable_interrupts();
146 Cyg_Interrupt::enable_interrupts();
157 // If this attaching interrupt replaces the previous interrupt
158 // instead of adding to it we could be in a big mess if the
159 // vector is being used by something important.
161 cyg_vector v = (CYGNUM_HAL_VSR_MIN + 11) % CYGNUM_HAL_VSR_COUNT;
162 cyg_VSR *old_vsr, *new_vsr;
163 Cyg_Interrupt::set_vsr( v, vsr0, &old_vsr );
164 Cyg_Interrupt::get_vsr( v, &new_vsr );
165 CHECK( vsr0 == new_vsr );
168 Cyg_Interrupt::set_vsr( v, old_vsr, &new_vsr );
169 CHECK( new_vsr == vsr0 );
171 Cyg_Interrupt::set_vsr( v, new_vsr );
173 Cyg_Interrupt::get_vsr( v, &new_vsr );
174 CHECK( vsr0 == new_vsr );
176 Cyg_Interrupt::set_vsr( v, old_vsr );
177 CHECK( vsr0 == new_vsr );
179 Cyg_Interrupt::get_vsr( v, &new_vsr );
180 CHECK( old_vsr == new_vsr );
182 CHECK( NULL != vsr0 );
185 #ifdef CYGPKG_HAL_MIPS_TX39
186 // This can be removed when PR 17831 is fixed
187 if ( cyg_test_is_simulator )
188 v1 = 12 % CYGNUM_HAL_ISR_COUNT;
189 else /* NOTE TRAILING ELSE... */
191 v1 = CYGNUM_HAL_ISR_MIN + (6 % CYGNUM_HAL_ISR_COUNT);
193 Cyg_Interrupt::mask_interrupt(v1);
194 Cyg_Interrupt::unmask_interrupt(v1);
196 Cyg_Interrupt::configure_interrupt(v1, true, true);
198 CYG_TEST_PASS_FINISH("Intr 0 OK");
204 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
205 cyg_hal_invoke_constructors();