From 412f5cf3e04a67fea0c7ad057ad8f7c71ca9c843 Mon Sep 17 00:00:00 2001 From: Alex Alashkin Date: Fri, 18 Feb 2022 10:07:10 +0200 Subject: [PATCH] Add RTX-RTOS support --- .github/workflows/test.yml | 6 +++ .../Makefile | 9 ++++ mongoose.c | 2 +- mongoose.h | 41 +++++++++++++++++++ src/arch.h | 1 + src/arch_rtx_lwip.h | 40 ++++++++++++++++++ src/sock.c | 2 +- 7 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 examples/infineon/infineon-xmc4700_4800-lwip-rtx-rtos/Makefile create mode 100644 src/arch_rtx_lwip.h diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61a265d8..ad110c7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -209,3 +209,9 @@ jobs: - uses: actions/checkout@v2 - name: nxp-twrkv58f220m-lwip-freertos run: make -C examples/nxp/nxp-twrkv58f220m-lwip-freertos build + infineon-xmc4700_4800-lwip-rtx-rtos: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: infineon-xmc4700_4800-lwip-rtx-rtos + run: make -C examples/infineon/infineon-xmc4700_4800-lwip-rtx-rtos build \ No newline at end of file diff --git a/examples/infineon/infineon-xmc4700_4800-lwip-rtx-rtos/Makefile b/examples/infineon/infineon-xmc4700_4800-lwip-rtx-rtos/Makefile new file mode 100644 index 00000000..3423b36b --- /dev/null +++ b/examples/infineon/infineon-xmc4700_4800-lwip-rtx-rtos/Makefile @@ -0,0 +1,9 @@ +NAME ?= $(notdir $(CURDIR)) + +build: + git clone --depth 1 https://github.com/mongoose-examples/$(NAME) + cp ./../../../mongoose.[ch] $(NAME) + make -C $(NAME) build + +clean: + rm -rf $(NAME) diff --git a/mongoose.c b/mongoose.c index e6d2351e..74a89a7a 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3337,7 +3337,7 @@ static void mg_set_non_blocking_mode(SOCKET fd) { const BaseType_t off = 0; if (setsockopt(fd, 0, FREERTOS_SO_RCVTIMEO, &off, sizeof(off)) != 0) (void) 0; if (setsockopt(fd, 0, FREERTOS_SO_SNDTIMEO, &off, sizeof(off)) != 0) (void) 0; -#elif MG_ARCH == MG_ARCH_FREERTOS_LWIP +#elif MG_ARCH == MG_ARCH_FREERTOS_LWIP || MG_ARCH == MG_ARCH_RTX_LWIP lwip_fcntl(fd, F_SETFL, O_NONBLOCK); #elif MG_ARCH == MG_ARCH_AZURERTOS fcntl(fd, F_SETFL, O_NONBLOCK); diff --git a/mongoose.h b/mongoose.h index ad0ee86a..ce809ad4 100644 --- a/mongoose.h +++ b/mongoose.h @@ -35,6 +35,7 @@ extern "C" { #define MG_ARCH_FREERTOS_TCP 5 #define MG_ARCH_FREERTOS_LWIP 6 #define MG_ARCH_AZURERTOS 7 +#define MG_ARCH_RTX_LWIP 8 #if !defined(MG_ARCH) #if defined(__unix__) || defined(__APPLE__) @@ -287,6 +288,46 @@ struct timeval { #endif // MG_ARCH == MG_ARCH_FREERTOS_TCP +#if MG_ARCH == MG_ARCH_RTX_LWIP + +#include +#include +#include +#include +#include +#include + +#if defined(__GNUC__) +#include +#include +#else +struct timeval { + time_t tv_sec; + long tv_usec; +}; +#endif + +#include + +#if LWIP_SOCKET != 1 +// Sockets support disabled in LWIP by default +#error Set LWIP_SOCKET variable to 1 (in lwipopts.h) +#endif + +#define mkdir(a, b) (-1) + +#ifndef MG_IO_SIZE +#define MG_IO_SIZE 512 +#endif + +#ifndef MG_PATH_MAX +#define MG_PATH_MAX 128 +#endif + + +#endif + + #if MG_ARCH == MG_ARCH_UNIX #define _DARWIN_UNLIMITED_SELECT 1 // No limit on file descriptors diff --git a/src/arch.h b/src/arch.h index fee7671d..f0a1f8ca 100644 --- a/src/arch.h +++ b/src/arch.h @@ -8,6 +8,7 @@ #define MG_ARCH_FREERTOS_TCP 5 #define MG_ARCH_FREERTOS_LWIP 6 #define MG_ARCH_AZURERTOS 7 +#define MG_ARCH_RTX_LWIP 8 #if !defined(MG_ARCH) #if defined(__unix__) || defined(__APPLE__) diff --git a/src/arch_rtx_lwip.h b/src/arch_rtx_lwip.h new file mode 100644 index 00000000..9200a3ec --- /dev/null +++ b/src/arch_rtx_lwip.h @@ -0,0 +1,40 @@ +#pragma once + +#if MG_ARCH == MG_ARCH_RTX_LWIP + +#include +#include +#include +#include +#include +#include + +#if defined(__GNUC__) +#include +#include +#else +struct timeval { + time_t tv_sec; + long tv_usec; +}; +#endif + +#include + +#if LWIP_SOCKET != 1 +// Sockets support disabled in LWIP by default +#error Set LWIP_SOCKET variable to 1 (in lwipopts.h) +#endif + +#define mkdir(a, b) (-1) + +#ifndef MG_IO_SIZE +#define MG_IO_SIZE 512 +#endif + +#ifndef MG_PATH_MAX +#define MG_PATH_MAX 128 +#endif + + +#endif diff --git a/src/sock.c b/src/sock.c index 38f510df..0ba1936d 100644 --- a/src/sock.c +++ b/src/sock.c @@ -170,7 +170,7 @@ static void mg_set_non_blocking_mode(SOCKET fd) { const BaseType_t off = 0; if (setsockopt(fd, 0, FREERTOS_SO_RCVTIMEO, &off, sizeof(off)) != 0) (void) 0; if (setsockopt(fd, 0, FREERTOS_SO_SNDTIMEO, &off, sizeof(off)) != 0) (void) 0; -#elif MG_ARCH == MG_ARCH_FREERTOS_LWIP +#elif MG_ARCH == MG_ARCH_FREERTOS_LWIP || MG_ARCH == MG_ARCH_RTX_LWIP lwip_fcntl(fd, F_SETFL, O_NONBLOCK); #elif MG_ARCH == MG_ARCH_AZURERTOS fcntl(fd, F_SETFL, O_NONBLOCK);