Hello : I just sent a mail asking for help on the parallel port application that hangs my machine, but forgot to attach the files. Here are the files : common.h control.h robot.c rectangle.c Again, the problem is when I tell the RT to set a bit pattern, it sets the first bit pattern, and then hangs the machine so I have to reboot. Sincerely, ______________________________________________________________________ Olga Mill ([EMAIL PROTECTED]) Eastern Washington University Voice Mail : (509) 359-6907 __________________________________________________________________________
/* rectangle.c */ /* Produce a rectangular wave on output 0 of a parallel port */ /* a bit pattern is passed through a variable called bit_pattern */ /* */ #ifndef MODULE #define MODULE #endif #include <linux/module.h> #include <linux/kernel.h> #include <linux/version.h> #include <linux/cons.h> #include <asm/io.h> #include <linux/errno.h> #include </usr/src/rtl/include/rtl_sched.h> #include "common.h" #include </usr/src/rtl/include/rtl_fifo.h> #include "control.h" RT_TASK mytask; void fun(int b) { while(1){ outb(b, LPT_PORT); /* write to parallel port */ rt_task_wait(); } } int my_handler(unsigned int fifo) { struct my_msg_struct msg; int err; RTIME now; while ((err = rtf_get(3, &msg, sizeof(msg))) == sizeof(msg)) { switch (msg.command) { case START_TASK: now = rt_get_time(); rt_task_make_periodic(&mytask, now, msg.period); break; case STOP_TASK: rt_task_suspend(&mytask); break; case BIT_PATTERN : fun(msg.bits); rtl_schedule(); break; default: return -EINVAL; /* fun (msg.bits); */ } /*end of switch */ } /* end of while */ if (err != 0) { return -EINVAL; } return 0; } int init_module(void) { rtf_create(1, 4000); rtf_create(2, 4000); rtf_create(3, 100); /* printk ("init_module: bit_pattern %x\n ", 0x00 ); */ rt_task_init(&mytask, fun, 0x00, 3000, 4); /* init task with 0x00 */ rtf_create_handler(3, &my_handler); return 0; } void cleanup_module(void) { rtf_destroy(1); rtf_destroy(2); rtf_destroy(3); rt_task_delete (&mytask) ; }
/* robot.c that is a merge of a parallel example and frank and zappa */ /* Olga Mill , May 1, 1999 */ /* On a key press, this code sends a message to the RT module. */ /* Menu : (continued) - May 12, 1999 */ /* The value on the parallel port is set on pins 2-9 inclusively */ /* setting pins through the globals does not work because */ /* linux task can not change parameters of the high-priority */ /* RT task */ /* use FIFOs to get the bit pattern to the RT task */ #include <stdio.h> #include <errno.h> #include <sys/time.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include </usr/src/release0K/rtl/include/rtl_fifo.h> #include <asm/rt_time.h> #include "common.h" /* bit pattern is declared there */ #include "control.h" #define BUFSIZE 70 char buf[BUFSIZE]; fd_set rfds; struct timeval tv; int retval; int fd0, fd1, ctl; int n; int i; struct my_msg_struct msg; /* task is not periodic, so msg.period */ /* is set to some default value */ int start_RT_task (int task, int bit ) /*you can start a RT task with a default bit pattern bit */ { msg.command = START_TASK; msg.task = task; /*just the name of the task */ msg.period = (RT_TICKS_PER_SEC * 5000) / 1000000; msg.bits=bit; printf("start_RT_task: bit pattern %x \n", bit); if (write(ctl, &msg, sizeof(msg)) < 0) { fprintf(stderr, "Can't send a command to RT-task\n"); exit(1); } return (1); } int suspend_RT_task (int task) { /* suspend the task */ msg.command = STOP_TASK; msg.task = task; msg.period=(RT_TICKS_PER_SEC * 5000)/1000000; printf("Suspending the task..\n"); if (write(ctl, &msg, sizeof(msg)) < 0) { fprintf(stderr, "Can't send a command to RT-task\n"); exit(1); } } int send_RT_bit (int task, int bit ) /* sends the bit pattern BIT to the task TASK */ { msg.command = BIT_PATTERN; /* this message carries a bit pattern */ msg.task = task; /* the same task in my case */ /* but could be different */ msg.period = (RT_TICKS_PER_SEC * 5000) / 1000000; msg.bits=bit; printf("send_RT_bit: sending a bit pattern %x \n", bit); if (write(ctl, &msg, sizeof(msg)) < 0) { fprintf(stderr, "Can't send a command to RT-task\n"); exit(1); } return (1); } int main() { char keypress; /* user presses a key*/ int control ; /* control variable that sets the message */ if ((fd0 = open("/dev/rtf1", O_RDONLY)) < 0) { fprintf(stderr, "Error opening /dev/rtf1\n"); exit(1); } if ((fd1 = open("/dev/rtf2", O_RDONLY)) < 0) { fprintf(stderr, "Error opening /dev/rtf2\n"); exit(1); } /* a FIFO to write to */ if ((ctl = open("/dev/rtf3", O_WRONLY)) < 0) { fprintf(stderr, "Error opening /dev/rtf3\n"); exit(1); } /* now start the tasks while a key is pressed */ printf ("\n----------------------------------\n"); printf ("\t1. Rotate Right [0000]\n"); printf ("\t2. Rotate Base Left [0001]\n"); printf ("\t3. Move Arm Down [0010]\n"); printf ("\t4. Move Arm Up [0011]\n"); printf ("\t5. Open Hand [0100]\n"); printf ("\n---------------------------------\n"); printf ("Enter one of the options: 1-5 , OR \n"); printf (" 0 -suspend current RT task, R-resume RT task, E-exit \n"); start_RT_task(0,0); /*send the bit 0 to the task 0 */ /* I start a 0 task */ while (1==1) { keypress=getchar(); if (keypress=='1') { send_RT_bit (0,0); printf ("Rotating base right... \n" ); keypress ='^'; } else if (keypress =='2') { send_RT_bit(0,1); printf ("Rotating base left .. \n "); keypress ='^'; } else if (keypress=='3') { send_RT_bit(0,2); printf ("Moving arm down ...\n"); keypress='^'; } else if (keypress=='4') { send_RT_bit(0,3); printf ("Moving arm up .. \n "); keypress ='^'; } else if (keypress=='5') { send_RT_bit(0,4); printf ("Opening hand ..\n"); keypress='^'; } else if ((keypress=='R')||(keypress=='r')) { start_RT_task(0,0); printf ("Resuming the RT task with a bit pattern 0x00 \n "); keypress='^'; } else if (keypress=='0') { suspend_RT_task(0); keypress='^'; } else if ((keypress=='e')||(keypress=='E')) { printf ("Exiting the application\n"); exit (1); } } /*end of while */ /* get out RT control out of the infinite while loop */ /* reading part is commented out. We do not read off the parallel port for (i = 0; i < 100; i++) { FD_ZERO(&rfds); FD_SET(fd0, &rfds); FD_SET(fd1, &rfds); tv.tv_sec = 1; tv.tv_usec = 0; retval = select(FD_SETSIZE, &rfds, NULL, NULL, &tv); if (retval > 0) { if (FD_ISSET(fd0, &rfds)) { n = read(fd0, buf, BUFSIZE - 1); buf[n] = 0; printf("FIFO 1: %s\n", buf); } if (FD_ISSET(fd1, &rfds)) { n = read(fd1, buf, BUFSIZE - 1); buf[n] = 0; printf("FIFO 2: %s\n", buf); } } } */ return 0; }
#define START_TASK 1 #define STOP_TASK 2 #define BIT_PATTERN 3 struct my_msg_struct { int command; int task; int period; int bits; };
#define LPT_PORT 0x378 #define LPT_IRQ 7 #define RTC_IRQ 8 #include <asm/rt_time.h> struct sample { RTIME min; RTIME max; };