22 #include "pedigree/kernel/Log.h" 23 #include "pedigree/kernel/processor/PhysicalMemoryManager.h" 24 #include "pedigree/kernel/processor/Processor.h" 25 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 27 #include "pedigree/kernel/machine/Machine.h" 31 void SyncTimer::initialise(uintptr_t base)
43 uint32_t hardwareRevision =
44 *
reinterpret_cast<volatile uint32_t *
>(m_MmioBase.
virtualAddress());
46 "32-kHz sync timer at " 48 <<
" - revision " <<
Dec << ((hardwareRevision >> 4) & 0xF) <<
"." 49 << (hardwareRevision & 0xF) <<
Hex);
52 uint32_t SyncTimer::getTickCount()
57 return reinterpret_cast<uint32_t *
>(m_MmioBase.
virtualAddress())[4];
83 volatile uint32_t *registers =
84 reinterpret_cast<volatile uint32_t *
>(m_MmioBase.
virtualAddress());
87 registers[TIOCP_CFG] = 2;
89 while (!(registers[TISTAT] & 1))
99 uint32_t hardwareRevision = registers[TIDR];
101 "General Purpose timer at " 103 <<
" - revision " <<
Dec << ((hardwareRevision >> 4) & 0xF) <<
"." 104 << (hardwareRevision & 0xF) <<
Hex);
108 if (timer <= 2 || timer == 11)
110 registers[TPIR] = 232000;
111 registers[TNIR] = -768000;
112 registers[TLDR] = 0xFFFFFFE0;
117 registers[TCRR] = 0xFFFFFFE0;
137 for (nHandler = 0; nHandler < MAX_TIMER_HANDLERS; nHandler++)
139 if (m_Handlers[nHandler] == 0)
141 m_Handlers[nHandler] = handler;
143 if (!m_bIrqInstalled && m_Irq)
164 for (nHandler = 0; nHandler < MAX_TIMER_HANDLERS; nHandler++)
166 if (m_Handlers[nHandler] == handler)
168 m_Handlers[nHandler] = 0;
178 size_t time = (alarmSecs * 1000) + (alarmUsecs / 1000) + m_TickCount;
181 m_Alarms.pushBack(pAlarm);
191 if ((*it)->m_pEvent == pEvent)
203 size_t currTime = getTickCount();
208 if ((*it)->m_pEvent == pEvent)
213 size_t alarmEndTime = (*it)->m_Time;
216 if (alarmEndTime < currTime)
220 size_t diff = alarmEndTime - currTime;
221 ret = (diff / 1000) + 1;
242 for (nHandler = 0; nHandler < MAX_TIMER_HANDLERS; nHandler++)
245 if (m_Handlers[nHandler])
246 m_Handlers[nHandler]->timer(1000000, state);
254 if (pA->m_Time <= m_TickCount)
257 it = m_Alarms.erase(it);
262 volatile uint32_t *registers =
263 reinterpret_cast<volatile uint32_t *
>(m_MmioBase.
virtualAddress());
264 registers[TISR] = registers[TISR];
virtual bool registerInterruptHandler(size_t nInterruptNumber, InterruptHandler *pHandler)=0
virtual void removeAlarm(class Event *pEvent)
static PhysicalMemoryManager & instance()
void SetIfaceClockPER(size_t clock, bool enabled)
static const size_t continuous
void initialise(size_t timer, uintptr_t base)
bool acquire(bool recurse=false, bool safe=true)
static ProcessorInformation & information()
void SetFuncClockPER(size_t clock, bool enabled)
static const size_t Write
bool sendEvent(Event *pEvent)
static const size_t KernelMode
::Iterator< T, node_t > Iterator
void * virtualAddress() const
virtual void addAlarm(class Event *pEvent, size_t alarmSecs, size_t alarmUsecs=0)
static InterruptManager & instance()
void SelectClockPER(size_t clock, Clock which)
virtual void interrupt(size_t nInterruptnumber, InterruptState &state)