rpmsg_queue.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright (c) 2014, Mentor Graphics Corporation
  3. * Copyright (c) 2015 Xilinx, Inc.
  4. * Copyright (c) 2016 Freescale Semiconductor, Inc.
  5. * Copyright 2016-2022 NXP
  6. * Copyright 2021 ACRIOS Systems s.r.o.
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holder nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef RPMSG_QUEUE_H_
  34. #define RPMSG_QUEUE_H_
  35. #include "rpmsg_lite.h"
  36. //! @addtogroup rpmsg_queue
  37. //! @{
  38. /*! \typedef rpmsg_queue_handle
  39. \brief Rpmsg queue handle type.
  40. */
  41. typedef void *rpmsg_queue_handle;
  42. /* RL_API_HAS_ZEROCOPY has to be enabled for RPMsg Queue to work */
  43. #if defined(RL_API_HAS_ZEROCOPY) && (RL_API_HAS_ZEROCOPY == 1)
  44. /*******************************************************************************
  45. * API
  46. ******************************************************************************/
  47. /* Exported API functions */
  48. #if defined(__cplusplus)
  49. extern "C" {
  50. #endif
  51. /*!
  52. * @brief
  53. * This callback needs to be registered with an endpoint
  54. *
  55. * @param payload Pointer to the buffer containing received data
  56. * @param payload_len Size of data received, in bytes
  57. * @param src Pointer to address of the endpoint from which data is received
  58. * @param priv Private data provided during endpoint creation
  59. *
  60. * @return RL_HOLD or RL_RELEASE to release or hold the buffer in payload
  61. */
  62. int32_t rpmsg_queue_rx_cb(void *payload, uint32_t payload_len, uint32_t src, void *priv);
  63. /*!
  64. * @brief
  65. * Create a RPMsg queue which can be used
  66. * for blocking reception.
  67. *
  68. * @param rpmsg_lite_dev RPMsg Lite instance
  69. * @param queue_storage RPMsg Lite queue static storage pointer
  70. * @param queue_ctxt RPMsg Lite queue static context holder
  71. *
  72. * @return RPMsg queue handle or RL_NULL
  73. *
  74. */
  75. #if defined(RL_USE_STATIC_API) && (RL_USE_STATIC_API == 1)
  76. rpmsg_queue_handle rpmsg_queue_create(struct rpmsg_lite_instance *rpmsg_lite_dev,
  77. uint8_t *queue_storage,
  78. rpmsg_static_queue_ctxt *queue_ctxt);
  79. #else
  80. rpmsg_queue_handle rpmsg_queue_create(struct rpmsg_lite_instance *rpmsg_lite_dev);
  81. #endif
  82. /*!
  83. * @brief
  84. * Destroy a queue and clean up.
  85. * Do not destroy a queue which is registered with an active endpoint!
  86. *
  87. * @param rpmsg_lite_dev RPMsg-Lite instance
  88. * @param[in] q RPMsg queue handle to destroy
  89. *
  90. * @return Status of function execution
  91. *
  92. */
  93. int32_t rpmsg_queue_destroy(struct rpmsg_lite_instance *rpmsg_lite_dev, rpmsg_queue_handle q);
  94. /*!
  95. * @brief
  96. * blocking receive function - blocking version of the received function that can be called from an RTOS task.
  97. * The data is copied from the receive buffer into the user supplied buffer.
  98. *
  99. * This is the "receive with copy" version of the RPMsg receive function. This version is simple
  100. * to use but it requires copying data from shared memory into the user space buffer.
  101. * The user has no obligation or burden to manage the shared memory buffers.
  102. *
  103. * @param rpmsg_lite_dev RPMsg-Lite instance
  104. * @param[in] q RPMsg queue handle to listen on
  105. * @param[in] data Pointer to the user buffer the received data are copied to
  106. * @param[out] len Pointer to an int variable that will contain the number of bytes actually copied into the
  107. * buffer
  108. * @param[in] maxlen Maximum number of bytes to copy (received buffer size)
  109. * @param[out] src Pointer to address of the endpoint from which data is received
  110. * @param[in] timeout Timeout, in milliseconds, to wait for a message. A value of 0 means don't wait (non-blocking
  111. * call).
  112. * A value of 0xffffffff means wait forever (blocking call).
  113. *
  114. * @return Status of function execution
  115. *
  116. * @see rpmsg_queue_recv_nocopy
  117. */
  118. int32_t rpmsg_queue_recv(struct rpmsg_lite_instance *rpmsg_lite_dev,
  119. rpmsg_queue_handle q,
  120. uint32_t *src,
  121. char *data,
  122. uint32_t maxlen,
  123. uint32_t *len,
  124. uintptr_t timeout);
  125. /*!
  126. * @brief
  127. * blocking receive function - blocking version of the received function that can be called from an RTOS task.
  128. * The data is NOT copied into the user-app. buffer.
  129. *
  130. * This is the "zero-copy receive" version of the RPMsg receive function. No data is copied.
  131. * Only the pointer to the data is returned. This version is fast, but it requires the user to manage
  132. * buffer allocation. Specifically, the user must decide when a buffer is no longer in use and
  133. * make the appropriate API call to free it, see rpmsg_queue_nocopy_free().
  134. *
  135. * @param rpmsg_lite_dev RPMsg Lite instance
  136. * @param[in] q RPMsg queue handle to listen on
  137. * @param[out] data Pointer to the RPMsg buffer of the shared memory where the received data is stored
  138. * @param[out] len Pointer to an int variable that that will contain the number of valid bytes in the RPMsg
  139. * buffer
  140. * @param[out] src Pointer to address of the endpoint from which data is received
  141. * @param[in] timeout Timeout, in milliseconds, to wait for a message. A value of 0 means don't wait (non-blocking
  142. * call).
  143. * A value of 0xffffffff means wait forever (blocking call).
  144. *
  145. * @return Status of function execution.
  146. *
  147. * @see rpmsg_queue_nocopy_free
  148. * @see rpmsg_queue_recv
  149. */
  150. int32_t rpmsg_queue_recv_nocopy(struct rpmsg_lite_instance *rpmsg_lite_dev,
  151. rpmsg_queue_handle q,
  152. uint32_t *src,
  153. char **data,
  154. uint32_t *len,
  155. uintptr_t timeout);
  156. /*!
  157. * @brief This function frees a buffer previously returned by rpmsg_queue_recv_nocopy().
  158. *
  159. * Once the zero-copy mechanism of receiving data is used, this function
  160. * has to be called to free a buffer and to make it available for the next data
  161. * transfer.
  162. *
  163. * @param rpmsg_lite_dev RPMsg-Lite instance
  164. * @param[in] data Pointer to the RPMsg buffer of the shared memory that has to be freed
  165. *
  166. * @return Status of function execution.
  167. *
  168. * @see rpmsg_queue_recv_nocopy
  169. */
  170. int32_t rpmsg_queue_nocopy_free(struct rpmsg_lite_instance *rpmsg_lite_dev, void *data);
  171. /*!
  172. * @brief This function returns the number of pending messages in the queue.
  173. *
  174. * @param[in] q RPMsg queue handle
  175. *
  176. * @return Number of pending messages in the queue.
  177. */
  178. int32_t rpmsg_queue_get_current_size(rpmsg_queue_handle q);
  179. //! @}
  180. #if defined(__cplusplus)
  181. }
  182. #endif
  183. #endif /* RL_API_HAS_ZEROCOPY */
  184. #endif /* RPMSG_QUEUE_H_ */