Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f33bf01
Turn off vscode cmake prompt - we don't use cmake on meshtastic
geeksville Jun 16, 2024
ce2047a
Add rak4631_dap variant for debugging with NanoDAP debug probe device.
geeksville Jun 16, 2024
22212b2
The rak device can also run freertos (which is underneath nrf52 arduino)
geeksville Jun 17, 2024
8d65e03
Add semihosting support for nrf52840 devices
geeksville Jun 17, 2024
03033ec
Merge remote-tracking branch 'root/master' into dev
geeksville Jun 18, 2024
f435851
powermon WIP (for https://github.com/meshtastic/firmware/issues/4136 )
geeksville Jun 18, 2024
8c46a7e
oops - mean't to mark the _dbg variant as an 'extra' board.
geeksville Jun 20, 2024
a8c265a
Merge remote-tracking branch 'root/master' into dev
geeksville Jun 20, 2024
dc5c5bf
powermon wip
geeksville Jun 20, 2024
2705fe6
Merge branch 'dev' into powermon
geeksville Jun 20, 2024
f872cf1
Make serial port on wio-sdk-wm1110 board work
geeksville Jun 20, 2024
33a929c
Instrument (radiolib only for now) lora for powermon
geeksville Jun 20, 2024
809e06b
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 21, 2024
b2a388b
powermon gps support
geeksville Jun 21, 2024
febe747
Add CPU deep and light sleep powermon states
geeksville Jun 21, 2024
c830942
Change the board/swversion bootstring so it is a new "structured" log…
geeksville Jun 21, 2024
c328e6a
powermon wip
geeksville Jun 21, 2024
0acfeae
add example script for getting esp S3 debugging working
geeksville Jun 21, 2024
039de45
Add PowerMon reporting for screen and bluetooth pwr.
geeksville Jun 21, 2024
c05f2e3
make power.powermon_enables config setting work.
geeksville Jun 21, 2024
948bc4b
update to latest protobufs
geeksville Jun 23, 2024
c67a9df
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 23, 2024
1eff321
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 25, 2024
232e9d9
fix bogus shellcheck warning
geeksville Jun 27, 2024
76c9fb3
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 27, 2024
d266484
make powermon optional (but default enabled because tiny and no runti…
geeksville Jun 27, 2024
6c753ce
tell vscode, if formatting, use whatever our trunk formatter wants
geeksville Jun 27, 2024
6929a14
Merge branch 'pr-trunkish' into powermon
geeksville Jun 27, 2024
669afac
add PowerStress module
geeksville Jun 27, 2024
b0de20f
nrf52 arduino is built upon freertos, so let platformio debug it
geeksville Jun 27, 2024
1382ac6
don't accidentally try to Segger ICE if we are using another ICE
geeksville Jun 27, 2024
1d65dae
clean up RedirectablePrint::log so it doesn't have three very differe…
geeksville Jun 27, 2024
5464310
remove NoopPrint - it is no longer needed
geeksville Jun 27, 2024
a94a5e6
when talking to API clients via serial, don't turn off log msgs inste…
geeksville Jun 27, 2024
c0482f5
fix the build - would loop forever if there were no files to send
geeksville Jun 28, 2024
5fd18a0
Merge branch 'master' into pr-fixbuild
geeksville Jun 28, 2024
c8a4b99
Merge branch 'pr-fixbuild' into pr-protolog
geeksville Jun 28, 2024
4301544
don't use Segger code if not talking to a Segger debugger
geeksville Jun 28, 2024
b69956e
when encapsulating logs, make sure the strings always has nul termina…
geeksville Jun 28, 2024
ca53564
nrf52 soft device will watchdog if you use ICE while BT on...
geeksville Jun 28, 2024
359fe6a
Merge branch 'pr-fixdebug2' into pr-protolog
geeksville Jun 28, 2024
f37bed4
Important to not print debug messages while writing to the toPhone sc…
geeksville Jun 28, 2024
d5bcfc6
don't include newlines if encapsulating log records as protobufs
geeksville Jun 28, 2024
fcb7f13
Merge remote-tracking branch 'root/master' into pr-protolog
geeksville Jun 28, 2024
a5a2a7d
Merge branch 'pr-protolog' into powermon
geeksville Jun 28, 2024
d885d59
update to latest protobufs (needed for powermon goo)
geeksville Jun 28, 2024
baa258c
PowerStress WIP
geeksville Jun 30, 2024
95885a1
Merge remote-tracking branch 'root/master' into pr-protolog
geeksville Jun 30, 2024
7cd3c0c
Merge branch 'pr-protolog' into powermon
geeksville Jun 30, 2024
25ebf4c
Merge remote-tracking branch 'root/master' into powermon
geeksville Jul 3, 2024
c0a7796
fix linter warning
geeksville Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bin/setup-python-for-esp-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# shellcheck shell=bash
# (this minor script is actually shell agnostic, and is intended to be sourced rather than run in a subshell)

# This is a little script you can source if you want to make ESP debugging work on a modern (24.04) ubuntu machine
# It assumes you have built and installed python 2.7 from source with:
# ./configure --enable-optimizations --enable-shared --enable-unicode=ucs4
# sudo make clean
# make
# sudo make altinstall

export LD_LIBRARY_PATH=$HOME/packages/python-2.7.18/
export PYTHON_HOME=/usr/local/lib/python2.7/
2 changes: 1 addition & 1 deletion boards/wio-sdk-wm1110.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"jlink_device": "nRF52840_xxAA",
"svd_path": "nrf52840.svd"
},
"frameworks": ["arduino"],
"frameworks": ["arduino", "freertos"],
"name": "Seeed WIO WM1110",
"upload": {
"maximum_ram_size": 248832,
Expand Down
17 changes: 17 additions & 0 deletions src/PowerFSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Default.h"
#include "MeshService.h"
#include "NodeDB.h"
#include "PowerMon.h"
#include "configuration.h"
#include "graphics/Screen.h"
#include "main.h"
Expand Down Expand Up @@ -49,6 +50,7 @@ static bool isPowered()
static void sdsEnter()
{
LOG_DEBUG("Enter state: SDS\n");
powerMon->setState(meshtastic_PowerMon_State_CPU_DeepSleep);
// FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw
doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false);
}
Expand All @@ -68,6 +70,7 @@ static uint32_t secsSlept;
static void lsEnter()
{
LOG_INFO("lsEnter begin, ls_secs=%u\n", config.power.ls_secs);
powerMon->clearState(meshtastic_PowerMon_State_Screen_On);
screen->setOn(false);
secsSlept = 0; // How long have we been sleeping this time

Expand All @@ -87,8 +90,10 @@ static void lsIdle()
// Briefly come out of sleep long enough to blink the led once every few seconds
uint32_t sleepTime = SLEEP_TIME;

powerMon->setState(meshtastic_PowerMon_State_CPU_LightSleep);
setLed(false); // Never leave led on while in light sleep
esp_sleep_source_t wakeCause2 = doLightSleep(sleepTime * 1000LL);
powerMon->clearState(meshtastic_PowerMon_State_CPU_LightSleep);

switch (wakeCause2) {
case ESP_SLEEP_WAKEUP_TIMER:
Expand Down Expand Up @@ -144,6 +149,7 @@ static void lsExit()
static void nbEnter()
{
LOG_DEBUG("Enter state: NB\n");
powerMon->clearState(meshtastic_PowerMon_State_BT_On);
screen->setOn(false);
#ifdef ARCH_ESP32
// Only ESP32 should turn off bluetooth
Expand All @@ -155,13 +161,17 @@ static void nbEnter()

static void darkEnter()
{
powerMon->clearState(meshtastic_PowerMon_State_BT_On);
powerMon->clearState(meshtastic_PowerMon_State_Screen_On);
setBluetoothEnable(true);
screen->setOn(false);
}

static void serialEnter()
{
LOG_DEBUG("Enter state: SERIAL\n");
powerMon->clearState(meshtastic_PowerMon_State_BT_On);
powerMon->setState(meshtastic_PowerMon_State_Screen_On);
setBluetoothEnable(false);
screen->setOn(true);
screen->print("Serial connected\n");
Expand All @@ -170,6 +180,7 @@ static void serialEnter()
static void serialExit()
{
// Turn bluetooth back on when we leave serial stream API
powerMon->setState(meshtastic_PowerMon_State_BT_On);
setBluetoothEnable(true);
screen->print("Serial disconnected\n");
}
Expand All @@ -182,6 +193,8 @@ static void powerEnter()
LOG_INFO("Loss of power in Powered\n");
powerFSM.trigger(EVENT_POWER_DISCONNECTED);
} else {
powerMon->setState(meshtastic_PowerMon_State_BT_On);
powerMon->setState(meshtastic_PowerMon_State_Screen_On);
screen->setOn(true);
setBluetoothEnable(true);
// within enter() the function getState() returns the state we came from
Expand All @@ -205,6 +218,8 @@ static void powerIdle()

static void powerExit()
{
powerMon->setState(meshtastic_PowerMon_State_BT_On);
powerMon->setState(meshtastic_PowerMon_State_Screen_On);
screen->setOn(true);
setBluetoothEnable(true);

Expand All @@ -216,6 +231,8 @@ static void powerExit()
static void onEnter()
{
LOG_DEBUG("Enter state: ON\n");
powerMon->setState(meshtastic_PowerMon_State_BT_On);
powerMon->setState(meshtastic_PowerMon_State_Screen_On);
screen->setOn(true);
setBluetoothEnable(true);
}
Expand Down
45 changes: 45 additions & 0 deletions src/PowerMon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "PowerMon.h"
#include "NodeDB.h"

// Use the 'live' config flag to figure out if we should be showing this message
static bool is_power_enabled(uint64_t m)
{
return (m & config.power.powermon_enables) ? true : false;
}

void PowerMon::setState(_meshtastic_PowerMon_State state, const char *reason)
{
#ifdef USE_POWERMON
auto oldstates = states;
states |= state;
if (oldstates != states && is_power_enabled(state)) {
emitLog(reason);
}
#endif
}

void PowerMon::clearState(_meshtastic_PowerMon_State state, const char *reason)
{
#ifdef USE_POWERMON
auto oldstates = states;
states &= ~state;
if (oldstates != states && is_power_enabled(state)) {
emitLog(reason);
}
#endif
}

void PowerMon::emitLog(const char *reason)
{
#ifdef USE_POWERMON
// The nrf52 printf doesn't understand 64 bit ints, so if we ever reach that point this function will need to change.
LOG_INFO("S:PM:0x%08lx,%s\n", (uint32_t)states, reason);
#endif
}

PowerMon *powerMon;

void powerMonInit()
{
powerMon = new PowerMon();
}
34 changes: 34 additions & 0 deletions src/PowerMon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
#include "configuration.h"

#include "meshtastic/powermon.pb.h"

#ifndef MESHTASTIC_EXCLUDE_POWERMON
#define USE_POWERMON // FIXME turn this only for certain builds
#endif

/**
* The singleton class for monitoring power consumption of device
* subsystems/modes.
*
* For more information see the PowerMon docs.
*/
class PowerMon
{
uint64_t states = 0UL;

public:
PowerMon() {}

// Mark entry/exit of a power consuming state
void setState(_meshtastic_PowerMon_State state, const char *reason = "");
void clearState(_meshtastic_PowerMon_State state, const char *reason = "");

private:
// Emit the coded log message
void emitLog(const char *reason);
};

extern PowerMon *powerMon;

void powerMonInit();
2 changes: 2 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MESHTASTIC_EXCLUDE_GPS 1
#define MESHTASTIC_EXCLUDE_SCREEN 1
#define MESHTASTIC_EXCLUDE_MQTT 1
#define MESHTASTIC_EXCLUDE_POWERMON 1
#endif

// Turn off all optional modules
Expand All @@ -281,6 +282,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MESHTASTIC_EXCLUDE_WAYPOINT 1
#define MESHTASTIC_EXCLUDE_INPUTBROKER 1
#define MESHTASTIC_EXCLUDE_SERIAL 1
#define MESHTASTIC_EXCLUDE_POWERSTRESS 1
#endif

// // Turn off wifi even if HW supports wifi (webserver relies on wifi and is also disabled)
Expand Down
4 changes: 4 additions & 0 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Default.h"
#include "GPS.h"
#include "NodeDB.h"
#include "PowerMon.h"
#include "RTC.h"

#include "main.h" // pmu_found
Expand Down Expand Up @@ -815,9 +816,12 @@ void GPS::setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime)
return;

if (on) {
powerMon->setState(meshtastic_PowerMon_State_GPS_Active);
clearBuffer(); // drop any old data waiting in the buffer before re-enabling
if (en_gpio)
digitalWrite(en_gpio, on ? GPS_EN_ACTIVE : !GPS_EN_ACTIVE); // turn this on if defined, every time
} else {
powerMon->clearState(meshtastic_PowerMon_State_GPS_Active);
}
isInPowersave = !on;
if (!standbyOnly && en_gpio != 0 &&
Expand Down
12 changes: 11 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "MeshService.h"
#include "NodeDB.h"
#include "PowerFSM.h"
#include "PowerMon.h"
#include "ReliableRouter.h"
#include "airtime.h"
#include "buzz.h"
Expand Down Expand Up @@ -214,6 +215,14 @@ __attribute__((weak, noinline)) bool loopCanSleep()
return true;
}

/**
* Print info as a structured log message (for automated log processing)
*/
void printInfo()
{
LOG_INFO("S:B:%d,%s\n", HW_VENDOR, optstr(APP_VERSION));
}

void setup()
{
concurrency::hasBeenSetup = true;
Expand All @@ -234,6 +243,7 @@ void setup()
#ifdef DEBUG_PORT
consoleInit(); // Set serial baud rate and init our mesh console
#endif
powerMonInit();

serialSinceMsec = millis();

Expand Down Expand Up @@ -553,7 +563,7 @@ void setup()
#endif

// Hello
LOG_INFO("Meshtastic hwvendor=%d, swver=%s\n", HW_VENDOR, optstr(APP_VERSION));
printInfo();

#ifdef ARCH_ESP32
esp32Setup();
Expand Down
3 changes: 2 additions & 1 deletion src/mesh/LR11x0Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ template <typename T> void LR11x0Interface<T>::setStandby()
activeReceiveStart = 0;
disableInterrupt();
completeSending(); // If we were sending, not anymore
RadioLibInterface::setStandby();
}

/**
Expand Down Expand Up @@ -223,7 +224,7 @@ template <typename T> void LR11x0Interface<T>::startReceive()
0); // only RX_DONE IRQ is needed, we'll check for PREAMBLE_DETECTED and HEADER_VALID in isActivelyReceiving
assert(err == RADIOLIB_ERR_NONE);

isReceiving = true;
Comment thread
thebentern marked this conversation as resolved.
RadioLibInterface::startReceive();

// Must be done AFTER, starting transmit, because startTransmit clears (possibly stale) interrupt pending register bits
enableInterrupt(isrRxLevel0);
Expand Down
31 changes: 17 additions & 14 deletions src/mesh/RF95Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ typedef struct {
} DACDB;

// Interpolation function
DACDB interpolate(uint8_t dbm, uint8_t dbm1, uint8_t dbm2, DACDB val1, DACDB val2) {
DACDB interpolate(uint8_t dbm, uint8_t dbm1, uint8_t dbm2, DACDB val1, DACDB val2)
{
DACDB result;
double fraction = (double)(dbm - dbm1) / (dbm2 - dbm1);
result.dac = (uint8_t)(val1.dac + fraction * (val2.dac - val1.dac));
Expand All @@ -34,16 +35,17 @@ DACDB interpolate(uint8_t dbm, uint8_t dbm1, uint8_t dbm2, DACDB val1, DACDB val
}

// Function to find the correct DAC and DB values based on dBm using interpolation
DACDB getDACandDB(uint8_t dbm) {
DACDB getDACandDB(uint8_t dbm)
{
// Predefined values
static const struct {
uint8_t dbm;
DACDB values;
} dbmToDACDB[] = {
{20, {168, 2}}, // 100mW
{24, {148, 6}}, // 250mW
{27, {128, 9}}, // 500mW
{30, {90, 12}} // 1000mW
{20, {168, 2}}, // 100mW
{24, {148, 6}}, // 250mW
{27, {128, 9}}, // 500mW
{30, {90, 12}} // 1000mW
};
const int numValues = sizeof(dbmToDACDB) / sizeof(dbmToDACDB[0]);

Expand Down Expand Up @@ -103,7 +105,7 @@ bool RF95Interface::init()

if (power > RF95_MAX_POWER) // This chip has lower power limits than some
power = RF95_MAX_POWER;

limitPower();

iface = lora = new RadioLibRF95(&module);
Expand All @@ -116,13 +118,13 @@ bool RF95Interface::init()
// enable PA
#ifdef RF95_PA_EN
#if defined(RF95_PA_DAC_EN)
#ifdef RADIOMASTER_900_BANDIT_NANO
// Use calculated DAC value
dacWrite(RF95_PA_EN, powerDAC);
#else
// Use Value set in /*/variant.h
dacWrite(RF95_PA_EN, RF95_PA_LEVEL);
#endif
#ifdef RADIOMASTER_900_BANDIT_NANO
// Use calculated DAC value
dacWrite(RF95_PA_EN, powerDAC);
#else
// Use Value set in /*/variant.h
dacWrite(RF95_PA_EN, RF95_PA_LEVEL);
#endif
#endif
#endif

Expand Down Expand Up @@ -254,6 +256,7 @@ void RF95Interface::setStandby()
isReceiving = false; // If we were receiving, not any more
disableInterrupt();
completeSending(); // If we were sending, not anymore
RadioLibInterface::setStandby();
}

/** We override to turn on transmitter power as needed.
Expand Down
Loading