MeterLogger
Data Structures | Macros | Typedefs | Enumerations | Functions
tcpip.h File Reference
#include "lwip/opt.h"
#include "lwip/api_msg.h"
#include "lwip/netifapi.h"
#include "lwip/pbuf.h"
#include "lwip/api.h"
#include "lwip/sys.h"
#include "lwip/timers.h"
#include "lwip/netif.h"
Include dependency graph for tcpip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tcpip_msg
 

Macros

#define LWIP_TCPIP_THREAD_ALIVE()
 
#define LOCK_TCPIP_CORE()
 
#define UNLOCK_TCPIP_CORE()
 
#define TCPIP_APIMSG(m)   tcpip_apimsg(m)
 
#define TCPIP_APIMSG_ACK(m)   sys_sem_signal(&m->conn->op_completed)
 
#define TCPIP_NETIFAPI(m)   tcpip_netifapi(m)
 
#define TCPIP_NETIFAPI_ACK(m)   sys_sem_signal(&m->sem)
 
#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)
 

Enumerations

enum  tcpip_msg_type { TCPIP_MSG_INPKT, TCPIP_MSG_CALLBACK }
 

Functions

void tcpip_init (tcpip_init_done_fn tcpip_init_done, void *arg)
 
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)
 
err_t pbuf_free_callback (struct pbuf *p)
 
err_t mem_free_callback (void *m)
 

Macro Definition Documentation

◆ LOCK_TCPIP_CORE

#define LOCK_TCPIP_CORE ( )

Definition at line 67 of file tcpip.h.

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_thread().

◆ LWIP_TCPIP_THREAD_ALIVE

#define LWIP_TCPIP_THREAD_ALIVE ( )

Define this to something that triggers a watchdog. This is called from tcpip_thread after processing a message.

Definition at line 54 of file tcpip.h.

Referenced by tcpip_thread().

◆ TCPIP_APIMSG

#define TCPIP_APIMSG (   m)    tcpip_apimsg(m)

Definition at line 69 of file tcpip.h.

◆ TCPIP_APIMSG_ACK

#define TCPIP_APIMSG_ACK (   m)    sys_sem_signal(&m->conn->op_completed)

Definition at line 70 of file tcpip.h.

◆ tcpip_callback

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

Definition at line 99 of file tcpip.h.

Referenced by netif_set_link_down().

◆ TCPIP_NETIFAPI

#define TCPIP_NETIFAPI (   m)    tcpip_netifapi(m)

Definition at line 71 of file tcpip.h.

◆ TCPIP_NETIFAPI_ACK

#define TCPIP_NETIFAPI_ACK (   m)    sys_sem_signal(&m->sem)

Definition at line 72 of file tcpip.h.

◆ UNLOCK_TCPIP_CORE

#define UNLOCK_TCPIP_CORE ( )

Definition at line 68 of file tcpip.h.

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_thread().

Typedef Documentation

◆ tcpip_callback_fn

typedef void(* tcpip_callback_fn) (void *ctx)

Function prototype for functions passed to tcpip_callback()

Definition at line 78 of file tcpip.h.

◆ tcpip_init_done_fn

typedef void(* tcpip_init_done_fn) (void *arg)

Function prototype for the init_done function passed to tcpip_init

Definition at line 76 of file tcpip.h.

Enumeration Type Documentation

◆ tcpip_msg_type

Enumerator
TCPIP_MSG_INPKT 
TCPIP_MSG_CALLBACK 

Definition at line 110 of file tcpip.h.

110  {
111 #if LWIP_NETCONN
112  TCPIP_MSG_API,
113 #endif /* LWIP_NETCONN */
115 #if LWIP_NETIF_API
116  TCPIP_MSG_NETIFAPI,
117 #endif /* LWIP_NETIF_API */
118 #if LWIP_TCPIP_TIMEOUT
119  TCPIP_MSG_TIMEOUT,
120  TCPIP_MSG_UNTIMEOUT,
121 #endif /* LWIP_TCPIP_TIMEOUT */
123 };

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

Definition at line 455 of file tcpip.c.

References mem_free(), and tcpip_callback_with_block().

456 {
457  return tcpip_callback_with_block(mem_free, m, 0);
458 }
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:206
void mem_free(void *mem) ICACHE_FLASH_ATTR
Definition: mem.c:310
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

Definition at line 442 of file tcpip.c.

References pbuf_free_int(), and tcpip_callback_with_block().

443 {
445 }
static void pbuf_free_int(void *p)
Definition: tcpip.c:429
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:206
Here is the call 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
fthe 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

Definition at line 206 of file tcpip.c.

References tcpip_msg::cb, tcpip_msg::ctx, ERR_MEM, ERR_OK, ERR_VAL, LOCK_TCPIP_CORE, mbox, memp_free(), memp_malloc(), tcpip_msg::msg, NULL, sys_arch_sem_wait(), sys_mbox_post(), sys_mbox_trypost(), sys_mbox_valid(), sys_sem_free(), sys_sem_new(), sys_sem_wait, TCPIP_MSG_CALLBACK, tcpip_msg::type, and UNLOCK_TCPIP_CORE.

Referenced by mem_free_callback(), and pbuf_free_callback().

207 {
208  struct tcpip_msg *msg;
209 
210  if (sys_mbox_valid(&mbox)) {
211  msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
212  if (msg == NULL) {
213  return ERR_MEM;
214  }
215 
216  msg->type = TCPIP_MSG_CALLBACK;
217  msg->msg.cb.function = function;
218  msg->msg.cb.ctx = ctx;
219  if (block) {
220  sys_mbox_post(&mbox, msg);
221  } else {
222  if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
223  memp_free(MEMP_TCPIP_MSG_API, msg);
224  return ERR_MEM;
225  }
226  }
227  return ERR_OK;
228  }
229  return ERR_VAL;
230 }
void memp_free(memp_t type, void *mem) ICACHE_FLASH_ATTR
Definition: memp.c:438
int sys_mbox_valid(sys_mbox_t *mbox)
#define ERR_VAL
Definition: err.h:58
#define NULL
Definition: def.h:47
void * memp_malloc(memp_t type) ICACHE_FLASH_ATTR
Definition: memp.c:393
enum tcpip_msg_type type
Definition: tcpip.h:126
union tcpip_msg::@2 msg
#define ERR_OK
Definition: err.h:52
struct tcpip_msg::@2::@4 cb
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
void * ctx
Definition: tcpip.h:141
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
static sys_mbox_t mbox
Definition: tcpip.c:55
#define ERR_MEM
Definition: err.h:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 404 of file tcpip.c.

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

405 {
406  lwip_init();//初始化内核 tcpip_init_done = initfunc;//注册用户自定义函数 tcpip_init_done_arg = arg;//函数参数 if(sys_mbox_new(&mbox, TCPIP_MBOX_SIZE) != ERR_OK) {//创建内核邮箱 LWIP_ASSERT("failed to create tcpip_thread mbox", 0); } #if LWIP_TCPIP_CORE_LOCKING if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) { LWIP_ASSERT("failed to create lock_tcpip_core", 0); } #endif /* LWIP_TCPIP_CORE_LOCKING */ sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);//创建内核进程 }
407 
408  tcpip_init_done = initfunc;//注册用户自定义函数
409  tcpip_init_done_arg = arg;//函数参数 if(sys_mbox_new(&mbox, TCPIP_MBOX_SIZE) != ERR_OK) {//创建内核邮箱 LWIP_ASSERT("failed to create tcpip_thread mbox", 0); } #if LWIP_TCPIP_CORE_LOCKING if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) { LWIP_ASSERT("failed to create lock_tcpip_core", 0); } #endif /* LWIP_TCPIP_CORE_LOCKING */ sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);//创建内核进程 }
410  if(sys_mbox_new(&mbox, TCPIP_MBOX_SIZE) != ERR_OK) {//创建内核邮箱 LWIP_ASSERT("failed to create tcpip_thread mbox", 0); } #if LWIP_TCPIP_CORE_LOCKING if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) { LWIP_ASSERT("failed to create lock_tcpip_core", 0); } #endif /* LWIP_TCPIP_CORE_LOCKING */ sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);//创建内核进程 }
411  LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
412  }
413 #if LWIP_TCPIP_CORE_LOCKING
414  if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
415  LWIP_ASSERT("failed to create lock_tcpip_core", 0);
416  }
417 #endif /* LWIP_TCPIP_CORE_LOCKING */
418 
420 }
#define TCPIP_THREAD_NAME
Definition: opt.h:1199
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
err_t sys_mutex_new(sys_mutex_t *mutex)
void lwip_init(void) ICACHE_FLASH_ATTR
Definition: init.c:261
#define TCPIP_THREAD_PRIO
Definition: opt.h:1217
#define NULL
Definition: def.h:47
static void tcpip_thread(void *arg)
Definition: tcpip.c:74
#define TCPIP_MBOX_SIZE
Definition: opt.h:1226
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
#define ERR_OK
Definition: err.h:52
static tcpip_init_done_fn tcpip_init_done
Definition: tcpip.c:53
static void * tcpip_init_done_arg
Definition: tcpip.c:54
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:65
#define TCPIP_THREAD_STACKSIZE
Definition: opt.h:1208
static sys_mbox_t mbox
Definition: tcpip.c:55
Here is the call 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

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

Definition at line 156 of file tcpip.c.

References ERR_MEM, ERR_OK, ERR_VAL, tcpip_msg::inp, ip_input(), LOCK_TCPIP_CORE, LWIP_DEBUGF, mbox, memp_free(), memp_malloc(), tcpip_msg::msg, NETIF_FLAG_ETHARP, NETIF_FLAG_ETHERNET, NULL, tcpip_msg::p, sys_mbox_trypost(), sys_mbox_valid(), TCPIP_DEBUG, TCPIP_MSG_INPKT, tcpip_msg::type, and UNLOCK_TCPIP_CORE.

Referenced by netif_init().

157 {
158 #if LWIP_TCPIP_CORE_LOCKING_INPUT
159  err_t ret;
160  LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_input: PACKET %p/%p\n", (void *)p, (void *)inp));
161  LOCK_TCPIP_CORE();
162 #if LWIP_ETHERNET
164  ret = ethernet_input(p, inp);
165  } else
166 #endif /* LWIP_ETHERNET */
167  {
168  ret = ip_input(p, inp);
169  }
171  return ret;
172 #else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
173  struct tcpip_msg *msg;
174 
175  if (sys_mbox_valid(&mbox)) {
176  msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
177  if (msg == NULL) {
178  return ERR_MEM;
179  }
180 
181  msg->type = TCPIP_MSG_INPKT;
182  msg->msg.inp.p = p;
183  msg->msg.inp.netif = inp;
184  if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
185  memp_free(MEMP_TCPIP_MSG_INPKT, msg);
186  return ERR_MEM;
187  }
188  return ERR_OK;
189  }
190  return ERR_VAL;
191 #endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
192 }
void memp_free(memp_t type, void *mem) ICACHE_FLASH_ATTR
Definition: memp.c:438
int sys_mbox_valid(sys_mbox_t *mbox)
#define ERR_VAL
Definition: err.h:58
#define LOCK_TCPIP_CORE()
Definition: tcpip.h:67
#define NULL
Definition: def.h:47
void * memp_malloc(memp_t type) ICACHE_FLASH_ATTR
Definition: memp.c:393
enum tcpip_msg_type type
Definition: tcpip.h:126
struct pbuf * p
Definition: tcpip.h:136
#define UNLOCK_TCPIP_CORE()
Definition: tcpip.h:68
union tcpip_msg::@2 msg
#define NETIF_FLAG_ETHARP
Definition: netif.h:88
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
#define ERR_OK
Definition: err.h:52
u8_t flags
Definition: netif.h:193
s8_t err_t
Definition: err.h:47
struct tcpip_msg::@2::@3 inp
#define NETIF_FLAG_ETHERNET
Definition: netif.h:92
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
err_t ip_input(struct pbuf *p, struct netif *inp) ICACHE_FLASH_ATTR
Definition: ip.c:923
static sys_mbox_t mbox
Definition: tcpip.c:55
#define ERR_MEM
Definition: err.h:53
#define TCPIP_DEBUG
Definition: opt.h:1995
Here is the call graph for this function:
Here is the caller graph for this function: