Generic background tasks in C #18788
Replies: 2 comments
-
|
I think there would be a lot of interest in a software UART: this has been discussed a few times but as far as I know there is no well-proven implementation. As for timing one approach might be to investigate how soft (virtual) timers are implemented (https://docs.micropython.org/en/latest/library/machine.Timer.html). |
Beta Was this translation helpful? Give feedback.
-
|
I've sorted out most of a machine.VirtualUART and aside from the background task side of things, it works fine. Project I'm working on needs to use the USB port on an ESP32 to run PPP over serial. I've managed to disable REPL on the USB port and now with the aid of my new VirtualUART, CDCInterface and one other 'glue' Python class using _thread to keep the i/o flowing between them, PPP has just come up on the USB port of an ESP32 this afternoon, while REPL works on the UART (for debugging). So I'm off to crack open a beer!
I'll look at the machine.Timer and see if that helps me clean things up. Happy to share VirtualUART as a PR - it's clearly working, but if the Timer stuff lets me refine it, then I'll do that first. To be honest, after finding the mp_sched_schedule function (which got me past the context crashing issues), in a naive way, a simple solution might be to add a mp_sched_schedule_after() function with an argument of how long before it gets added to the queue. As this is MP (and indeed Python) day 10, I really have no idea how easy/difficult that is! I'm not 100% sure MICROPY_ENABLE_SCHEDULER is set on all plaftorms, so I've used it if it is, otherwise fall back to mp_call_function_1; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm working on a C based virtualUART class/object which will behave like a normal UART on one side and give a developer access to the in/out buffers on the other side, so they can then abstract and hook it up to whatever they choose. My own 'itch' is to get PPP running over the USB serial connection on an ESP32, but that's irrelevant here - but does explain why I'm doing this.
Currently have all the read & write methods sorted - the one I need to provide a generic solution to is the 'irq' function. Ideally I want to do this without having to put h/w specifc code in and use generic MP functions - if they are available.
irq on RX is easy - once data arrives call the IRQ handler.
irq on RXIDLE (which the PPP class wants) is where I'm stuck - I need to ack the data arriving but at a 'later time', call the IRQ handler. This needs a timer and some sort of background task.
I'm testing on ESP32 and unix, both of which I know have threads etc in C, and I've started to look at the functions around the scheduler, but that doesn't seem to be built into MP by default.
Is there any advice for how to do a low level timer callback that's generic across all platforms (so uses an existing MP abstracted function)?
I'm proficient with C and coding - hey I've got this far 2 weeks after 'finding' MP. Just need the guidance of the sages as to whether such functions etc exist and I can then go look at code.
Beta Was this translation helpful? Give feedback.
All reactions