From: Natanael Adityasatria Date: Mon, 28 Sep 2015 11:03:25 +0000 (+0200) Subject: Added ex09b X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=93ae51a3f1ccee058f4e2e2431936cf597880520;p=des2015.git Added ex09b --- diff --git a/natanael/ex09/ex09a1.c b/natanael/ex09/ex09a1.c index 86c80e6..cb7257d 100644 --- a/natanael/ex09/ex09a1.c +++ b/natanael/ex09/ex09a1.c @@ -8,9 +8,7 @@ RT_INTR keypress; RT_TASK key_isr; -#define PARPORT_IRQ 7 - -unsigned char byte; +#define KEYBOARD_IRQ 1 void key_handler(void *arg) { @@ -28,12 +26,10 @@ void key_handler(void *arg) //startup code void startup() { - rt_intr_create(&keypress, NULL, PARPORT_IRQ, I_PROPAGATE); - enable_interupt(); + rt_intr_create(&keypress, NULL, KEYBOARD_IRQ, I_PROPAGATE); rt_task_create(&key_isr, NULL,0,50,0); rt_task_start(&key_isr, &key_handler, NULL); - } void init_xenomai() { @@ -44,21 +40,6 @@ void init_xenomai() { rt_print_auto_init(1); } -void enable_interupt() -{ - ioperm(0x37A, 1, 1); - byte = inb(0x37A); - byte = byte | 0x10; /* hex 10 = 00010000 */ - outb(byte, 0x37A); -} - -void disable_interupt() -{ - byte = inb(0x37A); - byte = byte & 0xEF; /* hex EF = binary 11101111 */ - outb(byte, 0x37A); -} - int main(int argc, char* argv[]) { printf("\nType CTRL-C to end this program\n\n" ); @@ -71,6 +52,4 @@ int main(int argc, char* argv[]) // wait for CTRL-c is typed to end the program pause(); - - disable_interupt(); -} +} \ No newline at end of file diff --git a/natanael/ex09/ex09b.c b/natanael/ex09/ex09b.c new file mode 100644 index 0000000..86c80e6 --- /dev/null +++ b/natanael/ex09/ex09b.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include + +RT_INTR keypress; +RT_TASK key_isr; +#define PARPORT_IRQ 7 + +unsigned char byte; + +void key_handler(void *arg) +{ + int count = 0; + int nr_interrupts_waiting; + while(1) { + rt_printf("%d\n",count++); + nr_interrupts_waiting = rt_intr_wait(&keypress,TM_INFINITE); + if (nr_interrupts_waiting>0) + { + } + } +} + +//startup code +void startup() +{ + rt_intr_create(&keypress, NULL, PARPORT_IRQ, I_PROPAGATE); + enable_interupt(); + + rt_task_create(&key_isr, NULL,0,50,0); + rt_task_start(&key_isr, &key_handler, NULL); + +} + +void init_xenomai() { + /* Avoids memory swapping for this program */ + mlockall(MCL_CURRENT|MCL_FUTURE); + + /* Perform auto-init of rt_print buffers if the task doesn't do so */ + rt_print_auto_init(1); +} + +void enable_interupt() +{ + ioperm(0x37A, 1, 1); + byte = inb(0x37A); + byte = byte | 0x10; /* hex 10 = 00010000 */ + outb(byte, 0x37A); +} + +void disable_interupt() +{ + byte = inb(0x37A); + byte = byte & 0xEF; /* hex EF = binary 11101111 */ + outb(byte, 0x37A); +} + +int main(int argc, char* argv[]) +{ + printf("\nType CTRL-C to end this program\n\n" ); + + // code to set things to run xenomai + init_xenomai(); + + //startup code + startup(); + + // wait for CTRL-c is typed to end the program + pause(); + + disable_interupt(); +}