forked from Imagelibrary/rtems
Added tcdrain(), cfgetospeed(0, cfsetospeed(), cfgetispeed(), and
cfsetispeed().
This commit is contained in:
26
c/src/exec/libcsupport/src/tcdrain.c
Normal file
26
c/src/exec/libcsupport/src/tcdrain.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file contains the RTEMS implementation of the POSIX API
|
||||
* routines tcdrain.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "libio.h"
|
||||
|
||||
int
|
||||
tcdrain(int fd)
|
||||
{
|
||||
return __rtems_ioctl(fd,RTEMS_IO_TCDRAIN,0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -297,6 +297,31 @@ rtems_termios_open (
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Drain output queue
|
||||
*/
|
||||
static void
|
||||
drainOutput (struct rtems_termios_tty *tty)
|
||||
{
|
||||
rtems_interrupt_level level;
|
||||
rtems_status_code sc;
|
||||
|
||||
if (tty->device.outputUsesInterrupts) {
|
||||
rtems_interrupt_disable (level);
|
||||
while (tty->rawOutBufTail != tty->rawOutBufHead) {
|
||||
tty->rawOutBufState = rob_wait;
|
||||
rtems_interrupt_enable (level);
|
||||
sc = rtems_semaphore_obtain (tty->rawOutBufSemaphore,
|
||||
RTEMS_WAIT,
|
||||
RTEMS_NO_TIMEOUT);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_fatal_error_occurred (sc);
|
||||
rtems_interrupt_disable (level);
|
||||
}
|
||||
rtems_interrupt_enable (level);
|
||||
}
|
||||
}
|
||||
|
||||
rtems_status_code
|
||||
rtems_termios_close (void *arg)
|
||||
{
|
||||
@@ -308,6 +333,7 @@ rtems_termios_close (void *arg)
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_fatal_error_occurred (sc);
|
||||
if (--tty->refcount == 0) {
|
||||
drainOutput (tty);
|
||||
if (tty->device.lastClose)
|
||||
(*tty->device.lastClose)(tty->major, tty->minor, arg);
|
||||
if (tty->forw == NULL)
|
||||
@@ -384,6 +410,10 @@ rtems_termios_ioctl (void *arg)
|
||||
if (tty->device.setAttributes)
|
||||
(*tty->device.setAttributes)(tty->minor, &tty->termios);
|
||||
break;
|
||||
|
||||
case RTEMS_IO_TCDRAIN:
|
||||
drainOutput (tty);
|
||||
break;
|
||||
}
|
||||
rtems_semaphore_release (tty->osem);
|
||||
args->ioctl_return = sc;
|
||||
|
||||
54
c/src/lib/libc/cfiospeed.c
Normal file
54
c/src/lib/libc/cfiospeed.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file contains the RTEMS implementation of the POSIX API
|
||||
* routines cfgetispeed, cfgetospeed, cfsetispeed and cfsetospeed.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "libio.h"
|
||||
|
||||
speed_t
|
||||
cfgetospeed(const struct termios *tp)
|
||||
{
|
||||
return tp->c_cflag & CBAUD;
|
||||
}
|
||||
|
||||
int
|
||||
cfsetospeed(struct termios *tp, speed_t speed)
|
||||
{
|
||||
if (speed & ~CBAUD) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
tp->c_cflag = (tp->c_cflag & ~CBAUD) | speed;
|
||||
return 0;
|
||||
}
|
||||
|
||||
speed_t
|
||||
cfgetispeed(const struct termios *tp)
|
||||
{
|
||||
return (tp->c_cflag / (CIBAUD / CBAUD)) & CBAUD;
|
||||
}
|
||||
|
||||
int
|
||||
cfsetispeed(struct termios *tp, speed_t speed)
|
||||
{
|
||||
if (speed & ~CBAUD) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
tp->c_cflag = (tp->c_cflag & ~CBAUD) | (speed * (CIBAUD / CBAUD));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -37,10 +37,4 @@ tcsetattr(int fd, int opt, struct termios *tp)
|
||||
return __rtems_ioctl(fd,RTEMS_IO_SET_ATTRIBUTES,tp);
|
||||
}
|
||||
|
||||
int
|
||||
tcdrain(int fd)
|
||||
{
|
||||
return __rtems_ioctl(fd,RTEMS_IO_TCDRAIN,0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
26
c/src/lib/libc/tcdrain.c
Normal file
26
c/src/lib/libc/tcdrain.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file contains the RTEMS implementation of the POSIX API
|
||||
* routines tcdrain.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "libio.h"
|
||||
|
||||
int
|
||||
tcdrain(int fd)
|
||||
{
|
||||
return __rtems_ioctl(fd,RTEMS_IO_TCDRAIN,0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -297,6 +297,31 @@ rtems_termios_open (
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Drain output queue
|
||||
*/
|
||||
static void
|
||||
drainOutput (struct rtems_termios_tty *tty)
|
||||
{
|
||||
rtems_interrupt_level level;
|
||||
rtems_status_code sc;
|
||||
|
||||
if (tty->device.outputUsesInterrupts) {
|
||||
rtems_interrupt_disable (level);
|
||||
while (tty->rawOutBufTail != tty->rawOutBufHead) {
|
||||
tty->rawOutBufState = rob_wait;
|
||||
rtems_interrupt_enable (level);
|
||||
sc = rtems_semaphore_obtain (tty->rawOutBufSemaphore,
|
||||
RTEMS_WAIT,
|
||||
RTEMS_NO_TIMEOUT);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_fatal_error_occurred (sc);
|
||||
rtems_interrupt_disable (level);
|
||||
}
|
||||
rtems_interrupt_enable (level);
|
||||
}
|
||||
}
|
||||
|
||||
rtems_status_code
|
||||
rtems_termios_close (void *arg)
|
||||
{
|
||||
@@ -308,6 +333,7 @@ rtems_termios_close (void *arg)
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_fatal_error_occurred (sc);
|
||||
if (--tty->refcount == 0) {
|
||||
drainOutput (tty);
|
||||
if (tty->device.lastClose)
|
||||
(*tty->device.lastClose)(tty->major, tty->minor, arg);
|
||||
if (tty->forw == NULL)
|
||||
@@ -384,6 +410,10 @@ rtems_termios_ioctl (void *arg)
|
||||
if (tty->device.setAttributes)
|
||||
(*tty->device.setAttributes)(tty->minor, &tty->termios);
|
||||
break;
|
||||
|
||||
case RTEMS_IO_TCDRAIN:
|
||||
drainOutput (tty);
|
||||
break;
|
||||
}
|
||||
rtems_semaphore_release (tty->osem);
|
||||
args->ioctl_return = sc;
|
||||
|
||||
26
cpukit/libcsupport/src/tcdrain.c
Normal file
26
cpukit/libcsupport/src/tcdrain.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file contains the RTEMS implementation of the POSIX API
|
||||
* routines tcdrain.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "libio.h"
|
||||
|
||||
int
|
||||
tcdrain(int fd)
|
||||
{
|
||||
return __rtems_ioctl(fd,RTEMS_IO_TCDRAIN,0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -297,6 +297,31 @@ rtems_termios_open (
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Drain output queue
|
||||
*/
|
||||
static void
|
||||
drainOutput (struct rtems_termios_tty *tty)
|
||||
{
|
||||
rtems_interrupt_level level;
|
||||
rtems_status_code sc;
|
||||
|
||||
if (tty->device.outputUsesInterrupts) {
|
||||
rtems_interrupt_disable (level);
|
||||
while (tty->rawOutBufTail != tty->rawOutBufHead) {
|
||||
tty->rawOutBufState = rob_wait;
|
||||
rtems_interrupt_enable (level);
|
||||
sc = rtems_semaphore_obtain (tty->rawOutBufSemaphore,
|
||||
RTEMS_WAIT,
|
||||
RTEMS_NO_TIMEOUT);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_fatal_error_occurred (sc);
|
||||
rtems_interrupt_disable (level);
|
||||
}
|
||||
rtems_interrupt_enable (level);
|
||||
}
|
||||
}
|
||||
|
||||
rtems_status_code
|
||||
rtems_termios_close (void *arg)
|
||||
{
|
||||
@@ -308,6 +333,7 @@ rtems_termios_close (void *arg)
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_fatal_error_occurred (sc);
|
||||
if (--tty->refcount == 0) {
|
||||
drainOutput (tty);
|
||||
if (tty->device.lastClose)
|
||||
(*tty->device.lastClose)(tty->major, tty->minor, arg);
|
||||
if (tty->forw == NULL)
|
||||
@@ -384,6 +410,10 @@ rtems_termios_ioctl (void *arg)
|
||||
if (tty->device.setAttributes)
|
||||
(*tty->device.setAttributes)(tty->minor, &tty->termios);
|
||||
break;
|
||||
|
||||
case RTEMS_IO_TCDRAIN:
|
||||
drainOutput (tty);
|
||||
break;
|
||||
}
|
||||
rtems_semaphore_release (tty->osem);
|
||||
args->ioctl_return = sc;
|
||||
|
||||
Reference in New Issue
Block a user