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