Subversion Repositories NaviCtrl

Rev

Rev 1 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 196
Line 1... Line 1...
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
*******************************************************************************/
Line 19... Line 15...
19
 
15
 
-
 
16
/* Includes ------------------------------------------------------------------*/
-
 
17
/* Private typedef -----------------------------------------------------------*/
-
 
18
/* Private define ------------------------------------------------------------*/
-
 
19
/* Private macro -------------------------------------------------------------*/
-
 
20
/* Private variables ---------------------------------------------------------*/
-
 
21
/* Private function prototypes -----------------------------------------------*/
-
 
22
/* Private functions ---------------------------------------------------------*/
-
 
23
 
20
/* Includes ------------------------------------------------------------------*/
24
/* Includes ------------------------------------------------------------------*/
21
#include "usb_lib.h"
25
#include "usb_lib.h"
22
#include "usb_mem.h"
26
#include "usb_mem.h"
-
 
27
#include "usb_conf.h"
23
#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))
-
 
33
#define ClrBit(VAR,Place)    (VAR &= ((1<<Place)^255))
-
 
34
 
-
 
35
#define Send0LengthData() { \
-
 
36
    _SetEPTxCount(ENDP0, 0); \
-
 
37
    vSetEPTxStatus(EP_TX_VALID); \
Line 28... Line 38...
28
#define ClrBit(VAR,Place)    ( VAR &= ((1<<Place)^255) )
38
  }
29
 
-
 
30
#define Send0LengthData() {     \
39
 
31
        _SetEPTxCount(ENDP0, 0);        \
-
 
Line 32... Line 40...
32
        vSetEPTxStatus(EP_TX_VALID);    \
40
#define vSetEPRxStatus(st)   (SaveRState = st)
33
        }
41
#define vSetEPTxStatus(st)   (SaveTState = st)
Line 34... Line 42...
34
 
42
 
35
#define vSetEPRxStatus(st)      (SaveRState = st)
43
#define USB_StatusIn()       Send0LengthData()
Line 36... Line -...
36
#define vSetEPTxStatus(st)      (SaveTState = st)
-
 
37
 
-
 
38
#define USB_StatusIn()  Send0LengthData()
44
#define USB_StatusOut()      vSetEPRxStatus(EP_RX_VALID)
39
#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
45
 
40
 
46
#define StatusInfo0          StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
-
 
47
#define StatusInfo1          StatusInfo.bw.bb0
41
#define StatusInfo0 StatusInfo.bw.bb1   /* Reverse bb0 & bb1 */
48
 
-
 
49
/* Private macro -------------------------------------------------------------*/
-
 
50
/* Private variables ---------------------------------------------------------*/
-
 
51
u16_u8 StatusInfo;
-
 
52
bool Data_Mul_MaxPacketSize = FALSE;
42
#define StatusInfo1 StatusInfo.bw.bb0
53
/* Private function prototypes -----------------------------------------------*/
Line 43... Line 54...
43
/* Private macro -------------------------------------------------------------*/
54
static void DataStageOut(void);
44
/* Private variables ---------------------------------------------------------*/
55
static void DataStageIn(void);
45
u16_u8 StatusInfo;
56
static void NoData_Setup0(void);
46
/* Private function prototypes -----------------------------------------------*/
57
static void Data_Setup0(void);
47
/* Private functions ---------------------------------------------------------*/
58
/* Private functions ---------------------------------------------------------*/
48
 
-
 
49
/*******************************************************************************
59
 
50
* Function Name  : Standard_GetConfiguration
60
/*******************************************************************************
51
* Description    : Return the current configuration variable address
61
* Function Name  : Standard_GetConfiguration.
52
* Input          : Length - How many bytes are needed.
62
* Description    : Return the current configuration variable address.
53
* Output         : If "Length" is 0, return the length of configuration value
63
* Input          : Length - How many bytes are needed.
54
                   If "Length" is not 0, return the data buffer address.
64
* Output         : None.
-
 
65
* Return         : Return 1 , if the request is invalid when "Length" is 0.
-
 
66
*                  Return "Buffer" if the "Length" is not 0.
55
* Return         : Return 1 , if the request is invalid when "Length" is 0
67
*******************************************************************************/
-
 
68
u8 *Standard_GetConfiguration(u16 Length)
56
                   Return "Buffer" if the "Length" is not 0
69
{
57
*******************************************************************************/
70
  if (Length == 0)
58
u8 *Standard_GetConfiguration(u16 Length)
71
  {
59
{
72
    pInformation->Ctrl_Info.Usb_wLength =
60
  if (Length == 0){
73
      sizeof(pInformation->Current_Configuration);
-
 
74
 
61
    pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_Configuration);
75
    return 0;
62
                return 0;
76
  }
63
  }
77
  pUser_Standard_Requests->User_GetConfiguration();
64
        pUser_Standard_Requests->User_GetConfiguration();
78
  return (u8 *)&pInformation->Current_Configuration;
65
        return (u8 *)&pInformation->Current_Configuration;
79
}
66
}
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.
-
 
86
* Output         : None.
-
 
87
* Return         : Return USB_SUCCESS, if the request is performed.
-
 
88
*                  Return USB_UNSUPPORT, if the request is invalid.
-
 
89
*******************************************************************************/
-
 
90
RESULT Standard_SetConfiguration(void)
-
 
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;
Line 72... Line -...
72
* Output         :
-
 
73
* Return         : Return USB_SUCCESS, if the request is performed
-
 
74
                   Return USB_UNSUPPORT, if the request is invalid
-
 
75
*******************************************************************************/
-
 
76
RESULT Standard_SetConfiguration(void)
-
 
77
{
-
 
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;
99
  }
83
                pUser_Standard_Requests->User_SetConfiguration();
100
  else
84
                return USB_SUCCESS;
101
  {
85
        }
102
    return USB_UNSUPPORT;
86
        else
103
  }
87
        return USB_UNSUPPORT;
-
 
88
}
104
}
89
/*******************************************************************************
105
 
90
* Function Name  : Standard_GetInterface
106
/*******************************************************************************
91
* Description    : Return the Alternate Setting of the current interface
107
* Function Name  : Standard_GetInterface.
92
* Input          : Length - How many bytes are needed
108
* Description    : Return the Alternate Setting of the current interface.
93
* Output         : If "Length" is 0, return the length of interface value
109
* Input          : Length - How many bytes are needed.
-
 
110
* Output         : None.
-
 
111
* Return         : Return 0, if the request is invalid when "Length" is 0.
94
                   If "Length" is not 0, return the data buffer address
112
*                  Return "Buffer" if the "Length" is not 0.
95
* Return         : Return 0, if the request is invalid when "Length" is 0
113
*******************************************************************************/
96
                   Return "Buffer" if the "Length" is not 0
114
u8 *Standard_GetInterface(u16 Length)
97
*******************************************************************************/
115
{
98
u8 *Standard_GetInterface(u16 Length)
116
  if (Length == 0)
99
{
117
  {
-
 
118
    pInformation->Ctrl_Info.Usb_wLength =
100
  if (Length == 0){
119
      sizeof(pInformation->Current_AlternateSetting);
101
        pInformation->Ctrl_Info.Usb_wLength =   sizeof(pInformation->Current_AlternateSetting);
120
    return 0;
102
    return 0;
121
  }
103
  }
122
  pUser_Standard_Requests->User_GetInterface();
104
        pUser_Standard_Requests->User_GetInterface();
123
  return (u8 *)&pInformation->Current_AlternateSetting;
105
        return (u8 *)&pInformation->Current_AlternateSetting;
124
}
106
}
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.
-
 
132
* Return         : - Return USB_SUCCESS, if the request is performed.
113
* Return         : Return USB_SUCCESS, if the request is performed
133
*                  - Return USB_UNSUPPORT, if the request is invalid.
-
 
134
*******************************************************************************/
114
                   Return USB_UNSUPPORT, if the request is invalid
135
RESULT Standard_SetInterface(void)
115
*******************************************************************************/
136
{
116
RESULT Standard_SetInterface(void)
137
  RESULT Re;
117
{
138
  /*Test if the specified Interface and Alternate Setting are supported by
-
 
139
  the application Firmware*/
-
 
140
  Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,
118
        RESULT                  Re;
141
       pInformation->USBwValue0);
-
 
142
 
119
        /*Test if the specified Interface and Alternate Setting are supported by the application Firmware*/
143
  if (pInformation->Current_Configuration != 0 )
120
        Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,pInformation->USBwValue0);
144
  {
121
 
145
    if (Re != USB_SUCCESS || pInformation->USBwIndex1 != 0
122
        if(pInformation->Current_Configuration!=0 )
146
        || pInformation->USBwValue1 != 0)
123
        {
147
    {
124
                if (Re!= USB_SUCCESS || pInformation->USBwIndex1!=0 || pInformation->USBwValue1!=0)
148
      return  USB_UNSUPPORT;
125
                                return  USB_UNSUPPORT;
149
    }
126
                else if ( Re == USB_SUCCESS)
-
 
127
                {
150
    else if (Re == USB_SUCCESS)
128
                 pUser_Standard_Requests->User_SetInterface();
-
 
129
                 pInformation->Current_Interface = pInformation->USBwIndex0;
151
    {
130
                 pInformation->Current_AlternateSetting = pInformation->USBwValue0;
152
      pUser_Standard_Requests->User_SetInterface();
-
 
153
      pInformation->Current_Interface = pInformation->USBwIndex0;
131
                 return USB_SUCCESS;
154
      pInformation->Current_AlternateSetting = pInformation->USBwValue0;
132
                }
155
      return USB_SUCCESS;
133
                       
156
    }
134
        }
157
  }
135
 
158
  return USB_UNSUPPORT;
136
 return USB_UNSUPPORT;
-
 
137
}
159
}
138
/*******************************************************************************
160
 
139
* Function Name  : Standard_GetStatus
161
/*******************************************************************************
140
* Description    : Copy the device request data to "StatusInfo buffer"
162
* Function Name  : Standard_GetStatus.
141
* Input          : Length - How many bytes are needed
163
* Description    : Copy the device request data to "StatusInfo buffer".
142
* Output         : If "Length" is 0, return the length of status data
164
* Input          : - Length - How many bytes are needed.
-
 
165
* Output         : None.
143
                   If "Length" is not 0, return number of bytes have been copied
166
* Return         : Return 0, if the request is at end of data block,
144
* Return         : Return 0, if the request is at end of data block,
167
*                  or is invalid when "Length" is 0.
145
                   or is invalid when "Length" is 0
168
*******************************************************************************/
146
*******************************************************************************/
169
u8 *Standard_GetStatus(u16 Length)
147
u8 *Standard_GetStatus(u16 Length)
170
{
148
{
171
  if (Length == 0)
149
  if (Length == 0){
172
  {
150
          pInformation->Ctrl_Info.Usb_wLength =2;
173
    pInformation->Ctrl_Info.Usb_wLength = 2;
-
 
174
    return 0;
-
 
175
  }
151
                return 0;
176
 
152
  }
177
  StatusInfo.w = 0;
-
 
178
  /* Reset Status Information */
153
 
179
 
-
 
180
  if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
154
        StatusInfo.w = 0;
181
  {
155
                                /* Reset Status Information */
182
    /*Get Device Status */
156
       
183
    u8 Feature = pInformation->Current_Feature;
-
 
184
 
157
        if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/*Get Device Status */
185
    /* Remote Wakeup enabled */
-
 
186
    if (ValBit(Feature, 5))
-
 
187
    {
-
 
188
      SetBit(StatusInfo0, 1);
158
                u8      Feature = pInformation->Current_Feature;
189
    }
159
 
190
 
160
                if (ValBit(Feature, 5))
191
    /* Bus-powered */
-
 
192
    if (ValBit(Feature, 6))
161
                        SetBit(StatusInfo0, 1); /* Remote Wakeup enabled */
193
    {
-
 
194
      ClrBit(StatusInfo0, 0);
162
 
195
    }
-
 
196
    else /* Self-powered */
163
               
197
    {
164
                if (ValBit(Feature, 6))
198
      SetBit(StatusInfo0, 0);
-
 
199
    }
165
                        SetBit(StatusInfo0, 0);  /* Self-powered */
200
  }
-
 
201
  /*Interface Status*/
166
                else
202
  else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
167
                        ClrBit(StatusInfo0, 0); /* Bus-powered */
203
  {
168
        }
204
    return (u8 *)&StatusInfo;
169
        else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))/*Interface Status*/
205
  }
170
                        return (u8 *)&StatusInfo;
206
  /*Get EndPoint Status*/
-
 
207
  else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
171
 
208
  {
172
        else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {/*Get EndPoint Status*/
209
    u8 Related_Endpoint;
-
 
210
    u8 wIndex0 = pInformation->USBwIndex0;
173
                u8      Related_Endpoint;
211
 
-
 
212
    Related_Endpoint = (wIndex0 & 0x0f);
174
                u8      wIndex0 = pInformation->USBwIndex0;
213
    if (ValBit(wIndex0, 7))
175
 
214
    {
-
 
215
      /* IN endpoint */
176
                Related_Endpoint = (wIndex0 & 0x0f);
216
      if (_GetTxStallStatus(Related_Endpoint))
177
                        if (ValBit(wIndex0, 7)) {
217
      {
-
 
218
        SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
178
                                /* IN endpoint */
219
      }
-
 
220
    }
179
                                if (_GetTxStallStatus( Related_Endpoint ))
221
    else
180
                                SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
222
    {
181
                        }
223
      /* OUT endpoint */
182
                        else {
224
      if (_GetRxStallStatus(Related_Endpoint))
-
 
225
      {
183
                                /* OUT endpoint */
226
        SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
-
 
227
      }
184
                                if (_GetRxStallStatus( Related_Endpoint ))
228
    }
185
                                SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
229
 
186
                        }
230
  }
-
 
231
  else
187
               
232
  {
188
        }
233
    return NULL;
189
        else
234
  }
190
                return NULL;
235
  pUser_Standard_Requests->User_GetStatus();
191
        pUser_Standard_Requests->User_GetStatus();
236
  return (u8 *)&StatusInfo;
192
        return (u8 *)&StatusInfo;
237
}
-
 
238
 
193
}
239
/*******************************************************************************
194
/*******************************************************************************
240
* Function Name  : Standard_ClearFeature.
195
* Function Name  : Standard_ClearFeature
241
* Description    : Clear or disable a specific feature.
196
* Description    : Clear or disable a specific feature
-
 
197
* Input          :
-
 
198
* Output         :
-
 
199
* Return         :
-
 
200
*******************************************************************************/
-
 
201
RESULT Standard_ClearFeature(void)
-
 
202
{
-
 
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);
-
 
Line -... Line 242...
-
 
242
* Input          : None.
-
 
243
* Output         : None.
-
 
244
* Return         : - Return USB_SUCCESS, if the request is performed.
-
 
245
*                  - Return USB_UNSUPPORT, if the request is invalid.
-
 
246
*******************************************************************************/
-
 
247
RESULT Standard_ClearFeature(void)
-
 
248
{
-
 
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);
250
                                        _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
316
          _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
251
                                }
317
        }
-
 
318
      }
252
                        }
319
    }
253
                }
320
    pUser_Standard_Requests->User_ClearFeature();
254
                pUser_Standard_Requests->User_ClearFeature();
321
    return USB_SUCCESS;
255
                return USB_SUCCESS;
322
  }
256
        }
323
 
257
 
324
  return USB_UNSUPPORT;
-
 
325
}
258
        return USB_UNSUPPORT;
326
 
259
}
327
/*******************************************************************************
260
/*******************************************************************************
328
* Function Name  : Standard_SetEndPointFeature
261
* Function Name  : Standard_SetEndPointFeature
329
* Description    : Set or enable a specific feature of EndPoint
262
* Description    : Set or enable a specific feature of EndPoint
330
* Input          : None.
263
* Input          :
331
* Output         : None.
264
* Output         :
332
* Return         : - Return USB_SUCCESS, if the request is performed.
265
* Return         :
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;
-
 
338
  u32    Related_Endpoint;
270
        u32    Related_Endpoint;
339
  u32    rEP;
-
 
340
  u32   Status;
271
        u32    rEP;
341
 
-
 
342
  wIndex0 = pInformation->USBwIndex0;
-
 
343
  rEP = wIndex0 & ~0x80;
-
 
344
  Related_Endpoint = ENDP0 + rEP;
272
        u32   Status;
345
 
-
 
346
  if (ValBit(pInformation->USBwIndex0, 7))
-
 
347
  { /* get Status of endpoint & stall the request if the related_ENdpoint is
-
 
348
        Disabled*/
-
 
349
    Status = _GetEPTxStatus(Related_Endpoint);
-
 
350
  }
-
 
351
  else
-
 
352
  {
-
 
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
  {
273
 
359
    return USB_UNSUPPORT;
-
 
360
  }
-
 
361
  else
-
 
362
  {
-
 
363
    if (wIndex0 & 0x80)
-
 
364
    {  /* IN endpoint */
-
 
365
      _SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
-
 
366
    }
274
                wIndex0 = pInformation->USBwIndex0;
367
 
Line 275... Line -...
275
                rEP = wIndex0 & ~0x80;
-
 
276
                Related_Endpoint = ENDP0 + rEP;
-
 
277
 
-
 
278
                if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/* get Status of endpoint & stall the request if
-
 
279
                                                                                                    the related_ENdpoint is Disabled*/
-
 
280
                else Status =_GetEPRxStatus(Related_Endpoint);
-
 
281
 
-
 
282
 
-
 
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
                        }
368
    else
292
                               
369
    {    /* OUT endpoint */
293
                        else {                          /* OUT endpoint */
370
      _SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
294
                                _SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
371
    }
295
                        }
372
  }
296
                }
373
  pUser_Standard_Requests->User_SetEndPointFeature();
-
 
374
  return USB_SUCCESS;
297
        pUser_Standard_Requests->User_SetEndPointFeature();
375
}
298
        return USB_SUCCESS;
376
 
299
}
377
/*******************************************************************************
300
/*******************************************************************************
378
* Function Name  : Standard_SetDeviceFeature.
301
* Function Name  : Standard_SetDeviceFeature
379
* Description    : Set or enable a specific feature of Device.
302
* Description    : Set or enable a specific feature of Device
380
* Input          : None.
Line 303... Line 381...
303
* Input          :
381
* Output         : None.
Line 304... Line 382...
304
* Output         :
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)
-
 
386
{
308
{
387
  SetBit(pInformation->Current_Feature, 5);
309
                        SetBit(pInformation->Current_Feature, 5);
388
  pUser_Standard_Requests->User_SetDeviceFeature();
310
                        pUser_Standard_Requests->User_SetDeviceFeature();
389
  return USB_SUCCESS;
-
 
390
 
311
                        return USB_SUCCESS;
391
}
312
 
392
 
313
}
393
/*******************************************************************************
314
 
394
* Function Name  : Standard_GetDescriptorData.
315
/*******************************************************************************
395
* Description    : Standard_GetDescriptorData is used for descriptors transfer.
-
 
396
*                : This routine is used for the descriptors resident in Flash
316
* Function Name  : Standard_GetDescriptorData
397
*                  or RAM
317
* Description    : Standard_GetDescriptorData is used for descriptors transfer
398
*                  pDesc can be in either Flash or RAM
318
*                : This routine is used for the descriptors resident in Flash or RAM
399
*                  The purpose of this routine is to have a versatile way to
319
                  pDesc can be in either Flash or RAM
400
*                  response descriptors request. It allows user to generate
320
                  The purpose of this routine is to have a versatile way to response
-
 
321
                  descriptors request. It allows user to generate certain descriptors
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.
Line 324... Line 404...
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
-
 
406
*                  its original size.
326
                          descriptor and 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
 
412
u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
-
 
413
{
332
u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
414
  u32  wOffset;
333
{
415
 
334
        u32      wOffset;
416
  wOffset = pInformation->Ctrl_Info.Usb_wOffset;
335
 
417
  if (Length == 0)
336
        wOffset = pInformation->Ctrl_Info.Usb_wOffset;
418
  {
337
        if (Length == 0) {
419
    pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
338
                pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
420
    return 0;
339
                return 0;
421
  }
340
        }
422
 
341
 
423
  return pDesc->Descriptor + wOffset;
342
        return pDesc->Descriptor + wOffset;
424
}
-
 
425
 
-
 
426
/*******************************************************************************
-
 
427
* Function Name  : DataStageOut.
-
 
428
* Description    : Data stage of a Control Write Transfer.
-
 
429
* Input          : None.
-
 
430
* Output         : None.
-
 
431
* Return         : None.
Line 343... Line 432...
343
}
432
*******************************************************************************/
-
 
433
void DataStageOut(void)
-
 
434
{
-
 
435
  ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
-
 
436
  u32 save_rLength;
-
 
437
 
-
 
438
  save_rLength = pEPinfo->Usb_rLength;
-
 
439
 
-
 
440
  if (pEPinfo->CopyData && save_rLength)
Line 344... Line -...
344
/*******************************************************************************
-
 
345
* Function Name  : DataStageOut
-
 
346
* Description    : Data stage of a Control Write Transfer
-
 
347
* Input          :
-
 
348
* Output         :
-
 
349
* Return         :
-
 
350
*******************************************************************************/
-
 
351
void DataStageOut(void)
-
 
352
{
-
 
353
        ENDPOINT_INFO   *pEPinfo = &pInformation->Ctrl_Info;
-
 
354
        u32     save_rLength;
-
 
355
 
-
 
356
        save_rLength = pEPinfo->Usb_rLength;
441
  {
357
 
442
    u8 *Buffer;
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;
-
 
369
 
-
 
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 */
-
 
Line -... Line 443...
-
 
443
    u32 Length;
-
 
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;
-
 
453
    pEPinfo->Usb_rOffset += Length;
-
 
454
 
-
 
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)
377
        }
466
  {
-
 
467
    pInformation->ControlState = OUT_DATA;
378
/* Set the next State*/
468
  }
379
        if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
469
  else
380
                pInformation->ControlState = OUT_DATA;
470
  {
381
        else
471
    if (pEPinfo->Usb_rLength > 0)
382
                {
472
    {
383
                        if (pEPinfo->Usb_rLength >0)
473
      pInformation->ControlState = LAST_OUT_DATA;
384
                                pInformation->ControlState = LAST_OUT_DATA;
474
    }
385
                        else if (pEPinfo->Usb_rLength == 0)
475
    else if (pEPinfo->Usb_rLength == 0)
386
                                {
476
    {
387
                                pInformation->ControlState = WAIT_STATUS_IN;
477
      pInformation->ControlState = WAIT_STATUS_IN;
388
                                USB_StatusIn();
478
      USB_StatusIn();
389
                                }
479
    }
-
 
480
  }
-
 
481
}
-
 
482
 
Line -... Line 483...
-
 
483
/*******************************************************************************
-
 
484
* Function Name  : DataStageIn.
-
 
485
* Description    : Data stage of a Control Read Transfer.
-
 
486
* Input          : None.
-
 
487
* Output         : None.
390
                }
488
* Return         : None.
-
 
489
*******************************************************************************/
-
 
490
void DataStageIn(void)
-
 
491
{
391
 
492
  ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
-
 
493
  u32 save_wLength = pEPinfo->Usb_wLength;
-
 
494
  u32 ControlState = pInformation->ControlState;
-
 
495
 
-
 
496
  u8 *DataBuffer;
-
 
497
  u32 Length;
-
 
498
 
-
 
499
  if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
-
 
500
  {
Line 392... Line 501...
392
}
501
    if(Data_Mul_MaxPacketSize == TRUE)
393
/*******************************************************************************
502
    {
394
* Function Name  : DataStageIn
-
 
395
* Description    : Data stage of a Control Read Transfer
-
 
396
* Input          :
-
 
397
* Output         :
-
 
Line 398... Line 503...
398
* Return         :
503
      /* No more data to send and empty packet */
-
 
504
      Send0LengthData();
399
*******************************************************************************/
505
      ControlState = LAST_IN_DATA;
-
 
506
      Data_Mul_MaxPacketSize = FALSE;
Line 400... Line 507...
400
void DataStageIn(void)
507
    }
401
{
-
 
Line 402... Line -...
402
        ENDPOINT_INFO   *pEPinfo = &pInformation->Ctrl_Info;
-
 
403
        u32     save_wLength = pEPinfo->Usb_wLength;
-
 
404
        u32     ControlState = pInformation->ControlState;
508
    else
Line 405... Line 509...
405
 
509
    {
Line 406... Line 510...
406
        u8      *DataBuffer;
510
      /* No more data to send so STALL the TX Status*/
407
        u32     Length;
511
      ControlState = WAIT_STATUS_OUT;
408
 
512
      vSetEPTxStatus(EP_TX_STALL);
Line 409... Line 513...
409
        if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
513
    }
Line 410... Line -...
410
        { /* no more data to send so STALL the TX Status*/
-
 
411
                ControlState = WAIT_STATUS_OUT;
514
   
412
                vSetEPTxStatus(EP_TX_STALL);
515
    goto Expect_Status_Out;
413
                goto Expect_Status_Out;
516
  }
414
        }
517
 
415
 
518
  Length = pEPinfo->PacketSize;
416
        Length = pEPinfo->PacketSize;
519
  ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
417
        ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
520
 
418
 
521
  if (Length > save_wLength)
419
        if (Length > save_wLength)
522
  {
420
                Length = save_wLength;
523
    Length = save_wLength;
421
 
524
  }
422
        DataBuffer = (*pEPinfo->CopyData)(Length);
525
 
423
       
526
  DataBuffer = (*pEPinfo->CopyData)(Length);
424
        UserToPMABufferCopy(DataBuffer,GetEPTxAddr(ENDP0),Length);
527
 
425
 
528
  UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
426
        SetEPTxCount(ENDP0, Length);
529
 
427
 
530
  SetEPTxCount(ENDP0, Length);
-
 
531
 
428
        pEPinfo->Usb_wLength -= Length;
532
  pEPinfo->Usb_wLength -= Length;
429
        pEPinfo->Usb_wOffset += Length;
533
  pEPinfo->Usb_wOffset += Length;
430
        vSetEPTxStatus(EP_TX_VALID);
534
  vSetEPTxStatus(EP_TX_VALID);
-
 
535
 
431
 
536
  USB_StatusOut();/* Expect the host to abort the data IN stage */
-
 
537
 
432
        USB_StatusOut();/* Expect the host to abort the data IN stage */
538
Expect_Status_Out:
433
 
539
  pInformation->ControlState = ControlState;
434
       
540
}
-
 
541
/*******************************************************************************
435
Expect_Status_Out:
542
* Function Name  : NoData_Setup0.
-
 
543
* Description    : Proceed the processing of setup request without data stage.
436
        pInformation->ControlState = ControlState;
544
* Input          : None.
437
}
545
* Output         : None.
438
/*******************************************************************************
546
* Return         : None.
439
* Function Name  : NoData_Setup0
547
*******************************************************************************/
440
* Description    : Proceed the processing of setup request without data stage
548
void NoData_Setup0(void)
441
* Input          : None
549
{
-
 
550
  RESULT Result = USB_UNSUPPORT;
-
 
551
  u32 RequestNo = pInformation->USBbRequest;
442
* Output         : None
552
  u32 ControlState;
-
 
553
 
443
* Return         : None
554
  if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
444
*******************************************************************************/
555
  {/* Device Request*/
445
void NoData_Setup0(void)
556
 
-
 
557
    /* SET_CONFIGURATION*/
446
{
558
    if (RequestNo == SET_CONFIGURATION)
-
 
559
    {
447
        RESULT  Result = USB_UNSUPPORT;
560
      Result = Standard_SetConfiguration();
448
        u32     RequestNo = pInformation->USBbRequest;
561
    }
449
        u32     ControlState;
562
 
450
       
563
    /*SET ADDRESS*/
451
        if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/* Device Request*/
564
    else if (RequestNo == SET_ADDRESS)
452
               
-
 
453
                /* SET_CONFIGURATION*/
-
 
454
                if (RequestNo == SET_CONFIGURATION)
-
 
455
                        Result = Standard_SetConfiguration();
565
    {
456
       
566
      if (pInformation->USBwValue0 > 127 || pInformation->USBwValue1 != 0
457
                /*SET ADDRESS*/
567
          || pInformation->USBwIndex != 0
458
                else if (RequestNo == SET_ADDRESS){
-
 
459
                        if(pInformation->USBwValue0 > 127 || pInformation->USBwValue1!=0
568
          || pInformation->Current_Configuration != 0)
460
                                ||pInformation->USBwIndex!=0 || pInformation->Current_Configuration!=0) /* Device Address should be 127 or less*/
-
 
461
                                                                                          /*call Beck spec USB 2.0*/
569
        /* Device Address should be 127 or less -> call Back spec USB 2.0*/
462
                                {              
-
 
463
                                ControlState = STALLED;
-
 
464
                                goto exit_NoData_Setup0;
-
 
465
                                }
-
 
466
                        else Result = USB_SUCCESS;
570
      {
467
                        }
-
 
468
                /*SET FEATURE for Device*/
571
        ControlState = STALLED;
469
                else if (RequestNo == SET_FEATURE){
-
 
470
                                if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
-
 
471
                                Result = Standard_SetDeviceFeature();
-
 
472
                                else
-
 
473
                                Result = USB_UNSUPPORT;
572
        goto exit_NoData_Setup0;
474
                        }
573
      }
475
                /*Clear FEATURE for Device */
-
 
476
                else if (RequestNo == CLEAR_FEATURE){
574
      else
477
                        if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
575
      {
478
                        Result = Standard_ClearFeature();
-
 
479
                        else
576
        Result = USB_SUCCESS;
480
                        Result = USB_UNSUPPORT;
577
      }
481
                }
-
 
482
 
578
    }
483
         }
-
 
484
 
-
 
485
        /* Interface Request*/
-
 
486
 
579
    /*SET FEATURE for Device*/
487
        else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) { 
-
 
488
                       
580
    else if (RequestNo == SET_FEATURE)
489
                        /*SET INTERFACE*/
-
 
490
                        if (RequestNo == SET_INTERFACE)
-
 
491
                                Result = Standard_SetInterface();
581
    {
492
        }
-
 
493
 
-
 
494
       
-
 
495
        /* EndPoint Request*/
-
 
496
 
-
 
497
        else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {
582
      if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
Line -... Line 583...
-
 
583
          && pInformation->USBwIndex == 0
-
 
584
          && ValBit(pInformation->Current_Feature, 5))
-
 
585
      {
-
 
586
        Result = Standard_SetDeviceFeature();
-
 
587
      }
-
 
588
      else
-
 
589
      {
-
 
590
        Result = USB_UNSUPPORT;
-
 
591
      }
-
 
592
    }
-
 
593
    /*Clear FEATURE for Device */
-
 
594
    else if (RequestNo == CLEAR_FEATURE)
-
 
595
    {
-
 
596
      if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
-
 
597
          && pInformation->USBwIndex == 0
-
 
598
          && ValBit(pInformation->Current_Feature, 5))
-
 
599
      {
-
 
600
        Result = Standard_ClearFeature();
-
 
601
      }
-
 
602
      else
-
 
603
      {
-
 
604
        Result = USB_UNSUPPORT;
-
 
605
      }
-
 
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
  }
498
                        /*CLEAR FEATURE for EndPoint*/
621
 
-
 
622
 
-
 
623
  /* EndPoint Request*/
-
 
624
 
-
 
625
  else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
-
 
626
  {
-
 
627
    /*CLEAR FEATURE for EndPoint*/
Line -... Line 628...
-
 
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();
499
                        if (RequestNo == CLEAR_FEATURE)
636
    }
Line 500... Line 637...
500
                         Result = Standard_ClearFeature();
637
  }
501
                        /* SET FEATURE for EndPoint*/
638
  else
502
                         else if (RequestNo == SET_FEATURE){
639
  {
503
                                Result = Standard_SetEndPointFeature();
640
    Result = USB_UNSUPPORT;
-
 
641
  }
-
 
642
 
504
                        }
643
 
505
        }
644
  if (Result != USB_SUCCESS)
506
        else
645
  {
507
                        Result = USB_UNSUPPORT;
646
    Result = (*pProperty->Class_NoData_Setup)(RequestNo);
508
 
647
    if (Result == USB_NOT_READY)
509
 
648
    {
510
        if (Result != USB_SUCCESS) {
649
      ControlState = PAUSE;
511
                    Result = (*pProperty->Class_NoData_Setup)(RequestNo);
650
      goto exit_NoData_Setup0;
512
                    if (Result == USB_NOT_READY) {
651
    }
Line 626... Line -...
626
 
-
 
627
        if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF) {    /* Data is not ready, wait it */
-
 
628
                pInformation->ControlState = PAUSE;
820
    {
629
                return;
821
      pInformation->Ctrl_Info.Usb_wLength = wLength;
630
        }
822
    }
631
        if (Result == USB_UNSUPPORT || pInformation->Ctrl_Info.Usb_wLength == 0) {
823
   
632
                /* Unsupported request */
824
    else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength)
633
                pInformation->ControlState = STALLED;
825
    {
634
                return;
826
      if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize)
635
        }
827
      {
636
 
828
        Data_Mul_MaxPacketSize = FALSE;
637
 
829
      }
638
        if (ValBit(pInformation->USBbmRequestType, 7)) {
830
      else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0)
639
                /* Device ==> Host */
831
      {
640
                u32     wLength = pInformation->USBwLength;
832
        Data_Mul_MaxPacketSize = TRUE;
641
 
833
      }
642
                /* Restrict the data length to be the one host asks */
834
    }  
643
                if (pInformation->Ctrl_Info.Usb_wLength > wLength)
835
 
644
                        pInformation->Ctrl_Info.Usb_wLength = wLength;
836
    pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
-
 
837
    DataStageIn();
645
 
838
  }
646
                pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
839
  else
647
                DataStageIn();
840
  {
648
        }
841
    pInformation->ControlState = OUT_DATA;
649
        else {
842
    vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */
650
                pInformation->ControlState = OUT_DATA;
843
  }
651
                vSetEPRxStatus(EP_RX_VALID);/* enable for next data reception */       
844
 
652
        }
845
  return;
653
 
846
}
654
        return;
847
 
655
} /* Data_Setup0 */
848
/*******************************************************************************
656
/*******************************************************************************
849
* Function Name  : Setup0_Process
657
* Function Name  : Setup0_Process
850
* Description    : Get the device request data and dispatch to individual process.
Line 658... Line 851...
658
* Description    : Get the device request data and dispatch to individual process
851
* Input          : None.
659
* Input          :
852
* Output         : None.
660
* Output         :
853
* Return         : Post0_Process.
661
* Return         :
854
*******************************************************************************/
662
*******************************************************************************/
855
u8 Setup0_Process(void)
663
u8 Setup0_Process(void)
856
{
664
{
857
#ifdef STR7xx /* STR7xx family*/
665
#ifdef STR7xx /* STR7xx family*/
858
  union {
666
  union {
859
    u8* b;
667
        u8*     b;
860
    u16* w;
668
        u16*    w;
861
  } pBuf;
669
        } pBuf;
862
  pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
670
  pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0)*2); /* *2 for 32 bits addr */
863
 
Line 705... Line 898...
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;
-
 
Line -... Line 914...
-
 
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;
Line -... Line 935...
-
 
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
{
-
 
754
        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
               
-
 
Line -... Line 950...
-
 
950
{
-
 
951
  u32 ControlState = pInformation->ControlState;
-
 
952
 
773
                ControlState = STALLED;
953
  if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
-
 
954
  {
-
 
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
Line -... Line 971...
-
 
971
  {
-
 
972
    ControlState = STALLED;
774
        }
973
  }
775
 
974
 
Line 776... Line 975...
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
 
-
 
980
/*******************************************************************************
781
/*******************************************************************************
981
* Function Name  : Post0_Process
782
* Function Name  : Post0_Process
982
* Description    : Stall the Endpoint 0 in case of error.
783
* Description    :
983
* Input          : None.
784
* Input          :
984
* Output         : None.
785
* Output         :
985
* Return         : - 0 if the control State is in PAUSE
Line 786... Line 986...
786
* Return         :
986
*                  - 1 if not.
-
 
987
*******************************************************************************/
787
*******************************************************************************/
988
u8 Post0_Process(void)
788
u8 Post0_Process(void)
989
{
789
{
990
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
Line 790... Line 991...
790
        SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
991
 
791
 
992
  if (pInformation->ControlState == STALLED)
-
 
993
  {
792
        if (pInformation->ControlState == STALLED) {
994
    vSetEPRxStatus(EP_RX_STALL);
793
                vSetEPRxStatus(EP_RX_STALL);
995
    vSetEPTxStatus(EP_TX_STALL);
794
                vSetEPTxStatus(EP_TX_STALL);
996
  }
795
        }
997
 
796
 
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.
Line 803... Line 1005...
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;
Line 809... Line 1011...
809
  u32   nEP = Device_Table.Total_Endpoint;
1011
  u32 nEP = Device_Table.Total_Endpoint;
-
 
1012
 
810
 
1013
  /* set address in every used endpoint */
811
        /* set address in every used endpoint */
1014
  for (i = 0; i < nEP; i++)
812
        for(i=0;i<nEP;i++)
1015
  {
813
        {
1016
    _SetEPAddress((u8)i, (u8)i);
814
                _SetEPAddress((u8)i, (u8)i);
1017
  }
815
        } /* for */
1018
  _SetDADDR(Val | DADDR_EF); /* set device address and enable function */
816
        _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