⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smiltest.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
字号:
/*********************************************************************** 
 * $Workfile:   smiltest.c  $ 
 * $Revision: 1.1.1.1 $ 
 * $Author: meterchen $ 
 * $Date: 2003/11/10 17:00:55 $ 
 * 
 * Project:     NAND FLASH MANAGEMENT
 * 
 * Description: 
 *        
 *
 * Revision History: 
 * 
 *********************************************************************** 
 * 
 *  Copyright (c) 2003 CHENMENG
 * 
 *  All rights reserved 
 * 
 **********************************************************************/

//< smiltest.c >
#include <stdio.h>
//#include <conio.h>
#include <stdlib.h>
#include "common.h"
/***************************************************************************/
void DispTitle(void);
void DispMenu(void);
char SelectMenu(void);
void DumpBufData(unsigned char *);
void SetBufData(unsigned long,unsigned short);
int CheckBufData(unsigned long,unsigned short);
/***************************************************************************/
extern int Init$SmartMedia(void);
extern int Check$SmartMedia(void);
extern int Check$Parameter(unsigned short *,unsigned char *,unsigned char *);
extern int Media$ReadSector(unsigned long,unsigned short,unsigned char *);
extern int Media$WriteSector(unsigned long,unsigned short,unsigned char *);
extern int Media$EraseBlock(unsigned long,unsigned short);
extern int Media$EraseAll(void);
extern int Logical$Format(void);
extern void Led$TernOn(void);
extern void Led$TernOff(void);
/***************************************************************************/
unsigned char buf[0x20][0x200];
/***************************************************************************
SmartMedia Controll Main Routine
***************************************************************************/
#define printf Uart_Printf
#define getch  Uart_Getch
#define scanf  Uart_GetIntNum

#include <string.h>
#include "..\inc\option.h"
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"

int Main()
{
	unsigned long start;
	unsigned short count;
	int ch, ErrCode;
	unsigned short c;
	unsigned char h,s;
	unsigned char buf1[512],buf2[512];
	
	__rt_lib_init();
	
	rSYSCFG=0;//CACHECFG;	// Using 8KB Cache//
	Port_Init();
	//Isr_Init();
	Uart_Init(0,115200);

	Led_Display(0xf);
	Delay(0);
	
	Init$SmartMedia();
	
	/* use only once in factory */
	//Physical$Format();
	
	Media$ReadSector(0L,1,buf[0]); /* Dummy Read */
	DispTitle();
	DispMenu();
	while(1) {
		switch(SelectMenu()) {
		case '0':
			Led$TernOn();
			ErrCode=Check$SmartMedia();
			if(! ErrCode)
				{ printf("\n\n ****** SmartMedia Ready ****** \n"); break; }
			if(ErrCode==ERR_ChangedMedia)
				printf("\n\n ****** Medium Changed !! ****** \n");
			if(ErrCode==ERR_NoSmartMedia)
				printf("\n\n ****** No SmartMedia !! ****** \n");
			printf("\t\t\t\t\t\t ErrCode : %02X \n",ErrCode);
			break;
		case '1':
			printf("\n << Verify Sectors >>\n");
			printf(" Start Sector (Hex) : "); start=scanf();//scanf("%lx", &start);
			printf(" Counts <max.0x20> (Hex) : "); count=scanf();//scanf("%x", &count);
			if(count>0x20) count=0x20;
			printf("\n");
			printf(" Read Sectors ( Start: %08lxh, Count: %02xh )", start,count);
			printf("\n\n");
			/*****/
			Led$TernOn();
			ErrCode=Media$ReadSector(start,count,buf[0]);
			if(! ErrCode) {
				if(! CheckBufData(start,count))
					printf("\n\n ***** Data Read Finished. ***** \n");
				else printf("\n\n ** Illegal Sector ID Data !! ** \n");
				break;
			}
			if(! ErrCode)
				{ printf("\n\n ***** Data Read Finished. ***** \n"); break; }
			printf("\n\n ***** Data Read Error !! ***** \n");
			printf("\t\t\t\t\t\t ErrCode : %02X \n",ErrCode);
			break;
		case '2':
			printf("\n << Write Sectors >>\n");
			printf(" Start Sector (Hex) : "); start=scanf();//scanf("%lx", &start);
			printf(" Counts <max.0x20> (Hex) : "); count=scanf();//scanf("%x", &count);
			if(count>0x20) count=0x20;
			printf("\n");
			printf(" Write Sectors ( Start: %08lxh, Count: %02xh )", start,count);
			printf("\n Data Write ? (Yes/No) ");
			ch=getch();
			if(ch!='y' && ch!='Y')
				{ printf("\n\n ****** Write Canceled. ****** \n"); break; }
			printf("\n");
			/*****/
			Led$TernOn();
			SetBufData(start,count);
			ErrCode=Media$WriteSector(start,count,buf[0]);
			if(! ErrCode)
				{ printf("\n\n ***** Data Write Finished. ***** \n"); break; }
			printf("\n\n ***** Data Write Error !! ***** \n");
			printf("\t\t\t\t\t\t ErrCode : %02X \n",ErrCode);
			break;
		case '3':
			printf("\n << Dump Sector Data >>\n");
			printf(" Start Sector (Hex) : "); start=scanf();//scanf("%lx", &start);
			printf("\n");
			printf(" Dump Sector Data ( Start: %08lxh )", start);
			printf("\n\n");
			/*****/
			Led$TernOn();
			ErrCode=Media$ReadSector(start,1,buf[0]);
			if(! ErrCode) {
				DumpBufData(&buf[0][0]);
				break;
			}
			printf("\n\n ****** Data Read Error !! ****** \n");
			printf("\t\t\t\t\t\t ErrCode : %02X \n",ErrCode);
			DumpBufData(&buf[0][0]);
			break;
		case '7':
			printf("\n DOS Format ? (Yes/No) ");
			ch=getch();
			if(ch!='y' && ch!='Y')
				{ printf("\n\n ****** Format Canceled. ****** \n"); break; }
			printf("\n");
			Led$TernOn();
			ErrCode=Logical$Format();
			if(! ErrCode)
				{ printf("\n\n ****** Format Finished. ****** \n"); break; }
			printf("\n\n ****** Format Error !! ****** \n");
			printf("\t\t\t\t\t\t ErrCode : %02X \n",ErrCode);
			break;
		case '8':
			printf("\n Erase All Sectors ? (Yes/No) ");
			ch=getch();
			if(ch!='y' && ch!='Y')
				{ printf("\n\n ****** Erase Canceled. ****** \n"); break; }
			printf("\n");
			Led$TernOn();
			ErrCode=Media$EraseAll();
			if(! ErrCode)
				{ printf("\n\n ****** Erase Finished. ****** \n"); break; }
			printf("\n\n ****** Erase Error !! ****** \n");
			printf("\t\t\t\t\t\t ErrCode : %02X \n",ErrCode);
			break;
		case '9':
			Led$TernOn();
			ErrCode=Check$Parameter(&c,&h,&s);
			if(! ErrCode)
				{ printf("\n\n Cyl: %04Xh, Head: %02Xh, Sect: %02Xh \n",c,h,s); break; }
			printf("\t\t\t\t\t\t ErrCode : %02X \n",ErrCode);
			break;
		case 'q':
		case 'Q': Init$SmartMedia(); return(0);
		case '?':
		default: DispMenu(); break;
}
Led$TernOff();
}
return(0);
}
/***************************************************************************
SmartMedia Controll Subroutine
***************************************************************************/
void DispTitle(void)
{
	printf("\n");
	printf("\n ****************************************************************************");
	printf("\n ****** SmartMedia(TM) Interface Library Support Software ****************");
	printf("\n ****************************************************************************");
	printf("\n Copyright (c) 1997-2000, Toshiba Corporation. All rights reserved. ");
	printf("\n\n\n\n\n\n");
}
void DispMenu(void)
{
	printf("\n");
	printf("\n ***** SmartMedia(TM) Controll Menu (Ver 1.00) ***");
	printf("\n 0: Check SmartMedia ");
	printf("\n 1: Verify Sectors ");
	printf("\n 2: Write Sectors ");
	printf("\n 3: Dump Sector Data ");
	printf("\n *: ---------------------- ");
	printf("\n 7: DOS Format ");
	printf("\n 8: Erase All Sectors ");
	printf("\n 9: Read CHS Parameter ");
	printf("\n Q: Quit ");
	printf("\n ***************************************************");
}
char SelectMenu(void)
{
	char c;
	printf("\n\nCommand : ");
	c=(char)getch();
	return(c);
}
void DumpBufData(unsigned char *buf)
{
	char h, i, j;
	unsigned char s[0x10];
	for(h=0; h<2; h++) {
		for(i=0; i<0x10; i++) {
			printf("\n %04Xh: ",h*0x100+i*0x10);
			for(j=0; j<0x10; j++) {
				s[j]=*buf++;
				printf(" %02X",s[j]);
				s[j]=(unsigned char)((' '<=s[j]&&s[j]<='~')?s[j]:'.');
			}
			printf(" ");
			for(j=0; j<0x10; j++)
				printf("%c",s[j]);
		}
		if(h==0) {
			printf("\n\n ******* Hit Any Key ******* \n\n");
			getch();
		}
	}
}
void SetBufData(unsigned long start, unsigned short count)
{
	unsigned short sect;
	int i;
	for(sect=0; sect<count; sect++) {
		for(i=0; i<0x200; i++)
			buf[sect][i]=(char)rand();
		buf[sect][4]=0x00;
		buf[sect][3]=(unsigned char)(start &0xFF);
		buf[sect][2]=(unsigned char)((start/0x100L) &0xFF);
		buf[sect][1]=(unsigned char)((start/0x10000L) &0xFF);
		buf[sect][0]=(unsigned char)((start/0x1000000L) &0xFF);
		start++;
	}
}
int CheckBufData(unsigned long start, unsigned short count)
{
	unsigned short sect;
	for(sect=0; sect<count; sect++) {
		if(buf[sect][4]!=0x00) return(ERROR);
		if(buf[sect][3]!=(unsigned char)((start &0xFF))) return(ERROR);
		if(buf[sect][2]!=(unsigned char)((start/0x100L) &0xFF)) return(ERROR);
		if(buf[sect][1]!=(unsigned char)((start/0x10000L) &0xFF)) return(ERROR);
		if(buf[sect][0]!=(unsigned char)((start/0x1000000L) &0xFF)) return(ERROR);
		start++;
	}
	return(SUCCESS);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -