kopia lustrzana https://github.com/sh123/esp32_loraprs
Use xTaskNotifyFromISR/xTaskNotifyWait to notify on incoming data from ISR
rodzic
9f216ee30b
commit
f0fcd6ce03
|
@ -6,6 +6,7 @@ byte Service::rxBuf_[CfgMaxPacketSize];
|
||||||
|
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
#pragma message("Using RadioLib")
|
#pragma message("Using RadioLib")
|
||||||
|
TaskHandle_t Service::rxTaskHandle_;
|
||||||
volatile bool Service::loraDataAvailable_ = false;
|
volatile bool Service::loraDataAvailable_ = false;
|
||||||
bool Service::interruptEnabled_ = true;
|
bool Service::interruptEnabled_ = true;
|
||||||
std::shared_ptr<MODULE_NAME> Service::radio_;
|
std::shared_ptr<MODULE_NAME> Service::radio_;
|
||||||
|
@ -73,7 +74,7 @@ void Service::setup(const Config &conf)
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
if (!config_.LoraUseIsr) {
|
if (!config_.LoraUseIsr) {
|
||||||
LOG_INFO("Reading data on separate task");
|
LOG_INFO("Reading data on separate task");
|
||||||
xTaskCreate(processIncomingDataTask, "processIncomingDataTask", 10000, NULL, 1, NULL);
|
xTaskCreate(processIncomingDataTask, "processIncomingDataTask", 10000, NULL, 1, &rxTaskHandle_);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -395,8 +396,13 @@ bool Service::isLoraRxBusy() {
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
|
|
||||||
ICACHE_RAM_ATTR void Service::onLoraDataAvailableIsrNoRead() {
|
ICACHE_RAM_ATTR void Service::onLoraDataAvailableIsrNoRead() {
|
||||||
|
BaseType_t xHigherPriorityTaskWoken;
|
||||||
|
uint32_t interruptStatusBits = 0;
|
||||||
|
|
||||||
if (interruptEnabled_) {
|
if (interruptEnabled_) {
|
||||||
loraDataAvailable_ = true;
|
loraDataAvailable_ = true;
|
||||||
|
interruptStatusBits |= 1;
|
||||||
|
xTaskNotifyFromISR(rxTaskHandle_, interruptStatusBits, eSetBits, &xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,9 +429,12 @@ ICACHE_RAM_ATTR void Service::onLoraDataAvailableIsr() {
|
||||||
|
|
||||||
void Service::processIncomingDataTask(void *param) {
|
void Service::processIncomingDataTask(void *param) {
|
||||||
LOG_INFO("Incoming data process task started");
|
LOG_INFO("Incoming data process task started");
|
||||||
|
uint32_t interruptStatusBits;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (loraDataAvailable_) {
|
xTaskNotifyWait(0, 0x00, &interruptStatusBits, portMAX_DELAY);
|
||||||
|
|
||||||
|
if (interruptStatusBits & 0x01) {
|
||||||
int packetSize = radio_->getPacketLength();
|
int packetSize = radio_->getPacketLength();
|
||||||
|
|
||||||
if (packetSize > 0) {
|
if (packetSize > 0) {
|
||||||
|
@ -444,7 +453,6 @@ void Service::processIncomingDataTask(void *param) {
|
||||||
}
|
}
|
||||||
loraDataAvailable_ = false;
|
loraDataAvailable_ = false;
|
||||||
}
|
}
|
||||||
delay(CfgPollDelayMs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ private:
|
||||||
|
|
||||||
// processor config
|
// processor config
|
||||||
const int CfgConnRetryMs = 500; // connection retry delay, e.g. wifi
|
const int CfgConnRetryMs = 500; // connection retry delay, e.g. wifi
|
||||||
static const int CfgPollDelayMs = 5; // main loop delay
|
static const int CfgPollDelayMs = 20; // main loop delay
|
||||||
const int CfgConnRetryMaxTimes = 10; // number of connection retries
|
const int CfgConnRetryMaxTimes = 10; // number of connection retries
|
||||||
static const int CfgMaxPacketSize = 256; // maximum packet size
|
static const int CfgMaxPacketSize = 256; // maximum packet size
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ private:
|
||||||
// peripherals
|
// peripherals
|
||||||
static byte rxBuf_[CfgMaxPacketSize];
|
static byte rxBuf_[CfgMaxPacketSize];
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
|
static TaskHandle_t rxTaskHandle_;
|
||||||
static volatile bool loraDataAvailable_;
|
static volatile bool loraDataAvailable_;
|
||||||
static bool interruptEnabled_;
|
static bool interruptEnabled_;
|
||||||
CircularBuffer<uint8_t, CfgMaxPacketSize> txQueue_;
|
CircularBuffer<uint8_t, CfgMaxPacketSize> txQueue_;
|
||||||
|
|
Ładowanie…
Reference in New Issue