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

📄 fileio.h

📁 PIC18F4550 SD CARD USB
💻 H
📖 第 1 页 / 共 2 页
字号:
        word BPB_BytsPerSec;     // BYTEs per sector
        byte  BPB_SecPerClus;     // sectors per allocation unit
        word BPB_RsvdSecCnt;     // number of reserved sectors after start
        byte  BPB_NumFATs;        // number of FATs
        word BPB_RootEntCnt;     // number of root directory entries
        word BPB_TotSec16;       // total number of sectors
        byte  BPB_Media;          // media descriptor
        word BPB_FATSz16;         // number of sectors per FAT
        word BPB_SecPerTrk;      // sectors per track
        word BPB_NumHeads;       // number of heads
        dword BPB_HiddSec;        // number of hidden sectors
        dword BPB_TotSec32;       // New 32bit total sec count
        dword BPB_FATSz32;        // Sectors occupied by one FAT
        word BPB_ExtFlags;       // Presently active FAT as defined by bits 0-3 if bit 7 is 1
        word BPB_FSVers;         // FAT32 filesystem version, should be 0:0
        dword BPB_RootClus;       // start cluster of the root directory (should be 2)
        word BPB_FSInfo;         // filesystem info structure sector
        word BPB_BkBootSec;      // backup boot sector normally 6
        byte  BPB_Reserved[12];   // Reserved memory
        byte  BS_DrvNum;          // Int 13 drive number
        byte  BS_Reserved1;       // Nothing
        byte  BS_BootSig;         // 0x29
        byte  BS_VolID[4];        // Volume Id
        byte  BS_VolLab[11];       // Volume Label
        byte  BS_FilSysType[8];   // File system type, not used for determination  
}_BPB_FAT32;

typedef _BPB_FAT32 * BPB_FAT32;

typedef struct __BS
{
    union
    {
        _BPB_FAT32  FAT_32;	
        _BPB_FAT16  FAT_16;	
        _BPB_FAT12  FAT_12;	
    }FAT;    
    byte  	Reserved[SDC_SECTOR_SIZE-sizeof(_BPB_FAT32)-2];
    byte      Signature0;     // 0x55
    byte      Signature1;     // 0xAA
}_BS;

typedef _BS * BS;


#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)

// DOS directory entry structure
typedef struct __DIRENTRY 
{
        char        DIR_Name[DIR_NAMESIZE];      // Name 
        char        DIR_Extension[DIR_EXTENSION]; // Extension
        byte          DIR_Attr;         // Attributes
        byte          DIR_NTRes;        // reserved by NT
        byte          DIR_CrtTimeTenth; // millisecond stamp
        word         DIR_CrtTime;      // time created
        word         DIR_CrtDate;      // date created
        word         DIR_LstAccDate;   // Last Access date
        word         DIR_FstClusHI;    // high word of this enty's first cluster number
        word         DIR_WrtTime;      // last update time
        word         DIR_WrtDate;      // last update date
        word         DIR_FstClusLO;    // low word of this entry's first cluster number
        dword         DIR_FileSize;     // file size in DWORD
}_DIRENTRY;

typedef _DIRENTRY * DIRENTRY;

// number of directory entries in one sector
#define DIRENTRIES_PER_SECTOR   0x10

typedef struct
{
    unsigned    write :1;           // set if the file was opened in a write mode 
	unsigned    FileWriteEOF :1;    // set if we are writing and have reached the EOF
}FileFlags;

typedef struct 
{
    DISK *      	dsk;            // disk structure
    word         	cluster;        // first cluster
    word         	ccls;           // current cluster in file
    word         	sec;            // sector in current cluster
    word         	pos;            // position in current sector
    dword         	seek;           // position in the file
    dword         	size;           // file size
    FileFlags   	Flags;
    word     		time;           // last update time
    word     		date;           // last update date
    char     		name[FILE_NAME_SIZE];       // Needed to make it WORD wide for external mem
    word     		entry;          // entry position in cur directory
    word     		chk;            // FILE structure checksum = ~( entry + name[0])
    word     		attributes;     // the bare bones attributes
    word     		dirclus;        // base cluster of directory
    word     		dirccls;        // current cluster
} FILE;

// since we use an address generator, FILE is not actually the cast of what we pass
typedef FILE        * FILEOBJ;
   
#define FILEEXTPAGESIZE         sizeof(_FILEEXTND)

#define SIZEOF(s,m)             ((size_t) sizeof(((s *)0)->m)) 

#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

///////////////////////////////////////////////////////////////////////////
//////////////////////Formatting stuff/////////////////////////////////////
///////////////////////////////////////////////////////////////////////////   
#define defNUMOFFATS        2
#define defNUMOFROOTDIRS    512
#define defMEDIADESCRIPTOR  0xF8
#define defSECPERTRACK      0x3F
#define defNUMHEADS         0xFF
#define defBOOTSIG          0x29
#define defDRIVENUM         0x0
#define defRESERVEDSECS     0x01

// From MS FAT HW White paper 
typedef struct DSKSZTOSECPERCLUS_
{   
    dword DiskSize;
    byte  SecPerClusVal;
}DSKSZTOSECPERCLUS;
    
typedef union _CARDSTATUS
{
    struct
    {
        byte  CS_Inserted:1;  // Card is inserted and initialized
        byte  CS_Reset:1;     // Card has just been reset
        byte  CS_SDMMC:1;     // Card is of the SDMMC type
        byte  CS_WP:1;        // Card is write Protected
        byte  CS_Failure:1;   // There was a failure initializing the card
    };
    word _word;   
}CARDSTATUS;
    
#ifndef EOF
#define EOF         (-1)
#endif

#define APPEND 'a'
#define WRITE 'w'
#define READ 'r'

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2


// prototypes

CETYPE CreateFileEntry(FILEOBJ fo, word *fHandle);
byte FILEfind( FILEOBJ foDest, FILEOBJ foCompareTo, byte cmd);
byte FILEget_next_cluster(FILEOBJ fo, word n);
byte FILEallocate_new_cluster( FILEOBJ fo);
byte FILEopen (FILEOBJ fo, word *fHandle, char type);
byte FILEerase( FILEOBJ fo, word *fHandle, byte EraseClusters);

extern FILE * fopen(char * fileName, DISK * disk, word mode);
extern CETYPE fclose(FILEOBJ fo);
extern CETYPE remove (char * fileName, DISK * disk);
extern void rewind (FILEOBJ fo);
extern byte fread( FILEOBJ fo, void * dest, word count);
extern byte fwrite( FILEOBJ fo, void * src, word count);
extern CETYPE fseek(FILEOBJ fo, dword offset, byte whence);
extern dword ftell(FILEOBJ fo);
extern byte StartupCard(DISK *dsk, CARDSTATUS *CardStatus);
extern void StopCard(DISK *dsk, CARDSTATUS *cs);

#endif

⌨️ 快捷键说明

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