|
1 |
|
2 #include <kern_priv.h> |
|
3 //#include <beagle/beagle_gpio.h> |
|
4 #include <beagle/variant.h> |
|
5 //#include <assp/omap3530_assp/omap3530_assp_priv.h> |
|
6 //#include <assp/omap3530_assp/omap3530_irqmap.h> // GPIO interrupts |
|
7 //#include <assp/omap3530_assp/omap3530_gpio.h> |
|
8 |
|
9 //#include <assp.h> // Required for definition of TIsr |
|
10 |
|
11 #include <cyastoria.h> |
|
12 #include <cyasmtp.h> |
|
13 #include <cyasusbinit.h> |
|
14 //#include <cyasusbdescs.h> |
|
15 #include "CyAsSymbianStorageDriver.h" |
|
16 |
|
17 extern TmtpAstDev g_AstDevice; |
|
18 extern TmtpAstDev * g_pAstDevice; |
|
19 |
|
20 _LIT(KLitWbAPIMutex,"WBAPIMutex"); |
|
21 static DMutex *WbApiMutex; |
|
22 const TUint8 KMutexOrdWB = 0x11; /**< @internalComponent */ |
|
23 |
|
24 TInt64 iMediaTotalSize; |
|
25 EXPORT_C int CyAsSymbianStorageDriver::Open(void) |
|
26 { |
|
27 //CyAsHalDeviceTag tag; |
|
28 CyAsDeviceHandle h; |
|
29 CyAsReturnStatus_t ret ; |
|
30 char *media_name = "SD"; |
|
31 uint32_t count = 0 ; |
|
32 |
|
33 Kern::MutexCreate(WbApiMutex, KLitWbAPIMutex, KMutexOrdWB); |
|
34 //tag = g_pAstDevice->astHalTag ; |
|
35 h = g_pAstDevice->astDevHandle ; |
|
36 |
|
37 Kern::Printf("*** CyAsStorageStart...\n") ; |
|
38 ret = CyAsStorageStart(h, 0, 0) ; |
|
39 if (ret != CY_AS_ERROR_SUCCESS) |
|
40 { |
|
41 Kern::Printf("CyAsSymbianStorageOpen: CyAsStorageStart returned error code %d\n", ret) ; |
|
42 return 0 ; |
|
43 } |
|
44 |
|
45 Kern::Printf("*** CyAsStorageQueryMedia...\n") ; |
|
46 ret = CyAsStorageQueryMedia(h, CyAsMediaSDFlash, &count, 0, 0) ; |
|
47 if (ret != CY_AS_ERROR_SUCCESS) |
|
48 { |
|
49 Kern::Printf("CyAsSymbianStorageOpen: Cannot query %s device count - Reason code %d\n", media_name, ret) ; |
|
50 return 0 ; |
|
51 } |
|
52 Kern::Printf("%d %s device(s) found\n", count, media_name) ; |
|
53 |
|
54 Kern::Printf("*** CyAsStorageClaim...\n") ; |
|
55 ret = CyAsStorageClaim(h, CyAsBus_1, 0, 0, 0) ; |
|
56 if (ret != CY_AS_ERROR_SUCCESS) |
|
57 { |
|
58 Kern::Printf("CyAsSymbianStorageOpen: Cannot claim %s media - Reason code %d\n", media_name, ret) ; |
|
59 return 0; |
|
60 } |
|
61 |
|
62 /* We know that there is only one */ |
|
63 g_pAstDevice->dev_data.bus = CyAsBus_1 ; |
|
64 g_pAstDevice->dev_data.device = 0 ; |
|
65 ret = CyAsStorageQueryDevice(h, &(g_pAstDevice->dev_data), 0, 0) ; |
|
66 if (ret != CY_AS_ERROR_SUCCESS) |
|
67 { |
|
68 Kern::Printf("CyAsSymbianStorageOpen: Cannot query %s device - Reason code %d\n", media_name, ret) ; |
|
69 return 0 ; |
|
70 } |
|
71 |
|
72 g_pAstDevice->unit_data.bus = CyAsBus_1 ; |
|
73 g_pAstDevice->unit_data.device = 0 ; |
|
74 g_pAstDevice->unit_data.unit = 0 ; |
|
75 |
|
76 /* We know that there is only one */ |
|
77 ret = CyAsStorageQueryUnit(h, &(g_pAstDevice->unit_data), 0, 0) ; |
|
78 if (ret != CY_AS_ERROR_SUCCESS) |
|
79 { |
|
80 Kern::Printf("CyAsSymbianStorageOpen: Cannot query %s device unit - Reason code %d\n", media_name, ret) ; |
|
81 return 0 ; |
|
82 } |
|
83 |
|
84 iMediaTotalSize = (TInt64)g_pAstDevice->dev_data.desc_p.block_size * (TInt64)g_pAstDevice->unit_data.desc_p.unit_size; |
|
85 |
|
86 #if 0 |
|
87 Kern::Printf("========================================================") ; |
|
88 Kern::Printf("WBStorageInfo.type - %d", g_pAstDevice->dev_data.desc_p.type) ; |
|
89 Kern::Printf("WBStorageInfo.removable - %d", g_pAstDevice->dev_data.desc_p.removable) ; |
|
90 Kern::Printf("WBStorageInfo.writeable - %d", g_pAstDevice->dev_data.desc_p.writeable) ; |
|
91 Kern::Printf("WBStorageInfo.block_size - %d Bytes", g_pAstDevice->dev_data.desc_p.block_size) ; |
|
92 Kern::Printf("WBStorageInfo.number_units - %d", g_pAstDevice->dev_data.desc_p.number_units) ; |
|
93 Kern::Printf("WBStorageInfo.locked - %d", g_pAstDevice->dev_data.desc_p.locked) ; |
|
94 Kern::Printf("WBStorageInfo.erase_unit_size - %d Bytes", g_pAstDevice->dev_data.desc_p.erase_unit_size) ; |
|
95 Kern::Printf("WBStorageInfo.unit_size - %d", g_pAstDevice->unit_data.desc_p.unit_size) ; |
|
96 Kern::Printf("WBStorageInfo.start_block - %d", g_pAstDevice->unit_data.desc_p.start_block) ; |
|
97 Kern::Printf("WBStorageInfo.totalsize - %d Bytes", iMediaTotalSize) ; |
|
98 Kern::Printf("========================================================\n") ; |
|
99 #endif |
|
100 return 1; |
|
101 } |
|
102 EXPORT_C int CyAsSymbianStorageDriver::Close(void) |
|
103 { |
|
104 CyAsDeviceHandle h; |
|
105 CyAsReturnStatus_t ret ; |
|
106 |
|
107 //tag = g_pAstDevice->astHalTag ; |
|
108 h = g_pAstDevice->astDevHandle ; |
|
109 Kern::Printf("*** CyAsStorageStop...\n") ; |
|
110 ret = CyAsStorageStop(h, 0, 0) ; |
|
111 if (ret != CY_AS_ERROR_SUCCESS) |
|
112 { |
|
113 Kern::Printf("CyAsStorageStop: CyAsStorageStop returned error code %d\n", ret) ; |
|
114 return 0 ; |
|
115 } |
|
116 return 1; |
|
117 } |
|
118 |
|
119 EXPORT_C int CyAsSymbianStorageDriver::Read(int pos, int num_block, void* cybuf) |
|
120 { |
|
121 //CyAsHalDeviceTag tag; |
|
122 CyAsDeviceHandle h; |
|
123 CyAsReturnStatus_t ret ; |
|
124 char *tmpbuf; |
|
125 |
|
126 Kern::MutexWait(*WbApiMutex); |
|
127 |
|
128 tmpbuf = (char *)cybuf; |
|
129 //tag = g_pAstDevice->astHalTag ; |
|
130 h = g_pAstDevice->astDevHandle ; |
|
131 //CyAsHalPrintMessage("Read SD card\n"); |
|
132 ret = CyAsStorageRead( h, 1, 0, 0, pos, tmpbuf, num_block); |
|
133 if (ret != CY_AS_ERROR_SUCCESS) |
|
134 { |
|
135 Kern::Printf("CyAsSymbianStorageRead: Cannot read sector %d (%d@%d)\n", ret, num_block, pos) ; |
|
136 return 0 ; |
|
137 } |
|
138 Kern::MutexSignal(*WbApiMutex); |
|
139 |
|
140 return 1; |
|
141 } |
|
142 |
|
143 |
|
144 EXPORT_C int CyAsSymbianStorageDriver::Write(int pos, int num_block, void* cybuf) |
|
145 { |
|
146 //CyAsHalDeviceTag tag; |
|
147 CyAsDeviceHandle h; |
|
148 CyAsReturnStatus_t ret ; |
|
149 char *tmpbuf; |
|
150 |
|
151 Kern::MutexWait(*WbApiMutex); |
|
152 |
|
153 tmpbuf = (char *)cybuf; |
|
154 //tag = g_pAstDevice->astHalTag ; |
|
155 h = g_pAstDevice->astDevHandle ; |
|
156 |
|
157 ret = CyAsStorageWrite(h, 1, 0, 0, pos, tmpbuf, num_block); |
|
158 if ( ret != CY_AS_ERROR_SUCCESS ) |
|
159 { |
|
160 Kern::Printf("CyAsSymbianStorageWrite: Cannot write to first sector of SD card\n") ; |
|
161 return 0 ; |
|
162 } |
|
163 Kern::MutexSignal(*WbApiMutex); |
|
164 |
|
165 return 1; |
|
166 } |
|
167 |
|
168 EXPORT_C TInt CyAsSymbianStorageDriver::GetMediaType(void) |
|
169 { |
|
170 /* Type of device */ |
|
171 return (TInt)g_pAstDevice->dev_data.desc_p.type; |
|
172 } |
|
173 |
|
174 EXPORT_C TInt CyAsSymbianStorageDriver::GetIsRemovable(void) |
|
175 { |
|
176 /* Is the device removable */ |
|
177 return g_pAstDevice->dev_data.desc_p.removable; |
|
178 } |
|
179 |
|
180 EXPORT_C TInt CyAsSymbianStorageDriver::GetIsWriteable(void) |
|
181 { |
|
182 /* Is the device writeable */ |
|
183 return g_pAstDevice->dev_data.desc_p.writeable; |
|
184 } |
|
185 |
|
186 EXPORT_C TUint16 CyAsSymbianStorageDriver::GetBlockSize(void) |
|
187 { |
|
188 /* Basic block size for device */ |
|
189 return g_pAstDevice->dev_data.desc_p.block_size; |
|
190 } |
|
191 |
|
192 EXPORT_C TUint CyAsSymbianStorageDriver::GetNumberOfUnits(void) |
|
193 { |
|
194 /* Number of LUNs on the device */ |
|
195 return g_pAstDevice->dev_data.desc_p.number_units; |
|
196 } |
|
197 |
|
198 EXPORT_C TInt CyAsSymbianStorageDriver::GetIsLocked(void) |
|
199 { |
|
200 /* Is the device password locked */ |
|
201 return g_pAstDevice->dev_data.desc_p.locked; |
|
202 } |
|
203 |
|
204 EXPORT_C TUint CyAsSymbianStorageDriver::GetEraseBlockSize(void) |
|
205 { |
|
206 /* Size in bytes of an Erase Unit. Block erase operation is only supported for SD storage, |
|
207 and the erase_unit_size is invalid for all other kinds of storage. */ |
|
208 return g_pAstDevice->dev_data.desc_p.erase_unit_size; |
|
209 } |
|
210 |
|
211 EXPORT_C TUint CyAsSymbianStorageDriver::GetUnitSize(void) |
|
212 { |
|
213 /* Number of blocks in the LUN */ |
|
214 return g_pAstDevice->unit_data.desc_p.unit_size; |
|
215 } |
|
216 |
|
217 EXPORT_C TUint CyAsSymbianStorageDriver::GetStartBlock(void) |
|
218 { |
|
219 /* Physical start block for LUN */ |
|
220 return g_pAstDevice->unit_data.desc_p.start_block; |
|
221 } |
|
222 |
|
223 EXPORT_C TInt64 CyAsSymbianStorageDriver::GetMediaSize(void) |
|
224 { |
|
225 |
|
226 /*(Basic block size for device x Number of LUNs on the device) |
|
227 g_pAstDevice->dev_data.desc_p.block_size * g_pAstDevice->dev_data.desc_p.number_units */ |
|
228 return iMediaTotalSize; |
|
229 } |
|
230 |
|
231 |
|
232 |
|
233 |