]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/kernel/v2_0/tests/intr0.cxx
f2be469e3b13a4f60a47ee6302331d351d7ad5cc
[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 //     CYGIMP_KERNEL_INTERRUPTS_DSRS_TABLE_SIZE
50 //     CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
51 //####DESCRIPTIONEND####
52
53 #include <pkgconf/kernel.h>
54
55 #include <cyg/kernel/intr.hxx>
56 #include <cyg/hal/hal_intr.h>
57
58 #include <cyg/infra/testcase.h>
59
60 #include "testaux.hxx"
61
62 static cyg_ISR isr0, isr1;
63 static cyg_DSR dsr0, dsr1;
64
65 static char intr0_obj[sizeof(Cyg_Interrupt)];
66 static char intr1_obj[sizeof(Cyg_Interrupt)];
67
68 static cyg_uint32 isr0(cyg_vector vector, CYG_ADDRWORD data)
69 {
70     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
71
72     Cyg_Interrupt::acknowledge_interrupt(vector);
73     return 0;
74 }
75
76 static void dsr0(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
77 {
78     CYG_UNUSED_PARAM(cyg_vector, vector);
79     CYG_UNUSED_PARAM(cyg_ucount32, count);
80     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
81 }
82
83 static cyg_uint32 isr1(cyg_vector vector, CYG_ADDRWORD data)
84 {
85     CYG_UNUSED_PARAM(cyg_vector, vector);
86     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
87     return 0;
88 }
89
90 static void dsr1(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
91 {
92     CYG_UNUSED_PARAM(cyg_vector, vector);
93     CYG_UNUSED_PARAM(cyg_ucount32, count);
94     CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
95 }
96
97 static bool flash( void )
98 {
99     Cyg_Interrupt intr0 = Cyg_Interrupt(CYGNUM_HAL_ISR_MIN, 0, (CYG_ADDRWORD)333, isr0, dsr0 );
100
101     return true;
102 }
103
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.
109  * 
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
114  * freeze.
115  */
116
117 static cyg_VSR vsr0;
118
119 static void vsr0()
120 {
121 }
122
123 void intr0_main( void )
124 {
125     CYG_TEST_INIT();
126
127     CHECK(flash());
128     CHECK(flash());
129
130     // Make sure the chosen levels are not already in use.
131     int 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;
135     if (!in_use)
136         intr0 = new((void *)&intr0_obj[0]) Cyg_Interrupt( lvl1, 1, (CYG_ADDRWORD)777, isr0, dsr0 );
137      
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 );
143
144     // Check these functions at least exist
145     Cyg_Interrupt::disable_interrupts();
146     Cyg_Interrupt::enable_interrupts();
147
148     if (intr0)
149         intr0->attach();
150     if (intr1)
151         intr1->attach();
152     if (intr0)
153         intr0->detach();
154     if (intr1)
155         intr1->detach();
156
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.
160         
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 );
166
167     new_vsr = NULL;
168     Cyg_Interrupt::set_vsr( v, old_vsr, &new_vsr );
169     CHECK( new_vsr == vsr0 );
170
171     Cyg_Interrupt::set_vsr( v, new_vsr );
172     new_vsr = NULL;
173     Cyg_Interrupt::get_vsr( v, &new_vsr );      
174     CHECK( vsr0 == new_vsr );
175
176     Cyg_Interrupt::set_vsr( v, old_vsr );
177     CHECK( vsr0 == new_vsr );
178     new_vsr = NULL;
179     Cyg_Interrupt::get_vsr( v, &new_vsr );
180     CHECK( old_vsr == new_vsr );
181         
182     CHECK( NULL != vsr0 );
183
184     cyg_vector v1;
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... */
190 #endif
191     v1 = CYGNUM_HAL_ISR_MIN + (6 % CYGNUM_HAL_ISR_COUNT);
192
193     Cyg_Interrupt::mask_interrupt(v1);
194     Cyg_Interrupt::unmask_interrupt(v1);
195
196     Cyg_Interrupt::configure_interrupt(v1, true, true);
197
198     CYG_TEST_PASS_FINISH("Intr 0 OK");
199 }
200
201 externC void
202 cyg_start( void )
203 {
204 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
205     cyg_hal_invoke_constructors();
206 #endif
207     intr0_main();
208 }
209 // EOF intr0.cxx