arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.23k stars 224 forks source link

Add support for bare-metal AVR #43

Closed kevinpt closed 6 years ago

kevinpt commented 6 years ago

I've added some changes to support using TaskScheduler on bare-metal AVR without the Arduino support libraries. Additional minor work is needed to do the same for ESP8266 and ESP32.

arkhipenko commented 6 years ago

Thanks. Will look into this after the holidays.

arkhipenko commented 6 years ago

Hi, I am a little concerned about this part:

#  if !(defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32))
#    error Missing ARDUINO_ARCH_* definition.
#  endif

Will it nor break other platforms, like teensy or other non-AVR ones which supply their own Arduino.h? I have never implemented this for bare-bones, so help is appreciated.

arkhipenko commented 6 years ago

I am thinking further: wouldn't a simpler and safer (from the compatibility perspective) way be to include a small local Arduino.h include with your changes for the bare-metal implementations? This way there is no need to change the library at all. (I am just trying to avoid platform-specific limitations as much as I can). What do you think?

arkhipenko commented 6 years ago

Upon further thinking I went with a explicit brute force approach:

#ifdef _TASK_BARE_METAL
    extern unsigned long micros(void);
    extern unsigned long millis(void);
    extern void yield(void);
    extern void delay(unsigned long);
#endif

All sketches seem to compile fine. Will push this into the testing branch. Could you please test once it is there?

Thanks

arkhipenko commented 6 years ago

Updated in the testing branch. Please test.

arkhipenko commented 6 years ago

As a matter of fact I don't think TaskScheduler uses yield()or delay(). I can just go with those:

#ifdef _TASK_BARE_METAL
    extern unsigned long micros(void);
    extern unsigned long millis(void);
#endif
arkhipenko commented 6 years ago

Will give you a little more time to test if you wish, otherwise will close this request.

kevinpt commented 6 years ago

I believe the plain ARDUINO define is also used if you want a platform independent check for the Arduino environment.

arkhipenko commented 6 years ago

Pushed v2.6.0 into the "testing" branch with bare metal fwd definitions. Could you please test? https://github.com/arkhipenko/TaskScheduler/tree/testing