Mercurial > ecos
comparison packages/kernel/current/src/common/kapi.cxx @ 2:443894e2e912 ecos-v1_2_1-release
Block commit of eCos version 1.2.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 12:24:34 +0000 |
| parents | 3111d98ba7b3 |
| children | 1d7f19c9e4d1 |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 1 //========================================================================== | 1 //========================================================================== |
| 2 // | 2 // |
| 3 // common/kapi.cxx | 3 // common/kapi.cxx |
| 4 // | 4 // |
| 5 // C API Implementation | 5 // C API Implementation |
| 6 // | 6 // |
| 7 //========================================================================== | 7 //========================================================================== |
| 8 //####COPYRIGHTBEGIN#### | 8 //####COPYRIGHTBEGIN#### |
| 9 // | 9 // |
| 10 // ------------------------------------------- | 10 // ------------------------------------------- |
| 20 // | 20 // |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | 21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
| 22 // September 30, 1998. | 22 // September 30, 1998. |
| 23 // | 23 // |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | 24 // The Initial Developer of the Original Code is Cygnus. Portions created |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 26 // ------------------------------------------- | 26 // ------------------------------------------- |
| 27 // | 27 // |
| 28 //####COPYRIGHTEND#### | 28 //####COPYRIGHTEND#### |
| 29 //========================================================================== | 29 //========================================================================== |
| 30 //#####DESCRIPTIONBEGIN#### | 30 //#####DESCRIPTIONBEGIN#### |
| 31 // | 31 // |
| 32 // Author(s): nickg, dsm | 32 // Author(s): nickg, dsm |
| 33 // Contributors: nickg | 33 // Contributors: nickg |
| 34 // Date: 1998-03-02 | 34 // Date: 1998-03-02 |
| 35 // Purpose: C API Implementation | 35 // Purpose: C API Implementation |
| 36 // Description: C++ implementation of the C API | 36 // Description: C++ implementation of the C API |
| 37 // | 37 // |
| 38 // | 38 // |
| 39 //####DESCRIPTIONEND#### | 39 //####DESCRIPTIONEND#### |
| 40 // | 40 // |
| 41 //========================================================================== | 41 //========================================================================== |
| 132 | 132 |
| 133 /*---------------------------------------------------------------------------*/ | 133 /*---------------------------------------------------------------------------*/ |
| 134 /* Thread operations */ | 134 /* Thread operations */ |
| 135 | 135 |
| 136 externC void cyg_thread_create( | 136 externC void cyg_thread_create( |
| 137 cyg_addrword_t sched_info, /* scheduling info (eg pri) */ | 137 cyg_addrword_t sched_info, /* scheduling info (eg pri) */ |
| 138 cyg_thread_entry_t *entry, /* entry point function */ | 138 cyg_thread_entry_t *entry, /* entry point function */ |
| 139 cyg_addrword_t entry_data, /* entry data */ | 139 cyg_addrword_t entry_data, /* entry data */ |
| 140 char *name, /* optional thread name */ | 140 char *name, /* optional thread name */ |
| 141 void *stack_base, /* stack base, NULL = alloc */ | 141 void *stack_base, /* stack base, NULL = alloc */ |
| 142 cyg_ucount32 stack_size, /* stack size, 0 = default */ | 142 cyg_ucount32 stack_size, /* stack size, 0 = default */ |
| 143 cyg_handle_t *handle, /* returned thread handle */ | 143 cyg_handle_t *handle, /* returned thread handle */ |
| 144 cyg_thread *thread /* put thread here */ | 144 cyg_thread *thread /* put thread here */ |
| 149 Cyg_Thread *t = new((void *)thread) Cyg_Thread ( | 149 Cyg_Thread *t = new((void *)thread) Cyg_Thread ( |
| 150 (CYG_ADDRWORD) sched_info, | 150 (CYG_ADDRWORD) sched_info, |
| 151 (cyg_thread_entry *)entry, | 151 (cyg_thread_entry *)entry, |
| 152 (CYG_ADDRWORD) entry_data, | 152 (CYG_ADDRWORD) entry_data, |
| 153 name, | 153 name, |
| 154 (CYG_ADDRWORD) stack_base, | 154 (CYG_ADDRWORD) stack_base, |
| 155 stack_size | 155 stack_size |
| 156 ); | 156 ); |
| 157 t=t; | 157 t=t; |
| 158 | 158 |
| 159 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); | 159 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); |
| 160 *handle = (cyg_handle_t)thread; | 160 *handle = (cyg_handle_t)thread; |
| 163 externC void cyg_thread_exit() | 163 externC void cyg_thread_exit() |
| 164 { | 164 { |
| 165 Cyg_Thread::exit(); | 165 Cyg_Thread::exit(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 externC void cyg_thread_delete( cyg_handle_t thread ) | |
| 169 { | |
| 170 Cyg_Thread *th = (Cyg_Thread *)thread; | |
| 171 if( th->get_state() != Cyg_Thread::EXITED ) | |
| 172 th->kill(); | |
| 173 th->~Cyg_Thread(); | |
| 174 } | |
| 175 | |
| 168 externC void cyg_thread_suspend(cyg_handle_t thread) | 176 externC void cyg_thread_suspend(cyg_handle_t thread) |
| 169 { | 177 { |
| 170 ((Cyg_Thread *)thread)->suspend(); | 178 ((Cyg_Thread *)thread)->suspend(); |
| 171 } | 179 } |
| 172 | 180 |
| 184 } | 192 } |
| 185 | 193 |
| 186 externC void cyg_thread_kill( cyg_handle_t thread) | 194 externC void cyg_thread_kill( cyg_handle_t thread) |
| 187 { | 195 { |
| 188 ((Cyg_Thread *)thread)->kill(); | 196 ((Cyg_Thread *)thread)->kill(); |
| 197 } | |
| 198 | |
| 199 externC void cyg_thread_release( cyg_handle_t thread) | |
| 200 { | |
| 201 ((Cyg_Thread *)thread)->release(); | |
| 189 } | 202 } |
| 190 | 203 |
| 191 externC void cyg_thread_yield() | 204 externC void cyg_thread_yield() |
| 192 { | 205 { |
| 193 Cyg_Thread::yield(); | 206 Cyg_Thread::yield(); |
| 224 externC void cyg_thread_delay(cyg_tick_count_t delay) | 237 externC void cyg_thread_delay(cyg_tick_count_t delay) |
| 225 { | 238 { |
| 226 Cyg_Thread::self()->delay(delay); | 239 Cyg_Thread::self()->delay(delay); |
| 227 } | 240 } |
| 228 | 241 |
| 242 /*---------------------------------------------------------------------------*/ | |
| 243 /* Per-thread data */ | |
| 244 | |
| 245 #ifdef CYGVAR_KERNEL_THREADS_DATA | |
| 246 | |
| 247 externC cyg_ucount32 cyg_thread_new_data_index() | |
| 248 { | |
| 249 return Cyg_Thread::new_data_index(); | |
| 250 } | |
| 251 | |
| 252 externC void cyg_thread_free_data_index(cyg_ucount32 index) | |
| 253 { | |
| 254 Cyg_Thread::free_data_index(index); | |
| 255 } | |
| 256 | |
| 257 externC CYG_ADDRWORD cyg_thread_get_data(cyg_ucount32 index) | |
| 258 { | |
| 259 return Cyg_Thread::get_data(index); | |
| 260 } | |
| 261 | |
| 262 externC CYG_ADDRWORD *cyg_thread_get_data_ptr(cyg_ucount32 index) | |
| 263 { | |
| 264 return Cyg_Thread::get_data_ptr(index); | |
| 265 } | |
| 266 | |
| 267 externC void cyg_thread_set_data(cyg_ucount32 index, CYG_ADDRWORD | |
| 268 data) | |
| 269 { | |
| 270 Cyg_Thread::self()->set_data(index, data); | |
| 271 } | |
| 272 #endif | |
| 229 | 273 |
| 230 /*---------------------------------------------------------------------------*/ | 274 /*---------------------------------------------------------------------------*/ |
| 231 /* Exception handling. */ | 275 /* Exception handling. */ |
| 232 | 276 |
| 233 #ifdef CYGPKG_KERNEL_EXCEPTIONS | 277 #ifdef CYGPKG_KERNEL_EXCEPTIONS |
| 234 externC void cyg_exception_set_handler( | 278 externC void cyg_exception_set_handler( |
| 235 cyg_code_t exception_number, | 279 cyg_code_t exception_number, |
| 236 cyg_exception_handler_t *new_handler, | 280 cyg_exception_handler_t *new_handler, |
| 237 cyg_addrword_t new_data, | 281 cyg_addrword_t new_data, |
| 238 cyg_exception_handler_t **old_handler, | 282 cyg_exception_handler_t **old_handler, |
| 239 cyg_addrword_t *old_data | 283 cyg_addrword_t *old_data |
| 240 ) | 284 ) |
| 241 { | 285 { |
| 242 Cyg_Thread::register_exception( | 286 Cyg_Thread::register_exception( |
| 243 exception_number, | 287 exception_number, |
| 244 (cyg_exception_handler *)new_handler, | 288 (cyg_exception_handler *)new_handler, |
| 258 | 302 |
| 259 /* Invoke exception handler */ | 303 /* Invoke exception handler */ |
| 260 externC void cyg_exception_call_handler( | 304 externC void cyg_exception_call_handler( |
| 261 cyg_handle_t thread, | 305 cyg_handle_t thread, |
| 262 cyg_code_t exception_number, | 306 cyg_code_t exception_number, |
| 263 cyg_code_t error_code | 307 cyg_addrword_t error_code |
| 264 ) | 308 ) |
| 265 { | 309 { |
| 266 Cyg_Thread *t = (Cyg_Thread *)thread; | 310 Cyg_Thread *t = (Cyg_Thread *)thread; |
| 267 | 311 |
| 268 t->deliver_exception( exception_number, error_code ); | 312 t->deliver_exception( exception_number, error_code ); |
| 273 /* Interrupt handling */ | 317 /* Interrupt handling */ |
| 274 | 318 |
| 275 externC void cyg_interrupt_create( | 319 externC void cyg_interrupt_create( |
| 276 cyg_vector_t vector, /* Vector to attach to */ | 320 cyg_vector_t vector, /* Vector to attach to */ |
| 277 cyg_priority_t priority, /* Queue priority */ | 321 cyg_priority_t priority, /* Queue priority */ |
| 278 cyg_addrword_t data, /* Data pointer */ | 322 cyg_addrword_t data, /* Data pointer */ |
| 279 cyg_ISR_t *isr, /* Interrupt Service Routine */ | 323 cyg_ISR_t *isr, /* Interrupt Service Routine */ |
| 280 cyg_DSR_t *dsr, /* Deferred Service Routine */ | 324 cyg_DSR_t *dsr, /* Deferred Service Routine */ |
| 281 cyg_handle_t *handle, /* returned handle */ | 325 cyg_handle_t *handle, /* returned handle */ |
| 282 cyg_interrupt *intr /* put interrupt here */ | 326 cyg_interrupt *intr /* put interrupt here */ |
| 283 ) | 327 ) |
| 487 #endif | 531 #endif |
| 488 | 532 |
| 489 externC void cyg_alarm_create( | 533 externC void cyg_alarm_create( |
| 490 cyg_handle_t counter, /* Attached to this counter */ | 534 cyg_handle_t counter, /* Attached to this counter */ |
| 491 cyg_alarm_t *alarmfn, /* Call-back function */ | 535 cyg_alarm_t *alarmfn, /* Call-back function */ |
| 492 cyg_addrword_t data, /* Call-back data */ | 536 cyg_addrword_t data, /* Call-back data */ |
| 493 cyg_handle_t *handle, /* Returned alarm object */ | 537 cyg_handle_t *handle, /* Returned alarm object */ |
| 494 cyg_alarm *alarm /* put alarm here */ | 538 cyg_alarm *alarm /* put alarm here */ |
| 495 ) | 539 ) |
| 496 { | 540 { |
| 497 CYG_ASSERT_SIZES( cyg_alarm, Cyg_Alarm ); | 541 CYG_ASSERT_SIZES( cyg_alarm, Cyg_Alarm ); |
| 498 | 542 |
| 499 Cyg_Alarm *t = new((void *)alarm) Cyg_Alarm ( | 543 Cyg_Alarm *t = new((void *)alarm) Cyg_Alarm ( |
| 500 (Cyg_Counter *)counter, | 544 (Cyg_Counter *)counter, |
| 501 (cyg_alarm_fn *)alarmfn, | 545 (cyg_alarm_fn *)alarmfn, |
| 502 (CYG_ADDRWORD)data | 546 (CYG_ADDRWORD)data |
| 503 ); | 547 ); |
| 504 t=t; | 548 t=t; |
| 505 | 549 |
| 506 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); | 550 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); |
| 507 *handle = (cyg_handle_t)alarm; | 551 *handle = (cyg_handle_t)alarm; |
| 518 cyg_tick_count_t trigger, /* Absolute trigger time */ | 562 cyg_tick_count_t trigger, /* Absolute trigger time */ |
| 519 cyg_tick_count_t interval /* Relative retrigger interval */ | 563 cyg_tick_count_t interval /* Relative retrigger interval */ |
| 520 ) | 564 ) |
| 521 { | 565 { |
| 522 ((Cyg_Alarm *)alarm)->initialize( | 566 ((Cyg_Alarm *)alarm)->initialize( |
| 523 (cyg_tick_count)trigger, | 567 (cyg_tick_count)trigger, |
| 524 (cyg_tick_count)interval); | 568 (cyg_tick_count)interval); |
| 525 } | 569 } |
| 526 | 570 |
| 527 externC void cyg_alarm_enable( cyg_handle_t alarm ) | 571 externC void cyg_alarm_enable( cyg_handle_t alarm ) |
| 528 { | 572 { |
| 529 ((Cyg_Alarm *)alarm)->enable(); | 573 ((Cyg_Alarm *)alarm)->enable(); |
| 633 { | 677 { |
| 634 CYG_ASSERT_SIZES( cyg_mempool_var, Cyg_Mempool_Variable ); | 678 CYG_ASSERT_SIZES( cyg_mempool_var, Cyg_Mempool_Variable ); |
| 635 | 679 |
| 636 Cyg_Mempool_Variable *t = new((void *)var) Cyg_Mempool_Variable ( | 680 Cyg_Mempool_Variable *t = new((void *)var) Cyg_Mempool_Variable ( |
| 637 (cyg_uint8 *)base, | 681 (cyg_uint8 *)base, |
| 638 size | 682 size |
| 639 ); | 683 ); |
| 640 t=t; | 684 t=t; |
| 641 | 685 |
| 642 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); | 686 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); |
| 643 *handle = (cyg_handle_t)var; | 687 *handle = (cyg_handle_t)var; |
| 726 { | 770 { |
| 727 CYG_ASSERT_SIZES( cyg_mempool_fix, Cyg_Mempool_Fixed ); | 771 CYG_ASSERT_SIZES( cyg_mempool_fix, Cyg_Mempool_Fixed ); |
| 728 | 772 |
| 729 Cyg_Mempool_Fixed *t = new((void *)fix) Cyg_Mempool_Fixed ( | 773 Cyg_Mempool_Fixed *t = new((void *)fix) Cyg_Mempool_Fixed ( |
| 730 (cyg_uint8 *)base, | 774 (cyg_uint8 *)base, |
| 731 size, | 775 size, |
| 732 blocksize | 776 blocksize |
| 733 ); | 777 ); |
| 734 t=t; | 778 t=t; |
| 735 | 779 |
| 736 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); | 780 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); |
| 805 /*---------------------------------------------------------------------------*/ | 849 /*---------------------------------------------------------------------------*/ |
| 806 /* Semaphores */ | 850 /* Semaphores */ |
| 807 | 851 |
| 808 externC void cyg_semaphore_init( | 852 externC void cyg_semaphore_init( |
| 809 cyg_sem_t *sem, /* Semaphore to init */ | 853 cyg_sem_t *sem, /* Semaphore to init */ |
| 810 cyg_ucount32 val /* Initial semaphore value */ | 854 cyg_count32 val /* Initial semaphore value */ |
| 811 ) | 855 ) |
| 812 { | 856 { |
| 813 CYG_ASSERT_SIZES( cyg_sem_t, Cyg_Counting_Semaphore ); | 857 CYG_ASSERT_SIZES( cyg_sem_t, Cyg_Counting_Semaphore ); |
| 814 | 858 |
| 815 Cyg_Counting_Semaphore *t = new((void *)sem) Cyg_Counting_Semaphore(val); | 859 Cyg_Counting_Semaphore *t = new((void *)sem) Cyg_Counting_Semaphore(val); |
| 845 externC void cyg_semaphore_post( cyg_sem_t *sem ) | 889 externC void cyg_semaphore_post( cyg_sem_t *sem ) |
| 846 { | 890 { |
| 847 ((Cyg_Counting_Semaphore *)sem)->post(); | 891 ((Cyg_Counting_Semaphore *)sem)->post(); |
| 848 } | 892 } |
| 849 | 893 |
| 850 externC void cyg_semaphore_peek( cyg_sem_t *sem, cyg_ucount32 *val ) | 894 externC void cyg_semaphore_peek( cyg_sem_t *sem, cyg_count32 *val ) |
| 851 { | 895 { |
| 852 CYG_CHECK_DATA_PTR( val, "Bad val parameter" ); | 896 CYG_CHECK_DATA_PTR( val, "Bad val parameter" ); |
| 853 | 897 |
| 854 *val = ((Cyg_Counting_Semaphore *)sem)->peek(); | 898 *val = ((Cyg_Counting_Semaphore *)sem)->peek(); |
| 855 } | 899 } |
| 948 externC void cyg_mutex_destroy( cyg_mutex_t *mutex ) | 992 externC void cyg_mutex_destroy( cyg_mutex_t *mutex ) |
| 949 { | 993 { |
| 950 // no need to do anything here | 994 // no need to do anything here |
| 951 } | 995 } |
| 952 | 996 |
| 953 externC void cyg_mutex_lock( cyg_mutex_t *mutex ) | 997 externC cyg_bool_t cyg_mutex_lock( cyg_mutex_t *mutex ) |
| 954 { | 998 { |
| 955 ((Cyg_Mutex *)mutex)->lock(); | 999 return ((Cyg_Mutex *)mutex)->lock(); |
| 956 } | 1000 } |
| 957 | 1001 |
| 958 externC cyg_bool_t cyg_mutex_trylock( cyg_mutex_t *mutex ) | 1002 externC cyg_bool_t cyg_mutex_trylock( cyg_mutex_t *mutex ) |
| 959 { | 1003 { |
| 960 return ((Cyg_Mutex *)mutex)->trylock(); | 1004 return ((Cyg_Mutex *)mutex)->trylock(); |
| 961 } | 1005 } |
| 962 | 1006 |
| 963 externC void cyg_mutex_unlock( cyg_mutex_t *mutex ) | 1007 externC void cyg_mutex_unlock( cyg_mutex_t *mutex ) |
| 964 { | 1008 { |
| 965 ((Cyg_Mutex *)mutex)->unlock(); | 1009 ((Cyg_Mutex *)mutex)->unlock(); |
| 1010 } | |
| 1011 | |
| 1012 externC void cyg_mutex_release( cyg_mutex_t *mutex ) | |
| 1013 { | |
| 1014 ((Cyg_Mutex *)mutex)->release(); | |
| 966 } | 1015 } |
| 967 | 1016 |
| 968 /*---------------------------------------------------------------------------*/ | 1017 /*---------------------------------------------------------------------------*/ |
| 969 /* Condition Variables */ | 1018 /* Condition Variables */ |
| 970 | 1019 |
