Skip to content
Snippets Groups Projects
Commit 90d00c1c authored by Max Horn's avatar Max Horn
Browse files

Fix ESP8266 crashes with receiver enabled

This should fix #46
parent 43db1b27
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,15 @@ ...@@ -40,6 +40,15 @@
#define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) #define memcpy_P(dest, src, num) memcpy((dest), (src), (num))
#endif #endif
#ifdef ESP8266
// interrupt handler and related code must be in RAM on ESP8266,
// according to issue #46.
#define RECEIVE_ATTR ICACHE_RAM_ATTR
#else
#define RECEIVE_ATTR
#endif
/* Format for protocol definitions: /* Format for protocol definitions:
* {pulselength, Sync bit, "0" bit, "1" bit} * {pulselength, Sync bit, "0" bit, "1" bit}
* *
...@@ -59,7 +68,11 @@ ...@@ -59,7 +68,11 @@
* *
* These are combined to form Tri-State bits when sending or receiving codes. * These are combined to form Tri-State bits when sending or receiving codes.
*/ */
#ifdef ESP8266
static const RCSwitch::Protocol proto[] = {
#else
static const RCSwitch::Protocol PROGMEM proto[] = { static const RCSwitch::Protocol PROGMEM proto[] = {
#endif
{ 350, { 1, 31 }, { 1, 3 }, { 3, 1 } }, // protocol 1 { 350, { 1, 31 }, { 1, 3 }, { 3, 1 } }, // protocol 1
{ 650, { 1, 10 }, { 1, 2 }, { 2, 1 } }, // protocol 2 { 650, { 1, 10 }, { 1, 2 }, { 2, 1 } }, // protocol 2
{ 100, { 30, 71 }, { 4, 11 }, { 9, 6 } }, // protocol 3 { 100, { 30, 71 }, { 4, 11 }, { 9, 6 } }, // protocol 3
...@@ -621,10 +634,13 @@ static inline unsigned int diff(int A, int B) { ...@@ -621,10 +634,13 @@ static inline unsigned int diff(int A, int B) {
/** /**
* *
*/ */
bool RCSwitch::receiveProtocol(const int p, unsigned int changeCount) { bool RECEIVE_ATTR RCSwitch::receiveProtocol(const int p, unsigned int changeCount) {
#ifdef ESP8266
const Protocol &pro = proto[p-1];
#else
Protocol pro; Protocol pro;
memcpy_P(&pro, &proto[p-1], sizeof(Protocol)); memcpy_P(&pro, &proto[p-1], sizeof(Protocol));
#endif
unsigned long code = 0; unsigned long code = 0;
const unsigned int delay = RCSwitch::timings[0] / pro.syncFactor.low; const unsigned int delay = RCSwitch::timings[0] / pro.syncFactor.low;
...@@ -655,7 +671,7 @@ bool RCSwitch::receiveProtocol(const int p, unsigned int changeCount) { ...@@ -655,7 +671,7 @@ bool RCSwitch::receiveProtocol(const int p, unsigned int changeCount) {
return true; return true;
} }
void RCSwitch::handleInterrupt() { void RECEIVE_ATTR RCSwitch::handleInterrupt() {
static unsigned int changeCount = 0; static unsigned int changeCount = 0;
static unsigned long lastTime = 0; static unsigned long lastTime = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment