1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2023 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8 #ifndef _FSL_FLEXCAN_EDMA_H_
9 #define _FSL_FLEXCAN_EDMA_H_
10
11 #include "fsl_flexcan.h"
12 #include "fsl_edma.h"
13
14 /*!
15 * @addtogroup flexcan_edma_driver
16 * @{
17 */
18
19 /*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
23 /*! @name Driver version */
24 /*@{*/
25 /*! @brief FlexCAN EDMA driver version. */
26 #define FSL_FLEXCAN_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 11, 0))
27 /*@}*/
28
29 /* Forward declaration of the handle typedef. */
30 typedef struct _flexcan_edma_handle flexcan_edma_handle_t;
31
32 /*! @brief FlexCAN transfer callback function. */
33 typedef void (*flexcan_edma_transfer_callback_t)(CAN_Type *base,
34 flexcan_edma_handle_t *handle,
35 status_t status,
36 void *userData);
37
38 /*!
39 * @brief FlexCAN eDMA handle
40 */
41 struct _flexcan_edma_handle
42 {
43 flexcan_edma_transfer_callback_t callback; /*!< Callback function. */
44 void *userData; /*!< FlexCAN callback function parameter.*/
45 edma_handle_t *rxFifoEdmaHandle; /*!< The EDMA handler for Rx FIFO. */
46 volatile uint8_t rxFifoState; /*!< Rx FIFO transfer state. */
47 size_t frameNum; /*!< The number of messages that need to be received. */
48 #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
49 flexcan_fd_frame_t *framefd; /*!< Point to the buffer of CAN Message to be received from Enhanced Rx FIFO. */
50 #endif
51 };
52
53 /*******************************************************************************
54 * API
55 ******************************************************************************/
56
57 #if defined(__cplusplus)
58 extern "C" {
59 #endif
60
61 /*!
62 * @name eDMA transactional
63 * @{
64 */
65
66 /*!
67 * @brief Initializes the FlexCAN handle, which is used in transactional functions.
68 *
69 * @param base FlexCAN peripheral base address.
70 * @param handle Pointer to flexcan_edma_handle_t structure.
71 * @param callback The callback function.
72 * @param userData The parameter of the callback function.
73 * @param rxFifoEdmaHandle User-requested DMA handle for Rx FIFO DMA transfer.
74 */
75 void FLEXCAN_TransferCreateHandleEDMA(CAN_Type *base,
76 flexcan_edma_handle_t *handle,
77 flexcan_edma_transfer_callback_t callback,
78 void *userData,
79 edma_handle_t *rxFifoEdmaHandle);
80
81 /*!
82 * @brief Prepares the eDMA transfer configuration for FLEXCAN Legacy RX FIFO.
83 *
84 * This function prepares the eDMA transfer configuration structure according to FLEXCAN Legacy RX FIFO.
85 *
86 * @param base FlexCAN peripheral base address.
87 * @param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
88 * @param pEdmaConfig The user configuration structure of type edma_transfer_t.
89 *
90 */
91 void FLEXCAN_PrepareTransfConfiguration(CAN_Type *base,
92 flexcan_fifo_transfer_t *pFifoXfer,
93 edma_transfer_config_t *pEdmaConfig);
94
95 /*!
96 * @brief Start Transfer Data from the FLEXCAN Legacy Rx FIFO using eDMA.
97 *
98 * This function to Update edma transfer confiugration and Start eDMA transfer
99 *
100 * @param base FlexCAN peripheral base address.
101 * @param handle Pointer to flexcan_edma_handle_t structure.
102 * @param pEdmaConfig The user configuration structure of type edma_transfer_t.
103 * @retval kStatus_Success if succeed, others failed.
104 * @retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
105 */
106 status_t FLEXCAN_StartTransferDatafromRxFIFO(CAN_Type *base,
107 flexcan_edma_handle_t *handle,
108 edma_transfer_config_t *pEdmaConfig);
109
110 /*!
111 * @brief Receives the CAN Message from the Legacy Rx FIFO using eDMA.
112 *
113 * This function receives the CAN Message using eDMA. This is a non-blocking function, which returns
114 * right away. After the CAN Message is received, the receive callback function is called.
115 *
116 * @param base FlexCAN peripheral base address.
117 * @param handle Pointer to flexcan_edma_handle_t structure.
118 * @param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
119 * @retval kStatus_Success if succeed, others failed.
120 * @retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
121 */
122 status_t FLEXCAN_TransferReceiveFifoEDMA(CAN_Type *base,
123 flexcan_edma_handle_t *handle,
124 flexcan_fifo_transfer_t *pFifoXfer);
125 /*!
126 * @brief Gets the Legacy Rx Fifo transfer status during a interrupt non-blocking receive.
127 *
128 * @param base FlexCAN peripheral base address.
129 * @param handle FlexCAN handle pointer.
130 * @param count Number of CAN messages receive so far by the non-blocking transaction.
131 * @retval kStatus_InvalidArgument count is Invalid.
132 * @retval kStatus_Success Successfully return the count.
133 */
134
135 status_t FLEXCAN_TransferGetReceiveFifoCountEMDA(CAN_Type *base, flexcan_edma_handle_t *handle, size_t *count);
136 /*!
137 * @brief Aborts the receive Legacy/Enhanced Rx FIFO process which used eDMA.
138 *
139 * This function aborts the receive Legacy/Enhanced Rx FIFO process which used eDMA.
140 *
141 * @param base FlexCAN peripheral base address.
142 * @param handle Pointer to flexcan_edma_handle_t structure.
143 */
144 void FLEXCAN_TransferAbortReceiveFifoEDMA(CAN_Type *base, flexcan_edma_handle_t *handle);
145
146 #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
147 /*!
148 * @brief Receives the CAN FD Message from the Enhanced Rx FIFO using eDMA.
149 *
150 * This function receives the CAN FD Message using eDMA. This is a non-blocking function, which returns
151 * right away. After the CAN Message is received, the receive callback function is called.
152 *
153 * @param base FlexCAN peripheral base address.
154 * @param handle Pointer to flexcan_edma_handle_t structure.
155 * @param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
156 * @retval kStatus_Success if succeed, others failed.
157 * @retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
158 */
159 status_t FLEXCAN_TransferReceiveEnhancedFifoEDMA(CAN_Type *base,
160 flexcan_edma_handle_t *handle,
161 flexcan_fifo_transfer_t *pFifoXfer);
162 /*!
163 * @brief Gets the Enhanced Rx Fifo transfer status during a interrupt non-blocking receive.
164 *
165 * @param base FlexCAN peripheral base address.
166 * @param handle FlexCAN handle pointer.
167 * @param count Number of CAN messages receive so far by the non-blocking transaction.
168 * @retval kStatus_InvalidArgument count is Invalid.
169 * @retval kStatus_Success Successfully return the count.
170 */
171
FLEXCAN_TransferGetReceiveEnhancedFifoCountEMDA(CAN_Type * base,flexcan_edma_handle_t * handle,size_t * count)172 static inline status_t FLEXCAN_TransferGetReceiveEnhancedFifoCountEMDA(CAN_Type *base,
173 flexcan_edma_handle_t *handle,
174 size_t *count)
175 {
176 return FLEXCAN_TransferGetReceiveFifoCountEMDA(base, handle, count);
177 }
178 #endif
179
180 /*@}*/
181
182 #if defined(__cplusplus)
183 }
184 #endif
185
186 /*! @}*/
187
188 #endif /* _FSL_FLEXCAN_EDMA_H_ */
189