1 /* 2 * Copyright 2016-2017 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 #ifndef _FSL_SPI_DMA_H_ 7 #define _FSL_SPI_DMA_H_ 8 9 #include "fsl_ecspi.h" 10 #include "fsl_sdma.h" 11 12 /*! 13 * @addtogroup ecspi_sdma 14 * @{ 15 */ 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 /*! @name Driver version */ 21 /*@{*/ 22 /*! @brief ECSPI FreeRTOS driver version 2.0.1. */ 23 #define FSL_ECSPI_FREERTOS_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) 24 /*@}*/ 25 26 typedef struct _ecspi_sdma_handle ecspi_sdma_handle_t; 27 28 /*! @brief ECSPI SDMA callback called at the end of transfer. */ 29 typedef void (*ecspi_sdma_callback_t)(ECSPI_Type *base, ecspi_sdma_handle_t *handle, status_t status, void *userData); 30 31 /*! @brief ECSPI SDMA transfer handle, users should not touch the content of the handle.*/ 32 struct _ecspi_sdma_handle 33 { 34 bool txInProgress; /*!< Send transfer finished */ 35 bool rxInProgress; /*!< Receive transfer finished */ 36 sdma_handle_t *txSdmaHandle; /*!< DMA handler for ECSPI send */ 37 sdma_handle_t *rxSdmaHandle; /*!< DMA handler for ECSPI receive */ 38 ecspi_sdma_callback_t callback; /*!< Callback for ECSPI SDMA transfer */ 39 void *userData; /*!< User Data for ECSPI SDMA callback */ 40 uint32_t state; /*!< Internal state of ECSPI SDMA transfer */ 41 uint32_t ChannelTx; /*!< Channel for send handle */ 42 uint32_t ChannelRx; /*!< Channel for receive handler */ 43 }; 44 45 /******************************************************************************* 46 * APIs 47 ******************************************************************************/ 48 #if defined(__cplusplus) 49 extern "C" { 50 #endif 51 52 /*! 53 * @name DMA Transactional 54 * @{ 55 */ 56 57 /*! 58 * @brief Initialize the ECSPI master SDMA handle. 59 * 60 * This function initializes the ECSPI master SDMA handle which can be used for other SPI master transactional APIs. 61 * Usually, for a specified ECSPI instance, user need only call this API once to get the initialized handle. 62 * 63 * @param base ECSPI peripheral base address. 64 * @param handle ECSPI handle pointer. 65 * @param callback User callback function called at the end of a transfer. 66 * @param userData User data for callback. 67 * @param txHandle SDMA handle pointer for ECSPI Tx, the handle shall be static allocated by users. 68 * @param rxHandle SDMA handle pointer for ECSPI Rx, the handle shall be static allocated by users. 69 * @param eventSourceTx event source for ECSPI send, which can be found in SDMA mapping. 70 * @param eventSourceRx event source for ECSPI receive, which can be found in SDMA mapping. 71 * @param TxChannel SDMA channel for ECSPI send. 72 * @param RxChannel SDMA channel for ECSPI receive. 73 */ 74 void ECSPI_MasterTransferCreateHandleSDMA(ECSPI_Type *base, 75 ecspi_sdma_handle_t *handle, 76 ecspi_sdma_callback_t callback, 77 void *userData, 78 sdma_handle_t *txHandle, 79 sdma_handle_t *rxHandle, 80 uint32_t eventSourceTx, 81 uint32_t eventSourceRx, 82 uint32_t TxChannel, 83 uint32_t RxChannel); 84 85 /*! 86 * @brief Initialize the ECSPI Slave SDMA handle. 87 * 88 * This function initializes the ECSPI Slave SDMA handle which can be used for other SPI Slave transactional APIs. 89 * Usually, for a specified ECSPI instance, user need only call this API once to get the initialized handle. 90 * 91 * @param base ECSPI peripheral base address. 92 * @param handle ECSPI handle pointer. 93 * @param callback User callback function called at the end of a transfer. 94 * @param userData User data for callback. 95 * @param txHandle SDMA handle pointer for ECSPI Tx, the handle shall be static allocated by users. 96 * @param rxHandle SDMA handle pointer for ECSPI Rx, the handle shall be static allocated by users. 97 * @param eventSourceTx event source for ECSPI send, which can be found in SDMA mapping. 98 * @param eventSourceRx event source for ECSPI receive, which can be found in SDMA mapping. 99 * @param TxChannel SDMA channel for ECSPI send. 100 * @param RxChannel SDMA channel for ECSPI receive. 101 */ 102 void ECSPI_SlaveTransferCreateHandleSDMA(ECSPI_Type *base, 103 ecspi_sdma_handle_t *handle, 104 ecspi_sdma_callback_t callback, 105 void *userData, 106 sdma_handle_t *txHandle, 107 sdma_handle_t *rxHandle, 108 uint32_t eventSourceTx, 109 uint32_t eventSourceRx, 110 uint32_t TxChannel, 111 uint32_t RxChannel); 112 113 /*! 114 * @brief Perform a non-blocking ECSPI master transfer using SDMA. 115 * 116 * @note This interface returned immediately after transfer initiates. 117 * 118 * @param base ECSPI peripheral base address. 119 * @param handle ECSPI SDMA handle pointer. 120 * @param xfer Pointer to sdma transfer structure. 121 * @retval kStatus_Success Successfully start a transfer. 122 * @retval kStatus_InvalidArgument Input argument is invalid. 123 * @retval kStatus_ECSPI_Busy EECSPI is not idle, is running another transfer. 124 */ 125 status_t ECSPI_MasterTransferSDMA(ECSPI_Type *base, ecspi_sdma_handle_t *handle, ecspi_transfer_t *xfer); 126 127 /*! 128 * @brief Perform a non-blocking ECSPI slave transfer using SDMA. 129 * 130 * @note This interface returned immediately after transfer initiates. 131 * 132 * @param base ECSPI peripheral base address. 133 * @param handle ECSPI SDMA handle pointer. 134 * @param xfer Pointer to sdma transfer structure. 135 * @retval kStatus_Success Successfully start a transfer. 136 * @retval kStatus_InvalidArgument Input argument is invalid. 137 * @retval kStatus_ECSPI_Busy EECSPI is not idle, is running another transfer. 138 */ 139 status_t ECSPI_SlaveTransferSDMA(ECSPI_Type *base, ecspi_sdma_handle_t *handle, ecspi_transfer_t *xfer); 140 /*! 141 * @brief Abort a ECSPI master transfer using SDMA. 142 * 143 * @param base ECSPI peripheral base address. 144 * @param handle ECSPI SDMA handle pointer. 145 */ 146 void ECSPI_MasterTransferAbortSDMA(ECSPI_Type *base, ecspi_sdma_handle_t *handle); 147 /*! 148 * @brief Abort a ECSPI slave transfer using SDMA. 149 * 150 * @param base ECSPI peripheral base address. 151 * @param handle ECSPI SDMA handle pointer. 152 */ 153 void ECSPI_SlaveTransferAbortSDMA(ECSPI_Type *base, ecspi_sdma_handle_t *handle); 154 155 /*! @} */ 156 157 #if defined(__cplusplus) 158 } 159 #endif 160 161 /*! 162 * @} 163 */ 164 #endif 165