Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Garcia <danielgarcia@gmail.com>2016-06-02 10:23:43 +0300
committerDaniel Garcia <danielgarcia@gmail.com>2016-06-02 10:23:43 +0300
commit96704eefab0e3660ab0fb009b0b84c5336ae65fb (patch)
treefb54fd56cebcc06d341cdbf06e31c6efe6750afd
parent1b546b31896dd2c4d95c16bb17c852b3d8177eb1 (diff)
Change how we do the timing to reduce the risk of running a long loop and kicking off the watchdog timer on the esp8266 - see comments in #306
-rw-r--r--platforms/esp/8266/clockless_block_esp8266.h30
-rw-r--r--platforms/esp/8266/clockless_esp8266.h24
2 files changed, 27 insertions, 27 deletions
diff --git a/platforms/esp/8266/clockless_block_esp8266.h b/platforms/esp/8266/clockless_block_esp8266.h
index 7ef284e7..90690c3c 100644
--- a/platforms/esp/8266/clockless_block_esp8266.h
+++ b/platforms/esp/8266/clockless_block_esp8266.h
@@ -80,7 +80,7 @@ public:
#define ESP_ADJUST 0 // (2*(F_CPU/24000000))
#define ESP_ADJUST2 0
- template<int BITS,int PX> __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & next_mark, register Lines & b, PixelController<RGB_ORDER, LANES, PORT_MASK> &pixels) { // , register uint32_t & b2) {
+ template<int BITS,int PX> __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & last_mark, register Lines & b, PixelController<RGB_ORDER, LANES, PORT_MASK> &pixels) { // , register uint32_t & b2) {
Lines b2 = b;
transpose8x1_noinline(b.bytes,b2.bytes);
@@ -88,28 +88,28 @@ public:
register uint8_t scale = pixels.template getscale<PX>(pixels);
for(register uint32_t i = 0; i < USED_LANES; i++) {
- while((int32_t)(next_mark - __clock_cycles()) > 0);
- next_mark = __clock_cycles() + (T1+T2+T3) + ESP_ADJUST;
+ while((__clock_cycles() - last_mark) < (T1+T2+T3));
+ last_mark = __clock_cycles();
*FastPin<FIRST_PIN>::sport() = PORT_MASK << FIRST_PIN;
- while((int32_t)(next_mark - __clock_cycles()) > (T2+T3+ESP_ADJUST2));
+ while((__clock_cycles() - last_mark) < T1);
*FastPin<FIRST_PIN>::cport() = ((uint32_t)(~b2.bytes[7-i]) & PORT_MASK) << FIRST_PIN;
- while((int32_t)(next_mark - __clock_cycles()) > (T3 + ESP_ADJUST));
+ while((__clock_cycles() - last_mark) < (T1+T2));
*FastPin<FIRST_PIN>::cport() = PORT_MASK << FIRST_PIN;
b.bytes[i] = pixels.template loadAndScale<PX>(pixels,i,d,scale);
}
for(register uint32_t i = USED_LANES; i < 8; i++) {
- while((int32_t)(next_mark - __clock_cycles()) > 0);
- next_mark = __clock_cycles() + (T1+T2+T3) + ESP_ADJUST;
+ while((__clock_cycles() - last_mark) < (T1+T2+T3));
+ last_mark = __clock_cycles() + (T1+T2+T3) + ESP_ADJUST;
*FastPin<FIRST_PIN>::sport() = PORT_MASK << FIRST_PIN;
- while((int32_t)(next_mark - __clock_cycles()) > (T2+T3+ESP_ADJUST2));
+ while((__clock_cycles() - last_mark) < T1);
*FastPin<FIRST_PIN>::cport() = ((uint32_t)(~b2.bytes[7-i]) & PORT_MASK) << FIRST_PIN;
- while((int32_t)(next_mark - __clock_cycles()) > (T3 + ESP_ADJUST));
+ while((__clock_cycles() - last_mark) < (T1+T2));
*FastPin<FIRST_PIN>::cport() = PORT_MASK << FIRST_PIN;
}
}
@@ -128,18 +128,18 @@ public:
os_intr_lock();
uint32_t _start = __clock_cycles();
- uint32_t next_mark = _start;
+ uint32_t last_mark = _start;
while(allpixels.has(1)) {
// Write first byte, read next byte
- writeBits<8+XTRA0,1>(next_mark, b0, allpixels);
+ writeBits<8+XTRA0,1>(last_mark, b0, allpixels);
// Write second byte, read 3rd byte
- writeBits<8+XTRA0,2>(next_mark, b0, allpixels);
+ writeBits<8+XTRA0,2>(last_mark, b0, allpixels);
allpixels.advanceData();
// Write third byte
- writeBits<8+XTRA0,0>(next_mark, b0, allpixels);
+ writeBits<8+XTRA0,0>(last_mark, b0, allpixels);
#if (FASTLED_ALLOW_INTERRUPTS == 1)
os_intr_unlock();
@@ -150,8 +150,8 @@ public:
#if (FASTLED_ALLOW_INTERRUPTS == 1)
os_intr_lock();
// if interrupts took longer than 45µs, punt on the current frame
- if((int32_t)(__clock_cycles()-next_mark) > 0) {
- if((int32_t)(__clock_cycles()-next_mark) > ((WAIT_TIME-INTERRUPT_THRESHOLD)*CLKS_PER_US)) { os_intr_unlock(); return 0; }
+ if((int32_t)(__clock_cycles()-last_mark) > 0) {
+ if((int32_t)(__clock_cycles()-last_mark) > (T1+T2+T3+((WAIT_TIME-INTERRUPT_THRESHOLD)*CLKS_PER_US))) { os_intr_unlock(); return 0; }
}
#endif
};
diff --git a/platforms/esp/8266/clockless_esp8266.h b/platforms/esp/8266/clockless_esp8266.h
index 668a8ad1..5e6d0a08 100644
--- a/platforms/esp/8266/clockless_esp8266.h
+++ b/platforms/esp/8266/clockless_esp8266.h
@@ -39,7 +39,7 @@ protected:
int cnt = FASTLED_INTERRUPT_RETRY_COUNT;
while(!showRGBInternal(pixels) && cnt--) {
os_intr_unlock();
- delayMicroseconds(WAIT_TIME * 10);
+ delayMicroseconds(WAIT_TIME * 20);
os_intr_lock();
showRGBInternal(pixels);
}
@@ -49,18 +49,18 @@ protected:
#define _ESP_ADJ (0)
#define _ESP_ADJ2 (0)
- template<int BITS> __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & next_mark, register uint32_t b) {
+ template<int BITS> __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & last_mark, register uint32_t b) {
b = ~b; b <<= 24;
for(register uint32_t i = BITS; i > 0; i--) {
- while((int32_t)(next_mark - __clock_cycles()) > 0);
- next_mark = __clock_cycles() + (T1+T2+T3 + _ESP_ADJ);
+ while((__clock_cycles() - last_mark) < (T1+T2+T3));
+ last_mark = __clock_cycles();
FastPin<DATA_PIN>::hi();
- while((int32_t)(next_mark - __clock_cycles()) > (T2+T3 + _ESP_ADJ2));
+ while((__clock_cycles() - last_mark) < T1);
if(b & 0x80000000L) { FastPin<DATA_PIN>::lo(); }
b <<= 1;
- while((int32_t)(next_mark - __clock_cycles()) > (T3 + _ESP_ADJ));
+ while((__clock_cycles() - last_mark) < (T1+T2));
FastPin<DATA_PIN>::lo();
}
}
@@ -74,18 +74,18 @@ protected:
pixels.preStepFirstByteDithering();
os_intr_lock();
uint32_t start = __clock_cycles();
- uint32_t next_mark = start + (T1+T2+T3 + _ESP_ADJ);
+ uint32_t last_mark = start;
while(pixels.has(1)) {
// Write first byte, read next byte
- writeBits<8+XTRA0>(next_mark, b);
+ writeBits<8+XTRA0>(last_mark, b);
b = pixels.loadAndScale1();
// Write second byte, read 3rd byte
- writeBits<8+XTRA0>(next_mark, b);
+ writeBits<8+XTRA0>(last_mark, b);
b = pixels.loadAndScale2();
// Write third byte, read 1st byte of next pixel
- writeBits<8+XTRA0>(next_mark, b);
+ writeBits<8+XTRA0>(last_mark, b);
b = pixels.advanceAndLoadAndScale0();
#if (FASTLED_ALLOW_INTERRUPTS == 1)
@@ -97,8 +97,8 @@ protected:
#if (FASTLED_ALLOW_INTERRUPTS == 1)
os_intr_lock();
// if interrupts took longer than 45µs, punt on the current frame
- if((int32_t)(__clock_cycles()-next_mark) > 0) {
- if((int32_t)(__clock_cycles()-next_mark) > ((WAIT_TIME-INTERRUPT_THRESHOLD)*CLKS_PER_US)) { sei(); return 0; }
+ if((int32_t)(__clock_cycles()-last_mark) > 0) {
+ if((int32_t)(__clock_cycles()-last_mark) > (T1+T2+T3+((WAIT_TIME-INTERRUPT_THRESHOLD)*CLKS_PER_US))) { sei(); return 0; }
}
#endif
};