This commit is contained in:
geeksville 2020-09-04 17:23:17 -07:00
parent c629b94333
commit 6a475d8288
11 changed files with 152 additions and 59 deletions

View File

@ -48,7 +48,8 @@
"optional": "cpp", "optional": "cpp",
"string_view": "cpp", "string_view": "cpp",
"cassert": "cpp", "cassert": "cpp",
"iterator": "cpp" "iterator": "cpp",
"shared_mutex": "cpp"
}, },
"cSpell.words": [ "cSpell.words": [
"Blox", "Blox",

View File

@ -62,6 +62,7 @@ lib_deps =
https://github.com/meshtastic/TinyGPSPlus.git https://github.com/meshtastic/TinyGPSPlus.git
https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460 https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460
Wire ; explicitly needed here because the AXP202 library forgets to add it Wire ; explicitly needed here because the AXP202 library forgets to add it
SPI
; Common settings for Ardino targets ; Common settings for Ardino targets
[arduino_base] [arduino_base]
@ -70,7 +71,6 @@ framework = arduino
lib_deps = lib_deps =
${env.lib_deps} ${env.lib_deps}
SPI
; Common settings for ESP targes, mixin with extends = esp32_base ; Common settings for ESP targes, mixin with extends = esp32_base
[esp32_base] [esp32_base]
@ -248,7 +248,7 @@ lib_deps =
[env:linux] [env:linux]
platform = https://github.com/geeksville/platform-portduino.git platform = https://github.com/geeksville/platform-portduino.git
src_filter = ${env.src_filter} +<../../Portduino/src> -<esp32/> -<nimble/> src_filter = ${env.src_filter} -<esp32/> -<nimble/>
build_flags = ${env.build_flags} -I../Portduino/src -I../Portduino/cores/arduino/api build_flags = ${env.build_flags} -DRADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
framework = arduino framework = arduino
board = linux_x86_64 board = linux_x86_64

View File

@ -0,0 +1,37 @@
#pragma once
#include "WorkerThread.h"
namespace concurrency {
/**
* @brief A worker thread that waits on a freertos notification
*/
class BaseNotifiedWorkerThread : public WorkerThread
{
public:
/**
* Notify this thread so it can run
*/
virtual void notify(uint32_t v = 0, eNotifyAction action = eNoAction) = 0;
protected:
/**
* The notification that was most recently used to wake the thread. Read from loop()
*/
uint32_t notification = 0;
/**
* What notification bits should be cleared just after we read and return them in notification?
*
* Defaults to clear all of them.
*/
uint32_t clearOnRead = UINT32_MAX;
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block() = 0;
};
} // namespace concurrency

View File

@ -1,19 +1,23 @@
#include "NotifiedWorkerThread.h" #include "NotifiedWorkerThread.h"
#ifdef HAS_FREE_RTOS
namespace concurrency { namespace concurrency {
/** /**
* Notify this thread so it can run * Notify this thread so it can run
*/ */
void NotifiedWorkerThread::notify(uint32_t v, eNotifyAction action) void FreeRtosNotifiedWorkerThread::notify(uint32_t v, eNotifyAction action)
{ {
xTaskNotify(taskHandle, v, action); xTaskNotify(taskHandle, v, action);
} }
void NotifiedWorkerThread::block() void FreeRtosNotifiedWorkerThread::block()
{ {
xTaskNotifyWait(0, // don't clear notification on entry xTaskNotifyWait(0, // don't clear notification on entry
clearOnRead, &notification, portMAX_DELAY); // Wait forever clearOnRead, &notification, portMAX_DELAY); // Wait forever
} }
} // namespace concurrency } // namespace concurrency
#endif

View File

@ -0,0 +1,40 @@
#pragma once
#include "BaseNotifiedWorkerThread.h"
#ifdef HAS_FREE_RTOS
namespace concurrency {
/**
* @brief A worker thread that waits on a freertos notification
*/
class FreeRtosNotifiedWorkerThread : public BaseNotifiedWorkerThread
{
public:
/**
* Notify this thread so it can run
*/
void notify(uint32_t v = 0, eNotifyAction action = eNoAction);
/**
* Notify from an ISR
*
* This must be inline or IRAM_ATTR on ESP32
*/
inline void notifyFromISR(BaseType_t *highPriWoken, uint32_t v = 0, eNotifyAction action = eNoAction)
{
xTaskNotifyFromISR(taskHandle, v, action, highPriWoken);
}
protected:
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block();
};
} // namespace concurrency
#endif

View File

@ -1,47 +1,17 @@
#pragma once #pragma once
#include "WorkerThread.h" #include "FreeRtosNotifiedWorkerThread.h"
#include "PosixNotifiedWorkerThread.h"
namespace concurrency { namespace concurrency
/**
* @brief A worker thread that waits on a freertos notification
*/
class NotifiedWorkerThread : public WorkerThread
{ {
public:
/**
* Notify this thread so it can run
*/
void notify(uint32_t v = 0, eNotifyAction action = eNoAction);
/** #ifdef HAS_FREE_RTOS
* Notify from an ISR typedef FreeRtosNotifiedWorkerThread NotifiedWorkerThread;
* #endif
* This must be inline or IRAM_ATTR on ESP32
*/
inline void notifyFromISR(BaseType_t *highPriWoken, uint32_t v = 0, eNotifyAction action = eNoAction)
{
xTaskNotifyFromISR(taskHandle, v, action, highPriWoken);
}
protected: #ifdef __unix__
/** typedef PosixNotifiedWorkerThread NotifiedWorkerThread;
* The notification that was most recently used to wake the thread. Read from loop() #endif
*/
uint32_t notification = 0;
/**
* What notification bits should be cleared just after we read and return them in notification?
*
* Defaults to clear all of them.
*/
uint32_t clearOnRead = UINT32_MAX;
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block();
};
} // namespace concurrency } // namespace concurrency

View File

@ -0,0 +1,26 @@
#pragma once
#include "BaseNotifiedWorkerThread.h"
namespace concurrency {
/**
* @brief A worker thread that waits on a freertos notification
*/
class PosixNotifiedWorkerThread : public BaseNotifiedWorkerThread
{
public:
/**
* Notify this thread so it can run
*/
void notify(uint32_t v = 0, eNotifyAction action = eNoAction);
protected:
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block();
};
} // namespace concurrency

View File

@ -59,7 +59,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth) #define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
#elif NRF52_SERIES // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be #elif defined(NRF52_SERIES) // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be
// board specific // board specific
// //
@ -103,17 +103,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define GPS_TX_PIN 12 #define GPS_TX_PIN 12
#endif #endif
//
// Standard definitions for !ESP32 targets
//
#ifdef NO_ESP32
// Nop definition for these attributes - not used on NRF52
#define EXT_RAM_ATTR
#define IRAM_ATTR
#define RTC_DATA_ATTR
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// LoRa SPI // LoRa SPI
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -128,6 +117,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif #endif
//
// Standard definitions for !ESP32 targets
//
#ifdef NO_ESP32
// Nop definition for these attributes - not used on NRF52
#define EXT_RAM_ATTR
#define IRAM_ATTR
#define RTC_DATA_ATTR
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// OLED // OLED
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -37,5 +37,13 @@ typedef uint32_t BaseType_t;
#define portMAX_DELAY UINT32_MAX #define portMAX_DELAY UINT32_MAX
#define tskIDLE_PRIORITY 0 #define tskIDLE_PRIORITY 0
#define configMAX_PRIORITIES 10 // Highest priority level
// Don't do anything on non free rtos platforms when done with the ISR
#define portYIELD_FROM_ISR(x)
enum eNotifyAction {
eNoAction
};
#endif #endif

View File

@ -223,7 +223,7 @@ void setup()
// Init our SPI controller (must be before screen and lora) // Init our SPI controller (must be before screen and lora)
initSPI(); initSPI();
#ifdef NRF52_SERIES #ifdef NO_ESP32
SPI.begin(); SPI.begin();
#else #else
// ESP32 // ESP32

View File

@ -32,7 +32,14 @@ DeviceState versions used to be defined in the .proto file but really only this
#define DEVICESTATE_CUR_VER 11 #define DEVICESTATE_CUR_VER 11
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER #define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
#ifndef NO_ESP32 #ifdef PORTDUINO
// Portduino version
#include "PortduinoFS.h"
#define FS PortduinoFS
#define FSBegin() FS.begin(true)
#define FILE_O_WRITE "w"
#define FILE_O_READ "r"
#elif !defined(NO_ESP32)
// ESP32 version // ESP32 version
#include "SPIFFS.h" #include "SPIFFS.h"
#define FS SPIFFS #define FS SPIFFS