Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 363 | johboh | 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 | * This software is owned by Microchip Technology Inc. ("Microchip") |
||
| 16 | * and is supplied to you for use exclusively as described in the |
||
| 17 | * associated software agreement. This software is protected by |
||
| 18 | * software and other intellectual property laws. Any use in |
||
| 19 | * violation of the software license may subject the user to criminal |
||
| 20 | * sanctions as well as civil liability. Copyright 2006 Microchip |
||
| 21 | * Technology Inc. All rights reserved. |
||
| 22 | * |
||
| 23 | * This software is provided "AS IS." MICROCHIP DISCLAIMS ALL |
||
| 24 | * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED |
||
| 25 | * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND |
||
| 26 | * INFRINGEMENT. Microchip shall in no event be liable for special, |
||
| 27 | * incidental, or consequential damages. |
||
| 28 | * |
||
| 29 | * This file provides Microchip File System access calls. |
||
| 30 | * |
||
| 31 | * Author Date Comment |
||
| 32 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
| 33 | * Nilesh Rajbharti 8/14/01 Original (Rev. 1.0) |
||
| 34 | * Nilesh Rajbharti 2/9/02 Cleanup |
||
| 35 | * Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail) |
||
| 36 | * Howard Schlunder 5/31/06 Changed EEPROM addressing to 32 bits |
||
| 37 | ********************************************************************/ |
||
| 38 | |||
| 39 | #ifndef MPFS_H |
||
| 40 | #define MPFS_H |
||
| 41 | |||
| 42 | #include "..\Include\StackTsk.h" |
||
| 43 | |||
| 44 | #if defined(MPFS_USE_PGRM) |
||
| 45 | typedef ROM BYTE* MPFS; |
||
| 46 | #define MPFS_INVALID (MPFS)(0xffffff) |
||
| 47 | typedef WORD MPFS_OFFSET; |
||
| 48 | #else |
||
| 49 | // typedef DWORD MPFS; // For 32 bit addressing (use /ll option with MPFS.exe) |
||
| 50 | // #define MPFS_INVALID (0xffffffff)// For 32 bit addressing (use /ll option with MPFS.exe) |
||
| 51 | typedef WORD MPFS; // For default 16 bit addressing |
||
| 52 | #define MPFS_INVALID (0xffff) // For default 16 bit addressing |
||
| 53 | typedef WORD MPFS_OFFSET; |
||
| 54 | #endif |
||
| 55 | |||
| 56 | #define MPFS_NOT_AVAILABLE (0x0) |
||
| 57 | |||
| 58 | #if defined(MPFS_USE_EEPROM) |
||
| 59 | #define MPFS_WRITE_PAGE_SIZE (64) |
||
| 60 | #elif defined(MPFS_USE_PGRM) |
||
| 61 | #define MPFS_WRITE_PAGE_SIZE (8) |
||
| 62 | #endif |
||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | /********************************************************************* |
||
| 67 | * Function: BOOL MPFSInit(void) |
||
| 68 | * |
||
| 69 | * PreCondition: None |
||
| 70 | * |
||
| 71 | * Input: None |
||
| 72 | * |
||
| 73 | * Output: TRUE, if MPFS Storage access is initialized and |
||
| 74 | * MPFS is is ready to be used. |
||
| 75 | * FALSE otherwise |
||
| 76 | * |
||
| 77 | * Side Effects: None |
||
| 78 | * |
||
| 79 | * Overview: None |
||
| 80 | * |
||
| 81 | * Note: None |
||
| 82 | ********************************************************************/ |
||
| 83 | BOOL MPFSInit(void); |
||
| 84 | |||
| 85 | |||
| 86 | /********************************************************************* |
||
| 87 | * Function: MPFS MPFSOpen(BYTE* name) |
||
| 88 | * |
||
| 89 | * PreCondition: None |
||
| 90 | * |
||
| 91 | * Input: name - NULL terminate file name. |
||
| 92 | * |
||
| 93 | * Output: MPFS_INVALID if not found |
||
| 94 | * != MPFS_INVALID if found ok. |
||
| 95 | * |
||
| 96 | * Side Effects: None |
||
| 97 | * |
||
| 98 | * Overview: None |
||
| 99 | * |
||
| 100 | * Note: None |
||
| 101 | ********************************************************************/ |
||
| 102 | MPFS MPFSOpen(BYTE* name); |
||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | /********************************************************************* |
||
| 107 | * Function: void MPFSClose(void) |
||
| 108 | * |
||
| 109 | * PreCondition: None |
||
| 110 | * |
||
| 111 | * Input: handle - File handle to be closed |
||
| 112 | * |
||
| 113 | * Output: None |
||
| 114 | * |
||
| 115 | * Side Effects: None |
||
| 116 | * |
||
| 117 | * Overview: None |
||
| 118 | * |
||
| 119 | * Note: None |
||
| 120 | ********************************************************************/ |
||
| 121 | void MPFSClose(void); |
||
| 122 | |||
| 123 | |||
| 124 | /********************************************************************* |
||
| 125 | * Function: BOOL MPFSGetBegin(MPFS handle) |
||
| 126 | * |
||
| 127 | * PreCondition: MPFSOpen() != MPFS_INVALID && |
||
| 128 | * |
||
| 129 | * Input: handle - handle of file that is to be read |
||
| 130 | * |
||
| 131 | * Output: TRUE if successful |
||
| 132 | * !TRUE otherwise |
||
| 133 | * |
||
| 134 | * Side Effects: None |
||
| 135 | * |
||
| 136 | * Overview: Prepares MPFS storage media for subsequent reads. |
||
| 137 | * |
||
| 138 | * Note: None |
||
| 139 | ********************************************************************/ |
||
| 140 | #if defined(MPFS_USE_EEPROM) |
||
| 141 | BOOL MPFSGetBegin(MPFS handle); |
||
| 142 | #else |
||
| 143 | #define MPFSGetBegin(handle) (_currentHandle = handle) |
||
| 144 | #endif |
||
| 145 | |||
| 146 | |||
| 147 | /********************************************************************* |
||
| 148 | * Function: BYTE MPFSGet(void) |
||
| 149 | * |
||
| 150 | * PreCondition: MPFSOpen() != MPFS_INVALID && |
||
| 151 | * MPFSGetBegin() == TRUE |
||
| 152 | * |
||
| 153 | * Input: None |
||
| 154 | * |
||
| 155 | * Output: Data byte from current address. |
||
| 156 | * |
||
| 157 | * Side Effects: None |
||
| 158 | * |
||
| 159 | * Overview: Reads a byte from current address. |
||
| 160 | * |
||
| 161 | * Note: Caller must call MPFSIsEOF() to check for end of |
||
| 162 | * file condition |
||
| 163 | ********************************************************************/ |
||
| 164 | BYTE MPFSGet(void); |
||
| 165 | |||
| 166 | |||
| 167 | /********************************************************************* |
||
| 168 | * Function: MPFS MPFSGetEnd(void) |
||
| 169 | * |
||
| 170 | * PreCondition: MPFSOpen() != MPFS_INVALID && |
||
| 171 | * MPFSGetBegin() = TRUE |
||
| 172 | * |
||
| 173 | * Input: None |
||
| 174 | * |
||
| 175 | * Output: Current mpfs handle. |
||
| 176 | * |
||
| 177 | * Side Effects: None |
||
| 178 | * |
||
| 179 | * Overview: Ends on-going read cycle. |
||
| 180 | * MPFS handle that is returned must be used |
||
| 181 | * for subsequent begin gets.. |
||
| 182 | * |
||
| 183 | * Note: None |
||
| 184 | ********************************************************************/ |
||
| 185 | #if defined(MPFS_USE_EEPROM) |
||
| 186 | MPFS MPFSGetEnd(void); |
||
| 187 | #else |
||
| 188 | #define MPFSGetEnd() _currentHandle |
||
| 189 | #endif |
||
| 190 | |||
| 191 | |||
| 192 | /********************************************************************* |
||
| 193 | * Macro: BOOL MPFSIsEOF(void) |
||
| 194 | * |
||
| 195 | * PreCondition: MPFSGetBegin() must be called. |
||
| 196 | * |
||
| 197 | * Input: None |
||
| 198 | * |
||
| 199 | * Output: TRUE if current file read has reached end of file. |
||
| 200 | * FALSE if otherwise. |
||
| 201 | * |
||
| 202 | * Side Effects: None |
||
| 203 | * |
||
| 204 | * Overview: None |
||
| 205 | * |
||
| 206 | * Note: None |
||
| 207 | ********************************************************************/ |
||
| 208 | #define MPFSIsEOF() (_currentHandle == MPFS_INVALID) |
||
| 209 | |||
| 210 | |||
| 211 | /********************************************************************* |
||
| 212 | * Function: MPFS MPFSFormat(void) |
||
| 213 | * |
||
| 214 | * PreCondition: None |
||
| 215 | * |
||
| 216 | * Input: None |
||
| 217 | * |
||
| 218 | * Output: A valid MPFS handle that can be used for MPFSPut |
||
| 219 | * |
||
| 220 | * Side Effects: None |
||
| 221 | * |
||
| 222 | * Overview: Prepares MPFS image to get re-written |
||
| 223 | * Declares MPFS as in use. |
||
| 224 | * |
||
| 225 | * Note: MPFS will be unaccessible until MPFSClose is |
||
| 226 | * called. |
||
| 227 | ********************************************************************/ |
||
| 228 | MPFS MPFSFormat(void); |
||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 | /********************************************************************* |
||
| 233 | * Function: BOOL MPFSPutBegin(MPFS handle) |
||
| 234 | * |
||
| 235 | * PreCondition: MPFSInit() and MPFSFormat() are already called. |
||
| 236 | * |
||
| 237 | * Input: handle - handle to where put to begin |
||
| 238 | * |
||
| 239 | * Output: TRUE if successful |
||
| 240 | * !TRUE otherwise |
||
| 241 | * |
||
| 242 | * Side Effects: None |
||
| 243 | * |
||
| 244 | * Overview: Prepares MPFS image to get re-written |
||
| 245 | * |
||
| 246 | * Note: MPFS will be unaccessible until MPFSClose is |
||
| 247 | * called. |
||
| 248 | ********************************************************************/ |
||
| 249 | #if defined(MPFS_USE_EEPROM) |
||
| 250 | BOOL MPFSPutBegin(MPFS handle); |
||
| 251 | #else |
||
| 252 | #define MPFSPutBegin(handle) (_currentHandle = handle) |
||
| 253 | #endif |
||
| 254 | |||
| 255 | |||
| 256 | /********************************************************************* |
||
| 257 | * Function: BOOL MPFSPut(BYTE b) |
||
| 258 | * |
||
| 259 | * PreCondition: MPFSFormat() or MPFSCreate() must be called |
||
| 260 | * |
||
| 261 | * Input: b - byte to be written |
||
| 262 | * |
||
| 263 | * Output: TRUE if successful |
||
| 264 | * !TRUE if otherwise |
||
| 265 | * |
||
| 266 | * Side Effects: MPFS handle is updated. |
||
| 267 | * |
||
| 268 | * Overview: None |
||
| 269 | * |
||
| 270 | * Note: Since this function updates internal MPFS handle |
||
| 271 | * caller must call MPFSPutEnd() to obtain |
||
| 272 | * up-to-date handle. |
||
| 273 | ********************************************************************/ |
||
| 274 | BOOL MPFSPut(BYTE b); |
||
| 275 | |||
| 276 | |||
| 277 | /********************************************************************* |
||
| 278 | * Function: MPFS MPFSPutEnd(void) |
||
| 279 | * |
||
| 280 | * PreCondition: MPFSPutBegin() is already called. |
||
| 281 | * |
||
| 282 | * Input: None |
||
| 283 | * |
||
| 284 | * Output: Up-to-date MPFS handle |
||
| 285 | * |
||
| 286 | * Side Effects: Original MPFS handle is no longer valid. |
||
| 287 | * Updated MPFS handle must be obtained by calling |
||
| 288 | * MPFSPutEnd(). |
||
| 289 | * |
||
| 290 | * Overview: None |
||
| 291 | * |
||
| 292 | * Note: Actual write may not get started until internal |
||
| 293 | * write page is full. To ensure that previously |
||
| 294 | * data gets written, caller must call MPFSPutEnd() |
||
| 295 | * after last call to MPFSPut(). |
||
| 296 | ********************************************************************/ |
||
| 297 | MPFS MPFSPutEnd(void); |
||
| 298 | |||
| 299 | |||
| 300 | /********************************************************************* |
||
| 301 | * Macro: BYTE MPFSInUse(void) |
||
| 302 | * |
||
| 303 | * PreCondition: None |
||
| 304 | * |
||
| 305 | * Input: None |
||
| 306 | * |
||
| 307 | * Output: No. of file currently open. |
||
| 308 | * If == 0, MPFS is not in use. |
||
| 309 | * |
||
| 310 | * Side Effects: None |
||
| 311 | * |
||
| 312 | * Overview: None |
||
| 313 | * |
||
| 314 | * Note: None |
||
| 315 | ********************************************************************/ |
||
| 316 | #if !defined(THIS_IS_MPFS) |
||
| 317 | extern BYTE mpfsOpenCount; |
||
| 318 | #endif |
||
| 319 | |||
| 320 | /********************************************************************* |
||
| 321 | * Function: MPFS MPFSSeek(MPFS_OFFSET offset) |
||
| 322 | * |
||
| 323 | * PreCondition: MPFSGetBegin() is already called. |
||
| 324 | * |
||
| 325 | * Input: offset - Offset from current pointer |
||
| 326 | * |
||
| 327 | * Output: New MPFS handle located to given offset |
||
| 328 | * |
||
| 329 | * Side Effects: None. |
||
| 330 | * |
||
| 331 | * Overview: None |
||
| 332 | * |
||
| 333 | * Note: None. |
||
| 334 | ********************************************************************/ |
||
| 335 | MPFS MPFSSeek(MPFS_OFFSET offset); |
||
| 336 | |||
| 337 | |||
| 338 | /********************************************************************* |
||
| 339 | * Function: MPFS MPFSTell(void) |
||
| 340 | * |
||
| 341 | * PreCondition: MPFSOpen() is already called. |
||
| 342 | * |
||
| 343 | * Input: None |
||
| 344 | * |
||
| 345 | * Output: current MPFS file pointer |
||
| 346 | * |
||
| 347 | * Side Effects: None. |
||
| 348 | * |
||
| 349 | * Overview: None |
||
| 350 | * |
||
| 351 | * Note: None. |
||
| 352 | ********************************************************************/ |
||
| 353 | #define MPFSTell() (_currentHandle) |
||
| 354 | |||
| 355 | |||
| 356 | #define MPFSIsInUse() (mpfsOpenCount) |
||
| 357 | |||
| 358 | #if !defined(THIS_IS_MPFS) |
||
| 359 | extern MPFS _currentHandle; |
||
| 360 | extern BYTE _currentCount; |
||
| 361 | #endif |
||
| 362 | |||
| 363 | |||
| 364 | #endif |