cp_dma_hal.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "soc/soc_caps.h"
  15. #include "hal/cp_dma_hal.h"
  16. #include "hal/cp_dma_ll.h"
  17. void cp_dma_hal_init(cp_dma_hal_context_t *hal, const cp_dma_hal_config_t *config)
  18. {
  19. hal->dev = &CP_DMA;
  20. cp_dma_ll_enable_clock(hal->dev, true);
  21. cp_dma_ll_reset_in_link(hal->dev);
  22. cp_dma_ll_reset_out_link(hal->dev);
  23. cp_dma_ll_reset_cmd_fifo(hal->dev);
  24. cp_dma_ll_reset_fifo(hal->dev);
  25. cp_dma_ll_enable_intr(hal->dev, UINT32_MAX, false);
  26. cp_dma_ll_clear_intr_status(hal->dev, UINT32_MAX);
  27. cp_dma_ll_enable_owner_check(hal->dev, true);
  28. }
  29. void cp_dma_hal_set_desc_base_addr(cp_dma_hal_context_t *hal, intptr_t outlink_base, intptr_t inlink_base)
  30. {
  31. /* set base address of the first descriptor */
  32. cp_dma_ll_tx_set_descriptor_base_addr(hal->dev, outlink_base);
  33. cp_dma_ll_rx_set_descriptor_base_addr(hal->dev, inlink_base);
  34. }
  35. void cp_dma_hal_deinit(cp_dma_hal_context_t *hal)
  36. {
  37. cp_dma_ll_enable_clock(hal->dev, false);
  38. hal->dev = NULL;
  39. }
  40. void cp_dma_hal_start(cp_dma_hal_context_t *hal)
  41. {
  42. // enable DMA engine
  43. cp_dma_ll_start_rx(hal->dev, true);
  44. cp_dma_ll_start_tx(hal->dev, true);
  45. // enable RX EOF interrupt
  46. cp_dma_ll_enable_intr(hal->dev, CP_DMA_LL_EVENT_RX_EOF, true);
  47. }
  48. void cp_dma_hal_stop(cp_dma_hal_context_t *hal)
  49. {
  50. // disable interrupt
  51. cp_dma_ll_enable_intr(hal->dev, CP_DMA_LL_EVENT_RX_EOF, false);
  52. // disable DMA
  53. cp_dma_ll_start_rx(hal->dev, false);
  54. cp_dma_ll_start_tx(hal->dev, false);
  55. }
  56. uint32_t cp_dma_hal_get_intr_status(cp_dma_hal_context_t *hal)
  57. {
  58. return cp_dma_ll_get_intr_status(hal->dev);
  59. }
  60. void cp_dma_hal_clear_intr_status(cp_dma_hal_context_t *hal, uint32_t mask)
  61. {
  62. cp_dma_ll_clear_intr_status(hal->dev, mask);
  63. }
  64. void cp_dma_hal_restart_tx(cp_dma_hal_context_t *hal)
  65. {
  66. cp_dma_ll_restart_tx(hal->dev);
  67. }
  68. void cp_dma_hal_restart_rx(cp_dma_hal_context_t *hal)
  69. {
  70. cp_dma_ll_restart_rx(hal->dev);
  71. }