Skip to content

Commit

Permalink
Merge branch 'master' into bracz-callback-event-identified
Browse files Browse the repository at this point in the history
* master:
  Fix test makefiles and test target (#736)
  Moves the bootloader hook so that the hook implementation gets a chance to look at incoming frames.
  Fixes missing includes.
  Fixes missing symbol error.
  Adds stm32f072 HAL drivers to bare.armv6m compilation target.
  Update HASSERT and DIE to use ets_printf() on ESP32 (#744)
  Adds a useful command to generate release notes.
  Fix MultiConfiguredPC.hxx compilation with C++20 (#737)
  Esp32 TWAI updates based on comments (#720)
  Fork spiffs/stm32f7/Stm32SPIFFS.cxx to st/Stm32Flash.hxx step 4
  Fork spiffs/stm32f7/Stm32SPIFFS.cxx to st/Stm32Flash.hxx step 2
  Fork spiffs/stm32f7/Stm32SPIFFS.cxx to st/Stm32Flash.hxx
  Fix compile error in railcom board definitions.
  Stm32 pwm f7xx update (#735)
  Add L4xx HAL include for Stm32PWM (#734)
  Fix missing ifdef for reboot because macos build is broken.
  • Loading branch information
balazsracz committed Nov 11, 2023
2 parents ca9ba6b + e9e660a commit 809a4c2
Show file tree
Hide file tree
Showing 50 changed files with 380 additions and 172 deletions.
1 change: 1 addition & 0 deletions arduino/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Arduino ecosystem (whichever incarnation) are used.
1. Edit library.properties and library.json to increment the version number.
1. Run `arduino/libify.sh "/path/to/OpenMRNLite" . -f`
1. Go to OpenMRNLite, commit the results to git, then push it to master.
To generate the commit note and later the release notes, use this command: `git log --oneline OpenMRNLite-v1.0.3..OpenMRNLite-v2.0.0 | sed -e 's/[(]#/(https:\/\/github.com\/bakerstu\/openmrn\/pull\//' | sed 's/^/bakerstu\/openmrn@/'`
1. go to http://github.com/openmrn/OpenMRNLite, click the releases tab, then
create a release called v1.2.3 if your library.properties said 1.2.3 as
version.
Expand Down
6 changes: 6 additions & 0 deletions boards/bracz-railcom/hardware.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,14 @@ struct DCCDecode
/// counts how many edges / transitions we had on the DCC signal.
static unsigned sampleCount_;
static inline void cap_event_hook() { ++sampleCount_; }

// These functions fine-tune the railcom cutout timing.
static int time_delta_railcom_pre_usec() { return 0; }
static int time_delta_railcom_mid_usec() { return 0; }
static int time_delta_railcom_end_usec() { return 0; }
};


#endif // ! pindefs_only

#endif // _HARDWARE_HXX_
13 changes: 10 additions & 3 deletions etc/core_target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ include $(OPENMRNPATH)/etc/config.mk
include $(OPENMRNPATH)/etc/path.mk
include $(OPENMRNPATH)/etc/$(TARGET).mk

# lib here is only needed for clean to work properly. Libraries are copied
# there by the original build rules.
SUBDIRS = $(CORELIBS) $(SYSLIB_SUBDIRS) lib
SUBDIRS = $(CORELIBS) $(SYSLIB_SUBDIRS)

# This defines how to create nonexistant directories.
MKSUBDIR_OPENMRNINCLUDE=lib.mk

include $(OPENMRNPATH)/etc/recurse.mk

# lib/timestamp is a dependency to all test binaries. This rule has to have a
# body to execute, or else make will take the mtime of this file too early in
# the execution process. The body shall not actually touch the file, as the
# touches happen in the BUILDDIRS recursions. This workaround ensures that when
# a source file changes in openmrn, the tests are all re-linked and
# re-run. Otherwise you need to run tests twice to actually execute them.
lib/timestamp: $(BUILDDIRS)
true
26 changes: 24 additions & 2 deletions etc/core_test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

ifneq ($(HOST_TARGET)$(EMU),0)

include $(OPENMRNPATH)/etc/make_utils.mk

FULLPATHCXXTESTSRCS := $(foreach DIR,$(SUBDIRS) tests,$(wildcard $(SRCDIR)/$(DIR)/*.cxxtest))

TESTOBJSEXTRA += gtest-all.o gmock-all.o
Expand All @@ -33,16 +35,36 @@ CXXFLAGS += $(INCLUDES)
ifdef LIBDIR
# we are under prog.mk
TESTLIBDEPS += $(foreach lib,$(SUBDIRS),lib/lib$(lib).a)

# This ensures that link targets that depend on lib/libfoo.a will recurse into
# the directory foo and rebuild stuff that's there. However, the dependency is
# phrased in a way that if recursing does not change the library (when it's
# up-to-date) then the .elf linking is not re-done.
$(foreach lib,$(SUBDIRS),$(eval $(call SUBDIR_helper_template,$(lib))))

# Ensures that when the core target is clean (missing lib/libfoo.a), make knows
# how to build its libraries. This also ensures that the text.executable files
# are remade when something changes in the openmrn codebase.
$(foreach lib,$(CORELIBS),$(LIBDIR)/lib$(lib).a): $(LIBDIR)/timestamp

else
LIBDIR = lib

# This ensures that link targets that depend on lib/libfoo.a will recurse into
# the directory foo and rebuild stuff that's there. However, the dependency is
# phrased in a way that if recursing does not change the library (when it's
# up-to-date) then the .elf linking is not re-done.
$(foreach lib,$(CORELIBS),$(eval $(call SUBDIR_helper_template,$(lib))))

endif
TESTLIBDEPS += $(foreach lib,$(CORELIBS),$(LIBDIR)/lib$(lib).a)

LDFLAGS += -L$(LIBDIR)

$(LIBDIR)/timestamp: $(BUILDDIRS)

$(info test deps $(TESTOBJSEXTRA) $(LIBDIR)/timestamp )

$(info test deps $(TESTOBJSEXTRA) $(LIBDIR)/timestamp | $(BUILDDIRS) )
$(TESTBINS): %.test$(EXTENTION) : %.test.o $(TESTOBJSEXTRA) $(LIBDIR)/timestamp lib/timestamp $(TESTLIBDEPS) $(TESTEXTRADEPS) | $(BUILDDIRS)
$(LD) -o $@ $(LDFLAGS) -los $< $(TESTOBJSEXTRA) $(LIBS) $(STARTGROUP) $(LINKCORELIBS) $(ENDGROUP) $(SYSLIBRARIES)

Expand All @@ -53,7 +75,7 @@ $(TESTOBJS): %.test.o : $(SRCDIR)/%.cxxtest
$(CXX) $(CXXFLAGS) -MMD -MF $*.dtest -MT $@ -x c++ $< -o $@

gtest-all.o : %.o : $(GTESTSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -Wno-uninitialized -I$(GTESTPATH) -I$(GTESTSRCPATH) -MMD -MF $*.d $< -o $@
$(CXX) $(CXXFLAGS) -Wno-uninitialized -Wno-maybe-uninitialized -I$(GTESTPATH) -I$(GTESTSRCPATH) -MMD -MF $*.d $< -o $@

gmock-all.o : %.o : $(GMOCKSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -I$(GMOCKPATH) -I$(GMOCKSRCPATH) -MMD -MF $*.d $< -o $@
Expand Down
8 changes: 5 additions & 3 deletions etc/cov.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ else
ARCHOPTIMIZATION = -g $(TESTOPTIMIZATION) -fprofile-arcs -ftest-coverage
endif

CSHAREDFLAGS = -c -frandom-seed=$(shell echo $(abspath $<) | md5sum | sed 's/\(.*\) .*/\1/') $(ARCHOPTIMIZATION) $(INCLUDES) -Wall -Werror -Wno-unknown-pragmas -MD -MP -fno-stack-protector -D_GNU_SOURCE -DGTEST
CSHAREDFLAGS = -c -frandom-seed=$(shell echo $(abspath $<) | md5sum | sed 's/\(.*\) .*/\1/') \
$(ARCHOPTIMIZATION) $(INCLUDES) -Wall -Werror -Wno-unknown-pragmas -MD -MP \
-fno-stack-protector -D_GNU_SOURCE -DGTEST

CFLAGS = $(CSHAREDFLAGS) -std=gnu99 $(CFLAGSEXTRA)
CFLAGS = $(CSHAREDFLAGS) -std=gnu99 $(CFLAGSENV) $(CFLAGSEXTRA)

CXXFLAGS = $(CSHAREDFLAGS) -std=c++14 -D__STDC_FORMAT_MACROS \
-D__STDC_LIMIT_MACROS $(CXXFLAGSEXTRA) #-D__LINEAR_MAP__
-D__STDC_LIMIT_MACROS $(CXXFLAGSENV) $(CXXFLAGSEXTRA) \


LDFLAGS = $(ARCHOPTIMIZATION) -Wl,-Map="$(@:%=%.map)"
Expand Down
8 changes: 4 additions & 4 deletions etc/make_utils.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ $(foreach tgt,$(1),$(eval $(call REDIRECT_helper_template,$(tgt),$(2))))
endef


### Helper template to declare a dependency.
### Arguments: target_file dependency_file
### Helper template to declare a library subdirectory dependency.
### Arguments: library_basename
### Example on how to call: Put the following on a standalone line in the Makefile
### $(foreach lib,$(LIBDIRS),$(eval $(call SUBDIR_helper_template,lib/lib$(lib).a,build-$(lib))))
### $(foreach lib,$(LIBDIRS),$(eval $(call SUBDIR_helper_template,$(lib))))
define SUBDIR_helper_template

$(1)/lib$(1).a: | build-$(1)
$(1)/lib$(1).a: build-$(1)

lib/lib$(1).a: $(1)/lib$(1).a

Expand Down
126 changes: 26 additions & 100 deletions etc/test.mk
Original file line number Diff line number Diff line change
@@ -1,116 +1,42 @@
ifeq ($(BASENAME),)
# if the basename is so far undefined
BASENAME := $(notdir $(CURDIR))
endif
TOOLPATH ?= /usr/bin

include $(OPENMRNPATH)/etc/config.mk
# Get the $(CFLAGSENV), $(CXXFLAGSENV), $(LDFLAGSENV)
include $(OPENMRNPATH)/etc/env.mk

include $(OPENMRNPATH)/etc/linux.x86.mk
# Define this variable if you want to use a specific (suffixed) GCC version
# instead of the system default.
#GCCVERSION=-8

include $(OPENMRNPATH)/etc/path.mk
CC = $(shell $(OPENMRNPATH)/bin/find_distcc.sh gcc$(GCCVERSION))
CXX = $(shell $(OPENMRNPATH)/bin/find_distcc.sh g++$(GCCVERSION))
AR = ar
LD = g++$(GCCVERSION)
OBJDUMP = objdump

SRCDIR = $(OPENMRNPATH)/src/$(BASENAME)/
VPATH = $(SRCDIR):$(GMOCKPATH)/src:$(GMOCKSRCPATH)
AROPTS=D

exist := $(wildcard $(SRCDIR)/sources)
ifneq ($(strip $(exist)),)
include $(SRCDIR)/sources
else
exist := $(wildcard sources)
ifneq ($(strip $(exist)),)
include sources
else
FULLPATHCSRCS = $(wildcard $(VPATH)*.c)
FULLPATHCXXSRCS = $(wildcard $(VPATH)*.cxx)
FULLPATHCXXTESTSRCS = $(wildcard $(VPATH)*.cxxtest)
HOST_TARGET := 1

CSRCS = $(notdir $(FULLPATHCSRCS)) $(wildcard *.c)
CXXSRCS = $(notdir $(FULLPATHCXXSRCS)) $(wildcard *.cxx)
CXXTESTSRCS = $(notdir $(FULLPATHCXXTESTSRCS)) $(wildcard *.cxxtest)
endif
endif

OBJS = $(CXXSRCS:.cxx=.o) $(CSRCS:.c=.o)
TESTOBJS = $(CXXTESTSRCS:.cxxtest=.otest)
TESTOBJSEXTRA = gtest-all.o gmock-all.o

TESTBINS = $(CXXTESTSRCS:.cxxtest=.test)
TESTOUTPUTS = $(CXXTESTSRCS:.cxxtest=.testout)

LIBDIR = $(OPENMRNPATH)/targets/linux.x86/lib
FULLPATHLIBS = $(wildcard $(LIBDIR)/*.a) $(wildcard lib/*.a)
LIBDIRS := $(SUBDIRS)
LIBS = $(STARTGROUP) \
$(foreach lib,$(LIBDIRS),-l$(lib)) \
$(ENDGROUP) \
$(LINKCORELIBS)
STARTGROUP := -Wl,--start-group
ENDGROUP := -Wl,--end-group

TESTOPTIMIZATION=-O0

INCLUDES += -I$(GTESTPATH)/include -I$(GMOCKPATH)/include -I$(GMOCKPATH) \
-I$(OPENMRNPATH)/src -I$(OPENMRNPATH)/include
CFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
CXXFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
SYSLIBRARIES += -lgcov -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
LDFLAGS += -L$(LIBDIR)

.SUFFIXES:
.SUFFIXES: .o .otest .c .cxx .cxxtest .test

all: $(TESTBINS)

-include $(OBJS:.o=.d) $(TESTOBJS:.otest=.dtest)

$(TESTBINS): $(OBJS) $(TESTOBJS) $(FULLPATHLIBS) $(TESTOBJSEXTRA)
$(LD) -o $@ $*.otest $(TESTOBJSEXTRA) \
$(filter $(@:.test=.o),$(OBJS)) $(OBJSEXTRA) \
$(LDFLAGS) $(LIBS) $(SYSLIBRARIES)

$(TESTOUTPUTS): %.testout : %.test
(cd lcovdir; ../$< $(TESTARGS) --gtest_death_test_style=threadsafe && touch $@)

gtest-all.o : %.o : $(GTESTSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -I$(GTESTPATH) -I$(GTESTSRCPATH) $< -o $@
$(CXX) -MM $(CXXFLAGS) -I$(GTESTPATH) -I$(GTESTSRCPATH) $< > $*.d

gmock-all.o : %.o : $(GMOCKSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -I$(GMOCKPATH) -I$(GMOCKSRCPATH) $< -o $@
$(CXX) -MM $(CXXFLAGS) -I$(GMOCKPATH) -I$(GMOCKSRCPATH) $< > $*.d

.cxx.o:
$(CXX) $(CXXFLAGS) $< -o $@

.c.o:
$(CC) $(CFLAGS) $< -o $@

.cxxtest.otest:
$(CXX) $(CXXFLAGS) -MF $*.dtest -x c++ $< -o $@
# ln -s [email protected] $*.gcno
ARCHOPTIMIZATION = -g $(TESTOPTIMIZATION) -fdata-sections -ffunction-sections -fPIC -O0

#.otest.test:
# $(LD) -o $@ $< $(GTESTPATH)/src/gtest-all.o \
# $(GTESTPATH)/src/gtest_main.o $(filter $(<:.otest=.o),$(OBJS)) \
# $(LDFLAGS) $(SYSLIBRARIES)
CSHAREDFLAGS = -c -frandom-seed=$(shell echo $(abspath $<) | md5sum | sed 's/\(.*\) .*/\1/') \
$(ARCHOPTIMIZATION) $(INCLUDES) -Wall -Werror -Wno-unknown-pragmas -MD -MP \
-fno-stack-protector -D_GNU_SOURCE -DGTEST

tests: all
echo $(foreach TESTBINS,$(TESTBINS),gcov $(VPATH)$(TESTBINS:.test=.cxxtest))
[ -z "$(TESTBINS)" ] || (mkdir -p lcovdir; cd lcovdir; \
lcov --directory ../ --no-recursion -z; cd .. ; \
$(MAKE) run-tests ; cd lcovdir ; \
lcov --directory ../ --no-recursion --capture --output-file app.info; \
lcov -r app.info "/usr/include/*" -o app.info; \
lcov -r app.info "*.cxxtest" -o app.info; \
lcov -r app.info "*gtest*" -o app.info; \
genhtml -o . app.info )
CFLAGS = $(CSHAREDFLAGS) -std=gnu99 $(CFLAGSENV) $(CFLAGSEXTRA)

run-tests: $(TESTOUTPUTS)
CXXFLAGS = $(CSHAREDFLAGS) -std=c++14 -D__STDC_FORMAT_MACROS \
-D__STDC_LIMIT_MACROS $(CXXFLAGSENV) $(CXXFLAGSEXTRA) \

clean: clean-local
LDFLAGS = $(ARCHOPTIMIZATION) -pg -Wl,-Map="$(@:%=%.map)" -Wl,--undefined=ignore_fn

clean-local:
rm -rf *.o *.otest *.d *.dtest *.test *.gcda *.gcno *.png *.info bits ext home i686-linux-gnu opt usr *.html *.css lcovdir *.map
SYSLIB_SUBDIRS +=
SYSLIBRARIES = -lrt -lpthread -lavahi-client -lavahi-common $(SYSLIBRARIESEXTRA)

veryclean: clean-local
EXTENTION =

#nothing to do
mksubdirs:
25 changes: 13 additions & 12 deletions src/freertos_drivers/esp32/Esp32HardwareTwai.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include <hal/twai_types.h>
#include <hal/twai_hal.h>
#include <soc/gpio_sig_map.h>
#include <stdint.h>

#include "can_frame.h"
#include "can_ioctl.h"
Expand Down Expand Up @@ -234,7 +235,7 @@ static inline void twai_purge_rx_queue()
Notifiable* n = nullptr;
{
AtomicHolder h(&twai.buf_lock);
LOG(VERBOSE, "ESP-TWAI: puring RX-Q: %d", twai.rx_buf->pending());
LOG(VERBOSE, "ESP-TWAI: purging RX-Q: %zu", twai.rx_buf->pending());
twai.stats.rx_missed += twai.rx_buf->pending();
twai.rx_buf->flush();
std::swap(n, twai.readable_notify);
Expand All @@ -260,7 +261,7 @@ static inline void twai_purge_tx_queue()
Notifiable* n = nullptr;
{
AtomicHolder h(&twai.buf_lock);
LOG(VERBOSE, "ESP-TWAI: puring TX-Q: %d", twai.tx_buf->pending());
LOG(VERBOSE, "ESP-TWAI: purging TX-Q: %zu", twai.tx_buf->pending());
twai.stats.tx_failed += twai.tx_buf->pending();
twai.tx_buf->flush();
std::swap(n, twai.writable_notify);
Expand Down Expand Up @@ -288,7 +289,7 @@ static inline void twai_purge_tx_queue()
/// blocking operation.
static ssize_t twai_vfs_write(int fd, const void *buf, size_t size)
{
LOG(VERBOSE, "ESP-TWAI: write(%d, %p, %d)", fd, buf, size);
LOG(VERBOSE, "ESP-TWAI: write(%d, %p, %zu)", fd, buf, size);
DASSERT(fd == TWAI_VFS_FD);
ssize_t sent = 0;
const struct can_frame *data = (const struct can_frame *)buf;
Expand All @@ -307,7 +308,7 @@ static ssize_t twai_vfs_write(int fd, const void *buf, size_t size)
else if (!is_twai_running())
{
LOG_ERROR("ESP-TWAI: TWAI driver is not running, unable to write "
"%d frames.", size);
"%zu frames.", size);
bus_error = true;
break;
}
Expand Down Expand Up @@ -360,7 +361,7 @@ static ssize_t twai_vfs_write(int fd, const void *buf, size_t size)
{
errno = EWOULDBLOCK;
}
LOG(VERBOSE, "ESP-TWAI: write() %d", sent * sizeof(struct can_frame));
LOG(VERBOSE, "ESP-TWAI: write() %zu", sent * sizeof(struct can_frame));
return sent * sizeof(struct can_frame);
}

Expand All @@ -373,7 +374,7 @@ static ssize_t twai_vfs_write(int fd, const void *buf, size_t size)
/// blocking operation.
static ssize_t twai_vfs_read(int fd, void *buf, size_t size)
{
LOG(VERBOSE, "ESP-TWAI: read(%d, %p, %d)", fd, buf, size);
LOG(VERBOSE, "ESP-TWAI: read(%d, %p, %zu)", fd, buf, size);
DASSERT(fd == TWAI_VFS_FD);

ssize_t received = 0;
Expand Down Expand Up @@ -401,7 +402,7 @@ static ssize_t twai_vfs_read(int fd, void *buf, size_t size)
return -1;
}

LOG(VERBOSE, "ESP-TWAI: read() %d", received * sizeof(struct can_frame));
LOG(VERBOSE, "ESP-TWAI: read() %zu", received * sizeof(struct can_frame));
return received * sizeof(struct can_frame);
}

Expand Down Expand Up @@ -715,7 +716,7 @@ static void twai_isr(void *arg)
{
BaseType_t wakeup = pdFALSE;
uint32_t events = twai_hal_get_events(&twai.context);
ESP_EARLY_LOGV(TWAI_LOG_TAG, "events: %04x", events);
ESP_EARLY_LOGV(TWAI_LOG_TAG, "events: %08x", events);

#if defined(CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID) || \
defined(CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT)
Expand Down Expand Up @@ -793,8 +794,8 @@ static void twai_isr(void *arg)
// Arbitration error detected
if (events & TWAI_HAL_EVENT_ARB_LOST)
{
twai.stats.arb_error++;
ESP_EARLY_LOGV(TWAI_LOG_TAG, "arb-lost:%d", twai.stats.arb_error);
twai.stats.arb_loss++;
ESP_EARLY_LOGV(TWAI_LOG_TAG, "arb-lost:%d", twai.stats.arb_loss);
}

if (wakeup == pdTRUE)
Expand Down Expand Up @@ -877,13 +878,13 @@ void* twai_watchdog(void* param)
"ESP-TWAI: "
"RX:%d (pending:%zu,overrun:%d,discard:%d,missed:%d,lost:%d) "
"TX:%d (pending:%zu,suc:%d,fail:%d) "
"Bus (arb-err:%d,err:%d,state:%s)",
"Bus (arb-loss:%d,err:%d,state:%s)",
twai.stats.rx_processed, twai.rx_buf->pending(),
twai.stats.rx_overrun, twai.stats.rx_discard,
twai.stats.rx_missed, twai.stats.rx_lost,
twai.stats.tx_processed, twai.tx_buf->pending(),
twai.stats.tx_success, twai.stats.tx_failed,
twai.stats.arb_error, twai.stats.bus_error,
twai.stats.arb_loss, twai.stats.bus_error,
is_twai_running() ? "Running" :
is_twai_recovering() ? "Recovering" :
is_twai_err_warn() ? "Err-Warn" :
Expand Down
4 changes: 2 additions & 2 deletions src/freertos_drivers/esp32/Esp32HardwareTwai.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ typedef struct
/// by the low-level TWAI driver.
uint32_t tx_failed;

/// Number of arbitration errors that have been observed on the TWAI bus.
uint32_t arb_error;
/// Number of arbitration losses that have been observed on the TWAI bus.
uint32_t arb_loss;

/// Number of general bus errors that have been observed on the TWAI bus.
uint32_t bus_error;
Expand Down
Loading

0 comments on commit 809a4c2

Please sign in to comment.