📄 main.c
字号:
#include <common.h>
#include "config.h"
#include <common/lpc24xx.h>
#include <common/fio.h>
#include <common/uart.h>
//#include "project.h"
#include "yaffs2/yaffsfs.h"
#include <common/LPC_UTIL_DEFS.h>
#include <common/ex_sdram.h>
static void sysInit(void)
{
uint32_t i;
SCS |= GPIOM;
T0IR = 0; /* disable all timer0 interrupts */
T0TCR = 0; /* disable timer0 */
T0PR = CFG_SYS_CLK_FREQ / CFG_HZ;
T0MCR = 0;
T0TC = 0;
T0TCR = 1; /* enable timer0 */
reset_timer_masked();
//(1)DBUG test
uart0Init(UART_BAUD(HOST_BAUD_U0), UART_8N1, UART_FIFO_8); // setup the UART
printf("uart0 configure ok!\n");
#if 0
//(2)SDRAM test
//
for(i=0; i<100; i++)
{
*(volatile unsigned char *)(SDRAM_BASE_ADDR+i) = i;
}
for(i=0; i<100; i++)
{
if(*(volatile unsigned char *)(SDRAM_BASE_ADDR+i) != i)
{
break;
}
}
if(i == 100)printf("sdram test ok!\n");
else printf("sdram test error!\n");
#endif
//(3)EMAC test
printf("start test emac......\n");
// Init_EMAC();
printf("start test emac ok!\n");
FIO0DIR = (1 << 11) | (1<<17) | (1<<18) | (1<<19) | (1<<20) | (1<<21) | (1<<24) | (1<<25) | (1<<26);
FIO0CLR = (1<<11);
FIO0CLR = (1<<17);
FIO0CLR = (1<<18);
FIO0CLR = (1<<19);
FIO0CLR = (1<<20);
FIO0CLR = (1<<21);
FIO0CLR = (1<<24);
FIO0CLR = (1<<25);
FIO0CLR = (1<<26);
//nand support
EMC_CTRL = 0x00000001;
PCONP |= 0x00000800; /* Turn On EMC PCLK */
PINSEL6 = 0x55555555;//p4.0-p4.15 as A0-A15
PINSEL8 = 0x55555555;//p4.0-p4.15 as A0-A15
PINSEL9 = 0x50555555;//跟手册有出入? 0x5000A000:p4.24,p4.25 as OE,WE,p4.30,p4.31 as cs0,cs1
EMC_STA_CFG1 = 0x00000080;
/* for NAND FLASH */
PINSEL0 &= ~(0xF << 20); //0.10,0.11 as gpio
IODIR0 &= ~(1 << 10); //0.10 input
IODIR0 |= 1 << 11; //0.11 output
//EMC_CONFIG = 0;//little endian
//EMC_STA_CFG1 = 0;//8 bit,buffer...disabled
//EMC_STA_WAITWEN1 = 0;
//EMC_STA_WAITOEN1 = 0;
EMC_STA_WAITRD1 = 8; //2 should be enough
EMC_STA_WAITWR1 = 8;
//EMC_CTRL = 1;//enable,no map,normal mode
}
int nand_ready_lowlevel(void)
{
if(FIO0PIN & (1 << 10))
{
return 1;
}
return 0;
}
void dump_directory_tree_worker(const char *dname,int recursive)
{
yaffs_DIR *d;
yaffs_dirent *de;
struct yaffs_stat s;
char str[1000];
d = yaffs_opendir(dname);
if(!d)
{
printf("opendir failed\n");
}
else
{
while((de = yaffs_readdir(d)) != NULL)
{
sprintf(str,"%s/%s",dname,de->d_name);
yaffs_lstat(str,&s);
printf("%s inode %d obj %x length %d mode %X ",str,s.st_ino,de->d_dont_use,(int)s.st_size,s.st_mode);
switch(s.st_mode & S_IFMT)
{
case S_IFREG: printf("data file"); break;
case S_IFDIR: printf("directory"); break;
case S_IFLNK: printf("symlink -->");
if(yaffs_readlink(str,str,100) < 0)
printf("no alias");
else
printf("\"%s\"",str);
break;
default: printf("unknown"); break;
}
printf("\n");
if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
dump_directory_tree_worker(str,1);
}
yaffs_closedir(d);
}
}
void simple_rw_test(const char *mountpt)
{
int i;
int h;
char a[100];
int x;
int result;
sprintf(a,"%s/aaa",mountpt);
yaffs_StartUp();
yaffs_mount(mountpt);
yaffs_unlink(a);
h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
for(i = 100000;i < 200000; i++){
result = yaffs_write(h,&i,sizeof(i));
if(result != 4)
{
printf("write error\n");
exit(1);
}
}
//yaffs_close(h);
// h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
yaffs_lseek(h,0,SEEK_SET);
for(i = 100000; i < 200000; i++){
result = yaffs_read(h,&x,sizeof(x));
if(result != 4 || x != i){
printf("read error %d %x %x\n",i,result,x);
}
}
printf("Simple rw test passed\n");
}
static void dump_directory_tree(const char *dname)
{
dump_directory_tree_worker(dname,1);
printf("\n");
printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
}
void dumpDir(const char *dname)
{ dump_directory_tree_worker(dname,0);
printf("\n");
printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
}
void small_mount_test(const char *mountpt,int nmounts)
{
char a[30];
int i;
int j;
int h0;
int h1;
int len0;
int len1;
int nread;
sprintf(a,"%s/a",mountpt);
yaffs_StartUp();
for(i = 0; i < nmounts; i++){
static char xx[1000];
printf("############### Iteration %d Start\n",i);
if(1 || i == 0 || i == 5)
yaffs_mount(mountpt);
printf("dump_directory_tree = %s\n", mountpt);
dump_directory_tree(mountpt);
printf("yaffs_mkdir\n");
yaffs_mkdir(a,0);
sprintf(xx,"%s/0",a);
if(i ==0){
h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
for(j = 0; j < 130; j++)
yaffs_write(h0,xx,1000);
yaffs_close(h0);
}
h0 = yaffs_open(xx,O_RDONLY,0);
sprintf(xx,"%s/1",a);
h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
while((nread = yaffs_read(h0,xx,1000)) > 0)
yaffs_write(h1,xx,nread);
len0 = yaffs_lseek(h0,0,SEEK_END);
len1 = yaffs_lseek(h1,0,SEEK_END);
yaffs_lseek(h0,0,SEEK_SET);
yaffs_lseek(h1,0,SEEK_SET);
for(j = 0; j < 200; j++){
yaffs_read(h0,xx,1000);
yaffs_read(h1,xx,1000);
}
yaffs_close(h0);
yaffs_close(h1);
printf("########### %d\n",i);
printf("dump_directory_treen");
dump_directory_tree(mountpt);
if(1 || i == 4 || i == nmounts -1)
yaffs_unmount(mountpt);
}
}
void rmdir_test(const char *mountpt)
{
char name[100];
printf("%s, %d\n", __FUNCTION__, __LINE__);
yaffs_StartUp();
yaffs_mount(mountpt);
printf("%s, %d\n", __FUNCTION__, __LINE__);
strcpy(name,mountpt);
strcat(name,"/");
strcat(name,"hello");
yaffs_mkdir(name,0666);
yaffs_rmdir(name);
yaffs_unmount(mountpt);
}
void short_scan_test(const char *path, int fsize, int niterations)
{
int i;
char fn[100];
sprintf(fn,"%s/%s",path,"f1");
yaffs_StartUp();
for(i = 0; i < niterations; i++)
{
printf("\n*****************\nIteration %d\n",i);
yaffs_mount(path);
printf("\nmount: Directory look-up of %s\n",path);
dumpDir(path);
make_a_file(fn,1,fsize);
yaffs_unmount(path);
}
}
int main(void)
{
sysInit();
printf("all test pass, may be good board!\n");
NandInit();
printf("nand :\n");
nand_init();
// rmdir_test("/flash");
{
uint8_t buff[256];
int i;
memset(buff, 0, sizeof(buff));
NFReadoob(0x2800, buff);
for(i=0; i<16; i++)
{
printf("0x%02X ", buff[i]);
}
}
small_mount_test("/flash",1);
// cmd_yaffs_mount("/flash");
// simple_rw_test("/flash");
// short_scan_test("/flash",40000,200);
while(1);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -