九 ARM9(2440)對nand flash的讀寫操作-程序?qū)嵗治?/h1>
本工程中用到的其他文件:
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)
#define EnNandFlash() (rNFCONT |= 1)
#define DsNandFlash() (rNFCONT &= ~1)
#define NFChipEn() (rNFCONT &= ~(1<<1))
#define NFChipDs() (rNFCONT |= (1<<1))
#define InitEcc() (rNFCONT |= (1<<4))
#define MEccUnlock() (rNFCONT &= ~(1<<5))
#define MEccLock() (rNFCONT |= (1<<5))
#define SEccUnlock() (rNFCONT &= ~(1<<6))
#define SEccLock() (rNFCONT |= (1<<6))
#define WrNFDat8(dat) (rNFDATA8 = (dat))
#define WrNFDat32(dat) (rNFDATA = (dat))
#define RdNFDat8() (rNFDATA8) //byte access
#define RdNFDat32() (rNFDATA) //word access
#define WrNFCmd(cmd) (rNFCMD = (cmd))
#define WrNFAddr(addr) (rNFADDR = (addr))
#define WrNFDat(dat) WrNFDat8(dat)
#define RdNFDat() RdNFDat8() //for 8 bit nand flash, use byte access
#define RdNFMEcc() (rNFMECC0) //for 8 bit nand flash, only use NFMECC0
#define RdNFSEcc() (rNFSECC) //for 8 bit nand flash, only use low 16 bits
#define RdNFStat() (rNFSTAT)
#define NFIsBusy() (!(rNFSTAT&1))
#define NFIsReady() (rNFSTAT&1)
#define READCMD0 0
#define READCMD1 0x30
#define ERASECMD0 0x60
#define ERASECMD1 0xd0
#define PROGCMD0 0x80
#define PROGCMD1 0x10
#define QUERYCMD 0x70
#define RdIDCMD 0x90
#define TACLS 1//7 // 1-clk(0ns)
#define TWRPH0 4//7 // 3-clk(25ns)
#define TWRPH1 1//7 // 1-clk(10ns) //TACLS+TWRPH0+TWRPH1>=50ns
#define U32 unsigned int
#define U16 unsigned short
#define S32 int
#define S16 short int
#define U8 unsigned char
#define S8 char
#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
// 0 1 0 , 0 1 0 0 , 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt 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);
}
另外還要加上初始化文件以跳轉(zhuǎn)到nandMain
以上就是一個完整的工程
本工程中用到的其他文件:
include.h:
#define rNFCONF (*(volatile unsigned *)0x4E000000)
#define rNFCONT (*(volatile unsigned *)0x4E000004)
#define rNFCMD
#define rNFADDR
#define rNFCMMD
#define rNFDATA
#define rNFDATA8
#define rNFMECC0
#define rNFSTAT
#define rNFESTAT0
#define rGPACON
#define rUTRSTAT0
#define rULCON0
#define rUCON0
#define rUFCON0
#define rUBRDIV0
#define WrUTXH0(ch) (*(volatile unsigned char *)0x50000020)=(unsigned char)(ch)
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define TACLS
#define TWRPH0
#define TWRPH1
#define U32 unsigned int
#define U16 unsigned short
#define S32 int
#define S16 short int
#define U8
#define
#define TRUE 1
#define FALSE 0
#define OK 1
#define FAIL 0
///////////////////////////////////////////////////////////////////////////////////////////////
uart.c
#include "include.h" //==================================================================== //===================================================================== 另外還要加上初始化文件以跳轉(zhuǎn)到nandMain 以上就是一個完整的工程
#include
void Uart_Init(int baud)
{
//UART0
//UART1
}
//=====================================================================
void Uart_SendByte(int data)
{
}
void Uart_SendString(S8 *pt)
{
}
//If you dont use vsprintf(), the code size is reduced very much.
void Uart_Printf(S8 *fmt,...)
{
}
評論