⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_core.c

📁 arm(str710)usb功能的实现
💻 C
📖 第 1 页 / 共 4 页
字号:
		} while (offset < pDesc->Descriptor_Size);

		return 0;
	}
	uart_printf("Standard_GetStringDescriptor call",0);

	return pDesc->Descriptor + wOffset;
}/* Standard_GetStringDescriptor */

/*============================================================================*/
/*============================================================================*/
BYTE *Standard_GetDescriptorData(WORD Length, ONE_DESCRIPTOR *pDesc)
{
	int		len, wOffset;

	wOffset = pInformation->Ctrl_Info.Usb_wOffset;
	if (Length == 0) {
		len = pDesc->Descriptor_Size - wOffset;

		if (len <= 0)
			return 0;

		return (BYTE *)len;
	}
	uart_printf("Standard_GetDescriptorData call",0);

	return pDesc->Descriptor + wOffset;
} /* Standard_GetDescriptorData */

/*-----------------------------------------------------------------------------
ROUTINE NAME : DataStageOut
INPUT/OUTPUT : None
DESCRIPTION  : Data stage of a Control Write Transfer
-----------------------------------------------------------------------------*/

//SCSI-Read_Format_capacities命令的返回数据	
 unsigned char B_Read_Format_capacities[] = {0x00, 0x00, 0x00, 0x10,	        //capacity list header
									0x00, 0x00, 0x07, 0xf5,	0x01, 0x00, 0x02, 0x00,	//capacity descriptor
								    //Number of Blocks =2037,unformatted media,blocklength = 512Bytes
									0x00, 0x00, 0x07, 0xfd,	0x00, 0x00, 0x02, 0x00  //Formattable Capacity Descriptors
									};
//SCSI-Read_Capacity命令的返回数据
 unsigned char B_Read_Capacity[] = {
								0x00, 0x00, 0xfe, 0xa0,	   //Last  Logical Block Address for 32MB 
								0x00, 0x00, 0x02, 0x00	   //block length in bytes
								};
//SCSI-Mode_Sense命令的返回数据    	   		
 unsigned char B_Mode_Sense_ALL[] = {0x0b, 0x00,       //Mode Data Length
							0x00, 0x08, 0x00, 0x00,
							0x7d, 0, 0, 0, 0x02, 0x00
							};
//SCSI-Mode_Sense命令的返回数据			
 unsigned char B_Mode_Sense_TPP[] = {0xf0, 0x00,       //Mode Data Length
							05, 00, 00, 00, 00, 0x0b, 00, 00, 00, 00, 0x24, 00, 00, 00, 00, 00
							};
//SCSI-Mode_Sense命令的返回数据			
 unsigned char B_Mode_Sense_ZERO[] = {0x00, 0x06,      //Mode Data Length
							0x00,	                       //Medium Type Code
							0,                             //write enabled
							0, 0, 0, 0                     //reserved	
                            };

void DataStageOut()
{
	ENDPOINT_INFO	*pEPinfo = &pInformation->Ctrl_Info;
	WORD	save_rLength;

	save_rLength = pEPinfo->Usb_rLength;

	if (pEPinfo->CopyData && save_rLength) {
		BYTE *Buffer;
		WORD Length;
		BYTE *Source;

		Length = pEPinfo->PacketSize;
		if (Length > save_rLength)
			Length = save_rLength;

		Buffer = (*pEPinfo->CopyData)(Length);

		pEPinfo->Usb_rLength -= Length;
		pEPinfo->Usb_rOffset += Length;

/*sb		Source = pProperty->RxEP_buffer; */
		Source = PMAAddr + (BYTE *)(_GetEPRxAddr(ENDP0)*2); /* *2 for 32 bits addr */
		while (Length) {
			*Buffer++ = *Source++;
			Length--;
			if(Length == 0) break; /* odd counter */
			*Buffer++ = *Source++;
			Length--;
			Source++;Source++; /* skip 2 bytes for 32 bit addressing */
		}
	}

	if (pEPinfo->Usb_rLength == 0) {
		/* this OUT Transaction is the last one */
		pInformation->ControlState =
			(save_rLength == pEPinfo->PacketSize) ?
					/*	If the previous read length is same as MaxPacketSize
						This is the multiple MaxPacketSize package
						Wait for another OUT token and send 0 length data
					*/
				WAIT_OUT_ZERO :
					/*	If the previous read length is NOT same as MaxPacketSize
						Wait for the IN token to finish the status stage
					*/
				LAST_OUT_DATA;
	}
} /* DataStageOut */
void DataStageOut1()
{
	ENDPOINT_INFO	*pEPinfo = &pInformation->Ctrl_Info;
	WORD	save_rLength;

	save_rLength = pEPinfo->Usb_rLength;
	save_rLength = _GetEPRxCount(ENDP1);
	uart_printf("DataStageOut1 save_rLength cal=%d l",save_rLength);

	if (pEPinfo->CopyData && save_rLength) {
		BYTE *Buffer;
		WORD Length;
		BYTE *Source;

		Length = pEPinfo->PacketSize;
		if (Length > save_rLength)
			Length = save_rLength;

		Buffer = (*pEPinfo->CopyData)(Length);

		pEPinfo->Usb_rLength -= Length;
		pEPinfo->Usb_rOffset += Length;

/*sb		Source = pProperty->RxEP_buffer; */
		Source = PMAAddr + (BYTE *)(_GetEPRxAddr(ENDP1)*2); /* *2 for 32 bits addr */
		while (Length) {
			*Buffer++ = *Source++;
			Length--;
			if(Length == 0) break; /* odd counter */
			*Buffer++ = *Source++;
			Length--;
			Source++;Source++; /* skip 2 bytes for 32 bit addressing */
		}
	}

	if (pEPinfo->Usb_rLength == 0) {
		/* this OUT Transaction is the last one */
		pInformation->ControlState =
			(save_rLength == pEPinfo->PacketSize) ?
					/*	If the previous read length is same as MaxPacketSize
						This is the multiple MaxPacketSize package
						Wait for another OUT token and send 0 length data
					*/
				WAIT_OUT_ZERO :
					/*	If the previous read length is NOT same as MaxPacketSize
						Wait for the IN token to finish the status stage
					*/
				LAST_OUT_DATA;
	}
} /* DataStageOut */


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
	NAME:	DataStageIn
	INPUT:	none
	OUTPUT:
	DESCRIPTION:
		Data stage of a Control Read Transfer
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void DataStageIn(void)
{
	ENDPOINT_INFO	*pEPinfo = &pInformation->Ctrl_Info;
	WORD	save_wLength = pEPinfo->Usb_wLength;
	BYTE	ControlState;

	BYTE	*DataBuffer;
	WORD	Length;
	int i;
    DWORD *pTxBuff;
    WORD wTra;
 	union {
		BYTE *bTra;
    	WORD *wTra;
	}pBuf;
	//uart_printf("MaxPacketSize=l %d",pEPinfo->PacketSize);
	
	if (save_wLength == 0) {
		/* if the number of byte to be sent is				*/
		/* multiple of MaxPacketSize: send a 0 length data packet	*/
		ControlState = WAIT_IN_ZERO;
		Send0LengthData();
		goto Expect_Status_Out;
	}

	Length = pEPinfo->PacketSize;
	ControlState = (save_wLength < Length) ? LAST_IN_DATA : IN_DATA;

	/* Same as UsbWrite */
	if (Length > save_wLength)
		Length = save_wLength;

	DataBuffer = (*pEPinfo->CopyData)(Length);

    // Usb_Send(0,DataBuffer,Length);
#if 1    // transfer data from buffer to PMA //
    pTxBuff = (DWORD *)(PMAAddr + (BYTE *)(_GetEPTxAddr(ENDP0)*2));
    pBuf.wTra = &wTra;
    for(i=0;i < Length;)
    {
    	*(pBuf.bTra  ) = *DataBuffer++;
    	i++;
    	*(pBuf.bTra+1) = *DataBuffer++;
    	i++;
    	*pTxBuff = wTra;
    	pTxBuff++;
    }

	_SetEPTxCount(ENDP0, Length);

      pEPinfo->Usb_wLength -= Length;
	pEPinfo->Usb_wOffset += Length;
	
	vSetEPTxStatus(EP_TX_VALID);
#endif
Expect_Status_Out:
	USB_StatusOut();	/* Expect the host to abort the data IN stage */
	pInformation->ControlState = ControlState;
}/* DataStageIn */
const WORD data[30]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
    DWORD wTra;
    int i,j;

void DataStageIn1(void)
{
	ENDPOINT_INFO	*pEPinfo = &pInformation->Ctrl_Info;
	WORD	save_wLength = pEPinfo->Usb_wLength;
	BYTE	ControlState;

	BYTE	*DataBuffer;
	WORD	Length;
       volatile  DWORD *pTxBuff;
 	union {
		BYTE *bTra;
    	WORD *wTra;
	}pBuf;
	//uart_printf("MaxPacketSize=l %d",pEPinfo->PacketSize);
	uart_printf("DataStageIn1 save_wLength cal=%d l",save_wLength);

	if (save_wLength == 0) {
		/* if the number of byte to be sent is				*/
		/* multiple of MaxPacketSize: send a 0 length data packet	*/
		ControlState = WAIT_IN_ZERO;
		Sendn0LengthData(pEPinfo->Endpn);
		goto Expect_Status_Out;
	}

	Length = pEPinfo->PacketSize;
	ControlState = (save_wLength < Length) ? LAST_IN_DATA : IN_DATA;
	uart_printf("DataStageIn1 ControlState=%d",ControlState);
	/* Same as UsbWrite */
	if (Length > save_wLength)
		Length = save_wLength;
	pEPinfo->pData =pInformation->senddata;
	DataBuffer =(BYTE*) pEPinfo->pData+pEPinfo->Usb_wOffset;//(*pEPinfo->CopyData)(Length);
    /* transfer data from buffer to PMA */
    pTxBuff = (DWORD *)(PMAAddr + (BYTE *)(_GetEPTxAddr(ENDP1)*2)+0);
    pBuf.wTra =(WORD*) &wTra;

    #if 1
    for(i=0;i < Length;)
    {
   	*(pBuf.bTra  ) = *(DataBuffer++);
	 //wTra = data[i];
    	i++;
    	*(pBuf.bTra+1) =*(DataBuffer++);
    //	wTra |= data[i]<<8;
    	i++;
   //  	uart_printf("wTra=%d",wTra);
    	*pTxBuff = wTra;  
    	pTxBuff++;
    }
    #else
      	wTra = pEPinfo->pData[0];
 	wTra |= pEPinfo->pData[1]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[2];
 	wTra |= pEPinfo->pData[3]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
    	wTra = pEPinfo->pData[4];
 	wTra |= pEPinfo->pData[5]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[6];
 	wTra |= pEPinfo->pData[7]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[8];
 	wTra |= pEPinfo->pData[9]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
    	wTra = pEPinfo->pData[10];
 	wTra |= pEPinfo->pData[11]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[12];
 	wTra |= pEPinfo->pData[13]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[14];
 	wTra |= pEPinfo->pData[15]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
   	
    wTra = pEPinfo->pData[16];
 	wTra |= pEPinfo->pData[17]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[18];
 	wTra |= pEPinfo->pData[29]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[20];
 	wTra |= pEPinfo->pData[21]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
    	wTra = pEPinfo->pData[22];
 	wTra |= pEPinfo->pData[23]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;    	
  /*      wTra = pEPinfo->pData[24];
 	wTra |= pEPinfo->pData[25]<<8;
    	*pTxBuff = wTra;
      	pTxBuff++;
     	wTra = pEPinfo->pData[26];
 	wTra |= pEPinfo->pData[27]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
    	wTra = pEPinfo->pData[28];
 	wTra |= pEPinfo->pData[29]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[30];
 	wTra |= pEPinfo->pData[31]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
      	wTra = pEPinfo->pData[32];
 	wTra |= pEPinfo->pData[33]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
    	wTra = pEPinfo->pData[34];
 	wTra |= pEPinfo->pData[35]<<8;
    	*pTxBuff = wTra;
    	pTxBuff++;
    	*/
#endif

    	
	_SetEPTxCount(ENDP1, Length);
      SetEPTxValid(ENDP1);
	pEPinfo->Usb_wLength -= Length;
	pEPinfo->Usb_wOffset += Length;
	vSetEPTxStatus(EP_TX_VALID);

Expect_Status_Out:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -