High,

i am new here and have a problem with reading and writing fifos
inside a rt-task. The rt-task multiplies (at moment only this)
two values. It get this data using FIFO1, multiplying, and put the
result into the FIFO2. I get the data from the user-space into the
rt-task using FIFO1 (debug with printk .., see source rt-ss.c), 
calculate and put the result into FIFO2. Inside the user-prog all
my data are destroyd after this. I dont't know why - please help me.
My code based on the frank-example.

It is possible to communicate 3 rt-task trought a fifo:
A/DU-RT-Task -> FIFO -> Controller RT-Task -> FIFO -> D/A-RT-Task ?
It's for a controller.

Thanks a lot    Olaf

-----8<---- control.h ---------
#define FIFO1           0x0
#define FIFO2           0x1
#define TASK1           0x0

struct sSample {
  float a;
  float b;
  float u;
  float r;
} TestSample;


-----8<---- control.c ---------
....
int main(int argc, int **argv)
{
  int fd0, fd1;
  
  /* Open RT Pipes FIFO1 & FIFO2*/
  if ((fd0 = open("/dev/rtf0", O_WRONLY)) < 0) {
    perror("Error opening /dev/rtf0");
    exit(errno);
  }
  
  if ((fd1 = open("/dev/rtf1", O_RDONLY)) < 0) {
    perror("Error opening /dev/rtf1");
    exit(errno);
  }
    /* Calculate in UserSpace */
    printf("Multiplikation:\n");
    printf("1. Zahl: ");
    scanf("%f", &TestSample.a);
    printf("2. Zahl: ");
    scanf("%f", &TestSample.b);
    TestSample.u=TestSample.a*TestSample.b;
    printf("UserSpace Multiplikation: %f*%f=%f\n", TestSample.a, TestSample.b, 
TestSample.u);
    
    /* Write FIFO */
    if(write(fd0, &TestSample, sizeof(TestSample)) < 0) {
      perror("Can't write to fd0");
    };
    
    /* Read FIFO */
    if(read(fd1, &TestSample, sizeof(TestSample)) < 0 ) {
      perror("Can't read from fd1");
    };
    
    /* Print RT Calc: All values are zero */
    printf("RT Multiplikation: %f*%f=%f\n", TestSample.a, TestSample.b, TestSample.r);
    fflush(stdout);
  }
  return 0;
}


-----8<---- rt-ss.c -----------
...
#include "control.h"
...
RT_TASK mytasks[1];
...
void fun(int t)
{
  while (1) {
    rtf_get(FIFO1, &TestSample, sizeof(TestSample));

    TestSample.r=TestSample.a*TestSample.b;

    rtf_put(FIFO2, &TestSample, sizeof(TestSample));
    /* All values are o.k. */
    printk("Task %i: a=%i, b=%i, u=%i, r=%i\n", t,
           (int)TestSample.a, 
           (int)TestSample.b, 
           (int)TestSample.u, 
           (int)TestSample.r);

    rt_task_wait();
  }
}

int init_module(void)
...
  rtf_create(FIFO1, fifo_size);
  rtf_create(FIFO2, fifo_size);
  rt_task_init(&mytasks[TASK1], fun, data, stack_size, priority);
  rt_task_use_fp(&mytasks[TASK1], 1);
  rt_task_make_periodic(&mytasks[TASK1], rt_get_time(), ticks);

  return 0;
}

void cleanup_module(void)
{
  rtf_destroy(FIFO1);
  rtf_destroy(FIFO2);
  rt_task_delete(&mytasks[TASK1]);
}

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