1 /* 2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved. 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 /****************************************************************************** 17 * @file drv_eflash.h 18 * @brief header file for eflash driver 19 * @version V1.0 20 * @date 02. June 2017 21 ******************************************************************************/ 22 #ifndef _CSI_EFLASH_H_ 23 #define _CSI_EFLASH_H_ 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #include <stdint.h> 30 #include <drv_common.h> 31 32 33 /// definition for eflash handle. 34 typedef void *eflash_handle_t; 35 36 /** 37 \brief Flash information 38 */ 39 typedef struct { 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) 47 } eflash_info; 48 49 /** 50 \brief Flash Status 51 */ 52 typedef struct { 53 uint32_t busy : 1; ///< Flash busy flag 54 uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation) 55 } eflash_status_t; 56 57 /****** EFLASH Event *****/ 58 typedef enum { 59 EFLASH_EVENT_READY = 0, ///< Flash Ready 60 EFLASH_EVENT_ERROR , ///< Read/Program/Erase Error 61 } eflash_event_e; 62 63 typedef void (*eflash_event_cb_t)(eflash_event_e event); ///< Pointer to \ref eflash_event_cb_t : EFLASH Event call back. 64 65 /** 66 \brief Flash Driver Capabilities. 67 */ 68 typedef struct { 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; 73 74 // Function documentation 75 76 /** 77 \brief get eflash handle count. 78 \return eflash handle count 79 */ 80 int32_t csi_eflash_get_instance_count(void); 81 82 /** 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 87 */ 88 eflash_handle_t csi_eflash_initialize(int32_t idx, eflash_event_cb_t cb_event); 89 90 /** 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. 93 \return error code 94 */ 95 int32_t csi_eflash_uninitialize(eflash_handle_t handle); 96 97 /** 98 \brief Get driver capabilities. 99 \param[in] handle eflash handle to operate. 100 \return \ref eflash_capabilities_t 101 */ 102 eflash_capabilities_t csi_eflash_get_capabilities(eflash_handle_t handle); 103 104 /** 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 111 */ 112 int32_t csi_eflash_read(eflash_handle_t handle, uint32_t addr, void *data, uint32_t cnt); 113 114 /** 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 121 */ 122 int32_t csi_eflash_program(eflash_handle_t handle, uint32_t addr, const void *data, uint32_t cnt); 123 124 /** 125 \brief Erase Flash Sector. 126 \param[in] handle eflash handle to operate. 127 \param[in] addr Sector address 128 \return error code 129 */ 130 int32_t csi_eflash_erase_sector(eflash_handle_t handle, uint32_t addr); 131 132 /** 133 \brief Erase complete Flash. 134 \param[in] handle eflash handle to operate. 135 \return error code 136 */ 137 int32_t csi_eflash_erase_chip(eflash_handle_t handle); 138 139 /** 140 \brief Get Flash information. 141 \param[in] handle eflash handle to operate. 142 \return Pointer to Flash information \ref eflash_info 143 */ 144 eflash_info *csi_eflash_get_info(eflash_handle_t handle); 145 146 /** 147 \brief Get EFLASH status. 148 \param[in] handle eflash handle to operate. 149 \return EFLASH status \ref eflash_status_t 150 */ 151 eflash_status_t csi_eflash_get_status(eflash_handle_t handle); 152 153 #ifdef __cplusplus 154 } 155 #endif 156 157 #endif /* _CSI_EFLASH_H_ */ 158