打印
[Atmel]

用ASF跑SAMD21程序(23)DMAC

[复制链接]
1150|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
首先建立ASF工程,然后工程中加入DMAC模块。


然后打开ASF EXPLORER 打开快速指导



然后按照快速指导来形成程序。

然后编译

当编译通过时,在DMAC传输完成后边打一个断点。

则目地数组内也有相应的数据:



时钟没有特别要求。

程序清单如下:


/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to system_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
/**
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/
#include <asf.h>
struct dma_resource example_resource;
#define DATA_LENGTH (512)
static uint8_t source_memory[DATA_LENGTH];
static uint8_t destination_memory[DATA_LENGTH];
static volatile bool transfer_is_done = false;
COMPILER_ALIGNED(16)
DmacDescriptor example_descriptor;
static void transfer_done( const struct dma_resource* const resource )
{    transfer_is_done = true;}
static void configure_dma_resource(struct dma_resource *resource)
{   
        struct dma_resource_config config;
        dma_get_config_defaults(&config);
        dma_allocate(resource, &config);}
static void setup_transfer_descriptor(DmacDescriptor *descriptor )
{   
        struct dma_descriptor_config descriptor_config;
        dma_descriptor_get_config_defaults(&descriptor_config);
        descriptor_config.block_transfer_count = sizeof(source_memory);
        descriptor_config.source_address = (uint32_t)source_memory +        sizeof(source_memory);
        descriptor_config.destination_address = (uint32_t)destination_memory +        sizeof(source_memory);
        dma_descriptor_create(descriptor, &descriptor_config);}


int main (void)
{
        system_init();
        
         configure_dma_resource(&example_resource);
         setup_transfer_descriptor(&example_descriptor);
         dma_add_descriptor(&example_resource, &example_descriptor);
         dma_register_callback(&example_resource, transfer_done,            DMA_CALLBACK_TRANSFER_DONE);
         dma_enable_callback(&example_resource, DMA_CALLBACK_TRANSFER_DONE);
         for (uint32_t i = 0; i < DATA_LENGTH; i++)
         {        source_memory[i] = i;    }

      
         
           dma_start_transfer_job(&example_resource);
           dma_trigger_transfer(&example_resource);
           while (!transfer_is_done) {        /* Wait for transfer done */    }   
           while (true) {        /* Nothing to do */    }
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2398

主题

6956

帖子

67

粉丝