1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-10-30 12:03:52 -04:00

Add function "hwint_unregister_handler"

This commit is contained in:
Braiden Vasco 2017-11-06 12:06:28 +00:00
parent 243f93c8d9
commit 05aff13118
5 changed files with 28 additions and 6 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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