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

📄 pccard_test.c

📁 三星2443芯片
💻 C
字号:
#include "system.h"
#include "etc.h"
#include "pccard.h"
#include "cf.h"


//static PCCARD oPccard;
#define CODEC_MEM_ST 0x31000000


unsigned int SelectMode(void)
{
	printf("\nWhich mode do you want test? \n");
	printf(" 0:Memory mode[D], 1:IO mode1, 2 :IO mode1, 3 :IO mode1\n");
	return (unsigned int)GetIntNum();
}

void PrintCIS(void)
{
    unsigned int cisEnd=0;
    unsigned char str[16];
    unsigned char c;
    unsigned int i,j;
    
	OpenPccardMediaWithMode(0);   // memory mode
									
    printf("[Card Information Structure.]\n");

	// just test for attribute region
	for (i=0;i<6;i++) //0x01, 04, DF, 4A, 01, FF
	{
   		GetAttribData(i*2, &c);
   		printf(" at_addr : 0x%x, at_data : 0x%x\n", i*2, c);
	}
	
    //search the end of CIS
    while (1)
    {
    	GetAttribData((cisEnd)*2, &c); // id
		if (c==0xff)	//0xff= termination tuple	
	    	break;
		cisEnd++;
		GetAttribData((cisEnd)*2, &c); // next tuple pointer
		cisEnd += c+1;
    }
    printf("cisEnd=0~%x\n",cisEnd);			


    for (i=0; i<=cisEnd*2; i+=2)
    {
		GetAttribData(i, &c);
		str[(i%0x20)/2]=c;
		printf("%2x,",c);
		if ((i%0x20)>=0x1e)
		{
		    printf("//");
		    for (j=0; j<0x10; j++)
			if (str[j]>=' ' && str[j]<=127)
				printf("%c",str[j]);
			else 
				printf(".");
		    printf("\n");
		}
    }
    printf("\n");	

	ClosePccardMedia();
}

void TestWriteRead_PcCard(void)
{
	unsigned int uWriteBuf = CODEC_MEM_ST;
	unsigned int uReadBuf = CODEC_MEM_ST + 0x400000;

	unsigned int deviceLba;
	unsigned int uBlockCount;

    unsigned int mode;
    unsigned int i=0;
    
    mode = SelectMode();
	OpenPccardMediaWithMode(mode);

	printf("\nInput device sector address\n");
	deviceLba = (unsigned int)GetIntNum();

	printf("Input sector count\n");
	uBlockCount = (unsigned int)GetIntNum();

	printf("Fill & Clear buffer!!\n");
	for (i=0; i<uBlockCount*512; i++){
		Outp8(uWriteBuf+i, (i+3)%256);
		Outp8(uReadBuf+i, 0);
	}
	
	printf("Press Enter \n");	
	getchar();

	WriteBlocks(deviceLba, uBlockCount, uWriteBuf);
	ReadBlocks(deviceLba, uBlockCount, uReadBuf);

	if (Compare32(uWriteBuf, uReadBuf, uBlockCount*128) == FALSE)
	{
		printf("Error detected.. W:0x%x, R:0x%x\n", *(unsigned int *)(uWriteBuf+512), *(unsigned int *)(uReadBuf+512));
		Dump32(uReadBuf, uBlockCount*128);
	}
	else
	{
		printf("Write/Read in PC Card mode is OK\n");
	}

	ClosePccardMedia();
}

void TestRead_PcCard(void)
{
	unsigned int uReadBuf = CODEC_MEM_ST + 0x400000;

	unsigned int deviceLba;
	unsigned int uBlockCount;

    unsigned int mode;
    unsigned int i;
    
    mode = SelectMode();
	OpenPccardMediaWithMode(mode);
	
	printf("\nInput device sector address\n");
	deviceLba = (unsigned int)GetIntNum();

	printf("Input sector count\n");
	uBlockCount = (unsigned int)GetIntNum();

	printf("Clear buffer!!\n");
	for (i=0; i<uBlockCount*512; i=i+4)	 // buffer clear
	{
		Outp32(uReadBuf+i, 0);
	}
	
	printf("Press Enter \n");	
	getchar();
	
	ReadBlocks(deviceLba, uBlockCount, uReadBuf);
	
	printf("Dump.....!!\n");
	Dump32(uReadBuf, uBlockCount*128);

	ClosePccardMedia();
}


void Clear_PcCard(void)
{
	unsigned int uWriteBuf = CODEC_MEM_ST;
	

	unsigned int deviceLba;
	unsigned int uBlockCount;

    unsigned int mode;
    unsigned int i=0;
    
    mode = SelectMode();
	OpenPccardMediaWithMode(mode);

	printf("\nInput device sector address\n");
	deviceLba = (unsigned int)GetIntNum();

	printf("Input sector count\n");
	uBlockCount = (unsigned int)GetIntNum();

	printf("Fill & Clear buffer!!\n");
	for (i=0; i<uBlockCount*512; i++){
		Outp8(uWriteBuf+i, 0);
	}
	
	printf("Press Enter \n");	
	getchar();

	WriteBlocks(deviceLba, uBlockCount, uWriteBuf);

	printf("Clear sectors as zero in PC Card mode.\n");

	ClosePccardMedia();
}


void Test_PCCARD(void)
{
	int i, sel;

	const FUNC_MENU menu[]=
	{
		NULL,						"Exit",
		PrintCIS,					"PC Card CIS(Card Information Structure)",
		TestWriteRead_PcCard,		"PC Card Common memory Write/Read test",
		TestRead_PcCard,			"PC Card Common memory Read test",
		Clear_PcCard,				"PC Card Common memory clear data",

		0,0
	};

	while(1)
	{
		printf("\n");
		for (i=0; (int)(menu[i].desc)!=0; i++)
			printf("%2d: %s\n", i, menu[i].desc);

		printf("\nSelect the function to test : ");
		sel = GetIntNum();
		printf("\n");

		if (sel == 0)
			break;
		else if (sel>0 && sel<(sizeof(menu)/8-1))
			(menu[sel].func)();
	}	
}


⌨️ 快捷键说明

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