[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: [rtl] clearing a fifo



Markus Weiss wrote:

> Hi everybody,
>
> I wrote a small rtl-application to collect data from an ESR-spectrometer
> and write it to a fifo (replacing an ugly old OS-9 Box).
> However, i have to go shure that the fifo is empty before starting a
> measurement.
>
> What would be the best way to clear a fifo ?
> Is it OK to destroy it and immediately create it again ?
>
> Some time ago there was a discussion in this list about writing
> an ioctl call to get the number of bytes waiting in a fifo.
> Has anybody actually done that ?
>
> Thanks
>

I did two little modifications on the rt_fifo_new.c to help me getting the
bufferlevel  of an rt_fifo.

1. A new function to read the buffersize from within the rt_tasks

int rtf_fifolevel(unsigned int minor)
{
                       return(RTF_LEN (minor));


}




2. A new case construct in the ioctl section of rt_fifo_new.


     /* Fifolaenge holen */
    case GETRTFIFOLEN:
      error = verify_area (VERIFY_WRITE, (void *) arg, sizeof (int));
      if (error)
        return error;
      memcpy_tofs ((int *) arg, &RTF_LEN (minor), sizeof (int));
      return (0);


 3. I also put two other case constructs into the ioctl, which seems to be
    usefull for my side here ..

      /* Resize fifo */
    case SETRTFIFOBUFSIZE:
      error = verify_area (VERIFY_READ, (void *) arg, sizeof (int));
      if (error)
        return error;
      memcpy_fromfs (&RTF_SIZE, (int *) arg, sizeof (int));
      if ((error = rtf_resize (minor, RTF_SIZE)) < 0)
          return (error);
      return (0);

      /* This is to check if a RT-Fifo is present from the user side ->
           for testing purpose you can use normal pipes and read in small
           chunks, on the "real" system use RT-Fifo and read big chunks */
    case ISRTFIFOPRESENT:
      error = verify_area (VERIFY_WRITE, (void *) arg, sizeof (int));
      if (error)
        return error;
      ret = (int) SCF_PRESENT;
      memcpy_tofs ((int *) arg, &ret, sizeof (int));
      return (0);

    default:
      return -EINVAL;




Hope this will help ...




--

-----------------------------------------------------------------------

Dipl.Ing. (BA) Oliver Schindler

c/o Robert Bosch Multimedia / EMS3 / Infrastruktur

-----------------------------------------------------------------------
Every program has at least one bug and can be shortened by at least one
instruction -- from which, by induction, one can deduce that every
program can be reduced to one instruction which doesn't work.

By unknown

-----------------------------------------------------------------------



--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail majordomo@rtlinux.cs.nmt.edu OR
echo "unsubscribe rtl <Your_email>" | mail majordomo@rtlinux.cs.nmt.edu