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