Skip to content

Commit

Permalink
Merge branch 'bracz-st-decoder-update' into bracz-decoder-railcom-impl
Browse files Browse the repository at this point in the history
* bracz-st-decoder-update:
  Tiva 129 updates around emulator (#556)
  Adds some example railcom feedback (#552)
  Adds routines to encode railcom data for a sender. (#553)
  Fix comment.
  Adds driver and hooks for sending railcom data out. (#551)
  Adds missing header guard. (#557)
  Reduce the number of times the config file is opened in SimpleStack (#555)
  • Loading branch information
balazsracz committed Aug 2, 2021
2 parents 4d95f23 + ee19377 commit 70bd716
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 38 deletions.
7 changes: 3 additions & 4 deletions applications/async_blink/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
#include "utils/ESPWifiClient.hxx"
#endif

#if defined (BOARD_LAUNCHPAD_EK) || defined (__linux__)
#if (defined (TARGET_IS_CC3200) || defined (__linux__) || defined(PART_TM4C1294NCPDT)) && (!defined(NO_CONSOLE))
#define HAVE_CONSOLE
#include "console/Console.hxx"
#endif

Expand Down Expand Up @@ -206,9 +207,7 @@ openlcb::BitEventConsumer consumer(&logger);
*/
int appl_main(int argc, char* argv[])
{
#if defined (BOARD_LAUNCHPAD_EK)
//new Console(stack.executor(), Console::FD_STDIN, Console::FD_STDOUT);
#elif defined (__linux__)
#ifdef HAVE_CONSOLE
new Console(stack.executor(), Console::FD_STDIN, Console::FD_STDOUT, 2121);
#endif

Expand Down
12 changes: 0 additions & 12 deletions applications/blink_raw/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@

#include "os/os.h"
#include "utils/blinker.h"
#include "console/Console.hxx"

#if (defined (TARGET_IS_CC3200) || defined (__linux__) || defined(PART_TM4C1294NCPDT)) && (!defined(NO_CONSOLE))
#define HAVE_CONSOLE
#endif

#ifdef HAVE_CONSOLE
Executor<1> executor("executor", 0, 2048);
#endif

/** Entry point to application.
* @param argc number of command line arguments
Expand All @@ -59,9 +50,6 @@ Executor<1> executor("executor", 0, 2048);
int appl_main(int argc, char *argv[])
{
setblink(0);
#ifdef HAVE_CONSOLE
new Console(&executor, Console::FD_STDIN, Console::FD_STDOUT, 2121);
#endif
while (1)
{
resetblink(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,21 @@ export BOARD

OPENOCDARGS = -f board/ek-tm4c1294xl.cfg

# this works for XDS110 with SWD (2 wire)
#OPENOCDARGS = -c 'set TRANSPORT swd' -f interface/xds110.cfg -c 'transport select swd' -c 'set WORKAREASIZE 0x8000' -c 'set CHIPNAME tm4c1294ncpdt' -f target/stellaris.cfg

#OPENOCDARGS = -f interface/xds110.cfg -c 'set WORKAREASIZE 0x8000' -c 'set CHIPNAME tm4c1294ncpdt' -f target/stellaris.cfg

# this works for XDS110 with JTAG (4 wire)
#OPENOCDARGS = -f interface/xds110.cfg -c 'transport select jtag' -c 'set WORKAREASIZE 0x8000' -c 'set CHIPNAME tm4c1294ncpdt' -f target/stellaris.cfg

include $(OPENMRNPATH)/etc/prog.mk

ifeq ($(call find_missing_deps,OPENOCDSCRIPTSPATH OPENOCDPATH),)
flash: $(EXECUTABLE)$(EXTENTION) $(EXECUTABLE).lst
@if ps ax -o comm | grep -q openocd ; then echo openocd already running. quit existing first. ; exit 1 ; fi
cp $< last-flashed-$<
$(GDB) $< -ex "target remote | $(OPENOCDPATH)/openocd -c \"gdb_port pipe\" --search $(OPENOCDSCRIPTSPATH) $(OPENOCDARGS)" -ex "monitor reset halt" -ex "load" -ex "monitor reset init" -ex "monitor reset run" -ex "detach" -ex "quit"
$(GDB) $< -ex "target remote | $(OPENOCDPATH)/openocd -c \"gdb_port pipe\" --search $(OPENOCDSCRIPTSPATH) $(OPENOCDARGS)" -ex "monitor reset init" -ex "monitor reset run" -ex "load" -ex "monitor reset init" -ex "monitor reset run" -ex "detach" -ex "quit"

gdb:
@if ps ax -o comm | grep -q openocd ; then echo openocd already running. quit existing first. ; exit 1 ; fi
Expand Down
2 changes: 1 addition & 1 deletion etc/path.mk
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ SEARCHPATH := \
/usr/share/openocd/scripts \


TRYPATH:=$(call findfirst,target/stellaris_icdi.cfg,$(SEARCHPATH))
TRYPATH:=$(call findfirst,target/stm32f0x.cfg,$(SEARCHPATH))
ifneq ($(TRYPATH),)
OPENOCDSCRIPTSPATH:=$(TRYPATH)
endif
Expand Down
2 changes: 1 addition & 1 deletion src/dcc/RailCom.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extern const uint8_t railcom_decode[256];
/// Table for 6-to-8 encoding of railcom data. The table can be indexed by a
/// 6-bit value that is the semantic content of a railcom byte, and returns the
/// matching 8-bit value to put out on the UART. This table only contains the
/// standard codes, for the special codes like ACK use RailcomDefs above.
/// standard codes, for the special codes like ACK use RailcomDefs::ACK.
extern const uint8_t railcom_encode[64];

/// Special constant values returned by the @ref railcom_decode[] array.
Expand Down
14 changes: 4 additions & 10 deletions src/openlcb/ConfigUpdateFlow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,10 @@ namespace openlcb

int ConfigUpdateFlow::open_file(const char *path)
{
if (fd_ >= 0) return fd_;
if (!path)
{
fd_ = -1;
}
else
{
fd_ = ::open(path, O_RDWR);
HASSERT(fd_ >= 0);
}
HASSERT(fd_ < 0);
HASSERT(path);
fd_ = ::open(path, O_RDWR);
HASSERT(fd_ >= 0);
return fd_;
}

Expand Down
13 changes: 11 additions & 2 deletions src/openlcb/ConfigUpdateFlow.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,30 @@ public:
{
}

/// Must be called once before calling anything else. Returns the file
/// descriptor.
/// Must be called once (only) before calling anything else. Returns the
/// file descriptor.
int open_file(const char *path);
/// Asynchronously invokes all update listeners with the config FD.
void init_flow();
/// Synchronously invokes all update listeners to factory reset.
void factory_reset();

/// @return the file descriptor of the configuration file, or -1 if the
/// configuration file has not yet been opened.
int get_fd()
{
return fd_;
}

#ifdef GTEST
void TEST_set_fd(int fd)
{
fd_ = fd;
}
bool TEST_is_terminated() {
return is_terminated();
}
#endif // GTEST

void trigger_update() override
{
Expand Down
26 changes: 19 additions & 7 deletions src/openlcb/SimpleStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ void SimpleStackBase::start_stack(bool delay_start)
{
#if OPENMRN_HAVE_POSIX_FD
// Opens the eeprom file and sends configuration update commands to all
// listeners.
configUpdateFlow_.open_file(CONFIG_FILENAME);
// listeners. We must only call ConfigUpdateFlow::open_file() once and it
// may have been done by an earlier call to create_config_file_if_needed()
// or check_version_and_factory_reset().
if (configUpdateFlow_.get_fd() < 0)
{
configUpdateFlow_.open_file(CONFIG_FILENAME);
}
configUpdateFlow_.init_flow();
#endif // have posix fd

Expand Down Expand Up @@ -139,12 +144,12 @@ void SimpleStackBase::default_start_node()
#if OPENMRN_HAVE_POSIX_FD
{
auto *space = new FileMemorySpace(
SNIP_DYNAMIC_FILENAME, sizeof(SimpleNodeDynamicValues));
configUpdateFlow_.get_fd(), sizeof(SimpleNodeDynamicValues));
memoryConfigHandler_.registry()->insert(
node(), MemoryConfigDefs::SPACE_ACDI_USR, space);
additionalComponents_.emplace_back(space);
}
#endif // NOT ARDUINO, YES ESP32
#endif // OPENMRN_HAVE_POSIX_FD
size_t cdi_size = strlen(CDI_DATA);
if (cdi_size > 0)
{
Expand All @@ -157,12 +162,13 @@ void SimpleStackBase::default_start_node()
#if OPENMRN_HAVE_POSIX_FD
if (CONFIG_FILENAME != nullptr)
{
auto *space = new FileMemorySpace(CONFIG_FILENAME, CONFIG_FILE_SIZE);
auto *space =
new FileMemorySpace(configUpdateFlow_.get_fd(), CONFIG_FILE_SIZE);
memory_config_handler()->registry()->insert(
node(), openlcb::MemoryConfigDefs::SPACE_CONFIG, space);
additionalComponents_.emplace_back(space);
}
#endif // NOT ARDUINO, YES ESP32
#endif // OPENMRN_HAVE_POSIX_FD
}

SimpleTrainCanStack::SimpleTrainCanStack(
Expand Down Expand Up @@ -220,6 +226,7 @@ int SimpleStackBase::create_config_file_if_needed(const InternalConfigData &cfg,
uint16_t expected_version, unsigned file_size)
{
HASSERT(CONFIG_FILENAME);
HASSERT(configUpdateFlow_.get_fd() < 0);
struct stat statbuf;
bool reset = false;
bool extend = false;
Expand Down Expand Up @@ -318,7 +325,12 @@ int SimpleStackBase::check_version_and_factory_reset(
const InternalConfigData &cfg, uint16_t expected_version, bool force)
{
HASSERT(CONFIG_FILENAME);
int fd = configUpdateFlow_.open_file(CONFIG_FILENAME);
int fd = configUpdateFlow_.get_fd();
if (fd < 0)
{
fd = configUpdateFlow_.open_file(CONFIG_FILENAME);
}

if (cfg.version().read(fd) != expected_version)
{
/// @todo (balazs.racz): We need to clear the eeprom. Best would be if
Expand Down
5 changes: 5 additions & 0 deletions src/utils/Crc.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
* @date 16 Dec 2014
*/

#ifndef _UTILS_CRC_HXX_
#define _UTILS_CRC_HXX_

#include <stdint.h>
#include <stddef.h>

Expand Down Expand Up @@ -186,3 +189,5 @@ private:
/// Current value of the state register for the CRC computation.
uint8_t state_;
};

#endif // _UTILS_CRC_HXX_

0 comments on commit 70bd716

Please sign in to comment.