ser_phy_hci.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /** @file
  41. *
  42. * @defgroup ser_phy_hci HCI Serialization PHY
  43. * @{
  44. * @ingroup ble_sdk_lib_serialization
  45. *
  46. * @brief HCI PHY layer for serialization.
  47. *
  48. * @details This file contains declarations of functions and definitions of data structures and
  49. * identifiers (typedef enum) used as API of the serialization HCI PHY layer.
  50. *
  51. *
  52. */
  53. #ifndef SER_PHY_HCI_H__
  54. #define SER_PHY_HCI_H__
  55. #include <stdint.h>
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. /**@brief Serialization PHY HCI module events types. */
  60. typedef enum
  61. {
  62. SER_PHY_HCI_SLIP_EVT_PKT_SENT = 0, /**< An event indicating that packet has been transmitted. */
  63. SER_PHY_HCI_SLIP_EVT_ACK_SENT, /**< An event indicating that ack packet has been transmitted. */
  64. SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED, /**< An event indicating that packet has been received. */
  65. SER_PHY_HCI_SLIP_EVT_HW_ERROR, /**< An event indicating a hardware error in PHY HCI module. */
  66. SER_PHY_HCI_SLIP_EVT_TYPE_MAX /**< Enumeration upper bound. */
  67. } ser_phy_hci_slip_evt_type_t;
  68. /**@brief Struct representing a PHY HCI packet. */
  69. typedef struct
  70. {
  71. uint8_t * p_buffer; /**< Pointer to a buffer containing a packet. */
  72. uint16_t num_of_bytes; /**< Length of a packet in octets. */
  73. } ser_phy_hci_pkt_params_t;
  74. /**@brief Struct containing parameters of event of type @ref SER_PHY_HCI_SLIP_EVT_HW_ERROR. */
  75. typedef struct
  76. {
  77. uint32_t error_code; /**< Hardware error code - specific for a microcontroller. */
  78. } ser_phy_hci_evt_hw_error_params_t;
  79. /**@brief Struct containing events from the Serialization PHY module.
  80. *
  81. * @note Some events do not have parameters, then the whole information is contained in the evt_type.
  82. */
  83. typedef struct
  84. {
  85. ser_phy_hci_slip_evt_type_t evt_type; /**< Type of an event. */
  86. union /**< Union alternative identified by evt_type in the enclosing struct. */
  87. {
  88. /** Parameters of event of type @ref SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED. */
  89. ser_phy_hci_pkt_params_t received_pkt;
  90. /** Parameters of event of type @ref SER_PHY_HCI_SLIP_EVT_HW_ERROR. */
  91. ser_phy_hci_evt_hw_error_params_t hw_error;
  92. } evt_params;
  93. } ser_phy_hci_slip_evt_t;
  94. /**@brief Type of generic callback function handler to be used by all PHY HCI events.
  95. *
  96. * @param[in] event Serialization PHY HCI module event.
  97. */
  98. typedef void (*ser_phy_hci_slip_event_handler_t)(ser_phy_hci_slip_evt_t *p_event);
  99. /**@brief Function for opening and initializing a HCI SLIP PHY module.
  100. *
  101. * @note The function initializes hardware and internal module states and registers callback
  102. * function to be used by all PHY HCI module events.
  103. *
  104. * @warning If the function has been already called, the function @ref ser_phy_hci_slip_close has to be
  105. * called before ser_phy_hci_slip_open can be called again.
  106. *
  107. * @param[in] events_handler Generic callback function handler to be used by all PHY HCI module
  108. * events.
  109. *
  110. * @retval NRF_SUCCESS Operation success.
  111. * @retval NRF_ERROR_INVALID_STATE Operation failure. The function has been already called.
  112. * To call it again, the function @ref ser_phy_hci_slip_close has to
  113. * be called first.
  114. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
  115. * @retval NRF_ERROR_INVALID_PARAM Operation failure. Hardware initialization parameters are not
  116. * supported.
  117. */
  118. uint32_t ser_phy_hci_slip_open(ser_phy_hci_slip_event_handler_t events_handler);
  119. /**@brief Function for resetting the module.*/
  120. void ser_phy_hci_slip_reset(void);
  121. /**@brief A function for transmitting a HCI SLIP packet.
  122. *
  123. * @note The function adds a packet pointed by p_buffer parameter to a transmission queue and
  124. * schedules generation of an event of type @ref SER_PHY_HCI_SLIP_EVT_PKT_SENT upon transmission
  125. * completion.
  126. *
  127. * @param[in] p_header Pointer to ser_phy_hci_pkt_params_t structure representing packet header.
  128. * @param[in] p_payload Pointer to ser_phy_hci_pkt_params_t structure representing packet payload.
  129. * @param[in] p_crc Pointer to ser_phy_hci_pkt_params_t structure representing packet crc.
  130. *
  131. * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue
  132. * and event will be sent upon transmission completion.
  133. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied in p_header parameter.
  134. * NULL pointer is allowed for p_payload and p_crc parameters.
  135. * @retval NRF_ERROR_INVALID_PARAM Operation failure. Number of bytes to be sent equals 0.
  136. * @retval NRF_ERROR_BUSY Operation failure. Transmitting of a packet in progress.
  137. */
  138. uint32_t ser_phy_hci_slip_tx_pkt_send(const ser_phy_hci_pkt_params_t * p_header,
  139. const ser_phy_hci_pkt_params_t * p_payload,
  140. const ser_phy_hci_pkt_params_t * p_crc);
  141. /**@brief A function for freeing an RX buffer.
  142. *
  143. * @note The function has to be called as a response to event @ref SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED
  144. * when an RX packet has been processed. The function frees the RX buffer and therefore enables
  145. * reception of next incoming data.
  146. * @param[in] p_buffer Pointer to an RX buffer which must be freed.
  147. *
  148. * @retval NRF_SUCCESS Operation success.
  149. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
  150. * @retval NRF_ERROR_INVALID_STATE Operation failure. A buffer was already free.
  151. */
  152. uint32_t ser_phy_hci_slip_rx_buf_free(uint8_t * p_buffer);
  153. /**@brief A function for closing a PHY HCI module.
  154. *
  155. * @note The function disables hardware, resets internal module states, and unregisters the events
  156. * callback function.
  157. */
  158. void ser_phy_hci_slip_close(void);
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif /* SER_PHY_HCI_H__ */
  163. /** @} */