|
|
@@ -177,24 +177,31 @@ static IRAM_ATTR void esp_aes_complete_isr(void *arg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static esp_err_t esp_aes_isr_initialise( void )
|
|
|
+void esp_aes_intr_alloc(void)
|
|
|
{
|
|
|
- aes_hal_interrupt_clear();
|
|
|
- aes_hal_interrupt_enable(true);
|
|
|
if (op_complete_sem == NULL) {
|
|
|
- op_complete_sem = xSemaphoreCreateBinary();
|
|
|
-
|
|
|
- if (op_complete_sem == NULL) {
|
|
|
- ESP_LOGE(TAG, "Failed to create intr semaphore");
|
|
|
- return ESP_FAIL;
|
|
|
- }
|
|
|
const int isr_flags = esp_intr_level_to_flags(CONFIG_MBEDTLS_AES_INTERRUPT_LEVEL);
|
|
|
|
|
|
esp_err_t ret = esp_intr_alloc(ETS_AES_INTR_SOURCE, isr_flags, esp_aes_complete_isr, NULL, NULL);
|
|
|
if (ret != ESP_OK) {
|
|
|
- return ret;
|
|
|
+ ESP_LOGE(TAG, "Failed to allocate AES interrupt %d", ret);
|
|
|
+ // This should be treated as fatal error as this API would mostly
|
|
|
+ // be invoked within mbedTLS interface. There is no way for the system
|
|
|
+ // to proceed if the AES interrupt allocation fails here.
|
|
|
+ abort();
|
|
|
}
|
|
|
+
|
|
|
+ static StaticSemaphore_t op_sem_buf;
|
|
|
+ op_complete_sem = xSemaphoreCreateBinaryStatic(&op_sem_buf);
|
|
|
+ // Static semaphore creation is unlikley to fail but still basic sanity
|
|
|
+ assert(op_complete_sem != NULL);
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+static esp_err_t esp_aes_isr_initialise( void )
|
|
|
+{
|
|
|
+ aes_hal_interrupt_clear();
|
|
|
+ aes_hal_interrupt_enable(true);
|
|
|
|
|
|
/* AES is clocked proportionally to CPU clock, take power management lock */
|
|
|
#ifdef CONFIG_PM_ENABLE
|
|
|
@@ -433,7 +440,7 @@ static int esp_aes_process_dma(esp_aes_context *ctx, const unsigned char *input,
|
|
|
/* Only use interrupt for long AES operations */
|
|
|
if (len > AES_DMA_INTR_TRIG_LEN) {
|
|
|
use_intr = true;
|
|
|
- if (esp_aes_isr_initialise() == ESP_FAIL) {
|
|
|
+ if (esp_aes_isr_initialise() != ESP_OK) {
|
|
|
ESP_LOGE(TAG, "ESP-AES ISR initialisation failed");
|
|
|
ret = -1;
|
|
|
goto cleanup;
|
|
|
@@ -576,7 +583,7 @@ int esp_aes_process_dma_gcm(esp_aes_context *ctx, const unsigned char *input, un
|
|
|
/* Only use interrupt for long AES operations */
|
|
|
if (len > AES_DMA_INTR_TRIG_LEN) {
|
|
|
use_intr = true;
|
|
|
- if (esp_aes_isr_initialise() == ESP_FAIL) {
|
|
|
+ if (esp_aes_isr_initialise() != ESP_OK) {
|
|
|
ESP_LOGE(TAG, "ESP-AES ISR initialisation failed");
|
|
|
ret = -1;
|
|
|
goto cleanup;
|