co operative multi tasking with ets_task

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

co operative multi tasking with ets_task

Post by mianos » Sat Sep 03, 2016 1:03 am

In my previous esp micropython fork I created an os_task module for mp that wrapped the ESP SDK version of ets_task.
Then, from an interrupt handler (or a timer) I posted to the os_task python callback.

Doing things this way allowed me to have a repl and also handle buttons and devices as the os_task got called when the repl
was back, giving me a really easy co-operative threaded environment.

(To use this, I created a circular queue module that did not do any allocation using pre-allocated buffers, and could post to this queue in my interrupt handler, followed by a post to os_task. Then, when the task was started, it could read off the queue.
For example, I had a switch on the interrupt line then used a timer to de-debounce it, then sent the switch state to the queue and posted to my os_task handler, which turned on the light).

I made a new os_task module but it seems it is not valid to call a python function from the new custom ets_task function.
https://gist.github.com/mianos/3cfa911a ... 7bd0e9d371

Does anyone have any thoughts as to why it would crash mp if I do this again?
Is this a valid way still or is there a better way to block on both the repl and a task queue?

Post Reply