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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [powerpc/] [mpc5xx/] [v2_0/] [tests/] [intr0.c] - Blame information for rev 578

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

Line No. Rev Author Line
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
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
extern diag_printf( char *format, ... );
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
#ifdef CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE
66
 
67
#undef CHECK(b)
68
#define CHECK(b) CYG_TEST_CHECK(b,#b)
69
 
70
// Can't rely on Cyg_Interrupt class being defined.
71
#define Cyg_InterruptHANDLED 1
72
 
73
// This is the period between interrupts, measured in decrementer ticks.
74
// Period must be longer than the time required for setting up all the
75
// interrupt handlers.
76
#define PIT_PERIOD 5000
77
 
78
#ifdef CYGPKG_HAL_POWERPC_MBX
79
#define TB_PERIOD (PIT_PERIOD*384)      // PTA period is 15.36 uS
80
#else
81
#define TB_PERIOD (PIT_PERIOD*32)       // assuming 512/16 divisors
82
#endif
83
 
84
#define ID_RTC_SEC   12345
85
#define ID_RTC_ALR   23451
86
#define ID_PIT       34512
87
#define ID_TBA       45123
88
#define ID_TBB       51234
89
 
90
volatile cyg_uint32 count = 0;
91
 
92
// Time/PERIOD    0   1   2   3   4   5   6   7   8   9   10
93
// Interrupt             PIT TBA PIT     PIT TBB PIT     PIT
94
// pit_count      0   0   0   1   1   2   2   3   3   4   4
95
// count          0   0   1   3   4   4   5   40  41      42
96
 
97
static cyg_uint32 count_verify_table[] = {1, 4, 5, 41, 42};
98
static int pit_count = 0;
99
 
100
// These are useful for debugging:
101
static cyg_uint32 count_actual_table[] = { -1, -1, -1, -1, -1};
102
static cyg_uint32 tbr_actual_table[] = { -1, -1, -1, -1, -1};
103
 
104
// Periodic timer ISR. Should be executing 5 times.
105
static cyg_uint32 isr_pit(CYG_ADDRWORD vector, CYG_ADDRWORD data)
106
{
107
    cyg_uint32 verify_value;
108
 
109
    CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
110
 
111
    CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_PIT == vector, "Wrong vector!");
112
    CYG_ASSERT (ID_PIT == data, "Wrong data!");
113
 
114
    HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_PIT);
115
 
116
    count++;
117
 
118
    count_actual_table[pit_count] = count;
119
    {
120
        cyg_uint32 tbl;
121
        CYGARC_MFTB (TBL_R, tbl);
122
        tbr_actual_table[pit_count] = tbl;
123
    }
124
 
125
    verify_value = count_verify_table[pit_count++];
126
 
127
#ifdef DEBUG_PRINTFS
128
    diag_printf( "ISR_PIT executed %d of 5\n", pit_count );
129
#endif
130
 
131
    CYG_ASSERT (count == verify_value, "Count wrong!");
132
 
133
    // End of test when count is 42. Mask interrupts and print PASS text.
134
    if (42 <= count || 5 == pit_count) {
135
        HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_PIT);
136
        HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
137
        HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
138
 
139
#ifdef DEBUG_PRINTFS
140
        diag_printf( "INFO: Actual counts: %d %d %d %d %d\n",
141
                     count_actual_table[0],
142
                     count_actual_table[1],
143
                     count_actual_table[2],
144
                     count_actual_table[3],
145
                     count_actual_table[4] );
146
        diag_printf( "INFO: Actuals tbrs: %d %d %d %d %d\n",
147
                     tbr_actual_table[0],
148
                     tbr_actual_table[1],
149
                     tbr_actual_table[2],
150
                     tbr_actual_table[3],
151
                     tbr_actual_table[4] );
152
#endif
153
        if (42 == count && 5 == pit_count)
154
            CYG_TEST_PASS_FINISH("Intr 0 OK");
155
        else
156
            CYG_TEST_FAIL_FINISH("Intr 0 Failed.");
157
    }
158
 
159
    return Cyg_InterruptHANDLED;
160
}
161
 
162
// TimeBase A ISR. Should be executing once.
163
static cyg_uint32 isr_tba(CYG_ADDRWORD vector, CYG_ADDRWORD data)
164
{
165
    CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
166
 
167
    CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_TB_A == vector, "Wrong vector!");
168
    CYG_ASSERT (ID_TBA == data, "Wrong data!");
169
 
170
    HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
171
 
172
    count = count * 3;
173
 
174
#ifdef DEBUG_PRINTFS
175
    diag_printf( "ISR_TBA executed\n" );
176
#endif
177
 
178
    return Cyg_InterruptHANDLED;
179
}
180
 
181
// TimeBase B ISR. Should be executing once.
182
static cyg_uint32 isr_tbb(CYG_ADDRWORD vector, CYG_ADDRWORD data)
183
{
184
    CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
185
 
186
    CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_TB_B == vector, "Wrong vector!");
187
    CYG_ASSERT (ID_TBB == data, "Wrong data!");
188
 
189
    HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
190
 
191
    count = count * 8;
192
 
193
#ifdef DEBUG_PRINTFS
194
    diag_printf( "ISR_TBB executed\n" );
195
#endif
196
 
197
    return Cyg_InterruptHANDLED;
198
}
199
 
200
void intr0_main( void )
201
{
202
    CYG_TEST_INIT();
203
 
204
#if 0
205
    // The A.3 revision of the CPU I'm using at the moment generates a
206
    // machine check exception when writing to IMM_RTCSC.  Smells a
207
    // bit like the "SIU4. Spurious External Bus Transaction Following
208
    // PLPRCR Write." CPU errata. Have to find out for sure.  Run real
209
    // time clock interrupts on level 0
210
    {
211
        // Still to do.
212
    }
213
#endif
214
 
215
    // Run periodic timer interrupt on level 1
216
    {
217
        cyg_uint16 piscr;
218
 
219
        // Attach pit arbiter.
220
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_LVL1,
221
                              &hal_arbitration_isr_pit, ID_PIT, 0);
222
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_LVL1);
223
 
224
        // Attach pit isr.
225
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_PIT, &isr_pit,
226
                              ID_PIT, 0);
227
        HAL_INTERRUPT_SET_LEVEL (CYGNUM_HAL_INTERRUPT_SIU_PIT, 1);
228
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_PIT);
229
 
230
 
231
        // Set period.
232
        HAL_WRITE_UINT32 (CYGARC_REG_IMM_PITC,
233
                          (2*PIT_PERIOD) << CYGARC_REG_IMM_PITC_COUNT_SHIFT);
234
 
235
#ifdef DEBUG_PRINTFS
236
        diag_printf( "PIT set to %d\n", 2*PIT_PERIOD );
237
#endif
238
        // Enable.
239
        HAL_READ_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
240
        piscr |= CYGARC_REG_IMM_PISCR_PTE;
241
        HAL_WRITE_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
242
    }
243
 
244
    // Run timebase interrupts on level 2
245
    {
246
        cyg_uint16 tbscr;
247
        cyg_uint32 tbl;
248
 
249
        // Attach tb arbiter.
250
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_LVL2,
251
                              &hal_arbitration_isr_tb, ID_TBA, 0);
252
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_LVL2);
253
 
254
        // Attach tb isrs.
255
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_TB_A, &isr_tba,
256
                              ID_TBA, 0);
257
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_TB_B, &isr_tbb,
258
                              ID_TBB, 0);
259
        HAL_INTERRUPT_SET_LEVEL (CYGNUM_HAL_INTERRUPT_SIU_TB_A, 2);
260
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
261
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
262
 
263
        // Set reference A & B registers.
264
        CYGARC_MFTB (TBL_R, tbl);
265
        tbl += TB_PERIOD*3;
266
        HAL_WRITE_UINT32 (CYGARC_REG_IMM_TBREF0, tbl);
267
        tbl += TB_PERIOD*4;
268
        HAL_WRITE_UINT32 (CYGARC_REG_IMM_TBREF1, tbl);
269
 
270
#ifdef DEBUG_PRINTFS
271
        diag_printf( "TB initial %d, !1 %d !2 %d\n",
272
                     tbl - 7*TB_PERIOD,
273
                     tbl - 4*TB_PERIOD,
274
                     tbl - 0*TB_PERIOD );
275
#endif
276
        // Enable.
277
        HAL_READ_UINT16 (CYGARC_REG_IMM_TBSCR, tbscr);
278
        tbscr |= (CYGARC_REG_IMM_TBSCR_REFA | CYGARC_REG_IMM_TBSCR_REFB |
279
                  CYGARC_REG_IMM_TBSCR_TBE);
280
        HAL_WRITE_UINT16 (CYGARC_REG_IMM_TBSCR, tbscr);
281
        tbscr |= CYGARC_REG_IMM_TBSCR_REFAE | CYGARC_REG_IMM_TBSCR_REFBE;
282
        HAL_WRITE_UINT16 (CYGARC_REG_IMM_TBSCR, tbscr);
283
    }
284
 
285
    HAL_ENABLE_INTERRUPTS();
286
 
287
    for (;;);
288
}
289
 
290
externC void
291
cyg_start( void )
292
{
293
    intr0_main();
294
}
295
 
296
#else  // ifdef CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE
297
 
298
externC void
299
cyg_start( void )
300
{
301
    CYG_TEST_INIT();
302
    CYG_TEST_PASS_FINISH("N/A: CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE disabled");
303
}
304
 
305
#endif // ifdef CYGSEM_HAL_POWERPC_MPC860_CPM_ENABLE
306
 
307
// EOF intr0.c

powered by: WebSVN 2.1.0

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