Hi,
I had to move from the commonly found 'statically allocated' os_event
usage pattern to something dynamic.
This is what I'm using:
// Post event:
struct os_event* my_event = (struct os_event
*)os_memblock_get(&bleprph_mbuf_mpool);
if (!my_event) {
// TODO: scream loudly
return;
}
my_event->ev_queued = 0;
my_event->ev_arg = arg;
my_event->ev_type=OS_EVENT_T_PERUSER+1; // *1
my_event(&MY_EVENT_QUEUE, my_event);
// Poll handler:
case OS_EVENT_T_PERUSER+1:
my_data = ev->ev_arg;
os_eventq_remove(&btask_evq, ev);
os_memblock_put(&task_mbuf_mpool, ev); //* 2
process_data(my_data);
break;
This seems to work and will fail quickly (reset) if step *2 isn't
performed, but I have some questions.
1. Is this really correct? I've not seen it in the samples or the docs.
2. The samples and docs didn't make *2 obvious, e.g. who owns the memory
pool.
3. Would it be better if the Task didn't care which pool the memory came
from? i.e. inter task events.
4. I've assumed OS_EVENT_T_PERUSER+n is a valid thing todo, is it? until
what n? is there a documented range limit?
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;
}
At *1 a default application pool, registered with the OS, is used (which
would require additional API and setup in the application main startup)
// Poll:
struct os_event ev;
os_eventq_get(&task_evq, &ev); // *1
switch (ev->ev_type) {
case OS_EVENT_T_PERUSER+1:
my_data = ev->ev_arg;
process_data(my_data);
break;
}
At *1 the event data is copied and the event itself is released by '
os_eventq_get'
All the best
Wayne