Subversion Repositories NaviCtrl

Rev

Rev 1 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 196
1
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
1
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
2
* File Name          : usb_core.c
2
* File Name          : usb_core.c
3
* Author             : MCD Application Team
3
* Author             : MCD Application Team
-
 
4
* Version            : V4.0.0
4
* Date First Issued  : 10/27/2003 : V1.0
5
* Date               : 09/29/2008
5
* Description        : Standard protocol processing (USB v2.0)
6
* Description        : Standard protocol processing (USB v2.0).
6
********************************************************************************
7
********************************************************************************
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
8
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
9
* 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,
10
* 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
11
* 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
12
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
17
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
13
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
14
*******************************************************************************/
19
 
15
 
20
/* Includes ------------------------------------------------------------------*/
16
/* Includes ------------------------------------------------------------------*/
-
 
17
/* Private typedef -----------------------------------------------------------*/
-
 
18
/* Private define ------------------------------------------------------------*/
-
 
19
/* Private macro -------------------------------------------------------------*/
-
 
20
/* Private variables ---------------------------------------------------------*/
-
 
21
/* Private function prototypes -----------------------------------------------*/
-
 
22
/* Private functions ---------------------------------------------------------*/
-
 
23
 
-
 
24
/* Includes ------------------------------------------------------------------*/
21
#include "usb_lib.h"
25
#include "usb_lib.h"
22
#include "usb_mem.h"
26
#include "usb_mem.h"
23
#include "usb_conf.h"
27
#include "usb_conf.h"
-
 
28
 
24
/* Private typedef -----------------------------------------------------------*/
29
/* Private typedef -----------------------------------------------------------*/
25
/* Private define ------------------------------------------------------------*/
30
/* Private define ------------------------------------------------------------*/
26
#define ValBit(VAR,Place)    (VAR & (1<<Place))
31
#define ValBit(VAR,Place)    (VAR & (1<<Place))
27
#define SetBit(VAR,Place)    ( VAR |= (1<<Place) )
32
#define SetBit(VAR,Place)    (VAR |= (1<<Place))
28
#define ClrBit(VAR,Place)    ( VAR &= ((1<<Place)^255) )
33
#define ClrBit(VAR,Place)    (VAR &= ((1<<Place)^255))
-
 
34
 
-
 
35
#define Send0LengthData() { \
-
 
36
    _SetEPTxCount(ENDP0, 0); \
-
 
37
    vSetEPTxStatus(EP_TX_VALID); \
-
 
38
  }
29
 
39
 
30
#define Send0LengthData() {     \
-
 
31
        _SetEPTxCount(ENDP0, 0);        \
40
#define vSetEPRxStatus(st)   (SaveRState = st)
32
        vSetEPTxStatus(EP_TX_VALID);    \
-
 
33
        }
41
#define vSetEPTxStatus(st)   (SaveTState = st)
34
 
42
 
35
#define vSetEPRxStatus(st)      (SaveRState = st)
43
#define USB_StatusIn()       Send0LengthData()
36
#define vSetEPTxStatus(st)      (SaveTState = st)
44
#define USB_StatusOut()      vSetEPRxStatus(EP_RX_VALID)
37
 
-
 
38
#define USB_StatusIn()  Send0LengthData()
-
 
39
#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
45
 
40
 
46
#define StatusInfo0          StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
41
#define StatusInfo0 StatusInfo.bw.bb1   /* Reverse bb0 & bb1 */
47
#define StatusInfo1          StatusInfo.bw.bb0
42
#define StatusInfo1 StatusInfo.bw.bb0
48
 
43
/* Private macro -------------------------------------------------------------*/
49
/* Private macro -------------------------------------------------------------*/
44
/* Private variables ---------------------------------------------------------*/
50
/* Private variables ---------------------------------------------------------*/
45
u16_u8 StatusInfo;
51
u16_u8 StatusInfo;
-
 
52
bool Data_Mul_MaxPacketSize = FALSE;
46
/* Private function prototypes -----------------------------------------------*/
53
/* Private function prototypes -----------------------------------------------*/
-
 
54
static void DataStageOut(void);
-
 
55
static void DataStageIn(void);
-
 
56
static void NoData_Setup0(void);
-
 
57
static void Data_Setup0(void);
47
/* Private functions ---------------------------------------------------------*/
58
/* Private functions ---------------------------------------------------------*/
48
 
59
 
49
/*******************************************************************************
60
/*******************************************************************************
50
* Function Name  : Standard_GetConfiguration
61
* Function Name  : Standard_GetConfiguration.
51
* Description    : Return the current configuration variable address
62
* Description    : Return the current configuration variable address.
52
* Input          : Length - How many bytes are needed.
63
* Input          : Length - How many bytes are needed.
53
* Output         : If "Length" is 0, return the length of configuration value
64
* Output         : None.
54
                   If "Length" is not 0, return the data buffer address.
-
 
55
* Return         : Return 1 , if the request is invalid when "Length" is 0
65
* Return         : Return 1 , if the request is invalid when "Length" is 0.
56
                   Return "Buffer" if the "Length" is not 0
66
*                  Return "Buffer" if the "Length" is not 0.
57
*******************************************************************************/
67
*******************************************************************************/
58
u8 *Standard_GetConfiguration(u16 Length)
68
u8 *Standard_GetConfiguration(u16 Length)
59
{
69
{
60
  if (Length == 0){
70
  if (Length == 0)
-
 
71
  {
-
 
72
    pInformation->Ctrl_Info.Usb_wLength =
61
    pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_Configuration);
73
      sizeof(pInformation->Current_Configuration);
-
 
74
 
62
                return 0;
75
    return 0;
63
  }
76
  }
64
        pUser_Standard_Requests->User_GetConfiguration();
77
  pUser_Standard_Requests->User_GetConfiguration();
65
        return (u8 *)&pInformation->Current_Configuration;
78
  return (u8 *)&pInformation->Current_Configuration;
66
}
79
}
-
 
80
 
67
/*******************************************************************************
81
/*******************************************************************************
68
* Function Name  : Standard_SetConfiguration
82
* Function Name  : Standard_SetConfiguration.
69
* Description    : This routine is called to set the configuration value
83
* Description    : This routine is called to set the configuration value
70
                   Then each class should configure device themself
84
*                  Then each class should configure device themself.
71
* Input          :
85
* Input          : None.
72
* Output         :
86
* Output         : None.
73
* Return         : Return USB_SUCCESS, if the request is performed
87
* Return         : Return USB_SUCCESS, if the request is performed.
74
                   Return USB_UNSUPPORT, if the request is invalid
88
*                  Return USB_UNSUPPORT, if the request is invalid.
75
*******************************************************************************/
89
*******************************************************************************/
76
RESULT Standard_SetConfiguration(void)
90
RESULT Standard_SetConfiguration(void)
77
{
91
{
-
 
92
  if (pInformation->USBwValue0 <= Device_Table.Total_Configuration
-
 
93
      && pInformation->USBwValue1 == 0 && pInformation->USBwIndex == 0)
-
 
94
    /*call Back usb spec 2.0*/
-
 
95
  {
-
 
96
    pInformation->Current_Configuration = pInformation->USBwValue0;
-
 
97
    pUser_Standard_Requests->User_SetConfiguration();
-
 
98
    return USB_SUCCESS;
-
 
99
  }
-
 
100
  else
-
 
101
  {
-
 
102
    return USB_UNSUPPORT;
-
 
103
  }
-
 
104
}
78
 
-
 
79
        if (pInformation->USBwValue0 <= Device_Table.Total_Configuration && pInformation->USBwValue1==0
-
 
80
            && pInformation->USBwIndex==0) /*call Back usb spec 2.0*/
-
 
81
        {
-
 
82
                pInformation->Current_Configuration = pInformation->USBwValue0;
-
 
83
                pUser_Standard_Requests->User_SetConfiguration();
-
 
84
                return USB_SUCCESS;
-
 
85
        }
-
 
86
        else
-
 
87
        return USB_UNSUPPORT;
-
 
88
}
105
 
89
/*******************************************************************************
106
/*******************************************************************************
90
* Function Name  : Standard_GetInterface
107
* Function Name  : Standard_GetInterface.
91
* Description    : Return the Alternate Setting of the current interface
108
* Description    : Return the Alternate Setting of the current interface.
92
* Input          : Length - How many bytes are needed
109
* Input          : Length - How many bytes are needed.
93
* Output         : If "Length" is 0, return the length of interface value
-
 
94
                   If "Length" is not 0, return the data buffer address
110
* Output         : None.
95
* Return         : Return 0, if the request is invalid when "Length" is 0
111
* Return         : Return 0, if the request is invalid when "Length" is 0.
96
                   Return "Buffer" if the "Length" is not 0
112
*                  Return "Buffer" if the "Length" is not 0.
97
*******************************************************************************/
113
*******************************************************************************/
98
u8 *Standard_GetInterface(u16 Length)
114
u8 *Standard_GetInterface(u16 Length)
99
{
115
{
100
  if (Length == 0){
116
  if (Length == 0)
-
 
117
  {
-
 
118
    pInformation->Ctrl_Info.Usb_wLength =
101
        pInformation->Ctrl_Info.Usb_wLength =   sizeof(pInformation->Current_AlternateSetting);
119
      sizeof(pInformation->Current_AlternateSetting);
102
    return 0;
120
    return 0;
103
  }
121
  }
104
        pUser_Standard_Requests->User_GetInterface();
122
  pUser_Standard_Requests->User_GetInterface();
105
        return (u8 *)&pInformation->Current_AlternateSetting;
123
  return (u8 *)&pInformation->Current_AlternateSetting;
106
}
124
}
-
 
125
 
107
/*******************************************************************************
126
/*******************************************************************************
108
* Function Name  : Standard_SetInterface
127
* Function Name  : Standard_SetInterface.
109
* Description    : This routine is called to set the interface
128
* Description    : This routine is called to set the interface.
110
                   Then each class should configure the interface them self
129
*                  Then each class should configure the interface them self.
111
* Input          :
130
* Input          : None.
112
* Output         :
131
* Output         : None.
113
* Return         : Return USB_SUCCESS, if the request is performed
132
* Return         : - Return USB_SUCCESS, if the request is performed.
114
                   Return USB_UNSUPPORT, if the request is invalid
133
*                  - Return USB_UNSUPPORT, if the request is invalid.
115
*******************************************************************************/
134
*******************************************************************************/
116
RESULT Standard_SetInterface(void)
135
RESULT Standard_SetInterface(void)
117
{
136
{
118
        RESULT                  Re;
137
  RESULT Re;
119
        /*Test if the specified Interface and Alternate Setting are supported by the application Firmware*/
138
  /*Test if the specified Interface and Alternate Setting are supported by
-
 
139
  the application Firmware*/
120
        Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,pInformation->USBwValue0);
140
  Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,
-
 
141
       pInformation->USBwValue0);
121
 
142
 
122
        if(pInformation->Current_Configuration!=0 )
143
  if (pInformation->Current_Configuration != 0 )
123
        {
144
  {
124
                if (Re!= USB_SUCCESS || pInformation->USBwIndex1!=0 || pInformation->USBwValue1!=0)
145
    if (Re != USB_SUCCESS || pInformation->USBwIndex1 != 0
-
 
146
        || pInformation->USBwValue1 != 0)
-
 
147
    {
125
                                return  USB_UNSUPPORT;
148
      return  USB_UNSUPPORT;
-
 
149
    }
126
                else if ( Re == USB_SUCCESS)
150
    else if (Re == USB_SUCCESS)
127
                {
151
    {
128
                 pUser_Standard_Requests->User_SetInterface();
152
      pUser_Standard_Requests->User_SetInterface();
129
                 pInformation->Current_Interface = pInformation->USBwIndex0;
153
      pInformation->Current_Interface = pInformation->USBwIndex0;
130
                 pInformation->Current_AlternateSetting = pInformation->USBwValue0;
154
      pInformation->Current_AlternateSetting = pInformation->USBwValue0;
131
                 return USB_SUCCESS;
155
      return USB_SUCCESS;
132
                }
156
    }
133
                       
-
 
134
        }
157
  }
135
 
-
 
136
 return USB_UNSUPPORT;
158
  return USB_UNSUPPORT;
137
}
159
}
-
 
160
 
138
/*******************************************************************************
161
/*******************************************************************************
139
* Function Name  : Standard_GetStatus
162
* Function Name  : Standard_GetStatus.
140
* Description    : Copy the device request data to "StatusInfo buffer"
163
* Description    : Copy the device request data to "StatusInfo buffer".
141
* Input          : Length - How many bytes are needed
164
* Input          : - Length - How many bytes are needed.
142
* Output         : If "Length" is 0, return the length of status data
165
* Output         : None.
143
                   If "Length" is not 0, return number of bytes have been copied
-
 
144
* Return         : Return 0, if the request is at end of data block,
166
* Return         : Return 0, if the request is at end of data block,
145
                   or is invalid when "Length" is 0
167
*                  or is invalid when "Length" is 0.
146
*******************************************************************************/
168
*******************************************************************************/
147
u8 *Standard_GetStatus(u16 Length)
169
u8 *Standard_GetStatus(u16 Length)
148
{
170
{
149
  if (Length == 0){
171
  if (Length == 0)
-
 
172
  {
150
          pInformation->Ctrl_Info.Usb_wLength =2;
173
    pInformation->Ctrl_Info.Usb_wLength = 2;
151
                return 0;
174
    return 0;
152
  }
175
  }
153
 
176
 
154
        StatusInfo.w = 0;
177
  StatusInfo.w = 0;
155
                                /* Reset Status Information */
178
  /* Reset Status Information */
156
       
179
 
157
        if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/*Get Device Status */
180
  if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
-
 
181
  {
-
 
182
    /*Get Device Status */
158
                u8      Feature = pInformation->Current_Feature;
183
    u8 Feature = pInformation->Current_Feature;
159
 
184
 
-
 
185
    /* Remote Wakeup enabled */
160
                if (ValBit(Feature, 5))
186
    if (ValBit(Feature, 5))
-
 
187
    {
161
                        SetBit(StatusInfo0, 1); /* Remote Wakeup enabled */
188
      SetBit(StatusInfo0, 1);
162
 
189
    }
163
               
190
 
-
 
191
    /* Bus-powered */
164
                if (ValBit(Feature, 6))
192
    if (ValBit(Feature, 6))
-
 
193
    {
-
 
194
      ClrBit(StatusInfo0, 0);
-
 
195
    }
165
                        SetBit(StatusInfo0, 0);  /* Self-powered */
196
    else /* Self-powered */
166
                else
197
    {
167
                        ClrBit(StatusInfo0, 0); /* Bus-powered */
198
      SetBit(StatusInfo0, 0);
-
 
199
    }
168
        }
200
  }
-
 
201
  /*Interface Status*/
169
        else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))/*Interface Status*/
202
  else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
-
 
203
  {
170
                        return (u8 *)&StatusInfo;
204
    return (u8 *)&StatusInfo;
171
 
205
  }
-
 
206
  /*Get EndPoint Status*/
172
        else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {/*Get EndPoint Status*/
207
  else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
-
 
208
  {
173
                u8      Related_Endpoint;
209
    u8 Related_Endpoint;
174
                u8      wIndex0 = pInformation->USBwIndex0;
210
    u8 wIndex0 = pInformation->USBwIndex0;
175
 
211
 
176
                Related_Endpoint = (wIndex0 & 0x0f);
212
    Related_Endpoint = (wIndex0 & 0x0f);
177
                        if (ValBit(wIndex0, 7)) {
213
    if (ValBit(wIndex0, 7))
-
 
214
    {
178
                                /* IN endpoint */
215
      /* IN endpoint */
179
                                if (_GetTxStallStatus( Related_Endpoint ))
216
      if (_GetTxStallStatus(Related_Endpoint))
-
 
217
      {
180
                                SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
218
        SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
-
 
219
      }
181
                        }
220
    }
182
                        else {
221
    else
-
 
222
    {
183
                                /* OUT endpoint */
223
      /* OUT endpoint */
184
                                if (_GetRxStallStatus( Related_Endpoint ))
224
      if (_GetRxStallStatus(Related_Endpoint))
-
 
225
      {
185
                                SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
226
        SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
-
 
227
      }
186
                        }
228
    }
187
               
229
 
188
        }
230
  }
189
        else
231
  else
-
 
232
  {
190
                return NULL;
233
    return NULL;
-
 
234
  }
191
        pUser_Standard_Requests->User_GetStatus();
235
  pUser_Standard_Requests->User_GetStatus();
192
        return (u8 *)&StatusInfo;
236
  return (u8 *)&StatusInfo;
193
}
237
}
-
 
238
 
194
/*******************************************************************************
239
/*******************************************************************************
195
* Function Name  : Standard_ClearFeature
240
* Function Name  : Standard_ClearFeature.
196
* Description    : Clear or disable a specific feature
241
* Description    : Clear or disable a specific feature.
197
* Input          :
242
* Input          : None.
198
* Output         :
243
* Output         : None.
199
* Return         :
244
* Return         : - Return USB_SUCCESS, if the request is performed.
-
 
245
*                  - Return USB_UNSUPPORT, if the request is invalid.
200
*******************************************************************************/
246
*******************************************************************************/
201
RESULT Standard_ClearFeature(void)
247
RESULT Standard_ClearFeature(void)
202
{
248
{
203
       
-
 
204
        u32     Type_Rec = Type_Recipient;
-
 
205
        u32     Status;
-
 
206
 
-
 
207
       
-
 
208
        if ( Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT) ) {/*Device Clear Feature*/
-
 
209
                ClrBit(pInformation->Current_Feature, 5);
-
 
210
                return USB_SUCCESS;
-
 
211
        }
-
 
212
        else if ( Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT) ) {/*EndPoint Clear Feature*/
-
 
213
                DEVICE* pDev;
-
 
214
                u32     Related_Endpoint;
-
 
215
                u32     wIndex0;
-
 
216
                u32     rEP;
-
 
217
 
-
 
218
                if (pInformation->USBwValue != ENDPOINT_STALL || pInformation->USBwIndex1!=0)
-
 
219
                        return USB_UNSUPPORT;
-
 
220
 
-
 
221
                pDev = &Device_Table;
-
 
222
                wIndex0 = pInformation->USBwIndex0;
-
 
223
                rEP = wIndex0 & ~0x80;
-
 
224
                Related_Endpoint = ENDP0 + rEP;
-
 
225
 
-
 
226
                if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/*Get Status of endpoint & stall the request if
-
 
227
                                                                                                      the related_ENdpoint is Disabled*/
-
 
228
                else Status =_GetEPRxStatus(Related_Endpoint);
-
 
229
 
-
 
230
                if (rEP >= pDev->Total_Endpoint || Status==0 || pInformation->Current_Configuration==0)
-
 
231
                        return USB_UNSUPPORT;
-
 
232
 
-
 
233
       
-
 
234
                if (wIndex0 & 0x80) {           /* IN endpoint */
-
 
235
                  if (_GetTxStallStatus(Related_Endpoint )){
-
 
236
                                ClearDTOG_TX(Related_Endpoint);
-
 
237
                                SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
-
 
238
                  }
-
 
239
                }
-
 
240
                else {                                                  /* OUT endpoint */
-
 
241
                        if (_GetRxStallStatus(Related_Endpoint)){
-
 
242
                                if (Related_Endpoint == ENDP0) {
-
 
243
                                        /* After clear the STALL, enable the default endpoint receiver */
-
 
244
                                        SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
-
 
245
                                        _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
-
 
246
                                }
-
 
247
                                else
-
 
248
                                {
-
 
249
                                        ClearDTOG_RX(Related_Endpoint);
-
 
250
                                        _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
-
 
251
                                }
-
 
252
                        }
-
 
253
                }
-
 
254
                pUser_Standard_Requests->User_ClearFeature();
-
 
255
                return USB_SUCCESS;
-
 
256
        }
-
 
-
 
249
 
-
 
250
  u32 Type_Rec = Type_Recipient;
-
 
251
  u32 Status;
-
 
252
 
-
 
253
 
-
 
254
  if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT))
-
 
255
  {/*Device Clear Feature*/
-
 
256
    ClrBit(pInformation->Current_Feature, 5);
-
 
257
    pUser_Standard_Requests->User_ClearFeature();
-
 
258
    return USB_SUCCESS;
-
 
259
  }
-
 
260
  else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
-
 
261
  {/*EndPoint Clear Feature*/
-
 
262
    DEVICE* pDev;
-
 
263
    u32 Related_Endpoint;
-
 
264
    u32 wIndex0;
-
 
265
    u32 rEP;
-
 
266
 
-
 
267
    if (pInformation->USBwValue != ENDPOINT_STALL
-
 
268
        || pInformation->USBwIndex1 != 0)
-
 
269
    {
-
 
270
      return USB_UNSUPPORT;
-
 
271
    }
-
 
272
 
-
 
273
    pDev = &Device_Table;
-
 
274
    wIndex0 = pInformation->USBwIndex0;
-
 
275
    rEP = wIndex0 & ~0x80;
-
 
276
    Related_Endpoint = ENDP0 + rEP;
-
 
277
 
-
 
278
    if (ValBit(pInformation->USBwIndex0, 7))
-
 
279
    { /*Get Status of endpoint & stall the request if the related_ENdpoint is
-
 
280
            Disabled*/
-
 
281
      Status = _GetEPTxStatus(Related_Endpoint);
-
 
282
    }
-
 
283
    else
-
 
284
    {
-
 
285
      Status = _GetEPRxStatus(Related_Endpoint);
-
 
286
    }
-
 
287
 
-
 
288
    if (rEP >= pDev->Total_Endpoint || Status == 0
-
 
289
        || pInformation->Current_Configuration == 0)
-
 
290
    {
-
 
291
      return USB_UNSUPPORT;
-
 
292
    }
-
 
293
 
-
 
294
 
-
 
295
    if (wIndex0 & 0x80)
-
 
296
    {  /* IN endpoint */
-
 
297
      if (_GetTxStallStatus(Related_Endpoint ))
-
 
298
      {
-
 
299
        ClearDTOG_TX(Related_Endpoint);
-
 
300
        SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
-
 
301
      }
-
 
302
    }
-
 
303
    else
-
 
304
    {       /* OUT endpoint */
-
 
305
      if (_GetRxStallStatus(Related_Endpoint))
-
 
306
      {
-
 
307
        if (Related_Endpoint == ENDP0)
-
 
308
        {
-
 
309
          /* After clear the STALL, enable the default endpoint receiver */
-
 
310
          SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
-
 
311
          _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
-
 
312
        }
-
 
313
        else
-
 
314
        {
-
 
315
          ClearDTOG_RX(Related_Endpoint);
-
 
316
          _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
-
 
317
        }
-
 
318
      }
-
 
319
    }
-
 
320
    pUser_Standard_Requests->User_ClearFeature();
-
 
321
    return USB_SUCCESS;
-
 
322
  }
257
 
323
 
258
        return USB_UNSUPPORT;
324
  return USB_UNSUPPORT;
-
 
325
}
259
}
326
 
260
/*******************************************************************************
327
/*******************************************************************************
261
* Function Name  : Standard_SetEndPointFeature
328
* Function Name  : Standard_SetEndPointFeature
262
* Description    : Set or enable a specific feature of EndPoint
329
* Description    : Set or enable a specific feature of EndPoint
263
* Input          :
330
* Input          : None.
264
* Output         :
331
* Output         : None.
265
* Return         :
332
* Return         : - Return USB_SUCCESS, if the request is performed.
-
 
333
*                  - Return USB_UNSUPPORT, if the request is invalid.
266
*******************************************************************************/
334
*******************************************************************************/
267
RESULT Standard_SetEndPointFeature(void)
335
RESULT Standard_SetEndPointFeature(void)
268
{
336
{
269
        u32    wIndex0;
337
  u32    wIndex0;
270
        u32    Related_Endpoint;
338
  u32    Related_Endpoint;
271
        u32    rEP;
339
  u32    rEP;
272
        u32   Status;
340
  u32   Status;
273
 
341
 
274
                wIndex0 = pInformation->USBwIndex0;
342
  wIndex0 = pInformation->USBwIndex0;
275
                rEP = wIndex0 & ~0x80;
343
  rEP = wIndex0 & ~0x80;
276
                Related_Endpoint = ENDP0 + rEP;
344
  Related_Endpoint = ENDP0 + rEP;
277
 
345
 
-
 
346
  if (ValBit(pInformation->USBwIndex0, 7))
278
                if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/* get Status of endpoint & stall the request if
347
  { /* get Status of endpoint & stall the request if the related_ENdpoint is
-
 
348
        Disabled*/
279
                                                                                                    the related_ENdpoint is Disabled*/
349
    Status = _GetEPTxStatus(Related_Endpoint);
-
 
350
  }
-
 
351
  else
-
 
352
  {
280
                else Status =_GetEPRxStatus(Related_Endpoint);
353
    Status = _GetEPRxStatus(Related_Endpoint);
-
 
354
  }
-
 
355
  if (Related_Endpoint >= Device_Table.Total_Endpoint
-
 
356
      || pInformation->USBwValue != 0 || Status == 0
-
 
357
      || pInformation->Current_Configuration == 0)
-
 
358
  {
-
 
359
    return USB_UNSUPPORT;
-
 
360
  }
-
 
361
  else
-
 
362
  {
-
 
363
    if (wIndex0 & 0x80)
-
 
364
    {  /* IN endpoint */
-
 
365
      _SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
-
 
366
    }
281
 
367
 
-
 
368
    else
-
 
369
    {    /* OUT endpoint */
-
 
370
      _SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
-
 
371
    }
-
 
372
  }
-
 
373
  pUser_Standard_Requests->User_SetEndPointFeature();
-
 
374
  return USB_SUCCESS;
282
 
375
}
283
 
-
 
284
                if (Related_Endpoint >= Device_Table.Total_Endpoint || pInformation->USBwValue !=0 || Status==0 ||
-
 
285
                        pInformation->Current_Configuration==0 /*&& Related_Endpoint!=ENDP0)*/)
-
 
286
                        return USB_UNSUPPORT;
-
 
287
                else {
-
 
288
 
-
 
289
                        if (wIndex0 & 0x80) {           /* IN endpoint */
-
 
290
                                _SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
-
 
291
                        }
-
 
292
                               
-
 
293
                        else {                          /* OUT endpoint */
-
 
294
                                _SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
-
 
295
                        }
-
 
296
                }
-
 
297
        pUser_Standard_Requests->User_SetEndPointFeature();
-
 
298
        return USB_SUCCESS;
-
 
299
}
376
 
300
/*******************************************************************************
377
/*******************************************************************************
301
* Function Name  : Standard_SetDeviceFeature
378
* Function Name  : Standard_SetDeviceFeature.
302
* Description    : Set or enable a specific feature of Device
379
* Description    : Set or enable a specific feature of Device.
303
* Input          :
380
* Input          : None.
304
* Output         :
381
* Output         : None.
-
 
382
* Return         : - Return USB_SUCCESS, if the request is performed.
305
* Return         :
383
*                  - Return USB_UNSUPPORT, if the request is invalid.
306
*******************************************************************************/
384
*******************************************************************************/
307
RESULT Standard_SetDeviceFeature(void)
385
RESULT Standard_SetDeviceFeature(void)
308
{
386
{
309
                        SetBit(pInformation->Current_Feature, 5);
387
  SetBit(pInformation->Current_Feature, 5);
310
                        pUser_Standard_Requests->User_SetDeviceFeature();
388
  pUser_Standard_Requests->User_SetDeviceFeature();
311
                        return USB_SUCCESS;
389
  return USB_SUCCESS;
312
 
390
 
313
}
391
}
314
 
392
 
315
/*******************************************************************************
393
/*******************************************************************************
316
* Function Name  : Standard_GetDescriptorData
394
* Function Name  : Standard_GetDescriptorData.
317
* Description    : Standard_GetDescriptorData is used for descriptors transfer
395
* Description    : Standard_GetDescriptorData is used for descriptors transfer.
318
*                : This routine is used for the descriptors resident in Flash or RAM
396
*                : This routine is used for the descriptors resident in Flash
-
 
397
*                  or RAM
319
                  pDesc can be in either Flash or RAM
398
*                  pDesc can be in either Flash or RAM
320
                  The purpose of this routine is to have a versatile way to response
399
*                  The purpose of this routine is to have a versatile way to
321
                  descriptors request. It allows user to generate certain descriptors
400
*                  response descriptors request. It allows user to generate
-
 
401
*                  certain descriptors with software or read descriptors from
322
                  with software or read descriptors from external storage part by part.
402
*                  external storage part by part.
323
* Input          : Length - Length of the data in this transfer
403
* Input          : - Length - Length of the data in this transfer.
324
                   pDesc - A pointer points to descriptor struct.
404
*                  - pDesc - A pointer points to descriptor struct.
325
                          The structure gives the initial address of the
405
*                  The structure gives the initial address of the descriptor and
326
                          descriptor and its original size
406
*                  its original size.
-
 
407
* Output         : None.
327
* Output         : Address of a part of the descriptor pointed by the Usb_wOffset
408
* Return         : Address of a part of the descriptor pointed by the Usb_
328
                   The buffer pointed by this address contains at least Length bytes
409
*                  wOffset The buffer pointed by this address contains at least
329
* Return         :
410
*                  Length bytes.
330
*******************************************************************************/
411
*******************************************************************************/
331
 
-
 
332
u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
412
u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
333
{
413
{
334
        u32      wOffset;
414
  u32  wOffset;
335
 
415
 
336
        wOffset = pInformation->Ctrl_Info.Usb_wOffset;
416
  wOffset = pInformation->Ctrl_Info.Usb_wOffset;
-
 
417
  if (Length == 0)
337
        if (Length == 0) {
418
  {
338
                pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
419
    pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
339
                return 0;
420
    return 0;
340
        }
421
  }
341
 
422
 
342
        return pDesc->Descriptor + wOffset;
423
  return pDesc->Descriptor + wOffset;
-
 
424
}
343
}
425
 
344
/*******************************************************************************
426
/*******************************************************************************
345
* Function Name  : DataStageOut
427
* Function Name  : DataStageOut.
346
* Description    : Data stage of a Control Write Transfer
428
* Description    : Data stage of a Control Write Transfer.
347
* Input          :
429
* Input          : None.
348
* Output         :
430
* Output         : None.
349
* Return         :
431
* Return         : None.
350
*******************************************************************************/
432
*******************************************************************************/
351
void DataStageOut(void)
433
void DataStageOut(void)
352
{
434
{
353
        ENDPOINT_INFO   *pEPinfo = &pInformation->Ctrl_Info;
435
  ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
354
        u32     save_rLength;
436
  u32 save_rLength;
-
 
437
 
-
 
438
  save_rLength = pEPinfo->Usb_rLength;
-
 
439
 
-
 
440
  if (pEPinfo->CopyData && save_rLength)
-
 
441
  {
-
 
442
    u8 *Buffer;
-
 
443
    u32 Length;
355
 
444
 
-
 
445
    Length = pEPinfo->PacketSize;
-
 
446
    if (Length > save_rLength)
-
 
447
    {
-
 
448
      Length = save_rLength;
-
 
449
    }
-
 
450
 
-
 
451
    Buffer = (*pEPinfo->CopyData)(Length);
-
 
452
    pEPinfo->Usb_rLength -= Length;
356
        save_rLength = pEPinfo->Usb_rLength;
-
 
357
 
-
 
358
        if (pEPinfo->CopyData && save_rLength) {
-
 
359
                u8 *Buffer;
-
 
360
                u32 Length;
-
 
361
 
-
 
362
                Length = pEPinfo->PacketSize;
-
 
363
                if (Length > save_rLength)
-
 
364
                        Length = save_rLength;
-
 
365
 
-
 
366
                Buffer = (*pEPinfo->CopyData)(Length);
-
 
367
                pEPinfo->Usb_rLength -= Length;
-
 
368
                pEPinfo->Usb_rOffset += Length;
453
    pEPinfo->Usb_rOffset += Length;
369
 
454
 
370
                PMAToUserBufferCopy(Buffer,GetEPRxAddr(ENDP0), Length);
-
 
371
        }
-
 
372
 
-
 
373
        if(pEPinfo->Usb_rLength !=0){
-
 
374
                vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */
-
 
375
                SetEPTxCount(ENDP0, 0);
-
 
376
                vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */
-
 
377
        }
-
 
378
/* Set the next State*/
-
 
379
        if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
-
 
380
                pInformation->ControlState = OUT_DATA;
-
 
381
        else
-
 
382
                {
-
 
383
                        if (pEPinfo->Usb_rLength >0)
-
 
384
                                pInformation->ControlState = LAST_OUT_DATA;
-
 
385
                        else if (pEPinfo->Usb_rLength == 0)
-
 
386
                                {
-
 
387
                                pInformation->ControlState = WAIT_STATUS_IN;
-
 
388
                                USB_StatusIn();
-
 
-
 
455
    PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length);
-
 
456
  }
-
 
457
 
-
 
458
  if (pEPinfo->Usb_rLength != 0)
-
 
459
  {
-
 
460
    vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */
-
 
461
    SetEPTxCount(ENDP0, 0);
-
 
462
    vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */
-
 
463
  }
-
 
464
  /* Set the next State*/
-
 
465
  if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
-
 
466
  {
-
 
467
    pInformation->ControlState = OUT_DATA;
-
 
468
  }
-
 
469
  else
-
 
470
  {
-
 
471
    if (pEPinfo->Usb_rLength > 0)
-
 
472
    {
-
 
473
      pInformation->ControlState = LAST_OUT_DATA;
-
 
474
    }
-
 
475
    else if (pEPinfo->Usb_rLength == 0)
-
 
476
    {
-
 
477
      pInformation->ControlState = WAIT_STATUS_IN;
389
                                }
478
      USB_StatusIn();
-
 
479
    }
390
                }
480
  }
391
 
481
}
392
}
482
 
393
/*******************************************************************************
483
/*******************************************************************************
394
* Function Name  : DataStageIn
484
* Function Name  : DataStageIn.
395
* Description    : Data stage of a Control Read Transfer
485
* Description    : Data stage of a Control Read Transfer.
396
* Input          :
486
* Input          : None.
397
* Output         :
487
* Output         : None.
398
* Return         :
488
* Return         : None.
399
*******************************************************************************/
489
*******************************************************************************/
400
void DataStageIn(void)
490
void DataStageIn(void)
401
{
491
{
402
        ENDPOINT_INFO   *pEPinfo = &pInformation->Ctrl_Info;
492
  ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
403
        u32     save_wLength = pEPinfo->Usb_wLength;
493
  u32 save_wLength = pEPinfo->Usb_wLength;
404
        u32     ControlState = pInformation->ControlState;
494
  u32 ControlState = pInformation->ControlState;
-
 
495
 
-
 
496
  u8 *DataBuffer;
-
 
497
  u32 Length;
-
 
498
 
-
 
499
  if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
-
 
500
  {
-
 
501
    if(Data_Mul_MaxPacketSize == TRUE)
-
 
502
    {
405
 
503
      /* No more data to send and empty packet */
-
 
504
      Send0LengthData();
-
 
505
      ControlState = LAST_IN_DATA;
-
 
506
      Data_Mul_MaxPacketSize = FALSE;
406
        u8      *DataBuffer;
507
    }
-
 
508
    else
-
 
509
    {
-
 
510
      /* No more data to send so STALL the TX Status*/
-
 
511
      ControlState = WAIT_STATUS_OUT;
-
 
512
      vSetEPTxStatus(EP_TX_STALL);
-
 
513
    }
-
 
514
   
-
 
515
    goto Expect_Status_Out;
407
        u32     Length;
516
  }
408
 
517
 
409
        if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
-
 
410
        { /* no more data to send so STALL the TX Status*/
-
 
411
                ControlState = WAIT_STATUS_OUT;
-
 
412
                vSetEPTxStatus(EP_TX_STALL);
-
 
413
                goto Expect_Status_Out;
518
  Length = pEPinfo->PacketSize;
-
 
519
  ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
414
        }
520
 
-
 
521
  if (Length > save_wLength)
415
 
522
  {
416
        Length = pEPinfo->PacketSize;
-
 
417
        ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
-
 
418
 
-
 
419
        if (Length > save_wLength)
523
    Length = save_wLength;
420
                Length = save_wLength;
524
  }
421
 
525
 
422
        DataBuffer = (*pEPinfo->CopyData)(Length);
526
  DataBuffer = (*pEPinfo->CopyData)(Length);
423
       
527
 
424
        UserToPMABufferCopy(DataBuffer,GetEPTxAddr(ENDP0),Length);
528
  UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
425
 
-
 
426
        SetEPTxCount(ENDP0, Length);
529
 
427
 
530
  SetEPTxCount(ENDP0, Length);
428
        pEPinfo->Usb_wLength -= Length;
531
 
429
        pEPinfo->Usb_wOffset += Length;
532
  pEPinfo->Usb_wLength -= Length;
430
        vSetEPTxStatus(EP_TX_VALID);
533
  pEPinfo->Usb_wOffset += Length;
431
 
534
  vSetEPTxStatus(EP_TX_VALID);
432
        USB_StatusOut();/* Expect the host to abort the data IN stage */
535
 
433
 
536
  USB_StatusOut();/* Expect the host to abort the data IN stage */
434
       
537
 
435
Expect_Status_Out:
538
Expect_Status_Out:
436
        pInformation->ControlState = ControlState;
539
  pInformation->ControlState = ControlState;
437
}
540
}
438
/*******************************************************************************
541
/*******************************************************************************
439
* Function Name  : NoData_Setup0
542
* Function Name  : NoData_Setup0.
440
* Description    : Proceed the processing of setup request without data stage
543
* Description    : Proceed the processing of setup request without data stage.
441
* Input          : None
544
* Input          : None.
442
* Output         : None
545
* Output         : None.
443
* Return         : None
546
* Return         : None.
444
*******************************************************************************/
547
*******************************************************************************/
445
void NoData_Setup0(void)
548
void NoData_Setup0(void)
446
{
549
{
447
        RESULT  Result = USB_UNSUPPORT;
550
  RESULT Result = USB_UNSUPPORT;
448
        u32     RequestNo = pInformation->USBbRequest;
551
  u32 RequestNo = pInformation->USBbRequest;
449
        u32     ControlState;
552
  u32 ControlState;
450
       
553
 
451
        if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/* Device Request*/
554
  if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
-
 
555
  {/* Device Request*/
452
               
556
 
453
                /* SET_CONFIGURATION*/
557
    /* SET_CONFIGURATION*/
454
                if (RequestNo == SET_CONFIGURATION)
558
    if (RequestNo == SET_CONFIGURATION)
-
 
559
    {
455
                        Result = Standard_SetConfiguration();
560
      Result = Standard_SetConfiguration();
-
 
561
    }
456
       
562
 
457
                /*SET ADDRESS*/
563
    /*SET ADDRESS*/
458
                else if (RequestNo == SET_ADDRESS){
564
    else if (RequestNo == SET_ADDRESS)
-
 
565
    {
459
                        if(pInformation->USBwValue0 > 127 || pInformation->USBwValue1!=0
566
      if (pInformation->USBwValue0 > 127 || pInformation->USBwValue1 != 0
-
 
567
          || pInformation->USBwIndex != 0
460
                                ||pInformation->USBwIndex!=0 || pInformation->Current_Configuration!=0) /* Device Address should be 127 or less*/
568
          || pInformation->Current_Configuration != 0)
461
                                                                                          /*call Beck spec USB 2.0*/
569
        /* Device Address should be 127 or less -> call Back spec USB 2.0*/
462
                                {              
570
      {
463
                                ControlState = STALLED;
571
        ControlState = STALLED;
464
                                goto exit_NoData_Setup0;
572
        goto exit_NoData_Setup0;
465
                                }
573
      }
-
 
574
      else
-
 
575
      {
466
                        else Result = USB_SUCCESS;
576
        Result = USB_SUCCESS;
-
 
577
      }
467
                        }
578
    }
468
                /*SET FEATURE for Device*/
579
    /*SET FEATURE for Device*/
469
                else if (RequestNo == SET_FEATURE){
580
    else if (RequestNo == SET_FEATURE)
-
 
581
    {
470
                                if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
582
      if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
-
 
583
          && pInformation->USBwIndex == 0
471
                                Result = Standard_SetDeviceFeature();
584
          && ValBit(pInformation->Current_Feature, 5))
472
                                else
585
      {
473
                                Result = USB_UNSUPPORT;
586
        Result = Standard_SetDeviceFeature();
474
                        }
587
      }
475
                /*Clear FEATURE for Device */
588
      else
476
                else if (RequestNo == CLEAR_FEATURE){
-
 
477
                        if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
-
 
478
                        Result = Standard_ClearFeature();
-
 
479
                        else
589
      {
480
                        Result = USB_UNSUPPORT;
590
        Result = USB_UNSUPPORT;
481
                }
591
      }
482
 
-
 
483
         }
592
    }
484
 
-
 
485
        /* Interface Request*/
593
    /*Clear FEATURE for Device */
486
 
-
 
487
        else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) { 
-
 
488
                       
-
 
489
                        /*SET INTERFACE*/
-
 
490
                        if (RequestNo == SET_INTERFACE)
594
    else if (RequestNo == CLEAR_FEATURE)
491
                                Result = Standard_SetInterface();
-
 
492
        }
595
    {
493
 
-
 
494
       
-
 
495
        /* EndPoint Request*/
-
 
496
 
-
 
497
        else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {
596
      if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
498
                        /*CLEAR FEATURE for EndPoint*/
597
          && pInformation->USBwIndex == 0
499
                        if (RequestNo == CLEAR_FEATURE)
-
 
500
                         Result = Standard_ClearFeature();
598
          && ValBit(pInformation->Current_Feature, 5))
501
                        /* SET FEATURE for EndPoint*/
599
      {
502
                         else if (RequestNo == SET_FEATURE){
-
 
503
                                Result = Standard_SetEndPointFeature();
600
        Result = Standard_ClearFeature();
504
                        }
601
      }
505
        }
-
 
506
        else
602
      else
507
                        Result = USB_UNSUPPORT;
-
 
508
 
-
 
509
 
-
 
510
        if (Result != USB_SUCCESS) {
603
      {
511
                    Result = (*pProperty->Class_NoData_Setup)(RequestNo);
-
 
512
                    if (Result == USB_NOT_READY) {
604
        Result = USB_UNSUPPORT;
513
                    ControlState = PAUSE;
-
 
514
                    goto exit_NoData_Setup0;
-
 
515
                }
605
      }
516
        }
-
 
517
 
-
 
518
        if (Result != USB_SUCCESS) {
-
 
519
                ControlState = STALLED;
-
 
520
                goto exit_NoData_Setup0;
-
 
521
        }
606
    }
-
 
607
 
-
 
608
  }
-
 
609
 
-
 
610
  /* Interface Request*/
-
 
611
 
-
 
612
  else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
-
 
613
  {
-
 
614
 
-
 
615
    /*SET INTERFACE*/
-
 
616
    if (RequestNo == SET_INTERFACE)
-
 
617
    {
-
 
618
      Result = Standard_SetInterface();
-
 
619
    }
-
 
620
  }
-
 
621
 
-
 
622
 
-
 
623
  /* EndPoint Request*/
-
 
624
 
-
 
625
  else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
-
 
626
  {
-
 
627
    /*CLEAR FEATURE for EndPoint*/
-
 
628
    if (RequestNo == CLEAR_FEATURE)
-
 
629
    {
-
 
630
      Result = Standard_ClearFeature();
-
 
631
    }
-
 
632
    /* SET FEATURE for EndPoint*/
-
 
633
    else if (RequestNo == SET_FEATURE)
-
 
634
    {
-
 
635
      Result = Standard_SetEndPointFeature();
-
 
636
    }
-
 
637
  }
-
 
638
  else
-
 
639
  {
-
 
640
    Result = USB_UNSUPPORT;
-
 
641
  }
-
 
642
 
-
 
643
 
-
 
644
  if (Result != USB_SUCCESS)
522
 
645
  {
-
 
646
    Result = (*pProperty->Class_NoData_Setup)(RequestNo);
-
 
647
    if (Result == USB_NOT_READY)
-
 
648
    {
-
 
649
      ControlState = PAUSE;
-
 
650
      goto exit_NoData_Setup0;
-
 
651
    }
-
 
652
  }
-
 
653
 
-
 
654
  if (Result != USB_SUCCESS)
-
 
655
  {
-
 
656
    ControlState = STALLED;
-
 
657
    goto exit_NoData_Setup0;
-
 
658
  }
-
 
659
 
523
        ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */
660
  ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */
524
 
661
 
525
        USB_StatusIn();
662
  USB_StatusIn();
526
 
663
 
527
exit_NoData_Setup0:
664
exit_NoData_Setup0:
-
 
665
  pInformation->ControlState = ControlState;
-
 
666
  return;
528
        pInformation->ControlState = ControlState;
667
}
529
        return;
668
 
530
}
669
 
531
/*******************************************************************************
670
/*******************************************************************************
532
* Function Name  : Data_Setup0
671
* Function Name  : Data_Setup0.
533
* Description    : Proceed the processing of setup request with data stage
672
* Description    : Proceed the processing of setup request with data stage.
534
* Input          :
673
* Input          : None.
535
* Output         :
674
* Output         : None.
536
* Return         :
675
* Return         : None.
537
*******************************************************************************/
676
*******************************************************************************/
538
void Data_Setup0(void)
677
void Data_Setup0(void)
539
{
678
{
653
 
-
 
654
        return;
-
 
655
} /* Data_Setup0 */
847
 
656
/*******************************************************************************
848
/*******************************************************************************
657
* Function Name  : Setup0_Process
849
* Function Name  : Setup0_Process
658
* Description    : Get the device request data and dispatch to individual process
850
* Description    : Get the device request data and dispatch to individual process.
659
* Input          :
851
* Input          : None.
660
* Output         :
852
* Output         : None.
661
* Return         :
853
* Return         : Post0_Process.
662
*******************************************************************************/
854
*******************************************************************************/
663
u8 Setup0_Process(void)
855
u8 Setup0_Process(void)
664
{
856
{
665
#ifdef STR7xx /* STR7xx family*/
857
#ifdef STR7xx /* STR7xx family*/
666
  union {
858
  union {
667
        u8*     b;
859
    u8* b;
668
        u16*    w;
860
    u16* w;
669
        } pBuf;
861
  } pBuf;
670
  pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0)*2); /* *2 for 32 bits addr */
862
  pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
671
 
863
 
672
  if (pInformation->ControlState != PAUSE) {
864
  if (pInformation->ControlState != PAUSE)
-
 
865
  {
673
        pInformation->USBbmRequestType = *pBuf.b++;     /* bmRequestType */
866
    pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
674
        pInformation->USBbRequest               = *pBuf.b++;    /* bRequest */
867
    pInformation->USBbRequest  = *pBuf.b++; /* bRequest */
675
        pBuf.w++;  /* word not accessed because of 32 bits addressing */
868
    pBuf.w++;  /* word not accessed because of 32 bits addressing */
676
        pInformation->USBwValue         = ByteSwap(*pBuf.w++);  /* wValue */
869
    pInformation->USBwValue  = ByteSwap(*pBuf.w++); /* wValue */
677
        pBuf.w++;  /* word not accessed because of 32 bits addressing */
870
    pBuf.w++;  /* word not accessed because of 32 bits addressing */
678
        pInformation->USBwIndex         = ByteSwap(*pBuf.w++);  /* wIndex */
871
    pInformation->USBwIndex  = ByteSwap(*pBuf.w++); /* wIndex */
679
        pBuf.w++;  /* word not accessed because of 32 bits addressing */
872
    pBuf.w++;  /* word not accessed because of 32 bits addressing */
680
        pInformation->USBwLength                = *pBuf.w;      /* wLength */
873
    pInformation->USBwLength  = *pBuf.w; /* wLength */
681
  }
874
  }
682
#endif/* End of STR7xx family*/
875
#endif/* End of STR7xx family*/
683
 
876
 
684
#ifdef STR91x /* STR91x family*/
877
#ifdef STR91x /* STR91x family*/
685
  u16*    pBuf;
878
  u16*    pBuf;
686
 
879
 
687
  pBuf= (u16 *)(GetEPRxAddr(ENDP0)+PMAAddr);
880
  pBuf = (u16 *)(GetEPRxAddr(ENDP0) + PMAAddr);
688
  if (pInformation->ControlState != PAUSE)
881
  if (pInformation->ControlState != PAUSE)
689
  {
882
  {
690
    pInformation->USBbmRequestType = (*pBuf)&0xFF; /* bmRequestType */
883
    pInformation->USBbmRequestType = (*pBuf) & 0xFF; /* bmRequestType */
691
    pInformation->USBbRequest = ((*pBuf)&0xFF00)>>8; /* bRequest */
884
    pInformation->USBbRequest = ((*pBuf) & 0xFF00) >> 8; /* bRequest */
692
    pInformation->USBwValue = ByteSwap(*(pBuf+1)); /* wValue */
885
    pInformation->USBwValue = ByteSwap(*(pBuf + 1)); /* wValue */
693
    pInformation->USBwIndex = ByteSwap(*(pBuf+2)); /* wIndex */
886
    pInformation->USBwIndex = ByteSwap(*(pBuf + 2)); /* wIndex */
694
    pInformation->USBwLength = *(pBuf+3);  /* wLength */
887
    pInformation->USBwLength = *(pBuf + 3);  /* wLength */
695
  }
888
  }
696
#endif /* End of STR91x family*/
889
#endif /* End of STR91x family*/
697
  pInformation->ControlState = SETTING_UP;
890
  pInformation->ControlState = SETTING_UP;
698
  if (pInformation->USBwLength == 0)
891
  if (pInformation->USBwLength == 0)
699
  {
892
  {
700
    /* Setup with no data stage */
893
    /* Setup with no data stage */
701
    NoData_Setup0();
894
    NoData_Setup0();
702
  }
895
  }
703
  else
896
  else
704
  {
897
  {
705
    /* Setup with data stage */
898
    /* Setup with data stage */
706
    Data_Setup0();
899
    Data_Setup0();
707
  }
900
  }
708
  return Post0_Process();
901
  return Post0_Process();
709
}
902
}
-
 
903
 
710
/*******************************************************************************
904
/*******************************************************************************
711
* Function Name  : In0_Process
905
* Function Name  : In0_Process
712
* Description    : Process the IN token on all default endpoint
906
* Description    : Process the IN token on all default endpoint.
713
* Input          :
907
* Input          : None.
714
* Output         :
908
* Output         : None.
715
* Return         :
909
* Return         : Post0_Process.
716
*******************************************************************************/
910
*******************************************************************************/
717
u8 In0_Process(void)
911
u8 In0_Process(void)
718
{
912
{
719
        u32     ControlState = pInformation->ControlState;
913
  u32 ControlState = pInformation->ControlState;
720
       
-
 
721
        if (ControlState == IN_DATA || ControlState == LAST_IN_DATA)
-
 
722
        {
-
 
723
                DataStageIn();
-
 
724
                ControlState = pInformation->ControlState; /* may be changed outside the function */
-
 
725
        }
-
 
726
       
-
 
727
        else if (ControlState == WAIT_STATUS_IN) {
-
 
728
                if (pInformation->USBbRequest == SET_ADDRESS &&
-
 
729
                                Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) )
-
 
730
                {
-
 
731
                        SetDeviceAddress(pInformation->USBwValue0);
-
 
732
                        pUser_Standard_Requests->User_SetDeviceAddress();
-
 
733
                }
-
 
734
                (*pProperty->Process_Status_IN)();
-
 
735
                ControlState = STALLED;
-
 
736
        }
-
 
737
               
-
 
738
        else
-
 
739
        ControlState = STALLED;
-
 
-
 
914
 
-
 
915
  if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
-
 
916
  {
740
 
917
    DataStageIn();
-
 
918
    ControlState = pInformation->ControlState;
-
 
919
    /* may be changed outside the function */
-
 
920
  }
-
 
921
  else if (ControlState == WAIT_STATUS_IN)
-
 
922
  {
-
 
923
    if (pInformation->USBbRequest == SET_ADDRESS &&
-
 
924
        Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) )
-
 
925
    {
-
 
926
      SetDeviceAddress(pInformation->USBwValue0);
-
 
927
      pUser_Standard_Requests->User_SetDeviceAddress();
-
 
928
    }
-
 
929
    (*pProperty->Process_Status_IN)();
-
 
930
    ControlState = STALLED;
-
 
931
  }
-
 
932
  else
-
 
933
  {
-
 
934
    ControlState = STALLED;
-
 
935
  }
-
 
936
 
741
        pInformation->ControlState = ControlState;
937
  pInformation->ControlState = ControlState;
742
 
938
 
-
 
939
  return Post0_Process();
743
        return Post0_Process();
940
}
744
}
941
 
745
/*******************************************************************************
942
/*******************************************************************************
746
* Function Name  : Out0_Process
943
* Function Name  : Out0_Process
747
* Description    : Process the OUT token on all default endpoint
944
* Description    : Process the OUT token on all default endpoint.
748
* Input          :
945
* Input          : None.
749
* Output         :
946
* Output         : None.
750
* Return         :
947
* Return         : Post0_Process.
751
*******************************************************************************/
948
*******************************************************************************/
752
u8 Out0_Process(void)
949
u8 Out0_Process(void)
753
{
950
{
754
        u32     ControlState = pInformation->ControlState;
951
  u32 ControlState = pInformation->ControlState;
755
       
-
 
756
        if(ControlState == OUT_DATA || ControlState == LAST_OUT_DATA)
-
 
757
                DataStageOut();
-
 
758
 
-
 
759
        else if (ControlState == WAIT_STATUS_OUT) {
-
 
760
                (*pProperty->Process_Status_OUT)();    
-
 
761
                ControlState = STALLED;
-
 
762
                }
-
 
763
 
-
 
764
        else if (ControlState == IN_DATA || ControlState == LAST_IN_DATA) {
-
 
765
                /* host aborts the transfer before finish */
-
 
766
                                ControlState = STALLED;
-
 
767
        }
-
 
768
 
-
 
769
 
-
 
770
        /* Unexpect state, STALL the endpoint */
-
 
771
        else {
-
 
772
               
-
 
773
                ControlState = STALLED;
-
 
774
        }
-
 
-
 
952
 
-
 
953
  if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
-
 
954
  {
775
 
955
    DataStageOut();
-
 
956
    ControlState = pInformation->ControlState;
-
 
957
    /* may be changed outside the function */
-
 
958
  }
-
 
959
  else if (ControlState == WAIT_STATUS_OUT)
-
 
960
  {
-
 
961
    (*pProperty->Process_Status_OUT)();
-
 
962
    ControlState = STALLED;
-
 
963
  }
-
 
964
  else if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
-
 
965
  {
-
 
966
    /* host aborts the transfer before finish */
-
 
967
    ControlState = STALLED;
-
 
968
  }
-
 
969
  /* Unexpect state, STALL the endpoint */
-
 
970
  else
-
 
971
  {
-
 
972
    ControlState = STALLED;
-
 
973
  }
-
 
974
 
776
        pInformation->ControlState = ControlState;
975
  pInformation->ControlState = ControlState;
777
 
976
 
778
        return Post0_Process();
977
  return Post0_Process();
779
} /* Out0_Process */
978
} /* Out0_Process */
780
 
979
 
781
/*******************************************************************************
980
/*******************************************************************************
782
* Function Name  : Post0_Process
981
* Function Name  : Post0_Process
783
* Description    :
982
* Description    : Stall the Endpoint 0 in case of error.
784
* Input          :
983
* Input          : None.
785
* Output         :
984
* Output         : None.
-
 
985
* Return         : - 0 if the control State is in PAUSE
786
* Return         :
986
*                  - 1 if not.
787
*******************************************************************************/
987
*******************************************************************************/
788
u8 Post0_Process(void)
988
u8 Post0_Process(void)
789
{
989
{
790
        SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
990
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
791
 
991
 
-
 
992
  if (pInformation->ControlState == STALLED)
792
        if (pInformation->ControlState == STALLED) {
993
  {
793
                vSetEPRxStatus(EP_RX_STALL);
994
    vSetEPRxStatus(EP_RX_STALL);
794
                vSetEPTxStatus(EP_TX_STALL);
995
    vSetEPTxStatus(EP_TX_STALL);
795
        }
996
  }
796
 
997
 
-
 
998
  return (pInformation->ControlState == PAUSE);
797
        return (pInformation->ControlState == PAUSE);
999
}
798
}
1000
 
799
/*******************************************************************************
1001
/*******************************************************************************
800
* Function Name  : SetDeviceAddress
1002
* Function Name  : SetDeviceAddress.
801
* Description    : set the device and all the used Endpoints addresses
1003
* Description    : Set the device and all the used Endpoints addresses.
802
* Input          : Val : device adress
1004
* Input          : - Val: device adress.
803
* Output         :
1005
* Output         : None.
804
* Return         :
1006
* Return         : None.
805
*******************************************************************************/
1007
*******************************************************************************/
806
void SetDeviceAddress(u8 Val)
1008
void SetDeviceAddress(u8 Val)
807
{
1009
{
808
  u32 i;
1010
  u32 i;
809
  u32   nEP = Device_Table.Total_Endpoint;
1011
  u32 nEP = Device_Table.Total_Endpoint;
810
 
1012
 
811
        /* set address in every used endpoint */
1013
  /* set address in every used endpoint */
812
        for(i=0;i<nEP;i++)
1014
  for (i = 0; i < nEP; i++)
813
        {
1015
  {
814
                _SetEPAddress((u8)i, (u8)i);
1016
    _SetEPAddress((u8)i, (u8)i);
815
        } /* for */
1017
  }
816
        _SetDADDR(Val|DADDR_EF); /* set device address and enable function */
1018
  _SetDADDR(Val | DADDR_EF); /* set device address and enable function */
-
 
1019
 
817
 
1020
}
818
}
1021
 
819
/*******************************************************************************
1022
/*******************************************************************************
820
* Function Name  : NOP_Process
1023
* Function Name  : NOP_Process
821
* Description    : no operation function.
1024
* Description    : No operation function.
822
* Input          :
1025
* Input          : None.
823
* Output         :
1026
* Output         : None.
824
* Return         :
1027
* Return         : None.
825
*******************************************************************************/
1028
*******************************************************************************/
826
void NOP_Process(void)
1029
void NOP_Process(void)
827
{
1030
{
828
}
1031
}
829
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
1032
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
830
 
1033
 
831
 
1034
 
832
 
1035