You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/07/15 13:28:28 UTC

[GitHub] [incubator-nuttx] michallenc commented on a diff in pull request #6614: samv7: add support for RX DMA and RS-485 mode to serial driver

michallenc commented on code in PR #6614:
URL: https://github.com/apache/incubator-nuttx/pull/6614#discussion_r922165937


##########
arch/arm/src/samv7/sam_serial.c:
##########
@@ -46,14 +46,82 @@
 
 #include "arm_internal.h"
 #include "sam_config.h"
+
+#include "hardware/sam_pinmap.h"
 #include "hardware/sam_uart.h"
+#include "hardware/sam_xdmac.h"
+#include "sam_xdmac.h"
+#include "sam_gpio.h"
+#include "sam_serial.h"
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
 #ifdef USE_SERIALDRIVER
 
+/* DMA Configuration */
+
+#if defined(CONFIG_USART0_RXDMA) || defined(CONFIG_USART1_RXDMA) || \
+    defined(CONFIG_USART2_RXDMA)
+# define SERIAL_HAVE_RXDMA
+#else
+# undef SERIAL_HAVE_RXDMA
+#endif
+
+#if defined(CONFIG_UART0_RXDMA) || defined(CONFIG_UART1_RXDMA) || \
+    defined(CONFIG_UART2_RXDMA) || defined(CONFIG_UART3_RXDMA) || \
+    defined(CONFIG_UART4_RXDMA)
+# warning RX DMA is currently supported only for USART driver.
+#endif
+
+#if defined(SERIAL_HAVE_RXDMA) && !defined(CONFIG_SAMV7_XDMAC)
+# error SERIAL DMA requires CONFIG_SAMV7_XDMAC to be selected
+#endif
+
+#ifdef SERIAL_HAVE_CONSOLE_RXDMA
+# error RX DMA for serial console is currently not supported.
+#endif
+
+#if defined(CONFIG_UART0_TXDMA) || defined(CONFIG_UART1_TXDMA) || \
+    defined(CONFIG_UART2_TXDMA) || defined(CONFIG_UART3_TXDMA) || \
+    defined(CONFIG_UART4_TXDMA) || defined(CONFIG_USART0_TXDMA) || \
+    defined(CONFIG_USART1_TXDMA) || defined(CONFIG_USART2_TXDMA)
+# warning TX DMA is currently not supported.
+#endif
+
+#ifndef CONFIG_SAMV7_SERIAL_DMA_TIMEOUT
+# define CONFIG_SAMV7_SERIAL_DMA_TIMEOUT 0
+#endif
+
+#ifdef SERIAL_HAVE_RXDMA
+
+# define DMA_RXFLAGS  (DMACH_FLAG_FIFOCFG_LARGEST | \
+     DMACH_FLAG_PERIPHH2SEL | DMACH_FLAG_PERIPHISPERIPH |  \
+     DMACH_FLAG_PERIPHWIDTH_32BITS | DMACH_FLAG_PERIPHCHUNKSIZE_1 | \
+     DMACH_FLAG_MEMPID_MAX | DMACH_FLAG_MEMAHB_AHB_IF0 | \
+     DMACH_FLAG_PERIPHAHB_AHB_IF1 | DMACH_FLAG_MEMWIDTH_32BITS | \
+     DMACH_FLAG_MEMINCREMENT | DMACH_FLAG_MEMCHUNKSIZE_1 | \
+     DMACH_FLAG_MEMBURST_1)
+
+/* The DMA buffer size when using RX DMA to emulate a FIFO.
+ *
+ * When streaming data, the generic serial layer will be called
+ * every time the FIFO receives half this number of bytes.
+ */
+
+#  ifndef CONFIG_SAMV7_SERIAL_RXDMA_BUFFER
+#    define CONFIG_SAMV7_SERIAL_RXDMA_BUFFER 128
+#  endif
+#define RXDMA_CACHE_SIZE  ARMV7M_DCACHE_LINESIZE/sizeof(uint32_t)
+#define RXDMA_MUTIPLE (4 > RXDMA_CACHE_SIZE) ? (4) : (RXDMA_CACHE_SIZE)
+#define RXDMA_MUTIPLE_MASK  (RXDMA_MUTIPLE - 1)
+#define RXDMA_BUFFER_SIZE ((CONFIG_SAMV7_SERIAL_RXDMA_BUFFER \
+                           + RXDMA_MUTIPLE_MASK) \
+                           & ~RXDMA_MUTIPLE_MASK)

Review Comment:
   I agree it might not be needed in this case as`ARMV7M_DCACHE_LINESIZE` is always defined on samv7. However I think it is better to have it this way so the code could be more easily used on other platforms where this might not be the case. Hence why we added it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org