meh

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Fri Sep 12 16:41:52 2014 +0100
Revision:
89:552587b429a1
Release 89 of the mbed library

Main changes:

- low power optimizations for Nordic targets
- code structure changes for Freescale K64F targets
- bug fixes in various backends

Who changed what in which revision?

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