1 |
27 |
unneback |
//=================================================================
|
2 |
|
|
//
|
3 |
|
|
// intr0.c
|
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): jskov
|
44 |
|
|
// Contributors: jskov, gthomas
|
45 |
|
|
// Date: 1998-12-01
|
46 |
|
|
// Description: Simple test of MPC860 interrupt handling when the
|
47 |
|
|
// kernel has not been configured. Uses timer interrupts.
|
48 |
|
|
// Options:
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
|
51 |
|
|
// #define DEBUG_PRINTFS
|
52 |
|
|
#ifdef DEBUG_PRINTFS
|
53 |
|
|
#include <cyg/infra/diag.h>
|
54 |
|
|
#endif
|
55 |
|
|
|
56 |
|
|
#include <pkgconf/hal.h>
|
57 |
|
|
|
58 |
|
|
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
|
59 |
|
|
#include <cyg/hal/ppc_regs.h>
|
60 |
|
|
|
61 |
|
|
#include <cyg/hal/hal_intr.h>
|
62 |
|
|
|
63 |
|
|
#include <cyg/infra/testcase.h>
|
64 |
|
|
|
65 |
|
|
#ifndef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN
|
66 |
|
|
#ifdef CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE
|
67 |
|
|
|
68 |
|
|
#undef CHECK
|
69 |
|
|
#define CHECK(b) CYG_TEST_CHECK(b,#b)
|
70 |
|
|
|
71 |
|
|
// Can't rely on Cyg_Interrupt class being defined.
|
72 |
|
|
#define Cyg_InterruptHANDLED 1
|
73 |
|
|
|
74 |
|
|
// This is the period between interrupts, measured in decrementer ticks.
|
75 |
|
|
// Period must be longer than the time required for setting up all the
|
76 |
|
|
// interrupt handlers.
|
77 |
|
|
#define PIT_PERIOD 5000
|
78 |
|
|
|
79 |
|
|
#ifdef CYGPKG_HAL_POWERPC_MBX
|
80 |
|
|
#define TB_PERIOD (PIT_PERIOD*384) // PTA period is 15.36 uS
|
81 |
|
|
#else
|
82 |
|
|
// This value is based on the relationship between the PIT clock
|
83 |
|
|
// and the TB clock. This is set in the SCCR register and the
|
84 |
|
|
// default value seems to be that the TB runs 128 times faster
|
85 |
|
|
// than the PIT. Of course, this doesn't match the documentation :-(
|
86 |
|
|
// Also, the basis for this is hardware strappable (set at reset time)
|
87 |
|
|
// so the value chosen below is a guess which works on the 860 platforms
|
88 |
|
|
// we have seen, other than the Motorola MBX860.
|
89 |
|
|
#define TB_PERIOD (PIT_PERIOD*128) // assuming 512/4 divisors
|
90 |
|
|
#endif
|
91 |
|
|
|
92 |
|
|
#define PIT_IRQ_LEVEL 4
|
93 |
|
|
#define PIT_IRQ CYGNUM_HAL_INTERRUPT_SIU_LVL4
|
94 |
|
|
#define TB_IRQ_LEVEL 5
|
95 |
|
|
#define TB_IRQ CYGNUM_HAL_INTERRUPT_SIU_LVL5
|
96 |
|
|
|
97 |
|
|
#define ID_RTC_SEC 12345
|
98 |
|
|
#define ID_RTC_ALR 23451
|
99 |
|
|
#define ID_PIT 34512
|
100 |
|
|
#define ID_TBA 45123
|
101 |
|
|
#define ID_TBB 51234
|
102 |
|
|
|
103 |
|
|
volatile cyg_uint32 count = 0;
|
104 |
|
|
|
105 |
|
|
// Time/PERIOD 0 1 2 3 4 5 6 7 8 9 10
|
106 |
|
|
// Interrupt PIT TBA PIT PIT TBB PIT PIT
|
107 |
|
|
// pit_count 0 0 0 1 1 2 2 3 3 4 4
|
108 |
|
|
// count 0 0 1 3 4 4 5 40 41 42
|
109 |
|
|
|
110 |
|
|
static cyg_uint32 count_verify_table[] = {1, 4, 5, 41, 42};
|
111 |
|
|
static int pit_count = 0;
|
112 |
|
|
|
113 |
|
|
// These are useful for debugging:
|
114 |
|
|
static cyg_uint32 count_actual_table[] = { -1, -1, -1, -1, -1};
|
115 |
|
|
static cyg_uint32 tbr_actual_table[] = { -1, -1, -1, -1, -1};
|
116 |
|
|
|
117 |
|
|
// Periodic timer ISR. Should be executing 5 times.
|
118 |
|
|
static cyg_uint32 isr_pit(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
119 |
|
|
{
|
120 |
|
|
cyg_uint32 verify_value;
|
121 |
|
|
|
122 |
|
|
CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
|
123 |
|
|
|
124 |
|
|
CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_PIT == vector, "Wrong vector!");
|
125 |
|
|
CYG_ASSERT (ID_PIT == data, "Wrong data!");
|
126 |
|
|
|
127 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_PIT);
|
128 |
|
|
|
129 |
|
|
count++;
|
130 |
|
|
|
131 |
|
|
count_actual_table[pit_count] = count;
|
132 |
|
|
{
|
133 |
|
|
cyg_uint32 tbl;
|
134 |
|
|
CYGARC_MFTB (TBL_R, tbl);
|
135 |
|
|
tbr_actual_table[pit_count] = tbl;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
verify_value = count_verify_table[pit_count++];
|
139 |
|
|
|
140 |
|
|
#ifdef DEBUG_PRINTFS
|
141 |
|
|
diag_printf( "ISR_PIT executed %d of 5\n", pit_count );
|
142 |
|
|
#endif
|
143 |
|
|
|
144 |
|
|
CYG_ASSERT (count == verify_value, "Count wrong!");
|
145 |
|
|
|
146 |
|
|
// End of test when count is 42. Mask interrupts and print PASS text.
|
147 |
|
|
if (42 <= count || 5 == pit_count) {
|
148 |
|
|
HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_PIT);
|
149 |
|
|
HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
|
150 |
|
|
HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
|
151 |
|
|
|
152 |
|
|
#ifdef DEBUG_PRINTFS
|
153 |
|
|
diag_printf( "INFO: Actual counts: %d %d %d %d %d\n",
|
154 |
|
|
count_actual_table[0],
|
155 |
|
|
count_actual_table[1],
|
156 |
|
|
count_actual_table[2],
|
157 |
|
|
count_actual_table[3],
|
158 |
|
|
count_actual_table[4] );
|
159 |
|
|
diag_printf( "INFO: Actuals tbrs: %d %d %d %d %d\n",
|
160 |
|
|
tbr_actual_table[0],
|
161 |
|
|
tbr_actual_table[1],
|
162 |
|
|
tbr_actual_table[2],
|
163 |
|
|
tbr_actual_table[3],
|
164 |
|
|
tbr_actual_table[4] );
|
165 |
|
|
#endif
|
166 |
|
|
if (5 == pit_count) {
|
167 |
|
|
#ifndef CYGPKG_HAL_POWERPC_MBX
|
168 |
|
|
if (42 != count) {
|
169 |
|
|
#else
|
170 |
|
|
if ((42 != count) && (49 != count)) {
|
171 |
|
|
#endif
|
172 |
|
|
CYG_TEST_INFO("TB/PIT ratio does not match");
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
#ifndef CYGPKG_HAL_POWERPC_MBX
|
176 |
|
|
if (42 == count && 5 == pit_count)
|
177 |
|
|
#else
|
178 |
|
|
if (((42 == count) || (49 == count)) && (5 == pit_count))
|
179 |
|
|
#endif
|
180 |
|
|
CYG_TEST_PASS_FINISH("Intr 0 OK");
|
181 |
|
|
else
|
182 |
|
|
CYG_TEST_FAIL_FINISH("Intr 0 Failed.");
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
return Cyg_InterruptHANDLED;
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
// TimeBase A ISR. Should be executing once.
|
189 |
|
|
static cyg_uint32 isr_tba(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
190 |
|
|
{
|
191 |
|
|
CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
|
192 |
|
|
|
193 |
|
|
CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_TB_A == vector, "Wrong vector!");
|
194 |
|
|
CYG_ASSERT (ID_TBA == data, "Wrong data!");
|
195 |
|
|
|
196 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
|
197 |
|
|
|
198 |
|
|
count = count * 3;
|
199 |
|
|
|
200 |
|
|
#ifdef DEBUG_PRINTFS
|
201 |
|
|
diag_printf( "ISR_TBA executed, count now %d\n", count );
|
202 |
|
|
#endif
|
203 |
|
|
|
204 |
|
|
return Cyg_InterruptHANDLED;
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
// TimeBase B ISR. Should be executing once.
|
208 |
|
|
static cyg_uint32 isr_tbb(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
209 |
|
|
{
|
210 |
|
|
CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
|
211 |
|
|
|
212 |
|
|
CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_TB_B == vector, "Wrong vector!");
|
213 |
|
|
CYG_ASSERT (ID_TBB == data, "Wrong data!");
|
214 |
|
|
|
215 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
|
216 |
|
|
|
217 |
|
|
count = count * 8;
|
218 |
|
|
|
219 |
|
|
#ifdef DEBUG_PRINTFS
|
220 |
|
|
diag_printf( "ISR_TBB executed, count now %d\n", count );
|
221 |
|
|
#endif
|
222 |
|
|
|
223 |
|
|
return Cyg_InterruptHANDLED;
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
void intr0_main( void )
|
227 |
|
|
{
|
228 |
|
|
#ifndef CYGPKG_HAL_POWERPC_MBX
|
229 |
|
|
unsigned long sccr = *(volatile unsigned long *)CYGARC_REG_IMM_SCCR;
|
230 |
|
|
#endif
|
231 |
|
|
int tb_period = TB_PERIOD;
|
232 |
|
|
CYG_TEST_INIT();
|
233 |
|
|
|
234 |
|
|
#ifndef CYGPKG_HAL_POWERPC_MBX
|
235 |
|
|
#ifdef DEBUG_PRINTFS
|
236 |
|
|
diag_printf("sccr = %x\n", sccr);
|
237 |
|
|
#endif
|
238 |
|
|
if (sccr & 0x01000000) tb_period /= 4;
|
239 |
|
|
#endif
|
240 |
|
|
|
241 |
|
|
#if 0
|
242 |
|
|
// The A.3 revision of the CPU I'm using at the moment generates a
|
243 |
|
|
// machine check exception when writing to IMM_RTCSC. Smells a
|
244 |
|
|
// bit like the "SIU4. Spurious External Bus Transaction Following
|
245 |
|
|
// PLPRCR Write." CPU errata. Have to find out for sure. Run real
|
246 |
|
|
// time clock interrupts on level 0
|
247 |
|
|
{
|
248 |
|
|
// Still to do.
|
249 |
|
|
}
|
250 |
|
|
#endif
|
251 |
|
|
|
252 |
|
|
// Run periodic timer interrupt on level 1
|
253 |
|
|
{
|
254 |
|
|
cyg_uint16 piscr;
|
255 |
|
|
|
256 |
|
|
// Attach pit arbiter.
|
257 |
|
|
HAL_INTERRUPT_ATTACH (PIT_IRQ,
|
258 |
|
|
&hal_arbitration_isr_pit, ID_PIT, 0);
|
259 |
|
|
HAL_INTERRUPT_UNMASK (PIT_IRQ);
|
260 |
|
|
|
261 |
|
|
// Attach pit isr.
|
262 |
|
|
HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_PIT, &isr_pit,
|
263 |
|
|
ID_PIT, 0);
|
264 |
|
|
HAL_INTERRUPT_SET_LEVEL (CYGNUM_HAL_INTERRUPT_SIU_PIT, PIT_IRQ_LEVEL);
|
265 |
|
|
HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_PIT);
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
// Set period.
|
269 |
|
|
HAL_WRITE_UINT32 (CYGARC_REG_IMM_PITC,
|
270 |
|
|
(2*PIT_PERIOD) << CYGARC_REG_IMM_PITC_COUNT_SHIFT);
|
271 |
|
|
|
272 |
|
|
#ifdef DEBUG_PRINTFS
|
273 |
|
|
diag_printf( "PIT set to %d\n", 2*PIT_PERIOD );
|
274 |
|
|
#endif
|
275 |
|
|
// Enable.
|
276 |
|
|
HAL_READ_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
|
277 |
|
|
piscr |= CYGARC_REG_IMM_PISCR_PTE;
|
278 |
|
|
HAL_WRITE_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
|
279 |
|
|
}
|
280 |
|
|
|
281 |
|
|
// Run timebase interrupts on level 2
|
282 |
|
|
{
|
283 |
|
|
cyg_uint16 tbscr;
|
284 |
|
|
cyg_uint32 tbl;
|
285 |
|
|
|
286 |
|
|
// Attach tb arbiter.
|
287 |
|
|
HAL_INTERRUPT_ATTACH (TB_IRQ,
|
288 |
|
|
&hal_arbitration_isr_tb, ID_TBA, 0);
|
289 |
|
|
HAL_INTERRUPT_UNMASK (TB_IRQ);
|
290 |
|
|
|
291 |
|
|
// Attach tb isrs.
|
292 |
|
|
HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_TB_A, &isr_tba,
|
293 |
|
|
ID_TBA, 0);
|
294 |
|
|
HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_TB_B, &isr_tbb,
|
295 |
|
|
ID_TBB, 0);
|
296 |
|
|
HAL_INTERRUPT_SET_LEVEL (CYGNUM_HAL_INTERRUPT_SIU_TB_A, TB_IRQ_LEVEL);
|
297 |
|
|
HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
|
298 |
|
|
HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
|
299 |
|
|
|
300 |
|
|
// Set reference A & B registers.
|
301 |
|
|
CYGARC_MFTB (TBL_R, tbl);
|
302 |
|
|
tbl += tb_period*3;
|
303 |
|
|
HAL_WRITE_UINT32 (CYGARC_REG_IMM_TBREF0, tbl);
|
304 |
|
|
tbl += tb_period*4;
|
305 |
|
|
HAL_WRITE_UINT32 (CYGARC_REG_IMM_TBREF1, tbl);
|
306 |
|
|
|
307 |
|
|
#ifdef DEBUG_PRINTFS
|
308 |
|
|
diag_printf( "TB initial %d, !1 %d !2 %d\n",
|
309 |
|
|
tbl - 7*tb_period,
|
310 |
|
|
tbl - 4*tb_period,
|
311 |
|
|
tbl - 0*tb_period );
|
312 |
|
|
#endif
|
313 |
|
|
// Enable.
|
314 |
|
|
HAL_READ_UINT16 (CYGARC_REG_IMM_TBSCR, tbscr);
|
315 |
|
|
tbscr |= (CYGARC_REG_IMM_TBSCR_REFA | CYGARC_REG_IMM_TBSCR_REFB |
|
316 |
|
|
CYGARC_REG_IMM_TBSCR_TBE);
|
317 |
|
|
HAL_WRITE_UINT16 (CYGARC_REG_IMM_TBSCR, tbscr);
|
318 |
|
|
tbscr |= CYGARC_REG_IMM_TBSCR_REFAE | CYGARC_REG_IMM_TBSCR_REFBE;
|
319 |
|
|
HAL_WRITE_UINT16 (CYGARC_REG_IMM_TBSCR, tbscr);
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
HAL_ENABLE_INTERRUPTS();
|
323 |
|
|
|
324 |
|
|
for (;;);
|
325 |
|
|
}
|
326 |
|
|
|
327 |
|
|
externC void
|
328 |
|
|
cyg_start( void )
|
329 |
|
|
{
|
330 |
|
|
intr0_main();
|
331 |
|
|
}
|
332 |
|
|
|
333 |
|
|
#else // ifdef CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE
|
334 |
|
|
|
335 |
|
|
externC void
|
336 |
|
|
cyg_start( void )
|
337 |
|
|
{
|
338 |
|
|
CYG_TEST_INIT();
|
339 |
|
|
CYG_TEST_PASS_FINISH("N/A: CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE disabled");
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
#endif // ifdef CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE
|
343 |
|
|
#else
|
344 |
|
|
|
345 |
|
|
externC void
|
346 |
|
|
cyg_start( void )
|
347 |
|
|
{
|
348 |
|
|
CYG_TEST_INIT();
|
349 |
|
|
CYG_TEST_PASS_FINISH("N/A: CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN enabled");
|
350 |
|
|
}
|
351 |
|
|
#endif // ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN
|
352 |
|
|
|
353 |
|
|
// EOF intr0.c
|