diff options
author | Yilun Lin <yllin@chromium.org> | 2019-11-07 10:25:03 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-11-07 17:21:05 +0000 |
commit | f04a43078744572059aa60e054d2eabe9bc2924e (patch) | |
tree | d3eccc5fa1d130418c5f0d9ec273673e68908291 /common/uart_buffering.c | |
parent | 1bd0562b78ca98740ae987ddf8cc96fdcddf0f37 (diff) | |
download | chrome-ec-f04a43078744572059aa60e054d2eabe9bc2924e.tar.gz |
uart_buffer: ensure uart tx/rx buffer size are power of two
uart buffers are circular buffers and the pointer advancing needs
the buffer size power of two.
TEST=set CONFIG_UART_TX/RX_BUF_SIZE to various values and ensure the
results are correct
BUG=none
BRANCH=kukui
Change-Id: I53feb28f0397c67e282126faf25b0fbfdd8d5251
Signed-off-by: Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1902889
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Commit-Queue: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'common/uart_buffering.c')
-rw-r--r-- | common/uart_buffering.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/common/uart_buffering.c b/common/uart_buffering.c index 6eb8241355..e3b7e73fbd 100644 --- a/common/uart_buffering.c +++ b/common/uart_buffering.c @@ -28,6 +28,10 @@ #define TX_BUF_DIFF(i, j) (((i) - (j)) & (CONFIG_UART_TX_BUF_SIZE - 1)) #define RX_BUF_DIFF(i, j) (((i) - (j)) & (CONFIG_UART_RX_BUF_SIZE - 1)) +/* Check if both UART TX/RX buffer sizes are power of two. */ +BUILD_ASSERT((CONFIG_UART_TX_BUF_SIZE & (CONFIG_UART_TX_BUF_SIZE - 1)) == 0); +BUILD_ASSERT((CONFIG_UART_RX_BUF_SIZE & (CONFIG_UART_RX_BUF_SIZE - 1)) == 0); + /* * Interval between rechecking the receive DMA head pointer, after a character * of input has been detected by the normal tick task. There will be @@ -500,4 +504,3 @@ int uart_console_read_buffer(uint8_t type, return EC_RES_SUCCESS; } - |