summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/discovery-stm32f072/board.h1
-rw-r--r--board/discovery-stm32f072/build.mk2
-rw-r--r--board/discovery-stm32f072/ec.tasklist3
-rw-r--r--board/discovery-stm32f072/echo.c175
-rw-r--r--board/hoho/board.h1
-rw-r--r--chip/stm32/usart.h2
-rw-r--r--chip/stm32/usb-stream.h2
-rw-r--r--common/build.mk1
-rw-r--r--common/in_stream.c19
-rw-r--r--common/out_stream.c24
-rw-r--r--common/queue_policies.c15
-rw-r--r--common/stream_adaptor.c71
-rw-r--r--driver/mcdp28x0.c24
-rw-r--r--include/config.h9
-rw-r--r--include/in_stream.h54
-rw-r--r--include/out_stream.h77
-rw-r--r--include/queue_policies.h8
-rw-r--r--include/stream_adaptor.h107
18 files changed, 41 insertions, 554 deletions
diff --git a/board/discovery-stm32f072/board.h b/board/discovery-stm32f072/board.h
index 025c72de48..e8a83a47e7 100644
--- a/board/discovery-stm32f072/board.h
+++ b/board/discovery-stm32f072/board.h
@@ -12,7 +12,6 @@
#define CPU_CLOCK 48000000
/* Enable USART1,3,4 and USB streams */
-#define CONFIG_STREAM
#define CONFIG_STREAM_USART
#define CONFIG_STREAM_USART1
#define CONFIG_STREAM_USART3
diff --git a/board/discovery-stm32f072/build.mk b/board/discovery-stm32f072/build.mk
index d8a22a6ad5..f3d39ab655 100644
--- a/board/discovery-stm32f072/build.mk
+++ b/board/discovery-stm32f072/build.mk
@@ -10,4 +10,4 @@ CHIP:=stm32
CHIP_FAMILY:=stm32f0
CHIP_VARIANT:=stm32f07x
-board-y=board.o echo.o
+board-y=board.o
diff --git a/board/discovery-stm32f072/ec.tasklist b/board/discovery-stm32f072/ec.tasklist
index 6a623f151c..fa284f1a0c 100644
--- a/board/discovery-stm32f072/ec.tasklist
+++ b/board/discovery-stm32f072/ec.tasklist
@@ -18,5 +18,4 @@
*/
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(ECHO, echo_task, NULL, TASK_STACK_SIZE)
+ TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE)
diff --git a/board/discovery-stm32f072/echo.c b/board/discovery-stm32f072/echo.c
deleted file mode 100644
index 63a0360d94..0000000000
--- a/board/discovery-stm32f072/echo.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-/*
- * Task to echo any characters from the three non-console USARTs back to all
- * non-console USARTs.
- */
-
-#include "atomic.h"
-#include "common.h"
-#include "compile_time_macros.h"
-#include "console.h"
-#include "panic.h"
-#include "task.h"
-#include "queue_policies.h"
-#include "stream_adaptor.h"
-#include "timer.h"
-#include "usart-stm32f0.h"
-#include "usb-stream.h"
-#include "util.h"
-
-static void in_ready(struct in_stream const *stream)
-{
- task_wake(TASK_ID_ECHO);
-}
-
-static void out_ready(struct out_stream const *stream)
-{
- task_wake(TASK_ID_ECHO);
-}
-
-/*
- * 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;
-
-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,
- USB_STR_STREAM_NAME,
- USB_EP_STREAM,
- 64,
- 64,
- usb_stream1_rx_queue,
- usb_stream1_tx_queue)
-
-struct stream_console_state {
- size_t wrote;
-};
-
-struct stream_console_config {
- struct stream_console_state *state;
-
- struct in_stream const *in;
- struct out_stream const *out;
-};
-
-#define STREAM_CONSOLE_CONFIG(IN, OUT) { \
- .state = &((struct stream_console_state){}), \
- .in = IN, \
- .out = OUT, \
- }
-
-static struct stream_console_config const consoles[] = {
- STREAM_CONSOLE_CONFIG(&usart1_in.in, &usart1_out.out),
- STREAM_CONSOLE_CONFIG(&usart3_in.in, &usart3_out.out),
- STREAM_CONSOLE_CONFIG(&usart4_in.in, &usart4_out.out),
- STREAM_CONSOLE_CONFIG(&usb_stream1_in.in, &usb_stream1_out.out)
-};
-
-static size_t echo(struct stream_console_config const consoles[],
- size_t consoles_count)
-{
- size_t total = 0;
- size_t i;
-
- for (i = 0; i < consoles_count; ++i) {
- size_t j;
- uint8_t buffer[64];
- size_t remaining = 0;
- size_t count = in_stream_read(consoles[i].in,
- buffer,
- sizeof(buffer));
-
- if (count == 0)
- continue;
-
- for (j = 0; j < consoles_count; ++j)
- consoles[j].state->wrote = 0;
-
- do {
- remaining = 0;
-
- for (j = 0; j < consoles_count; ++j) {
- size_t wrote = consoles[j].state->wrote;
-
- if (count == wrote)
- continue;
-
- wrote += out_stream_write(consoles[j].out,
- buffer + wrote,
- count - wrote);
-
- consoles[j].state->wrote = wrote;
-
- remaining += count - wrote;
- }
- } while (remaining);
-
- total += count;
- }
-
- return total;
-}
-
-void echo_task(void)
-{
- usart_init(&usart1);
- usart_init(&usart3);
- usart_init(&usart4);
-
- while (1) {
- while (echo(consoles, ARRAY_SIZE(consoles))) {
- /*
- * Make sure other tasks, like the HOOKS get to run.
- */
- msleep(1);
- }
-
- /*
- * There was nothing left to echo, go to sleep and be
- * woken up by the next input.
- */
- task_wait_event(-1);
- }
-}
-
-static int command_echo_info(int argc, char **argv)
-{
- char const message[] = "Hello World!\r\n";
- size_t i;
-
- ccprintf("USART1 RX dropped %d bytes\n",
- atomic_read_clear((uint32_t *) &(usart1.state->rx_dropped)));
-
- ccprintf("USART3 RX dropped %d bytes\n",
- atomic_read_clear((uint32_t *) &(usart3.state->rx_dropped)));
-
- ccprintf("USART4 RX dropped %d bytes\n",
- atomic_read_clear((uint32_t *) &(usart4.state->rx_dropped)));
-
- for (i = 0; i < ARRAY_SIZE(consoles); ++i)
- out_stream_write(consoles[i].out, message, strlen(message));
-
- return EC_SUCCESS;
-}
-
-DECLARE_CONSOLE_COMMAND(echo_info,
- command_echo_info,
- NULL,
- "Dump echo task debug info",
- NULL);
diff --git a/board/hoho/board.h b/board/hoho/board.h
index b83bd832ec..7b91a669eb 100644
--- a/board/hoho/board.h
+++ b/board/hoho/board.h
@@ -50,7 +50,6 @@
#define CONFIG_USB_PD_NO_VBUS_DETECT
/* mcdp2850 serial interface */
#define CONFIG_MCDP28X0 usart3_hw
-#define CONFIG_STREAM
#define CONFIG_STREAM_USART
#define CONFIG_STREAM_USART3
#undef CONFIG_WATCHDOG_HELP
diff --git a/chip/stm32/usart.h b/chip/stm32/usart.h
index b4e76f4945..79a87331bd 100644
--- a/chip/stm32/usart.h
+++ b/chip/stm32/usart.h
@@ -9,8 +9,6 @@
#include "common.h"
#include "consumer.h"
-#include "in_stream.h"
-#include "out_stream.h"
#include "producer.h"
#include "queue.h"
diff --git a/chip/stm32/usb-stream.h b/chip/stm32/usb-stream.h
index fcc688ecdc..97816afa05 100644
--- a/chip/stm32/usb-stream.h
+++ b/chip/stm32/usb-stream.h
@@ -10,8 +10,6 @@
#include "compile_time_macros.h"
#include "consumer.h"
#include "hooks.h"
-#include "in_stream.h"
-#include "out_stream.h"
#include "producer.h"
#include "queue.h"
#include "usb.h"
diff --git a/common/build.mk b/common/build.mk
index 3941a40c5f..b551c3f8fc 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -72,7 +72,6 @@ common-$(CONFIG_SHA256)+=sha256.o
common-$(CONFIG_SMBUS)+= smbus.o
common-$(CONFIG_SOFTWARE_CLZ)+=clz.o
common-$(CONFIG_SPI_FLASH)+=spi_flash.o spi_flash_reg.o
-common-$(CONFIG_STREAM)+=in_stream.o out_stream.o stream_adaptor.o
common-$(CONFIG_SWITCH)+=switch.o
common-$(CONFIG_SW_CRC)+=crc.o
common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o thermal.o throttle_ap.o
diff --git a/common/in_stream.c b/common/in_stream.c
deleted file mode 100644
index 6df8b59879..0000000000
--- a/common/in_stream.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "in_stream.h"
-
-size_t in_stream_read(struct in_stream const *stream,
- uint8_t *buffer,
- size_t count)
-{
- return stream->ops->read(stream, buffer, count);
-}
-
-void in_stream_ready(struct in_stream const *stream)
-{
- if (stream->ready)
- stream->ready(stream);
-}
diff --git a/common/out_stream.c b/common/out_stream.c
deleted file mode 100644
index 984b20fc59..0000000000
--- a/common/out_stream.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "out_stream.h"
-
-size_t out_stream_write(struct out_stream const *stream,
- uint8_t const *buffer,
- size_t count)
-{
- return stream->ops->write(stream, buffer, count);
-}
-
-void out_stream_flush(struct out_stream const *stream)
-{
- stream->ops->flush(stream);
-}
-
-void out_stream_ready(struct out_stream const *stream)
-{
- if (stream->ready)
- stream->ready(stream);
-}
diff --git a/common/queue_policies.c b/common/queue_policies.c
index 130dee52f0..85395fec15 100644
--- a/common/queue_policies.c
+++ b/common/queue_policies.c
@@ -26,3 +26,18 @@ void queue_remove_direct(struct queue_policy const *policy, size_t count)
if (count && direct->producer->ops->read)
direct->producer->ops->read(direct->producer, count);
}
+
+struct producer const null_producer = {
+ .queue = NULL,
+ .ops = &((struct producer_ops const) {
+ .read = NULL,
+ }),
+};
+
+struct consumer const null_consumer = {
+ .queue = NULL,
+ .ops = &((struct consumer_ops const) {
+ .written = NULL,
+ .flush = NULL,
+ }),
+};
diff --git a/common/stream_adaptor.c b/common/stream_adaptor.c
deleted file mode 100644
index 8a8a414f55..0000000000
--- a/common/stream_adaptor.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Stream adaptor implementation.
- */
-
-#include "producer.h"
-#include "consumer.h"
-#include "stream_adaptor.h"
-#include "util.h"
-
-static size_t in_stream_from_queue_read(struct in_stream const *stream,
- uint8_t *buffer,
- size_t count)
-{
- struct in_stream_from_queue const *adaptor =
- DOWNCAST(stream, struct in_stream_from_queue, in);
-
- return queue_remove_memcpy(adaptor->consumer.queue,
- buffer,
- count,
- memcpy);
-}
-
-static void in_stream_from_queue_written(struct consumer const *consumer,
- size_t count)
-{
- struct in_stream_from_queue const *adaptor =
- DOWNCAST(consumer, struct in_stream_from_queue, consumer);
-
- in_stream_ready(&adaptor->in);
-}
-
-struct in_stream_ops const in_stream_from_queue_in_stream_ops = {
- .read = in_stream_from_queue_read,
-};
-
-struct consumer_ops const in_stream_from_queue_consumer_ops = {
- .written = in_stream_from_queue_written,
-};
-
-static size_t out_stream_from_queue_write(struct out_stream const *stream,
- uint8_t const *buffer,
- size_t count)
-{
- struct out_stream_from_queue const *adaptor =
- DOWNCAST(stream, struct out_stream_from_queue, out);
-
- return queue_add_memcpy(adaptor->producer.queue,
- buffer,
- count,
- memcpy);
-}
-
-static void out_stream_from_queue_read(struct producer const *producer,
- size_t count)
-{
- struct out_stream_from_queue const *adaptor =
- DOWNCAST(producer, struct out_stream_from_queue, producer);
-
- out_stream_ready(&adaptor->out);
-}
-
-struct out_stream_ops const out_stream_from_queue_out_stream_ops = {
- .write = out_stream_from_queue_write,
-};
-
-struct producer_ops const out_stream_from_queue_producer_ops = {
- .read = out_stream_from_queue_read,
-};
diff --git a/driver/mcdp28x0.c b/driver/mcdp28x0.c
index d5d37e1bed..552d2dc474 100644
--- a/driver/mcdp28x0.c
+++ b/driver/mcdp28x0.c
@@ -10,7 +10,8 @@
#include "common.h"
#include "ec_commands.h"
#include "mcdp28x0.h"
-#include "stream_adaptor.h"
+#include "queue.h"
+#include "queue_policies.h"
#include "timer.h"
#include "usart-stm32f0.h"
#include "util.h"
@@ -39,7 +40,14 @@ static inline void print_buffer(uint8_t *buf, int cnt) {}
struct usart_config const usart_mcdp;
-IO_STREAM_CONFIG(usart_mcdp, MCDP_INBUF_MAX, MCDP_OUTBUF_MAX, NULL, NULL);
+struct queue const usart_mcdp_rx_queue = QUEUE_DIRECT(MCDP_INBUF_MAX,
+ uint8_t,
+ usart_mcdp.producer,
+ null_consumer);
+struct queue const usart_mcdp_tx_queue = QUEUE_DIRECT(MCDP_OUTBUF_MAX,
+ uint8_t,
+ null_producer,
+ usart_mcdp.consumer);
USART_CONFIG(usart_mcdp,
CONFIG_MCDP28X0,
@@ -84,15 +92,15 @@ static int tx_serial(const uint8_t *msg, int cnt)
/* 1st byte (not in msg) is always cnt + 2, so seed chksum with that */
uint8_t chksum = compute_checksum(cnt + 2, msg, cnt);
- if (out_stream_write(&usart_mcdp_out.out, &out, 1) != 1)
+ if (queue_add_unit(&usart_mcdp_tx_queue, &out) != 1)
return EC_ERROR_UNKNOWN;
- if (out_stream_write(&usart_mcdp_out.out, msg, cnt) != cnt)
+ if (queue_add_units(&usart_mcdp_tx_queue, msg, cnt) != cnt)
return EC_ERROR_UNKNOWN;
print_buffer((uint8_t *)msg, cnt);
- if (out_stream_write(&usart_mcdp_out.out, &chksum, 1) != 1)
+ if (queue_add_unit(&usart_mcdp_tx_queue, &chksum) != 1)
return EC_ERROR_UNKNOWN;
return EC_SUCCESS;
@@ -119,11 +127,11 @@ static int rx_serial(uint8_t *msg, int cnt)
size_t read;
int retry = 2;
- read = in_stream_read(&usart_mcdp_in.in, msg, cnt);
+ read = queue_remove_units(&usart_mcdp_rx_queue, msg, cnt);
while ((read < cnt) && retry) {
usleep(100*MSEC);
- read += in_stream_read(&usart_mcdp_in.in, msg + read,
- cnt - read);
+ read += queue_remove_units(&usart_mcdp_rx_queue, msg + read,
+ cnt - read);
retry--;
}
diff --git a/include/config.h b/include/config.h
index 28c24f8ea6..8ceba6036b 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1190,15 +1190,6 @@
#undef CONFIG_TEMP_SENSOR_POWER_GPIO
/*****************************************************************************/
-/* Stream config
- *
- * Streams are an abstraction for managing character based IO streams. Streams
- * can virtualize USARTs (interrupt, polled, or DMA driven), USB bulk
- * endpoints, I2C transfers, and more.
- */
-#undef CONFIG_STREAM
-
-/*****************************************************************************/
/* USART stream config */
#undef CONFIG_STREAM_USART
diff --git a/include/in_stream.h b/include/in_stream.h
deleted file mode 100644
index 7bf8821394..0000000000
--- a/include/in_stream.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef INCLUDE_IN_STREAM_H
-#define INCLUDE_IN_STREAM_H
-
-#include <stddef.h>
-#include <stdint.h>
-
-struct in_stream;
-
-struct in_stream_ops {
- /*
- * Read at most count characters from the input stream into the user
- * buffer provided. Return the number of characters actually read
- * into the buffer.
- */
- size_t (*read)(struct in_stream const *stream,
- uint8_t *buffer,
- size_t count);
-};
-
-struct in_stream {
- /*
- * Ready will be called by the stream every time new characters are
- * added to the stream. This may be called from an interrupt context
- * so work done by the ready callback should be minimal. Likely this
- * callback will be used to call task_wake, or some similar signaling
- * mechanism.
- *
- * This callback is part of the user configuration of a stream, and not
- * a stream manipulation function (in_stream_ops). That means that
- * each stream can be configured with its own ready callback.
- *
- * If no callback functionality is required ready can be specified as
- * NULL.
- */
- void (*ready)(struct in_stream const *stream);
-
- struct in_stream_ops const *ops;
-};
-
-/*
- * Helper functions that call the associated stream operation and pass it the
- * given stream. These help prevent mistakes where one stream is passed to
- * another stream's functions.
- */
-size_t in_stream_read(struct in_stream const *stream,
- uint8_t *buffer,
- size_t count);
-void in_stream_ready(struct in_stream const *stream);
-
-#endif /* INCLUDE_IN_STREAM_H */
diff --git a/include/out_stream.h b/include/out_stream.h
deleted file mode 100644
index 6deefd69cf..0000000000
--- a/include/out_stream.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef INCLUDE_OUT_STREAM_H
-#define INCLUDE_OUT_STREAM_H
-
-#include <stddef.h>
-#include <stdint.h>
-
-struct out_stream;
-
-/*
- * An out_stream is a generic interface providing operations that can be used
- * to send a character stream over a USB endpoint, UART, I2C host interface, and
- * more. Each realization of an out_stream provides a constant instance of
- * the out_stream_ops structure that is used to operate on that realizations
- * out_streams. For example, the UART driver could provide one out_stream_ops
- * structure and four UART configs. Each UART config uses the same
- * out_stream_ops structure.
- */
-struct out_stream_ops {
- /*
- * Write at most count characters from buffer into the output stream.
- * Return the number of characters actually written.
- */
- size_t (*write)(struct out_stream const *stream,
- uint8_t const *buffer,
- size_t count);
-
- /*
- * Flush all outgoing data. This works if we are in an interrupt
- * context, or normal context. The call blocks until the output
- * stream is empty.
- */
- void (*flush)(struct out_stream const *stream);
-
-};
-
-/*
- * The out_stream structure is embedded in the device configuration structure
- * that wishes to publish an out_stream capable interface. Uses of that device
- * can pass a pointer to the embedded out_stream around and use it like any
- * other out_stream.
- */
-struct out_stream {
- /*
- * Ready will be called by the stream every time characters are removed
- * from the stream. This may be called from an interrupt context
- * so work done by the ready callback should be minimal. Likely this
- * callback will be used to call task_wake, or some similar signaling
- * mechanism.
- *
- * This callback is part of the user configuration of a stream, and not
- * a stream manipulation function (in_stream_ops). That means that
- * each stream can be configured with its own ready callback.
- *
- * If no callback functionality is required ready can be specified as
- * NULL.
- */
- void (*ready)(struct out_stream const *stream);
-
- struct out_stream_ops const *ops;
-};
-
-/*
- * Helper functions that call the associated stream operation and pass it the
- * given stream. These help prevent mistakes where one stream is passed to
- * another stream's functions.
- */
-size_t out_stream_write(struct out_stream const *stream,
- uint8_t const *buffer,
- size_t count);
-void out_stream_flush(struct out_stream const *stream);
-void out_stream_ready(struct out_stream const *stream);
-
-#endif /* INCLUDE_OUT_STREAM_H */
diff --git a/include/queue_policies.h b/include/queue_policies.h
index ec6ba1a0ec..61ab75c3a6 100644
--- a/include/queue_policies.h
+++ b/include/queue_policies.h
@@ -40,4 +40,12 @@ void queue_remove_direct(struct queue_policy const *policy, size_t count);
#define QUEUE_DIRECT(SIZE, TYPE, PRODUCER, CONSUMER) \
QUEUE(SIZE, TYPE, QUEUE_POLICY_DIRECT(PRODUCER, CONSUMER).policy)
+/*
+ * The null_producer and null_consumer are useful when constructing a queue
+ * where one end needs notification, but the other end doesn't care. These
+ * producer and consumer structs just ignore all notifications.
+ */
+extern struct producer const null_producer;
+extern struct consumer const null_consumer;
+
#endif /* INCLUDE_QUEUE_POLICIES_H */
diff --git a/include/stream_adaptor.h b/include/stream_adaptor.h
deleted file mode 100644
index 3074231ef3..0000000000
--- a/include/stream_adaptor.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef INCLUDE_STREAM_ADAPTOR_H
-#define INCLUDE_STREAM_ADAPTOR_H
-
-#include "common.h"
-#include "in_stream.h"
-#include "out_stream.h"
-#include "consumer.h"
-#include "producer.h"
-#include "queue.h"
-#include "queue_policies.h"
-
-/*
- * +..........+ +..........+------+...........+
- * . .<------------->. | | .
- * . Producer . +---------+ . Consumer | ISFQ | In Stream .
- * . .->| Queue |->. | | .
- * +..........+ +---------+ +..........+------+...........+
- */
-
-struct in_stream_from_queue {
- struct consumer consumer;
- struct in_stream in;
-};
-
-/*
- *
- */
-extern struct in_stream_ops const in_stream_from_queue_in_stream_ops;
-extern struct consumer_ops const in_stream_from_queue_consumer_ops;
-
-#define IN_STREAM_FROM_QUEUE(QUEUE, READY) \
- ((struct in_stream_from_queue) { \
- .consumer = { \
- .queue = &QUEUE, \
- .ops = &in_stream_from_queue_consumer_ops, \
- }, \
- .in = { \
- .ready = READY, \
- .ops = &in_stream_from_queue_in_stream_ops, \
- }, \
- })
-
-/*
- * +..........+ +..........+------+............+
- * . .<------------->. | | .
- * . Consumer . +---------+ . Producer | OSFQ | Out Stream .
- * . .<-| Queue |<-. | | .
- * +..........+ +---------+ +..........+------+............+
- */
-
-struct out_stream_from_queue {
- struct producer producer;
- struct out_stream out;
-};
-
-/*
- *
- */
-extern struct out_stream_ops const out_stream_from_queue_out_stream_ops;
-extern struct producer_ops const out_stream_from_queue_producer_ops;
-
-#define OUT_STREAM_FROM_QUEUE(QUEUE, READY) \
- ((struct out_stream_from_queue) { \
- .producer = { \
- .queue = &QUEUE, \
- .ops = &out_stream_from_queue_producer_ops, \
- }, \
- .out = { \
- .ready = READY, \
- .ops = &out_stream_from_queue_out_stream_ops, \
- }, \
- })
-
-/*
- * Given a forward declared device configuration called NAME that implements
- * producer and consumer interfaces construct RX/TX queues and expose them as
- * streams called <NAME>_in and <NAME>_out.
- */
-#define IO_STREAM_CONFIG(NAME, RX_SIZE, TX_SIZE, IN_READY, OUT_READY) \
- struct in_stream_from_queue const CONCAT2(NAME, _in); \
- \
- struct queue const CONCAT2(NAME, _rx_queue) = \
- QUEUE_DIRECT(RX_SIZE, \
- uint8_t, \
- NAME.producer, \
- CONCAT2(NAME, _in).consumer); \
- struct in_stream_from_queue const CONCAT2(NAME, _in) = \
- IN_STREAM_FROM_QUEUE(CONCAT2(NAME, _rx_queue), \
- IN_READY); \
- \
- \
- struct out_stream_from_queue const CONCAT2(NAME, _out); \
- \
- struct queue const CONCAT2(NAME, _tx_queue) = \
- QUEUE_DIRECT(TX_SIZE, \
- uint8_t, \
- CONCAT2(NAME, _out).producer, \
- NAME.consumer); \
- struct out_stream_from_queue const CONCAT2(NAME, _out) = \
- OUT_STREAM_FROM_QUEUE(CONCAT2(NAME, _tx_queue), \
- OUT_READY);
-
-#endif /* INCLUDE_STREAM_ADAPTOR_H */