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 
35 class Timer
36 {
37  public:
38 
42  typedef struct Info
43  {
46  }
47  ALIGN(8) Info;
48 
52  enum Result
53  {
58  };
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 */
Timer::getFrequency
Size getFrequency() const
Get timer frequency.
Definition: Timer.cpp:33
Timer::Success
@ Success
Definition: Timer.h:54
Timer::m_int
Size m_int
Timer interrupt number.
Definition: Timer.h:165
Macros.h
Timer::stop
virtual Result stop()
Stop the timer.
Definition: Timer.cpp:69
Timer::start
virtual Result start()
Start the timer.
Definition: Timer.cpp:64
Types.h
Timer::m_ticks
Size m_ticks
The current timer ticks.
Definition: Timer.h:159
Timer::Info::frequency
Size frequency
Definition: Timer.h:45
Timer::wait
virtual Result wait(u32 microseconds) const
Busy wait a number of microseconds.
Definition: Timer.cpp:80
Timer::Info
Timer information structure.
Definition: Timer.h:42
Timer
Represents a configurable timer device.
Definition: Timer.h:35
Timer::m_frequency
Size m_frequency
Frequency of the Timer.
Definition: Timer.h:162
Timer::ALIGN
enum Timer::Result ALIGN
Timer::setFrequency
virtual Result setFrequency(Size hertz)
Set timer frequency.
Definition: Timer.cpp:38
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
Timer::initialize
virtual Result initialize()
Initialize the timer.
Definition: Timer.cpp:59
Timer::isExpired
bool isExpired(const Info &info) const
Check if a timer value is expired.
Definition: Timer.cpp:85
Timer::Info::ticks
u32 ticks
Definition: Timer.h:44
Timer::Timer
Timer()
Constructor.
Definition: Timer.cpp:21
Timer::NotFound
@ NotFound
Definition: Timer.h:55
Timer::InvalidFrequency
@ InvalidFrequency
Definition: Timer.h:57
Timer::Result
Result
Result codes.
Definition: Timer.h:52
Timer::IOError
@ IOError
Definition: Timer.h:56
Timer::getInterrupt
Size getInterrupt() const
Get timer interrupt number.
Definition: Timer.cpp:28
Timer::getCurrent
virtual Result getCurrent(Info *info, const Size msecOffset=0)
Get current timer info.
Definition: Timer.cpp:44
Timer::tick
virtual Result tick()
Process timer tick.
Definition: Timer.cpp:74