74
74
busy-waiting, 30000 bytes is approx 0.5 ms */
75
75
#define AES_DMA_INTR_TRIG_LEN 2000
76
76
77
+ /* With buffers in PSRAM (worst condition) we still achieve a speed of 4 MB/s
78
+ thus a 2 second timeout value should be suffient for even very large buffers.
79
+ */
80
+ #define AES_WAIT_INTR_TIMEOUT_MS 2000
77
81
78
82
#if defined(CONFIG_MBEDTLS_AES_USE_INTERRUPT )
79
83
static SemaphoreHandle_t op_complete_sem ;
@@ -209,14 +213,14 @@ static esp_err_t esp_aes_isr_initialise( void )
209
213
#endif // CONFIG_MBEDTLS_AES_USE_INTERRUPT
210
214
211
215
/* Wait for AES hardware block operation to complete */
212
- static void esp_aes_dma_wait_complete (bool use_intr , lldesc_t * output_desc )
216
+ static int esp_aes_dma_wait_complete (bool use_intr , lldesc_t * output_desc )
213
217
{
214
218
#if defined (CONFIG_MBEDTLS_AES_USE_INTERRUPT )
215
219
if (use_intr ) {
216
- if (!xSemaphoreTake (op_complete_sem , 2000 / portTICK_PERIOD_MS )) {
220
+ if (!xSemaphoreTake (op_complete_sem , AES_WAIT_INTR_TIMEOUT_MS / portTICK_PERIOD_MS )) {
217
221
/* indicates a fundamental problem with driver */
218
- ESP_LOGE ("AES" , "Timed out waiting for completion of AES Interrupt" );
219
- abort () ;
222
+ ESP_LOGE (TAG , "Timed out waiting for completion of AES Interrupt" );
223
+ return -1 ;
220
224
}
221
225
#ifdef CONFIG_PM_ENABLE
222
226
esp_pm_lock_release (s_pm_cpu_lock );
@@ -230,6 +234,7 @@ static void esp_aes_dma_wait_complete(bool use_intr, lldesc_t *output_desc)
230
234
aes_hal_wait_done ();
231
235
232
236
esp_aes_wait_dma_done (output_desc );
237
+ return 0 ;
233
238
}
234
239
235
240
@@ -436,7 +441,12 @@ static int esp_aes_process_dma(esp_aes_context *ctx, const unsigned char *input,
436
441
}
437
442
438
443
aes_hal_transform_dma_start (blocks );
439
- esp_aes_dma_wait_complete (use_intr , out_desc_tail );
444
+
445
+ if (esp_aes_dma_wait_complete (use_intr , out_desc_tail ) < 0 ) {
446
+ ESP_LOGE (TAG , "esp_aes_dma_wait_complete failed" );
447
+ ret = -1 ;
448
+ goto cleanup ;
449
+ }
440
450
441
451
#if (CONFIG_SPIRAM && SOC_PSRAM_DMA_CAPABLE )
442
452
if (block_bytes > 0 ) {
@@ -561,7 +571,11 @@ int esp_aes_process_dma_gcm(esp_aes_context *ctx, const unsigned char *input, un
561
571
562
572
aes_hal_transform_dma_gcm_start (blocks );
563
573
564
- esp_aes_dma_wait_complete (use_intr , out_desc_head );
574
+ if (esp_aes_dma_wait_complete (use_intr , out_desc_head ) < 0 ) {
575
+ ESP_LOGE (TAG , "esp_aes_dma_wait_complete failed" );
576
+ ret = -1 ;
577
+ goto cleanup ;
578
+ }
565
579
566
580
aes_hal_transform_dma_finish ();
567
581
0 commit comments