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

📄 main.c

📁 IDE接口实验 Embest Teach Kit II boot success Embest 44B0X Evaluation Board(EduKit II) IDE Test Exampl
💻 C
字号:
/*********************************************************************************************
* File:	main.c
* Author:	embest
* Desc:	c main entry
* History:	
*********************************************************************************************/


/*--- include files ---*/
#include "44b.h"
#include "44blib.h"
#include "ide.h"


/*--- function declare ---*/
void Main(void);


/*--- function code ---*/
/*********************************************************************************************
* name:		PrintIdentification
* func:		print drive identificatin
* para:		id --- drive identificatin
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void PrintIdentification(const struct DriveId *id)
{
	uart_printf("Model Number : ");
	uart_printf((char *)id->model_number);
	uart_printf("\n");

	uart_printf("Serial Number: ");
	uart_printf((char *)id->serial_number);
	uart_printf("\n");

	uart_printf("Version      : ");
	uart_printf((char *)id->firmware_version);
	uart_printf("\n");

	uart_printf("Vendor ID    : %04X\n", id->vendor_id);
	uart_printf("Cylinder: %d, Head: %d: Sector: %d\n",
			id->cylinders, id->heads, id->sectors_per_track);
}


/*********************************************************************************************
* name:		PrintSectorData
* func:		print sector data
* para:		sec --- sector data
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void PrintSectorData(const struct Sector *sec)
{
	int i, j;

	for(i=0; i<SECTOR_BYTES; i+=0x10)
	{
		uart_printf("%04XH: ", i);

		for(j=0; j<8; j++)
			uart_printf("%X%X ", (sec->data[i+j] & 0xf0)>>4, sec->data[i+j] & 0xf);
		uart_printf(" ");
		for(j=8; j<16; j++)
			uart_printf("%X%X ", (sec->data[i+j] & 0xf0)>>4, sec->data[i+j] & 0xf);
		
		uart_printf("  ");
		for(j=0; j<8; j++)
		{
			if(sec->data[i+j] > 127 || isprint(sec->data[i+j]))
				uart_sendbyte(sec->data[i+j]);
			else
				uart_sendbyte('.');
		}
		uart_printf(" ");
		for(j=8; j<16; j++)
		{
			if(sec->data[i+j] > 127 || isprint(sec->data[i+j]))
				uart_sendbyte(sec->data[i+j]);
			else
				uart_sendbyte('.');
		}
		uart_printf("\r\n");
	}
}


/*********************************************************************************************
* name:		main
* func:		c code entry
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Main(void)
{
	unsigned int   i, status;		/* status */
	unsigned long  lba;				/* logic block address */
	struct DriveId id;				/* drive id */
	struct Sector  sec, sec2;		/* sector buffer */
	enum DrvErr    err;				/* drive diagnostic error code */
	unsigned short c, h, s;			/* CHS */

    sys_init();        /* Initial 44B0X's Interrupt,Port and UART */

	/******************/
	/* user interface */
	/******************/
	uart_printf("\n\rEmbest 44B0X Evaluation Board(EduKit II)");
	uart_printf("\n\rIDE Test Example\n\n");

	/* memory bank1(0x0200_xxxx) data bus is 16bits width */
	status = rBWSCON;
	status &= ~(0x03 << 4);
	status |= (0x01 << 4);
	rBWSCON = status;

	if(IDE_Init(PRIMARY))
	{
		status = IDE_Identification(PRIMARY, &id);
		if(status != ERR_NOERR)
			goto ERROR;
		PrintIdentification(&id);

		uart_printf("\n\n");
		uart_printf("Read MBR sector data... \n");
		lba = MAKE_LBA(PRIMARY, 0, 0, 1);
		status = IDE_ReadSectors(lba, &sec, 1);
		if(status != ERR_NOERR)
			goto ERROR;
		PrintSectorData(&sec);

		srand(rTICINT);
		c = rand() % (id.cylinders);
		h = rand() % (id.heads);
		s = (rand() % (id.sectors_per_track)) + 1;
		if(s == 1) s++; /* don't write MBR */

		c=0; h=0; s=2;		
		uart_printf("\n\n");
		uart_printf("Write random sector (C=%d, H=%d, S=%d) ... \n", c, h, s);
		for(i=0; i<SECTOR_BYTES; i++)
			sec.data[i] = i;//(rand() & 0xff);
		PrintSectorData(&sec);

		lba = MAKE_LBA(PRIMARY, c, h, s);
		status = IDE_WriteSectors(lba, &sec, 1);
		if(status != ERR_NOERR)
			goto ERROR;

		uart_printf("\n\n");
		uart_printf("Read random sector (C=%d, H=%d, S=%d) ... \n", c, h, s);
		lba = MAKE_LBA(PRIMARY, c, h, s);
		status = IDE_ReadSectors(lba, &sec2, 1);
		if(status != ERR_NOERR)
			goto ERROR;
		PrintSectorData(&sec2);

		if(memcmp(&sec, &sec2, sizeof(sec)) == 0)
			uart_printf("Verify sector data, OK!\n");
		else
			uart_printf("Verify sector data, Error!\n");
	}
	else
	{
		uart_printf("Can not found IDE drive.\n");
	}

	while(1);

ERROR:
	uart_printf((char *)IDE_GetStatusString(status));
	IDE_Diagnostics(PRIMARY, &err);
	uart_printf((char *)IDE_GetErrorString(err));
	while(1);
}

⌨️ 快捷键说明

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