FreeNOS
ARMTimer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 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 <FreeNOS/System.h>
19 #include "ARMCore.h"
20 #include "ARMTimer.h"
21 
23  : m_initialTimerCounter(0)
24 {
25  m_int = ARMTIMER_IRQ;
26 }
27 
29 {
30  u32 f = mrc(p15, 0, 0, c14, c0);
31 
32 #ifdef SYSTEM_FREQ
33  if (f == 0)
34  {
35  f = SYSTEM_FREQ;
36  }
37 #endif /* SYSTEM_FREQ */
38 
39  return f;
40 }
41 
43 {
44  mcr(p15, 0, 0, c14, c2, value);
45 }
46 
48 {
49  mcr(p15, 0, 1, c14, c2, value);
50 }
51 
53 {
55  tick();
56 
57  return Timer::setFrequency(hertz);
58 }
59 
61 {
64 
65  return Timer::tick();
66 }
ARMTimer::tick
virtual Result tick()
Process timer tick.
Definition: ARMTimer.cpp:60
mrc
#define mrc(coproc, opcode1, opcode2, reg, subReg)
Move to ARM from CoProcessor (MRC).
Definition: ARMCore.h:51
Timer::m_int
Size m_int
Timer interrupt number.
Definition: Timer.h:165
mcr
#define mcr(coproc, opcode1, opcode2, reg, subReg, value)
Move to CoProcessor from ARM (MCR).
Definition: ARMCore.h:63
ARMTimer::m_initialTimerCounter
Size m_initialTimerCounter
Currently configured initial timer counter.
Definition: ARMTimer.h:98
ARMTimer::setPL1PhysicalTimerControl
void setPL1PhysicalTimerControl(const u32 value)
Set Physical Timer 1 control value.
Definition: ARMTimer.cpp:47
ARMCore.h
ARMTimer.h
ARMTimer::setPL1PhysicalTimerValue
void setPL1PhysicalTimerValue(const u32 value)
Set Physical Timer 1 value.
Definition: ARMTimer.cpp:42
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
ARMTimer::TimerControlEnable
static const u32 TimerControlEnable
Set this bit in the PL1 control register to enable it.
Definition: ARMTimer.h:44
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
ARMTimer::setFrequency
virtual Result setFrequency(const Size hertz)
Set timer frequency.
Definition: ARMTimer.cpp:52
Timer::Result
Result
Result codes.
Definition: Timer.h:52
ARMTimer::ARMTimer
ARMTimer()
Constructor.
Definition: ARMTimer.cpp:22
ARMTimer::getSystemFrequency
u32 getSystemFrequency(void) const
Retrieve system timer frequency.
Definition: ARMTimer.cpp:28
Timer::tick
virtual Result tick()
Process timer tick.
Definition: Timer.cpp:74