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