21 #include "pedigree/kernel/compiler.h" 22 #include "pedigree/kernel/machine/Machine.h" 23 #include "pedigree/kernel/process/Event.h" 24 #include "pedigree/kernel/process/Thread.h" 25 #include "pedigree/kernel/processor/Processor.h" 27 #include "pedigree/kernel/core/SlamAllocator.h" 30 #define INTERVAL 1000000 36 extern size_t g_AllocedPages;
40 uint8_t daysPerMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
45 pEvent, alarmSecs * 1000000 + alarmUsecs + getTickCount(),
47 m_Alarms.pushBack(pAlarm);
55 if ((*it)->m_pEvent == pEvent)
65 size_t currTime = getTickCount();
70 if ((*it)->m_pEvent == pEvent)
75 size_t alarmEndTime = (*it)->m_Time;
78 if (alarmEndTime < currTime)
82 size_t diff = alarmEndTime - currTime;
83 ret = (diff / 1000) + 1;
99 for (nHandler = 0; nHandler < MAX_TIMER_HANDLERS; nHandler++)
101 if (m_Handlers[nHandler] == 0)
103 m_Handlers[nHandler] = handler;
112 bool HostedTimer::unregisterHandler(
TimerHandler *handler)
116 for (nHandler = 0; nHandler < MAX_TIMER_HANDLERS; nHandler++)
118 if (m_Handlers[nHandler] == handler)
120 m_Handlers[nHandler] = 0;
172 clock_gettime(CLOCK_MONOTONIC, &tv);
173 return (tv.tv_sec * 1000ULL) + (tv.tv_nsec / 1000ULL);
179 clock_gettime(CLOCK_MONOTONIC, &tv);
180 return (tv.tv_sec * 1000000000ULL) + (tv.tv_nsec);
187 ByteSet(m_Handlers, 0,
sizeof(
TimerHandler *) * MAX_TIMER_HANDLERS);
190 ByteSet(&sv, 0,
sizeof(sv));
191 sv.sigev_notify = SIGEV_SIGNAL;
192 sv.sigev_signo = SIGUSR1;
193 sv.sigev_value.sival_ptr =
this;
194 int r = timer_create(CLOCK_MONOTONIC, &sv, &m_Timer);
201 struct itimerspec interval;
202 ByteSet(&interval, 0,
sizeof(interval));
203 interval.it_interval.tv_nsec = INTERVAL;
204 interval.it_value.tv_nsec = INTERVAL;
205 r = timer_settime(m_Timer, 0, &interval, 0);
208 timer_delete(m_Timer);
212 IrqManager &irqManager = *Machine::instance().getIrqManager();
216 timer_delete(m_Timer);
229 clock_gettime(CLOCK_REALTIME, &tv);
230 struct tm *t = gmtime(&tv.tv_sec);
232 m_Nanosecond = tv.tv_nsec;
233 m_Second = t->tm_sec;
234 m_Minute = t->tm_min;
236 m_DayOfMonth = t->tm_mday;
238 m_Year = t->tm_year + 1900;
239 m_DayOfWeek = t->tm_wday;
246 timer_delete(m_Timer);
249 IrqManager &irqManager = *Machine::instance().getIrqManager();
254 : m_Year(0), m_Month(0), m_DayOfMonth(0), m_DayOfWeek(0), m_Hour(0),
255 m_Minute(0), m_Second(0), m_Nanosecond(0), m_IrqId(0), m_Handlers(),
263 uint64_t opaque = state.getRegister(0);
264 if (opaque != reinterpret_cast<uint64_t>(
this))
270 uint64_t delta = INTERVAL;
278 bool bDispatched =
false;
299 Machine::instance().getIrqManager()->
tick();
307 #ifdef MEMORY_LOGGING_ENABLED 311 str += SlamAllocator::instance().heapPageCount() * 4;
313 str += (g_AllocedPages * 4096) / 1024;
337 bool isLeap = ((
m_Year % 4) == 0) & (((
m_Year % 100) != 0) |
342 ((
m_Month != 2) || isLeap ==
false)) ||
361 for (nHandler = 0; nHandler < MAX_TIMER_HANDLERS; nHandler++)
virtual Serial * getSerial(size_t n)=0
virtual uint64_t getTickCount()
virtual uint64_t getTickCountNano()
virtual void synchronise(bool tohw=false)
static ProcessorInformation & information()
virtual void removeAlarm(class Event *pEvent)
virtual uint8_t getSecond()
static HostedTimer m_Instance
bool sendEvent(Event *pEvent)
bool initialise() INITIALISATION_ONLY
virtual uint8_t getMinute()
HostedTimer() INITIALISATION_ONLY
::Iterator< T, node_t > Iterator
virtual void addAlarm(class Event *pEvent, size_t alarmSecs, size_t alarmUsecs=0)
virtual void unregisterHandler(irq_id_t Id, IrqHandler *handler)=0
virtual uint64_t getNanosecond()
virtual bool irq(irq_id_t number, InterruptState &state)
virtual uint8_t getMonth()
virtual void timer(uint64_t delta, InterruptState &state)=0
virtual uint8_t getDayOfMonth()
TimerHandler * m_Handlers[MAX_TIMER_HANDLERS]
virtual irq_id_t registerIsaIrqHandler(uint8_t irq, IrqHandler *handler, bool bEdge=false)=0
virtual uint8_t getHour()
virtual uint8_t getDayOfWeek()