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
63
65{
66 return Success;
67}
68
70{
71 return Success;
72}
73
75{
76 m_ticks++;
77 return Success;
78}
79
80Timer::Result Timer::wait(u32 microseconds) const
81{
82 return Success;
83}
84
85bool Timer::isExpired(const Timer::Info & info) const
86{
87 if (!info.frequency)
88 return false;
89
90 return m_ticks >= info.ticks;
91}
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
virtual Result stop()
Stop the timer.
Definition Timer.cpp:69
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