2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Time/timer functions
26 #ifndef KE_TIMER_H_INCLUDED
27 #define KE_TIMER_H_INCLUDED
34 * Timer callback function
36 typedef void (*KeTimerCallback
)(struct KeTimer
*timer
);
39 * Generic timer struct. If the timer is triggered, an interrupt is caused, so
40 * don't use this timer with too small intervals as it has absolute priority.
42 typedef struct KeTimer
45 * Time to be waited in microseconds. If the timer is periodic, this is a
46 * relative value, otherwise it's an absolute value which can be computed by
47 * adding your time to keGetTime().
51 * Sets whether this is a periodic timer, e.g. gets reactivated after it
57 * Callback to be called after the timer has expired.
59 KeTimerCallback callback
;
62 * Absolute time at which the timer expires. Must not be set by the user.
67 * 1, if the timer is currently active, e.g. is the next timer in the queue.
68 * Must not be set by the user.
72 * 1, if the timer is queued. Must not be set by the user.
76 * Next timer in the queue.
80 * Previous timer in the queue.
86 * Initializes the timer functions. Is called by the operating system at
89 void keInitTimer(uint32_t frequency
);
92 * Installs the timer system on the current CPU.
94 void keInstallTimer(void);
97 * Creates a new timer. The user then has to specify callback in the timer
98 * struct before passing it to keSetTimer().
100 KeTimer
*keCreateTimer(void);
102 * Unqueues and destroys a timer.
103 * \todo Stopping the timer does not quite work yet.
105 int keDestroyTimer(KeTimer
*timer
);
107 * Adds a timer to the timer queue.
108 * \param timer Timer to be activated
109 * \param time Time to be waited. If the timer is not periodic, this is an
111 * \param periodic If set to 1, the timer is activated again if it expires.
113 int keSetTimer(KeTimer
*timer
, uint64_t time
, int periodic
);
115 * Cancels an activated timer.
116 * \todo Does not quite work yet if the timer does not belong to the current
119 int keCancelTimer(KeTimer
*timer
);
122 * \todo Does not quite work yet if the timer does not belong to the current
125 int keAdjustTimer(KeTimer
*timer
, uint64_t time
);
128 * Returns the current time in microseconds since the start of the operating
131 uint64_t keGetTime(void);
133 * Returns the interval in which threads are rescheduled.
135 uint32_t keGetTimePerTick(void);
138 * Returns the current time in seconds since unix epoch.
140 uint32_t keGetUnixTime(void);