2 * @brief USB ROM based hardware function prototypes
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
34 #include "usbd_core.h"
\r
40 /** @ingroup Group_USBD
\r
41 * @defgroup USBD_HW USB Device Controller Driver
\r
42 * @section Sec_HWModDescription Module Description
\r
43 * The Device Controller Driver Layer implements the routines to deal directly with the hardware.
\r
46 /** @ingroup USBD_HW
\r
47 * USB Endpoint/class handler Callback Events.
\r
51 USB_EVT_SETUP =1, /**< 1 Setup Packet received */
\r
52 USB_EVT_OUT, /**< 2 OUT Packet received */
\r
53 USB_EVT_IN, /**< 3 IN Packet sent */
\r
54 USB_EVT_OUT_NAK, /**< 4 OUT Packet - Not Acknowledged */
\r
55 USB_EVT_IN_NAK, /**< 5 IN Packet - Not Acknowledged */
\r
56 USB_EVT_OUT_STALL, /**< 6 OUT Packet - Stalled */
\r
57 USB_EVT_IN_STALL, /**< 7 IN Packet - Stalled */
\r
58 USB_EVT_OUT_DMA_EOT, /**< 8 DMA OUT EP - End of Transfer */
\r
59 USB_EVT_IN_DMA_EOT, /**< 9 DMA IN EP - End of Transfer */
\r
60 USB_EVT_OUT_DMA_NDR, /**< 10 DMA OUT EP - New Descriptor Request */
\r
61 USB_EVT_IN_DMA_NDR, /**< 11 DMA IN EP - New Descriptor Request */
\r
62 USB_EVT_OUT_DMA_ERR, /**< 12 DMA OUT EP - Error */
\r
63 USB_EVT_IN_DMA_ERR, /**< 13 DMA IN EP - Error */
\r
64 USB_EVT_RESET, /**< 14 Reset event recieved */
\r
65 USB_EVT_SOF, /**< 15 Start of Frame event */
\r
66 USB_EVT_DEV_STATE, /**< 16 Device status events */
\r
67 USB_EVT_DEV_ERROR, /**< 16 Device error events */
\r
71 * @brief Hardware API functions structure.
\r
74 * This module exposes functions which interact directly with USB device controller hardware.
\r
77 typedef struct USBD_HW_API
\r
79 /** @fn uint32_t GetMemSize(USBD_API_INIT_PARAM_T* param)
\r
80 * Function to determine the memory required by the USB device stack's DCD and core layers.
\r
82 * This fuction is called by application layer before calling pUsbApi->hw->Init(), to allocate memory used
\r
83 * by DCD and core layers. The application should allocate the memory which is accessible by USB
\r
84 * controller/DMA controller.
\r
85 * @note Some memory areas are not accessible by all bus masters.
\r
87 * @param param Structure containing USB device stack initialization parameters.
\r
88 * @return Returns the required memory size in bytes.
\r
90 uint32_t (*GetMemSize)(USBD_API_INIT_PARAM_T* param);
\r
92 /** @fn ErrorCode_t Init(USBD_HANDLE_T* phUsb, USB_CORE_DESCS_T* pDesc, USBD_API_INIT_PARAM_T* param)
\r
93 * Function to initialize USB device stack's DCD and core layers.
\r
95 * This function is called by application layer to initialize USB hardware and core layers.
\r
96 * On successful initialization the function returns a handle to USB device stack which should
\r
97 * be passed to the rest of the functions.
\r
99 * \param[in,out] phUsb Pointer to the USB device stack handle of type USBD_HANDLE_T.
\r
100 * @param param Structure containing USB device stack initialization parameters.
\r
101 * @return Returns @ref ErrorCode_t type to indicate success or error condition.
\r
102 * @retval LPC_OK(0) On success
\r
103 * @retval ERR_USBD_BAD_MEM_BUF(0x0004000b) When insufficient memory buffer is passed or memory
\r
104 * is not aligned on 2048 boundary.
\r
106 ErrorCode_t (*Init)(USBD_HANDLE_T* phUsb, USB_CORE_DESCS_T* pDesc, USBD_API_INIT_PARAM_T* param);
\r
108 /** @fn void Connect(USBD_HANDLE_T hUsb, uint32_t con)
\r
109 * Function to make USB device visible/invisible on the USB bus.
\r
111 * This function is called after the USB initialization. This function uses the soft connect
\r
112 * feature to make the device visible on the USB bus. This function is called only after the
\r
113 * application is ready to handle the USB data. The enumeration process is started by the
\r
114 * host after the device detection. The driver handles the enumeration process according to
\r
115 * the USB descriptors passed in the USB initialization function.
\r
117 * @param hUsb Handle to the USB device stack.
\r
118 * @param con States whether to connect (1) or to disconnect (0).
\r
121 void (*Connect)(USBD_HANDLE_T hUsb, uint32_t con);
\r
123 /** @fn void ISR(USBD_HANDLE_T hUsb)
\r
124 * Function to USB device controller interrupt events.
\r
126 * When the user application is active the interrupt handlers are mapped in the user flash
\r
127 * space. The user application must provide an interrupt handler for the USB interrupt and
\r
128 * call this function in the interrupt handler routine. The driver interrupt handler takes
\r
129 * appropriate action according to the data received on the USB bus.
\r
131 * @param hUsb Handle to the USB device stack.
\r
134 void (*ISR)(USBD_HANDLE_T hUsb);
\r
136 /** @fn void Reset(USBD_HANDLE_T hUsb)
\r
137 * Function to Reset USB device stack and hardware controller.
\r
139 * Reset USB device stack and hardware controller. Disables all endpoints except EP0.
\r
140 * Clears all pending interrupts and resets endpoint transfer queues.
\r
141 * This function is called internally by pUsbApi->hw->init() and from reset event.
\r
143 * @param hUsb Handle to the USB device stack.
\r
146 void (*Reset)(USBD_HANDLE_T hUsb);
\r
148 /** @fn void ForceFullSpeed(USBD_HANDLE_T hUsb, uint32_t cfg)
\r
149 * Function to force high speed USB device to operate in full speed mode.
\r
151 * This function is useful for testing the behaviour of current device when connected
\r
152 * to a full speed only hosts.
\r
154 * @param hUsb Handle to the USB device stack.
\r
155 * @param cfg When 1 - set force full-speed or
\r
156 * 0 - clear force full-speed.
\r
159 void (*ForceFullSpeed )(USBD_HANDLE_T hUsb, uint32_t cfg);
\r
161 /** @fn void WakeUpCfg(USBD_HANDLE_T hUsb, uint32_t cfg)
\r
162 * Function to configure USB device controller to wakeup host on remote events.
\r
164 * This function is called by application layer to configure the USB device controller
\r
165 * to wakeup on remote events. It is recommended to call this function from users's
\r
166 * USB_WakeUpCfg() callback routine registered with stack.
\r
167 * @note User's USB_WakeUpCfg() is registered with stack by setting the USB_WakeUpCfg member
\r
168 * of USBD_API_INIT_PARAM_T structure before calling pUsbApi->hw->Init() routine.
\r
169 * Certain USB device controllers needed to keep some clocks always on to generate
\r
170 * resume signaling through pUsbApi->hw->WakeUp(). This hook is provided to support
\r
171 * such controllers. In most controllers cases this is an empty routine.
\r
173 * @param hUsb Handle to the USB device stack.
\r
174 * @param cfg When 1 - Configure controller to wake on remote events or
\r
175 * 0 - Configure controller not to wake on remote events.
\r
178 void (*WakeUpCfg)(USBD_HANDLE_T hUsb, uint32_t cfg);
\r
180 /** @fn void SetAddress(USBD_HANDLE_T hUsb, uint32_t adr)
\r
181 * Function to set USB address assigned by host in device controller hardware.
\r
183 * This function is called automatically when USB_REQUEST_SET_ADDRESS request is received
\r
184 * by the stack from USB host.
\r
185 * This interface is provided to users to invoke this function in other scenarios which are not
\r
186 * handle by current stack. In most user applications this function is not called directly.
\r
187 * Also this function can be used by users who are selectively modifying the USB device stack's
\r
188 * standard handlers through callback interface exposed by the stack.
\r
190 * @param hUsb Handle to the USB device stack.
\r
191 * @param adr USB bus Address to which the device controller should respond. Usually
\r
192 * assigned by the USB host.
\r
195 void (*SetAddress)(USBD_HANDLE_T hUsb, uint32_t adr);
\r
197 /** @fn void Configure(USBD_HANDLE_T hUsb, uint32_t cfg)
\r
198 * Function to configure device controller hardware with selected configuration.
\r
200 * This function is called automatically when USB_REQUEST_SET_CONFIGURATION request is received
\r
201 * by the stack from USB host.
\r
202 * This interface is provided to users to invoke this function in other scenarios which are not
\r
203 * handle by current stack. In most user applications this function is not called directly.
\r
204 * Also this function can be used by users who are selectively modifying the USB device stack's
\r
205 * standard handlers through callback interface exposed by the stack.
\r
207 * @param hUsb Handle to the USB device stack.
\r
208 * @param cfg Configuration index.
\r
211 void (*Configure)(USBD_HANDLE_T hUsb, uint32_t cfg);
\r
213 /** @fn void ConfigEP(USBD_HANDLE_T hUsb, USB_ENDPOINT_DESCRIPTOR *pEPD)
\r
214 * Function to configure USB Endpoint according to descriptor.
\r
216 * This function is called automatically when USB_REQUEST_SET_CONFIGURATION request is received
\r
217 * by the stack from USB host. All the endpoints associated with the selected configuration
\r
219 * This interface is provided to users to invoke this function in other scenarios which are not
\r
220 * handle by current stack. In most user applications this function is not called directly.
\r
221 * Also this function can be used by users who are selectively modifying the USB device stack's
\r
222 * standard handlers through callback interface exposed by the stack.
\r
224 * @param hUsb Handle to the USB device stack.
\r
225 * @param pEPD Endpoint descriptor structure defined in USB 2.0 specification.
\r
228 void (*ConfigEP)(USBD_HANDLE_T hUsb, USB_ENDPOINT_DESCRIPTOR *pEPD);
\r
230 /** @fn void DirCtrlEP(USBD_HANDLE_T hUsb, uint32_t dir)
\r
231 * Function to set firection for USB control endpoint EP0.
\r
233 * This function is called automatically by the stack on need bassis.
\r
234 * This interface is provided to users to invoke this function in other scenarios which are not
\r
235 * handle by current stack. In most user applications this function is not called directly.
\r
236 * Also this function can be used by users who are selectively modifying the USB device stack's
\r
237 * standard handlers through callback interface exposed by the stack.
\r
239 * @param hUsb Handle to the USB device stack.
\r
240 * @param cfg When 1 - Set EP0 in IN transfer mode
\r
241 * 0 - Set EP0 in OUT transfer mode
\r
244 void (*DirCtrlEP)(USBD_HANDLE_T hUsb, uint32_t dir);
\r
246 /** @fn void EnableEP(USBD_HANDLE_T hUsb, uint32_t EPNum)
\r
247 * Function to enable selected USB endpoint.
\r
249 * This function enables interrupts on selected endpoint.
\r
251 * @param hUsb Handle to the USB device stack.
\r
252 * @param EPNum Endpoint number as per USB specification.
\r
253 * ie. An EP1_IN is represented by 0x81 number.
\r
256 void (*EnableEP)(USBD_HANDLE_T hUsb, uint32_t EPNum);
\r
258 /** @fn void DisableEP(USBD_HANDLE_T hUsb, uint32_t EPNum)
\r
259 * Function to disable selected USB endpoint.
\r
261 * This function disables interrupts on selected endpoint.
\r
263 * @param hUsb Handle to the USB device stack.
\r
264 * @param EPNum Endpoint number as per USB specification.
\r
265 * ie. An EP1_IN is represented by 0x81 number.
\r
268 void (*DisableEP)(USBD_HANDLE_T hUsb, uint32_t EPNum);
\r
270 /** @fn void ResetEP(USBD_HANDLE_T hUsb, uint32_t EPNum)
\r
271 * Function to reset selected USB endpoint.
\r
273 * This function flushes the endpoint buffers and resets data toggle logic.
\r
275 * @param hUsb Handle to the USB device stack.
\r
276 * @param EPNum Endpoint number as per USB specification.
\r
277 * ie. An EP1_IN is represented by 0x81 number.
\r
280 void (*ResetEP)(USBD_HANDLE_T hUsb, uint32_t EPNum);
\r
282 /** @fn void SetStallEP(USBD_HANDLE_T hUsb, uint32_t EPNum)
\r
283 * Function to STALL selected USB endpoint.
\r
285 * Generates STALL signalling for requested endpoint.
\r
287 * @param hUsb Handle to the USB device stack.
\r
288 * @param EPNum Endpoint number as per USB specification.
\r
289 * ie. An EP1_IN is represented by 0x81 number.
\r
292 void (*SetStallEP)(USBD_HANDLE_T hUsb, uint32_t EPNum);
\r
294 /** @fn void ClrStallEP(USBD_HANDLE_T hUsb, uint32_t EPNum)
\r
295 * Function to clear STALL state for the requested endpoint.
\r
297 * This function clears STALL state for the requested endpoint.
\r
299 * @param hUsb Handle to the USB device stack.
\r
300 * @param EPNum Endpoint number as per USB specification.
\r
301 * ie. An EP1_IN is represented by 0x81 number.
\r
304 void (*ClrStallEP)(USBD_HANDLE_T hUsb, uint32_t EPNum);
\r
306 /** @fn ErrorCode_t SetTestMode(USBD_HANDLE_T hUsb, uint8_t mode)
\r
307 * Function to set high speed USB device controller in requested test mode.
\r
309 * USB-IF requires the high speed device to be put in various test modes
\r
310 * for electrical testing. This USB device stack calls this function whenever
\r
311 * it receives USB_REQUEST_CLEAR_FEATURE request for USB_FEATURE_TEST_MODE.
\r
312 * Users can put the device in test mode by directly calling this function.
\r
313 * Returns ERR_USBD_INVALID_REQ when device controller is full-speed only.
\r
315 * @param hUsb Handle to the USB device stack.
\r
316 * @param mode Test mode defined in USB 2.0 electrical testing specification.
\r
317 * @return Returns @ref ErrorCode_t type to indicate success or error condition.
\r
318 * @retval LPC_OK(0) - On success
\r
319 * @retval ERR_USBD_INVALID_REQ(0x00040001) - Invalid test mode or
\r
320 * Device controller is full-speed only.
\r
322 ErrorCode_t (*SetTestMode)(USBD_HANDLE_T hUsb, uint8_t mode);
\r
324 /** @fn uint32_t ReadEP(USBD_HANDLE_T hUsb, uint32_t EPNum, uint8_t *pData)
\r
325 * Function to read data received on the requested endpoint.
\r
327 * This function is called by USB stack and the application layer to read the data
\r
328 * received on the requested endpoint.
\r
330 * @param hUsb Handle to the USB device stack.
\r
331 * @param EPNum Endpoint number as per USB specification.
\r
332 * ie. An EP1_IN is represented by 0x81 number.
\r
333 * \param[in,out] pData Pointer to the data buffer where data is to be copied.
\r
334 * @return Returns the number of bytes copied to the buffer.
\r
336 uint32_t (*ReadEP)(USBD_HANDLE_T hUsb, uint32_t EPNum, uint8_t *pData);
\r
338 /** @fn uint32_t ReadReqEP(USBD_HANDLE_T hUsb, uint32_t EPNum, uint8_t *pData, uint32_t len)
\r
339 * Function to queue read request on the specified endpoint.
\r
341 * This function is called by USB stack and the application layer to queue a read request
\r
342 * on the specified endpoint.
\r
344 * @param hUsb Handle to the USB device stack.
\r
345 * @param EPNum Endpoint number as per USB specification.
\r
346 * ie. An EP1_IN is represented by 0x81 number.
\r
347 * \param[in,out] pData Pointer to the data buffer where data is to be copied. This buffer
\r
348 * address should be accessible by USB DMA master.
\r
349 * @param len Length of the buffer passed.
\r
350 * @return Returns the length of the requested buffer.
\r
352 uint32_t (*ReadReqEP)(USBD_HANDLE_T hUsb, uint32_t EPNum, uint8_t *pData, uint32_t len);
\r
354 /** @fn uint32_t ReadSetupPkt(USBD_HANDLE_T hUsb, uint32_t EPNum, uint32_t *pData)
\r
355 * Function to read setup packet data received on the requested endpoint.
\r
357 * This function is called by USB stack and the application layer to read setup packet data
\r
358 * received on the requested endpoint.
\r
360 * @param hUsb Handle to the USB device stack.
\r
361 * @param EPNum Endpoint number as per USB specification.
\r
362 * ie. An EP0_IN is represented by 0x80 number.
\r
363 * \param[in,out] pData Pointer to the data buffer where data is to be copied.
\r
364 * @return Returns the number of bytes copied to the buffer.
\r
366 uint32_t (*ReadSetupPkt)(USBD_HANDLE_T hUsb, uint32_t EPNum, uint32_t *pData);
\r
368 /** @fn uint32_t WriteEP(USBD_HANDLE_T hUsb, uint32_t EPNum, uint8_t *pData, uint32_t cnt)
\r
369 * Function to write data to be sent on the requested endpoint.
\r
371 * This function is called by USB stack and the application layer to send data
\r
372 * on the requested endpoint.
\r
374 * @param hUsb Handle to the USB device stack.
\r
375 * @param EPNum Endpoint number as per USB specification.
\r
376 * ie. An EP1_IN is represented by 0x81 number.
\r
377 * @param pData Pointer to the data buffer from where data is to be copied.
\r
378 * @param cnt Number of bytes to write.
\r
379 * @return Returns the number of bytes written.
\r
381 uint32_t (*WriteEP)(USBD_HANDLE_T hUsb, uint32_t EPNum, uint8_t *pData, uint32_t cnt);
\r
383 /** @fn void WakeUp(USBD_HANDLE_T hUsb)
\r
384 * Function to generate resume signaling on bus for remote host wakeup.
\r
386 * This function is called by application layer to remotely wakeup host controller
\r
387 * when system is in suspend state. Application should indicate this remote wakeup
\r
388 * capability by setting USB_CONFIG_REMOTE_WAKEUP in bmAttributes of Configuration
\r
389 * Descriptor. Also this routine will generate resume signalling only if host
\r
390 * enables USB_FEATURE_REMOTE_WAKEUP by sending SET_FEATURE request before suspending
\r
393 * @param hUsb Handle to the USB device stack.
\r
396 void (*WakeUp)(USBD_HANDLE_T hUsb);
\r
398 /** @fn void EnableEP(USBD_HANDLE_T hUsb, uint32_t EPNum)
\r
399 * Function to enable/disable selected USB event.
\r
401 * This function enables interrupts on selected endpoint.
\r
403 * @param hUsb Handle to the USB device stack.
\r
404 * @param EPNum Endpoint number corresponding to the eventas per USB specification.
\r
405 * ie. An EP1_IN is represented by 0x81 number. For device events
\r
406 * set this param to 0x0.
\r
407 * @param event Type of endpoint event. See @ref USBD_EVENT_T for more details.
\r
408 * @param enable 1 - enable event, 0 - disable event.
\r
409 * @return Returns @ref ErrorCode_t type to indicate success or error condition.
\r
410 * @retval LPC_OK(0) - On success
\r
411 * @retval ERR_USBD_INVALID_REQ(0x00040001) - Invalid event type.
\r
413 ErrorCode_t (*EnableEvent)(USBD_HANDLE_T hUsb, uint32_t EPNum, uint32_t event_type,
\r
421 #endif /* __USBHW_H__ */
\r