-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
119c1af
commit 778ec17
Showing
6 changed files
with
84 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include "system.h" | ||
#include "PIC.h" | ||
#include "EventQueue.h" | ||
#include "Time.h" | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Created by artypoole on 13/07/24. | ||
// | ||
|
||
#include "Time.h" | ||
|
||
volatile u32 timer_ticks = 0; | ||
volatile u64 timer_count = 0; | ||
u32 rate = 0; | ||
|
||
|
||
|
||
// extern "C" | ||
void configurePit(const u32 hz) | ||
{ | ||
auto& log = Serial::get(); | ||
const u32 divisor = 1193180 / hz; /* Calculate our divisor */ | ||
rate = hz; | ||
log.write("Configured PIT. Divisor: "); | ||
log.write(divisor); | ||
log.newLine(); | ||
outb(0x43, 0x36); /* Set our command byte 0x36 */ | ||
outb(0x40, divisor & 0xFF); /* Set low byte of divisor */ | ||
outb(0x40, divisor >> 8); /* Set high byte of divisor */ | ||
} | ||
|
||
void sleep(const u32 ms) | ||
{ | ||
auto& log = Serial::get(); | ||
if (rate == 0) | ||
{ | ||
log.write("Tried to sleep when timer is not initiated."); | ||
return; | ||
} | ||
|
||
timer_ticks = ms * rate / 1000; // rate is in hz, time is in ms | ||
|
||
log.write("Sleeping for "); | ||
log.write(ms); | ||
log.write("ms. Ticks: "); | ||
log.write(timer_ticks); | ||
log.write(" Rate: "); | ||
log.write(rate); | ||
log.newLine(); | ||
while (timer_ticks > 0); | ||
//log.write("Exited while loop. "); | ||
//log.write("Remaining timer_ticks: "); | ||
//log.write_int(timer_ticks); | ||
// log.new_line(); | ||
} | ||
|
||
void timerHandler() | ||
{ | ||
timer_count = timer_count + 1; // always add one to the time counter | ||
|
||
// Check if sleep is still active. | ||
if (timer_ticks == 0) return; | ||
|
||
timer_ticks = timer_ticks - 1; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Created by artypoole on 13/07/24. | ||
// | ||
|
||
#ifndef TIME_H | ||
#define TIME_H | ||
|
||
|
||
|
||
#include "Serial.h" | ||
|
||
void configurePit(u32 hz); | ||
|
||
void sleep(u32 ms); | ||
|
||
void timerHandler(); | ||
|
||
#endif //TIME_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters