OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [kintr0.c] - Blame information for rev 530

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.