?? seeddm642_ide.c
字號:
/********************************************************************/
/* Copyright 2004 by SEED Incorporated. */
/* All rights reserved. Property of SEED Incorporated. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/********************************************************************/
#include "seeddm642_ide.h"
#include "seeddm642.h"
/*******************************************************************/
/* */
/* int ata_reg_read() */
/* 描述:讀回當前寄存器的狀態 */
/* 參數:寄存器指示 */
/* 返值:當前狀態寄存器的值 */
/* */
/*******************************************************************/
int ata_reg_read(Uint32 regaddr)
{
int regdata = 0;
/*延時*/
SEEDDM642_wait(20);
/*讀寄存器的值*/
regdata = *((unsigned long *)regaddr);
return regdata;
}
/*******************************************************************/
/* */
/* int ata_reg_write() */
/* 描述:設置當前寄存器 */
/* 參數:regaddr:寄存器地址 */
/* regdata:寄存器的值 */
/* 返值:無 */
/* */
/*******************************************************************/
void ata_reg_write(Uint32 regaddr,Uint32 regdata)
{
Uint8 *psrc;
/*延時*/
SEEDDM642_wait(20);
/*寫入當前寄存器的值*/
psrc = (Uint8 *)regaddr;
*psrc = regdata;
}
/*******************************************************************/
/* */
/* int ata_status() */
/* 描述:讀回當前硬盤的狀態 */
/* 參數:無 */
/* 返值:當前狀態寄存器的值 */
/* */
/*******************************************************************/
int ata_status()
{
int registervalue = 0;
/*延時*/
SEEDDM642_wait(20);
/*讀寄存器的值*/
registervalue = *((unsigned long *)SEEDDM642_ATA_STATUS);
return registervalue;
}
/*******************************************************************/
/* */
/* SEEDDM642_ATAHandle ata_open() */
/* 描述:打開有效的硬盤設備 */
/* 參數:無 */
/* 返值:有效設備的句柄 */
/* */
/*******************************************************************/
SEEDDM642_ATAHandle ata_open()
{
int ata_flag = 0xff;
/*等待2ms*/
SEEDDM642_waitusec(2000);
/*讀取狀態寄存器,判斷復位是否結束*/
do
{
ata_flag = ata_status();
if(ata_flag & ATA_BUS_ERR )
{
return (SEEDDM642_ATAHandle)0xff;
}
ata_flag = ata_flag & ATA_BUS_BSY;
}while(ata_flag != 0 );
return (SEEDDM642_ATAHandle)1;
}
/*******************************************************************/
/* */
/* int ata_command() */
/* 描述:設置當前寄存器 */
/* 參數:regaddr:寄存器地址 */
/* regdata:寄存器的值 */
/* 返值:無 */
/* */
/*******************************************************************/
Bool ata_command(ATA_command *command,Uint32 buffer,Uint32 longth)
{
int ata_st = 0;
Uint32 *psrc;
Uint32 errcount = 0;
Uint32 i;
psrc = (Uint32 *)buffer;
/*判斷當前總線是否釋放*/
do
{
ata_st = ata_status();
ata_st = (ata_st & ATA_BUS_BSY);
errcount++;
if(errcount ==0x10000)
{
return FALSE;
}
}while(ata_st !=0);
/*判斷先決條件是否成立*/
errcount = 0;
do
{
ata_st = ata_status();
ata_st = (ata_st & (command->prereq));
errcount++;
if(errcount ==0x10000)
{
return FALSE;
}
}while(ata_st ==0);
/*將命令的各個參數寫入到相應的寄存器*/
if(command->features < 0x100)
{
ata_reg_write(SEEDDM642_ATA_FEATURES,command->features);
}
if(command->sector_count < 0xff)
{
ata_reg_write(SEEDDM642_ATA_SECTOR,command->sector_count);
}
if(command->LBA_l < 0x100)
{
ata_reg_write(SEEDDM642_ATA_LBAL,command->LBA_l);
}
if(command->LBA_M < 0x100)
{
ata_reg_write(SEEDDM642_ATA_LBAM,command->LBA_M);
}
if(command->LBA_H < 0x100)
{
ata_reg_write(SEEDDM642_ATA_LBAH,command->LBA_H);
}
if(command->device < 0x100)
{
ata_reg_write(SEEDDM642_ATA_DEVICE,command->device);
}
/*提交命令*/
ata_reg_write(SEEDDM642_ATA_COM,command->com_code);
/*等待命令執行完畢:BSY為0*/
errcount = 0;
do
{
ata_st = ata_status();
ata_st = (ata_st & ATA_BUS_BSY);
errcount++;
if(errcount ==0x10000)
{
return FALSE;
}
}while(ata_st !=0);
/*等待完成條件出現*/
errcount = 0;
do
{
ata_st = ata_status();
ata_st = (ata_st & (command->complete_flag));
errcount++;
if(errcount ==0x10000)
{
return FALSE;
}
}while(ata_st ==0);
/*判斷是否出錯*/
ata_st = ata_status();
if((ata_st & 0x1)==1)
{
ata_st = ata_reg_read(SEEDDM642_ATA_ERROR);
return FALSE;
}
/*讀取命令結果*/
for(i = 0;i<longth;i++)
{
*psrc++ =ata_reg_read(SEEDDM642_ATA_DATA);
}
ata_st = ata_status();
if((ata_st & 0x1) != 0 )
{
return FALSE;
}
else
{
return TRUE;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -