Mercurial > ecos
annotate packages/kernel/current/include/clock.hxx @ 3292:7f8e529b4d82 default tip
Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
| author | vae |
|---|---|
| date | Wed, 29 Apr 2015 23:31:48 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| 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 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
11 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
12 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
13 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
148
diff
changeset
|
15 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
16 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
17 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
18 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
19 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
148
diff
changeset
|
20 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
21 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
22 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
23 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
24 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
148
diff
changeset
|
25 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
26 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
27 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
28 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
148
diff
changeset
|
29 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
30 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
31 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
32 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
33 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
34 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
35 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
36 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
148
diff
changeset
|
37 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
38 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
39 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
40 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1088
diff
changeset
|
41 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 42 //========================================================================== |
| 43 //#####DESCRIPTIONBEGIN#### | |
| 44 // | |
| 2 | 45 // Author(s): nickg |
| 46 // Contributors: nickg | |
| 47 // Date: 1997-09-09 | |
| 48 // Purpose: Define Clock and Alarm class interfaces | |
| 49 // Description: The classes defined here collectively implement the | |
| 0 | 50 // internal API used to create, configure and manage Counters, |
| 51 // Clocks and Alarms. | |
| 52 // Usage: #include <cyg/kernel/clock.hxx> | |
| 53 // | |
| 54 //####DESCRIPTIONEND#### | |
| 55 // | |
| 56 //========================================================================== | |
| 57 | |
| 58 #include <cyg/kernel/ktypes.h> | |
| 59 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 60 | |
|
148
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
61 #include <cyg/infra/clist.hxx> |
|
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
62 |
| 0 | 63 // ------------------------------------------------------------------------- |
|
148
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
64 // Forward definitions and typedefs. |
| 0 | 65 |
| 66 class Cyg_Alarm; | |
| 67 | |
| 68 typedef void cyg_alarm_fn(Cyg_Alarm *alarm, CYG_ADDRWORD data); | |
| 69 | |
|
148
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
70 typedef Cyg_CList_T<Cyg_Alarm> Cyg_Alarm_List; |
|
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
71 |
| 0 | 72 // ------------------------------------------------------------------------- |
| 73 // Counter object. | |
| 74 | |
| 75 class Cyg_Counter | |
| 76 { | |
| 77 | |
| 78 friend class Cyg_Alarm; | |
| 79 | |
| 80 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST) | |
| 81 | |
|
148
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
82 Cyg_Alarm_List alarm_list; // Linear list of Alarms |
| 0 | 83 |
| 84 #elif defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST) | |
| 85 | |
|
148
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
86 Cyg_Alarm_List alarm_list[CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE]; |
| 0 | 87 |
| 88 #endif | |
| 89 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
90 volatile cyg_tick_count counter; // counter value |
| 0 | 91 |
| 92 cyg_uint32 increment; // increment per tick | |
|
1088
4c13726203c5
* include/clock.hxx: Made Cyg_Counter::add_alarm() and
nickg
parents:
210
diff
changeset
|
93 |
|
4c13726203c5
* include/clock.hxx: Made Cyg_Counter::add_alarm() and
nickg
parents:
210
diff
changeset
|
94 // Add an alarm to this counter |
|
4c13726203c5
* include/clock.hxx: Made Cyg_Counter::add_alarm() and
nickg
parents:
210
diff
changeset
|
95 void add_alarm( Cyg_Alarm *alarm ); |
|
4c13726203c5
* include/clock.hxx: Made Cyg_Counter::add_alarm() and
nickg
parents:
210
diff
changeset
|
96 |
|
4c13726203c5
* include/clock.hxx: Made Cyg_Counter::add_alarm() and
nickg
parents:
210
diff
changeset
|
97 // Remove an alarm from this counter |
|
4c13726203c5
* include/clock.hxx: Made Cyg_Counter::add_alarm() and
nickg
parents:
210
diff
changeset
|
98 void rem_alarm( Cyg_Alarm *alarm ); |
| 0 | 99 |
| 100 public: | |
| 101 | |
| 102 CYGDBG_DEFINE_CHECK_THIS | |
| 103 | |
| 104 Cyg_Counter( | |
| 105 cyg_uint32 increment = 1 | |
| 106 ); | |
| 107 | |
| 108 ~Cyg_Counter(); | |
| 109 | |
| 110 // Return current value of counter | |
| 111 cyg_tick_count current_value(); | |
| 112 | |
| 113 // Return low and high halves of the | |
| 114 // counter value. | |
| 115 cyg_uint32 current_value_lo(); | |
| 116 cyg_uint32 current_value_hi(); | |
| 117 | |
| 118 // Set the counter's current value | |
| 119 void set_value( cyg_tick_count new_value); | |
| 120 | |
| 121 // Advance counter by some number of ticks | |
| 122 void tick( cyg_uint32 ticks = 1); | |
| 123 | |
| 124 }; | |
| 125 | |
| 126 // ------------------------------------------------------------------------- | |
| 127 // Clock class. This is derived from a Counter and defines extra | |
| 128 // features to support clock-like behaviour. | |
| 129 | |
| 130 class Cyg_Clock | |
| 131 : public Cyg_Counter | |
| 132 { | |
| 133 | |
| 134 public: | |
| 135 | |
| 136 CYGDBG_DEFINE_CHECK_THIS | |
| 137 | |
| 138 // This structure allows a more accurate representation | |
| 139 // of the resolution than a single integer would allow. | |
| 140 // The resolution is defined as dividend/divisor nanoseconds | |
| 141 // per tick. | |
| 142 struct cyg_resolution { | |
| 143 cyg_uint32 dividend; | |
| 144 cyg_uint32 divisor; | |
| 145 }; | |
| 146 | |
| 147 private: | |
| 148 | |
| 149 cyg_resolution resolution; // Current clock resolution | |
| 150 | |
| 151 public: | |
| 152 | |
| 153 Cyg_Clock( // Create clock with given resolution | |
| 154 cyg_resolution resolution | |
| 155 ); | |
| 156 | |
| 157 ~Cyg_Clock(); // Destructor | |
| 158 | |
| 159 cyg_resolution get_resolution(); // Return current resolution | |
| 160 | |
| 161 void set_resolution( // Set new resolution | |
| 162 cyg_resolution resolution | |
| 163 ); | |
| 164 | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
165 // There is a need for converting from "other" ticks to clock ticks. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
166 // We will construct 4 numbers to do the conversion as: |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
167 // clock_ticks = (((otherticks*mul1)/div1)*mul2/div2) |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
168 // with the values chosen to minimize the possibility of overflow. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
169 // Do the arithmetic in cyg_uint64s throughout. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
170 struct converter { |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
171 cyg_uint64 mul1, div1, mul2, div2; |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
172 }; |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
173 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
174 // There are two of these because the 4 numbers are different depending |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
175 // on the direction of the conversion, to prevent loss of significance. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
176 // NB these relate to the resolution of the clock object they are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
177 // called against, not necessarily "the" system real time clock. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
178 void get_other_to_clock_converter( cyg_uint64 ns_per_other_tick, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
179 struct converter *pcc ); |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
180 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
181 void get_clock_to_other_converter( cyg_uint64 ns_per_other_tick, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
182 struct converter *pcc ); |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
183 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
184 // A utility to perform the conversion in the obvious way, with |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
185 // rounding to nearest at each stage. Static because it uses a |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
186 // previously acquired converter. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
187 static cyg_tick_count convert( cyg_tick_count value, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
188 struct converter *pcc ); |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
189 |
| 0 | 190 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK |
| 191 | |
| 192 // There is a system supplied real time clock... | |
| 193 | |
| 194 static Cyg_Clock *real_time_clock; | |
| 195 | |
| 196 #endif | |
| 197 | |
| 198 }; | |
| 199 | |
| 200 // ------------------------------------------------------------------------- | |
| 201 // Alarm class. An alarm may be attached to a counter (or a clock) to be | |
| 202 // called when the trigger value is reached. | |
| 203 | |
| 204 class Cyg_Alarm | |
|
148
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
205 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST) || defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST) |
|
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
206 : public Cyg_DNode_T<Cyg_Alarm> |
|
8f2f7615e727
Merge from eCos master repository on 2001-01-12-06:43:03-GMT
jlarmour
parents:
115
diff
changeset
|
207 #endif |
| 0 | 208 { |
| 209 friend class Cyg_Counter; | |
| 210 | |
| 211 protected: | |
| 212 Cyg_Counter *counter; // Attached to this counter/clock | |
| 213 | |
| 214 cyg_alarm_fn *alarm; // Call-back function | |
| 215 | |
| 216 CYG_ADDRWORD data; // Call-back data | |
| 217 | |
| 218 cyg_tick_count trigger; // Absolute trigger time | |
| 219 | |
| 220 cyg_tick_count interval; // Retrigger interval | |
| 221 | |
| 222 cyg_bool enabled; // True if enabled | |
| 223 | |
| 224 Cyg_Alarm(); | |
| 225 | |
| 226 void synchronize( void ); // deal with times in the past, | |
| 227 // make next alarm in synch. | |
| 228 | |
| 229 public: | |
| 230 | |
| 231 CYGDBG_DEFINE_CHECK_THIS | |
| 232 | |
| 233 Cyg_Alarm // Constructor | |
| 234 ( | |
| 235 Cyg_Counter *counter, // Attached to this counter | |
| 236 cyg_alarm_fn *alarm, // Call-back function | |
| 237 CYG_ADDRWORD data // Call-back data | |
| 238 ); | |
| 239 | |
| 240 ~Cyg_Alarm(); // Destructor | |
| 241 | |
| 242 void initialize( // Initialize Alarm | |
| 243 cyg_tick_count trigger, // Absolute trigger time | |
| 244 cyg_tick_count interval = 0 // Relative retrigger interval | |
| 245 ); | |
| 246 | |
| 247 void enable(); // Ensure alarm enabled | |
| 248 | |
| 249 void disable(); // Ensure alarm disabled | |
| 250 | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
251 void get_times( |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
252 cyg_tick_count *trigger, // Next trigger time |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
253 cyg_tick_count *interval // Current interval |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
254 ); |
| 0 | 255 }; |
| 256 | |
| 257 // ------------------------------------------------------------------------- | |
| 258 | |
| 259 #endif // ifndef CYGONCE_KERNEL_CLOCK_HXX | |
| 260 // EOF clock.hxx |
