OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [include/] [clock.hxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#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
// ####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//==========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
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
50
//              internal API used to create, configure and manage Counters,
51
//              Clocks and Alarms.
52
// Usage:       #include 
53
//
54
//####DESCRIPTIONEND####
55
//
56
//==========================================================================
57
 
58
#include 
59
#include             // assertion macros
60
 
61
#include 
62
 
63
// -------------------------------------------------------------------------
64
// Forward definitions and typedefs.
65
 
66
class Cyg_Alarm;
67
 
68
typedef void cyg_alarm_fn(Cyg_Alarm *alarm, CYG_ADDRWORD data);
69
 
70
typedef Cyg_CList_T Cyg_Alarm_List;
71
 
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
 
82
    Cyg_Alarm_List      alarm_list;     // Linear list of Alarms
83
 
84
#elif defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST)
85
 
86
    Cyg_Alarm_List      alarm_list[CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE];
87
 
88
#endif
89
 
90
    volatile cyg_tick_count counter;    // counter value
91
 
92
    cyg_uint32          increment;      // increment per tick
93
 
94
    // Add an alarm to this counter
95
    void add_alarm( Cyg_Alarm *alarm );
96
 
97
    // Remove an alarm from this counter
98
    void rem_alarm( Cyg_Alarm *alarm );
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
 
165
    // There is a need for converting from "other" ticks to clock ticks.
166
    // We will construct 4 numbers to do the conversion as:
167
    //   clock_ticks = (((otherticks*mul1)/div1)*mul2/div2)
168
    // with the values chosen to minimize the possibility of overflow.
169
    // Do the arithmetic in cyg_uint64s throughout.
170
    struct converter {
171
        cyg_uint64 mul1, div1, mul2, div2;
172
    };
173
 
174
    // There are two of these because the 4 numbers are different depending
175
    // on the direction of the conversion, to prevent loss of significance.
176
    // NB these relate to the resolution of the clock object they are
177
    // called against, not necessarily "the" system real time clock.
178
    void get_other_to_clock_converter( cyg_uint64 ns_per_other_tick,
179
                                       struct converter *pcc );
180
 
181
    void get_clock_to_other_converter( cyg_uint64 ns_per_other_tick,
182
                                       struct converter *pcc );
183
 
184
    // A utility to perform the conversion in the obvious way, with
185
    // rounding to nearest at each stage.  Static because it uses a
186
    // previously acquired converter.
187
    static cyg_tick_count convert( cyg_tick_count value,
188
                                   struct converter *pcc );
189
 
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
205
#if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST) || defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST)
206
    : public Cyg_DNode_T
207
#endif
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
 
251
    void get_times(
252
        cyg_tick_count  *trigger,       // Next trigger time
253
        cyg_tick_count  *interval       // Current interval
254
        );
255
};
256
 
257
// -------------------------------------------------------------------------
258
 
259
#endif // ifndef CYGONCE_KERNEL_CLOCK_HXX
260
// EOF clock.hxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.