Copy of nRF51822 library

Fork of nRF51822 by Nordic Semiconductor

Committer:
wd5gnr
Date:
Sun Sep 21 19:21:08 2014 +0000
Revision:
61:6fb5c2c43d35
Parent:
37:c29c330d942c
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rohit Grover 37:c29c330d942c 1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
Rohit Grover 37:c29c330d942c 2 *
Rohit Grover 37:c29c330d942c 3 * The information contained herein is property of Nordic Semiconductor ASA.
Rohit Grover 37:c29c330d942c 4 * Terms and conditions of usage are described in detail in NORDIC
Rohit Grover 37:c29c330d942c 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
Rohit Grover 37:c29c330d942c 6 *
Rohit Grover 37:c29c330d942c 7 * Licensees are granted free, non-transferable use of the information. NO
Rohit Grover 37:c29c330d942c 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
Rohit Grover 37:c29c330d942c 9 * the file.
Rohit Grover 37:c29c330d942c 10 *
Rohit Grover 37:c29c330d942c 11 */
Rohit Grover 37:c29c330d942c 12
Rohit Grover 37:c29c330d942c 13 /**@file
Rohit Grover 37:c29c330d942c 14 *
Rohit Grover 37:c29c330d942c 15 * @defgroup hci_transport HCI Transport
Rohit Grover 37:c29c330d942c 16 * @{
Rohit Grover 37:c29c330d942c 17 * @ingroup app_common
Rohit Grover 37:c29c330d942c 18 *
Rohit Grover 37:c29c330d942c 19 * @brief HCI transport module implementation.
Rohit Grover 37:c29c330d942c 20 *
Rohit Grover 37:c29c330d942c 21 * This module implements certain specific features from the three-wire UART transport layer,
Rohit Grover 37:c29c330d942c 22 * defined by the Bluetooth specification version 4.0 [Vol 4] part D.
Rohit Grover 37:c29c330d942c 23 *
Rohit Grover 37:c29c330d942c 24 * \par Features supported
Rohit Grover 37:c29c330d942c 25 * - Transmission and reception of Vendor Specific HCI packet type application packets.
Rohit Grover 37:c29c330d942c 26 * - Transmission and reception of reliable packets: defined by chapter 6 of the specification.
Rohit Grover 37:c29c330d942c 27 *
Rohit Grover 37:c29c330d942c 28 * \par Features not supported
Rohit Grover 37:c29c330d942c 29 * - Link establishment procedure: defined by chapter 8 of the specification.
Rohit Grover 37:c29c330d942c 30 * - Low power: defined by chapter 9 of the specification.
Rohit Grover 37:c29c330d942c 31 *
Rohit Grover 37:c29c330d942c 32 * \par Implementation specific behaviour
Rohit Grover 37:c29c330d942c 33 * - As Link establishment procedure is not supported following static link configuration parameters
Rohit Grover 37:c29c330d942c 34 * are used:
Rohit Grover 37:c29c330d942c 35 * + TX window size is 1.
Rohit Grover 37:c29c330d942c 36 * + 16 bit CCITT-CRC must be used.
Rohit Grover 37:c29c330d942c 37 * + Out of frame software flow control not supported.
Rohit Grover 37:c29c330d942c 38 * + Parameters specific for resending reliable packets are compile time configurable (clarifed
Rohit Grover 37:c29c330d942c 39 * later in this document).
Rohit Grover 37:c29c330d942c 40 * + Acknowledgement packet transmissions are not timeout driven , meaning they are delivered for
Rohit Grover 37:c29c330d942c 41 * transmission within same context which the corresponding application packet was received.
Rohit Grover 37:c29c330d942c 42 *
Rohit Grover 37:c29c330d942c 43 * \par Implementation specific limitations
Rohit Grover 37:c29c330d942c 44 * Current implementation has the following limitations which will have impact to system wide
Rohit Grover 37:c29c330d942c 45 * behaviour:
Rohit Grover 37:c29c330d942c 46 * - Delayed acknowledgement scheduling not implemented:
Rohit Grover 37:c29c330d942c 47 * There exists a possibility that acknowledgement TX packet and application TX packet will collide
Rohit Grover 37:c29c330d942c 48 * in the TX pipeline having the end result that acknowledgement packet will be excluded from the TX
Rohit Grover 37:c29c330d942c 49 * pipeline which will trigger the retransmission algorithm within the peer protocol entity.
Rohit Grover 37:c29c330d942c 50 * - Delayed retransmission scheduling not implemented:
Rohit Grover 37:c29c330d942c 51 * There exists a possibility that retransmitted application TX packet and acknowledgement TX packet
Rohit Grover 37:c29c330d942c 52 * will collide in the TX pipeline having the end result that retransmitted application TX packet
Rohit Grover 37:c29c330d942c 53 * will be excluded from the TX pipeline.
Rohit Grover 37:c29c330d942c 54 * - Processing of the acknowledgement number from RX application packets:
Rohit Grover 37:c29c330d942c 55 * Acknowledgement number is not processed from the RX application packets having the end result
Rohit Grover 37:c29c330d942c 56 * that unnecessary application packet retransmissions can occur.
Rohit Grover 37:c29c330d942c 57 *
Rohit Grover 37:c29c330d942c 58 * The application TX packet processing flow is illustrated by the statemachine below.
Rohit Grover 37:c29c330d942c 59 *
Rohit Grover 37:c29c330d942c 60 * @image html hci_transport_tx_sm.png "TX - application packet statemachine"
Rohit Grover 37:c29c330d942c 61 *
Rohit Grover 37:c29c330d942c 62 * \par Component specific configuration options
Rohit Grover 37:c29c330d942c 63 *
Rohit Grover 37:c29c330d942c 64 * The following compile time configuration options are available, and used to configure the
Rohit Grover 37:c29c330d942c 65 * application TX packet retransmission interval, in order to suite various application specific
Rohit Grover 37:c29c330d942c 66 * implementations:
Rohit Grover 37:c29c330d942c 67 * - MAC_PACKET_SIZE_IN_BITS Maximum size of a single application packet in bits.
Rohit Grover 37:c29c330d942c 68 * - USED_BAUD_RATE Used uart baudrate.
Rohit Grover 37:c29c330d942c 69 *
Rohit Grover 37:c29c330d942c 70 * The following compile time configuration option is available to configure module specific
Rohit Grover 37:c29c330d942c 71 * behaviour:
Rohit Grover 37:c29c330d942c 72 * - MAX_RETRY_COUNT Max retransmission retry count for applicaton packets.
Rohit Grover 37:c29c330d942c 73 */
Rohit Grover 37:c29c330d942c 74
Rohit Grover 37:c29c330d942c 75 #ifndef HCI_TRANSPORT_H__
Rohit Grover 37:c29c330d942c 76 #define HCI_TRANSPORT_H__
Rohit Grover 37:c29c330d942c 77
Rohit Grover 37:c29c330d942c 78 #include <stdint.h>
Rohit Grover 37:c29c330d942c 79 #include "nrf_error.h"
Rohit Grover 37:c29c330d942c 80
Rohit Grover 37:c29c330d942c 81 #define HCI_TRANSPORT_PKT_HEADER_SIZE (2) /**< Size of transport packet header */
Rohit Grover 37:c29c330d942c 82
Rohit Grover 37:c29c330d942c 83 /**@brief Generic event callback function events. */
Rohit Grover 37:c29c330d942c 84 typedef enum
Rohit Grover 37:c29c330d942c 85 {
Rohit Grover 37:c29c330d942c 86 HCI_TRANSPORT_RX_RDY, /**< An event indicating that RX packet is ready for read. */
Rohit Grover 37:c29c330d942c 87 HCI_TRANSPORT_EVT_TYPE_MAX /**< Enumeration upper bound. */
Rohit Grover 37:c29c330d942c 88 } hci_transport_evt_type_t;
Rohit Grover 37:c29c330d942c 89
Rohit Grover 37:c29c330d942c 90 /**@brief Struct containing events from the Transport layer.
Rohit Grover 37:c29c330d942c 91 */
Rohit Grover 37:c29c330d942c 92 typedef struct
Rohit Grover 37:c29c330d942c 93 {
Rohit Grover 37:c29c330d942c 94 hci_transport_evt_type_t evt_type; /**< Type of event. */
Rohit Grover 37:c29c330d942c 95 } hci_transport_evt_t;
Rohit Grover 37:c29c330d942c 96
Rohit Grover 37:c29c330d942c 97 /**@brief Transport layer generic event callback function type.
Rohit Grover 37:c29c330d942c 98 *
Rohit Grover 37:c29c330d942c 99 * @param[in] event Transport layer event.
Rohit Grover 37:c29c330d942c 100 */
Rohit Grover 37:c29c330d942c 101 typedef void (*hci_transport_event_handler_t)(hci_transport_evt_t event);
Rohit Grover 37:c29c330d942c 102
Rohit Grover 37:c29c330d942c 103 /**@brief TX done event callback function result codes. */
Rohit Grover 37:c29c330d942c 104 typedef enum
Rohit Grover 37:c29c330d942c 105 {
Rohit Grover 37:c29c330d942c 106 HCI_TRANSPORT_TX_DONE_SUCCESS, /**< Transmission success, peer transport entity has acknowledged the transmission. */
Rohit Grover 37:c29c330d942c 107 HCI_TRANSPORT_TX_DONE_FAILURE /**< Transmission failure. */
Rohit Grover 37:c29c330d942c 108 } hci_transport_tx_done_result_t;
Rohit Grover 37:c29c330d942c 109
Rohit Grover 37:c29c330d942c 110 /**@brief Transport layer TX done event callback function type.
Rohit Grover 37:c29c330d942c 111 *
Rohit Grover 37:c29c330d942c 112 * @param[in] result TX done event result code.
Rohit Grover 37:c29c330d942c 113 */
Rohit Grover 37:c29c330d942c 114 typedef void (*hci_transport_tx_done_handler_t)(hci_transport_tx_done_result_t result);
Rohit Grover 37:c29c330d942c 115
Rohit Grover 37:c29c330d942c 116 /**@brief Function for registering a generic event handler.
Rohit Grover 37:c29c330d942c 117 *
Rohit Grover 37:c29c330d942c 118 * @note Multiple registration requests will overwrite any possible existing registration.
Rohit Grover 37:c29c330d942c 119 *
Rohit Grover 37:c29c330d942c 120 * @param[in] event_handler The function to be called by the transport layer upon an event.
Rohit Grover 37:c29c330d942c 121 *
Rohit Grover 37:c29c330d942c 122 * @retval NRF_SUCCESS Operation success.
Rohit Grover 37:c29c330d942c 123 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
Rohit Grover 37:c29c330d942c 124 */
Rohit Grover 37:c29c330d942c 125 uint32_t hci_transport_evt_handler_reg(hci_transport_event_handler_t event_handler);
Rohit Grover 37:c29c330d942c 126
Rohit Grover 37:c29c330d942c 127 /**@brief Function for registering a handler for TX done event.
Rohit Grover 37:c29c330d942c 128 *
Rohit Grover 37:c29c330d942c 129 * @note Multiple registration requests will overwrite any possible existing registration.
Rohit Grover 37:c29c330d942c 130 *
Rohit Grover 37:c29c330d942c 131 * @param[in] event_handler The function to be called by the transport layer upon TX done
Rohit Grover 37:c29c330d942c 132 * event.
Rohit Grover 37:c29c330d942c 133 *
Rohit Grover 37:c29c330d942c 134 * @retval NRF_SUCCESS Operation success.
Rohit Grover 37:c29c330d942c 135 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
Rohit Grover 37:c29c330d942c 136 */
Rohit Grover 37:c29c330d942c 137 uint32_t hci_transport_tx_done_register(hci_transport_tx_done_handler_t event_handler);
Rohit Grover 37:c29c330d942c 138
Rohit Grover 37:c29c330d942c 139 /**@brief Function for opening the transport channel and initializing the transport layer.
Rohit Grover 37:c29c330d942c 140 *
Rohit Grover 37:c29c330d942c 141 * @warning Must not be called for a channel which has been allready opened.
Rohit Grover 37:c29c330d942c 142 *
Rohit Grover 37:c29c330d942c 143 * @retval NRF_SUCCESS Operation success.
Rohit Grover 37:c29c330d942c 144 * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred.
Rohit Grover 37:c29c330d942c 145 */
Rohit Grover 37:c29c330d942c 146 uint32_t hci_transport_open(void);
Rohit Grover 37:c29c330d942c 147
Rohit Grover 37:c29c330d942c 148 /**@brief Function for closing the transport channel.
Rohit Grover 37:c29c330d942c 149 *
Rohit Grover 37:c29c330d942c 150 * @note Can be called multiple times and also for not opened channel.
Rohit Grover 37:c29c330d942c 151 *
Rohit Grover 37:c29c330d942c 152 * @retval NRF_SUCCESS Operation success.
Rohit Grover 37:c29c330d942c 153 */
Rohit Grover 37:c29c330d942c 154 uint32_t hci_transport_close(void);
Rohit Grover 37:c29c330d942c 155
Rohit Grover 37:c29c330d942c 156 /**@brief Function for allocating tx packet memory.
Rohit Grover 37:c29c330d942c 157 *
Rohit Grover 37:c29c330d942c 158 * @param[out] pp_memory Pointer to the packet data.
Rohit Grover 37:c29c330d942c 159 *
Rohit Grover 37:c29c330d942c 160 * @retval NRF_SUCCESS Operation success. Memory was allocated.
Rohit Grover 37:c29c330d942c 161 * @retval NRF_ERROR_NO_MEM Operation failure. No memory available.
Rohit Grover 37:c29c330d942c 162 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
Rohit Grover 37:c29c330d942c 163 */
Rohit Grover 37:c29c330d942c 164 uint32_t hci_transport_tx_alloc(uint8_t ** pp_memory);
Rohit Grover 37:c29c330d942c 165
Rohit Grover 37:c29c330d942c 166 /**@brief Function for freeing tx packet memory.
Rohit Grover 37:c29c330d942c 167 *
Rohit Grover 37:c29c330d942c 168 * @note Memory management works in FIFO principle meaning that free order must match the alloc
Rohit Grover 37:c29c330d942c 169 * order.
Rohit Grover 37:c29c330d942c 170 *
Rohit Grover 37:c29c330d942c 171 * @retval NRF_SUCCESS Operation success. Memory was freed.
Rohit Grover 37:c29c330d942c 172 */
Rohit Grover 37:c29c330d942c 173 uint32_t hci_transport_tx_free(void);
Rohit Grover 37:c29c330d942c 174
Rohit Grover 37:c29c330d942c 175 /**@brief Function for writing a packet.
Rohit Grover 37:c29c330d942c 176 *
Rohit Grover 37:c29c330d942c 177 * @note Completion of this method does not guarantee that actual peripheral transmission would
Rohit Grover 37:c29c330d942c 178 * have completed.
Rohit Grover 37:c29c330d942c 179 *
Rohit Grover 37:c29c330d942c 180 * @note In case of 0 byte packet length write request, message will consist of only transport
Rohit Grover 37:c29c330d942c 181 * module specific headers.
Rohit Grover 37:c29c330d942c 182 *
Rohit Grover 37:c29c330d942c 183 * @note The buffer provided to this function must be allocated through @ref hci_transport_tx_alloc
Rohit Grover 37:c29c330d942c 184 * function.
Rohit Grover 37:c29c330d942c 185 *
Rohit Grover 37:c29c330d942c 186 * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue
Rohit Grover 37:c29c330d942c 187 * and an event will be send upon transmission completion.
Rohit Grover 37:c29c330d942c 188 * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
Rohit Grover 37:c29c330d942c 189 * added to the transmission queue. User should wait for
Rohit Grover 37:c29c330d942c 190 * a appropriate event prior issuing this operation again.
Rohit Grover 37:c29c330d942c 191 * @retval NRF_ERROR_DATA_SIZE Operation failure. Packet size exceeds limit.
Rohit Grover 37:c29c330d942c 192 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
Rohit Grover 37:c29c330d942c 193 * @retval NRF_ERROR_INVALID_STATE Operation failure. Channel is not open.
Rohit Grover 37:c29c330d942c 194 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Buffer provided is not allocated through
Rohit Grover 37:c29c330d942c 195 * hci_transport_tx_alloc function.
Rohit Grover 37:c29c330d942c 196 */
Rohit Grover 37:c29c330d942c 197 uint32_t hci_transport_pkt_write(const uint8_t * p_buffer, uint16_t length);
Rohit Grover 37:c29c330d942c 198
Rohit Grover 37:c29c330d942c 199 /**@brief Function for extracting received packet.
Rohit Grover 37:c29c330d942c 200 *
Rohit Grover 37:c29c330d942c 201 * @note Extracted memory can't be reused by the underlying transport layer untill freed by call to
Rohit Grover 37:c29c330d942c 202 * hci_transport_rx_pkt_consume().
Rohit Grover 37:c29c330d942c 203 *
Rohit Grover 37:c29c330d942c 204 * @param[out] pp_buffer Pointer to the packet data.
Rohit Grover 37:c29c330d942c 205 * @param[out] p_length Length of packet data in bytes.
Rohit Grover 37:c29c330d942c 206 *
Rohit Grover 37:c29c330d942c 207 * @retval NRF_SUCCESS Operation success. Packet was extracted.
Rohit Grover 37:c29c330d942c 208 * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to extract.
Rohit Grover 37:c29c330d942c 209 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
Rohit Grover 37:c29c330d942c 210 */
Rohit Grover 37:c29c330d942c 211 uint32_t hci_transport_rx_pkt_extract(uint8_t ** pp_buffer, uint16_t * p_length);
Rohit Grover 37:c29c330d942c 212
Rohit Grover 37:c29c330d942c 213 /**@brief Function for consuming extracted packet described by p_buffer.
Rohit Grover 37:c29c330d942c 214 *
Rohit Grover 37:c29c330d942c 215 * RX memory pointed to by p_buffer is freed and can be reused by the underlying transport layer.
Rohit Grover 37:c29c330d942c 216 *
Rohit Grover 37:c29c330d942c 217 * @param[in] p_buffer Pointer to the buffer that has been consumed.
Rohit Grover 37:c29c330d942c 218 *
Rohit Grover 37:c29c330d942c 219 * @retval NRF_SUCCESS Operation success.
Rohit Grover 37:c29c330d942c 220 * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to consume.
Rohit Grover 37:c29c330d942c 221 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer.
Rohit Grover 37:c29c330d942c 222 */
Rohit Grover 37:c29c330d942c 223 uint32_t hci_transport_rx_pkt_consume(uint8_t * p_buffer);
Rohit Grover 37:c29c330d942c 224
Rohit Grover 37:c29c330d942c 225 #endif // HCI_TRANSPORT_H__
Rohit Grover 37:c29c330d942c 226
Rohit Grover 37:c29c330d942c 227 /** @} */