1 |
786 |
skrzyp |
/*=================================================================
|
2 |
|
|
//
|
3 |
|
|
// intr.c
|
4 |
|
|
//
|
5 |
|
|
// HAL Interrupt API 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 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): nickg
|
43 |
|
|
// Contributors: nickg
|
44 |
|
|
// Date: 1998-10-08
|
45 |
|
|
//####DESCRIPTIONEND####
|
46 |
|
|
*/
|
47 |
|
|
|
48 |
|
|
#include <pkgconf/hal.h>
|
49 |
|
|
|
50 |
|
|
#include <cyg/infra/testcase.h>
|
51 |
|
|
|
52 |
|
|
#include <cyg/hal/hal_intr.h>
|
53 |
|
|
#include <cyg/hal/drv_api.h>
|
54 |
|
|
|
55 |
|
|
// Include HAL/Platform specifics
|
56 |
|
|
#include CYGBLD_HAL_PLATFORM_H
|
57 |
|
|
|
58 |
|
|
#ifdef CYGPKG_KERNEL
|
59 |
|
|
#include <pkgconf/kernel.h> // Need to look for the RTC config.
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
// Fallback defaults (in case HAL didn't define these)
|
63 |
|
|
#ifndef CYGNUM_HAL_RTC_NUMERATOR
|
64 |
|
|
#define CYGNUM_HAL_RTC_NUMERATOR 1000000000
|
65 |
|
|
#define CYGNUM_HAL_RTC_DENOMINATOR 100
|
66 |
|
|
#define CYGNUM_HAL_RTC_PERIOD 9999
|
67 |
|
|
#endif
|
68 |
|
|
|
69 |
|
|
// -------------------------------------------------------------------------
|
70 |
|
|
|
71 |
|
|
#define ISR_DATA 0xAAAA1234
|
72 |
|
|
|
73 |
|
|
// -------------------------------------------------------------------------
|
74 |
|
|
|
75 |
|
|
volatile cyg_count32 ticks = 0;
|
76 |
|
|
volatile cyg_count32 dsr_ticks = 0;
|
77 |
|
|
static cyg_interrupt intr;
|
78 |
|
|
static cyg_handle_t intr_handle;
|
79 |
|
|
|
80 |
|
|
// -------------------------------------------------------------------------
|
81 |
|
|
|
82 |
|
|
cyg_uint32 isr( cyg_uint32 vector, CYG_ADDRWORD data )
|
83 |
|
|
{
|
84 |
|
|
CYG_TEST_CHECK( ISR_DATA == data , "Bad data passed to ISR");
|
85 |
|
|
CYG_TEST_CHECK( CYGNUM_HAL_INTERRUPT_RTC == vector ,
|
86 |
|
|
"Bad vector passed to ISR");
|
87 |
|
|
|
88 |
|
|
HAL_CLOCK_RESET( vector, CYGNUM_HAL_RTC_PERIOD );
|
89 |
|
|
|
90 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE( vector );
|
91 |
|
|
|
92 |
|
|
ticks++;
|
93 |
|
|
|
94 |
|
|
return CYG_ISR_CALL_DSR;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
// -------------------------------------------------------------------------
|
98 |
|
|
|
99 |
|
|
void dsr( cyg_uint32 vector, cyg_ucount32 count, CYG_ADDRWORD data )
|
100 |
|
|
{
|
101 |
|
|
CYG_TEST_CHECK( ISR_DATA == data , "Bad data passed to DSR");
|
102 |
|
|
CYG_TEST_CHECK( CYGNUM_HAL_INTERRUPT_RTC == vector ,
|
103 |
|
|
"Bad vector passed to DSR");
|
104 |
|
|
|
105 |
|
|
dsr_ticks += count;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
void intr_main( void )
|
109 |
|
|
{
|
110 |
|
|
CYG_INTERRUPT_STATE oldints;
|
111 |
|
|
|
112 |
|
|
cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_RTC, 1,
|
113 |
|
|
ISR_DATA, isr, dsr, &intr_handle, &intr);
|
114 |
|
|
cyg_drv_interrupt_attach(intr_handle);
|
115 |
|
|
HAL_CLOCK_INITIALIZE( CYGNUM_HAL_RTC_PERIOD );
|
116 |
|
|
cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_RTC);
|
117 |
|
|
|
118 |
|
|
HAL_ENABLE_INTERRUPTS();
|
119 |
|
|
|
120 |
|
|
while( ticks < 10 )
|
121 |
|
|
{
|
122 |
|
|
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
CYG_TEST_CHECK( dsr_ticks == 10, "DSR not called sufficient times");
|
127 |
|
|
|
128 |
|
|
HAL_DISABLE_INTERRUPTS(oldints);
|
129 |
|
|
|
130 |
|
|
CYG_TEST_PASS_FINISH("HAL interrupt test");
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
// -------------------------------------------------------------------------
|
135 |
|
|
|
136 |
|
|
externC void
|
137 |
|
|
cyg_start( void )
|
138 |
|
|
{
|
139 |
|
|
CYG_TEST_INIT();
|
140 |
|
|
|
141 |
|
|
// Attaching the ISR will not succeed if the kernel real-time
|
142 |
|
|
// clock has been configured in.
|
143 |
|
|
#ifndef CYGVAR_KERNEL_COUNTERS_CLOCK
|
144 |
|
|
|
145 |
|
|
intr_main();
|
146 |
|
|
|
147 |
|
|
#else
|
148 |
|
|
|
149 |
|
|
CYG_TEST_NA("Cannot override kernel real-time clock.");
|
150 |
|
|
|
151 |
|
|
#endif
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
// -------------------------------------------------------------------------
|
156 |
|
|
// EOF intr.c
|