Skip to content

Commit a2d4998

Browse files
Make LWIP task priority configurable, document (#3100)
It is a good idea to leave the highes priority task slots for user tasks with real-time needs, so move LWIP to MAX-2 and add a configuration define to change it if needed. Update docs with info on setting.
1 parent 24dd858 commit a2d4998

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cores/rp2040/freertos/freertos-lwip.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ typedef struct {
3535

3636
#define LWIP_WORK_ENTRIES 16
3737

38+
#ifndef LWIP_TASK_PRIORITY
39+
#define LWIP_TASK_PRIORITY (configMAX_PRIORITIES - 2)
40+
#endif
41+
3842
// The notify item we'll use to wake the calling process back up
3943
#define TASK_NOTIFY_LWIP_WAKEUP (configTASK_NOTIFICATION_ARRAY_ENTRIES - 1)
4044

@@ -47,7 +51,7 @@ void __startLWIPThread() {
4751
if (!__lwipQueue) {
4852
panic("Unable to allocate LWIP work queue");
4953
}
50-
if (pdPASS != xTaskCreate(lwipThread, "LWIP", 1024, 0, configMAX_PRIORITIES - 1, &__lwipTask)) {
54+
if (pdPASS != xTaskCreate(lwipThread, "LWIP", 1024, 0, LWIP_TASK_PRIORITY, &__lwipTask)) {
5155
panic("Unable to create LWIP task");
5256
}
5357
vTaskCoreAffinitySet(__lwipTask, 1 << 0);

docs/freertos.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ to your sketch and select ``Tools->Operating System->FreeRTOS SMP`` to enable it
1919

2020
When using Platform.IO you need to add the following define to your .ini file:
2121

22-
.. code::
22+
.. code:: ini
23+
24+
; Enable FreeRTOS Support
25+
build_flags = -DPIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS
2326
24-
-D__FREERTOS=1
2527
2628
Configuration and Predefined Tasks
2729
----------------------------------
@@ -33,6 +35,12 @@ quantum is 1 millisecond (i.e. 1,000 switches per second).
3335
``setup()`` and ``loop()`` are assigned to only run on core 0, while ``setup1()`` and ``loop1()``
3436
only run in core 1 in this mode, the same as the default multithreading mode.
3537

38+
There is an LWIP worker thread running on core 0 at priority ``(configMAX_PRIORITIES - 2)``
39+
This should allow for LWIP to always make progress even with applications that don't
40+
``yield`` or ``delay``, while leaving the highest priority available for hard
41+
real time processes. This setting can be changed by defining ``LWIP_TASK_PRIORITY``
42+
in your build process.
43+
3644
You can launch and manage additional processes using the standard FreeRTOS routines.
3745

3846
``delay()`` and ``yield()`` free the CPU for other tasks, while ``delayMicroseconds()`` does not.

0 commit comments

Comments
 (0)