diff --git a/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/ESP8266SoftwareSerial.cpp b/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/ESP8266SoftwareSerial.cpp index da28bd6adcd581571b9e5fa949d69dc9282c95f3..4672c196a6dd401147be8a5122a87046015abce0 100644 --- a/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/ESP8266SoftwareSerial.cpp +++ b/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/ESP8266SoftwareSerial.cpp @@ -35,19 +35,17 @@ extern "C" { // and callbacks corresponding to each possible GPIO pins have to be defined ESP8266SoftwareSerial *ObjList[MAX_PIN + 1]; -void ICACHE_RAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_2() { ObjList[2]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_3() { ObjList[3]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_4() { ObjList[4]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_5() { ObjList[5]->rxRead(); }; +void IRAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); }; +void IRAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); }; +void IRAM_ATTR sws_isr_2() { ObjList[2]->rxRead(); }; +void IRAM_ATTR sws_isr_3() { ObjList[3]->rxRead(); }; +void IRAM_ATTR sws_isr_4() { ObjList[4]->rxRead(); }; +void IRAM_ATTR sws_isr_5() { ObjList[5]->rxRead(); }; // Pin 6 to 11 can not be used -void ICACHE_RAM_ATTR sws_isr_12() { ObjList[12]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_13() { ObjList[13]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_14() { ObjList[14]->rxRead(); }; -void ICACHE_RAM_ATTR sws_isr_15() { ObjList[15]->rxRead(); }; - -static boolean SerialBusy = false; +void IRAM_ATTR sws_isr_12() { ObjList[12]->rxRead(); }; +void IRAM_ATTR sws_isr_13() { ObjList[13]->rxRead(); }; +void IRAM_ATTR sws_isr_14() { ObjList[14]->rxRead(); }; +void IRAM_ATTR sws_isr_15() { ObjList[15]->rxRead(); }; static void(*ISRList[MAX_PIN + 1])() = { sws_isr_0, @@ -287,7 +285,6 @@ void ICACHE_RAM_ATTR ESP8266SoftwareSerial::rxRead() { int pulseBitLength; bool previousBit = !rxLevel; - bool gotByte = false; switch (m_getByteState) { @@ -313,7 +310,7 @@ void ICACHE_RAM_ATTR ESP8266SoftwareSerial::rxRead() { if (propgateBits(previousBit, pulseBitLength - 1)) { // store byte in buffer - int next = (m_inPos + 1) % m_buffSize; + unsigned int next = (m_inPos + 1) % m_buffSize; if (next != m_outPos) { m_buffer[m_inPos] = m_rec; m_inPos = next; @@ -344,7 +341,7 @@ void ICACHE_RAM_ATTR ESP8266SoftwareSerial::rxRead() { propgateBits(true, 8); // store the byte in the buffer - int next = (m_inPos + 1) % m_buffSize; + unsigned int next = (m_inPos + 1) % m_buffSize; if (next != m_outPos) { m_buffer[m_inPos] = m_rec; m_inPos = next; @@ -359,7 +356,7 @@ void ICACHE_RAM_ATTR ESP8266SoftwareSerial::rxRead() { if (propgateBits(previousBit, pulseBitLength)) { // Store the received value in the buffer unless we have an overflow - int next = (m_inPos + 1) % m_buffSize; + unsigned int next = (m_inPos + 1) % m_buffSize; if (next != m_outPos) { m_buffer[m_inPos] = m_rec; m_inPos = next; @@ -387,7 +384,7 @@ void ICACHE_RAM_ATTR ESP8266SoftwareSerial::rxRead() { // Stop bit WAIT; // Store the received value in the buffer unless we have an overflow - int next = (m_inPos + 1) % m_buffSize; + unsigned int next = (m_inPos + 1) % m_buffSize; if (next != m_inPos) { m_buffer[m_inPos] = rec; m_inPos = next; diff --git a/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/README.md b/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/README.md index f1b57c98c787f598a2aea39b0200d815cfcf2606..21d3519fa3a12c91a80dbc2179783ab6296e5de2 100644 --- a/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/README.md +++ b/ampel-firmware/src/lib/Esp8266EdgeSoftwareSerial/README.md @@ -1,6 +1,6 @@ # Esp8266EdgeSoftwareSerial Software serial for the ESP8266 that uses edge triggered interrupts to improve performance. -Incoming characters do not block programs for the time it takes them to arrive, leading to signficant performance improvements when used on serial data ports running at speeds of 9600 baud or less. Note that the slower the data rate, the more useful this driver becomes. For high speeds it doesn't confer as much of an advantage. +Incoming characters do not block programs for the time it takes them to arrive, leading to significant performance improvements when used on serial data ports running at speeds of 9600 baud or less. Note that the slower the data rate, the more useful this driver becomes. For high speeds it doesn't confer as much of an advantage. You can drop the files into your Arduino sketch folder and use them as straight replacements for the SoftwareSerial library files. Simply replace the < and > characters with double quote characters in the include statement to use the new library: @@ -8,7 +8,7 @@ You can drop the files into your Arduino sketch folder and use them as straight ```c++ #include <SoftwareSerial.h> ``` -with +with ```c++ #include "SoftwareSerial.h" @@ -22,16 +22,16 @@ SoftwareSerial gpsSerial = new SoftwareSerial(12, -1, false, 128, true); ``` The above statement creates a gps receiver that listens on pin 12 but does not transmit anything (that's what the -1 means in the constructor). -The data is not inverted (that's what false means) and it is using a 128 byte buffer for incoming characters. +The data is not inverted (that's what false means) and it is using a 128 byte buffer for incoming characters. -The final parameter (which is true in the above code) selects edge operation. +The final parameter (which is true in the above code) selects edge operation. -If you leave the final parameter off your constructor the SoftwareSerial library works in exaclty the same way as the original library. In other words it defaults to non-edge operation. +If you leave the final parameter off your constructor the SoftwareSerial library works in exactly the same way as the original library. In other words it defaults to non-edge operation. -# Late charcters +# Late characters -There is one issue with this implmenentation. It is not guaranteed that the last character of a sequence of characters will be detected when it arrives. This happens because the driver needs to detect a signal change to detect data and some values don't have a signal change at their end. +There is one issue with this implementation. It is not guaranteed that the last character of a sequence of characters will be detected when it arrives. This happens because the driver needs to detect a signal change to detect data and some values don't have a signal change at their end. -The "late" character will be registered when the next character arrives. This is not a problem for devices such as GPS sensors and Air Quality sensors as these transmit data continuously, but it would be an issue if you used this mechanism on a user terminal connection. Having said that, you would not need to use edge triggering on such an interface, as your user will not type so quickly and continuously as to cause a problem. +The "late" character will be registered when the next character arrives. This is not a problem for devices such as GPS sensors and Air Quality sensors as these transmit data continuously, but it would be an issue if you used this mechanism on a user terminal connection. Having said that, you would not need to use edge triggering on such an interface, as your user will not type so quickly and continuously as to cause a problem. Rob Miles