/[projet1]/public/oric/hardware/cumulus/fw/fat32.h
Defence Force logotype

Contents of /public/oric/hardware/cumulus/fw/fat32.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 423 - (show annotations)
Mon Jan 24 12:19:33 2011 UTC (9 years, 4 months ago) by retromaster
File MIME type: text/plain
File size: 3609 byte(s)
Initial add of 18F46K20 firmware sources.
1 /* Cumulus 18F46K20 Firmware
2 * FAT32 Routines.
3 * Copyright 2010 Retromaster.
4 *
5 * This file is part of Cumulus Firmware.
6 *
7 * Cumulus Firmware is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License,
10 * or any later version.
11 *
12 * Cumulus Firmware is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cumulus Firmware. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _FAT32_H_
22 #define _FAT32_H_
23
24 #include "global.h"
25
26 #define LE16(card_sector, X) (((uint16_t) card_sector[(X)]) + \
27 (((uint16_t) card_sector[(X) + 1]) << 8))
28
29 #define LE32(card_sector, X) (((uint32_t) card_sector[(X)]) + \
30 (((uint32_t) card_sector[(X) + 1]) << 8) + \
31 (((uint32_t) card_sector[(X) + 2]) << 16) + \
32 (((uint32_t) card_sector[(X) + 3]) << 24))
33
34 #define LBA(X) (cluster_begin_lba + ((X) - 2) * sectors_per_cluster)
35 //#define LBA(X) (cluster_begin_lba + (((X) - 2) << 3))
36
37
38 extern uint32_t cluster_begin_lba;
39 extern uint8_t sectors_per_cluster;
40 extern uint32_t fpp_begin_lba;
41 extern uint32_t fat_begin_lba;
42 extern uint32_t sectors_per_fat;
43 extern uint32_t cluster_begin_lba;
44 extern uint8_t sectors_per_cluster;
45 extern uint8_t fat_count;
46 extern uint16_t root_dir_first_cluster;
47 extern uint16_t reserved_sector_count;
48
49 typedef struct _fat32_cluster_range
50 {
51 uint16_t start;
52 uint16_t end;
53 uint32_t cluster;
54 } fat32_cluster_range;
55
56 typedef struct _fat32_dir
57 {
58 uint8_t* entry;
59 uint32_t sector;
60 uint32_t cluster;
61 uint8_t error;
62 } fat32_dir;
63
64 #define FLN_MAX_SIZE 21
65 #define MAX_RANGES 8
66
67 typedef struct _fat32_file
68 {
69 char name[FLN_MAX_SIZE + 1];
70 char ext[4];
71 uint8_t dir; /* Is it a directory? */
72 uint32_t size;
73 fat32_cluster_range ranges[MAX_RANGES]; /* Cluster ranges */
74 uint32_t pos; /* Position indicator for byte routines */
75 uint8_t sector_valid; /* Is sector buffer valid? */
76 uint8_t sector_dirty; /* Is sector buffer dirty? */
77 } fat32_file;
78
79 typedef struct _fat32_dir_entry
80 {
81 char name[FLN_MAX_SIZE + 1];
82 char ext[4];
83 uint8_t dir; /* Is it a directory? */
84 uint32_t size;
85 uint32_t cluster; /* Starting cluster */
86 } fat32_dir_entry;
87
88 extern uint8_t fat32_init(void);
89 extern uint8_t fat32_card_read(uint32_t sector);
90 extern uint8_t fat32_card_write(uint32_t sector);
91 extern void fat32_root_dir(fat32_dir_entry* file);
92 extern void fat32_dir_begin(fat32_dir* dir, fat32_dir_entry* file);
93 extern uint8_t fat32_dir_next(fat32_dir* dir, fat32_dir_entry* file, far rom char* ext);
94 extern uint32_t fat32_file_get_lba(fat32_file* file, uint32_t sector);
95 extern uint8_t fat32_file_read(fat32_file* file, uint32_t offset, uint32_t length, uint8_t* buffer);
96 extern uint8_t fat32_file_seek(fat32_file* file, uint32_t position);
97 extern uint8_t fat32_file_get_byte(fat32_file* file, uint8_t *byte);
98 extern uint8_t fat32_file_put_byte(fat32_file* file, uint8_t byte);
99 extern uint8_t fat32_file_flush(fat32_file* file);
100 extern uint8_t fat32_file_from_dir_entry(fat32_file* file, fat32_dir_entry* dir_entry);
101
102 extern uint8_t fat32_sector_buffer[512];
103 extern fat32_file* fat32_sector_buffer_owner;
104
105
106 #endif

  ViewVC Help
Powered by ViewVC 1.1.26