mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-16 10:02:05 +00:00
new threading finished- saves about 10mA for the high activity states
This commit is contained in:
parent
c44d8a0433
commit
0c8e0efed2
@ -20,5 +20,6 @@
|
|||||||
#define EVENT_POWER_DISCONNECTED 14
|
#define EVENT_POWER_DISCONNECTED 14
|
||||||
|
|
||||||
extern Fsm powerFSM;
|
extern Fsm powerFSM;
|
||||||
|
extern State statePOWER;
|
||||||
|
|
||||||
void PowerFSM_setup();
|
void PowerFSM_setup();
|
||||||
|
@ -20,12 +20,12 @@ InterruptableDelay::~InterruptableDelay()
|
|||||||
bool InterruptableDelay::delay(uint32_t msec)
|
bool InterruptableDelay::delay(uint32_t msec)
|
||||||
{
|
{
|
||||||
if (msec) {
|
if (msec) {
|
||||||
DEBUG_MSG("delay %u ", msec);
|
// DEBUG_MSG("delay %u ", msec);
|
||||||
|
|
||||||
// sem take will return false if we timed out (i.e. were not interrupted)
|
// sem take will return false if we timed out (i.e. were not interrupted)
|
||||||
bool r = xSemaphoreTake(semaphore, pdMS_TO_TICKS(msec));
|
bool r = xSemaphoreTake(semaphore, pdMS_TO_TICKS(msec));
|
||||||
|
|
||||||
DEBUG_MSG("interrupt=%d\n", r);
|
// DEBUG_MSG("interrupt=%d\n", r);
|
||||||
return !r;
|
return !r;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,21 +17,12 @@ extern InterruptableDelay mainDelay;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Base threading
|
* @brief Base threading
|
||||||
|
*
|
||||||
|
* This is a pseudo threading layer that is super easy to port, well suited to our slow network and very ram & power efficient.
|
||||||
*
|
*
|
||||||
* TODO FIXME @geeksville
|
* TODO FIXME @geeksville
|
||||||
*
|
*
|
||||||
* make bluetooth wake cpu immediately (because it puts a message in a queue?)
|
* move more things into OSThreads
|
||||||
*
|
|
||||||
* don't sleep at all if in POWER mode
|
|
||||||
*
|
|
||||||
* wake for serial character received
|
|
||||||
*
|
|
||||||
* add concept of 'low priority' threads that are not used to block sleep?
|
|
||||||
*
|
|
||||||
* make everything use osthread
|
|
||||||
*
|
|
||||||
* if we wake once because of a ble packet we might need to run loop multiple times before we can truely sleep
|
|
||||||
*
|
|
||||||
* remove lock/lockguard
|
* remove lock/lockguard
|
||||||
*
|
*
|
||||||
* move typedQueue into concurrency
|
* move typedQueue into concurrency
|
||||||
|
33
src/main.cpp
33
src/main.cpp
@ -53,7 +53,6 @@ meshtastic::NodeStatus *nodeStatus = new meshtastic::NodeStatus();
|
|||||||
bool ssd1306_found;
|
bool ssd1306_found;
|
||||||
bool axp192_found;
|
bool axp192_found;
|
||||||
|
|
||||||
|
|
||||||
Router *router = NULL; // Users of router don't care what sort of subclass implements that API
|
Router *router = NULL; // Users of router don't care what sort of subclass implements that API
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -115,7 +114,28 @@ static int32_t ledBlinker()
|
|||||||
return powerStatus->getIsCharging() ? 1000 : (ledOn ? 1 : 1000);
|
return powerStatus->getIsCharging() ? 1000 : (ledOn ? 1 : 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wrapper to convert our powerFSM stuff into a 'thread'
|
||||||
|
class PowerFSMThread : public OSThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
||||||
|
PowerFSMThread() : OSThread("PowerFSM") {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int32_t runOnce()
|
||||||
|
{
|
||||||
|
powerFSM.run_machine();
|
||||||
|
|
||||||
|
/// If we are in power state we force the CPU to wake every 10ms to check for serial characters (we don't yet wake
|
||||||
|
/// cpu for serial rx - FIXME)
|
||||||
|
canSleep = (powerFSM.getState() != &statePOWER);
|
||||||
|
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static Periodic *ledPeriodic;
|
static Periodic *ledPeriodic;
|
||||||
|
static OSThread *powerFSMthread;
|
||||||
|
|
||||||
// Prepare for button presses
|
// Prepare for button presses
|
||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
@ -349,6 +369,7 @@ void setup()
|
|||||||
|
|
||||||
// This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values
|
// This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values
|
||||||
PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS
|
PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS
|
||||||
|
powerFSMthread = new PowerFSMThread();
|
||||||
|
|
||||||
// setBluetoothEnable(false); we now don't start bluetooth until we enter the proper state
|
// setBluetoothEnable(false); we now don't start bluetooth until we enter the proper state
|
||||||
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
||||||
@ -377,8 +398,6 @@ axpDebugOutput.setup();
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
powerFSM.run_machine();
|
|
||||||
|
|
||||||
// axpDebugOutput.loop();
|
// axpDebugOutput.loop();
|
||||||
|
|
||||||
#ifdef DEBUG_PORT
|
#ifdef DEBUG_PORT
|
||||||
@ -416,9 +435,11 @@ void loop()
|
|||||||
|
|
||||||
long delayMsec = mainController.runOrDelay();
|
long delayMsec = mainController.runOrDelay();
|
||||||
|
|
||||||
if(mainController.nextThread && delayMsec)
|
/* if (mainController.nextThread && delayMsec)
|
||||||
DEBUG_MSG("Next %s in %ld\n", mainController.nextThread->ThreadName.c_str(), mainController.nextThread->tillRun(millis()));
|
DEBUG_MSG("Next %s in %ld\n", mainController.nextThread->ThreadName.c_str(),
|
||||||
|
mainController.nextThread->tillRun(millis()));
|
||||||
|
*/
|
||||||
|
|
||||||
// We want to sleep as long as possible here - because it saves power
|
// We want to sleep as long as possible here - because it saves power
|
||||||
mainDelay.delay(delayMsec);
|
mainDelay.delay(delayMsec);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user