📄 ata_atapiif.c
字号:
#ifdef IDE_SWAP_BIT_OFF
pATAIFStatus->status = RD_REG_VAL_L( IDE_CS16 );/* Alternate Status Register */
#else
pATAIFStatus->status = RD_REG_VAL_H( IDE_CS16 );/* Alternate Status Register */
#endif
REG_CMP_CLEAR(); /* Interrupt Status Clear */
// For IDE SWAP(SWAP Bit is ON by default.)
#ifdef IDE_SWAP_BIT_OFF
pATAIFStatus->IntReasen = RD_REG_VAL_L( IDE_CS02 );/* Interrupt Reason Register */
#else
pATAIFStatus->IntReasen = RD_REG_VAL_H( IDE_CS02 );/* Interrupt Reason Register */
#endif
REG_CMP_CLEAR(); /* Interrupt Status Clear */
// For IDE SWAP(SWAP Bit is ON by default.)
#ifdef IDE_SWAP_BIT_OFF
pATAIFStatus->transfersize = ( RD_REG_VAL_L( IDE_CS05 ) * 0x100 );/* Byte Count MSB Register */
#else
pATAIFStatus->transfersize = ( RD_REG_VAL_H( IDE_CS05 ) * 0x100 );/* Byte Count MSB Register */
#endif
REG_CMP_CLEAR(); /* Interrupt Status Clear */
// For IDE SWAP(SWAP Bit is ON by default.)
#ifdef IDE_SWAP_BIT_OFF
pATAIFStatus->transfersize |= RD_REG_VAL_L( IDE_CS04 );/* Byte Count LSB Register */
#else
pATAIFStatus->transfersize |= RD_REG_VAL_H( IDE_CS04 );/* Byte Count LSB Register */
#endif
REG_CMP_CLEAR(); /* Interrupt Status Clear */
pATAIFStatus->busStatus = RegRead( REG08_IDE_Status );
if( ( pATAIFStatus->busStatus & 0x20 ) ){/* INTRQ Assert ? */
// For IDE SWAP(SWAP Bit is ON by default.)
#ifdef IDE_SWAP_BIT_OFF
RD_REG_VAL_L( IDE_CS07 ); /* Status register */
#else
RD_REG_VAL_H( IDE_CS07 ); /* Status register */
#endif
REG_CMP_CLEAR(); /* Interrupt Status Clear */
}
if( !( pATAIFStatus->status & 0x88 ) && !( pATAIFStatus->busStatus & 0xC0 ) ){
PortExecFlag[portNumber] = PORT_STOP; /* ATA/ATAPI PORT under suspension */
}
/* Complete */
return STATUS_SUCCESS;
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name: ATA_IFPIODataTransfer
//
// description : Executing PIO data transfer
//
// : Executing PIO data transfer to the specified device.
// Return error when the specified port port is in suspension.
//
// argument : USHORT portNumber The port No that the device is connected.
// UCHAR selectDevice Master/Slave and BigDrive selection
// ATA_IFTRANPARA *pTranPara PIO transfer parameter
//
// return : LONG status Processing result
//
////////////////////////////////////////////////////////////////////////
*/
LONG ATA_IFPIODataTransfer( USHORT portNumber, UCHAR selectDevice, ATA_IFTRANPARA *pTranPara )
{
USHORT i;
UCHAR *pDataPtr;
if( PortLock[portNumber] == ATA_IF_PORT_UNLOCK ){
/* The specified port is not locked. */
return STATUS_UNLOCK_PORT;
}
if( PortExecFlag[portNumber] == PORT_STOP ){
/* Error */
return STATUS_UNSUCCESSFUL;
}
if( selectDevice != ATA_IF_MASTER && selectDevice != ATA_IF_SLAVE ){
/* Select Device Parameter Error */
return STATUS_INVALID_PARAMETER;
}
/*
// Because the SWAP bit was lost Revives SWAP bit
// rbIDE_Config_1.Swap = BIT_ON; // Data Swap
// For IDE SWAP(SWAP Bit is ON by default.)
*/
#ifdef IDE_SWAP_BIT_OFF
/* Swap None */
RegClear( REG08_IDE_Config_1, BIT_Swap_None );
#endif
pDataPtr = (UCHAR *)pTranPara->dataPointer;
if( pTranPara->direction == ATA_IF_IDE_IN ){
/* PIO Data IN */
REG_CMP_CLEAR(); /* Interrupt Status Clear */
for(i=0; i<pTranPara->transfersize; i+=2){
RD_REG_SET( IDE_CS00 ); /* Data register */
RD_GO();
RD_REG_CMP_WAIT();
// Because the SWAP bit was lost
// *pDataPtr++ = rbIDE_RdRegValue_H.IDE_RdRegValueH;
// *pDataPtr++ = rbIDE_RdRegValue_L.IDE_RdRegValueL;
// For IDE SWAP(SWAP Bit is ON by default.)
#ifdef IDE_SWAP_BIT_OFF
*pDataPtr++ = RegRead( REG08_IDE_RdRegValue_0 );
*pDataPtr++ = RegRead( REG08_IDE_RdRegValue_1 );
#else
*pDataPtr++ = RegRead( REG08_IDE_RdRegValue_0 );
*pDataPtr++ = RegRead( REG08_IDE_RdRegValue_1 );
#endif
REG_CMP_CLEAR(); /* Interrupt Status Clear */
pTranPara->dataPointer +=2;
}
}else{
/* PIO Data OUT */
SEQ_WR_REG_CMP_CLEAR(); /* Interrupt Status Clear */
for( i = 0; i < (pTranPara->transfersize / 2); i++){
// For IDE SWAP(SWAP Bit is ON by default.)
#ifdef IDE_SWAP_BIT_OFF
RegWrite( REG08_IDE_SeqWrRegAdrs, IDE_CS00 );
RegWrite( REG08_IDE_SeqWrRegValue, *pDataPtr++ );
RegWrite( REG08_IDE_SeqWrRegAdrs, IDE_CS00 );
RegWrite( REG08_IDE_SeqWrRegValue, *pDataPtr++ );
#else
RegWrite( REG08_IDE_SeqWrRegAdrs, IDE_CS00 );
RegWrite( REG08_IDE_SeqWrRegValue, *pDataPtr++ );
RegWrite( REG08_IDE_SeqWrRegAdrs, IDE_CS00 );
RegWrite( REG08_IDE_SeqWrRegValue, *pDataPtr++ );
#endif
// if(( i + 1 ) % 8 == 0 ){
if( (( i + 1 ) % 8 == 0 ) || ((pTranPara->transfersize / 2) - 1 == i) ){
/* When writing in 16 registers */
SEQ_WR_GO(); /* IDE Sequence Write Go */
SEQ_WR_REG_CMP_WAIT(); /* Waiting of the end of write operation */
SEQ_WR_REG_CMP_CLEAR(); /* Interrupt Status Clear */
}
pTranPara->dataPointer +=2;
}
}
/* Complete */
return STATUS_SUCCESS;
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name: ATA_InterruptProc
//
// description : ATA Interface interrupt process
//
// argument : none
//
// return : none
//
////////////////////////////////////////////////////////////////////////
*/
LONG ATA_IFGetInterrupt( UCHAR mainIntEnb, ATA_IFINTERRUPT *pATAIFInterrupt)
{
UCHAR enb;
*(UCHAR*)&pATAIFInterrupt->ide_int_stat = RegRead(REG08_IDE_IntStat);
/* clear the interrupt factor */
RegWrite( REG08_IDE_IntStat, *(UCHAR*)&pATAIFInterrupt->ide_int_stat );
enb = RegRead(REG08_MainIntEnb);
enb |= mainIntEnb;
RegWrite( REG08_MainIntEnb, enb );
return STATUS_SUCCESS;
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name: ATA_IFSetIntEvent
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
LONG ATA_IFSetIntEvent( UCHAR val )
{
RegWrite( REG08_IDE_IntStat, 0xFF );
RegWrite( REG08_IDE_IntEnb, val );
return STATUS_SUCCESS;
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name: ATA_IFIdeTerm
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
LONG ATA_IFIdeTerm( UCHAR term )
{
/* Protect Release */
RegWrite( REG08_ModeProtect, BIT_ModeProtect_ON );
if( term == ATA_IF_TERM_ON ){
/* Device Connect */
RegSet( REG08_ClkSelect, BIT_xActIDE_Term_OFF );
}
else{
RegClear( REG08_ClkSelect, BIT_xActIDE_Term_OFF );
}
RegClear( REG08_ClkSelect, BIT_xActIDE_DD_Term_OFF ); /* Default on.(xActIDE_DD_Term=0) */
RegWrite( REG08_ModeProtect, BIT_ModeProtect_OFF );
return STATUS_SUCCESS;
}
/*--------------------------------------------------------------------------*/
/* */
/*--------------------------------------------------------------------------*/
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void SEQ_WR_REG_SET( UCHAR adr, UCHAR val )
{
/* IDE Sequential Register Write Address FIFO*/
RegWrite( REG08_IDE_SeqWrRegAdrs, adr );
/* IDE Sequential Register Write Value FIFO*/
RegWrite( REG08_IDE_SeqWrRegValue, val );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void SEQ_WR_GO( void )
{
RegSet( REG08_IDE_SeqWrRegControl, BIT_IDE_SeqWrReg );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void SEQ_WR_REG_CMP_WAIT( void )
{
while( !(RegRead( REG08_IDE_IntStat ) & BIT_IDE_SeqWrRegCmp ) ){
;
}
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void SEQ_WR_REG_CMP_CLEAR( void )
{
/* Interrupt Status Clear(IDE_SeqWrRegCmp)*/
RegWrite( REG08_IDE_IntStat, BIT_IDE_SeqWrRegCmp );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline UCHAR RD_REG_VAL_L( UCHAR adr )
{
RegWrite( REG08_IDE_RegAdrs, ( BIT_IDE_RdReg | adr ) );
while( !(RegRead( REG08_IDE_IntStat ) & BIT_IDE_RegCmp ) ){
;
}
return RegRead( REG08_IDE_RdRegValue_1 );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline UCHAR RD_REG_VAL_H( UCHAR adr )
{
RegWrite( REG08_IDE_RegAdrs, ( BIT_IDE_RdReg | adr ) );
while( !(RegRead( REG08_IDE_IntStat ) & BIT_IDE_RegCmp ) ){
;
}
return RegRead( REG08_IDE_RdRegValue_0 );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void WR_REG_VAL_L( UCHAR adr, UCHAR val )
{
RegWrite( REG08_IDE_WrRegValue_1, val );
RegWrite( REG08_IDE_RegAdrs, ( BIT_IDE_WrReg | adr ) );
while( !(RegRead( REG08_IDE_IntStat ) & BIT_IDE_RegCmp ) ){
;
}
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void WR_REG_VAL_H( UCHAR adr, UCHAR val )
{
RegWrite( REG08_IDE_WrRegValue_0, val );
/* IDE Register Write Go */
RegWrite( REG08_IDE_RegAdrs, ( BIT_IDE_WrReg | adr ) );
while( !(RegRead( REG08_IDE_IntStat ) & BIT_IDE_RegCmp ) ){
;
}
/* Write opration completed */
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void RD_REG_SET( UCHAR adr )
{
/* IDE_RegAddress */
RegWrite( REG08_IDE_RegAdrs, adr );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void RD_GO( void )
{
/* IDE Register Read Go */
RegSet( REG08_IDE_RegAdrs, BIT_IDE_RdReg );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void RD_REG_CMP_WAIT( void )
{
while( !(RegRead( REG08_IDE_IntStat ) & BIT_IDE_RegCmp ) ){
;
}
/* Read operation completed. */
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline void REG_CMP_CLEAR( void )
{
/* Interrupt Status Clear(IDE_RegCmp)*/
RegWrite( REG08_IDE_IntStat, BIT_IDE_RegCmp );
}
/*
////////////////////////////////////////////////////////////////////////
// Function_Name:
//
// description :
//
// argument :
//
// return :
//
////////////////////////////////////////////////////////////////////////
*/
Inline LONG REG_RMOD_SET( UCHAR piomode )
{
switch( piomode ){
case ATA_IF_PIO_MODE0: /* PIO Mode0 Set */
RegWrite( REG08_IDE_Rmod, 0xFF );
break;
case ATA_IF_PIO_MODE1: /* PIO Mode1 Set */
RegWrite( REG08_IDE_Rmod, 0xF1 );
break;
case ATA_IF_PIO_MODE2: /* PIO Mode2 Set */
RegWrite( REG08_IDE_Rmod, 0xF0 );
break;
case ATA_IF_PIO_MODE3: /* PIO Mode3 Set */
RegWrite( REG08_IDE_Rmod, 0x22 );
break;
case ATA_IF_PIO_MODE4: /* PIO Mode4 Set */
RegWrite( REG08_IDE_Rmod, 0x10 );
break;
default: /* PIO Mode Parameter Error */
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -