Skip to content

Commit 2bf249f

Browse files
Avoid freezeing the core from LWIP under FreeRTOS (earlephilhower#1884)
Avoid issues with interrupts and priority inversions and other deadlocks and use a SW based random generator for LWIP when under FreeRTOS. This means removing any overrides for sleep_until and the two get_rand_xx calls from the SDK, making things much saner. Related to earlephilhower#1883, earlephilhower#1872, and other random FreeRTOS lockups.
1 parent 81070a0 commit 2bf249f

12 files changed

+1500
-53
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ If you want to contribute or have bugfixes, drop me a note at <earlephilhower@ya
252252
* [UF2CONV.PY](https://github.com/microsoft/uf2) is by Microsoft Corporation and licensed under the MIT license.
253253
* Networking and filesystem code taken from the [ESP8266 Arduino Core](https://github.com/esp8266/Arduino) and licensed under the LGPL.
254254
* DHCP server for AP host mode from the [Micropython Project](https://micropython.org), distributed under the MIT License.
255-
* [FreeRTOS](https://freertos.org) is Copyright Amazon.com, Inc. or its affiliates, and distributed under the MIT license.
255+
* [FreeRTOS](https://freertos.org) is copyright Amazon.com, Inc. or its affiliates, and distributed under the MIT license.
256256
* [lwIP](https://savannah.nongnu.org/projects/lwip/) is (c) the Swedish Institute of Computer Science and licenced under the BSD license.
257257
* [BearSSL](https://bearssl.org) library written by Thomas Pornin, is distributed under the [MIT License](https://bearssl.org/#legal-details).
258258
* [UZLib](https://github.com/pfalcon/uzlib) is copyright (c) 2003 Joergen Ibsen and distributed under the zlib license.
259259
* [LEAmDNS](https://github.com/LaborEtArs/ESP8266mDNS) is copyright multiple authors and distributed under the MIT license.
260260
* [http-parser](https://github.com/nodejs/http-parser) is copyright Joyent, Inc. and other Node contributors.
261-
* WebServer code modified from the [ESP32 WebServer](https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer) and is copyright (c) 2015 Ivan Grokhotkov and others
262-
261+
* WebServer code modified from the [ESP32 WebServer](https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer) and is copyright (c) 2015 Ivan Grokhotkov and others.
262+
* [Xoshiro-cpp](https://github.com/Reputeless/Xoshiro-cpp) is copyright (c) 2020 Ryo Suzuki and distributed under the MIT license.
263263
264264
-Earle F. Philhower, III
265265

cores/rp2040/_freertos.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,45 +60,3 @@ SemaphoreHandle_t __get_freertos_mutex_for_ptr(mutex_t *m, bool recursive) {
6060
}
6161
return nullptr; // Need to make space for more mutex maps!
6262
}
63-
64-
65-
// The HW Random code needs a precise sleep_until() in order to assure it
66-
// grabs the ROSC bit when it wants. Unfortunately, under FreeRTOS the
67-
// sleep_until() becomes imprecise and the "did I get the bit when I wanted"
68-
// check in the pico_rand code always fails and you get an infinite loop.
69-
70-
// This block wraps the 2 get_rand calls to set a flag to convert
71-
// sleep_until() (which can do a task swap and cause bad timing) into a
72-
// busy wait.
73-
74-
extern "C" {
75-
static bool __inRand = false;
76-
77-
extern uint64_t __real_get_rand_64();
78-
uint64_t __wrap_get_rand_64() {
79-
if (__isFreeRTOS) {
80-
rp2040.idleOtherCore();
81-
__inRand = true;
82-
auto r = __real_get_rand_64();
83-
__inRand = false;
84-
rp2040.resumeOtherCore();
85-
return r;
86-
} else {
87-
return __real_get_rand_64();
88-
}
89-
}
90-
91-
uint32_t __wrap_get_rand_32() {
92-
return (uint32_t) __wrap_get_rand_64();
93-
}
94-
95-
extern void __real_sleep_until(absolute_time_t t);
96-
void __wrap_sleep_until(absolute_time_t t) {
97-
if (__inRand) {
98-
busy_wait_until(t);
99-
} else {
100-
__real_sleep_until(t);
101-
}
102-
}
103-
104-
}

0 commit comments

Comments
 (0)