Nut/OS  5.0.5
API Reference
usb_core.h
Go to the documentation of this file.
00001 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
00002 * File Name          : usb_core.h
00003 * Author             : MCD Application Team
00004 * Version            : V3.1.1
00005 * Date               : 04/07/2010
00006 * Description        : Standard protocol processing functions prototypes
00007 ********************************************************************************
00008 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00009 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
00010 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
00011 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
00012 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
00013 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00014 *******************************************************************************/
00015 
00016 /* Define to prevent recursive inclusion -------------------------------------*/
00017 #ifndef __USB_CORE_H
00018 #define __USB_CORE_H
00019 
00020 #include <stdint.h>
00021 #define __IO volatile
00022 
00023 /* Includes ------------------------------------------------------------------*/
00024 /* Exported types ------------------------------------------------------------*/
00025 typedef enum _CONTROL_STATE
00026 {
00027   WAIT_SETUP,       /* 0 */
00028   SETTING_UP,       /* 1 */
00029   IN_DATA,          /* 2 */
00030   OUT_DATA,         /* 3 */
00031   LAST_IN_DATA,     /* 4 */
00032   LAST_OUT_DATA,    /* 5 */
00033   WAIT_STATUS_IN,   /* 7 */
00034   WAIT_STATUS_OUT,  /* 8 */
00035   STALLED,          /* 9 */
00036   PAUSE             /* 10 */
00037 } CONTROL_STATE;    /* The state machine states of a control pipe */
00038 
00039 typedef struct OneDescriptor
00040 {
00041   uint8_t *Descriptor;
00042   uint16_t Descriptor_Size;
00043 }
00044 ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
00045 /* All the request process routines return a value of this type
00046    If the return value is not SUCCESS or NOT_READY,
00047    the software will STALL the correspond endpoint */
00048 typedef enum _RESULT
00049 {
00050   USB_SUCCESS = 0,    /* Process sucessfully */
00051   USB_ERROR,
00052   USB_UNSUPPORT,
00053   USB_NOT_READY       /* The process has not been finished, endpoint will be
00054                          NAK to further rquest */
00055 } RESULT;
00056 
00057 
00058 /*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/
00059 typedef struct _ENDPOINT_INFO
00060 {
00061   /* When send data out of the device,
00062    CopyData() is used to get data buffer 'Length' bytes data
00063    if Length is 0,
00064     CopyData() returns the total length of the data
00065     if the request is not supported, returns 0
00066     (NEW Feature )
00067      if CopyData() returns -1, the calling routine should not proceed
00068      further and will resume the SETUP process by the class device
00069    if Length is not 0,
00070     CopyData() returns a pointer to indicate the data location
00071    Usb_wLength is the data remain to be sent,
00072    Usb_wOffset is the Offset of original data
00073   When receive data from the host,
00074    CopyData() is used to get user data buffer which is capable
00075    of Length bytes data to copy data from the endpoint buffer.
00076    if Length is 0,
00077     CopyData() returns the available data length,
00078    if Length is not 0,
00079     CopyData() returns user buffer address
00080    Usb_rLength is the data remain to be received,
00081    Usb_rPointer is the Offset of data buffer
00082   */
00083   uint16_t  Usb_wLength;
00084   uint16_t  Usb_wOffset;
00085   uint16_t  PacketSize;
00086   uint8_t   *(*CopyData)(uint16_t Length);
00087 }ENDPOINT_INFO;
00088 
00089 /*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/
00090 
00091 typedef struct _DEVICE
00092 {
00093   uint8_t Total_Endpoint;     /* Number of endpoints that are used */
00094   uint8_t Total_Configuration;/* Number of configuration available */
00095 }
00096 DEVICE;
00097 
00098 typedef union
00099 {
00100   uint16_t w;
00101   struct BW
00102   {
00103     uint8_t bb1;
00104     uint8_t bb0;
00105   }
00106   bw;
00107 } uint16_t_uint8_t;
00108 
00109 typedef struct _DEVICE_INFO
00110 {
00111   uint8_t USBbmRequestType;       /* bmRequestType */
00112   uint8_t USBbRequest;            /* bRequest */
00113   uint16_t_uint8_t USBwValues;         /* wValue */
00114   uint16_t_uint8_t USBwIndexs;         /* wIndex */
00115   uint16_t_uint8_t USBwLengths;        /* wLength */
00116 
00117   uint8_t ControlState;           /* of type CONTROL_STATE */
00118   uint8_t Current_Feature;
00119   uint8_t Current_Configuration;   /* Selected configuration */
00120   uint8_t Current_Interface;       /* Selected interface of current configuration */
00121   uint8_t Current_AlternateSetting;/* Selected Alternate Setting of current
00122                                      interface*/
00123 
00124   ENDPOINT_INFO Ctrl_Info;
00125 }DEVICE_INFO;
00126 
00127 typedef struct _DEVICE_PROP
00128 {
00129   void (*Init)(void);        /* Initialize the device */
00130   void (*Reset)(void);       /* Reset routine of this device */
00131 
00132   /* Device dependent process after the status stage */
00133   void (*Process_Status_IN)(void);
00134   void (*Process_Status_OUT)(void);
00135 
00136   /* Procedure of process on setup stage of a class specified request with data stage */
00137   /* All class specified requests with data stage are processed in Class_Data_Setup
00138    Class_Data_Setup()
00139     responses to check all special requests and fills ENDPOINT_INFO
00140     according to the request
00141     If IN tokens are expected, then wLength & wOffset will be filled
00142     with the total transferring bytes and the starting position
00143     If OUT tokens are expected, then rLength & rOffset will be filled
00144     with the total expected bytes and the starting position in the buffer
00145 
00146     If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT
00147 
00148    CAUTION:
00149     Since GET_CONFIGURATION & GET_INTERFACE are highly related to
00150     the individual classes, they will be checked and processed here.
00151   */
00152   RESULT (*Class_Data_Setup)(uint8_t RequestNo);
00153 
00154   /* Procedure of process on setup stage of a class specified request without data stage */
00155   /* All class specified requests without data stage are processed in Class_NoData_Setup
00156    Class_NoData_Setup
00157     responses to check all special requests and perform the request
00158 
00159    CAUTION:
00160     Since SET_CONFIGURATION & SET_INTERFACE are highly related to
00161     the individual classes, they will be checked and processed here.
00162   */
00163   RESULT (*Class_NoData_Setup)(uint8_t RequestNo);
00164 
00165   /*Class_Get_Interface_Setting
00166    This function is used by the file usb_core.c to test if the selected Interface
00167    and Alternate Setting (uint8_t Interface, uint8_t AlternateSetting) are supported by
00168    the application.
00169    This function is writing by user. It should return "SUCCESS" if the Interface
00170    and Alternate Setting are supported by the application or "UNSUPPORT" if they
00171    are not supported. */
00172 
00173   RESULT  (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting);
00174 
00175   uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
00176   uint8_t* (*GetConfigDescriptor)(uint16_t Length);
00177   uint8_t* (*GetStringDescriptor)(uint16_t Length);
00178 
00179   uint8_t* RxEP_buffer;
00180   uint8_t MaxPacketSize;
00181 
00182 }DEVICE_PROP;
00183 
00184 typedef struct _USER_STANDARD_REQUESTS
00185 {
00186   void (*User_GetConfiguration)(void);       /* Get Configuration */
00187   void (*User_SetConfiguration)(void);       /* Set Configuration */
00188   void (*User_GetInterface)(void);           /* Get Interface */
00189   void (*User_SetInterface)(void);           /* Set Interface */
00190   void (*User_GetStatus)(void);              /* Get Status */
00191   void (*User_ClearFeature)(void);           /* Clear Feature */
00192   void (*User_SetEndPointFeature)(void);     /* Set Endpoint Feature */
00193   void (*User_SetDeviceFeature)(void);       /* Set Device Feature */
00194   void (*User_SetDeviceAddress)(void);       /* Set Device Address */
00195 }
00196 USER_STANDARD_REQUESTS;
00197 
00198 /* Exported constants --------------------------------------------------------*/
00199 #define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
00200 
00201 #define Usb_rLength Usb_wLength
00202 #define Usb_rOffset Usb_wOffset
00203 
00204 #define USBwValue USBwValues.w
00205 #define USBwValue0 USBwValues.bw.bb0
00206 #define USBwValue1 USBwValues.bw.bb1
00207 #define USBwIndex USBwIndexs.w
00208 #define USBwIndex0 USBwIndexs.bw.bb0
00209 #define USBwIndex1 USBwIndexs.bw.bb1
00210 #define USBwLength USBwLengths.w
00211 #define USBwLength0 USBwLengths.bw.bb0
00212 #define USBwLength1 USBwLengths.bw.bb1
00213 
00214 /* Exported macro ------------------------------------------------------------*/
00215 /* Exported functions ------------------------------------------------------- */
00216 uint8_t Setup0_Process(void);
00217 uint8_t Post0_Process(void);
00218 uint8_t Out0_Process(void);
00219 uint8_t In0_Process(void);
00220 
00221 RESULT Standard_SetEndPointFeature(void);
00222 RESULT Standard_SetDeviceFeature(void);
00223 
00224 uint8_t *Standard_GetConfiguration(uint16_t Length);
00225 RESULT Standard_SetConfiguration(void);
00226 uint8_t *Standard_GetInterface(uint16_t Length);
00227 RESULT Standard_SetInterface(void);
00228 uint8_t *Standard_GetDescriptorData(uint16_t Length, PONE_DESCRIPTOR pDesc);
00229 
00230 uint8_t *Standard_GetStatus(uint16_t Length);
00231 RESULT Standard_ClearFeature(void);
00232 void SetDeviceAddress(uint8_t);
00233 void NOP_Process(void);
00234 
00235 extern DEVICE_PROP Device_Property;
00236 extern  USER_STANDARD_REQUESTS User_Standard_Requests;
00237 extern  DEVICE  Device_Table;
00238 extern DEVICE_INFO Device_Info;
00239 
00240 /* cells saving status during interrupt servicing */
00241 extern __IO uint16_t SaveRState;
00242 extern __IO uint16_t SaveTState;
00243 
00244 #endif /* __USB_CORE_H */
00245 
00246 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/