Prusa MINI Firmware overview
slipif.h File Reference
#include "lwip/opt.h"
#include "lwip/netif.h"

Go to the source code of this file.

Macros

#define SLIP_USE_RX_THREAD   !NO_SYS
 
#define SLIP_RX_FROM_ISR   0
 
#define SLIP_RX_QUEUE   SLIP_RX_FROM_ISR
 

Functions

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

Detailed Description

SLIP netif API

Macro Definition Documentation

◆ SLIP_USE_RX_THREAD

#define SLIP_USE_RX_THREAD   !NO_SYS

Set this to 1 to start a thread that blocks reading on the serial line (using sio_read()).

◆ SLIP_RX_FROM_ISR

#define SLIP_RX_FROM_ISR   0

Set this to 1 to enable functions to pass in RX bytes from ISR context. If enabled, slipif_received_byte[s]() process incoming bytes and put assembled packets on a queue, which is fed into lwIP from slipif_poll(). If disabled, slipif_poll() polls the serial line (using sio_tryread()).

◆ SLIP_RX_QUEUE

#define SLIP_RX_QUEUE   SLIP_RX_FROM_ISR

Set this to 1 (default for SLIP_RX_FROM_ISR) to queue incoming packets received by slipif_received_byte[s]() as long as PBUF_POOL pbufs are available. If disabled, packets will be dropped if more than one packet is received.

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
netif->num must contain the number of the serial port to open (0 by default). If netif->state is != NULL, it is interpreted as an u8_t pointer pointing to the serial port number instead of netif->num.
362 {
363  struct slipif_priv *priv;
364  u8_t sio_num;
365 
366  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));
367 
368  /* Allocate private data */
369  priv = (struct slipif_priv *)mem_malloc(sizeof(struct slipif_priv));
370  if (!priv) {
371  return ERR_MEM;
372  }
373 
374  netif->name[0] = 's';
375  netif->name[1] = 'l';
376 #if LWIP_IPV4
377  netif->output = slipif_output_v4;
378 #endif /* LWIP_IPV4 */
379 #if LWIP_IPV6
380  netif->output_ip6 = slipif_output_v6;
381 #endif /* LWIP_IPV6 */
383 
384  /* netif->state or netif->num contain the port number */
385  if (netif->state != NULL) {
386  sio_num = *(u8_t*)netif->state;
387  } else {
388  sio_num = netif->num;
389  }
390  /* Try to open the serial port. */
391  priv->sd = sio_open(sio_num);
392  if (!priv->sd) {
393  /* Opening the serial port failed. */
394  mem_free(priv);
395  return ERR_IF;
396  }
397 
398  /* Initialize private data */
399  priv->p = NULL;
400  priv->q = NULL;
401  priv->state = SLIP_RECV_NORMAL;
402  priv->i = 0;
403  priv->recved = 0;
404 #if SLIP_RX_FROM_ISR
405  priv->rxpackets = NULL;
406 #endif
407 
408  netif->state = priv;
409 
410  /* initialize the snmp variables and counters inside the struct netif */
411  MIB2_INIT_NETIF(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd));
412 
413 #if SLIP_USE_RX_THREAD
414  /* Create a thread to poll the serial line. */
415  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
417 #endif /* SLIP_USE_RX_THREAD */
418  return ERR_OK;
419 }
Here is the call graph for this function:

◆ 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
428 {
429  u8_t c;
430  struct slipif_priv *priv;
431 
432  LWIP_ASSERT("netif != NULL", (netif != NULL));
433  LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
434 
435  priv = (struct slipif_priv *)netif->state;
436 
437  while (sio_tryread(priv->sd, &c, 1) > 0) {
439  }
440 }
Here is the call graph for this function:
slipif_priv::recved
u16_t recved
Definition: slipif.c:100
SLIP_SIO_SPEED
#define SLIP_SIO_SPEED(sio_fd)
Definition: slipif.c:87
LWIP_ASSERT
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
slipif_priv::i
u16_t i
Definition: slipif.c:100
SLIPIF_THREAD_PRIO
#define SLIPIF_THREAD_PRIO
Definition: opt.h:1599
u16_t
uint16_t u16_t
Definition: arch.h:121
netif::state
void * state
Definition: netif.h:279
sys_thread_new
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
Definition: sys_arch.c:376
netif::mtu
u16_t mtu
Definition: netif.h:299
SLIP_DEBUG
#define SLIP_DEBUG
Definition: opt.h:2821
NULL
#define NULL
Definition: usbd_def.h:53
ERR_MEM
Definition: err.h:65
SLIPIF_THREAD_NAME
#define SLIPIF_THREAD_NAME
Definition: opt.h:1581
netif::num
u8_t num
Definition: netif.h:309
u8_t
uint8_t u8_t
Definition: arch.h:119
SLIP_MAX_SIZE
#define SLIP_MAX_SIZE
Definition: slipif.c:79
netif
Definition: netif.h:225
MIB2_INIT_NETIF
#define MIB2_INIT_NETIF(netif, type, speed)
Definition: snmp.h:138
SLIP_RECV_NORMAL
Definition: slipif.c:91
slipif_priv
Definition: slipif.c:95
ERR_IF
Definition: err.h:87
slipif_priv::sd
sio_fd_t sd
Definition: slipif.c:96
netif::name
char name[2]
Definition: netif.h:307
while
while(sofevent)
Definition: USB_HOST_SHIELD.h:456
sio_tryread
u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
U16_F
#define U16_F
Definition: arch.h:143
ERR_OK
Definition: err.h:63
slipif_priv::p
struct pbuf * p
Definition: slipif.c:98
sio_open
sio_fd_t sio_open(u8_t devnum)
slipif_rxbyte_input
static void slipif_rxbyte_input(struct netif *netif, u8_t c)
Definition: slipif.c:310
slipif_priv::q
struct pbuf * q
Definition: slipif.c:98
mem_malloc
void * mem_malloc(mem_size_t size)
Definition: mem.c:603
SLIPIF_THREAD_STACKSIZE
#define SLIPIF_THREAD_STACKSIZE
Definition: opt.h:1590
mem_free
void mem_free(void *rmem)
Definition: mem.c:419
slipif_priv::state
u8_t state
Definition: slipif.c:99
LWIP_DEBUGF
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:164