FreeNOS
Timer.cpp
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 #include <MemoryBlock.h>
19 #include "Timer.h"
20 
22  : m_ticks(0)
23  , m_frequency(0)
24  , m_int(0)
25 {
26 }
27 
29 {
30  return m_int;
31 }
32 
34 {
35  return m_frequency;
36 }
37 
39 {
40  m_frequency = hertz;
41  return Success;
42 }
43 
45  const Size msecOffset)
46 {
47  info->frequency = m_frequency;
48  info->ticks = m_ticks;
49 
50  if (msecOffset != 0 && m_frequency != 0)
51  {
52  const Size msecPerTick = 1000 / m_frequency;
53  info->ticks += ((msecOffset / msecPerTick) + 1);
54  }
55 
56  return Success;
57 }
58 
60 {
61  return Success;
62 }
63 
65 {
66  return Success;
67 }
68 
70 {
71  return Success;
72 }
73 
75 {
76  m_ticks++;
77  return Success;
78 }
79 
80 Timer::Result Timer::wait(u32 microseconds) const
81 {
82  return Success;
83 }
84 
85 bool Timer::isExpired(const Timer::Info & info) const
86 {
87  if (!info.frequency)
88  return false;
89 
90  return m_ticks >= info.ticks;
91 }
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
Timer::stop
virtual Result stop()
Stop the timer.
Definition: Timer.cpp:69
Timer::start
virtual Result start()
Start the timer.
Definition: Timer.cpp:64
Timer::m_ticks
Size m_ticks
The current timer ticks.
Definition: Timer.h:159
Timer::Info::frequency
Size frequency
Definition: Timer.h:45
MemoryBlock.h
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::m_frequency
Size m_frequency
Frequency of the Timer.
Definition: Timer.h:162
Timer.h
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::Result
Result
Result codes.
Definition: Timer.h:52
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