You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/27 04:40:52 UTC

[incubator-nuttx] 01/02: xtensa/esp32: Fix wrong math round operation on DMA init

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit d3342795a8de597f675fb4acb8637d6125932caf
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Fri Mar 26 12:20:30 2021 -0300

    xtensa/esp32: Fix wrong math round operation on DMA init
---
 arch/xtensa/src/esp32/esp32_dma.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_dma.c b/arch/xtensa/src/esp32/esp32_dma.c
index b4b2d21..8bd2f31 100644
--- a/arch/xtensa/src/esp32/esp32_dma.c
+++ b/arch/xtensa/src/esp32/esp32_dma.c
@@ -43,6 +43,10 @@
 #  define MIN(a,b) (a < b ? a : b)
 #endif
 
+#ifndef ALIGN_UP
+#  define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -82,11 +86,9 @@ uint32_t esp32_dma_init(struct esp32_dmadesc_s *dmadesc, uint32_t num,
     {
       data_len = MIN(bytes, ESP32_DMA_DATALEN_MAX);
 
-      /* Round the number of bytes to the nearest word, since the buffer
-       * length must be word-aligned.
-       */
+      /* Buffer length must be rounded to next 32-bit boundary. */
 
-      buf_len = (data_len + sizeof(uintptr_t) - 1) / sizeof(uintptr_t);
+      buf_len = ALIGN_UP(data_len, sizeof(uintptr_t));
 
       dmadesc[i].ctrl = (data_len << DMA_CTRL_DATALEN_S) |
                         (buf_len << DMA_CTRL_BUFLEN_S) |