2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /******************************************************************************
18 * @brief header file for eflash driver
21 ******************************************************************************/
22 #ifndef _CSI_EFLASH_H_
23 #define _CSI_EFLASH_H_
30 #include <drv_common.h>
33 /// definition for eflash handle.
34 typedef void *eflash_handle_t;
37 \brief Flash information
40 uint32_t start; ///< Chip Start address
41 uint32_t end; ///< Chip End address (start+size-1)
42 uint32_t sector_count; ///< Number of sectors
43 uint32_t sector_size; ///< Uniform sector size in bytes (0=sector_info used)
44 uint32_t page_size; ///< Optimal programming page size in bytes
45 uint32_t program_unit; ///< Smallest programmable unit in bytes
46 uint8_t erased_value; ///< Contents of erased memory (usually 0xFF)
53 uint32_t busy : 1; ///< Flash busy flag
54 uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation)
57 /****** EFLASH Event *****/
59 EFLASH_EVENT_READY = 0, ///< Flash Ready
60 EFLASH_EVENT_ERROR , ///< Read/Program/Erase Error
63 typedef void (*eflash_event_cb_t)(eflash_event_e event); ///< Pointer to \ref eflash_event_cb_t : EFLASH Event call back.
66 \brief Flash Driver Capabilities.
69 uint32_t event_ready : 1; ///< Signal Flash Ready event
70 uint32_t data_width : 2; ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
71 uint32_t erase_chip : 1; ///< Supports EraseChip operation
72 } eflash_capabilities_t;
74 // Function documentation
77 \brief get eflash handle count.
78 \return eflash handle count
80 int32_t csi_eflash_get_instance_count(void);
83 \brief Initialize EFLASH Interface. 1. Initializes the resources needed for the EFLASH interface 2.registers event callback function
84 \param[in] idx must not exceed return value of csi_eflash_get_instance_count()
85 \param[in] cb_event Pointer to \ref eflash_event_cb_t
86 \return pointer to eflash handle
88 eflash_handle_t csi_eflash_initialize(int32_t idx, eflash_event_cb_t cb_event);
91 \brief De-initialize EFLASH Interface. stops operation and releases the software resources used by the interface
92 \param[in] handle eflash handle to operate.
95 int32_t csi_eflash_uninitialize(eflash_handle_t handle);
98 \brief Get driver capabilities.
99 \param[in] handle eflash handle to operate.
100 \return \ref eflash_capabilities_t
102 eflash_capabilities_t csi_eflash_get_capabilities(eflash_handle_t handle);
105 \brief Read data from Flash.
106 \param[in] handle eflash handle to operate.
107 \param[in] addr Data address.
108 \param[out] data Pointer to a buffer storing the data read from Flash.
109 \param[in] cnt Number of data items to read.
110 \return number of data items read or error code
112 int32_t csi_eflash_read(eflash_handle_t handle, uint32_t addr, void *data, uint32_t cnt);
115 \brief Program data to Flash.
116 \param[in] handle eflash handle to operate.
117 \param[in] addr Data address.
118 \param[in] data Pointer to a buffer containing the data to be programmed to Flash..
119 \param[in] cnt Number of data items to program.
120 \return number of data items programmed or error code
122 int32_t csi_eflash_program(eflash_handle_t handle, uint32_t addr, const void *data, uint32_t cnt);
125 \brief Erase Flash Sector.
126 \param[in] handle eflash handle to operate.
127 \param[in] addr Sector address
130 int32_t csi_eflash_erase_sector(eflash_handle_t handle, uint32_t addr);
133 \brief Erase complete Flash.
134 \param[in] handle eflash handle to operate.
137 int32_t csi_eflash_erase_chip(eflash_handle_t handle);
140 \brief Get Flash information.
141 \param[in] handle eflash handle to operate.
142 \return Pointer to Flash information \ref eflash_info
144 eflash_info_t *csi_eflash_get_info(eflash_handle_t handle);
147 \brief Get EFLASH status.
148 \param[in] handle eflash handle to operate.
149 \return EFLASH status \ref eflash_status_t
151 eflash_status_t csi_eflash_get_status(eflash_handle_t handle);
157 #endif /* _CSI_EFLASH_H_ */