/tags/V0.26f/usblibrary/src/usb_core.c |
---|
0,0 → 1,1034 |
/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
* File Name : usb_core.c |
* Author : MCD Application Team |
* Version : V4.0.0 |
* Date : 09/29/2008 |
* Description : Standard protocol processing (USB v2.0). |
******************************************************************************** |
* THE PRESENT FIRMWARE 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 ------------------------------------------------------------------*/ |
/* Private typedef -----------------------------------------------------------*/ |
/* Private define ------------------------------------------------------------*/ |
/* Private macro -------------------------------------------------------------*/ |
/* Private variables ---------------------------------------------------------*/ |
/* Private function prototypes -----------------------------------------------*/ |
/* Private functions ---------------------------------------------------------*/ |
/* 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; |
bool Data_Mul_MaxPacketSize = FALSE; |
/* Private function prototypes -----------------------------------------------*/ |
static void DataStageOut(void); |
static void DataStageIn(void); |
static void NoData_Setup0(void); |
static void Data_Setup0(void); |
/* Private functions ---------------------------------------------------------*/ |
/******************************************************************************* |
* Function Name : Standard_GetConfiguration. |
* Description : Return the current configuration variable address. |
* Input : Length - How many bytes are needed. |
* Output : None. |
* 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 : None. |
* Output : None. |
* 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 : None. |
* 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 : None. |
* Output : None. |
* 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 : None. |
* 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; |
/* Remote Wakeup enabled */ |
if (ValBit(Feature, 5)) |
{ |
SetBit(StatusInfo0, 1); |
} |
/* Bus-powered */ |
if (ValBit(Feature, 6)) |
{ |
ClrBit(StatusInfo0, 0); |
} |
else /* Self-powered */ |
{ |
SetBit(StatusInfo0, 0); |
} |
} |
/*Interface Status*/ |
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) |
{ |
return (u8 *)&StatusInfo; |
} |
/*Get EndPoint Status*/ |
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) |
{ |
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 : None. |
* Output : None. |
* Return : - Return USB_SUCCESS, if the request is performed. |
* - Return USB_UNSUPPORT, if the request is invalid. |
*******************************************************************************/ |
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); |
pUser_Standard_Requests->User_ClearFeature(); |
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)) |
{ /*Get Status of endpoint & stall the request if the related_ENdpoint is |
Disabled*/ |
Status = _GetEPTxStatus(Related_Endpoint); |
} |
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 : None. |
* Output : None. |
* Return : - Return USB_SUCCESS, if the request is performed. |
* - Return USB_UNSUPPORT, if the request is invalid. |
*******************************************************************************/ |
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)) |
{ /* get Status of endpoint & stall the request if the related_ENdpoint is |
Disabled*/ |
Status = _GetEPTxStatus(Related_Endpoint); |
} |
else |
{ |
Status = _GetEPRxStatus(Related_Endpoint); |
} |
if (Related_Endpoint >= Device_Table.Total_Endpoint |
|| pInformation->USBwValue != 0 || Status == 0 |
|| pInformation->Current_Configuration == 0) |
{ |
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 : None. |
* Output : None. |
* Return : - Return USB_SUCCESS, if the request is performed. |
* - Return USB_UNSUPPORT, if the request is invalid. |
*******************************************************************************/ |
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 : None. |
* Return : Address of a part of the descriptor pointed by the Usb_ |
* wOffset The buffer pointed by this address contains at least |
* Length bytes. |
*******************************************************************************/ |
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 : None. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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 : None. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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)) |
{ |
if(Data_Mul_MaxPacketSize == TRUE) |
{ |
/* No more data to send and empty packet */ |
Send0LengthData(); |
ControlState = LAST_IN_DATA; |
Data_Mul_MaxPacketSize = FALSE; |
} |
else |
{ |
/* 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 Back 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 : None. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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)) |
{ |
/*Get Status of endpoint & stall the request if the related_ENdpoint |
is Disabled*/ |
Status = _GetEPTxStatus(Related_Endpoint); |
} |
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 */ |
vu32 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; |
} |
else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength) |
{ |
if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize) |
{ |
Data_Mul_MaxPacketSize = FALSE; |
} |
else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0) |
{ |
Data_Mul_MaxPacketSize = TRUE; |
} |
} |
pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize; |
DataStageIn(); |
} |
else |
{ |
pInformation->ControlState = OUT_DATA; |
vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */ |
} |
return; |
} |
/******************************************************************************* |
* Function Name : Setup0_Process |
* Description : Get the device request data and dispatch to individual process. |
* Input : None. |
* Output : None. |
* Return : Post0_Process. |
*******************************************************************************/ |
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 : None. |
* Output : None. |
* Return : Post0_Process. |
*******************************************************************************/ |
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 : None. |
* Output : None. |
* Return : Post0_Process. |
*******************************************************************************/ |
u8 Out0_Process(void) |
{ |
u32 ControlState = pInformation->ControlState; |
if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA)) |
{ |
DataStageOut(); |
ControlState = pInformation->ControlState; |
/* may be changed outside the function */ |
} |
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 : Stall the Endpoint 0 in case of error. |
* Input : None. |
* Output : None. |
* Return : - 0 if the control State is in PAUSE |
* - 1 if not. |
*******************************************************************************/ |
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 : None. |
* Return : None. |
*******************************************************************************/ |
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); |
} |
_SetDADDR(Val | DADDR_EF); /* set device address and enable function */ |
} |
/******************************************************************************* |
* Function Name : NOP_Process |
* Description : No operation function. |
* Input : None. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void NOP_Process(void) |
{ |
} |
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ |
/tags/V0.26f/usblibrary/src/usb_init.c |
---|
0,0 → 1,63 |
/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
* File Name : usb_init.c |
* Author : MCD Application Team |
* Version : V4.0.0 |
* Date : 09/29/2008 |
* Description : Initialization routines & global variables. |
******************************************************************************** |
* THE PRESENT FIRMWARE 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; |
/* Private function prototypes -----------------------------------------------*/ |
/* Private functions ---------------------------------------------------------*/ |
/******************************************************************************* |
* Function Name : USB_Init |
* Description : USB system initialization |
* Input : None. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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 2008 STMicroelectronics *****END OF FILE****/ |
/tags/V0.26f/usblibrary/src/usb_int.c |
---|
0,0 → 1,190 |
/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
* File Name : usb_int.c |
* Author : MCD Application Team |
* Version : V4.0.0 |
* Date : 09/29/2008 |
* Description : Endpoint CTR (Low and High) interrupt's service routines. |
******************************************************************************** |
* THE PRESENT FIRMWARE 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 priority Endpoint Correct Transfer interrupt's service |
* routine. |
* Input : None. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void CTR_LP(void) |
{ |
u32 wEPVal = 0; |
/* 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(); |
/* before terminate set Tx & Rx status */ |
_SetEPRxStatus(ENDP0, SaveRState); |
_SetEPTxStatus(ENDP0, SaveTState); |
return; |
} |
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(); |
/* before terminate set Tx & Rx status */ |
_SetEPRxStatus(ENDP0, SaveRState); |
_SetEPTxStatus(ENDP0, SaveTState); |
return; |
} |
else if ((wEPVal &EP_SETUP) != 0) |
{ |
_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */ |
Setup0_Process(); |
/* before terminate set Tx & Rx status */ |
_SetEPRxStatus(ENDP0, SaveRState); |
_SetEPTxStatus(ENDP0, SaveTState); |
return; |
} |
else if ((wEPVal & EP_CTR_RX) != 0) |
{ |
_ClearEP_CTR_RX(ENDP0); |
Out0_Process(); |
/* before terminate set Tx & Rx status */ |
_SetEPRxStatus(ENDP0, SaveRState); |
_SetEPTxStatus(ENDP0, SaveTState); |
return; |
} |
} |
}/* 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(...) */ |
} |
/******************************************************************************* |
* Function Name : CTR_HP. |
* Description : High Priority 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 2008 STMicroelectronics *****END OF FILE****/ |
/tags/V0.26f/usblibrary/src/usb_mem.c |
---|
0,0 → 1,123 |
/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
* File Name : usb_mem.c |
* Author : MCD Application Team |
* Version : V4.0.0 |
* Date : 09/29/2008 |
* Description : Utility functions for memory transfers to/from PMA. |
******************************************************************************** |
* THE PRESENT FIRMWARE 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 ---------------------------------------------------------*/ |
/* Private function prototypes -----------------------------------------------*/ |
/* Private functions ---------------------------------------------------------*/ |
/******************************************************************************* |
* Function Name : UserToPMABufferCopy |
* Description : Copy a buffer from user memory area to packet memory area (PMA) |
* Input : - pbUsrBuf: pointer to user memory area. |
* - wPMABufAddr: address into PMA. |
* - 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 : - pbUsrBuf = pointer to user memory area. |
* - wPMABufAddr = address into PMA. |
* - wNBytes = no. of bytes to be copied. |
* Output : None. |
* 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--) |
{ |
*pbUsrBuf++ = *(u8*)pdwVal; |
*pbUsrBuf++ = *((u8*)pdwVal + 1); |
pdwVal ++; |
} |
#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 2008 STMicroelectronics *****END OF FILE****/ |
/tags/V0.26f/usblibrary/src/usb_regs.c |
---|
0,0 → 1,1096 |
/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
* File Name : usb_regs.c |
* Author : MCD Application Team |
* Version : V4.0.0 |
* Date : 09/29/2008 |
* Description : Interface functions to USB cell registers. |
******************************************************************************** |
* THE PRESENT FIRMWARE 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 : Set the CNTR register value. |
* Input : wRegValue: new register value. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetCNTR(u16 wRegValue) |
{ |
_SetCNTR(wRegValue); |
} |
/******************************************************************************* |
* Function Name : GetCNTR. |
* Description : returns the CNTR register value. |
* Input : None. |
* Output : None. |
* Return : CNTR register Value. |
*******************************************************************************/ |
u16 GetCNTR(void) |
{ |
return(_GetCNTR()); |
} |
/******************************************************************************* |
* Function Name : SetISTR. |
* Description : Set the ISTR register value. |
* Input : wRegValue: new register value. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetISTR(u16 wRegValue) |
{ |
_SetISTR(wRegValue); |
} |
/******************************************************************************* |
* Function Name : GetISTR. |
* Description : Returns the ISTR register value. |
* Input : None. |
* Output : None. |
* Return : ISTR register Value. |
*******************************************************************************/ |
u16 GetISTR(void) |
{ |
return(_GetISTR()); |
} |
/******************************************************************************* |
* Function Name : GetFNR. |
* Description : Returns the FNR register value. |
* Input : None. |
* Output : None. |
* Return : FNR register Value. |
*******************************************************************************/ |
u16 GetFNR(void) |
{ |
return(_GetFNR()); |
} |
/******************************************************************************* |
* Function Name : SetDADDR. |
* Description : Set the DADDR register value. |
* Input : wRegValue: new register value. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetDADDR(u16 wRegValue) |
{ |
_SetDADDR(wRegValue); |
} |
/******************************************************************************* |
* Function Name : GetDADDR. |
* Description : Returns the DADDR register value. |
* Input : None. |
* Output : None. |
* Return : DADDR register Value |
*******************************************************************************/ |
u16 GetDADDR(void) |
{ |
return(_GetDADDR()); |
} |
/******************************************************************************* |
* Function Name : SetBTABLE. |
* Description : Set the BTABLE. |
* Input : wRegValue: New register value. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetBTABLE(u16 wRegValue) |
{ |
_SetBTABLE(wRegValue); |
} |
/******************************************************************************* |
* Function Name : GetBTABLE. |
* Description : Returns the BTABLE register value. |
* Input : None. |
* Output : None. |
* Return : BTABLE address. |
*******************************************************************************/ |
u16 GetBTABLE(void) |
{ |
return(_GetBTABLE()); |
} |
/******************************************************************************* |
* Function Name : SetENDPOINT. |
* Description : Setthe Endpoint register value. |
* Input : bEpNum: Endpoint Number. |
* wRegValue. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetENDPOINT(u8 bEpNum, u16 wRegValue) |
{ |
_SetENDPOINT(bEpNum, wRegValue); |
} |
/******************************************************************************* |
* Function Name : GetENDPOINT. |
* Description : Return the Endpoint register value. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Endpoint register value. |
*******************************************************************************/ |
u16 GetENDPOINT(u8 bEpNum) |
{ |
return(_GetENDPOINT(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : SetEPType. |
* Description : sets the type in the endpoint register. |
* Input : bEpNum: Endpoint Number. |
* wType: type definition. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPType(u8 bEpNum, u16 wType) |
{ |
_SetEPType(bEpNum, wType); |
} |
/******************************************************************************* |
* Function Name : GetEPType. |
* Description : Returns the endpoint type. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Endpoint Type. |
*******************************************************************************/ |
u16 GetEPType(u8 bEpNum) |
{ |
return(_GetEPType(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : SetEPTxStatus. |
* Description : Set the status of Tx endpoint. |
* Input : bEpNum: Endpoint Number. |
* wState: new state. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPTxStatus(u8 bEpNum, u16 wState) |
{ |
_SetEPTxStatus(bEpNum, wState); |
} |
/******************************************************************************* |
* Function Name : SetEPRxStatus. |
* Description : Set the status of Rx endpoint. |
* Input : bEpNum: Endpoint Number. |
* wState: new state. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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 : None. |
* Return : None. |
*******************************************************************************/ |
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 : Returns the endpoint Tx status. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Endpoint TX Status. |
*******************************************************************************/ |
u16 GetEPTxStatus(u8 bEpNum) |
{ |
return(_GetEPTxStatus(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : GetEPRxStatus. |
* Description : Returns the endpoint Rx status. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Endpoint RX Status. |
*******************************************************************************/ |
u16 GetEPRxStatus(u8 bEpNum) |
{ |
return(_GetEPRxStatus(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : SetEPTxValid. |
* Description : Valid the endpoint Tx Status. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPTxValid(u8 bEpNum) |
{ |
_SetEPTxStatus(bEpNum, EP_TX_VALID); |
} |
/******************************************************************************* |
* Function Name : SetEPRxValid. |
* Description : Valid the endpoint Rx Status. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPRxValid(u8 bEpNum) |
{ |
_SetEPRxStatus(bEpNum, EP_RX_VALID); |
} |
/******************************************************************************* |
* Function Name : SetEP_KIND. |
* Description : Clear the EP_KIND bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEP_KIND(u8 bEpNum) |
{ |
_SetEP_KIND(bEpNum); |
} |
/******************************************************************************* |
* Function Name : ClearEP_KIND. |
* Description : set the EP_KIND bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ClearEP_KIND(u8 bEpNum) |
{ |
_ClearEP_KIND(bEpNum); |
} |
/******************************************************************************* |
* Function Name : Clear_Status_Out. |
* Description : Clear the Status Out of the related Endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void Set_Status_Out(u8 bEpNum) |
{ |
_SetEP_KIND(bEpNum); |
} |
/******************************************************************************* |
* Function Name : SetEPDoubleBuff. |
* Description : Enable the double buffer feature for the endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPDoubleBuff(u8 bEpNum) |
{ |
_SetEP_KIND(bEpNum); |
} |
/******************************************************************************* |
* Function Name : ClearEPDoubleBuff. |
* Description : Disable the double buffer feature for the endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ClearEPDoubleBuff(u8 bEpNum) |
{ |
_ClearEP_KIND(bEpNum); |
} |
/******************************************************************************* |
* Function Name : GetTxStallStatus |
* Description : Returns the Stall status of the Tx endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Tx Stall status. |
*******************************************************************************/ |
u16 GetTxStallStatus(u8 bEpNum) |
{ |
return(_GetTxStallStatus(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : GetRxStallStatus |
* Description : Returns the Stall status of the Rx endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Rx Stall status. |
*******************************************************************************/ |
u16 GetRxStallStatus(u8 bEpNum) |
{ |
return(_GetRxStallStatus(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : ClearEP_CTR_RX |
* Description : Clear the CTR_RX bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ClearEP_CTR_RX(u8 bEpNum) |
{ |
_ClearEP_CTR_RX(bEpNum); |
} |
/******************************************************************************* |
* Function Name : ClearEP_CTR_TX |
* Description : Clear the CTR_TX bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ClearEP_CTR_TX(u8 bEpNum) |
{ |
_ClearEP_CTR_TX(bEpNum); |
} |
/******************************************************************************* |
* Function Name : ToggleDTOG_RX |
* Description : Toggle the DTOG_RX bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ToggleDTOG_RX(u8 bEpNum) |
{ |
_ToggleDTOG_RX(bEpNum); |
} |
/******************************************************************************* |
* Function Name : ToggleDTOG_TX |
* Description : Toggle the DTOG_TX bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ToggleDTOG_TX(u8 bEpNum) |
{ |
_ToggleDTOG_TX(bEpNum); |
} |
/******************************************************************************* |
* Function Name : ClearDTOG_RX. |
* Description : Clear the DTOG_RX bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ClearDTOG_RX(u8 bEpNum) |
{ |
_ClearDTOG_RX(bEpNum); |
} |
/******************************************************************************* |
* Function Name : ClearDTOG_TX. |
* Description : Clear the DTOG_TX bit. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void ClearDTOG_TX(u8 bEpNum) |
{ |
_ClearDTOG_TX(bEpNum); |
} |
/******************************************************************************* |
* Function Name : SetEPAddress |
* Description : Set the endpoint address. |
* Input : bEpNum: Endpoint Number. |
* bAddr: New endpoint address. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPAddress(u8 bEpNum, u8 bAddr) |
{ |
_SetEPAddress(bEpNum, bAddr); |
} |
/******************************************************************************* |
* Function Name : GetEPAddress |
* Description : Get the endpoint address. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Endpoint address. |
*******************************************************************************/ |
u8 GetEPAddress(u8 bEpNum) |
{ |
return(_GetEPAddress(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : SetEPTxAddr |
* Description : Set the endpoint Tx buffer address. |
* Input : bEpNum: Endpoint Number. |
* wAddr: new address. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPTxAddr(u8 bEpNum, u16 wAddr) |
{ |
_SetEPTxAddr(bEpNum, wAddr); |
} |
/******************************************************************************* |
* Function Name : SetEPRxAddr |
* Description : Set the endpoint Rx buffer address. |
* Input : bEpNum: Endpoint Number. |
* wAddr: new address. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPRxAddr(u8 bEpNum, u16 wAddr) |
{ |
_SetEPRxAddr(bEpNum, wAddr); |
} |
/******************************************************************************* |
* Function Name : GetEPTxAddr |
* Description : Returns the endpoint Tx buffer address. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Rx buffer address. |
*******************************************************************************/ |
u16 GetEPTxAddr(u8 bEpNum) |
{ |
return(_GetEPTxAddr(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : GetEPRxAddr. |
* Description : Returns the endpoint Rx buffer address. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Rx buffer address. |
*******************************************************************************/ |
u16 GetEPRxAddr(u8 bEpNum) |
{ |
return(_GetEPRxAddr(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : SetEPTxCount. |
* Description : Set the Tx count. |
* Input : bEpNum: Endpoint Number. |
* wCount: new count value. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPTxCount(u8 bEpNum, u16 wCount) |
{ |
_SetEPTxCount(bEpNum, wCount); |
} |
/******************************************************************************* |
* Function Name : SetEPCountRxReg. |
* Description : Set the Count Rx Register value. |
* Input : *pdwReg: point to the register. |
* wCount: the new register value. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
#ifdef STR7xx |
void SetEPCountRxReg(u32 *pdwReg, u16 wCount) |
{ |
_SetEPCountRxReg(dwReg, wCount); |
} |
#endif |
/******************************************************************************* |
* Function Name : SetEPRxCount. |
* Description : Set the Rx count. |
* Input : bEpNum: Endpoint Number. |
* wCount: the new count value. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPRxCount(u8 bEpNum, u16 wCount) |
{ |
_SetEPRxCount(bEpNum, wCount); |
} |
/******************************************************************************* |
* Function Name : GetEPTxCount. |
* Description : Get the Tx count. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Tx count value. |
*******************************************************************************/ |
u16 GetEPTxCount(u8 bEpNum) |
{ |
return(_GetEPTxCount(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : GetEPRxCount. |
* Description : Get the Rx count. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Rx count value. |
*******************************************************************************/ |
u16 GetEPRxCount(u8 bEpNum) |
{ |
return(_GetEPRxCount(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : SetEPDblBuffAddr. |
* Description : Set the addresses of the buffer 0 and 1. |
* Input : bEpNum: Endpoint Number. |
* wBuf0Addr: new address of buffer 0. |
* wBuf1Addr: new address of buffer 1. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPDblBuffAddr(u8 bEpNum, u16 wBuf0Addr, u16 wBuf1Addr) |
{ |
_SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr); |
} |
/******************************************************************************* |
* Function Name : SetEPDblBuf0Addr. |
* Description : Set the Buffer 1 address. |
* Input : bEpNum: Endpoint Number. |
* wBuf0Addr: new address. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPDblBuf0Addr(u8 bEpNum, u16 wBuf0Addr) |
{ |
_SetEPDblBuf0Addr(bEpNum, wBuf0Addr); |
} |
/******************************************************************************* |
* Function Name : SetEPDblBuf1Addr. |
* Description : Set the Buffer 1 address. |
* Input : bEpNum: Endpoint Number. |
* wBuf1Addr: new address. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
void SetEPDblBuf1Addr(u8 bEpNum, u16 wBuf1Addr) |
{ |
_SetEPDblBuf1Addr(bEpNum, wBuf1Addr); |
} |
/******************************************************************************* |
* Function Name : GetEPDblBuf0Addr. |
* Description : Returns the address of the Buffer 0. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
u16 GetEPDblBuf0Addr(u8 bEpNum) |
{ |
return(_GetEPDblBuf0Addr(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : GetEPDblBuf1Addr |
* Description : Returns the address of the Buffer 1. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Address of the Buffer 1. |
*******************************************************************************/ |
u16 GetEPDblBuf1Addr(u8 bEpNum) |
{ |
return(_GetEPDblBuf1Addr(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : SetEPDblBuffCount. |
* Description : Set the number of bytes for a double Buffer endpoint. |
* Input : bEpNum,bDir, wCount. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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 : Set the number of bytes in the buffer 0 of a double Buffer |
* endpoint. |
* Input : bEpNum, bDir, wCount. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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 : Set the number of bytes in the buffer 0 of a double Buffer |
* endpoint. |
* Input : bEpNum, bDir, wCount. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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 : Returns the number of byte received in the buffer 0 of a |
* double Buffer endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Endpoint Buffer 0 count. |
*******************************************************************************/ |
u16 GetEPDblBuf0Count(u8 bEpNum) |
{ |
return(_GetEPDblBuf0Count(bEpNum)); |
} |
/******************************************************************************* |
* Function Name : GetEPDblBuf1Count |
* Description : Returns the number of data received in the buffer 1 of a |
* double Buffer endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : Endpoint Buffer 1 count. |
*******************************************************************************/ |
u16 GetEPDblBuf1Count(u8 bEpNum) |
{ |
return(_GetEPDblBuf1Count(bEpNum)); |
} |
#ifdef STR7xx /*STR7xx family */ |
/******************************************************************************* |
* Function Name : GetEPDblBufDir. |
* Description : gets direction of the double buffered endpoint. |
* Input : bEpNum: Endpoint Number. |
* Output : None. |
* Return : EP_DBUF_OUT, EP_DBUF_IN, |
* EP_DBUF_ERR if the endpoint counter not yet programmed. |
*******************************************************************************/ |
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 realizing it to the |
* line toggles bit SW_BUF in the double buffered endpoint |
* register. |
* Input : bEpNum, bDir. |
* Output : None. |
* Return : None. |
*******************************************************************************/ |
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 : merge two byte in a word. |
* Input : bh: byte high, bl: bytes low. |
* Output : None. |
* Return : resulted word. |
*******************************************************************************/ |
u16 ToWord(u8 bh, u8 bl) |
{ |
u16 wRet; |
wRet = (u16)bl | ((u16)bh << 8); |
return(wRet); |
} |
/******************************************************************************* |
* Function Name : ByteSwap |
* Description : Swap two byte in a word. |
* Input : wSwW: word to Swap. |
* Output : None. |
* Return : resulted word. |
*******************************************************************************/ |
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 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 2008 STMicroelectronics *****END OF FILE****/ |