2 * @brief Definition of functions exported by ROM based MSC 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
34 #include "usbd_msc.h"
\r
35 #include "usbd_core.h"
\r
37 #ifndef __MSCUSER_H__
\r
38 #define __MSCUSER_H__
\r
41 /** @ingroup Group_USBD_Class
\r
42 * @defgroup USBD_MSC Mass Storage Class (MSC) Function Driver
\r
43 * @section Sec_MSCModDescription Module Description
\r
44 * MSC Class Function Driver module. This module contains an internal implementation of the USB MSC Class.
\r
45 * User applications can use this class driver instead of implementing the MSC class manually
\r
46 * via the low-level USBD_HW and USBD_Core APIs.
\r
48 * This module is designed to simplify the user code by exposing only the required interface needed to interface with
\r
49 * Devices using the USB MSC Class.
\r
52 /** @brief Mass Storage class function driver initilization parameter data structure.
\r
55 * @details This data structure is used to pass initialization parameters to the
\r
56 * Mass Storage class function driver's init function.
\r
59 typedef struct USBD_MSC_INIT_PARAM
\r
61 /* memory allocation params */
\r
62 uint32_t mem_base; /**< Base memory location from where the stack can allocate
\r
63 data and buffers. @note The memory address set in this field
\r
64 should be accessible by USB DMA controller. Also this value
\r
65 should be aligned on 4 byte boundary.
\r
67 uint32_t mem_size; /**< The size of memory buffer which stack can use.
\r
68 @note The \em mem_size should be greater than the size
\r
69 returned by USBD_MSC_API::GetMemSize() routine.*/
\r
70 /* mass storage paramas */
\r
71 uint8_t* InquiryStr; /**< Pointer to the 28 character string. This string is
\r
72 sent in response to the SCSI Inquiry command. @note The data
\r
73 pointed by the pointer should be of global scope.
\r
75 uint32_t BlockCount; /**< Number of blocks present in the mass storage device */
\r
76 uint32_t BlockSize; /**< Block size in number of bytes */
\r
77 uint32_t MemorySize; /**< Memory size in number of bytes */
\r
78 /** Pointer to the interface descriptor within the descriptor
\r
79 * array (\em high_speed_desc) passed to Init() through @ref USB_CORE_DESCS_T
\r
80 * structure. The stack assumes both HS and FS use same BULK endpoints.
\r
83 /* user defined functions */
\r
86 * MSC Write callback function.
\r
88 * This function is provided by the application software. This function gets called
\r
89 * when host sends a write command.
\r
91 * @param offset Destination start address.
\r
92 * @param src Pointer to a pointer to the source of data. Pointer-to-pointer
\r
93 * is used to implement zero-copy buffers.
\r
94 * @param length Number of bytes to be written.
\r
98 void (*MSC_Write)( uint32_t offset, uint8_t** src, uint32_t length);
\r
100 * MSC Read callback function.
\r
102 * This function is provided by the application software. This function gets called
\r
103 * when host sends a read command.
\r
105 * @param offset Source start address.
\r
106 * @param dst Pointer to a pointer to the source of data. The MSC function drivers
\r
107 * implemented in stack are written with zero-copy model. Meaning the stack doesn't make an
\r
108 * extra copy of buffer before writing/reading data from USB hardware FIFO. Hence the
\r
109 * parameter is pointer to a pointer containing address buffer (<em>uint8_t** dst</em>).
\r
110 * So that the user application can update the buffer pointer instead of copying data to
\r
111 * address pointed by the parameter. /note The updated buffer address should be accessable
\r
112 * by USB DMA master. If user doesn't want to use zero-copy model, then the user should copy
\r
113 * data to the address pointed by the passed buffer pointer parameter and shouldn't change
\r
114 * the address value.
\r
115 * @param length Number of bytes to be read.
\r
119 void (*MSC_Read)( uint32_t offset, uint8_t** dst, uint32_t length);
\r
121 * MSC Verify callback function.
\r
123 * This function is provided by the application software. This function gets called
\r
124 * when host sends a verify command. The callback function should compare the buffer
\r
125 * with the destination memory at the requested offset and
\r
127 * @param offset Destination start address.
\r
128 * @param buf Buffer containing the data sent by the host.
\r
129 * @param length Number of bytes to verify.
\r
130 * @return Returns @ref ErrorCode_t type to indicate success or error condition.
\r
131 * @retval LPC_OK If data in the buffer matches the data at destination
\r
132 * @retval ERR_FAILED Atleast one byte is different.
\r
135 ErrorCode_t (*MSC_Verify)( uint32_t offset, uint8_t buf[], uint32_t length);
\r
137 * Optional callback function to optimize MSC_Write buffer transfer.
\r
139 * This function is provided by the application software. This function gets called
\r
140 * when host sends SCSI_WRITE10/SCSI_WRITE12 command. The callback function should
\r
141 * update the \em buff_adr pointer so that the stack transfers the data directly
\r
142 * to the target buffer. /note The updated buffer address should be accessable
\r
143 * by USB DMA master. If user doesn't want to use zero-copy model, then the user
\r
144 * should not update the buffer pointer.
\r
146 * @param offset Destination start address.
\r
147 * \param[in,out] buf Buffer containing the data sent by the host.
\r
148 * @param length Number of bytes to write.
\r
152 void (*MSC_GetWriteBuf)( uint32_t offset, uint8_t** buff_adr, uint32_t length);
\r
155 * Optional user overridable function to replace the default MSC class handler.
\r
157 * The application software could override the default EP0 class handler with their
\r
158 * own by providing the handler function address as this data member of the parameter
\r
159 * structure. Application which like the default handler should set this data member
\r
160 * to zero before calling the USBD_MSC_API::Init().
\r
164 * @param hUsb Handle to the USB device stack.
\r
165 * @param data Pointer to the data which will be passed when callback function is called by the stack.
\r
166 * @param event Type of endpoint event. See @ref USBD_EVENT_T for more details.
\r
167 * @return The call back should returns @ref ErrorCode_t type to indicate success or error condition.
\r
168 * @retval LPC_OK On success.
\r
169 * @retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line.
\r
170 * @retval ERR_USBD_xxx For other error conditions.
\r
173 ErrorCode_t (*MSC_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
\r
175 } USBD_MSC_INIT_PARAM_T;
\r
177 /** @brief MSC class API functions structure.
\r
178 * @ingroup USBD_MSC
\r
180 * This module exposes functions which interact directly with USB device controller hardware.
\r
183 typedef struct USBD_MSC_API
\r
185 /** @fn uint32_t GetMemSize(USBD_MSC_INIT_PARAM_T* param)
\r
186 * Function to determine the memory required by the MSC function driver module.
\r
188 * This function is called by application layer before calling pUsbApi->msc->Init(), to allocate memory used
\r
189 * by MSC function driver module. The application should allocate the memory which is accessible by USB
\r
190 * controller/DMA controller.
\r
191 * @note Some memory areas are not accessible by all bus masters.
\r
193 * @param param Structure containing HID function driver module initialization parameters.
\r
194 * @return Returns the required memory size in bytes.
\r
196 uint32_t (*GetMemSize)(USBD_MSC_INIT_PARAM_T* param);
\r
198 /** @fn ErrorCode_t init(USBD_HANDLE_T hUsb, USBD_MSC_INIT_PARAM_T* param)
\r
199 * Function to initialize MSC function driver module.
\r
201 * This fuction is called by application layer to initialize MSC function driver module.
\r
203 * @param hUsb Handle to the USB device stack.
\r
204 * @param param Structure containing HID function driver module initialization parameters.
\r
205 * @return Returns @ref ErrorCode_t type to indicate success or error condition.
\r
206 * @retval LPC_OK On success
\r
207 * @retval ERR_USBD_BAD_MEM_BUF Memory buffer passed is not 4-byte
\r
208 * aligned or smaller than required.
\r
209 * @retval ERR_API_INVALID_PARAM2 Either MSC_Write() or MSC_Read() or
\r
210 * MSC_Verify() callbacks are not defined.
\r
211 * @retval ERR_USBD_BAD_INTF_DESC Wrong interface descriptor is passed.
\r
212 * @retval ERR_USBD_BAD_EP_DESC Wrong endpoint descriptor is passed.
\r
214 ErrorCode_t (*init)(USBD_HANDLE_T hUsb, USBD_MSC_INIT_PARAM_T* param);
\r
218 /*-----------------------------------------------------------------------------
\r
219 * Private functions & structures prototypes
\r
220 *-----------------------------------------------------------------------------*/
\r
221 /** @cond ADVANCED_API */
\r
223 typedef struct _MSC_CTRL_T
\r
225 /* If it's a USB HS, the max packet is 512, if it's USB FS,
\r
226 the max packet is 64. Use 512 for both HS and FS. */
\r
227 /*ALIGNED(4)*/ uint8_t BulkBuf[512]; /* Bulk In/Out Buffer */
\r
228 /*ALIGNED(4)*/MSC_CBW CBW; /* Command Block Wrapper */
\r
229 /*ALIGNED(4)*/MSC_CSW CSW; /* Command Status Wrapper */
\r
231 USB_CORE_CTRL_T* pUsbCtrl;
\r
233 uint32_t Offset; /* R/W Offset */
\r
234 uint32_t Length; /* R/W Length */
\r
235 uint32_t BulkLen; /* Bulk In/Out Length */
\r
238 uint8_t BulkStage; /* Bulk Stage */
\r
239 uint8_t if_num; /* interface number */
\r
240 uint8_t epin_num; /* BULK IN endpoint number */
\r
241 uint8_t epout_num; /* BULK OUT endpoint number */
\r
242 uint32_t MemOK; /* Memory OK */
\r
244 uint8_t* InquiryStr;
\r
245 uint32_t BlockCount;
\r
246 uint32_t BlockSize;
\r
247 uint32_t MemorySize;
\r
248 /* user defined functions */
\r
249 void (*MSC_Write)( uint32_t offset, uint8_t** src, uint32_t length);
\r
250 void (*MSC_Read)( uint32_t offset, uint8_t** dst, uint32_t length);
\r
251 ErrorCode_t (*MSC_Verify)( uint32_t offset, uint8_t src[], uint32_t length);
\r
252 /* optional call back for MSC_Write optimization */
\r
253 void (*MSC_GetWriteBuf)( uint32_t offset, uint8_t** buff_adr, uint32_t length);
\r
262 #endif /* __MSCUSER_H__ */
\r