hci_slip.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /** @file
  13. *
  14. * @defgroup hci_slip SLIP module
  15. * @{
  16. * @ingroup app_common
  17. *
  18. * @brief SLIP layer for supporting packet framing in HCI transport.
  19. *
  20. * @details This module implements SLIP packet framing as described in the Bluetooth Core
  21. * Specification 4.0, Volume 4, Part D, Chapter 3 SLIP Layer.
  22. *
  23. * SLIP framing ensures that all packets sent on the UART are framed as:
  24. * <0xC0> SLIP packet 1 <0xC0> <0xC0> SLIP packet 2 <0xC0>.
  25. *
  26. * The SLIP layer uses events to notify the upper layer when data transmission is complete
  27. * and when a SLIP packet is received.
  28. */
  29. #ifndef HCI_SLIP_H__
  30. #define HCI_SLIP_H__
  31. #include <stdint.h>
  32. /**@brief Event types from the SLIP Layer. */
  33. typedef enum
  34. {
  35. HCI_SLIP_RX_RDY, /**< An event indicating that an RX packet is ready to be read. */
  36. HCI_SLIP_TX_DONE, /**< An event indicating write completion of the TX packet provided in the function call \ref hci_slip_write . */
  37. HCI_SLIP_RX_OVERFLOW, /**< An event indicating that RX data has been discarded due to lack of free RX memory. */
  38. HCI_SLIP_ERROR, /**< An event indicating that an unrecoverable error has occurred. */
  39. HCI_SLIP_EVT_TYPE_MAX /**< Enumeration upper bound. */
  40. } hci_slip_evt_type_t;
  41. /**@brief Structure containing an event from the SLIP layer.
  42. */
  43. typedef struct
  44. {
  45. hci_slip_evt_type_t evt_type; /**< Type of event. */
  46. const uint8_t * packet; /**< This field contains a pointer to the packet for which the event relates, i.e. SLIP_TX_DONE: the packet transmitted, SLIP_RX_RDY: the packet received, SLIP_RX_OVERFLOW: The packet which overflow/or NULL if no receive buffer is available. */
  47. uint32_t packet_length; /**< Packet length, i.e. SLIP_TX_DONE: Bytes transmitted, SLIP_RX_RDY: Bytes received, SLIP_RX_OVERFLOW: index at which the packet overflowed. */
  48. } hci_slip_evt_t;
  49. /**@brief Function for the SLIP layer event callback.
  50. */
  51. typedef void (*hci_slip_event_handler_t)(hci_slip_evt_t event);
  52. /**@brief Function for registering the event handler provided as parameter and this event handler
  53. * will be used by SLIP layer to send events described in \ref hci_slip_evt_type_t.
  54. *
  55. * @note Multiple registration requests will overwrite any existing registration.
  56. *
  57. * @param[in] event_handler This function is called by the SLIP layer upon an event.
  58. *
  59. * @retval NRF_SUCCESS Operation success.
  60. */
  61. uint32_t hci_slip_evt_handler_register(hci_slip_event_handler_t event_handler);
  62. /**@brief Function for opening the SLIP layer. This function must be called before
  63. * \ref hci_slip_write and before any data can be received.
  64. *
  65. * @note Can be called multiple times.
  66. *
  67. * @retval NRF_SUCCESS Operation success.
  68. *
  69. * The SLIP layer module will propagate errors from underlying sub-modules.
  70. * This implementation is using UART module as a physical transmission layer, and hci_slip_open
  71. * executes \ref app_uart_init . For an extended error list, please refer to \ref app_uart_init .
  72. */
  73. uint32_t hci_slip_open(void);
  74. /**@brief Function for closing the SLIP layer. After this function is called no data can be
  75. * transmitted or received in this layer.
  76. *
  77. * @note This function can be called multiple times and also for an unopened channel.
  78. *
  79. * @retval NRF_SUCCESS Operation success.
  80. */
  81. uint32_t hci_slip_close(void);
  82. /**@brief Function for writing a packet with SLIP encoding. Packet transmission is confirmed when
  83. * the HCI_SLIP_TX_DONE event is received by the function caller.
  84. *
  85. * @param[in] p_buffer Pointer to the packet to transmit.
  86. * @param[in] length Packet length, in bytes.
  87. *
  88. * @retval NRF_SUCCESS Operation success. Packet was encoded and added to the
  89. * transmission queue and an event will be sent upon transmission
  90. * completion.
  91. * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
  92. * added to the transmission queue. Application shall wait for
  93. * the \ref HCI_SLIP_TX_DONE event. After HCI_SLIP_TX_DONE this
  94. * function can be executed for transmission of next packet.
  95. * @retval NRF_ERROR_INVALID_ADDR If a NULL pointer is provided.
  96. * @retval NRF_ERROR_INVALID_STATE Operation failure. Module is not open.
  97. */
  98. uint32_t hci_slip_write(const uint8_t * p_buffer, uint32_t length);
  99. /**@brief Function for registering a receive buffer. The receive buffer will be used for storage of
  100. * received and SLIP decoded data.
  101. * No data can be received by the SLIP layer until a receive buffer has been registered.
  102. *
  103. * @note The lifetime of the buffer must be valid during complete reception of data. A static
  104. * buffer is recommended.
  105. *
  106. * @warning Multiple registration requests will overwrite any existing registration.
  107. *
  108. * @param[in] p_buffer Pointer to receive buffer. The received and SLIP decoded packet
  109. * will be placed in this buffer.
  110. * @param[in] length Buffer length, in bytes.
  111. *
  112. * @retval NRF_SUCCESS Operation success.
  113. */
  114. uint32_t hci_slip_rx_buffer_register(uint8_t * p_buffer, uint32_t length);
  115. #endif // HCI_SLIP_H__
  116. /** @} */