1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file eflash.h 7 * @brief header file for eflash driver 8 * @version V1.0 9 * @date 02. June 2017 10 * @model eflash 11 ******************************************************************************/ 12 #ifndef _DRV_EFLASH_H_ 13 #define _DRV_EFLASH_H_ 14 15 #include <stdint.h> 16 #include <drv/common.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 /** 23 \brief Flash information 24 */ 25 typedef struct { 26 uint32_t flash_size; ///< Chip End address (start+size-1) 27 uint32_t sector_size; ///< Uniform sector size in bytes 28 uint32_t erased_value; ///< erased value 29 } csi_eflash_info_t; 30 31 /** 32 \brief Flash Status 33 */ 34 typedef struct { 35 uint32_t busy : 1; ///< Flash busy flag 36 uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation) 37 } eflash_status_t; 38 39 /// definition for eflash handle. 40 typedef struct { 41 csi_dev_t dev; 42 void *arg; 43 csi_eflash_info_t eflashinfo; 44 uint16_t prog; 45 uint16_t erase; 46 void *priv; 47 } csi_eflash_t; 48 49 // Function documentation 50 51 /** 52 \brief Initialize EFLASH Interface. 1. Initializes the resources needed for the EFLASH interface 2.registers event callback function 53 \param[in] eflash eflash handle to operate. 54 \param[in] idx device id 55 \param[in] arg User can define it by himself as callback's param 56 \return error code 57 */ 58 csi_error_t csi_eflash_init(csi_eflash_t *eflash, int32_t idx, void *arg); 59 60 /** 61 \brief De-initialize EFLASH Interface. stops operation and releases the software resources used by the interface 62 \param[in] eflash eflash handle to operate. 63 \return error code 64 */ 65 csi_error_t csi_eflash_uninit(csi_eflash_t *eflash); 66 67 /** 68 \brief Read data from Flash. 69 \param[in] eflash eflash handle to operate. 70 \param[in] offset Data address. 71 \param[out] data Pointer to a buffer storing the data read from Flash. 72 \param[in] size Number of data items to read. 73 \return error code 74 */ 75 csi_error_t csi_eflash_read(csi_eflash_t *eflash, uint32_t offset, void *data, uint32_t size); 76 77 /** 78 \brief Program data to Flash. 79 \param[in] eflash eflash handle to operate. 80 \param[in] offset Data address. 81 \param[in] data Pointer to a buffer containing the data to be programmed to Flash. 82 \param[in] size Number of data items to program. 83 \return error code 84 */ 85 csi_error_t csi_eflash_program(csi_eflash_t *eflash, uint32_t offset, const void *data, uint32_t size); 86 87 /** 88 \brief Erase Flash Sector. 89 \param[in] eflash eflash handle to operate. 90 \param[in] offset flash address, flash address need sector size aligned 91 \param[in] size erase size 92 \return error code 93 */ 94 csi_error_t csi_eflash_erase(csi_eflash_t *eflash, uint32_t offset,uint32_t size); 95 96 /** 97 \brief Erase whole flash 98 \param[in] eflash eflash handle to operate. 99 \return error code 100 */ 101 csi_error_t csi_eflash_erase_chip(csi_eflash_t *eflash); 102 103 /** 104 \brief Get Flash information. 105 \param[in] eflash eflash handle to operate. 106 */ 107 void csi_eflash_dev_info(csi_eflash_t *eflash,csi_eflash_info_t *eflash_info); 108 109 /** 110 \brief enable eflash power manage 111 \param[in] eflash eflash handle to operate. 112 \return error code 113 */ 114 csi_error_t csi_eflash_enable_pm(csi_eflash_t *eflash); 115 116 /** 117 \brief disable eflash power manage 118 \param[in] eflash eflash handle to operate. 119 */ 120 void csi_eflash_disable_pm(csi_eflash_t *eflash); 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 #endif /* _DRV_EFLASH_H_ */ 127