diff --git a/include/nanokernel.h b/include/nanokernel.h index 21a1af31010..4f6fc206cdf 100644 --- a/include/nanokernel.h +++ b/include/nanokernel.h @@ -90,6 +90,10 @@ extern void task_fiber_start(char *pStack, /* FIFO APIs */ extern void nano_fifo_init(struct nano_fifo *chan); +/* scheduling context independent methods (when context is not known) */ +extern void nano_fifo_put(struct nano_fifo *chan, void *data); +extern void *nano_fifo_get(struct nano_fifo *chan); +extern void *nano_fifo_get_wait(struct nano_fifo *chan); /* methods for ISRs */ extern void nano_isr_fifo_put(struct nano_fifo *chan, void *data); extern void *nano_isr_fifo_get(struct nano_fifo *chan); diff --git a/kernel/nanokernel/core/nano_mwfifo.c b/kernel/nanokernel/core/nano_mwfifo.c index f0abb216981..2441473b24d 100644 --- a/kernel/nanokernel/core/nano_mwfifo.c +++ b/kernel/nanokernel/core/nano_mwfifo.c @@ -192,9 +192,27 @@ void nano_task_fifo_put( irq_unlock_inline(imask); } +/******************************************************************************* +* +* nano_fifo_put - add an element to the end of a fifo +* +* This is a convenience wrapper for the context-specific APIs. This is +* helpful whenever the exact scheduling context is not known, but should +* be avoided when the context is known up-front (to avoid unnecessary +* overhead). +*/ +void nano_fifo_put(struct nano_fifo *chan, void *data) +{ + static void (*func[3])(struct nano_fifo *chan, void *data) = { + nano_isr_fifo_put, nano_fiber_fifo_put, nano_task_fifo_put + }; + func[context_type_get()](chan, data); +} + FUNC_ALIAS(_fifo_get, nano_isr_fifo_get, void *); FUNC_ALIAS(_fifo_get, nano_fiber_fifo_get, void *); FUNC_ALIAS(_fifo_get, nano_task_fifo_get, void *); +FUNC_ALIAS(_fifo_get, nano_fifo_get, void *); /******************************************************************************* * @@ -360,3 +378,23 @@ void *nano_task_fifo_get_wait( return data; } + +/******************************************************************************* +* +* nano_fifo_get_wait - get an element from the head of a fifo, poll/pend if +* not available +* +* This is a convenience wrapper for the context-specific APIs. This is +* helpful whenever the exact scheduling context is not known, but should +* be avoided when the context is known up-front (to avoid unnecessary +* overhead). +* +* It's only valid to call this API from a fiber or a task. +*/ +void *nano_fifo_get_wait(struct nano_fifo *chan) +{ + static void *(*func[3])(struct nano_fifo *chan) = { + NULL, nano_fiber_fifo_get_wait, nano_task_fifo_get_wait + }; + return func[context_type_get()](chan); +}