• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 efuse driver \n
16  *
17  * History: \n
18  * 2022-07-26, Create file. \n
19  */
20 #ifndef EFUSE_H
21 #define EFUSE_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 
26 #ifdef __cplusplus
27 #if __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30 #endif /* __cplusplus */
31 
32 #define EFUSE_WRITE_PROTECT_FLAG            0x5A5A5A5A
33 /**
34  * @defgroup drivers_driver_efuse eFuse
35  * @ingroup  drivers_driver
36  * @{
37  */
38 
39 /**
40  * @if Eng
41  * @brief  Initialize the eFuse.
42  * @retval ERRCODE_SUCC Success.
43  * @retval Other        Failure. For details, see @ref errcode_t.
44  * @else
45  * @brief  初始化eFuse。
46  * @retval ERRCODE_SUCC 成功。
47  * @retval Other        失败,参考 @ref errcode_t 。
48  * @endif
49  */
50 errcode_t uapi_efuse_init(void);
51 
52 /**
53  * @if Eng
54  * @brief  Deinitialize the eFuse.
55  * @retval ERRCODE_SUCC Success.
56  * @retval Other        Failure. For details, see @ref errcode_t.
57  * @else
58  * @brief  去初始化eFuse。
59  * @retval ERRCODE_SUCC 成功。
60  * @retval Other        失败,参考 @ref errcode_t 。
61  * @endif
62  */
63 errcode_t uapi_efuse_deinit(void);
64 
65 #ifdef EFUSE_BIT_OPERATION
66 /**
67  * @if Eng
68  * @brief  Reads a bit from the eFuse.
69  * @param  [in] value The value of the bit read.
70  * @param  [in] byte_number The source OTP bit byte_number of the bit to be read.
71  * @param  [in] bit_pos Position of the bit.
72  * @retval ERRCODE_SUCC Success.
73  * @retval Other        Failure. For details, see @ref errcode_t.
74  * @else
75  * @brief  从eFuse中读取一位。
76  * @param  [in] value 读取的位值。
77  * @param  [in] byte_number 要读取位的源eFuse位地址。
78  * @param  [in] bit_pos 位的位置。
79  * @retval ERRCODE_SUCC 成功。
80  * @retval Other        失败,参考 @ref errcode_t 。
81  * @endif
82  */
83 errcode_t uapi_efuse_read_bit(uint8_t *value, uint32_t byte_number, uint8_t bit_pos);
84 #endif
85 
86 /**
87  * @if Eng
88  * @brief  Reads multiple bytes from the eFuse into the provided buffer.
89  * @param  [in] buffer The value of the bit read.
90  * @param  [in] byte_number The source eFuse bit byte_number of the bit to be read.
91  * @param  [in] length The length of the data, in bytes.
92  * @retval ERRCODE_SUCC Success.
93  * @retval Other        Failure. For details, see @ref errcode_t.
94  * @else
95  * @brief  从eFuse中读取多个字节,进入提供的缓冲区。
96  * @param  [in] buffer 保存读取数据的缓冲区。
97  * @param  [in] byte_number 要读取的数据的初始源eFuse字节地址。
98  * @param  [in] length 数据的长度,以字节为单位。
99  * @retval ERRCODE_SUCC 成功。
100  * @retval Other        失败,参考 @ref errcode_t 。
101  * @endif
102  */
103 errcode_t uapi_efuse_read_buffer(uint8_t *buffer, uint32_t byte_number, uint16_t length);
104 
105 #ifdef EFUSE_BIT_OPERATION
106 /**
107  * @if Eng
108  * @brief  Writes a bit to the eFuse.
109  * @param  [in] byte_number The destination OTP bit byte_number of the bit to be written.
110  * @param  [in] bit_pos A non-zero value indicates the bit will be set,
111            a zero value indicates a write should not actually occur.
112  * @retval ERRCODE_SUCC Success.
113  * @retval Other        Failure. For details, see @ref errcode_t.
114  * @else
115  * @brief  向eFuse写入一位。
116  * @param  [in] byte_number 要写入位的目标OTP位地址。
117  * @param  [in] bit_pos 非零值表示将设置该位。零值表示不应实际发生写入。
118  * @retval ERRCODE_SUCC 成功。
119  * @retval Other        失败,参考 @ref errcode_t 。
120  * @endif
121  */
122 errcode_t uapi_efuse_write_bit(uint32_t byte_number, uint8_t bit_pos);
123 
124 /**
125  * @if Eng
126  * @brief  Writes a bit to the eFuse when the protection flag is correct.
127  * @param  [in] byte_number The destination OTP bit byte_number of the bit to be written.
128  * @param  [in] bit_pos A non-zero value indicates the bit will be set,
129            a zero value indicates a write should not actually occur.
130  * @param  [in] flag protection flag.
131  * @retval ERRCODE_SUCC Success.
132  * @retval Other        Failure. For details, see @ref errcode_t.
133  * @else
134  * @brief  在保护标志正确的情况下向eFuse写入一位。
135  * @param  [in] byte_number 要写入位的目标OTP位地址。
136  * @param  [in] bit_pos 非零值表示将设置该位。零值表示不应实际发生写入。
137  * @param  [in] flag 保护标志。
138  * @retval ERRCODE_SUCC 成功。
139  * @retval Other        失败,参考 @ref errcode_t 。
140  * @endif
141  */
142 errcode_t uapi_efuse_write_bit_with_flag(uint32_t byte_number, uint8_t bit_pos, uint32_t flag);
143 #endif
144 
145 /**
146  * @if Eng
147  * @brief  Writes multiple bytes to the eFuse from the provided buffer.
148  * @param  [in] byte_number The initial destination eFuse byte byte_number of the data to be written.
149  * @param  [in] buffer A buffer containing the data to write.
150  * @param  [in] length The length of the data, in bytes.
151  * @retval ERRCODE_SUCC Success.
152  * @retval Other        Failure. For details, see @ref errcode_t.
153  * @else
154  * @brief  从提供的缓冲区向eFuse写入多个字节。
155  * @param  [in] byte_number 要写入数据的初始目的eFuse字节地址。
156  * @param  [in] buffer 包含要写入的数据的缓冲区。
157  * @param  [in] length 数据的长度,以字节为单位。
158  * @retval ERRCODE_SUCC 成功。
159  * @retval Other        失败,参考 @ref errcode_t 。
160  * @endif
161  */
162 errcode_t uapi_efuse_write_buffer(uint32_t byte_number, const uint8_t *buffer, uint16_t length);
163 
164 /**
165  * @if Eng
166  * @brief  Writes multiple bytes to the eFuse from the provided buffer when the protection flag is correct.
167  * @param  [in] byte_number The initial destination eFuse byte byte_number of the data to be written.
168  * @param  [in] buffer A buffer containing the data to write.
169  * @param  [in] length The length of the data, in bytes.
170  * @param  [in] flag protection flag.
171  * @retval ERRCODE_SUCC Success.
172  * @retval Other        Failure. For details, see @ref errcode_t.
173  * @else
174  * @brief  在保护标志正确的情况下从提供的缓冲区向eFuse写入多个字节。
175  * @param  [in] byte_number 要写入数据的初始目的eFuse字节地址。
176  * @param  [in] buffer 包含要写入的数据的缓冲区。
177  * @param  [in] length 数据的长度,以字节为单位。
178  * @param  [in] flag 保护标志。
179  * @retval ERRCODE_SUCC 成功。
180  * @retval Other        失败,参考 @ref errcode_t 。
181  * @endif
182  */
183 errcode_t uapi_efuse_write_buffer_with_flag(uint32_t byte_number, const uint8_t *buffer,
184                                             uint16_t length, uint32_t flag);
185 
186 /**
187  * @if Eng
188  * @brief  Obtains the Die-ID of the eFuse.
189  * @param  [out] buffer OTP byte value of the die id.
190  * @param  [in] length The length of the Die-ID, in bytes.
191  * @retval ERRCODE_SUCC Success.
192  * @retval Other        Failure. For details, see @ref errcode_t
193  * @else
194  * @brief  获取efuse的Die-ID。
195  * @param  [in] buffer 保存读取数据的缓冲区
196  * @param  [in] length Die-ID数据的长度,以字节为单位。
197  * @retval ERRCODE_SUCC 成功。
198  * @retval Other        失败,参考 @ref errcode_t 。
199  * @endif
200  */
201 errcode_t uapi_efuse_get_die_id(uint8_t *buffer, uint16_t length);
202 
203 /**
204  * @if Eng
205  * @brief  Obtains the Chip-ID of the eFuse.
206  * @param  [out] buffer OTP byte value of the chip id.
207  * @param  [in] length The length of the chip_id, in bytes.
208  * @retval ERRCODE_SUCC Success.
209  * @retval Other        Failure. For details, see @ref errcode_t.
210  * @else
211  * @brief  获取efuse的Chip-ID。
212  * @param  [in] buffer 保存读取数据的缓冲区。
213  * @param  [in] length Chip-ID数据的长度,以字节为单位。
214  * @retval ERRCODE_SUCC 成功。
215  * @retval Other        失败,参考 @ref errcode_t 。
216  * @endif
217  */
218 errcode_t uapi_efuse_get_chip_id(uint8_t *buffer, uint16_t length);
219 
220 /**
221  * @if Eng
222  * @brief  Calculate efuse zero-counting CRC for a block.
223  * @param  [in] buffer A buffer containing the data to write.
224  * @param  [in] length The length of the Chip-ID, in bytes.
225  * @param  [in] crc Buffer for storing CRC values.
226  * @retval ERRCODE_SUCC Success.
227  * @retval Other        Failure. For details, see @ref errcode_t.
228  * @else
229  * @brief  计算efuse零计数CRC。
230  * @param  [in] buffer 保存读取数据的缓冲区。
231  * @param  [in] length 数据长度,以字节为单位。
232  * @param  [in] crc 保存CRC值的缓冲区
233  * @retval ERRCODE_SUCC 成功。
234  * @retval Other        失败,参考 @ref errcode_t 。
235  * @endif
236  */
237 errcode_t uapi_efuse_calc_crc(const uint8_t *buffer, uint8_t length, uint8_t *crc);
238 
239 /**
240  * @if Eng
241  * @brief  Obtain SoC-ID.
242  * @param  [in]  id The address of the returned value, ID is a length of 20 uint8_t type array.
243  * @param  [in]  id_length The length of ID param, The length needs to be greater than 20 bytes.
244  * @else
245  * @brief  获取SoC-ID。
246  * @param  [in]  id 用于存储返回的ID,ID是一个长度为20字节的数组。
247  * @param  [in]  id_length ID数组的长度,这个长度必须是20字节以上的长度。
248  * @retval ERRCODE_SUCC 成功。
249  * @retval Other        失败,参考 @ref errcode_t 。
250  * @endif
251  */
252 errcode_t uapi_soc_read_id(uint8_t *id, uint16_t id_length);
253 /**
254  * @}
255  */
256 
257 #ifdef __cplusplus
258 #if __cplusplus
259 }
260 #endif /* __cplusplus */
261 #endif /* __cplusplus */
262 
263 #endif
264 
265