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

📄 fileio.h

📁 SD卡驱动
💻 H
字号:
/******************************************************************************
 *
 *       PIC18 C18 Secure Digital and Multimedia Cards Interface
 *
 ******************************************************************************
 * FileName:        fileio.h
 * Dependencies:    generic.h
 *					_fat.def
 *					_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_DOT_H
#define  FILEIO_DOT_H

#include "generic.h"
#include "_fat.def"
#include "_FATDefs.h"
#include "stddef.h"

#define     NOFAT12SUPPORT

#define FALSE	0
#define TRUE	!FALSE

#define FAIL    -1

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

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

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;

#define FILE_NAME_SIZE	    11

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
} MYFILE;


/***************************************************************************
* Prototypes                                                               *
***************************************************************************/

unsigned char FAT16Init();

MYFILE * my_fopen(const char * fileName, const char *mode);
//cmpt = ok, but need to implement static and dynamic file pointers

//FILE * fopenpgm(const rom char * fileName, const rom char *mode);
//cmpt = ok, but need to implement static and dynamic file pointers

int my_fclose(MYFILE *fo);
//returns 0 on success. It returns EOF if any errors were detected.

int my_remove (const char * fileName);

//int removepgm (const rom char * fileName);

void my_rewind (MYFILE *fo);

size_t my_fread(void *ptr, size_t size, size_t n, MYFILE *stream);
//On success fread returns the number of items (not bytes) actually read.
//On end-of-file or error it returns a short count or 0

size_t my_fwrite(const void *ptr, size_t size, size_t n, MYFILE *stream);
//On successful completion fwrite returns the number of items (not bytes) actually written.
//On error it returns a short count or 0.

int my_fseek(MYFILE *stream, long offset, int whence);
// return 0 if success. returns -1 on error

long my_ftell(MYFILE *fo);
// returns the current file pointer position on success.
// It returns -1L on error.

int my_feof( MYFILE * stream );

#endif

⌨️ 快捷键说明

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