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 flash driver
21 ******************************************************************************/
31 #include <drv_common.h>
40 \brief Flash Sector information
43 uint32_t start; ///< Sector Start address
44 uint32_t end; ///< Sector End address (start+size-1)
48 \brief Flash information
51 flash_sector *sector_info; ///< Sector layout information (NULL=Uniform sectors)
52 uint32_t sector_count; ///< Number of sectors
53 uint32_t sector_size; ///< Uniform sector size in bytes (0=sector_info used)
54 uint32_t page_size; ///< Optimal programming page size in bytes
55 uint32_t program_unit; ///< Smallest programmable unit in bytes
56 uint8_t erased_value; ///< Contents of erased memory (usually 0xFF)
63 uint32_t busy : 1; ///< Flash busy flag
64 uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation)
67 /****** FLASH Event *****/
69 FLASH_EVENT_READY = 0, ///< Flash Ready
70 FLASH_EVENT_ERROR , ///< Read/Program/Erase Error
73 typedef void (*flash_event_cb_t)(flash_event_e event); ///< Pointer to \ref flash_event_cb_t : FLASH Event call back.
76 \brief Flash Driver Capabilities.
79 uint32_t event_ready : 1; ///< Signal Flash Ready event
80 uint32_t data_width : 2; ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
81 uint32_t erase_chip : 1; ///< Supports EraseChip operation
82 } flash_capabilities_t;
88 \brief get flash instance count.
89 \return flash instance count
91 int32_t drv_flash_get_instance_count(void);
94 \brief get flash instance .
95 \param[in] idx must not exceed return value of drv_flash_get_instance_count()
96 \return pointer to flash instance
98 csi_flash_t *drv_flash_get_instance(int32_t idx);
101 \brief Get driver capabilities.
102 \param[in] instance flash instance to operate.
103 \return \ref flash_capabilities_t
105 flash_capabilities_t drv_flash_get_capabilities(const csi_flash_t *instance);
108 \brief Initialize FLASH Interface. 1. Initializes the resources needed for the FLASH interface 2.registers event callback function
109 \param[in] instance flash instance to operate.
110 \param[in] cb_event Pointer to \ref flash_event_cb_t
113 int32_t drv_flash_initialize(const csi_flash_t *instance, flash_event_cb_t cb_event);
116 \brief De-initialize FLASH Interface. stops operation and releases the software resources used by the interface
117 \param[in] instance flash instance to operate.
120 int32_t drv_flash_uninitialize(const csi_flash_t *instance);
123 \brief Get Flash information.
124 \param[in] instance flash instance to operate.
125 \return Pointer to Flash information \ref flash_info_t
127 flash_info_t *drv_flash_get_info(const csi_flash_t *instance);
130 \brief Read data from Flash.
131 \param[in] instance flash instance to operate.
132 \param[in] addr Data address.
133 \param[in] data Pointer to a buffer storing the data read from Flash.
134 \param[in] cnt Number of data items to read.
135 \return number of data items read or error code
137 int32_t drv_flash_read(const csi_flash_t *instance, uint32_t addr, void *data, uint32_t cnt);
140 \brief Program data to Flash.
141 \param[in] instance flash instance to operate.
142 \param[in] addr Data address.
143 \param[in] data Pointer to a buffer containing the data to be programmed to Flash..
144 \param[in] cnt Number of data items to program.
145 \return number of data items programmed or error code
147 int32_t drv_flash_program(const csi_flash_t *instance, uint32_t addr, const void *data, uint32_t cnt);
150 \brief Erase Flash Sector.
151 \param[in] instance flash instance to operate.
152 \param[in] addr Sector address
155 int32_t drv_flash_erase_sector(const csi_flash_t *instance, uint32_t addr);
158 \brief Erase complete Flash.
159 \param[in] instance flash instance to operate.
162 int32_t drv_flash_erase_chip(const csi_flash_t *instance);
165 \brief Get FLASH status.
166 \param[in] instance flash instance to operate.
167 \return FLASH status \ref flash_status_t
169 flash_status_t drv_flash_get_status(const csi_flash_t *instance);
175 #endif /* _CSI_FLASH_H_ */