OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [usb/] [msd/] [slave/] [current/] [include/] [usbs_msd.h] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.