Mercurial > flash_v2
annotate packages/kernel/current/include/clock.hxx @ 62:7a6ac9edc838 ecos-sw-2000-01-24
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
| author | jlarmour |
|---|---|
| date | Mon, 24 Jan 2000 21:43:17 +0000 |
| parents | 443894e2e912 |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_CLOCK_HXX |
| 2 #define CYGONCE_KERNEL_CLOCK_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // clock.hxx |
| 0 | 7 // |
| 2 | 8 // Clock and Alarm class declaration(s) |
| 0 | 9 // |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
| 12 // | |
| 13 // ------------------------------------------- | |
| 14 // The contents of this file are subject to the Cygnus eCos Public License | |
| 15 // Version 1.0 (the "License"); you may not use this file except in | |
| 16 // compliance with the License. You may obtain a copy of the License at | |
| 17 // http://sourceware.cygnus.com/ecos | |
| 18 // | |
| 19 // Software distributed under the License is distributed on an "AS IS" | |
| 20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 21 // License for the specific language governing rights and limitations under | |
| 22 // the License. | |
| 23 // | |
| 24 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 25 // September 30, 1998. | |
| 26 // | |
| 27 // The Initial Developer of the Original Code is Cygnus. Portions created | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
28 // by Cygnus are Copyright (C) 1998,1999,2000 Cygnus Solutions. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
29 // All Rights Reserved. |
| 0 | 30 // ------------------------------------------- |
| 31 // | |
| 32 //####COPYRIGHTEND#### | |
| 33 //========================================================================== | |
| 34 //#####DESCRIPTIONBEGIN#### | |
| 35 // | |
| 2 | 36 // Author(s): nickg |
| 37 // Contributors: nickg | |
| 38 // Date: 1997-09-09 | |
| 39 // Purpose: Define Clock and Alarm class interfaces | |
| 40 // Description: The classes defined here collectively implement the | |
| 0 | 41 // internal API used to create, configure and manage Counters, |
| 42 // Clocks and Alarms. | |
| 43 // Usage: #include <cyg/kernel/clock.hxx> | |
| 44 // | |
| 45 //####DESCRIPTIONEND#### | |
| 46 // | |
| 47 //========================================================================== | |
| 48 | |
| 49 #include <cyg/kernel/ktypes.h> | |
| 50 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 51 | |
| 52 // ------------------------------------------------------------------------- | |
| 53 | |
| 54 class Cyg_Alarm; | |
| 55 | |
| 56 typedef void cyg_alarm_fn(Cyg_Alarm *alarm, CYG_ADDRWORD data); | |
| 57 | |
| 58 // ------------------------------------------------------------------------- | |
| 59 // Counter object. | |
| 60 | |
| 61 class Cyg_Counter | |
| 62 { | |
| 63 | |
| 64 friend class Cyg_Alarm; | |
| 65 | |
| 66 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST) | |
| 67 | |
| 68 Cyg_Alarm *alarm_list; // Linear list of Alarms | |
| 69 | |
| 70 #elif defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST) | |
| 71 | |
| 72 Cyg_Alarm *alarm_list[CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE]; | |
| 73 | |
| 74 #endif | |
| 75 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
76 volatile cyg_tick_count counter; // counter value |
| 0 | 77 |
| 78 cyg_uint32 increment; // increment per tick | |
| 79 | |
| 80 public: | |
| 81 | |
| 82 CYGDBG_DEFINE_CHECK_THIS | |
| 83 | |
| 84 Cyg_Counter( | |
| 85 cyg_uint32 increment = 1 | |
| 86 ); | |
| 87 | |
| 88 ~Cyg_Counter(); | |
| 89 | |
| 90 // Return current value of counter | |
| 91 cyg_tick_count current_value(); | |
| 92 | |
| 93 // Return low and high halves of the | |
| 94 // counter value. | |
| 95 cyg_uint32 current_value_lo(); | |
| 96 cyg_uint32 current_value_hi(); | |
| 97 | |
| 98 // Set the counter's current value | |
| 99 void set_value( cyg_tick_count new_value); | |
| 100 | |
| 101 // Advance counter by some number of ticks | |
| 102 void tick( cyg_uint32 ticks = 1); | |
| 103 | |
| 104 // Add an alarm to this counter | |
| 105 void add_alarm( Cyg_Alarm *alarm ); | |
| 106 | |
| 107 // Remove an alarm from this counter | |
| 108 void rem_alarm( Cyg_Alarm *alarm ); | |
| 109 | |
| 110 }; | |
| 111 | |
| 112 // ------------------------------------------------------------------------- | |
| 113 // Clock class. This is derived from a Counter and defines extra | |
| 114 // features to support clock-like behaviour. | |
| 115 | |
| 116 class Cyg_Clock | |
| 117 : public Cyg_Counter | |
| 118 { | |
| 119 | |
| 120 public: | |
| 121 | |
| 122 CYGDBG_DEFINE_CHECK_THIS | |
| 123 | |
| 124 // This structure allows a more accurate representation | |
| 125 // of the resolution than a single integer would allow. | |
| 126 // The resolution is defined as dividend/divisor nanoseconds | |
| 127 // per tick. | |
| 128 struct cyg_resolution { | |
| 129 cyg_uint32 dividend; | |
| 130 cyg_uint32 divisor; | |
| 131 }; | |
| 132 | |
| 133 private: | |
| 134 | |
| 135 cyg_resolution resolution; // Current clock resolution | |
| 136 | |
| 137 public: | |
| 138 | |
| 139 Cyg_Clock( // Create clock with given resolution | |
| 140 cyg_resolution resolution | |
| 141 ); | |
| 142 | |
| 143 ~Cyg_Clock(); // Destructor | |
| 144 | |
| 145 cyg_resolution get_resolution(); // Return current resolution | |
| 146 | |
| 147 void set_resolution( // Set new resolution | |
| 148 cyg_resolution resolution | |
| 149 ); | |
| 150 | |
| 151 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 152 | |
| 153 // There is a system supplied real time clock... | |
| 154 | |
| 155 static Cyg_Clock *real_time_clock; | |
| 156 | |
| 157 #endif | |
| 158 | |
| 159 }; | |
| 160 | |
| 161 // ------------------------------------------------------------------------- | |
| 162 // Alarm class. An alarm may be attached to a counter (or a clock) to be | |
| 163 // called when the trigger value is reached. | |
| 164 | |
| 165 class Cyg_Alarm | |
| 166 { | |
| 167 friend class Cyg_Counter; | |
| 168 | |
| 169 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST) || defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST) | |
| 170 | |
| 171 Cyg_Alarm *next; // next alarm in list | |
| 172 | |
| 173 #endif | |
| 174 | |
| 175 protected: | |
| 176 Cyg_Counter *counter; // Attached to this counter/clock | |
| 177 | |
| 178 cyg_alarm_fn *alarm; // Call-back function | |
| 179 | |
| 180 CYG_ADDRWORD data; // Call-back data | |
| 181 | |
| 182 cyg_tick_count trigger; // Absolute trigger time | |
| 183 | |
| 184 cyg_tick_count interval; // Retrigger interval | |
| 185 | |
| 186 cyg_bool enabled; // True if enabled | |
| 187 | |
| 188 Cyg_Alarm(); | |
| 189 | |
| 190 void synchronize( void ); // deal with times in the past, | |
| 191 // make next alarm in synch. | |
| 192 | |
| 193 public: | |
| 194 | |
| 195 CYGDBG_DEFINE_CHECK_THIS | |
| 196 | |
| 197 Cyg_Alarm // Constructor | |
| 198 ( | |
| 199 Cyg_Counter *counter, // Attached to this counter | |
| 200 cyg_alarm_fn *alarm, // Call-back function | |
| 201 CYG_ADDRWORD data // Call-back data | |
| 202 ); | |
| 203 | |
| 204 ~Cyg_Alarm(); // Destructor | |
| 205 | |
| 206 void initialize( // Initialize Alarm | |
| 207 cyg_tick_count trigger, // Absolute trigger time | |
| 208 cyg_tick_count interval = 0 // Relative retrigger interval | |
| 209 ); | |
| 210 | |
| 211 void enable(); // Ensure alarm enabled | |
| 212 | |
| 213 void disable(); // Ensure alarm disabled | |
| 214 | |
| 215 | |
| 216 }; | |
| 217 | |
| 218 // ------------------------------------------------------------------------- | |
| 219 | |
| 220 #endif // ifndef CYGONCE_KERNEL_CLOCK_HXX | |
| 221 // EOF clock.hxx |
