1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file drv_norflash.h 7 * @brief header file for norflash driver 8 * @version V1.0 9 * @date 02. June 2017 10 * @model norflash 11 ******************************************************************************/ 12 #ifndef _CSI_NORFLASH_H_ 13 #define _CSI_NORFLASH_H_ 14 15 16 #include <stdint.h> 17 #include <drv/common.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /// definition for norflash handle. 24 typedef void *norflash_handle_t; 25 26 /** 27 \brief Flash information 28 */ 29 typedef struct { 30 uint32_t start; ///< Chip Start address 31 uint32_t end; ///< Chip End address (start+size-1) 32 uint32_t sector_count; ///< Number of sectors 33 uint32_t sector_size; ///< Uniform sector size in bytes (0=sector_info used) 34 uint32_t page_size; ///< Optimal programming page size in bytes 35 uint32_t program_unit; ///< Smallest programmable unit in bytes 36 uint8_t erased_value; ///< Contents of erased memory (usually 0xFF) 37 } norflash_info; 38 39 /** 40 \brief Flash Status 41 */ 42 typedef struct { 43 uint32_t busy : 1; ///< Flash busy flag 44 uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation) 45 } norflash_status_t; 46 47 /****** NORFLASH Event *****/ 48 typedef enum { 49 NORFLASH_EVENT_READY = 0, ///< Flash Ready 50 NORFLASH_EVENT_ERROR, ///< Read/Program/Erase Error 51 } norflash_event_e; 52 53 typedef void (*norflash_event_cb_t)(int32_t idx, norflash_event_e event); ///< Pointer to \ref norflash_event_cb_t : NORFLASH Event call back. 54 55 /** 56 \brief Flash Driver Capabilities. 57 */ 58 typedef struct { 59 uint32_t event_ready : 1; ///< Signal Flash Ready event 60 uint32_t data_width : 2; ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit 61 uint32_t erase_chip : 1; ///< Supports EraseChip operation 62 } norflash_capabilities_t; 63 64 // Function documentation 65 66 /** 67 \brief Get driver capabilities. 68 \param[in] handle norflash handle to operate. 69 \return \ref norflash_capabilities_t 70 */ 71 norflash_capabilities_t csi_norflash_get_capabilities(int32_t idx); 72 73 /** 74 \brief Initialize NORFLASH Interface. 1. Initializes the resources needed for the NORFLASH interface 2.registers event callback function 75 \param[in] idx device id 76 \param[in] cb_event Pointer to \ref norflash_event_cb_t 77 \return pointer to norflash handle 78 */ 79 norflash_handle_t csi_norflash_initialize(int32_t idx, norflash_event_cb_t cb_event); 80 81 /** 82 \brief control norflash power. 83 \param[in] handle norflash handle to operate. 84 \param[in] state power state.\ref csi_power_stat_e. 85 \return error code 86 */ 87 int32_t csi_norflash_power_control(norflash_handle_t handle, csi_power_stat_e state); 88 89 /** 90 \brief De-initialize NORFLASH Interface. stops operation and releases the software resources used by the interface 91 \param[in] handle norflash handle to operate. 92 \return error code 93 */ 94 int32_t csi_norflash_uninitialize(norflash_handle_t handle); 95 96 /** 97 \brief Read data from Flash. 98 \param[in] handle norflash handle to operate. 99 \param[in] addroffset read address offset. 100 \param[out] dstbuf Pointer to a buffer storing the data read from Flash. 101 \param[in] len Number of data items to read. 102 \return number of data items read or error code 103 */ 104 105 int32_t csi_norflash_read(norflash_handle_t handle, uint32_t addroffset, void *dstbuf, uint32_t len); 106 107 /** 108 \brief Read id num from Flash. 109 \param[in] handle norflash handle to operate. 110 \param[in] id Pointer to a buffer storing the id num. 111 \return error code 112 */ 113 int32_t csi_norflash_readid(norflash_handle_t handle, void *id); 114 115 /** 116 \brief Program data to Flash. 117 \param[in] handle norflash handle to operate. 118 \param[in] addroffset program address offset. 119 \param[in] srcbuf Pointer to a buffer containing the data to be programmed to Flash.. 120 \param[in] len Number of data items to program. 121 \return number of data items programmed or error code 122 */ 123 int32_t csi_norflash_write(norflash_handle_t handle, uint32_t addroffset, const void *srcbuf, uint32_t len); 124 125 /** 126 \brief Erase Flash Sector. 127 \param[in] handle norflash handle to operate. 128 \param[in] addroffset erase address offset 129 \param[in] num erase sector num 130 \return error code 131 */ 132 int32_t csi_norflash_erase_sector(norflash_handle_t handle, uint32_t addroffset, uint32_t num); 133 134 /** 135 \brief Erase complete Flash. 136 \param[in] handle norflash handle to operate. 137 \return error code 138 */ 139 int32_t csi_norflash_erase_chip(norflash_handle_t handle); 140 141 /** 142 \brief Get Flash information. 143 \param[in] handle norflash handle to operate. 144 \return Pointer to Flash information \ref norflash_info 145 */ 146 norflash_info *csi_norflash_get_info(norflash_handle_t handle); 147 148 /** 149 \brief Get NORFLASH status. 150 \param[in] handle norflash handle to operate. 151 \return NORFLASH status \ref norflash_status_t 152 */ 153 norflash_status_t csi_norflash_get_status(norflash_handle_t handle); 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif /* _CSI_NORFLASH_H_ */ 160