Skip to content

Commit

Permalink
FreeRTOS-Plus-TCP port (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa authored Oct 30, 2023
1 parent 995f082 commit 2ee5282
Show file tree
Hide file tree
Showing 25 changed files with 1,707 additions and 24 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/freertos_plus_tcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Copyright (c) 2023 ZettaScale Technology
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Błażej Sowa, <blazej@fictionlab.pl>
#
name: freertos_plus_tcp

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: jwlawson/actions-setup-cmake@v1.13
- name: Install requirements
run: |
sudo apt update
sudo apt install -y ninja-build libslirp-dev
- name: Build examples
run: |
cd examples/freertos_plus_tcp
cmake -Bbuild -G"Ninja Multi-Config"
cmake --build ./build --config Debug
cmake --build ./build --config Release
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include(GNUInstallDirs)
option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON)
option(ZENOH_DEBUG "Use this to set the ZENOH_DEBUG variable." 0)
option(WITH_ZEPHYR "Build for Zephyr RTOS" OFF)
option(WITH_FREERTOS_PLUS_TCP "Build for FreeRTOS RTOS and FreeRTOS-Plus-TCP network stack" OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
Expand Down Expand Up @@ -91,6 +92,8 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
if(WITH_ZEPHYR)
add_definition(ZENOH_ZEPHYR)
elseif(WITH_FREERTOS_PLUS_TCP)
add_definition(ZENOH_FREERTOS_PLUS_TCP)
endif()
else()
message(FATAL_ERROR "zenoh-pico is not yet available on ${CMAKE_SYSTEM_NAME} platform")
Expand All @@ -104,6 +107,7 @@ message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
message(STATUS "Build shared library: ${BUILD_SHARED_LIBS}")
message(STATUS "Zenoh Level Log: ${ZENOH_DEBUG}")
message(STATUS "Build for Zephyr RTOS: ${WITH_ZEPHYR}")
message(STATUS "Build for FreeRTOS-Plus-TCP: ${WITH_FREERTOS_PLUS_TCP}")
message(STATUS "Configuring for ${CMAKE_SYSTEM_NAME}")

if(SKBUILD)
Expand Down Expand Up @@ -163,6 +167,9 @@ file(GLOB_RECURSE Sources
if(WITH_ZEPHYR)
file (GLOB Sources_Zephyr "src/system/zephyr/*.c")
list(APPEND Sources ${Sources_Zephyr})
elseif(WITH_FREERTOS_PLUS_TCP)
file (GLOB Sources_Freertos_Plus_TCP "src/system/freertos_plus_tcp/*.c")
list(APPEND Sources ${Sources_Freertos_Plus_TCP})
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD" OR POSIX_COMPATIBLE)
file (GLOB Sources_Unix "src/system/unix/*.c")
list(APPEND Sources ${Sources_Unix})
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ It is fully compatible with its main [Rust Zenoh implementation](https://github.

Currently, zenoh-pico provides support for the following (RT)OSs and protocols:

| **(RT)OS** | **Transport Layer** | **Network Layer** | **Data Link Layer** |
|:---------------:|:--------------------------------:|:-------------------:|:--------------------------------------------------:|
| **Unix** | UDP (unicast and multicast), TCP | IPv4, IPv6, 6LoWPAN | WiFi, Ethernet, Thread |
| **Windows** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet |
| **Zephyr** | UDP (unicast and multicast), TCP | IPv4, IPv6, 6LoWPAN | WiFi, Ethernet, Thread, Serial |
| **Arduino** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet, Bluetooth (Serial profile), Serial |
| **ESP-IDF** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet, Serial |
| **MbedOS** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet, Serial |
| **OpenCR** | UDP (unicast and multicast), TCP | IPv4 | WiFi |
| **Emscripten** | Websocket | IPv4, IPv6 | WiFi, Ethernet |
| **(RT)OS** | **Transport Layer** | **Network Layer** | **Data Link Layer** |
|:---------------------:|:--------------------------------:|:-------------------:|:--------------------------------------------------:|
| **Unix** | UDP (unicast and multicast), TCP | IPv4, IPv6, 6LoWPAN | WiFi, Ethernet, Thread |
| **Windows** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet |
| **Zephyr** | UDP (unicast and multicast), TCP | IPv4, IPv6, 6LoWPAN | WiFi, Ethernet, Thread, Serial |
| **Arduino** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet, Bluetooth (Serial profile), Serial |
| **ESP-IDF** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet, Serial |
| **MbedOS** | UDP (unicast and multicast), TCP | IPv4, IPv6 | WiFi, Ethernet, Serial |
| **OpenCR** | UDP (unicast and multicast), TCP | IPv4 | WiFi |
| **Emscripten** | Websocket | IPv4, IPv6 | WiFi, Ethernet |
| **FreeRTOS-Plus-TCP** | UDP (unicast), TCP | IPv4 | Ethernet |

Check the website [zenoh.io](http://zenoh.io) and the [roadmap](https://github.com/eclipse-zenoh/roadmap) for more detailed information.

Expand Down
98 changes: 98 additions & 0 deletions examples/freertos_plus_tcp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#
# Copyright (c) 2023 Fictionlab sp. z o.o.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Błażej Sowa, <blazej@fictionlab.pl>

cmake_minimum_required(VERSION 3.20)
project(zenohpico_freertos_plus_tcp_examples)

set(CMAKE_SYSTEM_NAME "Generic")
set(CMAKE_C_STANDARD 11)

include(../../cmake/helpers.cmake)
set_default_build_type(Release)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SLIRP REQUIRED slirp)

add_library(slirp INTERFACE)
target_link_libraries(slirp INTERFACE ${SLIRP_LINK_LIBRARIES})
target_include_directories(slirp INTERFACE ${SLIRP_INCLUDE_DIRS})
target_compile_options(slirp INTERFACE -Wno-error)

include(FetchContent)

FetchContent_Declare(freertos_kernel
GIT_REPOSITORY "https://github.com/FreeRTOS/FreeRTOS-Kernel.git"
GIT_TAG "V10.6.1"
)

FetchContent_Declare(freertos_plus_tcp
GIT_REPOSITORY "https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git"
GIT_TAG "34148c3"
GIT_SUBMODULES ""
)

add_library(freertos_config INTERFACE)
target_include_directories(freertos_config SYSTEM INTERFACE include)
target_compile_options(freertos_config INTERFACE -Wno-error)

set(FREERTOS_HEAP "3" CACHE STRING "" FORCE)
set(FREERTOS_PORT "GCC_POSIX" CACHE STRING "" FORCE)
set(FREERTOS_PLUS_TCP_NETWORK_IF "LIBSLIRP" CACHE STRING "" FORCE)
set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "2" CACHE STRING "" FORCE)

FetchContent_MakeAvailable(freertos_kernel freertos_plus_tcp)

set(BUILD_SHARED_LIBS OFF)
set(WITH_FREERTOS_PLUS_TCP ON)
set(ZENOH_DEBUG 3)
configure_include_project(ZENOHPICO zenohpico zenohpico "../.." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")

target_link_libraries(zenohpico
freertos_kernel
freertos_plus_tcp
)
target_compile_definitions(zenohpico
PUBLIC
Z_FEATURE_MULTI_THREAD=1
Z_FEATURE_LINK_TCP=1
Z_FEATURE_SCOUTING_UDP=1
Z_FEATURE_LINK_UDP_UNICAST=1
Z_FEATURE_LINK_UDP_MULTICAST=0
Z_CONFIG_SOCKET_TIMEOUT=1000
)

add_library(main OBJECT main.c)
target_link_libraries(main
freertos_kernel
freertos_plus_tcp
)

function(add_example name)
add_executable(${name} ${name}.c)
target_link_libraries(${name}
main
freertos_kernel
freertos_plus_tcp
zenohpico
)
endfunction()

add_example(z_get)
add_example(z_pub_st)
add_example(z_pub)
add_example(z_pull)
add_example(z_put)
add_example(z_queryable)
add_example(z_scout)
add_example(z_sub_st)
add_example(z_sub)
64 changes: 64 additions & 0 deletions examples/freertos_plus_tcp/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Copyright (c) 2023 Fictionlab sp. z o.o.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// Błażej Sowa, <blazej@fictionlab.pl>

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include "bits/pthread_stack_min.h"

/* Core options */
#define configUSE_PREEMPTION 1
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (56)
#define configMINIMAL_STACK_SIZE ((uint16_t) PTHREAD_STACK_MIN)
#define configMAX_TASK_NAME_LEN (16)
#define configUSE_16_BIT_TICKS 0
#define configQUEUE_REGISTRY_SIZE 0
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 1
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
#define configUSE_SB_COMPLETED_CALLBACK 0

/* Enable/Disable features */
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_CO_ROUTINES 0
#define configUSE_TIMERS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_QUEUE_SETS 0
#define configUSE_NEWLIB_REENTRANT 0

/* Set the API functions which should be included */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xQueueGetMutexHolder 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTimerPendFunctionCall 0

#endif /* FREERTOS_CONFIG_H */
54 changes: 54 additions & 0 deletions examples/freertos_plus_tcp/include/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Copyright (c) 2023 Fictionlab sp. z o.o.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// Błażej Sowa, <blazej@fictionlab.pl>

#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H

// Driver specific
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 0
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
#define ipconfigZERO_COPY_RX_DRIVER 1
#define ipconfigZERO_COPY_TX_DRIVER 1
#define ipconfigUSE_LINKED_RX_MESSAGES 1
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60

// Enable/Disable features
#define ipconfigUSE_IPv4 1
#define ipconfigUSE_IPv6 1
#define ipconfigUSE_DHCP 1
#define ipconfigUSE_DHCPv6 0
#define ipconfigUSE_RA 0
#define ipconfigUSE_DNS 1
#define ipconfigUSE_TCP 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 0
#define ipconfigUSE_ARP_REVERSED_LOOKUP 0
#define ipconfigSUPPORT_SELECT_FUNCTION 0
#define ipconfigSUPPORT_OUTGOING_PINGS 0
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
#define ipconfigUSE_DHCP_HOOK 0

// DHCP
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD (pdMS_TO_TICKS(1000U))
#define ipconfigDHCP_REGISTER_HOSTNAME 1

#define ipconfigIP_TASK_PRIORITY (configMAX_PRIORITIES - 2)
#define ipconfigIP_TASK_STACK_SIZE_WORDS (configMINIMAL_STACK_SIZE * 5)

// Set ipconfigBUFFER_PADDING on 64-bit platforms
#if INTPTR_MAX == INT64_MAX
#define ipconfigBUFFER_PADDING 14U
#endif

#endif /* FREERTOS_IP_CONFIG_H */
Loading

0 comments on commit 2ee5282

Please sign in to comment.