1 /*
2  * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "soc/soc_caps.h"
8 #include "esp_attr.h"
9 #include "freertos/FreeRTOS.h"
10 #include "freertos/portmacro.h"
11 #include "esp32s3/rom/apb_backup_dma.h"
12 
13 static portMUX_TYPE s_apb_backup_dma_mutex = portMUX_INITIALIZER_UNLOCKED;
14 
apb_backup_dma_lock(void)15 static void IRAM_ATTR apb_backup_dma_lock(void)
16 {
17     if (xPortInIsrContext()) {
18         portENTER_CRITICAL_ISR(&s_apb_backup_dma_mutex);
19     } else {
20         portENTER_CRITICAL(&s_apb_backup_dma_mutex);
21     }
22 }
23 
apb_backup_dma_unlock(void)24 static void IRAM_ATTR apb_backup_dma_unlock(void)
25 {
26     if (xPortInIsrContext()) {
27         portEXIT_CRITICAL_ISR(&s_apb_backup_dma_mutex);
28     } else {
29         portEXIT_CRITICAL(&s_apb_backup_dma_mutex);
30     }
31 }
32 
esp_apb_backup_dma_lock_init(void)33 void esp_apb_backup_dma_lock_init(void)
34 {
35     ets_apb_backup_init_lock_func(apb_backup_dma_lock, apb_backup_dma_unlock);
36 }
37