mirror of
https://github.com/meshtastic/firmware.git
synced 2025-07-31 02:45:41 +00:00
ensure acquired SPI lock prevents light-sleep
This commit is contained in:
parent
035dfaf602
commit
0b5030b436
@ -1,12 +1,57 @@
|
|||||||
#include "SPILock.h"
|
#include "SPILock.h"
|
||||||
|
#include "PowerFSM.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "sleep.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
concurrency::Lock *spiLock;
|
concurrency::Lock *spiLock;
|
||||||
|
|
||||||
|
class SPILock : public concurrency::Lock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SPILock();
|
||||||
|
~SPILock();
|
||||||
|
|
||||||
|
void lock() override;
|
||||||
|
void unlock() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool locked;
|
||||||
|
|
||||||
|
int preflightSleepCb(void *unused = NULL) { return locked ? 1 : 0; }
|
||||||
|
|
||||||
|
CallbackObserver<SPILock, void *> preflightSleepObserver =
|
||||||
|
CallbackObserver<SPILock, void *>(this, &SPILock::preflightSleepCb);
|
||||||
|
};
|
||||||
|
|
||||||
|
SPILock::SPILock() : Lock()
|
||||||
|
{
|
||||||
|
locked = false;
|
||||||
|
preflightSleepObserver.observe(&preflightSleep);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPILock::~SPILock()
|
||||||
|
{
|
||||||
|
preflightSleepObserver.unobserve(&preflightSleep);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SPILock::lock()
|
||||||
|
{
|
||||||
|
powerFSM.trigger(EVENT_WAKE_TIMER);
|
||||||
|
|
||||||
|
Lock::lock();
|
||||||
|
locked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SPILock::unlock()
|
||||||
|
{
|
||||||
|
locked = false;
|
||||||
|
Lock::unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void initSPI()
|
void initSPI()
|
||||||
{
|
{
|
||||||
assert(!spiLock);
|
assert(!spiLock);
|
||||||
spiLock = new concurrency::Lock();
|
spiLock = new SPILock();
|
||||||
}
|
}
|
@ -19,12 +19,12 @@ class Lock
|
|||||||
/// Locks the lock.
|
/// Locks the lock.
|
||||||
//
|
//
|
||||||
// Must not be called from an ISR.
|
// Must not be called from an ISR.
|
||||||
void lock();
|
virtual void lock();
|
||||||
|
|
||||||
// Unlocks the lock.
|
// Unlocks the lock.
|
||||||
//
|
//
|
||||||
// Must not be called from an ISR.
|
// Must not be called from an ISR.
|
||||||
void unlock();
|
virtual void unlock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef HAS_FREE_RTOS
|
#ifdef HAS_FREE_RTOS
|
||||||
|
Loading…
Reference in New Issue
Block a user