📄 ide_base.c
字号:
#include "ide_include.h"
void Wait_Ready(void)
{
#ifdef DEBUG_LV0_ON
DEBUG_OUT("\n\rdy's debug:Enter <Wait_Ready>");
debug_stat.CountOut = 0;
while(!(ReadReg(STATUS) & 0x40))debug_stat.CountOut++;
DEBUG_OUT(" timeOut = %d",debug_stat.CountOut);
DEBUG_OUT("-->--Exit <Wait_Ready>\n\r");
#else
while(!(ReadReg(STATUS) & 0x40));
#endif
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Wait_ReadyBusy(void)
{
#ifdef DEBUG_LV0_ON
DEBUG_OUT("\n\rdy's debug:Enter <Wait_ReadyBusy>");
debug_stat.CountOut = 0;
while((ReadReg(STATUS) & 0xC0)!= 0x40) debug_stat.CountOut++;
DEBUG_OUT(" timeOut = %d",debug_stat.CountOut);
DEBUG_OUT("-->--Exit <Wait_ReadyBusy>\n\r");
#else
while((ReadReg(STATUS) & 0xC0)!= 0x40);
#endif
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Wait_DRQBusy(void)
{
#ifdef DEBUG_LV0_ON
DEBUG_OUT("\n\rdy's debug:Enter <Wait_DRQBusy>");
debug_stat.CountOut = 0;
while((ReadReg(STATUS) & 0x88)!= 0x08) debug_stat.CountOut++;
DEBUG_OUT(" timeOut = %d",debug_stat.CountOut);
DEBUG_OUT("-->--Exit <Wait_DRQBusy>\n\r");
#else
while((ReadReg(STATUS) & 0x88)!= 0x08);
#endif
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Wait_DRQ(void)
{
#ifdef DEBUG_LV0_ON
DEBUG_OUT("\n\rdy's debug:Enter <Wait_DRQ>");
debug_stat.CountOut = 0;
while(!(ReadReg(STATUS) & 0x80)) debug_stat.CountOut++;
DEBUG_OUT(" timeOut = %d",debug_stat.CountOut);
DEBUG_OUT("-->--Exit <Wait_DRQ>\n\r");
#else
while(!(ReadReg(STATUS) & 0x80));
#endif
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
UI8 CheckforError(void)
{
UI8 statbyte;
statbyte = ReadReg(STATUS); // Read Status Register
if (statbyte & 0x01) return 1; // Is LSB (error bit) is set then return 1
else return 0;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void ReadErrors(void)
{
UI8 errors;
errors = ReadReg(ERROR); // Read Error Register
s3c44b0x_Printf("\r\nError Report");
if (errors &0x80) s3c44b0x_Printf("\r\nReserved bit....");
if (errors &0x40) s3c44b0x_Printf("\r\nUNC bit: Uncorrectable data error");
if (errors &0x20) s3c44b0x_Printf("\r\nMC bit: The media has changed");
if (errors &0x10) s3c44b0x_Printf("\r\nIDNF bit: Sector ID not found");
if (errors &0x08) s3c44b0x_Printf("\r\nMCR bit: Media Change Requested");
if (errors &0x04) s3c44b0x_Printf("\r\nABRT bit: Bad Parameters for Rd/Wr; possible out of range IO");
if (errors &0x02) s3c44b0x_Printf("\r\nTK0NF bit: Can't find track 0; possible disc failure");
if (errors &0x01) s3c44b0x_Printf("\r\nAMNF bit: Address mark not found");
s3c44b0x_SysHalt();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
UI16 tempbuffer[HDD_SECTOR_SIZE/2];
UI32 Fetch_ID_Max_LBA(UI8 silent)
{
UI8 cnt,chardata;
#ifdef DEBUG_LV0_ON
UI8 *ch;
#endif
UI16 i;
UI32 TotalLBAs=0;
// Wait till not busy and RDY?
Wait_ReadyBusy();
// Send Command for drive identification
#ifdef DEBUG_LV0_ON
DEBUG_OUT("\n\rdy's debug:Enter <WriteReg(COMMAND, DRIVEID);>");
#endif
WriteReg(COMMAND, DRIVEID);
#ifdef DEBUG_LV0_ON
DEBUG_OUT("\n\rdy's debug:Exit <WriteReg(COMMAND, DRIVEID);>");
#endif
// Wait for DRQ
Wait_DRQBusy();
// Read in first 512 bytes of the drive identification
for (i=0; i<HDD_SECTOR_SIZE/2; i++)
{
// Read data words from drives buffer
tempbuffer[i] = ReadWord(DATA);
}
#ifdef DEBUG_LV0_ON
//display Sector data
ch=(UI8*)tempbuffer;
for(i=0;i<HDD_SECTOR_SIZE;i=i+16)
{
s3c44b0x_Printf("\n\rBYTE%4x:%4x%4x%4x%4x%4x%4x%4x%4x%4x%4x%4x%4x%4x%4x%4x%4x",\
i, *(ch+i+0), *(ch+i+1), *(ch+i+2), *(ch+i+3), *(ch+i+4), *(ch+i+5), *(ch+i+6), *(ch+i+7),\
*(ch+i+8), *(ch+i+9), *(ch+i+10), *(ch+i+11), *(ch+i+12), *(ch+i+13), *(ch+i+14), *(ch+i+15));
}
#endif
// Assuming drive supports LBA find max LBA sector
TotalLBAs = tempbuffer[60] + tempbuffer[61]<<16;
if (!silent)
{
s3c44b0x_Printf("\r\nHard Disc Auto Detect Parameters");
s3c44b0x_Printf("\r\n--------------------------------\r\n");
// Detect HDD or CDROM
s3c44b0x_Printf("\r\nType of device: ");
if (tempbuffer[0]&0x8000) s3c44b0x_Printf("ATA Device ");
else s3c44b0x_Printf("ATAPI Device ");
// Detect removable media
if (tempbuffer[0]&0x0080) s3c44b0x_Printf("which has removable media");
// Heads
s3c44b0x_Printf("\r\nThe number of heads is = %d",tempbuffer[3]);
// Cylinders
s3c44b0x_Printf("\r\nThe number of Cylinders is = %d",tempbuffer[1]);
// Sectors Per Track
s3c44b0x_Printf("\r\nThe number of Sectors per track is = %d", tempbuffer[6]);
// Serial Number
s3c44b0x_Printf("\r\nThe number of Serial Number of the device is = ");
for (cnt=10; cnt<19; cnt++)
{
chardata = tempbuffer[cnt]>>8;
s3c44b0x_putchar(chardata);
chardata = tempbuffer[cnt];
s3c44b0x_putchar(chardata);
}
// Model Number
s3c44b0x_Printf("\r\nThe number of Model Number of the device is = ");
for (cnt=27; cnt<46; cnt++)
{
chardata = tempbuffer[cnt]>>8;
s3c44b0x_putchar(chardata);
chardata = tempbuffer[cnt];
s3c44b0x_putchar(chardata);
}
// CHS or LBA
if(!((tempbuffer[49] >> 8) & 0x1))
s3c44b0x_Printf("\r\nCHS Mode Only (NO LBA)");
else
s3c44b0x_Printf("\r\nLBA Supported");
// Report max lba address
s3c44b0x_Printf("\r\nLBA sectors is 0x%lx", TotalLBAs);
}
// Return Max LBA sector address in global drive information
return TotalLBAs;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -