📄 usb_core.c
字号:
pInfo->Ctrl_Info.Usb_wOffset =0;
DataStageIn1();
break;
case TEST_UNIT_READY: //just return csw,because flash always be ready
uart_printf("TEST_UNIT_READY call", 0);
send_bot_status(GOOD_STATUS,0);
break;
case READ_10:
uart_printf("READ_10 call", 0);
break;
case WRITE_10:
uart_printf("WRITE_10 call", 0);
break;
case VERIFY:
uart_printf("VERIFY call", 0);
send_bot_status(GOOD_STATUS,0);
break;
case REQUEST_SENSE:
uart_printf("REQUEST_SENSE call", 0);
break;
case MODE_SENSE://-4
uart_printf("MODE_SENSE call", 0);
/*
if(bulk_CBW.CBWCB[2] == SCSI_MSPGCD_TPP) //Page Code=Timer and Potect Page
{
WriteEpBulk(1, sizeof(B_Mode_Sense_TPP), B_Mode_Sense_TPP);
}
else if(bulk_CBW.CBWCB[2] == SCSI_MSPGCD_RETALL) //Page Code=All
{
WriteEpBulk(1, sizeof(B_Mode_Sense_ALL), B_Mode_Sense_ALL);
}
else
{
WriteEpBulk(1, sizeof(B_Mode_Sense_ZERO), B_Mode_Sense_ZERO);
}
*/
pInfo->Ctrl_Info.Usb_wLength=12;//pInfo->cbw.dCBWDataTransferLength_0+pInfo->cbw.dCBWDataTransferLength_1<<8+pInfo->cbw.dCBWDataTransferLength_2<<16+pInfo->cbw.dCBWDataTransferLength_3<<24;//sizeof(T_USBMS_INQUIRY_DATA);
pInfo->Ctrl_Info.pData = B_Mode_Sense_ALL;
pInfo->Ctrl_Info.Usb_wOffset =0;
DataStageIn1();
break;
case Read_Format_Capacities:
//-2
//send_bot_status(GOOD_STATUS,0);
pInfo->Ctrl_Info.Usb_wLength=20;//pInfo->cbw.dCBWDataTransferLength_0+pInfo->cbw.dCBWDataTransferLength_1<<8+pInfo->cbw.dCBWDataTransferLength_2<<16+pInfo->cbw.dCBWDataTransferLength_3<<24;//sizeof(T_USBMS_INQUIRY_DATA);
pInfo->Ctrl_Info.pData = B_Read_Format_capacities;
pInfo->Ctrl_Info.Usb_wOffset =0;
DataStageIn1();
uart_printf("Read_Format_Capacities call", 0);
break;
default:
uart_printf("Unknow scsi cmd",0);
break;
}
return Post_Process();
} /* Setup0_Process */
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
NAME: In0_Process
INPUT:
OUTPUT: none
DESCRIPTION:
Process the IN token on all default endpoint
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
BYTE In0_Process()
{
DEVICE_INFO *pInfo = pInformation;
BYTE ControlState = pInfo->ControlState;
if (ControlState == IN_DATA)
{
DataStageIn();
/* sb questo e' un baco della libreria st9 */
ControlState = pInfo->ControlState; /* may be changed outside the function */
/* sb */
}
else if (ControlState == LAST_IN_DATA || ControlState == WAIT_IN_ZERO) {
ControlState = WAIT_STATUS_OUT;
USB_StatusOut();
}
else if (ControlState == WAIT_OUT_ZERO || ControlState == WAIT_STATUS_IN) {
if (pInfo->USBbRequest == SET_ADDRESS &&
Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) ) {
/* Device address must be written */
/* after completion of Status Stage (ACK from Host) */
SetDeviceAddress(pInfo->USBwValue0);
}
(*pProperty->Process_Status_IN)();
ControlState = WAIT_SETUP;
}
else
ControlState = STALLED;
pInfo->ControlState = ControlState;
return Post0_Process();
} /* In0_Process */
BYTE In1_Process()
{
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
DEVICE_INFO *pInfo = pInformation;
BYTE ControlState = pInfo->ControlState;
uart_printf("In1_Process ControlState=%d",ControlState);
if (ControlState == IN_DATA||ControlState == WAIT_SETUP)
{
uart_printf("continue send ControlState=%d",ControlState);
DataStageIn1();
/* sb questo e' un baco della libreria st9 */
ControlState = pInfo->ControlState; /* may be changed outside the function */
/* sb */
}
else if (ControlState == LAST_IN_DATA || ControlState == WAIT_IN_ZERO)
{
uart_printf("send csw ControlState=%d",ControlState);
ControlState = WAIT_STATUS_OUT;
send_bot_status(GOOD_STATUS,0);
//DataStageIn1();
//Sendn0LengthData(pEPinfo->Endpn);
//USB_StatusOut();
//USB_StatusIn1();
}
else if(ControlState == WAIT_STATUS_OUT)
{
//send_bot_status(GOOD_STATUS,0);
ControlState == WAIT_OUT_ZERO;
//DataStageIn1();
uart_printf("Sendn0LengthData ControlState=%d",ControlState);
USB_StatusOut();
Sendn0LengthData(pEPinfo->Endpn);
}
else
{
//Sendn0LengthData(pEPinfo->Endpn);
USB_StatusOut();
}
pInfo->ControlState = ControlState;
return Post_Process();
} /* In0_Process */
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
NAME: Out0_Process
INPUT:
OUTPUT: none
DESCRIPTION:
Process the OUT token on all default endpoint
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
BYTE Out0_Process()
{
DEVICE_INFO *pInfo = pInformation;
BYTE ControlState = pInfo->ControlState;
if (ControlState == OUT_DATA) {
DataStageOut();
if (pInfo->ControlState == LAST_OUT_DATA) {
ControlState = WAIT_STATUS_IN;
USB_StatusIn();
}
else {
/* Expecting another OUT token with 0 length data */
SetEPRxCount(ENDP0, 0);
vSetEPRxStatus(EP_RX_VALID);
/* Also expecting an IN token to finish the transaction */
USB_StatusIn();
}
}
else if (ControlState == WAIT_STATUS_OUT || ControlState == IN_DATA) {
/* host aborts the xfer before finish */
/* Clear_Status_Out(EPindex);*/ /* Clear ST_OUT bit of this EP */
vSetEPTxStatus(EP_TX_NAK);
/* This is to ensure that when the xfer is aborted,
close down the transmitter, in case the next IN
token comes in before I config the transmitter */
(*pProperty->Process_Status_OUT)();
ControlState = WAIT_SETUP;
}
else if (ControlState == WAIT_OUT_ZERO) {
ControlState = WAIT_STATUS_IN;
USB_StatusIn();
}
else {
/* Unexpect state, STALL the endpoint */
ControlState = STALLED;
}
pInfo->ControlState = ControlState;
return Post0_Process();
} /* Out0_Process */
BYTE Out1_Process()
{
DEVICE_INFO *pInfo = pInformation;
BYTE ControlState = pInfo->ControlState;
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
//uart_printf("Out1_Process",0);
uart_printf("Out1_Process ControlState=%d",ControlState);
if (ControlState == OUT_DATA||ControlState == SETTING_UP) {
DataStageOut1();
if (pInfo->ControlState == LAST_OUT_DATA) {
ControlState = WAIT_STATUS_IN;
USB_StatusInn(pEPinfo->Endpn);
}
else {
//Expecting another OUT token with 0 length data //
SetEPRxCount(pEPinfo->Endpn, 0);
vSetEPRxStatus(EP_RX_VALID);
// Also expecting an IN token to finish the transaction /
USB_StatusInn(pEPinfo->Endpn);
}
}
else if (ControlState == WAIT_STATUS_OUT || ControlState == IN_DATA) {
// host aborts the xfer before finish
// Clear_Status_Out(EPindex); Clear ST_OUT bit of this EP
vSetEPTxStatus(EP_TX_NAK);
// This is to ensure that when the xfer is aborted,
// close down the transmitter, in case the next IN
// token comes in before I config the transmitter
(*pProperty->Process_Status_OUT)();
ControlState = WAIT_SETUP;
}
else if (ControlState == WAIT_OUT_ZERO) {
ControlState = WAIT_STATUS_IN;
USB_StatusInn(pEPinfo->Endpn);
}
else {
// Unexpect state, STALL the endpoint
ControlState = STALLED;
}
pInfo->ControlState = ControlState;
return Post_Process();
}
/*============================================================================*/
/*============================================================================*/
BYTE Post0_Process()
{
SetEPRxCount(ENDP0, STD_MAXPACKETSIZE);
if (pInformation->ControlState == STALLED) {
vSetEPRxStatus(EP_RX_STALL);
vSetEPTxStatus(EP_TX_STALL);
}
/*
* Since the SIE will receive SETUP even in NAK state
* There is no need to enable the receiver again
*/
return (pInformation->ControlState == PAUSE);
} /* Post0_Process */
/***************************************************************************
BYTE DescriptorBuffer[128];
BYTE *SetDeviceDescriptor(WORD Length)
{
if (Length == 0)
return (BYTE*)sizeof(DescriptorBuffer);
return DescriptorBuffer + pInfomation->Ctrl_Info.Usb_rOffset;
}
***************************************************************************/
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
BYTE Post_Process()
{
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
SetEPRxCount(pEPinfo->Endpn, STD_MAXPACKETSIZE);
//SetEPRxValid(pEPinfo->Endpn);
if (pInformation->ControlState == STALLED)
{
vSetEPRxStatus(EP_RX_STALL);
vSetEPTxStatus(EP_TX_STALL);
}
/*
* Since the SIE will receive SETUP even in NAK state
* There is no need to enable the receiver again
*/
return (pInformation->ControlState == PAUSE);
} /* Post0_Process */
BYTE* send_bot_status(T_COMMAND_BLOCK_STATUS command_block_status,
UINT32 data_residue)
{
DEVICE_INFO *pInfo = pInformation;
uart_printf("csw length = %d call",data_residue);
pInfo->senddata[0] = pInfo->csw.dCSWSignature_0 = 0x55;
pInfo->senddata[1] = pInfo->csw.dCSWSignature_1 = 0x53;
pInfo->senddata[2] = pInfo->csw.dCSWSignature_2 = 0x42;
pInfo->senddata[3] = pInfo->csw.dCSWSignature_3 = 0x53;
pInfo->senddata[4] = pInfo->csw.dCSWTag_0 = pInformation->cbw.dCBWTag_0;
pInfo->senddata[5] = pInfo->csw.dCSWTag_1 = pInformation->cbw.dCBWTag_1;
pInfo->senddata[6] = pInfo->csw.dCSWTag_2 = pInformation->cbw.dCBWTag_2;
pInfo->senddata[7] = pInfo->csw.dCSWTag_3= pInformation->cbw.dCBWTag_3;
pInfo->senddata[8] = pInfo->csw.dCSWDataResidue_0 =data_residue&0xff;
pInfo->senddata[9] = pInfo->csw.dCSWDataResidue_1 =(data_residue&0xff00)>>8;
pInfo->senddata[10] = pInfo->csw.dCSWDataResidue_2 = (data_residue&0xff0000)>>16;
pInfo->senddata[11] = pInfo->csw.dCSWDataResidue_3 = (data_residue&0xff000000)>>24;
pInfo->senddata[12] = pInfo->csw.bCSWStatus = command_block_status;
pInfo->Ctrl_Info.Usb_wLength=sizeof(T_USBMS_CSW);
pInfo->Ctrl_Info.pData = pInfo->senddata;
pInfo->Ctrl_Info.Usb_wOffset =0;
DataStageIn1();
return (BYTE*)(&pInfo->csw);
}
void SetDeviceAddress(BYTE Val)
{
int i;
DEVICE *pDevice = &Device_Table;
/* BYTE EP0 = pDevice->EP0; */
int nEP = pDevice->Total_Endpoint;
uart_printf("SetDeviceAddress call",0);
/* set address in every used endpoint */
for(i=0;i<nEP;i++)
{
_SetEPAddress((BYTE)i, (BYTE)i);
} /* for */
_SetDADDR(Val|DADDR_EF); /* set device address and enable function */
} /* SetDeviceAddress */
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
void NOP_Process(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -