微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 九 ARM9(2440)对nand flash的读写操作-程序实例分析

九 ARM9(2440)对nand flash的读写操作-程序实例分析

时间:11-27 来源:互联网 点击:

2、单击菜单project->

3、单击Porcessor Views->

5、单击Execute->

6、单击Execute->

本工程中用到的其他文件:

include.h:

#define rNFCONF (*(volatile unsigned *)0x4E000000)

#define rNFCONT (*(volatile unsigned *)0x4E000004)

#define rNFCMD(*(volatile unsigned *)0x4E000008)

#define rNFADDR(*(volatile unsigned *)0x4E00000C)

#define rNFCMMD(*(volatile unsigned *)0x4E000008)

#define rNFDATA(*(volatile unsigned *)0x4E000010)

#define rNFDATA8(*(volatile unsigned char *)0x4E000010)

#define rNFMECC0(*(volatile unsigned *)0x4E00002c)

#define rNFSTAT(*(volatile unsigned *)0x4E000020)

#define rNFESTAT0(*(volatile unsigned *)0x4E000024)

#define rGPACON(*(volatile unsigned *)0x56000000)

#define rUTRSTAT0(*(volatile unsigned *)0x50000010)//UART 0 Tx/Rx status
#define rULCON0(*(volatile unsigned *)0x50000000)//UART 0 Line control
#define rUCON0(*(volatile unsigned *)0x50000004)//UART 0 Control
#define rUFCON0(*(volatile unsigned *)0x50000008)//UART 0 FIFO control
#define rUBRdiv0(*(volatile unsigned *)0x50000028)//UART 0 Baud rate divisor
#define WrUTXH0(ch) (*(volatile unsigned char *)0x50000020)=(unsigned char)(ch)

#defineEnNandFlash()(rNFCONT |= 1)
#defineDsNandFlash()(rNFCONT &= ~1)
#defineNFChipEn()(rNFCONT &= ~(1<1))
#defineNFChipDs()(rNFCONT |= (1<1))
#defineInitEcc()(rNFCONT |= (1<4))
#defineMEccUnlock()(rNFCONT &= ~(1<5))
#defineMEccLock()(rNFCONT |= (1<5))
#defineSEccUnlock()(rNFCONT &= ~(1<6))
#defineSEccLock()(rNFCONT |= (1<6))

#defineWrNFDat8(dat)(rNFDATA8 = (dat))
#defineWrNFDat32(dat)(rNFDATA = (dat))
#defineRdNFDat8()(rNFDATA8)//byte access
#defineRdNFDat32()(rNFDATA)//word access

#defineWrNFCmd(cmd)(rNFCMD = (cmd))
#defineWrNFAddr(addr)(rNFADDR = (addr))
#defineWrNFDat(dat)WrNFDat8(dat)
#defineRdNFDat()RdNFDat8()//for 8 bit nand flash, use byte access

#defineRdNFMEcc()(rNFMECC0)//for 8 bit nand flash, only use NFMECC0
#defineRdNFSEcc()(rNFSECC)//for 8 bit nand flash, only use low 16 bits

#defineRdNFStat()(rNFSTAT)
#defineNFIsBusy()(!(rNFSTAT&1))
#defineNFIsReady()(rNFSTAT&1)

#defineREADCMD00
#defineREADCMD10x30
#defineERASECMD00x60
#defineERASECMD10xd0
#definePROGCMD00x80
#definePROGCMD10x10
#defineQUERYCMD0x70
#defineRdIDCMD0x90

#define TACLS1//7// 1-clk(0ns)
#define TWRPH04//7// 3-clk(25ns)
#define TWRPH11//7// 1-clk(10ns)//TACLS+TWRPH0+TWRPH1>=50ns

#define U32 unsigned int
#define U16 unsigned short
#define S32 int
#define S16 short int
#define U8unsigned char
#defineS8char

#define TRUE 1
#define FALSE 0

#define OK 1
#define FAIL 0

///////////////////////////////////////////////////////////////////////////////////////////////
uart.c

#include "include.h"
#include

void Uart_Init(int baud)
{
int i;
rUFCON0 = 0x0;//UART channel 0 FIFO control register, FIFO disable


//UART0
rULCON0 = 0x3;//Line control register : Normal,No parity,1 stop,8 bits
//[10][9][8][7][6][5][4][3:2][1:0]
// Clock Sel,Tx Int,Rx Int, Rx Time Out, Rx err, Loop-back, Send break,Transmit Mode, Receive Mode
//010,0100,0101
//PCLKLevelPulseDisableGenerateNormalNormalInterrupt or Polling
rUCON0= 0x805;// Control register
rUBRdiv0=( (int)(50000000/16./baud+0.5) -1 );//Baud rate divisior register 0
//UART1

for(i=0;i<100;i++);
}


//=====================================================================
void Uart_SendByte(int data)
{

if(data==n)
{
while(!(rUTRSTAT0 & 0x2));
// Delay(1);//because the slow response of hyper_terminal
WrUTXH0(r);
}
while(!(rUTRSTAT0 & 0x2));//Wait until THR is empty.
//Delay(1);
WrUTXH0(data);


}

//====================================================================
void Uart_SendString(S8 *pt)
{
while(*pt)
Uart_SendByte(*pt++);
}

//=====================================================================
//If you dont use vsprintf(), the code size is reduced very much.
void Uart_Printf(S8 *fmt,...)
{
va_list ap;
S8 str[255];

va_start(ap,fmt);
vsprintf(str,fmt,ap);
Uart_SendString(str);
va_end(ap);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top