sforkowany z mirror/meshtastic-firmware
Get build (kinda, not really) running on a NRF52
Lots of NO_ESP32 to remove later...1.2-legacy
rodzic
0b62083e35
commit
0a6af936ed
|
@ -12,8 +12,9 @@
|
|||
"type": "platformio-debug",
|
||||
"request": "launch",
|
||||
"name": "PIO Debug",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf",
|
||||
"toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/bare/firmware.elf",
|
||||
"toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-gccarmnoneeabi/bin",
|
||||
"svdPath": "/home/kevinh/.platformio/platforms/nordicnrf52/misc/svd/nrf52840.svd",
|
||||
"preLaunchTask": {
|
||||
"type": "PlatformIO",
|
||||
"task": "Pre-Debug"
|
||||
|
@ -24,8 +25,9 @@
|
|||
"type": "platformio-debug",
|
||||
"request": "launch",
|
||||
"name": "PIO Debug (skip Pre-Debug)",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf",
|
||||
"toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/bare/firmware.elf",
|
||||
"toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-gccarmnoneeabi/bin",
|
||||
"svdPath": "/home/kevinh/.platformio/platforms/nordicnrf52/misc/svd/nrf52840.svd",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -42,7 +42,12 @@
|
|||
"typeinfo": "cpp",
|
||||
"string": "cpp",
|
||||
"*.xbm": "cpp",
|
||||
"list": "cpp"
|
||||
"list": "cpp",
|
||||
"atomic": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"optional": "cpp",
|
||||
"string_view": "cpp",
|
||||
"cassert": "cpp"
|
||||
},
|
||||
"cSpell.words": [
|
||||
"Meshtastic",
|
||||
|
|
|
@ -9,16 +9,12 @@
|
|||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = tbeam
|
||||
default_envs = bare
|
||||
|
||||
[common]
|
||||
; default to a US frequency range, change it as needed for your region and hardware (CN, JP, EU433, EU865)
|
||||
hw_version = US
|
||||
|
||||
; Common settings for ESP targes, mixin with extends = esp32_base
|
||||
[esp32_base]
|
||||
src_filter =
|
||||
${env.src_filter} -<bare/>
|
||||
|
||||
[env]
|
||||
platform = espressif32
|
||||
|
@ -30,7 +26,7 @@ board_build.partitions = partition-table.csv
|
|||
|
||||
; 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
|
||||
build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Isrc/rf95 -Os -Wl,-Map,.pio/build/output.map -DAXP_DEBUG_PORT=Serial -DHW_VERSION_${common.hw_version}
|
||||
build_flags = -Wno-missing-field-initializers -Isrc -Isrc/rf95 -Os -Wl,-Map,.pio/build/output.map -DAXP_DEBUG_PORT=Serial -DHW_VERSION_${common.hw_version}
|
||||
|
||||
; 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
|
||||
|
@ -43,8 +39,6 @@ build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Isrc/rf95 -Os
|
|||
;upload_port = /dev/ttyUSB0
|
||||
;monitor_port = /dev/ttyUSB0
|
||||
|
||||
upload_speed = 921600
|
||||
|
||||
; the default is esptool
|
||||
; upload_protocol = esp-prog
|
||||
|
||||
|
@ -62,8 +56,6 @@ debug_tool = jlink
|
|||
;debug_init_cmds =
|
||||
; monitor adapter_khz 10000
|
||||
|
||||
debug_init_break = tbreak setup
|
||||
|
||||
lib_deps =
|
||||
https://github.com/meshtastic/LoRaLayer2.git
|
||||
https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
|
||||
|
@ -74,6 +66,15 @@ lib_deps =
|
|||
https://github.com/meshtastic/arduino-fsm.git
|
||||
https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git
|
||||
|
||||
; Common settings for ESP targes, mixin with extends = esp32_base
|
||||
[esp32_base]
|
||||
src_filter =
|
||||
${env.src_filter} -<bare/>
|
||||
upload_speed = 921600
|
||||
debug_init_break = tbreak setup
|
||||
build_flags =
|
||||
${env.build_flags} -Wall -Wextra
|
||||
|
||||
; The 1.0 release of the TBEAM board
|
||||
[env:tbeam]
|
||||
extends = esp32_base
|
||||
|
@ -82,14 +83,14 @@ lib_deps =
|
|||
${env.lib_deps}
|
||||
AXP202X_Library
|
||||
build_flags =
|
||||
${env.build_flags} -D TBEAM_V10
|
||||
${esp32_base.build_flags} -D TBEAM_V10
|
||||
|
||||
; The original TBEAM board without the AXP power chip and a few other changes
|
||||
[env:tbeam0.7]
|
||||
extends = esp32_base
|
||||
board = ttgo-t-beam
|
||||
build_flags =
|
||||
${env.build_flags} -D TBEAM_V07
|
||||
${esp32_base.build_flags} -D TBEAM_V07
|
||||
|
||||
[env:heltec]
|
||||
;build_type = debug ; to make it possible to step through our jtag debugger
|
||||
|
@ -100,22 +101,28 @@ board = heltec_wifi_lora_32_V2
|
|||
extends = esp32_base
|
||||
board = ttgo-lora32-v1
|
||||
build_flags =
|
||||
${env.build_flags} -D TTGO_LORA_V1
|
||||
${esp32_base.build_flags} -D TTGO_LORA_V1
|
||||
|
||||
; note: the platformio definition for lora32-v2 seems stale, it is missing a pins_arduino.h file, therefore I don't think it works
|
||||
[env:ttgo-lora32-v2]
|
||||
extends = esp32_base
|
||||
board = ttgo-lora32-v1
|
||||
build_flags =
|
||||
${env.build_flags} -D TTGO_LORA_V2
|
||||
${esp32_base.build_flags} -D TTGO_LORA_V2
|
||||
|
||||
|
||||
; This is a temporary build target to test turning off particular hardare bits in the build (to improve modularity)
|
||||
[env:bare]
|
||||
board = ttgo-lora32-v1
|
||||
platform = nordicnrf52
|
||||
board = nrf52840_dk_adafruit ; nicer than nrf52840_dk - more full gpio mappings
|
||||
framework = arduino
|
||||
debug_tool = jlink
|
||||
build_flags =
|
||||
${env.build_flags} -D BARE_BOARD
|
||||
${env.build_flags} -D BARE_BOARD -Wno-unused-variable -Isrc/bare
|
||||
src_filter =
|
||||
${env.src_filter} -<esp32/>
|
||||
lib_ignore =
|
||||
BluetoothOTA
|
||||
BluetoothOTA
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
monitor_port = /dev/ttyACM1
|
10
src/GPS.cpp
10
src/GPS.cpp
|
@ -2,9 +2,15 @@
|
|||
#include "GPS.h"
|
||||
#include "configuration.h"
|
||||
#include "time.h"
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef GPS_RX_PIN
|
||||
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
|
||||
#else
|
||||
// Assume NRF52
|
||||
// Uart _serial_gps(GPS_SERIAL_NUM);
|
||||
#endif
|
||||
|
||||
bool timeSetFromGPS; // We try to set our time from GPS each time we wake from sleep
|
||||
|
||||
|
@ -97,7 +103,11 @@ void GPS::perhapsSetRTC(const struct timeval *tv)
|
|||
if (!timeSetFromGPS) {
|
||||
timeSetFromGPS = true;
|
||||
DEBUG_MSG("Setting RTC %ld secs\n", tv->tv_sec);
|
||||
#ifndef NO_ESP32
|
||||
settimeofday(tv, NULL);
|
||||
#else
|
||||
assert(0);
|
||||
#endif
|
||||
readFromRTC();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#include "GPS.h"
|
||||
//#include "MeshBluetoothService.h"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#include "MemoryPool.h"
|
||||
#include "MeshRadio.h"
|
||||
|
|
|
@ -30,7 +30,12 @@ DeviceState versions used to be defined in the .proto file but really only this
|
|||
#define DEVICESTATE_CUR_VER 7
|
||||
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
|
||||
|
||||
#ifndef NO_ESP32
|
||||
#define FS SPIFFS
|
||||
#endif
|
||||
|
||||
// FIXME - move this somewhere else
|
||||
extern void getMacAddr(uint8_t *dmac);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -97,7 +102,7 @@ void NodeDB::init()
|
|||
strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model));
|
||||
|
||||
// Init our blank owner info to reasonable defaults
|
||||
esp_efuse_mac_get_default(ourMacAddr);
|
||||
getMacAddr(ourMacAddr);
|
||||
sprintf(owner.id, "!%02x%02x%02x%02x%02x%02x", ourMacAddr[0], ourMacAddr[1], ourMacAddr[2], ourMacAddr[3], ourMacAddr[4],
|
||||
ourMacAddr[5]);
|
||||
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
|
||||
|
@ -116,12 +121,6 @@ void NodeDB::init()
|
|||
info->user = owner;
|
||||
info->has_user = true;
|
||||
|
||||
if (!FS.begin(true)) // FIXME - do this in main?
|
||||
{
|
||||
DEBUG_MSG("ERROR SPIFFS Mount Failed\n");
|
||||
// FIXME - report failure to phone
|
||||
}
|
||||
|
||||
// saveToDisk();
|
||||
loadFromDisk();
|
||||
resetRadioConfig(); // If bogus settings got saved, then fix them
|
||||
|
@ -157,8 +156,15 @@ const char *preftmp = "/db.proto.tmp";
|
|||
|
||||
void NodeDB::loadFromDisk()
|
||||
{
|
||||
#ifdef FS
|
||||
static DeviceState scratch;
|
||||
|
||||
if (!FS.begin(true)) // FIXME - do this in main?
|
||||
{
|
||||
DEBUG_MSG("ERROR SPIFFS Mount Failed\n");
|
||||
// FIXME - report failure to phone
|
||||
}
|
||||
|
||||
File f = FS.open(preffile);
|
||||
if (f) {
|
||||
DEBUG_MSG("Loading saved preferences\n");
|
||||
|
@ -185,10 +191,14 @@ void NodeDB::loadFromDisk()
|
|||
} else {
|
||||
DEBUG_MSG("No saved preferences found\n");
|
||||
}
|
||||
#else
|
||||
DEBUG_MSG("ERROR: Filesystem not implemented\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void NodeDB::saveToDisk()
|
||||
{
|
||||
#ifdef FS
|
||||
File f = FS.open(preftmp, "w");
|
||||
if (f) {
|
||||
DEBUG_MSG("Writing preferences\n");
|
||||
|
@ -213,6 +223,9 @@ void NodeDB::saveToDisk()
|
|||
} else {
|
||||
DEBUG_MSG("ERROR: can't write prefs\n"); // FIXME report to app
|
||||
}
|
||||
#else
|
||||
DEBUG_MSG("ERROR filesystem not implemented\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
const NodeInfo *NodeDB::readNextInfo()
|
||||
|
|
|
@ -38,6 +38,7 @@ static void lsIdle()
|
|||
{
|
||||
DEBUG_MSG("lsIdle begin ls_secs=%u\n", radioConfig.preferences.ls_secs);
|
||||
|
||||
#ifndef NO_ESP32
|
||||
uint32_t secsSlept = 0;
|
||||
esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED;
|
||||
bool reached_ls_secs = false;
|
||||
|
@ -80,6 +81,7 @@ static void lsIdle()
|
|||
powerFSM.trigger(EVENT_WAKE_TIMER);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lsExit()
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
// FIXME - make a FS abstraction for NRF52
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
// FIXME - make a FS abstraction for NRF52
|
|
@ -73,6 +73,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// devices. Comment this out to not rotate screen 180 degrees.
|
||||
#define FLIP_SCREEN_VERTICALLY
|
||||
|
||||
// DEBUG LED
|
||||
|
||||
#define LED_INVERTED 0 // define as 1 if LED is active low (on)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// GPS
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -204,6 +208,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
|
||||
|
||||
// Turn off GPS code for now
|
||||
#undef GPS_RX_PIN
|
||||
#undef GPS_TX_PIN
|
||||
|
||||
// FIXME, not yet ready for NRF52
|
||||
#define RTC_DATA_ATTR
|
||||
|
||||
#define LED_PIN PIN_LED1 // LED1 on nrf52840-DK
|
||||
#define BUTTON_PIN PIN_BUTTON1
|
||||
|
||||
// This board uses 0 to be mean LED on
|
||||
#undef LED_INVERTED
|
||||
#define LED_INVERTED 1
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "freertosinc.h"
|
||||
#include "configuration.h"
|
||||
|
||||
namespace meshtastic
|
||||
|
@ -12,9 +10,11 @@ namespace meshtastic
|
|||
|
||||
void printThreadInfo(const char *extra)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
uint32_t taskHandle = reinterpret_cast<uint32_t>(xTaskGetCurrentTaskHandle());
|
||||
DEBUG_MSG("printThreadInfo(%s) task: %" PRIx32 " core id: %u min free stack: %u\n", extra, taskHandle, xPortGetCoreID(),
|
||||
uxTaskGetStackHighWaterMark(nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace meshtastic
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
// 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
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/queue.h>
|
||||
#else
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <semphr.h>
|
||||
#include <queue.h>
|
||||
#endif
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include "freertosinc.h"
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
|
26
src/main.cpp
26
src/main.cpp
|
@ -29,14 +29,12 @@
|
|||
#include "PowerFSM.h"
|
||||
#include "configuration.h"
|
||||
#include "error.h"
|
||||
#include "esp32/pm.h"
|
||||
#include "esp_pm.h"
|
||||
#include "power.h"
|
||||
#include "rom/rtc.h"
|
||||
// #include "rom/rtc.h"
|
||||
#include "screen.h"
|
||||
#include "sleep.h"
|
||||
#include <Wire.h>
|
||||
#include <driver/rtc_io.h>
|
||||
// #include <driver/rtc_io.h>
|
||||
|
||||
#ifndef NO_ESP32
|
||||
#include "BluetoothUtil.h"
|
||||
|
@ -195,10 +193,24 @@ void axp192Init()
|
|||
#endif
|
||||
}
|
||||
|
||||
void getMacAddr(uint8_t *dmac) {
|
||||
#ifndef NO_ESP32
|
||||
assert(esp_efuse_mac_get_default(dmac) == ESP_OK);
|
||||
#else
|
||||
dmac[0] = 0xde;
|
||||
dmac[1] = 0xad;
|
||||
dmac[2] = 0xbe;
|
||||
dmac[3] = 0xef;
|
||||
dmac[4] = 0x01;
|
||||
dmac[5] = 0x02; // FIXME, macaddr stuff needed for NRF52
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *getDeviceName()
|
||||
{
|
||||
uint8_t dmac[6];
|
||||
assert(esp_efuse_mac_get_default(dmac) == ESP_OK);
|
||||
|
||||
getMacAddr(dmac);
|
||||
|
||||
// Meshtastic_ab3c
|
||||
static char name[20];
|
||||
|
@ -239,15 +251,17 @@ void setup()
|
|||
#endif
|
||||
#ifdef LED_PIN
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, 1); // turn on for now
|
||||
digitalWrite(LED_PIN, 1 ^ LED_INVERTED); // turn on for now
|
||||
#endif
|
||||
|
||||
// Hello
|
||||
DEBUG_MSG("Meshtastic swver=%s, hwver=%s\n", xstr(APP_VERSION), xstr(HW_VERSION));
|
||||
|
||||
#ifndef NO_ESP32
|
||||
// Don't init display if we don't have one or we are waking headless due to a timer event
|
||||
if (wakeCause == ESP_SLEEP_WAKEUP_TIMER)
|
||||
ssd1306_found = false; // forget we even have the hardware
|
||||
#endif
|
||||
|
||||
// Initialize the screen first so we can show the logo while we start up everything else.
|
||||
if (ssd1306_found)
|
||||
|
|
|
@ -35,8 +35,9 @@ bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msg
|
|||
/// Read from an Arduino File
|
||||
bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
|
||||
{
|
||||
bool status = false;
|
||||
#ifndef NO_ESP32
|
||||
File *file = (File *)stream->state;
|
||||
bool status;
|
||||
|
||||
if (buf == NULL) {
|
||||
while (count-- && file->read() != EOF)
|
||||
|
@ -48,14 +49,18 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
|
|||
|
||||
if (file->available() == 0)
|
||||
stream->bytes_left = 0;
|
||||
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
/// Write to an arduino file
|
||||
bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
File *file = (File *)stream->state;
|
||||
// DEBUG_MSG("writing %d bytes to protobuf file\n", count);
|
||||
return file->write(buf, count) == count;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ template <class T> class MemoryPool
|
|||
buf = new T[maxElements];
|
||||
|
||||
// prefill dead
|
||||
for (int i = 0; i < maxElements; i++)
|
||||
for (size_t i = 0; i < maxElements; i++)
|
||||
release(&buf[i]);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ template <class T> class MemoryPool
|
|||
{
|
||||
assert(dead.enqueue(p, 0));
|
||||
assert(p >= buf &&
|
||||
(p - buf) <
|
||||
(size_t) (p - buf) <
|
||||
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ template <class T> class MemoryPool
|
|||
{
|
||||
assert(dead.enqueueFromISR(p, higherPriWoken));
|
||||
assert(p >= buf &&
|
||||
(p - buf) <
|
||||
(size_t) (p - buf) <
|
||||
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* This is port of Dean Camera's ATOMIC_BLOCK macros for AVR to ARM Cortex M3
|
||||
* v1.0
|
||||
* Mark Pendrith, Nov 27, 2012.
|
||||
*
|
||||
* From Mark:
|
||||
* >When I ported the macros I emailed Dean to ask what attribution would be
|
||||
* >appropriate, and here is his response:
|
||||
* >
|
||||
* >>Mark,
|
||||
* >>I think it's great that you've ported the macros; consider them
|
||||
* >>public domain, to do with whatever you wish. I hope you find them >useful .
|
||||
* >>
|
||||
* >>Cheers!
|
||||
* >>- Dean
|
||||
*/
|
||||
|
||||
#ifdef __arm__
|
||||
#ifndef _CORTEX_M3_ATOMIC_H_
|
||||
#define _CORTEX_M3_ATOMIC_H_
|
||||
|
||||
static __inline__ uint32_t __get_primask(void) \
|
||||
{ uint32_t primask = 0; \
|
||||
__asm__ volatile ("MRS %[result], PRIMASK\n\t":[result]"=r"(primask)::); \
|
||||
return primask; } // returns 0 if interrupts enabled, 1 if disabled
|
||||
|
||||
static __inline__ void __set_primask(uint32_t setval) \
|
||||
{ __asm__ volatile ("MSR PRIMASK, %[value]\n\t""dmb\n\t""dsb\n\t""isb\n\t"::[value]"r"(setval):);
|
||||
__asm__ volatile ("" ::: "memory");}
|
||||
|
||||
static __inline__ uint32_t __iSeiRetVal(void) \
|
||||
{ __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); return 1; }
|
||||
|
||||
static __inline__ uint32_t __iCliRetVal(void) \
|
||||
{ __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); return 1; }
|
||||
|
||||
static __inline__ void __iSeiParam(const uint32_t *__s) \
|
||||
{ __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); (void)__s; }
|
||||
|
||||
static __inline__ void __iCliParam(const uint32_t *__s) \
|
||||
{ __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); (void)__s; }
|
||||
|
||||
static __inline__ void __iRestore(const uint32_t *__s) \
|
||||
{ __set_primask(*__s); __asm__ volatile ("dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); }
|
||||
|
||||
|
||||
#define ATOMIC_BLOCK(type) \
|
||||
for ( type, __ToDo = __iCliRetVal(); __ToDo ; __ToDo = 0 )
|
||||
|
||||
#define ATOMIC_RESTORESTATE \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask()
|
||||
|
||||
#define ATOMIC_FORCEON \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iSeiParam))) = 0
|
||||
|
||||
#define NONATOMIC_BLOCK(type) \
|
||||
for ( type, __ToDo = __iSeiRetVal(); __ToDo ; __ToDo = 0 )
|
||||
|
||||
#define NONATOMIC_RESTORESTATE \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask()
|
||||
|
||||
#define NONATOMIC_FORCEOFF \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iCliParam))) = 0
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -3,8 +3,7 @@
|
|||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/queue.h>
|
||||
#include "freertosinc.h"
|
||||
|
||||
/**
|
||||
* A wrapper for freertos queues. Note: each element object should be small
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "TypedQueue.h"
|
||||
#include "lock.h"
|
||||
#include "power.h"
|
||||
#include <string>
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
|
|
@ -6,16 +6,20 @@
|
|||
#include "Periodic.h"
|
||||
#include "configuration.h"
|
||||
#include "error.h"
|
||||
#include "esp32/pm.h"
|
||||
#include "esp_pm.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "rom/rtc.h"
|
||||
#include "target_specific.h"
|
||||
#include <Wire.h>
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
#ifndef NO_ESP32
|
||||
#include "rom/rtc.h"
|
||||
#include "esp32/pm.h"
|
||||
#include "esp_pm.h"
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
#include "BluetoothUtil.h"
|
||||
|
||||
esp_sleep_source_t wakeCause; // the reason we booted this time
|
||||
#endif
|
||||
|
||||
#ifdef TBEAM_V10
|
||||
|
@ -31,7 +35,6 @@ Observable<void *> notifySleep, notifyDeepSleep;
|
|||
|
||||
// deep sleep support
|
||||
RTC_DATA_ATTR int bootCount = 0;
|
||||
esp_sleep_source_t wakeCause; // the reason we booted this time
|
||||
|
||||
#define xstr(s) str(s)
|
||||
#define str(s) #s
|
||||
|
@ -48,14 +51,16 @@ esp_sleep_source_t wakeCause; // the reason we booted this time
|
|||
*/
|
||||
void setCPUFast(bool on)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
setCpuFrequencyMhz(on ? 240 : 80);
|
||||
#endif
|
||||
}
|
||||
|
||||
void setLed(bool ledOn)
|
||||
{
|
||||
#ifdef LED_PIN
|
||||
// toggle the led so we can get some rough sense of how often loop is pausing
|
||||
digitalWrite(LED_PIN, ledOn);
|
||||
digitalWrite(LED_PIN, ledOn ^ LED_INVERTED);
|
||||
#endif
|
||||
|
||||
#ifdef TBEAM_V10
|
||||
|
@ -79,6 +84,7 @@ void setGPSPower(bool on)
|
|||
// Perform power on init that we do on each wake from deep sleep
|
||||
void initDeepSleep()
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
bootCount++;
|
||||
wakeCause = esp_sleep_get_wakeup_cause();
|
||||
/*
|
||||
|
@ -106,6 +112,7 @@ void initDeepSleep()
|
|||
reason = "timeout";
|
||||
|
||||
DEBUG_MSG("booted, wake cause %d (boot count %d), reset_reason=%s\n", wakeCause, bootCount, reason);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// return true if sleep is allowed
|
||||
|
@ -148,6 +155,7 @@ void doDeepSleep(uint64_t msecToWake)
|
|||
{
|
||||
DEBUG_MSG("Entering deep sleep for %llu seconds\n", msecToWake / 1000);
|
||||
|
||||
#ifndef NO_ESP32
|
||||
// not using wifi yet, but once we are this is needed to shutoff the radio hw
|
||||
// esp_wifi_stop();
|
||||
waitEnterSleep();
|
||||
|
@ -232,8 +240,10 @@ void doDeepSleep(uint64_t msecToWake)
|
|||
|
||||
esp_sleep_enable_timer_wakeup(msecToWake * 1000ULL); // call expects usecs
|
||||
esp_deep_sleep_start(); // TBD mA sleep current (battery)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef NO_ESP32
|
||||
/**
|
||||
* enter light sleep (preserves ram but stops everything about CPU).
|
||||
*
|
||||
|
@ -274,6 +284,7 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
|
|||
// digitalRead(PMU_IRQ));
|
||||
return esp_sleep_get_wakeup_cause();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// not legal on the stock android ESP build
|
||||
|
|
|
@ -2,10 +2,15 @@
|
|||
|
||||
#include "Arduino.h"
|
||||
#include "Observer.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "configuration.h"
|
||||
|
||||
void doDeepSleep(uint64_t msecToWake);
|
||||
#ifndef NO_ESP32
|
||||
#include "esp_sleep.h"
|
||||
esp_sleep_wakeup_cause_t doLightSleep(uint64_t msecToWake);
|
||||
|
||||
extern esp_sleep_source_t wakeCause;
|
||||
#endif
|
||||
void setGPSPower(bool on);
|
||||
|
||||
// Perform power on init that we do on each wake from deep sleep
|
||||
|
@ -15,7 +20,6 @@ void setCPUFast(bool on);
|
|||
void setLed(bool ledOn);
|
||||
|
||||
extern int bootCount;
|
||||
extern esp_sleep_source_t wakeCause;
|
||||
|
||||
// is bluetooth sw currently running?
|
||||
extern bool bluetoothOn;
|
||||
|
|
Ładowanie…
Reference in New Issue