?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /*********************************************************************
2 *
3 * File system access interface layer Source File
4 *
5 *********************************************************************
6 * FileName: FileSystem.c
7 * Description: File system access interface layer
8 * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32
9 * Compiler: Microchip C32 v1.00 or higher
10 * Microchip C30 v3.01 or higher
11 * Microchip C18 v3.20 or higher
12 * HI-TECH PICC-18 STD 9.50PL3 or higher
13 * Company: Microchip Technology, Inc.
14 *
15 * Software License Agreement
16 *
17 * Copyright (C) 2008 Microchip Technology Inc. All rights
18 * reserved.
19 *
20 * Microchip licenses to you the right to use, modify, copy, and
21 * distribute:
22 * (i) the Software when embedded on a Microchip microcontroller or
23 * digital signal controller product ("Device") which is
24 * integrated into Licensee's product; or
25 * (ii) ONLY the Software driver source files ENC28J60.c and
26 * ENC28J60.h ported to a non-Microchip device used in
27 * conjunction with a Microchip ethernet controller for the
28 * sole purpose of interfacing with the ethernet controller.
29 *
30 * You should refer to the license agreement accompanying this
31 * Software for additional information regarding your rights and
32 * obligations.
33 *
34 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
35 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
36 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
37 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
39 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
40 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
41 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
42 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
43 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
44 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
45 *
46 * Author Date Comment
47 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48 * Aseem Swalah 7/31/08 Original
49 * Amit Shirbhate 7/18/09 Modified
50 ********************************************************************/
51 #include "TCPIP Stack/TCPIP.h"
52  
53 int FileSystemInit(void)
54 {
55 #if defined STACK_USE_MPFS2
56 MPFSInit();
57 #elif defined STACK_USE_MDD
58 return FSInit();
59 #endif
60  
61 return TRUE;
62 }
63  
64  
65 FILE_HANDLE FileOpen(const char * fileName, const char *mode)
66 {
67 #if defined STACK_USE_MPFS2
68 return MPFSOpen((BYTE*)fileName);
69 #elif defined STACK_USE_MDD
70 return FSfopen(fileName, mode);
71 #endif
72 }
73  
74 FILE_HANDLE FileOpenROM(const char * fileName, const char *mode)
75 {
76 #if defined STACK_USE_MPFS2
77 return MPFSOpenROM((BYTE*)fileName);
78 #elif defined STACK_USE_MDD
79 return FSfopen(fileName, mode);
80 #endif
81 }
82  
83 int FileClose(FILE_HANDLE fh)
84 {
85 #if defined STACK_USE_MPFS2
86 MPFSClose(fh);
87 #elif defined STACK_USE_MDD
88 return FSfclose(fh);
89 #endif
90  
91 return 0;
92 }
93  
94 size_t FileRead(void *ptr, size_t size, size_t n, FILE_HANDLE stream)
95 {
96 #if defined STACK_USE_MPFS2
97 WORD length;
98 length = size * n;
99 return MPFSGetArray(stream, (BYTE*)ptr, length);
100 #elif defined STACK_USE_MDD
101 if(ptr == NULL)
102 {
103 return 0;
104 }
105 else
106 {
107 return FSfread(ptr, size, n, stream);
108 }
109 #endif
110 }
111  
112 int FileSeek(FILE_HANDLE stream, long offset, int whence)
113 {
114 #if defined STACK_USE_MPFS2
115 BOOL status;
116 status = MPFSSeek(stream, offset, whence);
117 if(status == TRUE)
118 return 0;
119 else
120 return -1;
121  
122 #elif defined STACK_USE_MDD
123 return FSfseek(stream, offset, whence);
124 #endif
125 }
126  
127 long FileTell(FILE_HANDLE fh)
128 {
129 #if defined STACK_USE_MPFS2
130 return MPFSGetPosition(fh);
131 #elif defined STACK_USE_MDD
132 return FSftell(fh);
133 #endif
134 }
135  
136 int FileEOF(FILE_HANDLE stream)
137 {
138 #if defined STACK_USE_MPFS2
139 return MPFSGetBytesRem(stream);
140 #elif defined STACK_USE_MDD
141 return FSfeof(stream);
142 #endif
143 }
144  
145 int FileFormat(char mode, long int serialNumber, char *volumeID)
146 {
147 #if defined STACK_USE_MPFS2
148 int status;
149 status = MPFSFormat();
150 if(status == MPFS_INVALID_HANDLE)
151 return -1;
152 else
153 return 0;
154 #elif defined STACK_USE_MDD
155 return FSformat(mode, serialNumber, volumeID);
156 #endif
157 }
158  
159 size_t FileWrite(const void *ptr, size_t size, size_t n, FILE_HANDLE stream)
160 {
161 #if defined STACK_USE_MPFS2
162 WORD length;
163 length = size * n;
164 return MPFSPutArray(stream, (BYTE*)ptr, length);
165 #elif defined STACK_USE_MDD
166 return FSfwrite(ptr, size, n, stream);
167 #endif
168 }
169  
170  
171 size_t FileReadUInt32(DWORD *ptr, FILE_HANDLE stream)
172 {
173 BYTE databuff[4];
174 *ptr=0x00000000;
175  
176 #if defined STACK_USE_MPFS2
177 WORD retVal;
178  
179 retVal=MPFSGetArray(stream, (BYTE*)ptr, 4);
180  
181 if(retVal == 4)//Number of Uints of 4 bytes each Read
182 {
183  
184 ((BYTE*)ptr)[3] = databuff[3];
185 ((BYTE*)ptr)[2] = databuff[2];
186 ((BYTE*)ptr)[1] = databuff[1];
187 ((BYTE*)ptr)[0] = databuff[0];
188  
189 return 4;//Number of bytes read
190 }
191 else
192 return 0;
193  
194 #elif defined STACK_USE_MDD
195 size_t retVal;
196  
197 retVal= FSfread(databuff, 4, 1, stream);
198  
199 if(retVal == 1)//Number of Uints of 4 bytes each Read
200 {
201  
202 ((BYTE*)ptr)[3] = databuff[3];
203 ((BYTE*)ptr)[2] = databuff[2];
204 ((BYTE*)ptr)[1] = databuff[1];
205 ((BYTE*)ptr)[0] = databuff[0];
206  
207 return 4;//Number of bytes read
208 }
209 else
210 return 0;
211  
212 #endif
213 }
214  
215 size_t FileReadUInt16(WORD *ptr, FILE_HANDLE stream)
216 {
217 BYTE databuff[2];
218 *ptr=0x0000;
219  
220 #if defined STACK_USE_MPFS2
221 WORD retVal;
222  
223 retVal=MPFSGetArray(stream, (BYTE*)ptr, 2);
224  
225 if(retVal == 2)//Number of bytes read
226 {
227 ((BYTE*)ptr)[1]= databuff[1];
228 ((BYTE*)ptr)[0]= databuff[0];
229 return 2;//Number of bytes read
230 }
231 else
232 return 0;
233  
234 #elif defined STACK_USE_MDD
235 size_t retVal;
236  
237 retVal= FSfread(databuff, 2, 1, stream);
238  
239 if(retVal == 1)//Number of Uints of 4 bytes each Read
240 {
241 ((BYTE*)ptr)[1]= databuff[1];
242 ((BYTE*)ptr)[0]= databuff[0];
243 return 2;//Number of bytes read
244 }
245 else
246 return 0;
247  
248 #endif
249 }
250  
251  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3