mDMA implements DMA APIs for mbed. It is inspired by modDMA and simpleDMA. Compared with other mbed DMA implementations, mDMA has new features like 1) support LLI 2) support more than 4KB data transfer 3) support vectorized transfer. 4) support burst transfer. 5) Improved memory-memory transfer. It could beat memcpy 6) The library implementation fit the code structure of mbed sdk. Currently only support LPC1768 but could be extended to other platforms.

Dependents:   test_mDMA



File content as of revision 1:9421d79fb372:

#ifndef MBED_DMA_API_H
#define MBED_DMA_API_H

#include "device.h"
#include "platform.h"
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {

//Declare number of DMA channels available. Defined in the dma_api.c
extern int _channel_num ;

typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;

//DMA transfer type
typedef enum {
    M2M = 0x00,
    M2P = 0x01,
    P2M = 0x02,
    P2P = 0x03
} TransferType;

// DMA Trigger type.
// To be done: trigger type should be able to caculated automatically according to source/destination address
typedef enum {  
     ALWAYS ,
} TriggerType;

//define DMA interrupt type: ERR, generated when err happens; FINISH, generated when transfer finish
typedef enum {ERR, FINISH} DMA_IT;

// declear DMA IRQ. The real IRQ number will be defined in per platform file dma_api.c
extern IRQn_Type _DMA_IRQ;

// Forward declaration 
// DMA Init structures definition. It is used to describe DMA configurable features.

typedef struct DMA_InitTypeDef DMA_InitTypeDef;

typedef struct LLI
     uint32_t LLI_src;
     uint32_t LLI_dst;
     uint32_t LLI_next;
     uint32_t LLI_control; // Only care about transfer size, as other charactors will be same as initial transfer

void DMA_destination(DMA_InitTypeDef* DMA_InitStruct, const uint32_t dst, unsigned int width, bool inc);
void DMA_source(DMA_InitTypeDef* DMA_InitStruct, const uint32_t src, unsigned int width, bool inc);
void DMA_trigger_source(DMA_InitTypeDef* DMA_InitStruct, TriggerType trig);
void DMA_trigger_destination(DMA_InitTypeDef* DMA_InitStruct, TriggerType trig);

  * @brief  Initializes the DMAy Channelx according to the specified parameters
  *         in the DMA_InitStruct.
  * @param  channel. The chosen channel number.
  * @param  DMA_InitStruct: pointer to a DMA_InitTypeDef structure that contains
  *         the configuration information for the specified DMA Channel.
  * @retval None
void DMA_init(int channel, DMA_InitTypeDef* DMA_InitStruct);

void DMA_start(int channel, DMA_InitTypeDef* DMA_InitStruct, unsigned int lengh);
//void DMA_next(DMA_InitTypeDef* DMA_InitStruct, LLI* list);
void DMA_next(DMA_InitTypeDef* DMA_InitStruct, const uint32_t src, const uint32_t dst, uint32_t size); // The input size has to smaller than 4096bytes. 
  * @brief  Check whether channel is active or not
    * @param  channel. The channel number.
  * @retval 0 or 1
bool DMA_channel_active(int channel);

  * @brief  Reset the DMA channel to default reset value
  * @param  channel. The chosen channel number
  * @retval None
void DMA_reset(int channel);

  * @brief  Allocate a struct pointer point to DMA_InitTypeDef type memory space. Fills each DMA_InitStruct member with its default value.
  * @param  None
    * @retval a pointer point to a  DMA_InitTypeDef structure.
DMA_InitTypeDef*  DMA_struct_create(void);

  * @brief  Delete the memory allocated for the DMA_InitTypeDef structure
  * @param  A pointer point to a DMA_InitTypeDef structure 
    * @retval None
void DMA_struct_delete(DMA_InitTypeDef* ptr);

typedef void (*func_ptr)();

void DMA_IRQ_handler(void);
void DMA_IRQ_attach(int channel, int status, func_ptr ptr);
void DMA_IRQ_detach(int channel);

#ifdef __cplusplus