diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 8f994fdc..54ccf9ac 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -103,6 +103,11 @@ tcpip_thread(void *arg) LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg)); msg->msg.api.function(msg->msg.api.msg); break; + case TCPIP_MSG_API_CALL: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API CALL message %p\n", (void *)msg)); + msg->msg.api_call->err = msg->msg.api_call->function(msg->msg.api_call); + sys_sem_signal(&msg->msg.api_call->sem); + break; #endif /* LWIP_TCPIP_CORE_LOCKING */ #if !LWIP_TCPIP_CORE_LOCKING_INPUT @@ -331,6 +336,38 @@ tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem) } #endif /* !LWIP_TCPIP_CORE_LOCKING */ +err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call) +{ +#if LWIP_TCPIP_CORE_LOCKING + LOCK_TCPIP_CORE(); + call->err = fn(call); + UNLOCK_TCPIP_CORE(); + return call->err; +#else + + if (sys_mbox_valid_val(mbox)) { + TCPIP_MSG_VAR_DECLARE(msg); + err_t err; + + err = sys_sem_new(&call->sem, 0); + if (err != ERR_OK) { + return err; + } + + TCPIP_MSG_VAR_ALLOC(msg); + TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API_CALL; + TCPIP_MSG_VAR_REF(msg).msg.api_call = call; + TCPIP_MSG_VAR_REF(msg).msg.api_call->function = fn; + sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg)); + sys_arch_sem_wait(&call->sem, 0); + sys_sem_free(&call->sem); + TCPIP_MSG_VAR_FREE(msg); + return ERR_OK; + } + return ERR_VAL; +#endif +} + /** * Allocate a structure for a static callback message and initialize it. * This is intended to be used to send "static" messages from interrupt context. diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h index 5d19ee3c..c7c94fd1 100644 --- a/src/include/lwip/priv/tcpip_priv.h +++ b/src/include/lwip/priv/tcpip_priv.h @@ -99,8 +99,21 @@ extern sys_mutex_t lock_tcpip_core; err_t tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem); #endif /* !LWIP_TCPIP_CORE_LOCKING */ +struct tcpip_api_call; +typedef err_t (*tcpip_api_call_fn)(struct tcpip_api_call* call); +struct tcpip_api_call +{ + tcpip_api_call_fn function; +#if !LWIP_TCPIP_CORE_LOCKING + sys_sem_t sem; +#endif /* !LWIP_TCPIP_CORE_LOCKING */ + err_t err; +}; +err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call); + enum tcpip_msg_type { TCPIP_MSG_API, + TCPIP_MSG_API_CALL, TCPIP_MSG_INPKT, #if LWIP_TCPIP_TIMEOUT TCPIP_MSG_TIMEOUT, @@ -117,6 +130,7 @@ struct tcpip_msg { tcpip_callback_fn function; void* msg; } api; + struct tcpip_api_call *api_call; struct { struct pbuf *p; struct netif *netif;