Mercurial > flash_v2
annotate packages/devs/wallclock/current/src/emulate.cxx @ 24:306eee292492 ecos-sw-1999-07-16
Merge from eCos master repository on 1999-07-16-05:47:06-BST
| author | jlarmour |
|---|---|
| date | Fri, 16 Jul 1999 21:54:32 +0000 |
| parents | 443894e2e912 |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 3 // devs/wallclock/emulate.cxx | |
| 4 // | |
| 5 // Wallclock emulation implementation | |
| 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 // | |
| 2 | 32 // Author(s): nickg |
| 0 | 33 // Contributors: nickg |
| 2 | 34 // Date: 1999-03-05 |
| 35 // Purpose: Wallclock emulation | |
| 0 | 36 // |
| 37 //####DESCRIPTIONEND#### | |
| 38 // | |
| 39 //========================================================================== | |
| 40 | |
| 41 #include <pkgconf/wallclock.h> // Wallclock device config | |
| 42 | |
|
24
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
43 #ifdef CYGIMP_WALLCLOCK_EMULATE |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
44 |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
45 #include <pkgconf/kernel.h> // Kernel config |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
46 |
| 0 | 47 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
| 48 #include <cyg/hal/hal_diag.h> // HAL diagnostic output | |
| 49 | |
| 50 #include <cyg/devs/wallclock.hxx> | |
| 51 | |
| 2 | 52 #include <cyg/kernel/ktypes.h> |
| 0 | 53 #include <cyg/kernel/sched.hxx> |
| 54 #include <cyg/kernel/clock.hxx> | |
| 55 | |
| 56 #include <cyg/kernel/sched.inl> | |
| 57 | |
| 58 | |
| 59 /*---------------------------------------------------------------------------*/ | |
| 60 // Local static variables | |
| 61 | |
| 62 static Cyg_WallClock wallclock_instance CYG_INIT_PRIORITY( CLOCK ); | |
| 63 | |
| 64 static cyg_tick_count epoch_ticks; | |
| 65 | |
| 66 static cyg_uint32 epoch_time_stamp; | |
| 67 | |
| 68 Cyg_WallClock *Cyg_WallClock::wallclock; | |
| 69 | |
| 70 /*---------------------------------------------------------------------------*/ | |
| 71 // Constructor | |
| 72 | |
| 73 Cyg_WallClock::Cyg_WallClock() | |
| 74 { | |
| 75 // install instance pointer | |
| 76 wallclock = &wallclock_instance; | |
| 77 } | |
| 78 | |
| 79 /*---------------------------------------------------------------------------*/ | |
| 80 // Returns the current timestamp. This may involve reading the | |
| 81 // hardware, so it may take anything up to a second to complete. | |
| 82 | |
| 83 cyg_uint32 Cyg_WallClock::get_current_time() | |
| 84 { | |
| 85 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); | |
| 86 | |
| 87 Cyg_Scheduler::lock(); | |
| 88 | |
| 89 cyg_tick_count diff = Cyg_Clock::real_time_clock->current_value() | |
| 90 - epoch_ticks; | |
| 91 | |
| 92 diff = ( diff * res.dividend ) / ( res.divisor * 1000000000LL ) ; | |
| 93 | |
| 94 Cyg_Scheduler::unlock(); | |
| 95 | |
| 96 return epoch_time_stamp + diff; | |
| 97 } | |
| 98 | |
| 99 /*---------------------------------------------------------------------------*/ | |
| 100 // Sets the value of the timestamp relative to now. This may involve | |
| 101 // writing to the hardware, so it may take anything up to a second to | |
| 102 // complete. | |
| 103 void Cyg_WallClock::set_current_time( cyg_uint32 time_stamp ) | |
| 104 { | |
| 105 Cyg_Scheduler::lock(); | |
| 106 | |
| 107 epoch_time_stamp = time_stamp; | |
| 108 epoch_ticks = Cyg_Clock::real_time_clock->current_value(); | |
| 109 | |
| 110 Cyg_Scheduler::unlock(); | |
| 111 } | |
| 112 | |
| 113 /*---------------------------------------------------------------------------*/ | |
| 114 | |
| 115 #endif | |
| 116 /*---------------------------------------------------------------------------*/ | |
| 117 /* End of devs/wallclock/emulate.cxx */ |
