playing around with pffs (NOT FINISHED, DOESNT COMPILE!)
[my-code/arm.git] / betty / pffs.h
1 /*
2  * pfs.h - pseudo flash filesystem header file
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 #ifndef PFFS_H
9 #define PFFS_H
10
11 #include "lpc2xxx.h"
12 #include "types.h"
13 #include "functions.h"
14
15 /* defines */
16 #define PFFS_MAX_FILENAME_SIZE  15              // in words
17 #define PFFS_HEADER_SIZE        3               // in words
18
19 #define PFFS_REGISTERED         (1<<0)
20
21 #define PFFS_INDEX_MAGIC        0x7000
22
23 #define PFFS_INDEX_MAGIC_MASK   0xf000
24 #define PFFS_RESERVED_MASK      0x0f00
25 #define PFFS_FNLEN_MASK         0x00f0
26 #define PFFS_LEN_MSB_MASK       0x000f
27
28 /* file modes */
29 #define PFFS_READ               0x01
30 #define PFFS_WRITE              0x02
31 #define PFFS_RDWR               0x03
32
33 /* pffs write / read return codes */
34 #define PFFS_FILE_EXISTS        0x01
35 #define PFFS_FILE_NOT_FOUND     0x02
36 #define PFFS_NO_SPACE_LEFT      0x04
37 #define PFFS_FILENAME_TOO_LONG  0x08
38
39 /* type definitions */
40
41 typedef struct s_pffs {
42         /* flash specs */
43         u32 base_addr;
44         u32 *sec_addr;
45         /* flash write, read and sector erase function pointers */
46         int (*fw)(u32 addr,u16 *buf,int len);
47         int (*fr)(u32 addr,u16 *buf,int len);
48         int (*fe)(u32 addr);
49         /* pffs internal variables */
50         u8 state;
51         u32 data_ptr;                   // pointer where new data goes
52         u32 index_ptr[3];               // 0: start, 1: new, 2: current
53         u8 sec_num_data[2];             // data start/end sectors
54         u8 sec_num_index[2];            // 2 index sectors
55 } t_pffs;
56
57 typedef struct s_pffs_fd {
58         u32 daddr;
59         u32 iaddr;
60         char file[PFFS_MAX_FILENAME_SIZE+PFFS_MAX_FILENAME_SIZE];
61         u8 fn_size;
62         u8 mode;
63         t_pffs *pffs;
64 } t_pffs_fd;
65
66 /* function prototypes */
67 int pffs_open(t_pffs *pffs,char *file,u8 mode);
68 int pffs_write(t_pffs *pffs,int fd,u8 *buf,int len);
69 int pffs_read(t_pffs *pffs,int fd,u8 *buf,int len);
70 int pffs_close(t_pffs *pffs,int fd);
71 int pffs_unlink(t_pffs *pffs,char *file);
72
73 #endif