ARM开发步步深入之NandFlash 4KB突围
发出片选信号 */
static void s3c2410_nand_select_chip(void)
{
int i;
s3c2410nand->NFCONF &= ~(1<<11); //对NFCONF的11位写0,激活NandFlash
for(i=0; i<10; i++);
}
/* 取消片选信号 */
static void s3c2410_nand_deselect_chip(void)
{
s3c2410nand->NFCONF |= (1<<11); //对NFCONF的11位写1,使NandFlash不活动
}
/* 发出命令 */
static void s3c2410_write_cmd(int cmd)
{
volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFCMD;
*p = cmd;
}
/* 发出地址 */
static void s3c2410_write_addr(unsigned int addr)
{
int i;
volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFADDR;
*p = addr & 0xff;
for(i=0; i<10; i++);
*p = (addr >> 9) & 0xff;
for(i=0; i<10; i++);
*p = (addr >> 17) & 0xff;
for(i=0; i<10; i++);
*p = (addr >> 25) & 0xff;
for(i=0; i<10; i++);
}
/* 读取数据 */
static unsigned char s3c2410_read_data(void)
{
volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFDATA;
return *p;
}
//设置TACLS、TWRPH0、TWRPH1三者的值,貌似ViVi等代码中TWRPH0设为3,不知这样的好处,知道的可以告诉我!
#define TACLS 0
#define TWRPH0 2
#define TWRPH1 0
/* 初始化NandFlash */
void nand_init(void)
{
/* 使能NandFlash控制器, 初始化ECC, 禁止片选, 设置时序 */
s3c2410nand->NFCONF = (1<<15)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);
/* 复位s3c2410 NandFlash */
s3c2410_nand_reset();
}
#define NAND_SECTOR_SIZE 512
#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)
/* 读函数 */
void nand_read(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;
if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {
return ; /* 地址或长度不对齐 */
}
/* 选中芯片 */
s3c2410_nand_select_chip();
for(i=start_addr; i < (start_addr + size);) {
/* 发出READ0命令 */
s3c2410_write_cmd(0);
/* 写地址*/
s3c2410_write_addr(i);
/*等待*/
s3c2410_wait_idle();
for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
*buf = s3c2410_read_data();
buf++;
}
}
/* 取消片选信号 */
s3c2410_nand_deselect_chip();
return ;
};
- Linux嵌入式系统开发平台选型探讨(11-09)
- 基于ARM体系的嵌入式系统BSP的程序设计方案(04-11)
- 在Ubuntu上建立Arm Linux 开发环境(04-23)
- 达芬奇数字媒体片上系统的架构和Linux启动过程(06-02)
- SQLite嵌入式数据库系统的研究与实现(02-20)
- 革新2410D开发板试用手记(04-21)