poll() versus spin on any()

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

poll() versus spin on any()

Post by dbc » Mon Oct 19, 2015 11:57 pm

What is to be gained by calling poll() versus spinning on any() for the current PyBoard peripherals? Does it reduce latency?

Related, I note that the CAN peripheral is not enabled as a stream. It would be a little strange, in that it has two receive fifo's, but I guess there would be one CAN stream interface and then after poll() the user would call both can_instance.any(0) and can_instance.any(1) to see where data might be found.

Also, I presume the can.rxcallback function runs at interrupt level, correct?

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: poll() versus spin on any()

Post by Damien » Tue Oct 20, 2015 9:49 pm

poll() will basically spin in a loop, calling any() on all the streams that you pass in, and executing a WFI if nothing is ready, before looping again.

poll() is useful when waiting on multiple streams. Otherwise you can just use any() in a loop (with a pyb.wif() if you like to reduce power consumption).

You can poll() a CAN object, but it does not have read/write methods. I don't think they are sensible, since send must specify an address as well as the data, and recv must specify the fifo.

CAN callbacks run at interrupt level, like all callbacks.

Post Reply