Skip to content

Commit

Permalink
Merge branch 'master' into bakerstu-ble-basics
Browse files Browse the repository at this point in the history
* master:
  Removes unnecessary includes that might not exist on an embedded compiler.
  Fix compilation of TempFile under esp8266.
  Add libatomic to esp8266 nonos target.
  Fix compile errors in time_client app.
  • Loading branch information
balazsracz committed Jun 18, 2024
2 parents cf0f099 + b15b4d1 commit 633cdd4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions applications/time_client/targets/linux.x86/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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: ");
}
Expand Down
38 changes: 37 additions & 1 deletion src/freertos_drivers/common/libatomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,35 @@

#include <stdint.h>

#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.
Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/os/TempFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@
#define _DARWIN_C_SOURCE // mkdtemp
#endif

#if defined(ESP_NONOS)
#define __sh__ // for ftruncate
#endif

#include "os/TempFile.hxx"

#include <unistd.h>

/// @todo mingw does not seem to have an mkdtemp call.
#if !defined(__FreeRTOS__) && !defined(__WINNT__)
TempDir::TempDir()
Expand Down
2 changes: 0 additions & 2 deletions src/utils/ClientConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

#include "utils/ClientConnection.hxx"

#include "netinet/in.h"
#include "netinet/tcp.h"
#include "nmranet_config.h"

#include "utils/FdUtils.hxx"
Expand Down
1 change: 0 additions & 1 deletion src/utils/GcTcpHub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "utils/GcTcpHub.hxx"

#include <memory>
#include <sys/socket.h>

#include "nmranet_config.h"
#include "utils/GridConnectHub.hxx"
Expand Down
3 changes: 2 additions & 1 deletion targets/nonos.xtensa-lx106.esp8266/core/sources
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 633cdd4

Please sign in to comment.