Thanks Chris,
On 4 November 2016 at 18:11, Christopher Collins <[email protected]>
wrote:
> Hi Wayne,
>
> Good question. I'll address the specifics below, but I should mention
> that OS event handling has undergone some fairly major changes in recent
> days. Later today, I will send a follow up email to the dev list
> detailing these changes and the rationale.
>
ok cool.
> It would be nice to have the API that perhaps look something like this:
> >
> > // Post:
> > rc = my_event(&MY_EVENT_QUEUE, OS_EVENT_T_PERUSER+1, arg ); //*1
> > if (rc) {
> > // TODO: scream loudly
> > return;
> > }
> >
> >
>
> I think this is a good idea that is safer than the current approach.
> However, I believe there are tradeoffs involved. If an event knows how
> to free itself, then it must either:
>
> 1. contain a pointer to its source pool, or
> 2. come from the same pool as all other events.
>
> But I could be missing something. Do you see another option?
>
nope.
> The first option increases the size of each event, even events which
> are statically allocated. The second solution restricts how much
> control the developer has, as you can no longer pre-allocate for a set
> number of events of a particular type. Others can certainly chime in,
> but personally I don't know that I'm comfortable with either of these
> tradeoffs.
>
The expectation is that most events will be statically
> allocated, so I think it is important to keep that path simple and
> efficient.
'm totally with you on it's best to keep Mynewt simple; an application
developer can pass a user defined struct to the arg which has the actual
user data and also a pointer to the pool to be freed; they can also create
their own convenience functions/macros around it.
In my case I'm (currently) passing inbound serial character data as an
event, in order to decouple the IRQ handler context from the MicroPython
interpreter and it's REPL.
Eventually I'll switch back to using the Console when it has the low level
TX/RX handler support, ticket #469.
But, I also need to use the same pattern to decouple GPIO IRQ's and the
Python callbacks, in order to support this:
from gpiozero import Button
def buttonA_pressed():
print("Button pressed.")
buttonA = Button(17)
buttonA.when_pressed(buttonA_pressed)
(In case you were wondering, I back ported the 0.10.0 nRF GPIO HAL to
0.9.0, thanks Will :)
So the event struct wrapping and helper function could become a much more
commonly used pattern as 3rd party libraries (which hook in into IRQ's and
events) and other scripting languages are ported to Mynewt.
I'm now not suggesting change what's in the core, instead, perhaps make
available a simple struct wrapper and support functions/macros as
'codified' best practice of this pattern.
I can take a look at creating a PR once I've seen the latest Event API and
am closer to the v1.0 codebase.
All the best
Wayne