1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* Init |
---|
4 | * |
---|
5 | * This routine is the initialization task for this test program. |
---|
6 | * It is called from init_exec and has the responsibility for creating |
---|
7 | * and starting the tasks that make up the test. If the time of day |
---|
8 | * clock is required for the test, it should also be set to a known |
---|
9 | * value by this function. |
---|
10 | * |
---|
11 | * Input parameters: NONE |
---|
12 | * |
---|
13 | * Output parameters: NONE |
---|
14 | * |
---|
15 | * COPYRIGHT (c) 1989-1999. |
---|
16 | * On-Line Applications Research Corporation (OAR). |
---|
17 | * |
---|
18 | * Redistribution and use in source and binary forms, with or without |
---|
19 | * modification, are permitted provided that the following conditions |
---|
20 | * are met: |
---|
21 | * 1. Redistributions of source code must retain the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer. |
---|
23 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
24 | * notice, this list of conditions and the following disclaimer in the |
---|
25 | * documentation and/or other materials provided with the distribution. |
---|
26 | * |
---|
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
31 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
37 | * POSSIBILITY OF SUCH DAMAGE. |
---|
38 | * |
---|
39 | * OAR init.c Template modified by T. Straumann who provided |
---|
40 | * the implementation of this application. |
---|
41 | */ |
---|
42 | |
---|
43 | #define CONFIGURE_INIT |
---|
44 | |
---|
45 | #include <rtems.h> |
---|
46 | |
---|
47 | /* functions */ |
---|
48 | rtems_task Init( |
---|
49 | rtems_task_argument argument |
---|
50 | ); |
---|
51 | |
---|
52 | /* configuration information */ |
---|
53 | #include <bsp.h> /* for device driver prototypes */ |
---|
54 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
55 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
56 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
57 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
58 | #include <confdefs.h> |
---|
59 | |
---|
60 | #include <stdio.h> |
---|
61 | #include <stdlib.h> |
---|
62 | |
---|
63 | #include <bsp/irq.h> |
---|
64 | #include <rtems/bspIo.h> |
---|
65 | |
---|
66 | |
---|
67 | void noop(){} |
---|
68 | int connected() {return 1;} |
---|
69 | |
---|
70 | rtems_irq_connect_data blah = { 0, 0, noop, noop, connected }; |
---|
71 | extern void discovery_pic_set_debug_irq(); |
---|
72 | |
---|
73 | #define WIRE_IRQ (BSP_IRQ_GPP_0 + 6) |
---|
74 | #define ABRT_IRQ (BSP_IRQ_GPP_0 + 2) |
---|
75 | |
---|
76 | static volatile int testno=0; |
---|
77 | static volatile int wloops =0; |
---|
78 | static volatile int aloops =0; |
---|
79 | |
---|
80 | void wire_hdl() |
---|
81 | { |
---|
82 | if ( 1 == testno ) { |
---|
83 | BSP_disable_irq_at_pic(WIRE_IRQ); |
---|
84 | } |
---|
85 | |
---|
86 | if ( 2 == testno || 3 == testno ) { |
---|
87 | discovery_pic_set_debug_irq(0); |
---|
88 | printk("WIRE -- this message should be printed %s\n", 3==testno ? "FIRST":"SECOND"); |
---|
89 | } else { |
---|
90 | } |
---|
91 | |
---|
92 | /* assume the driver checks for less than 1000 loops */ |
---|
93 | if ( ++wloops > 1000) { |
---|
94 | printk("wire IRQ. FAILURE -- driver couldn't catch runaway ISR. Disabling IRQ source.\n"); |
---|
95 | discovery_pic_set_debug_irq(0); |
---|
96 | BSP_disable_irq_at_pic(WIRE_IRQ); |
---|
97 | } |
---|
98 | /* |
---|
99 | */ |
---|
100 | } |
---|
101 | |
---|
102 | void abrt_hdl() |
---|
103 | { |
---|
104 | aloops++; |
---|
105 | if ( 2 == testno || 3 == testno ) { |
---|
106 | discovery_pic_set_debug_irq(1); |
---|
107 | printk("ABRT -- this message should be printed %s\n", 2==testno ? "FIRST":"SECOND"); |
---|
108 | } else |
---|
109 | printk("ABRT IRQ\n"); |
---|
110 | |
---|
111 | if ( 1== testno ) { |
---|
112 | BSP_enable_irq_at_pic(WIRE_IRQ); |
---|
113 | } |
---|
114 | BSP_disable_irq_at_pic(ABRT_IRQ); |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | rtems_task Init( |
---|
119 | rtems_task_argument ignored |
---|
120 | ) |
---|
121 | { |
---|
122 | blah.name = WIRE_IRQ; |
---|
123 | blah.hdl = wire_hdl; |
---|
124 | if (!BSP_install_rtems_irq_handler(&blah)) { |
---|
125 | fprintf(stderr,"installing handler 1 failed\n"); |
---|
126 | } |
---|
127 | blah.name = ABRT_IRQ; |
---|
128 | blah.hdl = abrt_hdl; |
---|
129 | if (!BSP_install_rtems_irq_handler(&blah)) { |
---|
130 | fprintf(stderr,"installing handler 2 failed\n"); |
---|
131 | } |
---|
132 | printf("Hello, testing the ISR dispatcher...\n"); |
---|
133 | printf(" 1. Trying to catch runaway interrupt\n"); |
---|
134 | printf(" If the system freezes, the test failed!\n"); |
---|
135 | fflush(stdout); sleep(1); |
---|
136 | aloops = wloops = 0; |
---|
137 | discovery_pic_set_debug_irq(1); |
---|
138 | printf(" >>> %s\n", wloops<1000 ? "SUCCESS" : "FAILED"); |
---|
139 | discovery_pic_set_debug_irq(0); |
---|
140 | |
---|
141 | testno++; |
---|
142 | printf(" 2. Testing enabling / disabling interrupt from ISR\n"); |
---|
143 | printf(" Hit the ABORT key for this test\n"); |
---|
144 | fflush(stdout); sleep(1); |
---|
145 | aloops = wloops = 0; |
---|
146 | BSP_disable_irq_at_pic(WIRE_IRQ); |
---|
147 | BSP_irq_set_priority(ABRT_IRQ,1); |
---|
148 | BSP_enable_irq_at_pic(ABRT_IRQ); |
---|
149 | discovery_pic_set_debug_irq(1); |
---|
150 | while (!aloops) |
---|
151 | ; |
---|
152 | discovery_pic_set_debug_irq(0); |
---|
153 | sleep(2); |
---|
154 | printf(" >>> disabling ABRT IRQ from isr %s\n", 1==aloops ? "SUCCESS":"FAILURE"); |
---|
155 | printf(" flashing WIRE IRQ from isr %s\n", 1==wloops ? "SUCCESS":"FAILURE"); |
---|
156 | |
---|
157 | |
---|
158 | testno++; |
---|
159 | printf(" 3. Testing interrupt priorities\n"); |
---|
160 | BSP_irq_set_priority(ABRT_IRQ,2); |
---|
161 | BSP_irq_set_priority(WIRE_IRQ,2); |
---|
162 | BSP_enable_irq_at_pic(ABRT_IRQ); |
---|
163 | BSP_enable_irq_at_pic(WIRE_IRQ); |
---|
164 | printf(" Hit the ABORT key for this test\n"); |
---|
165 | fflush(stdout); sleep(1); |
---|
166 | aloops = wloops = 0; |
---|
167 | while (!aloops) |
---|
168 | ; |
---|
169 | sleep(2); |
---|
170 | testno++; |
---|
171 | printf(" Now we are raising the priority of the wire interrupt\n"); |
---|
172 | BSP_irq_set_priority(WIRE_IRQ,3); |
---|
173 | BSP_enable_irq_at_pic(ABRT_IRQ); |
---|
174 | printf(" Hit the ABORT key for this test\n"); |
---|
175 | fflush(stdout); sleep(1); |
---|
176 | aloops = wloops = 0; |
---|
177 | while (!aloops) |
---|
178 | ; |
---|
179 | |
---|
180 | sleep(2); |
---|
181 | printf( "That's it; we're done...\n" ); |
---|
182 | exit( 0 ); |
---|
183 | } |
---|