1 /*
2  * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "esp_efuse.h"
8 #include "esp_efuse_utility.h"
9 #include "esp_efuse_table.h"
10 #include "stdlib.h"
11 #include "esp_types.h"
12 #include "esp32c6/rom/efuse.h"
13 #include "assert.h"
14 #include "esp_err.h"
15 #include "esp_log.h"
16 #include "soc/efuse_periph.h"
17 #include "sys/param.h"
18 
19 static __attribute__((unused)) const char *TAG = "efuse";
20 
21 // Contains functions that provide access to efuse fields which are often used in IDF.
22 
23 // Returns chip package from efuse
esp_efuse_get_pkg_ver(void)24 uint32_t esp_efuse_get_pkg_ver(void)
25 {
26     uint32_t pkg_ver = 0;
27     esp_efuse_read_field_blob(ESP_EFUSE_PKG_VERSION, &pkg_ver, ESP_EFUSE_PKG_VERSION[0]->bit_count);
28     return pkg_ver;
29 }
30 
31 
esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme)32 esp_err_t esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme)
33 {
34     int cur_log_scheme = 0;
35     esp_efuse_read_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &cur_log_scheme, 2);
36     if (!cur_log_scheme) { // not burned yet
37         return esp_efuse_write_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &log_scheme, 2);
38     } else {
39         return ESP_ERR_INVALID_STATE;
40     }
41 }
42 
esp_efuse_disable_rom_download_mode(void)43 esp_err_t esp_efuse_disable_rom_download_mode(void)
44 {
45     return esp_efuse_write_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE);
46 }
47 
esp_efuse_enable_rom_secure_download_mode(void)48 esp_err_t esp_efuse_enable_rom_secure_download_mode(void)
49 {
50     if (esp_efuse_read_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE)) {
51         return ESP_ERR_INVALID_STATE;
52     }
53     return esp_efuse_write_field_bit(ESP_EFUSE_ENABLE_SECURITY_DOWNLOAD);
54 }
55