📄 ata.c
字号:
break;
}
#if PERF_TEST_ATA
uElapsedTime = StopTimer(0);
Disp(" Writing time : %d us, Performance : %lf MByte/sec\n"
,uElapsedTime,(float)(uBlocks*512./uElapsedTime));
#endif
return bStatus;
}
//////////
// Function Name : ATA_ReadBlocks
// Function Description : This function reads block data from device to host.
// Input : ucCon - ATA Controller Number
// uStBlock - LBA Block
// uBlocks - Block Count
// uBufAddr - Address of Buffer
// Output : true/false
// Version : v0.1
bool ATA_ReadBlocks(u8 ucCon, u32 uStBlock, u32 uBlocks, u32 uBufAddr)
{
eATA_MODE_6400 eAtaMode = g_oaATAInform[ucCon].eAtaMode;
bool bStatus = FALSE;
#if PERF_TEST_ATA
u32 uElapsedTime = 0;
#endif
Disp("ReadBlocks() in %s mode...\n", ATA_GetModeName(eAtaMode));
#if PERF_TEST_ATA
StartTimer(0);
#endif
switch(eAtaMode)
{
case eATA_MODE_PIOCPU :
bStatus = ATA_ReadSectors_PIO( ucCon, uStBlock, uBlocks, uBufAddr);
break;
case eATA_MODE_PIODMA :
bStatus = ATA_ReadSectors_PDMA( ucCon, uStBlock, uBlocks, uBufAddr);
break;
case eATA_MODE_UDMA :
bStatus = ATA_ReadSectors_UDMA( ucCon, uStBlock, uBlocks, uBufAddr);
break;
default :
Disp("Not supported mode in WriteBlocks()\n");
break;
}
#if PERF_TEST_ATA
uElapsedTime = StopTimer(0);
Disp(" Reading time : %d us, Performance : %lf MByte/sec\n"
,uElapsedTime,(float)(uBlocks*512./uElapsedTime));
#endif
return bStatus;
}
//////////
// Function Name : ATA_WriteSectors_PIO
// Function Description : This function writes block data to device in PIO mode.
// Input : ucCon - ATA Controller Number
// uLBA - LBA Block
// uSectorCount - Sector Count
// uSrcAddress - Address of Buffer
// Output : true/false
// Version : v0.1
bool ATA_WriteSectors_PIO(u8 ucCon, u32 uLBA, u32 uSectorCount, u32 uSrcAddress)
{
u32 uCurrentCount;
u32 uRemainderCount;
u32 uCurrentLba;
u32 uCurrentSrcAddr;
u32 uRound;
u16* usAtaHostAddr;
u32 uLoopCnt;
#if PERF_TEST_PIO
u32 uElapsedTime = 0;
#endif
uRemainderCount = uSectorCount;
uCurrentLba = uLBA;
uRound = 0;
while(uRemainderCount != 0) {
if(uRemainderCount>256) {
uCurrentCount = 256; //0 means 256
uRemainderCount -= 256;
} else {
uCurrentCount = uRemainderCount;
uRemainderCount = 0;
}
uCurrentLba = uLBA + uRound*256;
uCurrentSrcAddr = uSrcAddress + uRound*256*ATA_SECTORSIZE;
usAtaHostAddr = (u16*)uCurrentSrcAddr;
ATA_SetDevicePosition(ucCon, uCurrentLba, uCurrentCount);
ATA_SetTaskFileRegValue(ucCon, eCF_TASKFILE_COMMAND, ATA_CMD_WRITESECTOR);
while(uCurrentCount-- ) {
ATA_WaitForDeviceReady(ucCon);
#if PERF_TEST_PIO
StartTimer(2);
#endif
for (uLoopCnt=0;uLoopCnt<ATA_SECTORSIZE/2;uLoopCnt++) {
ATA_SetDataToDevice(ucCon, *usAtaHostAddr);
usAtaHostAddr++;
}
#if PERF_TEST_PIO
uElapsedTime += StopTimer(2);
#endif
}
ATA_WaitForDeviceReady(ucCon);
uRound++;
}
#if PERF_TEST_PIO
Disp(" PIO Writing time : %d us, Performance : %lf MByte/sec\n"
,uElapsedTime,(float)(uSectorCount*512./uElapsedTime));
#endif
return TRUE;
}
//////////
// Function Name : ATA_ReadSectors_PIO
// Function Description : This function writes block data to device in PIO mode.
// Input : ucCon - ATA Controller Number
// uLBA - LBA Block
// uSectorCount - Sector Count
// uSrcAddress - Address of Buffer
// Output : true/false
// Version : v0.1
bool ATA_ReadSectors_PIO(u8 ucCon, u32 uLBA, u32 uSectorCount, u32 uDstAddress)
{
u32 uCurrentCount;
u32 uRemainderCount;
u32 uCurrentLba;
u32 uCurrentDstAddr;
u32 uRound;
u16* usAtaHostAddr;
u32 uLoopCnt;
#if PERF_TEST_PIO
u32 uElapsedTime = 0;
#endif
uRemainderCount = uSectorCount;
uCurrentLba = uLBA;
uRound = 0;
while(uRemainderCount != 0) {
if(uRemainderCount>256) {
uCurrentCount = 256; //0 means 256
uRemainderCount -= 256;
} else {
uCurrentCount = uRemainderCount;
uRemainderCount = 0;
}
uCurrentLba = uLBA + uRound*256;
uCurrentDstAddr = uDstAddress + uRound*256*ATA_SECTORSIZE;
usAtaHostAddr = (u16*)uCurrentDstAddr;
ATA_SetDevicePosition(ucCon, uCurrentLba, uCurrentCount);
ATA_SetTaskFileRegValue(ucCon, eCF_TASKFILE_COMMAND, ATA_CMD_READSECTOR);
while(uCurrentCount-- ) {
ATA_WaitForDeviceReady(ucCon);
#if PERF_TEST_PIO
StartTimer(2);
#endif
for (uLoopCnt=0;uLoopCnt<ATA_SECTORSIZE/2;uLoopCnt++) {
*usAtaHostAddr = ATA_GetDataFromDevice(ucCon);
usAtaHostAddr++;
}
#if PERF_TEST_PIO
uElapsedTime += StopTimer(2);
#endif
}
ATA_WaitForDeviceReady(ucCon);
uRound++;
}
#if PERF_TEST_PIO
Disp(" PIO Reading time : %d us, Performance : %lf MByte/sec\n"
,uElapsedTime,(float)(uSectorCount*512./uElapsedTime));
#endif
return TRUE;
}
//////////
// Function Name : ATA_ReadSectors_PDMA
// Function Description : This function writes sector data to device in UDMA mode.
// Input : ucCon - ATA Controller Number
// uLBA - LBA Block
// uSectorCount - Sector Count
// uSrcAddress - Address of Buffer
// Output : true/false
// Version : v0.1
bool ATA_ReadSectors_PDMA(u8 ucCon, u32 uLBA, u32 uSectorCount, u32 uDstAddress)
{
u32 uCurrentCount;
u32 uRemainderCount;
u32 uCurrentLba;
u32 uCurrentDstAddr;
u32 uRound;
u32 uRoundSub;
#if PERF_TEST_UDMA
u32 uElapsedTime = 0;
#endif
uRemainderCount = uSectorCount;
uRound = 0;
uRoundSub = 0;
while(uRemainderCount != 0)
{
if(uRemainderCount>256) {
uCurrentCount = 256; //0 means 256
uRemainderCount -= 256;
} else {
uCurrentCount = uRemainderCount;
uRemainderCount = 0;
}
uCurrentLba = uLBA + uRound*256;
ATA_SetDevicePosition(ucCon, uCurrentLba, uCurrentCount);
ATA_SetTaskFileRegValue(ucCon, eCF_TASKFILE_COMMAND, ATA_CMD_READSECTOR);
ATA_WaitForDeviceReady(ucCon);
uRoundSub = 0;
while(uCurrentCount != 0)
{
uCurrentDstAddr = uDstAddress + (uRound*256+uRoundSub)*ATA_SECTORSIZE;
/*Source Buffer 1 Setting*/
ATA_SetTBufStart( ucCon, uCurrentDstAddr);
ATA_SetTBufSize( ucCon, ATA_SECTORSIZE-1);
ATA_SetXfrNum(ucCon, ATA_SECTORSIZE);
ATA_WaitForDeviceReady(ucCon);
ATA_SetConfig(ucCon, eATA_MODE_PIODMA, eATA_DMA_READ_DATA);
#if PERF_TEST_UDMA
StartTimer(1);
#endif
/*ATA Transfer Command */
ATA_SetTransferCommand(ucCon, eATA_XFR_CMD_START);
ATA_WaitForTransferDone(ucCon);
ATA_SetTransferCommand(ucCon, eATA_XFR_CMD_ABORT);
ATA_SetConfig(ucCon, eATA_MODE_PIOCPU, eATA_DMA_READ_DATA);
#if PERF_TEST_UDMA
uElapsedTime += StopTimer(1);
#endif
uRoundSub++;
uCurrentCount--;
}
uRound++;
ATA_WaitForDeviceReady(ucCon);
}
ATA_WaitForDeviceReady(ucCon);
#if PERF_TEST_UDMA
Disp(" PDMA Reading time : %d us, Performance : %lf MByte/sec\n"
,uElapsedTime,(float)(uSectorCount*512./uElapsedTime));
#endif
return TRUE;
}
//////////
// Function Name : ATA_WriteSectors_PDMA
// Function Description : This function writes sector data to device in PDMA mode.
// Input : ucCon - ATA Controller Number
// uLBA - LBA Block
// uSectorCount - Sector Count
// uSrcAddress - Address of Buffer
// Output : true/false
// Version : v0.1
bool ATA_WriteSectors_PDMA(u8 ucCon, u32 uLBA, u32 uSectorCount, u32 uSrcAddress)
{
u32 uCurrentCount;
u32 uRemainderCount;
u32 uCurrentLba;
u32 uCurrentSrcAddr;
u32 uRound;
u32 uRoundSub;
#if PERF_TEST_UDMA
u32 uElapsedTime = 0;
#endif
uRemainderCount = uSectorCount;
uRound = 0;
uRoundSub = 0;
while(uRemainderCount != 0)
{
if(uRemainderCount>256) {
uCurrentCount = 256; //0 means 256
uRemainderCount -= 256;
} else {
uCurrentCount = uRemainderCount;
uRemainderCount = 0;
}
uCurrentLba = uLBA + uRound*256;
ATA_SetDevicePosition(ucCon, uCurrentLba, uCurrentCount);
ATA_SetTaskFileRegValue(ucCon, eCF_TASKFILE_COMMAND, ATA_CMD_WRITESECTOR);
ATA_WaitForDeviceReady(ucCon);
uRoundSub = 0;
while(uCurrentCount != 0) {
uCurrentSrcAddr = uSrcAddress + (uRound*256+uRoundSub)*ATA_SECTORSIZE;
/*Source Buffer 1 Setting*/
ATA_SetSBufStart( ucCon, uCurrentSrcAddr);
ATA_SetSBufSize( ucCon, ATA_SECTORSIZE-1);
ATA_SetXfrNum(ucCon, ATA_SECTORSIZE);
ATA_WaitForDeviceReady(ucCon);
ATA_SetConfig(ucCon, eATA_MODE_PIODMA, eATA_DMA_WRITE_DATA);
#if PERF_TEST_UDMA
StartTimer(1);
#endif
/*ATA Transfer Command */
ATA_SetTransferCommand(ucCon, eATA_XFR_CMD_START);
ATA_WaitForTransferDone(ucCon);
ATA_SetTransferCommand(ucCon, eATA_XFR_CMD_ABORT);
#if PERF_TEST_UDMA
uElapsedTime += StopTimer(1);
#endif
ATA_SetConfig(ucCon, eATA_MODE_PIOCPU, eATA_DMA_WRITE_DATA);
uRoundSub++;
uCurrentCount--;
}
uRound++;
ATA_WaitForDeviceReady(ucCon);
}
ATA_WaitForDeviceReady(ucCon);
#if PERF_TEST_UDMA
Disp(" PDMA Writing time : %d us, Performance : %lf MByte/sec\n"
,uElapsedTime,(float)(uSectorCount*512./uElapsedTime));
#endif
return TRUE;
}
//////////
// Function Name : ATA_WriteSectors_UDMA
// Function Description : This function writes sector data to device in UDMA mode.
// Input : ucCon - ATA Controller Number
// uLBA - LBA Block
// uSectorCount - Sector Count
// uSrcAddress - Address of Buffer
// Output : true/false
// Version : v0.1
bool ATA_WriteSectors_UDMA(u8 ucCon, u32 uLBA, u32 uSectorCount, u32 uSrcAddress)
{
u32 uCurrentCount;
u32 uRemainderCount;
u32 uCurrentLba;
u32 uCurrentSrcAddr;
u32 uRound;
#if PERF_TEST_UDMA
u32 uElapsedTime = 0;
#endif
uRemainderCount = uSectorCount;
uRound = 0;
while(uRemainderCount != 0) {
if(uRemainderCount>256) {
uCurrentCount = 256; //0 means 256
uRemainderCount -= 256;
} else {
uCurrentCount = uRemainderCount;
uRemainderCount = 0;
}
uCurrentLba = uLBA + uRound*256;
uCurrentSrcAddr = uSrcAddress + uRound*256*ATA_SECTORSIZE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -