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

📄 main.c

📁 at91的典型HDD代码,经典的HDD代码范例!at91rm9200也是经典的芯片!
💻 C
字号:
//*----------------------------------------------------------------------------
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : main.c
//* Object              : main application written in C
//* Creation            : GGi  12/11/2002
//*
//*----------------------------------------------------------------------------
#include "hdd.h"


//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_Printk
//* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
//*----------------------------------------------------------------------------
void AT91F_DBGU_Printk(
	char *buffer) // \arg pointer to a string ending by \0
{
	while(*buffer != '\0') {
		while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
		AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, *buffer++);
	}
}
/*--------------------------------------------------------
*
*						MAIN
*
*--------------------------------------------------------*/
int main (void){
int i ;
unsigned short signature;
unsigned short data[BUF_SIZE/2];
unsigned short ret[BUF_SIZE/2];
int i, cpt = 0;
char mes[64];

	AT91F_DBGU_Printk("application started \r\n");

/*-------------------------------------------------
*
*		OPEN CF
*
*-------------------------------------------------*/

	
    //Opening device
    AT91F_HDDOpen();
	AT91F_DBGU_Printk("CF opened \r\n");


/*-------------------------------------------------
*
*		TEST IDE MODE
*
*-------------------------------------------------*/

	//read the HDD ID
	AT91F_HDDRead_ID(data);

	AT91F_DBGU_Printk("HDD_READ_IDE_ID done \r\n");

	if (buf16[0] != ATA_SIGNATURE) goto fail;
	else AT91F_DBGU_Printk("IDE OK\r\n");


	//storing data into the HDD
	for (i=0; i< BUF_SIZE/2; i++) data[i] = i | (i << 8) ;
	AT91F_DBGU_Printk("\r\n#### HDD transfert START\r\n");

	AT91F_DBGU_Printk("\r\n#### WRITING 1 MB\r\n");

	//writing
		
	AT91F_DBGU_Printk( "storing data into HDD (2048 sector) \r\n");
		
	while(cpt < 2048){
		sprintf(mes, "block %i / 2048 \r\n", cpt);
		AT91F_DBGU_Printk(mes);
		if (AT91F_HDDWrite(data,cpt) < 0) goto fail;
		cpt ++;	
	}
					
	AT91F_DBGU_Printk( "end writing data in HDD (2048 sector) \r\n");			
	
	
	AT91F_DBGU_Printk( "reading data in HDD (2048 sector) \r\n");			
		
	// reading		
			
	cpt=0;					
	while(cpt < 2048){
		sprintf(mes, "block %i / 2048 \r\n", cpt);
		AT91F_DBGU_Printk(mes);
		delay_us(5000000);			
		if (AT91F_HDDRead(ret,cpt)  < 0) goto fail;
		cpt ++;
	}	
					
	//verifying			
					
	AT91F_DBGU_Printk("verifying	data betwen read and write  \r\n");
		
	for (i=0; i< BUF_SIZE/2; i++) 
		if (ret[i] != data[i]) {
			sprintf(mes, "**** onto page %i short %i is %x must be %x", cpt, i, ret[i], data[i]);
		   	AT91F_DBGU_Printk(mes);
	}
	
	AT91F_HDDSleep();
	return 0;

fail :
	AT91F_DBGU_Printk("\r\n**** HDD ERROR !!\r\n");
	AT91F_HDDSleep();
	return -1;
}

⌨️ 快捷键说明

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