Added sys_mbox_trypost_fromisr() and tcpip_callbackmsg_trycallback_fromisr()

This can be used to post preallocated messages from an ISR to the tcpip thread
when using FreeRTOS, where where calls differ between task level and ISR level.

Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
goldsimon 2018-01-05 21:08:27 +01:00
parent 1623c3e2cc
commit 8fc20142f7
3 changed files with 31 additions and 1 deletions

View File

@ -531,6 +531,25 @@ tcpip_callbackmsg_trycallback(struct tcpip_callback_msg *msg)
return sys_mbox_trypost(&mbox, msg); return sys_mbox_trypost(&mbox, msg);
} }
/**
* @ingroup lwip_os
* Try to post a callback-message to the tcpip_thread mbox.
* Same as @ref tcpip_callbackmsg_trycallback but calls sys_mbox_trypost_fromisr(),
* mainly to help FreeRTOS, where calls differ between task level and ISR level.
*
* @param msg pointer to the message to post
* @return sys_mbox_trypost_fromisr() return code (without change, so this
* knowledge can be used to e.g. propagate "bool needs_scheduling")
*
* @see tcpip_callbackmsg_new()
*/
err_t
tcpip_callbackmsg_trycallback_fromisr(struct tcpip_callback_msg *msg)
{
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
return sys_mbox_trypost_fromisr(&mbox, msg);
}
/** /**
* @ingroup lwip_os * @ingroup lwip_os
* Initialize this module: * Initialize this module:

View File

@ -295,13 +295,23 @@ void sys_mbox_post(sys_mbox_t *mbox, void *msg);
/** /**
* @ingroup sys_mbox * @ingroup sys_mbox
* Try to post a message to an mbox - may fail if full. * Try to post a message to an mbox - may fail if full.
* Can be used from ISR. * Can be used from ISR (if the sys arch layer allows this).
* Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted. * Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted.
* *
* @param mbox mbox to posts the message * @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL) * @param msg message to post (ATTENTION: can be NULL)
*/ */
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg); err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg);
/**
* @ingroup sys_mbox
* Try to post a message to an mbox - may fail if full.
* To be be used from ISR.
* Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted.
*
* @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL)
*/
err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg);
/** /**
* @ingroup sys_mbox * @ingroup sys_mbox
* Blocks the thread until a message arrives in the mailbox, but does * Blocks the thread until a message arrives in the mailbox, but does

View File

@ -89,6 +89,7 @@ err_t tcpip_callback(tcpip_callback_fn function, void *ctx);
struct tcpip_callback_msg* tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx); struct tcpip_callback_msg* tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx);
void tcpip_callbackmsg_delete(struct tcpip_callback_msg* msg); void tcpip_callbackmsg_delete(struct tcpip_callback_msg* msg);
err_t tcpip_callbackmsg_trycallback(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);
/* free pbufs or heap memory from another context without blocking */ /* free pbufs or heap memory from another context without blocking */
err_t pbuf_free_callback(struct pbuf *p); err_t pbuf_free_callback(struct pbuf *p);