The Pedigree Project  0.1
kernel/machine/hosted/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_HOSTED_COMMON_TIMER_H
21 #define KERNEL_MACHINE_HOSTED_COMMON_TIMER_H
22 
23 #include "pedigree/kernel/machine/IrqManager.h"
24 #include "pedigree/kernel/machine/SchedulerTimer.h"
25 #include "pedigree/kernel/machine/Timer.h"
26 
27 namespace __pedigree_hosted
28 {
29 #include <signal.h>
30 #include <time.h>
31 } // namespace __pedigree_hosted
32 
33 #define MAX_TIMER_HANDLERS 32
34 
38 class HostedTimer : public Timer, private IrqHandler
39 {
40  public:
41  inline static HostedTimer &instance()
42  {
43  return m_Instance;
44  }
45 
46  //
47  // Timer interface
48  //
49  virtual bool registerHandler(TimerHandler *handler);
50  virtual bool unregisterHandler(TimerHandler *handler);
51  virtual void
52  addAlarm(class Event *pEvent, size_t alarmSecs, size_t alarmUsecs = 0);
53  virtual void removeAlarm(class Event *pEvent);
54  virtual size_t removeAlarm(class Event *pEvent, bool bRetZero);
55  virtual size_t getYear();
56  virtual uint8_t getMonth();
57  virtual uint8_t getDayOfMonth();
58  virtual uint8_t getDayOfWeek();
59  virtual uint8_t getHour();
60  virtual uint8_t getMinute();
61  virtual uint8_t getSecond();
62  virtual uint64_t getNanosecond();
63  virtual uint64_t getTickCount();
64  virtual uint64_t getTickCountNano();
65 
68  bool initialise() INITIALISATION_ONLY;
70  virtual void synchronise(bool tohw = false);
72  void uninitialise();
73 
74  protected:
78  inline virtual ~HostedTimer()
79  {
80  }
81 
82  private:
85  HostedTimer(const HostedTimer &);
88  HostedTimer &operator=(const HostedTimer &);
89 
90  //
91  // IrqHandler interface
92  //
93  virtual bool irq(irq_id_t number, InterruptState &state);
94 
96  size_t m_Year;
98  uint8_t m_Month;
100  uint8_t m_DayOfMonth;
102  uint8_t m_DayOfWeek;
104  uint8_t m_Hour;
106  uint8_t m_Minute;
108  uint8_t m_Second;
110  uint64_t m_Nanosecond;
111 
113  __pedigree_hosted::timer_t m_Timer;
114 
116  irq_id_t m_IrqId;
117 
120 
122  TimerHandler *m_Handlers[MAX_TIMER_HANDLERS];
123 
125  class Alarm
126  {
127  public:
128  Alarm(class Event *pEvent, size_t time, class Thread *pThread)
129  : m_pEvent(pEvent), m_Time(time), m_pThread(pThread)
130  {
131  }
132  class Event *m_pEvent;
133  size_t m_Time;
134  class Thread *m_pThread;
135 
136  private:
137  Alarm(const Alarm &);
138  Alarm &operator=(const Alarm &);
139  };
140 
143 };
144 
147 #endif
__pedigree_hosted::timer_t m_Timer
static HostedTimer m_Instance
Definition: List.h:64
List< Alarm * > m_Alarms
Definition: Thread.h:54
Definition: Event.h:48
Thread & operator=(const Thread &)