The Pedigree Project 0.1
include/pedigree/kernel/machine/Timer.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef KERNEL_MACHINE_TIMER_H
21#define KERNEL_MACHINE_TIMER_H
22
23#include "pedigree/kernel/processor/types.h"
24#include "pedigree/kernel/time/Time.h"
25
26class TimerHandler;
27
32class Timer {
33 public:
36 virtual size_t getYear() = 0;
39 virtual uint8_t getMonth() = 0;
42 virtual uint8_t getDayOfMonth() = 0;
45 virtual uint8_t getDayOfWeek() = 0;
48 virtual uint8_t getHour() = 0;
51 virtual uint8_t getMinute() = 0;
54 virtual uint8_t getSecond() = 0;
57 virtual uint64_t getNanosecond() = 0;
58
61 virtual uint64_t getTickCount() = 0;
64 virtual uint64_t getTickCountNano() {
65 return getTickCount() * Time::Multiplier::Millisecond;
66 }
68 virtual uint64_t getTickCountNanoFast() {
69 return getTickCountNano();
70 }
71
74
76 virtual Time::Timestamp getUnixTimestamp();
77
78 virtual bool registerHandler(TimerHandler* handler) = 0;
79 virtual bool unregisterHandler(TimerHandler* handler) = 0;
80
86 virtual bool armHandler(TimerHandler*, uint64_t) {
87 return false;
88 }
89
91 virtual bool supportsDeadlines() const {
92 return false;
93 }
94
96 virtual void deadlineInterrupt() {}
97
102 virtual void addAlarm(class Event* pEvent, size_t alarmSecs, size_t alarmUsecs = 0) = 0;
106 virtual void removeAlarm(class Event* pEvent) = 0;
113 virtual size_t removeAlarm(class Event* pEvent, bool bRetZero) = 0;
114
121 virtual void synchronise(bool tohw = false) {}
122
123 protected:
125 inline Timer() {}
127 inline virtual ~Timer() {}
128
129 private:
132 Timer(const Timer&);
136};
137
140#endif
Definition Event.h:49
virtual uint64_t getTickCountNanoFast()
virtual uint64_t getTickCount()=0
virtual bool supportsDeadlines() const
virtual void removeAlarm(class Event *pEvent)=0
virtual uint64_t getTickCountNano()
virtual uint8_t getDayOfWeek()=0
Timer & operator=(const Timer &)
virtual Time::CpuTimeSample sampleCpuTime()
Definition Timer.cc:24
virtual uint64_t getNanosecond()=0
virtual uint8_t getHour()=0
virtual uint8_t getMinute()=0
virtual size_t getYear()=0
virtual void addAlarm(class Event *pEvent, size_t alarmSecs, size_t alarmUsecs=0)=0
virtual void synchronise(bool tohw=false)
Synchronises the timer with the hardware. Useful for updating the fields returned by get*,...
virtual uint8_t getDayOfMonth()=0
virtual Time::Timestamp getUnixTimestamp()
Definition Timer.cc:29
Timer(const Timer &)
virtual uint8_t getMonth()=0
virtual uint8_t getSecond()=0
virtual size_t removeAlarm(class Event *pEvent, bool bRetZero)=0
virtual bool armHandler(TimerHandler *, uint64_t)