Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
Rohit Grover
Date:
Mon Jul 07 13:43:31 2014 +0100
Revision:
37:c29c330d942c
Parent:
0:eff01767de02
changes required to upgrade to V7 of the soft-device

Who changed what in which revision?

UserRevisionLine numberNew 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
bogdanm 0:eff01767de02 36 /**@brief Event types from the SLIP Layer. */
bogdanm 0:eff01767de02 37 typedef enum
bogdanm 0:eff01767de02 38 {
bogdanm 0:eff01767de02 39 HCI_SLIP_RX_RDY, /**< An event indicating that an RX packet is ready to be read. */
bogdanm 0:eff01767de02 40 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 41 HCI_SLIP_RX_OVERFLOW, /**< An event indicating that RX data has been discarded due to lack of free RX memory. */
bogdanm 0:eff01767de02 42 HCI_SLIP_ERROR, /**< An event indicating that an unrecoverable error has occurred. */
bogdanm 0:eff01767de02 43 HCI_SLIP_EVT_TYPE_MAX /**< Enumeration upper bound. */
bogdanm 0:eff01767de02 44 } hci_slip_evt_type_t;
bogdanm 0:eff01767de02 45
bogdanm 0:eff01767de02 46 /**@brief Structure containing an event from the SLIP layer.
bogdanm 0:eff01767de02 47 */
bogdanm 0:eff01767de02 48 typedef struct
bogdanm 0:eff01767de02 49 {
bogdanm 0:eff01767de02 50 hci_slip_evt_type_t evt_type; /**< Type of event. */
bogdanm 0:eff01767de02 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. */
bogdanm 0:eff01767de02 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. */
bogdanm 0:eff01767de02 53 } hci_slip_evt_t;
bogdanm 0:eff01767de02 54
bogdanm 0:eff01767de02 55 /**@brief Function for the SLIP layer event callback.
bogdanm 0:eff01767de02 56 */
bogdanm 0:eff01767de02 57 typedef void (*hci_slip_event_handler_t)(hci_slip_evt_t event);
bogdanm 0:eff01767de02 58
bogdanm 0:eff01767de02 59 /**@brief Function for registering the event handler provided as parameter and this event handler
bogdanm 0:eff01767de02 60 * will be used by SLIP layer to send events described in \ref hci_slip_evt_type_t.
bogdanm 0:eff01767de02 61 *
bogdanm 0:eff01767de02 62 * @note Multiple registration requests will overwrite any existing registration.
bogdanm 0:eff01767de02 63 *
bogdanm 0:eff01767de02 64 * @param[in] event_handler This function is called by the SLIP layer upon an event.
bogdanm 0:eff01767de02 65 *
bogdanm 0:eff01767de02 66 * @retval NRF_SUCCESS Operation success.
bogdanm 0:eff01767de02 67 */
bogdanm 0:eff01767de02 68 uint32_t hci_slip_evt_handler_register(hci_slip_event_handler_t event_handler);
bogdanm 0:eff01767de02 69
bogdanm 0:eff01767de02 70 /**@brief Function for opening the SLIP layer. This function must be called before
bogdanm 0:eff01767de02 71 * \ref hci_slip_write and before any data can be received.
bogdanm 0:eff01767de02 72 *
bogdanm 0:eff01767de02 73 * @note Can be called multiple times.
bogdanm 0:eff01767de02 74 *
bogdanm 0:eff01767de02 75 * @retval NRF_SUCCESS Operation success.
bogdanm 0:eff01767de02 76 *
bogdanm 0:eff01767de02 77 * The SLIP layer module will propagate errors from underlying sub-modules.
bogdanm 0:eff01767de02 78 * This implementation is using UART module as a physical transmission layer, and hci_slip_open
bogdanm 0:eff01767de02 79 * executes \ref app_uart_init . For an extended error list, please refer to \ref app_uart_init .
bogdanm 0:eff01767de02 80 */
bogdanm 0:eff01767de02 81 uint32_t hci_slip_open(void);
bogdanm 0:eff01767de02 82
bogdanm 0:eff01767de02 83 /**@brief Function for closing the SLIP layer. After this function is called no data can be
bogdanm 0:eff01767de02 84 * transmitted or received in this layer.
bogdanm 0:eff01767de02 85 *
bogdanm 0:eff01767de02 86 * @note This function can be called multiple times and also for an unopened channel.
bogdanm 0:eff01767de02 87 *
bogdanm 0:eff01767de02 88 * @retval NRF_SUCCESS Operation success.
bogdanm 0:eff01767de02 89 */
bogdanm 0:eff01767de02 90 uint32_t hci_slip_close(void);
bogdanm 0:eff01767de02 91
bogdanm 0:eff01767de02 92 /**@brief Function for writing a packet with SLIP encoding. Packet transmission is confirmed when
bogdanm 0:eff01767de02 93 * the HCI_SLIP_TX_DONE event is received by the function caller.
bogdanm 0:eff01767de02 94 *
bogdanm 0:eff01767de02 95 * @param[in] p_buffer Pointer to the packet to transmit.
bogdanm 0:eff01767de02 96 * @param[in] length Packet length, in bytes.
bogdanm 0:eff01767de02 97 *
bogdanm 0:eff01767de02 98 * @retval NRF_SUCCESS Operation success. Packet was encoded and added to the
bogdanm 0:eff01767de02 99 * transmission queue and an event will be sent upon transmission
bogdanm 0:eff01767de02 100 * completion.
bogdanm 0:eff01767de02 101 * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
bogdanm 0:eff01767de02 102 * added to the transmission queue. Application shall wait for
bogdanm 0:eff01767de02 103 * the \ref HCI_SLIP_TX_DONE event. After HCI_SLIP_TX_DONE this
bogdanm 0:eff01767de02 104 * function can be executed for transmission of next packet.
bogdanm 0:eff01767de02 105 * @retval NRF_ERROR_INVALID_ADDR If a NULL pointer is provided.
bogdanm 0:eff01767de02 106 * @retval NRF_ERROR_INVALID_STATE Operation failure. Module is not open.
bogdanm 0:eff01767de02 107 */
bogdanm 0:eff01767de02 108 uint32_t hci_slip_write(const uint8_t * p_buffer, uint32_t length);
bogdanm 0:eff01767de02 109
bogdanm 0:eff01767de02 110 /**@brief Function for registering a receive buffer. The receive buffer will be used for storage of
bogdanm 0:eff01767de02 111 * received and SLIP decoded data.
bogdanm 0:eff01767de02 112 * No data can be received by the SLIP layer until a receive buffer has been registered.
bogdanm 0:eff01767de02 113 *
bogdanm 0:eff01767de02 114 * @note The lifetime of the buffer must be valid during complete reception of data. A static
bogdanm 0:eff01767de02 115 * buffer is recommended.
bogdanm 0:eff01767de02 116 *
bogdanm 0:eff01767de02 117 * @warning Multiple registration requests will overwrite any existing registration.
bogdanm 0:eff01767de02 118 *
bogdanm 0:eff01767de02 119 * @param[in] p_buffer Pointer to receive buffer. The received and SLIP decoded packet
bogdanm 0:eff01767de02 120 * will be placed in this buffer.
bogdanm 0:eff01767de02 121 * @param[in] length Buffer length, in bytes.
bogdanm 0:eff01767de02 122 *
bogdanm 0:eff01767de02 123 * @retval NRF_SUCCESS Operation success.
bogdanm 0:eff01767de02 124 */
bogdanm 0:eff01767de02 125 uint32_t hci_slip_rx_buffer_register(uint8_t * p_buffer, uint32_t length);
bogdanm 0:eff01767de02 126
bogdanm 0:eff01767de02 127 #endif // HCI_SLIP_H__
bogdanm 0:eff01767de02 128
bogdanm 0:eff01767de02 129 /** @} */