+/***********************************************************************\r
+* $Id:: mw_usbd_core.h 331 2012-08-09 18:54:34Z usb10131 $\r
+*\r
+* Project: USB device ROM Stack\r
+*\r
+* Description:\r
+* USB core controller structure definitions and function prototypes.\r
+*\r
+***********************************************************************\r
+* Copyright(C) 2011, NXP Semiconductor\r
+* All rights reserved.\r
+*\r
+* Software that is described herein is for illustrative purposes only\r
+* which provides customers with programming information regarding the\r
+* products. This software is supplied "AS IS" without any warranties.\r
+* NXP Semiconductors assumes no responsibility or liability for the\r
+* use of the software, conveys no license or title under any patent,\r
+* copyright, or mask work right to the product. NXP Semiconductors\r
+* reserves the right to make changes in the software without\r
+* notification. NXP Semiconductors also make no representation or\r
+* warranty that such application will be suitable for the specified\r
+* use without further testing or modification.\r
+**********************************************************************/\r
+#ifndef __MW_USBD_CORE_H__\r
+#define __MW_USBD_CORE_H__\r
+\r
+#include "error.h"\r
+#include "usbd.h"\r
+#include "app_usbd_cfg.h"\r
+\r
+/** \file\r
+ * \brief ROM API for USB device stack.\r
+ *\r
+ * Definition of functions exported by core layer of ROM based USB device stack.\r
+ *\r
+ */\r
+\r
+/** \ingroup Group_USBD\r
+ * @defgroup USBD_Core USB Core Layer\r
+ * \section Sec_CoreModDescription Module Description\r
+ * The USB Core Layer implements the device abstraction defined in the <em> Universal Serial Bus Specification, </em>\r
+ * for applications to interact with the USB device interface on the device. The software in this layer responds to \r
+ * standard requests and returns standard descriptors. In current stack the Init() routine part of \r
+ * \ref USBD_HW_API_T structure initializes both hardware layer and core layer.\r
+ */\r
+\r
+\r
+/* function pointer types */\r
+\r
+/** \ingroup USBD_Core \r
+ * \typedef USB_CB_T\r
+ * \brief USB device stack's event callback function type.\r
+ *\r
+ * The USB device stack exposes several event triggers through callback to application layer. The\r
+ * application layer can register methods to be called when such USB event happens.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.\r
+ * \retval LPC_OK On success\r
+ * \retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line. \r
+ * \retval ERR_USBD_xxx Other error conditions. \r
+ * \r
+ */\r
+typedef ErrorCode_t (*USB_CB_T) (USBD_HANDLE_T hUsb);\r
+\r
+/** \ingroup USBD_Core \r
+ * \typedef USB_PARAM_CB_T\r
+ * \brief USB device stack's event callback function type.\r
+ *\r
+ * The USB device stack exposes several event triggers through callback to application layer. The\r
+ * application layer can register methods to be called when such USB event happens.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \param[in] param1 Extra information related to the event. \r
+ * \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.\r
+ * \retval LPC_OK On success\r
+ * \retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line. \r
+ * \retval ERR_USBD_xxx For other error conditions. \r
+ * \r
+ */\r
+typedef ErrorCode_t (*USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t param1);\r
+\r
+/** \ingroup USBD_Core\r
+ * \typedef USB_EP_HANDLER_T\r
+ * \brief USBD setup request and endpoint event handler type.\r
+ *\r
+ * The application layer should define the custom class's EP0 handler with function signature. \r
+ * The stack calls all the registered class handlers on any EP0 event before going through default \r
+ * handling of the event. This gives the class handlers to implement class specific request handlers\r
+ * and also to override the default stack handling for a particular event targeted to the interface.\r
+ * If an event is not handled by the callback the function should return ERR_USBD_UNHANDLED. For all\r
+ * other return codes the stack assumes that callback has taken care of the event and hence will not\r
+ * process the event any further and issues a STALL condition on EP0 indicating error to the host.\r
+ * \n\r
+ * For endpoint interrupt handler the return value is ignored by the stack.\r
+ * \n\r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \param[in] data Pointer to the data which will be passed when callback function is called by the stack. \r
+ * \param[in] event Type of endpoint event. See \ref USBD_EVENT_T for more details.\r
+ * \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.\r
+ * \retval LPC_OK On success.\r
+ * \retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line. \r
+ * \retval ERR_USBD_xxx For other error conditions. \r
+ * \r
+ */\r
+typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void* data, uint32_t event);\r
+\r
+\r
+/** \ingroup USBD_Core \r
+ * \brief USB descriptors data structure.\r
+ * \ingroup USBD_Core\r
+ *\r
+ * \details This structure is used as part of USB device stack initialization\r
+ * parameter structure \ref USBD_API_INIT_PARAM_T. This structure contains\r
+ * pointers to various descriptor arrays needed by the stack. These descriptors\r
+ * are reported to USB host as part of enumerations process.\r
+ *\r
+ * \note All descriptor pointers assigned in this structure should be on 4 byte\r
+ * aligned address boundary.\r
+ */\r
+typedef struct _USB_CORE_DESCS_T\r
+{\r
+ uint8_t *device_desc; /**< Pointer to USB device descriptor */\r
+ uint8_t *string_desc; /**< Pointer to array of USB string descriptors */\r
+ uint8_t *full_speed_desc; /**< Pointer to USB device configuration descriptor\r
+ * when device is operating in full speed mode.\r
+ */\r
+ uint8_t *high_speed_desc; /**< Pointer to USB device configuration descriptor\r
+ * when device is operating in high speed mode. For\r
+ * full-speed only implementation this pointer should\r
+ * be same as full_speed_desc.\r
+ */\r
+ uint8_t *device_qualifier; /**< Pointer to USB device qualifier descriptor. For\r
+ * full-speed only implementation this pointer should\r
+ * be set to null (0).\r
+ */\r
+} USB_CORE_DESCS_T;\r
+\r
+/** \brief USB device stack initialization parameter data structure.\r
+ * \ingroup USBD_Core\r
+ *\r
+ * \details This data structure is used to pass initialization parameters to the \r
+ * USB device stack's init function.\r
+ *\r
+ */\r
+typedef struct USBD_API_INIT_PARAM\r
+{\r
+ uint32_t usb_reg_base; /**< USB device controller's base register address. */ \r
+ uint32_t mem_base; /**< Base memory location from where the stack can allocate\r
+ data and buffers. \note The memory address set in this field\r
+ should be accessible by USB DMA controller. Also this value\r
+ should be aligned on 2048 byte boundary.\r
+ */\r
+ uint32_t mem_size; /**< The size of memory buffer which stack can use. \r
+ \note The \em mem_size should be greater than the size \r
+ returned by USBD_HW_API::GetMemSize() routine.*/\r
+ uint8_t max_num_ep; /**< max number of endpoints supported by the USB device \r
+ controller instance (specified by \em usb_reg_base field)\r
+ to which this instance of stack is attached. \r
+ */\r
+ uint8_t pad0[3];\r
+ /* USB Device Events Callback Functions */\r
+ /** Event for USB interface reset. This event fires when the USB host requests that the device \r
+ * reset its interface. This event fires after the control endpoint has been automatically\r
+ * configured by the library.\r
+ * \n\r
+ * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
+ * callback will prevent the device from enumerating correctly or operate properly.\r
+ *\r
+ */\r
+ USB_CB_T USB_Reset_Event;\r
+\r
+ /** Event for USB suspend. This event fires when the USB host suspends the device by halting its\r
+ * transmission of Start Of Frame pulses to the device. This is generally hooked in order to move\r
+ * the device over to a low power state until the host wakes up the device. \r
+ * \n\r
+ * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
+ * callback will cause other system issues.\r
+ */\r
+ USB_CB_T USB_Suspend_Event;\r
+\r
+ /** Event for USB wake up or resume. This event fires when a the USB device interface is suspended \r
+ * and the host wakes up the device by supplying Start Of Frame pulses. This is generally\r
+ * hooked to pull the user application out of a low power state and back into normal operating\r
+ * mode. \r
+ * \n\r
+ * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
+ * callback will cause other system issues.\r
+ *\r
+ */\r
+ USB_CB_T USB_Resume_Event;\r
+\r
+ /** Reserved parameter should be set to zero. */\r
+ USB_CB_T reserved_sbz;\r
+\r
+ /** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB\r
+ * frame, once per millisecond in full-speed mode or once per 125 microseconds in high-speed mode,\r
+ * and is synchronized to the USB bus. \r
+ *\r
+ * This event is time-critical; it is run once per millisecond (full-speed mode) and thus long handlers \r
+ * will significantly degrade device performance. This event should only be enabled when needed to \r
+ * reduce device wake-ups.\r
+ *\r
+ * \note This event is not normally active - it must be manually enabled and disabled via the USB interrupt\r
+ * register.\r
+ * \n\n\r
+ */ \r
+ USB_CB_T USB_SOF_Event;\r
+\r
+ /** Event for remote wake-up configuration, when enabled. This event fires when the USB host\r
+ * request the device to configure itself for remote wake-up capability. The USB host sends\r
+ * this request to device which report remote wake-up capable in their device descriptors,\r
+ * before going to low-power state. The application layer should implement this callback if\r
+ * they have any special on board circuit to trigger remote wake up event. Also application\r
+ * can use this callback to differentiate the following SUSPEND event is caused by cable plug-out\r
+ * or host SUSPEND request. The device can wake-up host only after receiving this callback and\r
+ * remote wake-up feature is enabled by host. To signal remote wake-up the device has to generate\r
+ * resume signaling on bus by calling usapi.hw->WakeUp() routine.\r
+ *\r
+ * \n\n\r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \param[in] param1 When 0 - Clear the wake-up configuration, 1 - Enable the wake-up configuration.\r
+ * \return The call back should return \ref ErrorCode_t type to indicate success or error condition.\r
+ */ \r
+ USB_PARAM_CB_T USB_WakeUpCfg;\r
+\r
+ /** Reserved parameter should be set to zero. */\r
+ USB_PARAM_CB_T USB_Power_Event;\r
+\r
+ /** Event for error condition. This event fires when USB device controller detect \r
+ * an error condition in the system. \r
+ *\r
+ * \n\n\r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \param[in] param1 USB device interrupt status register. \r
+ * \return The call back should return \ref ErrorCode_t type to indicate success or error condition.\r
+ */ \r
+ USB_PARAM_CB_T USB_Error_Event;\r
+\r
+ /* USB Core Events Callback Functions */\r
+ /** Event for USB configuration number changed. This event fires when a the USB host changes the\r
+ * selected configuration number. On receiving configuration change request from host, the stack\r
+ * enables/configures the endpoints needed by the new configuration before calling this callback\r
+ * function.\r
+ * \n\r
+ * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
+ * callback will prevent the device from enumerating correctly or operate properly.\r
+ *\r
+ */\r
+ USB_CB_T USB_Configure_Event;\r
+\r
+ /** Event for USB interface setting changed. This event fires when a the USB host changes the\r
+ * interface setting to one of alternate interface settings. On receiving interface change \r
+ * request from host, the stack enables/configures the endpoints needed by the new alternate \r
+ * interface setting before calling this callback function.\r
+ * \n\r
+ * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
+ * callback will prevent the device from enumerating correctly or operate properly.\r
+ *\r
+ */\r
+ USB_CB_T USB_Interface_Event;\r
+\r
+ /** Event for USB feature changed. This event fires when a the USB host send set/clear feature\r
+ * request. The stack handles this request for USB_FEATURE_REMOTE_WAKEUP, USB_FEATURE_TEST_MODE\r
+ * and USB_FEATURE_ENDPOINT_STALL features only. On receiving feature request from host, the \r
+ * stack handle the request appropriately and then calls this callback function.\r
+ * \n\r
+ * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this\r
+ * callback will prevent the device from enumerating correctly or operate properly.\r
+ *\r
+ */\r
+ USB_CB_T USB_Feature_Event;\r
+\r
+ /* cache and MMU translation functions */\r
+ /** Reserved parameter for future use. should be set to zero. */\r
+ uint32_t (* virt_to_phys)(void* vaddr);\r
+ /** Reserved parameter for future use. should be set to zero. */\r
+ void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);\r
+\r
+} USBD_API_INIT_PARAM_T;\r
+\r
+\r
+/** \brief USBD stack Core API functions structure.\r
+ * \ingroup USBD_Core\r
+ *\r
+ * \details This module exposes functions which interact directly with USB device stack's core layer.\r
+ * The application layer uses this component when it has to implement custom class function driver or \r
+ * standard class function driver which is not part of the current USB device stack.\r
+ * The functions exposed by this interface are to register class specific EP0 handlers and corresponding\r
+ * utility functions to manipulate EP0 state machine of the stack. This interface also exposes\r
+ * function to register custom endpoint interrupt handler.\r
+ *\r
+ */\r
+typedef struct USBD_CORE_API \r
+{\r
+ /** \fn ErrorCode_t RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data)\r
+ * Function to register class specific EP0 event handler with USB device stack.\r
+ *\r
+ * The application layer uses this function when it has to register the custom class's EP0 handler. \r
+ * The stack calls all the registered class handlers on any EP0 event before going through default \r
+ * handling of the event. This gives the class handlers to implement class specific request handlers\r
+ * and also to override the default stack handling for a particular event targeted to the interface.\r
+ * Check \ref USB_EP_HANDLER_T for more details on how the callback function should be implemented. Also\r
+ * application layer could use this function to register EP0 handler which responds to vendor specific \r
+ * requests.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \param[in] pfn Class specific EP0 handler function.\r
+ * \param[in] data Pointer to the data which will be passed when callback function is called by the stack. \r
+ * \return Returns \ref ErrorCode_t type to indicate success or error condition.\r
+ * \retval LPC_OK On success\r
+ * \retval ERR_USBD_TOO_MANY_CLASS_HDLR(0x0004000c) The number of class handlers registered is \r
+ greater than the number of handlers allowed by the stack.\r
+ * \r
+ */\r
+ ErrorCode_t (*RegisterClassHandler)(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);\r
+\r
+ /** \fn ErrorCode_t RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data)\r
+ * Function to register interrupt/event handler for the requested endpoint with USB device stack.\r
+ *\r
+ * The application layer uses this function to register the endpoint event handler. \r
+ * The stack calls all the registered endpoint handlers when \r
+ * - USB_EVT_OUT or USB_EVT_OUT_NAK events happen for OUT endpoint. \r
+ * - USB_EVT_IN or USB_EVT_IN_NAK events happen for IN endpoint.\r
+ * Check USB_EP_HANDLER_T for more details on how the callback function should be implemented.\r
+ * \note By default endpoint _NAK events are not enabled. Application should call \ref USBD_HW_API_T::EnableEvent\r
+ * for the corresponding endpoint.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \param[in] ep_index Endpoint index. Computed as \r
+ * - For OUT endpoints = 2 * endpoint number eg. for EP2_OUT it is 4.\r
+ * - For IN endopoints = (2 * endpoint number) + 1 eg. for EP2_IN it is 5.\r
+ * \param[in] pfn Endpoint event handler function.\r
+ * \param[in] data Pointer to the data which will be passed when callback function is called by the stack. \r
+ * \return Returns \ref ErrorCode_t type to indicate success or error condition.\r
+ * \retval LPC_OK On success\r
+ * \retval ERR_API_INVALID_PARAM2 ep_index is outside the boundary ( < 2 * USBD_API_INIT_PARAM_T::max_num_ep). \r
+ * \r
+ */\r
+ ErrorCode_t (*RegisterEpHandler)(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);\r
+ \r
+ /** \fn void SetupStage(USBD_HANDLE_T hUsb)\r
+ * Function to set EP0 state machine in setup state.\r
+ *\r
+ * This function is called by USB stack and the application layer to \r
+ * set the EP0 state machine in setup state. This function will read\r
+ * the setup packet received from USB host into stack's buffer. \r
+ * \n\r
+ * \note This interface is provided to users to invoke this function in other \r
+ * scenarios which are not handle by current stack. In most user applications \r
+ * this function is not called directly.Also this function can be used by \r
+ * users who are selectively modifying the USB device stack's standard handlers \r
+ * through callback interface exposed by the stack.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \return Nothing.\r
+ */\r
+ void (*SetupStage )(USBD_HANDLE_T hUsb); \r
+ \r
+ /** \fn void DataInStage(USBD_HANDLE_T hUsb)\r
+ * Function to set EP0 state machine in data_in state.\r
+ *\r
+ * This function is called by USB stack and the application layer to \r
+ * set the EP0 state machine in data_in state. This function will write\r
+ * the data present in EP0Data buffer to EP0 FIFO for transmission to host.\r
+ * \n\r
+ * \note This interface is provided to users to invoke this function in other \r
+ * scenarios which are not handle by current stack. In most user applications \r
+ * this function is not called directly.Also this function can be used by \r
+ * users who are selectively modifying the USB device stack's standard handlers \r
+ * through callback interface exposed by the stack.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \return Nothing.\r
+ */\r
+ void (*DataInStage)(USBD_HANDLE_T hUsb);\r
+\r
+ /** \fn void DataOutStage(USBD_HANDLE_T hUsb)\r
+ * Function to set EP0 state machine in data_out state.\r
+ *\r
+ * This function is called by USB stack and the application layer to \r
+ * set the EP0 state machine in data_out state. This function will read\r
+ * the control data (EP0 out packets) received from USB host into EP0Data buffer. \r
+ * \n\r
+ * \note This interface is provided to users to invoke this function in other \r
+ * scenarios which are not handle by current stack. In most user applications \r
+ * this function is not called directly.Also this function can be used by \r
+ * users who are selectively modifying the USB device stack's standard handlers \r
+ * through callback interface exposed by the stack.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \return Nothing.\r
+ */\r
+ void (*DataOutStage)(USBD_HANDLE_T hUsb); \r
+\r
+ /** \fn void StatusInStage(USBD_HANDLE_T hUsb)\r
+ * Function to set EP0 state machine in status_in state.\r
+ *\r
+ * This function is called by USB stack and the application layer to \r
+ * set the EP0 state machine in status_in state. This function will send\r
+ * zero length IN packet on EP0 to host, indicating positive status. \r
+ * \n\r
+ * \note This interface is provided to users to invoke this function in other \r
+ * scenarios which are not handle by current stack. In most user applications \r
+ * this function is not called directly.Also this function can be used by \r
+ * users who are selectively modifying the USB device stack's standard handlers \r
+ * through callback interface exposed by the stack.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \return Nothing.\r
+ */\r
+ void (*StatusInStage)(USBD_HANDLE_T hUsb); \r
+ /** \fn void StatusOutStage(USBD_HANDLE_T hUsb)\r
+ * Function to set EP0 state machine in status_out state.\r
+ *\r
+ * This function is called by USB stack and the application layer to \r
+ * set the EP0 state machine in status_out state. This function will read\r
+ * the zero length OUT packet received from USB host on EP0. \r
+ * \n\r
+ * \note This interface is provided to users to invoke this function in other \r
+ * scenarios which are not handle by current stack. In most user applications \r
+ * this function is not called directly.Also this function can be used by \r
+ * users who are selectively modifying the USB device stack's standard handlers \r
+ * through callback interface exposed by the stack.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \return Nothing.\r
+ */\r
+ void (*StatusOutStage)(USBD_HANDLE_T hUsb);\r
+\r
+ /** \fn void StallEp0(USBD_HANDLE_T hUsb)\r
+ * Function to set EP0 state machine in stall state.\r
+ *\r
+ * This function is called by USB stack and the application layer to \r
+ * generate STALL signaling on EP0 endpoint. This function will also\r
+ * reset the EP0Data buffer. \r
+ * \n\r
+ * \note This interface is provided to users to invoke this function in other \r
+ * scenarios which are not handle by current stack. In most user applications \r
+ * this function is not called directly.Also this function can be used by \r
+ * users who are selectively modifying the USB device stack's standard handlers \r
+ * through callback interface exposed by the stack.\r
+ * \r
+ * \param[in] hUsb Handle to the USB device stack. \r
+ * \return Nothing.\r
+ */\r
+ void (*StallEp0)(USBD_HANDLE_T hUsb);\r
+\r
+} USBD_CORE_API_T;\r
+\r
+/*-----------------------------------------------------------------------------\r
+ * Private functions & structures prototypes\r
+ *-----------------------------------------------------------------------------*/\r
+\r
+ /** @cond ADVANCED_API */\r
+\r
+/* forward declaration */\r
+struct _USB_CORE_CTRL_T;\r
+typedef struct _USB_CORE_CTRL_T USB_CORE_CTRL_T;\r
+\r
+/* USB device Speed status defines */\r
+#define USB_FULL_SPEED 0\r
+#define USB_HIGH_SPEED 1\r
+\r
+/* USB Endpoint Data Structure */\r
+typedef struct _USB_EP_DATA\r
+{\r
+ uint8_t *pData;\r
+ uint16_t Count;\r
+ uint16_t pad0;\r
+} USB_EP_DATA;\r
+\r
+\r
+/* USB core controller data structure */\r
+struct _USB_CORE_CTRL_T\r
+{\r
+ /* override-able function pointers ~ c++ style virtual functions*/\r
+ USB_CB_T USB_EvtSetupHandler;\r
+ USB_CB_T USB_EvtOutHandler;\r
+ USB_PARAM_CB_T USB_ReqVendor;\r
+ USB_CB_T USB_ReqGetStatus;\r
+ USB_CB_T USB_ReqGetDescriptor;\r
+ USB_CB_T USB_ReqGetConfiguration;\r
+ USB_CB_T USB_ReqSetConfiguration;\r
+ USB_CB_T USB_ReqGetInterface;\r
+ USB_CB_T USB_ReqSetInterface;\r
+ USB_PARAM_CB_T USB_ReqSetClrFeature;\r
+\r
+ /* USB Device Events Callback Functions */\r
+ USB_CB_T USB_Reset_Event;\r
+ USB_CB_T USB_Suspend_Event;\r
+ USB_CB_T USB_Resume_Event;\r
+ USB_CB_T USB_SOF_Event;\r
+ USB_PARAM_CB_T USB_Power_Event;\r
+ USB_PARAM_CB_T USB_Error_Event;\r
+ USB_PARAM_CB_T USB_WakeUpCfg;\r
+\r
+ /* USB Core Events Callback Functions */\r
+ USB_CB_T USB_Configure_Event;\r
+ USB_CB_T USB_Interface_Event;\r
+ USB_CB_T USB_Feature_Event;\r
+\r
+ /* cache and MMU translation functions */\r
+ uint32_t (* virt_to_phys)(void* vaddr);\r
+ void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);\r
+\r
+ /* event handlers for endpoints. */\r
+ USB_EP_HANDLER_T ep_event_hdlr[2 * USB_MAX_EP_NUM];\r
+ void* ep_hdlr_data[2 * USB_MAX_EP_NUM];\r
+\r
+ /* USB class handlers */\r
+ USB_EP_HANDLER_T ep0_hdlr_cb[USB_MAX_IF_NUM];\r
+ void* ep0_cb_data[USB_MAX_IF_NUM];\r
+ uint8_t num_ep0_hdlrs;\r
+ /* USB Core data Variables */\r
+ uint8_t max_num_ep; /* max number of endpoints supported by the HW */\r
+ uint8_t device_speed;\r
+ uint8_t num_interfaces;\r
+ uint8_t device_addr;\r
+ uint8_t config_value;\r
+ uint16_t device_status;\r
+ uint8_t *device_desc;\r
+ uint8_t *string_desc;\r
+ uint8_t *full_speed_desc;\r
+ uint8_t *high_speed_desc;\r
+ uint8_t *device_qualifier;\r
+ uint32_t ep_mask;\r
+ uint32_t ep_halt;\r
+ uint32_t ep_stall;\r
+ uint8_t alt_setting[USB_MAX_IF_NUM];\r
+ /* HW driver data pointer */\r
+ void* hw_data;\r
+\r
+ /* USB Endpoint 0 Data Info */\r
+ USB_EP_DATA EP0Data;\r
+\r
+ /* USB Endpoint 0 Buffer */\r
+ //ALIGNED(4)\r
+ uint8_t EP0Buf[64];\r
+\r
+ /* USB Setup Packet */\r
+ //ALIGNED(4)\r
+ USB_SETUP_PACKET SetupPacket;\r
+\r
+};\r
+\r
+/* USB Core Functions */\r
+extern void mwUSB_InitCore(USB_CORE_CTRL_T* pCtrl, USB_CORE_DESCS_T* pdescr, USBD_API_INIT_PARAM_T* param);\r
+extern void mwUSB_ResetCore(USBD_HANDLE_T hUsb);\r
+\r
+/* inline functions */\r
+static INLINE void USB_SetSpeedMode(USB_CORE_CTRL_T* pCtrl, uint8_t mode)\r
+{\r
+ pCtrl->device_speed = mode; \r
+}\r
+\r
+static INLINE bool USB_IsConfigured(USBD_HANDLE_T hUsb)\r
+{\r
+ USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*) hUsb;\r
+ return (bool) (pCtrl->config_value != 0); \r
+}\r
+\r
+/** @cond DIRECT_API */\r
+/* midleware API */\r
+extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);\r
+extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);\r
+extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb); \r
+extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);\r
+extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb); \r
+extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb); \r
+extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);\r
+extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);\r
+extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);\r
+extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);\r
+extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb); \r
+extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);\r
+extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb); \r
+extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb); \r
+extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);\r
+extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);\r
+/** @endcond */\r
+\r
+/** @endcond */\r
+\r
+#endif /* __MW_USBD_CORE_H__ */\r