Nordic stack and drivers for the mbed BLE API

Dependents:   idd_hw5_bleFanProto

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hal_transport.h Source File

hal_transport.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_transport HCI Transport
00016  * @{
00017  * @ingroup  app_common
00018  *
00019  * @brief    HCI transport module implementation.
00020  *
00021  * This module implements certain specific features from the three-wire UART transport layer, 
00022  * defined by the Bluetooth specification version 4.0 [Vol 4] part D.
00023  *
00024  * \par Features supported
00025  * - Transmission and reception of Vendor Specific HCI packet type application packets.
00026  * - Transmission and reception of reliable packets: defined by chapter 6 of the specification.
00027  *
00028  * \par Features not supported
00029  * - Link establishment procedure: defined by chapter 8 of the specification.
00030  * - Low power: defined by chapter 9 of the specification. 
00031  *
00032  * \par Implementation specific behaviour
00033  * - As Link establishment procedure is not supported following static link configuration parameters
00034  * are used:
00035  * + TX window size is 1.
00036  * + 16 bit CCITT-CRC must be used.
00037  * + Out of frame software flow control not supported.
00038  * + Parameters specific for resending reliable packets are compile time configurable (clarifed 
00039  * later in this document).
00040  * + Acknowledgement packet transmissions are not timeout driven , meaning they are delivered for 
00041  * transmission within same context which the corresponding application packet was received. 
00042  *
00043  * \par Implementation specific limitations
00044  * Current implementation has the following limitations which will have impact to system wide 
00045  * behaviour:
00046  * - Delayed acknowledgement scheduling not implemented: 
00047  * There exists a possibility that acknowledgement TX packet and application TX packet will collide 
00048  * in the TX pipeline having the end result that acknowledgement packet will be excluded from the TX 
00049  * pipeline which will trigger the retransmission algorithm within the peer protocol entity.
00050  * - Delayed retransmission scheduling not implemented:  
00051  * There exists a possibility that retransmitted application TX packet and acknowledgement TX packet
00052  * will collide in the TX pipeline having the end result that retransmitted application TX packet 
00053  * will be excluded from the TX pipeline.
00054  * - Processing of the acknowledgement number from RX application packets:
00055  * Acknowledgement number is not processed from the RX application packets having the end result 
00056  * that unnecessary application packet retransmissions can occur.
00057  *
00058  * The application TX packet processing flow is illustrated by the statemachine below. 
00059  *
00060  * @image html hci_transport_tx_sm.png "TX - application packet statemachine"
00061  *
00062  * \par Component specific configuration options
00063  *
00064  * The following compile time configuration options are available, and used to configure the 
00065  * application TX packet retransmission interval, in order to suite various application specific 
00066  * implementations:
00067  * - MAC_PACKET_SIZE_IN_BITS Maximum size of a single application packet in bits. 
00068  * - USED_BAUD_RATE Used uart baudrate. 
00069  *
00070  * The following compile time configuration option is available to configure module specific 
00071  * behaviour:
00072  * - MAX_RETRY_COUNT Max retransmission retry count for applicaton packets.
00073  */
00074  
00075 #ifndef HCI_TRANSPORT_H__
00076 #define HCI_TRANSPORT_H__
00077 
00078 #include <stdint.h>
00079 #include "nrf_error.h"
00080 
00081 #define HCI_TRANSPORT_PKT_HEADER_SIZE  (2)   /**< Size of transport packet header */
00082 
00083 /**@brief Generic event callback function events. */
00084 typedef enum
00085 {
00086     HCI_TRANSPORT_RX_RDY,               /**< An event indicating that RX packet is ready for read. */
00087     HCI_TRANSPORT_EVT_TYPE_MAX          /**< Enumeration upper bound. */  
00088 } hci_transport_evt_type_t;
00089 
00090 /**@brief Struct containing events from the Transport layer.
00091  */
00092 typedef struct
00093 {
00094     hci_transport_evt_type_t evt_type;  /**< Type of event. */
00095 } hci_transport_evt_t;
00096 
00097 /**@brief Transport layer generic event callback function type.
00098  *
00099  * @param[in] event                Transport layer event.  
00100  */
00101 typedef void (*hci_transport_event_handler_t)(hci_transport_evt_t event);
00102 
00103 /**@brief TX done event callback function result codes. */
00104 typedef enum
00105 {
00106     HCI_TRANSPORT_TX_DONE_SUCCESS,      /**< Transmission success, peer transport entity has acknowledged the transmission. */
00107     HCI_TRANSPORT_TX_DONE_FAILURE       /**< Transmission failure. */    
00108 } hci_transport_tx_done_result_t;
00109 
00110 /**@brief Transport layer TX done event callback function type.
00111  *
00112  * @param[in] result                TX done event result code. 
00113  */
00114 typedef void (*hci_transport_tx_done_handler_t)(hci_transport_tx_done_result_t result);
00115 
00116 /**@brief Function for registering a generic event handler.
00117  *
00118  * @note Multiple registration requests will overwrite any possible existing registration. 
00119  *
00120  * @param[in] event_handler         The function to be called by the transport layer upon an event.
00121  *
00122  * @retval NRF_SUCCESS              Operation success.
00123  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.    
00124  */
00125 uint32_t hci_transport_evt_handler_reg(hci_transport_event_handler_t event_handler);
00126 
00127 /**@brief Function for registering a handler for TX done event.
00128  *
00129  * @note Multiple registration requests will overwrite any possible existing registration. 
00130  *
00131  * @param[in] event_handler         The function to be called by the transport layer upon TX done
00132  *                                  event.
00133  *
00134  * @retval NRF_SUCCESS              Operation success.
00135  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.    
00136  */
00137 uint32_t hci_transport_tx_done_register(hci_transport_tx_done_handler_t event_handler);
00138                                         
00139 /**@brief Function for opening the transport channel and initializing the transport layer.
00140  *
00141  * @warning Must not be called for a channel which has been allready opened. 
00142  * 
00143  * @retval NRF_SUCCESS              Operation success.
00144  * @retval NRF_ERROR_INTERNAL       Operation failure. Internal error ocurred. 
00145  */
00146 uint32_t hci_transport_open(void);
00147 
00148 /**@brief Function for closing the transport channel.
00149  *
00150  * @note Can be called multiple times and also for not opened channel.
00151  * 
00152  * @retval NRF_SUCCESS              Operation success.  
00153  */
00154 uint32_t hci_transport_close(void);
00155 
00156 /**@brief Function for allocating tx packet memory.
00157  * 
00158  * @param[out] pp_memory            Pointer to the packet data.
00159  * 
00160  * @retval NRF_SUCCESS              Operation success. Memory was allocated.
00161  * @retval NRF_ERROR_NO_MEM         Operation failure. No memory available.
00162  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.   
00163  */
00164 uint32_t hci_transport_tx_alloc(uint8_t ** pp_memory);
00165 
00166 /**@brief Function for freeing tx packet memory.
00167  *
00168  * @note Memory management works in FIFO principle meaning that free order must match the alloc 
00169  *       order.
00170  * 
00171  * @retval NRF_SUCCESS              Operation success. Memory was freed.   
00172  */
00173 uint32_t hci_transport_tx_free(void);
00174 
00175 /**@brief Function for writing a packet.
00176  *
00177  * @note Completion of this method does not guarantee that actual peripheral transmission would 
00178  *       have completed. 
00179  *
00180  * @note In case of 0 byte packet length write request, message will consist of only transport 
00181  *       module specific headers.  
00182  *
00183  * @note The buffer provided to this function must be allocated through @ref hci_transport_tx_alloc
00184  *       function.
00185  *
00186  * @retval NRF_SUCCESS              Operation success. Packet was added to the transmission queue 
00187  *                                  and an event will be send upon transmission completion. 
00188  * @retval NRF_ERROR_NO_MEM         Operation failure. Transmission queue is full and packet was not
00189  *                                  added to the transmission queue. User should wait for 
00190  *                                  a appropriate event prior issuing this operation again.
00191  * @retval NRF_ERROR_DATA_SIZE      Operation failure. Packet size exceeds limit.
00192  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.  
00193  * @retval NRF_ERROR_INVALID_STATE  Operation failure. Channel is not open.
00194  * @retval NRF_ERROR_INVALID_ADDR   Operation failure. Buffer provided is not allocated through
00195  *                                  hci_transport_tx_alloc function.
00196  */
00197 uint32_t hci_transport_pkt_write(const uint8_t * p_buffer, uint16_t length);
00198 
00199 /**@brief Function for extracting received packet.
00200  *
00201  * @note Extracted memory can't be reused by the underlying transport layer untill freed by call to 
00202  *       hci_transport_rx_pkt_consume().
00203  *
00204  * @param[out] pp_buffer            Pointer to the packet data.
00205  * @param[out] p_length             Length of packet data in bytes.  
00206  *
00207  * @retval NRF_SUCCESS              Operation success. Packet was extracted. 
00208  * @retval NRF_ERROR_NO_MEM         Operation failure. No packet available to extract.
00209  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.   
00210  */
00211 uint32_t hci_transport_rx_pkt_extract(uint8_t ** pp_buffer, uint16_t * p_length);
00212 
00213 /**@brief Function for consuming extracted packet described by p_buffer.
00214  *
00215  * RX memory pointed to by p_buffer is freed and can be reused by the underlying transport layer.
00216  *
00217  * @param[in] p_buffer              Pointer to the buffer that has been consumed.
00218  *
00219  * @retval NRF_SUCCESS              Operation success. 
00220  * @retval NRF_ERROR_NO_MEM         Operation failure. No packet available to consume. 
00221  * @retval NRF_ERROR_INVALID_ADDR   Operation failure. Not a valid pointer. 
00222  */
00223 uint32_t hci_transport_rx_pkt_consume(uint8_t * p_buffer);
00224 
00225 #endif // HCI_TRANSPORT_H__
00226 
00227 /** @} */