SG RFID nRF51822 fork

Fork of nRF51822 by Nordic Semiconductor

Committer:
bogdanm
Date:
Wed Mar 26 14:38:17 2014 +0000
Revision:
0:eff01767de02
Child:
37:c29c330d942c
Initial import of the nRF51822 code

Who changed what in which revision?

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