Prusa MINI Firmware overview
tcpip.h File Reference
#include "lwip/opt.h"
#include "lwip/err.h"
#include "lwip/timeouts.h"
#include "lwip/netif.h"

Go to the source code of this file.

Macros

#define LOCK_TCPIP_CORE()
 
#define UNLOCK_TCPIP_CORE()
 
#define tcpip_callback(f, ctx)   tcpip_callback_with_block(f, ctx, 1)
 

Typedefs

typedef void(* tcpip_init_done_fn) (void *arg)
 
typedef void(* tcpip_callback_fn) (void *ctx)
 

Functions

void tcpip_init (tcpip_init_done_fn tcpip_init_done, void *arg)
 
err_t tcpip_inpkt (struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
 
err_t tcpip_input (struct pbuf *p, struct netif *inp)
 
err_t tcpip_callback_with_block (tcpip_callback_fn function, void *ctx, u8_t block)
 
struct tcpip_callback_msg * tcpip_callbackmsg_new (tcpip_callback_fn function, void *ctx)
 
void tcpip_callbackmsg_delete (struct tcpip_callback_msg *msg)
 
err_t tcpip_trycallback (struct tcpip_callback_msg *msg)
 
err_t pbuf_free_callback (struct pbuf *p)
 
err_t mem_free_callback (void *m)
 

Detailed Description

Functions to sync with TCPIP thread

Macro Definition Documentation

◆ LOCK_TCPIP_CORE

#define LOCK_TCPIP_CORE ( )

◆ UNLOCK_TCPIP_CORE

#define UNLOCK_TCPIP_CORE ( )

◆ tcpip_callback

#define tcpip_callback (   f,
  ctx 
)    tcpip_callback_with_block(f, ctx, 1)

Typedef Documentation

◆ tcpip_init_done_fn

typedef void(* tcpip_init_done_fn) (void *arg)

Function prototype for the init_done function passed to tcpip_init

◆ tcpip_callback_fn

typedef void(* tcpip_callback_fn) (void *ctx)

Function prototype for functions passed to tcpip_callback()

Function Documentation

◆ tcpip_init()

void tcpip_init ( tcpip_init_done_fn  initfunc,
void arg 
)

Initialize this module:

  • initialize all sub modules
  • start the tcpip_thread
Parameters
initfunca function to call when tcpip_thread is running and finished initializing
argargument to pass to initfunc
463 {
464  lwip_init();
465 
466  tcpip_init_done = initfunc;
467  tcpip_init_done_arg = arg;
469  LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
470  }
471 #if LWIP_TCPIP_CORE_LOCKING
472  if (sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
473  LWIP_ASSERT("failed to create lock_tcpip_core", 0);
474  }
475 #endif /* LWIP_TCPIP_CORE_LOCKING */
476 
478 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpip_inpkt()

err_t tcpip_inpkt ( struct pbuf p,
struct netif inp,
netif_input_fn  input_fn 
)

Pass a received packet to tcpip_thread for input processing

Parameters
pthe received packet
inpthe network interface on which the packet was received
input_fninput function to call
170 {
171 #if LWIP_TCPIP_CORE_LOCKING_INPUT
172  err_t ret;
173  LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_inpkt: PACKET %p/%p\n", (void *)p, (void *)inp));
174  LOCK_TCPIP_CORE();
175  ret = input_fn(p, inp);
177  return ret;
178 #else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
179  struct tcpip_msg *msg;
180 
181  LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
182 
183  msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
184  if (msg == NULL) {
185  return ERR_MEM;
186  }
187 
188  msg->type = TCPIP_MSG_INPKT;
189  msg->msg.inp.p = p;
190  msg->msg.inp.netif = inp;
191  msg->msg.inp.input_fn = input_fn;
192  if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
193  memp_free(MEMP_TCPIP_MSG_INPKT, msg);
194  return ERR_MEM;
195  }
196  return ERR_OK;
197 #endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
198 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpip_input()

err_t tcpip_input ( struct pbuf p,
struct netif inp 
)

Pass a received packet to tcpip_thread for input processing with ethernet_input or ip_input. Don't call directly, pass to netif_add() and call netif->input().

Parameters
pthe received packet, p->payload pointing to the Ethernet header or to an IP header (if inp doesn't have NETIF_FLAG_ETHARP or NETIF_FLAG_ETHERNET flags)
inpthe network interface on which the packet was received
213 {
214 #if LWIP_ETHERNET
215  if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
216  return tcpip_inpkt(p, inp, ethernet_input);
217  } else
218 #endif /* LWIP_ETHERNET */
219  return tcpip_inpkt(p, inp, ip_input);
220 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpip_callback_with_block()

err_t tcpip_callback_with_block ( tcpip_callback_fn  function,
void ctx,
u8_t  block 
)

Call a specific function in the thread context of tcpip_thread for easy access synchronization. A function called in that way may access lwIP core code without fearing concurrent access.

Parameters
functionthe function to call
ctxparameter passed to f
block1 to block until the request is posted, 0 to non-blocking mode
Returns
ERR_OK if the function was called, another err_t if not
235 {
236  struct tcpip_msg *msg;
237 
238  LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
239 
240  msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
241  if (msg == NULL) {
242  return ERR_MEM;
243  }
244 
245  msg->type = TCPIP_MSG_CALLBACK;
246  msg->msg.cb.function = function;
247  msg->msg.cb.ctx = ctx;
248  if (block) {
250  } else {
251  if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
252  memp_free(MEMP_TCPIP_MSG_API, msg);
253  return ERR_MEM;
254  }
255  }
256  return ERR_OK;
257 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpip_callbackmsg_new()

struct tcpip_callback_msg* tcpip_callbackmsg_new ( tcpip_callback_fn  function,
void ctx 
)

Allocate a structure for a static callback message and initialize it. This is intended to be used to send "static" messages from interrupt context.

Parameters
functionthe function to call
ctxparameter passed to function
Returns
a struct pointer to pass to tcpip_trycallback().
416 {
417  struct tcpip_msg *msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
418  if (msg == NULL) {
419  return NULL;
420  }
422  msg->msg.cb.function = function;
423  msg->msg.cb.ctx = ctx;
424  return (struct tcpip_callback_msg*)msg;
425 }
Here is the call graph for this function:

◆ tcpip_callbackmsg_delete()

void tcpip_callbackmsg_delete ( struct tcpip_callback_msg *  msg)

Free a callback message allocated by tcpip_callbackmsg_new().

Parameters
msgthe message to free
434 {
435  memp_free(MEMP_TCPIP_MSG_API, msg);
436 }
Here is the call graph for this function:

◆ tcpip_trycallback()

err_t tcpip_trycallback ( struct tcpip_callback_msg *  msg)

Try to post a callback-message to the tcpip_thread mbox This is intended to be used to send "static" messages from interrupt context.

Parameters
msgpointer to the message to post
Returns
sys_mbox_trypost() return code
447 {
448  LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
449  return sys_mbox_trypost(&mbox, msg);
450 }
Here is the call graph for this function:

◆ pbuf_free_callback()

err_t pbuf_free_callback ( struct pbuf p)

A simple wrapper function that allows you to free a pbuf from interrupt context.

Parameters
pThe pbuf (chain) to be dereferenced.
Returns
ERR_OK if callback could be enqueued, an err_t if not
501 {
503 }
Here is the call graph for this function:

◆ mem_free_callback()

err_t mem_free_callback ( void m)

A simple wrapper function that allows you to free heap memory from interrupt context.

Parameters
mthe heap memory to free
Returns
ERR_OK if callback could be enqueued, an err_t if not
514 {
515  return tcpip_callback_with_block(mem_free, m, 0);
516 }
Here is the call graph for this function:
sys_mbox_valid_val
#define sys_mbox_valid_val(mbox)
Definition: sys.h:311
tcpip_callback_with_block
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:234
memp_malloc
void * memp_malloc(memp_t type)
Definition: memp.c:385
lwip_init
void lwip_init(void)
Definition: init.c:337
TCPIP_DEBUG
#define TCPIP_DEBUG
Definition: opt.h:2814
LWIP_ASSERT
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
memp_free
void memp_free(memp_t type, void *mem)
Definition: memp.c:469
TCPIP_MSG_INPKT
Definition: tcpip_priv.h:114
sys_mbox_new
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
Definition: sys_arch.c:50
mbox
static sys_mbox_t mbox
Definition: tcpip.c:61
tcpip_init_done_arg
static void * tcpip_init_done_arg
Definition: tcpip.c:60
NETIF_FLAG_ETHARP
#define NETIF_FLAG_ETHARP
Definition: netif.h:91
UNLOCK_TCPIP_CORE
#define UNLOCK_TCPIP_CORE()
Definition: tcpip.h:61
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
NULL
#define NULL
Definition: usbd_def.h:53
sys_mbox_post
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:96
tcpip_msg::msg
void * msg
Definition: tcpip_priv.h:128
ERR_MEM
Definition: err.h:65
tcpip_thread
static void tcpip_thread(void *arg)
Definition: tcpip.c:87
TCPIP_MBOX_SIZE
#define TCPIP_MBOX_SIZE
Definition: opt.h:1566
tcpip_msg::input_fn
netif_input_fn input_fn
Definition: tcpip_priv.h:138
tcpip_inpkt
err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
Definition: tcpip.c:169
tcpip_msg::inp
struct tcpip_msg::@61::@64 inp
sys_mutex_new
err_t sys_mutex_new(sys_mutex_t *mutex)
Definition: sys_arch.c:319
TCPIP_MSG_CALLBACK_STATIC
Definition: tcpip_priv.h:120
tcpip_msg
Definition: tcpip_priv.h:123
ERR_OK
Definition: err.h:63
err_t
s8_t err_t
Definition: err.h:57
NETIF_FLAG_ETHERNET
#define NETIF_FLAG_ETHERNET
Definition: netif.h:95
TCPIP_THREAD_PRIO
#define TCPIP_THREAD_PRIO
Definition: opt.h:1557
tcpip_msg::ctx
void * ctx
Definition: tcpip_priv.h:142
pbuf_free_int
static void pbuf_free_int(void *p)
Definition: tcpip.c:487
TCPIP_THREAD_NAME
#define TCPIP_THREAD_NAME
Definition: opt.h:1539
sys_mbox_trypost
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:104
TCPIP_THREAD_STACKSIZE
#define TCPIP_THREAD_STACKSIZE
Definition: opt.h:1548
tcpip_msg::p
struct pbuf * p
Definition: tcpip_priv.h:136
mem_free
void mem_free(void *rmem)
Definition: mem.c:419
LWIP_DEBUGF
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:164
tcpip_init_done
static tcpip_init_done_fn tcpip_init_done
Definition: tcpip.c:59
LOCK_TCPIP_CORE
#define LOCK_TCPIP_CORE()
Definition: tcpip.h:60
TCPIP_MSG_CALLBACK
Definition: tcpip_priv.h:119