rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
fsl_lpspi_edma.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8#ifndef _FSL_LPSPI_EDMA_H_
9#define _FSL_LPSPI_EDMA_H_
10
11#include "fsl_lpspi.h"
12#include "fsl_edma.h"
13
14/*!
15 * @addtogroup lpspi_edma_driver
16 * @{
17 */
18
19/***********************************************************************************************************************
20 * Definitions
21 **********************************************************************************************************************/
22/*! @name Driver version */
23/*@{*/
24/*! @brief LPSPI EDMA driver version 2.0.2. */
25#define FSL_LPSPI_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
26/*@}*/
27
28/*!
29* @brief Forward declaration of the _lpspi_master_edma_handle typedefs.
30*/
32
33/*!
34* @brief Forward declaration of the _lpspi_slave_edma_handle typedefs.
35*/
37
38/*!
39 * @brief Completion callback function pointer type.
40 *
41 * @param base LPSPI peripheral base address.
42 * @param handle Pointer to the handle for the LPSPI master.
43 * @param status Success or error code describing whether the transfer completed.
44 * @param userData Arbitrary pointer-dataSized value passed from the application.
45 */
46typedef void (*lpspi_master_edma_transfer_callback_t)(LPSPI_Type *base,
48 status_t status,
49 void *userData);
50/*!
51 * @brief Completion callback function pointer type.
52 *
53 * @param base LPSPI peripheral base address.
54 * @param handle Pointer to the handle for the LPSPI slave.
55 * @param status Success or error code describing whether the transfer completed.
56 * @param userData Arbitrary pointer-dataSized value passed from the application.
57 */
58typedef void (*lpspi_slave_edma_transfer_callback_t)(LPSPI_Type *base,
60 status_t status,
61 void *userData);
62
63/*! @brief LPSPI master eDMA transfer handle structure used for transactional API. */
65{
66 volatile bool isPcsContinuous; /*!< Is PCS continuous in transfer. */
67
68 volatile bool isByteSwap; /*!< A flag that whether should byte swap. */
69
70 volatile uint8_t fifoSize; /*!< FIFO dataSize. */
71
72 volatile uint8_t rxWatermark; /*!< Rx watermark. */
73
74 volatile uint8_t bytesEachWrite; /*!< Bytes for each write TDR. */
75 volatile uint8_t bytesEachRead; /*!< Bytes for each read RDR. */
76
77 volatile uint8_t bytesLastRead; /*!< Bytes for last read RDR. */
78 volatile uint8_t isThereExtraRxBytes; /*!< Is there extra RX byte. */
79
80 uint8_t *volatile txData; /*!< Send buffer. */
81 uint8_t *volatile rxData; /*!< Receive buffer. */
82 volatile size_t txRemainingByteCount; /*!< Number of bytes remaining to send.*/
83 volatile size_t rxRemainingByteCount; /*!< Number of bytes remaining to receive.*/
84
85 volatile uint32_t writeRegRemainingTimes; /*!< Write TDR register remaining times. */
86 volatile uint32_t readRegRemainingTimes; /*!< Read RDR register remaining times. */
87
88 uint32_t totalByteCount; /*!< Number of transfer bytes*/
89
90 uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
91 uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
92
93 uint32_t transmitCommand; /*!< Used to write TCR for DMA purpose.*/
94
95 volatile uint8_t state; /*!< LPSPI transfer state , _lpspi_transfer_state.*/
96
97 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
98
99 lpspi_master_edma_transfer_callback_t callback; /*!< Completion callback. */
100 void *userData; /*!< Callback user data. */
101
102 edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
103 edma_handle_t *edmaTxDataToTxRegHandle; /*!<edma_handle_t handle point used for TxData to TxReg buff*/
104
105 edma_tcd_t lpspiSoftwareTCD[3]; /*!<SoftwareTCD, internal used*/
106};
107
108/*! @brief LPSPI slave eDMA transfer handle structure used for transactional API.*/
110{
111 volatile bool isByteSwap; /*!< A flag that whether should byte swap. */
112
113 volatile uint8_t fifoSize; /*!< FIFO dataSize. */
114
115 volatile uint8_t rxWatermark; /*!< Rx watermark. */
116
117 volatile uint8_t bytesEachWrite; /*!< Bytes for each write TDR. */
118 volatile uint8_t bytesEachRead; /*!< Bytes for each read RDR. */
119
120 volatile uint8_t bytesLastRead; /*!< Bytes for last read RDR. */
121 volatile uint8_t isThereExtraRxBytes; /*!< Is there extra RX byte. */
122
123 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
124
125 uint8_t *volatile txData; /*!< Send buffer. */
126 uint8_t *volatile rxData; /*!< Receive buffer. */
127 volatile size_t txRemainingByteCount; /*!< Number of bytes remaining to send.*/
128 volatile size_t rxRemainingByteCount; /*!< Number of bytes remaining to receive.*/
129
130 volatile uint32_t writeRegRemainingTimes; /*!< Write TDR register remaining times. */
131 volatile uint32_t readRegRemainingTimes; /*!< Read RDR register remaining times. */
132
133 uint32_t totalByteCount; /*!< Number of transfer bytes*/
134
135 uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
136 uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
137
138 volatile uint8_t state; /*!< LPSPI transfer state.*/
139
140 uint32_t errorCount; /*!< Error count for slave transfer.*/
141
142 lpspi_slave_edma_transfer_callback_t callback; /*!< Completion callback. */
143 void *userData; /*!< Callback user data. */
144
145 edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
146 edma_handle_t *edmaTxDataToTxRegHandle; /*!<edma_handle_t handle point used for TxData to TxReg*/
147
148 edma_tcd_t lpspiSoftwareTCD[2]; /*!<SoftwareTCD, internal used*/
149};
150
151/***********************************************************************************************************************
152 * API
153 **********************************************************************************************************************/
154#if defined(__cplusplus)
155extern "C" {
156#endif /*_cplusplus*/
157
158/*Transactional APIs*/
159
160/*!
161 * @brief Initializes the LPSPI master eDMA handle.
162 *
163 * This function initializes the LPSPI eDMA handle which can be used for other LPSPI transactional APIs. Usually, for a
164 * specified LPSPI instance, call this API once to get the initialized handle.
165 *
166 * Note that the LPSPI eDMA has a separated (Rx and Rx as two sources) or shared (Rx and Tx are the same source) DMA
167 * request source.
168 * (1) For a separated DMA request source, enable and set the Rx DMAMUX source for edmaRxRegToRxDataHandle and
169 * Tx DMAMUX source for edmaIntermediaryToTxRegHandle.
170 * (2) For a shared DMA request source, enable and set the Rx/Rx DMAMUX source for edmaRxRegToRxDataHandle.
171 *
172 * @param base LPSPI peripheral base address.
173 * @param handle LPSPI handle pointer to lpspi_master_edma_handle_t.
174 * @param callback LPSPI callback.
175 * @param userData callback function parameter.
176 * @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
177 * @param edmaTxDataToTxRegHandle edmaTxDataToTxRegHandle pointer to edma_handle_t.
178 */
179void LPSPI_MasterTransferCreateHandleEDMA(LPSPI_Type *base,
182 void *userData,
183 edma_handle_t *edmaRxRegToRxDataHandle,
184 edma_handle_t *edmaTxDataToTxRegHandle);
185
186/*!
187 * @brief LPSPI master transfer data using eDMA.
188 *
189 * This function transfers data using eDMA. This is a non-blocking function, which returns right away. When all data
190 * is transferred, the callback function is called.
191 *
192 * Note:
193 * The transfer data size should be an integer multiple of bytesPerFrame if bytesPerFrame is less than or equal to 4.
194 * For bytesPerFrame greater than 4:
195 * The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not an integer multiple of 4.
196 * Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.
197 *
198 * @param base LPSPI peripheral base address.
199 * @param handle pointer to lpspi_master_edma_handle_t structure which stores the transfer state.
200 * @param transfer pointer to lpspi_transfer_t structure.
201 * @return status of status_t.
202 */
204
205/*!
206 * @brief LPSPI master aborts a transfer which is using eDMA.
207 *
208 * This function aborts a transfer which is using eDMA.
209 *
210 * @param base LPSPI peripheral base address.
211 * @param handle pointer to lpspi_master_edma_handle_t structure which stores the transfer state.
212 */
213void LPSPI_MasterTransferAbortEDMA(LPSPI_Type *base, lpspi_master_edma_handle_t *handle);
214
215/*!
216 * @brief Gets the master eDMA transfer remaining bytes.
217 *
218 * This function gets the master eDMA transfer remaining bytes.
219 *
220 * @param base LPSPI peripheral base address.
221 * @param handle pointer to lpspi_master_edma_handle_t structure which stores the transfer state.
222 * @param count Number of bytes transferred so far by the EDMA transaction.
223 * @return status of status_t.
224 */
226
227/*!
228 * @brief Initializes the LPSPI slave eDMA handle.
229 *
230 * This function initializes the LPSPI eDMA handle which can be used for other LPSPI transactional APIs. Usually, for a
231 * specified LPSPI instance, call this API once to get the initialized handle.
232 *
233 * Note that LPSPI eDMA has a separated (Rx and Tx as two sources) or shared (Rx and Tx as the same source) DMA request
234 * source.
235 *
236 * (1) For a separated DMA request source, enable and set the Rx DMAMUX source for edmaRxRegToRxDataHandle and
237 * Tx DMAMUX source for edmaTxDataToTxRegHandle.
238 * (2) For a shared DMA request source, enable and set the Rx/Rx DMAMUX source for edmaRxRegToRxDataHandle .
239 *
240 * @param base LPSPI peripheral base address.
241 * @param handle LPSPI handle pointer to lpspi_slave_edma_handle_t.
242 * @param callback LPSPI callback.
243 * @param userData callback function parameter.
244 * @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
245 * @param edmaTxDataToTxRegHandle edmaTxDataToTxRegHandle pointer to edma_handle_t.
246 */
247void LPSPI_SlaveTransferCreateHandleEDMA(LPSPI_Type *base,
250 void *userData,
251 edma_handle_t *edmaRxRegToRxDataHandle,
252 edma_handle_t *edmaTxDataToTxRegHandle);
253
254/*!
255 * @brief LPSPI slave transfers data using eDMA.
256 *
257 * This function transfers data using eDMA. This is a non-blocking function, which return right away. When all data
258 * is transferred, the callback function is called.
259 *
260 * Note:
261 * The transfer data size should be an integer multiple of bytesPerFrame if bytesPerFrame is less than or equal to 4.
262 * For bytesPerFrame greater than 4:
263 * The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not an integer multiple of 4.
264 * Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.
265 *
266 * @param base LPSPI peripheral base address.
267 * @param handle pointer to lpspi_slave_edma_handle_t structure which stores the transfer state.
268 * @param transfer pointer to lpspi_transfer_t structure.
269 * @return status of status_t.
270 */
272
273/*!
274 * @brief LPSPI slave aborts a transfer which is using eDMA.
275 *
276 * This function aborts a transfer which is using eDMA.
277 *
278 * @param base LPSPI peripheral base address.
279 * @param handle pointer to lpspi_slave_edma_handle_t structure which stores the transfer state.
280 */
281void LPSPI_SlaveTransferAbortEDMA(LPSPI_Type *base, lpspi_slave_edma_handle_t *handle);
282
283/*!
284 * @brief Gets the slave eDMA transfer remaining bytes.
285 *
286 * This function gets the slave eDMA transfer remaining bytes.
287 *
288 * @param base LPSPI peripheral base address.
289 * @param handle pointer to lpspi_slave_edma_handle_t structure which stores the transfer state.
290 * @param count Number of bytes transferred so far by the eDMA transaction.
291 * @return status of status_t.
292 */
294
295#if defined(__cplusplus)
296}
297#endif /*_cplusplus*/
298 /*!
299 *@}
300 */
301
302#endif /*_FSL_LPSPI_EDMA_H_*/
int32_t status_t
Type used for all status and error return values.
Definition fsl_common.h:169
status_t LPSPI_MasterTransferGetCountEDMA(LPSPI_Type *base, lpspi_master_edma_handle_t *handle, size_t *count)
Gets the master eDMA transfer remaining bytes.
edma_handle_t * edmaTxDataToTxRegHandle
lpspi_master_edma_transfer_callback_t callback
void LPSPI_MasterTransferCreateHandleEDMA(LPSPI_Type *base, lpspi_master_edma_handle_t *handle, lpspi_master_edma_transfer_callback_t callback, void *userData, edma_handle_t *edmaRxRegToRxDataHandle, edma_handle_t *edmaTxDataToTxRegHandle)
Initializes the LPSPI master eDMA handle.
volatile uint8_t fifoSize
volatile uint8_t bytesEachWrite
volatile uint8_t bytesEachRead
edma_handle_t * edmaRxRegToRxDataHandle
volatile uint32_t readRegRemainingTimes
void(* lpspi_master_edma_transfer_callback_t)(LPSPI_Type *base, lpspi_master_edma_handle_t *handle, status_t status, void *userData)
Completion callback function pointer type.
volatile uint32_t writeRegRemainingTimes
uint8_t *volatile txData
uint8_t *volatile rxData
void LPSPI_SlaveTransferAbortEDMA(LPSPI_Type *base, lpspi_slave_edma_handle_t *handle)
LPSPI slave aborts a transfer which is using eDMA.
volatile uint8_t bytesLastRead
volatile uint8_t rxWatermark
uint8_t *volatile txData
volatile uint8_t bytesEachWrite
volatile size_t rxRemainingByteCount
volatile uint8_t rxWatermark
volatile uint8_t isThereExtraRxBytes
lpspi_slave_edma_transfer_callback_t callback
volatile uint8_t isThereExtraRxBytes
volatile uint8_t fifoSize
volatile uint8_t bytesEachRead
volatile uint32_t writeRegRemainingTimes
uint8_t *volatile rxData
edma_handle_t * edmaTxDataToTxRegHandle
status_t LPSPI_MasterTransferEDMA(LPSPI_Type *base, lpspi_master_edma_handle_t *handle, lpspi_transfer_t *transfer)
LPSPI master transfer data using eDMA.
void LPSPI_MasterTransferAbortEDMA(LPSPI_Type *base, lpspi_master_edma_handle_t *handle)
LPSPI master aborts a transfer which is using eDMA.
volatile size_t rxRemainingByteCount
void LPSPI_SlaveTransferCreateHandleEDMA(LPSPI_Type *base, lpspi_slave_edma_handle_t *handle, lpspi_slave_edma_transfer_callback_t callback, void *userData, edma_handle_t *edmaRxRegToRxDataHandle, edma_handle_t *edmaTxDataToTxRegHandle)
Initializes the LPSPI slave eDMA handle.
status_t LPSPI_SlaveTransferEDMA(LPSPI_Type *base, lpspi_slave_edma_handle_t *handle, lpspi_transfer_t *transfer)
LPSPI slave transfers data using eDMA.
edma_handle_t * edmaRxRegToRxDataHandle
volatile size_t txRemainingByteCount
volatile uint32_t readRegRemainingTimes
status_t LPSPI_SlaveTransferGetCountEDMA(LPSPI_Type *base, lpspi_slave_edma_handle_t *handle, size_t *count)
Gets the slave eDMA transfer remaining bytes.
volatile size_t txRemainingByteCount
volatile uint8_t bytesLastRead
void(* lpspi_slave_edma_transfer_callback_t)(LPSPI_Type *base, lpspi_slave_edma_handle_t *handle, status_t status, void *userData)
Completion callback function pointer type.
eDMA transfer handle structure
Definition fsl_edma.h:246
eDMA TCD.
Definition fsl_edma.h:207
LPSPI master eDMA transfer handle structure used for transactional API.
LPSPI slave eDMA transfer handle structure used for transactional API.
LPSPI master/slave transfer structure.
Definition fsl_lpspi.h:337
uint16_t count
Definition tunerstudio.h:1