📄 main.c
字号:
/*************************************************************************************
* Copyright (c) 2007 by PROCHIP Limited.
* PROPRIETARY RIGHTS of PROCHIP Limited are involved in the subject matter of this
* material. All manufacturing, reproduction, use, and sales rights
* pertaining to this subject matter are governed by the license agreement.
* The recipient of this software implicitly accepts the terms of the license.
*
* File Name: main.c
*
* File Description: 主函数, 实现具体功能.
*
* Version Date Author
*------------------------------------------------------------------------------------
* 0.0.1 2008.1.9 Zhang Yang
*
*************************************************************************************
*/
#include <stdio.h>
#include "ub4020evb.h"
#include "intc.h"
#include "emitest.h"
int main()
{
int i =0;
U32 result=0x33000000;
U32 judge =0x3310000;
U32 flag=0;
for (i=0;i<25;i++);
INT_INIT();
/********* ok now ***********/
//select the clk rate
/*
*(RP)PMU_PMDR = 0x01; // slow-->normal (4M/48M , 2.5M/30M)
for(i = 0; i < 10; i++);
===========================================================//
#ifdef PMC_100M
*(RP)PMU_PMCR =0x8399 ; // 4M/100M(200/2)
for(i = 0; i < 10; i++);
#endif
===========================================================//
#ifdef PMC_80M
*(RP)PMU_PMCR =0x8394 ; // 4M/80M(160/2)
for(i = 0; i < 10; i++);
#endif
==========================================================//
#ifdef PMC_50M
*(RP)PMU_PMCR =0x8799 ; // 4M/50M(200/4)
for(i = 0; i < 10; i++);
#endif
*/
//在SRAM中开辟一个空间来存放本程序的运行结果
for(i=0;i<20;i++)
{
*(RP)(result+i*4)=0;
}
*(RP)judge = 0x00000000;
INI_EMI();
//*********** all commands test of NAND *********
//check value with the address of "result+0xc" for the result, 0 for well, 其他对应各个步骤的错误
#ifdef BASIC_OPERATION_NAND
flag = 0;
if(NAND_WRITE(0x30000000,0x10)!=0) flag = 1 ;//write
else if(NAND_READ_STATUS()!=0) flag = 2 ;//send the read status command to check the program status of NAND
else if(((*(RP)EMI_NAND_STA)&1)==1) flag = 3 ;//read the nand status from the EMI register if it showes erase pass then
else if(NAND_READ(0x30180000,0x10)!=0) flag = 4 ;//read
//else if(COMPARE_MEM(0x34000000, 0x34180000,132)!=0)flag = 5 ;//compare,hareware ECC,no software ECC
else if(NAND_ERASE(0x10)!=0) flag = 6 ;//erase
else if(NAND_READ_STATUS()!=0) flag = 7 ;//send the read status command to check the erase status of NAND
else if(((*(RP)EMI_NAND_STA)&1)==1) flag = 8 ;//read the nand status from the EMI register if it showes erase pass then
else if(NAND_WRITE(0x30000100,0x11)!=0) flag = 9 ;//write
else if(NAND_READ(0x32000000,0x11)!=0) flag = 10 ;//read
//else if(COMPARE_MEM(0x34000020, 0x36000000,132)!=0)flag = 11 ;//compare,hareware ECC,no software ECC
else if(NAND_READ_ID()!=0) flag = 12 ;//read id
*(RP)(result+0xc) = flag;
//****************************
if( *(RP)(result+0xc)!=0x0)
{
*(RP)judge=0xffffffff;
}else
{
*(RP)judge=0x00000000;
}
//*****************************
#endif
//************* ECC *****************************
//观察value with the address of "result+0x14",非0则表明正常第一页的ecc校验过程有错
//由EMIADDR_NANDERRORADDR1和EMIADDR_NANDERRORADDR2的读取结果,结合选取使用force语句的时间,
//判断用户手册的描述是否正确
//观察value with the address of "result+0x18",非0则表明正常第二页的ecc校验过程有错
#ifdef ECC
i=0;//for count the times of reading the EMIADDR_NANDFINECC
NAND_WRITE(0x30000000,0x0);
NAND_WRITE(0x30000000,0x1);
flag=NAND_READ(0x30180000,0x0);
if(flag!=0) *(RP)(result+0x14) = 1 ;//write and read
else
{
while(((*(RP)EMI_NAND_ECC&=1)==0)&&(i<100)) i++;
if(i>=100)*(RP)(result+0x14) = 2;
else
{
flag=*(RP)EMI_ERR_ADDR1;
flag=*(RP)EMI_ERR_ADDR2;
if((*(RP)EMI_NAND_INTR&=1)==0) *(RP)(result+0x14) = 3;
else
{
*(RP)EMI_NAND_INTR=0;
if((*(RP)EMI_NAND_INTR&=1)!=0) *(RP)(result+0x14) = 4;
else *(RP)(result+0x14) = 4;
}
}
}
if((NAND_READ(0x30180000,0x1))!=0)*(RP)(result+0x18)=1;
else
{
while(((*(RP)EMI_NAND_ECC&=1)==0)&&(i<100)) i++;
if(i>=100)*(RP)(result+0x18)=2;
else
{
flag=*(RP)EMI_ERR_ADDR1;
flag=*(RP)EMI_ERR_ADDR2;
if((*(RP)EMI_NAND_INTR&=1)==0) *(RP)(result+0x18)=3;
else
{
*(RP)EMI_NAND_INTR=0;
if((*(RP)EMI_NAND_INTR&=1)!=0)*(RP)(result+0x18)=4;
else *(RP)(result+0x18)=0;
}
}
}
//****************************
if(*(RP)(result+0x14)==0x0)
{
*(RP)judge=0xffffffff;
}else
{
*(RP)judge=0x00000000;
}
if(*(RP)(result+0x18)==0x0)
{
*(RP)judge=0xffffffff;
}else
{
*(RP)judge=0x00000000;
}
//*****************************
#endif
while(1);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -