XMEGA学习——DMA使用(含源代码)
手头项目也需要加入DMA数据传输,以最大限度地提升CPU效率,于是测试了一下
XMEGA的DMA模块,
把一块内存中的数据DMA传输到另外一块内存,DMA传输完成后,
在中断函数中显示“DMA Finished”,
提示DMA成功完成数据传输
另外DMA使用更多的情况是大量数据到USART、SPI等 ,本文只是小试牛刀。
效果如下,
源代码:
#define DMA_BUFFER_SIZE 1024
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 \ref source
* - Destination address is set to \ref 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();
...
}
更多Atmel及科技资讯请关注:
Atmel中文官网:https://www.atmel.com/zh/cn/
Atmel技术论坛:https://atmel.eefocus.com/
Atmel中文博客:https://blog.sina.com.cn/u/2253031744
Atmel新浪微博:https://www.weibo.com/atmelcn
51单片机、AVR单片机和PIC单片机IO口结构的均不同,导致了IO口操作也不同。操作单片机IO口的目的是让单片机的管脚输出逻辑电平和读取单片机管脚的逻辑电平。下面我们来看看51单片机、AVR单片机和PIC单片机IO口的操作的方法。
休眠电流要最小:掉电模式必须的,然后能关闭的功能全部关闭,关闭BOD检测,关闭看门狗,电压越低越好,1.8V,频率越低越好。
51单片机、AVR单片机和PIC单片机IO口结构的均不同,导致了IO口操作也不同。操作单片机IO口的目的是让单片机的管脚输出逻辑电平和读取单片机管脚的逻辑电平。下面我们来看看51单片机、AVR单片机和PIC单片机IO口的操作的方法。
AVR® Insights — 第1集 — AVR存储器 AVR® Insights — 第2集 — 边写边读存储器 AVR® Insights — 第3集 — 端口 AVR® Insights — 第4集 — 休眠模式 AVR® Insights — 第5集 &mdash
什么是AVR单片机?AVR单片机有什么优点?为什么要选择AVR单片机?