Просмотр исходного кода

更新MCU工程: dwspi驱动支持DMA方式。

helen 1 месяц назад
Родитель
Сommit
3adc3ccc5b

+ 21 - 12
amt630hv160-mcu/amt630hv160-mcu-iram/src/ArkmicroFiles/libcpu-amt630hv160/source/amt630hv160_spi.c

@@ -540,6 +540,9 @@ static int dw_spi_transfer_one(SPISlave *slave, SPIMessage *message)
 	u32 bits_per_word = 0;
 	unsigned long transfer_timeout;
 	int ret = 0;
+#ifdef DWSPI_DMA_EN
+	int dma_mapped = 0;		//1 line mode does not support the DMA method.
+#endif
 
 	chip->tmode = SPI_TMOD_TR;
 
@@ -620,15 +623,16 @@ static int dw_spi_transfer_one(SPISlave *slave, SPIMessage *message)
 	 * we only need set the TXEI IRQ, as TX/RX always happen syncronizely
 	 */
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_setup(dws, message);
 		if (ret < 0) {
 			spi_enable_chip(dws, 1);
 			goto end;
 		}
-	} else
-#endif
+	} else if (!chip->poll_mode)
+#else
 	if (!chip->poll_mode)
+#endif
 	{
 		dws->regs->DMACR = 0;
 
@@ -649,7 +653,7 @@ static int dw_spi_transfer_one(SPISlave *slave, SPIMessage *message)
 	spi_enable_chip(dws, 1);
 
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_transfer(dws, message);
 		if (ret < 0)
 			goto end;
@@ -690,6 +694,9 @@ static int dw_qspi_read(SPISlave *slave, QSPIMessage *qspi_message)
 	u32 xfer_len = 0;
 	int ret = 0;
 	int hasmode = 0;
+#ifdef DWSPI_DMA_EN
+	int dma_mapped = dws->dma_mapped;
+#endif
 
 	chip->tmode = SPI_TMOD_RO;
 
@@ -787,15 +794,16 @@ xfer_continue:
 	 * we only need set the TXEI IRQ, as TX/RX always happen syncronizely
 	 */
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_setup(dws, message);
 		if (ret < 0) {
 			spi_enable_chip(dws, 1);
 			goto end;
 		}
-	} else
-#endif
+	} else if (!chip->poll_mode)
+#else
 	if (!chip->poll_mode)
+#endif
 	{
 		dws->regs->DMACR = 0;
 
@@ -818,7 +826,7 @@ xfer_continue:
 	spi_enable_chip(dws, 1);
 
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_transfer(dws, message);
 		if (ret < 0)
 			goto end;
@@ -844,20 +852,21 @@ xfer_continue:
 		int_error_stop(dws, "transfer timeout");
 		ret = -ETIMEDOUT;
 #ifdef DWSPI_DMA_EN
-		if (dws->dma_mapped)
+		if (dma_mapped)
 			DMA_StopChannel(dws->rxchan);
 #endif
 		goto end;
 	}
 
-	if (dws->dma_mapped && dws->rx_dummy_buffer) {
+#ifdef DWSPI_DMA_EN
+	if (dma_mapped && dws->rx_dummy_buffer) {
 		memcpy(dws->rx, dws->rx_dummy_buffer, dws->len);
 		vPortFree(dws->rx_dummy_buffer);
 		dws->rx_dummy_buffer = NULL;
 	}
 
-#ifdef DWSPI_DMA_EN
-	DMA_StopChannel(dws->rxchan);
+	if (dma_mapped)
+		DMA_StopChannel(dws->rxchan);
 #endif
 
 	xfer_len += dws->len;

+ 1 - 1
amt630hv160-mcu/amt630hv160-mcu-sram-nos/src/ArkmicroFiles/libcpu-amt630hv160/source/amt630hv160_dma.c

@@ -366,7 +366,7 @@ void DMA_IRQHandler(void)
 int DMA_Init(void)
 {
 	//sys_soft_reset(softreset_dma);
-	NVIC_RegisterIrq(DMA_IRQChannel, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 2, 0);
+	NVIC_RegisterIrq(DMA_IRQChannel, MAX_INTERRUPT_PRIORITY + 2, 0);
 
 	/* Clear all interrupts on all channels. */
 	DMA->IntTCClear = 0xff;

+ 21 - 12
amt630hv160-mcu/amt630hv160-mcu-sram-nos/src/ArkmicroFiles/libcpu-amt630hv160/source/amt630hv160_spi.c

@@ -540,6 +540,9 @@ static int dw_spi_transfer_one(SPISlave *slave, SPIMessage *message)
 	u32 bits_per_word = 0;
 	unsigned long transfer_timeout;
 	int ret = 0;
+#ifdef DWSPI_DMA_EN
+	int dma_mapped = 0;		//1 line mode does not support the DMA method.
+#endif
 
 	chip->tmode = SPI_TMOD_TR;
 
@@ -620,15 +623,16 @@ static int dw_spi_transfer_one(SPISlave *slave, SPIMessage *message)
 	 * we only need set the TXEI IRQ, as TX/RX always happen syncronizely
 	 */
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_setup(dws, message);
 		if (ret < 0) {
 			spi_enable_chip(dws, 1);
 			goto end;
 		}
-	} else
-#endif
+	} else if (!chip->poll_mode)
+#else
 	if (!chip->poll_mode)
+#endif
 	{
 		dws->regs->DMACR = 0;
 
@@ -649,7 +653,7 @@ static int dw_spi_transfer_one(SPISlave *slave, SPIMessage *message)
 	spi_enable_chip(dws, 1);
 
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_transfer(dws, message);
 		if (ret < 0)
 			goto end;
@@ -690,6 +694,9 @@ static int dw_qspi_read(SPISlave *slave, QSPIMessage *qspi_message)
 	u32 xfer_len = 0;
 	int ret = 0;
 	int hasmode = 0;
+#ifdef DWSPI_DMA_EN
+	int dma_mapped = dws->dma_mapped;
+#endif
 
 	chip->tmode = SPI_TMOD_RO;
 
@@ -787,15 +794,16 @@ xfer_continue:
 	 * we only need set the TXEI IRQ, as TX/RX always happen syncronizely
 	 */
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_setup(dws, message);
 		if (ret < 0) {
 			spi_enable_chip(dws, 1);
 			goto end;
 		}
-	} else
-#endif
+	} else if (!chip->poll_mode)
+#else
 	if (!chip->poll_mode)
+#endif
 	{
 		dws->regs->DMACR = 0;
 
@@ -818,7 +826,7 @@ xfer_continue:
 	spi_enable_chip(dws, 1);
 
 #ifdef DWSPI_DMA_EN
-	if (dws->dma_mapped) {
+	if (dma_mapped) {
 		ret = dws->dma_ops->dma_transfer(dws, message);
 		if (ret < 0)
 			goto end;
@@ -844,20 +852,21 @@ xfer_continue:
 		int_error_stop(dws, "transfer timeout");
 		ret = -ETIMEDOUT;
 #ifdef DWSPI_DMA_EN
-		if (dws->dma_mapped)
+		if (dma_mapped)
 			DMA_StopChannel(dws->rxchan);
 #endif
 		goto end;
 	}
 
-	if (dws->dma_mapped && dws->rx_dummy_buffer) {
+#ifdef DWSPI_DMA_EN
+	if (dma_mapped && dws->rx_dummy_buffer) {
 		memcpy(dws->rx, dws->rx_dummy_buffer, dws->len);
 		vPortFree(dws->rx_dummy_buffer);
 		dws->rx_dummy_buffer = NULL;
 	}
 
-#ifdef DWSPI_DMA_EN
-	DMA_StopChannel(dws->rxchan);
+	if (dma_mapped)
+		DMA_StopChannel(dws->rxchan);
 #endif
 
 	xfer_len += dws->len;