Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bakerstu/openmrn into bracz-virut…
Browse files Browse the repository at this point in the history
…al-memory-space

* 'master' of github.com:bakerstu/openmrn:
  Adds a partial implementation of VirtualMemorySpace (#418)
  Adds the ability to run tests under performance profiling. (#416)
  Adds a railcom debug flow that sends a pulse to a GPIO when it sees a valid packet. (#415)
  Make dead code into less dead code. (#417)
  Bakerstu macos cleanup (#409)
  • Loading branch information
balazsracz committed Aug 27, 2020
2 parents 9aa5577 + 1225b67 commit cb99e2f
Show file tree
Hide file tree
Showing 41 changed files with 234 additions and 138 deletions.
1 change: 0 additions & 1 deletion applications/async_blink/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SUBDIRS = linux.x86 \
linux.armv7a \
linux.llvm \
mach.x86 \
mach.x86_64 \
freertos.armv7m.ek-lm4f120xl \
freertos.armv7m.ek-tm4c123gxl \
Expand Down
2 changes: 0 additions & 2 deletions applications/async_blink/targets/mach.x86/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion applications/async_blink/targets/mach.x86/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions applications/async_blink/targets/mach.x86/NodeId.cxx

This file was deleted.

1 change: 1 addition & 0 deletions applications/async_blink/targets/mach.x86_64/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-include ../../config.mk
include $(OPENMRNPATH)/etc/prog.mk
10 changes: 5 additions & 5 deletions applications/clinic_app/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SUBDIRS = \
freertos.armv7m.ek-tm4c123gxl \
freertos.armv7m.ek-tm4c1294xl \
freertos.armv6m.st-stm32f072b-discovery \
freertos.armv7m.st-stm32f303-discovery \
freertos.armv7m.ek-tm4c123gxl \
freertos.armv7m.ek-tm4c1294xl \
freertos.armv6m.st-stm32f072b-discovery \
freertos.armv7m.st-stm32f303-discovery \
linux.armv7a \
linux.x86 \
mach.x86
mach.x86_64


# freertos.armv7m.lpc1768-mbed \
Expand Down
2 changes: 1 addition & 1 deletion applications/hub/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SUBDIRS = linux.x86 \
linux.armv7a \
mach.x86
mach.x86_64

include $(OPENMRNPATH)/etc/recurse.mk
1 change: 0 additions & 1 deletion applications/hub/targets/mach.x86/lib/Makefile

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion applications/simple_client/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SUBDIRS = linux.x86 mach.x86
SUBDIRS = linux.x86 mach.x86_64
-include config.mk
include $(OPENMRNPATH)/etc/recurse.mk
1 change: 1 addition & 0 deletions applications/simple_client/targets/mach.x86_64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
simple_client
15 changes: 13 additions & 2 deletions etc/cov.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ HOST_TARGET := 1
STARTGROUP := -Wl,--start-group
ENDGROUP := -Wl,--end-group

TESTOPTIMIZATION=-O0

ifdef SKIP_COVERAGE
ARCHOPTIMIZATION = -g -O0
ARCHOPTIMIZATION = -g $(TESTOPTIMIZATION)
else
ARCHOPTIMIZATION = -g -O0 -fprofile-arcs -ftest-coverage
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
Expand All @@ -36,6 +38,15 @@ LDFLAGS = $(ARCHOPTIMIZATION) -Wl,-Map="$(@:%=%.map)"
SYSLIB_SUBDIRS +=
SYSLIBRARIES = -lrt -lpthread -lavahi-client -lavahi-common $(SYSLIBRARIESEXTRA)

ifdef RUN_GPERF
CXXFLAGS += -DWITHGPERFTOOLS
LDFLAGS += -DWITHGPERFTOOLS
SYSLIBRARIES += -lprofiler
TESTOPTIMIZATION = -O3
SKIP_COVERAGE = 1
endif


ifndef SKIP_COVERAGE
LDFLAGS += -pg
SYSLIBRARIES += -lgcov
Expand Down
30 changes: 0 additions & 30 deletions etc/mach.x86.mk

This file was deleted.

20 changes: 10 additions & 10 deletions etc/mach.x86_64.mk
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
ifndef TOOLPATH
TOOLPATH := $(shell \
sh -c "if [ -d /usr/include/mach ]; then echo /usr/bin; \
else echo; fi" \
)
# Get the toolchain path
include $(OPENMRNPATH)/etc/path.mk

ifeq ($(shell uname -sm),Darwin x86_64)
TOOLPATH := $(HOSTCLANGPPPATH)
endif

$(info mach toolpath '$(TOOLPATH)')

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

CC = gcc
CXX = g++
CC = clang
CXX = clang++
AR = ar
LD = g++
LD = clang++

STARTGROUP :=
ENDGROUP :=

INCLUDES += -I$(OPENMRNPATH)/include/mach

CFLAGS = -c -g -O0 -Wall -Werror -MD -MP -std=gnu99 -fno-stack-protector \
CFLAGS = -c -g -O0 -Wall -Werror -MD -MP -std=c99 -fno-stack-protector \
-D_GNU_SOURCE
CXXFLAGS = -c -g -O0 -Wall -Werror -MD -MP -std=c++0x -fno-stack-protector \
CXXFLAGS = -c -g -O0 -Wall -Werror -MD -MP -std=c++14 -fno-stack-protector \
-D_GNU_SOURCE

LDFLAGS = -g
Expand Down
12 changes: 12 additions & 0 deletions etc/path.mk
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,18 @@ CLANGPPPATH:=$(TRYPATH)
endif
endif #CLANGPPPATH

##################### HOSTCLANGPP ######################
ifndef HOSTCLANGPPPATH
SEARCHPATH := \
/usr/bin \


TRYPATH:=$(call findfirst,clang++,$(SEARCHPATH))
ifneq ($(TRYPATH),)
HOSTCLANGPPPATH:=$(TRYPATH)
endif
endif #HOSTCLANGPPPATH

##################### NODEJS ######################
ifndef NODEJSPATH
SEARCHPATH := \
Expand Down
8 changes: 5 additions & 3 deletions etc/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ LIBS = $(STARTGROUP) \
$(ENDGROUP) \
$(LINKCORELIBS)

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 -O0
CXXFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage -O0
SYSLIBRARIES += -lgcov -fprofile-arcs -ftest-coverage -O0
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:
Expand Down
66 changes: 66 additions & 0 deletions src/dcc/RailcomPortDebug.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,72 @@ private:
dcc::RailcomHubFlow *parent_;
};

/// This flow listens to Railcom packets coming from the hub, and if they are
/// correctly decoded, pulses the given GPIO output. Correctly decoded is
/// defined as having every single byte be a correct 4/8 codepoint.
class RailcomToGpioFlow : public dcc::RailcomHubPortInterface
{
public:
/// Constructor.
/// @param source is the railcom hub to listen to.
/// @param output
RailcomToGpioFlow(dcc::RailcomHubFlow *source, const Gpio *output)
: parent_(source)
, output_(output)
{
source->register_port(this);
}

~RailcomToGpioFlow()
{
parent_->unregister_port(this);
}

private:
/// Incoming railcom data.
///
/// @param d railcom buffer.
/// @param prio priority
void send(Buffer<dcc::RailcomHubData> *d, unsigned prio) OVERRIDE
{
AutoReleaseBuffer<dcc::RailcomHubData> rb(d);
dcc::Feedback &fb = *d->data();
if (fb.channel >= 0xfe)
{
// Occupancy feedback, not railcom data.
return;
}
unsigned correct = 0;
unsigned total = 0;
for (unsigned i = 0; i < fb.ch1Size; i++)
{
++total;
correct += (dcc::railcom_decode[fb.ch1Data[i]] != RailcomDefs::INV)
? 1
: 0;
}
for (unsigned i = 0; i < fb.ch2Size; i++)
{
++total;
correct += (dcc::railcom_decode[fb.ch2Data[i]] != RailcomDefs::INV)
? 1
: 0;
}
if (total > 0 && correct == total)
{
// Produces a short pulse on the output
output_->write(true);
for (volatile int i = 0; i < 3000; i++) { }
output_->write(false);
}
}

/// Flow to which we are registered.
dcc::RailcomHubFlow *parent_;
/// Output gpio to toggle.
const Gpio *output_;
}; // RailcomToGpioFlow

} // namespace dcc

namespace openlcb
Expand Down
100 changes: 100 additions & 0 deletions src/os/OSSelectWakeup.cxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,110 @@
/** \copyright
* Copyright (c) 2015, Balazs Racz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \file OSSelectWakeup.cxx
* Helper class for portable wakeup of a thread blocked in a select call.
*
* @author Balazs Racz
* @date 10 Apr 2015
*/

#include "os/OSSelectWakeup.hxx"
#include "utils/logging.h"
#if defined(__MACH__)
#define _DARWIN_C_SOURCE // pselect
#endif

void empty_signal_handler(int)
{
}

int OSSelectWakeup::select(int nfds, fd_set *readfds,
fd_set *writefds, fd_set *exceptfds,
long long deadline_nsec)
{
{
AtomicHolder l(this);
inSelect_ = true;
if (pendingWakeup_)
{
deadline_nsec = 0;
}
else
{
#if OPENMRN_FEATURE_DEVICE_SELECT
Device::select_clear();
#endif
}
}
#if OPENMRN_FEATURE_DEVICE_SELECT
int ret =
Device::select(nfds, readfds, writefds, exceptfds, deadline_nsec);
if (!ret && pendingWakeup_)
{
ret = -1;
errno = EINTR;
}
#elif OPENMRN_HAVE_PSELECT
struct timespec timeout;
timeout.tv_sec = deadline_nsec / 1000000000;
timeout.tv_nsec = deadline_nsec % 1000000000;
int ret =
::pselect(nfds, readfds, writefds, exceptfds, &timeout, &origMask_);
#elif OPENMRN_HAVE_SELECT
#ifdef ESP32
fd_set newexcept;
if (!exceptfds)
{
FD_ZERO(&newexcept);
exceptfds = &newexcept;
}
FD_SET(vfsFd_, exceptfds);
if (vfsFd_ >= nfds) {
nfds = vfsFd_ + 1;
}
#endif //ESP32
struct timeval timeout;
timeout.tv_sec = deadline_nsec / 1000000000;
timeout.tv_usec = (deadline_nsec / 1000) % 1000000;
int ret =
::select(nfds, readfds, writefds, exceptfds, &timeout);
#elif !defined(OPENMRN_FEATURE_SINGLE_THREADED)
#error no select implementation in multi threaded OS.
#else
// Single threaded OS: nothing to wake up.
int ret = 0;
#endif
{
AtomicHolder l(this);
pendingWakeup_ = false;
inSelect_ = false;
}
return ret;
}

#ifdef ESP32
#include <sys/types.h>
#include <sys/stat.h>
Expand Down
Loading

0 comments on commit cb99e2f

Please sign in to comment.