手頭項目也需要加入DMA數(shù)據(jù)傳輸,以最大限度地提升CPU效率,于是測試了一下XMEGA的DMA模塊,把一塊內(nèi)存中的數(shù)據(jù)DMA傳輸?shù)搅硗庖粔K內(nèi)存,DMA傳輸完成后,在中斷函數(shù)中顯示“DMAFinished”,提示DMA成功完成數(shù)據(jù)傳輸,另外DMA使用更多的情況是大量數(shù)據(jù)到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();
。。。
}
-
cpu
+關(guān)注
關(guān)注
68文章
10902瀏覽量
212997 -
數(shù)據(jù)傳輸
+關(guān)注
關(guān)注
9文章
1952瀏覽量
64852 -
dma
+關(guān)注
關(guān)注
3文章
566瀏覽量
100953
發(fā)布評論請先 登錄
相關(guān)推薦
CW32L052單片機支持DMA實現(xiàn)高速數(shù)據(jù)傳輸
Serial RapidIO接口DMA數(shù)據(jù)傳輸
DMA的數(shù)據(jù)傳輸速率是多少?
請問怎樣去設(shè)計一種Ultra DMA數(shù)據(jù)傳輸系統(tǒng)?
怎樣去實現(xiàn)DMA數(shù)據(jù)傳輸的有效進行呢
MPC5748G無法通過DMA將傳輸的數(shù)據(jù)傳輸到終端上的UART怎么解決?
DMA進行數(shù)據(jù)傳輸和CPU進行數(shù)據(jù)傳輸的疑問
數(shù)據(jù)傳輸速率是什么意思
DMA數(shù)據(jù)傳輸在SPEAR300實現(xiàn)高速串口驅(qū)動設(shè)計
![<b class='flag-5'>DMA</b><b class='flag-5'>數(shù)據(jù)傳輸</b>在SPEAR300實現(xiàn)高速串口驅(qū)動設(shè)計](https://file1.elecfans.com//web2/M00/A7/37/wKgZomUMQxKAI9zMAAAdg82_Gis405.jpg)
STM32定時器觸發(fā)DMA數(shù)據(jù)傳輸失敗的原因如何解決
![STM32定時器觸發(fā)<b class='flag-5'>DMA</b><b class='flag-5'>數(shù)據(jù)傳輸</b>失敗的原因如何解決](https://file.elecfans.com/web1/M00/75/9B/pIYBAFv5-TCAf65fAAIlPKKTQRM972.png)
淺析AXI DMA收發(fā)數(shù)據(jù)傳輸過程
SPI數(shù)據(jù)傳輸有哪些方式
![SPI<b class='flag-5'>數(shù)據(jù)傳輸</b>有哪些方式](https://file1.elecfans.com/web2/M00/8D/B5/wKgaomS_OQeAN3ojAADH16bJMbU306.jpg)
評論