Skip to content

Commit 1711b34

Browse files
Add LWIP network for FreeRTOS system (#932)
* ft: Add LWIP network implementation for `system/freertos`
1 parent fe559a4 commit 1711b34

File tree

8 files changed

+770
-7
lines changed

8 files changed

+770
-7
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ include(GNUInstallDirs)
4545
option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON)
4646
option(WITH_ZEPHYR "Build for Zephyr RTOS" OFF)
4747
option(WITH_FREERTOS_PLUS_TCP "Build for FreeRTOS RTOS and FreeRTOS-Plus-TCP network stack" OFF)
48+
option(WITH_FREERTOS_LWIP "Build for FreeRTOS RTOS and LWIP (Lightweight IP) network stack" OFF)
4849
option(WITH_RPI_PICO "Build for Raspberry Pi Pico" OFF)
4950
set(ZENOH_DEBUG 0 CACHE STRING "Use this to set the ZENOH_DEBUG variable")
5051
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
@@ -184,6 +185,8 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
184185
pico_add_compile_definition(ZENOH_ZEPHYR)
185186
elseif(WITH_FREERTOS_PLUS_TCP)
186187
pico_add_compile_definition(ZENOH_FREERTOS_PLUS_TCP)
188+
elseif(WITH_FREERTOS_LWIP)
189+
pico_add_compile_definition(ZENOH_FREERTOS_LWIP)
187190
endif()
188191
elseif(CMAKE_SYSTEM_NAME MATCHES "PICO") # Raspberry Pi Pico Series
189192
pico_add_compile_definition(ZENOH_RPI_PICO)
@@ -303,6 +306,7 @@ message(STATUS "Unicast batch max size: ${BATCH_UNICAST_SIZE}")
303306
message(STATUS "Multicast batch max size: ${BATCH_MULTICAST_SIZE}")
304307
message(STATUS "Build for Zephyr RTOS: ${WITH_ZEPHYR}")
305308
message(STATUS "Build for FreeRTOS-Plus-TCP: ${WITH_FREERTOS_PLUS_TCP}")
309+
message(STATUS "Build for FreeRTOS + LWIP: ${WITH_FREERTOS_LWIP}")
306310
message(STATUS "Build for Raspberry Pi Pico: ${WITH_RPI_PICO}")
307311
message(STATUS "Configuring for ${CMAKE_SYSTEM_NAME}")
308312

@@ -363,8 +367,13 @@ if(WITH_ZEPHYR)
363367
file (GLOB Sources_Zephyr "src/system/zephyr/*.c")
364368
list(APPEND Sources ${Sources_Zephyr})
365369
elseif(WITH_FREERTOS_PLUS_TCP)
366-
file (GLOB Sources_Freertos_Plus_TCP "src/system/freertos_plus_tcp/*.c")
370+
file (GLOB Sources_Freertos_Plus_TCP "src/system/freertos/freertos_plus_tcp/*.c")
371+
list(APPEND Sources_Freertos_Plus_TCP "src/system/freertos/system.c")
367372
list(APPEND Sources ${Sources_Freertos_Plus_TCP})
373+
elseif(WITH_FREERTOS_LWIP)
374+
file (GLOB Sources_Freertos_Plus_LWIP "src/system/freertos/lwip/*.c")
375+
list(APPEND Sources_Freertos_Plus_LWIP "src/system/freertos/system.c")
376+
list(APPEND Sources ${Sources_Freertos_Plus_LWIP})
368377
elseif(WITH_RPI_PICO)
369378
file (GLOB Sources_RPI_Pico "src/system/rpi_pico/*.c")
370379
list(APPEND Sources ${Sources_RPI_Pico})

extra_script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"-<system/arduino/>",
3434
"-<system/emscripten/>",
3535
"-<system/espidf/>",
36-
"-<system/freertos_plus_tcp/>",
36+
"-<system/freertos/>",
3737
"-<system/rpi_pico/>",
3838
"-<system/mbed/>",
3939
"-<system/unix/>",
@@ -50,7 +50,7 @@
5050
"-<system/arduino/opencr>",
5151
"-<system/emscripten/>",
5252
"-<system/espidf>",
53-
"-<system/freertos_plus_tcp/>",
53+
"-<system/freertos/>",
5454
"-<system/rpi_pico/>",
5555
"-<system/mbed/>",
5656
"-<system/unix/>",
@@ -67,7 +67,7 @@
6767
"-<system/arduino/esp32>",
6868
"-<system/emscripten/>",
6969
"-<system/espidf>",
70-
"-<system/freertos_plus_tcp/>",
70+
"-<system/freertos/>",
7171
"-<system/rpi_pico/>",
7272
"-<system/mbed/>",
7373
"-<system/unix/>",
@@ -82,7 +82,7 @@
8282
"-<example/>",
8383
"-<system/arduino/>",
8484
"-<system/emscripten/>",
85-
"-<system/freertos_plus_tcp/>",
85+
"-<system/freertos/>",
8686
"-<system/rpi_pico/>",
8787
"-<system/mbed/>",
8888
"-<system/unix/>",
@@ -98,7 +98,7 @@
9898
"-<system/arduino/>",
9999
"-<system/emscripten/>",
100100
"-<system/espidf/>",
101-
"-<system/freertos_plus_tcp/>",
101+
"-<system/freertos/>",
102102
"-<system/rpi_pico/>",
103103
"-<system/unix/>",
104104
"-<system/flipper/>",

include/zenoh-pico/system/common/platform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
#elif defined(ZENOH_FLIPPER)
4646
#include "zenoh-pico/system/platform/flipper.h"
4747
#elif defined(ZENOH_FREERTOS_PLUS_TCP)
48-
#include "zenoh-pico/system/platform/freertos_plus_tcp.h"
48+
#include "zenoh-pico/system/platform/freertos/freertos_plus_tcp.h"
49+
#elif defined(ZENOH_FREERTOS_LWIP)
50+
#include "zenoh-pico/system/platform/freertos/lwip.h"
4951
#elif defined(ZENOH_RPI_PICO)
5052
#include "zenoh-pico/system/platform/rpi_pico.h"
5153
#elif defined(ZENOH_GENERIC)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//
2+
// Copyright (c) 2023 Fictionlab sp. z o.o.
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0 which is available at
6+
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
//
11+
// Contributors:
12+
// João Mário Lago, <joaolago@bluerobotics.com>
13+
//
14+
15+
#ifndef ZENOH_PICO_SYSTEM_FREERTOS_PLUS_LWIP_TYPES_H
16+
#define ZENOH_PICO_SYSTEM_FREERTOS_PLUS_LWIP_TYPES_H
17+
18+
#include <time.h>
19+
20+
#include "FreeRTOS.h"
21+
#include "lwip/sockets.h"
22+
#include "semphr.h"
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
#if Z_FEATURE_MULTI_THREAD == 1
29+
typedef struct {
30+
const char *name;
31+
UBaseType_t priority;
32+
size_t stack_depth;
33+
#if (configSUPPORT_STATIC_ALLOCATION == 1)
34+
bool static_allocation;
35+
StackType_t *stack_buffer;
36+
StaticTask_t *task_buffer;
37+
#endif /* SUPPORT_STATIC_ALLOCATION */
38+
} z_task_attr_t;
39+
40+
typedef struct {
41+
TaskHandle_t handle;
42+
EventGroupHandle_t join_event;
43+
void *(*fun)(void *);
44+
void *arg;
45+
#if (configSUPPORT_STATIC_ALLOCATION == 1)
46+
StaticEventGroup_t join_event_buffer;
47+
#endif /* SUPPORT_STATIC_ALLOCATION */
48+
} _z_task_t;
49+
50+
typedef struct {
51+
SemaphoreHandle_t handle;
52+
#if (configSUPPORT_STATIC_ALLOCATION == 1)
53+
StaticSemaphore_t buffer;
54+
#endif /* SUPPORT_STATIC_ALLOCATION */
55+
} _z_mutex_t;
56+
typedef struct {
57+
SemaphoreHandle_t mutex;
58+
SemaphoreHandle_t sem;
59+
int waiters;
60+
#if (configSUPPORT_STATIC_ALLOCATION == 1)
61+
StaticSemaphore_t mutex_buffer;
62+
StaticSemaphore_t sem_buffer;
63+
#endif /* SUPPORT_STATIC_ALLOCATION */
64+
} _z_condvar_t;
65+
#endif // Z_MULTI_THREAD == 1
66+
67+
typedef TickType_t z_clock_t;
68+
typedef struct timeval z_time_t;
69+
70+
typedef struct {
71+
union {
72+
#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1
73+
int _socket;
74+
#endif
75+
};
76+
} _z_sys_net_socket_t;
77+
78+
typedef struct {
79+
union {
80+
#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1
81+
struct addrinfo *_iptcp;
82+
#endif
83+
};
84+
} _z_sys_net_endpoint_t;
85+
86+
#ifdef __cplusplus
87+
}
88+
#endif
89+
90+
#endif

0 commit comments

Comments
 (0)