From 05aff1311879fc07b1067c773dc66486d17b937c Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Mon, 6 Nov 2017 12:06:28 +0000 Subject: [PATCH] Add function "hwint_unregister_handler" --- arch/hwint.c | 11 ++++++++++- arch/hwint.h | 1 + arch/main.c | 16 +++++++++++----- arch/timer.c | 5 +++++ arch/timer.h | 1 + 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/arch/hwint.c b/arch/hwint.c index 4dbb5f3..d0edca6 100644 --- a/arch/hwint.c +++ b/arch/hwint.c @@ -52,6 +52,15 @@ void hwint_register_handler(unsigned int int_no, hwint_handler_t handler) } handlers[int_no] = handler; - pic_enable(int_no); } + +void hwint_unregister_handler(unsigned int int_no) +{ + if (int_no >= INT_HWINT_COUNT) { + return; + } + + pic_disable(int_no); + handlers[int_no] = 0; +} diff --git a/arch/hwint.h b/arch/hwint.h index ee02f65..0443c18 100644 --- a/arch/hwint.h +++ b/arch/hwint.h @@ -4,5 +4,6 @@ typedef void(*hwint_handler_t)(); void hwint_register_handler(unsigned int int_no, hwint_handler_t handler); +void hwint_unregister_handler(unsigned int int_no); #endif diff --git a/arch/main.c b/arch/main.c index 9968f2a..b0654f5 100644 --- a/arch/main.c +++ b/arch/main.c @@ -14,7 +14,8 @@ static struct KernelMQ_Info kinfo; #define TIMER_FREQ 50 -static unsigned long ticks = 0; +static unsigned char timer_enabled = 1; +static unsigned long timer_ticks = 0; static void on_timer(); @@ -79,7 +80,7 @@ void main(const struct KernelMQ_Info *const kinfo_ptr) timer_initialize(TIMER_FREQ); timer_register_handler(on_timer); - while (ticks < TIMER_FREQ * 3) {} + while (timer_enabled) {} for (unsigned int i = 0; i < kinfo.modules_count; ++i) { tasks_switch_to_user(kinfo.modules[i].base); @@ -91,9 +92,14 @@ void main(const struct KernelMQ_Info *const kinfo_ptr) void on_timer() { - if (ticks % TIMER_FREQ == 0) { - logger_info_from("main", "Timer tick %u.", ticks); + if (timer_ticks % TIMER_FREQ == 0) { + logger_info_from("main", "Timer tick %u.", timer_ticks); + + if (timer_ticks >= TIMER_FREQ * 3) { + timer_unregister_handler(); + timer_enabled = 0; + } } - ++ticks; + ++timer_ticks; } diff --git a/arch/timer.c b/arch/timer.c index 19ee05f..d538abb 100644 --- a/arch/timer.c +++ b/arch/timer.c @@ -21,3 +21,8 @@ void timer_register_handler(timer_handler_t handler) { hwint_register_handler(0, handler); } + +void timer_unregister_handler() +{ + hwint_unregister_handler(0); +} diff --git a/arch/timer.h b/arch/timer.h index b1b200f..d7d0992 100644 --- a/arch/timer.h +++ b/arch/timer.h @@ -8,5 +8,6 @@ typedef hwint_handler_t timer_handler_t; void timer_initialize(unsigned int frequency); void timer_register_handler(timer_handler_t handler); +void timer_unregister_handler(); #endif