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:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015 Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 3 * All rights reserved.
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 143:86740a56073b 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 143:86740a56073b 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 143:86740a56073b 15 *
AnnaBridge 143:86740a56073b 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 143:86740a56073b 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 143:86740a56073b 18 * written permission.
AnnaBridge 143:86740a56073b 19 *
AnnaBridge 143:86740a56073b 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 143:86740a56073b 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 143:86740a56073b 22 *
AnnaBridge 143:86740a56073b 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 143:86740a56073b 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 143:86740a56073b 25 *
AnnaBridge 143:86740a56073b 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 36 *
AnnaBridge 143:86740a56073b 37 */
AnnaBridge 143:86740a56073b 38
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40
AnnaBridge 143:86740a56073b 41 #ifndef PEER_MANAGER_INTERNAL_H__
AnnaBridge 143:86740a56073b 42 #define PEER_MANAGER_INTERNAL_H__
AnnaBridge 143:86740a56073b 43
AnnaBridge 143:86740a56073b 44 #include <stdint.h>
AnnaBridge 143:86740a56073b 45 #include "sdk_errors.h"
AnnaBridge 143:86740a56073b 46 #include "nrf_ble.h"
AnnaBridge 143:86740a56073b 47 #include "nrf_ble_gap.h"
AnnaBridge 143:86740a56073b 48 #include "peer_manager_types.h"
AnnaBridge 143:86740a56073b 49
AnnaBridge 143:86740a56073b 50
AnnaBridge 143:86740a56073b 51 /**
AnnaBridge 143:86740a56073b 52 * @cond NO_DOXYGEN
AnnaBridge 143:86740a56073b 53 * @file peer_manager_types.h
AnnaBridge 143:86740a56073b 54 *
AnnaBridge 143:86740a56073b 55 * @addtogroup peer_manager
AnnaBridge 143:86740a56073b 56 * @brief File containing definitions used solely inside the Peer Manager's modules.
AnnaBridge 143:86740a56073b 57 * @{
AnnaBridge 143:86740a56073b 58 */
AnnaBridge 143:86740a56073b 59
AnnaBridge 143:86740a56073b 60 ANON_UNIONS_ENABLE
AnnaBridge 143:86740a56073b 61
AnnaBridge 143:86740a56073b 62 /**@brief One piece of data associated with a peer, together with its type.
AnnaBridge 143:86740a56073b 63 *
AnnaBridge 143:86740a56073b 64 * @note This type is deprecated.
AnnaBridge 143:86740a56073b 65 */
AnnaBridge 143:86740a56073b 66 typedef struct
AnnaBridge 143:86740a56073b 67 {
AnnaBridge 143:86740a56073b 68 uint16_t length_words; /**< @brief The length of the data in words. */
AnnaBridge 143:86740a56073b 69 pm_peer_data_id_t data_id; /**< @brief ID that specifies the type of data (defines which member of the union is used). */
AnnaBridge 143:86740a56073b 70 union
AnnaBridge 143:86740a56073b 71 {
AnnaBridge 143:86740a56073b 72 pm_peer_data_bonding_t * p_bonding_data; /**< @brief The exchanged bond information in addition to metadata of the bonding. */
AnnaBridge 143:86740a56073b 73 uint32_t * p_peer_rank; /**< @brief A value locally assigned to this peer. Its interpretation is up to the user. The rank is not set automatically by the Peer Manager, but it is assigned by the user using either @ref pm_peer_rank_highest or a @ref PM_PEER_DATA_FUNCTIONS function. */
AnnaBridge 143:86740a56073b 74 bool * p_service_changed_pending; /**< @brief Whether a service changed indication should be sent to the peer. */
AnnaBridge 143:86740a56073b 75 pm_peer_data_local_gatt_db_t * p_local_gatt_db; /**< @brief Persistent information pertaining to a peer GATT client. */
AnnaBridge 143:86740a56073b 76 ble_gatt_db_srv_t * p_remote_gatt_db; /**< @brief Persistent information pertaining to a peer GATT server. */
AnnaBridge 143:86740a56073b 77 uint8_t * p_application_data; /**< @brief Arbitrary data to associate with the peer. This data can be freely used by the application. */
AnnaBridge 143:86740a56073b 78 void * p_all_data; /**< @brief Generic access pointer to the data. It is used only to handle the data without regard to type. */
AnnaBridge 143:86740a56073b 79 }; /**< @brief The data. */
AnnaBridge 143:86740a56073b 80 } pm_peer_data_t;
AnnaBridge 143:86740a56073b 81
AnnaBridge 143:86740a56073b 82
AnnaBridge 143:86740a56073b 83 /**@brief Immutable version of @ref pm_peer_data_t.
AnnaBridge 143:86740a56073b 84 *
AnnaBridge 143:86740a56073b 85 * @note This type is deprecated.
AnnaBridge 143:86740a56073b 86 */
AnnaBridge 143:86740a56073b 87 typedef struct
AnnaBridge 143:86740a56073b 88 {
AnnaBridge 143:86740a56073b 89 uint16_t length_words; /**< @brief The length of the data in words. */
AnnaBridge 143:86740a56073b 90 pm_peer_data_id_t data_id; /**< @brief ID that specifies the type of data (defines which member of the union is used). */
AnnaBridge 143:86740a56073b 91 union
AnnaBridge 143:86740a56073b 92 {
AnnaBridge 143:86740a56073b 93 pm_peer_data_bonding_t const * p_bonding_data; /**< @brief Immutable @ref pm_peer_data_t::p_bonding_data. */
AnnaBridge 143:86740a56073b 94 uint32_t const * p_peer_rank; /**< @brief Immutable @ref pm_peer_data_t::p_peer_rank. */
AnnaBridge 143:86740a56073b 95 bool const * p_service_changed_pending; /**< @brief Immutable @ref pm_peer_data_t::p_service_changed_pending. */
AnnaBridge 143:86740a56073b 96 pm_peer_data_local_gatt_db_t const * p_local_gatt_db; /**< @brief Immutable @ref pm_peer_data_t::p_local_gatt_db. */
AnnaBridge 143:86740a56073b 97 ble_gatt_db_srv_t const * p_remote_gatt_db; /**< @brief Immutable @ref pm_peer_data_t::p_remote_gatt_db. */
AnnaBridge 143:86740a56073b 98 uint8_t const * p_application_data; /**< @brief Immutable @ref pm_peer_data_t::p_application_data. */
AnnaBridge 143:86740a56073b 99 void const * p_all_data; /**< @brief Immutable @ref pm_peer_data_t::p_all_data. */
AnnaBridge 143:86740a56073b 100 }; /**< @brief The data. */
AnnaBridge 143:86740a56073b 101 } pm_peer_data_const_t;
AnnaBridge 143:86740a56073b 102
AnnaBridge 143:86740a56073b 103 ANON_UNIONS_DISABLE
AnnaBridge 143:86740a56073b 104
AnnaBridge 143:86740a56073b 105
AnnaBridge 143:86740a56073b 106 /**@brief Version of @ref pm_peer_data_t that reflects the structure of peer data in flash.
AnnaBridge 143:86740a56073b 107 *
AnnaBridge 143:86740a56073b 108 * @note This type is deprecated.
AnnaBridge 143:86740a56073b 109 */
AnnaBridge 143:86740a56073b 110 typedef pm_peer_data_const_t pm_peer_data_flash_t;
AnnaBridge 143:86740a56073b 111
AnnaBridge 143:86740a56073b 112
AnnaBridge 143:86740a56073b 113 /**@brief Macro for calculating the flash size of bonding data.
AnnaBridge 143:86740a56073b 114 *
AnnaBridge 143:86740a56073b 115 * @return The number of words that the data takes in flash.
AnnaBridge 143:86740a56073b 116 */
AnnaBridge 143:86740a56073b 117 #define PM_BONDING_DATA_N_WORDS() BYTES_TO_WORDS(sizeof(pm_peer_data_bonding_t))
AnnaBridge 143:86740a56073b 118
AnnaBridge 143:86740a56073b 119
AnnaBridge 143:86740a56073b 120 /**@brief Macro for calculating the flash size of service changed pending state.
AnnaBridge 143:86740a56073b 121 *
AnnaBridge 143:86740a56073b 122 * @return The number of words that the data takes in flash.
AnnaBridge 143:86740a56073b 123 */
AnnaBridge 143:86740a56073b 124 #define PM_SC_STATE_N_WORDS() BYTES_TO_WORDS(sizeof(bool))
AnnaBridge 143:86740a56073b 125
AnnaBridge 143:86740a56073b 126
AnnaBridge 143:86740a56073b 127 /**@brief Macro for calculating the flash size of local GATT database data.
AnnaBridge 143:86740a56073b 128 *
AnnaBridge 143:86740a56073b 129 * @param[in] local_db_len The length, in bytes, of the database as reported by the SoftDevice.
AnnaBridge 143:86740a56073b 130 *
AnnaBridge 143:86740a56073b 131 * @return The number of words that the data takes in flash.
AnnaBridge 143:86740a56073b 132 */
AnnaBridge 143:86740a56073b 133 #define PM_LOCAL_DB_N_WORDS(local_db_len) \
AnnaBridge 143:86740a56073b 134 BYTES_TO_WORDS((local_db_len) + PM_LOCAL_DB_LEN_OVERHEAD_BYTES)
AnnaBridge 143:86740a56073b 135
AnnaBridge 143:86740a56073b 136
AnnaBridge 143:86740a56073b 137 /**@brief Macro for calculating the length of a local GATT database attribute array.
AnnaBridge 143:86740a56073b 138 *
AnnaBridge 143:86740a56073b 139 * @param[in] n_words The number of words that the data takes in flash.
AnnaBridge 143:86740a56073b 140 *
AnnaBridge 143:86740a56073b 141 * @return The length of the database attribute array.
AnnaBridge 143:86740a56073b 142 */
AnnaBridge 143:86740a56073b 143 #define PM_LOCAL_DB_LEN(n_words) (((n_words) * BYTES_PER_WORD) - PM_LOCAL_DB_LEN_OVERHEAD_BYTES)
AnnaBridge 143:86740a56073b 144
AnnaBridge 143:86740a56073b 145
AnnaBridge 143:86740a56073b 146 /**@brief Macro for calculating the flash size of remote GATT database data.
AnnaBridge 143:86740a56073b 147 *
AnnaBridge 143:86740a56073b 148 * @param[in] service_count The number of services in the service array.
AnnaBridge 143:86740a56073b 149 *
AnnaBridge 143:86740a56073b 150 * @return The number of words that the data takes in flash.
AnnaBridge 143:86740a56073b 151 */
AnnaBridge 143:86740a56073b 152 #define PM_REMOTE_DB_N_WORDS(service_count) BYTES_TO_WORDS(sizeof(ble_gatt_db_srv_t) * (service_count))
AnnaBridge 143:86740a56073b 153
AnnaBridge 143:86740a56073b 154
AnnaBridge 143:86740a56073b 155 /**@brief Macro for calculating the flash size of remote GATT database data.
AnnaBridge 143:86740a56073b 156 *
AnnaBridge 143:86740a56073b 157 * @param[in] n_words The length in number of words.
AnnaBridge 143:86740a56073b 158 *
AnnaBridge 143:86740a56073b 159 * @return The number of words that the data takes in flash.
AnnaBridge 143:86740a56073b 160 */
AnnaBridge 143:86740a56073b 161 #define PM_REMOTE_DB_N_SERVICES(n_words) (((n_words) * BYTES_PER_WORD) / sizeof(ble_gatt_db_srv_t))
AnnaBridge 143:86740a56073b 162
AnnaBridge 143:86740a56073b 163
AnnaBridge 143:86740a56073b 164 /**@brief Function for calculating the flash size of the usage index.
AnnaBridge 143:86740a56073b 165 *
AnnaBridge 143:86740a56073b 166 * @return The number of words that the data takes in flash.
AnnaBridge 143:86740a56073b 167 */
AnnaBridge 143:86740a56073b 168 #define PM_USAGE_INDEX_N_WORDS() BYTES_TO_WORDS(sizeof(uint32_t))
AnnaBridge 143:86740a56073b 169
AnnaBridge 143:86740a56073b 170 /** @}
AnnaBridge 143:86740a56073b 171 * @endcond
AnnaBridge 143:86740a56073b 172 */
AnnaBridge 143:86740a56073b 173
AnnaBridge 143:86740a56073b 174 #endif /* PEER_MANAGER_INTERNAL_H__ */