diff --git a/20-interrupts-timer/README.md b/20-interrupts-timer/README.md index 8cfa0f8..19b7f22 100644 --- a/20-interrupts-timer/README.md +++ b/20-interrupts-timer/README.md @@ -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 sending the bytes to the appropriate ports. -## se printa gibberish, pq? mirar primero si se arregla con un kprint_int -## yo tenia una funcion que printaba enteros??!!! pero al rever. hacerla ahora bien y -## en el proximo episodio limpiar codigo y crear una libc - +We will now fix `kernel/utils.c int_to_ascii()` to print the numbers in the correct order. +For that, we need to implement `reverse()` and `strlen()`. Finally, go back to the `kernel/kernel.c` and do two things. Enable interrupts again (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 -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` +Go `make run` and you'll see the clock ticking! diff --git a/20-interrupts-timer/cpu/timer.c b/20-interrupts-timer/cpu/timer.c index 3d7ef1b..8092a9d 100644 --- a/20-interrupts-timer/cpu/timer.c +++ b/20-interrupts-timer/cpu/timer.c @@ -1,5 +1,6 @@ #include "timer.h" #include "../drivers/screen.h" +#include "../kernel/util.h" #include "isr.h" u32 tick = 0; @@ -7,7 +8,10 @@ u32 tick = 0; static void timer_callback(registers_t regs) { tick++; kprint("Tick: "); - kprint(tick); + + char *tick_ascii; + int_to_ascii(tick, tick_ascii); + kprint(tick_ascii); kprint("\n"); } diff --git a/20-interrupts-timer/kernel/util.c b/20-interrupts-timer/kernel/util.c index d7c5da7..9d2c1a0 100644 --- a/20-interrupts-timer/kernel/util.c +++ b/20-interrupts-timer/kernel/util.c @@ -26,5 +26,22 @@ void int_to_ascii(int n, char str[]) { if (sign < 0) str[i++] = '-'; 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; } diff --git a/20-interrupts-timer/kernel/util.h b/20-interrupts-timer/kernel/util.h index 3375159..b438bf7 100644 --- a/20-interrupts-timer/kernel/util.h +++ b/20-interrupts-timer/kernel/util.h @@ -6,5 +6,7 @@ void memory_copy(char *source, char *dest, int nbytes); void memory_set(u8 *dest, u8 val, u32 len); void int_to_ascii(int n, char str[]); +void reverse(char s[]); +int strlen(char s[]); #endif