Board logo

标题: [求助]继续询问关于FLASH用DMA的问题 [打印本页]

作者: beibeinv    时间: 2008-4-14 16:00     标题: [求助]继续询问关于FLASH用DMA的问题

看到大家说可以使用DMA对FLASH进行操作,我又试验了几次,还是没有成功,不知道问题在哪里,我想将SDRAM的数据通过DMA方式写入FLASH中。我的程序如下,请大家帮我看看:

#include <stdio.h>
#include <string.h>
#include <io.h>
//#include "includes.h"
#include <alt_types.h>
#include "sys/alt_irq.h"

#include "system.h"
#include "sys/alt_dma.h"
#include "altera_avalon_dma.h"
#include "altera_avalon_dma_regs.h"

#include "sys/alt_flash.h"

static volatile unsigned int *P_write_RAM=
(unsigned int *)(EXT_RAM_DMA_BASE);*/
static volatile unsigned short int *P_read_RAM=
(unsigned short int *)(SDRAM_BASE);
static volatile unsigned short int *P_write_RAM=
(unsigned short int *)(FLASH_BASE);

void DMA_interrupts(void* context, alt_u32 id);
void init_dma(void);
void write_data(void);
/******************************************************************
* Function: main
*
* Purpose: Continually prints the menu and performs the actions
* requested by the user.
*
******************************************************************/
int main(void)
{
alt_flash_fd* fd;
int ret_code;
int j;
write_data();
alt_irq_register(DMA_IRQ,0,DMA_interrupts);
init_dma();

while(1)
{
;
}
return (0);
}

//DMA传输设置
void init_dma(void)
{
alt_irq_register(DMA_IRQ,0,DMA_interrupts); //注册DMA中断服务程序
IOWR_ALTERA_AVALON_DMA_CONTROL (DMA_BASE, 0);//清控制寄存器

IOWR_ALTERA_AVALON_DMA_STATUS (DMA_BASE, 0);//清状态寄存器

IOWR_ALTERA_AVALON_DMA_LENGTH (DMA_BASE, 1024);//写入一次DMA传输的总数据长度

IOWR_ALTERA_AVALON_DMA_RADDRESS (DMA_BASE,(int)P_read_RAM);//DMA传输的源地址
IOWR_ALTERA_AVALON_DMA_WADDRESS (DMA_BASE,(int)P_write_RAM);//DMA传输的目的地址

IOWR_ALTERA_AVALON_DMA_CONTROL (DMA_BASE,
ALTERA_AVALON_DMA_CONTROL_HW_MSK | //半字传输
ALTERA_AVALON_DMA_CONTROL_GO_MSK |//启动DMA
ALTERA_AVALON_DMA_CONTROL_I_EN_MSK |//开中断
// ALTERA_AVALON_DMA_CONTROL_WCON_MSK |
// ALTERA_AVALON_DMA_CONTROL_WEEN_MSK |
ALTERA_AVALON_DMA_CONTROL_LEEN_MSK
);

}


//DMA中断服务程序
void DMA_interrupts(void* context, alt_u32 id)
{
// int i;
// for(i=0;i<300;i++);
int si=IORD_ALTERA_AVALON_DMA_STATUS (DMA_BASE);//读取状态寄存器
if(si&0x1)//判断是否传输完成,如果传输完成,重新设置DMA。
{
IOWR_ALTERA_AVALON_DMA_CONTROL (DMA_BASE, 0);
IOWR_ALTERA_AVALON_DMA_STATUS (DMA_BASE, 0);
IOWR_ALTERA_AVALON_DMA_CONTROL (DMA_BASE, 0);
IOWR_ALTERA_AVALON_DMA_LENGTH (DMA_BASE, 1024);

IOWR_ALTERA_AVALON_DMA_RADDRESS (DMA_BASE,(int)P_read_RAM);
IOWR_ALTERA_AVALON_DMA_WADDRESS (DMA_BASE,(int)P_write_RAM);

IOWR_ALTERA_AVALON_DMA_CONTROL (DMA_BASE,
ALTERA_AVALON_DMA_CONTROL_HW_MSK |
ALTERA_AVALON_DMA_CONTROL_GO_MSK |
ALTERA_AVALON_DMA_CONTROL_I_EN_MSK |
ALTERA_AVALON_DMA_CONTROL_WCON_MSK |
// ALTERA_AVALON_DMA_CONTROL_WEEN_MSK |
ALTERA_AVALON_DMA_CONTROL_LEEN_MSK
);
}
}
/////////////////
void write_data(void)
{
int i,j;
for(j=0;j<16;j++)
{
for(i=0;i<1024;i++)
{
P_read_RAM=0xcc;
}
}
}

不知有什么问题,请大家帮我指点一下,谢谢!


作者: beibeinv    时间: 2008-4-15 16:30

自己顶一下






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0