Ejemplo n.º 1
0
void
slip_init (slip_t *u, small_uint_t port, const char *name, int prio,
           mem_pool_t *pool, unsigned int khz, unsigned long baud)
{
    u->netif.interface = &slip_interface;
    u->netif.name = name;
    u->netif.arp = 0;
    u->netif.mtu = 552;
    u->netif.type = NETIF_SLIP;
    u->netif.bps = baud;
    u->pool = pool;
    u->port = port;
    u->khz = khz;
    buf_queue_init (&u->inq, u->inqdata, sizeof (u->inqdata));
    buf_queue_init (&u->outq, u->outqdata, sizeof (u->outqdata));

    /* Setup baud rate generator. */
    setup_baud_rate (u->port, u->khz, baud);

    /* Create slip receive task. */
    task_create (slip_receiver, u, "slipr", prio + 1,
                 u->rstack, sizeof (u->rstack));

#ifdef TRANSMIT_IRQ
    /* Create slip transmit task. */
    task_create (slip_transmitter, u, "slipt", prio,
                 u->tstack, sizeof (u->tstack));
#endif
}
Ejemplo n.º 2
0
gboolean
set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
{
	struct termios newtio;

	if (tcgetattr (fd, &newtio) == -1)
		return FALSE;

	newtio.c_cflag |=  (CLOCAL | CREAD);
	newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN );
	newtio.c_oflag &= ~(OPOST);
	newtio.c_iflag = IGNBRK;

	/* setup baudrate */
	baud_rate = setup_baud_rate (baud_rate);

	/* char lenght */
	newtio.c_cflag &= ~CSIZE;
	switch (dataBits)
	{
	case 5: 
	    newtio.c_cflag |= CS5;
	    break;
	case 6: 
	    newtio.c_cflag |= CS6;
	    break;
	case 7: 
	    newtio.c_cflag |= CS7;
	    break;
	case 8:
	default:
		newtio.c_cflag |= CS8;
		break;
	}

	/* stopbits */
	switch (stopBits)
	{
	case NoneStopBits:
		/* Unhandled */
		break;
	case One: /* One */
		/* do nothing, the default is one stop bit */
	    newtio.c_cflag &= ~CSTOPB;
		break;
	case Two: /* Two */
		newtio.c_cflag |= CSTOPB;
		break;
	case OnePointFive: /* OnePointFive */
		/* XXX unhandled */
		break;
	}

	/* parity */
	newtio.c_iflag &= ~(INPCK | ISTRIP );

	switch (parity)
	{
	case NoneParity: /* None */
	    newtio.c_cflag &= ~(PARENB | PARODD);
	    break;
	    
	case Odd: /* Odd */
	    newtio.c_cflag |= PARENB | PARODD;
	    break;
	    
	case Even: /* Even */
	    newtio.c_cflag &= ~(PARODD);
	    newtio.c_cflag |= (PARENB);
	    break;
	    
	case Mark: /* Mark */
	    /* XXX unhandled */
	    break;
	case Space: /* Space */
	    /* XXX unhandled */
	    break;
	}

   	newtio.c_iflag &= ~(IXOFF | IXON);
#ifdef CRTSCTS
	newtio.c_cflag &= ~CRTSCTS;
#endif /* def CRTSCTS */

	switch (handshake)
	{
	case NoneHandshake: /* None */
		/* do nothing */
		break;
	case RequestToSend: /* RequestToSend (RTS) */
#ifdef CRTSCTS
		newtio.c_cflag |= CRTSCTS;
#endif /* def CRTSCTS */
		break;
	case RequestToSendXOnXOff: /* RequestToSendXOnXOff (RTS + XON/XOFF) */
#ifdef CRTSCTS
		newtio.c_cflag |= CRTSCTS;
#endif /* def CRTSCTS */
		/* fall through */
	case XOnXOff: /* XOnXOff */
	    newtio.c_iflag |= IXOFF | IXON;
		break;
	}
	
	if (cfsetospeed (&newtio, baud_rate) < 0 || cfsetispeed (&newtio, baud_rate) < 0 ||
	    tcsetattr (fd, TCSANOW, &newtio) < 0)
	{
		return FALSE;
	}
	else
	{
	return TRUE;
	}
}
Ejemplo n.º 3
0
gboolean
is_baud_rate_legal (int baud_rate)
{
	return setup_baud_rate (baud_rate) != -1;
}
Ejemplo n.º 4
0
gboolean
set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
{
	struct termios newtio;
	gboolean custom_baud_rate = FALSE;

	if (tcgetattr (fd, &newtio) == -1)
		return FALSE;

	newtio.c_cflag |=  (CLOCAL | CREAD);
	newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN );
	newtio.c_oflag &= ~(OPOST);
	newtio.c_iflag = IGNBRK;

	/* setup baudrate */
	baud_rate = setup_baud_rate (baud_rate, &custom_baud_rate);

	/* char lenght */
	newtio.c_cflag &= ~CSIZE;
	switch (dataBits)
	{
	case 5: 
	    newtio.c_cflag |= CS5;
	    break;
	case 6: 
	    newtio.c_cflag |= CS6;
	    break;
	case 7: 
	    newtio.c_cflag |= CS7;
	    break;
	case 8:
	default:
		newtio.c_cflag |= CS8;
		break;
	}

	/* stopbits */
	switch (stopBits)
	{
	case NoneStopBits:
		/* Unhandled */
		break;
	case One: /* One */
		/* do nothing, the default is one stop bit */
	    newtio.c_cflag &= ~CSTOPB;
		break;
	case Two: /* Two */
		newtio.c_cflag |= CSTOPB;
		break;
	case OnePointFive: /* OnePointFive */
		/* XXX unhandled */
		break;
	}

	/* parity */
	newtio.c_iflag &= ~(INPCK | ISTRIP );

	switch (parity)
	{
	case NoneParity: /* None */
	    newtio.c_cflag &= ~(PARENB | PARODD);
	    break;
	    
	case Odd: /* Odd */
	    newtio.c_cflag |= PARENB | PARODD;
	    break;
	    
	case Even: /* Even */
	    newtio.c_cflag &= ~(PARODD);
	    newtio.c_cflag |= (PARENB);
	    break;
	    
	case Mark: /* Mark */
	    /* XXX unhandled */
	    break;
	case Space: /* Space */
	    /* XXX unhandled */
	    break;
	}

   	newtio.c_iflag &= ~(IXOFF | IXON);
#ifdef CRTSCTS
	newtio.c_cflag &= ~CRTSCTS;
#endif /* def CRTSCTS */

	switch (handshake)
	{
	case NoneHandshake: /* None */
		/* do nothing */
		break;
	case RequestToSend: /* RequestToSend (RTS) */
#ifdef CRTSCTS
		newtio.c_cflag |= CRTSCTS;
#endif /* def CRTSCTS */
		break;
	case RequestToSendXOnXOff: /* RequestToSendXOnXOff (RTS + XON/XOFF) */
#ifdef CRTSCTS
		newtio.c_cflag |= CRTSCTS;
#endif /* def CRTSCTS */
		/* fall through */
	case XOnXOff: /* XOnXOff */
	    newtio.c_iflag |= IXOFF | IXON;
		break;
	}

	if (custom_baud_rate == FALSE) {
		if (cfsetospeed (&newtio, baud_rate) < 0 || cfsetispeed (&newtio, baud_rate) < 0)
			return FALSE;
	} else {
#if __linux__ || (defined(__APPLE__) && !defined(HOST_IOS))

		/* On Linux to set a custom baud rate, we must set the
		 * "standard" baud_rate to 38400.   On Apple we set it purely
		 * so that tcsetattr has something to use (and report back later), but
		 * the Apple specific API is still opaque to these APIs, see:
		 * https://developer.apple.com/library/mac/samplecode/SerialPortSample/Listings/SerialPortSample_SerialPortSample_c.html#//apple_ref/doc/uid/DTS10000454-SerialPortSample_SerialPortSample_c-DontLinkElementID_4
		 */
		if (cfsetospeed (&newtio, B38400) < 0 || cfsetispeed (&newtio, B38400) < 0)
			return FALSE;
#endif
	}

	if (tcsetattr (fd, TCSANOW, &newtio) < 0)
		return FALSE;

	if (custom_baud_rate == TRUE){
#if defined(HAVE_LINUX_SERIAL_H)
		struct serial_struct ser;

		if (ioctl (fd, TIOCGSERIAL, &ser) < 0)
		{
			return FALSE;
		}

		ser.custom_divisor = ser.baud_base / baud_rate;
		ser.flags &= ~ASYNC_SPD_MASK;
		ser.flags |= ASYNC_SPD_CUST;

		if (ioctl (fd, TIOCSSERIAL, &ser) < 0)
		{
			return FALSE;
		}
#elif defined(__APPLE__) && !defined(HOST_IOS)
		speed_t speed = baud_rate;
		if (ioctl(fd, IOSSIOSPEED, &speed) == -1)
			return FALSE;
#else
		/* Don't know how to set custom baud rate on this platform. */
		return FALSE;
#endif
	}

	return TRUE;
}
Ejemplo n.º 5
0
gboolean
is_baud_rate_legal (int baud_rate)
{
	gboolean ignore = FALSE;
	return setup_baud_rate (baud_rate, &ignore) != -1;
}