当前位置:首页 > 单片机 > 单片机
[导读].text.global _start_start:ldrsp,=4096bldisable_watch_dogblmemsetupblnand_initldrr0,=0x30000000movr1,#4096movr2,#2048blnand_readldrsp,=0x34000000ldrlr,=halt_loopldrpc,=mainhalt_loop:bhalt_loop#define W

.text
.global _start
_start:

ldrsp,=4096
bldisable_watch_dog
blmemsetup
blnand_init



ldrr0,=0x30000000
movr1,#4096
movr2,#2048
blnand_read

ldrsp,=0x34000000
ldrlr,=halt_loop
ldrpc,=main
halt_loop:
bhalt_loop


#define WATCH_DOG(*(volatile unsigned long *)0x53000000)


#define MEM_CTL_BASE0X48000000

void disable_watch_dog();
void memsetup();


void disable_watch_dog()
{
WATCH_DOG=0;
}


void memsetup()
{
int i=0;
unsigned long *p=(unsigned long *)MEM_CTL_BASE;

unsigned long const mem_cfg_val[]={0x22011110,//BWSCON
0x00000700,//BANKCON0
0x00000700,//BANKCON1
0x00000700,//BANKCON2
0x00000700,//BANKCON3
0x00000700,//BANKCON4
0x00000700,//BANKCON5
0x00018005,//BANKCON6
0x00018005,//BANKCON7
0x008C07A3,//refresh
0x000000b1,//BANKSIZE
0x00000030,//MRSRB6
0x00000030,//MRSRB7
};
for(;i<13;i++)
p[i]=mem_cfg_val[i];
}

#define LARGER_NAND_PAGE

#define GSTATUS1(*(volatile unsigned int *)0x560000B0)
#define BUSY1

#define NAND_SECTOR_SIZE512
#define NAND_BLOCK_MASK(NAND_SECTOR_SIZE - 1)

#define NAND_SECTOR_SIZE_LP2048
#define NAND_BLOCK_MASK_LP(NAND_SECTOR_SIZE_LP - 1)

typedef unsigned int S3C24X0_REG32;



typedef struct {
S3C24X0_REG32NFCONF;
S3C24X0_REG32NFCMD;
S3C24X0_REG32NFADDR;
S3C24X0_REG32NFDATA;
S3C24X0_REG32NFSTAT;
S3C24X0_REG32NFECC;
} S3C2410_NAND;


typedef struct {
S3C24X0_REG32NFCONF;
S3C24X0_REG32NFCONT;
S3C24X0_REG32NFCMD;
S3C24X0_REG32NFADDR;
S3C24X0_REG32NFDATA;
S3C24X0_REG32NFMECCD0;
S3C24X0_REG32NFMECCD1;
S3C24X0_REG32NFSECCD;
S3C24X0_REG32NFSTAT;
S3C24X0_REG32NFESTAT0;
S3C24X0_REG32NFESTAT1;
S3C24X0_REG32NFMECC0;
S3C24X0_REG32NFMECC1;
S3C24X0_REG32NFSECC;
S3C24X0_REG32NFSBLK;
S3C24X0_REG32NFEBLK;
} S3C2440_NAND;


typedef struct {
void (*nand_reset)(void);
void (*wait_idle)(void);
void (*nand_select_chip)(void);
void (*nand_deselect_chip)(void);
void (*write_cmd)(int cmd);
void (*write_addr)(unsigned int addr);
unsigned char (*read_data)(void);
}t_nand_chip;

static S3C2410_NAND * s3c2410nand = (S3C2410_NAND *)0x4e000000;
static S3C2440_NAND * s3c2440nand = (S3C2440_NAND *)0x4e000000;

static t_nand_chip nand_chip;


void nand_init(void);
void nand_read(unsigned char *buf, unsigned long start_addr, int size);


static void nand_reset(void);
static void wait_idle(void);
static void nand_select_chip(void);
static void nand_deselect_chip(void);
static void write_cmd(int cmd);
static void write_addr(unsigned int addr);
static unsigned char read_data(void);


static void s3c2410_nand_reset(void);
static void s3c2410_wait_idle(void);
static void s3c2410_nand_select_chip(void);
static void s3c2410_nand_deselect_chip(void);
static void s3c2410_write_cmd(int cmd);
static void s3c2410_write_addr(unsigned int addr);
static unsigned char s3c2410_read_data();


static void s3c2440_nand_reset(void);
static void s3c2440_wait_idle(void);
static void s3c2440_nand_select_chip(void);
static void s3c2440_nand_deselect_chip(void);
static void s3c2440_write_cmd(int cmd);
static void s3c2440_write_addr(unsigned int addr);
static unsigned char s3c2440_read_data(void);




static void s3c2410_nand_reset(void)
{
s3c2410_nand_select_chip();
s3c2410_write_cmd(0xff);// 复位命令
s3c2410_wait_idle();
s3c2410_nand_deselect_chip();
}


static void s3c2410_wait_idle(void)
{
int i;
volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFSTAT;
while(!(*p & BUSY))
for(i=0; i<10; i++);
}


static void s3c2410_nand_select_chip(void)
{
int i;
s3c2410nand->NFCONF &= ~(1<<11);
for(i=0; i<10; i++);
}


static void s3c2410_nand_deselect_chip(void)
{
s3c2410nand->NFCONF |= (1<<11);
}


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;
}




static void s3c2440_nand_reset(void)
{
s3c2440_nand_select_chip();
s3c2440_write_cmd(0xff);// 复位命令
s3c2440_wait_idle();
s3c2440_nand_deselect_chip();
}


static void s3c2440_wait_idle(void)
{
int i;
volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFSTAT;
while(!(*p & BUSY))
for(i=0; i<10; i++);
}


static void s3c2440_nand_select_chip(void)
{
int i;
s3c2440nand->NFCONT &= ~(1<<1);
for(i=0; i<10; i++);
}


static void s3c2440_nand_deselect_chip(void)
{
s3c2440nand->NFCONT |= (1<<1);
}


static void s3c2440_write_cmd(int cmd)
{
volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFCMD;
*p = cmd;
}


static void s3c2440_write_addr(unsigned int addr)
{
int i;
volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->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 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 TACLS0
#define TWRPH03
#define TWRPH10


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 ;
}


#define GPFCON(*(volatile unsigned long *)0x56000050)
#define GPFDAT(*(volatile unsigned long *)0x56000054)

#defineGPF4_OUT(1<<(2*4))
#define GPF5_OUT(1<<(2*5))
#define GPF6_OUT(1<<(2*6))

void Delay(volatile unsigned long dly)
{
for(;dly>0;dly--);
}

int main(void)
{
unsigned long i=0;

GPFCON=GPF4_OUT|GPF5_OUT|GPF6_OUT;

while(1)
{
Delay(20000);
GPFDAT=(~(i<<4));
if(++i==8)
i=0;
}

return 0;
}
nand.lds:
SECTIONS{
firtst0x00000000 : { head.o init.o nand.o }
second0x30000000 : AT(4096) { main.o }
}

Makefile:
objs := head.o init.o nand.o main.o

nand.bin : $(objs)
arm-linux-ld -Tnand.lds-o nand_elf $^
arm-linux-objcopy -O binary -S nand_elf $@
arm-linux-objdump -D -m armnand_elf > nand.dis

%.o:%.c
arm-linux-gcc -Wall -c -O2 -o $@ $<

%.o:%.S
arm-linux-gcc -Wall -c -O2 -o $@ $<

clean:
rm -fnand.dis nand.bin nand_elf *.o2017-11-17

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

9月2日消息,不造车的华为或将催生出更大的独角兽公司,随着阿维塔和赛力斯的入局,华为引望愈发显得引人瞩目。

关键字: 阿维塔 塞力斯 华为

加利福尼亚州圣克拉拉县2024年8月30日 /美通社/ -- 数字化转型技术解决方案公司Trianz今天宣布,该公司与Amazon Web Services (AWS)签订了...

关键字: AWS AN BSP 数字化

伦敦2024年8月29日 /美通社/ -- 英国汽车技术公司SODA.Auto推出其旗舰产品SODA V,这是全球首款涵盖汽车工程师从创意到认证的所有需求的工具,可用于创建软件定义汽车。 SODA V工具的开发耗时1.5...

关键字: 汽车 人工智能 智能驱动 BSP

北京2024年8月28日 /美通社/ -- 越来越多用户希望企业业务能7×24不间断运行,同时企业却面临越来越多业务中断的风险,如企业系统复杂性的增加,频繁的功能更新和发布等。如何确保业务连续性,提升韧性,成...

关键字: 亚马逊 解密 控制平面 BSP

8月30日消息,据媒体报道,腾讯和网易近期正在缩减他们对日本游戏市场的投资。

关键字: 腾讯 编码器 CPU

8月28日消息,今天上午,2024中国国际大数据产业博览会开幕式在贵阳举行,华为董事、质量流程IT总裁陶景文发表了演讲。

关键字: 华为 12nm EDA 半导体

8月28日消息,在2024中国国际大数据产业博览会上,华为常务董事、华为云CEO张平安发表演讲称,数字世界的话语权最终是由生态的繁荣决定的。

关键字: 华为 12nm 手机 卫星通信

要点: 有效应对环境变化,经营业绩稳中有升 落实提质增效举措,毛利润率延续升势 战略布局成效显著,战新业务引领增长 以科技创新为引领,提升企业核心竞争力 坚持高质量发展策略,塑强核心竞争优势...

关键字: 通信 BSP 电信运营商 数字经济

北京2024年8月27日 /美通社/ -- 8月21日,由中央广播电视总台与中国电影电视技术学会联合牵头组建的NVI技术创新联盟在BIRTV2024超高清全产业链发展研讨会上宣布正式成立。 活动现场 NVI技术创新联...

关键字: VI 传输协议 音频 BSP

北京2024年8月27日 /美通社/ -- 在8月23日举办的2024年长三角生态绿色一体化发展示范区联合招商会上,软通动力信息技术(集团)股份有限公司(以下简称"软通动力")与长三角投资(上海)有限...

关键字: BSP 信息技术
关闭
关闭