Merge branch 'dev'

1.2-legacy
geeksville 2020-09-17 11:20:41 -07:00
commit d3e28e3e2c
42 zmienionych plików z 495 dodań i 205 usunięć

Wyświetl plik

@ -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",

Wyświetl plik

@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
default_envs = tbeam # or if you'd like to change the default to something like lora-relay-v1 put that here default_envs = tbeam # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here
[common] [common]
; common is not currently used ; common is not currently used
@ -23,15 +23,9 @@ default_envs = tbeam # or if you'd like to change the default to something like
[env] [env]
framework = arduino
; customize the partition table
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
board_build.partitions = partition-table.csv
; note: we add src to our include search path so that lmic_project_config can override ; note: we add src to our include search path so that lmic_project_config can override
; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc ; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc
build_flags = -Wno-missing-field-initializers -Isrc -Isrc/mesh -Isrc/gps -Ilib/nanopb/include -Os -Wl,-Map,.pio/build/output.map build_flags = -Wno-missing-field-initializers -Isrc -Isrc/mesh -Isrc/gps -Ilib/nanopb/include -Wl,-Map,.pio/build/output.map
-DHW_VERSION_${sysenv.COUNTRY} -DHW_VERSION_${sysenv.COUNTRY}
-DAPP_VERSION=${sysenv.APP_VERSION} -DAPP_VERSION=${sysenv.APP_VERSION}
-DHW_VERSION=${sysenv.HW_VERSION} -DHW_VERSION=${sysenv.HW_VERSION}
@ -60,25 +54,38 @@ debug_tool = jlink
lib_deps = lib_deps =
https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306 https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
SPI
1260 ; OneButton library for non-blocking button debounce 1260 ; OneButton library for non-blocking button debounce
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib 1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
Wire ; explicitly needed here because the AXP202 library forgets to add it
https://github.com/meshtastic/arduino-fsm.git https://github.com/meshtastic/arduino-fsm.git
https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git
https://github.com/meshtastic/RadioLib.git#7989a269be590a5d4914ac04069b58f4930c45c1 https://github.com/meshtastic/RadioLib.git#7989a269be590a5d4914ac04069b58f4930c45c1
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
SPI
; Common settings for conventional (non Portduino) Ardino targets
[arduino_base]
framework = arduino
lib_deps =
${env.lib_deps}
build_flags = ${env.build_flags} -Os
src_filter = ${env.src_filter} -<portduino/>
; Common settings for ESP targes, mixin with extends = esp32_base ; Common settings for ESP targes, mixin with extends = esp32_base
[esp32_base] [esp32_base]
extends = arduino_base
platform = espressif32 platform = espressif32
src_filter = src_filter =
${env.src_filter} -<nrf52/> ${arduino_base.src_filter} -<nrf52/>
upload_speed = 921600 upload_speed = 921600
debug_init_break = tbreak setup debug_init_break = tbreak setup
build_flags = build_flags =
${env.build_flags} -Wall -Wextra -Isrc/esp32 -mfix-esp32-psram-cache-issue -lnimble -std=c++11 ${arduino_base.build_flags} -Wall -Wextra -Isrc/esp32 -Isrc/esp32-mfix-esp32-psram-cache-issue -lnimble -std=c++11
-DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DAXP_DEBUG_PORT=Serial -DAXP_DEBUG_PORT=Serial
# Hmm - this doesn't work yet # Hmm - this doesn't work yet
@ -87,6 +94,10 @@ lib_ignore = segger_rtt
platform_packages = platform_packages =
framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#2814f110aa618429bdd9a0a2d6a93c55f29f87a6 framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#2814f110aa618429bdd9a0a2d6a93c55f29f87a6
; customize the partition table
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
board_build.partitions = partition-table.csv
; not needed included in ttgo-t-beam board file ; not needed included in ttgo-t-beam board file
; also to use PSRAM https://docs.platformio.org/en/latest/platforms/espressif32.html#external-ram-psram ; also to use PSRAM https://docs.platformio.org/en/latest/platforms/espressif32.html#external-ram-psram
; -DBOARD_HAS_PSRAM ; -DBOARD_HAS_PSRAM
@ -99,7 +110,7 @@ platform_packages =
extends = esp32_base extends = esp32_base
board = ttgo-t-beam board = ttgo-t-beam
lib_deps = lib_deps =
${env.lib_deps} ${arduino_base.lib_deps}
build_flags = build_flags =
${esp32_base.build_flags} -D TBEAM_V10 ${esp32_base.build_flags} -D TBEAM_V10
@ -142,25 +153,26 @@ build_flags =
platform = https://github.com/HelTecAutomation/platform-asrmicro650x.git ; we use top-of-tree because stable version has too many bugs - asrmicro650x platform = https://github.com/HelTecAutomation/platform-asrmicro650x.git ; we use top-of-tree because stable version has too many bugs - asrmicro650x
board = cubecell_board_plus board = cubecell_board_plus
; FIXME, bug in cubecell arduino - they are supposed to set ARDUINO ; FIXME, bug in cubecell arduino - they are supposed to set ARDUINO
build_flags = ${env.build_flags} -DARDUINO=100 -Isrc/cubecell build_flags = ${arduino_base.build_flags} -DARDUINO=100 -Isrc/cubecell
src_filter = src_filter =
${env.src_filter} -<esp32/> -<nrf52/> ${arduino_base.src_filter} -<esp32/> -<nrf52/>
; Common settings for NRF52 based targets ; Common settings for NRF52 based targets
[nrf52_base] [nrf52_base]
; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files ; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files
; platform = nordicnrf52 ; platform = nordicnrf52
platform = https://github.com/meshtastic/platform-nordicnrf52.git#1a2639a6b0f79b5df66bea3e3089f0d5285fdc63 platform = https://github.com/meshtastic/platform-nordicnrf52.git#1a2639a6b0f79b5df66bea3e3089f0d5285fdc63
extends = arduino_base
debug_tool = jlink debug_tool = jlink
build_type = debug ; I'm debugging with ICE a lot now build_type = debug ; I'm debugging with ICE a lot now
; note: liboberon provides the AES256 implementation for NRF52 (though not using the hardware acceleration of the NRF52840 - FIXME) ; note: liboberon provides the AES256 implementation for NRF52 (though not using the hardware acceleration of the NRF52840 - FIXME)
build_flags = build_flags =
${env.build_flags} -Wno-unused-variable ${arduino_base.build_flags} -Wno-unused-variable
-Isrc/nrf52 -Isrc/nrf52
-Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.3 -Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.3
;-DCFG_DEBUG=3 ;-DCFG_DEBUG=3
src_filter = src_filter =
${env.src_filter} -<esp32/> -<nimble/> ${arduino_base.src_filter} -<esp32/> -<nimble/>
lib_ignore = lib_ignore =
BluetoothOTA BluetoothOTA
monitor_port = /dev/ttyACM1 monitor_port = /dev/ttyACM1
@ -212,7 +224,7 @@ monitor_speed = 115200
extends = nrf52_base extends = nrf52_base
board = ppr board = ppr
lib_deps = lib_deps =
${env.lib_deps} ${arduino_base.lib_deps}
UC1701 UC1701
; The https://github.com/BigCorvus/SX1262-LoRa-BLE-Relay board by @BigCorvus ; The https://github.com/BigCorvus/SX1262-LoRa-BLE-Relay board by @BigCorvus
@ -233,11 +245,15 @@ build_flags = ${nrf52_base.build_flags} -Ivariants/lora_relay_v1
-DSPI_FREQUENCY=27000000 -DSPI_FREQUENCY=27000000
src_filter = ${nrf52_base.src_filter} +<../variants/lora_relay_v1> src_filter = ${nrf52_base.src_filter} +<../variants/lora_relay_v1>
lib_deps = lib_deps =
${env.lib_deps} ${arduino_base.lib_deps}
SparkFun BQ27441 LiPo Fuel Gauge Arduino Library SparkFun BQ27441 LiPo Fuel Gauge Arduino Library
TFT_eSPI TFT_eSPI
# Adafruit ST7735 and ST7789 Library # Adafruit ST7735 and ST7789 Library
; The Portduino based sim environment on top of linux
[env:linux]
platform = https://github.com/geeksville/platform-portduino.git
src_filter = ${env.src_filter} -<esp32/> -<nimble/> -<nrf52/>
build_flags = ${arduino_base.build_flags} -O0
framework = arduino
board = linux_x86_64

Wyświetl plik

@ -8,7 +8,6 @@
#include "graphics/Screen.h" #include "graphics/Screen.h"
#include "sleep.h" #include "sleep.h"
#include "target_specific.h" #include "target_specific.h"
#include "timing.h"
static void sdsEnter() static void sdsEnter()
{ {
@ -16,7 +15,7 @@ static void sdsEnter()
// Don't deepsleep if we have USB power or if the user as pressed a button recently // Don't deepsleep if we have USB power or if the user as pressed a button recently
// !isUSBPowered <- doesn't work yet because the axp192 isn't letting the battery fully charge when we are awake - FIXME // !isUSBPowered <- doesn't work yet because the axp192 isn't letting the battery fully charge when we are awake - FIXME
if (timing::millis() - lastPressMs > radioConfig.preferences.mesh_sds_timeout_secs) if (millis() - lastPressMs > radioConfig.preferences.mesh_sds_timeout_secs)
{ {
doDeepSleep(radioConfig.preferences.sds_secs); doDeepSleep(radioConfig.preferences.sds_secs);
} }
@ -131,7 +130,7 @@ static void onEnter()
static uint32_t lastPingMs; static uint32_t lastPingMs;
uint32_t now = timing::millis(); uint32_t now = millis();
if (now - lastPingMs > 30 * 1000) { // if more than a minute since our last press, ask other nodes to update their state if (now - lastPingMs > 30 * 1000) { // if more than a minute since our last press, ask other nodes to update their state
if (displayedNodeNum) if (displayedNodeNum)

Wyświetl plik

@ -0,0 +1,44 @@
#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;
/**
* Notify from an ISR
*
* This must be inline or IRAM_ATTR on ESP32
*/
virtual void notifyFromISR(BaseType_t *highPriWoken, uint32_t v = 0, eNotifyAction action = eNoAction) { notify(v, action); }
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

Wyświetl plik

@ -0,0 +1,12 @@
#include "Thread.h"
#include <assert.h>
namespace concurrency
{
void BaseThread::callRun(void *_this)
{
((BaseThread *)_this)->doRun();
}
} // namespace concurrency

Wyświetl plik

@ -0,0 +1,47 @@
#pragma once
#include <cstdlib>
#include <stdint.h>
#include "freertosinc.h"
namespace concurrency
{
/**
* @brief Base threading
*/
class BaseThread
{
protected:
/**
* set this to true to ask thread to cleanly exit asap
*/
volatile bool wantExit = false;
public:
virtual void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY) = 0;
virtual ~BaseThread() {}
// uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
/**
* All thread run methods must periodically call serviceWatchdog, or the system will declare them hung and panic.
*
* this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog()
*/
virtual void serviceWatchdog() {}
virtual void startWatchdog() {}
virtual void stopWatchdog() {}
static void callRun(void *_this);
};
} // namespace concurrency

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -1,5 +1,7 @@
#include "Thread.h" #include "FreeRtosThread.h"
#include "timing.h"
#ifdef HAS_FREE_RTOS
#include <assert.h> #include <assert.h>
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
@ -9,25 +11,20 @@
namespace concurrency namespace concurrency
{ {
void Thread::start(const char *name, size_t stackSize, uint32_t priority) void FreeRtosThread::start(const char *name, size_t stackSize, uint32_t priority)
{ {
auto r = xTaskCreate(callRun, name, stackSize, this, priority, &taskHandle); auto r = xTaskCreate(callRun, name, stackSize, this, priority, &taskHandle);
assert(r == pdPASS); assert(r == pdPASS);
} }
void Thread::callRun(void *_this) void FreeRtosThread::serviceWatchdog()
{
((Thread *)_this)->doRun();
}
void Thread::serviceWatchdog()
{ {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
esp_task_wdt_reset(); esp_task_wdt_reset();
#endif #endif
} }
void Thread::startWatchdog() void FreeRtosThread::startWatchdog()
{ {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
auto r = esp_task_wdt_add(taskHandle); auto r = esp_task_wdt_add(taskHandle);
@ -35,7 +32,7 @@ void Thread::startWatchdog()
#endif #endif
} }
void Thread::stopWatchdog() void FreeRtosThread::stopWatchdog()
{ {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
auto r = esp_task_wdt_delete(taskHandle); auto r = esp_task_wdt_delete(taskHandle);
@ -44,3 +41,5 @@ void Thread::stopWatchdog()
} }
} // namespace concurrency } // namespace concurrency
#endif

Wyświetl plik

@ -0,0 +1,44 @@
#pragma once
#include "BaseThread.h"
#include "freertosinc.h"
#ifdef HAS_FREE_RTOS
namespace concurrency
{
/**
* @brief Base threading
*/
class FreeRtosThread : public BaseThread
{
protected:
TaskHandle_t taskHandle = NULL;
public:
void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY);
virtual ~FreeRtosThread() { vTaskDelete(taskHandle); }
// uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
/**
* All thread run methods must periodically call serviceWatchdog, or the system will declare them hung and panic.
*
* this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog()
*/
void serviceWatchdog();
void startWatchdog();
void stopWatchdog();
};
} // namespace concurrency
#endif

Wyświetl plik

@ -1,8 +1,10 @@
#include "Lock.h" #include "Lock.h"
#include <cassert> #include <cassert>
namespace concurrency { namespace concurrency
{
#ifdef HAS_FREE_RTOS
Lock::Lock() Lock::Lock()
{ {
handle = xSemaphoreCreateBinary(); handle = xSemaphoreCreateBinary();
@ -19,5 +21,12 @@ void Lock::unlock()
{ {
assert(xSemaphoreGive(handle)); assert(xSemaphoreGive(handle));
} }
#else
Lock::Lock() {}
void Lock::lock() {}
void Lock::unlock() {}
#endif
} // namespace concurrency } // namespace concurrency

Wyświetl plik

@ -2,7 +2,8 @@
#include "../freertosinc.h" #include "../freertosinc.h"
namespace concurrency { namespace concurrency
{
/** /**
* @brief Simple wrapper around FreeRTOS API for implementing a mutex lock * @brief Simple wrapper around FreeRTOS API for implementing a mutex lock
@ -26,8 +27,9 @@ class Lock
void unlock(); void unlock();
private: private:
#ifdef HAS_FREE_RTOS
SemaphoreHandle_t handle; SemaphoreHandle_t handle;
#endif
}; };
} // namespace concurrency } // namespace concurrency

Wyświetl plik

@ -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

Wyświetl plik

@ -1,7 +1,6 @@
#include "PeriodicScheduler.h" #include "PeriodicScheduler.h"
#include "PeriodicTask.h" #include "PeriodicTask.h"
#include "LockGuard.h" #include "LockGuard.h"
#include "../timing.h"
namespace concurrency { namespace concurrency {
@ -10,7 +9,7 @@ void PeriodicScheduler::loop()
{ {
LockGuard lg(&lock); LockGuard lg(&lock);
uint32_t now = timing::millis(); uint32_t now = millis();
for (auto t : tasks) { for (auto t : tasks) {
if (t->period && (now - t->lastMsec) >= t->period) { if (t->period && (now - t->lastMsec) >= t->period) {

Wyświetl plik

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <Arduino.h>
#include "PeriodicScheduler.h" #include "PeriodicScheduler.h"
#include "timing.h"
namespace concurrency { namespace concurrency {
@ -38,7 +38,7 @@ class PeriodicTask
*/ */
void setPeriod(uint32_t p) void setPeriod(uint32_t p)
{ {
lastMsec = timing::millis(); // reset starting from now lastMsec = millis(); // reset starting from now
period = p; period = p;
} }

Wyświetl plik

@ -0,0 +1,19 @@
#include "PosixNotifiedWorkerThread.h"
#ifdef __unix__
#include <Utility.h>
using namespace concurrency;
/**
* Notify this thread so it can run
*/
void PosixNotifiedWorkerThread::notify(uint32_t v, eNotifyAction action) NOT_IMPLEMENTED("notify");
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
void PosixNotifiedWorkerThread::block() NOT_IMPLEMENTED("block");
#endif

Wyświetl plik

@ -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

Wyświetl plik

@ -0,0 +1,33 @@
#pragma once
#include "BaseThread.h"
#ifdef __unix__
namespace concurrency
{
/**
* @brief Base threading
*/
class PosixThread : public BaseThread
{
protected:
public:
void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY) {}
virtual ~PosixThread() {}
// uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
};
} // namespace concurrency
#endif

Wyświetl plik

@ -1,47 +1,17 @@
#pragma once #pragma once
#include "freertosinc.h" #include "FreeRtosThread.h"
#include "PosixThread.h"
namespace concurrency { namespace concurrency
/**
* @brief Base threading
*/
class Thread
{ {
protected:
TaskHandle_t taskHandle = NULL;
/** #ifdef HAS_FREE_RTOS
* set this to true to ask thread to cleanly exit asap typedef FreeRtosThread Thread;
*/ #endif
volatile bool wantExit = false;
public:
void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY);
virtual ~Thread() { vTaskDelete(taskHandle); }
uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
/**
* All thread run methods must periodically call serviceWatchdog, or the system will declare them hung and panic.
*
* this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog()
*/
void serviceWatchdog();
void startWatchdog();
void stopWatchdog();
private:
static void callRun(void *_this);
};
#ifdef __unix__
typedef PosixThread Thread;
#endif
} // namespace concurrency } // namespace concurrency

Wyświetl plik

@ -1,5 +1,4 @@
#include "WorkerThread.h" #include "WorkerThread.h"
#include "timing.h"
namespace concurrency { namespace concurrency {
@ -17,8 +16,8 @@ void WorkerThread::doRun()
#ifdef DEBUG_STACK #ifdef DEBUG_STACK
static uint32_t lastPrint = 0; static uint32_t lastPrint = 0;
if (timing::millis() - lastPrint > 10 * 1000L) { if (millis() - lastPrint > 10 * 1000L) {
lastPrint = timing::millis(); lastPrint = millis();
meshtastic::printThreadInfo("net"); meshtastic::printThreadInfo("net");
} }
#endif #endif

Wyświetl plik

@ -55,24 +55,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/// Convert a preprocessor name into a quoted string and if that string is empty use "unset" /// Convert a preprocessor name into a quoted string and if that string is empty use "unset"
#define optstr(s) (xstr(s)[0] ? xstr(s) : "unset") #define optstr(s) (xstr(s)[0] ? xstr(s) : "unset")
#ifdef NRF52_SERIES // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be #ifdef PORTDUINO
// board specific
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
#elif defined(NRF52_SERIES) // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be
// board specific
// //
// Standard definitions for NRF52 targets // Standard definitions for NRF52 targets
// //
// Nop definition for these attributes - not used on NRF52
#define EXT_RAM_ATTR
#define IRAM_ATTR
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth) #define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
// We bind to the GPS using variant.h instead for this platform (Serial1) // We bind to the GPS using variant.h instead for this platform (Serial1)
// FIXME, not yet ready for NRF52
#define RTC_DATA_ATTR
#define LED_PIN PIN_LED1 // LED1 on nrf52840-DK #define LED_PIN PIN_LED1 // LED1 on nrf52840-DK
// If the variant filed defines as standard button // If the variant filed defines as standard button
@ -89,9 +86,6 @@ 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)
// FIXME, not yet ready for NRF52
#define RTC_DATA_ATTR
#define LED_PIN -1 // FIXME totally bogus #define LED_PIN -1 // FIXME totally bogus
#define BUTTON_PIN -1 #define BUTTON_PIN -1
@ -123,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
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -195,8 +200,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define BUTTON_PIN 39 #define BUTTON_PIN 39
#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage
#define USE_RF95
#define USE_RF95 #define USE_RF95
#define LORA_DIO0 26 // a No connect on the SX1262 module #define LORA_DIO0 26 // a No connect on the SX1262 module
#define LORA_RESET 23 #define LORA_RESET 23
@ -338,6 +341,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define HW_VENDOR "nrf52unknown" // FIXME - unknown nrf52 board #define HW_VENDOR "nrf52unknown" // FIXME - unknown nrf52 board
#elif PORTDUINO
#define HW_VENDOR "portduino"
#define USE_SIM_RADIO
#define USE_RF95
#define LORA_DIO0 26 // a No connect on the SX1262 module
#define LORA_RESET 23
#define LORA_DIO1 33 // Not really used
#define LORA_DIO2 32 // Not really used
// Fake SPI device selections
#define RF95_SCK 5
#define RF95_MISO 19
#define RF95_MOSI 27
#define RF95_NSS 18
#endif #endif
#ifdef USE_RF95 #ifdef USE_RF95

Wyświetl plik

@ -1,7 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "../concurrency/LockGuard.h" #include "../concurrency/LockGuard.h"
#include "../timing.h"
#include "BluetoothSoftwareUpdate.h" #include "BluetoothSoftwareUpdate.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "RadioLibInterface.h" #include "RadioLibInterface.h"
@ -102,7 +101,7 @@ int update_crc32_callback(uint16_t conn_handle, uint16_t attr_handle, struct ble
} else { } else {
if (Update.end()) { if (Update.end()) {
DEBUG_MSG("OTA done, rebooting in 5 seconds!\n"); DEBUG_MSG("OTA done, rebooting in 5 seconds!\n");
rebootAtMsec = timing::millis() + 5000; rebootAtMsec = millis() + 5000;
} else { } else {
DEBUG_MSG("Error Occurred. Error #: %d\n", Update.getError()); DEBUG_MSG("Error Occurred. Error #: %d\n", Update.getError());
} }
@ -128,7 +127,7 @@ int update_result_callback(uint16_t conn_handle, uint16_t attr_handle, struct bl
void bluetoothRebootCheck() void bluetoothRebootCheck()
{ {
if (rebootAtMsec && timing::millis() > rebootAtMsec) { if (rebootAtMsec && millis() > rebootAtMsec) {
DEBUG_MSG("Rebooting for update\n"); DEBUG_MSG("Rebooting for update\n");
ESP.restart(); ESP.restart();
} }

Wyświetl plik

@ -3,22 +3,32 @@
// The FreeRTOS includes are in a different directory on ESP32 and I can't figure out how to make that work with platformio gcc // The FreeRTOS includes are in a different directory on ESP32 and I can't figure out how to make that work with platformio gcc
// options so this is my quick hack to make things work // options so this is my quick hack to make things work
#ifdef ARDUINO_ARCH_ESP32 #if defined(ARDUINO_ARCH_ESP32)
#define HAS_FREE_RTOS #define HAS_FREE_RTOS
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/queue.h> #include <freertos/queue.h>
#include <freertos/semphr.h> #include <freertos/semphr.h>
#include <freertos/task.h> #include <freertos/task.h>
#else #endif
// not yet supported on cubecell
#ifndef CubeCell_BoardPlus #if defined(ARDUINO_NRF52_ADAFRUIT)
#define HAS_FREE_RTOS #define HAS_FREE_RTOS
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <queue.h> #include <queue.h>
#include <semphr.h> #include <semphr.h>
#include <task.h> #include <task.h>
#endif
#ifdef HAS_FREE_RTOS
// Include real FreeRTOS defs above
#else #else
// Include placeholder fake FreeRTOS defs
#include <Arduino.h> #include <Arduino.h>
typedef uint32_t TickType_t; typedef uint32_t TickType_t;
@ -26,5 +36,12 @@ typedef uint32_t BaseType_t;
#define portMAX_DELAY UINT32_MAX #define portMAX_DELAY UINT32_MAX
#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, eSetValueWithoutOverwrite, eSetValueWithOverwrite };
#endif #endif
#endif

Wyświetl plik

@ -1,7 +1,6 @@
#include "GPS.h" #include "GPS.h"
#include "configuration.h" #include "configuration.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
@ -36,7 +35,7 @@ void readFromRTC()
struct timeval tv; /* btw settimeofday() is helpfull here too*/ struct timeval tv; /* btw settimeofday() is helpfull here too*/
if (!gettimeofday(&tv, NULL)) { if (!gettimeofday(&tv, NULL)) {
uint32_t now = timing::millis(); uint32_t now = millis();
DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS); DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS);
timeStartMsec = now; timeStartMsec = now;
@ -79,7 +78,7 @@ void perhapsSetRTC(struct tm &t)
uint32_t getTime() uint32_t getTime()
{ {
return ((timing::millis() - timeStartMsec) / 1000) + zeroOffsetSecs; return ((millis() - timeStartMsec) / 1000) + zeroOffsetSecs;
} }
uint32_t getValidTime() uint32_t getValidTime()

Wyświetl plik

@ -1,6 +1,5 @@
#include "NMEAGPS.h" #include "NMEAGPS.h"
#include "configuration.h" #include "configuration.h"
#include "timing.h"
static int32_t toDegInt(RawDegrees d) static int32_t toDegInt(RawDegrees d)
{ {
@ -19,7 +18,7 @@ void NMEAGPS::loop()
reader.encode(c); reader.encode(c);
} }
uint32_t now = timing::millis(); uint32_t now = millis();
if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume
// serial chars at whatever rate) // serial chars at whatever rate)
lastUpdateMsec = now; lastUpdateMsec = now;

Wyświetl plik

@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graphics/images.h" #include "graphics/images.h"
#include "main.h" #include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "target_specific.h"
#include "utils.h" #include "utils.h"
using namespace meshtastic; /** @todo remove */ using namespace meshtastic; /** @todo remove */

Wyświetl plik

@ -38,7 +38,7 @@
#include "graphics/Screen.h" #include "graphics/Screen.h"
#include "main.h" #include "main.h"
#include "sleep.h" #include "sleep.h"
#include "timing.h" #include "target_specific.h"
#include <OneButton.h> #include <OneButton.h>
#include <Wire.h> #include <Wire.h>
// #include <driver/rtc_io.h> // #include <driver/rtc_io.h>
@ -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
@ -268,7 +268,10 @@ void setup()
gps = new NMEAGPS(); gps = new NMEAGPS();
gps->setup(); gps->setup();
#endif #endif
gpsStatus->observe(&gps->newStatus); if (gps)
gpsStatus->observe(&gps->newStatus);
else
DEBUG_MSG("Warning: No GPS found - running without GPS\n");
nodeStatus->observe(&nodeDB.newStatus); nodeStatus->observe(&nodeDB.newStatus);
service.init(); service.init();
@ -362,7 +365,8 @@ void loop()
{ {
uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop? uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop?
gps->loop(); // FIXME, remove from main, instead block on read if (gps)
gps->loop(); // FIXME, remove from main, instead block on read
router.loop(); router.loop();
powerFSM.run_machine(); powerFSM.run_machine();
service.loop(); service.loop();
@ -392,15 +396,15 @@ void loop()
// Show boot screen for first 3 seconds, then switch to normal operation. // Show boot screen for first 3 seconds, then switch to normal operation.
static bool showingBootScreen = true; static bool showingBootScreen = true;
if (showingBootScreen && (timing::millis() > 3000)) { if (showingBootScreen && (millis() > 3000)) {
screen.stopBootScreen(); screen.stopBootScreen();
showingBootScreen = false; showingBootScreen = false;
} }
#ifdef DEBUG_STACK #ifdef DEBUG_STACK
static uint32_t lastPrint = 0; static uint32_t lastPrint = 0;
if (timing::millis() - lastPrint > 10 * 1000L) { if (millis() - lastPrint > 10 * 1000L) {
lastPrint = timing::millis(); lastPrint = millis();
meshtastic::printThreadInfo("main"); meshtastic::printThreadInfo("main");
} }
#endif #endif

Wyświetl plik

@ -21,6 +21,6 @@ extern graphics::Screen screen;
// Return a human readable string of the form "Meshtastic_ab13" // Return a human readable string of the form "Meshtastic_ab13"
const char *getDeviceName(); const char *getDeviceName();
void getMacAddr(uint8_t *dmac);
void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop();

Wyświetl plik

@ -13,7 +13,6 @@
#include "main.h" #include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "power.h" #include "power.h"
#include "timing.h"
/* /*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone. receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
@ -68,8 +67,8 @@ void MeshService::init()
sendOwnerPeriod.setup(); sendOwnerPeriod.setup();
nodeDB.init(); nodeDB.init();
assert(gps); if (gps)
gpsObserver.observe(&gps->newStatus); gpsObserver.observe(&gps->newStatus);
packetReceivedObserver.observe(&router.notifyPacketReceived); packetReceivedObserver.observe(&router.notifyPacketReceived);
} }
@ -316,7 +315,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused)
// We limit our GPS broadcasts to a max rate // We limit our GPS broadcasts to a max rate
static uint32_t lastGpsSend; static uint32_t lastGpsSend;
uint32_t now = timing::millis(); uint32_t now = millis();
if (lastGpsSend == 0 || now - lastGpsSend > radioConfig.preferences.position_broadcast_secs * 1000) { if (lastGpsSend == 0 || now - lastGpsSend > radioConfig.preferences.position_broadcast_secs * 1000) {
lastGpsSend = now; lastGpsSend = now;
DEBUG_MSG("Sending position to mesh\n"); DEBUG_MSG("Sending position to mesh\n");

Wyświetl plik

@ -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() 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

Wyświetl plik

@ -1,7 +1,6 @@
#include "PacketHistory.h" #include "PacketHistory.h"
#include "configuration.h" #include "configuration.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "../timing.h"
PacketHistory::PacketHistory() PacketHistory::PacketHistory()
{ {
@ -19,7 +18,7 @@ bool PacketHistory::wasSeenRecently(const MeshPacket *p, bool withUpdate)
return false; // Not a floodable message ID, so we don't care return false; // Not a floodable message ID, so we don't care
} }
uint32_t now = timing::millis(); uint32_t now = millis();
for (size_t i = 0; i < recentPackets.size();) { for (size_t i = 0; i < recentPackets.size();) {
PacketRecord &r = recentPackets[i]; PacketRecord &r = recentPackets[i];

Wyświetl plik

@ -4,7 +4,6 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "RadioInterface.h" #include "RadioInterface.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
PhoneAPI::PhoneAPI() PhoneAPI::PhoneAPI()
@ -21,7 +20,7 @@ void PhoneAPI::init()
void PhoneAPI::checkConnectionTimeout() void PhoneAPI::checkConnectionTimeout()
{ {
if (isConnected) { if (isConnected) {
bool newConnected = (timing::millis() - lastContactMsec < radioConfig.preferences.phone_timeout_secs * 1000L); bool newConnected = (millis() - lastContactMsec < radioConfig.preferences.phone_timeout_secs * 1000L);
if (!newConnected) { if (!newConnected) {
isConnected = false; isConnected = false;
onConnectionChanged(isConnected); onConnectionChanged(isConnected);
@ -35,7 +34,7 @@ void PhoneAPI::checkConnectionTimeout()
void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength)
{ {
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); // As long as the phone keeps talking to us, don't let the radio go to sleep powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); // As long as the phone keeps talking to us, don't let the radio go to sleep
lastContactMsec = timing::millis(); lastContactMsec = millis();
if (!isConnected) { if (!isConnected) {
isConnected = true; isConnected = true;
onConnectionChanged(isConnected); onConnectionChanged(isConnected);

Wyświetl plik

@ -6,7 +6,6 @@
#include "assert.h" #include "assert.h"
#include "configuration.h" #include "configuration.h"
#include "sleep.h" #include "sleep.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
@ -178,7 +177,7 @@ size_t RadioInterface::beginSending(MeshPacket *p)
// DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad()); // DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad());
assert(p->which_payload == MeshPacket_encrypted_tag); // It should have already been encoded by now assert(p->which_payload == MeshPacket_encrypted_tag); // It should have already been encoded by now
lastTxStart = timing::millis(); lastTxStart = millis();
PacketHeader *h = (PacketHeader *)radiobuf; PacketHeader *h = (PacketHeader *)radiobuf;

Wyświetl plik

@ -2,7 +2,6 @@
#include "MeshTypes.h" #include "MeshTypes.h"
#include "configuration.h" #include "configuration.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "timing.h"
// ReliableRouter::ReliableRouter() {} // ReliableRouter::ReliableRouter() {}
@ -163,7 +162,7 @@ PendingPacket *ReliableRouter::startRetransmission(MeshPacket *p)
*/ */
void ReliableRouter::doRetransmissions() void ReliableRouter::doRetransmissions()
{ {
uint32_t now = timing::millis(); uint32_t now = millis();
// FIXME, we should use a better datastructure rather than walking through this map. // FIXME, we should use a better datastructure rather than walking through this map.
// for(auto el: pending) { // for(auto el: pending) {

Wyświetl plik

@ -2,7 +2,6 @@
#include "FloodingRouter.h" #include "FloodingRouter.h"
#include "../concurrency/PeriodicTask.h" #include "../concurrency/PeriodicTask.h"
#include "../timing.h"
#include <unordered_map> #include <unordered_map>
/** /**
@ -49,7 +48,7 @@ struct PendingPacket {
PendingPacket() {} PendingPacket() {}
PendingPacket(MeshPacket *p); PendingPacket(MeshPacket *p);
void setNextTx() { nextTxMsec = timing::millis() + random(20 * 1000L, 22 * 1000L); } void setNextTx() { nextTxMsec = millis() + random(20 * 1000L, 22 * 1000L); }
}; };
class GlobalPacketIdHashFunction class GlobalPacketIdHashFunction

Wyświetl plik

@ -53,7 +53,7 @@ template <class T> class TypedQueue
public: public:
TypedQueue(int maxElements) {} TypedQueue(int maxElements) {}
// int numFree() { return uxQueueSpacesAvailable(h); } int numFree() { return 1; } // Always claim 1 free, because we can grow to any size
bool isEmpty() { return q.empty(); } bool isEmpty() { return q.empty(); }

Wyświetl plik

@ -6,10 +6,10 @@
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
#ifdef NO_ESP32 #ifdef ARDUINO_ARCH_NRF52
#include "Adafruit_LittleFS.h" #include "Adafruit_LittleFS.h"
using namespace Adafruit_LittleFS_Namespace; // To get File type using namespace Adafruit_LittleFS_Namespace; // To get File type
#endif #endif
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic /// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
/// returns the encoded packet size /// returns the encoded packet size
@ -49,7 +49,7 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
return count == 0; return count == 0;
} }
status = (file->read(buf, count) == (int) count); status = (file->read(buf, count) == (int)count);
if (file->available() == 0) if (file->available() == 0)
stream->bytes_left = 0; stream->bytes_left = 0;

Wyświetl plik

@ -0,0 +1,32 @@
#include "CryptoEngine.h"
#include "target_specific.h"
#include <Utility.h>
// FIXME - move getMacAddr/setBluetoothEnable into a HALPlatform class
uint32_t hwId; // fixme move into portduino
void getMacAddr(uint8_t *dmac)
{
if (!hwId) {
notImplemented("getMacAddr");
hwId = random();
}
dmac[0] = 0x80;
dmac[1] = 0;
dmac[2] = 0;
dmac[3] = hwId >> 16;
dmac[4] = hwId >> 8;
dmac[5] = hwId & 0xff;
}
void setBluetoothEnable(bool on)
{
notImplemented("setBluetoothEnable");
}
// FIXME - implement real crypto for linux
CryptoEngine *crypto = new CryptoEngine();
void updateBatteryLevel(uint8_t level) NOT_IMPLEMENTED("updateBatteryLevel");

Wyświetl plik

@ -7,7 +7,6 @@
#include "error.h" #include "error.h"
#include "main.h" #include "main.h"
#include "target_specific.h" #include "target_specific.h"
#include "timing.h"
#ifndef NO_ESP32 #ifndef NO_ESP32
#include "esp32/pm.h" #include "esp32/pm.h"
@ -123,11 +122,11 @@ bool doPreflightSleep()
/// Tell devices we are going to sleep and wait for them to handle things /// Tell devices we are going to sleep and wait for them to handle things
static void waitEnterSleep() static void waitEnterSleep()
{ {
uint32_t now = timing::millis(); uint32_t now = millis();
while (!doPreflightSleep()) { while (!doPreflightSleep()) {
delay(100); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives) delay(100); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives)
if (timing::millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep if (millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep
recordCriticalError(ErrSleepEnterWait); recordCriticalError(ErrSleepEnterWait);
assert(0); // FIXME - for now we just restart, need to fix bug #167 assert(0); // FIXME - for now we just restart, need to fix bug #167
break; break;

Wyświetl plik

@ -1,6 +1,10 @@
#pragma once #pragma once
#include <Arduino.h>
// Functions that are unique to particular target types (esp32, bare, nrf52 etc...) // Functions that are unique to particular target types (esp32, bare, nrf52 etc...)
// Enable/disable bluetooth. // Enable/disable bluetooth.
void setBluetoothEnable(bool on); void setBluetoothEnable(bool on);
void getMacAddr(uint8_t *dmac);

Wyświetl plik

@ -1,10 +0,0 @@
#include "timing.h"
#include "freertosinc.h"
namespace timing {
uint32_t millis() {
return xTaskGetTickCount();
}
} // namespace timing

Wyświetl plik

@ -1,9 +0,0 @@
#pragma once
#include <cstdint>
namespace timing {
uint32_t millis();
} // namespace timing