]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/kernel/v2_0/tests/intr0.cxx
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / kernel / v2_0 / tests / intr0.cxx
1 //=================================================================
2 //
3 //        intr0.cxx
4 //
5 //        Interrupt 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 Red Hat, 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 version.
16 //
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
20 // for more details.
21 //
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.
25 //
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.
32 //
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.
35 //
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####
42 //
43 // Author(s):     dsm
44 // Contributors:  dsm, jlarmour
45 // Date:          1999-02-16
46 // Description:   Very basic test of interrupt objects
47 // Options:
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####
53
54 #include <pkgconf/kernel.h>
55
56 #include <cyg/kernel/intr.hxx>
57 #include <cyg/hal/hal_intr.h>
58
59 #include <cyg/infra/testcase.h>
60
61 #include "testaux.hxx"
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_ISR isr0, isr1;
82 static cyg_DSR dsr0, dsr1;
83
84 static char intr0_obj[sizeof(Cyg_Interrupt)];
85 static char intr1_obj[sizeof(Cyg_Interrupt)];
86
87 static cyg_uint32 isr0(cyg_vector vector, CYG_ADDRWORD data)
88 {
89     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
90
91     Cyg_Interrupt::acknowledge_interrupt(vector);
92     return 0;
93 }
94
95 static void dsr0(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
96 {
97     CYG_UNUSED_PARAM(cyg_vector, vector);
98     CYG_UNUSED_PARAM(cyg_ucount32, count);
99     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
100 }
101
102 static cyg_uint32 isr1(cyg_vector vector, CYG_ADDRWORD data)
103 {
104     CYG_UNUSED_PARAM(cyg_vector, vector);
105     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
106     return 0;
107 }
108
109 static void dsr1(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
110 {
111     CYG_UNUSED_PARAM(cyg_vector, vector);
112     CYG_UNUSED_PARAM(cyg_ucount32, count);
113     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
114 }
115
116 static bool flash( void )
117 {
118     Cyg_Interrupt intr0 = Cyg_Interrupt(CYGNUM_HAL_ISR_MIN, PRIO_A,
119                                         (CYG_ADDRWORD)333, isr0, dsr0 );
120
121     return true;
122 }
123
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.
129  * 
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
134  * freeze.
135  */
136
137 static cyg_VSR vsr0;
138
139 static void vsr0()
140 {
141 }
142
143 void intr0_main( void )
144 {
145     CYG_TEST_INIT();
146
147     CHECK(flash());
148     CHECK(flash());
149
150     // Make sure the chosen levels are not already in use.
151     int 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;
155     if (!in_use)
156         intr0 = new((void *)&intr0_obj[0]) Cyg_Interrupt( lvl1, PRIO_B, (CYG_ADDRWORD)777, isr0, dsr0 );
157      
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 );
163
164     // Check these functions at least exist
165     Cyg_Interrupt::disable_interrupts();
166     Cyg_Interrupt::enable_interrupts();
167
168     if (intr0)
169         intr0->attach();
170     if (intr1)
171         intr1->attach();
172     if (intr0)
173         intr0->detach();
174     if (intr1)
175         intr1->detach();
176
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.
180         
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 );
186
187     new_vsr = NULL;
188     Cyg_Interrupt::set_vsr( v, old_vsr, &new_vsr );
189     CHECK( new_vsr == vsr0 );
190
191     Cyg_Interrupt::set_vsr( v, new_vsr );
192     new_vsr = NULL;
193     Cyg_Interrupt::get_vsr( v, &new_vsr );      
194     CHECK( vsr0 == new_vsr );
195
196     Cyg_Interrupt::set_vsr( v, old_vsr );
197     CHECK( vsr0 == new_vsr );
198     new_vsr = NULL;
199     Cyg_Interrupt::get_vsr( v, &new_vsr );
200     CHECK( old_vsr == new_vsr );
201         
202     CHECK( NULL != vsr0 );
203
204     cyg_vector v1;
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... */
210 #endif
211     v1 = CYGNUM_HAL_ISR_MIN + (6 % CYGNUM_HAL_ISR_COUNT);
212
213     Cyg_Interrupt::mask_interrupt(v1);
214     Cyg_Interrupt::unmask_interrupt(v1);
215
216     Cyg_Interrupt::configure_interrupt(v1, true, true);
217
218     CYG_TEST_PASS_FINISH("Intr 0 OK");
219 }
220
221 externC void
222 cyg_start( void )
223 {
224 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
225     cyg_hal_invoke_constructors();
226 #endif
227     intr0_main();
228 }
229 // EOF intr0.cxx