Mercurial > ecos
annotate packages/hal/common/current/src/drv_api.c @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | bf00f99aec69 |
| children | eb9fd8c04db3 |
| rev | line source |
|---|---|
| 2 | 1 //========================================================================== |
| 2 // | |
| 3 // drv_api.c | |
| 4 // | |
| 5 // Driver API for non-kernel configurations | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
29 // |
| 2 | 30 //####COPYRIGHTEND#### |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): Nick Garnett | |
| 35 // Date: 1999-02-24 | |
| 36 // Purpose: Driver API for non-kernel configurations | |
| 37 // Description: These functions are used to support drivers when the kernel | |
| 38 // is not present. | |
| 39 // | |
| 40 // | |
| 41 // | |
| 42 //####DESCRIPTIONEND#### | |
| 43 // | |
| 44 //========================================================================== | |
| 45 | |
| 46 #include <pkgconf/system.h> | |
| 47 | |
| 48 #ifndef CYGPKG_KERNEL | |
| 49 | |
| 50 #include <cyg/infra/cyg_type.h> | |
| 51 #include <cyg/infra/cyg_trac.h> | |
| 52 #include <cyg/infra/cyg_ass.h> | |
| 53 | |
| 54 #include <pkgconf/hal.h> | |
| 55 #include <cyg/hal/drv_api.h> | |
| 56 | |
| 57 #include <cyg/hal/hal_arch.h> | |
| 58 #include <cyg/hal/hal_intr.h> | |
| 59 | |
| 60 //-------------------------------------------------------------------------- | |
| 61 // Statics | |
| 62 | |
| 63 static volatile cyg_int32 isr_disable_counter; // ISR disable counter | |
| 64 | |
| 65 volatile cyg_int32 dsr_disable_counter asm("cyg_scheduler_sched_lock"); // DSR disable counter | |
| 66 | |
| 67 static volatile cyg_interrupt *dsr_list; // List of pending DSRs | |
| 68 | |
| 69 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 70 | |
| 71 cyg_interrupt *chain_list[CYGNUM_HAL_ISR_COUNT]; | |
| 72 | |
| 73 #endif | |
| 74 | |
| 75 //-------------------------------------------------------------------------- | |
| 76 // DSR handling functions. | |
| 77 // post_dsr() places a DSR on the list of DSRs to be called. | |
| 78 // call_dsrs() calls the DSRs. | |
| 79 | |
| 80 static void post_dsr( cyg_interrupt *intr ) | |
| 81 { | |
| 82 CYG_INTERRUPT_STATE old_intr; | |
| 83 | |
| 84 CYG_REPORT_FUNCTION(); | |
| 85 | |
| 86 HAL_DISABLE_INTERRUPTS(old_intr); | |
| 87 | |
| 88 if( intr->dsr_count++ == 0 ) | |
| 89 { | |
| 90 intr->next_dsr = dsr_list; | |
| 91 dsr_list = intr; | |
| 92 } | |
| 93 | |
| 94 HAL_RESTORE_INTERRUPTS(old_intr); | |
| 95 | |
| 96 CYG_REPORT_RETURN(); | |
| 97 } | |
| 98 | |
| 99 static void call_dsrs(void) | |
| 100 { | |
| 101 CYG_REPORT_FUNCTION(); | |
| 102 | |
| 103 while( dsr_list != NULL ) | |
| 104 { | |
| 105 volatile cyg_interrupt *intr; | |
| 106 cyg_int32 count; | |
| 107 CYG_INTERRUPT_STATE old_intr; | |
| 108 | |
| 109 HAL_DISABLE_INTERRUPTS(old_intr); | |
| 110 | |
| 111 intr = dsr_list; | |
| 112 dsr_list = intr->next_dsr; | |
| 113 count = intr->dsr_count; | |
| 114 intr->dsr_count = 0; | |
| 115 | |
| 116 HAL_RESTORE_INTERRUPTS(old_intr); | |
| 117 | |
| 118 intr->dsr( intr->vector, count, (CYG_ADDRWORD)intr->data ); | |
| 119 } | |
| 120 | |
| 121 CYG_REPORT_RETURN(); | |
| 122 | |
| 123 } | |
| 124 | |
| 125 //-------------------------------------------------------------------------- | |
|
6
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
126 // This is referenced from the HAL, although it does not actually get called. |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
127 |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
128 externC void |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
129 cyg_interrupt_call_pending_DSRs(void) |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
130 { |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
131 call_dsrs(); |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
132 } |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
133 |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
134 |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
135 //-------------------------------------------------------------------------- |
| 2 | 136 // Interrupt end function called from HAL VSR to tidy up. This is where |
| 137 // DSRs will be called if necessary. | |
| 138 | |
| 139 externC void | |
| 140 interrupt_end( | |
| 141 cyg_uint32 isr_ret, | |
| 142 cyg_interrupt *intr, | |
| 143 HAL_SavedRegisters *regs | |
| 144 ) | |
| 145 { | |
| 146 CYG_REPORT_FUNCTION(); | |
| 147 | |
| 148 #ifndef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 149 | |
| 150 // Only do this if we are in a non-chained configuration. | |
| 151 // If we are chained, then chain_isr will do the DSR | |
| 152 // posting. | |
| 153 | |
| 154 if( isr_ret & CYG_ISR_CALL_DSR && intr != NULL ) post_dsr(intr); | |
| 155 | |
| 156 #endif | |
| 157 | |
| 158 if( dsr_disable_counter == 0 ) call_dsrs(); | |
| 159 | |
| 160 CYG_REPORT_RETURN(); | |
| 161 } | |
| 162 | |
| 163 //-------------------------------------------------------------------------- | |
| 164 // ISR for handling chained interrupts. | |
| 165 | |
| 166 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 167 | |
| 168 cyg_uint32 chain_isr(cyg_vector_t vector, CYG_ADDRWORD data) | |
| 169 { | |
| 170 CYG_REPORT_FUNCTION(); | |
| 171 | |
| 172 cyg_interrupt *p = *(cyg_interrupt **)data; | |
| 173 | |
| 174 while( p != NULL ) | |
| 175 { | |
| 176 if( p->vector == vector ) | |
| 177 { | |
| 178 register cyg_uint32 isr_ret = p->isr(vector, p->data); | |
| 179 | |
| 180 if( isr_ret & CYG_ISR_CALL_DSR ) post_dsr(p); | |
| 181 | |
| 182 if( isr_ret & CYG_ISR_HANDLED ) break; | |
| 183 } | |
| 184 | |
| 185 p = p->next; | |
| 186 } | |
| 187 | |
| 188 CYG_REPORT_RETURN(); | |
| 189 | |
| 190 return 0; | |
| 191 } | |
| 192 | |
| 193 #endif | |
| 194 | |
| 195 //-------------------------------------------------------------------------- | |
| 196 // ISR lock. This disables interrupts and keeps a count of the number | |
| 197 // times it has been called. | |
| 198 | |
| 199 externC void cyg_drv_isr_lock() | |
| 200 { | |
| 201 CYG_INTERRUPT_STATE dummy; | |
| 202 | |
| 203 CYG_REPORT_FUNCTION(); | |
| 204 | |
| 205 HAL_DISABLE_INTERRUPTS(dummy); | |
| 206 | |
| 207 CYG_ASSERT( isr_disable_counter >= 0 , "Disable counter negative"); | |
| 208 | |
| 209 isr_disable_counter++; | |
| 210 | |
| 211 CYG_REPORT_RETURN(); | |
| 212 } | |
| 213 | |
| 214 //-------------------------------------------------------------------------- | |
| 215 // Unlock ISRs. This decrements the count and re-enables interrupts if it | |
| 216 // goes zero. | |
| 217 | |
| 218 externC void cyg_drv_isr_unlock() | |
| 219 { | |
| 220 CYG_REPORT_FUNCTION(); | |
| 221 | |
| 222 CYG_ASSERT( isr_disable_counter > 0 , "Disable counter not greater than zero"); | |
| 223 | |
| 224 isr_disable_counter--; | |
| 225 | |
| 226 if ( isr_disable_counter == 0 ) | |
| 227 { | |
| 228 HAL_ENABLE_INTERRUPTS(); | |
| 229 } | |
| 230 | |
| 231 CYG_REPORT_RETURN(); | |
| 232 } | |
| 233 | |
| 234 //-------------------------------------------------------------------------- | |
| 235 // Lock DSR lock. Simply increment the counter. | |
| 236 | |
| 237 externC void cyg_drv_dsr_lock() | |
| 238 { | |
| 239 CYG_REPORT_FUNCTION(); | |
| 240 | |
| 241 dsr_disable_counter++; | |
| 242 | |
| 243 CYG_REPORT_RETURN(); | |
| 244 } | |
| 245 | |
| 246 //-------------------------------------------------------------------------- | |
| 247 // Unlock DSR lock. If the counter is about to go zero, call any pending | |
| 248 // DSRs and then zero the counter. | |
| 249 | |
| 250 externC void cyg_drv_dsr_unlock() | |
| 251 { | |
| 252 CYG_REPORT_FUNCTION(); | |
| 253 | |
| 254 do | |
| 255 { | |
| 256 if( dsr_disable_counter == 1 ) | |
| 257 { | |
| 258 call_dsrs(); | |
| 259 } | |
| 260 | |
| 261 HAL_REORDER_BARRIER(); | |
| 262 | |
| 263 dsr_disable_counter = 0; | |
| 264 | |
| 265 HAL_REORDER_BARRIER(); | |
| 266 | |
| 267 // Check that no DSRs have been posted between calling | |
| 268 // call_dsrs() and zeroing dsr_disable_counter. If so, | |
| 269 // loop back and call them. | |
| 270 | |
| 271 if( dsr_list != NULL ) | |
| 272 { | |
| 273 dsr_disable_counter = 1; | |
| 274 continue; | |
| 275 } | |
| 276 | |
| 277 CYG_REPORT_RETURN(); | |
| 278 | |
| 279 return; | |
| 280 | |
| 281 } while(1); | |
| 282 | |
| 283 CYG_FAIL( "Should not be executed" ); | |
| 284 } | |
| 285 | |
| 286 //-------------------------------------------------------------------------- | |
| 287 // Initialize a mutex. | |
| 288 | |
| 289 externC void cyg_drv_mutex_init( cyg_drv_mutex_t *mutex ) | |
| 290 { | |
| 291 CYG_REPORT_FUNCTION(); | |
| 292 | |
| 293 mutex->lock = 0; | |
| 294 | |
| 295 CYG_REPORT_RETURN(); | |
| 296 } | |
| 297 | |
| 298 //-------------------------------------------------------------------------- | |
| 299 // Destroy a mutex. | |
| 300 | |
| 301 externC void cyg_drv_mutex_destroy( cyg_drv_mutex_t *mutex ) | |
| 302 { | |
| 303 CYG_REPORT_FUNCTION(); | |
| 304 | |
| 305 mutex->lock = -1; | |
| 306 | |
| 307 CYG_REPORT_RETURN(); | |
| 308 } | |
| 309 | |
| 310 //-------------------------------------------------------------------------- | |
| 311 // Lock a mutex. We check that we are not trying to lock a locked or | |
| 312 // destroyed mutex and if not, set it locked. | |
| 313 | |
| 314 externC cyg_bool_t cyg_drv_mutex_lock( cyg_drv_mutex_t *mutex ) | |
| 315 { | |
| 316 CYG_REPORT_FUNCTION(); | |
| 317 | |
| 318 CYG_ASSERT( mutex->lock == 0 , "Trying to lock locked mutex"); | |
| 319 | |
| 320 mutex->lock = 1; | |
| 321 | |
| 322 CYG_REPORT_RETURN(); | |
| 323 | |
| 324 return true; | |
| 325 } | |
| 326 | |
| 327 //-------------------------------------------------------------------------- | |
| 328 // Attempt to claim a mutex, and return if it cannot be. | |
| 329 | |
| 330 externC cyg_bool_t cyg_drv_mutex_trylock( cyg_drv_mutex_t *mutex ) | |
| 331 { | |
| 332 cyg_bool_t result = true; | |
| 333 | |
| 334 CYG_REPORT_FUNCTION(); | |
| 335 | |
| 336 if( mutex->lock == 1 ) result = false; | |
| 337 | |
| 338 CYG_REPORT_RETURN(); | |
| 339 | |
| 340 return result; | |
| 341 } | |
| 342 | |
| 343 //-------------------------------------------------------------------------- | |
| 344 // Unlock a mutex. We check that the mutex is actually locked before doing | |
| 345 // this. | |
| 346 | |
| 347 externC void cyg_drv_mutex_unlock( cyg_drv_mutex_t *mutex ) | |
| 348 { | |
| 349 CYG_REPORT_FUNCTION(); | |
| 350 | |
| 351 CYG_ASSERT( mutex->lock == 1 , "Trying to unlock unlocked mutex"); | |
| 352 | |
| 353 mutex->lock = 0; | |
| 354 | |
| 355 CYG_REPORT_RETURN(); | |
| 356 } | |
| 357 | |
| 358 //-------------------------------------------------------------------------- | |
| 359 // Release all threads waiting for the mutex. | |
| 360 // This is really for threads, so we do nothing here. | |
| 361 | |
| 362 externC void cyg_drv_mutex_release( cyg_drv_mutex_t *mutex ) | |
| 363 { | |
| 364 CYG_REPORT_FUNCTION(); | |
| 365 | |
| 366 | |
| 367 | |
| 368 CYG_REPORT_RETURN(); | |
| 369 } | |
| 370 | |
| 371 | |
| 372 //-------------------------------------------------------------------------- | |
| 373 // Initialized a condition variable. | |
| 374 | |
| 375 externC void cyg_drv_cond_init( cyg_drv_cond_t *cond, cyg_drv_mutex_t *mutex ) | |
| 376 { | |
| 377 CYG_REPORT_FUNCTION(); | |
| 378 | |
| 379 cond->wait = 0; | |
| 380 cond->mutex = mutex; | |
| 381 | |
| 382 CYG_REPORT_RETURN(); | |
| 383 } | |
| 384 | |
| 385 | |
| 386 //-------------------------------------------------------------------------- | |
| 387 // Destroy a condition variable. | |
| 388 | |
| 389 externC void cyg_drv_cond_destroy( cyg_drv_cond_t *cond ) | |
| 390 { | |
| 391 CYG_REPORT_FUNCTION(); | |
| 392 | |
| 393 cond->wait = -1; | |
| 394 cond->mutex = NULL; | |
| 395 | |
| 396 CYG_REPORT_RETURN(); | |
| 397 } | |
| 398 | |
| 399 // ------------------------------------------------------------------------- | |
| 400 // Wait for a condition variable to be signalled. We simply busy wait | |
| 401 // polling the condition variable's wait member until a DSR sets it to | |
| 402 // 0. Note that the semantics of condition variables means that the | |
| 403 // wakeup only happens if there is a thread actually waiting on the CV | |
| 404 // when the signal is sent. | |
| 405 | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
406 externC cyg_bool cyg_drv_cond_wait( cyg_drv_cond_t *cond ) |
| 2 | 407 { |
| 408 CYG_REPORT_FUNCTION(); | |
| 409 | |
| 410 CYG_ASSERT( cond->mutex != NULL, "Uninitialized condition variable"); | |
| 411 CYG_ASSERT( cond->mutex->lock, "Mutex not locked"); | |
| 412 | |
| 413 cyg_drv_dsr_lock(); | |
| 414 | |
| 415 cond->wait = 1; | |
| 416 | |
| 417 while( cond->wait == 1 ) | |
| 418 { | |
| 419 // While looping we call call_dsrs() to service any DSRs that | |
| 420 // get posted. One of these will make the call to cond_signal | |
| 421 // to break us out of this loop. If we do not have the DSR | |
| 422 // lock claimed, then a race condition could occur and keep us | |
| 423 // stuck here forever. | |
| 424 | |
| 425 call_dsrs(); | |
| 426 } | |
| 427 | |
| 428 cyg_drv_dsr_unlock(); | |
| 429 | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
430 CYG_REPORT_RETURN(); |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
431 |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
432 return true; |
| 2 | 433 } |
| 434 | |
| 435 //-------------------------------------------------------------------------- | |
| 436 // Signal a condition variable. This sets the wait member to zero, which | |
| 437 // has no effect when there is no waiter, but will wake up any waiting | |
| 438 // thread. | |
| 439 | |
| 440 externC void cyg_drv_cond_signal( cyg_drv_cond_t *cond ) | |
| 441 { | |
| 442 CYG_REPORT_FUNCTION(); | |
| 443 | |
| 444 cond->wait = 0; | |
| 445 | |
| 446 CYG_REPORT_RETURN(); | |
| 447 } | |
| 448 | |
| 449 | |
| 450 //-------------------------------------------------------------------------- | |
| 451 // Broadcast to condition variable. This is exactly the same a signal since | |
| 452 // there can only be one waiter. | |
| 453 | |
| 454 externC void cyg_drv_cond_broadcast( cyg_drv_cond_t *cond ) | |
| 455 { | |
| 456 CYG_REPORT_FUNCTION(); | |
| 457 | |
| 458 cond->wait = 0; | |
| 459 | |
| 460 CYG_REPORT_RETURN(); | |
| 461 } | |
| 462 | |
| 463 | |
| 464 //-------------------------------------------------------------------------- | |
| 465 // Create an interrupt object. | |
| 466 | |
| 467 externC void cyg_drv_interrupt_create( | |
| 468 cyg_vector_t vector, | |
| 469 cyg_priority_t priority, | |
| 470 cyg_addrword_t data, | |
| 471 cyg_ISR_t *isr, | |
| 472 cyg_DSR_t *dsr, | |
| 473 cyg_handle_t *handle, | |
| 474 cyg_interrupt *intr | |
| 475 ) | |
| 476 { | |
| 477 CYG_REPORT_FUNCTION(); | |
| 478 | |
| 479 intr->vector = vector; | |
| 480 intr->priority = priority; | |
| 481 intr->isr = isr; | |
| 482 intr->dsr = dsr; | |
| 483 intr->data = data; | |
| 484 intr->next_dsr = NULL; | |
| 485 intr->dsr_count = 0; | |
| 486 | |
| 487 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 488 | |
| 489 intr->next = NULL; | |
| 490 | |
| 491 #endif | |
| 492 | |
| 493 *handle = (cyg_handle_t)intr; | |
| 494 | |
| 495 CYG_REPORT_RETURN(); | |
| 496 } | |
| 497 | |
| 498 //-------------------------------------------------------------------------- | |
| 499 // Delete an interrupt object. This merely ensures that it is detached from | |
| 500 // the vector. | |
| 501 | |
| 502 externC void cyg_drv_interrupt_delete( cyg_handle_t interrupt ) | |
| 503 { | |
| 504 CYG_REPORT_FUNCTION(); | |
| 505 | |
| 506 cyg_drv_interrupt_detach( interrupt ); | |
| 507 | |
| 508 CYG_REPORT_RETURN(); | |
| 509 } | |
| 510 | |
| 511 //-------------------------------------------------------------------------- | |
| 512 // | |
| 513 | |
| 514 externC void cyg_drv_interrupt_attach( cyg_handle_t interrupt ) | |
| 515 { | |
| 516 cyg_interrupt *intr = (cyg_interrupt *)interrupt; | |
| 517 | |
| 518 CYG_REPORT_FUNCTION(); | |
| 519 | |
| 520 CYG_ASSERT( intr->vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 521 CYG_ASSERT( intr->vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 522 | |
| 523 HAL_INTERRUPT_SET_LEVEL( intr->vector, intr->priority ); | |
| 524 | |
| 525 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 526 | |
| 527 CYG_ASSERT( intr->next == NULL , "cyg_interrupt already on a list"); | |
| 528 | |
| 529 cyg_uint32 index; | |
| 530 | |
| 531 HAL_TRANSLATE_VECTOR( intr->vector, index ); | |
| 532 | |
| 533 if( chain_list[index] == NULL ) | |
| 534 { | |
| 535 // First Interrupt on this chain, just assign it and register | |
| 536 // the chain_isr with the HAL. | |
| 537 | |
| 538 chain_list[index] = intr; | |
| 539 | |
| 540 HAL_INTERRUPT_ATTACH( intr->vector, chain_isr, &chain_list[index], NULL ); | |
| 541 } | |
| 542 else | |
| 543 { | |
| 544 // There are already interrupts chained, add this one into the | |
| 545 // chain in priority order. | |
| 546 | |
| 547 Cyg_Interrupt **p = &chain_list[index]; | |
| 548 | |
| 549 while( *p != NULL ) | |
| 550 { | |
| 551 cyg_interrupt *n = *p; | |
| 552 | |
| 553 if( n->priority < intr->priority ) break; | |
| 554 | |
| 555 p = &n->next; | |
| 556 } | |
| 557 next = *p; | |
| 558 *p = intr; | |
| 559 } | |
| 560 | |
| 561 #else | |
| 562 | |
| 563 HAL_INTERRUPT_ATTACH( intr->vector, intr->isr, intr->data, intr ); | |
| 564 | |
| 565 #endif | |
| 566 | |
| 567 CYG_REPORT_RETURN(); | |
| 568 } | |
| 569 | |
| 570 | |
| 571 //-------------------------------------------------------------------------- | |
| 572 // Detach an interrupt from its vector. | |
| 573 | |
| 574 externC void cyg_drv_interrupt_detach( cyg_handle_t interrupt ) | |
| 575 { | |
| 576 cyg_interrupt *intr = (cyg_interrupt *)interrupt; | |
| 577 | |
| 578 CYG_REPORT_FUNCTION(); | |
| 579 | |
| 580 CYG_ASSERT( intr->vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 581 CYG_ASSERT( intr->vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 582 | |
| 583 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 584 | |
| 585 // Remove the interrupt object from the vector chain. | |
| 586 | |
| 587 cyg_uint32 index; | |
| 588 | |
| 589 HAL_TRANSLATE_VECTOR( vector, index ); | |
| 590 | |
| 591 cyg_interrupt **p = &chain_list[index]; | |
| 592 | |
| 593 while( *p != NULL ) | |
| 594 { | |
| 595 cyg_interrupt *n = *p; | |
| 596 | |
| 597 if( n == intr ) | |
| 598 { | |
| 599 *p = intr->next; | |
| 600 break; | |
| 601 } | |
| 602 | |
| 603 p = &n->next; | |
| 604 } | |
| 605 | |
| 606 // If this was the last one, detach the vector. | |
| 607 | |
| 608 if( chain_list[index] == NULL ) | |
| 609 HAL_INTERRUPT_DETACH( intr->vector, chain_isr ); | |
| 610 | |
| 611 #else | |
| 612 | |
| 613 HAL_INTERRUPT_DETACH( intr->vector, intr->isr ); | |
| 614 | |
| 615 #endif | |
| 616 | |
| 617 CYG_REPORT_RETURN(); | |
| 618 } | |
| 619 | |
| 620 | |
| 621 //-------------------------------------------------------------------------- | |
| 622 // Mask delivery of an interrupt at the interrupt controller. | |
| 623 | |
| 624 externC void cyg_drv_interrupt_mask( cyg_vector_t vector ) | |
| 625 { | |
| 626 CYG_REPORT_FUNCTION(); | |
| 627 CYG_REPORT_FUNCARG1("vector=%d", vector); | |
| 628 | |
| 629 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 630 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 631 | |
| 632 HAL_INTERRUPT_MASK( vector ); | |
| 633 | |
| 634 CYG_REPORT_RETURN(); | |
| 635 } | |
| 636 | |
| 637 //-------------------------------------------------------------------------- | |
| 638 // Unmask delivery of an interrupt at the interrupt controller. | |
| 639 | |
| 640 externC void cyg_drv_interrupt_unmask( cyg_vector_t vector ) | |
| 641 { | |
| 642 CYG_REPORT_FUNCTION(); | |
| 643 | |
| 644 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 645 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 646 | |
| 647 HAL_INTERRUPT_UNMASK( vector ); | |
| 648 | |
| 649 CYG_REPORT_RETURN(); | |
| 650 } | |
| 651 | |
| 652 //-------------------------------------------------------------------------- | |
| 653 // Acknowledge an interrupt at the controller to allow another interrupt | |
| 654 // to be delivered. | |
| 655 | |
| 656 externC void cyg_drv_interrupt_acknowledge( cyg_vector_t vector ) | |
| 657 { | |
| 658 // CYG_REPORT_FUNCTION(); | |
| 659 | |
| 660 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 661 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 662 | |
| 663 HAL_INTERRUPT_ACKNOWLEDGE( vector ); | |
| 664 | |
| 665 // CYG_REPORT_RETURN(); | |
| 666 } | |
| 667 | |
| 668 //-------------------------------------------------------------------------- | |
| 669 // Configure interrupt detection parameters. | |
| 670 | |
| 671 externC void cyg_drv_interrupt_configure( | |
| 672 cyg_vector_t vector, | |
| 673 cyg_bool_t level, | |
| 674 cyg_bool_t up | |
| 675 ) | |
| 676 { | |
| 677 CYG_REPORT_FUNCTION(); | |
| 678 CYG_REPORT_FUNCARG3("vector = %d, level = %d, up = %d", vector, level, | |
| 679 up); | |
| 680 | |
| 681 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 682 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 683 | |
| 684 HAL_INTERRUPT_CONFIGURE( vector, level, up ); | |
| 685 | |
| 686 CYG_REPORT_RETURN(); | |
| 687 } | |
| 688 | |
| 689 //-------------------------------------------------------------------------- | |
| 690 // Configure interrupt priority level. | |
| 691 | |
| 692 externC void cyg_drv_interrupt_level( cyg_vector_t vector, cyg_priority_t level ) | |
| 693 { | |
| 694 CYG_REPORT_FUNCTION(); | |
| 695 CYG_REPORT_FUNCARG2("vector = %d, level = %d", vector, level); | |
| 696 | |
| 697 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 698 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 699 | |
| 700 HAL_INTERRUPT_SET_LEVEL( vector, level ); | |
| 701 | |
| 702 CYG_REPORT_RETURN(); | |
| 703 } | |
| 704 | |
| 705 | |
| 706 // ------------------------------------------------------------------------- | |
| 707 // Exception delivery function called from the HAL as a result of a | |
| 708 // hardware exception being raised. | |
| 709 | |
| 710 externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data ) | |
| 711 { | |
| 712 CYG_FAIL(" !!! Exception !!! "); | |
| 713 } | |
| 714 | |
| 715 | |
| 716 #endif | |
| 717 | |
| 718 //-------------------------------------------------------------------------- | |
| 719 // EOF drv_api.c |
