The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
emilmont
Date:
Fri Feb 21 12:21:39 2014 +0000
Revision:
80:8e73be2a2ac1
First alpha release for the NRF51822 target (to be tested in the online IDE)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 80:8e73be2a2ac1 1 /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
emilmont 80:8e73be2a2ac1 2 *
emilmont 80:8e73be2a2ac1 3 * The information contained herein is confidential property of Nordic Semiconductor. The use,
emilmont 80:8e73be2a2ac1 4 * copying, transfer or disclosure of such information is prohibited except by express written
emilmont 80:8e73be2a2ac1 5 * agreement with Nordic Semiconductor.
emilmont 80:8e73be2a2ac1 6 *
emilmont 80:8e73be2a2ac1 7 */
emilmont 80:8e73be2a2ac1 8 /**
emilmont 80:8e73be2a2ac1 9 @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
emilmont 80:8e73be2a2ac1 10 @{
emilmont 80:8e73be2a2ac1 11 @brief Definitions and prototypes for the L2CAP interface.
emilmont 80:8e73be2a2ac1 12 */
emilmont 80:8e73be2a2ac1 13
emilmont 80:8e73be2a2ac1 14 #ifndef BLE_L2CAP_H__
emilmont 80:8e73be2a2ac1 15 #define BLE_L2CAP_H__
emilmont 80:8e73be2a2ac1 16
emilmont 80:8e73be2a2ac1 17 #include "ble_types.h"
emilmont 80:8e73be2a2ac1 18 #include "ble_ranges.h"
emilmont 80:8e73be2a2ac1 19 #include "ble_err.h"
emilmont 80:8e73be2a2ac1 20 #include "nrf_svc.h"
emilmont 80:8e73be2a2ac1 21
emilmont 80:8e73be2a2ac1 22 /**@brief L2CAP API SVC numbers. */
emilmont 80:8e73be2a2ac1 23 enum BLE_L2CAP_SVCS
emilmont 80:8e73be2a2ac1 24 {
emilmont 80:8e73be2a2ac1 25 SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE, /**< Register a CID. */
emilmont 80:8e73be2a2ac1 26 SD_BLE_L2CAP_CID_UNREGISTER, /**< Unregister a CID. */
emilmont 80:8e73be2a2ac1 27 SD_BLE_L2CAP_TX /**< Transmit a packet. */
emilmont 80:8e73be2a2ac1 28 };
emilmont 80:8e73be2a2ac1 29
emilmont 80:8e73be2a2ac1 30 /**@addtogroup BLE_L2CAP_DEFINES Defines
emilmont 80:8e73be2a2ac1 31 * @{ */
emilmont 80:8e73be2a2ac1 32
emilmont 80:8e73be2a2ac1 33 /**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP
emilmont 80:8e73be2a2ac1 34 * @{ */
emilmont 80:8e73be2a2ac1 35 #define BLE_ERROR_L2CAP_CID_IN_USE (NRF_L2CAP_ERR_BASE + 0x000) /**< CID already in use. */
emilmont 80:8e73be2a2ac1 36 /** @} */
emilmont 80:8e73be2a2ac1 37
emilmont 80:8e73be2a2ac1 38 /**@brief Default L2CAP MTU. */
emilmont 80:8e73be2a2ac1 39 #define BLE_L2CAP_MTU_DEF (23)
emilmont 80:8e73be2a2ac1 40
emilmont 80:8e73be2a2ac1 41 /**@brief Invalid Channel Identifier. */
emilmont 80:8e73be2a2ac1 42 #define BLE_L2CAP_CID_INVALID (0x0000)
emilmont 80:8e73be2a2ac1 43
emilmont 80:8e73be2a2ac1 44 /**@brief Dynamic Channel Identifier base. */
emilmont 80:8e73be2a2ac1 45 #define BLE_L2CAP_CID_DYN_BASE (0x0040)
emilmont 80:8e73be2a2ac1 46
emilmont 80:8e73be2a2ac1 47 /**@brief Maximum amount of dynamic CIDs. */
emilmont 80:8e73be2a2ac1 48 #define BLE_L2CAP_CID_DYN_MAX (8)
emilmont 80:8e73be2a2ac1 49
emilmont 80:8e73be2a2ac1 50 /** @} */
emilmont 80:8e73be2a2ac1 51
emilmont 80:8e73be2a2ac1 52 /**@brief Packet header format for L2CAP transmission. */
emilmont 80:8e73be2a2ac1 53 typedef struct
emilmont 80:8e73be2a2ac1 54 {
emilmont 80:8e73be2a2ac1 55 uint16_t len; /**< Length of valid info in data member. */
emilmont 80:8e73be2a2ac1 56 uint16_t cid; /**< Channel ID on which packet is transmitted. */
emilmont 80:8e73be2a2ac1 57 } ble_l2cap_header_t;
emilmont 80:8e73be2a2ac1 58
emilmont 80:8e73be2a2ac1 59 /**@brief L2CAP Event IDs. */
emilmont 80:8e73be2a2ac1 60 enum BLE_L2CAP_EVTS
emilmont 80:8e73be2a2ac1 61 {
emilmont 80:8e73be2a2ac1 62 BLE_L2CAP_EVT_RX = BLE_L2CAP_EVT_BASE /**< L2CAP packet received. */
emilmont 80:8e73be2a2ac1 63 };
emilmont 80:8e73be2a2ac1 64
emilmont 80:8e73be2a2ac1 65
emilmont 80:8e73be2a2ac1 66 /**@brief L2CAP Received packet event report. */
emilmont 80:8e73be2a2ac1 67 typedef struct
emilmont 80:8e73be2a2ac1 68 {
emilmont 80:8e73be2a2ac1 69 ble_l2cap_header_t header; /** L2CAP packet header. */
emilmont 80:8e73be2a2ac1 70 uint8_t data[1]; /**< Packet data, variable length. */
emilmont 80:8e73be2a2ac1 71 } ble_l2cap_evt_rx_t;
emilmont 80:8e73be2a2ac1 72
emilmont 80:8e73be2a2ac1 73
emilmont 80:8e73be2a2ac1 74 /**@brief L2CAP event callback event structure. */
emilmont 80:8e73be2a2ac1 75 typedef struct
emilmont 80:8e73be2a2ac1 76 {
emilmont 80:8e73be2a2ac1 77 uint16_t conn_handle; /**< Connection Handle on which event occured. */
emilmont 80:8e73be2a2ac1 78 union
emilmont 80:8e73be2a2ac1 79 {
emilmont 80:8e73be2a2ac1 80 ble_l2cap_evt_rx_t rx; /**< RX Event parameters. */
emilmont 80:8e73be2a2ac1 81 } params;
emilmont 80:8e73be2a2ac1 82 } ble_l2cap_evt_t;
emilmont 80:8e73be2a2ac1 83
emilmont 80:8e73be2a2ac1 84
emilmont 80:8e73be2a2ac1 85 /**@brief Register a CID with L2CAP.
emilmont 80:8e73be2a2ac1 86 *
emilmont 80:8e73be2a2ac1 87 * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID.
emilmont 80:8e73be2a2ac1 88 *
emilmont 80:8e73be2a2ac1 89 * @param[in] cid L2CAP CID.
emilmont 80:8e73be2a2ac1 90 *
emilmont 80:8e73be2a2ac1 91 * @return @ref NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
emilmont 80:8e73be2a2ac1 92 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
emilmont 80:8e73be2a2ac1 93 * @return @ref BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
emilmont 80:8e73be2a2ac1 94 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
emilmont 80:8e73be2a2ac1 95 */
emilmont 80:8e73be2a2ac1 96 SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid));
emilmont 80:8e73be2a2ac1 97
emilmont 80:8e73be2a2ac1 98 /**@brief Unregister a CID with L2CAP.
emilmont 80:8e73be2a2ac1 99 *
emilmont 80:8e73be2a2ac1 100 * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer.
emilmont 80:8e73be2a2ac1 101 *
emilmont 80:8e73be2a2ac1 102 * @param[in] cid L2CAP CID.
emilmont 80:8e73be2a2ac1 103 *
emilmont 80:8e73be2a2ac1 104 * @return @ref NRF_SUCCESS Successfully unregistered the CID.
emilmont 80:8e73be2a2ac1 105 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
emilmont 80:8e73be2a2ac1 106 * @return @ref NRF_ERROR_NOT_FOUND CID not previously registered.
emilmont 80:8e73be2a2ac1 107 */
emilmont 80:8e73be2a2ac1 108 SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid));
emilmont 80:8e73be2a2ac1 109
emilmont 80:8e73be2a2ac1 110 /**@brief Transmit an L2CAP packet.
emilmont 80:8e73be2a2ac1 111 *
emilmont 80:8e73be2a2ac1 112 * @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore
emilmont 80:8e73be2a2ac1 113 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
emilmont 80:8e73be2a2ac1 114 * Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
emilmont 80:8e73be2a2ac1 115 *
emilmont 80:8e73be2a2ac1 116 * @param[in] conn_handle Connection Handle.
emilmont 80:8e73be2a2ac1 117 * @param[in] p_header Pointer to a packet header containing length and CID.
emilmont 80:8e73be2a2ac1 118 * @param[in] p_data Pointer to the data to be transmitted.
emilmont 80:8e73be2a2ac1 119 *
emilmont 80:8e73be2a2ac1 120 * @return @ref NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
emilmont 80:8e73be2a2ac1 121 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
emilmont 80:8e73be2a2ac1 122 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
emilmont 80:8e73be2a2ac1 123 * @return @ref NRF_ERROR_NOT_FOUND CID not found.
emilmont 80:8e73be2a2ac1 124 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
emilmont 80:8e73be2a2ac1 125 * @return @ref BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available.
emilmont 80:8e73be2a2ac1 126 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
emilmont 80:8e73be2a2ac1 127 */
emilmont 80:8e73be2a2ac1 128 SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const * const p_header, uint8_t const * const p_data));
emilmont 80:8e73be2a2ac1 129
emilmont 80:8e73be2a2ac1 130
emilmont 80:8e73be2a2ac1 131 #endif // BLE_L2CAP_H__
emilmont 80:8e73be2a2ac1 132
emilmont 80:8e73be2a2ac1 133 /**
emilmont 80:8e73be2a2ac1 134 @}
emilmont 80:8e73be2a2ac1 135 */