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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [powerpc/] [mpc5xx/] [current/] [tests/] [intr0.c] - Blame information for rev 791

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

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
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 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//=================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     Bob Koninckx
43
// Contributors:  Bob Koninckx
44
// Date:          2002-11-16
45
// Description:   Simple test of MPC5xx interrupt handling when the
46
//                kernel has not been configured. Uses timer interrupts.
47
// Options:
48
//####DESCRIPTIONEND####
49
 
50
#include <pkgconf/hal.h>
51
#include <pkgconf/infra.h>
52
 
53
#include <cyg/infra/testcase.h>
54
#include <cyg/infra/cyg_trac.h>
55
 
56
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
57
#include <cyg/hal/hal_arch.h>
58
#include <cyg/hal/hal_intr.h>
59
#include <cyg/hal/ppc_regs.h>
60
 
61
#define ID_RTC_SEC 12345
62
#define ID_RTC_ALR 23451
63
#define ID_PIT     34512
64
#define ID_TBA     45123
65
#define ID_TBB     51234
66
 
67
#define CYG_InterruptHANDLED 1
68
#define PIT_PERIOD 5000
69
#define TB_PERIOD  (PIT_PERIOD*160)
70
 
71
// Factor 160 comes from setting SCCR = 0x0300. Thus, TBS = 1   -->> Time base is clocked by 
72
//                                                                   system clock / 16 = 40MHz / 16
73
//                                                    RTDIV = 1 -->> RTC/PIT clocked by OSCM / 256
74
//                                                                   or 4 MHz / 256
75
//                                                                   Factor of 160 between the two
76
 
77
volatile cyg_uint32 count = 0;
78
static int pit_count = 0;
79
static cyg_uint32 count_verify_table[] = {1, 4, 5, 41, 42};
80
 
81
// These are useful for debugging:
82
static cyg_uint32 count_actual_table[] = { -1, -1, -1, -1, -1};
83
static cyg_uint32 tbr_actual_table[] = { -1, -1, -1, -1, -1};
84
 
85
hal_mpc5xx_arbitration_data hal_arbitration_data_tb;
86
hal_mpc5xx_arbitration_data hal_arbitration_data_pit;
87
 
88
static cyg_uint32 isr_tba(CYG_ADDRWORD vector, CYG_ADDRWORD data)
89
{
90
        CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
91
 
92
        CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_TB_A == vector, "Wrong vector!");
93
    CYG_ASSERT (ID_TBA == data, "Wrong data!");
94
 
95
        HAL_INTERRUPT_ACKNOWLEDGE(vector);
96
        count = count*3;
97
 
98
        return CYG_InterruptHANDLED;
99
}
100
 
101
static cyg_uint32 isr_tbb(CYG_ADDRWORD vector, CYG_ADDRWORD data)
102
{
103
        CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
104
 
105
        CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_TB_B == vector, "Wrong vector!");
106
    CYG_ASSERT (ID_TBB == data, "Wrong data!");
107
 
108
        HAL_INTERRUPT_ACKNOWLEDGE(vector);
109
        count = count*8;
110
 
111
        return CYG_InterruptHANDLED;
112
}
113
 
114
static cyg_uint32
115
isr_pit(CYG_ADDRWORD vector, CYG_ADDRWORD data)
116
{
117
        cyg_uint32 verify_value;
118
 
119
        CYG_UNUSED_PARAM(CYG_ADDRWORD, data);
120
 
121
        CYG_ASSERT (CYGNUM_HAL_INTERRUPT_SIU_TB_B == vector, "Wrong vector!");
122
    CYG_ASSERT (ID_PIT == data, "Wrong data!");
123
 
124
        HAL_INTERRUPT_ACKNOWLEDGE(vector);
125
 
126
        count++;
127
 
128
        count_actual_table[pit_count] = count;
129
        {
130
                cyg_uint32 tbl;
131
        CYGARC_MFTB (TBL_R, tbl);
132
        tbr_actual_table[pit_count] = tbl;
133
        }
134
 
135
        verify_value = count_verify_table[pit_count++];
136
 
137
        CYG_ASSERT (count == verify_value, "Count wrong!");
138
 
139
        // End of test when count is 42. Mask interrupts and print PASS text.
140
        if (42 <= count || 5 == pit_count) {
141
           HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_PIT);
142
           HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
143
           HAL_INTERRUPT_MASK (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
144
 
145
           if(5 == pit_count)
146
           {
147
                   if(42 != count) CYG_TEST_INFO("TB/PIT ratio does not match");
148
           }
149
 
150
           if(5 == pit_count && 42 == count)
151
           {
152
           CYG_TEST_PASS_FINISH("Intr 0 OK");
153
           }
154
           else
155
           {
156
           CYG_TEST_FAIL_FINISH("Intr 0 FAILED");
157
           }
158
        }
159
 
160
        return CYG_InterruptHANDLED;
161
}
162
 
163
static void
164
intr0_main( void )
165
{
166
    int tb_period = TB_PERIOD;
167
        cyg_uint32 tbl;
168
        cyg_uint16 piscr;
169
 
170
        // Install the PIT Interrupt arbiter
171
        hal_arbitration_data_pit.priority = CYGNUM_HAL_ISR_SOURCE_PRIORITY_PIT;
172
        hal_arbitration_data_pit.data     = 0;
173
        hal_arbitration_data_pit.arbiter  = hal_arbitration_isr_pit;
174
 
175
        hal_mpc5xx_install_arbitration_isr(&hal_arbitration_data_pit);
176
 
177
        // attach PIT isr
178
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_PIT, &isr_pit, ID_PIT, 0);
179
        HAL_INTERRUPT_SET_LEVEL (CYGNUM_HAL_INTERRUPT_SIU_PIT, CYGNUM_HAL_ISR_SOURCE_PRIORITY_PIT);
180
 
181
        // Set period
182
    HAL_WRITE_UINT32 (CYGARC_REG_IMM_PITC, (2*PIT_PERIOD) << CYGARC_REG_IMM_PITC_COUNT_SHIFT);
183
 
184
        // Enable.
185
    HAL_READ_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
186
    piscr |= CYGARC_REG_IMM_PISCR_PTE;
187
    HAL_WRITE_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
188
 
189
        // Clear any pending interrupts and enable them
190
        HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_PIT);
191
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_PIT);
192
 
193
        // Install the Timebase Interrupt Arbiter
194
        hal_arbitration_data_tb.priority = CYGNUM_HAL_ISR_SOURCE_PRIORITY_TB;
195
        hal_arbitration_data_tb.data     = 0;
196
        hal_arbitration_data_tb.arbiter  = hal_arbitration_isr_tb;
197
 
198
        hal_mpc5xx_install_arbitration_isr(&hal_arbitration_data_tb);
199
 
200
        // Attach tb isrs.
201
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_TB_A, &isr_tba, ID_TBA, 0);
202
        HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_TB_B, &isr_tbb, ID_TBB, 0);
203
    HAL_INTERRUPT_SET_LEVEL (CYGNUM_HAL_INTERRUPT_SIU_TB_A, CYGNUM_HAL_ISR_SOURCE_PRIORITY_TB);
204
 
205
    // Set reference A & B registers.
206
    CYGARC_MFTB (TBL_R, tbl);
207
    tbl += tb_period*3;
208
    HAL_WRITE_UINT32 (CYGARC_REG_IMM_TBREF0, tbl);
209
    tbl += tb_period*4;
210
    HAL_WRITE_UINT32 (CYGARC_REG_IMM_TBREF1, tbl);
211
 
212
        // Clear any pending interrupts and enable them
213
        HAL_INTERRUPT_ACKNOWLEDGE(CYGNUM_HAL_INTERRUPT_SIU_TB_A);
214
        HAL_INTERRUPT_ACKNOWLEDGE(CYGNUM_HAL_INTERRUPT_SIU_TB_B);
215
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_TB_A);
216
        HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_TB_B);
217
 
218
        HAL_ENABLE_INTERRUPTS();
219
 
220
        for(;;);
221
}
222
 
223
externC void
224
cyg_start( void )
225
{
226
    CYG_TEST_INIT();
227
    intr0_main();
228
        CYG_TEST_PASS_FINISH("HAL Interrupt test");
229
}

powered by: WebSVN 2.1.0

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