[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Re: [lwip] slip interface for linux?
From: |
Conny Öhult |
Subject: |
[lwip-users] Re: [lwip] slip interface for linux? |
Date: |
Wed, 08 Jan 2003 22:53:12 -0000 |
--=====================_1035231353==_.ALT
Content-Type: text/plain; charset="iso-8859-1"; format=flowed
Content-Transfer-Encoding: quoted-printable
>Hi, I have browsed around in the distribution 0.5.3 looking for a full=20
>implementation of a SLIP interface for linux. What I have found is the=20
>sioslip.c which lacks implementation of the macros SIO_RECV(c) and=20
>SIO_SEND(c) as well as neccesary initiation.
I think the purpose of the SLIP interface you found is to serve as a=20
platform independant implementation.
Something like this simple serial initialization and modifications to=20
sioslipif.c will probably work for linux:
/* Global variable in sioslipif.c */
u8_t fd;
/* These use the file descriptor returned by the serial init below */
#define SIO_RECV(c) read(fd, &c, 1);
#define SIO_SEND(c) write(fd, &c, 1);
/* Simply add this to sioslipif_init */
fd =3D sio_init();
----------
/* Simple linux serial initialization */
#include <stdlib.h>
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include "lwip/arch.h"
#define BAUDRATE B57600
#define SERIALDEVICE "/dev/ttyS0" /* change this to whatever tty you are=20
using */
#define _POSIX_SOURCE 1 /* POSIX compliant source */
void signal_handler_IO (int status); /* definition of signal handler */
u8_t
sio_init()
{
struct termios oldtio,newtio;
struct sigaction saio; /* definition of signal action */
int fd;
/* open the device to be non-blocking (read will return immediatly) */
fd =3D open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd <0) {perror(SERIALDEVICE); exit(-1); }
/* install the signal handler before making the device asynchronous */
saio.sa_handler =3D signal_handler_IO;
saio.sa_flags =3D 0;
saio.sa_restorer =3D NULL;
sigaction(SIGIO,&saio,NULL);
/* allow the process to receive SIGIO */
fcntl(fd, F_SETOWN, getpid());
/* Make the file descriptor asynchronous (the manual page says only
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
fcntl(fd, F_SETFL, FASYNC);
tcgetattr(fd,&oldtio); /* save current port settings */
/* set new port settings */
/* see 'man termios' for further settings */
newtio.c_cflag =3D BAUDRATE | CS8 | CLOCAL | CREAD; /* No CRTSCTS */
newtio.c_iflag =3D 0;
newtio.c_oflag =3D 0;
newtio.c_lflag =3D 0;
newtio.c_cc[VMIN] =3D 1; /* Read 1 byte at a time, no timer */
newtio.c_cc[VTIME] =3D 0;
tcsetattr(fd,TCSANOW,&newtio);
tcflush(fd, TCIOFLUSH);
return (u8_t)fd;
}
/* Signal handler for ttyXX to indicate bytes received */
void
signal_handler_IO (int status)
{
/* Only used for debuging */
printf("Data received on ttyXX\n");
}
-------------------------------------------------------------------------
Conny =D6hult
Lule=E5 University of Technology
Department of Computer Science and Electrical Engineering
SE-971 87 LULE=C5, Sweden
Phone: 0920-49 1577 (Intl: +46 920 49 1577)
Fax: 0920-49 2191 (Intl: +46 920 49 2191)
--------------------------------------------------------------------------
--=====================_1035231353==_.ALT
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>
<blockquote type=3Dcite class=3Dcite cite>Hi, I have browsed around in the
distribution 0.5.3 looking for a full implementation of a SLIP interface
for linux. What I have found is the sioslip.c which lacks implementation
of the macros SIO_RECV(c) and SIO_SEND(c) as well as neccesary
initiation.</blockquote><br>
I think the purpose of the SLIP interface you found is to serve as a
platform independant implementation.<br><br>
Something like this simple serial initialization and modifications to
sioslipif.c will probably work for linux:<br><br>
/* Global variable in sioslipif.c */<br>
u8_t fd;<br><br>
/* These use the file descriptor returned by the serial init below
*/<br>
#define SIO_RECV(c) read(fd, &c, 1);<br>
#define SIO_SEND(c) write(fd, &c, 1);<br><br>
/* Simply add this to sioslipif_init */<br>
fd =3D sio_init();<br>
<hr>
/* Simple linux serial initialization */<br>
#include <stdlib.h><br>
#include <termios.h><br>
#include <stdio.h><br>
#include <unistd.h><br>
#include <fcntl.h><br>
#include <sys/signal.h><br>
#include <sys/types.h><br><br>
#include "lwip/arch.h"<br><br>
#define BAUDRATE B57600<br>
#define SERIALDEVICE "/dev/ttyS0" /* change this to whatever
tty you are using */<br>
#define _POSIX_SOURCE 1 /* POSIX compliant source */<br><br>
void signal_handler_IO (int status); /* definition of signal
handler */<br><br>
u8_t<br>
sio_init()<br>
{<br>
struct termios oldtio,newtio;<br>
struct sigaction
saio; /*
definition of signal action */<br>
int fd;<br>
<br>
/* open the device to be non-blocking (read will return
immediatly) */<br>
fd =3D open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);<br>
if (fd <0) {perror(SERIALDEVICE); exit(-1); }<br>
<br>
/* install the signal handler before making the device
asynchronous */<br>
saio.sa_handler =3D signal_handler_IO;<br>
saio.sa_flags =3D 0;<br>
saio.sa_restorer =3D NULL;<br>
sigaction(SIGIO,&saio,NULL);<br><br>
/* allow the process to receive SIGIO */<br>
fcntl(fd, F_SETOWN, getpid());<br>
/* Make the file descriptor asynchronous (the manual page says
only<br>
O_APPEND and O_NONBLOCK, will work with
F_SETFL...) */<br>
fcntl(fd, F_SETFL, FASYNC);<br>
<br>
tcgetattr(fd,&oldtio); /* save current port settings */<br>
/* set new port settings */<br>
/* see 'man termios' for further settings */<br>
newtio.c_cflag =3D BAUDRATE | CS8 | CLOCAL | CREAD; /* No CRTSCTS
*/<br>
newtio.c_iflag =3D 0;<br>
newtio.c_oflag =3D 0;<br>
newtio.c_lflag =3D 0;<br>
newtio.c_cc[VMIN] =3D 1; /* Read 1 byte at a time, no timer */<br>
newtio.c_cc[VTIME] =3D 0;<br>
<br>
tcsetattr(fd,TCSANOW,&newtio);<br>
tcflush(fd, TCIOFLUSH);<br>
return (u8_t)fd;<br>
}<br><br>
/* Signal handler for ttyXX to indicate bytes received */<br>
void<br>
signal_handler_IO (int status)<br>
{<br>
/* Only used for debuging */<br>
printf("Data received on ttyXX\n");<br>
}<br><br>
<x-sigsep><p></x-sigsep>
-------------------------------------------------------------------------
<br>
Conny =D6hult <br>
Lule=E5 University of Technology <br>
Department of Computer Science and Electrical Engineering <br>
SE-971 87 LULE=C5, Sweden <br>
Phone: 0920-49 1577 (Intl: +46 920 49 1577) <br>
Fax: 0920-49 2191 (Intl: +46 920 49 2191) <br>
--------------------------------------------------------------------------<b=
r>
</html>
--=====================_1035231353==_.ALT--
[This message was sent through the lwip discussion list.]
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lwip-users] Re: [lwip] slip interface for linux?,
Conny Öhult <=