diff options
author | Anton Staaf <robotboy@chromium.org> | 2015-05-13 13:26:12 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-05-26 19:36:21 +0000 |
commit | 855646e36bebce29b929178cfb3c73b8f259c8b6 (patch) | |
tree | c0fcdc616da4ade170502a0cb842d70d1c44821b /driver | |
parent | a0ebf0a008670ece41529a2fce01882192331c6e (diff) | |
download | chrome-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 'driver')
-rw-r--r-- | driver/mcdp28x0.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/driver/mcdp28x0.c b/driver/mcdp28x0.c index afcb6f8e71..785a6f13a3 100644 --- a/driver/mcdp28x0.c +++ b/driver/mcdp28x0.c @@ -37,17 +37,15 @@ static inline void print_buffer(uint8_t *buf, int cnt) static inline void print_buffer(uint8_t *buf, int cnt) {} #endif -struct queue const rx_queue = QUEUE_NULL(MCDP_INBUF_MAX, uint8_t); -struct queue const tx_queue = QUEUE_NULL(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); +IO_STREAM_CONFIG(usart_mcdp, MCDP_INBUF_MAX, MCDP_OUTBUF_MAX, NULL, NULL); +USART_CONFIG(usart_mcdp, + CONFIG_MCDP28X0, + 115200, + usart_mcdp_rx_queue, + usart_mcdp_tx_queue); /** * Compute checksum. @@ -86,13 +84,13 @@ 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_out.out, &out, 1) != 1) + if (out_stream_write(&usart_mcdp_out.out, &out, 1) != 1) return EC_ERROR_UNKNOWN; - if (out_stream_write(&usart_out.out, msg, cnt) != cnt) + if (out_stream_write(&usart_mcdp_out.out, msg, cnt) != cnt) return EC_ERROR_UNKNOWN; - if (out_stream_write(&usart_out.out, &chksum, 1) != 1) + if (out_stream_write(&usart_mcdp_out.out, &chksum, 1) != 1) return EC_ERROR_UNKNOWN; return EC_SUCCESS; @@ -119,10 +117,10 @@ static int rx_serial(uint8_t *msg, int cnt) size_t read; int retry = 2; - read = in_stream_read(&usart_in.in, msg, cnt); + read = in_stream_read(&usart_mcdp_in.in, msg, cnt); while ((read < cnt) && retry) { usleep(100*MSEC); - read += in_stream_read(&usart_in.in, msg + read, + read += in_stream_read(&usart_mcdp_in.in, msg + read, cnt - read); retry--; } |