summaryrefslogtreecommitdiff
path: root/chip/stm32/usb-stream.h
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2015-02-23 14:02:41 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-03-02 18:48:40 +0000
commit65f049b977016273f93491f0d8b2c2d0a7549819 (patch)
treec6cd855878e8703b8bd4106b1777bfab0614c3e2 /chip/stm32/usb-stream.h
parent5e9eb3263d4f47f006f7b8e4eeaadd229a8df611 (diff)
downloadchrome-ec-65f049b977016273f93491f0d8b2c2d0a7549819.tar.gz
Producer/Consumer: Convert USART and USB Stream drivers
Previously the USART and USB Stream drivers exposed in_stream and out_stream interfaces, which don't allow for sharing their queues easily. This change converts these drivers over to the producer/consumer model and updates the two uses. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Verify that the discovery echo functionality is unchanged. Change-Id: I29f043ab1712373f638e1621378df98647d736cf Reviewed-on: https://chromium-review.googlesource.com/252820 Trybot-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org> Tested-by: Todd Broch <tbroch@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
Diffstat (limited to 'chip/stm32/usb-stream.h')
-rw-r--r--chip/stm32/usb-stream.h101
1 files changed, 42 insertions, 59 deletions
diff --git a/chip/stm32/usb-stream.h b/chip/stm32/usb-stream.h
index 796eacaa17..06374676f9 100644
--- a/chip/stm32/usb-stream.h
+++ b/chip/stm32/usb-stream.h
@@ -8,8 +8,10 @@
/* STM32 USB STREAM driver for Chrome EC */
#include "compile_time_macros.h"
+#include "consumer.h"
#include "in_stream.h"
#include "out_stream.h"
+#include "producer.h"
#include "queue.h"
#include "usb.h"
@@ -19,19 +21,13 @@
* Per-USB stream state stored in RAM. Zero initialization of this structure
* by the BSS initialization leaves it in a valid and correctly initialized
* state, so there is no need currently for a usb_stream_init style function.
- *
- * If this structure is changed to require non-zero initialization such a
- * function should be added.
*/
struct usb_stream_state {
- struct queue_state rx;
- struct queue_state tx;
-
/*
* Flag indicating that there is a full RX buffer in the USB packet RAM
* that we were not able to move into the RX queue because there was
* not enough room when the packet was initially received. The
- * in_stream read operation checks this flag so that once there is
+ * producer read operation checks this flag so that once there is
* room in the queue it can copy the RX buffer into the queue and
* restart USB reception by marking the RX buffer as VALID.
*/
@@ -46,8 +42,7 @@ struct usb_stream_state {
struct usb_stream_config {
/*
* Pointer to usb_stream_state structure. The state structure
- * maintains per USB stream information (head and tail pointers for
- * the queues for instance).
+ * maintains per USB stream information.
*/
struct usb_stream_state volatile *state;
@@ -59,62 +54,60 @@ struct usb_stream_config {
usb_uint *rx_ram;
usb_uint *tx_ram;
- /*
- * RX and TX queue config. The state for the queue is stored
- * separately in the usb_stream_state structure.
- */
- struct queue rx;
- struct queue tx;
-
- /*
- * In and Out streams, these contain pointers to the virtual function
- * tables that implement in and out streams. They can be used by any
- * code that wants to read or write to a stream interface.
- */
- struct in_stream in;
- struct out_stream out;
+ struct consumer consumer;
+ struct producer producer;
};
/*
- * These function tables are defined by the USB stream driver and are used to
- * initialize the in and out streams in the usb_stream_config.
+ * These function tables are defined by the USB Stream driver and are used to
+ * initialize the consumer and producer in the usb_stream_config.
*/
-extern struct in_stream_ops const usb_stream_in_stream_ops;
-extern struct out_stream_ops const usb_stream_out_stream_ops;
+extern struct consumer_ops const usb_stream_consumer_ops;
+extern struct producer_ops const usb_stream_producer_ops;
/*
* Convenience macro for defining USB streams and their associated state and
* buffers.
*
- * NAME is used to construct the names of the queue buffers, trampoline
+ * NAME is used to construct the names of the packet RAM buffers, trampoline
* functions, usb_stream_state struct, and usb_stream_config struct, the
* latter is just called NAME.
*
* INTERFACE is the index of the USB interface to associate with this
* stream.
*
+ * INTERFACE_NAME is the index of the USB string descriptor (iInterface).
+ *
* ENDPOINT is the index of the USB bulk endpoint used for receiving and
* transmitting bytes.
*
- * RX_SIZE and TX_SIZE are the size in bytes of the RX and TX queue buffers
- * respectively.
+ * RX_QUEUE and TX_QUEUE are the names of the RX and TX queues that this driver
+ * should write to and read from respectively. They must match the queues
+ * that the CONSUMER and PRODUCER read from and write to respectively.
+ *
+ * CONSUMER and PRODUCER are the names of the consumer and producer objects at
+ * the other ends of the RX and TX queues respectively.
+ */
+/*
+ * The following assertions can not be made because they require access to
+ * non-const fields, but should be kept in mind.
*
- * RX_READY and TX_READY are the callback functions for the in and out streams.
- * These functions are called when there are bytes to read or space for bytes
- * to write respectively.
+ * BUILD_ASSERT(RX_QUEUE.buffer_units >= USB_MAX_PACKET_SIZE);
+ * BUILD_ASSERT(TX_QUEUE.buffer_units >= USB_MAX_PACKET_SIZE);
+ * BUILD_ASSERT(RX_QUEUE.unit_bytes == 1);
+ * BUILD_ASSERT(TX_QUEUE.unit_bytes == 1);
+ * BUILD_ASSERT(PRODUCER.queue == &TX_QUEUE);
+ * BUILD_ASSERT(CONSUMER.queue == &RX_QUEUE);
*/
#define USB_STREAM_CONFIG(NAME, \
INTERFACE, \
INTERFACE_NAME, \
ENDPOINT, \
- RX_SIZE, \
- TX_SIZE, \
- RX_READY, \
- TX_READY) \
- BUILD_ASSERT(RX_SIZE >= USB_MAX_PACKET_SIZE); \
- BUILD_ASSERT(TX_SIZE >= USB_MAX_PACKET_SIZE); \
- static uint8_t CONCAT2(NAME, _rx_buffer)[RX_SIZE]; \
- static uint8_t CONCAT2(NAME, _tx_buffer)[TX_SIZE]; \
+ RX_QUEUE, \
+ TX_QUEUE, \
+ CONSUMER, \
+ PRODUCER) \
+ \
static usb_uint CONCAT2(NAME, _ep_rx_buffer)[USB_MAX_PACKET_SIZE / 2] __usb_ram; \
static usb_uint CONCAT2(NAME, _ep_tx_buffer)[USB_MAX_PACKET_SIZE / 2] __usb_ram; \
static struct usb_stream_state CONCAT2(NAME, _state); \
@@ -123,25 +116,15 @@ extern struct out_stream_ops const usb_stream_out_stream_ops;
.endpoint = ENDPOINT, \
.rx_ram = CONCAT2(NAME, _ep_rx_buffer), \
.tx_ram = CONCAT2(NAME, _ep_tx_buffer), \
- .rx = { \
- .state = &CONCAT2(NAME, _state.rx), \
- .buffer_units = RX_SIZE, \
- .unit_bytes = 1, \
- .buffer = CONCAT2(NAME, _rx_buffer), \
- }, \
- .tx = { \
- .state = &CONCAT2(NAME, _state.tx), \
- .buffer_units = TX_SIZE, \
- .unit_bytes = 1, \
- .buffer = CONCAT2(NAME, _tx_buffer), \
- }, \
- .in = { \
- .ready = RX_READY, \
- .ops = &usb_stream_in_stream_ops, \
+ .consumer = { \
+ .producer = &PRODUCER, \
+ .queue = &TX_QUEUE, \
+ .ops = &usb_stream_consumer_ops, \
}, \
- .out = { \
- .ready = TX_READY, \
- .ops = &usb_stream_out_stream_ops, \
+ .producer = { \
+ .consumer = &CONSUMER, \
+ .queue = &RX_QUEUE, \
+ .ops = &usb_stream_producer_ops, \
}, \
}; \
const struct usb_interface_descriptor \