From 8fc20142f7b1b18f24fc48187d390187d718ce30 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 5 Jan 2018 21:08:27 +0100 Subject: [PATCH] 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 --- src/api/tcpip.c | 19 +++++++++++++++++++ src/include/lwip/sys.h | 12 +++++++++++- src/include/lwip/tcpip.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/api/tcpip.c b/src/api/tcpip.c index ff01032b..1176c11c 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -531,6 +531,25 @@ tcpip_callbackmsg_trycallback(struct tcpip_callback_msg *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 * Initialize this module: diff --git a/src/include/lwip/sys.h b/src/include/lwip/sys.h index 771b8d3b..168e465b 100644 --- a/src/include/lwip/sys.h +++ b/src/include/lwip/sys.h @@ -295,13 +295,23 @@ void sys_mbox_post(sys_mbox_t *mbox, void *msg); /** * @ingroup sys_mbox * 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. * * @param mbox mbox to posts the message * @param msg message to post (ATTENTION: can be NULL) */ 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 * Blocks the thread until a message arrives in the mailbox, but does diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index b4cd7aaa..0b8880a9 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -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); 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); /* free pbufs or heap memory from another context without blocking */ err_t pbuf_free_callback(struct pbuf *p);