mbed library

Dependents:   Printf

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