PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
UsbHostMassStorage.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
54 #ifndef __USBHOSTMASSSTORAGE_H__
55 #define __USBHOSTMASSSTORAGE_H__
56 
57 /*****************************************************************************/
58 /* Include files */
59 /*****************************************************************************/
60 
61 #include "usb.h"
62 
63 #ifndef USBHOSTMASSSTORAGE_ENABLED
64  #define USBHOSTMASSSTORAGE_ENABLED OFF
65 #endif
66 
67 #if ((FM_PERIPHERAL_USB_HOST_ENABLED == ON) && (USBHOSTMASSSTORAGE_ENABLED == ON))
68 
69 /* C binding of definitions if building with C++ compiler */
70 #ifdef __cplusplus
71 extern "C"
72 {
73 #endif
74 
99 
100 #include "UsbHost.h"
101 #include "diskio.h"
102 
103 /*****************************************************************************/
104 /* Global pre-processor symbols/macros ('#define') */
105 /*****************************************************************************/
106 
107 #define USBMASSSTORAGE_FLAG_TRANSFERDONE (1<<0)
108 #define USBMASSSTORAGE_FLAG_TRANSFERDONE_IN (1<<1)
109 #define USBMASSSTORAGE_FLAG_TRANSFERDONE_OUT (1<<2)
110 
111 #define FORMAT_UNIT 0x04
112 #define INQUIRY_MASS_STORAGE 0x12
113 #define MODE_SELECT 0x55
114 #define MODE_SENSE 0x5A
115 #define PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E
116 #define READ_MASS_STORAGE 0x28
117 #define READ_MASS_STORAGE_CAPACITY 0x25
118 #define READ_FORMAT_CAPACITIES 0x23
119 #define MASS_STORAGE_REQUEST_SENSE 0x03
120 #define REZERO 0x01
121 #define SEEK10 0x2B
122 #define SEND_DIAGNOSTIC 0x1D
123 #define START_STOP_UNIT 0x1B
124 #define TEST_UNIT_READY 0x00
125 #define VERIFY 0x2F
126 #define WRITE_MASS_STORAGE 0x2A
127 #define WRITE12 0xAA
128 #define WRITE_AND_VERIFY 0x2E
129 
130 #define CBW_TAG 0x1A2B3C4D
131 
132 #define LITTLEENDIAN 1
133 #define BIGENDIAN 2
134 #define ENDIANTYPE BIGENDIAN
135 
136 #define LENDIAN_BUFFER_TO_U32(pu8Buffer)\
137 (uint32_t)( (uint32_t)*(uint8_t*)(pu8Buffer) \
138  | ((((uint32_t)*(((uint8_t*)(pu8Buffer))+1)) << 8 ) & 0xFF00UL )\
139  | ((((uint32_t)*(((uint8_t*)(pu8Buffer))+2)) << 16 ) & 0xFF0000UL )\
140  | ((((uint32_t)*(((uint8_t*)(pu8Buffer))+3)) << 24 ) & 0xFF000000UL)\
141  )
142 
143 #define U32_TO_LENDIAN_BUFFER(pu8Buffer,u32Data)\
144  { *((pu8Buffer)) =(uint8_t)((uint32_t)(u32Data) );\
145  *((pu8Buffer)+1)=(uint8_t)((uint32_t)(u32Data) >> 8);\
146  *((pu8Buffer)+2)=(uint8_t)((uint32_t)(u32Data) >> 16);\
147  *((pu8Buffer)+3)=(uint8_t)((uint32_t)(u32Data) >> 24);\
148  }
149 
150 /*****************************************************************************/
151 /* Global type definitions ('typedef') */
152 /*****************************************************************************/
153 typedef struct cbw
154 {
155  uint32_t dCBWSignature;
156  uint32_t dCBWTag;
158  uint8_t bCBWFlags;
159  uint8_t bCBWLUN;
160  uint8_t bCBWCBLength;
161  uint8_t CBWCB[16];
162 } cbw_t;
163 
164 typedef struct csw
165 {
166  uint32_t CSWSignatur;
167  uint32_t CSWTag;
168  uint32_t CSWDataResidue;
169  uint8_t CSWStatus;
170 } csw_t;
171 
172 // Response struct
173 typedef struct InquiryResponse
174 {
175  uint8_t Peripheral;
176  uint8_t Removable;
177  uint8_t Version;
180  uint8_t Sccstp;
181  uint8_t Bqueetc;
182  uint8_t CmdQue;
183  uint8_t VendorID[8];
184  uint8_t ProductID[16];
185  uint8_t ProductRev[4];
187 
188 
189 // 8 byte capacity value buffer
190 typedef struct read_capacity
191 {
192  uint32_t SectorCount;
193  uint32_t SectorSize;
195 
196 
197 // Functions
198 typedef struct RequestSenseResponse
199 {
200  uint16_t ResponseCode :7;
201  uint16_t VALID :1;
202  uint8_t Obsolete;
203  uint16_t SenseKey :4;
204  uint16_t Resv :1;
205  uint16_t ILI :1;
206  uint16_t EOM :1;
207  uint16_t FILEMARK :1;
208  uint32_t Information;
209  uint8_t AddSenseLen;
210  uint32_t CmdSpecificInfo;
211  uint8_t ASC;
212  uint8_t ASCQ;
213  uint8_t FRUC;
214  uint8_t SenseKeySpecific[3];
216 
217 typedef struct StorageInfo
218 {
219  uint8_t STORAGE_CMD;
220  uint16_t BUFFER_SIZE;
221  uint8_t* BUFFER;
222  uint16_t IN_EP;
223  uint16_t OUT_EP;
224  uint32_t BLOCK_START;
225  uint8_t BLOCK_CNT;
226  uint16_t STATUS;
227  uint8_t SEND_CBW;
228  uint8_t GET_CSW;
229  uint8_t CSW_STATUS;
231  uint16_t ERROR_CODE;
232  uint8_t MAX_LUN;
233 } StorageInfo_t;
234 
235 
236 typedef struct inquiry_response
237 {
238  uint8_t Peripheral;
239  uint8_t Removable;
240  uint8_t Version;
243  uint8_t Sccstp;
244  uint8_t Bqueetc;
245  uint8_t CmdQue;
246  uint8_t VendorID[8];
247  uint8_t ProductID[16];
248  uint8_t ProductRev[4];
250 
251 typedef struct ModeSenseResponse
252 {
253  uint8_t ModeDataLength;
254  uint8_t MediumType;
255  uint8_t Reserved1 :4;
256  uint8_t DPOFUA :1;
257  uint8_t Reserved2 :2;
258  uint8_t WriteProtect :1;
261 
262 typedef struct StorageReadWrite
263 {
264  uint8_t data[512];
266 
267 
268 // Struct for write data
269 typedef struct StorageWrite
270 {
271  uint8_t data[10];
273 
274 
275 /*****************************************************************************/
276 /* Global variable declarations ('extern', definition in C source) */
277 /*****************************************************************************/
278 
279 
280 
281 /*****************************************************************************/
282 /* Global function prototypes ('extern', definition in C source) */
283 /*****************************************************************************/
284 
285 /* Storage API */
286 int UsbHostMassStorage_StorageApiRead(BYTE *buff, DWORD sector, BYTE count);
287 int UsbHostMassStorage_StorageApiWrite(BYTE *buff, DWORD sector, BYTE count);
291 /* END Storage API */
292 
293 void UsbHostMassStorage_Init(void);
294 boolean_t UsbHostMassStorage_DeinitHandler(stc_usbn_t* pstcUsb);
295 boolean_t UsbHostMassStorage_InitHandler(stc_usbn_t* pstcUsb,uint8_t* pu8Configuration, uint32_t u32Length);
300 void UsbHostMassStorage_CheckForCompletion(volatile uint8_t *NAKDetected);
313 void UsbHostMassStorage_GetEPStatus(uint8_t* InEpStatus, uint8_t* OutEpStatus);
315 
317 
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 
325 
326 #endif /* (USE_USB_HOST == 1) */
327 #endif /* __USBMASSSTORAGE_H__*/