concurrency wip

1.2-legacy
Kevin Hester 2020-10-10 08:28:00 +08:00
rodzic 2044427e97
commit c46a884558
5 zmienionych plików z 88 dodań i 7 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -10,6 +10,11 @@ namespace concurrency
*/
class NotifiedWorkerThread : public OSThread
{
/**
* The notification that was most recently used to wake the thread. Read from runOnce()
*/
uint32_t notification = 0;
public:
NotifiedWorkerThread(const char *name) : OSThread(name) {}
@ -23,7 +28,7 @@ class NotifiedWorkerThread : public OSThread
*
* 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
@ -34,12 +39,6 @@ class NotifiedWorkerThread : public OSThread
virtual void onNotify(uint32_t notification) = 0;
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

Wyświetl plik

@ -4,4 +4,37 @@
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

Wyświetl plik

@ -25,6 +25,10 @@ extern ThreadController mainController, timerController;
* stopping sleep instantly as soon as an event occurs.
* 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
*
* remove lock/lockguard
@ -38,6 +42,8 @@ class OSThread : public Thread
virtual ~OSThread();
static void setup();
protected:
/**
* 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)
*/
virtual uint32_t runOnce() = 0;
// Do not override this
virtual void run();
};
} // namespace concurrency

Wyświetl plik

@ -13,6 +13,7 @@
// #include "debug.h"
#include "RTC.h"
#include "SPILock.h"
#include "concurrency/OSThread.h"
#include "concurrency/Periodic.h"
#include "graphics/Screen.h"
#include "main.h"
@ -155,6 +156,8 @@ void setup()
digitalWrite(RESET_OLED, 1);
#endif
concurrency::OSThread::setup();
#ifdef I2C_SDA
Wire.begin(I2C_SDA, I2C_SCL);
#else
@ -375,6 +378,8 @@ void loop()
userButtonAlt.tick();
#endif
concurrency::mainController.run();
loopWifi();
// For debugging