1 2 // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 #include "soc/soc_caps.h" 17 18 #if SOC_APB_BACKUP_DMA 19 #include "esp_attr.h" 20 #include "freertos/FreeRTOS.h" 21 #include "freertos/portmacro.h" 22 #include "esp32c3/rom/apb_backup_dma.h" 23 24 static portMUX_TYPE s_apb_backup_dma_mutex = portMUX_INITIALIZER_UNLOCKED; 25 apb_backup_dma_lock(void)26static void IRAM_ATTR apb_backup_dma_lock(void) 27 { 28 if (xPortInIsrContext()) { 29 portENTER_CRITICAL_ISR(&s_apb_backup_dma_mutex); 30 } else { 31 portENTER_CRITICAL(&s_apb_backup_dma_mutex); 32 } 33 } 34 apb_backup_dma_unlock(void)35static void IRAM_ATTR apb_backup_dma_unlock(void) 36 { 37 if (xPortInIsrContext()) { 38 portEXIT_CRITICAL_ISR(&s_apb_backup_dma_mutex); 39 } else { 40 portEXIT_CRITICAL(&s_apb_backup_dma_mutex); 41 } 42 } 43 esp_apb_backup_dma_lock_init(void)44void esp_apb_backup_dma_lock_init(void) 45 { 46 ets_apb_backup_init_lock_func(apb_backup_dma_lock, apb_backup_dma_unlock); 47 } 48 #endif 49