Subversion Repositories NaviCtrl

Rev

Rev 196 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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