Subversion Repositories Projects

Rev

Rev 317 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 317 Rev 333
1
#ifndef _FAT16_H
1
#ifndef _FAT16_H
2
#define _FAT16_H
2
#define _FAT16_H
3
 
3
 
4
 
4
 
5
//________________________________________________________________________________________________________________________________________
5
//________________________________________________________________________________________________________________________________________
6
//
6
//
7
// Definitions
7
// Definitions
8
//
8
//
9
//________________________________________________________________________________________________________________________________________
9
//________________________________________________________________________________________________________________________________________
10
 
10
 
11
//#define               __USE_TIME_DATE_ATTRIBUTE
11
//#define               __USE_TIME_DATE_ATTRIBUTE
12
#define FILE_MAX_OPEN   3                               // The number of files that can accessed simultaneously.
12
#define FILE_MAX_OPEN   3                               // The number of files that can accessed simultaneously.
13
#define SEEK_SET        0
13
#define SEEK_SET        0
14
#define SEEK_CUR        1
14
#define SEEK_CUR        1
15
#define SEEK_END        2
15
#define SEEK_END        2
16
#define EOF     (-1)
16
#define EOF     (-1)
17
#define BYTES_PER_SECTOR        512
17
#define BYTES_PER_SECTOR        512
18
/*
18
/*
19
________________________________________________________________________________________________________________________________________
19
________________________________________________________________________________________________________________________________________
20
 
20
 
21
        Structure of a filepointer
21
        Structure of a filepointer
22
________________________________________________________________________________________________________________________________________
22
________________________________________________________________________________________________________________________________________
23
*/
23
*/
24
typedef struct
24
typedef struct
25
{
25
{
26
        uint32_t        FirstSectorOfFirstCluster;      // First sector of the first cluster of the file.
26
        uint32_t        FirstSectorOfFirstCluster;      // First sector of the first cluster of the file.
27
        uint32_t        FirstSectorOfCurrCluster;       // First sector of the cluster which is edited at the moment.
27
        uint32_t        FirstSectorOfCurrCluster;       // First sector of the cluster which is edited at the moment.
28
        uint8_t         SectorOfCurrCluster;            // The sector within the current cluster.
28
        uint8_t         SectorOfCurrCluster;            // The sector within the current cluster.
29
        uint16_t        ByteOfCurrSector;                       // The byte location within the current sector.
29
        uint16_t        ByteOfCurrSector;                       // The byte location within the current sector.
30
        uint8_t         Mode;                                           // Mode of fileoperation (read,write)
30
        uint8_t         Mode;                                           // Mode of fileoperation (read,write)
31
        uint32_t        Size;                                           // The size of the opend file in bytes.
31
        uint32_t        Size;                                           // The size of the opend file in bytes.
32
        uint32_t        Position;                                       // Pointer to a character within the file 0 < fileposition < filesize
32
        uint32_t        Position;                                       // Pointer to a character within the file 0 < fileposition < filesize
33
        uint32_t        DirectorySector;                        // the sectorposition where the directoryentry has been made.
33
        uint32_t        DirectorySector;                        // the sectorposition where the directoryentry has been made.
34
        uint16_t        DirectoryIndex;                         // The index to the directoryentry within the specified sector.
34
        uint16_t        DirectoryIndex;                         // The index to the directoryentry within the specified sector.
35
        uint8_t         Attribute;                                      // The attribute of the file opened.
35
        uint8_t         Attribute;                                      // The attribute of the file opened.
36
        uint8_t         Cache[BYTES_PER_SECTOR];        // Cache for read and write operation from or to the sd-card.
36
        uint8_t         Cache[BYTES_PER_SECTOR];        // Cache for read and write operation from or to the sd-card.
37
        uint32_t        SectorInCache;                          // The last sector read, which is still in the sector cache.
37
        uint32_t        SectorInCache;                          // The last sector read, which is still in the sector cache.
38
        uint8_t         State;                                          // State of the filepointer (used/unused/...)
38
        uint8_t         State;                                          // State of the filepointer (used/unused/...)
39
} File_t;
39
} File_t;
40
 
40
 
41
//________________________________________________________________________________________________________________________________________
41
//________________________________________________________________________________________________________________________________________
42
//
42
//
43
// API to the FAT16 filesystem
43
// API to the FAT16 filesystem
44
//
44
//
45
//________________________________________________________________________________________________________________________________________
45
//________________________________________________________________________________________________________________________________________
46
 
46
 
47
extern uint8_t          Fat16_Init(void);
47
extern uint8_t          Fat16_Init(void);
48
extern uint8_t          Fat16_Deinit(void);
48
extern uint8_t          Fat16_Deinit(void);
-
 
49
extern uint8_t          Fat16_IsValid(void);
49
 
50
 
50
extern File_t *         fopen_(int8_t * const filename, const int8_t mode);
51
extern File_t *         fopen_(int8_t * const filename, const int8_t mode);
51
extern int16_t          fclose_(File_t *file);
52
extern int16_t          fclose_(File_t *file);
52
extern uint8_t          fexist_(int8_t * const filename);
53
extern uint8_t          fexist_(int8_t * const filename);
53
extern int16_t          fflush_(File_t * const file);
54
extern int16_t          fflush_(File_t * const file);
54
extern int16_t          fseek_(File_t * const file, int32_t offset, int16_t origin);
55
extern int16_t          fseek_(File_t * const file, int32_t offset, int16_t origin);
55
extern int16_t          fgetc_(File_t * const file);
56
extern int16_t          fgetc_(File_t * const file);
56
extern int16_t          fputc_(const int8_t c, File_t * const file);
57
extern int16_t          fputc_(const int8_t c, File_t * const file);
57
extern uint32_t         fread_(void * const buffer, uint32_t size, uint32_t count, File_t * const file);
58
extern uint32_t         fread_(void * const buffer, uint32_t size, uint32_t count, File_t * const file);
58
extern uint32_t         fwrite_(void *buffer, uint32_t size, uint32_t count, File_t *file);
59
extern uint32_t         fwrite_(void *buffer, uint32_t size, uint32_t count, File_t *file);
59
extern int16_t          fputs_(int8_t * const string, File_t * const file);
60
extern int16_t          fputs_(int8_t * const string, File_t * const file);
60
extern int8_t *         fgets_(int8_t * const string, const int16_t length, File_t * const file);
61
extern int8_t *         fgets_(int8_t * const string, const int16_t length, File_t * const file);
61
extern uint8_t          feof_(File_t * const file);
62
extern uint8_t          feof_(File_t * const file);
62
 
63
 
63
 
64
 
64
 
65
 
65
#endif //_FAT16_H
66
#endif //_FAT16_H
66
 
67
 
67
 
68
 
68
 
69
 
69
 
70
 
70
 
71