sforkowany z mirror/meshtastic-firmware
concurrency wip
rodzic
2044427e97
commit
c46a884558
|
@ -0,0 +1,35 @@
|
||||||
|
#include "NotifiedWorkerThread.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
namespace concurrency
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify this thread so it can run
|
||||||
|
*/
|
||||||
|
IRAM_ATTR void NotifiedWorkerThread::notify(uint32_t v, bool overwrite) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify from an ISR
|
||||||
|
*
|
||||||
|
* This must be inline or IRAM_ATTR on ESP32
|
||||||
|
*/
|
||||||
|
IRAM_ATTR void NotifiedWorkerThread::notifyFromISR(BaseType_t *highPriWoken, uint32_t v, bool overwrite)
|
||||||
|
{
|
||||||
|
notify(v, overwrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a notification to fire in delay msecs
|
||||||
|
*/
|
||||||
|
void NotifiedWorkerThread::notifyLater(uint32_t delay, uint32_t v, bool overwrite) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t NotifiedWorkerThread::runOnce() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace concurrency
|
|
@ -10,6 +10,11 @@ namespace concurrency
|
||||||
*/
|
*/
|
||||||
class NotifiedWorkerThread : public OSThread
|
class NotifiedWorkerThread : public OSThread
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The notification that was most recently used to wake the thread. Read from runOnce()
|
||||||
|
*/
|
||||||
|
uint32_t notification = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NotifiedWorkerThread(const char *name) : OSThread(name) {}
|
NotifiedWorkerThread(const char *name) : OSThread(name) {}
|
||||||
|
|
||||||
|
@ -23,7 +28,7 @@ class NotifiedWorkerThread : public OSThread
|
||||||
*
|
*
|
||||||
* This must be inline or IRAM_ATTR on ESP32
|
* This must be inline or IRAM_ATTR on ESP32
|
||||||
*/
|
*/
|
||||||
void notifyFromISR(BaseType_t *highPriWoken, uint32_t v, bool overwrite) { notify(v, overwrite); }
|
void notifyFromISR(BaseType_t *highPriWoken, uint32_t v, bool overwrite);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule a notification to fire in delay msecs
|
* Schedule a notification to fire in delay msecs
|
||||||
|
@ -34,12 +39,6 @@ class NotifiedWorkerThread : public OSThread
|
||||||
virtual void onNotify(uint32_t notification) = 0;
|
virtual void onNotify(uint32_t notification) = 0;
|
||||||
|
|
||||||
virtual uint32_t runOnce();
|
virtual uint32_t runOnce();
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* The notification that was most recently used to wake the thread. Read from runOnce()
|
|
||||||
*/
|
|
||||||
uint32_t notification = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace concurrency
|
} // namespace concurrency
|
||||||
|
|
|
@ -4,4 +4,37 @@
|
||||||
namespace concurrency
|
namespace concurrency
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ThreadController mainController, timerController;
|
||||||
|
|
||||||
|
void OSThread::setup()
|
||||||
|
{
|
||||||
|
mainController.ThreadName = "mainController";
|
||||||
|
timerController.ThreadName = "timerController";
|
||||||
|
}
|
||||||
|
|
||||||
|
OSThread::OSThread(const char *_name, uint32_t period, ThreadController *_controller)
|
||||||
|
: Thread(NULL, period), controller(_controller)
|
||||||
|
{
|
||||||
|
ThreadName = _name;
|
||||||
|
|
||||||
|
if (controller)
|
||||||
|
controller->add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
OSThread::~OSThread()
|
||||||
|
{
|
||||||
|
if (controller)
|
||||||
|
controller->remove(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSThread::run()
|
||||||
|
{
|
||||||
|
auto newDelay = runOnce();
|
||||||
|
|
||||||
|
runned();
|
||||||
|
|
||||||
|
if (newDelay != 0)
|
||||||
|
setInterval(newDelay);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace concurrency
|
} // namespace concurrency
|
||||||
|
|
|
@ -25,6 +25,10 @@ extern ThreadController mainController, timerController;
|
||||||
* stopping sleep instantly as soon as an event occurs.
|
* stopping sleep instantly as soon as an event occurs.
|
||||||
* use global functions delayTillWakeEvent(time), doWakeEvent(isInISR) - use freertos mutex or somesuch
|
* use global functions delayTillWakeEvent(time), doWakeEvent(isInISR) - use freertos mutex or somesuch
|
||||||
*
|
*
|
||||||
|
* make everything use osthread
|
||||||
|
*
|
||||||
|
* Debug what is keeping us from sleeping
|
||||||
|
*
|
||||||
* have router thread block on its message queue in runOnce
|
* have router thread block on its message queue in runOnce
|
||||||
*
|
*
|
||||||
* remove lock/lockguard
|
* remove lock/lockguard
|
||||||
|
@ -38,6 +42,8 @@ class OSThread : public Thread
|
||||||
|
|
||||||
virtual ~OSThread();
|
virtual ~OSThread();
|
||||||
|
|
||||||
|
static void setup();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* The method that will be called each time our thread gets a chance to run
|
* The method that will be called each time our thread gets a chance to run
|
||||||
|
@ -45,6 +51,9 @@ class OSThread : public Thread
|
||||||
* Returns desired period for next invocation (or 0 for no change)
|
* Returns desired period for next invocation (or 0 for no change)
|
||||||
*/
|
*/
|
||||||
virtual uint32_t runOnce() = 0;
|
virtual uint32_t runOnce() = 0;
|
||||||
|
|
||||||
|
// Do not override this
|
||||||
|
virtual void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace concurrency
|
} // namespace concurrency
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// #include "debug.h"
|
// #include "debug.h"
|
||||||
#include "RTC.h"
|
#include "RTC.h"
|
||||||
#include "SPILock.h"
|
#include "SPILock.h"
|
||||||
|
#include "concurrency/OSThread.h"
|
||||||
#include "concurrency/Periodic.h"
|
#include "concurrency/Periodic.h"
|
||||||
#include "graphics/Screen.h"
|
#include "graphics/Screen.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
@ -155,6 +156,8 @@ void setup()
|
||||||
digitalWrite(RESET_OLED, 1);
|
digitalWrite(RESET_OLED, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
concurrency::OSThread::setup();
|
||||||
|
|
||||||
#ifdef I2C_SDA
|
#ifdef I2C_SDA
|
||||||
Wire.begin(I2C_SDA, I2C_SCL);
|
Wire.begin(I2C_SDA, I2C_SCL);
|
||||||
#else
|
#else
|
||||||
|
@ -375,6 +378,8 @@ void loop()
|
||||||
userButtonAlt.tick();
|
userButtonAlt.tick();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
concurrency::mainController.run();
|
||||||
|
|
||||||
loopWifi();
|
loopWifi();
|
||||||
|
|
||||||
// For debugging
|
// For debugging
|
||||||
|
|
Ładowanie…
Reference in New Issue