1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file drv_efusec.h 7 * @brief header file for efusec driver 8 * @version V1.0 9 * @date 22. Mar 2019 10 * @model efusec 11 ******************************************************************************/ 12 #ifndef _CSI_EFUSEC_H_ 13 #define _CSI_EFUSEC_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 efusec handle. 24 typedef void *efusec_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 page_size; ///< Optimal programming page size in bytes 33 uint32_t program_unit; ///< Smallest programmable unit in bytes 34 } efusec_info_t; 35 36 /** 37 \brief Flash Status 38 */ 39 typedef struct { 40 uint32_t mode : 1; ///< 0: read mode 1: program mode 41 uint32_t lock_shadow : 1; ///< lock shadow regs 42 uint32_t lock_efuse : 1; ///< lock efusec 43 } efusec_status_t; 44 45 typedef enum { 46 EFUSEC_LOCK_SHADOW = 0, ///< all shadow regs can’t be programmed 47 EFUSEC_LOCK_EFUSE ///< all Efuse can’t be programmed 48 } efusec_lock_e; 49 50 /** 51 \brief Flash Driver Capabilities. 52 */ 53 typedef struct { 54 uint32_t lock_shadow : 1; ///< Supports lock shadow operation 55 } efusec_capabilities_t; 56 57 // Function documentation 58 59 /** 60 \brief Initialize EFUSEC Interface. 1. Initializes the resources needed for the EFUSEC interface 61 \param[in] idx device id 62 \return pointer to efusec handle 63 */ 64 efusec_handle_t drv_efusec_initialize(int32_t idx); 65 66 /** 67 \brief De-initialize EFUSEC Interface. stops operation and releases the software resources used by the interface 68 \param[in] handle efusec handle to operate. 69 \return error code 70 */ 71 int32_t csi_efusec_uninitialize(efusec_handle_t handle); 72 73 /** 74 \brief Get driver capabilities. 75 \param[in] idx device id 76 \return \ref efusec_capabilities_t 77 */ 78 efusec_capabilities_t drv_efusec_get_capabilities(int32_t idx); 79 80 /** 81 \brief control efusec power. 82 \param[in] handle efusec handle to operate. 83 \param[in] state power state.\ref csi_power_stat_e. 84 \return error code 85 */ 86 int32_t drv_efusec_power_control(efusec_handle_t handle, csi_power_stat_e state); 87 88 /** 89 \brief Read data from Flash. 90 \param[in] handle efusec handle to operate. 91 \param[in] addr Data address. 92 \param[out] data Pointer to a buffer storing the data read from Flash. 93 \param[in] cnt Number of data items to read. 94 \return number of data items read or error code 95 */ 96 int32_t drv_efusec_read(efusec_handle_t handle, uint32_t addr, void *data, uint32_t cnt); 97 98 /** 99 \brief Program data to Flash. 100 \param[in] handle efusec handle to operate. 101 \param[in] addr Data address. 102 \param[in] data Pointer to a buffer containing the data to be programmed to Flash. 103 \param[in] cnt Number of data items to program. 104 \return number of data items programmed or error code 105 */ 106 int32_t drv_efusec_program(efusec_handle_t handle, uint32_t addr, const void *data, uint32_t cnt); 107 108 /** 109 \brief lock efusec. 110 \param[in] handle efusec handle to operate. 111 \param[in] lock efusec lock type \ref efusec_lock_e. 112 \return error code 113 */ 114 int32_t drv_efusec_lock(efusec_handle_t handle, efusec_lock_e lock); 115 116 /** 117 \brief Get Flash information. 118 \param[in] handle efusec handle to operate. 119 \return Pointer to Flash information \ref efusec_info_t 120 */ 121 efusec_info_t *drv_efusec_get_info(efusec_handle_t handle); 122 /** 123 \brief Get FLASH status. 124 \param[in] handle efusec handle to operate. 125 \return EFUSEC status \ref efusec_status_t 126 */ 127 efusec_status_t drv_efusec_get_status(efusec_handle_t handle); 128 129 #ifdef __cplusplus 130 } 131 #endif 132 133 #endif /* _CSI_EFUSEC_H_ */ 134