FreeNOS
Timer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBARCH_TIMER_H
19#define __LIBARCH_TIMER_H
20
21#include <Macros.h>
22#include <Types.h>
23
35class Timer
36{
37 public:
38
42 typedef struct Info
43 {
46 }
47 ALIGN(8) Info;
48
59
63 Timer();
64
70 Size getInterrupt() const;
71
77 Size getFrequency() const;
78
86 virtual Result setFrequency(Size hertz);
87
96 virtual Result getCurrent(Info *info,
97 const Size msecOffset = 0);
98
104 virtual Result initialize();
105
114 virtual Result start();
115
124 virtual Result stop();
125
134 virtual Result tick();
135
143 virtual Result wait(u32 microseconds) const;
144
154 bool isExpired(const Info & info) const;
155
156 protected:
157
160
163
166};
167
173#endif /* __LIBARCH_TIMER_H */
Represents a configurable timer device.
Definition Timer.h:36
Size m_ticks
The current timer ticks.
Definition Timer.h:159
Size getFrequency() const
Get timer frequency.
Definition Timer.cpp:33
virtual Result tick()
Process timer tick.
Definition Timer.cpp:74
Size m_int
Timer interrupt number.
Definition Timer.h:165
virtual Result wait(u32 microseconds) const
Busy wait a number of microseconds.
Definition Timer.cpp:80
virtual Result start()
Start the timer.
Definition Timer.cpp:64
Timer()
Constructor.
Definition Timer.cpp:21
Result
Result codes.
Definition Timer.h:53
@ Success
Definition Timer.h:54
@ NotFound
Definition Timer.h:55
@ IOError
Definition Timer.h:56
@ InvalidFrequency
Definition Timer.h:57
virtual Result stop()
Stop the timer.
Definition Timer.cpp:69
enum Timer::Result ALIGN
Size getInterrupt() const
Get timer interrupt number.
Definition Timer.cpp:28
virtual Result initialize()
Initialize the timer.
Definition Timer.cpp:59
virtual Result getCurrent(Info *info, const Size msecOffset=0)
Get current timer info.
Definition Timer.cpp:44
bool isExpired(const Info &info) const
Check if a timer value is expired.
Definition Timer.cpp:85
Size m_frequency
Frequency of the Timer.
Definition Timer.h:162
virtual Result setFrequency(Size hertz)
Set timer frequency.
Definition Timer.cpp:38
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Timer information structure.
Definition Timer.h:43
u32 ticks
Definition Timer.h:44
Size frequency
Definition Timer.h:45