From 3e5dca9bfb310619c619c7e12dc93894346e90cb Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Wed, 24 Dec 2014 21:37:30 +0100 Subject: [PATCH] UNIX port, SIO, updated port the way it was intended to be done * renamed sio_ functions to sio_unix_ to prevent collision with lwIP SIO core functions. * using #define sio_* sio_unix_* to prevent function redefinition --- ports/unix/include/arch/sys_arch.h | 6 +++ ports/unix/include/netif/sio.h | 36 +++++++++------- ports/unix/netif/sio.c | 66 +++++++++++++++--------------- 3 files changed, 60 insertions(+), 48 deletions(-) diff --git a/ports/unix/include/arch/sys_arch.h b/ports/unix/include/arch/sys_arch.h index c69e8f9..7dad2cd 100644 --- a/ports/unix/include/arch/sys_arch.h +++ b/ports/unix/include/arch/sys_arch.h @@ -55,5 +55,11 @@ typedef struct sys_mbox *sys_mbox_t; struct sys_thread; typedef struct sys_thread * sys_thread_t; +/* include SIO driver before anything else, this way we never + * load lwip/sio.h before netif/sio.h in order to prevent prototypes + * redefinition. + */ +#include "netif/sio.h" + #endif /* LWIP_ARCH_SYS_ARCH_H */ diff --git a/ports/unix/include/netif/sio.h b/ports/unix/include/netif/sio.h index c1e8408..1c667db 100644 --- a/ports/unix/include/netif/sio.h +++ b/ports/unix/include/netif/sio.h @@ -11,15 +11,16 @@ typedef struct sio_status_t { int fd; fifo_t myfifo; } sio_status_t; - +#define sio_fd_t sio_status_t* +#define __sio_fd_t_defined /** Baudrates */ typedef enum sioBaudrates { SIO_BAUD_9600, SIO_BAUD_19200, SIO_BAUD_38400, - SIO_BAUD_57600, - SIO_BAUD_115200 + SIO_BAUD_57600, + SIO_BAUD_115200 } sioBaudrates; /** @@ -27,56 +28,58 @@ typedef enum sioBaudrates { * @param siostat siostatus struct, contains sio instance data, given by sio_open * @return char read from input stream */ -u8_t sio_recv( sio_status_t * siostat ); +u8_t sio_unix_recv( sio_status_t * siostat ); +#define sio_recv sio_unix_recv /** * Poll for a new character from incoming data stream * @param siostat siostatus struct, contains sio instance data, given by sio_open * @return char read from input stream, or < 0 if no char was available */ -s16_t sio_poll(sio_status_t * siostat); +s16_t sio_unix_poll(sio_status_t * siostat); /** * Parse incoming characters until a string str is recieved, blocking call * @param str zero terminated string to expect * @param siostat siostatus struct, contains sio instance data, given by sio_open */ -void sio_expect_string(u8_t *str, sio_status_t * siostat); +void sio_unix_expect_string(u8_t *str, sio_status_t * siostat); /** * Write a char to output data stream * @param c char to write to output stream * @param siostat siostatus struct, contains sio instance data, given by sio_open */ -void sio_send( u8_t c, sio_status_t * siostat ); +void sio_unix_send( u8_t c, sio_status_t * siostat ); /** * Write a char to output data stream * @param str pointer to a zero terminated string * @param siostat siostatus struct, contains sio instance data, given by sio_open */ -void sio_send_string(u8_t *str, sio_status_t * siostat); +void sio_unix_send_string(u8_t *str, sio_status_t * siostat); /** -* Flush outbuffer (send everything in buffer now), useful if some layer below is +* Flush outbuffer (send everything in buffer now), useful if some layer below is * holding on to data, waitng to fill a buffer * @param siostat siostatus struct, contains sio instance data, given by sio_open */ -void sio_flush( sio_status_t * siostat ); +void sio_unix_flush( sio_status_t * siostat ); /** * Open serial port entry point from serial protocol (slipif, pppif) * @param devnum the device number to use, i.e. ttySx, comx:, etc. there x = devnum * @return siostatus struct, contains sio instance data, use when calling sio functions */ -sio_status_t * sio_open( int devnum ); +sio_status_t * sio_unix_open( int devnum ); +#define sio_open sio_unix_open /** * Change baudrate of port, may close and reopen port * @param baud new baudrate * @param siostat siostatus struct, contains sio instance data, given by sio_open */ -void sio_change_baud( sioBaudrates baud, sio_status_t * siostat ); +void sio_unix_change_baud( sioBaudrates baud, sio_status_t * siostat ); #if PPP_SUPPORT /** @@ -85,7 +88,8 @@ void sio_change_baud( sioBaudrates baud, sio_status_t * siostat ); * @param buf output buffer * @param size output buffer size */ -u32_t sio_write(sio_status_t * siostat, u8_t *buf, u32_t size); +u32_t sio_unix_write(sio_status_t * siostat, u8_t *buf, u32_t size); +#define sio_write sio_unix_write /** * Read buffer from serial port @@ -93,13 +97,15 @@ u32_t sio_write(sio_status_t * siostat, u8_t *buf, u32_t size); * @param buf input buffer * @param size input buffer size */ -u32_t sio_read(sio_status_t * siostat, u8_t *buf, u32_t size); +u32_t sio_unix_read(sio_status_t * siostat, u8_t *buf, u32_t size); +#define sio_read sio_unix_read /** * Flush serial port input buffer * @param siostat siostatus struct, contains sio instance data, given by sio_open */ -void sio_read_abort(sio_status_t * siostat); +void sio_unix_read_abort(sio_status_t * siostat); +#define sio_read_abort sio_unix_read_abort #endif /* PPP_SUPPORT */ #endif diff --git a/ports/unix/netif/sio.c b/ports/unix/netif/sio.c index 31476ea..288696a 100644 --- a/ports/unix/netif/sio.c +++ b/ports/unix/netif/sio.c @@ -91,7 +91,7 @@ static void signal_handler_IO_1( int status ) * @param netif : netinterface struct, contains interface instance data * @return file handle to serial dev. */ -static int sio_init( char * device, int devnum, sio_status_t * siostat ) +static int sio_unix_init( char * device, int devnum, sio_status_t * siostat ) { struct termios oldtio,newtio; #if ! PPP_SUPPORT @@ -114,15 +114,15 @@ static int sio_init( char * device, int devnum, sio_status_t * siostat ) switch ( devnum ) { case 0: - LWIP_DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_0\n") ); + LWIP_DEBUGF( SIO_DEBUG, ("sio_unix_init, signal_handler_IO_0\n") ); saio.sa_handler = signal_handler_IO_0; break; case 1: - LWIP_DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_1\n") ); + LWIP_DEBUGF( SIO_DEBUG, ("sio_unix_init, signal_handler_IO_1\n") ); saio.sa_handler = signal_handler_IO_1; break; default: - LWIP_DEBUGF( SIO_DEBUG,("sioinit, devnum not allowed\n") ); + LWIP_DEBUGF( SIO_DEBUG,("sio_unix_init, devnum not allowed\n") ); break; } @@ -160,16 +160,16 @@ static int sio_init( char * device, int devnum, sio_status_t * siostat ) /** * */ -static void sio_speed( int fd, int speed ) +static void sio_unix_speed( int fd, int speed ) { struct termios oldtio,newtio; /* int fd; */ - LWIP_DEBUGF( 1,("sio_speed: baudcode:%d enter\n",speed ) ); + LWIP_DEBUGF( 1,("sio_unix_speed: baudcode:%d enter\n",speed ) ); if ( fd < 0 ) { - LWIP_DEBUGF(SIO_DEBUG, ( "sio_speed: fd ERROR\n" )); + LWIP_DEBUGF(SIO_DEBUG, ( "sio_unix_speed: fd ERROR\n" )); exit( -1 ); } @@ -187,34 +187,34 @@ static void sio_speed( int fd, int speed ) tcsetattr( fd,TCSANOW,&newtio ); tcflush( fd, TCIOFLUSH ); - LWIP_DEBUGF( SIO_DEBUG ,("sio_speed: leave\n" )); + LWIP_DEBUGF( SIO_DEBUG ,("sio_unix_speed: leave\n" )); } /* --public-functions----------------------------------------------------------------------------- */ -void sio_send( u8_t c, sio_status_t * siostat ) +void sio_unix_send( u8_t c, sio_status_t * siostat ) { /* sio_status_t * siostat = ((siostruct_t*)netif->state)->sio; */ if ( write( siostat->fd, &c, 1 ) <= 0 ) { - LWIP_DEBUGF( SIO_DEBUG,("sio_send: write refused\n") ); + LWIP_DEBUGF( SIO_DEBUG,("sio_unix_send: write refused\n") ); } } -void sio_send_string( u8_t *str, sio_status_t * siostat ) +void sio_unix_send_string( u8_t *str, sio_status_t * siostat ) { /* sio_status_t * siostat = ((siostruct_t*)netif->state)->sio; */ int len = strlen( (const char *)str ); if ( write( siostat->fd, str, len ) <= 0 ) { - LWIP_DEBUGF( SIO_DEBUG,("sio_send_string: write refused\n") ); + LWIP_DEBUGF( SIO_DEBUG,("sio_unix_send_string: write refused\n") ); } LWIP_DEBUGF( (PPP_DEBUG | SIO_DEBUG),("sent:%s\n",str ) ); } -void sio_flush( sio_status_t * siostat ) +void sio_unix_flush( sio_status_t * siostat ) { LWIP_UNUSED_ARG(siostat); /* not implemented in unix as it is not needed */ @@ -224,20 +224,20 @@ void sio_flush( sio_status_t * siostat ) #if ! PPP_SUPPORT /*u8_t sio_recv( struct netif * netif )*/ -u8_t sio_recv( sio_status_t * siostat ) +u8_t sio_unix_recv( sio_status_t * siostat ) { /* sio_status_t * siostat = ((siostruct_t*)netif->state)->sio; */ return fifoGet( &(siostat->myfifo) ); } -s16_t sio_poll(sio_status_t * siostat) +s16_t sio_unix_poll(sio_status_t * siostat) { /* sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;*/ return fifoGetNonBlock( &(siostat->myfifo) ); } -void sio_expect_string( u8_t *str, sio_status_t * siostat ) +void sio_unix_expect_string( u8_t *str, sio_status_t * siostat ) { /* sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;*/ u8_t c; @@ -267,24 +267,24 @@ void sio_expect_string( u8_t *str, sio_status_t * siostat ) #endif /* ! PPP_SUPPORT */ #if PPP_SUPPORT -u32_t sio_write(sio_status_t * siostat, u8_t *buf, u32_t size) +u32_t sio_unix_write(sio_status_t * siostat, u8_t *buf, u32_t size) { return write( siostat->fd, buf, size ); } -u32_t sio_read(sio_status_t * siostat, u8_t *buf, u32_t size) +u32_t sio_unix_read(sio_status_t * siostat, u8_t *buf, u32_t size) { return read( siostat->fd, buf, size ); } -void sio_read_abort(sio_status_t * siostat) +void sio_unix_read_abort(sio_status_t * siostat) { LWIP_UNUSED_ARG(siostat); printf("sio_read_abort: not yet implemented for unix\n"); } #endif /* PPP_SUPPORT */ -sio_status_t * sio_open( int devnum ) +sio_status_t * sio_unix_open( int devnum ) { char dev[20]; @@ -308,9 +308,9 @@ sio_status_t * sio_open( int devnum ) if ( (devnum == 1) || (devnum == 0) ) { - if ( ( siostate->fd = sio_init( dev, devnum, siostate ) ) == 0 ) + if ( ( siostate->fd = sio_unix_init( dev, devnum, siostate ) ) == 0 ) { - LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: ERROR opening serial device\n" )); + LWIP_DEBUGF(SIO_DEBUG, ( "sio_unix_open: ERROR opening serial device\n" )); abort( ); return NULL; } @@ -340,17 +340,17 @@ sio_status_t * sio_open( int devnum ) perror("execl pppd"); exit (1); } else { - LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: spawned pppd pid %d\n", childpid)); + LWIP_DEBUGF(SIO_DEBUG, ( "sio_unix_open: spawned pppd pid %d\n", childpid)); } } #endif else { - LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: device %s (%d) is not supported\n", dev, devnum )); + LWIP_DEBUGF(SIO_DEBUG, ( "sio_unix_open: device %s (%d) is not supported\n", dev, devnum )); return NULL; } - LWIP_DEBUGF( 1,("sio_open: dev=%s open.\n", dev )); + LWIP_DEBUGF( 1,("sio_unix_open: dev=%s open.\n", dev )); return siostate; } @@ -358,32 +358,32 @@ sio_status_t * sio_open( int devnum ) /** * */ -void sio_change_baud( sioBaudrates baud, sio_status_t * siostat ) +void sio_unix_change_baud( sioBaudrates baud, sio_status_t * siostat ) { /* sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;*/ - LWIP_DEBUGF( 1,("sio_change_baud\n" )); + LWIP_DEBUGF( 1,("sio_unix_change_baud\n" )); switch ( baud ) { case SIO_BAUD_9600: - sio_speed( siostat->fd, B9600 ); + sio_unix_speed( siostat->fd, B9600 ); break; case SIO_BAUD_19200: - sio_speed( siostat->fd, B19200 ); + sio_unix_speed( siostat->fd, B19200 ); break; case SIO_BAUD_38400: - sio_speed( siostat->fd, B38400 ); + sio_unix_speed( siostat->fd, B38400 ); break; case SIO_BAUD_57600: - sio_speed( siostat->fd, B57600 ); + sio_unix_speed( siostat->fd, B57600 ); break; case SIO_BAUD_115200: - sio_speed( siostat->fd, B115200 ); + sio_unix_speed( siostat->fd, B115200 ); break; default: - LWIP_DEBUGF( 1,("sio_change_baud: Unknown baudrate, code:%d\n", baud )); + LWIP_DEBUGF( 1,("sio_unix_change_baud: Unknown baudrate, code:%d\n", baud )); break; } }