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/10/05 20:02:10 UTC
[GitHub] [incubator-nuttx] btashton commented on a diff in pull request #7229: bl602: Add initial DMA support, including SPI over DMA.
btashton commented on code in PR #7229:
URL: https://github.com/apache/incubator-nuttx/pull/7229#discussion_r985621166
##########
arch/risc-v/src/bl602/bl602_dma.h:
##########
@@ -0,0 +1,262 @@
+/****************************************************************************
+ * arch/risc-v/src/bl602/bl602_dma.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RISCV_SRC_BL602_BL602_DMA_H
+#define __ARCH_RISCV_SRC_BL602_BL602_DMA_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BL602_DMA_NCHANNELS 4
+#define BL602_DMA_INT_EVT_TC 0 /* Interrupt callback status Transfer Complete */
+#define BL602_DMA_INT_EVT_ERR 1 /* Interrupt callback status Error */
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifdef CONFIG_DEBUG_DMA_INFO
+struct bl602_dmaregs_s
+{
+ uint32_t intstatus; /* Interrupt status. */
+ uint32_t inttcstatus; /* Interrupt terminal count request status. */
+ uint32_t inttcclear; /* Terminal count request clear. */
+ uint32_t interrorstatus; /* Interrupt error status. */
+ uint32_t interrclr; /* Interrupt error clear. */
+ uint32_t rawinttcstatus; /* Status of the terminal count interrupt prior to masking. */
+ uint32_t rawinterrorstatus; /* Status of the error interrupt prior to masking. */
+ uint32_t enbldchns; /* Channel enable status. */
+ uint32_t softbreq; /* Software burst request. */
+ uint32_t softsreq; /* Software single request. */
+ uint32_t softlbreq; /* Software last burst request. */
+ uint32_t softlsreq; /* Software last single request. */
+ uint32_t top_config; /* DMA general configuration. */
+ uint32_t sync; /* DMA request asynchronous setting. */
+ uint32_t c0srcaddr; /* Channel DMA source address. */
+ uint32_t c0dstaddr; /* Channel DMA Destination address. */
+ uint32_t c0lli; /* Channel DMA link list. */
+ uint32_t c0control; /* Channel DMA bus control. */
+ uint32_t c0config; /* Channel DMA configuration. */
+ uint32_t c1srcaddr; /* Channel DMA source address. */
+ uint32_t c1dstaddr; /* Channel DMA Destination address. */
+ uint32_t c1lli; /* Channel DMA link list. */
+ uint32_t c1control; /* Channel DMA bus control. */
+ uint32_t c1config; /* Channel DMA configuration. */
+ uint32_t c2srcaddr; /* Channel DMA source address. */
+ uint32_t c2dstaddr; /* Channel DMA Destination address. */
+ uint32_t c2lli; /* Channel DMA link list. */
+ uint32_t c2control; /* Channel DMA bus control. */
+ uint32_t c2config; /* Channel DMA configuration. */
+ uint32_t c3srcaddr; /* Channel DMA source address. */
+ uint32_t c3dstaddr; /* Channel DMA Destination address. */
+ uint32_t c3lli; /* Channel DMA link list. */
+ uint32_t c3control; /* Channel DMA bus control. */
+ uint32_t c3config; /* Channel DMA configuration. */
+};
+#endif
+
+/* Configuration for the LLI Control entry, defined as matching
+ * the DMA channel control register.
+ */
+
+begin_packed_struct struct bl602_dma_ctrl_s
+{
+ uint32_t transfer_size : 12;
+ uint32_t src_burst_size : 3;
+ uint32_t dst_burst_size : 3;
+ uint32_t src_width : 3;
+ uint32_t dst_width : 3;
+ uint32_t sld : 1;
+ uint32_t rsvd : 1;
+ uint32_t src_increment : 1;
+ uint32_t dst_increment : 1;
+ uint32_t protect : 3;
+ uint32_t tc_int_en : 1;
+} end_packed_struct;
+
+/* Configuration for the LLI packed data.
+ * This must be aligned to uint32 pointer.
+ */
+
+begin_packed_struct struct aligned_data(4) bl602_lli_ctrl_s
Review Comment:
Compiler warns that this could be aligned 1.
##########
arch/risc-v/src/common/riscv_initialize.c:
##########
@@ -105,6 +105,19 @@ void up_initialize(void)
riscv_pminitialize();
#endif
+#ifdef CONFIG_ARCH_DMA
+ /* Initialize the DMA subsystem if the weak function arm_dma_initialize has
+ * been brought into the build
+ */
+
+#ifdef CONFIG_HAVE_WEAKFUNCTIONS
+ if (riscv_dma_initialize)
Review Comment:
This is how we do this for ARM.
##########
arch/risc-v/src/bl602/bl602_dma.c:
##########
@@ -0,0 +1,491 @@
+/****************************************************************************
+ * arch/risc-v/src/bl602/bl602_dma.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/arch.h>
+
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include "chip.h"
+#include "riscv_internal.h"
+#include "hardware/bl602_dma.h"
+#include "bl602_dma.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure describes one DMA channel */
+
+struct dma_channel_s
+{
+ uint8_t chan; /* DMA channel number (0-BL602_DMA_NCHANNELS) */
+ bool inuse; /* TRUE: The DMA channel is in use */
+ bl602_dma_callback_t callback; /* Callback invoked when the DMA completes */
+ void *arg; /* Argument passed to callback function */
+};
+
+/* This structure describes the state of the DMA controller */
+
+struct dma_controller_s
+{
+ sem_t exclsem; /* Protects channel table */
Review Comment:
I was not sure if that PR was a prerequisite for the conversion. If the machinery already exists I can use it.
##########
arch/risc-v/src/common/riscv_initialize.c:
##########
@@ -105,6 +105,19 @@ void up_initialize(void)
riscv_pminitialize();
#endif
+#ifdef CONFIG_ARCH_DMA
+ /* Initialize the DMA subsystem if the weak function arm_dma_initialize has
+ * been brought into the build
+ */
+
+#ifdef CONFIG_HAVE_WEAKFUNCTIONS
+ if (riscv_dma_initialize)
Review Comment:
This is how we do this for ARM.https://github.com/apache/incubator-nuttx/blob/70290b6e384e979e44fe3f9777b62e6c1aad787a/arch/arm/src/common/arm_initialize.c#L118
--
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