annotate packages/io/usb/msd/slave/current/include/usbs_msd.h @ 2975:faa94c77900c

* ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage function driver. Contributed by Christophe Coutand. [ Bugzilla 1000987 ]
author jld
date Fri, 12 Nov 2010 13:19:06 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2975
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
1 #ifndef CYGONCE_USBS_MSD_H
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
2 #define CYGONCE_USBS_MSD_H
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
3 //==========================================================================
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
4 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
5 // include/usbs_msd.h
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
6 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
7 // Description of the USB slave-side MSD
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
8 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
9 //==========================================================================
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
10 // ####ECOSGPLCOPYRIGHTBEGIN####
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
11 // -------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
12 // This file is part of eCos, the Embedded Configurable Operating System.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
13 // Copyright (C) 2008, 2010 Free Software Foundation, Inc.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
14 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
15 // eCos is free software; you can redistribute it and/or modify it under
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
16 // the terms of the GNU General Public License as published by the Free
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
17 // Software Foundation; either version 2 or (at your option) any later
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
18 // version.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
19 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
20 // eCos is distributed in the hope that it will be useful, but WITHOUT
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
21 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
23 // for more details.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
24 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
25 // You should have received a copy of the GNU General Public License
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
26 // along with eCos; if not, write to the Free Software Foundation, Inc.,
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
27 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
28 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
29 // As a special exception, if other files instantiate templates or use
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
30 // macros or inline functions from this file, or you compile this file
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
31 // and link it with other works to produce a work based on this file,
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
32 // this file does not by itself cause the resulting work to be covered by
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
33 // the GNU General Public License. However the source code for this file
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
34 // must still be made available in accordance with section (3) of the GNU
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
35 // General Public License v2.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
36 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
37 // This exception does not invalidate any other reasons why a work based
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
38 // on this file might be covered by the GNU General Public License.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
39 // -------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
40 // ####ECOSGPLCOPYRIGHTEND####
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
41 //==========================================================================
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
42 //#####DESCRIPTIONBEGIN####
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
43 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
44 // Author(s): ccoutand
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
45 // Contributors:
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
46 // Date: 2010-06-03
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
47 // Purpose:
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
48 // Description: USB slave-side MSD support
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
49 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
50 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
51 //####DESCRIPTIONEND####
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
52 //==========================================================================
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
53
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
54 #ifdef __cplusplus
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
55 extern "C" {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
56 #endif
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
57
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
58 #include <cyg/infra/cyg_type.h>
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
59 #include <cyg/io/usb/usbs.h>
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
60
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
61 // ----------------------------------------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
62 // The Mass Storage class requests
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
63 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
64 #define USBS_MSD_CLASS_REQ_ADSC 0x00
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
65 #define USBS_MSD_CLASS_REQ_GET_REQUEST 0xFC
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
66 #define USBS_MSD_CLASS_REQ_PUT_REQUEST 0xFD
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
67 #define USBS_MSD_CLASS_REQ_GET_MAX_LUN 0xFE
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
68 #define USBS_MSD_CLASS_REQ_BOMSR 0xFF
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
69
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
70 // ----------------------------------------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
71 // Subclass values
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
72 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
73 #define USBS_MSD_SUB_CLASS_RBC 0x01 // Reduced Block Commands, typically for flash device
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
74 #define USBS_MSD_SUB_CLASS_SFF8020I 0x02 // For CDROM devices
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
75 #define USBS_MSD_SUB_CLASS_QIC_157 0x03 // QIC-157, Tape devices
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
76 #define USBS_MSD_SUB_CLASS_UFI 0x04 // For Floppy Drive Device
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
77 #define USBS_MSD_SUB_CLASS_SFF8070I 0x05 // For Floppy Drive Device
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
78 #define USBS_MSD_SUB_CLASS_SCSI 0x06 // SCSI transparent
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
79
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
80 #define USBS_MSD_DATA_IFACE_CLASS 0x8 // mass-storage
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
81
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
82 // ----------------------------------------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
83 // Command Wrapper values
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
84 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
85 #define USBS_MSD_CSW_STATUS_PASSED 0x0
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
86 #define USBS_MSD_CSW_STATUS_FAILED 0x1
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
87
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
88 #define USBS_MSD_CBW_SIGNATURE 0x43425355
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
89 #define USBS_MSD_CSW_SIGNATURE 0x53425355
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
90
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
91 #define USBS_MSD_CBW_HOST2DEVICE 0x00
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
92 #define USBS_MSD_CBW_DEVICE2HOST 0x80
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
93
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
94 #define USBS_MSD_DEVICE_CLASS 0
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
95 #define USBS_MSD_NUM_IFACE 1
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
96 #define USBS_MSD_NUM_ENDP 2
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
97
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
98 // ----------------------------------------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
99 // Helper macros
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
100 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
101 #define LO_BYTE_16(word16) ((cyg_uint8) ((word16) & 0xFF))
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
102 #define HI_BYTE_16(word16) ((cyg_uint8) (((word16) >> 8) & 0xFF))
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
103
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
104 #define BYTE0_32(word32) ((cyg_uint8) ((word32) & 0xFF))
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
105 #define BYTE1_32(word32) ((cyg_uint8) (((word32) >> 8) & 0xFF))
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
106 #define BYTE2_32(word32) ((cyg_uint8) (((word32) >> 16) & 0xFF))
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
107 #define BYTE3_32(word32) ((cyg_uint8) (((word32) >> 24) & 0xFF))
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
108
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
109 #define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH(interfaces, endpoints) \
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
110 (USB_CONFIGURATION_DESCRIPTOR_LENGTH + \
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
111 ((interfaces) * USB_INTERFACE_DESCRIPTOR_LENGTH) + \
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
112 ((endpoints) * USB_ENDPOINT_DESCRIPTOR_LENGTH))
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
113
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
114 // ----------------------------------------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
115 // Interface values
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
116 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
117 #define USBS_MSD_INTERFACE_PROTO 0x50 // Bulk mode
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
118
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
119 #define USBS_MSD_CBW_MAX_LUN 2
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
120 #define USBS_MSD_CBW_MIN_SCSI_CMD_LEN 1
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
121 #define USBS_MSD_CBW_MAX_SCSI_CMD_LEN 16
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
122
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
123 #define USBS_MSD_DISK_SECTOR_SIZE 512
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
124
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
125 // ----------------------------------------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
126 // Mass Storage task constant
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
127 //
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
128 #define USBS_MSD_THREAD_STACK_SIZE 2048
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
129 #define USBS_MSD_THREAD_STACK_PRIORITY 15
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
130
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
131 // command block wrapper
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
132 typedef struct usbs_msd_cbw {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
133 cyg_uint32 signature;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
134 cyg_uint32 tag;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
135 cyg_uint32 data_transfert_len;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
136 cyg_uint8 flags;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
137 cyg_uint8 lun;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
138 struct cb {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
139 cyg_uint8 len;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
140 cyg_uint8 data[16];
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
141 } cb;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
142 } __attribute__((packed)) usbs_msd_cbw;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
143
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
144 // command status wrapper
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
145 typedef struct usbs_msd_csw {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
146 cyg_uint32 signature;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
147 cyg_uint32 tag;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
148 cyg_uint32 data_residue;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
149 cyg_uint8 status;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
150 } __attribute__((packed)) usbs_msd_csw;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
151
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
152 // command block wrapper state
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
153 typedef enum {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
154 CYG_USBS_MSD_WAIT,
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
155 CYG_USBS_MSD_DATA_IN,
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
156 CYG_USBS_MSD_DATA_OUT
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
157 } usbs_msd_state_t;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
158
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
159 // End-point type
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
160 typedef enum {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
161 CYG_USBS_EP0,
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
162 CYG_USBS_EP_RX,
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
163 CYG_USBS_EP_TX
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
164 } usbs_msd_ep_t;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
165
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
166 // End-point status / control
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
167 typedef struct usbs_msd_ep_sc_t {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
168 cyg_sem_t ready;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
169 cyg_int32 result;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
170 } usbs_msd_ep_sc_t;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
171
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
172 // Storage devices
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
173 typedef struct usbs_msd_lun {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
174 cyg_io_handle_t handle[USBS_MSD_CBW_MAX_LUN];
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
175 const char * name[USBS_MSD_CBW_MAX_LUN];
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
176 cyg_uint8 max_lun;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
177 } usbs_msd_lun;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
178
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
179 typedef struct usbs_msd usbs_msd;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
180
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
181 // Sub Class Handler
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
182 typedef cyg_int32 (*handler_cmd_fn)( usbs_msd * );
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
183 typedef bool (*handler_init_fn)(void **);
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
184
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
185 // End-point functions
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
186 typedef cyg_int32 (*send_fn) ( usbs_msd *, const void * , cyg_int32 );
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
187 typedef cyg_int32 (*receive_fn)( usbs_msd *, const void * , cyg_int32 );
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
188 typedef cyg_int32 (*stall_fn) ( usbs_msd* msd, usbs_msd_ep_t ep );
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
189
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
190 // Mass-storage device structure
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
191 struct usbs_msd {
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
192 // Specify end-points to be used
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
193 usbs_control_endpoint* ctrl_ep;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
194 usbs_tx_endpoint* tx_ep;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
195 usbs_rx_endpoint* rx_ep;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
196
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
197 cyg_uint8 tx_ep_num;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
198 cyg_uint8 rx_ep_num;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
199
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
200 cyg_bool static_ep;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
201
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
202 // Enumeration data for this device
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
203 usbs_enumeration_data* enum_data;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
204
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
205 // Enumeration string
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
206 const char* mfg_str;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
207 const char* product_str;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
208 const char* serial_str;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
209 char* enum_mfg_str;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
210 char* enum_product_str;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
211 char* enum_serial_str;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
212
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
213 // End-point internal status/control
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
214 usbs_msd_ep_sc_t rx;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
215 usbs_msd_ep_sc_t tx;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
216
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
217 // Lock for the state
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
218 cyg_mutex_t lock;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
219
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
220 // Condition variable for state changes
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
221 cyg_cond_t state_cond;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
222
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
223 // State of the USB interface
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
224 cyg_uint32 usb_state;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
225
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
226 // Data transport-phase buffer
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
227 cyg_uint8 buffer[USBS_MSD_DISK_SECTOR_SIZE];
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
228
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
229 // State of the MSD
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
230 usbs_msd_state_t state;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
231
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
232 void (*app_state_change_fn)(struct usbs_control_endpoint*,
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
233 void*, usbs_state_change, int);
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
234
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
235 // Pointer to handler data
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
236 void* handler_data;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
237
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
238 // Commands Handler
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
239 handler_cmd_fn handler_cmd;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
240
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
241 // Initialize Command Handler
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
242 handler_init_fn handler_init;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
243
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
244 send_fn send;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
245 receive_fn receive;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
246 stall_fn stall;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
247
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
248 // Mass-Storage Service
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
249 char serv_stack[USBS_MSD_THREAD_STACK_SIZE];
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
250 cyg_handle_t serv_handle;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
251 cyg_thread serv_thread;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
252 char* serv_name;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
253
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
254 // Storage Device
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
255 usbs_msd_lun* lun;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
256
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
257 // Command Block Wrapper
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
258 usbs_msd_cbw cbw;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
259
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
260 // Command Status Wrapper
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
261 usbs_msd_csw csw;
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
262 };
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
263
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
264 // ----------------------------------------------------------------------------
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
265 // A C interface to the MSD USB code.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
266 // This is the interface for internal code
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
267
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
268 // Block the calling thread until the host configures the USB device.
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
269 void usbs_msd_wait_until_configured( usbs_msd* );
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
270
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
271 // Determines if the USB subsystem is configured
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
272 cyg_bool usbs_msd_is_configured( usbs_msd* );
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
273
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
274 // MSD main thread
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
275 void usbs_msd_handler( cyg_addrword_t );
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
276
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
277 #ifdef __cplusplus
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
278 } // extern "C"
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
279 #endif
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
280
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
281 #endif // CYGONCE_USBS_MSD_H
faa94c77900c * ecos.db, io/usb/msd/slave/current/*: Initial check-in of USB mass storage
jld
parents:
diff changeset
282