1 /** 2 ****************************************************************************** 3 * @file bl808_ef_ctrl.h 4 * @version V1.0 5 * @date 6 * @brief This file is the standard driver header file 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© COPYRIGHT(c) 2020 Bouffalo Lab</center></h2> 11 * 12 * Redistribution and use in source and binary forms, with or without modification, 13 * are permitted provided that the following conditions are met: 14 * 1. Redistributions of source code must retain the above copyright notice, 15 * this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright notice, 17 * this list of conditions and the following disclaimer in the documentation 18 * and/or other materials provided with the distribution. 19 * 3. Neither the name of Bouffalo Lab nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 ****************************************************************************** 35 */ 36 #ifndef __BL808_EF_CTRL_H__ 37 #define __BL808_EF_CTRL_H__ 38 39 #include "ef_ctrl_reg.h" 40 #include "bl808_common.h" 41 42 /** @addtogroup BL808_Peripheral_Driver 43 * @{ 44 */ 45 46 /** @addtogroup EF_CTRL 47 * @{ 48 */ 49 50 /** @defgroup EF_CTRL_Public_Types 51 * @{ 52 */ 53 54 /** 55 * @brief Efuse Ctrl key slot type definition 56 */ 57 typedef enum { 58 EF_CTRL_KEY_SLOT0, /*!< key slot 0 */ 59 EF_CTRL_KEY_SLOT1, /*!< key slot 1 */ 60 EF_CTRL_KEY_SLOT2, /*!< key slot 2 */ 61 EF_CTRL_KEY_SLOT3, /*!< key slot 3 */ 62 EF_CTRL_KEY_SLOT4, /*!< key slot 4 */ 63 EF_CTRL_KEY_SLOT5, /*!< key slot 5 */ 64 EF_CTRL_KEY_MAX, /*!< */ 65 } EF_Ctrl_Key_Type; 66 67 /** 68 * @brief Efuse Ctrl sign type definition 69 */ 70 typedef enum { 71 EF_CTRL_SIGN_NONE, /*!< no sign */ 72 EF_CTRL_SIGN_RSA, /*!< use RSA to sign */ 73 EF_CTRL_SIGN_ECC, /*!< use ECC to sign */ 74 } EF_Ctrl_Sign_Type; 75 76 /** 77 * @brief Efuse Ctrl flash AES type definition 78 */ 79 typedef enum { 80 EF_CTRL_SF_AES_NONE, /*!< No AES */ 81 EF_CTRL_SF_AES_128, /*!< AES 128 */ 82 EF_CTRL_SF_AES_192, /*!< AES 192 */ 83 EF_CTRL_SF_AES_256, /*!< AES 256 */ 84 } EF_Ctrl_SF_AES_Type; 85 86 /** 87 * @brief Efuse Ctrl Dbg type definition 88 */ 89 typedef enum { 90 EF_CTRL_DBG_OPEN = 0, /*!< Open debug */ 91 EF_CTRL_DBG_PASSWORD, /*!< Open debug with password */ 92 EF_CTRL_DBG_CLOSE = 4, /*!< Close debug */ 93 } EF_Ctrl_Dbg_Mode_Type; 94 95 /** 96 * @brief Efuse Ctrl clock type definition 97 */ 98 typedef enum { 99 EF_CTRL_EF_CLK, /*!< Select efuse clock */ 100 EF_CTRL_SAHB_CLK, /*!< Select SAHB clock */ 101 } EF_Ctrl_CLK_Type; 102 103 /** 104 * @brief Efuse Ctrl clock type definition 105 */ 106 typedef enum { 107 EF_CTRL_PARA_DFT, /*!< Select default cyc parameter */ 108 EF_CTRL_PARA_MANUAL, /*!< Select manual cyc parameter */ 109 } EF_Ctrl_CYC_PARA_Type; 110 111 /** 112 * @brief Efuse Ctrl clock type definition 113 */ 114 typedef enum { 115 EF_CTRL_OP_MODE_AUTO, /*!< Select efuse program auto mode */ 116 EF_CTRL_OP_MODE_MANUAL, /*!< Select efuse program manual mode */ 117 } EF_Ctrl_OP_MODE_Type; 118 119 /** 120 * @brief Efuse Ctrl secure configuration structure type definition 121 */ 122 typedef struct 123 { 124 EF_Ctrl_Dbg_Mode_Type ef_dbg_mode; /*!< Efuse debug mode */ 125 uint8_t ef_dbg_jtag_0_dis; /*!< Jtag debug disable config value */ 126 uint8_t ef_dbg_jtag_1_dis; /*!< Jtag debug disable config value */ 127 uint8_t ef_sboot_en; /*!< Secure boot enable config value */ 128 } EF_Ctrl_Sec_Param_Type; 129 130 /** 131 * @brief Efuse analog dcdc11 trim type definition 132 */ 133 typedef struct 134 { 135 uint32_t trimDcdc11VoutAon : 4; /*!< Efuse analog trim:dcdc11_vout_trim_aon */ 136 uint32_t trimDcdc11VoutAonParity : 1; /*!< Efuse analog trim:dcdc11_vout_trim_aon_parity */ 137 uint32_t trimDcdc11VoutAonEn : 1; /*!< Efuse analog trim:dcdc11_vout_trim_aon_en */ 138 uint32_t reserved : 26; /*!< Efuse analog trim:reserved */ 139 } Efuse_Ana_DCDC11_Trim_Type; 140 141 /** 142 * @brief Efuse analog dcdc18 trim type definition 143 */ 144 typedef struct 145 { 146 uint32_t trimDcdc18VoutAon : 4; /*!< Efuse analog trim:dcdc18_vout_trim_aon */ 147 uint32_t trimDcdc18VoutAonParity : 1; /*!< Efuse analog trim:dcdc18_vout_trim_aon_parity */ 148 uint32_t trimDcdc18VoutAonEn : 1; /*!< Efuse analog trim:dcdc18_vout_trim_aon_en */ 149 uint32_t reserved : 26; /*!< Efuse analog trim:reserved */ 150 } Efuse_Ana_DCDC18_Trim_Type; 151 152 /** 153 * @brief Efuse analog ldo18flash trim type definition 154 */ 155 typedef struct 156 { 157 uint32_t trimLdo18flashVoutAon : 4; /*!< Efuse analog trim:ldo18flash_vout_trim */ 158 uint32_t trimLdo18flashVoutAonParity : 1; /*!< Efuse analog trim:ldo18flash_vout_trim_parity */ 159 uint32_t trimLdo18flashVoutAonEn : 1; /*!< Efuse analog trim:ldo18flash_vout_trim_en */ 160 uint32_t reserved : 26; /*!< Efuse analog trim:reserved */ 161 } Efuse_Ana_LDO18FLASH_Trim_Type; 162 163 /** 164 * @brief Efuse analog usb20rcal trim type definition 165 */ 166 typedef struct 167 { 168 uint32_t trimUsb20rcalAon : 6; /*!< Efuse analog trim:usb20_rcal_code_aon */ 169 uint32_t trimUsb20rcalAonParity : 1; /*!< Efuse analog trim:usb20_rcal_code_aon_parity */ 170 uint32_t trimUsb20rcalAonEn : 1; /*!< Efuse analog trim:usb20_rcal_code_aon_en */ 171 uint32_t reserved : 24; /*!< Efuse analog trim:reserved */ 172 } Efuse_Ana_USB20RCAL_Trim_Type; 173 174 /** 175 * @brief Efuse analog RC32M trim type definition 176 */ 177 typedef struct 178 { 179 uint32_t trimRc32mCodeFrExt : 8; /*!< Efuse analog trim:trim_rc32m_code_fr_ext */ 180 uint32_t trimRc32mCodeFrExtParity : 1; /*!< Efuse analog trim:trim_rc32m_ext_code_en_parity */ 181 uint32_t trimRc32mExtCodeEn : 1; /*!< Efuse analog trim:trim_rc32m_ext_code_en */ 182 uint32_t reserved : 22; /*!< Efuse analog trim:reserved */ 183 } Efuse_Ana_RC32M_Trim_Type; 184 185 /** 186 * @brief Efuse analog RC32K trim type definition 187 */ 188 typedef struct 189 { 190 uint32_t trimRc32kCodeFrExt : 10; /*!< Efuse analog trim:trim_rc32k_code_fr_ext */ 191 uint32_t trimRc32kCodeFrExtParity : 1; /*!< Efuse analog trim:trim_rc32k_code_fr_ext_parity */ 192 uint32_t trimRc32kExtCodeEn : 1; /*!< Efuse analog trim:trim_rc32k_ext_code_en */ 193 uint32_t reserved : 20; /*!< Efuse analog trim:reserved */ 194 } Efuse_Ana_RC32K_Trim_Type; 195 196 typedef struct 197 { 198 uint32_t trimLdo18ioVoutVal : 4; /*!< Efuse analog trim:trim_ldo18io_vout_val */ 199 uint32_t trimLdo18ioVoutParity : 1; /*!< Efuse analog trim:trim_ldo18io_vout_parity */ 200 uint32_t trimLdo18ioVoutEn : 1; /*!< Efuse analog trim:trim_ldo18io_vout_en */ 201 uint32_t reserved : 26; /*!< Efuse analog trim:reserved */ 202 } Efuse_Ana_LDO18IO_VOUT_Trim_Type; 203 204 /** 205 * @brief Efuse analog TSEN trim type definition 206 */ 207 typedef struct 208 { 209 uint32_t tsenRefcodeCorner : 12; /*!< TSEN refcode */ 210 uint32_t tsenRefcodeCornerParity : 1; /*!< TSEN refcode parity */ 211 uint32_t tsenRefcodeCornerEn : 1; /*!< TSEN refcode enable */ 212 uint32_t tsenRefcodeCornerVersion : 1; /*!< TSEN refcode version */ 213 uint32_t reserved : 17; /*!< TSEN analog trim:reserved */ 214 } Efuse_TSEN_Refcode_Corner_Type; 215 216 /** 217 * @brief Efuse analog ADC Gain trim type definition 218 */ 219 typedef struct 220 { 221 uint32_t adcGainCoeff : 12; /*!< ADC gain coeff */ 222 uint32_t adcGainCoeffParity : 1; /*!< ADC gain coeff parity */ 223 uint32_t adcGainCoeffEn : 1; /*!< ADC gain coeff enable */ 224 uint32_t reserved : 18; /*!< ADC gain coeff:reserved */ 225 } Efuse_ADC_Gain_Coeff_Type; 226 227 /** 228 * @brief Efuse analog device info type definition 229 */ 230 typedef struct 231 { 232 uint32_t rsvd : 22; /*!< Reserved */ 233 uint32_t deviceInfo : 3; /*!< Efuse device information */ 234 uint32_t psramInfo : 2; /*!< Efuse psram info 0:no psram, 1:BW 4MB, 2:UHS 64MB */ 235 uint32_t memoryInfo : 2; /*!< Efuse memory info 0:no memory, 8:1MB flash */ 236 uint32_t chipInfo : 3; /*!< Efuse chip revision */ 237 } Efuse_Device_Info_Type; 238 239 /** 240 * @brief Efuse Capcode type definition 241 */ 242 typedef struct 243 { 244 uint32_t capCode : 6; /*!< Cap code value */ 245 uint32_t parity : 1; /*!< Parity of capcode */ 246 uint32_t en : 1; /*!< Enable status */ 247 uint32_t rsvd : 24; /*!< Reserved */ 248 } Efuse_Capcode_Info_Type; 249 250 /*@} end of group EF_CTRL_Public_Types */ 251 252 /** @defgroup EF_CTRL_Public_Constants 253 * @{ 254 */ 255 256 /** @defgroup EF_CTRL_KEY_TYPE 257 * @{ 258 */ 259 #define IS_EF_CTRL_KEY_TYPE(type) (((type) == EF_CTRL_KEY_SLOT0) || \ 260 ((type) == EF_CTRL_KEY_SLOT1) || \ 261 ((type) == EF_CTRL_KEY_SLOT2) || \ 262 ((type) == EF_CTRL_KEY_SLOT3) || \ 263 ((type) == EF_CTRL_KEY_SLOT4) || \ 264 ((type) == EF_CTRL_KEY_SLOT5) || \ 265 ((type) == EF_CTRL_KEY_MAX)) 266 267 /** @defgroup EF_CTRL_SIGN_TYPE 268 * @{ 269 */ 270 #define IS_EF_CTRL_SIGN_TYPE(type) (((type) == EF_CTRL_SIGN_NONE) || \ 271 ((type) == EF_CTRL_SIGN_RSA) || \ 272 ((type) == EF_CTRL_SIGN_ECC)) 273 274 /** @defgroup EF_CTRL_SF_AES_TYPE 275 * @{ 276 */ 277 #define IS_EF_CTRL_SF_AES_TYPE(type) (((type) == EF_CTRL_SF_AES_NONE) || \ 278 ((type) == EF_CTRL_SF_AES_128) || \ 279 ((type) == EF_CTRL_SF_AES_192) || \ 280 ((type) == EF_CTRL_SF_AES_256)) 281 282 /** @defgroup EF_CTRL_DBG_MODE_TYPE 283 * @{ 284 */ 285 #define IS_EF_CTRL_DBG_MODE_TYPE(type) (((type) == EF_CTRL_DBG_OPEN) || \ 286 ((type) == EF_CTRL_DBG_PASSWORD) || \ 287 ((type) == EF_CTRL_DBG_CLOSE)) 288 289 /** @defgroup EF_CTRL_CLK_TYPE 290 * @{ 291 */ 292 #define IS_EF_CTRL_CLK_TYPE(type) (((type) == EF_CTRL_EF_CLK) || \ 293 ((type) == EF_CTRL_SAHB_CLK)) 294 295 /** @defgroup EF_CTRL_CYC_PARA_TYPE 296 * @{ 297 */ 298 #define IS_EF_CTRL_CYC_PARA_TYPE(type) (((type) == EF_CTRL_PARA_DFT) || \ 299 ((type) == EF_CTRL_PARA_MANUAL)) 300 301 /** @defgroup EF_CTRL_OP_MODE_TYPE 302 * @{ 303 */ 304 #define IS_EF_CTRL_OP_MODE_TYPE(type) (((type) == EF_CTRL_OP_MODE_AUTO) || \ 305 ((type) == EF_CTRL_OP_MODE_MANUAL)) 306 307 /*@} end of group EF_CTRL_Public_Constants */ 308 309 /** @defgroup EF_CTRL_Public_Macros 310 * @{ 311 */ 312 #define EF_CTRL_EFUSE_R0_SIZE 128 313 #define EF_CTRL_EFUSE_R1_SIZE 128 314 315 /*@} end of group EF_CTRL_Public_Macros */ 316 317 /** @defgroup EF_CTRL_Public_Functions 318 * @{ 319 */ 320 /*----------*/ 321 BL_Err_Type EF_Ctrl_Get_Customer_PIDVID(uint16_t pid[1], uint16_t vid[1]); 322 /*----------*/ 323 void EF_Ctrl_Load_Efuse_R0(void); 324 void EF_Ctrl_Load_Efuse_R1(void); 325 void EF_Ctrl_Program_Efuse_0(void); 326 void EF_Ctrl_Program_Efuse_1(void); 327 BL_Sts_Type EF_Ctrl_Busy(void); 328 BL_Sts_Type EF_Ctrl_AutoLoad_Done(void); 329 void EF_Ctrl_Write_Dbg_Pwd(uint8_t slot, uint32_t passWdLow, uint32_t passWdHigh, uint8_t program); 330 void EF_Ctrl_Read_Dbg_Pwd(uint8_t slot, uint32_t *passWdLow, uint32_t *passWdHigh); 331 void EF_Ctrl_Readlock_Dbg_Pwd(uint8_t program); 332 void EF_Ctrl_Writelock_Dbg_Pwd(uint8_t program); 333 void EF_Ctrl_Write_Secure_Cfg(EF_Ctrl_Sec_Param_Type *cfg, uint8_t program); 334 void EF_Ctrl_Read_Secure_Cfg(EF_Ctrl_Sec_Param_Type *cfg); 335 void EF_Ctrl_Write_Secure_Boot(EF_Ctrl_Sign_Type sign[1], EF_Ctrl_SF_AES_Type aes[1], uint8_t program); 336 void EF_Ctrl_Read_Secure_Boot(EF_Ctrl_SF_AES_Type aes[2]); 337 void EF_Ctrl_Read_Xtal_Trim_RC32M(uint8_t *forceNoTrim, uint8_t *noXtal); 338 void EF_Ctrl_Set_sf_key_re_sel(uint8_t ef_sf_key_re_sel); 339 uint8_t EF_Ctrl_Get_Trim_Parity(uint32_t val, uint8_t len); 340 void EF_Ctrl_Read_DCDC11_Trim(Efuse_Ana_DCDC11_Trim_Type *trim); 341 void EF_Ctrl_Read_DCDC18_Trim(Efuse_Ana_DCDC18_Trim_Type *trim); 342 void EF_Ctrl_Read_LDO18FLASH_Trim(Efuse_Ana_LDO18FLASH_Trim_Type *trim); 343 void EF_Ctrl_Read_USB20RCAL_Trim(Efuse_Ana_USB20RCAL_Trim_Type *trim); 344 void EF_Ctrl_Read_RC32M_Trim(Efuse_Ana_RC32M_Trim_Type *trim); 345 void EF_Ctrl_Read_RC32K_Trim(Efuse_Ana_RC32K_Trim_Type *trim); 346 void EF_Ctrl_Read_LDO18IO_Vout_Trim(Efuse_Ana_LDO18IO_VOUT_Trim_Type *trim); 347 void EF_Ctrl_Read_TSEN_Trim(Efuse_TSEN_Refcode_Corner_Type *trim); 348 void EF_Ctrl_Read_ADC_Gain_Trim(Efuse_ADC_Gain_Coeff_Type *trim); 349 void EF_Ctrl_Write_Sw_Usage(uint32_t index, uint32_t usage, uint8_t program); 350 void EF_Ctrl_Read_Sw_Usage(uint32_t index, uint32_t *usage); 351 void EF_Ctrl_Writelock_Sw_Usage(uint32_t index, uint8_t program); 352 void EF_Ctrl_Write_MAC_Address(uint8_t mac[6], uint8_t program); 353 BL_Err_Type EF_Ctrl_Read_MAC_Address(uint8_t mac[6]); 354 BL_Err_Type EF_Ctrl_Read_MAC_Address_Raw(uint8_t mac[7]); 355 BL_Err_Type EF_Ctrl_Read_ZiggBee_MAC_Address(uint8_t mac[8]); 356 void EF_Ctrl_Writelock_MAC_Address(uint8_t program); 357 BL_Err_Type EF_Ctrl_Read_Chip_ID(uint8_t id[8]); 358 void EF_Ctrl_Write_AES_Key(uint8_t index, uint32_t *keyData, uint32_t len, uint8_t program); 359 void EF_Ctrl_Read_AES_Key(uint8_t index, uint32_t *keyData, uint32_t len); 360 void EF_Ctrl_Writelock_AES_Key(uint8_t index, uint8_t program); 361 void EF_Ctrl_Readlock_AES_Key(uint8_t index, uint8_t program); 362 void EF_Ctrl_Program_Direct(uint32_t offset, uint32_t *pword, uint32_t count); 363 void EF_Ctrl_Read_Direct(uint32_t offset, uint32_t *pword, uint32_t count); 364 void EF_Ctrl_Clear(uint8_t region, uint32_t index, uint32_t len); 365 void EF_Ctrl_Crc_Enable(void); 366 BL_Sts_Type EF_Ctrl_Crc_Is_Busy(void); 367 void EF_Ctrl_Crc_Set_Golden(uint32_t goldenValue); 368 BL_Err_Type EF_Ctrl_Crc_Result(void); 369 void EF_Ctrl_Sw_AHB_Clk_0(void); 370 void EF_Ctrl_Sw_AHB_Clk_1(void); 371 uint8_t EF_Ctrl_Is_All_Bits_Zero(uint32_t val, uint8_t start, uint8_t len); 372 373 /*@} end of group EF_CTRL_Public_Functions */ 374 375 /*@} end of group EF_CTRL */ 376 377 /*@} end of group BL808_Peripheral_Driver */ 378 379 #endif /* __BL808_EF_CTRL_H__ */ 380