lwip-users
[Top][All Lists]
Advanced

[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, &amp;c, 1);<br>
#define SIO_SEND(c) write(fd, &amp;c, 1);<br><br>
/* Simply add this to sioslipif_init */<br>
fd =3D sio_init();<br>
<hr>
/* Simple linux serial initialization */<br>
#include &lt;stdlib.h&gt;<br>
#include &lt;termios.h&gt;<br>
#include &lt;stdio.h&gt;<br>
#include &lt;unistd.h&gt;<br>
#include &lt;fcntl.h&gt;<br>
#include &lt;sys/signal.h&gt;<br>
#include &lt;sys/types.h&gt;<br><br>
#include &quot;lwip/arch.h&quot;<br><br>
#define BAUDRATE B57600<br>
#define SERIALDEVICE &quot;/dev/ttyS0&quot; /* change this to whatever
tty you are using */<br>
#define _POSIX_SOURCE 1 /* POSIX compliant source */<br><br>
void signal_handler_IO (int status);&nbsp;&nbsp; /* definition of signal
handler */<br><br>
u8_t<br>
sio_init()<br>
{<br>
&nbsp; struct termios oldtio,newtio;<br>
&nbsp; struct sigaction
saio;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*
definition of signal action */<br>
&nbsp; int fd;<br>
&nbsp; <br>
&nbsp; /* open the device to be non-blocking (read will return
immediatly) */<br>
&nbsp; fd =3D open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);<br>
&nbsp; if (fd &lt;0) {perror(SERIALDEVICE); exit(-1); }<br>
&nbsp; <br>
&nbsp; /* install the signal handler before making the device
asynchronous */<br>
&nbsp; saio.sa_handler =3D signal_handler_IO;<br>
&nbsp; saio.sa_flags =3D 0;<br>
&nbsp; saio.sa_restorer =3D NULL;<br>
&nbsp; sigaction(SIGIO,&amp;saio,NULL);<br><br>
&nbsp; /* allow the process to receive SIGIO */<br>
&nbsp; fcntl(fd, F_SETOWN, getpid());<br>
&nbsp; /* Make the file descriptor asynchronous (the manual page says
only<br>
&nbsp;&nbsp;&nbsp;&nbsp; O_APPEND and O_NONBLOCK, will work with
F_SETFL...) */<br>
&nbsp; fcntl(fd, F_SETFL, FASYNC);<br>
&nbsp; <br>
&nbsp; tcgetattr(fd,&amp;oldtio); /* save current port settings */<br>
&nbsp; /* set new port settings */<br>
&nbsp; /* see 'man termios' for further settings */<br>
&nbsp; newtio.c_cflag =3D BAUDRATE | CS8 | CLOCAL | CREAD; /* No CRTSCTS
*/<br>
&nbsp; newtio.c_iflag =3D 0;<br>
&nbsp; newtio.c_oflag =3D 0;<br>
&nbsp; newtio.c_lflag =3D 0;<br>
&nbsp; newtio.c_cc[VMIN] =3D 1; /* Read 1 byte at a time, no timer */<br>
&nbsp; newtio.c_cc[VTIME] =3D 0;<br>
&nbsp; <br>
&nbsp; tcsetattr(fd,TCSANOW,&amp;newtio);<br>
&nbsp; tcflush(fd, TCIOFLUSH);<br>
&nbsp; 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>
&nbsp; /* Only used for debuging */<br>
&nbsp; printf(&quot;Data received on ttyXX\n&quot;);<br>
}<br><br>
<x-sigsep><p></x-sigsep>
-------------------------------------------------------------------------
<br>
Conny =D6hult&nbsp; <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.]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]