Mercurial > flash_v2
comparison packages/kernel/current/src/common/clock.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 | 7253dcc42a09 |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 1 //========================================================================== | 1 //========================================================================== |
| 2 // | 2 // |
| 3 // common/clock.cxx | 3 // common/clock.cxx |
| 4 // | 4 // |
| 5 // Clock class implementations | 5 // Clock class implementations |
| 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 | 32 // Author(s): nickg |
| 33 // Contributors: nickg | 33 // Contributors: nickg |
| 34 // Date: 1997-09-15 | 34 // Date: 1997-09-15 |
| 35 // Purpose: Clock class implementation | 35 // Purpose: Clock class implementation |
| 36 // Description: This file contains the definitions of the counter, | 36 // Description: This file contains the definitions of the counter, |
| 37 // clock and alarm class member functions that are common | 37 // clock and alarm class member functions that are common |
| 38 // to all clock implementations. | 38 // to all clock implementations. |
| 39 // | 39 // |
| 40 //####DESCRIPTIONEND#### | 40 //####DESCRIPTIONEND#### |
| 105 // ------------------------------------------------------------------------- | 105 // ------------------------------------------------------------------------- |
| 106 // | 106 // |
| 107 | 107 |
| 108 #ifdef CYGDBG_USE_ASSERTS | 108 #ifdef CYGDBG_USE_ASSERTS |
| 109 | 109 |
| 110 bool Cyg_Counter::check_this( cyg_assert_class_zeal zeal) | 110 bool Cyg_Counter::check_this( cyg_assert_class_zeal zeal) const |
| 111 { | 111 { |
| 112 // check that we have a non-NULL pointer first | 112 // check that we have a non-NULL pointer first |
| 113 if( this == NULL ) return false; | 113 if( this == NULL ) return false; |
| 114 | 114 |
| 115 switch( zeal ) | 115 switch( zeal ) |
| 172 #endif | 172 #endif |
| 173 | 173 |
| 174 // Now that we have the list pointer, we can use common code for | 174 // Now that we have the list pointer, we can use common code for |
| 175 // both list oragnizations. | 175 // both list oragnizations. |
| 176 | 176 |
| 177 #ifdef CYGIMP_KERNEL_COUNTERS_SORT_LIST | |
| 178 | |
| 179 // With a sorted alarm list, we can simply pick alarms off the | |
| 180 // front of the list until we find one that is in the future. | |
| 181 | |
| 177 while( *alarm_list_ptr != NULL ) | 182 while( *alarm_list_ptr != NULL ) |
| 178 { | 183 { |
| 179 Cyg_Alarm *alarm = *alarm_list_ptr; | 184 Cyg_Alarm *alarm = *alarm_list_ptr; |
| 180 | 185 |
| 181 CYG_ASSERTCLASS(alarm, "Bad alarm in counter list" ); | 186 CYG_ASSERTCLASS(alarm, "Bad alarm in counter list" ); |
| 202 | 207 |
| 203 // all done, loop | 208 // all done, loop |
| 204 } | 209 } |
| 205 else break; | 210 else break; |
| 206 } | 211 } |
| 207 | 212 #else |
| 213 | |
| 214 // With an unsorted list, we must scan the whole list for | |
| 215 // candidates. We move the whole list to a temporary location | |
| 216 // before doing this so that we are not disturbed by new | |
| 217 // alarms being added to the list. As we consider and | |
| 218 // eliminate alarms we put them onto the done_list and at the | |
| 219 // end we then move it back to where it belongs. | |
| 220 | |
| 221 Cyg_Alarm *done_list = NULL; | |
| 222 | |
| 223 Cyg_Alarm *alarm_list = *alarm_list_ptr; | |
| 224 *alarm_list_ptr = NULL; | |
| 225 | |
| 226 while( alarm_list != NULL ) | |
| 227 { | |
| 228 Cyg_Alarm *alarm = alarm_list; | |
| 229 | |
| 230 CYG_ASSERTCLASS(alarm, "Bad alarm in counter list" ); | |
| 231 | |
| 232 // remove alarm from list | |
| 233 alarm_list = alarm->next; | |
| 234 | |
| 235 if( alarm->trigger <= counter ) | |
| 236 { | |
| 237 if( alarm->interval != 0 ) | |
| 238 { | |
| 239 // The alarm has a retrigger interval. | |
| 240 // Reset the trigger time and requeue | |
| 241 // the alarm. | |
| 242 alarm->trigger += alarm->interval; | |
| 243 add_alarm( alarm ); | |
| 244 } | |
| 245 else alarm->enabled = false; | |
| 246 | |
| 247 CYG_INSTRUMENT_ALARM( CALL, this, alarm ); | |
| 248 | |
| 249 // call alarm function | |
| 250 alarm->alarm(alarm, alarm->data); | |
| 251 | |
| 252 // all done, loop | |
| 253 } | |
| 254 else | |
| 255 { | |
| 256 // add unused alarm to done list. | |
| 257 alarm->next = done_list; | |
| 258 done_list = alarm; | |
| 259 } | |
| 260 } | |
| 261 | |
| 262 // Transfer any alarms that might have been added to the | |
| 263 // alarm list by alarm callbacks to the done list. This | |
| 264 // happens very rarely. | |
| 265 while( *alarm_list_ptr != NULL ) | |
| 266 { | |
| 267 Cyg_Alarm *alarm = *alarm_list_ptr; | |
| 268 *alarm_list_ptr = alarm->next; | |
| 269 alarm->next = done_list; | |
| 270 done_list = alarm; | |
| 271 } | |
| 272 | |
| 273 // return done list to real list | |
| 274 *alarm_list_ptr = done_list; | |
| 275 | |
| 276 #endif | |
| 208 Cyg_Scheduler::unlock(); | 277 Cyg_Scheduler::unlock(); |
| 209 | 278 |
| 210 } | 279 } |
| 211 | 280 |
| 212 } | 281 } |
| 285 | 354 |
| 286 #else | 355 #else |
| 287 #error "No CYGIMP_KERNEL_COUNTERS_x_LIST config" | 356 #error "No CYGIMP_KERNEL_COUNTERS_x_LIST config" |
| 288 #endif | 357 #endif |
| 289 | 358 |
| 290 | 359 #ifdef CYGIMP_KERNEL_COUNTERS_SORT_LIST |
| 360 | |
| 291 // Now that we have the list pointer, we can use common code for | 361 // Now that we have the list pointer, we can use common code for |
| 292 // both list oragnizations. | 362 // both list oragnizations. |
| 293 | 363 |
| 294 while( *alarm_list_ptr != NULL ) | 364 while( *alarm_list_ptr != NULL ) |
| 295 { | 365 { |
| 302 // it. | 372 // it. |
| 303 | 373 |
| 304 if( list_alarm->trigger > alarm->trigger ) break; | 374 if( list_alarm->trigger > alarm->trigger ) break; |
| 305 else alarm_list_ptr = &list_alarm->next; | 375 else alarm_list_ptr = &list_alarm->next; |
| 306 } | 376 } |
| 307 | 377 #endif |
| 308 // Insert the new alarm at *alarm_list_ptr | 378 // Insert the new alarm at *alarm_list_ptr |
| 309 | 379 |
| 310 alarm->next = *alarm_list_ptr; | 380 alarm->next = *alarm_list_ptr; |
| 311 *alarm_list_ptr = alarm; | 381 *alarm_list_ptr = alarm; |
| 312 | 382 |
| 391 // ------------------------------------------------------------------------- | 461 // ------------------------------------------------------------------------- |
| 392 // | 462 // |
| 393 | 463 |
| 394 #ifdef CYGDBG_USE_ASSERTS | 464 #ifdef CYGDBG_USE_ASSERTS |
| 395 | 465 |
| 396 bool Cyg_Clock::check_this( cyg_assert_class_zeal zeal) | 466 bool Cyg_Clock::check_this( cyg_assert_class_zeal zeal) const |
| 397 { | 467 { |
| 398 // check that we have a non-NULL pointer first | 468 // check that we have a non-NULL pointer first |
| 399 if( this == NULL ) return false; | 469 if( this == NULL ) return false; |
| 400 | 470 |
| 401 switch( zeal ) | 471 switch( zeal ) |
| 454 // ------------------------------------------------------------------------- | 524 // ------------------------------------------------------------------------- |
| 455 // | 525 // |
| 456 | 526 |
| 457 #ifdef CYGDBG_USE_ASSERTS | 527 #ifdef CYGDBG_USE_ASSERTS |
| 458 | 528 |
| 459 bool Cyg_Alarm::check_this( cyg_assert_class_zeal zeal) | 529 bool Cyg_Alarm::check_this( cyg_assert_class_zeal zeal) const |
| 460 { | 530 { |
| 461 // check that we have a non-NULL pointer first | 531 // check that we have a non-NULL pointer first |
| 462 if( this == NULL ) return false; | 532 if( this == NULL ) return false; |
| 463 | 533 |
| 464 switch( zeal ) | 534 switch( zeal ) |
| 575 | 645 |
| 576 // ------------------------------------------------------------------------- | 646 // ------------------------------------------------------------------------- |
| 577 | 647 |
| 578 Cyg_RealTimeClock::Cyg_RealTimeClock() | 648 Cyg_RealTimeClock::Cyg_RealTimeClock() |
| 579 : Cyg_Clock(rtc_resolution), | 649 : Cyg_Clock(rtc_resolution), |
| 580 interrupt(CYG_VECTOR_RTC, 1, (CYG_ADDRWORD)this, isr, dsr) | 650 interrupt(CYGNUM_HAL_INTERRUPT_RTC, 1, (CYG_ADDRWORD)this, isr, dsr) |
| 581 { | 651 { |
| 582 CYG_REPORT_FUNCTION(); | 652 CYG_REPORT_FUNCTION(); |
| 583 | 653 |
| 584 HAL_CLOCK_INITIALIZE( CYGNUM_KERNEL_COUNTERS_RTC_PERIOD ); | 654 HAL_CLOCK_INITIALIZE( CYGNUM_KERNEL_COUNTERS_RTC_PERIOD ); |
| 585 | 655 |
| 586 interrupt.attach(); | 656 interrupt.attach(); |
| 587 | 657 |
| 588 interrupt.unmask_interrupt(CYG_VECTOR_RTC); | 658 interrupt.unmask_interrupt(CYGNUM_HAL_INTERRUPT_RTC); |
| 589 | 659 |
| 590 Cyg_Clock::real_time_clock = this; | 660 Cyg_Clock::real_time_clock = this; |
| 591 } | 661 } |
| 592 | 662 |
| 663 #ifdef HAL_CLOCK_LATENCY | |
| 664 cyg_tick_count total_clock_latency, total_clock_interrupts; | |
| 665 cyg_int32 min_clock_latency = 0x7FFFFFFF; | |
| 666 cyg_int32 max_clock_latency = 0; | |
| 667 bool measure_clock_latency = false; | |
| 668 #endif | |
| 669 | |
| 593 // ------------------------------------------------------------------------- | 670 // ------------------------------------------------------------------------- |
| 594 | 671 |
| 595 cyg_uint32 Cyg_RealTimeClock::isr(cyg_vector vector, CYG_ADDRWORD data) | 672 cyg_uint32 Cyg_RealTimeClock::isr(cyg_vector vector, CYG_ADDRWORD data) |
| 596 { | 673 { |
| 597 // CYG_REPORT_FUNCTION(); | 674 // CYG_REPORT_FUNCTION(); |
| 598 | 675 |
| 676 #ifdef HAL_CLOCK_LATENCY | |
| 677 if (measure_clock_latency) { | |
| 678 cyg_int32 delta; | |
| 679 HAL_CLOCK_LATENCY(&delta); | |
| 680 // Note: Ignore a latency of 0 when finding min_clock_latency. | |
| 681 if (delta > 0) { | |
| 682 // Valid delta measured | |
| 683 total_clock_latency += delta; | |
| 684 total_clock_interrupts++; | |
| 685 if (min_clock_latency > delta) min_clock_latency = delta; | |
| 686 if (max_clock_latency < delta) max_clock_latency = delta; | |
| 687 } | |
| 688 } | |
| 689 #endif | |
| 690 | |
| 599 CYG_INSTRUMENT_CLOCK( ISR, 0, 0); | 691 CYG_INSTRUMENT_CLOCK( ISR, 0, 0); |
| 600 | 692 |
| 601 HAL_CLOCK_RESET( CYG_VECTOR_RTC, CYGNUM_KERNEL_COUNTERS_RTC_PERIOD ); | 693 HAL_CLOCK_RESET( CYGNUM_HAL_INTERRUPT_RTC, CYGNUM_KERNEL_COUNTERS_RTC_PERIOD ); |
| 602 | 694 |
| 603 Cyg_Interrupt::acknowledge_interrupt(CYG_VECTOR_RTC); | 695 Cyg_Interrupt::acknowledge_interrupt(CYGNUM_HAL_INTERRUPT_RTC); |
| 604 | 696 |
| 605 return Cyg_Interrupt::CALL_DSR; | 697 return Cyg_Interrupt::CALL_DSR; |
| 606 } | 698 } |
| 607 | 699 |
| 608 // ------------------------------------------------------------------------- | 700 // ------------------------------------------------------------------------- |
