ConOpSys V2970
P004.07
ANVILEX control operating system
|
#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"
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 |
Sequential API Main thread module
#define TCPIP_MBOX_FETCH | ( | mbox, | |
msg | |||
) | sys_mbox_fetch(mbox, msg) |
#define TCPIP_MSG_VAR_ALLOC | ( | name | ) | API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM) |
#define TCPIP_MSG_VAR_DECLARE | ( | name | ) | API_VAR_DECLARE(struct tcpip_msg, name) |
#define TCPIP_MSG_VAR_FREE | ( | name | ) | API_VAR_FREE(MEMP_TCPIP_MSG_API, name) |
#define TCPIP_MSG_VAR_REF | ( | name | ) | API_VAR_REF(name) |
err_t mem_free_callback | ( | void * | m | ) |
A simple wrapper function that allows you to free heap memory from interrupt context.
m | the heap memory to free |
References mem_free(), and tcpip_try_callback().
A simple wrapper function that allows you to free a pbuf from interrupt context.
p | The pbuf (chain) to be dereferenced. |
References pbuf_free_int(), and tcpip_try_callback().
|
static |
Simple callback function used with tcpip_callback to free a pbuf (pbuf_free has a wrong signature for tcpip_callback)
p | The pbuf (chain) to be dereferenced. |
References pbuf_free().
Referenced by pbuf_free_callback().
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.
fn | Function to call |
call | Call parameters |
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.
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!
function | the function to call |
ctx | parameter passed to f |
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.
void tcpip_callbackmsg_delete | ( | struct tcpip_callback_msg * | msg | ) |
Free a callback message allocated by tcpip_callbackmsg_new().
msg | the message to free |
References memp_free(), and tcpip_msg::msg.
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.
function | the function to call |
ctx | parameter passed to function |
References tcpip_msg::ctx, memp_malloc(), tcpip_msg::msg, NULL, and TCPIP_MSG_CALLBACK_STATIC.
err_t tcpip_callbackmsg_trycallback | ( | struct tcpip_callback_msg * | msg | ) |
Try to post a callback-message to the tcpip_thread tcpip_mbox.
msg | pointer to the message to post |
References LWIP_ASSERT, tcpip_msg::msg, sys_mbox_trypost(), sys_mbox_valid_val, and tcpip_mbox.
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.
msg | pointer to the message to post |
References LWIP_ASSERT, tcpip_msg::msg, sys_mbox_trypost_fromisr(), sys_mbox_valid_val, and tcpip_mbox.
void tcpip_init | ( | tcpip_init_done_fn | initfunc, |
void * | arg | ||
) |
initialise this module:
initfunc | a function to call when tcpip_thread is running and finished initialising |
arg | argument 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.
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
p | the received packet |
inp | the network interface on which the packet was received |
input_fn | input 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().
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().
p | the 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) |
inp | the 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().
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.
fn | function to be called from TCPIP thread |
apimsg | argument to API function |
sem | semaphore to wait on |
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.
|
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.
arg | unused 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().
|
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().
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.
function | the function to call |
ctx | parameter passed to f |
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().
|
static |
Referenced by tcpip_init(), and tcpip_thread().
|
static |
Referenced by tcpip_init(), and tcpip_thread().
|
static |