M480 BSP  V3.05.001
The Board Support Package for M480 Series
msc.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef _USBH_MSC_H_
10 #define _USBH_MSC_H_
11 
12 #include "ff.h"
13 #include "diskio.h" /* FatFs lower layer API */
14 
15 
17 
18 //#define MSC_DEBUG
19 
20 #ifdef MSC_DEBUG
21 #define msc_debug_msg printf
22 #else
23 #define msc_debug_msg(...)
24 #endif
25 
26 
27 #define USBDRV_0 3 /* FATFS assigned USB disk drive volumn number base */
28 #define USBDRV_MAX 9 /* FATFS assigned USB disk drive volumn number end */
29 #define USBDRV_CNT (USBDRV_MAX - USBDRV_0 + 1)
30 
31 
32 /* Mass Storage Class Sub-class */
33 #define MSC_SCLASS_RBC 0x01 /* Typically, flash devices */
34 #define MSC_SCLASS_8020 0x02 /* CD-ROM */
35 #define MSC_SCLASS_QIC 0x03 /* QIC-157 Tapes */
36 #define MSC_SCLASS_UFI 0x04 /* Floppy */
37 #define MSC_SCLASS_8070 0x05 /* Removable media */
38 #define MSC_SCLASS_SCSI 0x06 /* Transparent */
39 
40 /* Mass Storage Class Sub-protocol */
41 #define MSC_SPROTO_CBI 0x00 /* Control/Bulk/Interrupt */
42 #define MSC_SPROTO_CB 0x01 /* Control/Bulk w/o interrupt */
43 #define MSC_SPROTO_BULK 0x50 /* Bulk only */
44 #define MSC_SPROTO_DPCM_USB 0xf0 /* Combination CB/SDDR09 */
45 
46 
47 /* Command Block Wrapper */
48 struct bulk_cb_wrap
49 {
50  uint32_t Signature; /* 0x43425355 = "USBC" */
51  uint32_t Tag; /* unique per command id */
52  uint32_t DataTransferLength; /* size of data */
53  uint8_t Flags; /* Flag */
54  uint8_t Lun; /* LUN number (begin from 0) */
55  uint8_t Length; /* length of the CDB */
56  uint8_t CDB[16]; /* max command */
57 };
58 
59 #define MSC_CB_WRAP_LEN 31
60 #define MSC_CB_SIGN 0x43425355
61 #define MSC_FLAG_IN 1
62 #define MSC_FLAG_OUT 0
63 
64 /* Command Status Wrapper */
65 struct bulk_cs_wrap
66 {
67  uint32_t Signature; /* 0x53425355 = "USBS" */
68  uint32_t Tag; /* same as original command */
69  uint32_t Residue; /* amount not transferred */
70  uint8_t Status; /* see below */
71 };
72 
73 #define MSC_CS_WRAP_LEN 13
74 #define MSC_CS_SIGN 0x53425355 /* "USBS" */
75 #define MSC_STAT_OK 0 /* command passed */
76 #define MSC_STAT_FAIL 1 /* command failed */
77 #define MSC_STAT_PHASE 2 /* phase error */
78 
79 /*
80  * SCSI opcodes
81  */
82 #define TEST_UNIT_READY 0x00
83 #define REQUEST_SENSE 0x03
84 #define INQUIRY 0x12
85 #define MODE_SENSE 0x1a
86 #define READ_CAPACITY 0x25
87 #define READ_10 0x28
88 #define WRITE_10 0x2a
89 #define MODE_SENSE_10 0x5a
90 
91 #define SCSI_BUFF_LEN 36
92 
93 typedef struct msc_t
94 {
95  IFACE_T *iface;
96  uint32_t uid;
97  EP_INFO_T *ep_bulk_in; /* bulk-in endpoint */
98  EP_INFO_T *ep_bulk_out; /* bulk-out endpoint */
99  uint8_t max_lun;
100  uint8_t lun; /* MSC lun of this instance */
101  uint8_t root; /* root instance? */
102  struct bulk_cb_wrap cmd_blk; /* MSC Bulk-only command block */
103  struct bulk_cs_wrap cmd_status; /* MSC Bulk-only command status */
104  uint8_t scsi_buff[SCSI_BUFF_LEN];/* buffer for SCSI commands */
105  uint32_t uTotalSectorN;
106  uint32_t nSectorSize;
107  uint32_t uDiskSize;
108  int drv_no; /* Logical drive number associated with this instance */
109  FATFS fatfs_vol; /* FATFS volumn */
110  struct msc_t *next; /* point to next MSC device */
111 } MSC_T;
112 
113 
114 extern int run_scsi_command(MSC_T *msc, uint8_t *buff, uint32_t data_len, int bIsDataIn, int timeout_ticks);
115 
116 
118 
119 
120 #endif /* _USBH_MSC_H_ */
121 
122 /*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/
123 
124 
int run_scsi_command(MSC_T *msc, uint8_t *buff, uint32_t data_len, int bIsDataIn, int timeout_ticks)
Definition: msc_xfer.c:113