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

📄 cd_rom.c

📁 三星s3c2460开发板完整功能测试代码
💻 C
字号:
/*=============================================================

	File Name: cd_rom.c
	Description: S3C2460 CD-ROM Function Test
   	Version: 0.1

   	History:
		0.0: 2006. 06. 05, Created by Kim, Hak Soo(Sue)
		0.1: 
	       		  
==============================================================*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "type.h"
#include "option.h"

#include "2460addr.h"
#include "2460lib.h"
#include "2460slib.h"

#include "cd_rom.h"	

#include "PLL.h"

static uint16 ATA_ReadRegister(uint32 nRegister)
{
	return (*((volatile uint16 *) (nRegister))) & 0x00ff;
}

static void ATA_WriteRegister(uint32 nRegister, uint16 nValue)
{
	while (ATA_ReadRegister(ATA_STATUS) == 0x80) ;
	*((volatile uint16 *) (nRegister)) = nValue&0x00ff;
}

static void ATA_WriteData(uint16 nData)
{
	*((uint16*)(ATA_DATA)) = nData;
}

static uint16 ATA_ReadData(void)
{
	return (*((uint16 *)ATA_DATA))&0xffff;
}

static ATA_error_t WaitBusy2460(void) 
{
	int i;
	unsigned short tempRead;


	for(i=0;i<TIME_OUT_VALUE2;i++) {
		tempRead = 	ATA_ReadRegister(ATA_ALTANATE)&0x00ff;
		if((tempRead&0x80) == 0) break;
		Delay(1);
	}
	
	if(i==TIME_OUT_VALUE2) return ATA_TIMEOUT;

	return ATA_NO_ERROR;
}


static void Check_Ready_Status(void)
{
	uint16 tempRead;

	while(!Uart_GetKey()) 
	{
		tempRead = ATA_ReadRegister(ATA_STATUS);
		if(tempRead&0x40)
		{
			printf(" Status : 0x%x(ready)\n", tempRead);
			break;
		}
		printf(" Status : 0x%x(not ready)\n", tempRead);
		//Delay(100);
		Delay(10000);
	} 
		
	return;
}

static void Check_Busy_Status(void)
{
	uint16 tempRead;

	while(!Uart_GetKey()) 
	{
		tempRead = ATA_ReadRegister(ATA_STATUS);
		if(tempRead&0x80)
		{
			printf(" Status : 0x%x(busy)\n", tempRead);
			//Delay(100);
			Delay(10000);
			continue;
		}
		else
		{
			printf(" Status : 0x%x(not busy)\n", tempRead);
			break;
		}
	} 
		
	return;
}

static void Identify_Device(void)
{
	uint16 readBuffer[256];
	uint16 swapBuffer[256],tempData;
	uint8 tempBuffer;
	uint8 *tempString;
	int i=0;
	
	printf("\nATAPI device identify...!\n");

	for (i=0;i<256;i++) readBuffer[i] = 0;

	//* send Identify device command
	ATA_WriteRegister(ATA_DEVICE,0x00);
	ATA_WriteRegister(ATA_COMMAND,IDENTIFY_PACKET_DEVICE);
	Delay(1000);				//delay about 100ms
	Check_Ready_Status();

	if (WaitBusy2460() == ATA_TIMEOUT) 
	{
		printf(" ERROR : busy Time out!!!\n");
		return;
	}
	
	for(i=0;i<256;i++) 
	{
		readBuffer[i] = ATA_ReadData();
		Delay(10);
	}
	ATA_ReadRegister(ATA_STATUS);

  #if 0	//set '1' for debug	
	for(i=0;i<256;i++) 
	{
		printf("DATA[%3d]:0x%04X",i,readBuffer[i]);
		if((i%4)==3)
			printf("\n");
		else
			printf(",  ");
	}
  #endif	
	
	//* swap read data
	for(i=0;i<256;i++)
	{
		tempData = readBuffer[i];
		swapBuffer[i]=((tempData&0xff)<<8)|((tempData&0xff00)>>8);
	}	
	
	//* verify identify data
	tempString = (unsigned char *)&swapBuffer[SERIAL_NUMBER_OFFSET];
	printf("\n Serial Number : ");
	for(i=0;i<SERIAL_NUMBER_SIZE;i++) printf("%c",*(tempString+i));

	tempString = (unsigned char *)&swapBuffer[27];
	printf("\n Model Number : ");
	for(i=0;i<MODEL_NUMBER_SIZE;i++) printf("%c",*(tempString+i));
	
	tempString = (unsigned char *)&swapBuffer[FIRMWARE_REVISION_OFFSET];
	printf("\n f/w revision : ");
	for(i=0;i<FIRMWARE_REVISION_SIZE;i++) printf("%c",*(tempString+i));
	
	printf("\ndevice identify end!\n");
	
	return;
}

void CD_ROM_Test(void)
{
	int i;
	uint16 temp16[4],tempRead;
	uint32 save_GPJCON,save_GPJPU,save_GPJDAT;
	uint32 save_GPICON,save_GPIPU,save_GPIDAT;
	
	printf("\n\n================== CD-ROM Function Test =====================\n\n");
	
	//* save previous configuration of GPIO
	save_GPJCON = rGPJCON;
	save_GPJPU = rGPJPU;
	save_GPJDAT = rGPJDAT;
	
	save_GPICON = rGPICON;
	save_GPIPU = rGPIPU;
	save_GPIDAT = rGPIDAT;
		
	//* initialize rom controller for cd-rom i/f
	rSROM_BW |= (0x7<<3);	//bank2:using ub/lb,wait enable, 16-bit
	rSROM_BC1 = 0x3780;
	printf("ATAPI 2460 init complete!\n");	
	
	//* set DMA_ACK into high
	rGPICON &= ~(3<<14);
	rGPICON = (1<<14);		//setting GPJ15 into output port
	rGPIPU |= (1<<7);		//disable GPJ15 pull-up	
	rGPIDAT |= (1<<7);		//drive output-high	
	
	//* h/w-reset cd-rom
	printf("\nATAPI h/w reset...!\n");
	rGPJCON &= ~(3<<30);
	rGPJCON = (1<<30);		//setting GPJ15 into output port
	rGPJPU |= (1<<15);		//disable GPJ15 pull-up	
	rGPJDAT &= ~(1<<15);	//drive output-low
	Delay(100);				//delay about 10ms
	rGPJDAT |= (1<<15);		//drive output-high	
	Delay(500);				//delay about 50ms
	Check_Busy_Status();
	printf("h/w reset end!\n");
		
	//* reset device
	printf("\nATAPI s/w reset...!\n");
	ATA_WriteRegister(ATA_DEVICE,0x00);
	ATA_WriteRegister(ATA_COMMAND,DEVICE_RESET);
	Delay(500);				//delay about 50ms
	Check_Busy_Status();
	printf("s/w reset end!\n");	
	
	//* identify atapi device
	Identify_Device();
	
	//* return original configuration of GPJ
	rGPJCON = save_GPJCON;
	rGPJPU = save_GPJPU;
	rGPJDAT = save_GPJDAT;
	
	rGPICON = save_GPICON;
	rGPIPU = save_GPIPU;
	rGPIDAT = save_GPIDAT;
	
	return;
	
}


⌨️ 快捷键说明

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