diff options
author | Anton Staaf <robotboy@chromium.org> | 2015-05-13 08:39:58 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-05-27 01:27:20 +0000 |
commit | 8e7b34f314981b16cbec2a5ce64a4165b0f3b353 (patch) | |
tree | b02fc8307e5c79170a92513c688d25eeadc699f5 | |
parent | 2259e8ffb7645e0decfadd95fb4d1cdda8208095 (diff) | |
download | chrome-ec-8e7b34f314981b16cbec2a5ce64a4165b0f3b353.tar.gz |
Cleanup: Use compound literals for static initialization
This just makes a couple of convenience macros a little prettier
using compound literals.
Signed-off-by: Anton Staaf <robotboy@chromium.org>
BRANCH=None
BUG=None
TEST=make buildall -j
Change-Id: I2bcd846067dbbe000b0ecb36c1d8da2d8cd730b3
Reviewed-on: https://chromium-review.googlesource.com/273287
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
-rw-r--r-- | board/discovery-stm32f072/echo.c | 41 | ||||
-rw-r--r-- | include/stream_adaptor.h | 25 |
2 files changed, 28 insertions, 38 deletions
diff --git a/board/discovery-stm32f072/echo.c b/board/discovery-stm32f072/echo.c index 22b42623ca..63a0360d94 100644 --- a/board/discovery-stm32f072/echo.c +++ b/board/discovery-stm32f072/echo.c @@ -68,29 +68,20 @@ struct stream_console_config { struct out_stream const *out; }; -#define STREAM_CONSOLE_CONFIG(NAME, IN, OUT) \ - static struct stream_console_state NAME##_state; \ - struct stream_console_config const NAME = { \ - .state = &NAME##_state, \ +#define STREAM_CONSOLE_CONFIG(IN, OUT) { \ + .state = &((struct stream_console_state){}), \ .in = IN, \ .out = OUT, \ - }; - -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_stream1_in.in, - &usb_stream1_out.out) - -static struct stream_console_config const *const consoles[] = { - &usart1_stream_console, - &usart3_stream_console, - &usart4_stream_console, - &usb_stream1_console, + } + +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 *const consoles[], +static size_t echo(struct stream_console_config const consoles[], size_t consoles_count) { size_t total = 0; @@ -100,7 +91,7 @@ static size_t echo(struct stream_console_config const *const consoles[], size_t j; uint8_t buffer[64]; size_t remaining = 0; - size_t count = in_stream_read(consoles[i]->in, + size_t count = in_stream_read(consoles[i].in, buffer, sizeof(buffer)); @@ -108,22 +99,22 @@ static size_t echo(struct stream_console_config const *const consoles[], continue; for (j = 0; j < consoles_count; ++j) - consoles[j]->state->wrote = 0; + consoles[j].state->wrote = 0; do { remaining = 0; for (j = 0; j < consoles_count; ++j) { - size_t wrote = consoles[j]->state->wrote; + size_t wrote = consoles[j].state->wrote; if (count == wrote) continue; - wrote += out_stream_write(consoles[j]->out, + wrote += out_stream_write(consoles[j].out, buffer + wrote, count - wrote); - consoles[j]->state->wrote = wrote; + consoles[j].state->wrote = wrote; remaining += count - wrote; } @@ -172,7 +163,7 @@ static int command_echo_info(int argc, char **argv) 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)); + out_stream_write(consoles[i].out, message, strlen(message)); return EC_SUCCESS; } diff --git a/include/stream_adaptor.h b/include/stream_adaptor.h index 93ce923f40..3074231ef3 100644 --- a/include/stream_adaptor.h +++ b/include/stream_adaptor.h @@ -32,8 +32,8 @@ struct in_stream_from_queue { 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(NAME, QUEUE, READY) \ - struct in_stream_from_queue const NAME = { \ +#define IN_STREAM_FROM_QUEUE(QUEUE, READY) \ + ((struct in_stream_from_queue) { \ .consumer = { \ .queue = &QUEUE, \ .ops = &in_stream_from_queue_consumer_ops, \ @@ -42,7 +42,7 @@ extern struct consumer_ops const in_stream_from_queue_consumer_ops; .ready = READY, \ .ops = &in_stream_from_queue_in_stream_ops, \ }, \ - }; + }) /* * +..........+ +..........+------+............+ @@ -63,8 +63,8 @@ struct out_stream_from_queue { 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(NAME, QUEUE, READY) \ - struct out_stream_from_queue const NAME = { \ +#define OUT_STREAM_FROM_QUEUE(QUEUE, READY) \ + ((struct out_stream_from_queue) { \ .producer = { \ .queue = &QUEUE, \ .ops = &out_stream_from_queue_producer_ops, \ @@ -73,7 +73,7 @@ extern struct producer_ops const out_stream_from_queue_producer_ops; .ready = READY, \ .ops = &out_stream_from_queue_out_stream_ops, \ }, \ - }; + }) /* * Given a forward declared device configuration called NAME that implements @@ -81,7 +81,6 @@ extern struct producer_ops const out_stream_from_queue_producer_ops; * 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) = \ @@ -89,9 +88,9 @@ extern struct producer_ops const out_stream_from_queue_producer_ops; uint8_t, \ NAME.producer, \ CONCAT2(NAME, _in).consumer); \ - IN_STREAM_FROM_QUEUE(CONCAT2(NAME, _in), \ - CONCAT2(NAME, _rx_queue), \ - IN_READY) \ + 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); \ @@ -101,8 +100,8 @@ extern struct producer_ops const out_stream_from_queue_producer_ops; uint8_t, \ CONCAT2(NAME, _out).producer, \ NAME.consumer); \ - OUT_STREAM_FROM_QUEUE(CONCAT2(NAME, _out), \ - CONCAT2(NAME, _tx_queue), \ - OUT_READY) + struct out_stream_from_queue const CONCAT2(NAME, _out) = \ + OUT_STREAM_FROM_QUEUE(CONCAT2(NAME, _tx_queue), \ + OUT_READY); #endif /* INCLUDE_STREAM_ADAPTOR_H */ |