1 |
/*********************************************************************
|
2 |
*
|
3 |
* Microchip File System
|
4 |
*
|
5 |
*********************************************************************
|
6 |
* FileName: MPFS.h
|
7 |
* Dependencies: StackTsk.H
|
8 |
* Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
|
9 |
* Complier: Microchip C18 v3.02 or higher
|
10 |
* Microchip C30 v2.01 or higher
|
11 |
* Company: Microchip Technology, Inc.
|
12 |
*
|
13 |
* Software License Agreement
|
14 |
*
|
15 |
* Copyright © 2002-2007 Microchip Technology Inc. All rights
|
16 |
* reserved.
|
17 |
*
|
18 |
* Microchip licenses to you the right to use, modify, copy, and
|
19 |
* distribute:
|
20 |
* (i) the Software when embedded on a Microchip microcontroller or
|
21 |
* digital signal controller product (“Device”) which is
|
22 |
* integrated into Licensee’s product; or
|
23 |
* (ii) ONLY the Software driver source files ENC28J60.c and
|
24 |
* ENC28J60.h ported to a non-Microchip device used in
|
25 |
* conjunction with a Microchip ethernet controller for the
|
26 |
* sole purpose of interfacing with the ethernet controller.
|
27 |
*
|
28 |
* You should refer to the license agreement accompanying this
|
29 |
* Software for additional information regarding your rights and
|
30 |
* obligations.
|
31 |
*
|
32 |
* THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT
|
33 |
* WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
|
34 |
* LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
|
35 |
* PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
36 |
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
|
37 |
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
|
38 |
* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
|
39 |
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
|
40 |
* THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
|
41 |
* SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
|
42 |
* (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
|
43 |
*
|
44 |
*
|
45 |
* Author Date Comment
|
46 |
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
47 |
* Nilesh Rajbharti 8/14/01 Original (Rev. 1.0)
|
48 |
* Nilesh Rajbharti 2/9/02 Cleanup
|
49 |
* Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail)
|
50 |
* Howard Schlunder 5/31/06 Changed EEPROM addressing to 32 bits
|
51 |
********************************************************************/
|
52 |
#ifndef __MPFS_H
|
53 |
#define __MPFS_H
|
54 |
|
55 |
#if defined(MPFS_USE_EEPROM)
|
56 |
typedef DWORD MPFS; // For default 32 bit addressing (use /ll option with MPFS.exe)
|
57 |
#define MPFS_INVALID (0xffffffffu) // For default 32 bit addressing (use /ll option with MPFS.exe)
|
58 |
// typedef WORD MPFS; // For old short 16 bit addressing (use /b option with MPFS.exe)
|
59 |
// #define MPFS_INVALID (0xffff) // For old short 16 bit addressing (use /b option with MPFS.exe)
|
60 |
#else
|
61 |
#if defined(__C30__)
|
62 |
typedef DWORD MPFS;
|
63 |
#define MPFS_INVALID (MPFS)(0xffffffffu)
|
64 |
#else
|
65 |
typedef ROM BYTE* MPFS;
|
66 |
#define MPFS_INVALID (MPFS)(0xffffffu)
|
67 |
#endif
|
68 |
#endif
|
69 |
|
70 |
#define MPFS_NOT_AVAILABLE (0x0u)
|
71 |
|
72 |
#if defined(MPFS_USE_EEPROM)
|
73 |
#define MPFS_WRITE_PAGE_SIZE (64u)
|
74 |
#endif
|
75 |
|
76 |
|
77 |
|
78 |
/*********************************************************************
|
79 |
* Function: BOOL MPFSInit(void)
|
80 |
*
|
81 |
* PreCondition: None
|
82 |
*
|
83 |
* Input: None
|
84 |
*
|
85 |
* Output: TRUE, if MPFS Storage access is initialized and
|
86 |
* MPFS is is ready to be used.
|
87 |
* FALSE otherwise
|
88 |
*
|
89 |
* Side Effects: None
|
90 |
*
|
91 |
* Overview: None
|
92 |
*
|
93 |
* Note: None
|
94 |
********************************************************************/
|
95 |
BOOL MPFSInit(void);
|
96 |
|
97 |
|
98 |
/*********************************************************************
|
99 |
* Function: MPFS MPFSOpen(BYTE* name)
|
100 |
*
|
101 |
* PreCondition: None
|
102 |
*
|
103 |
* Input: name - NULL terminate file name.
|
104 |
*
|
105 |
* Output: MPFS_INVALID if not found
|
106 |
* != MPFS_INVALID if found ok.
|
107 |
*
|
108 |
* Side Effects: None
|
109 |
*
|
110 |
* Overview: None
|
111 |
*
|
112 |
* Note: None
|
113 |
********************************************************************/
|
114 |
MPFS MPFSOpen(BYTE* name);
|
115 |
|
116 |
|
117 |
|
118 |
/*********************************************************************
|
119 |
* Function: void MPFSClose(void)
|
120 |
*
|
121 |
* PreCondition: None
|
122 |
*
|
123 |
* Input: handle - File handle to be closed
|
124 |
*
|
125 |
* Output: None
|
126 |
*
|
127 |
* Side Effects: None
|
128 |
*
|
129 |
* Overview: None
|
130 |
*
|
131 |
* Note: None
|
132 |
********************************************************************/
|
133 |
void MPFSClose(void);
|
134 |
|
135 |
|
136 |
/*********************************************************************
|
137 |
* Function: BOOL MPFSGetBegin(MPFS handle)
|
138 |
*
|
139 |
* PreCondition: MPFSOpen() != MPFS_INVALID &&
|
140 |
*
|
141 |
* Input: handle - handle of file that is to be read
|
142 |
*
|
143 |
* Output: TRUE if successful
|
144 |
* !TRUE otherwise
|
145 |
*
|
146 |
* Side Effects: None
|
147 |
*
|
148 |
* Overview: Prepares MPFS storage media for subsequent reads.
|
149 |
*
|
150 |
* Note: None
|
151 |
********************************************************************/
|
152 |
#if defined(MPFS_USE_EEPROM)
|
153 |
BOOL MPFSGetBegin(MPFS handle);
|
154 |
#else
|
155 |
#define MPFSGetBegin(handle) (_currentHandle = handle)
|
156 |
#endif
|
157 |
|
158 |
|
159 |
/*********************************************************************
|
160 |
* Function: BYTE MPFSGet(void)
|
161 |
*
|
162 |
* PreCondition: MPFSOpen() != MPFS_INVALID &&
|
163 |
* MPFSGetBegin() == TRUE
|
164 |
*
|
165 |
* Input: None
|
166 |
*
|
167 |
* Output: Data byte from current address.
|
168 |
*
|
169 |
* Side Effects: None
|
170 |
*
|
171 |
* Overview: Reads a byte from current address.
|
172 |
*
|
173 |
* Note: Caller must call MPFSIsEOF() to check for end of
|
174 |
* file condition
|
175 |
********************************************************************/
|
176 |
BYTE MPFSGet(void);
|
177 |
|
178 |
|
179 |
/*********************************************************************
|
180 |
* Function: MPFS MPFSGetEnd(void)
|
181 |
*
|
182 |
* PreCondition: MPFSOpen() != MPFS_INVALID &&
|
183 |
* MPFSGetBegin() = TRUE
|
184 |
*
|
185 |
* Input: None
|
186 |
*
|
187 |
* Output: Current mpfs handle.
|
188 |
*
|
189 |
* Side Effects: None
|
190 |
*
|
191 |
* Overview: Ends on-going read cycle.
|
192 |
* MPFS handle that is returned must be used
|
193 |
* for subsequent begin gets..
|
194 |
*
|
195 |
* Note: None
|
196 |
********************************************************************/
|
197 |
#if defined(MPFS_USE_EEPROM)
|
198 |
MPFS MPFSGetEnd(void);
|
199 |
#else
|
200 |
#define MPFSGetEnd() _currentHandle
|
201 |
#endif
|
202 |
|
203 |
|
204 |
/*********************************************************************
|
205 |
* Macro: BOOL MPFSIsEOF(void)
|
206 |
*
|
207 |
* PreCondition: MPFSGetBegin() must be called.
|
208 |
*
|
209 |
* Input: None
|
210 |
*
|
211 |
* Output: TRUE if current file read has reached end of file.
|
212 |
* FALSE if otherwise.
|
213 |
*
|
214 |
* Side Effects: None
|
215 |
*
|
216 |
* Overview: None
|
217 |
*
|
218 |
* Note: None
|
219 |
********************************************************************/
|
220 |
#define MPFSIsEOF() (_currentHandle == MPFS_INVALID)
|
221 |
|
222 |
|
223 |
/*********************************************************************
|
224 |
* Function: MPFS MPFSFormat(void)
|
225 |
*
|
226 |
* PreCondition: None
|
227 |
*
|
228 |
* Input: None
|
229 |
*
|
230 |
* Output: A valid MPFS handle that can be used for MPFSPut
|
231 |
*
|
232 |
* Side Effects: None
|
233 |
*
|
234 |
* Overview: Prepares MPFS image to get re-written
|
235 |
* Declares MPFS as in use.
|
236 |
*
|
237 |
* Note: MPFS will be unaccessible until MPFSClose is
|
238 |
* called.
|
239 |
********************************************************************/
|
240 |
MPFS MPFSFormat(void);
|
241 |
|
242 |
|
243 |
|
244 |
/*********************************************************************
|
245 |
* Function: BOOL MPFSPutBegin(MPFS handle)
|
246 |
*
|
247 |
* PreCondition: MPFSInit() and MPFSFormat() are already called.
|
248 |
*
|
249 |
* Input: handle - handle to where put to begin
|
250 |
*
|
251 |
* Output: TRUE if successful
|
252 |
* !TRUE otherwise
|
253 |
*
|
254 |
* Side Effects: None
|
255 |
*
|
256 |
* Overview: Prepares MPFS image to get re-written
|
257 |
*
|
258 |
* Note: MPFS will be unaccessible until MPFSClose is
|
259 |
* called.
|
260 |
********************************************************************/
|
261 |
#if defined(MPFS_USE_EEPROM)
|
262 |
BOOL MPFSPutBegin(MPFS handle);
|
263 |
#else
|
264 |
#define MPFSPutBegin(handle) (_currentHandle = handle)
|
265 |
#endif
|
266 |
|
267 |
|
268 |
/*********************************************************************
|
269 |
* Function: BOOL MPFSPut(BYTE b)
|
270 |
*
|
271 |
* PreCondition: MPFSFormat() or MPFSCreate() must be called
|
272 |
*
|
273 |
* Input: b - byte to be written
|
274 |
*
|
275 |
* Output: TRUE if successful
|
276 |
* !TRUE if otherwise
|
277 |
*
|
278 |
* Side Effects: MPFS handle is updated.
|
279 |
*
|
280 |
* Overview: None
|
281 |
*
|
282 |
* Note: Since this function updates internal MPFS handle
|
283 |
* caller must call MPFSPutEnd() to obtain
|
284 |
* up-to-date handle.
|
285 |
********************************************************************/
|
286 |
BOOL MPFSPut(BYTE b);
|
287 |
|
288 |
|
289 |
/*********************************************************************
|
290 |
* Function: MPFS MPFSPutEnd(void)
|
291 |
*
|
292 |
* PreCondition: MPFSPutBegin() is already called.
|
293 |
*
|
294 |
* Input: None
|
295 |
*
|
296 |
* Output: Up-to-date MPFS handle
|
297 |
*
|
298 |
* Side Effects: Original MPFS handle is no longer valid.
|
299 |
* Updated MPFS handle must be obtained by calling
|
300 |
* MPFSPutEnd().
|
301 |
*
|
302 |
* Overview: None
|
303 |
*
|
304 |
* Note: Actual write may not get started until internal
|
305 |
* write page is full. To ensure that previously
|
306 |
* data gets written, caller must call MPFSPutEnd()
|
307 |
* after last call to MPFSPut().
|
308 |
********************************************************************/
|
309 |
MPFS MPFSPutEnd(void);
|
310 |
|
311 |
|
312 |
/*********************************************************************
|
313 |
* Macro: BYTE MPFSInUse(void)
|
314 |
*
|
315 |
* PreCondition: None
|
316 |
*
|
317 |
* Input: None
|
318 |
*
|
319 |
* Output: No. of file currently open.
|
320 |
* If == 0, MPFS is not in use.
|
321 |
*
|
322 |
* Side Effects: None
|
323 |
*
|
324 |
* Overview: None
|
325 |
*
|
326 |
* Note: None
|
327 |
********************************************************************/
|
328 |
#if !defined(__MPFS_C)
|
329 |
extern BYTE mpfsOpenCount;
|
330 |
#endif
|
331 |
|
332 |
/*********************************************************************
|
333 |
* Function: MPFS MPFSSeek(MPFS offset)
|
334 |
*
|
335 |
* PreCondition: MPFSGetBegin() is already called.
|
336 |
*
|
337 |
* Input: offset - Offset from current pointer
|
338 |
*
|
339 |
* Output: New MPFS handle located to given offset
|
340 |
*
|
341 |
* Side Effects: None.
|
342 |
*
|
343 |
* Overview: None
|
344 |
*
|
345 |
* Note: None.
|
346 |
********************************************************************/
|
347 |
MPFS MPFSSeek(MPFS offset);
|
348 |
|
349 |
|
350 |
/*********************************************************************
|
351 |
* Function: MPFS MPFSTell(void)
|
352 |
*
|
353 |
* PreCondition: MPFSOpen() is already called.
|
354 |
*
|
355 |
* Input: None
|
356 |
*
|
357 |
* Output: current MPFS file pointer
|
358 |
*
|
359 |
* Side Effects: None.
|
360 |
*
|
361 |
* Overview: None
|
362 |
*
|
363 |
* Note: None.
|
364 |
********************************************************************/
|
365 |
#define MPFSTell() (_currentHandle)
|
366 |
|
367 |
|
368 |
#define MPFSIsInUse() (mpfsOpenCount)
|
369 |
|
370 |
#if !defined(__MPFS_C)
|
371 |
extern MPFS _currentHandle;
|
372 |
extern BYTE _currentCount;
|
373 |
#endif
|
374 |
|
375 |
|
376 |
#endif
|