DMA数据传输(源代码分享)

手头项目也需要加入dma数据传输,以最大限度地提升cpu效率,于是测试了一下xmega的dma模块,把一块内存中的数据dma传输到另外一块内存,dma传输完成后,在中断函数中显示“dma finished”,提示dma成功完成数据传输,另外dma使用更多的情况是大量数据到usart、spi等 ,本文只是小试牛刀。
效果如下,
源代码:
#define dma_buffer_size 1024
#define dma_channel 0
uint8_t source[dma_buffer_size],destination[dma_buffer_size];
static void fill_pattern(uint8_t *buffer, size_t len)
{
int i;
for (i = 0; i 《 len; i++) {
buffer = 42 ^ (i & 0xff) ^ (i 》》 8);
}
}
static bool verify_pattern(uint8_t *buffer, size_t len)
{
for (size_t i = 0; i 《 len; i++) {
if (buffer != (42 ^ (i & 0xff) ^ (i 》》 8))) {
return false;
}
}
return true;
}
void dma_test(void)
{
struct dma_channel_config config;
fill_pattern(source, dma_buffer_size);
memset(destination, 0, dma_buffer_size);
dma_enable();
memset(&config, 0, sizeof(config));
/*
* this example will configure a dma channel with the following
* settings:
* - low interrupt priority
* - 1 byte burst length
* - dma_buffer_size bytes for each transfer
* - reload source and destination address at end of each transfer
* - increment source and destination address during transfer
* - source address is set to ef source
* - destination address is set to ef destination
*/
dma_channel_set_interrupt_level(&config, dma_int_lvl_lo);
dma_channel_set_burst_length(&config, dma_ch_burstlen_1byte_gc);
dma_channel_set_transfer_count(&config, dma_buffer_size);
dma_channel_set_src_reload_mode(&config,
dma_ch_srcreload_transaction_gc);
dma_channel_set_dest_reload_mode(&config,
dma_ch_destreload_transaction_gc);
dma_channel_set_src_dir_mode(&config, dma_ch_srcdir_inc_gc);
dma_channel_set_dest_dir_mode(&config, dma_ch_destdir_inc_gc);
dma_channel_set_source_address(&config, (uint16_t)(uintptr_t)source);
dma_channel_set_destination_address(&config,
(uint16_t)(uintptr_t)destination);
dma_channel_write_config(dma_channel, &config);
/* use the configuration above by enabling the dma channel in use. */
dma_channel_enable(dma_channel);
/*
* enable interrupts as the example is now configured to handle them
* properly.
*/
cpu_irq_enable();
/*
* trigger a manual start since there is no trigger sources used in
* this example.
*/
dma_channel_trigger_block_transfer(dma_channel);
pmic_init();
cpu_irq_enable();
while(1);
}
isr(dma_ch0_vect)
{
gfx_mono_draw_string(“dma finished”,0,0,&sysfont);
}
int main(void)
{
。。。
dma_test();
。。。
}

智能音箱有望成为智能家居领域竞争的第一战场
物联网非IP连接的用途优势分析
慕尼黑华南电子展将继续携手芯师爷打造“硬核中国芯科技园
Baobab工作室宣布新成员加入VR电影《Crow: The Legend》
华为掌握了芯片技术了吗
DMA数据传输(源代码分享)
机智云追踪外卖骑手保温箱硬件开发和项目演示
物联网技术将如何改变社区生活?
如何修复轴头磨损问题
你觉得人脸识别进入了我们的生活吗
充电器选用U6215电源IC享受到实惠价格和优异品质
云计算服务中断表明多云至关重要
细菌检测仪的使用步骤是怎样的?
业界要闻:华为与微软可能在AI芯片达成合作、360和欧瑞博推出智能门锁
科创板南微医学董事、副总经理张博介绍、履历信息
电机保护器使用要注意的11个问题
也许很多人还不知道,魅族15竟能媲美 iPhone 的触觉反馈体验
变电站数字孪生3D可视化运维系统,实现智能电网电力行业智慧化数字化信息化转型升级
12864液晶屏驱动程序分享
大众入股国轩?让子弹再飞一会