📄 ata.c
字号:
switch(mode)
{
case PIO:
status = ReadSectors_Pio( uStBlock, uBlocks, uBufAddr);
break;
case PIODMA:
for(i=0; i<uBlocks; i++)
{
ReadSector_PioDma(uStBlock+i, uBufAddr+ATA_SECTORSIZE*i);
WaitForTransferDone();
}
//status = true; // need to move..
status = 1; // need to move..
break;
case UDMA:
status = ReadSectors_Udma( uStBlock, uBlocks, uBufAddr);
break;
default:
Disp("Not supported mode in ReadBlocks()\n");
break;
}
return status;
}
U32 WriteBlocks(U32 uStBlock, U32 uBlocks, U32 uBufAddr)
{
// Assert(uStBlock+uBlocks <= m_oDevice[0].MaxSectors);
U32 k;
int mode = m_eMode;
U32 status;
switch(mode)
{
case PIO:
status = WriteSectors_Pio( uStBlock, uBlocks, uBufAddr);
break;
case PIODMA:
for(k=0; k<uBlocks; k++)
{
WriteSector_PioDma(uStBlock+k, uBufAddr+ATA_SECTORSIZE*k);
WaitForTransferDone();
}
//status = true;
status = 1;
break;
case UDMA:
status = WriteSectors_Udma( uStBlock, uBlocks, uBufAddr);
break;
default:
Disp("Not supported mode in WriteBlocks()\n");
break;
}
return status;
}
/*-----------------------------------------------------------
* MemDump
*/
void Dump32(U32 addr, U32 words)
{
int i, j;
U32 *pMem;
pMem = (U32 *)(addr/4*4);
Disp("\n");
for(i=0; i<words; )
{
Disp(" %3d: ", i);
for(j=0; j<8; j++)
Disp("%08x ", *pMem++),
i++;
Disp("\n");
}
}
void TestPioDmaMode(void)
{
U32 k,i;
U32 writeBufferAddr, readBufferAddr;
U32 deviceLBA;
int nSector;
U32 uDeviceMaxSectors;
writeBufferAddr = 0x31000000; //0x60000000;
readBufferAddr = 0x31400000; //0x60400000;
//+daedoo 060913
//why not??
//rGPBCON = 0x2beaaa; // ATA DMA PIN Enable/
rGPGCON |= (3<<2)|(3<<0); // ATA nRESET, INTRQ Enable
rBANK_CFG |= 0x30;
OpenMedia(PIODMA);
uDeviceMaxSectors=GetMaxSectors();
Disp("\nInput device sector address[max: 0x%x]\n",uDeviceMaxSectors);
deviceLBA = GetIntNum();
Disp("Input sector count[max: 0x%x]\n",uDeviceMaxSectors-deviceLBA);
nSector = GetIntNum();
for (i=0; i<nSector*512; i++)
{
Outp8(writeBufferAddr+i, (i+1)%256);
Outp8(readBufferAddr+i, 0);
}
//for (k=0; k<nSector*512; k++){
// Outp8(writeBufferAddr+k, (k+3)%256);
//}
/*#if 0
SetAtaMode(PIODMA);
WriteBlocks(deviceLBA, nSector, writeBufferAddr);
SetAtaMode(PIO);
ReadBlocks( deviceLBA, nSector, readBufferAddr);
#elif 0
SetAtaMode(PIO);
WriteBlocks(deviceLBA, nSector, writeBufferAddr);
SetAtaMode(PIODMA);
ReadBlocks( deviceLBA, nSector, readBufferAddr);
#elif 1
SetAtaMode(PIODMA);
*/
Start();
WriteBlocks(deviceLBA, nSector, writeBufferAddr);
ReadTime(count);
count =0 ;
Disp("write done!!!\n");
Stop();
Start();
ReadBlocks( deviceLBA, nSector, readBufferAddr);
ReadTime(count);
count =0 ;
Disp("read done!!!\n");
Stop();
//#endif
VerifyData(writeBufferAddr, readBufferAddr, nSector);
//Dump32(readBufferAddr, nSector*128);
}
void StartWritingBlocks(U32 uStBlock, U32 uBlocks, U32 uBufAddr)
{
// Only PIODMA
/*Source Buffer Setting*/
Outp32(ATA_SBUF_START, uBufAddr);
Outp32(ATA_SBUF_SIZE, uBlocks*ATA_SECTORSIZE);
Outp32(ATA_XFR_NUM, uBlocks*ATA_SECTORSIZE);
SetAtaDevice(uStBlock, uBlocks);
WriteOnTaskFileReg(DEV_COMMAND, WRITESECTOR);
WaitForNoBusyStatus();
SetConfigMode(m_eMode, true);
SetTransferCommand(ATA_CMD_START);
//return true;
}
void StartReadingBlocks(U32 uStBlock, U32 uBlocks, U32 uBufAddr)
{
// Only PIODMA
/*Track Buffer 1 Setting*/
Outp32(ATA_TBUF_START, uBufAddr);
Outp32(ATA_TBUF_SIZE, uBlocks*ATA_SECTORSIZE);
Outp32(ATA_XFR_NUM, uBlocks*ATA_SECTORSIZE);
SetAtaDevice(uStBlock, uBlocks);
WriteOnTaskFileReg(DEV_COMMAND, READSECTOR);
WaitForNoBusyStatus();
SetConfigMode(m_eMode, false);
SetTransferCommand(ATA_CMD_START);
//return true;
}
U32 IsDmaDone(void)
{
SetTransferCommand(ATA_CMD_ABORT);
SetConfigMode(PIO, true);
WaitForNoBusyStatus();
return true;
}
void TestPioDmaIntMode(void)
{
U32 k,i;
U32 writeBufferAddr, readBufferAddr;
U32 deviceLBA;
int nSector;
U32 uDeviceMaxSectors;
writeBufferAddr = 0x31000000; //0x60000000;
readBufferAddr = 0x31400000; //0x60400000;
rGPGCON |= (3<<2)|(3<<0); // ATA nRESET, INTRQ Enable
rEBIPR = 0x11; // CF priority 1
rBANK_CFG |= 0x30; // EBI CF Setting
Outp32(ATA_IRQ_MASK, 0x1f); // ATA Interrupt all masking
OpenMedia(PIODMA);
uDeviceMaxSectors=GetMaxSectors();
Disp("\nInput device sector address[max: 0x%x]\n",uDeviceMaxSectors);
deviceLBA = GetIntNum();
Disp("Input sector count[max: 0x%x]\n",uDeviceMaxSectors-deviceLBA);
nSector = GetIntNum();
for (i=0; i<nSector*512; i++)
{
Outp8(writeBufferAddr+i, (i+1)%256);
Outp8(readBufferAddr+i, 0);
}
bIsDone = false;
bIsXferDone = false;
pISR_SDI_CF = (unsigned)Isr_Ata;
rINTMSK &= ~(BIT_SDI_CF);
rINTSUBMSK &= ~(BIT_SUB_CF);
ATA_ClearAllInterrupt();
Start();
for (i=0; i< nSector; i++)
{
StartWritingBlocks(deviceLBA+i, 1, writeBufferAddr+i*512);
while(bIsXferDone != true);
bIsXferDone = false;
}
ReadTime(count);
Disp("write done!!!\n");
Stop();
Start();
for (i=0; i<nSector; i++)
{
StartReadingBlocks(deviceLBA+i, 1, readBufferAddr+i*512);
while(bIsXferDone != true) ;
bIsXferDone = false;
}
ReadTime(count);
Disp("read done!!!\n");
Stop();
VerifyData(writeBufferAddr, readBufferAddr, nSector);
//Dump32(readBufferAddr, nSector*128);
}
void TestPioDmaModeRead(void)
{
U32 k;
U32 readBufferAddr;
U32 deviceLBA;
int nSector;
U32 uDeviceMaxSectors;
readBufferAddr = 0x31400000;
//INTC_Mask(INT_FIU);
OpenMedia(PIODMA);
uDeviceMaxSectors=GetMaxSectors();
Disp("\nInput device sector address[max: 0x%x]\n",uDeviceMaxSectors);
// deviceLBA = GetIntNum();
deviceLBA = 0;
Disp("Input sector count[max: 0x%x]\n",uDeviceMaxSectors-deviceLBA);
// nSector = GetIntNum();
nSector = 1;
ReadBlocks( deviceLBA, nSector, readBufferAddr);
Dump32(readBufferAddr, nSector*128);
}
void __irq Timer0_int(void)
{
count++;
//printf(".");
rSRCPND = BIT_TIMER0; //Clear pending bit
rINTPND = BIT_TIMER0;
rINTPND; //Prevent an double interrupt pending
}
void TestPioMode(void)
{
U32 k;
U32 writeBufferAddr, readBufferAddr;
U32 deviceLBA;
int nSector;
U32 uDeviceMaxSectors;
writeBufferAddr = 0x31000000; //0x60000000;
readBufferAddr = 0x31400000; //0x60400000;
//INTC_Mask(INT_FIU);
//ATA TEST GPIO INIT
//+daedoo 060913
rGPGCON |= (3<<2)|(3<<0); // ATA nRESET, INTRQ Enable
rBANK_CFG |= 0x30;
ATA_Reset();
printf("ATA Reset!!!\n");
Delay(100000);
OpenMedia(PIO);
uDeviceMaxSectors=GetMaxSectors();
Disp("\nInput device sector address[max: 0x%x]\n",uDeviceMaxSectors);
deviceLBA = GetIntNum();
Disp("Input sector count[max: 0x%x]\n",uDeviceMaxSectors-deviceLBA);
nSector = GetIntNum();
for (k=0; k<nSector*512; k++){
Outp8(writeBufferAddr+k, k);
}
Start();
WriteBlocks(deviceLBA, nSector, writeBufferAddr);
ReadTime(count);
count =0 ;
Disp("write done!!!\n");
Stop();
Start();
ReadBlocks( deviceLBA, nSector, readBufferAddr);
ReadTime(count);
count =0 ;
Disp("read done!!!\n");
Stop();
VerifyData(writeBufferAddr, readBufferAddr, nSector);
//Dump32(readBufferAddr, nSector*128);
}
void TestPioIntMode(void)
{
U32 k;
U32 writeBufferAddr, readBufferAddr;
U32 deviceLBA;
int nSector;
U32 uDeviceMaxSectors;
writeBufferAddr = 0x31000000; //0x60000000;
readBufferAddr = 0x31400000; //0x60400000;
//INTC_Mask(INT_FIU);
//ATA TEST GPIO INIT
//+daedoo 060913
rGPGCON |= (3<<2)|(3<<0); // ATA nRESET, INTRQ Enable
rBANK_CFG |= 0x30;
//ATA_Reset();
//printf("ATA Reset!!!\n");
//Delay(100000);
OpenMedia(PIO);
uDeviceMaxSectors=GetMaxSectors();
Disp("\nInput device sector address[max: 0x%x]\n",uDeviceMaxSectors);
deviceLBA = GetIntNum();
Disp("Input sector count[max: 0x%x]\n",uDeviceMaxSectors-deviceLBA);
nSector = GetIntNum();
for (k=0; k<nSector*512; k++){
Outp8(writeBufferAddr+k, k);
}
//+daedoo 060919
pISR_SDI_CF = (unsigned)Isr_Ata;
ClearPending(BIT_SDI_CF);
rSUBSRCPND |= (BIT_SUB_CF);
rINTMSK &= ~(BIT_SDI_CF);
rINTSUBMSK &= ~(BIT_SUB_CF);
ATA_ClearAllInterrupt();
//+daedoo end
Start();
WriteBlocks(deviceLBA, nSector, writeBufferAddr);
ReadTime(count);
count =0 ;
Disp("write done!!!\n");
Stop();
Start();
ReadBlocks( deviceLBA, nSector, readBufferAddr);
ReadTime(count);
count =0 ;
Disp("read done!!!\n");
Stop();
VerifyData(writeBufferAddr, readBufferAddr, nSector);
//Dump32(readBufferAddr, nSector*128);
}
void TestPioModeRead(void)
{
U32 k;
U32 writeBufferAddr, readBufferAddr;
U32 deviceLBA;
int nSector;
U32 uDeviceMaxSectors;
readBufferAddr = 0x31400000; //0x60400000;
//INTC_Mask(INT_FIU);
OpenMedia(PIO);
//GetMaxSectors(uDeviceMaxSectors);
uDeviceMaxSectors=GetMaxSectors();
Disp("\nInput device sector address[max: 0x%x]\n",uDeviceMaxSectors);
// deviceLBA = GetIntNum();
deviceLBA = 0;
Disp("Input sector count[max: 0x%x]\n",uDeviceMaxSectors-deviceLBA);
// nSector = GetIntNum();
nSector = 1;
// Disp("deviceLBA = %d ,nSector = %d\n",deviceLBA,nSector);
ReadBlocks( deviceLBA, nSector, readBufferAddr);
Dump32(readBufferAddr, nSector*128);
}
void Start(void)
{
U32 temp;
//+daedoo 060913
//rGPBCON = 0x2beaaa;
rGPBCON=0x2aa;
// Assert(uPreScale <= 256 && 1 <= uPreScale);
rINTMSK &= ~(BIT_TIMER0);
pISR_TIMER0=(int)Timer0_int;
Outp32(rTCON, 0); // timer0 stop
rTCFG0= (uPreScale-1)<<0; // preScalerFor0&1[7:0], preScalerFor2&3[15:8]
//Outp32(rTCFG0, (uPreScale-1)<<0); // preScalerFor0&1[7:0], preScalerFor2&3[15:8]
rTCFG1= 3<<0; // divider0[3:0] (0=1/2, 1=1/4, 2=1/8, 3=1/16), divider1,2,3,4
//rTCFG1= 0<<0; // divider0[3:0] (0=1/2, 1=1/4, 2=1/8, 3=1/16), divider1,2,3,4
rTCNTB0= 50000;
rTCMPB0= 50;
rTCON= (0<<3)|(1<<1)|(0<<0); // tiemr0 manual update
///Outp32(TCON, (0<<3)|(0<<1)|(1<<0)); // timer0 start, one-shot
rTCON= (1<<3)|(0<<1)|(1<<0); // timer0 start, one-shot
// autoReload[3], inverted[2], manualUpdate[1], start[0]
// while(1);
// TransStart();
}
void ReadTime(U32 count)
{
U32 usec, x;
x=rTCNTO0;
usec = 50000 - x;
Disp("\n========%d usec =======\n",(count*4000000)+80*usec);
// Disp("\n========%d usec =======\n",80*usec);
//
// TransStopAndGetClks(&elapsed, &occupied);
// Disp("\n(%dk/%dk)\n", (occupied+500)/1000, (elapsed+500)/1000);
}
void Stop(void)
{
rTCON= 0; // timer0 stop
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -