1 /* 2 * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /******************************************************************************* 8 * NOTICE 9 * The HAL is not public api, don't use in application code. 10 * See readme.md in soc/README.md 11 ******************************************************************************/ 12 13 // CP DMA HAL usages: 14 // 1. Initialize HAL layer by cp_dma_hal_init, pass in the allocated descriptors for TX and RX 15 // 2. Enable DMA and interrupt by cp_dma_hal_start 16 // 3. Prepare descriptors used for TX and RX 17 // 4. Restart the DMA engine in case it's not in working 18 19 #pragma once 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #include <stddef.h> 26 #include <stdbool.h> 27 #include "esp_attr.h" 28 #include "hal/dma_types.h" 29 #include "soc/cp_dma_struct.h" 30 31 /** 32 * @brief HAL context 33 * 34 */ 35 typedef struct { 36 cp_dma_dev_t *dev; 37 } cp_dma_hal_context_t; 38 39 typedef struct { 40 } cp_dma_hal_config_t; 41 42 /** 43 * @brief Initialize HAL layer context 44 * 45 * @param hal HAL layer context, whose memroy should be allocated at driver layer 46 * @param config configuration for the HAL layer 47 */ 48 void cp_dma_hal_init(cp_dma_hal_context_t *hal, const cp_dma_hal_config_t *config); 49 50 /** 51 * @brief Deinitialize HAL layer context 52 */ 53 void cp_dma_hal_deinit(cp_dma_hal_context_t *hal); 54 55 /** 56 * @brief Set descriptor base address 57 */ 58 void cp_dma_hal_set_desc_base_addr(cp_dma_hal_context_t *hal, intptr_t outlink_base, intptr_t inlink_base); 59 60 /** 61 * @brief Start mem2mem DMA state machine 62 */ 63 void cp_dma_hal_start(cp_dma_hal_context_t *hal); 64 65 /** 66 * @brief Stop mem2mem DMA state machine 67 */ 68 void cp_dma_hal_stop(cp_dma_hal_context_t *hal); 69 70 /** 71 * @brief Get interrupt status word 72 * 73 * @return uint32_t Interrupt status 74 */ 75 uint32_t cp_dma_hal_get_intr_status(cp_dma_hal_context_t *hal) IRAM_ATTR; 76 77 /** 78 * @brief Clear interrupt mask 79 * 80 * @param mask interrupt mask 81 */ 82 void cp_dma_hal_clear_intr_status(cp_dma_hal_context_t *hal, uint32_t mask) IRAM_ATTR; 83 84 /**@{*/ 85 /** 86 * @brief Give the owner of descriptors between [start_desc, end_desc] to DMA, and restart DMA HW engine 87 * 88 * @param hal HAL layer context 89 * @param start_desc The first descriptor that carries one transaction 90 * @param end_desc The last descriptor that carries one transaction 91 */ 92 void cp_dma_hal_restart_tx(cp_dma_hal_context_t *hal); 93 void cp_dma_hal_restart_rx(cp_dma_hal_context_t *hal); 94 /**@}*/ 95 96 #ifdef __cplusplus 97 } 98 #endif 99