]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/sh/arch/v2_0/tests/intr0.c
Initial revision
[karo-tx-redboot.git] / packages / hal / sh / arch / v2_0 / tests / intr0.c
1 //==========================================================================
2 //
3 //        intr0.c
4 //
5 //        Interrupt controls test
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):     jskov
44 // Contributors:  jskov
45 // Date:          2001-01-18
46 //####DESCRIPTIONEND####
47 //==========================================================================
48
49 #include <pkgconf/system.h>
50
51 #include <cyg/infra/testcase.h>
52
53 #if defined(CYGPKG_KERNEL)
54
55 #include <pkgconf/kernel.h>
56
57 #if defined(CYGFUN_KERNEL_API_C)
58
59 #include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
60
61 #include <cyg/kernel/kapi.h>
62
63 #include <cyg/hal/hal_intr.h>
64
65 // -------------------------------------------------------------------------
66
67 #define NTHREADS 1
68 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
69
70 static cyg_handle_t thread[NTHREADS];
71
72 static cyg_thread thread_obj[NTHREADS];
73 static char stack[NTHREADS][STACKSIZE];
74
75 // -------------------------------------------------------------------------
76
77 // This is (tick time * 1.5) 
78 #define TICK_DELAY (1500000 / CYGNUM_HAL_RTC_DENOMINATOR)
79
80 static void
81 entry0( cyg_addrword_t data )
82 {
83     int tick;
84
85     // Scheduler and thus timer interrupts are running by the
86     // time we get here.
87
88     // Wait for next tick
89     tick = cyg_current_time();
90     do {} while (cyg_current_time() == tick);
91     tick = cyg_current_time();
92
93     // Then mask timer interrupts
94     HAL_INTERRUPT_MASK(CYGNUM_HAL_INTERRUPT_RTC);
95
96     // and wait for the time when the next tick should have come
97     // and check it didn't trigger an interrupt
98     hal_delay_us(TICK_DELAY);
99     CYG_TEST_CHECK(cyg_current_time() == tick, "Timer interrupt while masked");
100
101     // Now change interrupt level, and make the check again. Changing
102     // level should not affect interrupt mask state.
103     HAL_INTERRUPT_SET_LEVEL(CYGNUM_HAL_INTERRUPT_RTC, 8);
104     hal_delay_us(TICK_DELAY);
105     CYG_TEST_CHECK(cyg_current_time() == tick, 
106                    "Timer interrupt after changing level");
107
108     // Finally unmask the interrupt and make sure it results in ticks.
109     HAL_INTERRUPT_UNMASK(CYGNUM_HAL_INTERRUPT_RTC);
110     hal_delay_us(TICK_DELAY);
111     CYG_TEST_CHECK(cyg_current_time() != tick, 
112                    "No timer interrupt after unmask");
113
114     CYG_TEST_PASS_FINISH("SH intr0 test end");
115 }
116
117 // -------------------------------------------------------------------------
118
119 externC void
120 cyg_start( void )
121 {
122     CYG_TEST_INIT();
123
124     cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "intr",
125         (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
126     cyg_thread_resume(thread[0]);
127
128     cyg_scheduler_start();
129 }
130
131 // -------------------------------------------------------------------------
132
133 #else // def CYGFUN_KERNEL_API_C
134 #define N_A_MSG "Kernel C API layer disabled"
135 #endif // def CYGFUN_KERNEL_API_C
136 #else // def CYGPKG_KERNEL
137 #define N_A_MSG "Needs kernel"
138 #endif // def CYGPKG_KERNEL
139
140 #ifdef N_A_MSG
141 externC void
142 cyg_start( void )
143 {
144     CYG_TEST_INIT();
145     CYG_TEST_NA( N_A_MSG );
146 }
147 #endif // N_A_MSG
148
149 // -------------------------------------------------------------------------
150 // EOF intr0.c