📄 usbh_ide_if.c
字号:
//-----------------------------------------------------------------
// The first transfer
//-----------------------------------------------------------------
devicePara[deviceNo].transferSize = 0;
devicePara[deviceNo].xferDataLen = devicePara[deviceNo].tranCount = pXferReady->xferDataLen;
switch(devicePara[deviceNo].xferMode) {
case IDE_XFER_DMA:
/* DMA transfer */
REG_DMAX_WINDOW_ADDR(prsDMAxWindow, devicePara[deviceNo].usedDMACh);
prxDMAxWindow = (volatile REG_rxDMAxWindow *)prsDMAxWindow;
RegClear( &prxDMAxWindow->rcDMAx_Config, BIT_FreeRun_FreeRun );
if( USBH_HCD_DMA_MODE ){
RegModify( &prxDMAxWindow->rcDMAx_Config, MASK_DMA_Mode, BIT_DMA_Mode_AddressDecodeMode );
}else{
RegModify( &prxDMAxWindow->rcDMAx_Config, MASK_DMA_Mode, BIT_DMA_Mode_NormalMode );
}
RegModify( &prxDMAxWindow->rcDMAx_Config, MASK_ReqAssertCount, USBH_HCD_DMA_REQ_ASSERT_COUNT );
if( devicePara[deviceNo].direction == DRV_FUNC_OUT ){
/* In case of OUT direction */
RegModify( &prxDMAxWindow->rcDMAx_Control, MASK_DMA_Dir, BIT_DMA_DirToFIFO );
pSrcAdrs = devicePara[deviceNo].xferStart.bufferPtr;
pDesAdrs = (unsigned char *)&prxDMAxWindow->rsDMAx_WrData;
pfnCPUDMACallback = NULL;
} else {
/* In case of IN direction */
RegModify( &prxDMAxWindow->rcDMAx_Control, MASK_DMA_Dir, BIT_DMA_DirFromFIFO );
pSrcAdrs = (unsigned char *)&prxDMAxWindow->rsDMAx_RdData;
pDesAdrs = devicePara[deviceNo].xferStart.bufferPtr;
pfnCPUDMACallback = NULL;
}
if( devicePara[deviceNo].usedDMACh == 0 ) {
RegSet( REG08_MediaFIFO_Join, BIT_JoinDMA0 );
} else {
RegSet( REG08_MediaFIFO_Join, BIT_JoinDMA1 );
}
prxDMAxWindow->rsDMAx_Count_H = HIWORD(devicePara[deviceNo].tranCount);
prxDMAxWindow->rsDMAx_Count_L = LOWORD(devicePara[deviceNo].tranCount);
USBH_HCDS_CPUDMAStart(devicePara[deviceNo].direction, pSrcAdrs, pDesAdrs,
devicePara[deviceNo].tranCount, pfnCPUDMACallback);
RegSet( &prxDMAxWindow->rcDMAx_Control, BIT_DMA_Go );
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_XFER_START, sizeof(devicePara[deviceNo].xferStart), &devicePara[deviceNo].xferStart);
break;
case IDE_XFER_HPIO:
if(devicePara[deviceNo].direction == DRV_FUNC_IN) {
RegSet( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Full );
} else {
/* Data is put into FIFO */
if(devicePara[deviceNo].tranCount > MEDIA_FIFO_SIZE) {
dataCount = WriteMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr, MEDIA_FIFO_SIZE);
devicePara[deviceNo].tranCount -= dataCount;
} else {
dataCount = WriteMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr, devicePara[deviceNo].tranCount);
devicePara[deviceNo].tranCount -= dataCount;
}
devicePara[deviceNo].xferStart.bufferPtr += dataCount;
RegSet( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Empty );
}
/* IntStat Clear */
RegWrite( REG08_MainIntStat, BIT_MediaFIFO_IntStat );
/* IDE Interrupt Enable */
RegSet( REG08_MainIntEnb, BIT_EnMediaFIFO_IntStat );
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_XFER_START, sizeof(devicePara[deviceNo].xferStart), &devicePara[deviceNo].xferStart);
break;
case IDE_XFER_SPIO:
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_XFER_START, sizeof(devicePara[deviceNo].xferStart), &devicePara[deviceNo].xferStart);
break;
}
} else {
//-----------------------------------------------------------------
// Devision transfer process
//-----------------------------------------------------------------
/* Update bufferPtr */
if(devicePara[deviceNo].xferMode == IDE_XFER_SPIO) {
devicePara[deviceNo].xferStart.bufferPtr += devicePara[deviceNo].xferDataLen;
}
devicePara[deviceNo].xferDataLen = devicePara[deviceNo].tranCount = pXferReady->xferDataLen;
switch(devicePara[deviceNo].xferMode) {
case IDE_XFER_DMA:
/* In case of DMA Transfer */
REG_DMAX_WINDOW_ADDR(prsDMAxWindow, devicePara[deviceNo].usedDMACh);
prxDMAxWindow = (volatile REG_rxDMAxWindow *)prsDMAxWindow;
RegClear( &prxDMAxWindow->rcDMAx_Config, BIT_FreeRun_FreeRun );
if( USBH_HCD_DMA_MODE ){
RegModify( &prxDMAxWindow->rcDMAx_Config, MASK_DMA_Mode, BIT_DMA_Mode_AddressDecodeMode );
}else{
RegModify( &prxDMAxWindow->rcDMAx_Config, MASK_DMA_Mode, BIT_DMA_Mode_NormalMode );
}
RegModify( &prxDMAxWindow->rcDMAx_Config, MASK_ReqAssertCount, USBH_HCD_DMA_REQ_ASSERT_COUNT );
if( devicePara[deviceNo].direction == DRV_FUNC_OUT ){
/* In case of OUT direction */
RegModify( &prxDMAxWindow->rcDMAx_Control, MASK_DMA_Dir, BIT_DMA_DirToFIFO );
pSrcAdrs = devicePara[deviceNo].xferStart.bufferPtr;
pDesAdrs = (unsigned char *)&prxDMAxWindow->rsDMAx_WrData;
pfnCPUDMACallback = NULL;
} else {
/* In case of IN direction */
RegModify( &prxDMAxWindow->rcDMAx_Control, MASK_DMA_Dir, BIT_DMA_DirFromFIFO );
pSrcAdrs = (unsigned char *)&prxDMAxWindow->rsDMAx_RdData;
pDesAdrs = devicePara[deviceNo].xferStart.bufferPtr;
pfnCPUDMACallback = NULL;
}
if( devicePara[deviceNo].usedDMACh == 0 ) {
RegSet( REG08_MediaFIFO_Join, BIT_JoinDMA0 );
} else {
RegSet( REG08_MediaFIFO_Join, BIT_JoinDMA1 );
}
prxDMAxWindow->rsDMAx_Count_H = HIWORD(devicePara[deviceNo].tranCount);
prxDMAxWindow->rsDMAx_Count_L = LOWORD(devicePara[deviceNo].tranCount);
USBH_HCDS_CPUDMAStart(devicePara[deviceNo].direction, pSrcAdrs, pDesAdrs,
devicePara[deviceNo].tranCount, pfnCPUDMACallback);
RegSet( &prxDMAxWindow->rcDMAx_Control, BIT_DMA_Go );
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_XFER_START, sizeof(devicePara[deviceNo].xferStart), &devicePara[deviceNo].xferStart);
break;
case IDE_XFER_HPIO:
if(devicePara[deviceNo].direction == DRV_FUNC_IN) {
RegSet( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Full );
} else {
/* Write Data to FIFO */
if(devicePara[deviceNo].tranCount > MEDIA_FIFO_SIZE) {
dataCount = WriteMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr, MEDIA_FIFO_SIZE);
devicePara[deviceNo].tranCount -= dataCount;
} else {
dataCount = WriteMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr, devicePara[deviceNo].tranCount);
devicePara[deviceNo].tranCount -= dataCount;
}
devicePara[deviceNo].xferStart.bufferPtr += dataCount;
RegSet( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Empty );
}
/* IntStat Clear */
RegWrite( REG08_MainIntStat, BIT_MediaFIFO_IntStat );
/* IDE Interrupt Enable */
RegSet( REG08_MainIntEnb, BIT_EnMediaFIFO_IntStat );
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_XFER_START, sizeof(devicePara[deviceNo].xferStart), &devicePara[deviceNo].xferStart);
break;
case IDE_XFER_SPIO:
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_XFER_START, sizeof(devicePara[deviceNo].xferStart), &devicePara[deviceNo].xferStart);
break;
}
}
}
/*=============================================================================
// Function_Name: MsgIdeXferCmp
//
// description : It processes the IDE data transfer completion notification from IDE task
//
// argument : USBH_SAMPLE_MSG pMsg
//
// return : none
//=============================================================================
*/
void MsgIdeXferCmp ( UCHAR deviceNo, USBH_SAMPLE_MSG *pMsg )
{
ULONG dataCount;
volatile REG_rxDMAxWindow *prxDMAxWindow;
volatile unsigned short *prsDMAxWindow;
switch(devicePara[deviceNo].xferMode) {
case IDE_XFER_DMA:
REG_DMAX_WINDOW_ADDR(prsDMAxWindow, devicePara[deviceNo].usedDMACh);
prxDMAxWindow = (volatile REG_rxDMAxWindow *)prsDMAxWindow;
USBH_HCDS_CPUDMAStop();
RegClear( &prxDMAxWindow->rcDMAx_Config, BIT_ActiveDMA );
if( devicePara[deviceNo].usedDMACh == 0 ) {
RegClear( REG08_MediaFIFO_Join, BIT_JoinDMA0 );
} else {
RegClear( REG08_MediaFIFO_Join, BIT_JoinDMA1 );
}
devicePara[deviceNo].usedDMACh = DMA_NOT_USE;
break;
case IDE_XFER_HPIO:
if(devicePara[deviceNo].direction == DRV_FUNC_IN) {
/* Interrupt Disable */
RegClear( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Full );
/* read the remainder data from FIFO. */
if(devicePara[deviceNo].tranCount != 0) {
dataCount = ReadMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr);
devicePara[deviceNo].tranCount -= dataCount;
devicePara[deviceNo].xferStart.bufferPtr += dataCount;
}
} else {
/* Interrupt Disable */
RegClear( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Empty );
}
break;
case IDE_XFER_SPIO:
break;
}
/* Update the number that real transfered */
devicePara[deviceNo].transferSize += devicePara[deviceNo].xferDataLen;
}
/*=============================================================================
// Function_Name: MsgIdeCmdCmp
//
// description : It processes the IDE command completion notification from IDE task
//
// argument : USBH_SAMPLE_MSG pMsg
//
// return : none
//=============================================================================
*/
void MsgIdeCmdCmp ( UCHAR deviceNo, USBH_SAMPLE_MSG *pMsg )
{
PARAM_MSG_NTFY_IDE_CMD *pIdeStatus;
volatile REG_rxDMAxWindow *prxDMAxWindow;
volatile unsigned short *prsDMAxWindow;
pIdeStatus = (PARAM_MSG_NTFY_IDE_CMD *)pMsg->msgData;
if(devicePara[deviceNo].xferMode == IDE_XFER_DMA) {
REG_DMAX_WINDOW_ADDR(prsDMAxWindow, devicePara[deviceNo].usedDMACh);
prxDMAxWindow = (volatile REG_rxDMAxWindow *)prsDMAxWindow;
USBH_HCDS_CPUDMAStop();
RegClear( &prxDMAxWindow->rcDMAx_Config, BIT_ActiveDMA );
if( devicePara[deviceNo].usedDMACh == 0 ) {
RegClear( REG08_MediaFIFO_Join, BIT_JoinDMA0 );
} else {
RegClear( REG08_MediaFIFO_Join, BIT_JoinDMA1 );
}
devicePara[deviceNo].usedDMACh = DMA_NOT_USE;
}
if(pIdeStatus->result == IDE_REQ_OK) {
/* Update the number that real transfered */
devicePara[deviceNo].transferSize += devicePara[deviceNo].xferDataLen;
devicePara[deviceNo].commandStatus = COMMAND_OK;
} else {
/* Update the number that real transfered */
devicePara[deviceNo].transferSize += pIdeStatus->xferDataLen;
devicePara[deviceNo].commandStatus = COMMAND_NG;
}
}
/*=============================================================================
// Function_Name: USBH_IDE_IntEvent
//
// description : Process the interrupt event
//
// argument : None
//
// return : None
//=============================================================================*/
void USBH_IDE_IntEvent( UCHAR deviceNo )
{
UCHAR mediaFIFO_IntStat;
ULONG dataCount;
OS_LocCpu(); /* Disable the interrupt */
/* Get the interrupt factor */
mediaFIFO_IntStat = RegRead( REG08_MediaFIFO_IntStat );
DIRECT_B(main_int_enb_usbh_sample) = 0x00; /* Clear */
OS_UnlCpu(); /* Disable the interrupt */
switch(devicePara[deviceNo].xferMode) {
case IDE_XFER_DMA:
break;
case IDE_XFER_HPIO:
if( (devicePara[deviceNo].direction == DRV_FUNC_IN) && (mediaFIFO_IntStat & BIT_FIFO_Full ) ) {
RegClear( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Full );
/* Read the data from FIFO */
dataCount = ReadMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr);
devicePara[deviceNo].tranCount -= dataCount;
devicePara[deviceNo].xferStart.bufferPtr += dataCount;
RegWrite( REG08_MediaFIFO_IntStat, BIT_FIFO_Full );
if(devicePara[deviceNo].tranCount != 0) {
RegSet( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Full );
}
} else if( (devicePara[deviceNo].direction == DRV_FUNC_OUT) && (mediaFIFO_IntStat & BIT_FIFO_Empty) ) {
RegClear( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Empty );
/* Write to FIFO */
if(devicePara[deviceNo].tranCount > MEDIA_FIFO_SIZE) {
dataCount = WriteMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr, MEDIA_FIFO_SIZE);
} else {
dataCount = WriteMediaFIFOData(devicePara[deviceNo].xferStart.bufferPtr, devicePara[deviceNo].tranCount);
}
devicePara[deviceNo].tranCount -= dataCount;
devicePara[deviceNo].xferStart.bufferPtr += dataCount;
RegWrite( REG08_MediaFIFO_IntStat, BIT_FIFO_Empty );
if(devicePara[deviceNo].tranCount != 0) {
RegSet( REG08_MediaFIFO_IntEnb, BIT_EnFIFO_Empty );
}
}
/* IntStat Clear */
RegWrite( REG08_MainIntStat, BIT_MediaFIFO_IntStat );
/* IDE Interrupt Enable */
RegSet( REG08_MainIntEnb, BIT_EnMediaFIFO_IntStat );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -