25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

150 satır
4.8 KiB

  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_UART_RTOS_H__
  9. #define __FSL_UART_RTOS_H__
  10. #include "fsl_uart.h"
  11. #include <FreeRTOS.h>
  12. #include <event_groups.h>
  13. #include <semphr.h>
  14. /*!
  15. * @addtogroup uart_freertos_driver
  16. * @{
  17. */
  18. /*******************************************************************************
  19. * Definitions
  20. ******************************************************************************/
  21. /*! @name Driver version */
  22. /*@{*/
  23. /*! @brief UART FreeRTOS driver version 2.3.0. */
  24. #define FSL_UART_FREERTOS_DRIVER_VERSION (MAKE_VERSION(2, 3, 0))
  25. /*@}*/
  26. /*! @brief UART configuration structure */
  27. typedef struct _uart_rtos_config
  28. {
  29. UART_Type *base; /*!< UART base address */
  30. uint32_t srcclk; /*!< UART source clock in Hz*/
  31. uint32_t baudrate; /*!< Desired communication speed */
  32. uart_parity_mode_t parity; /*!< Parity setting */
  33. uart_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. } uart_rtos_config_t;
  37. /*!
  38. * @cond RTOS_PRIVATE
  39. * @name UART FreeRTOS handler
  40. *
  41. * These are the only valid states for txEvent and rxEvent (uart_rtos_handle_t).
  42. */
  43. /*@{*/
  44. /*! @brief Event flag - transfer complete. */
  45. #define RTOS_UART_COMPLETE 0x1
  46. /*! @brief Event flag - ring buffer overrun. */
  47. #define RTOS_UART_RING_BUFFER_OVERRUN 0x2
  48. /*! @brief Event flag - hardware buffer overrun. */
  49. #define RTOS_UART_HARDWARE_BUFFER_OVERRUN 0x4
  50. /*@}*/
  51. /*! @brief UART FreeRTOS transfer structure. */
  52. typedef struct _uart_rtos_handle
  53. {
  54. UART_Type *base; /*!< UART base address */
  55. uart_transfer_t txTransfer; /*!< TX transfer structure */
  56. uart_transfer_t rxTransfer; /*!< RX transfer structure */
  57. SemaphoreHandle_t rxSemaphore; /*!< RX semaphore for resource sharing */
  58. SemaphoreHandle_t txSemaphore; /*!< TX semaphore for resource sharing */
  59. EventGroupHandle_t rxEvent; /*!< RX completion event */
  60. EventGroupHandle_t txEvent; /*!< TX completion event */
  61. void *t_state; /*!< Transactional state of the underlying driver */
  62. #if (configSUPPORT_STATIC_ALLOCATION == 1)
  63. StaticSemaphore_t txSemaphoreBuffer; /*!< Statically allocated memory for txSemaphore */
  64. StaticSemaphore_t rxSemaphoreBuffer; /*!< Statically allocated memory for rxSemaphore */
  65. StaticEventGroup_t txEventBuffer; /*!< Statically allocated memory for txEvent */
  66. StaticEventGroup_t rxEventBuffer; /*!< Statically allocated memory for rxEvent */
  67. #endif
  68. } uart_rtos_handle_t;
  69. /*! \endcond */
  70. /*******************************************************************************
  71. * API
  72. ******************************************************************************/
  73. #if defined(__cplusplus)
  74. extern "C" {
  75. #endif
  76. /*!
  77. * @name UART RTOS Operation
  78. * @{
  79. */
  80. /*!
  81. * @brief Initializes a UART instance for operation in RTOS.
  82. *
  83. * @param handle The RTOS UART handle, the pointer to an allocated space for RTOS context.
  84. * @param t_handle The pointer to the allocated space to store the transactional layer internal state.
  85. * @param cfg The pointer to the parameters required to configure the UART after initialization.
  86. * @return 0 succeed; otherwise fail.
  87. */
  88. int UART_RTOS_Init(uart_rtos_handle_t *handle, uart_handle_t *t_handle, const uart_rtos_config_t *cfg);
  89. /*!
  90. * @brief Deinitializes a UART instance for operation.
  91. *
  92. * This function deinitializes the UART module, sets all register values to reset value,
  93. * and frees the resources.
  94. *
  95. * @param handle The RTOS UART handle.
  96. */
  97. int UART_RTOS_Deinit(uart_rtos_handle_t *handle);
  98. /*!
  99. * @name UART transactional Operation
  100. * @{
  101. */
  102. /*!
  103. * @brief Sends data in the background.
  104. *
  105. * This function sends data. It is a synchronous API.
  106. * If the hardware buffer is full, the task is in the blocked state.
  107. *
  108. * @param handle The RTOS UART handle.
  109. * @param buffer The pointer to the buffer to send.
  110. * @param length The number of bytes to send.
  111. */
  112. int UART_RTOS_Send(uart_rtos_handle_t *handle, const uint8_t *buffer, uint32_t length);
  113. /*!
  114. * @brief Receives data.
  115. *
  116. * This function receives data from UART. It is a synchronous API. If data is immediately available,
  117. * it is returned immediately and the number of bytes received.
  118. *
  119. * @param handle The RTOS UART handle.
  120. * @param buffer The pointer to the buffer to write received data.
  121. * @param length The number of bytes to receive.
  122. * @param received The pointer to a variable of size_t where the number of received data is filled.
  123. */
  124. int UART_RTOS_Receive(uart_rtos_handle_t *handle, uint8_t *buffer, uint32_t length, size_t *received);
  125. /* @} */
  126. #if defined(__cplusplus)
  127. }
  128. #endif
  129. /*! @}*/
  130. #endif /* __FSL_UART_RTOS_H__ */