energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
794 stars 672 forks source link

EMT: delay() without yield #679

Open rei-vilo opened 9 years ago

rei-vilo commented 9 years ago

delay() is often used for bit-banging protocols like I²C, Serial and SPI.

By default, delay() yield at other tasks under Energia MT.

How to use delay() without yielding?

This may solve #675 as noInterrupts(); and interrupts(); are used to protect the code in-between from other interrupts.

rei-vilo commented 9 years ago

Suggested solution:

void delay(uint32_t milliseconds, bool NoYield = false);

with

void delay(uint32_t milliseconds, bool NoYield)
{
    if (NoYield)
    {
        uint32_t chrono = millis() + milliseconds;
        while (millis() < chrono);
    }
    else
    {
        Task_sleep(milliseconds);
    }
}