]> git.sur5r.net Git - armstart-ibdap/blob - inc/usbd/usbd_core.h
initial commit
[armstart-ibdap] / inc / usbd / usbd_core.h
1 /***********************************************************************\r
2 * $Id:: mw_usbd_core.h 331 2012-08-09 18:54:34Z usb10131                      $\r
3 *\r
4 * Project: USB device ROM Stack\r
5 *\r
6 * Description:\r
7 *     USB core controller structure definitions and function prototypes.\r
8 *\r
9 ***********************************************************************\r
10 *   Copyright(C) 2011, NXP Semiconductor\r
11 *   All rights reserved.\r
12 *\r
13 * Software that is described herein is for illustrative purposes only\r
14 * which provides customers with programming information regarding the\r
15 * products. This software is supplied "AS IS" without any warranties.\r
16 * NXP Semiconductors assumes no responsibility or liability for the\r
17 * use of the software, conveys no license or title under any patent,\r
18 * copyright, or mask work right to the product. NXP Semiconductors\r
19 * reserves the right to make changes in the software without\r
20 * notification. NXP Semiconductors also make no representation or\r
21 * warranty that such application will be suitable for the specified\r
22 * use without further testing or modification.\r
23 **********************************************************************/\r
24 #ifndef __MW_USBD_CORE_H__\r
25 #define __MW_USBD_CORE_H__\r
26 \r
27 #include "error.h"\r
28 #include "usbd.h"\r
29 #include "app_usbd_cfg.h"\r
30 \r
31 /** \file\r
32  *  \brief ROM API for USB device stack.\r
33  *\r
34  *  Definition of functions exported by core layer of ROM based USB device stack.\r
35  *\r
36  */\r
37 \r
38 /** \ingroup Group_USBD\r
39  *  @defgroup USBD_Core USB Core Layer\r
40  *  \section Sec_CoreModDescription Module Description\r
41  *  The USB Core Layer implements the device abstraction defined in the <em> Universal Serial Bus Specification, </em>\r
42  *  for applications to interact with the USB device interface on the device. The software in this layer responds to \r
43  *  standard requests and returns standard descriptors. In current stack the Init() routine part of \r
44  *  \ref USBD_HW_API_T structure initializes both hardware layer and core layer.\r
45  */\r
46 \r
47 \r
48 /* function pointer types */\r
49 \r
50 /** \ingroup USBD_Core \r
51  *  \typedef USB_CB_T\r
52  *  \brief USB device stack's event callback function type.\r
53  *\r
54  *  The USB device stack exposes several event triggers through callback to application layer. The\r
55  *  application layer can register methods to be called when such USB event happens.\r
56  *  \r
57  *  \param[in] hUsb Handle to the USB device stack. \r
58  *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.\r
59  *          \retval LPC_OK On success\r
60  *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line. \r
61  *          \retval ERR_USBD_xxx  Other error conditions. \r
62  *                                             \r
63  */\r
64 typedef ErrorCode_t (*USB_CB_T) (USBD_HANDLE_T hUsb);\r
65 \r
66 /** \ingroup USBD_Core \r
67  *  \typedef USB_PARAM_CB_T\r
68  *  \brief USB device stack's event callback function type.\r
69  *\r
70  *  The USB device stack exposes several event triggers through callback to application layer. The\r
71  *  application layer can register methods to be called when such USB event happens.\r
72  *  \r
73  *  \param[in] hUsb Handle to the USB device stack. \r
74  *  \param[in] param1 Extra information related to the event. \r
75  *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.\r
76  *          \retval LPC_OK On success\r
77  *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line. \r
78  *          \retval ERR_USBD_xxx  For other error conditions. \r
79  *                                             \r
80  */\r
81 typedef ErrorCode_t (*USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t param1);\r
82 \r
83 /** \ingroup USBD_Core\r
84  *  \typedef USB_EP_HANDLER_T\r
85  *  \brief USBD setup request and endpoint event handler type.\r
86  *\r
87  *  The application layer should define the custom class's EP0 handler with function signature. \r
88  *  The stack calls all the registered class handlers on any EP0 event before going through default \r
89  *  handling of the event. This gives the class handlers to implement class specific request handlers\r
90  *  and also to override the default stack handling for a particular event targeted to the interface.\r
91  *  If an event is not handled by the callback the function should return ERR_USBD_UNHANDLED. For all\r
92  *  other return codes the stack assumes that callback has taken care of the event and hence will not\r
93  *  process the event any further and issues a STALL condition on EP0 indicating error to the host.\r
94  *  \n\r
95  *  For endpoint interrupt handler the return value is ignored by the stack.\r
96  *  \n\r
97  *  \param[in] hUsb Handle to the USB device stack. \r
98  *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack. \r
99  *  \param[in] event  Type of endpoint event. See \ref USBD_EVENT_T for more details.\r
100  *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.\r
101  *          \retval LPC_OK On success.\r
102  *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line. \r
103  *          \retval ERR_USBD_xxx  For other error conditions. \r
104  *                                             \r
105  */\r
106 typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void* data, uint32_t event);\r
107 \r
108 \r
109 /** \ingroup USBD_Core \r
110  *  \brief USB descriptors data structure.\r
111  *  \ingroup USBD_Core\r
112  *\r
113  *  \details  This structure is used as part of USB device stack initialization\r
114  *  parameter structure \ref USBD_API_INIT_PARAM_T. This structure contains\r
115  *  pointers to various descriptor arrays needed by the stack. These descriptors\r
116  *  are reported to USB host as part of enumerations process.\r
117  *\r
118  *  \note All descriptor pointers assigned in this structure should be on 4 byte\r
119  *  aligned address boundary.\r
120  */\r
121 typedef struct _USB_CORE_DESCS_T\r
122 {\r
123   uint8_t *device_desc; /**< Pointer to USB device descriptor */\r
124   uint8_t *string_desc; /**< Pointer to array of USB string descriptors */\r
125   uint8_t *full_speed_desc; /**< Pointer to USB device configuration descriptor\r
126                             * when device is operating in full speed mode.\r
127                             */\r
128   uint8_t *high_speed_desc; /**< Pointer to USB device configuration descriptor\r
129                             * when device is operating in high speed mode. For\r
130                             * full-speed only implementation this pointer should\r
131                             * be same as full_speed_desc.\r
132                             */\r
133   uint8_t *device_qualifier; /**< Pointer to USB device qualifier descriptor. For\r
134                              * full-speed only implementation this pointer should\r
135                              * be set to null (0).\r
136                              */\r
137 } USB_CORE_DESCS_T;\r
138 \r
139 /** \brief USB device stack initialization parameter data structure.\r
140  *  \ingroup USBD_Core\r
141  *\r
142  *  \details  This data structure is used to pass initialization parameters to the \r
143  *  USB device stack's init function.\r
144  *\r
145  */\r
146 typedef struct USBD_API_INIT_PARAM\r
147 {\r
148   uint32_t usb_reg_base; /**< USB device controller's base register address. */ \r
149   uint32_t mem_base;  /**< Base memory location from where the stack can allocate\r
150                       data and buffers. \note The memory address set in this field\r
151                       should be accessible by USB DMA controller. Also this value\r
152                       should be aligned on 2048 byte boundary.\r
153                       */\r
154   uint32_t mem_size;  /**< The size of memory buffer which stack can use. \r
155                       \note The \em mem_size should be greater than the size \r
156                       returned by USBD_HW_API::GetMemSize() routine.*/\r
157   uint8_t max_num_ep; /**< max number of endpoints supported by the USB device \r
158                       controller instance (specified by \em usb_reg_base field)\r
159                       to which this instance of stack is attached. \r
160                       */\r
161   uint8_t pad0[3];\r
162   /* USB Device Events Callback Functions */\r
163         /** Event for USB interface reset. This event fires when the USB host requests that the device \r
164          *  reset its interface. This event fires after the control endpoint has been automatically\r
165          *  configured by the library.\r
166          *  \n\r
167          *  \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
168          *  callback will prevent the device from enumerating correctly or operate properly.\r
169          *\r
170          */\r
171   USB_CB_T USB_Reset_Event;\r
172 \r
173         /** Event for USB suspend. This event fires when the USB host suspends the device by halting its\r
174          *  transmission of Start Of Frame pulses to the device. This is generally hooked in order to move\r
175          *  the device over to a low power state until the host wakes up the device. \r
176          *  \n\r
177          *  \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
178          *  callback will cause other system issues.\r
179          */\r
180   USB_CB_T USB_Suspend_Event;\r
181 \r
182         /** Event for USB wake up or resume. This event fires when a the USB device interface is suspended \r
183          *  and the host wakes up the device by supplying Start Of Frame pulses. This is generally\r
184          *  hooked to pull the user application out of a low power state and back into normal operating\r
185          *  mode. \r
186          *  \n\r
187          *  \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
188          *  callback will cause other system issues.\r
189          *\r
190          */\r
191   USB_CB_T USB_Resume_Event;\r
192 \r
193   /** Reserved parameter should be set to zero. */\r
194   USB_CB_T reserved_sbz;\r
195 \r
196   /** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB\r
197          *  frame, once per millisecond in full-speed mode or once per 125 microseconds in high-speed mode,\r
198    *  and is synchronized to the USB bus. \r
199          *\r
200          *  This event is time-critical; it is run once per millisecond (full-speed mode) and thus long handlers \r
201          *  will significantly degrade device performance. This event should only be enabled when needed to \r
202    *  reduce device wake-ups.\r
203          *\r
204          *  \note This event is not normally active - it must be manually enabled and disabled via the USB interrupt\r
205          *        register.\r
206          *        \n\n\r
207          */  \r
208   USB_CB_T USB_SOF_Event;\r
209 \r
210   /** Event for remote wake-up configuration, when enabled. This event fires when the USB host\r
211          *  request the device to configure itself for remote wake-up capability. The USB host sends\r
212    *  this request to device which report remote wake-up capable in their device descriptors,\r
213    *  before going to low-power state. The application layer should implement this callback if\r
214    *  they have any special on board circuit to trigger remote wake up event. Also application\r
215    *  can use this callback to differentiate the following SUSPEND event is caused by cable plug-out\r
216    *  or host SUSPEND request. The device can wake-up host only after receiving this callback and\r
217    *  remote wake-up feature is enabled by host. To signal remote wake-up the device has to generate\r
218    *  resume signaling on bus by calling usapi.hw->WakeUp() routine.\r
219          *\r
220          *  \n\n\r
221    *  \param[in] hUsb Handle to the USB device stack. \r
222    *  \param[in] param1 When 0 - Clear the wake-up configuration, 1 - Enable the wake-up configuration.\r
223    *  \return The call back should return \ref ErrorCode_t type to indicate success or error condition.\r
224          */  \r
225   USB_PARAM_CB_T USB_WakeUpCfg;\r
226 \r
227   /** Reserved parameter should be set to zero. */\r
228   USB_PARAM_CB_T USB_Power_Event;\r
229 \r
230   /** Event for error condition. This event fires when USB device controller detect \r
231          *  an error condition in the system.  \r
232          *\r
233          *  \n\n\r
234    *  \param[in] hUsb Handle to the USB device stack. \r
235    *  \param[in] param1 USB device interrupt status register. \r
236    *  \return The call back should return \ref ErrorCode_t type to indicate success or error condition.\r
237    */  \r
238   USB_PARAM_CB_T USB_Error_Event;\r
239 \r
240   /* USB Core Events Callback Functions */\r
241   /** Event for USB configuration number changed. This event fires when a the USB host changes the\r
242    *  selected configuration number. On receiving configuration change request from host, the stack\r
243    *  enables/configures the endpoints needed by the new configuration before calling this callback\r
244    *  function.\r
245          *  \n\r
246          *  \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
247          *  callback will prevent the device from enumerating correctly or operate properly.\r
248    *\r
249    */\r
250   USB_CB_T USB_Configure_Event;\r
251 \r
252   /** Event for USB interface setting changed. This event fires when a the USB host changes the\r
253    *  interface setting to one of alternate interface settings. On receiving interface change \r
254    *  request from host, the stack enables/configures the endpoints needed by the new alternate \r
255    *  interface setting before calling this callback function.\r
256          *  \n\r
257          *  \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
258          *  callback will prevent the device from enumerating correctly or operate properly.\r
259    *\r
260    */\r
261   USB_CB_T USB_Interface_Event;\r
262 \r
263   /** Event for USB feature changed. This event fires when a the USB host send set/clear feature\r
264    *  request. The stack handles this request for USB_FEATURE_REMOTE_WAKEUP, USB_FEATURE_TEST_MODE\r
265    *  and USB_FEATURE_ENDPOINT_STALL features only. On receiving feature request from host, the  \r
266    *  stack handle the request appropriately and then calls this callback function.\r
267          *  \n\r
268          *  \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
269          *  callback will prevent the device from enumerating correctly or operate properly.\r
270    *\r
271    */\r
272  USB_CB_T USB_Feature_Event;\r
273 \r
274   /* cache and MMU translation functions */\r
275   /** Reserved parameter for future use. should be set to zero. */\r
276   uint32_t (* virt_to_phys)(void* vaddr);\r
277   /** Reserved parameter for future use. should be set to zero. */\r
278   void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);\r
279 \r
280 } USBD_API_INIT_PARAM_T;\r
281 \r
282 \r
283 /** \brief USBD stack Core API functions structure.\r
284  *  \ingroup USBD_Core\r
285  *\r
286  *  \details  This module exposes functions which interact directly with USB device stack's core layer.\r
287  *  The application layer uses this component when it has to implement custom class function driver or \r
288  *  standard class function driver which is not part of the current USB device stack.\r
289  *  The functions exposed by this interface are to register class specific EP0 handlers and corresponding\r
290  *  utility functions to manipulate EP0 state machine of the stack. This interface also exposes\r
291  *  function to register custom endpoint interrupt handler.\r
292  *\r
293  */\r
294 typedef struct USBD_CORE_API \r
295 {\r
296  /** \fn ErrorCode_t RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data)\r
297   *  Function to register class specific EP0 event handler with USB device stack.\r
298   *\r
299   *  The application layer uses this function when it has to register the custom class's EP0 handler. \r
300   *  The stack calls all the registered class handlers on any EP0 event before going through default \r
301   *  handling of the event. This gives the class handlers to implement class specific request handlers\r
302   *  and also to override the default stack handling for a particular event targeted to the interface.\r
303   *  Check \ref USB_EP_HANDLER_T for more details on how the callback function should be implemented. Also\r
304   *  application layer could use this function to register EP0 handler which responds to vendor specific \r
305   *  requests.\r
306   *  \r
307   *  \param[in] hUsb Handle to the USB device stack. \r
308   *  \param[in] pfn  Class specific EP0 handler function.\r
309   *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack. \r
310   *  \return Returns \ref ErrorCode_t type to indicate success or error condition.\r
311   *          \retval LPC_OK On success\r
312   *          \retval ERR_USBD_TOO_MANY_CLASS_HDLR(0x0004000c)  The number of class handlers registered is \r
313                         greater than the number of handlers allowed by the stack.\r
314   *                                             \r
315   */\r
316   ErrorCode_t (*RegisterClassHandler)(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);\r
317 \r
318  /** \fn ErrorCode_t RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data)\r
319   *  Function to register interrupt/event handler for the requested endpoint with USB device stack.\r
320   *\r
321   *  The application layer uses this function to register the endpoint event handler. \r
322   *  The stack calls all the registered endpoint handlers when \r
323   *  - USB_EVT_OUT or USB_EVT_OUT_NAK events happen for OUT endpoint.  \r
324   *  - USB_EVT_IN or USB_EVT_IN_NAK events happen for IN endpoint.\r
325   *  Check USB_EP_HANDLER_T for more details on how the callback function should be implemented.\r
326   *  \note By default endpoint _NAK events are not enabled. Application should call \ref USBD_HW_API_T::EnableEvent\r
327   *  for the corresponding endpoint.\r
328   *  \r
329   *  \param[in] hUsb Handle to the USB device stack. \r
330   *  \param[in] ep_index  Endpoint index. Computed as \r
331   *                       - For OUT endpoints = 2 * endpoint number eg. for EP2_OUT it is 4.\r
332   *                       - For IN endopoints = (2 * endpoint number) + 1 eg. for EP2_IN it is 5.\r
333   *  \param[in] pfn  Endpoint event handler function.\r
334   *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack. \r
335   *  \return Returns \ref ErrorCode_t type to indicate success or error condition.\r
336   *          \retval LPC_OK On success\r
337   *          \retval ERR_API_INVALID_PARAM2  ep_index is outside the boundary ( < 2 * USBD_API_INIT_PARAM_T::max_num_ep). \r
338   *                                             \r
339   */\r
340   ErrorCode_t (*RegisterEpHandler)(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);\r
341   \r
342   /** \fn void SetupStage(USBD_HANDLE_T hUsb)\r
343    *  Function to set EP0 state machine in setup state.\r
344    *\r
345    *  This function is called by USB stack and the application layer to \r
346    *  set the EP0 state machine in setup state. This function will read\r
347    *  the setup packet received from USB host into stack's buffer. \r
348    *  \n\r
349    *  \note This interface is provided to users to invoke this function in other \r
350    *  scenarios which are not handle by current stack. In most user applications \r
351    *  this function is not called directly.Also this function can be used by  \r
352    *  users who are selectively modifying the USB device stack's standard handlers \r
353    *  through callback interface exposed by the stack.\r
354    *  \r
355    *  \param[in] hUsb Handle to the USB device stack. \r
356    *  \return Nothing.\r
357    */\r
358   void (*SetupStage )(USBD_HANDLE_T hUsb); \r
359   \r
360   /** \fn void DataInStage(USBD_HANDLE_T hUsb)\r
361    *  Function to set EP0 state machine in data_in state.\r
362    *\r
363    *  This function is called by USB stack and the application layer to \r
364    *  set the EP0 state machine in data_in state. This function will write\r
365    *  the data present in EP0Data buffer to EP0 FIFO for transmission to host.\r
366    *  \n\r
367    *  \note This interface is provided to users to invoke this function in other \r
368    *  scenarios which are not handle by current stack. In most user applications \r
369    *  this function is not called directly.Also this function can be used by  \r
370    *  users who are selectively modifying the USB device stack's standard handlers \r
371    *  through callback interface exposed by the stack.\r
372    *  \r
373    *  \param[in] hUsb Handle to the USB device stack. \r
374    *  \return Nothing.\r
375    */\r
376   void (*DataInStage)(USBD_HANDLE_T hUsb);\r
377 \r
378   /** \fn void DataOutStage(USBD_HANDLE_T hUsb)\r
379    *  Function to set EP0 state machine in data_out state.\r
380    *\r
381    *  This function is called by USB stack and the application layer to \r
382    *  set the EP0 state machine in data_out state. This function will read\r
383    *  the control data (EP0 out packets) received from USB host into EP0Data buffer. \r
384    *  \n\r
385    *  \note This interface is provided to users to invoke this function in other \r
386    *  scenarios which are not handle by current stack. In most user applications \r
387    *  this function is not called directly.Also this function can be used by  \r
388    *  users who are selectively modifying the USB device stack's standard handlers \r
389    *  through callback interface exposed by the stack.\r
390    *  \r
391    *  \param[in] hUsb Handle to the USB device stack. \r
392    *  \return Nothing.\r
393    */\r
394   void (*DataOutStage)(USBD_HANDLE_T hUsb); \r
395 \r
396   /** \fn void StatusInStage(USBD_HANDLE_T hUsb)\r
397    *  Function to set EP0 state machine in status_in state.\r
398    *\r
399    *  This function is called by USB stack and the application layer to \r
400    *  set the EP0 state machine in status_in state. This function will send\r
401    *  zero length IN packet on EP0 to host, indicating positive status. \r
402    *  \n\r
403    *  \note This interface is provided to users to invoke this function in other \r
404    *  scenarios which are not handle by current stack. In most user applications \r
405    *  this function is not called directly.Also this function can be used by  \r
406    *  users who are selectively modifying the USB device stack's standard handlers \r
407    *  through callback interface exposed by the stack.\r
408    *  \r
409    *  \param[in] hUsb Handle to the USB device stack. \r
410    *  \return Nothing.\r
411    */\r
412   void (*StatusInStage)(USBD_HANDLE_T hUsb); \r
413   /** \fn void StatusOutStage(USBD_HANDLE_T hUsb)\r
414    *  Function to set EP0 state machine in status_out state.\r
415    *\r
416    *  This function is called by USB stack and the application layer to \r
417    *  set the EP0 state machine in status_out state. This function will read\r
418    *  the zero length OUT packet received from USB host on EP0. \r
419    *  \n\r
420    *  \note This interface is provided to users to invoke this function in other \r
421    *  scenarios which are not handle by current stack. In most user applications \r
422    *  this function is not called directly.Also this function can be used by  \r
423    *  users who are selectively modifying the USB device stack's standard handlers \r
424    *  through callback interface exposed by the stack.\r
425    *  \r
426    *  \param[in] hUsb Handle to the USB device stack. \r
427    *  \return Nothing.\r
428    */\r
429   void (*StatusOutStage)(USBD_HANDLE_T hUsb);\r
430 \r
431   /** \fn void StallEp0(USBD_HANDLE_T hUsb)\r
432    *  Function to set EP0 state machine in stall state.\r
433    *\r
434    *  This function is called by USB stack and the application layer to \r
435    *  generate STALL signaling on EP0 endpoint. This function will also\r
436    *  reset the EP0Data buffer. \r
437    *  \n\r
438    *  \note This interface is provided to users to invoke this function in other \r
439    *  scenarios which are not handle by current stack. In most user applications \r
440    *  this function is not called directly.Also this function can be used by  \r
441    *  users who are selectively modifying the USB device stack's standard handlers \r
442    *  through callback interface exposed by the stack.\r
443    *  \r
444    *  \param[in] hUsb Handle to the USB device stack. \r
445    *  \return Nothing.\r
446    */\r
447   void (*StallEp0)(USBD_HANDLE_T hUsb);\r
448 \r
449 } USBD_CORE_API_T;\r
450 \r
451 /*-----------------------------------------------------------------------------\r
452  *  Private functions & structures prototypes\r
453  *-----------------------------------------------------------------------------*/\r
454 \r
455  /** @cond  ADVANCED_API */\r
456 \r
457 /* forward declaration */\r
458 struct _USB_CORE_CTRL_T;\r
459 typedef struct _USB_CORE_CTRL_T  USB_CORE_CTRL_T;\r
460 \r
461 /* USB device Speed status defines */\r
462 #define USB_FULL_SPEED    0\r
463 #define USB_HIGH_SPEED    1\r
464 \r
465 /* USB Endpoint Data Structure */\r
466 typedef struct _USB_EP_DATA\r
467 {\r
468   uint8_t  *pData;\r
469   uint16_t   Count;\r
470   uint16_t pad0;\r
471 } USB_EP_DATA;\r
472 \r
473 \r
474 /* USB core controller data structure */\r
475 struct _USB_CORE_CTRL_T\r
476 {\r
477   /* override-able function pointers ~ c++ style virtual functions*/\r
478   USB_CB_T USB_EvtSetupHandler;\r
479   USB_CB_T USB_EvtOutHandler;\r
480   USB_PARAM_CB_T USB_ReqVendor;\r
481   USB_CB_T USB_ReqGetStatus;\r
482   USB_CB_T USB_ReqGetDescriptor;\r
483   USB_CB_T USB_ReqGetConfiguration;\r
484   USB_CB_T USB_ReqSetConfiguration;\r
485   USB_CB_T USB_ReqGetInterface;\r
486   USB_CB_T USB_ReqSetInterface;\r
487   USB_PARAM_CB_T USB_ReqSetClrFeature;\r
488 \r
489   /* USB Device Events Callback Functions */\r
490   USB_CB_T USB_Reset_Event;\r
491   USB_CB_T USB_Suspend_Event;\r
492   USB_CB_T USB_Resume_Event;\r
493   USB_CB_T USB_SOF_Event;\r
494   USB_PARAM_CB_T USB_Power_Event;\r
495   USB_PARAM_CB_T USB_Error_Event;\r
496   USB_PARAM_CB_T USB_WakeUpCfg;\r
497 \r
498   /* USB Core Events Callback Functions */\r
499   USB_CB_T USB_Configure_Event;\r
500   USB_CB_T USB_Interface_Event;\r
501   USB_CB_T USB_Feature_Event;\r
502 \r
503   /* cache and MMU translation functions */\r
504   uint32_t (* virt_to_phys)(void* vaddr);\r
505   void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);\r
506 \r
507   /* event handlers for endpoints. */\r
508   USB_EP_HANDLER_T  ep_event_hdlr[2 * USB_MAX_EP_NUM];\r
509   void*  ep_hdlr_data[2 * USB_MAX_EP_NUM];\r
510 \r
511   /* USB class handlers */\r
512   USB_EP_HANDLER_T  ep0_hdlr_cb[USB_MAX_IF_NUM];\r
513   void*  ep0_cb_data[USB_MAX_IF_NUM];\r
514   uint8_t num_ep0_hdlrs;\r
515   /* USB Core data Variables */\r
516   uint8_t max_num_ep; /* max number of endpoints supported by the HW */\r
517   uint8_t device_speed;\r
518   uint8_t  num_interfaces;\r
519   uint8_t  device_addr;\r
520   uint8_t  config_value;\r
521   uint16_t device_status;\r
522   uint8_t *device_desc;\r
523   uint8_t *string_desc;\r
524   uint8_t *full_speed_desc;\r
525   uint8_t *high_speed_desc;\r
526   uint8_t *device_qualifier;\r
527   uint32_t ep_mask;\r
528   uint32_t ep_halt;\r
529   uint32_t ep_stall;\r
530   uint8_t  alt_setting[USB_MAX_IF_NUM];\r
531   /* HW driver data pointer */\r
532   void* hw_data;\r
533 \r
534   /* USB Endpoint 0 Data Info */\r
535   USB_EP_DATA EP0Data;\r
536 \r
537   /* USB Endpoint 0 Buffer */\r
538   //ALIGNED(4)\r
539   uint8_t  EP0Buf[64];\r
540 \r
541   /* USB Setup Packet */\r
542   //ALIGNED(4)\r
543   USB_SETUP_PACKET SetupPacket;\r
544 \r
545 };\r
546 \r
547 /* USB Core Functions */\r
548 extern void mwUSB_InitCore(USB_CORE_CTRL_T* pCtrl, USB_CORE_DESCS_T* pdescr, USBD_API_INIT_PARAM_T* param);\r
549 extern void mwUSB_ResetCore(USBD_HANDLE_T hUsb);\r
550 \r
551 /* inline functions */\r
552 static INLINE void USB_SetSpeedMode(USB_CORE_CTRL_T* pCtrl, uint8_t mode)\r
553 {\r
554     pCtrl->device_speed = mode;   \r
555 }\r
556 \r
557 static INLINE bool USB_IsConfigured(USBD_HANDLE_T hUsb)\r
558 {\r
559     USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*) hUsb;\r
560     return (bool) (pCtrl->config_value != 0);   \r
561 }\r
562 \r
563 /** @cond  DIRECT_API */\r
564 /* midleware API */\r
565 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);\r
566 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);\r
567 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb); \r
568 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);\r
569 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb); \r
570 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb); \r
571 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);\r
572 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);\r
573 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);\r
574 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);\r
575 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb); \r
576 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);\r
577 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb); \r
578 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb); \r
579 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);\r
580 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);\r
581 /** @endcond */\r
582 \r
583 /** @endcond */\r
584 \r
585 #endif  /* __MW_USBD_CORE_H__ */\r