diff options
author | Brian J. Nemec <bnemec@chromium.org> | 2020-05-23 23:04:31 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-04 14:49:43 +0000 |
commit | 11b912091e133568483e92b5aa7fadbf882e5e92 (patch) | |
tree | 92d5786eb1fd01fbb66a131ef5b9a6855968c09f | |
parent | f5e6ae210518bae0dc9a577d98c80a805b764fce (diff) | |
download | chrome-ec-11b912091e133568483e92b5aa7fadbf882e5e92.tar.gz |
ec: Minor cleanup of magic number commonly used in STM32 USB
Minor cleanup of a commonly used magic number in the STM32
USB interface.
BUG=none
BRANCH=none
TEST=Builds
Signed-off-by: Brian Nemec <bnemec@chromium.org>
Change-Id: I2c0b7947810aae651e452db42ac27221ab19b99b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2224763
Tested-by: Brian Nemec <bnemec@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Commit-Queue: Brian Nemec <bnemec@chromium.org>
-rw-r--r-- | chip/stm32/usb-stream.c | 2 | ||||
-rw-r--r-- | chip/stm32/usb_console.c | 3 | ||||
-rw-r--r-- | chip/stm32/usb_gpio.c | 2 | ||||
-rw-r--r-- | chip/stm32/usb_hw.h | 3 | ||||
-rw-r--r-- | chip/stm32/usb_spi.c | 2 |
5 files changed, 8 insertions, 4 deletions
diff --git a/chip/stm32/usb-stream.c b/chip/stm32/usb-stream.c index 5741201ff1..7429832f10 100644 --- a/chip/stm32/usb-stream.c +++ b/chip/stm32/usb-stream.c @@ -19,7 +19,7 @@ static size_t rx_read(struct usb_stream_config const *config) { uintptr_t address = btable_ep[config->endpoint].rx_addr; - size_t count = btable_ep[config->endpoint].rx_count & 0x3ff; + size_t count = btable_ep[config->endpoint].rx_count & RX_COUNT_MASK; /* * Only read the received USB packet if there is enough space in the diff --git a/chip/stm32/usb_console.c b/chip/stm32/usb_console.c index 0a792fe012..b5666c8fbf 100644 --- a/chip/stm32/usb_console.c +++ b/chip/stm32/usb_console.c @@ -79,7 +79,8 @@ static void con_ep_rx(void) { int i; - for (i = 0; i < (btable_ep[USB_EP_CONSOLE].rx_count & 0x3ff); i++) { + for (i = 0; i < (btable_ep[USB_EP_CONSOLE].rx_count & RX_COUNT_MASK); + i++) { int val = ((i & 1) ? (ep_buf_rx[i >> 1] >> 8) : (ep_buf_rx[i >> 1] & 0xff)); diff --git a/chip/stm32/usb_gpio.c b/chip/stm32/usb_gpio.c index 37eebf5b28..64d46875b5 100644 --- a/chip/stm32/usb_gpio.c +++ b/chip/stm32/usb_gpio.c @@ -42,7 +42,7 @@ void usb_gpio_rx(struct usb_gpio_config const *config) config->state->set_mask = set_mask; config->state->clear_mask = clear_mask; - if ((btable_ep[config->endpoint].rx_count & 0x3ff) == + if ((btable_ep[config->endpoint].rx_count & RX_COUNT_MASK) == USB_GPIO_RX_PACKET_SIZE) { for (i = 0; i < config->num_gpios; ++i, mask <<= 1) { if (ignore_mask & mask) diff --git a/chip/stm32/usb_hw.h b/chip/stm32/usb_hw.h index be2a88661e..0c75322a7d 100644 --- a/chip/stm32/usb_hw.h +++ b/chip/stm32/usb_hw.h @@ -34,6 +34,9 @@ extern usb_uint __usb_ram_start[]; /* Attribute to define a buffer variable in USB RAM */ #define __usb_ram __attribute__((section(".usb_ram.99_data"))) +/* Mask for the rx_count to identify the number of bytes in the buffer. */ +#define RX_COUNT_MASK (0x3ff) + struct stm32_endpoint { volatile usb_uint tx_addr; volatile usb_uint tx_count; diff --git a/chip/stm32/usb_spi.c b/chip/stm32/usb_spi.c index 597d4c5df7..1846e8efcd 100644 --- a/chip/stm32/usb_spi.c +++ b/chip/stm32/usb_spi.c @@ -25,7 +25,7 @@ static int16_t usb_spi_map_error(int error) static uint16_t usb_spi_read_packet(struct usb_spi_config const *config) { size_t i; - uint16_t bytes = btable_ep[config->endpoint].rx_count & 0x3ff; + uint16_t bytes = btable_ep[config->endpoint].rx_count & RX_COUNT_MASK; size_t count = MAX((bytes + 1) / 2, USB_MAX_PACKET_SIZE / 2); /* |