mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2024-10-27 20:34:19 +00:00
Lesson 20 step 1, the timer
This commit is contained in:
parent
1a98cab56b
commit
7797630a24
@ -8,14 +8,10 @@ The timer is easy to configure. First we'll declare an `init_timer()` on `cpu/ti
|
|||||||
implement it on `cpu/timer.c`. It is just a matter of computing the clock frequency and
|
implement it on `cpu/timer.c`. It is just a matter of computing the clock frequency and
|
||||||
sending the bytes to the appropriate ports.
|
sending the bytes to the appropriate ports.
|
||||||
|
|
||||||
## se printa gibberish, pq? mirar primero si se arregla con un kprint_int
|
We will now fix `kernel/utils.c int_to_ascii()` to print the numbers in the correct order.
|
||||||
## yo tenia una funcion que printaba enteros??!!! pero al rever. hacerla ahora bien y
|
For that, we need to implement `reverse()` and `strlen()`.
|
||||||
## en el proximo episodio limpiar codigo y crear una libc
|
|
||||||
|
|
||||||
|
|
||||||
Finally, go back to the `kernel/kernel.c` and do two things. Enable interrupts again
|
Finally, go back to the `kernel/kernel.c` and do two things. Enable interrupts again
|
||||||
(very important!) and then initialize the timer interrupt.
|
(very important!) and then initialize the timer interrupt.
|
||||||
|
|
||||||
Go `make run` and you'll see the clock ticking! Unfortunately we are not printing the correct values
|
Go `make run` and you'll see the clock ticking!
|
||||||
on screen, so we'll go ahead to `drivers/screen.c` and add a new `kprint_int()` method, also declaring
|
|
||||||
it on `drivers/screen.h`
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "../drivers/screen.h"
|
#include "../drivers/screen.h"
|
||||||
|
#include "../kernel/util.h"
|
||||||
#include "isr.h"
|
#include "isr.h"
|
||||||
|
|
||||||
u32 tick = 0;
|
u32 tick = 0;
|
||||||
@ -7,7 +8,10 @@ u32 tick = 0;
|
|||||||
static void timer_callback(registers_t regs) {
|
static void timer_callback(registers_t regs) {
|
||||||
tick++;
|
tick++;
|
||||||
kprint("Tick: ");
|
kprint("Tick: ");
|
||||||
kprint(tick);
|
|
||||||
|
char *tick_ascii;
|
||||||
|
int_to_ascii(tick, tick_ascii);
|
||||||
|
kprint(tick_ascii);
|
||||||
kprint("\n");
|
kprint("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,5 +26,22 @@ void int_to_ascii(int n, char str[]) {
|
|||||||
if (sign < 0) str[i++] = '-';
|
if (sign < 0) str[i++] = '-';
|
||||||
str[i] = '\0';
|
str[i] = '\0';
|
||||||
|
|
||||||
/* TODO: implement "reverse" */
|
reverse(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* K&R */
|
||||||
|
void reverse(char s[]) {
|
||||||
|
int c, i, j;
|
||||||
|
for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
|
||||||
|
c = s[i];
|
||||||
|
s[i] = s[j];
|
||||||
|
s[j] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* K&R */
|
||||||
|
int strlen(char s[]) {
|
||||||
|
int i = 0;
|
||||||
|
while (s[i] != '\0') ++i;
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,7 @@
|
|||||||
void memory_copy(char *source, char *dest, int nbytes);
|
void memory_copy(char *source, char *dest, int nbytes);
|
||||||
void memory_set(u8 *dest, u8 val, u32 len);
|
void memory_set(u8 *dest, u8 val, u32 len);
|
||||||
void int_to_ascii(int n, char str[]);
|
void int_to_ascii(int n, char str[]);
|
||||||
|
void reverse(char s[]);
|
||||||
|
int strlen(char s[]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user