User | Revision | Line number | New contents of line |
slowness |
0:4359b47b3d7c
|
1
|
/* USB Mass Storage device file system
|
slowness |
0:4359b47b3d7c
|
2
|
* Copyrigh (c) 2010, Igor Skochinsky
|
slowness |
0:4359b47b3d7c
|
3
|
* based on SDFileStorage
|
slowness |
0:4359b47b3d7c
|
4
|
* Copyright (c) 2008-2009, sford
|
slowness |
0:4359b47b3d7c
|
5
|
*/
|
slowness |
0:4359b47b3d7c
|
6
|
|
slowness |
0:4359b47b3d7c
|
7
|
/* Introduction
|
slowness |
0:4359b47b3d7c
|
8
|
* ------------
|
slowness |
0:4359b47b3d7c
|
9
|
* TODO: write one
|
slowness |
0:4359b47b3d7c
|
10
|
* we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library
|
slowness |
0:4359b47b3d7c
|
11
|
*/
|
slowness |
0:4359b47b3d7c
|
12
|
|
slowness |
0:4359b47b3d7c
|
13
|
#include "MSCFileSystem.h"
|
slowness |
0:4359b47b3d7c
|
14
|
#include "usbhost_inc.h"
|
slowness |
0:4359b47b3d7c
|
15
|
|
slowness |
0:4359b47b3d7c
|
16
|
MSCFileSystem::MSCFileSystem(const char* name) :
|
slowness |
0:4359b47b3d7c
|
17
|
FATFileSystem(name)
|
slowness |
0:4359b47b3d7c
|
18
|
{
|
slowness |
0:4359b47b3d7c
|
19
|
}
|
slowness |
0:4359b47b3d7c
|
20
|
|
slowness |
0:4359b47b3d7c
|
21
|
void print_inquiry(USB_INT08U *inqReply)
|
slowness |
0:4359b47b3d7c
|
22
|
{
|
slowness |
0:4359b47b3d7c
|
23
|
// see USB Mass Storage Class � UFI Command Specification,
|
slowness |
0:4359b47b3d7c
|
24
|
// 4.2 INQUIRY Command
|
slowness |
0:4359b47b3d7c
|
25
|
printf("Inquiry reply:\n");
|
slowness |
0:4359b47b3d7c
|
26
|
uint8_t tmp = inqReply[0]&0x1F;
|
slowness |
0:4359b47b3d7c
|
27
|
printf("Peripheral device type: %02Xh\n", tmp);
|
slowness |
0:4359b47b3d7c
|
28
|
if ( tmp == 0 )
|
slowness |
0:4359b47b3d7c
|
29
|
printf("\t- Direct access (floppy)\n");
|
slowness |
0:4359b47b3d7c
|
30
|
else if ( tmp == 0x1F )
|
slowness |
0:4359b47b3d7c
|
31
|
printf("\t- none (no FDD connected)\n");
|
slowness |
0:4359b47b3d7c
|
32
|
else
|
slowness |
0:4359b47b3d7c
|
33
|
printf("\t- unknown type\n");
|
slowness |
0:4359b47b3d7c
|
34
|
tmp = inqReply[1] >> 7;
|
slowness |
0:4359b47b3d7c
|
35
|
printf("Removable Media Bit: %d\n", tmp);
|
slowness |
0:4359b47b3d7c
|
36
|
tmp = inqReply[2] & 3;
|
slowness |
0:4359b47b3d7c
|
37
|
printf("ANSI Version: %02Xh\n", tmp);
|
slowness |
0:4359b47b3d7c
|
38
|
if ( tmp != 0 )
|
slowness |
0:4359b47b3d7c
|
39
|
printf("\t- warning! must be 0\n");
|
slowness |
0:4359b47b3d7c
|
40
|
tmp = (inqReply[2]>>3) & 3;
|
slowness |
0:4359b47b3d7c
|
41
|
printf("ECMA Version: %02Xh\n", tmp);
|
slowness |
0:4359b47b3d7c
|
42
|
if ( tmp != 0 )
|
slowness |
0:4359b47b3d7c
|
43
|
printf("\t- warning! should be 0\n");
|
slowness |
0:4359b47b3d7c
|
44
|
tmp = inqReply[2]>>6;
|
slowness |
0:4359b47b3d7c
|
45
|
printf("ISO Version: %02Xh\n", tmp);
|
slowness |
0:4359b47b3d7c
|
46
|
if ( tmp != 0 )
|
slowness |
0:4359b47b3d7c
|
47
|
printf("\t- warning! should be 0\n");
|
slowness |
0:4359b47b3d7c
|
48
|
tmp = inqReply[3] & 0xF;
|
slowness |
0:4359b47b3d7c
|
49
|
printf("Response Data Format: %02Xh\n", tmp);
|
slowness |
0:4359b47b3d7c
|
50
|
if ( tmp != 1 )
|
slowness |
0:4359b47b3d7c
|
51
|
printf("\t- warning! should be 1\n");
|
slowness |
0:4359b47b3d7c
|
52
|
tmp = inqReply[4];
|
slowness |
0:4359b47b3d7c
|
53
|
printf("Additional length: %02Xh\n", tmp);
|
slowness |
0:4359b47b3d7c
|
54
|
if ( tmp != 0x1F )
|
slowness |
0:4359b47b3d7c
|
55
|
printf("\t- warning! should be 1Fh\n");
|
slowness |
0:4359b47b3d7c
|
56
|
printf("Vendor Information: '%.8s'\n", &inqReply[8]);
|
slowness |
0:4359b47b3d7c
|
57
|
printf("Product Identification: '%.16s'\n", &inqReply[16]);
|
slowness |
0:4359b47b3d7c
|
58
|
printf("Product Revision: '%.4s'\n", &inqReply[32]);
|
slowness |
0:4359b47b3d7c
|
59
|
}
|
slowness |
0:4359b47b3d7c
|
60
|
|
slowness |
0:4359b47b3d7c
|
61
|
int MSCFileSystem::initialise_msc()
|
slowness |
0:4359b47b3d7c
|
62
|
{
|
slowness |
0:4359b47b3d7c
|
63
|
USB_INT32S rc;
|
slowness |
0:4359b47b3d7c
|
64
|
USB_INT08U inquiryResult[INQUIRY_LENGTH];
|
slowness |
0:4359b47b3d7c
|
65
|
|
slowness |
0:4359b47b3d7c
|
66
|
//print_clock();
|
slowness |
0:4359b47b3d7c
|
67
|
Host_Init(); /* Initialize the host controller */
|
slowness |
0:4359b47b3d7c
|
68
|
rc = Host_EnumDev(); /* Enumerate the device connected */
|
slowness |
0:4359b47b3d7c
|
69
|
if (rc != OK)
|
slowness |
0:4359b47b3d7c
|
70
|
{
|
slowness |
0:4359b47b3d7c
|
71
|
fprintf(stderr, "Could not enumerate device: %d\n", rc);
|
slowness |
0:4359b47b3d7c
|
72
|
return rc;
|
slowness |
0:4359b47b3d7c
|
73
|
}
|
slowness |
0:4359b47b3d7c
|
74
|
|
slowness |
0:4359b47b3d7c
|
75
|
|
slowness |
0:4359b47b3d7c
|
76
|
/* Initialize the mass storage and scsi interfaces */
|
slowness |
0:4359b47b3d7c
|
77
|
rc = MS_Init( &_blkSize, &_numBlks, inquiryResult );
|
slowness |
0:4359b47b3d7c
|
78
|
if (rc != OK)
|
slowness |
0:4359b47b3d7c
|
79
|
{
|
slowness |
0:4359b47b3d7c
|
80
|
fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc);
|
slowness |
0:4359b47b3d7c
|
81
|
return rc;
|
slowness |
0:4359b47b3d7c
|
82
|
}
|
slowness |
0:4359b47b3d7c
|
83
|
printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize);
|
slowness |
0:4359b47b3d7c
|
84
|
print_inquiry(inquiryResult);
|
slowness |
0:4359b47b3d7c
|
85
|
// FATFileSystem supports only 512-byte blocks
|
slowness |
0:4359b47b3d7c
|
86
|
return _blkSize == 512 ? OK : 1;
|
slowness |
0:4359b47b3d7c
|
87
|
}
|
slowness |
0:4359b47b3d7c
|
88
|
|
slowness |
0:4359b47b3d7c
|
89
|
int MSCFileSystem::disk_initialize()
|
slowness |
0:4359b47b3d7c
|
90
|
{
|
slowness |
0:4359b47b3d7c
|
91
|
if ( initialise_msc() != OK )
|
slowness |
0:4359b47b3d7c
|
92
|
return 1;
|
slowness |
0:4359b47b3d7c
|
93
|
|
slowness |
0:4359b47b3d7c
|
94
|
return 0;
|
slowness |
0:4359b47b3d7c
|
95
|
}
|
slowness |
0:4359b47b3d7c
|
96
|
|
slowness |
0:4359b47b3d7c
|
97
|
int MSCFileSystem::disk_write(const char *buffer, int block_number)
|
slowness |
0:4359b47b3d7c
|
98
|
{
|
slowness |
0:4359b47b3d7c
|
99
|
if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) )
|
slowness |
0:4359b47b3d7c
|
100
|
return 0;
|
slowness |
0:4359b47b3d7c
|
101
|
return 1;
|
slowness |
0:4359b47b3d7c
|
102
|
}
|
slowness |
0:4359b47b3d7c
|
103
|
|
slowness |
0:4359b47b3d7c
|
104
|
int MSCFileSystem::disk_read(char *buffer, int block_number)
|
slowness |
0:4359b47b3d7c
|
105
|
{
|
slowness |
0:4359b47b3d7c
|
106
|
if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) )
|
slowness |
0:4359b47b3d7c
|
107
|
return 0;
|
slowness |
0:4359b47b3d7c
|
108
|
return 1;
|
slowness |
0:4359b47b3d7c
|
109
|
}
|
slowness |
0:4359b47b3d7c
|
110
|
|
slowness |
0:4359b47b3d7c
|
111
|
int MSCFileSystem::disk_status() { return 0; }
|
slowness |
0:4359b47b3d7c
|
112
|
int MSCFileSystem::disk_sync() { return 0; }
|
slowness |
0:4359b47b3d7c
|
113
|
int MSCFileSystem::disk_sectors() { return _numBlks; }
|