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