Skip to content

Commit

Permalink
Feature macro work to remove ARDUINO ifdefs. (bakerstu#407)
Browse files Browse the repository at this point in the history
* Adds feature macro OPENMRN_HAVE_POSIX_FD.
Replaces uses of ifdef ARDUINO with feature macros.

* Adds comment.
  • Loading branch information
balazsracz authored Jul 19, 2020
1 parent e32be46 commit d5a3d9c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
7 changes: 7 additions & 0 deletions include/openmrn_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
#define OPENMRN_FEATURE_REENT 1
#endif

#if defined(__linux__) || defined(__MACH__) || defined(__WINNT__) || defined(ESP32) || defined(OPENMRN_FEATURE_DEVTAB)
/// Enables the code using ::open ::close ::read ::write for non-volatile
/// storage, FileMemorySpace for the configuration space, and
/// SNIP_DYNAMIC_FILE_NAME for node names.
#define OPENMRN_HAVE_POSIX_FD 1
#endif

/// @todo this should probably be a whitelist: __linux__ || __MACH__.
#if !defined(__FreeRTOS__) && !defined(__WINNT__) && !defined(ESP32) && \
!defined(ARDUINO) && !defined(ESP_NONOS)
Expand Down
17 changes: 9 additions & 8 deletions src/executor/Executor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "executor/Executor.hxx"

#include "openmrn_features.h"
#include <unistd.h>

#ifdef __WINNT__
Expand Down Expand Up @@ -228,14 +229,6 @@ void *ExecutorBase::entry()
return nullptr;
}

#elif defined(ARDUINO) && !defined(ESP32)

void *ExecutorBase::entry()
{
DIE("Arduino code should not start the executor.");
return nullptr;
}

#elif defined(ESP_NONOS)

#define EXECUTOR_TASK_PRIO USER_TASK_PRIO_0
Expand Down Expand Up @@ -285,6 +278,14 @@ void ICACHE_FLASH_ATTR *ExecutorBase::entry()
return nullptr;
}

#elif OPENMRN_FEATURE_SINGLE_THREADED

void *ExecutorBase::entry()
{
DIE("Arduino code should not start the executor.");
return nullptr;
}

#else
/** Thread entry point.
* @return Should never return
Expand Down
7 changes: 4 additions & 3 deletions src/openlcb/SimpleInfoProtocol.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <fcntl.h>
#include <unistd.h>

#include "openmrn_features.h"
#include "openlcb/If.hxx"
#include "executor/StateFlow.hxx"

Expand Down Expand Up @@ -217,7 +218,7 @@ private:
}
break;
}
#if (!defined(ARDUINO)) || defined(ESP32)
#if OPENMRN_HAVE_POSIX_FD
case SimpleInfoDescriptor::FILE_CHAR_ARRAY:
open_and_seek_next_file();
// fall through
Expand All @@ -227,7 +228,7 @@ private:
currentLength_ = d.arg;
HASSERT(currentLength_);
break;
#if (!defined(ARDUINO)) || defined(ESP32)
#if OPENMRN_HAVE_POSIX_FD
case SimpleInfoDescriptor::FILE_LITERAL_BYTE:
{
open_and_seek_next_file();
Expand All @@ -240,7 +241,7 @@ private:
byteOffset_ = 0;
break;
}
#endif // NOT ARDUINO, YES ESP32
#endif // if have fd
default:
currentLength_ = 0;
}
Expand Down
12 changes: 7 additions & 5 deletions src/openlcb/SimpleNodeInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include "openlcb/SimpleNodeInfo.hxx"

#include "openmrn_features.h"

namespace openlcb
{

Expand All @@ -46,15 +48,15 @@ const SimpleInfoDescriptor SNIPHandler::SNIP_RESPONSE[] = {
{SimpleInfoDescriptor::C_STRING, 0, 0, SNIP_STATIC_DATA.model_name},
{SimpleInfoDescriptor::C_STRING, 0, 0, SNIP_STATIC_DATA.hardware_version},
{SimpleInfoDescriptor::C_STRING, 0, 0, SNIP_STATIC_DATA.software_version},
#if defined(ARDUINO) && (!defined(ESP32))
#if OPENMRN_HAVE_POSIX_FD
{SimpleInfoDescriptor::FILE_LITERAL_BYTE, 2, 0, SNIP_DYNAMIC_FILENAME},
{SimpleInfoDescriptor::FILE_C_STRING, 63, 1, SNIP_DYNAMIC_FILENAME},
{SimpleInfoDescriptor::FILE_C_STRING, 64, 64, SNIP_DYNAMIC_FILENAME},
#else
/// @todo(balazs.racz) Add eeprom support to arduino.
{SimpleInfoDescriptor::LITERAL_BYTE, 2, 0, nullptr},
{SimpleInfoDescriptor::LITERAL_BYTE, 0, 0, nullptr},
{SimpleInfoDescriptor::LITERAL_BYTE, 0, 0, nullptr},
#else
{SimpleInfoDescriptor::FILE_LITERAL_BYTE, 2, 0, SNIP_DYNAMIC_FILENAME},
{SimpleInfoDescriptor::FILE_C_STRING, 63, 1, SNIP_DYNAMIC_FILENAME},
{SimpleInfoDescriptor::FILE_C_STRING, 64, 64, SNIP_DYNAMIC_FILENAME},
#endif
{SimpleInfoDescriptor::END_OF_DATA, 0, 0, 0}};

Expand Down
9 changes: 5 additions & 4 deletions src/openlcb/SimpleStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#include "openlcb/SimpleStack.hxx"

#include "openmrn_features.h"
#include "openlcb/EventHandler.hxx"
#include "openlcb/NodeInitializeFlow.hxx"
#include "openlcb/SimpleNodeInfo.hxx"
Expand Down Expand Up @@ -103,12 +104,12 @@ SimpleTcpStack::SimpleTcpStack(const openlcb::NodeID node_id)

void SimpleStackBase::start_stack(bool delay_start)
{
#if (!defined(ARDUINO)) || defined(ESP32)
#if OPENMRN_HAVE_POSIX_FD
// Opens the eeprom file and sends configuration update commands to all
// listeners.
configUpdateFlow_.open_file(CONFIG_FILENAME);
configUpdateFlow_.init_flow();
#endif // NOT ARDUINO, YES ESP32
#endif // have posix fd

if (!delay_start)
{
Expand Down Expand Up @@ -138,7 +139,7 @@ void SimpleStackBase::default_start_node()
node(), MemoryConfigDefs::SPACE_ACDI_SYS, space);
additionalComponents_.emplace_back(space);
}
#if (!defined(ARDUINO)) || defined(ESP32)
#if OPENMRN_HAVE_POSIX_FD
{
auto *space = new FileMemorySpace(
SNIP_DYNAMIC_FILENAME, sizeof(SimpleNodeDynamicValues));
Expand All @@ -156,7 +157,7 @@ void SimpleStackBase::default_start_node()
node(), MemoryConfigDefs::SPACE_CDI, space);
additionalComponents_.emplace_back(space);
}
#if (!defined(ARDUINO)) || defined(ESP32)
#if OPENMRN_HAVE_POSIX_FD
if (CONFIG_FILENAME != nullptr)
{
auto *space = new FileMemorySpace(CONFIG_FILENAME, CONFIG_FILE_SIZE);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/Queue.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <cstdlib>
#include <cstdarg>

#include "openmrn_features.h"
#include "executor/Executable.hxx"
#include "executor/Notifiable.hxx"
#include "os/OS.hxx"
Expand Down Expand Up @@ -868,7 +869,7 @@ public:
return result;
}

#if !(defined(ESP_NONOS) || defined(ARDUINO))
#if OPENMRN_FEATURE_SEM_TIMEDWAIT
/** Wait for an item from the front of the queue.
* @param timeout time to wait in nanoseconds
* @return item retrieved from queue, else NULL with errno set:
Expand Down

0 comments on commit d5a3d9c

Please sign in to comment.