1 /*
2  * COPYRIGHT (C) 2011-2023, Real-Thread Information Technology Ltd
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2012-5-30      Bernard      the first version
9  */
10 
11 #ifndef __MTD_NOR_H__
12 #define __MTD_NOR_H__
13 
14 #include <rtthread.h>
15 
16 struct rt_mtd_nor_driver_ops;
17 #define RT_MTD_NOR_DEVICE(device)   ((struct rt_mtd_nor_device*)(device))
18 
19 struct rt_mtd_nor_device
20 {
21     struct rt_device parent;
22 
23     rt_uint32_t block_size;         /* The Block size in the flash */
24     rt_uint32_t block_start;        /* The start of available block*/
25     rt_uint32_t block_end;          /* The end of available block */
26 
27     /* operations interface */
28     const struct rt_mtd_nor_driver_ops* ops;
29 };
30 
31 struct rt_mtd_nor_driver_ops
32 {
33     rt_err_t (*read_id) (struct rt_mtd_nor_device* device);
34 
35     rt_ssize_t (*read)    (struct rt_mtd_nor_device* device, rt_off_t offset, rt_uint8_t* data, rt_size_t length);
36     rt_ssize_t (*write)   (struct rt_mtd_nor_device* device, rt_off_t offset, const rt_uint8_t* data, rt_size_t length);
37 
38     rt_err_t (*erase_block)(struct rt_mtd_nor_device* device, rt_off_t offset, rt_size_t length);
39 };
40 
41 rt_err_t rt_mtd_nor_register_device(const char* name, struct rt_mtd_nor_device* device);
42 rt_uint32_t rt_mtd_nor_read_id(struct rt_mtd_nor_device* device);
43 rt_ssize_t rt_mtd_nor_read(struct rt_mtd_nor_device* device,
44         rt_off_t offset, rt_uint8_t* data, rt_size_t length);
45 rt_ssize_t rt_mtd_nor_write(struct rt_mtd_nor_device* device,
46         rt_off_t offset, const rt_uint8_t* data, rt_size_t length);
47 rt_err_t rt_mtd_nor_erase_block(struct rt_mtd_nor_device* device,
48         rt_off_t offset, rt_size_t length);
49 
50 #endif
51