summaryrefslogtreecommitdiff
path: root/driver/mcdp28x0.c
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 /driver/mcdp28x0.c
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 'driver/mcdp28x0.c')
-rw-r--r--driver/mcdp28x0.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/driver/mcdp28x0.c b/driver/mcdp28x0.c
index de2572c87e..7fba0bd035 100644
--- a/driver/mcdp28x0.c
+++ b/driver/mcdp28x0.c
@@ -10,6 +10,7 @@
#include "common.h"
#include "ec_commands.h"
#include "mcdp28x0.h"
+#include "stream_adaptor.h"
#include "timer.h"
#include "usart-stm32f0.h"
#include "util.h"
@@ -34,8 +35,17 @@ static inline void print_buffer(uint8_t *buf, int cnt)
static inline void print_buffer(uint8_t *buf, int cnt) {}
#endif
-USART_CONFIG(usart_mcdp, CONFIG_MCDP28X0, 115200, MCDP_INBUF_MAX,
- MCDP_OUTBUF_MAX, NULL, NULL);
+QUEUE_CONFIG(rx_queue, MCDP_INBUF_MAX, uint8_t);
+QUEUE_CONFIG(tx_queue, MCDP_OUTBUF_MAX, uint8_t);
+
+struct usart_config const usart_mcdp;
+
+IN_STREAM_FROM_PRODUCER(usart_in, usart_mcdp.producer, rx_queue, NULL)
+OUT_STREAM_FROM_CONSUMER(usart_out, usart_mcdp.consumer, tx_queue, NULL)
+
+USART_CONFIG(usart_mcdp, CONFIG_MCDP28X0, 115200, rx_queue, tx_queue,
+ usart_in.consumer, usart_out.producer);
+
/**
* Compute checksum.
@@ -73,16 +83,16 @@ static int tx_serial(const uint8_t *msg, int cnt)
uint8_t out = cnt + 2;
uint8_t chksum = compute_checksum(msg, cnt);
- if (out_stream_write(&usart_mcdp.out, &out, 1) != 1)
+ if (out_stream_write(&usart_out.out, &out, 1) != 1)
return EC_ERROR_UNKNOWN;
- if (out_stream_write(&usart_mcdp.out, msg, cnt) != cnt)
+ if (out_stream_write(&usart_out.out, msg, cnt) != cnt)
return EC_ERROR_UNKNOWN;
- if (out_stream_write(&usart_mcdp.out, &chksum, 1) != 1)
+ if (out_stream_write(&usart_out.out, &chksum, 1) != 1)
return EC_ERROR_UNKNOWN;
- print_buffer(usart_mcdp_tx_buffer, cnt + 2);
+ print_buffer(tx_queue_buffer, cnt + 2);
return EC_SUCCESS;
}
@@ -99,10 +109,10 @@ static int rx_serial(uint8_t *msg, int cnt)
size_t read;
int retry = 2;
- read = in_stream_read(&usart_mcdp.in, msg, cnt);
+ read = in_stream_read(&usart_in.in, msg, cnt);
while ((read < cnt) && retry) {
usleep(100*MSEC);
- read += in_stream_read(&usart_mcdp.in, msg + read,
+ read += in_stream_read(&usart_in.in, msg + read,
cnt - read);
retry--;
}