SG RFID nRF51822 fork

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hci_transport.h Source File

hci_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 /**@brief Generic event callback function events. */
00082 typedef enum
00083 {
00084     HCI_TRANSPORT_RX_RDY,               /**< An event indicating that RX packet is ready for read. */
00085     HCI_TRANSPORT_EVT_TYPE_MAX          /**< Enumeration upper bound. */  
00086 } hci_transport_evt_type_t;
00087 
00088 /**@brief Struct containing events from the Transport layer.
00089  */
00090 typedef struct
00091 {
00092     hci_transport_evt_type_t evt_type;  /**< Type of event. */
00093 } hci_transport_evt_t;
00094 
00095 /**@brief Transport layer generic event callback function type.
00096  *
00097  * @param[in] event                Transport layer event.  
00098  */
00099 typedef void (*hci_transport_event_handler_t)(hci_transport_evt_t event);
00100 
00101 /**@brief TX done event callback function result codes. */
00102 typedef enum
00103 {
00104     HCI_TRANSPORT_TX_DONE_SUCCESS,      /**< Transmission success, peer transport entity has acknowledged the transmission. */
00105     HCI_TRANSPORT_TX_DONE_FAILURE       /**< Transmission failure. */    
00106 } hci_transport_tx_done_result_t;
00107 
00108 /**@brief Transport layer TX done event callback function type.
00109  *
00110  * @param[in] result                TX done event result code. 
00111  */
00112 typedef void (*hci_transport_tx_done_handler_t)(hci_transport_tx_done_result_t result);
00113 
00114 /**@brief Function for registering a generic event handler.
00115  *
00116  * @note Multiple registration requests will overwrite any possible existing registration. 
00117  *
00118  * @param[in] event_handler         The function to be called by the transport layer upon an event.
00119  *
00120  * @retval NRF_SUCCESS              Operation success.
00121  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.    
00122  */
00123 uint32_t hci_transport_evt_handler_reg(hci_transport_event_handler_t event_handler);
00124 
00125 /**@brief Function for registering a handler for TX done event.
00126  *
00127  * @note Multiple registration requests will overwrite any possible existing registration. 
00128  *
00129  * @param[in] event_handler         The function to be called by the transport layer upon TX done
00130  *                                  event.
00131  *
00132  * @retval NRF_SUCCESS              Operation success.
00133  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.    
00134  */
00135 uint32_t hci_transport_tx_done_register(hci_transport_tx_done_handler_t event_handler);
00136                                         
00137 /**@brief Function for opening the transport channel and initializing the transport layer.
00138  *
00139  * @warning Must not be called for a channel which has been allready opened. 
00140  * 
00141  * @retval NRF_SUCCESS              Operation success.
00142  * @retval NRF_ERROR_INTERNAL       Operation failure. Internal error ocurred. 
00143  */
00144 uint32_t hci_transport_open(void);
00145 
00146 /**@brief Function for closing the transport channel.
00147  *
00148  * @note Can be called multiple times and also for not opened channel.
00149  * 
00150  * @retval NRF_SUCCESS              Operation success.  
00151  */
00152 uint32_t hci_transport_close(void);
00153 
00154 /**@brief Function for allocating tx packet memory.
00155  * 
00156  * @param[out] pp_memory            Pointer to the packet data.
00157  * 
00158  * @retval NRF_SUCCESS              Operation success. Memory was allocated.
00159  * @retval NRF_ERROR_NO_MEM         Operation failure. No memory available.
00160  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.   
00161  */
00162 uint32_t hci_transport_tx_alloc(uint8_t ** pp_memory);
00163 
00164 /**@brief Function for freeing tx packet memory.
00165  *
00166  * @note Memory management works in FIFO principle meaning that free order must match the alloc 
00167  *       order.
00168  * 
00169  * @retval NRF_SUCCESS              Operation success. Memory was freed.   
00170  */
00171 uint32_t hci_transport_tx_free(void);
00172 
00173 /**@brief Function for writing a packet.
00174  *
00175  * @note Completion of this method does not guarantee that actual peripheral transmission would 
00176  *       have completed.
00177  *
00178  * @note In case of 0 byte packet length write request, message will consist of only transport 
00179  *       module specific headers.  
00180  *
00181  * @retval NRF_SUCCESS              Operation success. Packet was added to the transmission queue 
00182  *                                  and an event will be send upon transmission completion. 
00183  * @retval NRF_ERROR_NO_MEM         Operation failure. Transmission queue is full and packet was not
00184  *                                  added to the transmission queue. User should wait for 
00185  *                                  a appropriate event prior issuing this operation again.
00186  * @retval NRF_ERROR_DATA_SIZE      Operation failure. Packet size exceeds limit.   
00187  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.  
00188  * @retval NRF_ERROR_INVALID_STATE  Operation failure. Channel is not open.
00189  */
00190 uint32_t hci_transport_pkt_write(const uint8_t * p_buffer, uint32_t length);
00191 
00192 /**@brief Function for extracting received packet.
00193  *
00194  * @note Extracted memory can't be reused by the underlying transport layer untill freed by call to 
00195  *       hci_transport_rx_pkt_consume().
00196  *
00197  * @param[out] pp_buffer            Pointer to the packet data.
00198  * @param[out] p_length             Length of packet data in bytes.  
00199  *
00200  * @retval NRF_SUCCESS              Operation success. Packet was extracted. 
00201  * @retval NRF_ERROR_NO_MEM         Operation failure. No packet available to extract.
00202  * @retval NRF_ERROR_NULL           Operation failure. NULL pointer supplied.   
00203  */
00204 uint32_t hci_transport_rx_pkt_extract(uint8_t ** pp_buffer, uint32_t * p_length);
00205 
00206 /**@brief Function for consuming extracted packet described by p_buffer.
00207  *
00208  * RX memory pointed to by p_buffer is freed and can be reused by the underlying transport layer.
00209  *
00210  * @param[in] p_buffer              Pointer to the buffer that has been consumed.
00211  *
00212  * @retval NRF_SUCCESS              Operation success. 
00213  * @retval NRF_ERROR_NO_MEM         Operation failure. No packet available to consume. 
00214  * @retval NRF_ERROR_INVALID_ADDR   Operation failure. Not a valid pointer. 
00215  */
00216 uint32_t hci_transport_rx_pkt_consume(uint8_t * p_buffer);
00217 
00218 #endif // HCI_TRANSPORT_H__
00219 
00220 /** @} */