system.c
字号:
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP){
SetLastError(ERROR_NOT_READY);
RETAILMSG(1, (TEXT("ATAPI_REQUESTSENSE Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
// PACKET command protocol
*ATAPI_FETR = 0; // ATAPI Features ( Not use OverLap and DMA )
*ATAPI_IRRN = 0; // Sector Count
*ATAPI_RSVE = 0; // Sector Number
*ATAPI_BCTL = 18; // Byte Count Low ( 18 byte )
*ATAPI_BCTH = 0; // Byte Count High
*ATAPI_DCTR = 0x02; // Device Control ( INTRQ-OFF )
*ATAPI_COMD = ATPCOM_ATAPIPAKET; // ATA Command ( Packet Command A0)
// Status Reg BSY=0 , DRQ=1 ?
dwTimer = 0;
while( ( *ATAPI_STAT & 0x88 ) != 0x08 ){ // Status BSY=0,DRQ=1 then next
Sleep(ATAPI_SLEEP); // 100ms SLEEP
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP){
SetLastError(ERROR_NOT_READY);
RETAILMSG(1, (TEXT("ATAPI_REQUESTSENSE Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
// Write Data Register (Command Packet)
*ATAPI_DATW = ATAPI_REQUESTSENSE; // 0 Command code 03h
*ATAPI_DATW = 0; // 2 Reserved
*ATAPI_DATW = 0x0012; // 4 Allocation length 18 Byte
*ATAPI_DATW = 0; // 6 Reserved
*ATAPI_DATW = 0; // 8 Reserved
*ATAPI_DATW = 0; //10 Reserved
// Status Reg BSY=0 , DRDY=1 ,DREQ=1 ?
dwTimer = 0;
while( ( *ATAPI_STAT & 0xc8 ) != 0x48 ){ // Status BSY=0,DRDY=1,DREQ=1 then next
Sleep(ATAPI_SLEEP); // 100ms SLEEP
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP){
SetLastError(ERROR_NOT_READY);
RETAILMSG(1, (TEXT("ATAPI_REQUESTSENSE Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
if( (*ATAPI_STAT & ATPMASK_CHEK) != 0 ){ // Error ?
SetLastError(ERROR_READ_FAULT);
RETAILMSG(1, (TEXT("ATAPI_REQUESTSENSE Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
// Execute Data Read
rdata = (WORD*)Kdata; // Saved data pointer
do{
*rdata++ = *ATAPI_DATW; // Saved sense data
}while( ( *ATAPI_STAT & 0x08) != 0 ); // read while Status Reg DRQ=1
SenseKey = Kdata[1];
SenseKey &= 0x000f;
SenseCode = Kdata[6];
SenseCode &= 0x00ff;
switch(SenseKey){
case 0x0001:switch(SenseCode){
case 0x0017:ATAPI_errcode = ERROR_OPEN_FAILED; //RECOVERED DATA WITH RETRIES
break;
case 0x0018:ATAPI_errcode = ERROR_OPEN_FAILED; //RECOVERED DATA WITH ERROR CORRECTION&RETRIES APPLIED
break;
default:ATAPI_errcode = ERROR_FILE_NOT_FOUND;
}
break;
case 0x0002:switch(SenseCode){
case 0x0004:ATAPI_errcode = ERROR_NOT_READY; //LOGICAL DRIVE NOT READY
break;
case 0x0006:ATAPI_errcode = ERROR_NO_DATA_DETECTED; //NO REFERENCE POSITION FOUND(medium may be upside down)
break;
case 0x0030:ATAPI_errcode = ERROR_WRONG_DISK; //INCOMPATIBLE MEDIUM INSTALLED/CANNOT READ MEDIUM
break;
case 0x003a:ATAPI_errcode = ERROR_NO_MEDIA_IN_DRIVE; //MEDIUM NOT PRESENT
break;
case 0x0053:ATAPI_errcode = ERROR_DRIVE_LOCKED; //MEDIA REMOVAL PREVENTED
break;
default:ATAPI_errcode = ERROR_FILE_NOT_FOUND;
}
break;
case 0x0003:switch(SenseCode){
case 0x0002:ATAPI_errcode = ERROR_SEEK; //NO SEEK COMPLETE
break;
case 0x0011:ATAPI_errcode = ERROR_READ_FAULT; //L-EC UNCORRECTABLE ERROR,CIRC UNRECOVERED ERROR
break;
default:ATAPI_errcode = ERROR_FILE_NOT_FOUND;
}
break;
case 0x0004:switch(SenseCode){
case 0x00b6:ATAPI_errcode = ERROR_BAD_UNIT; //MEDIA LOAD MECHNISM FAILED
break;
default:ATAPI_errcode = ERROR_FILE_NOT_FOUND;
}
break;
case 0x0005:switch(SenseCode){
case 0x0020:ATAPI_errcode = ERROR_BAD_COMMAND; //INVALID COMMAND OPERATION CODE
break;
case 0x0021:ATAPI_errcode = ERROR_INVALID_BLOCK_LENGTH;//LOGICAL BLOCK ADDRESS OUT OF RANGE
break;
case 0x0024:ATAPI_errcode = ERROR_INVALID_FUNCTION; //INVALID FIELD IN COMMAND PACKET
break;
case 0x0064:ATAPI_errcode = ERROR_BAD_FORMAT; //ILLEGAL MODE FOR THIS TRACK OR INCOMPATIBLE MEDIUM
break;
default:ATAPI_errcode = ERROR_FILE_NOT_FOUND;
}
break;
case 0x0006:switch(SenseCode){
case 0x0028:ATAPI_errcode = ERROR_NOT_READY; //NOT READY TO READY TRANSITION
break;
case 0x0029:ATAPI_errcode = ERROR_BUS_RESET; //POWER ON,RESET OR BUS DEVICE RESET OCCURRED
break;
default:ATAPI_errcode = ERROR_FILE_NOT_FOUND;
}
break;
default:ATAPI_errcode = ERROR_FILE_NOT_FOUND;
}
return TRUE;
}
//
// IST main procedure.
//
DWORD
ATAPIIsrThread(
PDISK pDisk
)
{
HANDLE hReadInterrupt;
DWORD dwWaitTime = INFINITE;
BYTE Intstatus;
//
// initial IST
//
hReadInterrupt = CreateEvent( // create Event object from ISR
NULL,
FALSE,
FALSE,
NULL
);
if( hReadInterrupt == NULL )
{
DEBUGMSG( ATAPI_ERROR, (TEXT("ATAPI: IRQ event is not gotten.\r\n")));
goto ist_leave;
}
if( !InterruptInitialize( SYSINTR_IDE, hReadInterrupt, NULL, 0 ) )
{
DEBUGMSG( ATAPI_ERROR, (TEXT("ATAPI: System interrupt No. is not bindded.\r\n")));
goto ist_leave;
}
//
// IST main routine
//
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_HIGHEST );
while( TRUE )
{
if( WaitForSingleObject( hReadInterrupt, dwWaitTime ) == WAIT_TIMEOUT )
{
DEBUGMSG( ATAPI_ERROR, (TEXT("ATAPI: CD-ROM read interrupt is time out.\r\n")));
}
Intstatus = *ATAPI_STAT ; // Read Status Reg and INTRQ off
dwTimer = 0;
/******************************************************************************
* Modification Done by Maneesh Gupta
*
* Interrupt Mask for the IDE has been changed as IDE interrupt status bit
* position is 5.
*****************************************************************************/
#if (SH_PLATFORM == PLATFORM_ASPEN)
while( ( *ATAPI_INT & 0x20 ) == 0 )
#elif (SH_PLATFORM == PLATFORM_BIGSUR)
while( ( *ATAPI_INT & 0x40 ) == 0 )
#endif
{ // ATAPI INTRQ(bit5) = HIGH then next
/******************************************************************************
* End of modification Done by Maneesh Gupta
*****************************************************************************/
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP)
{
ATAPI_errcode = ERROR_NOT_READY;
SetEvent( pDisk->d_ReadEvent ); // Notify end of read
/******************************************************************************
* Modification Done by Maneesh Gupta
*
* System Interrupt ID has been changed from SYSINTR_ATAPI to SYSINTR_IDE
*****************************************************************************/
InterruptDone( SYSINTR_IDE );
/******************************************************************************
* End of modification Done by Maneesh Gupta
*****************************************************************************/
return 0;
}
if( CD_ROM_STA.flag == ATAPI_READPROC ){ // ATAPI READ PROCESS ?
if( ( *ATAPI_STAT & ATPMASK_CHEK) != 0 ){ // Error ?
CD_ROM_STA.flag = ATAPI_ENDPROC; // Data read End (Clear wait flag)
}else{
// Error check
if( ( *ATAPI_STAT & ATPMASK_DREQ ) != 0 ){ // DREQ = 1 ?
if( ( *ATAPI_IRRN & 0x02 ) == 0x02 )
{
// Data to Host then read data
DEBUGMSG(1, (TEXT("Datain <========\r\n")));
DataIN(); // Data read
}
}else{
if( ( *ATAPI_IRRN & ATPMASK_IRRN ) == 3 ){ // End Status
if( ( *ATAPI_STAT & ATPMASK_DREQ ) == 0 ){ // DREQ = 0 ?
CD_ROM_STA.flag = ATAPI_ENDPROC; // Data read End (Clear wait flag)
}
}
}
}
if( CD_ROM_STA.flag == ATAPI_ENDPROC ){ // Read process is finished
SetEvent( pDisk->d_ReadEvent ); // Notify end of read
}
}
/******************************************************************************
* Modification Done by Maneesh Gupta
*
* System Interrupt ID has been changed from SYSINTR_ATAPI to SYSINTR_IDE
*****************************************************************************/
InterruptDone( SYSINTR_IDE );
/******************************************************************************
* End of modification Done by Maneesh Gupta
*****************************************************************************/
}
ist_leave:
return 0;
}
//
// IST main procedure.
//
WORD
DataIN()
{
struct BustDataS *rdata;
union CharShort datasize;
DWORD dwCot;
rdata = (struct BustDataS*)CD_ROM_STA.count;
/******************************************************************************
* Modification Done by Maneesh Gupta
*
* system should wait till Data request goes high
******************************************************************************/
while( ( *ATAPI_STAT & ATPMASK_DREQ ) == 0 )
{
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
/******************************************************************************
* End of modification Done by Maneesh Gupta
*****************************************************************************/
datasize.byte.low = (UCHAR)*ATAPI_BCTL;
datasize.byte.hi = (UCHAR)*ATAPI_BCTH;
CD_ROM_STA.count += (unsigned long)(datasize.word); // count up
dwCot = (long)( ((datasize.word >>2)>>2)>>1 );
while( dwCot != 0 ){
rdata->d0 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d1 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d2 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d3 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d4 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d5 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d6 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d7 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d8 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->d9 = (USHORT)*ATAPI_DATW; // Saved word data
rdata->da = (USHORT)*ATAPI_DATW; // Saved word data
rdata->db = (USHORT)*ATAPI_DATW; // Saved word data
rdata->dc = (USHORT)*ATAPI_DATW; // Saved word data
rdata->dd = (USHORT)*ATAPI_DATW; // Saved word data
rdata->de = (USHORT)*ATAPI_DATW; // Saved word data
rdata->df = (USHORT)*ATAPI_DATW; // Saved word data
rdata++;
dwCot--;
dwRSize = dwRSize + 32;
}
return 0;
}
/******************************************************************************
* Modification Done by Maneesh Gupta
*
* Start Atapi unit uses the Stop/Start Unt command to bring the CD-Rom drive
* to the responding state from the state when it stops responding to the com-
* mands
*****************************************************************************/
WORD StartATAPIUnit(VOID)
{
DEBUGMSG(1, (TEXT("Start Atapi Unit has be called \r\n")));
// Device selection protocol
dwTimer = 0;
while( ( *ATAPI_STAT & ATPMASK_BUSYDREQ ) != 0){ // Status Reg BSY , DRQ = 0
Sleep(ATAPI_SLEEP); // 100ms SLEEP
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP){
SetLastError(ERROR_NOT_READY);
RETAILMSG(1, (TEXT("ATAPI_STARTUNIT Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
dwTimer = 0;
*ATAPI_DSEL = ATAPI_DEVICESELECT; // Device Select ( DRIVE 0 master )
while( ( *ATAPI_STAT & ATPMASK_BUSYDREQ ) != 0){ // Status Reg BSY , DRQ = 0
Sleep(ATAPI_SLEEP); // 100ms SLEEP
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP){
SetLastError(ERROR_NOT_READY);
RETAILMSG(1, (TEXT("ATAPI_START UNIT Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
// PACKET command protocol
*ATAPI_FETR = 0; // ATAPI Features ( Not use OverLap and DMA )
*ATAPI_IRRN = 0; // Sector Count
*ATAPI_RSVE = 0; // Sector Number
*ATAPI_BCTL = 0; // Byte Count Low ( 512 byte )
*ATAPI_BCTH = 0; // Byte Count High
*ATAPI_DCTR = 0x02; // Device Control ( INTRQ-OFF )
*ATAPI_COMD = ATPCOM_ATAPIPAKET; // ATA Command ( Packet Command )
// Status Reg BSY=0 , DRQ=1 ?
dwTimer = 0;
while( ( *ATAPI_STAT & ATPMASK_BUSYDREQ ) != 0x08 ){ // Status BSY=0,DRQ=1 then next
Sleep(ATAPI_SLEEP); // 100ms SLEEP
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP){
SetLastError(ERROR_NOT_READY);
RETAILMSG(1, (TEXT("ATAPI_TESTUNITREADY Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
// Write Data Register (Command Packet)
*ATAPI_DATW = 0x1b;// ATAPI_TESTUNITREADY; //0,1 Command code
*ATAPI_DATW = 0; // 2,3 Reserved
*ATAPI_DATW = 0; // 4,5 Reserved
*ATAPI_DATW = 0; // 6,7 Reserved
*ATAPI_DATW = 0; // 8,9 Reserved
*ATAPI_DATW = 0; //10,11 Reserved
// Status Reg BSY=0 , DRDY=1 ?
dwTimer = 0;
while( ( *ATAPI_STAT & ATPMASK_BUSYDRDY ) != 0x40 ){ // Status BSY=0,DRDY=1 then next
Sleep(ATAPI_SLEEP); // 100ms SLEEP
dwTimer++;
if(dwTimer>ATAPI_SLEEP)
break;
}
if(dwTimer>ATAPI_SLEEP){
SetLastError(ERROR_NOT_READY);
RETAILMSG(1, (TEXT("ATAPI_TESTUNITREADY Command : GetLastError() = %d\r\n"), GetLastError()));
return FALSE;
}
if( ( *ATAPI_STAT & ATPMASK_CHEK) != 0 ){ // Error ?
GetATAPError();
return FALSE;
}
return TRUE;
}
/******************************************************************************
* End of modification Done by Maneesh Gupta
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -