Skip to content
Snippets Groups Projects
Commit 3d139216 authored by Thierno souleymane Bah's avatar Thierno souleymane Bah
Browse files

feat(getc function tested without semanphore, personal putc function renamed to add_to_queue)

parent 1fa0fe5b
No related branches found
No related tags found
No related merge requests found
...@@ -37,9 +37,7 @@ char keyboard_map(unsigned char code); ...@@ -37,9 +37,7 @@ char keyboard_map(unsigned char code);
void init_queue(); void init_queue();
void putc(unsigned char c); void add_to_queue(unsigned char c);
void putc(unsigned char c);
char getc(); char getc();
......
#include "keyboard.h" #include "keyboard.h"
#include "sem.h"
#include "utils.h"
sem_t keyboard_sem;
void init_keymapping() void init_keymapping()
{ {
...@@ -86,15 +90,16 @@ void init_queue() ...@@ -86,15 +90,16 @@ void init_queue()
keyboard_queue.first_free = 0; keyboard_queue.first_free = 0;
} }
void putc(unsigned char c) void add_to_queue(unsigned char c)
{ {
irq_disable(); irq_disable();
if (c != NONE && keyboard_queue.cpt < QUEUE_SIZE) if (c != NONE && keyboard_queue.cpt < QUEUE_SIZE)
{ {
keyboard_queue.cpt++;
keyboard_queue.first_free = (keyboard_queue.first_free + 1) % QUEUE_SIZE;
keyboard_queue.array[keyboard_queue.first_free] = c; keyboard_queue.array[keyboard_queue.first_free] = c;
keyboard_queue.first_free = (keyboard_queue.first_free + 1) % QUEUE_SIZE;
keyboard_queue.cpt++;
// sem_up(&keyboard_sem);
} }
irq_enable(); irq_enable();
...@@ -104,9 +109,15 @@ char getc() ...@@ -104,9 +109,15 @@ char getc()
{ {
irq_disable(); irq_disable();
char idx = (keyboard_queue.first_free + QUEUE_SIZE - keyboard_queue.cpt) % QUEUE_SIZE; char c = NONE;
if (keyboard_queue.cpt)
{
// sem_down(&keyboard_sem);
int idx = (keyboard_queue.first_free + QUEUE_SIZE - keyboard_queue.cpt) % QUEUE_SIZE;
c = keyboard_queue.array[idx];
keyboard_queue.cpt--; keyboard_queue.cpt--;
}
irq_enable(); irq_enable();
return keyboard_queue.array[idx]; return c;
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
extern int cursor_x; extern int cursor_x;
extern int cursor_y; extern int cursor_y;
extern sem_t keyboard_sem;
int counter = 0; int counter = 0;
...@@ -26,6 +27,21 @@ void timer_it(int_regs_t *r) ...@@ -26,6 +27,21 @@ void timer_it(int_regs_t *r)
yield(); yield();
} }
void keyboard_it(int_regs_t *r)
{
irq_disable();
// puts("keyboard_it\n");
if (_inb(0x64) == (0x1D))
{
_outb(0x64, 0x1C);
char c = keyboard_map(_inb(0x60));
add_to_queue(c);
}
irq_enable();
}
void counter_handler(void *args) void counter_handler(void *args)
{ {
while (1) while (1)
...@@ -39,51 +55,20 @@ void counter_handler(void *args) ...@@ -39,51 +55,20 @@ void counter_handler(void *args)
cursor_x = tmp_cursor[0]; cursor_x = tmp_cursor[0];
cursor_y = tmp_cursor[1]; cursor_y = tmp_cursor[1];
irq_enable(); irq_enable();
} }
} }
void keyboard_handler(void *args) void keyboard_handler(void *args)
{ {
init_keymapping();
while (1) while (1)
{ {
irq_disable(); irq_disable();
if (_inb(0x64) == (0x1D)) char c = getc();
{ if (c != NONE)
_outb(0x64, 0x1C);
unsigned char s = _inb(0x60);
char c = keyboard_map(s);
if (c)
putc(c); putc(c);
// puthex(s);
}
irq_enable();
}
}
void ping(void *arg)
{
while (1)
{
puts("PING\n");
for (int i = 0; i < 100000000; i++)
;
sem_up(&spong);
sem_down(&sping);
}
}
void pong(void *arg) irq_enable();
{
while (1)
{
puts("PONG\n");
for (int i = 0; i < 100000000; i++)
;
sem_up(&sping);
sem_down(&spong);
} }
} }
...@@ -103,8 +88,8 @@ void main(unsigned int *mboot_info) ...@@ -103,8 +88,8 @@ void main(unsigned int *mboot_info)
puts("\n\n"); puts("\n\n");
idt_setup_handler(0, empty_irq); idt_setup_handler(0, timer_it);
idt_setup_handler(1, empty_irq); idt_setup_handler(1, keyboard_it);
__asm volatile("sti"); __asm volatile("sti");
...@@ -112,13 +97,14 @@ void main(unsigned int *mboot_info) ...@@ -112,13 +97,14 @@ void main(unsigned int *mboot_info)
puts("Hello world\n\n"); puts("Hello world\n\n");
sem_init(&sping, -1); init_keymapping();
sem_init(&spong, 0); init_queue();
sem_init(&keyboard_sem, 0);
ctx_t *ping_ctx = create_ctx(ping, NULL); ctx_t *counter_ctx = create_ctx(&counter_handler, NULL);
ctx_t *pong_ctx = create_ctx(pong, NULL); ctx_t *keyboard_ctx = create_ctx(&keyboard_handler, NULL);
//sem_down(&sping);
yield(); yield();
for (;;) for (;;)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment