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 // CYGNUM_KERNEL_INTERRUPTS_DSRS_TABLE_SIZE
50 // CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
51 // CYGSEM_KERNEL_INTERRUPTS_DSRS_LIST_FIFO
52 //####DESCRIPTIONEND####
54 #include <pkgconf/kernel.h>
56 #include <cyg/kernel/intr.hxx>
57 #include <cyg/hal/hal_intr.h>
59 #include <cyg/infra/testcase.h>
61 #include "testaux.hxx"
63 #ifdef HAL_INTR_TEST_PRIO_A
64 # define PRIO_A HAL_INTR_TEST_PRIO_A
69 #ifdef HAL_INTR_TEST_PRIO_B
70 # define PRIO_B HAL_INTR_TEST_PRIO_B
75 #ifdef HAL_INTR_TEST_PRIO_C
76 # define PRIO_C HAL_INTR_TEST_PRIO_C
81 static cyg_ISR isr0, isr1;
82 static cyg_DSR dsr0, dsr1;
84 static char intr0_obj[sizeof(Cyg_Interrupt)];
85 static char intr1_obj[sizeof(Cyg_Interrupt)];
87 static cyg_uint32 isr0(cyg_vector vector, CYG_ADDRWORD data)
89 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
91 Cyg_Interrupt::acknowledge_interrupt(vector);
95 static void dsr0(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
97 CYG_UNUSED_PARAM(cyg_vector, vector);
98 CYG_UNUSED_PARAM(cyg_ucount32, count);
99 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
102 static cyg_uint32 isr1(cyg_vector vector, CYG_ADDRWORD data)
104 CYG_UNUSED_PARAM(cyg_vector, vector);
105 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
109 static void dsr1(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
111 CYG_UNUSED_PARAM(cyg_vector, vector);
112 CYG_UNUSED_PARAM(cyg_ucount32, count);
113 CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
116 static bool flash( void )
118 Cyg_Interrupt intr0 = Cyg_Interrupt(CYGNUM_HAL_ISR_MIN, PRIO_A,
119 (CYG_ADDRWORD)333, isr0, dsr0 );
124 /* IMPORTANT: The calling convention for VSRs is target dependent. It is
125 * unlikely that a plain C or C++ routine would function correctly on any
126 * particular platform, even if it could correctly access the system
127 * resources necessary to handle the event that caused it to be called.
128 * VSRs usually must be written in assembly language.
130 * This is just a test program. The routine vsr0() below is defined simply
131 * to define an address that will be in executable memory. If an event
132 * causes this VSR to be called, all bets are off. If it is accidentally
133 * installed in the vector for the realtime clock, the system will likely
143 void intr0_main( void )
150 // Make sure the chosen levels are not already in use.
152 cyg_vector lvl1 = CYGNUM_HAL_ISR_MIN + (1 % CYGNUM_HAL_ISR_COUNT);
153 HAL_INTERRUPT_IN_USE( lvl1, in_use );
154 Cyg_Interrupt* intr0 = NULL;
156 intr0 = new((void *)&intr0_obj[0]) Cyg_Interrupt( lvl1, PRIO_B, (CYG_ADDRWORD)777, isr0, dsr0 );
158 cyg_vector lvl2 = CYGNUM_HAL_ISR_MIN + ( 15 % CYGNUM_HAL_ISR_COUNT);
159 HAL_INTERRUPT_IN_USE( lvl2, in_use );
160 Cyg_Interrupt* intr1 = NULL;
161 if (!in_use && lvl1 != lvl2)
162 intr1 = new((void *)&intr1_obj[0]) Cyg_Interrupt( lvl2, PRIO_C, 888, isr1, dsr1 );
164 // Check these functions at least exist
165 Cyg_Interrupt::disable_interrupts();
166 Cyg_Interrupt::enable_interrupts();
177 // If this attaching interrupt replaces the previous interrupt
178 // instead of adding to it we could be in a big mess if the
179 // vector is being used by something important.
181 cyg_vector v = (CYGNUM_HAL_VSR_MIN + 11) % CYGNUM_HAL_VSR_COUNT;
182 cyg_VSR *old_vsr, *new_vsr;
183 Cyg_Interrupt::set_vsr( v, vsr0, &old_vsr );
184 Cyg_Interrupt::get_vsr( v, &new_vsr );
185 CHECK( vsr0 == new_vsr );
188 Cyg_Interrupt::set_vsr( v, old_vsr, &new_vsr );
189 CHECK( new_vsr == vsr0 );
191 Cyg_Interrupt::set_vsr( v, new_vsr );
193 Cyg_Interrupt::get_vsr( v, &new_vsr );
194 CHECK( vsr0 == new_vsr );
196 Cyg_Interrupt::set_vsr( v, old_vsr );
197 CHECK( vsr0 == new_vsr );
199 Cyg_Interrupt::get_vsr( v, &new_vsr );
200 CHECK( old_vsr == new_vsr );
202 CHECK( NULL != vsr0 );
205 #ifdef CYGPKG_HAL_MIPS_TX39
206 // This can be removed when PR 17831 is fixed
207 if ( cyg_test_is_simulator )
208 v1 = 12 % CYGNUM_HAL_ISR_COUNT;
209 else /* NOTE TRAILING ELSE... */
211 v1 = CYGNUM_HAL_ISR_MIN + (6 % CYGNUM_HAL_ISR_COUNT);
213 Cyg_Interrupt::mask_interrupt(v1);
214 Cyg_Interrupt::unmask_interrupt(v1);
216 Cyg_Interrupt::configure_interrupt(v1, true, true);
218 CYG_TEST_PASS_FINISH("Intr 0 OK");
224 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
225 cyg_hal_invoke_constructors();