Rev 43 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : usb_core.h |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 10/27/2003 : V1.0 |
||
5 | * Description : Standard protocol processing functions prototypes |
||
6 | ******************************************************************************** |
||
7 | * History: |
||
8 | * 09/18/2006 : V3.0 |
||
9 | * 09/01/2006 : V2.0 |
||
10 | * 10/27/2003 : V1.0 |
||
11 | ******************************************************************************** |
||
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
||
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
||
14 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
||
15 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
||
16 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
||
17 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
18 | *******************************************************************************/ |
||
19 | |||
20 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
21 | #ifndef __USB_CORE_H |
||
22 | #define __USB_CORE_H |
||
23 | /* Includes ------------------------------------------------------------------*/ |
||
24 | /* Exported types ------------------------------------------------------------*/ |
||
25 | typedef enum _CONTROL_STATE { |
||
26 | WAIT_SETUP, /* 0 */ |
||
27 | SETTING_UP, /* 1 */ |
||
28 | IN_DATA, /* 2 */ |
||
29 | OUT_DATA, /* 3 */ |
||
30 | LAST_IN_DATA, /* 4 */ |
||
31 | LAST_OUT_DATA, /* 5 */ |
||
32 | WAIT_STATUS_IN, /* 7 */ |
||
33 | WAIT_STATUS_OUT, /* 8 */ |
||
34 | STALLED, /* 9 */ |
||
35 | PAUSE /* 10 */ |
||
36 | } CONTROL_STATE; /* The state machine states of a control pipe */ |
||
37 | |||
38 | typedef struct OneDescriptor { |
||
39 | u8 *Descriptor; |
||
40 | u16 Descriptor_Size; |
||
41 | } ONE_DESCRIPTOR, *PONE_DESCRIPTOR; |
||
42 | /* All the request process routines return a value of this type |
||
43 | If the return value is not SUCCESS or NOT_READY, |
||
44 | the software will STALL the correspond endpoint |
||
45 | */ |
||
46 | typedef enum _RESULT { |
||
47 | USB_SUCCESS = 0, /* Process sucessfully */ |
||
48 | USB_ERROR, |
||
49 | USB_UNSUPPORT, |
||
50 | USB_NOT_READY /* The process has not been finished, */ |
||
51 | /* endpoint will be NAK to further rquest */ |
||
52 | } RESULT; |
||
53 | |||
54 | |||
55 | /*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/ |
||
56 | |||
57 | typedef struct _ENDPOINT_INFO { |
||
58 | /* |
||
59 | When send data out of the device, |
||
60 | CopyData() is used to get data buffer 'Length' bytes data |
||
61 | if Length is 0, |
||
62 | CopyData() returns the total length of the data |
||
63 | if the request is not supported, returns 0 |
||
64 | (NEW Feature ) |
||
65 | if CopyData() returns -1, the calling routine should not proceed |
||
66 | further and will resume the SETUP process by the class device |
||
67 | if Length is not 0, |
||
68 | CopyData() returns a pointer to indicate the data location |
||
69 | Usb_wLength is the data remain to be sent, |
||
70 | Usb_wOffset is the Offset of original data |
||
71 | When receive data from the host, |
||
72 | CopyData() is used to get user data buffer which is capable |
||
73 | of Length bytes data to copy data from the endpoint buffer. |
||
74 | if Length is 0, |
||
75 | CopyData() returns the available data length, |
||
76 | if Length is not 0, |
||
77 | CopyData() returns user buffer address |
||
78 | Usb_rLength is the data remain to be received, |
||
79 | Usb_rPointer is the Offset of data buffer |
||
80 | */ |
||
81 | u16 Usb_wLength; |
||
82 | u16 Usb_wOffset; |
||
83 | u16 PacketSize; |
||
84 | u8 *(*CopyData)(u16 Length); |
||
85 | } ENDPOINT_INFO; |
||
86 | |||
87 | /*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/ |
||
88 | |||
89 | typedef struct _DEVICE { |
||
90 | u8 Total_Endpoint; /* Number of endpoints that are used */ |
||
91 | u8 Total_Configuration;/* Number of configuration available */ |
||
92 | } DEVICE; |
||
93 | |||
94 | typedef union { |
||
95 | u16 w; |
||
96 | struct BW { |
||
97 | u8 bb1; |
||
98 | u8 bb0; |
||
99 | } bw; |
||
100 | } u16_u8; |
||
101 | |||
102 | typedef struct _DEVICE_INFO { |
||
103 | u8 USBbmRequestType; /* bmRequestType */ |
||
104 | u8 USBbRequest; /* bRequest */ |
||
105 | u16_u8 USBwValues; /* wValue */ |
||
106 | u16_u8 USBwIndexs; /* wIndex */ |
||
107 | u16_u8 USBwLengths; /* wLength */ |
||
108 | |||
109 | u8 ControlState; /* of type CONTROL_STATE */ |
||
110 | u8 Current_Feature; |
||
111 | |||
112 | u8 Current_Configuration; /* Selected configuration */ |
||
113 | u8 Current_Interface; /* Selected interface of current configuration */ |
||
114 | u8 Current_AlternateSetting;/* Selected Alternate Setting of current interface*/ |
||
115 | |||
116 | ENDPOINT_INFO Ctrl_Info; |
||
117 | } DEVICE_INFO; |
||
118 | |||
119 | typedef struct _DEVICE_PROP { |
||
120 | void (*Init)(void); /* Initialize the device */ |
||
121 | void (*Reset)(void); /* Reset routine of this device */ |
||
122 | |||
123 | /* Device dependent process after the status stage */ |
||
124 | void (*Process_Status_IN)(void); |
||
125 | void (*Process_Status_OUT)(void); |
||
126 | |||
127 | /* Procedure of process on setup stage of a class specified request with data stage */ |
||
128 | /* All class specified requests with data stage are processed in Class_Data_Setup |
||
129 | Class_Data_Setup() |
||
130 | responses to check all special requests and fills ENDPOINT_INFO |
||
131 | according to the request |
||
132 | If IN tokens are expected, then wLength & wOffset will be filled |
||
133 | with the total transferring bytes and the starting position |
||
134 | If OUT tokens are expected, then rLength & rOffset will be filled |
||
135 | with the total expected bytes and the starting position in the buffer |
||
136 | |||
137 | If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT |
||
138 | |||
139 | CAUTION: |
||
140 | Since GET_CONFIGURATION & GET_INTERFACE are highly related to |
||
141 | the individual classes, they will be checked and processed here. |
||
142 | */ |
||
143 | RESULT (*Class_Data_Setup)(u8 RequestNo); |
||
144 | |||
145 | /* Procedure of process on setup stage of a class specified request without data stage */ |
||
146 | /* All class specified requests without data stage are processed in Class_NoData_Setup |
||
147 | Class_NoData_Setup |
||
148 | responses to check all special requests and perform the request |
||
149 | |||
150 | CAUTION: |
||
151 | Since SET_CONFIGURATION & SET_INTERFACE are highly related to |
||
152 | the individual classes, they will be checked and processed here. |
||
153 | */ |
||
154 | RESULT (*Class_NoData_Setup)(u8 RequestNo); |
||
155 | |||
156 | /*Class_Get_Interface_Setting |
||
157 | This function is used by the file usb_core.c to test if the selected Interface |
||
158 | and Alternate Setting (u8 Interface, u8 AlternateSetting) are supported by |
||
159 | the application. |
||
160 | This function is writing by user. It should return "SUCCESS" if the Interface |
||
161 | and Alternate Setting are supported by the application or "UNSUPPORT" if they |
||
162 | are not supported. */ |
||
163 | |||
164 | RESULT (*Class_Get_Interface_Setting)(u8 Interface,u8 AlternateSetting); |
||
165 | |||
166 | u8* (*GetDeviceDescriptor)(u16 Length); |
||
167 | u8* (*GetConfigDescriptor)(u16 Length); |
||
168 | u8* (*GetStringDescriptor)(u16 Length); |
||
169 | |||
170 | u8* RxEP_buffer; |
||
171 | u8 MaxPacketSize; |
||
172 | |||
173 | } DEVICE_PROP; |
||
174 | |||
175 | typedef struct _USER_STANDARD_REQUESTS { |
||
176 | void (*User_GetConfiguration)(void); /* Get Configuration */ |
||
177 | void (*User_SetConfiguration)(void); /* Set Configuration */ |
||
178 | void (*User_GetInterface)(void); |
||
179 | void (*User_SetInterface)(void); |
||
180 | void (*User_GetStatus)(void); |
||
181 | void (*User_ClearFeature)(void); |
||
182 | void (*User_SetEndPointFeature)(void); |
||
183 | void (*User_SetDeviceFeature)(void); |
||
184 | void (*User_SetDeviceAddress)(void); |
||
185 | } USER_STANDARD_REQUESTS; |
||
186 | |||
187 | |||
188 | |||
189 | |||
190 | /* Exported constants --------------------------------------------------------*/ |
||
191 | #define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT)) |
||
192 | |||
193 | #define Usb_rLength Usb_wLength |
||
194 | #define Usb_rOffset Usb_wOffset |
||
195 | |||
196 | #define USBwValue USBwValues.w |
||
197 | #define USBwValue0 USBwValues.bw.bb0 |
||
198 | #define USBwValue1 USBwValues.bw.bb1 |
||
199 | #define USBwIndex USBwIndexs.w |
||
200 | #define USBwIndex0 USBwIndexs.bw.bb0 |
||
201 | #define USBwIndex1 USBwIndexs.bw.bb1 |
||
202 | #define USBwLength USBwLengths.w |
||
203 | #define USBwLength0 USBwLengths.bw.bb0 |
||
204 | #define USBwLength1 USBwLengths.bw.bb1 |
||
205 | /* Exported macro ------------------------------------------------------------*/ |
||
206 | /* Exported functions ------------------------------------------------------- */ |
||
207 | u8 Setup0_Process(void); |
||
208 | u8 Post0_Process(void); |
||
209 | u8 Out0_Process(void); |
||
210 | u8 In0_Process(void); |
||
211 | |||
212 | RESULT Standard_SetEndPointFeature(void); |
||
213 | RESULT Standard_SetDeviceFeature(void); |
||
214 | |||
215 | u8 *Standard_GetConfiguration(u16 Length); |
||
216 | RESULT Standard_SetConfiguration(void); |
||
217 | u8 *Standard_GetInterface(u16 Length); |
||
218 | RESULT Standard_SetInterface(void); |
||
219 | u8 *Standard_GetDescriptorData(u16 Length, PONE_DESCRIPTOR pDesc); |
||
220 | |||
221 | u8 *Standard_GetStatus(u16 Length); |
||
222 | RESULT Standard_ClearFeature(void); |
||
223 | void SetDeviceAddress(u8); |
||
224 | void NOP_Process(void); |
||
225 | |||
226 | extern DEVICE_PROP Device_Property; |
||
227 | extern USER_STANDARD_REQUESTS User_Standard_Requests; |
||
228 | extern DEVICE Device_Table; |
||
229 | extern DEVICE_INFO Device_Info; |
||
230 | |||
231 | /* cells saving status during interrupt servicing */ |
||
232 | extern u16 SaveRState; |
||
233 | extern u16 SaveTState; |
||
234 | #endif /* __USB_CORE_H */ |
||
235 | |||
236 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |