iOSのBLEコントローラアプリ「RCBController」と接続し、コントローラの操作を取得するサンプルプログラムです。 mbed HRM1017で動作を確認しています。 2014.08.20時点でのBLEライブラリに対応しました。

Dependencies:   BLE_API mbed

Fork of BLE_RCBController by Junichi Katsu

Committer:
jksoft
Date:
Wed Aug 20 13:41:01 2014 +0000
Revision:
4:ebda47d22091
Parent:
nRF51822/nordic/nrf-sdk/app_common/hal_transport.h@1:48f6e08a3ac2
?????????

Who changed what in which revision?

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