arch/mips/src/pic32mz: Add DMA support.

This commit is contained in:
Abdelatif Guettouche
2019-06-28 10:03:18 -06:00
committed by Gregory Nutt
parent 87499ba3ec
commit ee32b449a6
6 changed files with 1186 additions and 108 deletions
+1 -1
View File
@@ -52,7 +52,7 @@
#elif defined(CHIP_PIC32MZEF)
# include <arch/pic32mz/irq_pic32mzxxxef.h>
#else
# error "Unknown PIC32MZ family
# error "Unknown PIC32MZ family"
#endif
/****************************************************************************
+5
View File
@@ -111,3 +111,8 @@ endif
ifeq ($(CONFIG_PIC32MZ_ETHERNET),y)
CHIP_CSRCS += pic32mz-ethernet.c
endif
ifeq ($(CONFIG_PIC32MZ_DMA),y)
CHIP_CSRCS += pic32mz-dma.c
endif
+9 -4
View File
@@ -52,7 +52,7 @@
********************************************************************************************/
/* DMA Channel Offsets **********************************************************************/
#define PIC32MZ_DMACHn_OFFSET(n) (0x0060 + 00c0 *(n))
#define PIC32MZ_DMACHn_OFFSET(n) (0x0060 + 0xc0 *(n))
# define PIC32MZ_DMACH0_OFFSET 0x0060
# define PIC32MZ_DMACH1_OFFSET 0x0120
# define PIC32MZ_DMACH2_OFFSET 0x01e0
@@ -386,6 +386,7 @@
# define PIC32MZ_DMACH2_DATCLR (PIC32MZ_DMACH2_K1BASE+PIC32MZ_DMACH_DATCLR_OFFSET)
# define PIC32MZ_DMACH2_DATSET (PIC32MZ_DMACH2_K1BASE+PIC32MZ_DMACH_DATSET_OFFSET)
# define PIC32MZ_DMACH2_DATINV (PIC32MZ_DMACH2_K1BASE+PIC32MZ_DMACH_DATINV_OFFSET)
#endif
#if CHIP_NDMACH > 3
# define PIC32MZ_DMACH3_CON (PIC32MZ_DMACH3_K1BASE+PIC32MZ_DMACH_CON_OFFSET)
@@ -658,8 +659,8 @@
/* DMA Status Register */
#define DMA_STAT_DMACH_SHIFT (0) /* Bits 0-1: DMA channel */
#define DMA_STAT_DMACH_MASK (3 << DMA_STAT_DMACH_SHIFT)
#define DMA_STAT_RDWR (1 << 3) /* Bit 3: Read/write status */
#define DMA_STAT_DMACH_MASK (7 << DMA_STAT_DMACH_SHIFT)
#define DMA_STAT_RDWR (1 << 31) /* Bit 31: Read/write status */
/* DMA Address Register -- This register contains a 32-bit address value */
@@ -737,6 +738,10 @@
#define DMACH_INT_CHDDIE (1 << 21) /* Bit 21: Channel destination done interrupt enable */
#define DMACH_INT_CHSHIE (1 << 22) /* Bit 22: Channel source half empty interrupt enable */
#define DMACH_INT_CHSDIE (1 << 23) /* Bit 23: Channel source done interrupt enable */
#define DMACH_INT_FLAGS_SHIFT (0) /* Bits 0-7: Channel Interrupt flags */
#define DMACH_INT_FLAGS_MASK (0xff << DMACH_INT_FLAGS_SHIFT)
#define DMACH_INT_EN_SHIFT (16) /* Bits 16-23: Channel Interrupt Enable events */
#define DMACH_INT_EN_MASK (0xff << DMACH_INT_EN_SHIFT)
/* DMA Channel Source Start Address Register -- This register contains a 32-bit address value */
/* DMA Channel Destination Start Address Register -- This register contains a 32-bit address value */
@@ -762,7 +767,7 @@
/* DMA Channel Cell Pointer Register -- 16 bits of byte transferred data */
#define DMACH_DPCR_MASK 0x0000ffff
#define DMACH_CPTR_MASK 0x0000ffff
/* DMA Channel Pattern Data Register -- 16 bits of pattern data */
@@ -47,7 +47,7 @@
#elif defined(CONFIG_ARCH_CHIP_PIC32MZEF)
# include "hardware/pic32mzef-memorymap.h"
#else
# error Unknown PIC32MZ family
# error "Unknown PIC32MZ family"
#endif
#endif /* __ARCH_MIPS_SRC_PIC32MZ_HARDWARE_PIC32MZ_MEMORYMAP_H */
File diff suppressed because it is too large Load Diff
+190 -102
View File
@@ -1,7 +1,7 @@
/************************************************************************************
* arch/mips/src/pic32mx/pic32mx-dma.h
* arch/mips/src/pic32mz/pic32mz-dma.h
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -36,6 +36,40 @@
#ifndef __ARCH_MIPS_SRC_PIC32MZ_PIC32MZ_DMA_H
#define __ARCH_MIPS_SRC_PIC32MZ_PIC32MZ_DMA_H
/* General Usage:
*
* 1. Allocate a DMA channel
*
* DMA_HANDLE handle;
* handle = pic32mz_dma_alloc(chcfg);
*
* where chcfg is the channel's configuration (see struct pic32mz_dma_chcfg)
*
* 2. Setup the transfer
*
* struct pic32mz_dma_xfrcfg_s xfrcfg;
* xfrcfg.srcaddr = ...;
* xfrcfg.destaddr = ...;
* etc.
*
* pic32mz_dma_xfrsetup(handle, xfrcfg);
*
* 3. Start the transfer
*
* pic32mz_dma_start(handle, callback, arg);
*
* If a start irq is set this function will only enable the channel.
* The transfer will be controlled by the start irq.
* If no start irq is specified then the a force start is performed.
*
* 4. Stop and free the channel
*
* The DMA channel can be aborted if an abort irq is set.
* Alternatively, call to pic32mz_dma_stop will force the abort.
*
* pic32mz_dma_free will free the channel and make it available.
*/
/************************************************************************************
* Included Files
************************************************************************************/
@@ -46,49 +80,129 @@
#include <sys/types.h>
#include <stdint.h>
#include "hardware/pic32mz-dma.h"
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/************************************************************************************
/* Interrupt type arguments for pic32mz_dma_intctrl. */
#define PIC32MZ_DMA_INT_SRCDONE DMACH_INT_CHSDIE
#define PIC32MZ_DMA_INT_SRCHALF DMACH_INT_CHSHIE
#define PIC32MZ_DMA_INT_DESTDONE DMACH_INT_CHDDIE
#define PIC32MZ_DMA_INT_DESTHALF DMACH_INT_CHDHIE
#define PIC32MZ_DMA_INT_BLOCKDONE DMACH_INT_CHBCIE
#define PIC32MZ_DMA_INT_CELLDONE DMACH_INT_CHCCIE
#define PIC32MZ_DMA_INT_ABORT DMACH_INT_CHTAIE
#define PIC32MZ_DMA_INT_ERR DMACH_INT_CHERIE
#define PIC32MZ_DMA_INT_DISABLE (0)
/* This is used when setting a channel with no start/abort event */
#define PIC32MZ_DMA_NOEVENT (NR_IRQS + 1)
/*******************************************************************************
* Public Types
************************************************************************************/
*
******************************************************************************/
#ifndef __ASSEMBLY__
typedef FAR void *DMA_HANDLE;
typedef void (*dma_callback_t)(DMA_HANDLE handle, void *arg, int result);
typedef void (*dma_callback_t)(DMA_HANDLE handle, uint8_t status, void *arg);
/* The following is used for sampling DMA registers when CONFIG DEBUG_DMA is selected */
enum pic32mz_dma_chmode_e
{
PIC32MZ_DMA_MODE_BASIC = 1 << 0U, /* Basic transfert mode */
PIC32MZ_DMA_MODE_AUTOEN = 1 << 1U, /* Channel Auto-Enable mode */
PIC32MZ_DMA_MODE_PMATCH = 1 << 2U, /* Pattern Match termination mode */
PIC32MZ_DMA_MODE_CHCHAIN = 1 << 3U, /* Channel chaining mode */
PIC32MZ_DMA_MODE_SFM = 1 << 4U /* Special Function Module mode */
};
/* This structure holds the channel's configuration */
struct pic32mz_dma_chcfg_s
{
uint8_t priority; /* Channel's priority (0..3) */
uint8_t startirq; /* Start event */
uint8_t abortirq; /* Abort event */
uint8_t event; /* Interrupt event */
enum pic32mz_dma_chmode_e mode; /* Channel's mode of operation */
};
/* This structure holds a transfer's configuration */
struct pic32mz_dma_xfrcfg_s
{
uint32_t srcaddr; /* Source address */
uint32_t destaddr; /* Destination address */
uint16_t srcsize; /* Source size */
uint16_t destsize; /* Destination size */
uint16_t cellsize; /* Cell size */
};
/* The following is used for sampling DMA registers when CONFIG_DEBUG_DMA
* is selected
*/
#ifdef CONFIG_DEBUG_DMA
struct pic32mx_dmaglobalregs_s
{
/* Global Registers */
#warning "Missing definitions"
};
struct pic32mx_dmachanregs_s
{
/* Channel Registers */
#warning "Missing definitions"
};
struct pic32mx_dmaregs_s
struct pic32mz_dmagblregs_s
{
/* Global Registers */
struct pic32mx_dmaglobalregs_s gbl;
uint32_t con;
uint32_t stat;
uint32_t addr;
};
struct pic32mz_dmacrcregs_s
{
/* CRC Registers */
uint32_t con;
uint32_t data;
uint32_t xor;
};
struct pic32mz_dmachanregs_s
{
/* Channel Registers */
uint32_t con;
uint32_t econ;
uint32_t intcon;
uint32_t ssa;
uint32_t dsa;
uint32_t ssiz;
uint32_t dsiz;
uint32_t sptr;
uint32_t dptr;
uint32_t csiz;
uint32_t cptr;
uint32_t dat;
};
struct pic32mz_dmaregs_s
{
/* Global Registers */
struct pic32mz_dmagblregs_s gbl;
/* CRC Registers */
struct pic32mz_dmacrcregs_s crc;
/* Channel Registers */
struct pic32mx_dmachanregs_s ch;
struct pic32mz_dmachanregs_s ch;
};
#endif
/************************************************************************************
/*******************************************************************************
* Public Data
************************************************************************************/
******************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
@@ -99,129 +213,102 @@ extern "C"
#define EXTERN extern
#endif
/************************************************************************************
/*******************************************************************************
* Public Function Prototypes
************************************************************************************/
******************************************************************************/
/************************************************************************************
* Name: pic32mx_dmainitialize
/*******************************************************************************
* Name: pic32mz_dma_alloc
*
* Description:
* Initialize the GPDMA subsystem.
* Allocate a DMA channel. This function sets aside a DMA channel and gives
* the caller exclusive access to the DMA channel.
*
* Returned Value:
* On 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.
*
******************************************************************************/
DMA_HANDLE pic32mz_dma_alloc(const struct pic32mz_dma_chcfg_s *cfg);
/*******************************************************************************
* Name: pic32mz_dma_free
*
* Description:
* Release a DMA channel.
* NOTE: The 'handle' used in this argument must NEVER be used again until
* pic32mz_dmachannel() is called again to re-gain a valid handle.
*
* Returned Value:
* None
*
************************************************************************************/
******************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
void pic32mx_dmainitilaize(void);
#endif
void pic32mz_dma_free(DMA_HANDLE handle);
/************************************************************************************
* Name: pic32mx_dmachannel
*
* Description:
* Allocate a DMA channel. This function sets aside a DMA channel and gives the
* caller exclusive access to the DMA channel.
*
* 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.
*
************************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
DMA_HANDLE pic32mx_dmachannel(void);
#endif
/************************************************************************************
* Name: pic32mx_dmafree
*
* Description:
* Release a DMA channel. NOTE: The 'handle' used in this argument must NEVER be
* used again until pic32mx_dmachannel() is called again to re-gain a valid handle.
*
* Returned Value:
* None
*
************************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
void pic32mx_dmafree(DMA_HANDLE handle);
#endif
/************************************************************************************
* Name: pic32mx_dmasetup
/*******************************************************************************
* Name: pic32mz_dma_xfrsetup
*
* Description:
* Configure DMA for one transfer.
*
************************************************************************************/
******************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
int pic32mx_dmarxsetup(DMA_HANDLE handle, uint32_t control, uint32_t config,
uint32_t srcaddr, uint32_t destaddr, size_t nbytes);
#endif
int pic32mz_dma_xfrsetup(DMA_HANDLE handle,
FAR const struct pic32mz_dma_xfrcfg_s *cfg);
/************************************************************************************
* Name: pic32mx_dmastart
/*******************************************************************************
* Name: pic32mz_dma_start
*
* Description:
* Start the DMA transfer
*
************************************************************************************/
******************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
int pic32mx_dmastart(DMA_HANDLE handle, dma_callback_t callback, void *arg);
#endif
int pic32mz_dma_start(DMA_HANDLE handle, dma_callback_t callback, void *arg);
/************************************************************************************
* Name: pic32mx_dmastop
/*******************************************************************************
* Name: pic32mz_dma_stop
*
* Description:
* Cancel the DMA. After pic32mx_dmastop() is called, the DMA channel is reset
* and pic32mx_dmasetup() must be called before pic32mx_dmastart() can be called
* again
* Cancel the DMA.
* After pic32mz_dma_stop() is called, the DMA channel is reset
* and pic32mz_dma_xfrsetup() must be called before pic32mz_dma_start()
* can be called again.
*
************************************************************************************/
******************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
void pic32mx_dmastop(DMA_HANDLE handle);
#endif
void pic32mz_dma_stop(DMA_HANDLE handle);
/************************************************************************************
* Name: pic32mx_dmasample
/*******************************************************************************
* Name: pic32mz_dma_sample
*
* Description:
* Sample DMA register contents
*
************************************************************************************/
******************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
#ifdef CONFIG_DEBUG_DMA
void pic32mx_dmasample(DMA_HANDLE handle, struct pic32mx_dmaregs_s *regs);
void pic32mz_dma_sample(DMA_HANDLE handle, struct pic32mz_dmaregs_s *regs);
#else
# define pic32mx_dmasample(handle,regs)
#endif
# define pic32mz_dma_sample(handle,regs)
#endif
/************************************************************************************
* Name: pic32mx_dmadump
/*******************************************************************************
* Name: pic32mz_dma_dump
*
* Description:
* Dump previously sampled DMA register contents
*
************************************************************************************/
******************************************************************************/
#ifdef CONFIG_PIC32MX_DMA
#ifdef CONFIG_DEBUG_DMA
void pic32mx_dmadump(DMA_HANDLE handle, const struct pic32mx_dmaregs_s *regs,
void pic32mz_dma_dump(DMA_HANDLE handle, const struct pic32mz_dmaregs_s *regs,
const char *msg);
#else
# define pic32mx_dmadump(handle,regs,msg)
#endif
# define pic32mz_dma_dump(handle,regs,msg)
#endif
#if defined(__cplusplus)
@@ -231,3 +318,4 @@ void pic32mx_dmadump(DMA_HANDLE handle, const struct pic32mx_dmaregs_s *regs,
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_MIPS_SRC_PIC32MZ_PIC32MZ_DMA_H */