1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides hal efuse \n 16 * 17 * History: \n 18 * 2022-07-26, Create file. \n 19 */ 20 21 #ifndef HAL_EFUSE_H 22 #define HAL_EFUSE_H 23 24 #include <stdint.h> 25 #include "common_def.h" 26 #include "errcode.h" 27 #include "efuse_porting.h" 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif /* __cplusplus */ 33 #endif /* __cplusplus */ 34 35 /** 36 * @defgroup drivers_hal_efuse_api Efuse API 37 * @ingroup drivers_hal_efuse 38 * @{ 39 */ 40 41 /** 42 * @if Eng 43 * @brief Init device for hal efuse. 44 * @retval ERRCODE_SUCC Success. 45 * @retval Other Failure. For details, see @ref errcode_t 46 * @else 47 * @brief HAL层EFUSE的初始化接口 48 * @retval ERRCODE_SUCC 成功 49 * @retval Other 失败,参考 @ref errcode_t 50 * @endif 51 */ 52 typedef errcode_t (*hal_efuse_init_t)(void); 53 54 /** 55 * @if Eng 56 * @brief Deinit device for hal efuse. 57 * @else 58 * @brief HAL层EFUSE的去初始化接口 59 * @endif 60 */ 61 typedef void (*hal_efuse_deinit_t)(void); 62 63 /** 64 * @if Eng 65 * @brief Flush select otp region, write the value in register to efuse. 66 * @param [in] region Select OTP region 67 * @retval ERRCODE_SUCC Success. 68 * @retval Other Failure. For details, see @ref errcode_t 69 * @else 70 * @brief HAL层EFUSE的刷新写入接口 71 * @param [in] region 选择OTP区域 72 * @retval ERRCODE_SUCC 成功 73 * @retval Other 失败,参考 @ref errcode_t 74 * @endif 75 */ 76 typedef errcode_t (*hal_efuse_flush_write_t)(hal_efuse_region_t region); 77 78 /** 79 * @if Eng 80 * @brief Refresh read region to read mode after write. 81 * @param [in] region Select OTP region 82 * @retval ERRCODE_SUCC Success. 83 * @retval Other Failure. For details, see @ref errcode_t 84 * @else 85 * @brief HAL层EFUSE的刷新读取接口 86 * @param [in] region 选择OTP区域 87 * @retval ERRCODE_SUCC 成功 88 * @retval Other 失败,参考 @ref errcode_t 89 * @endif 90 */ 91 typedef errcode_t (*hal_efuse_refresh_read_t)(hal_efuse_region_t region); 92 93 /** 94 * @if Eng 95 * @brief Reads the byte at the given OTP memory location 96 * @param [in] byte_address OTP byte address of the byte to be read 97 * @param [out] value OTP byte value of the byte to be read 98 * @retval ERRCODE_SUCC Success. 99 * @retval Other Failure. For details, see @ref errcode_t 100 * @else 101 * @brief HAL层EFUSE的读单字节接口 102 * @param [in] byte_address 要读取的字节的OTP字节地址 103 * @param [in] value 要读取的字节的OTP字节值. 104 * @retval ERRCODE_SUCC 成功 105 * @retval Other 失败,参考 @ref errcode_t 106 * @endif 107 */ 108 typedef errcode_t (*hal_efuse_read_byte_t)(uint32_t byte_address, uint8_t *value); 109 110 /** 111 * @if Eng 112 * @brief Writes the value to the given OTP memory location 113 * @param [in] byte_address The OTP byte address of the byte to write 114 * @param [in] value The OTP byte value of the byte to write 115 * @retval ERRCODE_SUCC Success. 116 * @retval Other Failure. For details, see @ref errcode_t 117 * @else 118 * @brief HAL层EFUSE的写单字节接口 119 * @param [in] byte_address 要写入的字节的OTP字节地址 120 * @param [in] value 要写入的字节的OTP字节值 121 * @retval ERRCODE_SUCC 成功 122 * @retval Other 失败,参考 @ref errcode_t 123 * @endif 124 */ 125 typedef errcode_t (*hal_efuse_write_byte_t)(uint32_t byte_address, uint8_t value); 126 127 /** 128 * @if Eng 129 * @brief Clear all write register to protect next efuse write. 130 * @param [in] region The region of OTP to write 131 * @else 132 * @brief HAL层EFUSE的清除写区域接口 133 * @param [in] region 要写入的OTP区域 134 * @endif 135 */ 136 typedef void (*hal_efuse_clear_all_write_regs_t)(hal_efuse_region_t region); 137 138 /** 139 * @if Eng 140 * @brief Writes the value to the given OTP memory location 141 * @param [in] address The byte address of OTP to write to 142 * @param [in] value The value to write to OTP memory 143 * @param [in] region The region of OTP to write 144 * @retval ERRCODE_SUCC Success. 145 * @retval Other Failure. For details, see @ref errcode_t 146 * @else 147 * @brief HAL层EFUSE的固定区域写接口 148 * @param [in] address 要写入的OTP的字节地址 149 * @param [in] value 要写入OTP内存的值 150 * @param [in] region 要写入的OTP区域 151 * @retval ERRCODE_SUCC 成功 152 * @retval Other 失败,参考 @ref errcode_t 153 * @endif 154 */ 155 typedef errcode_t (*hal_efuse_write_operation_t)(uint32_t address, uint8_t value, hal_efuse_region_t region); 156 157 /** 158 * @if Eng 159 * @brief Writes the buffer to the given OTP memory location 160 * @param [in] address The byte address of OTP to write to 161 * @param [in] buffer The buffer to write to OTP memory 162 * @param [in] length The length of buffer to write to OTP memory 163 * @retval ERRCODE_SUCC Success. 164 * @retval Other Failure. For details, see @ref errcode_t 165 * @else 166 * @brief HAL层EFUSE的缓冲区写接口 167 * @param [in] address 要写入的OTP的字节地址 168 * @param [in] buffer 要写入OTP存储器的缓冲区 169 * @param [in] length 要写入OTP内存的缓冲区长度 170 * @retval ERRCODE_SUCC 成功 171 * @retval Other 失败,参考 @ref errcode_t 172 * @endif 173 */ 174 typedef errcode_t (*hal_efuse_write_buffer_operation_t)(uint32_t address, const uint8_t *buffer, uint16_t length); 175 176 /** 177 * @if Eng 178 * @brief Obtains the die_id of the EFUSE. 179 * @param [out] buffer OTP byte value of the die id. 180 * @param [in] length The length of the die_id, in bytes. 181 * @retval ERRCODE_SUCC Success. 182 * @retval Other Failure. For details, see @ref errcode_t 183 * @else 184 * @brief 获取efuse的die_id。 185 * @param [in] buffer 包含要写入的数据的缓冲区 186 * @param [in] length die_id数据的长度,以字节为单位。 187 * @retval ERRCODE_SUCC 成功 188 * @retval Other 失败,参考 @ref errcode_t 189 * @endif 190 */ 191 typedef errcode_t (*hal_efuse_get_die_id_t)(uint8_t *buffer, uint16_t length); 192 193 /** 194 * @if Eng 195 * @brief Obtains the chip_id of the EFUSE. 196 * @param [out] buffer OTP byte value of the chip id. 197 * @param [in] length The length of the chip_id, in bytes. 198 * @retval ERRCODE_SUCC Success. 199 * @retval Other Failure. For details, see @ref errcode_t 200 * @else 201 * @brief 获取efuse的chip_id。 202 * @param [in] buffer 包含要写入的数据的缓冲区 203 * @param [in] length chip_id数据的长度,以字节为单位。 204 * @retval ERRCODE_SUCC 成功 205 * @retval Other 失败,参考 @ref errcode_t 206 * @endif 207 */ 208 typedef errcode_t (*hal_efuse_get_chip_id_t)(uint8_t *buffer, uint16_t length); 209 210 /** 211 * @if Eng 212 * @brief Interface between efuse driver and efuse hal. 213 * @else 214 * @brief Driver层EFUSE和HAL层EFUSE的接口 215 * @endif 216 */ 217 typedef struct { 218 hal_efuse_init_t init; /*!< @if Eng Init efuse interface. 219 @else HAL层EFUSE的初始化接口 @endif */ 220 hal_efuse_deinit_t deinit; /*!< @if Eng Deinit efuse interface. 221 @else HAL层EFUSE去初始化接口 @endif */ 222 hal_efuse_flush_write_t flush_write; /*!< @if Eng Flush select interface. 223 @else HAL层EFUSE的刷新选择EFUSE区域接口 @endif */ 224 hal_efuse_refresh_read_t refresh_read; /*!< @if Eng Refresh read region to read interface. 225 @else HAL层EFUSE写入后将读取区域刷新为读取模式的接口 @endif */ 226 hal_efuse_read_byte_t read_byte; /*!< @if Eng EFUSE byte read interface. 227 @else HAL层EFUSE的单字节读接口 @endif */ 228 hal_efuse_write_byte_t write_byte; /*!< @if Eng EFUSE byte write interface. 229 @else HAL层EFUSE的单字节写接口 @endif */ 230 hal_efuse_clear_all_write_regs_t clear; /*!< @if Eng Clear all write register interface. 231 @else HAL层EFUSE的清除所有写入寄存器接口 @endif */ 232 hal_efuse_write_operation_t write_op; /*!< @if Eng Writes the value to the OTPinterface. 233 @else HAL层EFUSE的将值写入给定的OTP内存位置接口 @endif */ 234 hal_efuse_write_buffer_operation_t write_buffer_op; /*!< @if Eng Writes the buffer to the OTP interface. 235 @else HAL层EFUSE的将缓冲区写入给定的OTP内存位置接口 @endif */ 236 hal_efuse_get_die_id_t get_die_id; /*!< @if Eng Interface for Obtaining the Die ID. 237 @else HAL层EFUSE的获取die_id接口 @endif */ 238 hal_efuse_get_chip_id_t get_chip_id; /*!< @if Eng Interface for Obtaining the Chip ID. 239 @else HAL层EFUSE的获取chip_id接口 @endif */ 240 } hal_efuse_funcs_t; 241 242 /** 243 * @if Eng 244 * @brief Register @ref hal_efuse_funcs_t into the g_hal_efuses_funcs. 245 * @param [in] funcs Interface between efuse driver and efuse hal. 246 * @retval ERRCODE_SUCC Success. 247 * @retval Other Failure. For details, see @ref errcode_t 248 * @else 249 * @brief 注册 @ref hal_efuse_funcs_t 到 g_hal_efuses_funcs 250 * @param [in] funcs Driver层EFUSE和HAL层EFUSE的接口实例 251 * @retval ERRCODE_SUCC 成功 252 * @retval Other 失败,参考 @ref errcode_t 253 * @endif 254 */ 255 errcode_t hal_efuse_register_funcs(hal_efuse_funcs_t *funcs); 256 257 /** 258 * @if Eng 259 * @brief Unregister @ref hal_efuse_funcs_t into the g_hal_efuses_funcs. 260 * @retval ERRCODE_SUCC Success. 261 * @retval Other Failure. For details, see @ref errcode_t 262 * @else 263 * @brief 注册 @ref hal_efuse_funcs_t 到 g_hal_efuses_funcs 264 * @retval ERRCODE_SUCC 成功 265 * @retval Other 失败,参考 @ref errcode_t 266 * @endif 267 */ 268 errcode_t hal_efuse_unregister_funcs(void); 269 270 /** 271 * @if Eng 272 * @brief Get interface between efuse driver and efuse hal, see @ref hal_efuse_funcs_t. 273 * @return Interface between efuse driver and efuse hal, see @ref hal_efuse_funcs_t. 274 * @else 275 * @brief 获取Driver层EFUSE和HAL层EFUSE的接口实例,参考 @ref hal_efuse_funcs_t. 276 * @return Driver层EFUSE和HAL层EFUSE的接口实例,参考 @ref hal_efuse_funcs_t. 277 * @endif 278 */ 279 hal_efuse_funcs_t *hal_efuse_get_funcs(void); 280 281 /** 282 * @} 283 */ 284 285 #ifdef __cplusplus 286 #if __cplusplus 287 } 288 #endif /* __cplusplus */ 289 #endif /* __cplusplus */ 290 291 #endif 292