parlio_private.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "sdkconfig.h"
  8. #include "freertos/FreeRTOS.h"
  9. #include "soc/soc_caps.h"
  10. #include "soc/gdma_channel.h"
  11. #include "hal/parlio_types.h"
  12. #include "hal/parlio_hal.h"
  13. #include "hal/parlio_ll.h"
  14. #include "hal/dma_types.h"
  15. #include "hal/cache_hal.h"
  16. #include "hal/cache_ll.h"
  17. #include "rom/cache.h"
  18. #include "esp_heap_caps.h"
  19. #include "driver/parlio_types.h"
  20. #include "esp_private/periph_ctrl.h"
  21. #if CONFIG_PARLIO_ISR_IRAM_SAFE
  22. #define PARLIO_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
  23. #else
  24. #define PARLIO_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT
  25. #endif
  26. #if SOC_PARLIO_TX_RX_SHARE_INTERRUPT
  27. #define PARLIO_INTR_ALLOC_FLAG_SHARED ESP_INTR_FLAG_SHARED
  28. #else
  29. #define PARLIO_INTR_ALLOC_FLAG_SHARED 0
  30. #endif
  31. #if CONFIG_PARLIO_ISR_IRAM_SAFE
  32. #define PARLIO_INTR_ALLOC_FLAG (ESP_INTR_FLAG_LOWMED | PARLIO_INTR_ALLOC_FLAG_SHARED | ESP_INTR_FLAG_IRAM)
  33. #else
  34. #define PARLIO_INTR_ALLOC_FLAG (ESP_INTR_FLAG_LOWMED | PARLIO_INTR_ALLOC_FLAG_SHARED)
  35. #endif
  36. #if defined(SOC_GDMA_TRIG_PERIPH_PARLIO0_BUS) // Parlio uses GDMA
  37. #if defined(SOC_GDMA_BUS_AHB) && (SOC_GDMA_TRIG_PERIPH_PARLIO0_BUS == SOC_GDMA_BUS_AHB)
  38. typedef dma_descriptor_align4_t parlio_dma_desc_t;
  39. #define PARLIO_DMA_DESC_ALIGNMENT 4
  40. #define PARLIO_GDMA_NEW_CHANNEL gdma_new_ahb_channel
  41. #elif defined(SOC_GDMA_BUS_AXI) && (SOC_GDMA_TRIG_PERIPH_PARLIO0_BUS == SOC_GDMA_BUS_AXI)
  42. typedef dma_descriptor_align8_t parlio_dma_desc_t;
  43. #define PARLIO_DMA_DESC_ALIGNMENT 8
  44. #define PARLIO_GDMA_NEW_CHANNEL gdma_new_axi_channel
  45. #endif
  46. #endif // defined(SOC_GDMA_TRIG_PERIPH_PARLIO0_BUS)
  47. #ifdef CACHE_LL_L2MEM_NON_CACHE_ADDR
  48. /* The descriptor address can be mapped by a fixed offset */
  49. #define PARLIO_GET_NON_CACHED_DESC_ADDR(desc) (desc ? (parlio_dma_desc_t *)(CACHE_LL_L2MEM_NON_CACHE_ADDR(desc)) : NULL)
  50. #else
  51. #define PARLIO_GET_NON_CACHED_DESC_ADDR(desc) (desc)
  52. #endif // CACHE_LL_L2MEM_NON_CACHE_ADDR
  53. #if SOC_PERIPH_CLK_CTRL_SHARED
  54. #define PARLIO_CLOCK_SRC_ATOMIC() PERIPH_RCC_ATOMIC()
  55. #else
  56. #define PARLIO_CLOCK_SRC_ATOMIC()
  57. #endif
  58. #if !SOC_RCC_IS_INDEPENDENT
  59. // Reset and Clock Control registers are mixing with other peripherals, so we need to use a critical section
  60. #define PARLIO_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
  61. #else
  62. #define PARLIO_RCC_ATOMIC()
  63. #endif // SOC_RCC_IS_INDEPENDENT
  64. #define PARLIO_PM_LOCK_NAME_LEN_MAX 16
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. enum {
  69. PARLIO_TX_QUEUE_READY,
  70. PARLIO_TX_QUEUE_PROGRESS,
  71. PARLIO_TX_QUEUE_COMPLETE,
  72. PARLIO_TX_QUEUE_MAX,
  73. };
  74. typedef enum {
  75. PARLIO_TX_FSM_INIT_WAIT,
  76. PARLIO_TX_FSM_INIT,
  77. PARLIO_TX_FSM_ENABLE_WAIT,
  78. PARLIO_TX_FSM_ENABLE,
  79. PARLIO_TX_FSM_RUN_WAIT,
  80. PARLIO_TX_FSM_RUN,
  81. } parlio_tx_fsm_t;
  82. typedef struct parlio_group_t {
  83. int group_id; // group ID, index from 0
  84. portMUX_TYPE spinlock; // to protect per-group register level concurrent access
  85. parlio_hal_context_t hal; // hal layer for each group
  86. parlio_tx_unit_handle_t tx_units[SOC_PARLIO_TX_UNITS_PER_GROUP]; // tx unit handles
  87. } parlio_group_t;
  88. parlio_group_t *parlio_acquire_group_handle(int group_id);
  89. void parlio_release_group_handle(parlio_group_t *group);
  90. #ifdef __cplusplus
  91. }
  92. #endif