Skip to content

Commit

Permalink
* Right interrupts implementation (more details: https://www.esp8266.c…
Browse files Browse the repository at this point in the history
  • Loading branch information
anakod authored and Slavey Karadzhov committed Oct 10, 2016
1 parent 25dbf7b commit c0fc7cb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Sming/Libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void IRAM_ATTR Adafruit_NeoPixel::show(void) {
// state, computes 'pin high' and 'pin low' values, and writes these back
// to the PORT register as needed.

//noInterrupts(); // Need 100% focus on instruction timing
ets_intr_lock();
noInterrupts(); // Need 100% focus on instruction timing
//ets_intr_lock();

boolean is800KHz=true;

Expand Down Expand Up @@ -150,8 +150,9 @@ void IRAM_ATTR Adafruit_NeoPixel::show(void) {
}
}
while((_getCycleCount() - startTime) < period); // Wait for last bit
ets_intr_unlock();
//interrupts();
//ets_intr_unlock();
interrupts();

endTime = micros(); // Save EOD time for latch on next call
}

Expand Down
8 changes: 7 additions & 1 deletion Sming/Libraries/RCSwitch/RCSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <user_config.h>
//#include <../../SmingCore/SmingCore.h>
#include "RCSwitch.h"

/* Format for protocol definitions:
Expand Down Expand Up @@ -462,6 +464,7 @@ char* RCSwitch::getCodeWordD(char sGroup, int nDevice, boolean bStatus){
*/
void RCSwitch::sendTriState(const char* sCodeWord) {
for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) {
xt_disable_interrupts();
int i = 0;
while (sCodeWord[i] != '\0') {
switch(sCodeWord[i]) {
Expand All @@ -477,7 +480,8 @@ void RCSwitch::sendTriState(const char* sCodeWord) {
}
i++;
}
this->sendSync();
this->sendSync();
xt_enable_interrupts();
}
}

Expand All @@ -487,6 +491,7 @@ void RCSwitch::send(unsigned long code, unsigned int length) {

void RCSwitch::send(const char* sCodeWord) {
for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) {
xt_disable_interrupts();
int i = 0;
while (sCodeWord[i] != '\0') {
switch(sCodeWord[i]) {
Expand All @@ -500,6 +505,7 @@ void RCSwitch::send(const char* sCodeWord) {
i++;
}
this->sendSync();
xt_enable_interrupts();
}
}

Expand Down
3 changes: 0 additions & 3 deletions Sming/SmingCore/Digital.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include "../SmingCore/ESP8266EX.h"
#include "../Wiring/WiringFrameworkDependencies.h"

//#define interrupts() sei()
//#define noInterrupts() cli()

/** @brief Set the mode of a GPIO pin
* @param pin GPIO pin to configure
* @param mode Mode of pin [INPUT | INPUT_PULLUP | OUTPUT]
Expand Down
6 changes: 4 additions & 2 deletions Sming/SmingCore/Interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ GPIO_INT_TYPE ConvertArduinoInterruptMode(uint8_t mode)

void noInterrupts()
{
ETS_INTR_LOCK();
//ETS_INTR_LOCK();
xt_disable_interrupts(); // https://www.esp8266.com/viewtopic.php?p=16758
}
void interrupts()
{
ETS_INTR_UNLOCK();
//ETS_INTR_UNLOCK();
xt_enable_interrupts();
}

static void IRAM_ATTR interruptHandler(uint32 intr_mask, void *arg)
Expand Down
3 changes: 3 additions & 0 deletions Sming/system/include/esp_systemapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ extern void ets_intr_unlock();
extern void ets_update_cpu_frequency(uint32_t frq);
extern uint32_t ets_get_cpu_frequency();

extern void xt_disable_interrupts();
extern void xt_enable_interrupts();

typedef signed short file_t;

#endif
16 changes: 16 additions & 0 deletions Sming/system/xt_interrupts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <user_config.h>

static uint32_t interruptState = 0;

void xt_disable_interrupts()
{
__asm__ __volatile__("rsil %0,15":"=a" (interruptState));
__asm__("esync");
__asm__("isync");
__asm__("dsync");
}
void xt_enable_interrupts()
{
__asm__ __volatile__("wsr %0,ps"::"a" (interruptState) : "memory");
__asm__("esync");
}

0 comments on commit c0fc7cb

Please sign in to comment.