Mercurial > ecos
annotate packages/hal/common/current/src/drv_api.c @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | d376b777e2ce |
| children | bf00f99aec69 |
| 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 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
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 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
14 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
15 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
6
diff
changeset
|
16 // Software distributed under the License is distributed on an |
|
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 | |
| 406 externC void cyg_drv_cond_wait( cyg_drv_cond_t *cond ) | |
| 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 | |
| 430 CYG_REPORT_RETURN(); | |
| 431 } | |
| 432 | |
| 433 //-------------------------------------------------------------------------- | |
| 434 // Signal a condition variable. This sets the wait member to zero, which | |
| 435 // has no effect when there is no waiter, but will wake up any waiting | |
| 436 // thread. | |
| 437 | |
| 438 externC void cyg_drv_cond_signal( cyg_drv_cond_t *cond ) | |
| 439 { | |
| 440 CYG_REPORT_FUNCTION(); | |
| 441 | |
| 442 cond->wait = 0; | |
| 443 | |
| 444 CYG_REPORT_RETURN(); | |
| 445 } | |
| 446 | |
| 447 | |
| 448 //-------------------------------------------------------------------------- | |
| 449 // Broadcast to condition variable. This is exactly the same a signal since | |
| 450 // there can only be one waiter. | |
| 451 | |
| 452 externC void cyg_drv_cond_broadcast( cyg_drv_cond_t *cond ) | |
| 453 { | |
| 454 CYG_REPORT_FUNCTION(); | |
| 455 | |
| 456 cond->wait = 0; | |
| 457 | |
| 458 CYG_REPORT_RETURN(); | |
| 459 } | |
| 460 | |
| 461 | |
| 462 //-------------------------------------------------------------------------- | |
| 463 // Create an interrupt object. | |
| 464 | |
| 465 externC void cyg_drv_interrupt_create( | |
| 466 cyg_vector_t vector, | |
| 467 cyg_priority_t priority, | |
| 468 cyg_addrword_t data, | |
| 469 cyg_ISR_t *isr, | |
| 470 cyg_DSR_t *dsr, | |
| 471 cyg_handle_t *handle, | |
| 472 cyg_interrupt *intr | |
| 473 ) | |
| 474 { | |
| 475 CYG_REPORT_FUNCTION(); | |
| 476 | |
| 477 intr->vector = vector; | |
| 478 intr->priority = priority; | |
| 479 intr->isr = isr; | |
| 480 intr->dsr = dsr; | |
| 481 intr->data = data; | |
| 482 intr->next_dsr = NULL; | |
| 483 intr->dsr_count = 0; | |
| 484 | |
| 485 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 486 | |
| 487 intr->next = NULL; | |
| 488 | |
| 489 #endif | |
| 490 | |
| 491 *handle = (cyg_handle_t)intr; | |
| 492 | |
| 493 CYG_REPORT_RETURN(); | |
| 494 } | |
| 495 | |
| 496 //-------------------------------------------------------------------------- | |
| 497 // Delete an interrupt object. This merely ensures that it is detached from | |
| 498 // the vector. | |
| 499 | |
| 500 externC void cyg_drv_interrupt_delete( cyg_handle_t interrupt ) | |
| 501 { | |
| 502 CYG_REPORT_FUNCTION(); | |
| 503 | |
| 504 cyg_drv_interrupt_detach( interrupt ); | |
| 505 | |
| 506 CYG_REPORT_RETURN(); | |
| 507 } | |
| 508 | |
| 509 //-------------------------------------------------------------------------- | |
| 510 // | |
| 511 | |
| 512 externC void cyg_drv_interrupt_attach( cyg_handle_t interrupt ) | |
| 513 { | |
| 514 cyg_interrupt *intr = (cyg_interrupt *)interrupt; | |
| 515 | |
| 516 CYG_REPORT_FUNCTION(); | |
| 517 | |
| 518 CYG_ASSERT( intr->vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 519 CYG_ASSERT( intr->vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 520 | |
| 521 HAL_INTERRUPT_SET_LEVEL( intr->vector, intr->priority ); | |
| 522 | |
| 523 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 524 | |
| 525 CYG_ASSERT( intr->next == NULL , "cyg_interrupt already on a list"); | |
| 526 | |
| 527 cyg_uint32 index; | |
| 528 | |
| 529 HAL_TRANSLATE_VECTOR( intr->vector, index ); | |
| 530 | |
| 531 if( chain_list[index] == NULL ) | |
| 532 { | |
| 533 // First Interrupt on this chain, just assign it and register | |
| 534 // the chain_isr with the HAL. | |
| 535 | |
| 536 chain_list[index] = intr; | |
| 537 | |
| 538 HAL_INTERRUPT_ATTACH( intr->vector, chain_isr, &chain_list[index], NULL ); | |
| 539 } | |
| 540 else | |
| 541 { | |
| 542 // There are already interrupts chained, add this one into the | |
| 543 // chain in priority order. | |
| 544 | |
| 545 Cyg_Interrupt **p = &chain_list[index]; | |
| 546 | |
| 547 while( *p != NULL ) | |
| 548 { | |
| 549 cyg_interrupt *n = *p; | |
| 550 | |
| 551 if( n->priority < intr->priority ) break; | |
| 552 | |
| 553 p = &n->next; | |
| 554 } | |
| 555 next = *p; | |
| 556 *p = intr; | |
| 557 } | |
| 558 | |
| 559 #else | |
| 560 | |
| 561 HAL_INTERRUPT_ATTACH( intr->vector, intr->isr, intr->data, intr ); | |
| 562 | |
| 563 #endif | |
| 564 | |
| 565 CYG_REPORT_RETURN(); | |
| 566 } | |
| 567 | |
| 568 | |
| 569 //-------------------------------------------------------------------------- | |
| 570 // Detach an interrupt from its vector. | |
| 571 | |
| 572 externC void cyg_drv_interrupt_detach( cyg_handle_t interrupt ) | |
| 573 { | |
| 574 cyg_interrupt *intr = (cyg_interrupt *)interrupt; | |
| 575 | |
| 576 CYG_REPORT_FUNCTION(); | |
| 577 | |
| 578 CYG_ASSERT( intr->vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 579 CYG_ASSERT( intr->vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 580 | |
| 581 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN | |
| 582 | |
| 583 // Remove the interrupt object from the vector chain. | |
| 584 | |
| 585 cyg_uint32 index; | |
| 586 | |
| 587 HAL_TRANSLATE_VECTOR( vector, index ); | |
| 588 | |
| 589 cyg_interrupt **p = &chain_list[index]; | |
| 590 | |
| 591 while( *p != NULL ) | |
| 592 { | |
| 593 cyg_interrupt *n = *p; | |
| 594 | |
| 595 if( n == intr ) | |
| 596 { | |
| 597 *p = intr->next; | |
| 598 break; | |
| 599 } | |
| 600 | |
| 601 p = &n->next; | |
| 602 } | |
| 603 | |
| 604 // If this was the last one, detach the vector. | |
| 605 | |
| 606 if( chain_list[index] == NULL ) | |
| 607 HAL_INTERRUPT_DETACH( intr->vector, chain_isr ); | |
| 608 | |
| 609 #else | |
| 610 | |
| 611 HAL_INTERRUPT_DETACH( intr->vector, intr->isr ); | |
| 612 | |
| 613 #endif | |
| 614 | |
| 615 CYG_REPORT_RETURN(); | |
| 616 } | |
| 617 | |
| 618 | |
| 619 //-------------------------------------------------------------------------- | |
| 620 // Mask delivery of an interrupt at the interrupt controller. | |
| 621 | |
| 622 externC void cyg_drv_interrupt_mask( cyg_vector_t vector ) | |
| 623 { | |
| 624 CYG_REPORT_FUNCTION(); | |
| 625 CYG_REPORT_FUNCARG1("vector=%d", vector); | |
| 626 | |
| 627 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 628 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 629 | |
| 630 HAL_INTERRUPT_MASK( vector ); | |
| 631 | |
| 632 CYG_REPORT_RETURN(); | |
| 633 } | |
| 634 | |
| 635 //-------------------------------------------------------------------------- | |
| 636 // Unmask delivery of an interrupt at the interrupt controller. | |
| 637 | |
| 638 externC void cyg_drv_interrupt_unmask( cyg_vector_t vector ) | |
| 639 { | |
| 640 CYG_REPORT_FUNCTION(); | |
| 641 | |
| 642 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 643 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 644 | |
| 645 HAL_INTERRUPT_UNMASK( vector ); | |
| 646 | |
| 647 CYG_REPORT_RETURN(); | |
| 648 } | |
| 649 | |
| 650 //-------------------------------------------------------------------------- | |
| 651 // Acknowledge an interrupt at the controller to allow another interrupt | |
| 652 // to be delivered. | |
| 653 | |
| 654 externC void cyg_drv_interrupt_acknowledge( cyg_vector_t vector ) | |
| 655 { | |
| 656 // CYG_REPORT_FUNCTION(); | |
| 657 | |
| 658 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 659 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 660 | |
| 661 HAL_INTERRUPT_ACKNOWLEDGE( vector ); | |
| 662 | |
| 663 // CYG_REPORT_RETURN(); | |
| 664 } | |
| 665 | |
| 666 //-------------------------------------------------------------------------- | |
| 667 // Configure interrupt detection parameters. | |
| 668 | |
| 669 externC void cyg_drv_interrupt_configure( | |
| 670 cyg_vector_t vector, | |
| 671 cyg_bool_t level, | |
| 672 cyg_bool_t up | |
| 673 ) | |
| 674 { | |
| 675 CYG_REPORT_FUNCTION(); | |
| 676 CYG_REPORT_FUNCARG3("vector = %d, level = %d, up = %d", vector, level, | |
| 677 up); | |
| 678 | |
| 679 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 680 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 681 | |
| 682 HAL_INTERRUPT_CONFIGURE( vector, level, up ); | |
| 683 | |
| 684 CYG_REPORT_RETURN(); | |
| 685 } | |
| 686 | |
| 687 //-------------------------------------------------------------------------- | |
| 688 // Configure interrupt priority level. | |
| 689 | |
| 690 externC void cyg_drv_interrupt_level( cyg_vector_t vector, cyg_priority_t level ) | |
| 691 { | |
| 692 CYG_REPORT_FUNCTION(); | |
| 693 CYG_REPORT_FUNCARG2("vector = %d, level = %d", vector, level); | |
| 694 | |
| 695 CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); | |
| 696 CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); | |
| 697 | |
| 698 HAL_INTERRUPT_SET_LEVEL( vector, level ); | |
| 699 | |
| 700 CYG_REPORT_RETURN(); | |
| 701 } | |
| 702 | |
| 703 | |
| 704 // ------------------------------------------------------------------------- | |
| 705 // Exception delivery function called from the HAL as a result of a | |
| 706 // hardware exception being raised. | |
| 707 | |
| 708 externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data ) | |
| 709 { | |
| 710 CYG_FAIL(" !!! Exception !!! "); | |
| 711 } | |
| 712 | |
| 713 | |
| 714 #endif | |
| 715 | |
| 716 //-------------------------------------------------------------------------- | |
| 717 // EOF drv_api.c |
