ARM·Nand Flash的控制
static void s3c2440_write_addr_lp(unsigned int addr)
{
int i;
volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;
int col, page;
col = addr & NAND_BLOCK_MASK_LP;
page = addr / NAND_SECTOR_SIZE_LP;
*p = col & 0xff;
for(i=0; i<10; i++);
*p = (col >> 8) & 0x0f;
for(i=0; i<10; i++);
*p = page & 0xff;
for(i=0; i<10; i++);
*p = (page >> 8) & 0xff;
for(i=0; i<10; i++);
*p = (page >> 16) & 0x03;
for(i=0; i<10; i++);
}
static unsigned char s3c2440_read_data(void)
{ volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFDATA; return *p;
}
static void nand_reset(void)
{ nand_chip.nand_reset();
}
static void wait_idle(void)
{ nand_chip.wait_idle();
}
static void nand_select_chip(void)
{ int i; nand_chip.nand_select_chip(); for(i=0; i<10; i++);
}
static void nand_deselect_chip(void)
{ nand_chip.nand_deselect_chip();
}
static void write_cmd(int cmd)
{ nand_chip.write_cmd(cmd);
}
static void write_addr(unsigned int addr)
{ nand_chip.write_addr(addr);
}
static unsigned char read_data(void)
{ return nand_chip.read_data();
}
void nand_init(void)
{
#define TACLS 0
#define TWRPH0 3
#define TWRPH1 0 if ((GSTATUS1 == 0x32410000) || (GSTATUS1 == 0x32410002)) { nand_chip.nand_reset = s3c2410_nand_reset; nand_chip.wait_idle = s3c2410_wait_idle; nand_chip.nand_select_chip = s3c2410_nand_select_chip; nand_chip.nand_deselect_chip = s3c2410_nand_deselect_chip; nand_chip.write_cmd = s3c2410_write_cmd; nand_chip.write_addr = s3c2410_write_addr; nand_chip.read_data = s3c2410_read_data; s3c2410nand->NFCONF = (1<<15)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); } else { nand_chip.nand_reset = s3c2440_nand_reset; nand_chip.wait_idle = s3c2440_wait_idle; nand_chip.nand_select_chip = s3c2440_nand_select_chip; nand_chip.nand_deselect_chip = s3c2440_nand_deselect_chip; nand_chip.write_cmd = s3c2440_write_cmd;
#ifdef LARGER_NAND_PAGE nand_chip.write_addr = s3c2440_write_addr_lp;
#else
nand_chip.write_addr = s3c2440_write_addr;
#endif nand_chip.read_data = s3c2440_read_data; s3c2440nand->NFCONF = (TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4); s3c2440nand->NFCONT = (1<<4)|(1<<1)|(1<<0); } nand_reset();
}
void nand_read(unsigned char *buf, unsigned long start_addr, int size)
{ int i, j;
#ifdef LARGER_NAND_PAGE if ((start_addr & NAND_BLOCK_MASK_LP) || (size & NAND_BLOCK_MASK_LP)) { return ; }
#else if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) { return ; }
#endif nand_select_chip(); for(i=start_addr; i < (start_addr + size);) { write_cmd(0); write_addr(i);
#ifdef LARGER_NAND_PAGE write_cmd(0x30);
#endif wait_idle();
#ifdef LARGER_NAND_PAGE for(j=0; j < NAND_SECTOR_SIZE_LP; j++, i++) {
#else for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
#endif *buf = read_data(); buf++; } } nand_deselect_chip(); return ;
}
這一長串紅色的代碼也就是Nand Flash的初始化,我們可以仔細(xì)的分析一下Nand的控制寄存器
再看代碼,從head.s中也就跳轉(zhuǎn)到了nand.c中的灰色部分 ;
1)S3C2410和S3C2440的一個判斷
2)定義了一個結(jié)構(gòu)體 { nand_chip.nand_reset = s3c2440_nand_reset; nand_chip.wait_idle = s3c2440_wait_idle; nand_chip.nand_select_chip = s3c2440_nand_select_chip; nand_chip.nand_deselect_chip = s3c2440_nand_deselect_chip; nand_chip.write_cmd = s3c2440_write_cmd;
#ifdef LARGER_NAND_PAGE nand_chip.write_addr = s3c2440_write_addr_lp;
#else
nand_chip.write_addr = s3c2440_write_addr;
#endif nand_chip.read_data = s3c2440_read_data; s3c2440nand->NFCONF = (TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4); s3c2440nand->NFCONT = (1<<4)|(1<<1)|(1<<0); }
*上面定義了結(jié)構(gòu)體,右邊一列都是s3c2440中可以調(diào)用的函數(shù) ;
*在設(shè)置時序中:【NFCONF】寄存器
使能NAND Flash控制器,初始化ECC,禁止片選 :【NFCONT】寄存器
(我覺得了解一下就好了,還真的去看時序啊,那個老師都沒說的清楚,估計是默認(rèn)值)
【NFCONF】
【NFCONT】
關(guān)鍵詞:
ARMNandFlas
相關(guān)推薦
技術(shù)專區(qū)
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機(jī)
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線
- 開關(guān)電源
- 單片機(jī)
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩(wěn)壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機(jī)控制
- 藍(lán)牙
- PLC
- PWM
- 汽車電子
- 轉(zhuǎn)換器
- 電源管理
- 信號放大器
評論