Rybec / pyRTOS

RTOS written in pure Python, designed for use with CircuitPython
MIT License
150 stars 28 forks source link

Pi Pico (second core) ? #15

Open g0730n opened 9 months ago

g0730n commented 9 months ago

Is there any way to add functionality for tasks to run on second core of Pi Pico?

Rybec commented 9 months ago

Sadly, CircuitPython does not have any kind of multi-core functionality, so there is not. If you are working in MicroPython, it might be possible to do that manually, by making a task that runs code on the second core and then periodically checks in with that code and handles communication for it. Note though, that this does not officially support MicroPython, so if you run into issues, it's up to you to figure them out. (That said, I've helped out people working into MicroPython before, and I don't mind it if you open an issue for a problem found in MicroPython. Just understand that I can't guarantee that I'll fix it. I may instead just mention incompatibilities in the documentation or suggest alterations you could make to fix the issue. I just don't have the time to maintain two separate ports.)

If at some point CircuitPython adds this functionality, I may provide some way to use it in pyRTOS, but I'm not certain it is necessary. It shouldn't be very difficult to do what I suggested above, making a task that runs a function on another core and then communicates with that function through some shared variable. You would want to use Python's built-in mutex locks though, as the pyRTOS locks rely on the single threaded nature of CircuitPython to avoid race conditions within the locks themselves.

g0730n commented 9 months ago

Okay just checking. I haven't tried circuit python, or tested pyRTOS yet but will test it on my pico with micropython, thanks!

Rybec commented 9 months ago

You may have issues with some timing functions, as MicroPython doesn't support all of the same ones as CircuitPython (last time I checked, anyhow...). See issue #9 for some potential solutions.