2 * @brief Definition of functions exported by ROM based DFU function driver
\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
32 #ifndef __DFUUSER_H__
\r
33 #define __DFUUSER_H__
\r
36 #include "usbd_dfu.h"
\r
37 #include "usbd_core.h"
\r
40 /** @ingroup Group_USBD_Class
\r
41 * @defgroup USBD_DFU Device Firmware Upgrade (DFU) Class Function Driver
\r
42 * @section Sec_MSCModDescription Module Description
\r
43 * DFU Class Function Driver module. This module contains an internal implementation of the USB DFU Class.
\r
44 * User applications can use this class driver instead of implementing the DFU class manually
\r
45 * via the low-level USBD_HW and USBD_Core APIs.
\r
47 * This module is designed to simplify the user code by exposing only the required interface needed to interface with
\r
48 * Devices using the USB DFU Class.
\r
51 /** @brief USB descriptors data structure.
\r
54 * @details This module exposes functions which interact directly with USB device stack's core layer.
\r
55 * The application layer uses this component when it has to implement custom class function driver or
\r
56 * standard class function driver which is not part of the current USB device stack.
\r
57 * The functions exposed by this interface are to register class specific EP0 handlers and corresponding
\r
58 * utility functions to manipulate EP0 state machine of the stack. This interface also exposes
\r
59 * function to register custom endpoint interrupt handler.
\r
62 typedef struct USBD_DFU_INIT_PARAM
\r
64 /* memory allocation params */
\r
65 uint32_t mem_base; /**< Base memory location from where the stack can allocate
\r
66 data and buffers. @note The memory address set in this field
\r
67 should be accessible by USB DMA controller. Also this value
\r
68 should be aligned on 4 byte boundary.
\r
70 uint32_t mem_size; /**< The size of memory buffer which stack can use.
\r
71 @note The \em mem_size should be greater than the size
\r
72 returned by USBD_DFU_API::GetMemSize() routine.*/
\r
74 uint16_t wTransferSize; /**< DFU transfer block size in number of bytes.
\r
75 This value should match the value set in DFU descriptor
\r
76 provided as part of the descriptor array
\r
77 (\em high_speed_desc) passed to Init() through
\r
78 @ref USB_CORE_DESCS_T structure. */
\r
80 /** Pointer to the DFU interface descriptor within the descriptor
\r
81 * array (\em high_speed_desc) passed to Init() through @ref USB_CORE_DESCS_T
\r
85 /* user defined functions */
\r
87 * DFU Write callback function.
\r
89 * This function is provided by the application software. This function gets called
\r
90 * when host sends a write command. For application using zero-copy buffer scheme
\r
91 * this function is called for the first time with \em length parameter set to 0.
\r
92 * The application code should update the buffer pointer.
\r
94 * @param block_num Destination start address.
\r
95 * @param src Pointer to a pointer to the source of data. Pointer-to-pointer
\r
96 * is used to implement zero-copy buffers.
\r
97 * @param bwPollTimeout Pointer to a 3 byte buffer which the callback implementer
\r
98 * should fill with the amount of minimum time, in milliseconds,
\r
99 * that the host should wait before sending a subsequent
\r
100 * DFU_GETSTATUS request.
\r
101 * @param length Number of bytes to be written.
\r
102 * @return Returns DFU_STATUS_ values defined in mw_usbd_dfu.h.
\r
105 uint8_t (*DFU_Write)( uint32_t block_num, uint8_t** src, uint32_t length, uint8_t* bwPollTimeout);
\r
108 * DFU Read callback function.
\r
110 * This function is provided by the application software. This function gets called
\r
111 * when host sends a read command.
\r
113 * @param block_num Destination start address.
\r
114 * @param dst Pointer to a pointer to the source of data. Pointer-to-pointer
\r
115 * is used to implement zero-copy buffers.
\r
116 * @param length Amount of data copied to destination buffer.
\r
117 * @return Returns DFU_STATUS_ values defined in mw_usbd_dfu.h.
\r
120 uint32_t (*DFU_Read)( uint32_t block_num, uint8_t** dst, uint32_t length);
\r
123 * DFU done callback function.
\r
125 * This function is provided by the application software. This function gets called
\r
126 * after download is finished.
\r
131 void (*DFU_Done)(void);
\r
134 * DFU detach callback function.
\r
136 * This function is provided by the application software. This function gets called
\r
137 * after USB_REQ_DFU_DETACH is recieved. Applications which set USB_DFU_WILL_DETACH
\r
138 * bit in DFU descriptor should define this function. As part of this function
\r
139 * application can call Connect() routine to disconnect and then connect back with
\r
140 * host. For application which rely on WinUSB based host application should use this
\r
141 * feature since USB reset can be invoked only by kernel drivers on Windows host.
\r
142 * By implementing this feature host doen't have to issue reset instead the device
\r
143 * has to do it automatically by disconnect and connect procedure.
\r
145 * @param hUsb Handle DFU control structure.
\r
149 void (*DFU_Detach)(USBD_HANDLE_T hUsb);
\r
152 * Optional user overridable function to replace the default DFU class handler.
\r
154 * The application software could override the default EP0 class handler with their
\r
155 * own by providing the handler function address as this data member of the parameter
\r
156 * structure. Application which like the default handler should set this data member
\r
157 * to zero before calling the USBD_DFU_API::Init().
\r
161 * @param hUsb Handle to the USB device stack.
\r
162 * @param data Pointer to the data which will be passed when callback function is called by the stack.
\r
163 * @param event Type of endpoint event. See @ref USBD_EVENT_T for more details.
\r
164 * @return The call back should returns @ref ErrorCode_t type to indicate success or error condition.
\r
165 * @retval LPC_OK On success.
\r
166 * @retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line.
\r
167 * @retval ERR_USBD_xxx For other error conditions.
\r
170 ErrorCode_t (*DFU_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
\r
172 } USBD_DFU_INIT_PARAM_T;
\r
175 /** @brief DFU class API functions structure.
\r
176 * @ingroup USBD_DFU
\r
178 * This module exposes functions which interact directly with USB device controller hardware.
\r
181 typedef struct USBD_DFU_API
\r
183 /** @fn uint32_t GetMemSize(USBD_DFU_INIT_PARAM_T* param)
\r
184 * Function to determine the memory required by the DFU function driver module.
\r
186 * This function is called by application layer before calling pUsbApi->dfu->Init(), to allocate memory used
\r
187 * by DFU function driver module. The application should allocate the memory which is accessible by USB
\r
188 * controller/DMA controller.
\r
189 * @note Some memory areas are not accessible by all bus masters.
\r
191 * @param param Structure containing DFU function driver module initialization parameters.
\r
192 * @return Returns the required memory size in bytes.
\r
194 uint32_t (*GetMemSize)(USBD_DFU_INIT_PARAM_T* param);
\r
196 /** @fn ErrorCode_t init(USBD_HANDLE_T hUsb, USBD_DFU_INIT_PARAM_T* param)
\r
197 * Function to initialize DFU function driver module.
\r
199 * This function is called by application layer to initialize DFU function driver module.
\r
201 * @param hUsb Handle to the USB device stack.
\r
202 * @param param Structure containing DFU function driver module initialization parameters.
\r
203 * @return Returns @ref ErrorCode_t type to indicate success or error condition.
\r
204 * @retval LPC_OK On success
\r
205 * @retval ERR_USBD_BAD_MEM_BUF Memory buffer passed is not 4-byte aligned or smaller than required.
\r
206 * @retval ERR_API_INVALID_PARAM2 Either DFU_Write() or DFU_Done() or DFU_Read() callbacks are not defined.
\r
207 * @retval ERR_USBD_BAD_DESC
\r
208 * - USB_DFU_DESCRIPTOR_TYPE is not defined immediately after
\r
209 * interface descriptor.
\r
210 * - wTransferSize in descriptor doesn't match the value passed
\r
211 * in param->wTransferSize.
\r
212 * - DFU_Detach() is not defined while USB_DFU_WILL_DETACH is set
\r
213 * in DFU descriptor.
\r
214 * @retval ERR_USBD_BAD_INTF_DESC Wrong interface descriptor is passed.
\r
216 ErrorCode_t (*init)(USBD_HANDLE_T hUsb, USBD_DFU_INIT_PARAM_T* param, uint32_t init_state);
\r
220 /*-----------------------------------------------------------------------------
\r
221 * Private functions & structures prototypes
\r
222 *-----------------------------------------------------------------------------*/
\r
223 /** @cond ADVANCED_API */
\r
225 typedef struct _USBD_DFU_CTRL_T
\r
227 /*ALIGNED(4)*/ DFU_STATUS_T dfu_req_get_status;
\r
229 uint8_t dfu_status;
\r
230 uint8_t download_done;
\r
231 uint8_t if_num; /* interface number */
\r
234 USB_DFU_FUNC_DESCRIPTOR* dfu_desc;
\r
236 USB_CORE_CTRL_T* pUsbCtrl;
\r
237 /* user defined functions */
\r
238 /* return DFU_STATUS_ values defined in mw_usbd_dfu.h */
\r
239 uint8_t (*DFU_Write)( uint32_t block_num, uint8_t** src, uint32_t length, uint8_t* bwPollTimeout);
\r
241 * DFU_STATUS_ : values defined in mw_usbd_dfu.h in case of errors
\r
242 * 0 : If end of memory reached
\r
243 * length : Amount of data copied to destination buffer
\r
245 uint32_t (*DFU_Read)( uint32_t block_num, uint8_t** dst, uint32_t length);
\r
246 /* callback called after download is finished */
\r
247 void (*DFU_Done)(void);
\r
248 /* callback called after USB_REQ_DFU_DETACH is recived */
\r
249 void (*DFU_Detach)(USBD_HANDLE_T hUsb);
\r
256 #endif /* __DFUUSER_H__ */
\r