To make the VM not block the other RTOS tasks, I insert RTOS_sleep() in vm.c:DISPATCH() so that after every bytecode is executed, the VM relinquishes control to the next RTOS task.
I created a uPy interface to asynchronously obtain data from a CAN bus, similar to producer-consumer design pattern. The abstraction I chose is a queue, similar to https://github.com/peterhinch/micropyth ... d#35-queue
Usage in uPy:
Code: Select all
can_q = CANbus.queue()
message = can_q.get()
The implementation is basically (C-code):
Code: Select all
while(c_queue_empty() == true) RTOS_sleep(); // gives chance for c-queue to be filled
return c_queue_get_message();
I cannot directly use micropython-uasyncio.queues because my producer is asynchronous to the uPy script since it occurs at the C-level.
How do I implement can_q.get() so that I can await on the call to can_q.get() so can_q.get() doesn't block uPy?