Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 187 → Rev 188

/tags/V0.17e/usblibrary/src/usb_core.c
0,0 → 1,831
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : usb_core.c
* Author : MCD Application Team
* Date First Issued : 10/27/2003 : V1.0
* Description : Standard protocol processing (USB v2.0)
********************************************************************************
* History:
* 09/18/2006 : V3.0
* 09/01/2006 : V2.0
* 10/27/2003 : V1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "usb_mem.h"
#include "usb_conf.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define ValBit(VAR,Place) (VAR & (1<<Place))
#define SetBit(VAR,Place) ( VAR |= (1<<Place) )
#define ClrBit(VAR,Place) ( VAR &= ((1<<Place)^255) )
 
#define Send0LengthData() { \
_SetEPTxCount(ENDP0, 0); \
vSetEPTxStatus(EP_TX_VALID); \
}
 
#define vSetEPRxStatus(st) (SaveRState = st)
#define vSetEPTxStatus(st) (SaveTState = st)
 
#define USB_StatusIn() Send0LengthData()
#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
 
#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
#define StatusInfo1 StatusInfo.bw.bb0
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u16_u8 StatusInfo;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/*******************************************************************************
* Function Name : Standard_GetConfiguration
* Description : Return the current configuration variable address
* Input : Length - How many bytes are needed.
* Output : If "Length" is 0, return the length of configuration value
If "Length" is not 0, return the data buffer address.
* Return : Return 1 , if the request is invalid when "Length" is 0
Return "Buffer" if the "Length" is not 0
*******************************************************************************/
u8 *Standard_GetConfiguration(u16 Length)
{
if (Length == 0){
pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_Configuration);
return 0;
}
pUser_Standard_Requests->User_GetConfiguration();
return (u8 *)&pInformation->Current_Configuration;
}
/*******************************************************************************
* Function Name : Standard_SetConfiguration
* Description : This routine is called to set the configuration value
Then each class should configure device themself
* Input :
* Output :
* Return : Return USB_SUCCESS, if the request is performed
Return USB_UNSUPPORT, if the request is invalid
*******************************************************************************/
RESULT Standard_SetConfiguration(void)
{
 
if (pInformation->USBwValue0 <= Device_Table.Total_Configuration && pInformation->USBwValue1==0
&& pInformation->USBwIndex==0) /*call Back usb spec 2.0*/
{
pInformation->Current_Configuration = pInformation->USBwValue0;
pUser_Standard_Requests->User_SetConfiguration();
return USB_SUCCESS;
}
else
return USB_UNSUPPORT;
}
/*******************************************************************************
* Function Name : Standard_GetInterface
* Description : Return the Alternate Setting of the current interface
* Input : Length - How many bytes are needed
* Output : If "Length" is 0, return the length of interface value
If "Length" is not 0, return the data buffer address
* Return : Return 0, if the request is invalid when "Length" is 0
Return "Buffer" if the "Length" is not 0
*******************************************************************************/
u8 *Standard_GetInterface(u16 Length)
{
if (Length == 0){
pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_AlternateSetting);
return 0;
}
pUser_Standard_Requests->User_GetInterface();
return (u8 *)&pInformation->Current_AlternateSetting;
}
/*******************************************************************************
* Function Name : Standard_SetInterface
* Description : This routine is called to set the interface
Then each class should configure the interface them self
* Input :
* Output :
* Return : Return USB_SUCCESS, if the request is performed
Return USB_UNSUPPORT, if the request is invalid
*******************************************************************************/
RESULT Standard_SetInterface(void)
{
RESULT Re;
/*Test if the specified Interface and Alternate Setting are supported by the application Firmware*/
Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,pInformation->USBwValue0);
 
if(pInformation->Current_Configuration!=0 )
{
if (Re!= USB_SUCCESS || pInformation->USBwIndex1!=0 || pInformation->USBwValue1!=0)
return USB_UNSUPPORT;
else if ( Re == USB_SUCCESS)
{
pUser_Standard_Requests->User_SetInterface();
pInformation->Current_Interface = pInformation->USBwIndex0;
pInformation->Current_AlternateSetting = pInformation->USBwValue0;
return USB_SUCCESS;
}
}
 
return USB_UNSUPPORT;
}
/*******************************************************************************
* Function Name : Standard_GetStatus
* Description : Copy the device request data to "StatusInfo buffer"
* Input : Length - How many bytes are needed
* Output : If "Length" is 0, return the length of status data
If "Length" is not 0, return number of bytes have been copied
* Return : Return 0, if the request is at end of data block,
or is invalid when "Length" is 0
*******************************************************************************/
u8 *Standard_GetStatus(u16 Length)
{
if (Length == 0){
pInformation->Ctrl_Info.Usb_wLength =2;
return 0;
}
 
StatusInfo.w = 0;
/* Reset Status Information */
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/*Get Device Status */
u8 Feature = pInformation->Current_Feature;
 
if (ValBit(Feature, 5))
SetBit(StatusInfo0, 1); /* Remote Wakeup enabled */
 
if (ValBit(Feature, 6))
SetBit(StatusInfo0, 0); /* Self-powered */
else
ClrBit(StatusInfo0, 0); /* Bus-powered */
}
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))/*Interface Status*/
return (u8 *)&StatusInfo;
 
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {/*Get EndPoint Status*/
u8 Related_Endpoint;
u8 wIndex0 = pInformation->USBwIndex0;
 
Related_Endpoint = (wIndex0 & 0x0f);
if (ValBit(wIndex0, 7)) {
/* IN endpoint */
if (_GetTxStallStatus( Related_Endpoint ))
SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
}
else {
/* OUT endpoint */
if (_GetRxStallStatus( Related_Endpoint ))
SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
}
}
else
return NULL;
pUser_Standard_Requests->User_GetStatus();
return (u8 *)&StatusInfo;
}
/*******************************************************************************
* Function Name : Standard_ClearFeature
* Description : Clear or disable a specific feature
* Input :
* Output :
* Return :
*******************************************************************************/
RESULT Standard_ClearFeature(void)
{
u32 Type_Rec = Type_Recipient;
u32 Status;
 
if ( Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT) ) {/*Device Clear Feature*/
ClrBit(pInformation->Current_Feature, 5);
return USB_SUCCESS;
}
else if ( Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT) ) {/*EndPoint Clear Feature*/
DEVICE* pDev;
u32 Related_Endpoint;
u32 wIndex0;
u32 rEP;
 
if (pInformation->USBwValue != ENDPOINT_STALL || pInformation->USBwIndex1!=0)
return USB_UNSUPPORT;
 
pDev = &Device_Table;
wIndex0 = pInformation->USBwIndex0;
rEP = wIndex0 & ~0x80;
Related_Endpoint = ENDP0 + rEP;
 
if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/*Get Status of endpoint & stall the request if
the related_ENdpoint is Disabled*/
else Status =_GetEPRxStatus(Related_Endpoint);
 
if (rEP >= pDev->Total_Endpoint || Status==0 || pInformation->Current_Configuration==0)
return USB_UNSUPPORT;
 
if (wIndex0 & 0x80) { /* IN endpoint */
if (_GetTxStallStatus(Related_Endpoint )){
ClearDTOG_TX(Related_Endpoint);
SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
}
}
else { /* OUT endpoint */
if (_GetRxStallStatus(Related_Endpoint)){
if (Related_Endpoint == ENDP0) {
/* After clear the STALL, enable the default endpoint receiver */
SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
_SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
}
else
{
ClearDTOG_RX(Related_Endpoint);
_SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
}
}
}
pUser_Standard_Requests->User_ClearFeature();
return USB_SUCCESS;
}
 
return USB_UNSUPPORT;
}
/*******************************************************************************
* Function Name : Standard_SetEndPointFeature
* Description : Set or enable a specific feature of EndPoint
* Input :
* Output :
* Return :
*******************************************************************************/
RESULT Standard_SetEndPointFeature(void)
{
u32 wIndex0;
u32 Related_Endpoint;
u32 rEP;
u32 Status;
 
wIndex0 = pInformation->USBwIndex0;
rEP = wIndex0 & ~0x80;
Related_Endpoint = ENDP0 + rEP;
 
if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/* get Status of endpoint & stall the request if
the related_ENdpoint is Disabled*/
else Status =_GetEPRxStatus(Related_Endpoint);
 
 
 
if (Related_Endpoint >= Device_Table.Total_Endpoint || pInformation->USBwValue !=0 || Status==0 ||
pInformation->Current_Configuration==0 /*&& Related_Endpoint!=ENDP0)*/)
return USB_UNSUPPORT;
else {
 
if (wIndex0 & 0x80) { /* IN endpoint */
_SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
}
else { /* OUT endpoint */
_SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
}
}
pUser_Standard_Requests->User_SetEndPointFeature();
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : Standard_SetDeviceFeature
* Description : Set or enable a specific feature of Device
* Input :
* Output :
* Return :
*******************************************************************************/
RESULT Standard_SetDeviceFeature(void)
{
SetBit(pInformation->Current_Feature, 5);
pUser_Standard_Requests->User_SetDeviceFeature();
return USB_SUCCESS;
 
}
 
/*******************************************************************************
* Function Name : Standard_GetDescriptorData
* Description : Standard_GetDescriptorData is used for descriptors transfer
* : This routine is used for the descriptors resident in Flash or RAM
pDesc can be in either Flash or RAM
The purpose of this routine is to have a versatile way to response
descriptors request. It allows user to generate certain descriptors
with software or read descriptors from external storage part by part.
* Input : Length - Length of the data in this transfer
pDesc - A pointer points to descriptor struct.
The structure gives the initial address of the
descriptor and its original size
* Output : Address of a part of the descriptor pointed by the Usb_wOffset
The buffer pointed by this address contains at least Length bytes
* Return :
*******************************************************************************/
 
u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
{
u32 wOffset;
 
wOffset = pInformation->Ctrl_Info.Usb_wOffset;
if (Length == 0) {
pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
return 0;
}
 
return pDesc->Descriptor + wOffset;
}
/*******************************************************************************
* Function Name : DataStageOut
* Description : Data stage of a Control Write Transfer
* Input :
* Output :
* Return :
*******************************************************************************/
void DataStageOut(void)
{
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
u32 save_rLength;
 
save_rLength = pEPinfo->Usb_rLength;
 
if (pEPinfo->CopyData && save_rLength) {
u8 *Buffer;
u32 Length;
 
Length = pEPinfo->PacketSize;
if (Length > save_rLength)
Length = save_rLength;
 
Buffer = (*pEPinfo->CopyData)(Length);
pEPinfo->Usb_rLength -= Length;
pEPinfo->Usb_rOffset += Length;
 
PMAToUserBufferCopy(Buffer,GetEPRxAddr(ENDP0), Length);
}
 
if(pEPinfo->Usb_rLength !=0){
vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */
SetEPTxCount(ENDP0, 0);
vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */
}
/* Set the next State*/
if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
pInformation->ControlState = OUT_DATA;
else
{
if (pEPinfo->Usb_rLength >0)
pInformation->ControlState = LAST_OUT_DATA;
else if (pEPinfo->Usb_rLength == 0)
{
pInformation->ControlState = WAIT_STATUS_IN;
USB_StatusIn();
}
}
 
}
/*******************************************************************************
* Function Name : DataStageIn
* Description : Data stage of a Control Read Transfer
* Input :
* Output :
* Return :
*******************************************************************************/
void DataStageIn(void)
{
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
u32 save_wLength = pEPinfo->Usb_wLength;
u32 ControlState = pInformation->ControlState;
 
u8 *DataBuffer;
u32 Length;
 
if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
{ /* no more data to send so STALL the TX Status*/
ControlState = WAIT_STATUS_OUT;
vSetEPTxStatus(EP_TX_STALL);
goto Expect_Status_Out;
}
 
Length = pEPinfo->PacketSize;
ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
 
if (Length > save_wLength)
Length = save_wLength;
 
DataBuffer = (*pEPinfo->CopyData)(Length);
UserToPMABufferCopy(DataBuffer,GetEPTxAddr(ENDP0),Length);
 
SetEPTxCount(ENDP0, Length);
 
pEPinfo->Usb_wLength -= Length;
pEPinfo->Usb_wOffset += Length;
vSetEPTxStatus(EP_TX_VALID);
 
USB_StatusOut();/* Expect the host to abort the data IN stage */
 
Expect_Status_Out:
pInformation->ControlState = ControlState;
}
/*******************************************************************************
* Function Name : NoData_Setup0
* Description : Proceed the processing of setup request without data stage
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NoData_Setup0(void)
{
RESULT Result = USB_UNSUPPORT;
u32 RequestNo = pInformation->USBbRequest;
u32 ControlState;
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/* Device Request*/
/* SET_CONFIGURATION*/
if (RequestNo == SET_CONFIGURATION)
Result = Standard_SetConfiguration();
/*SET ADDRESS*/
else if (RequestNo == SET_ADDRESS){
if(pInformation->USBwValue0 > 127 || pInformation->USBwValue1!=0
||pInformation->USBwIndex!=0 || pInformation->Current_Configuration!=0) /* Device Address should be 127 or less*/
/*call Beck spec USB 2.0*/
{
ControlState = STALLED;
goto exit_NoData_Setup0;
}
else Result = USB_SUCCESS;
}
/*SET FEATURE for Device*/
else if (RequestNo == SET_FEATURE){
if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
Result = Standard_SetDeviceFeature();
else
Result = USB_UNSUPPORT;
}
/*Clear FEATURE for Device */
else if (RequestNo == CLEAR_FEATURE){
if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
Result = Standard_ClearFeature();
else
Result = USB_UNSUPPORT;
}
 
}
 
/* Interface Request*/
 
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) {
/*SET INTERFACE*/
if (RequestNo == SET_INTERFACE)
Result = Standard_SetInterface();
}
 
/* EndPoint Request*/
 
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {
/*CLEAR FEATURE for EndPoint*/
if (RequestNo == CLEAR_FEATURE)
Result = Standard_ClearFeature();
/* SET FEATURE for EndPoint*/
else if (RequestNo == SET_FEATURE){
Result = Standard_SetEndPointFeature();
}
}
else
Result = USB_UNSUPPORT;
 
 
if (Result != USB_SUCCESS) {
Result = (*pProperty->Class_NoData_Setup)(RequestNo);
if (Result == USB_NOT_READY) {
ControlState = PAUSE;
goto exit_NoData_Setup0;
}
}
 
if (Result != USB_SUCCESS) {
ControlState = STALLED;
goto exit_NoData_Setup0;
}
 
ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */
 
USB_StatusIn();
 
exit_NoData_Setup0:
pInformation->ControlState = ControlState;
return;
}
/*******************************************************************************
* Function Name : Data_Setup0
* Description : Proceed the processing of setup request with data stage
* Input :
* Output :
* Return :
*******************************************************************************/
void Data_Setup0(void)
{
u8 *(*CopyRoutine)(u16);
RESULT Result;
u32 Request_No = pInformation->USBbRequest;
u32 Related_Endpoint,Reserved;
u32 wOffset,Status;
 
 
 
CopyRoutine = NULL;
wOffset = 0;
 
if (Request_No == GET_DESCRIPTOR) {
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {
u8 wValue1 = pInformation->USBwValue1;
if (wValue1 == DEVICE_DESCRIPTOR)
CopyRoutine = pProperty->GetDeviceDescriptor;
else if (wValue1 == CONFIG_DESCRIPTOR)
CopyRoutine = pProperty->GetConfigDescriptor;
else if (wValue1 == STRING_DESCRIPTOR) {
CopyRoutine = pProperty->GetStringDescriptor;
} /* End of GET_DESCRIPTOR */
}
}
 
/*GET STATUS*/
else if (Request_No == GET_STATUS && pInformation->USBwValue==0 && pInformation->USBwLength == 0x0002 && pInformation->USBwIndex1==0) {
/* GET STATUS for Device*/
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) && pInformation->USBwIndex==0) {
CopyRoutine = Standard_GetStatus;
}
/* GET STATUS for Interface*/
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)){
if ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,0)==USB_SUCCESS && pInformation->Current_Configuration!=0)
CopyRoutine = Standard_GetStatus;
}
/* GET STATUS for EndPoint*/
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)){
 
Related_Endpoint = (pInformation->USBwIndex0 & 0x0f);
Reserved= pInformation->USBwIndex0 & 0x70;
 
if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/*Get Status of endpoint & stall the request if
the related_ENdpoint is Disabled*/
else Status =_GetEPRxStatus(Related_Endpoint);
 
if(Related_Endpoint < Device_Table.Total_Endpoint && Reserved==0 && Status != 0)
CopyRoutine = Standard_GetStatus;
}
 
 
}
/*GET CONFIGURATION*/
else if (Request_No == GET_CONFIGURATION) {
if ( Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) )
CopyRoutine = Standard_GetConfiguration;
}
/*GET INTERFACE*/
else if (Request_No == GET_INTERFACE) {
if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT) && pInformation->Current_Configuration!=0
&& pInformation->USBwValue==0 && pInformation->USBwIndex1==0 && pInformation->USBwLength == 0x0001
&& (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,0)==USB_SUCCESS)
CopyRoutine = Standard_GetInterface;
}
 
 
if (CopyRoutine) {
pInformation->Ctrl_Info.Usb_wOffset = wOffset;
pInformation->Ctrl_Info.CopyData = CopyRoutine;
/* sb in the original the cast to word was directly */
/* now the cast is made step by step */
(*CopyRoutine)(0);
Result = USB_SUCCESS;
}
else {
Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest);
if (Result == USB_NOT_READY) {
pInformation->ControlState = PAUSE;
return;
}
}
 
if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF) { /* Data is not ready, wait it */
pInformation->ControlState = PAUSE;
return;
}
if (Result == USB_UNSUPPORT || pInformation->Ctrl_Info.Usb_wLength == 0) {
/* Unsupported request */
pInformation->ControlState = STALLED;
return;
}
 
 
if (ValBit(pInformation->USBbmRequestType, 7)) {
/* Device ==> Host */
u32 wLength = pInformation->USBwLength;
 
/* Restrict the data length to be the one host asks */
if (pInformation->Ctrl_Info.Usb_wLength > wLength)
pInformation->Ctrl_Info.Usb_wLength = wLength;
 
pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
DataStageIn();
}
else {
pInformation->ControlState = OUT_DATA;
vSetEPRxStatus(EP_RX_VALID);/* enable for next data reception */
}
 
return;
} /* Data_Setup0 */
/*******************************************************************************
* Function Name : Setup0_Process
* Description : Get the device request data and dispatch to individual process
* Input :
* Output :
* Return :
*******************************************************************************/
u8 Setup0_Process(void)
{
#ifdef STR7xx /* STR7xx family*/
union {
u8* b;
u16* w;
} pBuf;
pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0)*2); /* *2 for 32 bits addr */
 
if (pInformation->ControlState != PAUSE) {
pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
pInformation->USBbRequest = *pBuf.b++; /* bRequest */
pBuf.w++; /* word not accessed because of 32 bits addressing */
pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
pBuf.w++; /* word not accessed because of 32 bits addressing */
pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
pBuf.w++; /* word not accessed because of 32 bits addressing */
pInformation->USBwLength = *pBuf.w; /* wLength */
}
#endif/* End of STR7xx family*/
#ifdef STR91x /* STR91x family*/
u16* pBuf;
 
pBuf= (u16 *)(GetEPRxAddr(ENDP0)+PMAAddr);
if (pInformation->ControlState != PAUSE)
{
pInformation->USBbmRequestType = (*pBuf)&0xFF; /* bmRequestType */
pInformation->USBbRequest = ((*pBuf)&0xFF00)>>8; /* bRequest */
pInformation->USBwValue = ByteSwap(*(pBuf+1)); /* wValue */
pInformation->USBwIndex = ByteSwap(*(pBuf+2)); /* wIndex */
pInformation->USBwLength = *(pBuf+3); /* wLength */
}
#endif /* End of STR91x family*/
pInformation->ControlState = SETTING_UP;
if (pInformation->USBwLength == 0)
{
/* Setup with no data stage */
NoData_Setup0();
}
else
{
/* Setup with data stage */
Data_Setup0();
}
return Post0_Process();
}
/*******************************************************************************
* Function Name : In0_Process
* Description : Process the IN token on all default endpoint
* Input :
* Output :
* Return :
*******************************************************************************/
u8 In0_Process(void)
{
u32 ControlState = pInformation->ControlState;
if (ControlState == IN_DATA || ControlState == LAST_IN_DATA)
{
DataStageIn();
ControlState = pInformation->ControlState; /* may be changed outside the function */
}
else if (ControlState == WAIT_STATUS_IN) {
if (pInformation->USBbRequest == SET_ADDRESS &&
Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) )
{
SetDeviceAddress(pInformation->USBwValue0);
pUser_Standard_Requests->User_SetDeviceAddress();
}
(*pProperty->Process_Status_IN)();
ControlState = STALLED;
}
else
ControlState = STALLED;
 
pInformation->ControlState = ControlState;
 
return Post0_Process();
}
/*******************************************************************************
* Function Name : Out0_Process
* Description : Process the OUT token on all default endpoint
* Input :
* Output :
* Return :
*******************************************************************************/
u8 Out0_Process(void)
{
u32 ControlState = pInformation->ControlState;
if(ControlState == OUT_DATA || ControlState == LAST_OUT_DATA)
DataStageOut();
 
else if (ControlState == WAIT_STATUS_OUT) {
(*pProperty->Process_Status_OUT)();
ControlState = STALLED;
}
 
else if (ControlState == IN_DATA || ControlState == LAST_IN_DATA) {
/* host aborts the transfer before finish */
ControlState = STALLED;
}
 
 
/* Unexpect state, STALL the endpoint */
else {
ControlState = STALLED;
}
 
pInformation->ControlState = ControlState;
 
return Post0_Process();
} /* Out0_Process */
 
/*******************************************************************************
* Function Name : Post0_Process
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
u8 Post0_Process(void)
{
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
 
if (pInformation->ControlState == STALLED) {
vSetEPRxStatus(EP_RX_STALL);
vSetEPTxStatus(EP_TX_STALL);
}
 
return (pInformation->ControlState == PAUSE);
}
/*******************************************************************************
* Function Name : SetDeviceAddress
* Description : set the device and all the used Endpoints addresses
* Input : Val : device adress
* Output :
* Return :
*******************************************************************************/
void SetDeviceAddress(u8 Val)
{
u32 i;
u32 nEP = Device_Table.Total_Endpoint;
 
/* set address in every used endpoint */
for(i=0;i<nEP;i++)
{
_SetEPAddress((u8)i, (u8)i);
} /* for */
_SetDADDR(Val|DADDR_EF); /* set device address and enable function */
 
}
/*******************************************************************************
* Function Name : NOP_Process
* Description : no operation function.
* Input :
* Output :
* Return :
*******************************************************************************/
void NOP_Process(void)
{
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
 
 
/tags/V0.17e/usblibrary/src/usb_init.c
0,0 → 1,66
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : usb_init.c
* Author : MCD Application Team
* Date First Issued : 10/27/2003 : V1.0
* Description : Initialization routines & global variables
********************************************************************************
* History:
* 09/18/2006 : V3.0
* 09/01/2006 : V2.0
* 10/27/2003 : V1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
 
/* The number of current endpoint, it will be used to specify an endpoint */
u8 EPindex;
/* The number of current device, it is an index to the Device_Table */
/* u8 Device_no; */
/* Points to the DEVICE_INFO structure of current device */
/* The purpose of this register is to speed up the execution */
DEVICE_INFO *pInformation;
/* Points to the DEVICE_PROP structure of current device */
/* The purpose of this register is to speed up the execution */
DEVICE_PROP *pProperty;
/* Temporary save the state of Rx & Tx status. */
/* Whenever the Rx or Tx state is changed, its value is saved */
/* in this variable first and will be set to the EPRB or EPRA */
/* at the end of interrupt process */
u16 SaveState ;
u16 wInterrupt_Mask;
DEVICE_INFO Device_Info;
 
USER_STANDARD_REQUESTS *pUser_Standard_Requests;
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/*******************************************************************************
* Function Name : USB_Init
* Description : USB system initialization
* Input :
* Output :
* Return :
*******************************************************************************/
void USB_Init(void)
{
pInformation = &Device_Info;
pInformation->ControlState = 2;
pProperty = &Device_Property;
pUser_Standard_Requests = &User_Standard_Requests;
/* Initialize devices one by one */
pProperty->Init();
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
/tags/V0.17e/usblibrary/src/usb_int.c
0,0 → 1,189
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : usb_int.c
* Author : MCD Application Team
* Date First Issued : 10/27/2003 : V1.0
* Description : Endpoint CTR (Low and High) interrupt's service routines
********************************************************************************
* History:
* 09/18/2006 : V3.0
* 09/01/2006 : V2.0
* 10/27/2003 : V1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u16 SaveRState;
u16 SaveTState;
/* Extern variables ----------------------------------------------------------*/
extern void (*pEpInt_IN[15])(void); /* Handles IN interrupts */
extern void (*pEpInt_OUT[15])(void); /* Handles OUT interrupts */
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : CTR_LP
* Description : Low Endpoint Correct Transfer interrupt's service routine
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CTR_LP(void)
{
u32 wEPVal;
/* stay in loop while pending ints */
while(((wIstr = _GetISTR()) & ISTR_CTR)!= 0)
{
_SetISTR((u16)CLR_CTR); /* clear CTR flag */
/* extract highest priority endpoint number */
EPindex = (u8)(wIstr & ISTR_EP_ID);
if(EPindex == 0)
{
/* Decode and service control endpoint interrupt */
/* calling related service routine */
/* (Setup0_Process, In0_Process, Out0_Process) */
 
/* save RX & TX status */
/* and set both to NAK */
SaveRState = _GetEPRxStatus(ENDP0);
SaveTState = _GetEPTxStatus(ENDP0);
_SetEPRxStatus(ENDP0, EP_RX_NAK);
_SetEPTxStatus(ENDP0, EP_TX_NAK);
 
 
/* DIR bit = origin of the interrupt */
 
if((wIstr & ISTR_DIR) == 0)
{/* DIR = 0 */
/* DIR = 0 => IN int */
/* DIR = 0 implies that (EP_CTR_TX = 1) always */
_ClearEP_CTR_TX(ENDP0);
In0_Process();
/* check if SETUP arrived during IN processing */
wEPVal = _GetENDPOINT(ENDP0);
if((wEPVal & (EP_CTR_RX|EP_SETUP)) != 0)
{
_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
Setup0_Process();
}
 
}/* DIR = 0 */
else
{/* DIR = 1 */
 
/* DIR = 1 & CTR_RX => SETUP or OUT int */
/* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
wEPVal = _GetENDPOINT(ENDP0);
if((wEPVal & EP_CTR_TX) != 0)
{
_ClearEP_CTR_TX(ENDP0);
In0_Process();
}
if((wEPVal &EP_SETUP) != 0)
{
_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
Setup0_Process();
}
 
else if((wEPVal & EP_CTR_RX) != 0)
{
_ClearEP_CTR_RX(ENDP0);
Out0_Process();
}
 
}/* DIR = 1 */
 
/* before terminate set Tx & Rx status */
_SetEPRxStatus(ENDP0, SaveRState);
_SetEPTxStatus(ENDP0, SaveTState);
}/* if(EPindex == 0) */
else
{ /* Decode and service non control endpoints interrupt */
 
/* process related endpoint register */
wEPVal = _GetENDPOINT(EPindex);
if((wEPVal & EP_CTR_RX) != 0)
{
/* clear int flag */
_ClearEP_CTR_RX(EPindex);
/* call OUT service function */
(*pEpInt_OUT[EPindex-1])();
 
} /* if((wEPVal & EP_CTR_RX) */
if((wEPVal & EP_CTR_TX) != 0)
{
/* clear int flag */
_ClearEP_CTR_TX(EPindex);
/* call IN service function */
(*pEpInt_IN[EPindex-1])();
} /* if((wEPVal & EP_CTR_TX) != 0) */
 
}/* if(EPindex == 0) else */
 
}/* while(...) */
} /* CTR_LP */
 
 
/*******************************************************************************
* Function Name : CTR_HP
* Description : High Endpoint Correct Transfer interrupt's service routine
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CTR_HP(void)
{
u32 wEPVal;
while(((wIstr = _GetISTR()) & ISTR_CTR)!= 0)
{
_SetISTR((u16)CLR_CTR); /* clear CTR flag */
/* extract highest priority endpoint number */
EPindex = (u8)(wIstr & ISTR_EP_ID);
/* process related endpoint register */
wEPVal = _GetENDPOINT(EPindex);
if((wEPVal & EP_CTR_RX) != 0)
{
/* clear int flag */
_ClearEP_CTR_RX(EPindex);
/* call OUT service function */
(*pEpInt_OUT[EPindex-1])();
 
} /* if((wEPVal & EP_CTR_RX) */
if((wEPVal & EP_CTR_TX) != 0)
{
/* clear int flag */
_ClearEP_CTR_TX(EPindex);
/* call IN service function */
(*pEpInt_IN[EPindex-1])();
} /* if((wEPVal & EP_CTR_TX) != 0) */
 
}/* while(...) */
} /* CTR_HP */
 
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
 
/tags/V0.17e/usblibrary/src/usb_mem.c
0,0 → 1,118
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : usb_mem.c
* Author : MCD Application Team
* Date First Issued : 10/27/2003 : V1.0
* Description : Utility functions for memory transfers to/from PMA
********************************************************************************
* History:
* 09/18/2006 : V3.0
* 09/01/2006 : V2.0
* 10/27/2003 : V1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "usb_mem.h"
#include "usb_conf.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
 
 
/*******************************************************************************
* Function Name : UserToPMABufferCopy
* Description : Copy a buffer from user memory area to packet memory area (PMA)
* Input 1 : pbUsrBuf = pointer to user memory area
* Input 2 : wPMABufAddr = address into PMA
* Input 3 : wNBytes = no. of bytes to be copied
* Output : None
* Return : None
*******************************************************************************/
void UserToPMABufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr, u16 wNBytes)
{
#ifdef STR7xx /* STR7xx family */
u32 n= (wNBytes+1)>>1; /* n=(wNBytes+1)/2 */
u32 i,temp1,temp2;
u16 *pdwVal;
pdwVal = (u16 *)(wPMABufAddr*2 + PMAAddr);
for (i = n; i!= 0; i--)
{
temp1 = (u16)*pbUsrBuf;
pbUsrBuf++;
temp2 = temp1 | (u16)*pbUsrBuf<<8;
*pdwVal++ = temp2;
pdwVal++;
pbUsrBuf++;
}
#endif /* End of STR7xx family*/
#ifdef STR91x /*STR91x family*/
u32 n= (wNBytes+3)>>2; /*n=(wNBytes+1)/4*/
u32 i,temp1,temp2,temp3,temp4;
u32 *pdwVal;
pdwVal = (u32 *)(PMAAddr+(u32)((wPMABufAddr)));
for (i=n; i!=0; i--)
{
temp1 = (u32)*pbUsrBuf;
temp2 = temp1 | (u32)*(pbUsrBuf+1)<<8;
temp3 = temp2 | (u32)*(pbUsrBuf+2)<<16;
temp4 = temp3 | (u32)*(pbUsrBuf+3)<<24;
pbUsrBuf+=4;
*pdwVal = temp4;
 
pdwVal++;
}
#endif /* End of STR91x family*/
}
/*******************************************************************************
* Function Name : PMAToUserBufferCopy
* Description : Copy a buffer from user memory area to packet memory area (PMA)
* Input 1 : pbUsrBuf = pointer to user memory area
* Input 2 : wPMABufAddr = address into PMA
* Input 3 : wNBytes = no. of bytes to be copied
* Output : pbUsrBuf = pointer to user memory area with correct data
* Return : None
*******************************************************************************/
void PMAToUserBufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr, u16 wNBytes)
{
#ifdef STR7xx /*STR7xx family*/
u32 n= (wNBytes+1)>>1;/* /2*/
u32 i;
u32 *pdwVal;
pdwVal = (u32 *)(wPMABufAddr*2 + PMAAddr);
for (i = n; i!= 0; i--)
{
*(u16*)pbUsrBuf++ = *pdwVal++;
pbUsrBuf++;
}
#endif /* End of STR7xx family*/
#ifdef STR91x /*STR91x family*/
u8 *pbVal;
u16 wNTrasf=wNBytes;
if((wNBytes) == 0) return;
pbVal = (u8 *)(PMAAddr + wPMABufAddr);
while(1)
{
*pbUsrBuf++ = *pbVal++;
if((--wNTrasf) == 0) return;
*pbUsrBuf++ = *pbVal++;
if((--wNTrasf) == 0) return;
}
#endif /* End of STR91x family*/
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
 
/tags/V0.17e/usblibrary/src/usb_regs.c
0,0 → 1,1010
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : usb_regs.c
* Author : MCD Application Team
* Date First Issued : 10/27/2003 : V1.0
* Description : Interface functions to USB cell registers
********************************************************************************
* History:
* 09/18/2006 : V3.0
* 09/01/2006 : V2.0
* 10/27/2003 : V1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : SetCNTR
* Description :
* Input : wRegValue
* Output : None
* Return : None
*******************************************************************************/
void SetCNTR(u16 wRegValue)
{
_SetCNTR(wRegValue);
}
/*******************************************************************************
* Function Name : GetCNTR
* Description :
* Input : None
* Output : None
* Return : CNTR register Value
*******************************************************************************/
u16 GetCNTR(void)
{
return(_GetCNTR());
}
/*******************************************************************************
* Function Name : SetISTR
* Description :
* Input : wRegValue
* Output : None
* Return : None
*******************************************************************************/
void SetISTR(u16 wRegValue)
{
_SetISTR(wRegValue);
}
/*******************************************************************************
* Function Name : GetISTR
* Description :
* Input :
* Output :
* Return : ISTR register Value
*******************************************************************************/
u16 GetISTR(void)
{
return(_GetISTR());
}
/*******************************************************************************
* Function Name : GetFNR
* Description :
* Input :
* Output :
* Return : FNR register Value
*******************************************************************************/
u16 GetFNR(void)
{
return(_GetFNR());
}
/*******************************************************************************
* Function Name : SetDADDR
* Description :
* Input : wRegValue
* Output :
* Return :
*******************************************************************************/
void SetDADDR(u16 wRegValue)
{
_SetDADDR(wRegValue);
}
/*******************************************************************************
* Function Name : GetDADDR
* Description :
* Input :
* Output :
* Return : DADDR register Value
*******************************************************************************/
u16 GetDADDR(void)
{
return(_GetDADDR());
}
/*******************************************************************************
* Function Name : SetBTABLE
* Description :
* Input : wRegValue
* Output :
* Return :
*******************************************************************************/
void SetBTABLE(u16 wRegValue)
{
_SetBTABLE(wRegValue);
}
 
/*******************************************************************************
* Function Name : GetBTABLE
* Description :
* Input :
* Output :
* Return : BTABLE address
*******************************************************************************/
u16 GetBTABLE(void)
{
return(_GetBTABLE());
}
/*******************************************************************************
* Function Name : SetENDPOINT
* Description :
* Input : bEpNum, wRegValue
* Output :
* Return :
*******************************************************************************/
void SetENDPOINT(u8 bEpNum, u16 wRegValue)
{
_SetENDPOINT(bEpNum,wRegValue);
}
/*******************************************************************************
* Function Name : GetENDPOINT
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetENDPOINT(u8 bEpNum)
{
return(_GetENDPOINT(bEpNum));
}
/*******************************************************************************
* Function Name : SetEPType
* Description :
* Input : bEpNum, wType
* Output :
* Return :
*******************************************************************************/
void SetEPType(u8 bEpNum, u16 wType)
{
_SetEPType(bEpNum, wType);
}
/*******************************************************************************
* Function Name : GetEPType
* Description :
* Input : bEpNum,
* Output :
* Return : Endpoint Type
*******************************************************************************/
u16 GetEPType(u8 bEpNum)
{
return(_GetEPType(bEpNum));
}
/*******************************************************************************
* Function Name : SetEPTxStatus
* Description :
* Input : bEpNum, wState
* Output :
* Return :
*******************************************************************************/
void SetEPTxStatus(u8 bEpNum, u16 wState)
{
_SetEPTxStatus(bEpNum,wState);
}
/*******************************************************************************
* Function Name : SetEPRxStatus
* Description :
* Input : bEpNum, wState
* Output :
* Return :
*******************************************************************************/
void SetEPRxStatus(u8 bEpNum, u16 wState)
{
_SetEPRxStatus(bEpNum,wState);
}
/*******************************************************************************
* Function Name : SetDouBleBuffEPStall
* Description : sets the status for Double Buffer Endpoint to STALL
* Input : bEpNum = endpoint number
bDir = Endpoint direction
* Output :
* Return :
*******************************************************************************/
void SetDouBleBuffEPStall(u8 bEpNum,u8 bDir)
{
u16 Endpoint_DTOG_Status;
Endpoint_DTOG_Status = GetENDPOINT(bEpNum);
if(bDir== EP_DBUF_OUT)
{ /* OUT double buffered endpoint */
_SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1);
}
else if(bDir == EP_DBUF_IN)
{ /* IN double buffered endpoint */
_SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1);
}
}
/*******************************************************************************
* Function Name : GetEPTxStatus
* Description :
* Input : bEpNum
* Output :
* Return : Endpoint TX Status
*******************************************************************************/
u16 GetEPTxStatus(u8 bEpNum)
{
return(_GetEPTxStatus(bEpNum));
}
/*******************************************************************************
* Function Name : GetEPRxStatus
* Description :
* Input : bEpNum
* Output :
* Return : Endpoint RX Status
*******************************************************************************/
u16 GetEPRxStatus(u8 bEpNum)
{
return(_GetEPRxStatus(bEpNum));
}
/*******************************************************************************
* Function Name : SetEPTxValid
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void SetEPTxValid(u8 bEpNum)
{
_SetEPTxStatus(bEpNum, EP_TX_VALID);
}
/*******************************************************************************
* Function Name : SetEPRxValid
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void SetEPRxValid(u8 bEpNum)
{
_SetEPRxStatus(bEpNum, EP_RX_VALID);
}
/*******************************************************************************
* Function Name : SetEP_KIND
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void SetEP_KIND(u8 bEpNum)
{
_SetEP_KIND(bEpNum);
}
/*******************************************************************************
* Function Name : ClearEP_KIND
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ClearEP_KIND(u8 bEpNum)
{
_ClearEP_KIND(bEpNum);
}
/*******************************************************************************
* Function Name : Clear_Status_Out
* Description : Clear the Status Out of the related Endpoint
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void Clear_Status_Out(u8 bEpNum)
{
_ClearEP_KIND(bEpNum);
}
/*******************************************************************************
* Function Name : Set_Status_Out
* Description : Set the Status Out of the related Endpoint
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void Set_Status_Out(u8 bEpNum)
{
_SetEP_KIND(bEpNum);
}
/*******************************************************************************
* Function Name : SetEPDoubleBuff
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void SetEPDoubleBuff(u8 bEpNum)
{
_SetEP_KIND(bEpNum);
}
/*******************************************************************************
* Function Name : ClearEPDoubleBuff
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ClearEPDoubleBuff(u8 bEpNum)
{
_ClearEP_KIND(bEpNum);
}
/*******************************************************************************
* Function Name : GetTxStallStatus
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetTxStallStatus(u8 bEpNum)
{
return(_GetTxStallStatus(bEpNum));
}
/*******************************************************************************
* Function Name : GetRxStallStatus
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetRxStallStatus(u8 bEpNum)
{
return(_GetRxStallStatus(bEpNum));
}
/*******************************************************************************
* Function Name : ClearEP_CTR_RX
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ClearEP_CTR_RX(u8 bEpNum)
{
_ClearEP_CTR_RX(bEpNum);
}
/*******************************************************************************
* Function Name : ClearEP_CTR_TX
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ClearEP_CTR_TX(u8 bEpNum)
{
_ClearEP_CTR_TX(bEpNum);
}
/*******************************************************************************
* Function Name : ToggleDTOG_RX
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ToggleDTOG_RX(u8 bEpNum)
{
_ToggleDTOG_RX(bEpNum);
}
/*******************************************************************************
* Function Name : ToggleDTOG_TX
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ToggleDTOG_TX(u8 bEpNum)
{
_ToggleDTOG_TX(bEpNum);
}
/*******************************************************************************
* Function Name : ClearDTOG_RX
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ClearDTOG_RX(u8 bEpNum)
{
_ClearDTOG_RX(bEpNum);
}
/*******************************************************************************
* Function Name : ClearDTOG_TX
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
void ClearDTOG_TX(u8 bEpNum)
{
_ClearDTOG_TX(bEpNum);
}
/*******************************************************************************
* Function Name : SetEPAddress
* Description :
* Input : bEpNum, bAddr
* Output :
* Return :
*******************************************************************************/
void SetEPAddress(u8 bEpNum,u8 bAddr)
{
_SetEPAddress(bEpNum,bAddr);
}
/*******************************************************************************
* Function Name : GetEPAddress
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u8 GetEPAddress(u8 bEpNum)
{
return(_GetEPAddress(bEpNum));
}
/*******************************************************************************
* Function Name : SetEPTxAddr
* Description :
* Input : bEpNum, wAddr
* Output :
* Return :
*******************************************************************************/
void SetEPTxAddr(u8 bEpNum, u16 wAddr)
{
_SetEPTxAddr(bEpNum,wAddr);
}
/*******************************************************************************
* Function Name : SetEPRxAddr
* Description :
* Input : bEpNum, wAddr
* Output :
* Return :
*******************************************************************************/
void SetEPRxAddr(u8 bEpNum, u16 wAddr)
{
_SetEPRxAddr(bEpNum,wAddr);
}
/*******************************************************************************
* Function Name : GetEPTxAddr
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPTxAddr(u8 bEpNum)
{
return(_GetEPTxAddr(bEpNum));
}
/*******************************************************************************
* Function Name : GetEPRxAddr
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPRxAddr(u8 bEpNum)
{
return(_GetEPRxAddr(bEpNum));
}
/*******************************************************************************
* Function Name : SetEPTxCount
* Description :
* Input : bEpNum, wCount
* Output :
* Return :
*******************************************************************************/
void SetEPTxCount(u8 bEpNum, u16 wCount)
{
_SetEPTxCount(bEpNum,wCount);
}
/*******************************************************************************
* Function Name : SetEPCountRxReg
* Description :
* Input : *pdwReg, wCount
* Output :
* Return :
*******************************************************************************/
#ifdef STR7xx
void SetEPCountRxReg(u32 *pdwReg, u16 wCount)
{
_SetEPCountRxReg(dwReg, wCount);
}
#endif
/*******************************************************************************
* Function Name : SetEPRxCount
* Description :
* Input : bEpNum, wCount
* Output :
* Return :
*******************************************************************************/
void SetEPRxCount(u8 bEpNum, u16 wCount)
{
_SetEPRxCount(bEpNum,wCount);
}
/*******************************************************************************
* Function Name : GetEPTxCount
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPTxCount(u8 bEpNum)
{
return(_GetEPTxCount(bEpNum));
}
/*******************************************************************************
* Function Name : GetEPRxCount
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPRxCount(u8 bEpNum)
{
return(_GetEPRxCount(bEpNum));
}
/*******************************************************************************
* Function Name : SetEPDblBuffAddr
* Description :
* Input : bEpNum, wBuf0Addr, wBuf1Addr
* Output :
* Return :
*******************************************************************************/
void SetEPDblBuffAddr(u8 bEpNum, u16 wBuf0Addr, u16 wBuf1Addr)
{
_SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr);
}
/*******************************************************************************
* Function Name : SetEPDblBuf0Addr
* Description :
* Input : bEpNum, wBuf0Addr
* Output :
* Return :
*******************************************************************************/
void SetEPDblBuf0Addr(u8 bEpNum,u16 wBuf0Addr)
{
_SetEPDblBuf0Addr(bEpNum, wBuf0Addr);
}
/*******************************************************************************
* Function Name : SetEPDblBuf1Addr
* Description :
* Input : bEpNum, wBuf1Addr
* Output :
* Return :
*******************************************************************************/
void SetEPDblBuf1Addr(u8 bEpNum,u16 wBuf1Addr)
{
_SetEPDblBuf1Addr(bEpNum, wBuf1Addr);
}
/*******************************************************************************
* Function Name : GetEPDblBuf0Addr
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPDblBuf0Addr(u8 bEpNum)
{
return(_GetEPDblBuf0Addr(bEpNum));
}
/*******************************************************************************
* Function Name : GetEPDblBuf1Addr
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPDblBuf1Addr(u8 bEpNum)
{
return(_GetEPDblBuf1Addr(bEpNum));
}
/*******************************************************************************
* Function Name : SetEPDblBuffCount
* Description :
* Input : bEpNum,bDir, wCount
* Output :
* Return :
*******************************************************************************/
void SetEPDblBuffCount(u8 bEpNum, u8 bDir, u16 wCount)
{
#ifdef STR7xx /*STR7xx family */
_SetEPDblBuffCount(bEpNum, bDir, wCount);
#endif
#ifdef STR91x /*STR91x family*/
SetEPDblBuf0Count(bEpNum, bDir,wCount);
SetEPDblBuf1Count(bEpNum, bDir,wCount);
#endif
}
/*******************************************************************************
* Function Name : SetEPDblBuf0Count
* Description :
* Input : bEpNum, bDir, wCount
* Output :
* Return :
*******************************************************************************/
void SetEPDblBuf0Count(u8 bEpNum, u8 bDir,u16 wCount)
{
#ifdef STR7xx /*STR7xx family */
_SetEPDblBuf0Count(bEpNum,bDir,wCount);
#endif
#ifdef STR91x /*STR91x family*/
u32 BLsize=0;
u32 Blocks;
if(bDir == EP_DBUF_IN)
/* IN double bufferd endpoint */
SetEPTxCount(bEpNum,wCount);
else if(bDir == EP_DBUF_OUT)
{
/* OUT double bufferd endpoint */
 
if (wCount < 64) Blocks = wCount>>1;
else
{
BLsize = 0x8000;
Blocks = wCount>>6;
}
*_pEPBufCount(bEpNum) &=~0x8000;
*_pEPBufCount(bEpNum) |=BLsize;
*_pEPBufCount(bEpNum) &=~0x7C00;
*_pEPBufCount(bEpNum) |=Blocks<<10;
*_pEPBufCount(bEpNum) &=0xFFFFFC00;
}
#endif
}
/*******************************************************************************
* Function Name : SetEPDblBuf1Count
* Description :
* Input : bEpNum, bDir, wCount
* Output :
* Return :
*******************************************************************************/
void SetEPDblBuf1Count(u8 bEpNum, u8 bDir,u16 wCount)
{
#ifdef STR7xx /*STR7xx family */
_SetEPDblBuf1Count(bEpNum,bDir,wCount);
#endif
#ifdef STR91x /*STR91x family*/
if(bDir == EP_DBUF_IN)
/* IN double buffered endpoint */
{
*_pEPBufCount(bEpNum)&= 0x000FFFF;
*_pEPBufCount(bEpNum)|=(wCount<<16);
}
else if(bDir == EP_DBUF_OUT)
/* OUT double buffered endpoint */
_SetEPRxCount(bEpNum, wCount);
#endif
}
/*******************************************************************************
* Function Name : GetEPDblBuf0Count
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPDblBuf0Count(u8 bEpNum)
{
return(_GetEPDblBuf0Count(bEpNum));
}
/*******************************************************************************
* Function Name : GetEPDblBuf1Count
* Description :
* Input : bEpNum
* Output :
* Return :
*******************************************************************************/
u16 GetEPDblBuf1Count(u8 bEpNum)
{
return(_GetEPDblBuf1Count(bEpNum));
}
#ifdef STR7xx /*STR7xx family */
/*******************************************************************************
* Function Name : GetEPDblBufDir
* Description : gets direction of the double buffered endpoint
* Input : bEpNum
* Output : EP_DBUF_OUT, EP_DBUF_IN,
EP_DBUF_ERR if the endpoint counter not yet programmed
* Return :
*******************************************************************************/
EP_DBUF_DIR GetEPDblBufDir(u8 bEpNum) {
if((u16)(*_pEPRxCount(bEpNum) & 0xFC00) != 0)
return(EP_DBUF_OUT);
else if(((u16)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0)
return(EP_DBUF_IN);
else
return(EP_DBUF_ERR);
}
#endif
/*******************************************************************************
* Function Name : FreeUserBuffer
* Description : free buffer used from the application realising it to the line
toggles bit SW_BUF in the double buffered endpoint register
* Input : bEpNum, bDir
* Output :
* Return :
*******************************************************************************/
void FreeUserBuffer(u8 bEpNum, u8 bDir)
{
if(bDir== EP_DBUF_OUT)
{ /* OUT double buffered endpoint */
_ToggleDTOG_TX(bEpNum);
}
else if(bDir == EP_DBUF_IN)
{ /* IN double buffered endpoint */
_ToggleDTOG_RX(bEpNum);
}
}
 
/*******************************************************************************
* Function Name : ToWord
* Description :
* Input : bh, bl
* Output :
* Return :
*******************************************************************************/
u16 ToWord(u8 bh, u8 bl)
{
u16 wRet;
wRet = (u16)bl | ((u16)bh << 8);
return(wRet);
}
/*******************************************************************************
* Function Name : ByteSwap
* Description :
* Input : wSwW
* Output :
* Return :
*******************************************************************************/
u16 ByteSwap(u16 wSwW)
{
u8 bTemp;
u16 wRet;
bTemp = (u8)(wSwW & 0xff);
wRet = (wSwW >> 8) | ((u16)bTemp << 8);
return(wRet);
}
 
/* DMA Functions only for STR91x */
#ifdef STR91x /*str91x family*/
/*******************************************************************************
* Function Name : SetDMAburstTxSize
* Description : Configure the Burst Size for a Tx Endpoint
* Input : DestBsize: Destination Burst Size
* Output : None
* Return : None
*******************************************************************************/
void SetDMABurstTxSize(u8 DestBsize)
{
*DMABSIZE &=~0xEF;
*DMABSIZE = (DestBsize<<4);
}
 
/*******************************************************************************
* Function Name : SetDMABurstRxSize
* Description : Configure the Burst Size for a Rx Endpoint
* Input : SrcBsize: Source Burst
* Output : None
* Return : None
*******************************************************************************/
void SetDMABurstRxSize(u8 SrcBsize)
{
*DMABSIZE &=~0x7;
*DMABSIZE = SrcBsize;
}
 
/*******************************************************************************
* Function Name : DMAUnlinkedModeTxConfig
* Description : Configure a Tx Endpoint to trigger TX Unlinked DMA request
* Note : Up to three endpoints could be configured to trigger DMA
request, an index[0:2] must be associated to an endpoint
* Input : -bEpNum: endpoint number[0:9]
* -index: 0,1 or 2
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeTxConfig(u8 bEpNum ,u8 index)
{
*DMACR2 &=~(0x0F<<(4*index));
*DMACR2 |=bEpNum<<(4*index);
}
 
/*******************************************************************************
* Function Name : DMAUnlinkedModeTxEnable
* Description : Enable a Tx endpoint to trigger Tx DMA request
* Input : -index :0,1 or 2 = index associated to endpoint in function
* "DMAUnlinkedModeTxConfig"
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeTxEnable(u8 index)
{
*DMACR3 &=~0x01; /*DMA Tx linked mode disabled*/
*DMACR2 &=~0x3000;
*DMACR2 |=(index+1)<<12;
}
/*******************************************************************************
* Function Name : DMAUnlinkedModeTxDisable
* Description : Enable a Tx endpoint to trigger Tx DMA request
* Input : index :0,1 or 2 = index associated to endpoint in function
* "DMAUnlinkedModeTxConfig"
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeTxDisable(u8 index)
{
*DMACR2 &=~0x3000;
}
 
/*******************************************************************************
* Function Name : DMAUnlinkedModeRxEnable
* Description : Enable a Rx Endpoint to trigger Rx DMA
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeRxEnable(u8 bEpNum)
{
*DMACR3 &=~0x80; /*DMA Rx linked mode disabled*/
*DMACR1 |=(0x1<<bEpNum);
}
 
/*******************************************************************************
* Function Name : DMAUnlinkedModeRxDisable
* Description : Disable a Rx Endpoint to trigger Rx DMA
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeRxDisable(u8 bEpNum)
{
*DMACR1 &=~(0x1<<bEpNum);
}
 
/*******************************************************************************
* Function Name : DMALinkedModeRxConfig
* Description : Configure a Rx endpoint to trigger DMA linked request
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeRxConfig(u8 bEpNum)
{
*DMACR3 &=~0x1E00;
*DMACR3 |=bEpNum<<9;
}
 
/*******************************************************************************
* Function Name : DMALinkedModeTxConfig
* Description : Configure a Tx endpoint to trigger DMA linked request
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeTxConfig(u8 bEpNum)
{
*DMACR3 &=~0x1E;
*DMACR3 |=bEpNum<<1;
}
 
/*******************************************************************************
* Function Name : DMALinkedModeRxEnable
* Description : Enable the DMA Linked Rx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeRxEnable(void)
{
*DMACR3 |=0x100;
*DMACR3 |=0x2000;
}
 
/*******************************************************************************
* Function Name : DMALinkedModeTxEnable
* Description : Enable the DMA Linked Tx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeTxEnable(void)
{
*DMACR3 |=0x1;
*DMACR3 |=0x20;
}
/*******************************************************************************
* Function Name : DMALinkedModeRxDisable
* Description : Disable the DMA Linked Rx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeRxDisable(void)
{
*DMACR3 &=~0x100;
*DMACR3 &=~0x2000;
}
 
/*******************************************************************************
* Function Name : DMALinkedModeTxDisable
* Description : Disable the DMA Linked Tx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeTxDisable(void)
{
*DMACR3 &=~0x1;
*DMACR3 &=~0x20;
}
/*******************************************************************************
* Function Name : USB_DMASynchEnable
* Description : Enable the Synchronization Logic
* Input : TRUE or FALSE
* Output : None
* Return : None
*******************************************************************************/
void DMASynchEnable(void)
{
*DMACR3 |=0x40;
}
 
/*******************************************************************************
* Function Name : USB_DMASynchDisable
* Description : Disable the Synchronization Logic
* Input : TRUE or FALSE
* Output : None
* Return : None
*******************************************************************************/
void DMASynchDisable(void)
{
*DMACR3 &=~0x40;
}
 
/*******************************************************************************
* Function Name : SetDMALLITxLength
* Description : Set the DMA LLI Tx length
* Input : length
* Output : None
* Return : None
*******************************************************************************/
void SetDMALLITxLength(u8 length)
{
*DMALLI &=~0xFF;
*DMALLI |= length;
}
 
/*******************************************************************************
* Function Name : SetDMALLIRxLength
* Description : Set the DMA LLI Rx length
* Input : length
* Output : None
* Return : None
*******************************************************************************/
void SetDMALLIRxLength(u8 length )
{
*DMALLI &=~0xFF00;
*DMALLI |= length<<8;
}
 
/*******************************************************************************
* Function Name : SetDMALLIRxPacketNum
* Description : Set the LLI_RX_NPACKETS field in register USB_DMABSIZE register
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SetDMALLIRxPacketNum(u8 PacketNum)
{
*DMABSIZE &=0xFF;
*DMABSIZE |=(PacketNum<<8);
}
 
/*******************************************************************************
* Function Name : GetDMALLIPacketNum
* Description : gets the LLI_RX_NPACKETS field value
* Input : None
* Output : None
* Return : LLI_RX_NPACKETS field value
*******************************************************************************/
u8 GetDMALLIRxPacketNum(void)
{
return((u8)(*DMABSIZE & 0xFF00)>>8);
}
#endif
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/