new threading finished- saves about 10mA for the high activity states

1.2-legacy
Kevin Hester 2020-10-11 08:12:53 +08:00
rodzic c44d8a0433
commit 0c8e0efed2
4 zmienionych plików z 33 dodań i 20 usunięć

Wyświetl plik

@ -20,5 +20,6 @@
#define EVENT_POWER_DISCONNECTED 14
extern Fsm powerFSM;
extern State statePOWER;
void PowerFSM_setup();

Wyświetl plik

@ -20,12 +20,12 @@ InterruptableDelay::~InterruptableDelay()
bool InterruptableDelay::delay(uint32_t 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)
bool r = xSemaphoreTake(semaphore, pdMS_TO_TICKS(msec));
DEBUG_MSG("interrupt=%d\n", r);
// DEBUG_MSG("interrupt=%d\n", r);
return !r;
} else {
return true;

Wyświetl plik

@ -17,21 +17,12 @@ extern InterruptableDelay mainDelay;
/**
* @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
*
* make bluetooth wake cpu immediately (because it puts a message in a queue?)
*
* 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
*
* move more things into OSThreads
* remove lock/lockguard
*
* move typedQueue into concurrency

Wyświetl plik

@ -53,7 +53,6 @@ meshtastic::NodeStatus *nodeStatus = new meshtastic::NodeStatus();
bool ssd1306_found;
bool axp192_found;
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);
}
/// 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 OSThread *powerFSMthread;
// Prepare for button presses
#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
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
setCPUFast(false); // 80MHz is fine for our slow peripherals
@ -377,8 +398,6 @@ axpDebugOutput.setup();
void loop()
{
powerFSM.run_machine();
// axpDebugOutput.loop();
#ifdef DEBUG_PORT
@ -416,9 +435,11 @@ void loop()
long delayMsec = mainController.runOrDelay();
if(mainController.nextThread && delayMsec)
DEBUG_MSG("Next %s in %ld\n", mainController.nextThread->ThreadName.c_str(), mainController.nextThread->tillRun(millis()));
/* if (mainController.nextThread && delayMsec)
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
mainDelay.delay(delayMsec);
}