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