ioctl using FIONREAD command

Ian Caddy ianc at microsol.iinet.net.au
Mon Feb 21 04:43:33 UTC 2005


Hi David,

We haven't used the FIONREAD function, and since we use 4.5.0, it 
doesn't exist in the code.

I have just had a quick look through the 4.6.1 code and have the 
following comments to make.

The RTEMS termios functions have 2 levels, there is the RAW level which 
is read in by the low level driver and stored in the tty structure in 
the raw structure elements (rawInBuf, and pointed to by rawInBufHead and 
rawInBufTail).

Now, they stay there, until a read is performed (by application 
firmware).  On this read, depending on your VMIN and VTIME settings, it 
will read one or more characters out of this raw buffer and into the 
cooked buffer, (cbuf with pointers ccount and cindex).

The problem is that this cooked buffer does not contain all the 
characters received by the serial connection, in fact, if you have not 
performed a read, the cooked buffer will be empty.

For reading the number of unread characters in the raw buffer, which we 
do, you will need to use the raw variables, I have attached an example:

/**
    This function returns the number of unread characters in the receive
    input buffer
**/
int rtems_termios_getnumchars (void *ttyp)
{
    int iNumChars;
    struct rtems_termios_tty *tty = ttyp;
    rtems_interrupt_level level;

    rtems_interrupt_disable (level);

    iNumChars = tty->rawInBufTail - tty->rawInBufHead;

    rtems_interrupt_enable (level);

    if(iNumChars < 0)
       iNumChars += RAW_INPUT_BUFFER_SIZE;

    return iNumChars;
}

You will need to add this function to your termios, and then you can 
call it directly.  It will show you the number of characters available 
in your raw buffer.

I hope this helps.

regards,

Ian Caddy



David García wrote:
> Hi again, since I had no response to the post I did the 14th of the
> present month I'm doing this new post. Sorry to be so insistent but I
> need some help.
>  
> I just would like if someone have ever used the function ioctl as I
> stated in my first post ( "ioctl(fildes,FIONREAD,&unread)" ) and
> if he/she obtained the expected result in the unread variable. In that
> case please tell me how you did it!
>  
> In those days I've also tried to find the source of my problem in the
> RTEMS source code, but the problem is that I probably have not enought
> knwoledge. So there goes an aditional question
> 
> In the source file:
> <RTEMS_SRC_INSTALLATION>/cpukit/libcsupport/src/termios.c  in the
> function rtems_termios_ioctl (void *arg)
>  
> I found the following lines
>  
> case FIONREAD:
>     /* Half guess that this is the right operation */
>     *(int *)args->buffer = tty->ccount - tty->cindex;
>     break;
>  
> Where tty is a struct rtems_termios_tty and args has been casted to
> (rtems_libio_ioctl_args_t *)
> 
> So the question is that if the operation it does really counts the
> unread bits in the serial port? (I wouldn't dare to do this question
> if the comment attached to the code wasn't there )
> 
> Finally I just will make a brieffing of my general settings:
>     TARGET: i386
>     BSP: pc586
>     and tty_drivers load succesfully at the inizialization of the application.
> 
> Again, sorry for being so insistant and thanks you for your attention.
> Bye, and hope to have any answer this time! ;)
> 
> David García
> david.garcia.anton at gmail.com
> 



More information about the users mailing list