コード例 #1
0
ファイル: posix_tty.c プロジェクト: XQuartz/xorg-server
int
xf86SetSerialSpeed(int fd, int speed)
{
    struct termios t;
    int baud, r;

    if (fd < 0)
        return -1;

    /* Don't try to set parameters for non-tty devices. */
    if (!isatty(fd))
        return 0;

    SYSCALL(tcgetattr(fd, &t));

    if ((baud = GetBaud(speed))) {
        cfsetispeed(&t, baud);
        cfsetospeed(&t, baud);
    }
    else {
        xf86Msg(X_ERROR, "Invalid Option BaudRate value: %d\n", speed);
        return -1;
    }

    SYSCALL(r = tcsetattr(fd, TCSANOW, &t));
    return r;
}
コード例 #2
0
ファイル: posix_tty.c プロジェクト: XQuartz/xorg-server
int
xf86SetSerial(int fd, XF86OptionPtr options)
{
    struct termios t;
    int val;
    const char *s;
    int baud, r;

    if (fd < 0)
        return -1;

    /* Don't try to set parameters for non-tty devices. */
    if (!isatty(fd))
        return 0;

    SYSCALL(tcgetattr(fd, &t));

    if ((val = xf86SetIntOption(options, "BaudRate", 0))) {
        if ((baud = GetBaud(val))) {
            cfsetispeed(&t, baud);
            cfsetospeed(&t, baud);
        }
        else {
            xf86Msg(X_ERROR, "Invalid Option BaudRate value: %d\n", val);
            return -1;
        }
    }

    if ((val = xf86SetIntOption(options, "StopBits", 0))) {
        switch (val) {
        case 1:
            t.c_cflag &= ~(CSTOPB);
            break;
        case 2:
            t.c_cflag |= CSTOPB;
            break;
        default:
            xf86Msg(X_ERROR, "Invalid Option StopBits value: %d\n", val);
            return -1;
            break;
        }
    }

    if ((val = xf86SetIntOption(options, "DataBits", 0))) {
        switch (val) {
        case 5:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS5;
            break;
        case 6:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS6;
            break;
        case 7:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS7;
            break;
        case 8:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS8;
            break;
        default:
            xf86Msg(X_ERROR, "Invalid Option DataBits value: %d\n", val);
            return -1;
            break;
        }
    }

    if ((s = xf86SetStrOption(options, "Parity", NULL))) {
        if (xf86NameCmp(s, "Odd") == 0) {
            t.c_cflag |= PARENB | PARODD;
        }
        else if (xf86NameCmp(s, "Even") == 0) {
            t.c_cflag |= PARENB;
            t.c_cflag &= ~(PARODD);
        }
        else if (xf86NameCmp(s, "None") == 0) {
            t.c_cflag &= ~(PARENB);
        }
        else {
            xf86Msg(X_ERROR, "Invalid Option Parity value: %s\n", s);
            return -1;
        }
    }

    if ((val = xf86SetIntOption(options, "Vmin", -1)) != -1) {
        t.c_cc[VMIN] = val;
    }
    if ((val = xf86SetIntOption(options, "Vtime", -1)) != -1) {
        t.c_cc[VTIME] = val;
    }

    if ((s = xf86SetStrOption(options, "FlowControl", NULL))) {
        xf86MarkOptionUsedByName(options, "FlowControl");
        if (xf86NameCmp(s, "Xoff") == 0) {
            t.c_iflag |= IXOFF;
        }
        else if (xf86NameCmp(s, "Xon") == 0) {
            t.c_iflag |= IXON;
        }
        else if (xf86NameCmp(s, "XonXoff") == 0) {
            t.c_iflag |= IXON | IXOFF;
        }
        else if (xf86NameCmp(s, "None") == 0) {
            t.c_iflag &= ~(IXON | IXOFF);
        }
        else {
            xf86Msg(X_ERROR, "Invalid Option FlowControl value: %s\n", s);
            return -1;
        }
    }

    if ((xf86SetBoolOption(options, "ClearDTR", FALSE))) {
#ifdef CLEARDTR_SUPPORT
#if defined(TIOCMBIC)
        val = TIOCM_DTR;
        SYSCALL(ioctl(fd, TIOCMBIC, &val));
#else
        SYSCALL(ioctl(fd, TIOCCDTR, NULL));
#endif
#else
        xf86Msg(X_WARNING, "Option ClearDTR not supported on this OS\n");
        return -1;
#endif
        xf86MarkOptionUsedByName(options, "ClearDTR");
    }

    if ((xf86SetBoolOption(options, "ClearRTS", FALSE))) {
        xf86Msg(X_WARNING, "Option ClearRTS not supported on this OS\n");
        return -1;
        xf86MarkOptionUsedByName(options, "ClearRTS");
    }

    SYSCALL(r = tcsetattr(fd, TCSANOW, &t));
    return r;
}
コード例 #3
0
/***************************************************************************
   Function : IntUartSetAttributes

   Description : This provides the hardware-dependent portion of tcsetattr().
   value and sets it. At the moment this just sets the baud rate.

   Note: The highest baudrate is 115200 as this stays within 
   an error of +/- 5% at 25MHz processor clock
 ***************************************************************************/
static int
IntUartSetAttributes(int minor, const struct termios *t)
{
	/* set default index values */
	int                         baud     = (int)19200;
	int                         databits = (int)MCF5282_UART_UMR1_BC_8;
	int                         parity   = (int)MCF5282_UART_UMR1_PM_NONE;
	int                         stopbits = (int)MCF5282_UART_UMR2_STOP_BITS_1;
	int                         hwflow   = (int)0;
	struct IntUartInfoStruct   *info     = &IntUartInfo[minor];

	/* check to see if input is valid */
	if ( t != (const struct termios *)0 )
	{
		/* determine baud rate index */
		baud = GetBaud( t->c_cflag & CBAUD );

		/* determine data bits */
		switch ( t->c_cflag & CSIZE )
		{
			case CS5:
				databits = (int)MCF5282_UART_UMR1_BC_5;
				break;
			case CS6:
				databits = (int)MCF5282_UART_UMR1_BC_6;
				break;
			case CS7:
				databits = (int)MCF5282_UART_UMR1_BC_7;
				break;
			case CS8:
				databits = (int)MCF5282_UART_UMR1_BC_8;
				break;
		}

		/* determine if parity is enabled */
		if ( t->c_cflag & PARENB )
		{
			if ( t->c_cflag & PARODD )
			{
				/* odd parity */
				parity = (int)MCF5282_UART_UMR1_PM_ODD;
			}
			else
			{
				/* even parity */
				parity = (int)MCF5282_UART_UMR1_PM_EVEN;
			}
		}

		/* determine stop bits */
		if ( t->c_cflag & CSTOPB )
		{
			/* two stop bits */
			stopbits = (int)MCF5282_UART_UMR2_STOP_BITS_2;
		}

		/* check to see if hardware flow control */
		if ( t->c_cflag & CRTSCTS )
		{
			hwflow = 1;
		}
	}

	/* check to see if values have changed */
	if ( ( baud     != info->baud     ) ||
		 ( databits != info->databits ) ||
		 ( parity   != info->parity   ) ||
		 ( stopbits != info->stopbits ) ||
		 ( hwflow   != info->hwflow   ) )
	{

		/* call function to set values */
		IntUartSet(minor, baud, databits, parity, stopbits, hwflow);
	}

	return( RTEMS_SUCCESSFUL );

}