2019-03-03 13:22:37 +01:00
|
|
|
/************************************************************************************
|
|
|
|
* arch/arm/src/stm32h7/stm32_dma.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ARCH_ARM_SRC_STM32H7_STM32_DMA_H
|
|
|
|
#define __ARCH_ARM_SRC_STM32H7_STM32_DMA_H
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Included Files
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2019-05-25 00:54:25 +02:00
|
|
|
#include "hardware/stm32_dma.h"
|
|
|
|
#include "hardware/stm32_dmamux.h"
|
2019-03-03 13:22:37 +01:00
|
|
|
|
|
|
|
/* These definitions provide the bit encoding of the 'status' parameter passed to the
|
|
|
|
* DMA callback function (see dma_callback_t).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DMA_STATUS_FEIF 0 /* Stream FIFO error (ignored) */
|
|
|
|
#define DMA_STATUS_DMEIF DMA_STREAM_DMEIF_BIT /* Stream direct mode error */
|
|
|
|
#define DMA_STATUS_TEIF DMA_STREAM_TEIF_BIT /* Stream Transfer Error */
|
|
|
|
#define DMA_STATUS_HTIF DMA_STREAM_HTIF_BIT /* Stream Half Transfer */
|
|
|
|
#define DMA_STATUS_TCIF DMA_STREAM_TCIF_BIT /* Stream Transfer Complete */
|
|
|
|
|
|
|
|
#define DMA_STATUS_ERROR (DMA_STATUS_FEIF|DMA_STATUS_DMEIF|DMA_STATUS_TEIF)
|
|
|
|
#define DMA_STATUS_SUCCESS (DMA_STATUS_TCIF|DMA_STATUS_HTIF)
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Public Types
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
/* DMA channel configuration - common for DMA1 DMA2 MDMA and BDMA */
|
|
|
|
|
|
|
|
struct stm32_dma_config_s
|
|
|
|
{
|
|
|
|
uint32_t paddr; /* Peripheral address */
|
|
|
|
uint32_t maddr; /* Memory address */
|
|
|
|
uint32_t cfg1; /* DMA transfer configuration 1.
|
|
|
|
* Its function depends on DMA controller:
|
|
|
|
* - DMA1 and DMA2 - SCR register configuration
|
|
|
|
* - BDMA - CCR register configuration
|
|
|
|
* - MDMA - CCR register configuration
|
|
|
|
*/
|
|
|
|
uint32_t cfg2; /* DMA transfer configuration 2.
|
|
|
|
* Its function depends on DMA controller:
|
|
|
|
* - MDMA - CTCR register configuration
|
|
|
|
*/
|
|
|
|
uint32_t ndata; /* Number of data to transfer */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct stm32_dma_config_s stm32_dmacfg_t;
|
|
|
|
|
|
|
|
/* DMA_HANDLE Provides an opaque are reference that can be used to represent a DMA
|
|
|
|
* a DMA stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef FAR void *DMA_HANDLE;
|
|
|
|
|
|
|
|
/* Description:
|
|
|
|
* This is the type of the callback that is used to inform the user of the
|
|
|
|
* completion of the DMA. NOTE: The DMA module does *NOT* perform any cache
|
|
|
|
* operations. It is the responsibility of the DMA client to invalidate DMA
|
|
|
|
* buffers after completion of the DMA RX operations.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* handle - Refers tot he DMA channel or stream
|
|
|
|
* status - A bit encoded value that provides the completion status. See the
|
|
|
|
* DMASTATUS_* definitions above.
|
|
|
|
* arg - A user-provided value that was provided when stm32_dmastart() was
|
|
|
|
* called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void (*dma_callback_t)(DMA_HANDLE handle, uint8_t status, void *arg);
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Public Data
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmachannel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocate a DMA channel. This function gives the caller mutually
|
|
|
|
* exclusive access to the DMA channel specified by the 'dmamap' argument.
|
|
|
|
* It is common for standard DMA (DMA1, DMA2), master DMA (MDMA) and
|
|
|
|
* basic DMA (BDMA) controllers.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dmamap - Identifies the stream/channel resource. For the STM32 H7, this
|
|
|
|
* is a bit-encoded value as provided by the DMAMAP_* definitions
|
|
|
|
* in chip/stm32h7xxxxxxx_dmamux.h
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* One success, this function returns a non-NULL, void* DMA channel
|
|
|
|
* handle. NULL is returned on any failure. This function can fail only
|
|
|
|
* if no DMA channel is available.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - The caller does not hold he DMA channel.
|
|
|
|
* - The caller can wait for the DMA channel to be freed if it is no
|
|
|
|
* available.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
DMA_HANDLE stm32_dmachannel(unsigned int dmamap);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmafree
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release a DMA channel and unmap DMAMUX if required.
|
|
|
|
*
|
|
|
|
* NOTE: The 'handle' used in this argument must NEVER be used again
|
|
|
|
* until stm32_dmachannel() is called again to re-gain access to the channel.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - The caller holds the DMA channel.
|
|
|
|
* - There is no DMA in progress
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void stm32_dmafree(DMA_HANDLE handle);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmasetup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure DMA before using
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void stm32_dmasetup(DMA_HANDLE handle, stm32_dmacfg_t *cfg);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmastart
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void stm32_dmastart(DMA_HANDLE handle, dma_callback_t callback, void *arg,
|
|
|
|
bool half);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmastop
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void stm32_dmastop(DMA_HANDLE handle);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmaresidual
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
size_t stm32_dmaresidual(DMA_HANDLE handle);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmacapable
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32H7_DMACAPABLE
|
|
|
|
bool stm32_dmacapable(DMA_HANDLE handle, stm32_dmacfg_t *cfg);
|
|
|
|
#else
|
|
|
|
# define stm32_dmacapable(handle, cfg) (true)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_dmadump
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_DMA_INFO
|
|
|
|
void stm32_dmadump(DMA_HANDLE handle, const char *msg);
|
|
|
|
#else
|
|
|
|
# define stm32_dmadump(handle,msg)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __ARCH_ARM_SRC_STM32H7_STM32_DMA_H */
|