Hallo,

I have a problem using pipes. Inside user-space I'm using 
the function fCliOnOff to start selected tasks. If I use:

  msg.task = ((1<<TASK1) | (1<<TASK2));

all things are going on. If I use:

  msg.task = ((1<<TASK1) | (1<<TASK2) | (1<<TASK3));

I will get a segmentation fault. The values of msg.task
are the right one (3 for the first case and 7 for the
second). The problem is the "write" function - this will
crash. I never got the COMMAND_TASK_START inside the
rt-process for the last case. Why is this and how can
I correct my code to going on working?

The structure MY_COMMAND I'm using for shared-memory 
commands as well but, this should not be the reason.


----------------- common.h ------------------------
#define COMMAND_TASK_START   (1<<0)
#define COMMAND_TASK_ON      (1<<1)
...
#define TASK1    0x00
#define TASK2    0x01
#define TASK3    0x02
#define TASKS    3

#define CTRL_FIFO 0
#define CTRL_FIFO_SIZE 1024

#define RT_TASK_STACK_SIZE 1024
#define RT_TASK_PRIORITY   1

static RT_TASK tasks[TASKS];
...

---------------- commands.c -----------------------
...
typedef struct 
{
  unsigned int inuse;
  unsigned int task;
  unsigned int command;
  unsigned int command_number;
  int arg1;
  int arg2;
} MY_COMMAND;


extern int ctrlfd; /* fd from Ctrl FIFO, opened in app.c
                    ... ctrlfd = open("/dev/rtf0", O_WRONLY)... */

...

int fCliTaskOnOff()
{
  /* Ctrl-Pipe */
  MY_COMMAND msg;

  msg.command = COMMAND_TASK_START;
  msg.task = ((1<<TASK1) | (1<<TASK2) | (1<<TASK3));

  if (write(ctrlfd, &msg, sizeof(msg)) < 0) {
    fprintf(stderr, "Can't send a command to Control-FIFO (%s)", 
            strerror(errno));
    exit(errno);
  }
  
  return(0);
}
...

----------------- rt_process.c ----------------
static void fController(int task_no)
{
  ...
}

int fTaskHandler(unsigned int fifo)
{
 MY_COMMAND msg;
  int err;
  register int task_no;
  RTIME now;

  while ((err=rtf_get(fifo, &msg, sizeof(msg))) > 0) {
    switch (msg.command) {
      case COMMAND_TASK_START:
        for(task_no=TASK1; task_no<TASKS; task_no++) {
          if((1 << task_no) & msg.task) {
            rt_task_make_periodic(&tasks[task_no],  /* RT_TASK */ 
                                  rt_get_time(),    /* Now! */
                                  MUSECS_TO_RTIME(RT_TASK_CYCLE_TIME));
          }
        } 
        break;
        
      case COMMAND_TASK_ON:
        ...
          rt_task_wakeup(&tasks[task_no]);
        ...
        break;

      case COMMAND_TASK_OFF:
        ...
          rt_task_suspend(&tasks[task_no);
        ...
        break;

      case COMMAND_TASK_PERIOD:
        ...
          now = rt_get_time();
          rt_task_make_periodic(&tasks[task_no] now, msg.arg1);
        ...
        break;

      default:
        return -EINVAL;
    }
  }

  ...
}
  
int init_module(void)
{
  register int task_no;

  ...
  for(task_no=TASK1; task_no<TASKS; task_no++) {
     ...
    /* initialize task code */
    rt_task_init(&tasks[task_no],         /* RT_TASK */
                 fController,             /* task code function */
                 task_no,                 /* startup arg to task code */
                 RT_TASK_STACK_SIZE,      /* task stack size */
                 RT_TASK_PRIORITY);       /* priority */
    
    /* use fp */
    rt_task_use_fp(&tasks[task_no], 1);
  }
  ...
  rtf_create(CTRL_FIFO, CTRL_FIFO_SIZE);
  rtf_create_handler(CTRL_FIFO, &fTaskHandler);

  return 0;
}

void cleanup_module(void)
{
  ...
}

--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/

Reply via email to