The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 148:fd96258d940d 1 /*
Kojto 148:fd96258d940d 2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
Kojto 148:fd96258d940d 3 * All rights reserved.
Kojto 148:fd96258d940d 4 *
Kojto 148:fd96258d940d 5 * Redistribution and use in source and binary forms, with or without modification,
Kojto 148:fd96258d940d 6 * are permitted provided that the following conditions are met:
Kojto 148:fd96258d940d 7 *
Kojto 148:fd96258d940d 8 * o Redistributions of source code must retain the above copyright notice, this list
Kojto 148:fd96258d940d 9 * of conditions and the following disclaimer.
Kojto 148:fd96258d940d 10 *
Kojto 148:fd96258d940d 11 * o Redistributions in binary form must reproduce the above copyright notice, this
Kojto 148:fd96258d940d 12 * list of conditions and the following disclaimer in the documentation and/or
Kojto 148:fd96258d940d 13 * other materials provided with the distribution.
Kojto 148:fd96258d940d 14 *
Kojto 148:fd96258d940d 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
Kojto 148:fd96258d940d 16 * contributors may be used to endorse or promote products derived from this
Kojto 148:fd96258d940d 17 * software without specific prior written permission.
Kojto 148:fd96258d940d 18 *
Kojto 148:fd96258d940d 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Kojto 148:fd96258d940d 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Kojto 148:fd96258d940d 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 148:fd96258d940d 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Kojto 148:fd96258d940d 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Kojto 148:fd96258d940d 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Kojto 148:fd96258d940d 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Kojto 148:fd96258d940d 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 148:fd96258d940d 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Kojto 148:fd96258d940d 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 148:fd96258d940d 29 */
Kojto 148:fd96258d940d 30 #ifndef _FSL_USART_DMA_H_
Kojto 148:fd96258d940d 31 #define _FSL_USART_DMA_H_
Kojto 148:fd96258d940d 32
Kojto 148:fd96258d940d 33 #include "fsl_common.h"
Kojto 148:fd96258d940d 34 #include "fsl_dma.h"
Kojto 148:fd96258d940d 35 #include "fsl_usart.h"
Kojto 148:fd96258d940d 36
Kojto 148:fd96258d940d 37 /*!
Kojto 148:fd96258d940d 38 * @addtogroup usart_dma_driver
Kojto 148:fd96258d940d 39 * @{
Kojto 148:fd96258d940d 40 */
Kojto 148:fd96258d940d 41
Kojto 148:fd96258d940d 42 /*! @file */
Kojto 148:fd96258d940d 43
Kojto 148:fd96258d940d 44 /*******************************************************************************
Kojto 148:fd96258d940d 45 * Definitions
Kojto 148:fd96258d940d 46 ******************************************************************************/
Kojto 148:fd96258d940d 47
Kojto 148:fd96258d940d 48 /* Forward declaration of the handle typedef. */
Kojto 148:fd96258d940d 49 typedef struct _usart_dma_handle usart_dma_handle_t;
Kojto 148:fd96258d940d 50
Kojto 148:fd96258d940d 51 /*! @brief UART transfer callback function. */
Kojto 148:fd96258d940d 52 typedef void (*usart_dma_transfer_callback_t)(USART_Type *base,
Kojto 148:fd96258d940d 53 usart_dma_handle_t *handle,
Kojto 148:fd96258d940d 54 status_t status,
Kojto 148:fd96258d940d 55 void *userData);
Kojto 148:fd96258d940d 56
Kojto 148:fd96258d940d 57 /*!
Kojto 148:fd96258d940d 58 * @brief UART DMA handle
Kojto 148:fd96258d940d 59 */
Kojto 148:fd96258d940d 60 struct _usart_dma_handle
Kojto 148:fd96258d940d 61 {
Kojto 148:fd96258d940d 62 USART_Type *base; /*!< UART peripheral base address. */
Kojto 148:fd96258d940d 63
Kojto 148:fd96258d940d 64 usart_dma_transfer_callback_t callback; /*!< Callback function. */
Kojto 148:fd96258d940d 65 void *userData; /*!< UART callback function parameter.*/
Kojto 148:fd96258d940d 66 size_t rxDataSizeAll; /*!< Size of the data to receive. */
Kojto 148:fd96258d940d 67 size_t txDataSizeAll; /*!< Size of the data to send out. */
Kojto 148:fd96258d940d 68
Kojto 148:fd96258d940d 69 dma_handle_t *txDmaHandle; /*!< The DMA TX channel used. */
Kojto 148:fd96258d940d 70 dma_handle_t *rxDmaHandle; /*!< The DMA RX channel used. */
Kojto 148:fd96258d940d 71
Kojto 148:fd96258d940d 72 volatile uint8_t txState; /*!< TX transfer state. */
Kojto 148:fd96258d940d 73 volatile uint8_t rxState; /*!< RX transfer state */
Kojto 148:fd96258d940d 74 };
Kojto 148:fd96258d940d 75
Kojto 148:fd96258d940d 76 /*******************************************************************************
Kojto 148:fd96258d940d 77 * API
Kojto 148:fd96258d940d 78 ******************************************************************************/
Kojto 148:fd96258d940d 79
Kojto 148:fd96258d940d 80 #if defined(__cplusplus)
Kojto 148:fd96258d940d 81 extern "C" {
Kojto 148:fd96258d940d 82 #endif /* _cplusplus */
Kojto 148:fd96258d940d 83
Kojto 148:fd96258d940d 84 /*!
Kojto 148:fd96258d940d 85 * @name DMA transactional
Kojto 148:fd96258d940d 86 * @{
Kojto 148:fd96258d940d 87 */
Kojto 148:fd96258d940d 88
Kojto 148:fd96258d940d 89 /*!
Kojto 148:fd96258d940d 90 * @brief Initializes the USART handle which is used in transactional functions.
Kojto 148:fd96258d940d 91 * @param base USART peripheral base address.
Kojto 148:fd96258d940d 92 * @param handle Pointer to usart_dma_handle_t structure.
Kojto 148:fd96258d940d 93 * @param callback Callback function.
Kojto 148:fd96258d940d 94 * @param userData User data.
Kojto 148:fd96258d940d 95 * @param txDmaHandle User-requested DMA handle for TX DMA transfer.
Kojto 148:fd96258d940d 96 * @param rxDmaHandle User-requested DMA handle for RX DMA transfer.
Kojto 148:fd96258d940d 97 */
Kojto 148:fd96258d940d 98 status_t USART_TransferCreateHandleDMA(USART_Type *base,
Kojto 148:fd96258d940d 99 usart_dma_handle_t *handle,
Kojto 148:fd96258d940d 100 usart_dma_transfer_callback_t callback,
Kojto 148:fd96258d940d 101 void *userData,
Kojto 148:fd96258d940d 102 dma_handle_t *txDmaHandle,
Kojto 148:fd96258d940d 103 dma_handle_t *rxDmaHandle);
Kojto 148:fd96258d940d 104
Kojto 148:fd96258d940d 105 /*!
Kojto 148:fd96258d940d 106 * @brief Sends data using DMA.
Kojto 148:fd96258d940d 107 *
Kojto 148:fd96258d940d 108 * This function sends data using DMA. This is a non-blocking function, which returns
Kojto 148:fd96258d940d 109 * right away. When all data is sent, the send callback function is called.
Kojto 148:fd96258d940d 110 *
Kojto 148:fd96258d940d 111 * @param base USART peripheral base address.
Kojto 148:fd96258d940d 112 * @param handle USART handle pointer.
Kojto 148:fd96258d940d 113 * @param xfer USART DMA transfer structure. See #usart_transfer_t.
Kojto 148:fd96258d940d 114 * @retval kStatus_Success if succeed, others failed.
Kojto 148:fd96258d940d 115 * @retval kStatus_USART_TxBusy Previous transfer on going.
Kojto 148:fd96258d940d 116 * @retval kStatus_InvalidArgument Invalid argument.
Kojto 148:fd96258d940d 117 */
Kojto 148:fd96258d940d 118 status_t USART_TransferSendDMA(USART_Type *base, usart_dma_handle_t *handle, usart_transfer_t *xfer);
Kojto 148:fd96258d940d 119
Kojto 148:fd96258d940d 120 /*!
Kojto 148:fd96258d940d 121 * @brief Receives data using DMA.
Kojto 148:fd96258d940d 122 *
Kojto 148:fd96258d940d 123 * This function receives data using DMA. This is a non-blocking function, which returns
Kojto 148:fd96258d940d 124 * right away. When all data is received, the receive callback function is called.
Kojto 148:fd96258d940d 125 *
Kojto 148:fd96258d940d 126 * @param base USART peripheral base address.
Kojto 148:fd96258d940d 127 * @param handle Pointer to usart_dma_handle_t structure.
Kojto 148:fd96258d940d 128 * @param xfer USART DMA transfer structure. See #usart_transfer_t.
Kojto 148:fd96258d940d 129 * @retval kStatus_Success if succeed, others failed.
Kojto 148:fd96258d940d 130 * @retval kStatus_USART_RxBusy Previous transfer on going.
Kojto 148:fd96258d940d 131 * @retval kStatus_InvalidArgument Invalid argument.
Kojto 148:fd96258d940d 132 */
Kojto 148:fd96258d940d 133 status_t USART_TransferReceiveDMA(USART_Type *base, usart_dma_handle_t *handle, usart_transfer_t *xfer);
Kojto 148:fd96258d940d 134
Kojto 148:fd96258d940d 135 /*!
Kojto 148:fd96258d940d 136 * @brief Aborts the sent data using DMA.
Kojto 148:fd96258d940d 137 *
Kojto 148:fd96258d940d 138 * This function aborts send data using DMA.
Kojto 148:fd96258d940d 139 *
Kojto 148:fd96258d940d 140 * @param base USART peripheral base address
Kojto 148:fd96258d940d 141 * @param handle Pointer to usart_dma_handle_t structure
Kojto 148:fd96258d940d 142 */
Kojto 148:fd96258d940d 143 void USART_TransferAbortSendDMA(USART_Type *base, usart_dma_handle_t *handle);
Kojto 148:fd96258d940d 144
Kojto 148:fd96258d940d 145 /*!
Kojto 148:fd96258d940d 146 * @brief Aborts the received data using DMA.
Kojto 148:fd96258d940d 147 *
Kojto 148:fd96258d940d 148 * This function aborts the received data using DMA.
Kojto 148:fd96258d940d 149 *
Kojto 148:fd96258d940d 150 * @param base USART peripheral base address
Kojto 148:fd96258d940d 151 * @param handle Pointer to usart_dma_handle_t structure
Kojto 148:fd96258d940d 152 */
Kojto 148:fd96258d940d 153 void USART_TransferAbortReceiveDMA(USART_Type *base, usart_dma_handle_t *handle);
Kojto 148:fd96258d940d 154
Kojto 148:fd96258d940d 155 /*!
Kojto 148:fd96258d940d 156 * @brief Get the number of bytes that have been received.
Kojto 148:fd96258d940d 157 *
Kojto 148:fd96258d940d 158 * This function gets the number of bytes that have been received.
Kojto 148:fd96258d940d 159 *
Kojto 148:fd96258d940d 160 * @param base USART peripheral base address.
Kojto 148:fd96258d940d 161 * @param handle USART handle pointer.
Kojto 148:fd96258d940d 162 * @param count Receive bytes count.
Kojto 148:fd96258d940d 163 * @retval kStatus_NoTransferInProgress No receive in progress.
Kojto 148:fd96258d940d 164 * @retval kStatus_InvalidArgument Parameter is invalid.
Kojto 148:fd96258d940d 165 * @retval kStatus_Success Get successfully through the parameter \p count;
Kojto 148:fd96258d940d 166 */
Kojto 148:fd96258d940d 167 status_t USART_TransferGetReceiveCountDMA(USART_Type *base, usart_dma_handle_t *handle, uint32_t *count);
Kojto 148:fd96258d940d 168
Kojto 148:fd96258d940d 169 /* @} */
Kojto 148:fd96258d940d 170
Kojto 148:fd96258d940d 171 #if defined(__cplusplus)
Kojto 148:fd96258d940d 172 }
Kojto 148:fd96258d940d 173 #endif
Kojto 148:fd96258d940d 174
Kojto 148:fd96258d940d 175 /*! @}*/
Kojto 148:fd96258d940d 176
Kojto 148:fd96258d940d 177 #endif /* _FSL_USART_DMA_H_ */