1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2018-05-17     armink       the first version
9  */
10 
11 #ifndef _FAL_DEF_H_
12 #define _FAL_DEF_H_
13 
14 #include <rtthread.h>
15 
16 /* FAL flash and partition device name max length */
17 #ifndef FAL_DEV_NAME_MAX
18 #define FAL_DEV_NAME_MAX 24
19 #endif
20 
21 #ifndef FAL_DEV_BLK_MAX
22 #define FAL_DEV_BLK_MAX 6
23 #endif
24 
25 struct flash_blk
26 {
27     rt_size_t size;
28     rt_size_t count;
29 };
30 
31 struct fal_flash_dev
32 {
33     char name[FAL_DEV_NAME_MAX];
34 
35     /* flash device start address and len  */
36     rt_uint32_t addr;
37     rt_size_t len;
38     /* the block size in the flash for erase minimum granularity */
39     rt_size_t blk_size;
40 
41     struct
42     {
43         int (*init)(void);
44         int (*read)(long offset, rt_uint8_t *buf, rt_size_t size);
45         int (*write)(long offset, const rt_uint8_t *buf, rt_size_t size);
46         int (*erase)(long offset, rt_size_t size);
47     } ops;
48 
49     /* write minimum granularity, unit: bit.
50        1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
51        0 will not take effect. */
52     rt_size_t write_gran;
53     struct flash_blk blocks[FAL_DEV_BLK_MAX];
54 };
55 typedef struct fal_flash_dev *fal_flash_dev_t;
56 
57 /**
58  * FAL partition
59  */
60 struct fal_partition
61 {
62     rt_uint32_t magic_word;
63 
64     /* partition name */
65     char name[FAL_DEV_NAME_MAX];
66     /* flash device name for partition */
67     char flash_name[FAL_DEV_NAME_MAX];
68 
69     /* partition offset address on flash device */
70     long offset;
71     rt_size_t len;
72 
73     rt_uint32_t reserved;
74 };
75 typedef struct fal_partition *fal_partition_t;
76 
77 #endif /* _FAL_DEF_H_ */
78