1 /**
2  * @file nand.h
3  * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited
4  */
5 
6 #ifndef HAL_NAND_H
7 #define HAL_NAND_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /** @addtogroup hal_nand NAND
14  *  nand hal API.
15  *
16  *  @{
17  */
18 
19 #include <stdint.h>
20 
21 typedef struct {
22     uint32_t page_size;       /**< NAND memory page size w/o spare area */
23     uint32_t spare_area_size; /**< NAND memory spare area size */
24     uint32_t block_size;      /**< NAND memory block size number of pages */
25     uint32_t zone_size;       /**< NAND memory zone size measured in number of blocks */
26     uint32_t zone_number;     /**< NAND memory number of zones */
27 } nand_config_t;
28 
29 typedef struct {
30     uint16_t page;  /**< NAND memory Page address */
31     uint16_t block; /**< NAND memory Block address */
32     uint16_t zone;  /**< NAND memory Zone address */
33 } nand_addr_t;
34 
35 typedef struct {
36     uint32_t       base_addr;   /**< NAND memory base address */
37     nand_config_t  config;      /**< NAND device config args */
38     void          *priv;        /**< NAND device priv args */
39 } nand_dev_t;
40 
41 /**
42  * Initialises a nand flash interface
43  *
44  * @param[in]  nand  the interface which should be initialised
45  *
46  * @return  0 : on success,  otherwise is error
47  */
48 int32_t hal_nand_init(nand_dev_t *nand);
49 
50 /**
51  * Deinitialises a nand flash interface
52  *
53  * @param[in]  nand  the interface which should be Deinitialised
54  *
55  * @return  0 : on success,  otherwise is error
56  */
57 int32_t hal_nand_finalize(nand_dev_t *nand);
58 
59 /**
60  * Read nand page(s)
61  *
62  * @param[in]   nand        the interface which should be Readed
63  * @param[out]  data        pointer to the buffer which will store incoming data
64  * @param[in]   addr        nand address
65  * @param[in]   page_count  the number of pages to read
66  *
67  * @return  0 : on success,  otherwise is error
68  */
69 int32_t hal_nand_read_page(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t page_count);
70 
71 
72 /**
73  * Write nand page(s)
74  *
75  * @param[in]   nand        the interface which should be Writed
76  * @param[in]   data        pointer to source buffer to write
77  * @param[in]   addr        nand address
78  * @param[in]   page_count  the number of pages to write
79  *
80  * @return  0 : on success,  otherwise is error
81  */
82 int32_t hal_nand_write_page(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t page_count);
83 
84 /**
85  * Read nand spare area
86  *
87  * @param[in]   nand      the interface which should be Readed
88  * @param[out]  data      pointer to the buffer which will store incoming data
89  * @param[in]   addr      nand address
90  * @param[in]   data_len  the number of spares to read
91  *
92  * @return  0 : on success,  otherwise is error
93  */
94 int32_t hal_nand_read_spare(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t data_len);
95 
96 
97 /**
98  * Write nand spare area
99  *
100  * @param[in]   nand      the interface which should be Writed
101  * @param[in]   data      pointer to source buffer to write
102  * @param[in]   addr      nand address
103  * @param[in]   data_len  the number of spares to write
104  *
105  * @return  0 : on success,  otherwise is error
106  */
107 int32_t hal_nand_write_spare(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t data_len);
108 
109 /**
110  * Erase nand block
111  *
112  * @param[in]   nand      the interface which should be Erased
113  * @param[in]   addr      nand address
114  *
115  * @return  0 : on success,  otherwise is error
116  */
117 int32_t hal_nand_erase_block(nand_dev_t *nand, nand_addr_t *addr);
118 
119 /** @} */
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif /* HAL_NAND_H */
126 
127