![]() |
|
|||
File indexing completed on 2025-05-11 08:23:00
0001 /* 0002 * Copyright (c) 2015, Freescale Semiconductor, Inc. 0003 * Copyright 2016-2020 NXP 0004 * All rights reserved. 0005 * 0006 * SPDX-License-Identifier: BSD-3-Clause 0007 */ 0008 #ifndef __FSL_LPUART_RTOS_H__ 0009 #define __FSL_LPUART_RTOS_H__ 0010 0011 #include "fsl_lpuart.h" 0012 #include <FreeRTOS.h> 0013 #include <event_groups.h> 0014 #include <semphr.h> 0015 0016 /*! 0017 * @addtogroup lpuart_freertos_driver 0018 * @{ 0019 */ 0020 0021 /******************************************************************************* 0022 * Definitions 0023 ******************************************************************************/ 0024 0025 /*! @name Driver version */ 0026 /*@{*/ 0027 /*! @brief LPUART FreeRTOS driver version. */ 0028 #define FSL_LPUART_FREERTOS_DRIVER_VERSION (MAKE_VERSION(2, 6, 0)) 0029 /*@}*/ 0030 0031 /*! @brief LPUART RTOS configuration structure. */ 0032 typedef struct _lpuart_rtos_config 0033 { 0034 LPUART_Type *base; /*!< UART base address */ 0035 uint32_t srcclk; /*!< UART source clock in Hz*/ 0036 uint32_t baudrate; /*!< Desired communication speed */ 0037 lpuart_parity_mode_t parity; /*!< Parity setting */ 0038 lpuart_stop_bit_count_t stopbits; /*!< Number of stop bits to use */ 0039 uint8_t *buffer; /*!< Buffer for background reception */ 0040 uint32_t buffer_size; /*!< Size of buffer for background reception */ 0041 /* Zero in constant and multiplier is interpreted as infinit timeout. */ 0042 uint32_t rx_timeout_constant_ms; /*!< RX timeout applied per receive */ 0043 uint32_t rx_timeout_multiplier_ms; /*!< RX timeout added for each byte of the receive. */ 0044 uint32_t tx_timeout_constant_ms; /*!< TX timeout applied per transmition */ 0045 uint32_t tx_timeout_multiplier_ms; /*!< TX timeout added for each byte of the transmition. */ 0046 #if defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT 0047 bool enableRxRTS; /*!< RX RTS enable */ 0048 bool enableTxCTS; /*!< TX CTS enable */ 0049 lpuart_transmit_cts_source_t txCtsSource; /*!< TX CTS source */ 0050 lpuart_transmit_cts_config_t txCtsConfig; /*!< TX CTS configure */ 0051 #endif 0052 } lpuart_rtos_config_t; 0053 0054 /*! 0055 * @cond RTOS_PRIVATE 0056 * @name LPUART event flags 0057 * 0058 * This are only valid states for txEvent and rxEvent (lpuart_rtos_handle_t). 0059 */ 0060 /*@{*/ 0061 /*! @brief Event flag - uart transmit complete. */ 0062 #define RTOS_LPUART_TX_COMPLETE 0x1U 0063 /*! @brief Event flag - uart receive complete. */ 0064 #define RTOS_LPUART_RX_COMPLETE 0x2U 0065 /*! @brief Event flag - ring buffer overrun. */ 0066 #define RTOS_LPUART_RING_BUFFER_OVERRUN 0x4U 0067 /*! @brief Event flag - hardware buffer overrun. */ 0068 #define RTOS_LPUART_HARDWARE_BUFFER_OVERRUN 0x8U 0069 /*@}*/ 0070 0071 /*! @brief LPUART FreeRTOS transfer structure. */ 0072 typedef struct _lpuart_rtos_handle 0073 { 0074 LPUART_Type *base; /*!< UART base address */ 0075 lpuart_transfer_t txTransfer; /*!< TX transfer structure */ 0076 lpuart_transfer_t rxTransfer; /*!< RX transfer structure */ 0077 SemaphoreHandle_t rxSemaphore; /*!< RX semaphore for resource sharing */ 0078 SemaphoreHandle_t txSemaphore; /*!< TX semaphore for resource sharing */ 0079 EventGroupHandle_t rxEvent; /*!< RX completion event */ 0080 EventGroupHandle_t txEvent; /*!< TX completion event */ 0081 uint32_t rx_timeout_constant_ms; /*!< RX Timeout applied per transfer */ 0082 uint32_t rx_timeout_multiplier_ms; /*!< RX Timeout added for each byte of the transfer. */ 0083 uint32_t tx_timeout_constant_ms; /*!< TX Timeout applied per transfer */ 0084 uint32_t tx_timeout_multiplier_ms; /*!< TX Timeout added for each byte of the transfer. */ 0085 void *t_state; /*!< Transactional state of the underlying driver */ 0086 #if (configSUPPORT_STATIC_ALLOCATION == 1) 0087 StaticSemaphore_t txSemaphoreBuffer; /*!< Statically allocated memory for txSemaphore */ 0088 StaticSemaphore_t rxSemaphoreBuffer; /*!< Statically allocated memory for rxSemaphore */ 0089 StaticEventGroup_t txEventBuffer; /*!< Statically allocated memory for txEvent */ 0090 StaticEventGroup_t rxEventBuffer; /*!< Statically allocated memory for rxEvent */ 0091 #endif 0092 } lpuart_rtos_handle_t; 0093 /*! \endcond */ 0094 0095 /******************************************************************************* 0096 * API 0097 ******************************************************************************/ 0098 0099 #if defined(__cplusplus) 0100 extern "C" { 0101 #endif 0102 0103 /*! 0104 * @name LPUART RTOS Operation 0105 * @{ 0106 */ 0107 0108 /*! 0109 * @brief Initializes an LPUART instance for operation in RTOS. 0110 * 0111 * @param handle The RTOS LPUART handle, the pointer to an allocated space for RTOS context. 0112 * @param t_handle The pointer to an allocated space to store the transactional layer internal state. 0113 * @param cfg The pointer to the parameters required to configure the LPUART after initialization. 0114 * @return 0 succeed, others failed 0115 */ 0116 int LPUART_RTOS_Init(lpuart_rtos_handle_t *handle, lpuart_handle_t *t_handle, const lpuart_rtos_config_t *cfg); 0117 0118 /*! 0119 * @brief Deinitializes an LPUART instance for operation. 0120 * 0121 * This function deinitializes the LPUART module, sets all register value to the reset value, 0122 * and releases the resources. 0123 * 0124 * @param handle The RTOS LPUART handle. 0125 */ 0126 int LPUART_RTOS_Deinit(lpuart_rtos_handle_t *handle); 0127 0128 /*! 0129 * @name LPUART transactional Operation 0130 * @{ 0131 */ 0132 0133 /*! 0134 * @brief Sends data in the background. 0135 * 0136 * This function sends data. It is an synchronous API. 0137 * If the hardware buffer is full, the task is in the blocked state. 0138 * 0139 * @param handle The RTOS LPUART handle. 0140 * @param buffer The pointer to buffer to send. 0141 * @param length The number of bytes to send. 0142 */ 0143 int LPUART_RTOS_Send(lpuart_rtos_handle_t *handle, uint8_t *buffer, uint32_t length); 0144 0145 /*! 0146 * @brief Receives data. 0147 * 0148 * This function receives data from LPUART. It is an synchronous API. If any data is immediately available 0149 * it is returned immediately and the number of bytes received. 0150 * 0151 * @param handle The RTOS LPUART handle. 0152 * @param buffer The pointer to buffer where to write received data. 0153 * @param length The number of bytes to receive. 0154 * @param received The pointer to a variable of size_t where the number of received data is filled. 0155 */ 0156 int LPUART_RTOS_Receive(lpuart_rtos_handle_t *handle, uint8_t *buffer, uint32_t length, size_t *received); 0157 0158 /*! 0159 * @brief Set RX timeout in runtime 0160 * 0161 * This function can modify RX timeout between initialization and receive. 0162 * 0163 * param handle The RTOS LPUART handle. 0164 * param rx_timeout_constant_ms RX timeout applied per receive. 0165 * param rx_timeout_multiplier_ms RX timeout added for each byte of the receive. 0166 */ 0167 int LPUART_RTOS_SetRxTimeout(lpuart_rtos_handle_t *handle, 0168 uint32_t rx_timeout_constant_ms, 0169 uint32_t rx_timeout_multiplier_ms); 0170 0171 /*! 0172 * @brief Set TX timeout in runtime 0173 * 0174 * This function can modify TX timeout between initialization and send. 0175 * 0176 * param handle The RTOS LPUART handle. 0177 * param tx_timeout_constant_ms TX timeout applied per transmition. 0178 * param tx_timeout_multiplier_ms TX timeout added for each byte of the transmition. 0179 */ 0180 int LPUART_RTOS_SetTxTimeout(lpuart_rtos_handle_t *handle, 0181 uint32_t tx_timeout_constant_ms, 0182 uint32_t tx_timeout_multiplier_ms); 0183 0184 /* @} */ 0185 0186 #if defined(__cplusplus) 0187 } 0188 #endif 0189 0190 /*! @}*/ 0191 0192 #endif /* __FSL_LPUART_RTOS_H__ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |