]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/kernel/v2_0/tests/kintr0.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / kernel / v2_0 / tests / kintr0.c
1 /*=================================================================
2 //
3 //        kintr0.c
4 //
5 //        Kernel C API Intr 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
55 #include <cyg/kernel/kapi.h>
56 #include <cyg/hal/hal_intr.h>
57
58 #include <cyg/infra/testcase.h>
59
60 #ifdef CYGFUN_KERNEL_API_C
61
62 #include "testaux.h"
63
64 #ifdef HAL_INTR_TEST_PRIO_A
65 # define PRIO_A HAL_INTR_TEST_PRIO_A
66 #else
67 # define PRIO_A 0
68 #endif
69
70 #ifdef HAL_INTR_TEST_PRIO_B
71 # define PRIO_B HAL_INTR_TEST_PRIO_B
72 #else
73 # define PRIO_B 1
74 #endif
75
76 #ifdef HAL_INTR_TEST_PRIO_C
77 # define PRIO_C HAL_INTR_TEST_PRIO_C
78 #else
79 # define PRIO_C 1
80 #endif
81
82 static cyg_interrupt intr_obj[2];
83
84 static cyg_handle_t intr0, intr1;
85
86
87 static cyg_ISR_t isr0, isr1;
88 static cyg_DSR_t dsr0, dsr1;
89
90 static cyg_uint32 isr0(cyg_vector_t vector, cyg_addrword_t data)
91 {
92     CYG_UNUSED_PARAM(cyg_addrword_t, data);
93
94     cyg_interrupt_acknowledge(vector);
95     return 0;
96 }
97
98 static void dsr0(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
99 {
100     CYG_UNUSED_PARAM(cyg_vector_t, vector);
101     CYG_UNUSED_PARAM(cyg_ucount32, count);
102     CYG_UNUSED_PARAM(cyg_addrword_t, data);
103 }
104
105 static cyg_uint32 isr1(cyg_vector_t vector, cyg_addrword_t data)
106 {
107     CYG_UNUSED_PARAM(cyg_vector_t, vector);
108     CYG_UNUSED_PARAM(cyg_addrword_t, data);
109     return 0;
110 }
111
112 static void dsr1(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
113 {
114     CYG_UNUSED_PARAM(cyg_vector_t, vector);
115     CYG_UNUSED_PARAM(cyg_ucount32, count);
116     CYG_UNUSED_PARAM(cyg_addrword_t, data);
117 }
118
119 static bool flash( void )
120 {
121     cyg_handle_t handle;
122     cyg_interrupt intr;
123
124     cyg_interrupt_create(CYGNUM_HAL_ISR_MIN, PRIO_A, (cyg_addrword_t)333,
125                          isr0, dsr0, &handle, &intr );
126     cyg_interrupt_delete(handle);
127
128     return true;
129 }
130
131 /* IMPORTANT: The calling convention for VSRs is target dependent.  It is
132  * unlikely that a plain C or C++ routine would function correctly on any
133  * particular platform, even if it could correctly access the system
134  * resources necessary to handle the event that caused it to be called.
135  * VSRs usually must be written in assembly language.
136  * 
137  * This is just a test program.  The routine vsr0() below is defined simply
138  * to define an address that will be in executable memory.  If an event
139  * causes this VSR to be called, all bets are off.  If it is accidentally
140  * installed in the vector for the realtime clock, the system will likely
141  * freeze.
142  */
143
144 static cyg_VSR_t vsr0;
145
146 static void vsr0()
147 {
148 }
149
150 void kintr0_main( void )
151 {
152     cyg_vector_t v = (CYGNUM_HAL_VSR_MIN + 11) % CYGNUM_HAL_VSR_COUNT;
153     cyg_vector_t v1;
154     cyg_vector_t lvl1 = CYGNUM_HAL_ISR_MIN + (1 % CYGNUM_HAL_ISR_COUNT);
155     cyg_vector_t lvl2 = CYGNUM_HAL_ISR_MIN + (15 % CYGNUM_HAL_ISR_COUNT);
156     int in_use;
157
158     cyg_VSR_t *old_vsr, *new_vsr;
159
160     CYG_TEST_INIT();
161  
162 #ifdef CYGPKG_HAL_MIPS_TX39    
163     // This can be removed when PR 17831 is fixed
164     if ( cyg_test_is_simulator )
165         v1 = 12 % CYGNUM_HAL_ISR_COUNT;
166     else /* NOTE TRAILING ELSE... */
167 #endif
168     v1 = CYGNUM_HAL_ISR_MIN + ( 6 % CYGNUM_HAL_ISR_COUNT);
169
170     CHECK(flash());
171     CHECK(flash());
172
173     // Make sure the chosen levels are not already in use.
174     HAL_INTERRUPT_IN_USE( lvl1, in_use );
175     intr0 = 0;
176     if (!in_use)
177         cyg_interrupt_create(lvl1, PRIO_B, (cyg_addrword_t)777,
178                              isr0, dsr0, &intr0, &intr_obj[0]);
179     
180     HAL_INTERRUPT_IN_USE( lvl2, in_use );
181     intr1 = 0;
182     if (!in_use && lvl1 != lvl2)
183         cyg_interrupt_create(lvl2, PRIO_C, 888,
184                              isr1, dsr1, &intr1, &intr_obj[1]);
185
186     // Check these functions at least exist
187
188     cyg_interrupt_disable();
189     cyg_interrupt_enable();
190
191     if (intr0)
192         cyg_interrupt_attach(intr0);
193     if (intr1)
194         cyg_interrupt_attach(intr1);
195     if (intr0)
196         cyg_interrupt_detach(intr0);
197     if (intr1)
198         cyg_interrupt_detach(intr1);
199
200     // If this attaching interrupt replaces the previous interrupt
201     // instead of adding to it we could be in a big mess if the
202     // vector is being used by something important.
203         
204     cyg_interrupt_get_vsr( v, &old_vsr );
205     cyg_interrupt_set_vsr( v, vsr0 );
206     cyg_interrupt_get_vsr( v, &new_vsr );
207     CHECK( vsr0 == new_vsr );
208
209     new_vsr = NULL;
210     cyg_interrupt_get_vsr( v, &new_vsr );
211     cyg_interrupt_set_vsr( v, old_vsr );
212     CHECK( new_vsr == vsr0 );
213
214     cyg_interrupt_set_vsr( v, new_vsr );
215     new_vsr = NULL;
216     cyg_interrupt_get_vsr( v, &new_vsr );       
217     CHECK( vsr0 == new_vsr );
218
219     cyg_interrupt_set_vsr( v, old_vsr );
220     CHECK( vsr0 == new_vsr );
221     new_vsr = NULL;
222     cyg_interrupt_get_vsr( v, &new_vsr );
223     CHECK( old_vsr == new_vsr );
224         
225     CHECK( NULL != vsr0 );
226
227     cyg_interrupt_mask(v1);
228     cyg_interrupt_unmask(v1);
229         
230     cyg_interrupt_configure(v1, true, true);
231
232     CYG_TEST_PASS_FINISH("Kernel C API Intr 0 OK");
233 }
234
235 externC void
236 cyg_start( void )
237
238     kintr0_main();
239 }
240
241 #else /* def CYGFUN_KERNEL_API_C */
242 externC void
243 cyg_start( void )
244 {
245     CYG_TEST_INIT();
246     CYG_TEST_NA("Kernel C API layer disabled");
247 }
248 #endif /* def CYGFUN_KERNEL_API_C */
249
250 /* EOF kintr0.c */