Giving core 0 work from core 1 via a interrupt or lock #11999
Replies: 2 comments 4 replies
-
Core 1 sets up the data in cross_thread.data by calling cross_thread.set_data(msg, core_0_does_this, "foo"). This function sets the msg, fn, args, and kwargs in cross_thread.data. Core 1 triggers an interrupt on a specific pin (Pin 25 in this case), which calls the do_the_thing(pin) function on Core 0. Core 0 reads the data from cross_thread.data in the do_the_thing(pin) function and executes the function specified in cross_thread.data["fn"] with the provided arguments (cross_thread.data["args"] and cross_thread.data["kwargs"]). The result of the function call is then passed back to Core 1 via the message object (msg). Core 1 waits for the message object to be set and retrieves the result from it using reply = await msg. Core 1 prints the result obtained from Core 0 and repeats the process in a loop. Core 0 runs the uasyncio event loop with the main() coroutine. A separate thread (_main()) is started on Core 0 to execute the uasyncio event loop. In the main loop (while True) on Core 1, a delay of 1 second is added to allow Core 0 to handle the tasks and execute the uasyncio event loop. This approach allows you to achieve collaborative multitasking on the Raspberry Pi Pico H using both cores. Core 1 offloads tasks to Core 0, which efficiently handles them through uasyncio. |
Beta Was this translation helpful? Give feedback.
-
A couple of thoughts. Have you considered using Secondly, while this is an interesting exercise and useful information, I'm unclear about practical use-cases. My approach is to run A random idea (this is the ideas thread). Damien once mentioned that it would be good if an instance of |
Beta Was this translation helpful? Give feedback.
-
Here is a demo script (tested on my PICO H)
uasyncio can only be used on a single core... some things only work on core 0 (eg use the network on a pico W)
But how can we have core 0 do work on behalf of core 1? Here is my solution, maybe there is a better way but this works
Alternate version using a lock instead of a interrupt, seems less useful since you are going to get anything else done on core 0, but if you need to debug it and thing it is cause it is a interrupt making it not work it is useful
Beta Was this translation helpful? Give feedback.
All reactions