-
Notifications
You must be signed in to change notification settings - Fork 3
Sleep fix #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Sleep fix #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,4 +34,8 @@ union { | |
|
|
||
| void init_timer(); | ||
|
|
||
| double get_uptime(); | ||
|
|
||
| void sleep(double seconds); | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,45 @@ | ||
|
|
||
| #include <arch/io.h> | ||
| #include <pic/timer.h> | ||
| #include <pic/interrupts.h> | ||
|
|
||
| int i = 0; | ||
| int j = 0; | ||
| void timer(struct interrupt_frame *frame) { | ||
| return; | ||
| unsigned long ticks; // The amount of ticks that have passed | ||
| int hz; // Self-Explanitory | ||
|
|
||
| // Timer callback | ||
| void timer(struct interrupt_frame * frame) { | ||
| ticks++; | ||
| return; | ||
| } | ||
|
|
||
| void sleep(double seconds) { | ||
| double to_wait = seconds + get_uptime(); | ||
| while(to_wait != get_uptime()); | ||
| } | ||
|
|
||
| void set_timer_phase(int hz) { | ||
| PIT_8254 cmd; | ||
| cmd.BCD = BCD_16_BIT; | ||
| cmd.mode = MODE_SQR_WAVE; | ||
| cmd.RW = RW_READ | RW_WRITE; | ||
| cmd.CNTR = 0; | ||
|
|
||
| outb(PIT_CMD, cmd.cmd); | ||
| int divisor = 1193180 / hz; | ||
| outb(PIT_CH0, divisor & 0xff); | ||
| outb(PIT_CH0, divisor >> 8); | ||
|
Comment on lines
-12
to
-22
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likewise, do not change file indentation. |
||
| // Returns how many seconds the computer was awake | ||
| double get_uptime() { | ||
| return ticks * (1 / hz); | ||
| } | ||
|
|
||
| void set_timer_phase() { | ||
| PIT_8254 cmd; | ||
| cmd.BCD = BCD_16_BIT; | ||
| cmd.mode = MODE_SQR_WAVE; | ||
| cmd.RW = RW_READ | RW_WRITE; | ||
| cmd.CNTR = 0; | ||
|
|
||
| outb(PIT_CMD, cmd.cmd); | ||
| int divisor = 1193180 / hz; | ||
| outb(PIT_CH0, divisor & 0xff); | ||
| outb(PIT_CH0, divisor >> 8); | ||
| } | ||
|
|
||
| void init_timer() { | ||
| set_timer_phase(20); | ||
| hz = 20; | ||
| secs = 0; | ||
| ticks = 0; | ||
| set_timer_phase(); | ||
|
|
||
| set_interrupt_handler(0x20, &timer); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not change file indentation. |
||
| outb(PIC1_DATA, inb(PIC1_DATA)&~0x01); | ||
| set_interrupt_handler(0x20, & timer); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a take-reference, not a bitwise and. please remove the space. |
||
| outb(PIC1_DATA, inb(PIC1_DATA) & ~0x01); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const int = 20;
// Self-explanatory isn't a valuable comment.