summaryrefslogtreecommitdiff
path: root/board/discovery-stm32f072
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2015-05-13 13:26:12 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-05-26 19:36:21 +0000
commit855646e36bebce29b929178cfb3c73b8f259c8b6 (patch)
treec0fcdc616da4ade170502a0cb842d70d1c44821b /board/discovery-stm32f072
parenta0ebf0a008670ece41529a2fce01882192331c6e (diff)
downloadchrome-ec-855646e36bebce29b929178cfb3c73b8f259c8b6.tar.gz
Producer/Consumer: Refactor to use Queue policies
Previously the Producer and Consumer interfaces tracked the Consumer and Producer respectively at the other end of the queue that they interacted with. This was done to avoid modifying the queue implementation, but resulted in a rougher interface that required additional initialization steps and prevented alternative configurations; many producers and one consumer for example. This commit uses the new queue policies to track this information. The new direct policy behaves as the old producer and consumers did. Now the producers and consumers are just named references to the queue that they work on and a convenient location for a notification callback when the queue is updated in a way that is relevent to the producer or consumer. All users of Producer and Consumer have been updated including the stream adaptors which are in use by the echo test code and the mcdp28x0 driver. Use of the stream adaptors has also been simplified. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Manual testing of Ryu (P5) and discovery board echo task Change-Id: I704be6378a31b4e20f5063295eff9943e4900409 Reviewed-on: https://chromium-review.googlesource.com/271792 Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Trybot-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org>
Diffstat (limited to 'board/discovery-stm32f072')
-rw-r--r--board/discovery-stm32f072/echo.c67
1 files changed, 21 insertions, 46 deletions
diff --git a/board/discovery-stm32f072/echo.c b/board/discovery-stm32f072/echo.c
index 8b1c60314c..22b42623ca 100644
--- a/board/discovery-stm32f072/echo.c
+++ b/board/discovery-stm32f072/echo.c
@@ -13,6 +13,7 @@
#include "console.h"
#include "panic.h"
#include "task.h"
+#include "queue_policies.h"
#include "stream_adaptor.h"
#include "timer.h"
#include "usart-stm32f0.h"
@@ -29,49 +30,23 @@ static void out_ready(struct out_stream const *stream)
task_wake(TASK_ID_ECHO);
}
-#define USART_STREAM_CONFIG(NAME, \
- HW, \
- BAUD, \
- RX_SIZE, \
- TX_SIZE, \
- IN_READY, \
- OUT_READY) \
- \
- static struct queue const CONCAT2(NAME, _rx_queue) = \
- QUEUE_NULL(RX_SIZE, uint8_t); \
- static struct queue const CONCAT2(NAME, _tx_queue) = \
- QUEUE_NULL(TX_SIZE, uint8_t); \
- \
- struct usart_config const NAME; \
- \
- IN_STREAM_FROM_PRODUCER(CONCAT2(NAME, _in), \
- NAME.producer, \
- CONCAT2(NAME, _rx_queue), \
- IN_READY) \
- OUT_STREAM_FROM_CONSUMER(CONCAT2(NAME, _out), \
- NAME.consumer, \
- CONCAT2(NAME, _tx_queue), \
- OUT_READY) \
- \
- USART_CONFIG(NAME, \
- HW, \
- BAUD, \
- CONCAT2(NAME, _rx_queue), \
- CONCAT2(NAME, _tx_queue), \
- CONCAT2(NAME, _in).consumer, \
- CONCAT2(NAME, _out).producer)
-
-USART_STREAM_CONFIG(usart1, usart1_hw, 115200, 64, 64, in_ready, NULL);
-USART_STREAM_CONFIG(usart3, usart3_hw, 115200, 64, 64, in_ready, NULL);
-USART_STREAM_CONFIG(usart4, usart4_hw, 115200, 64, 64, in_ready, NULL);
-
-static struct queue const usb_rx_queue = QUEUE_NULL(256, uint8_t);
-static struct queue const usb_tx_queue = QUEUE_NULL(256, uint8_t);
-
+/*
+ * Forward declare all device configurations so that they can be used to
+ * construct appropriate queue policies within the IO_STREAM_CONFIG macro.
+ */
+struct usart_config const usart1;
+struct usart_config const usart3;
+struct usart_config const usart4;
struct usb_stream_config const usb_stream1;
-IN_STREAM_FROM_PRODUCER(usb_in, usb_stream1.producer, usb_rx_queue, in_ready)
-OUT_STREAM_FROM_CONSUMER(usb_out, usb_stream1.consumer, usb_tx_queue, out_ready)
+IO_STREAM_CONFIG(usart1, 64, 64, in_ready, NULL)
+IO_STREAM_CONFIG(usart3, 64, 64, in_ready, NULL)
+IO_STREAM_CONFIG(usart4, 64, 64, in_ready, NULL)
+IO_STREAM_CONFIG(usb_stream1, 256, 256, in_ready, out_ready)
+
+USART_CONFIG(usart1, usart1_hw, 115200, usart1_rx_queue, usart1_tx_queue)
+USART_CONFIG(usart3, usart3_hw, 115200, usart3_rx_queue, usart3_tx_queue)
+USART_CONFIG(usart4, usart4_hw, 115200, usart4_rx_queue, usart4_tx_queue)
USB_STREAM_CONFIG(usb_stream1,
USB_IFACE_STREAM,
@@ -79,10 +54,8 @@ USB_STREAM_CONFIG(usb_stream1,
USB_EP_STREAM,
64,
64,
- usb_rx_queue,
- usb_tx_queue,
- usb_in.consumer,
- usb_out.producer)
+ usb_stream1_rx_queue,
+ usb_stream1_tx_queue)
struct stream_console_state {
size_t wrote;
@@ -106,7 +79,9 @@ struct stream_console_config {
STREAM_CONSOLE_CONFIG(usart1_stream_console, &usart1_in.in, &usart1_out.out)
STREAM_CONSOLE_CONFIG(usart3_stream_console, &usart3_in.in, &usart3_out.out)
STREAM_CONSOLE_CONFIG(usart4_stream_console, &usart4_in.in, &usart4_out.out)
-STREAM_CONSOLE_CONFIG(usb_stream1_console, &usb_in.in, &usb_out.out)
+STREAM_CONSOLE_CONFIG(usb_stream1_console,
+ &usb_stream1_in.in,
+ &usb_stream1_out.out)
static struct stream_console_config const *const consoles[] = {
&usart1_stream_console,