Mercurial > ecos-v3_0-branch
annotate packages/kernel/current/tests/kintr0.c @ 34:29bc183297e1 ecos-sw-1999-09-02
Merge from eCos master repository on 1999-09-02-16:26:10-BST
| author | jlarmour |
|---|---|
| date | Thu, 02 Sep 1999 16:11:22 +0000 |
| parents | d3fbcdfa1b2f |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 /*================================================================= |
| 2 // | |
| 3 // kintr0.c | |
| 4 // | |
| 5 // Kernel C API Intr test 0 | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | |
| 12 // Version 1.0 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 2 | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 0 | 26 // ------------------------------------------- |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): dsm | |
| 2 | 33 // Contributors: dsm, jlarmour |
| 34 // Date: 1999-02-16 | |
| 0 | 35 // Description: Very basic test of interrupt objects |
| 36 // Options: | |
| 37 // CYGIMP_KERNEL_INTERRUPTS_DSRS_TABLE | |
| 38 // CYGIMP_KERNEL_INTERRUPTS_DSRS_TABLE_MAX | |
| 39 // CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST | |
| 40 //####DESCRIPTIONEND#### | |
| 41 */ | |
| 42 | |
| 43 #include <cyg/kernel/kapi.h> | |
| 44 #include <cyg/hal/hal_intr.h> | |
| 45 | |
| 46 #include <cyg/infra/testcase.h> | |
| 47 | |
| 48 #ifdef CYGFUN_KERNEL_API_C | |
| 49 | |
| 50 #include "testaux.h" | |
| 51 | |
| 52 static cyg_interrupt intr_obj[2]; | |
| 53 | |
| 54 static cyg_handle_t intr0, intr1; | |
| 55 | |
| 56 | |
| 57 static cyg_ISR_t isr0, isr1; | |
| 58 static cyg_DSR_t dsr0, dsr1; | |
| 59 | |
| 60 static cyg_uint32 isr0(cyg_vector_t vector, cyg_addrword_t data) | |
| 61 { | |
| 62 CYG_UNUSED_PARAM(cyg_addrword_t, data); | |
| 63 | |
| 64 cyg_interrupt_acknowledge(vector); | |
| 65 return 0; | |
| 66 } | |
| 67 | |
| 68 static void dsr0(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) | |
| 69 { | |
| 70 CYG_UNUSED_PARAM(cyg_vector_t, vector); | |
| 71 CYG_UNUSED_PARAM(cyg_ucount32, count); | |
| 72 CYG_UNUSED_PARAM(cyg_addrword_t, data); | |
| 73 } | |
| 74 | |
| 75 static cyg_uint32 isr1(cyg_vector_t vector, cyg_addrword_t data) | |
| 76 { | |
| 77 CYG_UNUSED_PARAM(cyg_vector_t, vector); | |
| 78 CYG_UNUSED_PARAM(cyg_addrword_t, data); | |
| 79 return 0; | |
| 80 } | |
| 81 | |
| 82 static void dsr1(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) | |
| 83 { | |
| 84 CYG_UNUSED_PARAM(cyg_vector_t, vector); | |
| 85 CYG_UNUSED_PARAM(cyg_ucount32, count); | |
| 86 CYG_UNUSED_PARAM(cyg_addrword_t, data); | |
| 87 } | |
| 88 | |
| 89 static bool flash( void ) | |
| 90 { | |
| 91 cyg_handle_t handle; | |
| 92 cyg_interrupt intr; | |
| 93 | |
| 94 cyg_interrupt_create(0, 0, (cyg_addrword_t)333, isr0, dsr0, &handle, &intr ); | |
| 95 cyg_interrupt_delete(handle); | |
| 96 | |
| 97 return true; | |
| 98 } | |
| 99 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
100 /* IMPORTANT: The calling convention for VSRs is target dependent. It is |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
101 * unlikely that a plain C or C++ routine would function correctly on any |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
102 * particular platform, even if it could correctly access the system |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
103 * resources necessary to handle the event that caused it to be called. |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
104 * VSRs usually must be written in assembly language. |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
105 * |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
106 * This is just a test program. The routine vsr0() below is defined simply |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
107 * to define an address that will be in executable memory. If an event |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
108 * causes this VSR to be called, all bets are off. If it is accidentally |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
109 * installed in the vector for the realtime clock, the system will likely |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
110 * freeze. |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
111 */ |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
112 |
| 0 | 113 static cyg_VSR_t vsr0; |
| 114 | |
| 115 static void vsr0() | |
| 116 { | |
| 117 } | |
| 118 | |
| 119 void kintr0_main( void ) | |
| 120 { | |
| 2 | 121 cyg_vector_t v = 11 % CYGNUM_HAL_VSR_COUNT; |
| 122 cyg_vector_t v1; | |
| 123 cyg_vector_t lvl1 = 1 % (CYGNUM_HAL_ISR_COUNT); | |
| 124 cyg_vector_t lvl2 = 15 % (CYGNUM_HAL_ISR_COUNT); | |
| 125 int in_use; | |
| 126 | |
| 0 | 127 cyg_VSR_t *old_vsr, *new_vsr; |
| 128 | |
| 129 CYG_TEST_INIT(); | |
| 2 | 130 |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
131 #ifdef CYGPKG_HAL_MIPS_TX39 |
| 2 | 132 // This can be removed when PR 17831 is fixed |
| 133 if ( cyg_test_is_simulator ) | |
| 134 v1 = 12 % CYGNUM_HAL_ISR_COUNT; | |
| 135 else /* NOTE TRAILING ELSE... */ | |
| 136 #endif | |
| 137 v1 = 6 % CYGNUM_HAL_ISR_COUNT; | |
| 0 | 138 |
| 139 CHECK(flash()); | |
| 140 CHECK(flash()); | |
| 141 | |
| 2 | 142 // Make sure the chosen levels are not already in use. |
| 143 HAL_INTERRUPT_IN_USE( lvl1, in_use ); | |
| 144 intr0 = 0; | |
| 145 if (!in_use) | |
| 146 cyg_interrupt_create(lvl1, 1, (cyg_addrword_t)777, isr0, dsr0, | |
| 147 &intr0, &intr_obj[0]); | |
| 0 | 148 |
| 2 | 149 HAL_INTERRUPT_IN_USE( lvl2, in_use ); |
| 150 intr1 = 0; | |
| 151 if (!in_use && lvl1 != lvl2) | |
| 152 cyg_interrupt_create(lvl2, 1, 888, isr1, dsr1, &intr1, &intr_obj[1]); | |
| 0 | 153 |
| 154 // Check these functions at least exist | |
| 155 | |
| 156 cyg_interrupt_enable(); | |
| 157 cyg_interrupt_disable(); | |
| 158 | |
| 2 | 159 if (intr0) |
| 160 cyg_interrupt_attach(intr0); | |
| 161 if (intr1) | |
| 162 cyg_interrupt_attach(intr1); | |
| 163 if (intr0) | |
| 164 cyg_interrupt_detach(intr0); | |
| 165 if (intr1) | |
| 166 cyg_interrupt_detach(intr1); | |
| 0 | 167 |
| 168 // If this attaching interrupt replaces the previous interrupt | |
| 169 // instead of adding to it we could be in a big mess if the | |
| 170 // vector is being used by something important. | |
| 2 | 171 |
| 0 | 172 cyg_interrupt_get_vsr( v, &old_vsr ); |
| 173 cyg_interrupt_set_vsr( v, vsr0 ); | |
| 174 cyg_interrupt_get_vsr( v, &new_vsr ); | |
| 175 CHECK( vsr0 == new_vsr ); | |
| 176 | |
| 177 new_vsr = NULL; | |
| 178 cyg_interrupt_get_vsr( v, &new_vsr ); | |
| 179 cyg_interrupt_set_vsr( v, old_vsr ); | |
| 180 CHECK( new_vsr == vsr0 ); | |
| 181 | |
| 182 cyg_interrupt_set_vsr( v, new_vsr ); | |
| 183 new_vsr = NULL; | |
| 2 | 184 cyg_interrupt_get_vsr( v, &new_vsr ); |
| 0 | 185 CHECK( vsr0 == new_vsr ); |
| 186 | |
| 187 cyg_interrupt_set_vsr( v, old_vsr ); | |
| 188 CHECK( vsr0 == new_vsr ); | |
| 189 new_vsr = NULL; | |
| 190 cyg_interrupt_get_vsr( v, &new_vsr ); | |
| 191 CHECK( old_vsr == new_vsr ); | |
| 2 | 192 |
| 0 | 193 CHECK( NULL != vsr0 ); |
| 194 | |
| 195 cyg_interrupt_mask(v1); | |
| 196 cyg_interrupt_unmask(v1); | |
| 197 | |
| 198 cyg_interrupt_configure(v1, true, true); | |
| 199 | |
| 200 CYG_TEST_PASS_FINISH("Kernel C API Intr 0 OK"); | |
| 201 } | |
| 202 | |
| 203 externC void | |
| 204 cyg_start( void ) | |
| 205 { | |
| 206 kintr0_main(); | |
| 207 } | |
| 208 | |
| 209 #else /* def CYGFUN_KERNEL_API_C */ | |
| 210 externC void | |
| 211 cyg_start( void ) | |
| 212 { | |
| 213 CYG_TEST_INIT(); | |
| 2 | 214 CYG_TEST_NA("Kernel C API layer disabled"); |
| 0 | 215 } |
| 216 #endif /* def CYGFUN_KERNEL_API_C */ | |
| 217 | |
| 218 /* EOF kintr0.c */ |
