BLE temperature profile using digital DS1820 or analog LM35 sensors

Dependencies:   DS1820

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hci_slip.h Source File

hci_slip.h

Go to the documentation of this file.
00001 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is property of Nordic Semiconductor ASA.
00004  * Terms and conditions of usage are described in detail in NORDIC
00005  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *
00011  */
00012  
00013 /** @file
00014  *
00015  * @defgroup hci_slip SLIP module
00016  * @{
00017  * @ingroup app_common
00018  *
00019  * @brief SLIP layer for supporting packet framing in HCI transport.
00020  *
00021  * @details This module implements SLIP packet framing as described in the Bluetooth Core
00022  *          Specification 4.0, Volume 4, Part D, Chapter 3 SLIP Layer.
00023  *
00024  *          SLIP framing ensures that all packets sent on the UART are framed as:
00025  *          <0xC0> SLIP packet 1 <0xC0> <0xC0> SLIP packet 2 <0xC0>.
00026  *
00027  *          The SLIP layer uses events to notify the upper layer when data transmission is complete
00028  *          and when a SLIP packet is received.
00029  */
00030 
00031 #ifndef HCI_SLIP_H__
00032 #define HCI_SLIP_H__
00033 
00034 #include <stdint.h>
00035 #include "nordic_global.h"
00036 
00037 /**@brief Event types from the SLIP Layer. */
00038 typedef enum
00039 {
00040     HCI_SLIP_RX_RDY,                        /**< An event indicating that an RX packet is ready to be read. */
00041     HCI_SLIP_TX_DONE,                       /**< An event indicating write completion of the TX packet provided in the function call \ref hci_slip_write . */
00042     HCI_SLIP_RX_OVERFLOW,                   /**< An event indicating that RX data has been discarded due to lack of free RX memory. */
00043     HCI_SLIP_ERROR,                         /**< An event indicating that an unrecoverable error has occurred. */
00044     HCI_SLIP_EVT_TYPE_MAX                   /**< Enumeration upper bound. */
00045 } hci_slip_evt_type_t;
00046 
00047 /**@brief Structure containing an event from the SLIP layer.
00048  */
00049 typedef struct
00050 {
00051     hci_slip_evt_type_t evt_type;           /**< Type of event. */
00052     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. */
00053     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. */
00054 } hci_slip_evt_t;
00055 
00056 /**@brief Function for the SLIP layer event callback.
00057  */
00058 typedef void (*hci_slip_event_handler_t)(hci_slip_evt_t event);
00059 
00060 /**@brief Function for registering the event handler provided as parameter and this event handler
00061  *        will be used by SLIP layer to send events described in \ref hci_slip_evt_type_t.
00062  *
00063  * @note Multiple registration requests will overwrite any existing registration. 
00064  *
00065  * @param[in] event_handler         This function is called by the SLIP layer upon an event.
00066  *
00067  * @retval NRF_SUCCESS              Operation success.
00068  */
00069 uint32_t hci_slip_evt_handler_register(hci_slip_event_handler_t event_handler);
00070 
00071 /**@brief Function for opening the SLIP layer. This function must be called before
00072  *        \ref hci_slip_write and before any data can be received.
00073  *
00074  * @note Can be called multiple times. 
00075  * 
00076  * @retval NRF_SUCCESS              Operation success.
00077  *
00078  * The SLIP layer module will propagate errors from underlying sub-modules.
00079  * This implementation is using UART module as a physical transmission layer, and hci_slip_open
00080  * executes \ref app_uart_init . For an extended error list, please refer to \ref app_uart_init .
00081  */
00082 uint32_t hci_slip_open(void);
00083 
00084 /**@brief Function for closing the SLIP layer. After this function is called no data can be
00085  *        transmitted or received in this layer.
00086  *
00087  * @note This function can be called multiple times and also for an unopened channel.
00088  * 
00089  * @retval NRF_SUCCESS              Operation success.  
00090  */
00091 uint32_t hci_slip_close(void);
00092 
00093 /**@brief Function for writing a packet with SLIP encoding. Packet transmission is confirmed when
00094  *        the HCI_SLIP_TX_DONE event is received by the function caller.
00095  *
00096  * @param[in] p_buffer              Pointer to the packet to transmit.
00097  * @param[in] length                Packet length, in bytes.
00098  *
00099  * @retval NRF_SUCCESS              Operation success. Packet was encoded and added to the 
00100  *                                  transmission queue and an event will be sent upon transmission 
00101  *                                  completion.
00102  * @retval NRF_ERROR_NO_MEM         Operation failure. Transmission queue is full and packet was not
00103  *                                  added to the transmission queue. Application shall wait for
00104  *                                  the \ref HCI_SLIP_TX_DONE event. After HCI_SLIP_TX_DONE this
00105  *                                  function can be executed for transmission of next packet.
00106  * @retval NRF_ERROR_INVALID_ADDR   If a NULL pointer is provided.
00107  * @retval NRF_ERROR_INVALID_STATE  Operation failure. Module is not open.
00108  */
00109 uint32_t hci_slip_write(const uint8_t * p_buffer, uint32_t length);
00110 
00111 /**@brief Function for registering a receive buffer. The receive buffer will be used for storage of
00112  *        received and SLIP decoded data.
00113  *        No data can be received by the SLIP layer until a receive buffer has been registered.
00114  *
00115  * @note  The lifetime of the buffer must be valid during complete reception of data. A static
00116  *        buffer is recommended.
00117  *
00118  * @warning Multiple registration requests will overwrite any existing registration.
00119  *
00120  * @param[in]  p_buffer             Pointer to receive buffer. The received and SLIP decoded packet
00121  *                                  will be placed in this buffer.
00122  * @param[in]  length               Buffer length, in bytes.
00123  *
00124  * @retval NRF_SUCCESS              Operation success. 
00125  */
00126 uint32_t hci_slip_rx_buffer_register(uint8_t * p_buffer, uint32_t length);
00127  
00128 #endif // HCI_SLIP_H__
00129  
00130 /** @} */