⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _fatdefs.h

📁 SD卡驱动
💻 H
字号:
/******************************************************************************
 *
 *       PIC18 C18 Secure Digital and Multimedia Cards Interface
 *
 ******************************************************************************
 * FileName:        _FATDefs.h
 * Dependencies:    generic.h
 *					_FATDefs.h
 *					stddef.h
 * Processor:       PIC18
 * Compiler:        C18
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the 揅ompany? for its PICmicro?Microcontroller is intended and
 * supplied to you, the Company抯 customer, for use solely and
 * exclusively on Microchip PICmicro Microcontroller products. The
 * software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN 揂S IS?CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
*****************************************************************************/

#ifndef  _FILEIO__H
#define  _FILEIO__H

#include "generic.h"

// FILEIO ERROR CODES
typedef enum _CETYPE
{
	CE_GOOD = 0,					 // Everything is fine
	CE_ERASE_FAIL,					 // Internal Card erase failed
	CE_NOT_PRESENT,					 // CARD not present
	CE_NOT_FORMATTED,				 // The disk is of an unsupported format
	CE_BAD_PARTITION,				 // The boot record is bad
	CE_INIT_ERROR,					 // Initialization error has occured
	CE_NOT_INIT,					 // Card is not yet initialized because of some error
	CE_BAD_SECTOR_READ,				 // A bad read occured of a sector
	CE_WRITE_ERROR,					 // Could not write to the sector
	CE_INVALID_CLUSTER,				 // invalid cluster value > maxcls

	CE_FILE_NOT_FOUND,				 // Could not find the file on the card
	CE_DIR_NOT_FOUND,				 // Could not find the directory
	CE_BAD_FILE,					 // file is corrupted
	CE_DONE,						 // No more files in this directory
	CE_FILENAME_2_LONG,				 // The purposed file name is too long to use. Shorten the name and then resend.
	CE_FILENAME_EXISTS,				 // This filename already exists
	CE_NO_MORE_TAILS,				 // Long file name could not be created
	CE_DIR_FULL,					 // all root dir entry are taken
	CE_DISK_FULL,					 // all clusters in partition are taken
	CE_DIR_NOT_EMPTY,				 // This directory is not empty yet, remove files b4 deleting

	CE_NONSUPPORTED_SIZE,			 // The disk is too big to format as FAT16
	CE_TEMP_MOUNT_FAILED,			 // A temporary mount failed (format)
	CE_WRITE_PROTECTED,				 // Card is write protected
	CE_UNLOCK_FAILED,				 // Card unlock failed
	CE_INVALIDCSUM,					 // Invalid checksum
	CE_ENVLOADFAIL,					 // The environment failed to load
	CE_TMPMEMFULL,					 // No more external RAM
	CE_FILENOTOPENED,				 // File not openned for the write
	CE_BADCACHEREAD,				 // Bad cache read
	CE_CARDFAT32,					 // FAT 32 - card not supported

	CE_IMAGENOTAVAIL,				 // The PC has tried to tell me to use a SQTP file without a part selected
	CE_READONLY,					 // The File is readonly
	CE_CARDFAT12,					 // FAT12 during intial testing we are not supporting FAT12
	CE_WRITEONLY					 // The File is open in write only mode - a read was attempted
} CETYPE;

#define FOUND       0       // directory entry match
#define ERASED      0       // An erase occured correctly
#define NOT_FOUND   1       // directory entry not found
#define NO_MORE     2       // no more files found
#define WRITE_ERROR 3       // a write error occured

#define FAIL	-1

#define FAT12       1       // internal flags for FAT type 12 and 16
#define FAT16       2
#define FAT32       3

#define ATTR_READ_ONLY      0x01         
#define ATTR_HIDDEN         0x02           
#define ATTR_SYSTEM         0x04           
#define ATTR_VOLUME         0x08            
#define ATTR_LONG_NAME      0x0f                          
#define ATTR_EXTEND         0x0f 
#define ATTR_DIRECTORY      0x10            
#define ATTR_ARCHIVE        0x20       
#define ATTR_MASK			0x3f     


#define FILT_READ_ONLY      0x01         
#define FILT_HIDDEN         0x02           
#define FILT_SYSTEM         0x04           
#define FILT_VOLUME         0x08        
#define FILT_EXTND          (FILT_VOLUME|FILT_SYSTEM|FILT_HIDDEN|FILT_READ_ONLY)
#define FILT_DIRECTORY      0x10                
#define FILT_NORMAL_FILE    0x20   
#define FILT_MASK           (0x3F)       

#define CLUSTER_EMPTY       0x0000
#define LAST_CLUSTER_FAT12  0xff8
#define LAST_CLUSTER_FAT16  0xfff8
#define LAST_CLUSTER        0xfff8
#define END_CLUSTER         0xFFFE
#define CLUSTER_FAIL        0xFFFF
#define WIN_LAST_CLUS       0xFFFF
        
#define FAT_ENTRY0          0xFFF8
#define FAT_ENTRY1          0x7FFF

#define DIR_DEL             0xE5    // marker of a deleted entry
#define DIR_EMPTY           0       // marker of last entry in directory

#define DIR_NAMESIZE        8
#define DIR_EXTENSION       3
#define DIR_NAMECOMP        (DIR_NAMESIZE+DIR_EXTENSION)

#ifndef EOF
	#define EOF         		(-1)
#endif

typedef struct 
{ 
    BYTE*   	buffer;         // address of sector buffer in ext RAM
    DWORD     	firsts;         // lba of first sector in (first) partition
    DWORD     	fat;            // lba of FAT
    DWORD     	root;           // lba of root directory
    DWORD     	data;           // lba of the data area 
    WORD     	maxroot;        // max number of entries in root dir
    DWORD     	maxcls;         // max number of clusters in partition
    WORD     	fatsize;        // number of sectors
    BYTE      	fatcopy;        // number of copies
    BYTE      	SecPerClus;     // number of sectors per cluster
    BYTE      	type;           // type of FAT (FAT12, FAT16...)
    BYTE      	mount;          // flag (TRUE= mounted, FALSE= invalid)    
} DISK;

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -