summaryrefslogtreecommitdiff
path: root/Source/Kernel/Devices/Timer.class.cpp
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-08-22 21:44:32 +0200
committerAlexis211 <alexis211@gmail.com>2009-08-22 21:44:32 +0200
commit2582a11c37ccc22d64974b20b0793e5ba873fe1f (patch)
tree485565c0950f0355290690d3396bcb4c22774fd0 /Source/Kernel/Devices/Timer.class.cpp
parent74e721676ddd5d996ccf2e1d35da57320f658609 (diff)
downloadMelon-2582a11c37ccc22d64974b20b0793e5ba873fe1f.tar.gz
Melon-2582a11c37ccc22d64974b20b0793e5ba873fe1f.zip
Lots of stuff added : heap, timer, device managment, ...
Diffstat (limited to 'Source/Kernel/Devices/Timer.class.cpp')
-rw-r--r--Source/Kernel/Devices/Timer.class.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/Source/Kernel/Devices/Timer.class.cpp b/Source/Kernel/Devices/Timer.class.cpp
new file mode 100644
index 0000000..42a6d1c
--- /dev/null
+++ b/Source/Kernel/Devices/Timer.class.cpp
@@ -0,0 +1,56 @@
+#include "Timer.class.h"
+
+#include <DeviceManager/Dev.ns.h>
+#include <DeviceManager/Time.ns.h>
+
+using namespace Sys; //For outb
+
+Timer::Timer(u8int frequency) {
+ m_ticks = 0;
+ m_seconds = 0;
+
+ Dev::requestIRQ(this, 0);
+ Time::setTimer(this);
+ setFrequency(frequency);
+}
+
+String Timer::getClass() {
+ return String("timer");
+}
+
+String Timer::getName() {
+ return String("Programmable interrupt timer");
+}
+
+void Timer::setFrequency(u8int frequency) {
+ m_frequency = frequency;
+ u32int divisor = 1193180 / (u32int)frequency;
+ outb(0x43, 0x36);
+
+ u8int l = (u8int)(divisor & 0xFF);
+ u8int h = (u8int)( (divisor >> 8) & 0xFF);
+
+ outb(0x40, l);
+ outb(0x40, h);
+}
+
+u32int Timer::uptime() {
+ return m_seconds;
+}
+
+u32int Timer::time() {
+ return (m_seconds * 1000) + ((m_ticks * 1000) / m_frequency);
+}
+
+void Timer::handleIRQ(registers_t registers, int irq) {
+ if (irq == 0) {
+ m_ticks++;
+ if (m_ticks == m_frequency) {
+ m_ticks = 0;
+ m_seconds++;
+ }
+ //Switching task is called in Dev::handleInterrupt
+ }
+}
+
+