forked from Imagelibrary/rtems
termios: Implement tcflush()
New IO control RTEMS_IO_TCFLUSH.
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
#define RTEMS_IO_TCDRAIN 3
|
||||
#define RTEMS_IO_RCVWAKEUP 4
|
||||
#define RTEMS_IO_SNDWAKEUP 5
|
||||
#define RTEMS_IO_TCFLUSH 6
|
||||
|
||||
/* copied from libnetworking/sys/filio.h and commented out there */
|
||||
/* Generic file-descriptor ioctl's. */
|
||||
|
||||
@@ -10,39 +10,14 @@
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
/* #include <sys/ioctl.h> */
|
||||
#include <stdint.h>
|
||||
#include <sys/ioccom.h>
|
||||
|
||||
#include <rtems/seterr.h>
|
||||
#include <rtems/libio.h>
|
||||
|
||||
int tcflush (
|
||||
int fd __attribute__((unused)),
|
||||
int queue
|
||||
)
|
||||
int tcflush( int fd, int queue )
|
||||
{
|
||||
switch (queue) {
|
||||
case TCIFLUSH:
|
||||
case TCOFLUSH:
|
||||
case TCIOFLUSH:
|
||||
default:
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
}
|
||||
|
||||
/* fd is not validated */
|
||||
|
||||
/* When this is supported, implement it here */
|
||||
rtems_set_errno_and_return_minus_one( ENOTSUP );
|
||||
return 0;
|
||||
return ioctl( fd, RTEMS_IO_TCFLUSH, (intptr_t) queue );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -354,6 +354,28 @@ drainOutput (struct rtems_termios_tty *tty)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
flushOutput (struct rtems_termios_tty *tty)
|
||||
{
|
||||
rtems_interrupt_level level;
|
||||
|
||||
rtems_interrupt_disable (level);
|
||||
tty->rawOutBuf.Tail = 0;
|
||||
tty->rawOutBuf.Head = 0;
|
||||
rtems_interrupt_enable (level);
|
||||
}
|
||||
|
||||
static void
|
||||
flushInput (struct rtems_termios_tty *tty)
|
||||
{
|
||||
rtems_interrupt_level level;
|
||||
|
||||
rtems_interrupt_disable (level);
|
||||
tty->rawInBuf.Tail = 0;
|
||||
tty->rawInBuf.Head = 0;
|
||||
rtems_interrupt_enable (level);
|
||||
}
|
||||
|
||||
rtems_status_code
|
||||
rtems_termios_close (void *arg)
|
||||
{
|
||||
@@ -572,6 +594,24 @@ rtems_termios_ioctl (void *arg)
|
||||
drainOutput (tty);
|
||||
break;
|
||||
|
||||
case RTEMS_IO_TCFLUSH:
|
||||
switch ((intptr_t) args->buffer) {
|
||||
case TCIFLUSH:
|
||||
flushInput (tty);
|
||||
break;
|
||||
case TCOFLUSH:
|
||||
flushOutput (tty);
|
||||
break;
|
||||
case TCIOFLUSH:
|
||||
flushOutput (tty);
|
||||
flushInput (tty);
|
||||
break;
|
||||
default:
|
||||
sc = RTEMS_INVALID_NAME;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTEMS_IO_SNDWAKEUP:
|
||||
tty->tty_snd = *wakeup;
|
||||
break;
|
||||
|
||||
@@ -83,25 +83,27 @@ rtems_task Init(
|
||||
puts( "" );
|
||||
|
||||
/***** TEST TCFLUSH *****/
|
||||
puts( "tcflush(stdin, TCIFLUSH) - ENOTSUP" );
|
||||
puts( "tcflush(stdin, TCIFLUSH) - OK" );
|
||||
errno = 0;
|
||||
sc = tcflush( 0, TCIFLUSH );
|
||||
rtems_test_assert( sc == -1 );
|
||||
rtems_test_assert( errno = ENOTSUP );
|
||||
rtems_test_assert( sc == 0 );
|
||||
rtems_test_assert( errno == 0 );
|
||||
|
||||
puts( "tcflush(stdin, TCOFLUSH) - ENOTSUP" );
|
||||
puts( "tcflush(stdin, TCOFLUSH) - OK" );
|
||||
sc = tcflush( 0, TCOFLUSH );
|
||||
rtems_test_assert( sc == -1 );
|
||||
rtems_test_assert( errno = ENOTSUP );
|
||||
rtems_test_assert( sc == 0 );
|
||||
rtems_test_assert( errno == 0 );
|
||||
|
||||
puts( "tcflush(stdin, TCIOFLUSH) - ENOTSUP" );
|
||||
puts( "tcflush(stdin, TCIOFLUSH) - OK" );
|
||||
sc = tcflush( 0, TCIOFLUSH );
|
||||
rtems_test_assert( sc == -1 );
|
||||
rtems_test_assert( errno = ENOTSUP );
|
||||
rtems_test_assert( sc == 0 );
|
||||
rtems_test_assert( errno == 0 );
|
||||
|
||||
puts( "tcflush(stdin, 22) - EINVAL" );
|
||||
errno = 0;
|
||||
sc = tcflush( 0, 22 );
|
||||
rtems_test_assert( sc == -1 );
|
||||
rtems_test_assert( errno = EINVAL );
|
||||
rtems_test_assert( errno == EINVAL );
|
||||
|
||||
puts( "" );
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ tcflow(stdin, TCIOFF) - ENOTSUP
|
||||
tcflow(stdin, TCION) - ENOTSUP
|
||||
tcflow(stdin, 22) - EINVAL
|
||||
|
||||
tcflush(stdin, TCIFLUSH) - ENOTSUP
|
||||
tcflush(stdin, TCOFLUSH) - ENOTSUP
|
||||
tcflush(stdin, TCIOFLUSH) - ENOTSUP
|
||||
tcflush(stdin, TCIFLUSH) - OK
|
||||
tcflush(stdin, TCOFLUSH) - OK
|
||||
tcflush(stdin, TCIOFLUSH) - OK
|
||||
tcflush(stdin, 22) - EINVAL
|
||||
|
||||
tcgetpgrp( 1 ) - OK
|
||||
|
||||
Reference in New Issue
Block a user