Skip to content

Commit 9017fdc

Browse files
authored
Merge pull request #12 from ricaun/update
Fix the ISR not in IRAM chashes
2 parents c647129 + c57ebe1 commit 9017fdc

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This is the payload format, this protocol don't have any kind of encryption.
5555
## Installation
5656

5757
* Install the library by [Using the Library Manager](https://www.arduino.cc/en/Guide/Libraries#toc3)
58-
* **OR** by [Importing the .zip library](https://www.arduino.cc/en/Guide/Libraries#toc4) using either the [master](https://github.com/ricaun/LoRaNow/archive/1.0.4.zip) or one of the [releases](https://github.com/ricaun/LoRaNow/releases) ZIP files.
58+
* **OR** by [Importing the .zip library](https://www.arduino.cc/en/Guide/Libraries#toc4) using either the [master](https://github.com/ricaun/LoRaNow/archive/1.0.5.zip) or one of the [releases](https://github.com/ricaun/LoRaNow/releases) ZIP files.
5959

6060
## Examples
6161

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=LoRaNow
2-
version=1.0.4
2+
version=1.0.5
33
author=Luiz Henrique Cassettari
44
maintainer=Luiz Henrique Cassettari <[email protected]>
55
sentence=LoRaNow Library is a simple LoRa Node <> Gateway communication protocol.

src/LoRaNow.cpp

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ---------------------------------------------------- //
22
// LoRaNow.cpp
33
// ---------------------------------------------------- //
4+
// 28/08/2019 - esp32 interrupt fatal erro add ICACHE_RAM_ATTR
45
// 27/04/2019 - Add setPinsSPI to help esp32 boards
56
// 24/04/2019 - Fix LoRaNow board mosfet
67
// 23/04/2019 - Add onSleep callback
@@ -36,6 +37,12 @@
3637
#endif
3738
#endif
3839

40+
#ifdef ESP8266 || ESP32
41+
#define ISR_PREFIX ICACHE_RAM_ATTR
42+
#else
43+
#define ISR_PREFIX
44+
#endif
45+
3946
LoRaNowClass::LoRaNowClass()
4047
{
4148
setTimeout(0);
@@ -61,6 +68,7 @@ byte LoRaNowClass::begin()
6168
randomSeed(seed);
6269
now_id = makeId();
6370
}
71+
6472
LORANOW_DEBUG_PRINTLN("[ln] Begin");
6573
LoRa.onReceive(LoRaNowClass::onReceive);
6674
LoRa.onTxDone(LoRaNowClass::onTxDone);
@@ -141,21 +149,32 @@ void LoRaNowClass::state_do(byte _state)
141149
state_change(LORA_STATE_RX1_DONE, rxwindow);
142150
break;
143151
case LORA_STATE_RX1_DONE:
144-
//state_change(LORA_STATE_END);
145152
state_change(LORA_STATE_SLEEP);
146153
break;
147154
case LORA_STATE_RX1_WAIT:
148155
case LORA_STATE_SLEEP:
149156
sleep();
150157
break;
151158
case LORA_STATE_RECEIVE:
152-
if (LoRaNow.messageCallback)
159+
LoRaNow.beginDecode();
160+
while (LoRa.available())
161+
{
162+
LoRaNow.write(LoRa.read());
163+
}
164+
if (LoRaNow.endDecode())
153165
{
154-
LoRaNow.messageCallback((uint8_t *)LoRaNow.buffer(), LoRaNow.available());
166+
if (LoRaNow.messageCallback)
167+
{
168+
LoRaNow.messageCallback((uint8_t *)LoRaNow.buffer(), LoRaNow.available());
169+
}
170+
}
171+
else
172+
{
173+
LoRa.receive();
155174
}
156175
LoRaNow.clear();
157176
if (state != LORA_STATE_TX_WAIT)
158-
state_change(LORA_STATE_SLEEP);
177+
state_change(LORA_STATE_SLEEP);
159178
break;
160179
}
161180
}
@@ -269,7 +288,6 @@ void LoRaNowClass::gateway(bool gateway)
269288
{
270289
_gateway = gateway;
271290
rxwindow = 0;
272-
//state_change(LORA_STATE_RX1);
273291
}
274292

275293
void LoRaNowClass::setId(uint32_t _id)
@@ -510,13 +528,6 @@ int LoRaNowClass::endPacket()
510528
return 0;
511529
}
512530

513-
size_t LoRaNowClass::sendPacket(const uint8_t *buffer, size_t size)
514-
{
515-
LoRaNow.beginPacket();
516-
LoRaNow.write(buffer, size);
517-
return LoRaNow.endPacket();
518-
}
519-
520531
byte LoRaNowClass::calcCheckSum(byte *packege, byte length)
521532
{
522533
byte sum = 0;
@@ -529,6 +540,7 @@ byte LoRaNowClass::calcCheckSum(byte *packege, byte length)
529540

530541
void LoRaNowClass::txMode()
531542
{
543+
LORANOW_DEBUG_PRINTLN("[ln] txMode");
532544
LoRa.idle();
533545
LoRa.setFrequency(frequency);
534546
LoRa.setSpreadingFactor(sf);
@@ -578,31 +590,18 @@ void LoRaNowClass::onSleep(void (*cb)())
578590
// LoRa
579591
// ---------------------------------------------------- //
580592

581-
void LoRaNowClass::onReceive(int packetSize)
593+
ISR_PREFIX void LoRaNowClass::onReceive(int packetSize)
582594
{
583595
LORANOW_DEBUG_PRINTLN("[ln] Receive");
584596
LoRaNow.time = millis();
585-
LoRaNow.beginDecode();
586-
while (LoRa.available())
587-
{
588-
LoRaNow.write(LoRa.read());
589-
}
590-
if (LoRaNow.endDecode())
591-
{
592-
LoRaNow.state_change(LORA_STATE_RECEIVE, LORANOW_WAIT_RECEIVE);
593-
}
594-
else
595-
{
596-
LoRa.receive();
597-
LoRaNow.clear();
598-
}
597+
LoRaNow.state_change(LORA_STATE_RECEIVE, LORANOW_WAIT_RECEIVE);
599598
}
600599

601-
void LoRaNowClass::onTxDone()
600+
ISR_PREFIX void LoRaNowClass::onTxDone()
602601
{
603602
LORANOW_DEBUG_PRINTLN("[ln] txDone");
604603
LoRaNow.time = millis();
605-
LoRaNow.state_change(LORA_STATE_TX_DONE);
604+
LoRaNow.state_change(LORA_STATE_TX_DONE, LORANOW_WAIT_TXDONE);
606605
}
607606

608607
LoRaNowClass LoRaNow;

src/LoRaNow.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define LORANOW_BUF_SIZE 128
4444
#define LORANOW_WAIT_READY 2000
4545
#define LORANOW_WAIT_RECEIVE 100
46+
#define LORANOW_WAIT_TXDONE 10
4647

4748
#if defined(ARDUINO_ARCH_ESP32)
4849
#define LORANOW_DEFAULT_SS_PIN 18
@@ -188,9 +189,7 @@ class LoRaNowClass : public Stream
188189

189190
int beginPacket();
190191
int endPacket();
191-
192-
size_t sendPacket(const uint8_t *buffer, size_t size);
193-
192+
194193
uint32_t makeId();
195194

196195
// ----------------------------------------------- //

src/utility/LoRa.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
#define MAP_DIO3_LORA_NOP 0x03
8686

8787

88+
#ifdef ESP8266 || ESP32
89+
#define ISR_PREFIX ICACHE_RAM_ATTR
90+
#else
91+
#define ISR_PREFIX
92+
#endif
93+
94+
8895
LoRaClass::LoRaClass() :
8996
_spiSettings(LORA_DEFAULT_SPI_FREQUENCY, MSBFIRST, SPI_MODE0),
9097
_spi(&LORA_DEFAULT_SPI),
@@ -762,7 +769,7 @@ uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value)
762769
return response;
763770
}
764771

765-
void LoRaClass::onDio0Rise()
772+
ISR_PREFIX void LoRaClass::onDio0Rise()
766773
{
767774
LoRa.handleDio0Rise();
768775
}
@@ -806,7 +813,7 @@ void LoRaClass::receiveCAD()
806813
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_CAD);
807814
}
808815

809-
void LoRaClass::onCADRise()
816+
ISR_PREFIX void LoRaClass::onCADRise()
810817
{
811818
LoRa.handleCADRise();
812819
}

0 commit comments

Comments
 (0)