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

Go to the source code of this file.

Classes

struct  tcpip_api_call_data
 
struct  tcpip_msg
 

Macros

#define API_VAR_REF(name)   name
 
#define API_VAR_DECLARE(type, name)   type name
 
#define API_VAR_ALLOC(type, pool, name, errorval)
 
#define API_VAR_ALLOC_POOL(type, pool, name, errorval)
 
#define API_VAR_FREE(pool, name)
 
#define API_VAR_FREE_POOL(pool, name)
 
#define API_EXPR_REF(expr)   expr
 
#define API_EXPR_REF_SEM(expr)   API_EXPR_REF(expr)
 
#define API_EXPR_DEREF(expr)   (*(expr))
 
#define API_MSG_M_DEF(m)   *m
 
#define API_MSG_M_DEF_C(t, m)   const t * m
 

Typedefs

typedef err_t(* tcpip_api_call_fn) (struct tcpip_api_call_data *call)
 

Enumerations

enum  tcpip_msg_type {
  TCPIP_MSG_API, TCPIP_MSG_API_CALL, TCPIP_MSG_INPKT, TCPIP_MSG_CALLBACK,
  TCPIP_MSG_CALLBACK_STATIC
}
 

Functions

err_t tcpip_send_msg_wait_sem (tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem)
 
err_t tcpip_api_call (tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
 

Detailed Description

TCPIP API internal implementations (do not use in application code)

Macro Definition Documentation

◆ API_VAR_REF

#define API_VAR_REF (   name)    name

◆ API_VAR_DECLARE

#define API_VAR_DECLARE (   type,
  name 
)    type name

◆ API_VAR_ALLOC

#define API_VAR_ALLOC (   type,
  pool,
  name,
  errorval 
)

◆ API_VAR_ALLOC_POOL

#define API_VAR_ALLOC_POOL (   type,
  pool,
  name,
  errorval 
)

◆ API_VAR_FREE

#define API_VAR_FREE (   pool,
  name 
)

◆ API_VAR_FREE_POOL

#define API_VAR_FREE_POOL (   pool,
  name 
)

◆ API_EXPR_REF

#define API_EXPR_REF (   expr)    expr

◆ API_EXPR_REF_SEM

#define API_EXPR_REF_SEM (   expr)    API_EXPR_REF(expr)

◆ API_EXPR_DEREF

#define API_EXPR_DEREF (   expr)    (*(expr))

◆ API_MSG_M_DEF

#define API_MSG_M_DEF (   m)    *m

◆ API_MSG_M_DEF_C

#define API_MSG_M_DEF_C (   t,
 
)    const t * m

Typedef Documentation

◆ tcpip_api_call_fn

typedef err_t(* tcpip_api_call_fn) (struct tcpip_api_call_data *call)

Enumeration Type Documentation

◆ tcpip_msg_type

Enumerator
TCPIP_MSG_API 
TCPIP_MSG_API_CALL 
TCPIP_MSG_INPKT 
TCPIP_MSG_CALLBACK 
TCPIP_MSG_CALLBACK_STATIC 
111  {
115 #if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS
116  TCPIP_MSG_TIMEOUT,
117  TCPIP_MSG_UNTIMEOUT,
118 #endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */
121 };

Function Documentation

◆ tcpip_send_msg_wait_sem()

err_t tcpip_send_msg_wait_sem ( tcpip_callback_fn  fn,
void apimsg,
sys_sem_t sem 
)

Sends a message to TCPIP thread to call a function. Caller thread blocks on on a provided semaphore, which ist NOT automatically signalled by TCPIP thread, this has to be done by the user. It is recommended to use LWIP_TCPIP_CORE_LOCKING since this is the way with least runtime overhead.

Parameters
fnfunction to be called from TCPIP thread
apimsgargument to API function
semsemaphore to wait on
Returns
ERR_OK if the function was called, another err_t if not
330 {
331 #if LWIP_TCPIP_CORE_LOCKING
332  LWIP_UNUSED_ARG(sem);
333  LOCK_TCPIP_CORE();
334  fn(apimsg);
336  return ERR_OK;
337 #else /* LWIP_TCPIP_CORE_LOCKING */
339 
340  LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem));
341  LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
342 
343  TCPIP_MSG_VAR_ALLOC(msg);
344  TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API;
345  TCPIP_MSG_VAR_REF(msg).msg.api_msg.function = fn;
346  TCPIP_MSG_VAR_REF(msg).msg.api_msg.msg = apimsg;
348  sys_arch_sem_wait(sem, 0);
349  TCPIP_MSG_VAR_FREE(msg);
350  return ERR_OK;
351 #endif /* LWIP_TCPIP_CORE_LOCKING */
352 }
Here is the call graph for this function:

◆ tcpip_api_call()

err_t tcpip_api_call ( tcpip_api_call_fn  fn,
struct tcpip_api_call_data call 
)

Synchronously calls function in TCPIP thread and waits for its completion. It is recommended to use LWIP_TCPIP_CORE_LOCKING (preferred) or LWIP_NETCONN_SEM_PER_THREAD. If not, a semaphore is created and destroyed on every call which is usually an expensive/slow operation.

Parameters
fnFunction to call
callCall parameters
Returns
Return value from tcpip_api_call_fn
366 {
367 #if LWIP_TCPIP_CORE_LOCKING
368  err_t err;
369  LOCK_TCPIP_CORE();
370  err = fn(call);
372  return err;
373 #else /* LWIP_TCPIP_CORE_LOCKING */
375 
376 #if !LWIP_NETCONN_SEM_PER_THREAD
377  err_t err = sys_sem_new(&call->sem, 0);
378  if (err != ERR_OK) {
379  return err;
380  }
381 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
382 
383  LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
384 
385  TCPIP_MSG_VAR_ALLOC(msg);
387  TCPIP_MSG_VAR_REF(msg).msg.api_call.arg = call;
388  TCPIP_MSG_VAR_REF(msg).msg.api_call.function = fn;
389 #if LWIP_NETCONN_SEM_PER_THREAD
390  TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = LWIP_NETCONN_THREAD_SEM_GET();
391 #else /* LWIP_NETCONN_SEM_PER_THREAD */
392  TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = &call->sem;
393 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
395  sys_arch_sem_wait(TCPIP_MSG_VAR_REF(msg).msg.api_call.sem, 0);
396  TCPIP_MSG_VAR_FREE(msg);
397 
398 #if !LWIP_NETCONN_SEM_PER_THREAD
399  sys_sem_free(&call->sem);
400 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
401 
402  return call->err;
403 #endif /* LWIP_TCPIP_CORE_LOCKING */
404 }
Here is the call graph for this function:
sys_mbox_valid_val
#define sys_mbox_valid_val(mbox)
Definition: sys.h:311
TCPIP_MSG_VAR_DECLARE
#define TCPIP_MSG_VAR_DECLARE(name)
Definition: tcpip.c:54
LWIP_ASSERT
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
TCPIP_MSG_INPKT
Definition: tcpip_priv.h:114
mbox
static sys_mbox_t mbox
Definition: tcpip.c:61
tcpip_api_call_data::err
err_t err
Definition: tcpip_priv.h:100
UNLOCK_TCPIP_CORE
#define UNLOCK_TCPIP_CORE()
Definition: tcpip.h:61
sys_arch_sem_wait
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
Definition: sys_arch.c:251
sys_mbox_post
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:96
tcpip_api_call_data::sem
sys_sem_t sem
Definition: tcpip_priv.h:102
TCPIP_MSG_VAR_REF
#define TCPIP_MSG_VAR_REF(name)
Definition: tcpip.c:53
TCPIP_MSG_VAR_ALLOC
#define TCPIP_MSG_VAR_ALLOC(name)
Definition: tcpip.c:55
LWIP_UNUSED_ARG
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:308
TCPIP_MSG_CALLBACK_STATIC
Definition: tcpip_priv.h:120
sys_sem_new
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
Definition: sys_arch.c:206
ERR_OK
Definition: err.h:63
err_t
s8_t err_t
Definition: err.h:57
TCPIP_MSG_API
Definition: tcpip_priv.h:112
TCPIP_MSG_API_CALL
Definition: tcpip_priv.h:113
TCPIP_MSG_VAR_FREE
#define TCPIP_MSG_VAR_FREE(name)
Definition: tcpip.c:56
sys_sem_valid
int sys_sem_valid(sys_sem_t *sem)
Definition: sys_arch.c:291
LOCK_TCPIP_CORE
#define LOCK_TCPIP_CORE()
Definition: tcpip.h:60
TCPIP_MSG_CALLBACK
Definition: tcpip_priv.h:119
sys_sem_free
void sys_sem_free(sys_sem_t *sem)
Definition: sys_arch.c:282