From 68224c1c6989734ae062d95cfebc018c84a6c7cd Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 16 Apr 2015 12:23:55 +0300 Subject: [PATCH] nanokernel: Add scheduling context-independent APIs for nano_fifo When the exact scheduling context is not known it's convenient to have a wrapper API that uses context_type_get() to call the right function at runtime. Change-Id: Ie72a4b78d53f664575c1d9dfeace52b53d018850 Signed-off-by: Johan Hedberg --- include/nanokernel.h | 4 +++ kernel/nanokernel/core/nano_mwfifo.c | 38 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) 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); +}