@@ -828,28 +828,17 @@ extern "C" {
828828 return __real_ethernet_input (p, netif);
829829 }
830830
831- void lwip_callback (void (*cb)(void *), void *cbData, bool fromISR) {
832- #ifdef __FREERTOS
833- if (fromISR) {
834- // In ISR we can't check what the current thread is
835- static __callback_req req = { cb, cbData }; // TODO HACK HERE
836- // We pass in the address of an unknown sized request to the LWIP work queue
837- // For normal mode that address is on the app stack, which will be frozen until
838- // the callback is performed. So no problem, that stack address will remain valid.
839- // Here, we're in an ISR and won't block, just put a pointer on the queue and
840- // return from the interrupt. The stack address, there, is no longer safe and you
841- // will see memory corruption when the actual app thread uses its stack.
842- // We can't allocate memory in an IRQ in FreeRTOS, so for now we'll just have
843- // a single heap-based (static) request which will live forever. As long as
844- // only a single lwip_callback from IRQ is present we're OK. Should you have 2
845- // IRQ driver network cards, this will fail.
846- // A more satisfying method might have the NIC driver pass in its own class local
847- // preallocated storage space which we can use.
848- __lwip (__callback, &req, fromISR);
831+ void lwip_callback (void (*cb)(void *), void *cbData, void *buffer) {
832+ #ifdef __FREERTOS
833+ if (buffer) {
834+ __callback_req *req = (__callback_req *)buffer;
835+ req->cb = cb;
836+ req->cbData = cbData;
837+ __lwip (__callback, req, true );
849838 return ;
850839 } else if (!__isLWIPThread ()) {
851840 __callback_req req = { cb, cbData };
852- __lwip (__callback, &req, fromISR );
841+ __lwip (__callback, &req, false );
853842 return ;
854843 }
855844#endif
0 commit comments