chipKIT32 / chipKIT-core

Downloadable chipKIT core for use with Arduino 1.6 - 1.8+ IDE, PlatformIO, and UECIDE
http://chipkit.net/
Apache License 2.0
59 stars 53 forks source link

Set int flag #449

Closed majenkotech closed 5 years ago

majenkotech commented 5 years ago

This allows the triggering of an interrupt by software (simply setting the interrupt flag). This is especially useful if you want to make use of the two software interrupts SW0 and SW1.

The code is a direct copy-and-paste of clearIntFlag() with ifs->clr changed to ifs->set.

majenkotech commented 5 years ago

Test code:

void __USER_ISR blink() {
    static bool onoff = false;
    onoff = !onoff;
    digitalWrite(PIN_LED1, onoff);
    clearIntFlag(_CORE_SOFTWARE_0_IRQ);
}

void setup() {
    pinMode(PIN_LED1, OUTPUT);

    setIntVector(_CORE_SOFTWARE_0_VECTOR, blink);
    setIntPriority(_CORE_SOFTWARE_0_VECTOR, 4, 0);
    clearIntFlag(_CORE_SOFTWARE_0_IRQ);
    setIntEnable(_CORE_SOFTWARE_0_IRQ);
}

void loop() {
    delay(1000);
    setIntFlag(_CORE_SOFTWARE_0_IRQ);
}
EmbeddedMan commented 5 years ago

Very nice!