|
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 |
|
|
43 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
|
|
44 #include <cyg/hal/hal_diag.h> // HAL diagnostic output |
|
|
45 |
|
|
46 #include <cyg/devs/wallclock.hxx> |
|
|
47 |
|
2
|
48 #include <cyg/kernel/ktypes.h> |
|
0
|
49 #include <cyg/kernel/sched.hxx> |
|
|
50 #include <cyg/kernel/clock.hxx> |
|
|
51 |
|
|
52 #include <cyg/kernel/sched.inl> |
|
|
53 |
|
|
54 #ifdef CYGIMP_WALLCLOCK_EMULATE |
|
|
55 |
|
|
56 /*---------------------------------------------------------------------------*/ |
|
|
57 // Local static variables |
|
|
58 |
|
|
59 static Cyg_WallClock wallclock_instance CYG_INIT_PRIORITY( CLOCK ); |
|
|
60 |
|
|
61 static cyg_tick_count epoch_ticks; |
|
|
62 |
|
|
63 static cyg_uint32 epoch_time_stamp; |
|
|
64 |
|
|
65 Cyg_WallClock *Cyg_WallClock::wallclock; |
|
|
66 |
|
|
67 /*---------------------------------------------------------------------------*/ |
|
|
68 // Constructor |
|
|
69 |
|
|
70 Cyg_WallClock::Cyg_WallClock() |
|
|
71 { |
|
|
72 // install instance pointer |
|
|
73 wallclock = &wallclock_instance; |
|
|
74 } |
|
|
75 |
|
|
76 /*---------------------------------------------------------------------------*/ |
|
|
77 // Returns the current timestamp. This may involve reading the |
|
|
78 // hardware, so it may take anything up to a second to complete. |
|
|
79 |
|
|
80 cyg_uint32 Cyg_WallClock::get_current_time() |
|
|
81 { |
|
|
82 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); |
|
|
83 |
|
|
84 Cyg_Scheduler::lock(); |
|
|
85 |
|
|
86 cyg_tick_count diff = Cyg_Clock::real_time_clock->current_value() |
|
|
87 - epoch_ticks; |
|
|
88 |
|
|
89 diff = ( diff * res.dividend ) / ( res.divisor * 1000000000LL ) ; |
|
|
90 |
|
|
91 Cyg_Scheduler::unlock(); |
|
|
92 |
|
|
93 return epoch_time_stamp + diff; |
|
|
94 } |
|
|
95 |
|
|
96 /*---------------------------------------------------------------------------*/ |
|
|
97 // Sets the value of the timestamp relative to now. This may involve |
|
|
98 // writing to the hardware, so it may take anything up to a second to |
|
|
99 // complete. |
|
|
100 void Cyg_WallClock::set_current_time( cyg_uint32 time_stamp ) |
|
|
101 { |
|
|
102 Cyg_Scheduler::lock(); |
|
|
103 |
|
|
104 epoch_time_stamp = time_stamp; |
|
|
105 epoch_ticks = Cyg_Clock::real_time_clock->current_value(); |
|
|
106 |
|
|
107 Cyg_Scheduler::unlock(); |
|
|
108 } |
|
|
109 |
|
|
110 /*---------------------------------------------------------------------------*/ |
|
|
111 |
|
|
112 #endif |
|
|
113 /*---------------------------------------------------------------------------*/ |
|
|
114 /* End of devs/wallclock/emulate.cxx */ |