fsl_lpuart_freertos.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef __FSL_LPUART_RTOS_H__
  9. #define __FSL_LPUART_RTOS_H__
  10. #include "fsl_lpuart.h"
  11. #include <FreeRTOS.h>
  12. #include <event_groups.h>
  13. #include <semphr.h>
  14. /*!
  15. * @addtogroup lpuart_freertos_driver
  16. * @{
  17. */
  18. /*******************************************************************************
  19. * Definitions
  20. ******************************************************************************/
  21. /*! @name Driver version */
  22. /*@{*/
  23. /*! @brief LPUART FreeRTOS driver version. */
  24. #define FSL_LPUART_FREERTOS_DRIVER_VERSION (MAKE_VERSION(2, 5, 0))
  25. /*@}*/
  26. /*! @brief LPUART RTOS configuration structure. */
  27. typedef struct _lpuart_rtos_config
  28. {
  29. LPUART_Type *base; /*!< UART base address */
  30. uint32_t srcclk; /*!< UART source clock in Hz*/
  31. uint32_t baudrate; /*!< Desired communication speed */
  32. lpuart_parity_mode_t parity; /*!< Parity setting */
  33. lpuart_stop_bit_count_t stopbits; /*!< Number of stop bits to use */
  34. uint8_t *buffer; /*!< Buffer for background reception */
  35. uint32_t buffer_size; /*!< Size of buffer for background reception */
  36. #if defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
  37. bool enableRxRTS; /*!< RX RTS enable */
  38. bool enableTxCTS; /*!< TX CTS enable */
  39. lpuart_transmit_cts_source_t txCtsSource; /*!< TX CTS source */
  40. lpuart_transmit_cts_config_t txCtsConfig; /*!< TX CTS configure */
  41. #endif
  42. } lpuart_rtos_config_t;
  43. /*!
  44. * @cond RTOS_PRIVATE
  45. * @name LPUART event flags
  46. *
  47. * This are only valid states for txEvent and rxEvent (lpuart_rtos_handle_t).
  48. */
  49. /*@{*/
  50. /*! @brief Event flag - transfer complete. */
  51. #define RTOS_LPUART_COMPLETE 0x1U
  52. /*! @brief Event flag - ring buffer overrun. */
  53. #define RTOS_LPUART_RING_BUFFER_OVERRUN 0x2U
  54. /*! @brief Event flag - hardware buffer overrun. */
  55. #define RTOS_LPUART_HARDWARE_BUFFER_OVERRUN 0x4U
  56. /*@}*/
  57. /*! @brief LPUART FreeRTOS transfer structure. */
  58. typedef struct _lpuart_rtos_handle
  59. {
  60. LPUART_Type *base; /*!< UART base address */
  61. lpuart_transfer_t txTransfer; /*!< TX transfer structure */
  62. lpuart_transfer_t rxTransfer; /*!< RX transfer structure */
  63. SemaphoreHandle_t rxSemaphore; /*!< RX semaphore for resource sharing */
  64. SemaphoreHandle_t txSemaphore; /*!< TX semaphore for resource sharing */
  65. EventGroupHandle_t rxEvent; /*!< RX completion event */
  66. EventGroupHandle_t txEvent; /*!< TX completion event */
  67. void *t_state; /*!< Transactional state of the underlying driver */
  68. #if (configSUPPORT_STATIC_ALLOCATION == 1)
  69. StaticSemaphore_t txSemaphoreBuffer; /*!< Statically allocated memory for txSemaphore */
  70. StaticSemaphore_t rxSemaphoreBuffer; /*!< Statically allocated memory for rxSemaphore */
  71. StaticEventGroup_t txEventBuffer; /*!< Statically allocated memory for txEvent */
  72. StaticEventGroup_t rxEventBuffer; /*!< Statically allocated memory for rxEvent */
  73. #endif
  74. } lpuart_rtos_handle_t;
  75. /*! \endcond */
  76. /*******************************************************************************
  77. * API
  78. ******************************************************************************/
  79. #if defined(__cplusplus)
  80. extern "C" {
  81. #endif
  82. /*!
  83. * @name LPUART RTOS Operation
  84. * @{
  85. */
  86. /*!
  87. * @brief Initializes an LPUART instance for operation in RTOS.
  88. *
  89. * @param handle The RTOS LPUART handle, the pointer to an allocated space for RTOS context.
  90. * @param t_handle The pointer to an allocated space to store the transactional layer internal state.
  91. * @param cfg The pointer to the parameters required to configure the LPUART after initialization.
  92. * @return 0 succeed, others failed
  93. */
  94. int LPUART_RTOS_Init(lpuart_rtos_handle_t *handle, lpuart_handle_t *t_handle, const lpuart_rtos_config_t *cfg);
  95. /*!
  96. * @brief Deinitializes an LPUART instance for operation.
  97. *
  98. * This function deinitializes the LPUART module, sets all register value to the reset value,
  99. * and releases the resources.
  100. *
  101. * @param handle The RTOS LPUART handle.
  102. */
  103. int LPUART_RTOS_Deinit(lpuart_rtos_handle_t *handle);
  104. /*!
  105. * @name LPUART transactional Operation
  106. * @{
  107. */
  108. /*!
  109. * @brief Sends data in the background.
  110. *
  111. * This function sends data. It is an synchronous API.
  112. * If the hardware buffer is full, the task is in the blocked state.
  113. *
  114. * @param handle The RTOS LPUART handle.
  115. * @param buffer The pointer to buffer to send.
  116. * @param length The number of bytes to send.
  117. */
  118. int LPUART_RTOS_Send(lpuart_rtos_handle_t *handle, uint8_t *buffer, uint32_t length);
  119. /*!
  120. * @brief Receives data.
  121. *
  122. * This function receives data from LPUART. It is an synchronous API. If any data is immediately available
  123. * it is returned immediately and the number of bytes received.
  124. *
  125. * @param handle The RTOS LPUART handle.
  126. * @param buffer The pointer to buffer where to write received data.
  127. * @param length The number of bytes to receive.
  128. * @param received The pointer to a variable of size_t where the number of received data is filled.
  129. */
  130. int LPUART_RTOS_Receive(lpuart_rtos_handle_t *handle, uint8_t *buffer, uint32_t length, size_t *received);
  131. /* @} */
  132. #if defined(__cplusplus)
  133. }
  134. #endif
  135. /*! @}*/
  136. #endif /* __FSL_LPUART_RTOS_H__ */