|
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 |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): nickg |
|
|
33 // Contributors: nickg |
|
|
34 // Date: 1998-07-14 |
|
|
35 // Purpose: Wallclock emulation |
|
|
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 |
|
|
48 #include <cyg/kernel/sched.hxx> |
|
|
49 #include <cyg/kernel/clock.hxx> |
|
|
50 |
|
|
51 #include <cyg/kernel/sched.inl> |
|
|
52 |
|
|
53 #ifdef CYGIMP_WALLCLOCK_EMULATE |
|
|
54 |
|
|
55 /*---------------------------------------------------------------------------*/ |
|
|
56 // Local static variables |
|
|
57 |
|
|
58 static Cyg_WallClock wallclock_instance CYG_INIT_PRIORITY( CLOCK ); |
|
|
59 |
|
|
60 static cyg_tick_count epoch_ticks; |
|
|
61 |
|
|
62 static cyg_uint32 epoch_time_stamp; |
|
|
63 |
|
|
64 Cyg_WallClock *Cyg_WallClock::wallclock; |
|
|
65 |
|
|
66 /*---------------------------------------------------------------------------*/ |
|
|
67 // Constructor |
|
|
68 |
|
|
69 Cyg_WallClock::Cyg_WallClock() |
|
|
70 { |
|
|
71 // install instance pointer |
|
|
72 wallclock = &wallclock_instance; |
|
|
73 } |
|
|
74 |
|
|
75 /*---------------------------------------------------------------------------*/ |
|
|
76 // Returns the current timestamp. This may involve reading the |
|
|
77 // hardware, so it may take anything up to a second to complete. |
|
|
78 |
|
|
79 cyg_uint32 Cyg_WallClock::get_current_time() |
|
|
80 { |
|
|
81 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); |
|
|
82 |
|
|
83 Cyg_Scheduler::lock(); |
|
|
84 |
|
|
85 cyg_tick_count diff = Cyg_Clock::real_time_clock->current_value() |
|
|
86 - epoch_ticks; |
|
|
87 |
|
|
88 diff = ( diff * res.dividend ) / ( res.divisor * 1000000000LL ) ; |
|
|
89 |
|
|
90 Cyg_Scheduler::unlock(); |
|
|
91 |
|
|
92 return epoch_time_stamp + diff; |
|
|
93 } |
|
|
94 |
|
|
95 /*---------------------------------------------------------------------------*/ |
|
|
96 // Sets the value of the timestamp relative to now. This may involve |
|
|
97 // writing to the hardware, so it may take anything up to a second to |
|
|
98 // complete. |
|
|
99 void Cyg_WallClock::set_current_time( cyg_uint32 time_stamp ) |
|
|
100 { |
|
|
101 Cyg_Scheduler::lock(); |
|
|
102 |
|
|
103 epoch_time_stamp = time_stamp; |
|
|
104 epoch_ticks = Cyg_Clock::real_time_clock->current_value(); |
|
|
105 |
|
|
106 Cyg_Scheduler::unlock(); |
|
|
107 } |
|
|
108 |
|
|
109 /*---------------------------------------------------------------------------*/ |
|
|
110 |
|
|
111 #endif |
|
|
112 /*---------------------------------------------------------------------------*/ |
|
|
113 /* End of devs/wallclock/emulate.cxx */ |