From 0e397205cb50f292e42585191c2780ada1aefa18 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Tue, 28 May 2024 22:38:52 +0200 Subject: [PATCH 1/4] Fix compile errors in time_client app. --- applications/time_client/targets/linux.x86/main.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/time_client/targets/linux.x86/main.cxx b/applications/time_client/targets/linux.x86/main.cxx index f48e5c89a..578885844 100644 --- a/applications/time_client/targets/linux.x86/main.cxx +++ b/applications/time_client/targets/linux.x86/main.cxx @@ -72,7 +72,7 @@ extern const size_t openlcb::CONFIG_FILE_SIZE = extern const char *const openlcb::SNIP_DYNAMIC_FILENAME = openlcb::CONFIG_FILENAME; -void time_update_callback(); +void time_update_callback(time_t old, time_t current); void minute_update_callback(BarrierNotifiable *done); // Main time protocol client. @@ -101,7 +101,7 @@ void minute_update_callback(BarrierNotifiable *done) /// Callback from the time client when the time jumps or is reset for any other /// reason. -void time_update_callback() +void time_update_callback(time_t old, time_t current) { print_time("update: "); } From 52f2f0da16f89a611b6e5ec474908ef380002ed9 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Tue, 28 May 2024 22:39:18 +0200 Subject: [PATCH 2/4] Add libatomic to esp8266 nonos target. --- src/freertos_drivers/common/libatomic.c | 38 ++++++++++++++++++- .../nonos.xtensa-lx106.esp8266/core/sources | 3 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/freertos_drivers/common/libatomic.c b/src/freertos_drivers/common/libatomic.c index 094286e52..fd8632d7e 100644 --- a/src/freertos_drivers/common/libatomic.c +++ b/src/freertos_drivers/common/libatomic.c @@ -35,7 +35,35 @@ #include -#if defined(STM32F0xx) || (!defined(ARDUINO) && !defined(ESP_PLATFORM)) +#ifdef ESP_NONOS + +#ifndef __STRINGIFY +#define __STRINGIFY(a) #a +#endif + +// these low level routines provide a replacement for SREG interrupt save that AVR uses +// but are esp8266 specific. A normal use pattern is like +// +//{ +// uint32_t savedPS = xt_rsil(1); // this routine will allow level 2 and above +// // do work here +// xt_wsr_ps(savedPS); // restore the state +//} +// +// level (0-15), interrupts of the given level and above will be active +// level 15 will disable ALL interrupts, +// level 0 will enable ALL interrupts, +// +#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;})) +#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory") + + +#define ACQ_LOCK() \ + uint32_t savedPS = xt_rsil(15); + +#define REL_LOCK() xt_wsr_ps(savedPS); + +#elif defined(STM32F0xx) || (!defined(ARDUINO) && !defined(ESP_PLATFORM)) // On Cortex-M0 the only way to do atomic operation is to disable interrupts. /// Disables interrupts and saves the interrupt enable flag in a register. @@ -46,6 +74,14 @@ /// Restores the interrupte enable flag from a register. #define REL_LOCK() __asm volatile(" msr PRIMASK, %0\n " : : "r"(_pastlock)); +#endif + + + + +#ifdef ACQ_LOCK + + /// __atomic_fetch_add_1 /// /// This function is needed for GCC-generated code. diff --git a/targets/nonos.xtensa-lx106.esp8266/core/sources b/targets/nonos.xtensa-lx106.esp8266/core/sources index 729125644..5c141b458 100644 --- a/targets/nonos.xtensa-lx106.esp8266/core/sources +++ b/targets/nonos.xtensa-lx106.esp8266/core/sources @@ -1,12 +1,13 @@ COREPATH=$(ESPARDUINOPATH)/hardware/esp8266/2.2.0/cores/esp8266 -VPATH := $(COREPATH):$(COREPATH)/umm_malloc \ +VPATH := $(COREPATH):$(COREPATH)/umm_malloc:$(OPENMRNPATH)/src/freertos_drivers/common \ CSRCS += core_esp8266_noniso.c \ heap.c \ umm_malloc.c \ libc_replacements.c \ + libatomic.c \ CFLAGS += -I$(COREPATH) -include $(OPENMRNPATH)/include/esp8266/esp_predef.h From 77722238c3e49ccfd9f34943db56eca0c6a1da0b Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Tue, 28 May 2024 22:39:38 +0200 Subject: [PATCH 3/4] Fix compilation of TempFile under esp8266. --- src/os/TempFile.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/os/TempFile.cxx b/src/os/TempFile.cxx index 38b6c2835..eb807e2e0 100644 --- a/src/os/TempFile.cxx +++ b/src/os/TempFile.cxx @@ -41,8 +41,14 @@ #define _DARWIN_C_SOURCE // mkdtemp #endif +#if defined(ESP_NONOS) +#define __sh__ // for ftruncate +#endif + #include "os/TempFile.hxx" +#include + /// @todo mingw does not seem to have an mkdtemp call. #if !defined(__FreeRTOS__) && !defined(__WINNT__) TempDir::TempDir() From b15b4d11c87bc4791fbec596ef4fa237f2cf708b Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Tue, 28 May 2024 22:40:03 +0200 Subject: [PATCH 4/4] Removes unnecessary includes that might not exist on an embedded compiler. --- src/utils/ClientConnection.cxx | 2 -- src/utils/GcTcpHub.cxx | 1 - 2 files changed, 3 deletions(-) diff --git a/src/utils/ClientConnection.cxx b/src/utils/ClientConnection.cxx index b73345e9b..6d2c6ac9c 100644 --- a/src/utils/ClientConnection.cxx +++ b/src/utils/ClientConnection.cxx @@ -34,8 +34,6 @@ #include "utils/ClientConnection.hxx" -#include "netinet/in.h" -#include "netinet/tcp.h" #include "nmranet_config.h" #include "utils/FdUtils.hxx" diff --git a/src/utils/GcTcpHub.cxx b/src/utils/GcTcpHub.cxx index acded59ad..d1385f077 100644 --- a/src/utils/GcTcpHub.cxx +++ b/src/utils/GcTcpHub.cxx @@ -34,7 +34,6 @@ #include "utils/GcTcpHub.hxx" #include -#include #include "nmranet_config.h" #include "utils/GridConnectHub.hxx"