]> git.sur5r.net Git - armstart-ibdap/blob - inc/usbd/usbd_mscuser.h
Fix build
[armstart-ibdap] / inc / usbd / usbd_mscuser.h
1 /***********************************************************************\r
2 * $Id:: mw_usbd_mscuser.h 577 2012-11-20 01:42:04Z usb10131                   $\r
3 *\r
4 * Project: USB device ROM Stack\r
5 *\r
6 * Description:\r
7 *     Mass Storage Class Custom User Module definitions.\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 __MSCUSER_H__\r
25 #define __MSCUSER_H__\r
26 \r
27 #include "error.h"\r
28 #include "usbd.h"\r
29 #include "usbd_msc.h"\r
30 #include "usbd_core.h"\r
31 #include "app_usbd_cfg.h"\r
32 \r
33 /** \file\r
34  *  \brief Mass Storage Class (MSC) API structures and function prototypes.\r
35  *\r
36  *  Definition of functions exported by ROM based MSC function driver.\r
37  *\r
38  */\r
39 \r
40 /** \ingroup Group_USBD\r
41  *  @defgroup USBD_MSC Mass Storage Class (MSC) Function Driver\r
42  *  \section Sec_MSCModDescription Module Description\r
43  *  MSC Class Function Driver module. This module contains an internal implementation of the USB MSC Class.\r
44  *  User applications can use this class driver instead of implementing the MSC class manually\r
45  *  via the low-level USBD_HW and USBD_Core APIs.\r
46  *\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 MSC Class.\r
49  */\r
50 \r
51 /** \brief Mass Storage class function driver initialization parameter data structure.\r
52  *  \ingroup USBD_MSC\r
53  *\r
54  *  \details  This data structure is used to pass initialization parameters to the \r
55  *  Mass Storage class function driver's init function.\r
56  *\r
57  */\r
58 typedef struct USBD_MSC_INIT_PARAM\r
59 {\r
60   /* memory allocation params */\r
61   uint32_t mem_base;  /**< Base memory location from where the stack can allocate\r
62                       data and buffers. \note The memory address set in this field\r
63                       should be accessible by USB DMA controller. Also this value\r
64                       should be aligned on 4 byte boundary.\r
65                       */\r
66   uint32_t mem_size;  /**< The size of memory buffer which stack can use. \r
67                       \note The \em mem_size should be greater than the size \r
68                       returned by USBD_MSC_API::GetMemSize() routine.*/\r
69   /* mass storage params */\r
70   uint8_t*  InquiryStr; /**< Pointer to the 28 character string. This string is \r
71                         sent in response to the SCSI Inquiry command. \note The data \r
72                         pointed by the pointer should be of global scope. \r
73                         */\r
74   uint32_t  BlockCount; /**< Number of blocks present in the mass storage device */\r
75   uint32_t  BlockSize; /**< Block size in number of bytes */\r
76   uint32_t  MemorySize; /**< Memory size in number of bytes */\r
77   /** Pointer to the interface descriptor within the descriptor\r
78   * array (\em high_speed_desc) passed to Init() through \ref USB_CORE_DESCS_T \r
79   * structure. The stack assumes both HS and FS use same BULK endpoints. \r
80   */\r
81 \r
82   uint8_t* intf_desc;\r
83   /* user defined functions */\r
84 \r
85  /** \r
86   *  MSC Write callback function.\r
87   *\r
88   *  This function is provided by the application software. This function gets called \r
89   *  when host sends a write command.\r
90   *  \r
91   *  \param[in] offset Destination start address. \r
92   *  \param[in, out] src  Pointer to a pointer to the source of data. Pointer-to-pointer\r
93   *                       is used to implement zero-copy buffers. See \ref USBD_ZeroCopy\r
94   *                       for more details on zero-copy concept.\r
95   *  \param[in] length  Number of bytes to be written.\r
96   *  \return Nothing. \r
97   *                                             \r
98   */\r
99   void (*MSC_Write)( uint32_t offset, uint8_t** src, uint32_t length, uint32_t high_offset); \r
100  /** \r
101   *  MSC Read callback function.\r
102   *\r
103   *  This function is provided by the application software. This function gets called \r
104   *  when host sends a read command.\r
105   *  \r
106   *  \param[in] offset Source start address. \r
107   *  \param[in, out] dst  Pointer to a pointer to the source of data. The MSC function drivers \r
108   *         implemented in stack are written with zero-copy model. Meaning the stack doesn't make an \r
109   *          extra copy of buffer before writing/reading data from USB hardware FIFO. Hence the \r
110   *          parameter is pointer to a pointer containing address buffer (<em>uint8_t** dst</em>). \r
111   *          So that the user application can update the buffer pointer instead of copying data to \r
112   *          address pointed by the parameter. /note The updated buffer address should be accessible\r
113   *          by USB DMA master. If user doesn't want to use zero-copy model, then the user should copy\r
114   *          data to the address pointed by the passed buffer pointer parameter and shouldn't change \r
115   *          the address value. See \ref USBD_ZeroCopy for more details on zero-copy concept.\r
116   *  \param[in] length  Number of bytes to be read.\r
117   *  \return Nothing. \r
118   *                                             \r
119   */\r
120   void (*MSC_Read)( uint32_t offset, uint8_t** dst, uint32_t length, uint32_t high_offset);\r
121  /** \r
122   *  MSC Verify callback function.\r
123   *\r
124   *  This function is provided by the application software. This function gets called \r
125   *  when host sends a verify command. The callback function should compare the buffer\r
126   *  with the destination memory at the requested offset and \r
127   *  \r
128   *  \param[in] offset Destination start address. \r
129   *  \param[in] buf  Buffer containing the data sent by the host.\r
130   *  \param[in] length  Number of bytes to verify.\r
131   *  \return Returns \ref ErrorCode_t type to indicate success or error condition.\r
132   *          \retval LPC_OK If data in the buffer matches the data at destination\r
133   *          \retval ERR_FAILED  At least one byte is different.\r
134   *                                             \r
135   */\r
136   ErrorCode_t (*MSC_Verify)( uint32_t offset, uint8_t buf[], uint32_t length, uint32_t high_offset);\r
137   /** \r
138   *  Optional callback function to optimize MSC_Write buffer transfer.\r
139   *\r
140   *  This function is provided by the application software. This function gets called \r
141   *  when host sends SCSI_WRITE10/SCSI_WRITE12 command. The callback function should \r
142   *  update the \em buff_adr pointer so that the stack transfers the data directly\r
143   *  to the target buffer. /note The updated buffer address should be accessible\r
144   *  by USB DMA master. If user doesn't want to use zero-copy model, then the user \r
145   *  should not update the buffer pointer. See \ref USBD_ZeroCopy for more details\r
146   *  on zero-copy concept.\r
147   *  \r
148   *  \param[in] offset Destination start address. \r
149   *  \param[in,out] buf  Buffer containing the data sent by the host.\r
150   *  \param[in] length  Number of bytes to write.\r
151   *  \return Nothing. \r
152   *                                             \r
153   */\r
154   void (*MSC_GetWriteBuf)( uint32_t offset, uint8_t** buff_adr, uint32_t length, uint32_t high_offset); \r
155 \r
156   /** \r
157   *  Optional user override-able function to replace the default MSC class handler.\r
158   *\r
159   *  The application software could override the default EP0 class handler with their\r
160   *  own by providing the handler function address as this data member of the parameter\r
161   *  structure. Application which like the default handler should set this data member\r
162   *  to zero before calling the USBD_MSC_API::Init().\r
163   *  \n\r
164   *  \note \r
165   *  \r
166   *  \param[in] hUsb Handle to the USB device stack. \r
167   *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack. \r
168   *  \param[in] event  Type of endpoint event. See \ref USBD_EVENT_T for more details.\r
169   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.\r
170   *          \retval LPC_OK On success.\r
171   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line. \r
172   *          \retval ERR_USBD_xxx  For other error conditions. \r
173   *                                             \r
174   */\r
175   ErrorCode_t (*MSC_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);\r
176 \r
177   uint64_t  MemorySize64;\r
178   \r
179 } USBD_MSC_INIT_PARAM_T;\r
180 \r
181 /** \brief MSC class API functions structure.\r
182  *  \ingroup USBD_MSC\r
183  *\r
184  *  This module exposes functions which interact directly with USB device controller hardware.\r
185  *\r
186  */\r
187 typedef struct USBD_MSC_API\r
188 {\r
189   /** \fn uint32_t GetMemSize(USBD_MSC_INIT_PARAM_T* param)\r
190    *  Function to determine the memory required by the MSC function driver module.\r
191    * \r
192    *  This function is called by application layer before calling pUsbApi->msc->Init(), to allocate memory used \r
193    *  by MSC function driver module. The application should allocate the memory which is accessible by USB\r
194    *  controller/DMA controller. \r
195    *  \note Some memory areas are not accessible by all bus masters.\r
196    *\r
197    *  \param[in] param Structure containing MSC function driver module initialization parameters.\r
198    *  \return Returns the required memory size in bytes.\r
199    */\r
200   uint32_t (*GetMemSize)(USBD_MSC_INIT_PARAM_T* param);\r
201   \r
202   /** \fn ErrorCode_t init(USBD_HANDLE_T hUsb, USBD_MSC_INIT_PARAM_T* param)\r
203    *  Function to initialize MSC function driver module.\r
204    * \r
205    *  This function is called by application layer to initialize MSC function driver module.\r
206    *\r
207    *  \param[in] hUsb Handle to the USB device stack. \r
208    *  \param[in, out] param Structure containing MSC function driver module initialization parameters.\r
209    *  \return Returns \ref ErrorCode_t type to indicate success or error condition.\r
210    *          \retval LPC_OK On success\r
211    *          \retval ERR_USBD_BAD_MEM_BUF  Memory buffer passed is not 4-byte \r
212    *              aligned or smaller than required. \r
213    *          \retval ERR_API_INVALID_PARAM2 Either MSC_Write() or MSC_Read() or\r
214    *              MSC_Verify() callbacks are not defined. \r
215    *          \retval ERR_USBD_BAD_INTF_DESC  Wrong interface descriptor is passed. \r
216    *          \retval ERR_USBD_BAD_EP_DESC  Wrong endpoint descriptor is passed. \r
217    */\r
218   ErrorCode_t (*init)(USBD_HANDLE_T hUsb, USBD_MSC_INIT_PARAM_T* param);\r
219 \r
220 } USBD_MSC_API_T;\r
221 \r
222 /*-----------------------------------------------------------------------------\r
223  *  Private functions & structures prototypes\r
224  *-----------------------------------------------------------------------------*/\r
225 /** @cond  ADVANCED_API */\r
226 \r
227 typedef struct _MSC_CTRL_T\r
228 {\r
229   /* If it's a USB HS, the max packet is 512, if it's USB FS,\r
230   the max packet is 64. Use 512 for both HS and FS. */\r
231   /*ALIGNED(4)*/ uint8_t  BulkBuf[USB_HS_MAX_BULK_PACKET]; /* Bulk In/Out Buffer */\r
232   /*ALIGNED(4)*/MSC_CBW CBW;                   /* Command Block Wrapper */\r
233   /*ALIGNED(4)*/MSC_CSW CSW;                   /* Command Status Wrapper */\r
234 \r
235   USB_CORE_CTRL_T*  pUsbCtrl;\r
236   \r
237   uint64_t Offset;                  /* R/W Offset */\r
238   uint32_t Length;                  /* R/W Length */\r
239   uint32_t BulkLen;                 /* Bulk In/Out Length */\r
240   uint8_t* rx_buf;\r
241   \r
242   uint8_t BulkStage;               /* Bulk Stage */\r
243   uint8_t if_num;                  /* interface number */\r
244   uint8_t epin_num;                /* BULK IN endpoint number */\r
245   uint8_t epout_num;               /* BULK OUT endpoint number */\r
246   uint32_t MemOK;                  /* Memory OK */\r
247 \r
248   uint8_t*  InquiryStr;\r
249   uint32_t  BlockCount;\r
250   uint32_t  BlockSize;\r
251   uint64_t  MemorySize;\r
252   /* user defined functions */\r
253   void (*MSC_Write)( uint32_t offset, uint8_t** src, uint32_t length, uint32_t high_offset); \r
254   void (*MSC_Read)( uint32_t offset, uint8_t** dst, uint32_t length, uint32_t high_offset);\r
255   ErrorCode_t (*MSC_Verify)( uint32_t offset, uint8_t src[], uint32_t length, uint32_t high_offset);\r
256   /* optional call back for MSC_Write optimization */\r
257   void (*MSC_GetWriteBuf)( uint32_t offset, uint8_t** buff_adr, uint32_t length, uint32_t high_offset); \r
258 \r
259 \r
260 }USB_MSC_CTRL_T;\r
261 \r
262 /** @cond  DIRECT_API */\r
263 extern uint32_t mwMSC_GetMemSize(USBD_MSC_INIT_PARAM_T* param);\r
264 extern ErrorCode_t mwMSC_init(USBD_HANDLE_T hUsb, USBD_MSC_INIT_PARAM_T* param);\r
265 /** @endcond */\r
266 \r
267 /** @endcond */\r
268 \r
269 \r
270 #endif  /* __MSCUSER_H__ */\r