テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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