Reformatted the code to make it consistent with the rest of lwIP.

This commit is contained in:
adamdunkels 2002-11-02 20:40:06 +00:00
parent 4e4da8e019
commit 01cccf4aee

View File

@ -55,9 +55,10 @@ typedef struct slip_status_t {
static slip_status_t statusar[SLIPIF_NUM_OF_INTERFACES]; static slip_status_t statusar[SLIPIF_NUM_OF_INTERFACES];
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
err_t slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) err_t
slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
{ {
slip_status_t *slipState = (slip_status_t *) netif->state; slip_status_t *slipState = (slip_status_t *)netif->state;
struct pbuf *q; struct pbuf *q;
int i; int i;
u8_t c; u8_t c;
@ -87,11 +88,10 @@ err_t slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
return 0; return 0;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
static struct pbuf *
static struct pbuf * slipif_input( struct netif * netif ) slipif_input( struct netif * netif )
{ {
slip_status_t *slipState = (slip_status_t *) netif->state; slip_status_t *slipState = (slip_status_t *)netif->state;
u8_t c; u8_t c;
struct pbuf *p, *q; struct pbuf *p, *q;
int recved; int recved;
@ -101,34 +101,29 @@ static struct pbuf * slipif_input( struct netif * netif )
recved = i = 0; recved = i = 0;
c = 0; c = 0;
while ( 1 ) while(1) {
{ c = sio_recv(slipState->sio);
c = sio_recv( slipState->sio ); switch(c) {
switch ( c )
{
case SLIP_END: case SLIP_END:
if ( p == NULL ) if(p == NULL) {
{ return slipif_input(netif);
return slipif_input( netif );
} }
if ( recved > 0 ) if(recved > 0) {
{
/* Received whole packet. */ /* Received whole packet. */
pbuf_realloc( q, recved ); pbuf_realloc(q, recved);
#ifdef LINK_STATS #ifdef LINK_STATS
stats.link.recv++; ++stats.link.recv;
#endif /* LINK_STATS */ #endif /* LINK_STATS */
DEBUGF( SLIP_DEBUG, ("slipif: Got packet\n") ); DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
return q; return q;
} }
break; break;
case SLIP_ESC: case SLIP_ESC:
c = sio_recv( slipState->sio ); c = sio_recv(slipState->sio);
switch ( c ) switch(c) {
{
case SLIP_ESC_END: case SLIP_ESC_END:
c = SLIP_END; c = SLIP_END;
break; break;
@ -139,35 +134,28 @@ static struct pbuf * slipif_input( struct netif * netif )
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
if ( p == NULL ) if(p == NULL) {
{ DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
DEBUGF( SLIP_DEBUG, ("slipif_input: alloc\n") ); p = pbuf_alloc(PBUF_LINK, 128, PBUF_POOL);
p = pbuf_alloc( PBUF_LINK, 128, PBUF_POOL );
#ifdef LINK_STATS #ifdef LINK_STATS
if ( p == NULL ) if(p == NULL) {
{ ++stats.link.drop;
stats.link.drop++; DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
DEBUGF( SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n") );
} }
#endif /* LINK_STATS */ #endif /* LINK_STATS */
if ( q != NULL ) if(q != NULL) {
{ pbuf_chain(q, p);
pbuf_chain( q, p ); } else {
}
else
{
q = p; q = p;
} }
} }
if ( p != NULL && recved < MAX_SIZE ) if(p != NULL && recved < MAX_SIZE) {
{
((u8_t *)p->payload)[i] = c; ((u8_t *)p->payload)[i] = c;
recved++; recved++;
i++; i++;
if ( i >= p->len ) if(i >= p->len) {
{
i = 0; i = 0;
p = NULL; p = NULL;
} }
@ -179,56 +167,38 @@ static struct pbuf * slipif_input( struct netif * netif )
return NULL; return NULL;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
static void slipif_loop(void *nf) static void
slipif_loop(void *nf)
{ {
struct pbuf *p; struct pbuf *p;
struct netif *netif = (struct netif *) nf; struct netif *netif = (struct netif *)nf;
// slip_status_t *slipState = (slip_status_t *) netif->state; /* slip_status_t *slipState = (slip_status_t *) netif->state; */
while(1) { while(1) {
p = slipif_input( netif ); p = slipif_input(netif);
netif->input(p, netif); netif->input(p, netif);
} }
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
// void void
// sioslipif_init0(struct netif *netif) slipif_init(struct netif *netif)
// {
// slip_status_t * ss;
// printf("slipif_init0: netif->num=%x\n", (int)netif->num);
//
// netif->state = &statusar[0];
// netif->name[0] = 's';
// netif->name[1] = 'l';
// netif->output = sioslipif_output;
// netif->num = 0;
//
// sio_open( netif );
// ss = (slip_status_t*)(netif->state);
// printf("slipif_init0: netif=%x sio=0x%x\n", (int)netif, (int)(ss->sio));
// sys_thread_new((void *)slipif_loop, netif);
// }
/*-----------------------------------------------------------------------------------*/
void slipif_init(struct netif *netif)
{ {
slip_status_t *slipState; slip_status_t *slipState;
DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%x\n", (int)netif->num)); DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%x\n", (int)netif->num));
if ( netif->num >= SLIPIF_NUM_OF_INTERFACES ) if(netif->num >= SLIPIF_NUM_OF_INTERFACES) {
{
DEBUGF( SLIP_DEBUG, ("ERROR: To many slipifs")); DEBUGF( SLIP_DEBUG, ("ERROR: To many slipifs"));
return; return;
} }
/* dynamic allocation would be nice */ /* dynamic allocation would be nice */
netif->state = &statusar[ netif->num ]; netif->state = &statusar[netif->num];
netif->name[0] = 's'; netif->name[0] = 's';
netif->name[1] = 'l'; netif->name[1] = 'l';
netif->output = slipif_output; netif->output = slipif_output;
slipState = (slip_status_t *) netif->state; slipState = (slip_status_t *)netif->state;
slipState->sio = sio_open( netif->num ); slipState->sio = sio_open(netif->num);
sys_thread_new(slipif_loop, netif); sys_thread_new(slipif_loop, netif);
} }