From 16ad24dd00ba1c9718f07deeab16b513a4eff3e4 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 6 Apr 2020 18:27:48 +1000 Subject: [PATCH] efuse: Add an API to return the efuse descriptor for a key block's purpose field --- components/efuse/include/esp32s2/esp_efuse.h | 8 +++++++ components/efuse/include/esp_efuse.h | 11 +++++++--- components/efuse/src/esp32s2/esp_efuse_api.c | 22 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/components/efuse/include/esp32s2/esp_efuse.h b/components/efuse/include/esp32s2/esp_efuse.h index 52e86e921..30dcb5e80 100644 --- a/components/efuse/include/esp32s2/esp_efuse.h +++ b/components/efuse/include/esp32s2/esp_efuse.h @@ -56,6 +56,14 @@ typedef enum { EFUSE_BLK_MAX } esp_efuse_block_t; +struct esp_efuse_desc_s; + +/** + * @brief Given a key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY5, return + * efuse field for setting the key purpose + */ +const struct esp_efuse_desc_s **esp_efuse_get_purpose_field(esp_efuse_block_t block); + /** * @brief Type of coding scheme */ diff --git a/components/efuse/include/esp_efuse.h b/components/efuse/include/esp_efuse.h index aa20bf6c1..23d05712c 100644 --- a/components/efuse/include/esp_efuse.h +++ b/components/efuse/include/esp_efuse.h @@ -35,13 +35,18 @@ extern "C" { #define ESP_ERR_CODING (ESP_ERR_EFUSE + 0x04) /*!< Error while a encoding operation. */ /** -* @brief Structure eFuse field + * @brief Structure eFuse field */ -typedef struct { +struct esp_efuse_desc_s { esp_efuse_block_t efuse_block: 8; /**< Block of eFuse */ uint8_t bit_start; /**< Start bit [0..255] */ uint16_t bit_count; /**< Length of bit field [1..-]*/ -} esp_efuse_desc_t; +}; + +/** + * @brief Type definition for an eFuse field + */ +typedef struct esp_efuse_desc_s esp_efuse_desc_t; /** * @brief Reads bits from EFUSE field and writes it into an array. diff --git a/components/efuse/src/esp32s2/esp_efuse_api.c b/components/efuse/src/esp32s2/esp_efuse_api.c index 184d88338..ca15cbbcf 100644 --- a/components/efuse/src/esp32s2/esp_efuse_api.c +++ b/components/efuse/src/esp32s2/esp_efuse_api.c @@ -81,3 +81,25 @@ esp_efuse_coding_scheme_t esp_efuse_get_coding_scheme(esp_efuse_block_t blk) ESP_EARLY_LOGD(TAG, "coding scheme %d", scheme); return scheme; } + + +const esp_efuse_desc_t **esp_efuse_get_purpose_field(esp_efuse_block_t block) +{ + switch(block) { + case EFUSE_BLK_KEY0: + return ESP_EFUSE_KEY_PURPOSE_0; + case EFUSE_BLK_KEY1: + return ESP_EFUSE_KEY_PURPOSE_1; + case EFUSE_BLK_KEY2: + return ESP_EFUSE_KEY_PURPOSE_2; + case EFUSE_BLK_KEY3: + return ESP_EFUSE_KEY_PURPOSE_3; + case EFUSE_BLK_KEY4: + return ESP_EFUSE_KEY_PURPOSE_4; + case EFUSE_BLK_KEY5: + return ESP_EFUSE_KEY_PURPOSE_5; + default: + return NULL; + } +} +