2 * pfs.h - pseudo flash filesystem header file
4 * author: hackbard@hackdaworld.org
13 #include "functions.h"
16 #define PFFS_MAX_FILENAME_SIZE 15 // in words
17 #define PFFS_HEADER_SIZE 3 // in words
18 #define PFFS_MAX_FILE_SIZE 0xffff
20 /* general pffs system */
21 #define PFFS_INDEX_FOUND 0x00
22 #define PFFS_NO_INDEX_FOUND 0x01
24 #define PFFS_DATA_TMP_FOUND 0x00
25 #define PFFS_NO_DATA_TMP 0x01
27 #define PFFS_SEC_NOT_EMPTY 0x00
28 #define PFFS_SEC_EMPTY 0x01
30 #define PFFS_REGISTERED (1<<0)
32 /* pffs index format */
33 #define PFFS_INDEX_MAGIC_MASK 0xf000
34 #define PFFS_STATE_MASK 0x0f00
35 #define PFFS_FNLEN_MASK 0x00f0
36 #define PFFS_ADDR_MSB_MASK 0x000f
38 #define PFFS_INDEX_MAGIC 0x7000
39 #define PFFS_INDEX_REMOVED 0x0700
44 #define PFFS_READ 0x01
45 #define PFFS_WRITE 0x02
46 #define PFFS_RDWR 0x03
49 #define PFFS_SEEK_SET 0x01
50 #define PFFS_SEEK_CUR 0x02
51 #define PFFS_SEEK_END 0x03
53 /* pffs open / write / read return codes */
54 #define PFFS_FILE_FOUND 0x01
55 #define PFFS_FILE_NOT_FOUND 0x02
56 #define PFFS_NO_SPACE_LEFT 0x04
57 #define PFFS_FILENAME_TOO_LONG 0x08
58 #define PFFS_MODE_UNSUPPORTED 0x10
59 #define PFFS_NO_INDEX_SPACE_LEFT 0x20
60 #define PFFS_INDEX_WROTE_INIT 0x40
62 #define PFFS_INVALID_LEN 0x01
63 #define PFFS_EINVAL 0x02
65 /* type definitions */
67 typedef struct s_pffs {
71 u8 sec_num_data[2]; // first/last sector used for data
72 u8 sec_num_index[2]; // 2 sectors used as an index
74 /* flash write, read and sector erase function pointers */
75 int (*fw)(u32 addr,u16 *buf,int len);
76 int (*fr)(u32 addr,u16 *buf,int len);
79 /* pffs internal variables */
81 u8 index_sec; // current index sector
82 u8 data_tmp_sec; // current temp data sector
85 typedef struct s_pffs_fd {
86 u32 daddr; // data start address
87 u8 data_sec; // current data sector
88 u32 dptr; // data pointer
89 u32 iaddr; // index address
91 char file[PFFS_MAX_FILENAME_SIZE+PFFS_MAX_FILENAME_SIZE]; // the file
92 u8 fn_size; // file name size
93 u8 mode; // mode, eg: write, read
94 t_pffs *pffs; // the pffs main struct
97 /* function prototypes (only the ones applications should use!) */
98 int pffs_flash_register(t_pffs *pffs,u32 base_addr,u32 *sec_addr,
99 u8 sec_num_data_min,u8 sec_num_data_max,
100 u8 sec_num_index0,u8 sec_num_index1,
101 int (*fw)(u32 addr,u16 *buf,int len),
102 int (*fr)(u32 addr,u16 *buf,int len),
103 int (*fe)(u32 addr));
104 int pffs_init(t_pffs *pffs);
105 int pffs_open(t_pffs *pffs,t_pffs_fd *fd,char *file,u8 mode);
106 int pffs_write(t_pffs_fd *fd,u8 *buf,int len);
107 int pffs_read(t_pffs_fd *fd,u8 *buf,int len);
108 int pffs_lseek(t_pffs_fd *fd,u8 offset,int len);
109 int pffs_close(t_pffs_fd *fd);
110 int pffs_unlink(t_pffs_fd *fd,char *file);