ConOpSys V2970  P004.07
ANVILEX control operating system
Macros | Functions | Variables
tcpip.c File Reference
#include "lwip/opt.h"
#include "lwip/priv/tcpip_priv.h"
#include "lwip/sys.h"
#include "lwip/memp.h"
#include "lwip/mem.h"
#include "lwip/init.h"
#include "lwip/ip.h"
#include "lwip/pbuf.h"
#include "lwip/etharp.h"
#include "netif/ethernet.h"
Include dependency graph for tcpip.c:

Macros

#define TCPIP_MSG_VAR_REF(name)   API_VAR_REF(name)
 
#define TCPIP_MSG_VAR_DECLARE(name)   API_VAR_DECLARE(struct tcpip_msg, name)
 
#define TCPIP_MSG_VAR_ALLOC(name)   API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM)
 
#define TCPIP_MSG_VAR_FREE(name)   API_VAR_FREE(MEMP_TCPIP_MSG_API, name)
 
#define TCPIP_MBOX_FETCH(mbox, msg)   sys_mbox_fetch(mbox, msg)
 

Functions

static void tcpip_thread_handle_msg (struct tcpip_msg *msg)
 
static void tcpip_thread (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 (tcpip_callback_fn function, void *ctx)
 
err_t tcpip_try_callback (tcpip_callback_fn function, void *ctx)
 
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)
 
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_callbackmsg_trycallback (struct tcpip_callback_msg *msg)
 
err_t tcpip_callbackmsg_trycallback_fromisr (struct tcpip_callback_msg *msg)
 
void tcpip_init (tcpip_init_done_fn initfunc, void *arg)
 
static void pbuf_free_int (void *p)
 
err_t pbuf_free_callback (struct pbuf *p)
 
err_t mem_free_callback (void *m)
 

Variables

static tcpip_init_done_fn tcpip_init_done
 
static void * tcpip_init_done_arg
 
static sys_mbox_t tcpip_mbox
 

Detailed Description

Sequential API Main thread module

Macro Definition Documentation

◆ TCPIP_MBOX_FETCH

#define TCPIP_MBOX_FETCH (   mbox,
  msg 
)    sys_mbox_fetch(mbox, msg)

◆ TCPIP_MSG_VAR_ALLOC

#define TCPIP_MSG_VAR_ALLOC (   name)    API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM)

◆ TCPIP_MSG_VAR_DECLARE

#define TCPIP_MSG_VAR_DECLARE (   name)    API_VAR_DECLARE(struct tcpip_msg, name)

◆ TCPIP_MSG_VAR_FREE

#define TCPIP_MSG_VAR_FREE (   name)    API_VAR_FREE(MEMP_TCPIP_MSG_API, name)

◆ TCPIP_MSG_VAR_REF

#define TCPIP_MSG_VAR_REF (   name)    API_VAR_REF(name)

Function Documentation

◆ 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

References mem_free(), and tcpip_try_callback().

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

References pbuf_free_int(), and tcpip_try_callback().

Here is the call graph for this function:

◆ pbuf_free_int()

static void pbuf_free_int ( void *  p)
static

Simple callback function used with tcpip_callback to free a pbuf (pbuf_free has a wrong signature for tcpip_callback)

Parameters
pThe pbuf (chain) to be dereferenced.

References pbuf_free().

Referenced by pbuf_free_callback().

Here is the call graph for this function:
Here is the caller 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

References tcpip_api_call_data::err, ERR_OK, LOCK_TCPIP_CORE, LWIP_ASSERT, tcpip_msg::msg, tcpip_api_call_data::sem, sys_arch_sem_wait(), sys_mbox_post(), sys_mbox_valid_val, sys_sem_free(), sys_sem_new(), tcpip_mbox, TCPIP_MSG_API_CALL, TCPIP_MSG_VAR_ALLOC, TCPIP_MSG_VAR_DECLARE, TCPIP_MSG_VAR_FREE, TCPIP_MSG_VAR_REF, and UNLOCK_TCPIP_CORE.

Here is the call graph for this function:

◆ tcpip_callback()

err_t tcpip_callback ( tcpip_callback_fn  function,
void *  ctx 
)

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. Blocks until the request is posted. Must not be called from interrupt context!

Parameters
functionthe function to call
ctxparameter passed to f
Returns
ERR_OK if the function was called, another err_t if not
See also
tcpip_try_callback

References tcpip_msg::ctx, ERR_MEM, ERR_OK, LWIP_ASSERT, memp_malloc(), tcpip_msg::msg, NULL, sys_mbox_post(), sys_mbox_valid_val, tcpip_mbox, and TCPIP_MSG_CALLBACK.

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
See also
tcpip_callbackmsg_new()

References memp_free(), and tcpip_msg::msg.

Here is the call 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 initialise it. The message has a special type such that lwIP never frees it. This is intended to be used to send "static" messages from interrupt context, e.g. the message is allocated once and posted several times from an IRQ using tcpip_callbackmsg_trycallback(). Example usage: Trigger execution of an ethernet IRQ DPC routine in lwIP thread context.

Parameters
functionthe function to call
ctxparameter passed to function
Returns
a struct pointer to pass to tcpip_callbackmsg_trycallback().
See also
tcpip_callbackmsg_trycallback()
tcpip_callbackmsg_delete()

References tcpip_msg::ctx, memp_malloc(), tcpip_msg::msg, NULL, and TCPIP_MSG_CALLBACK_STATIC.

Here is the call graph for this function:

◆ tcpip_callbackmsg_trycallback()

err_t tcpip_callbackmsg_trycallback ( struct tcpip_callback_msg *  msg)

Try to post a callback-message to the tcpip_thread tcpip_mbox.

Parameters
msgpointer to the message to post
Returns
sys_mbox_trypost() return code
See also
tcpip_callbackmsg_new()

References LWIP_ASSERT, tcpip_msg::msg, sys_mbox_trypost(), sys_mbox_valid_val, and tcpip_mbox.

Here is the call graph for this function:

◆ tcpip_callbackmsg_trycallback_fromisr()

err_t tcpip_callbackmsg_trycallback_fromisr ( struct tcpip_callback_msg *  msg)

Try to post a callback-message to the tcpip_thread mbox. Same as tcpip_callbackmsg_trycallback but calls sys_mbox_trypost_fromisr(), mainly to help FreeRTOS, where calls differ between task level and ISR level.

Parameters
msgpointer to the message to post
Returns
sys_mbox_trypost_fromisr() return code (without change, so this knowledge can be used to e.g. propagate "bool needs_scheduling")
See also
tcpip_callbackmsg_new()

References LWIP_ASSERT, tcpip_msg::msg, sys_mbox_trypost_fromisr(), sys_mbox_valid_val, and tcpip_mbox.

Here is the call graph for this function:

◆ tcpip_init()

void tcpip_init ( tcpip_init_done_fn  initfunc,
void *  arg 
)

initialise this module:

  • initialise all sub modules
  • start the tcpip_thread
Parameters
initfunca function to call when tcpip_thread is running and finished initialising
argargument to pass to initfunc

References tcpip_msg::arg, ERR_OK, LWIP_ASSERT, lwip_init(), NULL, sys_mbox_new(), sys_mutex_new(), sys_thread_new(), tcpip_init_done, tcpip_init_done_arg, tcpip_mbox, TCPIP_MBOX_SIZE, tcpip_thread(), TCPIP_THREAD_NAME, TCPIP_THREAD_PRIO, and TCPIP_THREAD_STACKSIZE.

Here is the call 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

References ERR_MEM, ERR_OK, tcpip_msg::inp, tcpip_msg::input_fn, LOCK_TCPIP_CORE, LWIP_ASSERT, LWIP_DEBUGF, memp_free(), memp_malloc(), tcpip_msg::msg, NULL, tcpip_msg::p, sys_mbox_trypost(), sys_mbox_valid_val, TCPIP_DEBUG, tcpip_mbox, TCPIP_MSG_INPKT, and UNLOCK_TCPIP_CORE.

Referenced by tcpip_input().

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

References tcpip_msg::inp, NETIF_FLAG_ETHARP, NETIF_FLAG_ETHERNET, tcpip_msg::p, and tcpip_inpkt().

Referenced by netif_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

References ERR_OK, LOCK_TCPIP_CORE, LWIP_ASSERT, LWIP_UNUSED_ARG, tcpip_msg::msg, tcpip_msg::sem, sys_arch_sem_wait(), sys_mbox_post(), sys_mbox_valid_val, sys_sem_valid(), tcpip_mbox, TCPIP_MSG_API, TCPIP_MSG_VAR_ALLOC, TCPIP_MSG_VAR_DECLARE, TCPIP_MSG_VAR_FREE, TCPIP_MSG_VAR_REF, and UNLOCK_TCPIP_CORE.

Here is the call graph for this function:

◆ tcpip_thread()

static void tcpip_thread ( void *  arg)
static

The main lwIP thread. This thread has exclusive access to lwIP core functions (unless access to them is not locked). Other threads communicate with this thread using message boxes.

It also starts all the timers to make sure they are running in the right thread context.

Parameters
argunused argument

References tcpip_msg::arg, LOCK_TCPIP_CORE, LWIP_ASSERT, LWIP_DEBUGF, LWIP_MARK_TCPIP_THREAD, LWIP_TCPIP_THREAD_ALIVE, LWIP_UNUSED_ARG, tcpip_msg::msg, NULL, TCPIP_DEBUG, tcpip_init_done, tcpip_init_done_arg, tcpip_mbox, TCPIP_MBOX_FETCH, and tcpip_thread_handle_msg().

Referenced by tcpip_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpip_thread_handle_msg()

static void tcpip_thread_handle_msg ( struct tcpip_msg msg)
static

References ERR_OK, LWIP_ASSERT, LWIP_DEBUGF, memp_free(), tcpip_msg::msg, pbuf_free(), sys_sem_signal(), TCPIP_DEBUG, TCPIP_MSG_API, TCPIP_MSG_API_CALL, TCPIP_MSG_CALLBACK, TCPIP_MSG_CALLBACK_STATIC, and TCPIP_MSG_INPKT.

Referenced by tcpip_thread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcpip_try_callback()

err_t tcpip_try_callback ( tcpip_callback_fn  function,
void *  ctx 
)

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. Does NOT block when the request cannot be posted because the tcpip_mbox is full, but returns ERR_MEM instead. Can be called from interrupt context.

Parameters
functionthe function to call
ctxparameter passed to f
Returns
ERR_OK if the function was called, another err_t if not
See also
tcpip_callback

References tcpip_msg::ctx, ERR_MEM, ERR_OK, LWIP_ASSERT, memp_free(), memp_malloc(), tcpip_msg::msg, NULL, sys_mbox_trypost(), sys_mbox_valid_val, tcpip_mbox, and TCPIP_MSG_CALLBACK.

Referenced by mem_free_callback(), and pbuf_free_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ tcpip_init_done

tcpip_init_done_fn tcpip_init_done
static

Referenced by tcpip_init(), and tcpip_thread().

◆ tcpip_init_done_arg

void* tcpip_init_done_arg
static

Referenced by tcpip_init(), and tcpip_thread().

◆ tcpip_mbox

sys_mbox_t tcpip_mbox
static