[Atmel] 用ASF跑SAMD21程序(23)DMAC

[复制链接]
1358|0
 楼主| ddllxxrr 发表于 2015-1-26 20:23 | 显示全部楼层 |阅读模式
首先建立ASF工程,然后工程中加入DMAC模块。


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



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

然后编译

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

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



时钟没有特别要求。

程序清单如下:


  1. /**
  2. * \file
  3. *
  4. * \brief Empty user application template
  5. *
  6. */

  7. /**
  8. * \mainpage User Application template doxygen documentation
  9. *
  10. * \par Empty user application template
  11. *
  12. * This is a bare minimum user application template.
  13. *
  14. * For documentation of the board, go \ref group_common_boards "here" for a link
  15. * to the board-specific documentation.
  16. *
  17. * \par Content
  18. *
  19. * -# Include the ASF header files (through asf.h)
  20. * -# Minimal main function that starts with a call to system_init()
  21. * -# Basic usage of on-board LED and button
  22. * -# "Insert application code here" comment
  23. *
  24. */

  25. /*
  26. * Include header files for all drivers that have been imported from
  27. * Atmel Software Framework (ASF).
  28. */
  29. /**
  30. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  31. */
  32. #include <asf.h>
  33. struct dma_resource example_resource;
  34. #define DATA_LENGTH (512)
  35. static uint8_t source_memory[DATA_LENGTH];
  36. static uint8_t destination_memory[DATA_LENGTH];
  37. static volatile bool transfer_is_done = false;
  38. COMPILER_ALIGNED(16)
  39. DmacDescriptor example_descriptor;
  40. static void transfer_done( const struct dma_resource* const resource )
  41. {    transfer_is_done = true;}
  42. static void configure_dma_resource(struct dma_resource *resource)
  43. {   
  44.         struct dma_resource_config config;
  45.         dma_get_config_defaults(&config);
  46.         dma_allocate(resource, &config);}
  47. static void setup_transfer_descriptor(DmacDescriptor *descriptor )
  48. {   
  49.         struct dma_descriptor_config descriptor_config;
  50.         dma_descriptor_get_config_defaults(&descriptor_config);
  51.         descriptor_config.block_transfer_count = sizeof(source_memory);
  52.         descriptor_config.source_address = (uint32_t)source_memory +        sizeof(source_memory);
  53.         descriptor_config.destination_address = (uint32_t)destination_memory +        sizeof(source_memory);
  54.         dma_descriptor_create(descriptor, &descriptor_config);}


  55. int main (void)
  56. {
  57.         system_init();
  58.         
  59.          configure_dma_resource(&example_resource);
  60.          setup_transfer_descriptor(&example_descriptor);
  61.          dma_add_descriptor(&example_resource, &example_descriptor);
  62.          dma_register_callback(&example_resource, transfer_done,            DMA_CALLBACK_TRANSFER_DONE);
  63.          dma_enable_callback(&example_resource, DMA_CALLBACK_TRANSFER_DONE);
  64.          for (uint32_t i = 0; i < DATA_LENGTH; i++)
  65.          {        source_memory[i] = i;    }

  66.       
  67.          
  68.            dma_start_transfer_job(&example_resource);
  69.            dma_trigger_transfer(&example_resource);
  70.            while (!transfer_is_done) {        /* Wait for transfer done */    }   
  71.            while (true) {        /* Nothing to do */    }
  72. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

7001

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部