I thought the same Frank - Maybe I made a bad start of it - but I tried it once and it wasn't faster? And yes, lots of overhead to allocate a bool, set the bool, test the bool: a few times over.
It is nice to just kill the 'weak' yield() - but that is broken. As noted "EventResponder is a WIP it seems PJRC might incorporate best answer" ... but alas a week after posting and no answer . . .
Manitou first noted in p#3 that it was EventResponder - but referred to IDE build - but this is a bug in TeensyDuino build when the hack to yield() was introduced?
It was 3 months back - I just posted a comment on github: This yield.cpp change for EventResponder::runFromYield(); breaks removal of 'weak' yield and results in a non-functional upload when that common practice is done. and linked back to this thread.
Testing one bool is for sure way faster than 7 times calling a function "SerialX.available()"..
In addition even the tests in the brackets if (!running && flag) {if SerialX.available()...} can be saved if the flag is used in a smart way: Bitwise. Bit #0 for Serial1, bit#1 for Serial2... and setting back to 0 in read()...
Edit: Maybe something like this:
Code:
void yield(void)
{
static uint8_t running=0;
if (running) return; // TODO: does this need to be atomic? [B]<- no.[/B]
running = 1;
int flag = RealNameOfTheVolatileFlag;
if (flag) {
if (flag & 0x01) serialEvent();
if (flag & 0x02) serialEvent1();
if (flag & 0x04) serialEvent2();
if (flag & 0x08) serialEvent3();
#ifdef HAS_KINETISK_UART3
if (flag & 0x10) serialEvent4();
#endif
#ifdef HAS_KINETISK_UART4
if (flag & 0x20) serialEvent5();
#endif
#if defined(HAS_KINETISK_UART5) || defined (HAS_KINETISK_LPUART0)
if (flag & 0x40) serialEvent6();
#endif
}
running = 0;
EventResponder::runFromYield();
};
EventResponder::runFromYield(); needs a similar bit in the flag - and its own timer.
Edit: Doesn't this prevent including of the SerialX Code too ?
Last edited: