/tags/V0.12/usblibrary/inc/usb_core.h |
---|
0,0 → 1,236 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_core.h |
* Author : MCD Application Team |
* Date First Issued : 10/27/2003 : V1.0 |
* Description : Standard protocol processing functions prototypes |
******************************************************************************** |
* 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_CORE_H |
#define __USB_CORE_H |
/* Includes ------------------------------------------------------------------*/ |
/* Exported types ------------------------------------------------------------*/ |
typedef enum _CONTROL_STATE { |
WAIT_SETUP, /* 0 */ |
SETTING_UP, /* 1 */ |
IN_DATA, /* 2 */ |
OUT_DATA, /* 3 */ |
LAST_IN_DATA, /* 4 */ |
LAST_OUT_DATA, /* 5 */ |
WAIT_STATUS_IN, /* 7 */ |
WAIT_STATUS_OUT, /* 8 */ |
STALLED, /* 9 */ |
PAUSE /* 10 */ |
} CONTROL_STATE; /* The state machine states of a control pipe */ |
typedef struct OneDescriptor { |
u8 *Descriptor; |
u16 Descriptor_Size; |
} ONE_DESCRIPTOR, *PONE_DESCRIPTOR; |
/* All the request process routines return a value of this type |
If the return value is not SUCCESS or NOT_READY, |
the software will STALL the correspond endpoint |
*/ |
typedef enum _RESULT { |
USB_SUCCESS = 0, /* Process sucessfully */ |
USB_ERROR, |
USB_UNSUPPORT, |
USB_NOT_READY /* The process has not been finished, */ |
/* endpoint will be NAK to further rquest */ |
} RESULT; |
/*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/ |
typedef struct _ENDPOINT_INFO { |
/* |
When send data out of the device, |
CopyData() is used to get data buffer 'Length' bytes data |
if Length is 0, |
CopyData() returns the total length of the data |
if the request is not supported, returns 0 |
(NEW Feature ) |
if CopyData() returns -1, the calling routine should not proceed |
further and will resume the SETUP process by the class device |
if Length is not 0, |
CopyData() returns a pointer to indicate the data location |
Usb_wLength is the data remain to be sent, |
Usb_wOffset is the Offset of original data |
When receive data from the host, |
CopyData() is used to get user data buffer which is capable |
of Length bytes data to copy data from the endpoint buffer. |
if Length is 0, |
CopyData() returns the available data length, |
if Length is not 0, |
CopyData() returns user buffer address |
Usb_rLength is the data remain to be received, |
Usb_rPointer is the Offset of data buffer |
*/ |
u16 Usb_wLength; |
u16 Usb_wOffset; |
u16 PacketSize; |
u8 *(*CopyData)(u16 Length); |
} ENDPOINT_INFO; |
/*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/ |
typedef struct _DEVICE { |
u8 Total_Endpoint; /* Number of endpoints that are used */ |
u8 Total_Configuration;/* Number of configuration available */ |
} DEVICE; |
typedef union { |
u16 w; |
struct BW { |
u8 bb1; |
u8 bb0; |
} bw; |
} u16_u8; |
typedef struct _DEVICE_INFO { |
u8 USBbmRequestType; /* bmRequestType */ |
u8 USBbRequest; /* bRequest */ |
u16_u8 USBwValues; /* wValue */ |
u16_u8 USBwIndexs; /* wIndex */ |
u16_u8 USBwLengths; /* wLength */ |
u8 ControlState; /* of type CONTROL_STATE */ |
u8 Current_Feature; |
u8 Current_Configuration; /* Selected configuration */ |
u8 Current_Interface; /* Selected interface of current configuration */ |
u8 Current_AlternateSetting;/* Selected Alternate Setting of current interface*/ |
ENDPOINT_INFO Ctrl_Info; |
} DEVICE_INFO; |
typedef struct _DEVICE_PROP { |
void (*Init)(void); /* Initialize the device */ |
void (*Reset)(void); /* Reset routine of this device */ |
/* Device dependent process after the status stage */ |
void (*Process_Status_IN)(void); |
void (*Process_Status_OUT)(void); |
/* Procedure of process on setup stage of a class specified request with data stage */ |
/* All class specified requests with data stage are processed in Class_Data_Setup |
Class_Data_Setup() |
responses to check all special requests and fills ENDPOINT_INFO |
according to the request |
If IN tokens are expected, then wLength & wOffset will be filled |
with the total transferring bytes and the starting position |
If OUT tokens are expected, then rLength & rOffset will be filled |
with the total expected bytes and the starting position in the buffer |
If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT |
CAUTION: |
Since GET_CONFIGURATION & GET_INTERFACE are highly related to |
the individual classes, they will be checked and processed here. |
*/ |
RESULT (*Class_Data_Setup)(u8 RequestNo); |
/* Procedure of process on setup stage of a class specified request without data stage */ |
/* All class specified requests without data stage are processed in Class_NoData_Setup |
Class_NoData_Setup |
responses to check all special requests and perform the request |
CAUTION: |
Since SET_CONFIGURATION & SET_INTERFACE are highly related to |
the individual classes, they will be checked and processed here. |
*/ |
RESULT (*Class_NoData_Setup)(u8 RequestNo); |
/*Class_Get_Interface_Setting |
This function is used by the file usb_core.c to test if the selected Interface |
and Alternate Setting (u8 Interface, u8 AlternateSetting) are supported by |
the application. |
This function is writing by user. It should return "SUCCESS" if the Interface |
and Alternate Setting are supported by the application or "UNSUPPORT" if they |
are not supported. */ |
RESULT (*Class_Get_Interface_Setting)(u8 Interface,u8 AlternateSetting); |
u8* (*GetDeviceDescriptor)(u16 Length); |
u8* (*GetConfigDescriptor)(u16 Length); |
u8* (*GetStringDescriptor)(u16 Length); |
u8* RxEP_buffer; |
u8 MaxPacketSize; |
} DEVICE_PROP; |
typedef struct _USER_STANDARD_REQUESTS { |
void (*User_GetConfiguration)(void); /* Get Configuration */ |
void (*User_SetConfiguration)(void); /* Set Configuration */ |
void (*User_GetInterface)(void); |
void (*User_SetInterface)(void); |
void (*User_GetStatus)(void); |
void (*User_ClearFeature)(void); |
void (*User_SetEndPointFeature)(void); |
void (*User_SetDeviceFeature)(void); |
void (*User_SetDeviceAddress)(void); |
} USER_STANDARD_REQUESTS; |
/* Exported constants --------------------------------------------------------*/ |
#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT)) |
#define Usb_rLength Usb_wLength |
#define Usb_rOffset Usb_wOffset |
#define USBwValue USBwValues.w |
#define USBwValue0 USBwValues.bw.bb0 |
#define USBwValue1 USBwValues.bw.bb1 |
#define USBwIndex USBwIndexs.w |
#define USBwIndex0 USBwIndexs.bw.bb0 |
#define USBwIndex1 USBwIndexs.bw.bb1 |
#define USBwLength USBwLengths.w |
#define USBwLength0 USBwLengths.bw.bb0 |
#define USBwLength1 USBwLengths.bw.bb1 |
/* Exported macro ------------------------------------------------------------*/ |
/* Exported functions ------------------------------------------------------- */ |
u8 Setup0_Process(void); |
u8 Post0_Process(void); |
u8 Out0_Process(void); |
u8 In0_Process(void); |
RESULT Standard_SetEndPointFeature(void); |
RESULT Standard_SetDeviceFeature(void); |
u8 *Standard_GetConfiguration(u16 Length); |
RESULT Standard_SetConfiguration(void); |
u8 *Standard_GetInterface(u16 Length); |
RESULT Standard_SetInterface(void); |
u8 *Standard_GetDescriptorData(u16 Length, PONE_DESCRIPTOR pDesc); |
u8 *Standard_GetStatus(u16 Length); |
RESULT Standard_ClearFeature(void); |
void SetDeviceAddress(u8); |
void NOP_Process(void); |
extern DEVICE_PROP Device_Property; |
extern USER_STANDARD_REQUESTS User_Standard_Requests; |
extern DEVICE Device_Table; |
extern DEVICE_INFO Device_Info; |
/* cells saving status during interrupt servicing */ |
extern u16 SaveRState; |
extern u16 SaveTState; |
#endif /* __USB_CORE_H */ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/usblibrary/inc/usb_def.h |
---|
0,0 → 1,78 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_def.h |
* Author : MCD Application Team |
* Date First Issued : 10/27/2003 : V1.0 |
* Description : Definitions related to USB Core |
******************************************************************************** |
* 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_DEF_H |
#define __USB_DEF_H |
/* Includes ------------------------------------------------------------------*/ |
/* Exported types ------------------------------------------------------------*/ |
typedef enum _RECIPIENT_TYPE { |
DEVICE_RECIPIENT, /* Recipient device */ |
INTERFACE_RECIPIENT, /* Recipient interface */ |
ENDPOINT_RECIPIENT, /* Recipient endpoint */ |
OTHER_RECIPIENT |
} RECIPIENT_TYPE; |
typedef enum _STANDARD_REQUESTS { |
GET_STATUS = 0, |
CLEAR_FEATURE, |
RESERVED1, |
SET_FEATURE, |
RESERVED2, |
SET_ADDRESS, |
GET_DESCRIPTOR, |
SET_DESCRIPTOR, |
GET_CONFIGURATION, |
SET_CONFIGURATION, |
GET_INTERFACE, |
SET_INTERFACE, |
TOTAL_sREQUEST, /* Total number of Standard request */ |
SYNCH_FRAME = 12 |
} STANDARD_REQUESTS; |
/* Definition of "USBwValue" */ |
typedef enum _DESCRIPTOR_TYPE { |
DEVICE_DESCRIPTOR = 1, |
CONFIG_DESCRIPTOR, |
STRING_DESCRIPTOR, |
INTERFACE_DESCRIPTOR, |
ENDPOINT_DESCRIPTOR |
} DESCRIPTOR_TYPE; |
/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ |
typedef enum _FEATURE_SELECTOR { |
ENDPOINT_STALL, |
DEVICE_REMOTE_WAKEUP |
} FEATURE_SELECTOR; |
/* Exported constants --------------------------------------------------------*/ |
/* Definition of "USBbmRequestType" */ |
#define REQUEST_TYPE 0x60 /* Mask to get request type */ |
#define STANDARD_REQUEST 0x00 /* Standard request */ |
#define CLASS_REQUEST 0x20 /* Class request */ |
#define VENDOR_REQUEST 0x40 /* Vendor request */ |
#define RECIPIENT 0x1F /* Mask to get recipient */ |
/* Exported macro ------------------------------------------------------------*/ |
/* Exported functions ------------------------------------------------------- */ |
#endif /* __USB_DEF_H */ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/usblibrary/inc/usb_init.h |
---|
0,0 → 1,51 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_init.h |
* 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_INIT_H |
#define __USB_INIT_H |
/* Includes ------------------------------------------------------------------*/ |
/* Exported types ------------------------------------------------------------*/ |
/* Exported constants --------------------------------------------------------*/ |
/* Exported macro ------------------------------------------------------------*/ |
/* Exported functions ------------------------------------------------------- */ |
void USB_Init(void); |
/* External variables --------------------------------------------------------*/ |
/* The number of current endpoint, it will be used to specify an endpoint */ |
extern u8 EPindex; |
/* The number of current device, it is an index to the Device_Table */ |
/*extern u8 Device_no; */ |
/* Points to the DEVICE_INFO structure of current device */ |
/* The purpose of this register is to speed up the execution */ |
extern DEVICE_INFO* pInformation; |
/* Points to the DEVICE_PROP structure of current device */ |
/* The purpose of this register is to speed up the execution */ |
extern 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 */ |
extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; |
extern u16 SaveState ; |
extern u16 wInterrupt_Mask; |
#endif /* __USB_INIT_H */ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/usblibrary/inc/usb_int.h |
---|
0,0 → 1,32 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_int.h |
* Author : MCD Application Team |
* Date First Issued : 10/27/2003 : V1.0 |
* Description : Endpoint CTR (Low and High) interrupt's service routines |
* prototypes |
******************************************************************************** |
* 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_INT_H |
#define __USB_INT_H |
/* Includes ------------------------------------------------------------------*/ |
/* Exported types ------------------------------------------------------------*/ |
/* Exported constants --------------------------------------------------------*/ |
/* Exported macro ------------------------------------------------------------*/ |
/* Exported functions ------------------------------------------------------- */ |
void CTR_LP(void); |
void CTR_HP(void); |
/* External variables --------------------------------------------------------*/ |
#endif /* __USB_INT_H */ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/usblibrary/inc/usb_lib.h |
---|
0,0 → 1,38 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_lib.h |
* Author : MCD Application Team |
* Date First Issued : 10/27/2003 : V1.0 |
* Description : USB library include files |
******************************************************************************** |
* 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_LIB_H |
#define __USB_LIB_H |
/* Includes ------------------------------------------------------------------*/ |
#include "usb_type.h" |
#include "usb_regs.h" |
#include "usb_def.h" |
#include "usb_core.h" |
#include "usb_init.h" |
#include "usb_mem.h" |
#include "usb_int.h" |
/* Exported types ------------------------------------------------------------*/ |
/* Exported constants --------------------------------------------------------*/ |
/* Exported macro ------------------------------------------------------------*/ |
/* Exported functions ------------------------------------------------------- */ |
/* External variables --------------------------------------------------------*/ |
#endif /* __USB_LIB_H */ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/usblibrary/inc/usb_mem.h |
---|
0,0 → 1,35 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_mem.h |
* Author : MCD Application Team |
* Date First Issued : 10/27/2003 : V1.0 |
* Description : Utility prototypes functions for memory/PMA transfers |
******************************************************************************** |
* 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_MEM_H |
#define __USB_MEM_H |
/* Includes ------------------------------------------------------------------*/ |
/* Exported types ------------------------------------------------------------*/ |
/* Exported constants --------------------------------------------------------*/ |
/* Exported macro ------------------------------------------------------------*/ |
/* Exported functions ------------------------------------------------------- */ |
void UserToPMABufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr, u16 wNBytes); |
void PMAToUserBufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr, u16 wNBytes); |
/* External variables --------------------------------------------------------*/ |
#endif /*__USB_MEM_H*/ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/usblibrary/inc/usb_regs.h |
---|
0,0 → 1,724 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_regs.h |
* Author : MCD Application Team |
* Date First Issued : 10/27/2003 : V1.0 |
* Description : Interface prototype 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_REGS_H |
#define __USB_REGS_H |
/* Includes ------------------------------------------------------------------*/ |
/* Exported types ------------------------------------------------------------*/ |
typedef enum _EP_DBUF_DIR{ /* double buffered endpoint direction */ |
EP_DBUF_ERR, |
EP_DBUF_OUT, |
EP_DBUF_IN |
}EP_DBUF_DIR; |
/* endpoint buffer number */ |
enum EP_BUF_NUM{ |
EP_NOBUF, |
EP_BUF0, |
EP_BUF1 |
}; |
/* Exported constants --------------------------------------------------------*/ |
#ifdef STR7xx |
#ifdef STR71x /*STR71x family*/ |
#define RegBase (0xC0008800L) /* USB_IP Peripheral Registers base address */ |
#define PMAAddr (0xC0008000L) /* USB_IP Packet Memory Area base address */ |
#endif /*end of STR71x family*/ |
#ifdef STR75x /*STR75x family*/ |
#define RegBase (0xFFFFA800L) /* USB_IP Peripheral Registers base address */ |
#define PMAAddr (0xFFFFA000L) /* USB_IP Packet Memory Area base address */ |
#endif /*end of STR75x family*/ |
#endif /*end of STR7xx family*/ |
#ifdef STR91x /*STR91x family*/ |
#ifdef STR91x_USB_BUFFERED |
#define RegBase (0x60000800L) /* USB_IP Peripheral Registers base address */ |
#define PMAAddr (0x60000000L) /* USB_IP Packet Memory Area base address */ |
#endif |
#ifdef STR91x_USB_NON_BUFFERED |
#define RegBase (0x70000800L) /* USB_IP Peripheral Registers base address */ |
#define PMAAddr (0x70000000L) /* USB_IP Packet Memory Area base address */ |
#endif |
#endif |
/* General registers */ |
#define CNTR ((volatile unsigned *)(RegBase + 0x40)) /* Control register */ |
#define ISTR ((volatile unsigned *)(RegBase + 0x44)) /* Interrupt status register */ |
#define FNR ((volatile unsigned *)(RegBase + 0x48)) /* Frame number register */ |
#define DADDR ((volatile unsigned *)(RegBase + 0x4C)) /* Device address register */ |
#define BTABLE ((volatile unsigned *)(RegBase + 0x50)) /* Buffer Table address register */ |
#ifdef STR91x /*STR91x family DMA registers*/ |
#define DMACR1 ((volatile unsigned *)(RegBase + 0x54)) /* DMA control register 1 */ |
#define DMACR2 ((volatile unsigned *)(RegBase + 0x58)) /* DMA control register 2 */ |
#define DMACR3 ((volatile unsigned *)(RegBase + 0x5C)) /* DMA control register 3 */ |
#define DMABSIZE ((volatile unsigned *)(RegBase + 0x60))/* DMA burst size register */ |
#define DMALLI ((volatile unsigned *)(RegBase + 0x64)) /* DMA LLI register */ |
#endif |
/* Endpoint registers */ |
#define EP0REG ((volatile unsigned *)(RegBase)) /* endpoint 0 register address */ |
/* endpoints enumeration */ |
#define ENDP0 ((u8)0) |
#define ENDP1 ((u8)1) |
#define ENDP2 ((u8)2) |
#define ENDP3 ((u8)3) |
#define ENDP4 ((u8)4) |
#define ENDP5 ((u8)5) |
#define ENDP6 ((u8)6) |
#define ENDP7 ((u8)7) /* Only 8 endpoints for STR75x Family */ |
#define ENDP8 ((u8)8) |
#define ENDP9 ((u8)9) /* Only 10 endpoints for STR91x Family */ |
#define ENDP10 ((u8)10) |
#define ENDP11 ((u8)11) |
#define ENDP12 ((u8)12) |
#define ENDP13 ((u8)13) |
#define ENDP14 ((u8)14) |
#define ENDP15 ((u8)15) |
/*******************************************************************************/ |
/* ISTR interrupt events */ |
/*******************************************************************************/ |
#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */ |
#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */ |
#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */ |
#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */ |
#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */ |
#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */ |
#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */ |
#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */ |
#ifdef STR91x /*STR91x family*/ |
#define ISTR_SZDPR (0x0080) /* Short or Zero-Length Received Data Packet */ |
#endif |
#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */ |
#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */ |
#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */ |
#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/ |
#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */ |
#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */ |
#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */ |
#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */ |
#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */ |
#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */ |
#ifdef STR91x /*STR91x family*/ |
#define CLR_SZDPR (~ISTR_SZDPR)/* clear SZDPR bit */ |
#endif |
/*******************************************************************************/ |
/* CNTR control register bits definitions */ |
/*******************************************************************************/ |
#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */ |
#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */ |
#define CNTR_ERRM (0x2000) /* ERRor Mask */ |
#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */ |
#define CNTR_SUSPM (0x0800) /* SUSPend Mask */ |
#define CNTR_RESETM (0x0400) /* RESET Mask */ |
#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */ |
#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */ |
#ifdef STR91x /*STR91x family*/ |
#define CNTR_SZDPRM (0x0080) /* Short or Zero-Length Received Data Packet Mask*/ |
#endif |
#define CNTR_RESUME (0x0010) /* RESUME request */ |
#define CNTR_FSUSP (0x0008) /* Force SUSPend */ |
#define CNTR_LPMODE (0x0004) /* Low-power MODE */ |
#define CNTR_PDWN (0x0002) /* Power DoWN */ |
#define CNTR_FRES (0x0001) /* Force USB RESet */ |
/*******************************************************************************/ |
/* FNR Frame Number Register bit definitions */ |
/*******************************************************************************/ |
#define FNR_RXDP (0x8000) /* status of D+ data line */ |
#define FNR_RXDM (0x4000) /* status of D- data line */ |
#define FNR_LCK (0x2000) /* LoCKed */ |
#define FNR_LSOF (0x1800) /* Lost SOF */ |
#define FNR_FN (0x07FF) /* Frame Number */ |
/*******************************************************************************/ |
/* DADDR Device ADDRess bit definitions */ |
/*******************************************************************************/ |
#define DADDR_EF (0x80) |
#define DADDR_ADD (0x7F) |
/*===============================================================================*/ |
/* Endpoint register */ |
/*===============================================================================*/ |
/* bit positions */ |
#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */ |
#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */ |
#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */ |
#define EP_SETUP (0x0800) /* EndPoint SETUP */ |
#define EP_T_FIELD (0x0600) /* EndPoint TYPE */ |
#define EP_KIND (0x0100) /* EndPoint KIND */ |
#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */ |
#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */ |
#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */ |
#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */ |
/* EndPoint REGister MASK (no toggle fields) */ |
#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD) |
/* EP_TYPE[1:0] EndPoint TYPE */ |
#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */ |
#define EP_BULK (0x0000) /* EndPoint BULK */ |
#define EP_CONTROL (0x0200) /* EndPoint CONTROL */ |
#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */ |
#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */ |
#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK) |
/* EP_KIND EndPoint KIND */ |
#define EPKIND_MASK (~EP_KIND & EPREG_MASK) |
/* STAT_TX[1:0] STATus for TX transfer */ |
#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */ |
#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */ |
#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */ |
#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */ |
#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */ |
#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */ |
#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK) |
/* STAT_RX[1:0] STATus for RX transfer */ |
#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */ |
#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */ |
#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */ |
#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */ |
#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */ |
#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */ |
#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK) |
/* Exported macro ------------------------------------------------------------*/ |
/*----------------------------------------------------------------*/ |
/* SetCNTR */ |
/*----------------------------------------------------------------*/ |
#define _SetCNTR(wRegValue) (*CNTR = (u16)wRegValue) |
/*----------------------------------------------------------------*/ |
/* SetISTR */ |
/*----------------------------------------------------------------*/ |
#define _SetISTR(wRegValue) (*ISTR = (u16)wRegValue) |
/*----------------------------------------------------------------*/ |
/* SetDADDR */ |
/*----------------------------------------------------------------*/ |
#define _SetDADDR(wRegValue) (*DADDR = (u16)wRegValue) |
/*----------------------------------------------------------------*/ |
/* SetBTABLE */ |
/*----------------------------------------------------------------*/ |
#define _SetBTABLE(wRegValue)(*BTABLE = (u16)(wRegValue & 0xFFF8)) |
/*----------------------------------------------------------------*/ |
/* GetCNTR */ |
/*----------------------------------------------------------------*/ |
#define _GetCNTR() ((u16) *CNTR) |
/*----------------------------------------------------------------*/ |
/* GetISTR */ |
/*----------------------------------------------------------------*/ |
#define _GetISTR() ((u16) *ISTR) |
/*----------------------------------------------------------------*/ |
/* GetFNR */ |
/*----------------------------------------------------------------*/ |
#define _GetFNR() ((u16) *FNR) |
/*----------------------------------------------------------------*/ |
/* GetDADDR */ |
/*----------------------------------------------------------------*/ |
#define _GetDADDR() ((u16) *DADDR) |
/*----------------------------------------------------------------*/ |
/* GetBTABLE */ |
/*----------------------------------------------------------------*/ |
#define _GetBTABLE() ((u16) *BTABLE) |
/*----------------------------------------------------------------*/ |
/* SetENDPOINT */ |
/*----------------------------------------------------------------*/ |
#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \ |
(u16)wRegValue) |
/*----------------------------------------------------------------*/ |
/* GetENDPOINT */ |
/*----------------------------------------------------------------*/ |
#define _GetENDPOINT(bEpNum) ((u16)(*(EP0REG + bEpNum))) |
/*----------------------------------------------------------------*/ |
/* SetEPType */ |
/* sets the type in the endpoint register(bits EP_TYPE[1:0]) */ |
/* IN : bEpNum = endpoint number */ |
/* wType = type definition */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\ |
((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType))) |
/*----------------------------------------------------------------*/ |
/* GetEPType */ |
/* gets the type in the endpoint register(bits EP_TYPE[1:0]) */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: type definition */ |
/*----------------------------------------------------------------*/ |
#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD) |
/*----------------------------------------------------------------*/ |
/* SetEPTxStatus */ |
/* sets the status for tx transfer (bits STAT_TX[1:0]) */ |
/* IN : bEpNum = endpoint number */ |
/* wState = new state */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPTxStatus(bEpNum,wState) {\ |
register u16 _wRegVal; \ |
_wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\ |
/* toggle first bit ? */ \ |
if((EPTX_DTOG1 & wState)!= 0) \ |
_wRegVal ^= EPTX_DTOG1; \ |
/* toggle second bit ? */ \ |
if((EPTX_DTOG2 & wState)!= 0) \ |
_wRegVal ^= EPTX_DTOG2; \ |
_SetENDPOINT(bEpNum, _wRegVal); \ |
} /* _SetEPTxStatus */ |
/*----------------------------------------------------------------*/ |
/* SetEPRxStatus */ |
/* sets the status for rx transfer (bits STAT_TX[1:0]) */ |
/* IN : bEpNum = endpoint number */ |
/* wState = new state */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPRxStatus(bEpNum,wState) {\ |
register u16 _wRegVal; \ |
\ |
_wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\ |
/* toggle first bit ? */ \ |
if((EPRX_DTOG1 & wState)!= 0) \ |
_wRegVal ^= EPRX_DTOG1; \ |
/* toggle second bit ? */ \ |
if((EPRX_DTOG2 & wState)!= 0) \ |
_wRegVal ^= EPRX_DTOG2; \ |
_SetENDPOINT(bEpNum, _wRegVal); \ |
} /* _SetEPRxStatus */ |
/*----------------------------------------------------------------*/ |
/* GetEPTxStatus / GetEPRxStatus */ |
/* gets the status for tx/rx transfer (bits STAT_TX[1:0]/STAT_RX[1:0]) */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: u16 status */ |
/*----------------------------------------------------------------*/ |
#define _GetEPTxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPTX_STAT) |
#define _GetEPRxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPRX_STAT) |
/*----------------------------------------------------------------*/ |
/* SetEPTxValid / SetEPRxValid */ |
/* sets directly the VALID tx/rx-status into the enpoint register */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID)) |
#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID)) |
/*----------------------------------------------------------------*/ |
/* GetTxStallStatus / GetRxStallStatus */ |
/* checks stall condition in an endpoint */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: TRUE = endpoint in stall condition */ |
/*----------------------------------------------------------------*/ |
#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \ |
== EP_TX_STALL) |
#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \ |
== EP_RX_STALL) |
/*----------------------------------------------------------------*/ |
/* SetEP_KIND / ClearEP_KIND */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \ |
(_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK)) |
#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \ |
(_GetENDPOINT(bEpNum) & EPKIND_MASK))) |
/*----------------------------------------------------------------*/ |
/* Set_Status_Out / Clear_Status_Out */ |
/* sets/clears directly STATUS_OUT bit in the endpoint register */ |
/* to be used only during control transfers */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum) |
#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum) |
/*----------------------------------------------------------------*/ |
/* SetEPDoubleBuff / ClearEPDoubleBuff */ |
/* sets/clears directly EP_KIND bit in the endpoint register */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum) |
#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum) |
/*----------------------------------------------------------------*/ |
/* ClearEP_CTR_RX / ClearEP_CTR_TX */ |
/* clears bit CTR_RX / CTR_TX in the endpoint register */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\ |
_GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK)) |
#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\ |
_GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK)) |
/*----------------------------------------------------------------*/ |
/* ToggleDTOG_RX / ToggleDTOG_TX */ |
/* toggles DTOG_RX / DTOG_TX bit in the endpoint register */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \ |
EP_DTOG_RX | _GetENDPOINT(bEpNum) & EPREG_MASK)) |
#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \ |
EP_DTOG_TX | _GetENDPOINT(bEpNum) & EPREG_MASK)) |
/*----------------------------------------------------------------*/ |
/* ClearDTOG_RX / ClearDTOG_TX */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\ |
_ToggleDTOG_RX(bEpNum) |
#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\ |
_ToggleDTOG_TX(bEpNum) |
/*----------------------------------------------------------------*/ |
/* SetEPAddress */ |
/* sets address in an endpoint register */ |
/* IN : bEpNum = endpoint number */ |
/* bAddr = address */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\ |
_GetENDPOINT(bEpNum) & EPREG_MASK | bAddr) |
/*----------------------------------------------------------------*/ |
/* GetEPAddress */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _GetEPAddress(bEpNum) ((u8)(_GetENDPOINT(bEpNum) & EPADDR_FIELD)) |
/*----------------------------------------------------------------*/ |
#ifdef STR7xx /*STR7xx family*/ |
#define _pEPTxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr)) |
#define _pEPTxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr)) |
#define _pEPRxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr)) |
#define _pEPRxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr)) |
#endif |
#ifdef STR91x /*STR91x family*/ |
/* Pointers on endpoint(bEpNum) Count & Addr registers on PMA */ |
#define _pEPBufCount(bEpNum) ((u32 *)(_GetBTABLE()+bEpNum*8 + 4 + PMAAddr)) |
#define _pEPBufAddr(bEpNum) ((u32 *)(_GetBTABLE()+bEpNum*8 + PMAAddr)) |
#endif |
/*----------------------------------------------------------------*/ |
/* SetEPTxAddr / SetEPRxAddr */ |
/* sets address of the tx/rx buffer */ |
/* IN : bEpNum = endpoint number */ |
/* wAddr = address to be set ( must be word aligned ) */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#ifdef STR7xx /*STR7xx family*/ |
#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1)) |
#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1)) |
#endif |
#ifdef STR91x /*STR91x family*/ |
#define _SetEPTxAddr(bEpNum , wAddr) {\ |
*_pEPBufAddr(bEpNum) &=0xFFFF0000; \ |
*_pEPBufAddr(bEpNum) |=((wAddr)&0x0FFFC);\ |
} |
#define _SetEPRxAddr(bEpNum, wAddr) {\ |
*_pEPBufAddr(bEpNum) &=0x0000FFFF;\ |
*_pEPBufAddr(bEpNum) |=((wAddr<<16)&0xFFFC0000);\ |
} |
#endif |
/*----------------------------------------------------------------*/ |
/* GetEPTxAddr / GetEPRxAddr */ |
/* gets address of the tx/rx buffer */ |
/* IN : bEpNum = endpoint number */ |
/* IN : */ |
/* OUT: address of the buffer */ |
/*----------------------------------------------------------------*/ |
#ifdef STR7xx /*STR7xx family*/ |
#define _GetEPTxAddr(bEpNum) ((u16)*_pEPTxAddr(bEpNum)) |
#define _GetEPRxAddr(bEpNum) ((u16)*_pEPRxAddr(bEpNum)) |
#endif |
#ifdef STR91x /*STR91x family*/ |
#define _GetEPTxAddr(bEpNum) ((u16)(*_pEPBufAddr(bEpNum) &0x0000FFFF)) |
#define _GetEPRxAddr(bEpNum) ((u16)((*_pEPBufAddr(bEpNum)&0xFFFF0000)>>16)) |
#endif |
/*----------------------------------------------------------------*/ |
/* SetEPCountRxReg */ |
/* sets counter of rx buffer with no. of blocks */ |
/* IN : pdwReg = pointer to counter */ |
/* wCount = counter */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#ifdef STR7xx /*STR7xx family*/ |
#define _BlocksOf32(dwReg,wCount,wNBlocks) {\ |
wNBlocks = wCount >> 5;\ |
if((wCount & 0x1f) == 0)\ |
wNBlocks--;\ |
*pdwReg = (u32)((wNBlocks << 10) | 0x8000);\ |
}/* _BlocksOf32 */ |
#define _BlocksOf2(dwReg,wCount,wNBlocks) {\ |
wNBlocks = wCount >> 1;\ |
if((wCount & 0x1) != 0)\ |
wNBlocks++;\ |
*pdwReg = (u32)(wNBlocks << 10);\ |
}/* _BlocksOf2 */ |
#define _SetEPCountRxReg(dwReg,wCount) {\ |
u16 wNBlocks;\ |
if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\ |
else {_BlocksOf2(dwReg,wCount,wNBlocks);}\ |
}/* _SetEPCountRxReg */ |
#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\ |
u32 *pdwReg = _pEPTxCount(bEpNum); \ |
_SetEPCountRxReg(pdwReg, wCount);\ |
} |
#endif |
/*----------------------------------------------------------------*/ |
/* SetEPTxCount / SetEPRxCount */ |
/* sets counter for the tx/rx buffer */ |
/* IN : bEpNum = endpoint number */ |
/* wCount = counter value */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#ifdef STR7xx /*STR7xx family*/ |
#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount) |
#define _SetEPRxCount(bEpNum,wCount) {\ |
u32 *pdwReg = _pEPRxCount(bEpNum); \ |
_SetEPCountRxReg(pdwReg, wCount);\ |
} |
#endif |
#ifdef STR91x /*STR91x family*/ |
#define _SetEPTxCount(bEpNum,wCount) {\ |
*_pEPBufCount(bEpNum) &=0xFFFFFC00;\ |
*_pEPBufCount(bEpNum) |=wCount;\ |
} |
#define _SetEPRxCount(bEpNum,wCount) {\ |
u32 BLsize=0;\ |
u32 Blocks;\ |
if (wCount < 64) Blocks = wCount>>1;\ |
else\ |
{\ |
BLsize = 0x80000000;\ |
Blocks = wCount>>6;\ |
}\ |
*_pEPBufCount(bEpNum) &=~0x80000000;\ |
*_pEPBufCount(bEpNum) |=BLsize;\ |
*_pEPBufCount(bEpNum) &=0x83FFFFFF;\ |
*_pEPBufCount(bEpNum) |=Blocks<<26;\ |
*_pEPBufCount(bEpNum) &=0xFC00FFFF;\ |
} |
#endif |
/*----------------------------------------------------------------*/ |
/* GetEPTxCount / GetEPRxCount */ |
/* gets counter of the tx buffer */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: counter value */ |
/*----------------------------------------------------------------*/ |
#ifdef STR7xx /*STR7xx family*/ |
#define _GetEPTxCount(bEpNum)((u16)(*_pEPTxCount(bEpNum)) & 0x3ff) |
#define _GetEPRxCount(bEpNum)((u16)(*_pEPRxCount(bEpNum)) & 0x3ff) |
#endif |
#ifdef STR91x /*STR91x family*/ |
#define _GetEPTxCount(bEpNum) (u16)(*_pEPBufCount(bEpNum)&0x3FF) |
#define _GetEPRxCount(bEpNum) (u16)((*_pEPBufCount(bEpNum)&0x3FF0000)>>16) |
#endif |
/*----------------------------------------------------------------*/ |
/* SetEPDblBuf0Addr / SetEPDblBuf1Addr */ |
/* sets buffer 0/1 address in a double buffer endpoint */ |
/* IN : bEpNum = endpoint number */ |
/* wBuf0Addr = buffer 0 address */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);} |
#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);} |
/*----------------------------------------------------------------*/ |
/* SetEPDblBuffAddr */ |
/* sets addresses in a double buffer endpoint */ |
/* IN : bEpNum = endpoint number */ |
/* wBuf0Addr = buffer 0 address */ |
/* wBuf1Addr = buffer 1 address */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \ |
_SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\ |
_SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\ |
} /* _SetEPDblBuffAddr */ |
/*----------------------------------------------------------------*/ |
/* GetEPDblBuf0Addr / GetEPDblBuf1Addr */ |
/* gets buffer 0/1 address of a double buffer endpoint */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum)) |
#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum)) |
/*----------------------------------------------------------------*/ |
/* SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count */ |
/* sets both buffers or buff0 or buff1 counter for double buffering */ |
/* IN : bEpNum = endpoint number */ |
/* bDir = endpoint dir EP_DBUF_OUT = OUT */ |
/* EP_DBUF_IN = IN */ |
/* wCount = counter value */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#ifdef STR7xx /*STR7xx family*/ |
#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \ |
if(bDir == EP_DBUF_OUT)\ |
/* OUT endpoint */ \ |
{_SetEPRxDblBuf0Count(bEpNum,wCount);} \ |
else if(bDir == EP_DBUF_IN)\ |
/* IN endpoint */ \ |
*_pEPTxCount(bEpNum) = (u32)wCount; \ |
} /* SetEPDblBuf0Count*/ |
#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \ |
if(bDir == EP_DBUF_OUT)\ |
/* OUT endpoint */ \ |
{_SetEPRxCount(bEpNum,wCount);}\ |
else if(bDir == EP_DBUF_IN)\ |
/* IN endpoint */\ |
*_pEPRxCount(bEpNum) = (u32)wCount; \ |
} /* SetEPDblBuf1Count */ |
#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\ |
_SetEPDblBuf0Count(bEpNum, bDir, wCount); \ |
_SetEPDblBuf1Count(bEpNum, bDir, wCount); \ |
} /* _SetEPDblBuffCount */ |
#endif |
/*----------------------------------------------------------------*/ |
/* GetEPDblBuf0Count / GetEPDblBuf1Count */ |
/* gets buffer 0/1 rx/tx counter for double buffering */ |
/* IN : bEpNum = endpoint number */ |
/* OUT: none */ |
/*----------------------------------------------------------------*/ |
#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum)) |
#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum)) |
/* External variables --------------------------------------------------------*/ |
extern volatile u16 wIstr; /* ISTR register last read value */ |
/* Exported functions ------------------------------------------------------- */ |
void SetCNTR(u16 /*wRegValue*/); |
void SetISTR(u16 /*wRegValue*/); |
void SetDADDR(u16 /*wRegValue*/); |
void SetBTABLE(u16 /*wRegValue*/); |
void SetBTABLE(u16 /*wRegValue*/); |
u16 GetCNTR(void); |
u16 GetISTR(void); |
u16 GetFNR(void); |
u16 GetDADDR(void); |
u16 GetBTABLE(void); |
void SetENDPOINT(u8 /*bEpNum*/,u16 /*wRegValue*/); |
u16 GetENDPOINT(u8 /*bEpNum*/); |
void SetEPType(u8 /*bEpNum*/,u16 /*wType*/); |
u16 GetEPType(u8 /*bEpNum*/); |
void SetEPTxStatus(u8 /*bEpNum*/,u16 /*wState*/); |
void SetEPRxStatus(u8 /*bEpNum*/,u16 /*wState*/); |
void SetDouBleBuffEPStall(u8 /*bEpNum*/,u8 bDir); |
u16 GetEPTxStatus(u8 /*bEpNum*/); |
u16 GetEPRxStatus(u8 /*bEpNum*/); |
void SetEPTxValid(u8 /*bEpNum*/); |
void SetEPRxValid(u8 /*bEpNum*/); |
u16 GetTxStallStatus(u8 /*bEpNum*/); |
u16 GetRxStallStatus(u8 /*bEpNum*/); |
void SetEP_KIND(u8 /*bEpNum*/); |
void ClearEP_KIND(u8 /*bEpNum*/); |
void Set_Status_Out(u8 /*bEpNum*/); |
void Clear_Status_Out(u8 /*bEpNum*/); |
void SetEPDoubleBuff(u8 /*bEpNum*/); |
void ClearEPDoubleBuff(u8 /*bEpNum*/); |
void ClearEP_CTR_RX(u8 /*bEpNum*/); |
void ClearEP_CTR_TX(u8 /*bEpNum*/); |
void ToggleDTOG_RX(u8 /*bEpNum*/); |
void ToggleDTOG_TX(u8 /*bEpNum*/); |
void ClearDTOG_RX(u8 /*bEpNum*/); |
void ClearDTOG_TX(u8 /*bEpNum*/); |
void SetEPAddress(u8 /*bEpNum*/,u8 /*bAddr*/); |
u8 GetEPAddress(u8 /*bEpNum*/); |
void SetEPTxAddr(u8 /*bEpNum*/,u16 /*wAddr*/); |
void SetEPRxAddr(u8 /*bEpNum*/,u16 /*wAddr*/); |
u16 GetEPTxAddr(u8 /*bEpNum*/); |
u16 GetEPRxAddr(u8 /*bEpNum*/); |
void SetEPCountRxReg(u32 * /*pdwReg*/, u16 /*wCount*/); |
void SetEPTxCount(u8 /*bEpNum*/,u16 /*wCount*/); |
void SetEPRxCount(u8 /*bEpNum*/,u16 /*wCount*/); |
u16 GetEPTxCount(u8 /*bEpNum*/); |
u16 GetEPRxCount(u8 /*bEpNum*/); |
void SetEPDblBuf0Addr(u8 /*bEpNum*/,u16 /*wBuf0Addr*/); |
void SetEPDblBuf1Addr(u8 /*bEpNum*/,u16 /*wBuf1Addr*/); |
void SetEPDblBuffAddr(u8 /*bEpNum*/,u16 /*wBuf0Addr*/,u16 /*wBuf1Addr*/); |
u16 GetEPDblBuf0Addr(u8 /*bEpNum*/); |
u16 GetEPDblBuf1Addr(u8 /*bEpNum*/); |
void SetEPDblBuffCount(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/); |
void SetEPDblBuf0Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/); |
void SetEPDblBuf1Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/); |
u16 GetEPDblBuf0Count(u8 /*bEpNum*/); |
u16 GetEPDblBuf1Count(u8 /*bEpNum*/); |
EP_DBUF_DIR GetEPDblBufDir(u8 /*bEpNum*/); |
void FreeUserBuffer(u8 bEpNum/*bEpNum*/,u8 bDir); |
u16 ToWord(u8,u8); |
u16 ByteSwap(u16); |
#ifdef STR91x /*STR91x family*/ |
/* DMA Functions */ |
void SetDMABurstTxSize(u8 /*DestBsize*/); |
void SetDMABurstRxSize(u8 /*SrcBsize*/); |
void DMAUnlinkedModeTxConfig(u8 /*bEpNum*/ ,u8 /*index*/); |
void DMAUnlinkedModeTxEnable(u8 /*index*/); |
void DMAUnlinkedModeTxDisable(u8 /*index*/); |
void DMAUnlinkedModeRxEnable(u8 /*bEpNum*/); |
void DMAUnlinkedModeRxDisable(u8 /*bEpNum*/); |
void DMALinkedModeRxConfig(u8 /*bEpNum*/); |
void DMALinkedModeTxConfig(u8 /*bEpNum*/); |
void DMALinkedModeRxEnable(void); |
void DMALinkedModeTxEnable(void); |
void DMALinkedModeRxDisable(void); |
void DMALinkedModeTxDisable(void); |
void DMASynchEnable(void); |
void DMASynchDisable(void); |
void SetDMALLITxLength(u8 /*length*/); |
void SetDMALLIRxLength(u8 /*length*/ ); |
void SetDMALLIRxPacketNum(u8 /*PacketNum*/); |
u8 GetDMALLIRxPacketNum(void); |
#endif /* End of STR91x family*/ |
#endif /* __USB_REGS_H */ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/usblibrary/inc/usb_type.h |
---|
0,0 → 1,122 |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
* File Name : usb_type.h |
* Author : MCD Application Team |
* Date First Issued : 10/27/2003 : V1.0 |
* Description : Type definitions used by the STR USB Library |
******************************************************************************** |
* 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. |
*******************************************************************************/ |
/* Define to prevent recursive inclusion -------------------------------------*/ |
#ifndef __USB_TYPE_H |
#define __USB_TYPE_H |
/* Includes ------------------------------------------------------------------*/ |
#include "usb_conf.h" |
/* Exported types ------------------------------------------------------------*/ |
/* Exported constants --------------------------------------------------------*/ |
#ifndef NULL |
#define NULL ((void *)0) |
#endif |
#ifdef STR71x /*STR71x family*/ |
#ifndef _71x_type_H |
typedef unsigned long u32; |
typedef unsigned short u16; |
typedef unsigned char u8; |
typedef signed long s32; |
typedef signed short s16; |
typedef signed char s8; |
typedef volatile unsigned long vu32; |
typedef volatile unsigned short vu16; |
typedef volatile unsigned char vu8; |
typedef volatile signed long vs32; |
typedef volatile signed short vs16; |
typedef volatile signed char vs8; |
typedef enum { FALSE = 0, TRUE = !FALSE } bool; |
typedef enum { RESET = 0, SET = !RESET } FlagStatus; |
typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState; |
typedef enum { INDIRECT = 0, DIRECT = !INDIRECT} RegisterAccess; |
#endif |
#endif /* End of STR71x family*/ |
#ifdef STR91x /*STR91x family*/ |
#ifndef __91x_type_H |
typedef long long u64; |
typedef unsigned long u32; |
typedef unsigned short u16; |
typedef unsigned char u8; |
typedef signed long s32; |
typedef signed short s16; |
typedef signed char s8; |
typedef volatile unsigned long vu32; |
typedef volatile unsigned short vu16; |
typedef volatile unsigned char vu8; |
typedef volatile signed long vs32; |
typedef volatile signed short vs16; |
typedef volatile signed char vs8; |
typedef enum { FALSE = 0, TRUE = !FALSE } bool; |
typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus; |
typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState; |
typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus; |
#endif |
#endif /* End of STR91x family*/ |
#ifdef STR75x /*STR75x family*/ |
#ifndef __75x_TYPE_H |
typedef signed long s32; |
typedef signed short s16; |
typedef signed char s8; |
typedef volatile signed long vs32; |
typedef volatile signed short vs16; |
typedef volatile signed char vs8; |
typedef unsigned long u32; |
typedef unsigned short u16; |
typedef unsigned char u8; |
typedef volatile unsigned long vu32; |
typedef volatile unsigned short vu16; |
typedef volatile unsigned char vu8; |
typedef volatile unsigned long const vuc32; /* Read Only */ |
typedef volatile unsigned short const vuc16; /* Read Only */ |
typedef volatile unsigned char const vuc8; /* Read Only */ |
typedef enum { FALSE = 0, TRUE = !FALSE } bool; |
typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus; |
typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState; |
typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus; |
#endif |
#endif /* End of STR75x family*/ |
/* Exported macro ------------------------------------------------------------*/ |
/* Exported functions ------------------------------------------------------- */ |
/* External variables --------------------------------------------------------*/ |
#endif /* __USB_TYPE_H */ |
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
/tags/V0.12/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.12/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.12/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.12/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.12/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****/ |