iOSのBLEコントローラアプリ「RCBController」とmbed HRM1017を接続し、RCサーボモータを操作するテストプログラムです。

Dependencies:   BLE_API_Native_IRC Servo mbed

Fork of BLE_RCBController by Junichi Katsu

  • 古いBLEライブラリを使っているのでプラットフォームは”Nordic nRF51822”を選択してください。
  • ライブラリ類はUpdateしないでください。コンパイルエラーになります。

うまく接続できない時は、iPhone/iPadのBluetoothをOFF->ONしてキャッシュをクリアしてみてください。

/media/uploads/robo8080/img_1560.jpg

Committer:
jksoft
Date:
Thu Jul 10 14:21:52 2014 +0000
Revision:
0:8c643bfe55b7
??

Who changed what in which revision?

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