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 {
69 u32 base_addr; // base flash access address
70 u32 *sec_addr; // pointer to sector addresses
71 u8 sec_num; // number of sectors
73 /* flash write, read and sector erase function pointers */
74 int (*fw)(u32 addr,u16 *buf,int len);
75 int (*fr)(u32 addr,u16 *buf,int len);
78 /* pffs internal variables */
80 u8 data_tmp_sec; // current temp data sector
83 typedef struct s_pffs_fd {
84 u32 daddr; // data start address
85 u8 data_sec; // current data sector
86 u32 dptr; // data pointer
87 u32 iaddr; // index address
89 char file[PFFS_MAX_FILENAME_SIZE+PFFS_MAX_FILENAME_SIZE]; // the file
90 u8 fn_size; // file name size
91 u8 mode; // mode, eg: write, read
92 t_pffs *pffs; // pointer to the pffs main struct
95 typedef struct s_pffs_sector_header {
96 u32 wear_level; // program / erase cycles
99 typedef struct s_pffs_file_header {
100 u32 file_len; // length of files in ?
101 u32 file_cont; // continued file addr
102 u8 file_name_len; // lenght of the filename in words
105 /* function prototypes (only the ones applications should use!) */
106 int pffs_flash_register(t_pffs *pffs,u32 base_addr,u32 *sec_addr,u8 sec_num,
107 int (*fw)(u32 addr,u16 *buf,int len),
108 int (*fr)(u32 addr,u16 *buf,int len),
109 int (*fe)(u32 addr));
110 int pffs_init(t_pffs *pffs);
111 int pffs_open(t_pffs *pffs,t_pffs_fd *fd,char *file,u8 mode);
112 int pffs_write(t_pffs_fd *fd,u8 *buf,int len);
113 int pffs_read(t_pffs_fd *fd,u8 *buf,int len);
114 int pffs_lseek(t_pffs_fd *fd,u8 offset,int len);
115 int pffs_close(t_pffs_fd *fd);
116 int pffs_unlink(t_pffs_fd *fd,char *file);