ReactOS 0.4.16-dev-334-g4d9f67c
SLIP
Collaboration diagram for SLIP:

Functions

err_t slipif_init (struct netif *netif)
 
void slipif_poll (struct netif *netif)
 

Detailed Description

This is an arch independent SLIP netif. The specific serial hooks must be provided by another file. They are sio_open, sio_read/sio_tryread and sio_send

Usage: This netif can be used in three ways:

  1. For NO_SYS==0, an RX thread can be used which blocks on sio_read() until data is received.
  2. In your main loop, call slipif_poll() to check for new RX bytes, completed packets are fed into netif->input().
  3. Call slipif_received_byte[s]() from your serial RX ISR and slipif_process_rxqueue() from your main loop. ISR level decodes packets and puts completed packets on a queue which is fed into the stack from the main loop (needs SYS_LIGHTWEIGHT_PROT for pbuf_alloc to work on ISR level!).

Function Documentation

◆ slipif_init()

err_t slipif_init ( struct netif netif)

SLIP netif initialization

Call the arch specific sio_open and remember the opened device in the state field of the netif.

Parameters
netifthe lwip network interface structure for this slipif
Returns
ERR_OK if serial line could be opened, ERR_MEM if no memory could be allocated, ERR_IF is serial line couldn't be opened
Note
If netif->state is interpreted as an u8_t serial port number.

Definition at line 360 of file slipif.c.

361{
362 struct slipif_priv *priv;
363 u8_t sio_num;
364
365 LWIP_ASSERT("slipif needs an input callback", netif->input != NULL);
366
367 /* netif->state contains serial port number */
369
370 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)sio_num));
371
372 /* Allocate private data */
373 priv = (struct slipif_priv *)mem_malloc(sizeof(struct slipif_priv));
374 if (!priv) {
375 return ERR_MEM;
376 }
377
378 netif->name[0] = 's';
379 netif->name[1] = 'l';
380#if LWIP_IPV4
381 netif->output = slipif_output_v4;
382#endif /* LWIP_IPV4 */
383#if LWIP_IPV6
384 netif->output_ip6 = slipif_output_v6;
385#endif /* LWIP_IPV6 */
387
388 /* Try to open the serial port. */
389 priv->sd = sio_open(sio_num);
390 if (!priv->sd) {
391 /* Opening the serial port failed. */
392 mem_free(priv);
393 return ERR_IF;
394 }
395
396 /* Initialize private data */
397 priv->p = NULL;
398 priv->q = NULL;
399 priv->state = SLIP_RECV_NORMAL;
400 priv->i = 0;
401 priv->recved = 0;
402#if SLIP_RX_FROM_ISR
403 priv->rxpackets = NULL;
404#endif
405
406 netif->state = priv;
407
408 /* initialize the snmp variables and counters inside the struct netif */
409 MIB2_INIT_NETIF(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd));
410
411#if SLIP_USE_RX_THREAD
412 /* Create a thread to poll the serial line. */
413 sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
415#endif /* SLIP_USE_RX_THREAD */
416 return ERR_OK;
417}
#define mem_free(ptr, bsize)
Definition: types.h:124
#define NULL
Definition: types.h:112
#define U16_F
Definition: cc.h:19
void * mem_malloc(mem_size_t size_in)
Definition: mem.c:831
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:158
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
sio_fd_t sio_open(u8_t devnum)
#define MIB2_INIT_NETIF(netif, type, speed)
Definition: snmp.h:138
#define ERR_MEM
Definition: fontsub.h:52
uint8_t u8_t
Definition: arch.h:125
#define LWIP_PTR_NUMERIC_CAST(target_type, val)
Definition: arch.h:252
uint16_t u16_t
Definition: arch.h:127
@ ERR_IF
Definition: err.h:79
@ ERR_OK
Definition: err.h:55
#define SLIP_DEBUG
Definition: opt.h:3519
#define SLIPIF_THREAD_PRIO
Definition: opt.h:1867
#define SLIPIF_THREAD_STACKSIZE
Definition: opt.h:1858
#define SLIPIF_THREAD_NAME
Definition: opt.h:1849
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
Definition: sys_arch.c:275
#define SLIP_SIO_SPEED(sio_fd)
Definition: slipif.c:87
#define SLIP_MAX_SIZE
Definition: slipif.c:79
@ SLIP_RECV_NORMAL
Definition: slipif.c:91
Definition: netif.h:269
char name[2]
Definition: netif.h:356
void * state
Definition: netif.h:332
netif_input_fn input
Definition: netif.h:297
u16_t mtu
Definition: netif.h:344
struct pbuf * p
Definition: slipif.c:98
u16_t recved
Definition: slipif.c:100
struct pbuf * q
Definition: slipif.c:98
sio_fd_t sd
Definition: slipif.c:96
u8_t state
Definition: slipif.c:99
u16_t i
Definition: slipif.c:100

◆ slipif_poll()

void slipif_poll ( struct netif netif)

Polls the serial device and feeds the IP layer with incoming packets.

Parameters
netifThe lwip network interface structure for this slipif

Definition at line 426 of file slipif.c.

427{
428 u8_t c;
429 struct slipif_priv *priv;
430
431 LWIP_ASSERT("netif != NULL", (netif != NULL));
432 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
433
434 priv = (struct slipif_priv *)netif->state;
435
436 while (sio_tryread(priv->sd, &c, 1) > 0) {
438 }
439}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
static void slipif_rxbyte_input(struct netif *netif, u8_t c)
Definition: slipif.c:310