From: Natanael Adityasatria Date: Mon, 5 Oct 2015 08:15:44 +0000 (+0200) Subject: Added ex 10d X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=0a595f7ca3a5be20eafa6bccb23bab22b3f69d2a;p=des2015.git Added ex 10d --- diff --git a/natanael/ex10/Makefile b/natanael/ex10/Makefile index 1e36d5a..794362e 100644 --- a/natanael/ex10/Makefile +++ b/natanael/ex10/Makefile @@ -1,7 +1,7 @@ ###### CONFIGURATION ###### ### List of applications to be build -APPLICATIONS = ex10a ex10d +APPLICATIONS = ex10a ex10d1 ex10d2 ### Note: to override the search path for the xeno-config script, use "make XENO=..." diff --git a/natanael/ex10/ex10d1.c b/natanael/ex10/ex10d1.c new file mode 100644 index 0000000..0b699ba --- /dev/null +++ b/natanael/ex10/ex10d1.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include + +const RTIME period = 100000; +const int nsamples = 10000; + +RT_TASK task; +RTIME write_time; +RTIME time_diff[10000]; + +RT_INTR intr; +#define PARPORT_IRQ 7 +unsigned char byte; + +void enable_interupt() +{ + ioperm(0x37A, 1, 1); + byte = inb(0x37A); + byte = byte | 0x10; /* hex 10 = 00010000 */ + outb(byte, 0x37A); + + // enable port D0 + ioperm(0x378, 1, 1); + byte = inb(0x378); + byte = byte | 0x10; /* hex 10 = 00010000 */ + outb(byte, 0x378); +} + +void disable_interupt() +{ + byte = inb(0x37A); + byte = byte & 0xEF; /* hex EF = binary 11101111 */ + outb(byte, 0x37A); +} + +void write_RTIMES(char * filename, unsigned int number_of_values, + RTIME *time_values){ + unsigned int n=0; + FILE *file; + file = fopen(filename,"w"); + while (n +#include +#include +#include +#include +#include +#include + +const RTIME period = 100000; +const int nsamples = 10000; + +RT_TASK task; +RTIME write_time; + +RT_INTR intr; +#define PARPORT_IRQ 7 +unsigned char byte; + +void enable_interupt() +{ + ioperm(0x37A, 1, 1); + byte = inb(0x37A); + byte = byte | 0x10; /* hex 10 = 00010000 */ + outb(byte, 0x37A); + + // enable port D0 + ioperm(0x378, 1, 1); + byte = inb(0x378); + byte = byte | 0x10; /* hex 10 = 00010000 */ + outb(byte, 0x378); +} + +void disable_interupt() +{ + byte = inb(0x37A); + byte = byte & 0xEF; /* hex EF = binary 11101111 */ + outb(byte, 0x37A); +} + +void send_parallel_port_intrp() +{ + outb(inb(0x378) & 0xEF, 0x378); + outb(inb(0x378) | 0x10, 0x378); /* enable interrupt */ +} + +void do_task(void *arg) +{ + for(;;) + { + send_parallel_port_intrp(); + + rt_intr_wait(&intr,TM_INFINITE); + } +} + +//startup code +void startup() +{ + rt_intr_create(&intr, NULL, PARPORT_IRQ, I_PROPAGATE); + enable_interupt(); + + rt_task_create(&task, NULL,0,50,0); + rt_task_start(&task, &do_task, 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); +} + +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(); +} \ No newline at end of file