The Pedigree Project  0.1
GPTimer.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 #include "pedigree/kernel/machine/SchedulerTimer.h"
21 #include "pedigree/kernel/machine/Timer.h"
22 #include "pedigree/kernel/processor/InterruptManager.h"
23 #include "pedigree/kernel/processor/MemoryRegion.h"
24 #include "pedigree/kernel/utilities/List.h"
25 
26 #define MAX_TIMER_HANDLERS 32
27 
32 class SyncTimer
33 {
34  public:
35  SyncTimer() : m_MmioBase("SyncTimer")
36  {
37  }
38  virtual ~SyncTimer()
39  {
40  }
41 
42  void initialise(uintptr_t base);
43 
44  uint32_t getTickCount();
45 
46  private:
47  MemoryRegion m_MmioBase;
48 };
49 
54 class GPTimer : public Timer, public SchedulerTimer, public InterruptHandler
55 {
56  public:
58  inline GPTimer()
59  : m_MmioBase("GPTimer"), m_bIrqInstalled(false), m_Irq(0), m_Handlers(),
60  m_Alarms(), m_TickCount(0)
61  {
62  for (int i = 0; i < MAX_TIMER_HANDLERS; i++)
63  m_Handlers[i] = 0;
64  }
66  inline virtual ~GPTimer()
67  {
68  }
69 
71  void initialise(size_t timer, uintptr_t base);
72 
75  virtual size_t getYear()
76  {
77  return 0;
78  }
81  virtual uint8_t getMonth()
82  {
83  return 0;
84  }
87  virtual uint8_t getDayOfMonth()
88  {
89  return 0;
90  }
93  virtual uint8_t getDayOfWeek()
94  {
95  return 0;
96  }
99  virtual uint8_t getHour()
100  {
101  return 0;
102  }
105  virtual uint8_t getMinute()
106  {
107  return 0;
108  }
111  virtual uint8_t getSecond()
112  {
113  return 0;
114  }
117  virtual uint64_t getNanosecond()
118  {
119  return 0;
120  }
121 
124  virtual uint64_t getTickCount()
125  {
126  extern SyncTimer g_SyncTimer;
127  return g_SyncTimer.getTickCount();
128  }
129 
130  virtual bool registerHandler(TimerHandler *handler);
131  virtual bool unregisterHandler(TimerHandler *handler);
132 
137  virtual void
138  addAlarm(class Event *pEvent, size_t alarmSecs, size_t alarmUsecs = 0);
141  virtual void removeAlarm(class Event *pEvent);
147  virtual size_t removeAlarm(class Event *pEvent, bool bRetZero);
148 
149  private:
152  GPTimer(const Timer &);
155  GPTimer &operator=(const Timer &);
156 
157  virtual void interrupt(size_t nInterruptnumber, InterruptState &state);
158 
161 
167 
169  size_t m_Irq;
170 
172  TimerHandler *m_Handlers[MAX_TIMER_HANDLERS];
173 
175  class Alarm
176  {
177  public:
178  Alarm(class Event *pEvent, size_t time, class Thread *pThread)
179  : m_pEvent(pEvent), m_Time(time), m_pThread(pThread)
180  {
181  }
182  class Event *m_pEvent;
183  size_t m_Time;
184  class Thread *m_pThread;
185 
186  private:
187  Alarm(const Alarm &);
188  Alarm &operator=(const Alarm &);
189  };
190 
193 
195  uint64_t m_TickCount;
196 
199  {
200  TIDR = 0x00 / 4, // R
201  TIOCP_CFG = 0x10 / 4, // RW
202  TISTAT = 0x14 / 4, // R
203  TISR = 0x18 / 4, // RW
204  TIER = 0x1C / 4, // RW
205  TWER = 0x20 / 4, // RW
206  TCLR = 0x24 / 4, // RW
207  TCRR = 0x28 / 4, // RW
208  TLDR = 0x2C / 4, // RW
209  TTGR = 0x30 / 4, // RW
210  TWPS = 0x34 / 4, // R
211  TMAR = 0x38 / 4, // RW
212  TCAR1 = 0x3C / 4, // R
213  TSICR = 0x40 / 4, // RW
214  TCAR2 = 0x44 / 4, // R
215  TPIR = 0x48 / 4, // RW
216  TNIR = 0x4C / 4, // RW
217  TCVR = 0x50 / 4, // RW
218  TOCR = 0x54 / 4, // RW
219  TOWR = 0x58 / 4, // RW
220  };
221 };
virtual uint8_t getMonth()
Definition: GPTimer.h:81
virtual ~GPTimer()
Definition: GPTimer.h:66
uint64_t m_TickCount
Definition: GPTimer.h:195
virtual uint8_t getDayOfWeek()
Definition: GPTimer.h:93
bool m_bIrqInstalled
Definition: GPTimer.h:166
Definition: List.h:64
MemoryRegion m_MmioBase
Definition: GPTimer.h:160
virtual size_t getYear()
Definition: GPTimer.h:75
Special memory entity in the kernel&#39;s virtual address space.
Definition: MemoryRegion.h:35
List< Alarm * > m_Alarms
Definition: GPTimer.h:192
virtual uint64_t getTickCount()
Definition: GPTimer.h:124
virtual uint8_t getDayOfMonth()
Definition: GPTimer.h:87
GPTimer()
Definition: GPTimer.h:58
Definition: Thread.h:54
Definition: Event.h:48
Abstract base class for interrupt-handlers.
Registers
Definition: GPTimer.h:198
virtual uint64_t getNanosecond()
Definition: GPTimer.h:117
virtual uint8_t getMinute()
Definition: GPTimer.h:105
Thread & operator=(const Thread &)
virtual uint8_t getHour()
Definition: GPTimer.h:99
size_t m_Irq
Definition: GPTimer.h:169
virtual uint8_t getSecond()
Definition: GPTimer.h:111