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:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_VBLUNO51/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/ble/peer_manager/pm_buffer.h@169:a7c7b631e539
mbed library. Release version 164

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 BUFFER_H__
AnnaBridge 143:86740a56073b 42 #define BUFFER_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 "pm_mutex.h"
AnnaBridge 143:86740a56073b 47
AnnaBridge 143:86740a56073b 48
AnnaBridge 143:86740a56073b 49 /**
AnnaBridge 143:86740a56073b 50 * @cond NO_DOXYGEN
AnnaBridge 143:86740a56073b 51 * @defgroup pm_buffer Buffer
AnnaBridge 143:86740a56073b 52 * @ingroup peer_manager
AnnaBridge 143:86740a56073b 53 * @{
AnnaBridge 143:86740a56073b 54 * @brief An internal module of @ref peer_manager. This module provides a simple buffer.
AnnaBridge 143:86740a56073b 55 */
AnnaBridge 143:86740a56073b 56
AnnaBridge 143:86740a56073b 57
AnnaBridge 143:86740a56073b 58 #define BUFFER_INVALID_ID 0xFF
AnnaBridge 143:86740a56073b 59
AnnaBridge 143:86740a56073b 60 #define PM_BUFFER_INIT(p_buffer, n_blocks, block_size, err_code) \
AnnaBridge 143:86740a56073b 61 do \
AnnaBridge 143:86740a56073b 62 { \
AnnaBridge 143:86740a56073b 63 static union { \
AnnaBridge 143:86740a56073b 64 uint8_t u8[(n_blocks) * (block_size)]; \
AnnaBridge 143:86740a56073b 65 uint32_t u32[1]; /*force allign to uint32_t*/ \
AnnaBridge 143:86740a56073b 66 } buffer_memory; \
AnnaBridge 143:86740a56073b 67 static uint8_t mutex_memory[MUTEX_STORAGE_SIZE(n_blocks)]; \
AnnaBridge 143:86740a56073b 68 err_code = pm_buffer_init((p_buffer), \
AnnaBridge 143:86740a56073b 69 buffer_memory.u8, \
AnnaBridge 143:86740a56073b 70 (n_blocks) * (block_size), \
AnnaBridge 143:86740a56073b 71 mutex_memory, \
AnnaBridge 143:86740a56073b 72 MUTEX_STORAGE_SIZE(n_blocks), \
AnnaBridge 143:86740a56073b 73 (n_blocks), \
AnnaBridge 143:86740a56073b 74 (block_size)); \
AnnaBridge 143:86740a56073b 75 } while(0)
AnnaBridge 143:86740a56073b 76
AnnaBridge 143:86740a56073b 77
AnnaBridge 143:86740a56073b 78 typedef struct
AnnaBridge 143:86740a56073b 79 {
AnnaBridge 143:86740a56073b 80 uint8_t * p_memory; /**< The storage for all buffer entries. The size of the buffer must be n_blocks*block_size. */
AnnaBridge 143:86740a56073b 81 uint8_t * p_mutex; /**< A mutex group with one mutex for each buffer entry. */
AnnaBridge 143:86740a56073b 82 uint32_t n_blocks; /**< The number of allocatable blocks in the buffer. */
AnnaBridge 143:86740a56073b 83 uint32_t block_size; /**< The size of each block in the buffer. */
AnnaBridge 143:86740a56073b 84 } pm_buffer_t;
AnnaBridge 143:86740a56073b 85
AnnaBridge 143:86740a56073b 86 /**@brief Function for initializing a buffer instance.
AnnaBridge 143:86740a56073b 87 *
AnnaBridge 143:86740a56073b 88 * @param[out] p_buffer The buffer instance to initialize.
AnnaBridge 143:86740a56073b 89 * @param[in] p_buffer_memory The memory this buffer will use.
AnnaBridge 143:86740a56073b 90 * @param[in] buffer_memory_size The size of p_buffer_memory. This must be at least
AnnaBridge 143:86740a56073b 91 * n_blocks*block_size.
AnnaBridge 143:86740a56073b 92 * @param[in] p_mutex_memory The memory for the mutexes. This must be at least
AnnaBridge 143:86740a56073b 93 * @ref MUTEX_STORAGE_SIZE(n_blocks).
AnnaBridge 143:86740a56073b 94 * @param[in] mutex_memory_size The size of p_mutex_memory.
AnnaBridge 143:86740a56073b 95 * @param[in] n_blocks The number of blocks in the buffer.
AnnaBridge 143:86740a56073b 96 * @param[in] block_size The size of each block.
AnnaBridge 143:86740a56073b 97 *
AnnaBridge 143:86740a56073b 98 * @retval NRF_SUCCESS Successfully initialized buffer instance.
AnnaBridge 143:86740a56073b 99 * @retval NRF_ERROR_INVALID_PARAM A parameter was 0 or NULL or a size was too small.
AnnaBridge 143:86740a56073b 100 */
AnnaBridge 143:86740a56073b 101 ret_code_t pm_buffer_init(pm_buffer_t * p_buffer,
AnnaBridge 143:86740a56073b 102 uint8_t * p_buffer_memory,
AnnaBridge 143:86740a56073b 103 uint32_t buffer_memory_size,
AnnaBridge 143:86740a56073b 104 uint8_t * p_mutex_memory,
AnnaBridge 143:86740a56073b 105 uint32_t mutex_memory_size,
AnnaBridge 143:86740a56073b 106 uint32_t n_blocks,
AnnaBridge 143:86740a56073b 107 uint32_t block_size);
AnnaBridge 143:86740a56073b 108
AnnaBridge 143:86740a56073b 109
AnnaBridge 143:86740a56073b 110 /**@brief Function for acquiring a buffer block in a buffer.
AnnaBridge 143:86740a56073b 111 *
AnnaBridge 143:86740a56073b 112 * @param[in] p_buffer The buffer instance acquire from.
AnnaBridge 143:86740a56073b 113 * @param[in] n_blocks The number of contiguous blocks to acquire.
AnnaBridge 143:86740a56073b 114 *
AnnaBridge 143:86740a56073b 115 * @return The id of the acquired block, if successful.
AnnaBridge 143:86740a56073b 116 * @retval BUFFER_INVALID_ID If unsuccessful.
AnnaBridge 143:86740a56073b 117 */
AnnaBridge 143:86740a56073b 118 uint8_t pm_buffer_block_acquire(pm_buffer_t * p_buffer, uint32_t n_blocks);
AnnaBridge 143:86740a56073b 119
AnnaBridge 143:86740a56073b 120
AnnaBridge 143:86740a56073b 121 /**@brief Function for getting a pointer to a specific buffer block.
AnnaBridge 143:86740a56073b 122 *
AnnaBridge 143:86740a56073b 123 * @param[in] p_buffer The buffer instance get from.
AnnaBridge 143:86740a56073b 124 * @param[in] id The id of the buffer to get the pointer for.
AnnaBridge 143:86740a56073b 125 *
AnnaBridge 143:86740a56073b 126 * @return A pointer to the buffer for the specified id, if the id is valid.
AnnaBridge 143:86740a56073b 127 * @retval NULL If the id is invalid.
AnnaBridge 143:86740a56073b 128 */
AnnaBridge 143:86740a56073b 129 uint8_t * pm_buffer_ptr_get(pm_buffer_t * p_buffer, uint8_t id);
AnnaBridge 143:86740a56073b 130
AnnaBridge 143:86740a56073b 131
AnnaBridge 143:86740a56073b 132 /**@brief Function for releasing a buffer block.
AnnaBridge 143:86740a56073b 133 *
AnnaBridge 143:86740a56073b 134 * @param[in] p_buffer The buffer instance containing the block to release.
AnnaBridge 143:86740a56073b 135 * @param[in] id The id of the block to release.
AnnaBridge 143:86740a56073b 136 */
AnnaBridge 143:86740a56073b 137 void pm_buffer_release(pm_buffer_t * p_buffer, uint8_t id);
AnnaBridge 143:86740a56073b 138
AnnaBridge 143:86740a56073b 139
AnnaBridge 143:86740a56073b 140 #endif // BUFFER_H__
AnnaBridge 143:86740a56073b 141
AnnaBridge 143:86740a56073b 142 /**
AnnaBridge 143:86740a56073b 143 * @}
AnnaBridge 143:86740a56073b 144 * @endcond
AnnaBridge 143:86740a56073b 145 */