Pedro Correia / mbed-dev

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Fri May 26 12:39:01 2017 +0100
Revision:
165:e614a9f1c9e2
Parent:
targets/TARGET_NORDIC/TARGET_NRF5/sdk/ble/peer_manager/pm_buffer.h@149:156823d33999
This updates the lib to the mbed lib v 143

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /*
<> 149:156823d33999 2 * Copyright (c) 2015 Nordic Semiconductor ASA
<> 149:156823d33999 3 * All rights reserved.
<> 149:156823d33999 4 *
<> 149:156823d33999 5 * Redistribution and use in source and binary forms, with or without modification,
<> 149:156823d33999 6 * are permitted provided that the following conditions are met:
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * 1. Redistributions of source code must retain the above copyright notice, this list
<> 149:156823d33999 9 * of conditions and the following disclaimer.
<> 149:156823d33999 10 *
<> 149:156823d33999 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
<> 149:156823d33999 12 * integrated circuit in a product or a software update for such product, must reproduce
<> 149:156823d33999 13 * the above copyright notice, this list of conditions and the following disclaimer in
<> 149:156823d33999 14 * the documentation and/or other materials provided with the distribution.
<> 149:156823d33999 15 *
<> 149:156823d33999 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
<> 149:156823d33999 17 * used to endorse or promote products derived from this software without specific prior
<> 149:156823d33999 18 * written permission.
<> 149:156823d33999 19 *
<> 149:156823d33999 20 * 4. This software, with or without modification, must only be used with a
<> 149:156823d33999 21 * Nordic Semiconductor ASA integrated circuit.
<> 149:156823d33999 22 *
<> 149:156823d33999 23 * 5. Any software provided in binary or object form under this license must not be reverse
<> 149:156823d33999 24 * engineered, decompiled, modified and/or disassembled.
<> 149:156823d33999 25 *
<> 149:156823d33999 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<> 149:156823d33999 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
<> 149:156823d33999 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 149:156823d33999 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
<> 149:156823d33999 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
<> 149:156823d33999 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
<> 149:156823d33999 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
<> 149:156823d33999 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<> 149:156823d33999 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
<> 149:156823d33999 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 149:156823d33999 36 *
<> 149:156823d33999 37 */
<> 149:156823d33999 38
<> 149:156823d33999 39
<> 149:156823d33999 40
<> 149:156823d33999 41 #ifndef BUFFER_H__
<> 149:156823d33999 42 #define BUFFER_H__
<> 149:156823d33999 43
<> 149:156823d33999 44 #include <stdint.h>
<> 149:156823d33999 45 #include "sdk_errors.h"
<> 149:156823d33999 46 #include "pm_mutex.h"
<> 149:156823d33999 47
<> 149:156823d33999 48
<> 149:156823d33999 49 /**
<> 149:156823d33999 50 * @cond NO_DOXYGEN
<> 149:156823d33999 51 * @defgroup pm_buffer Buffer
<> 149:156823d33999 52 * @ingroup peer_manager
<> 149:156823d33999 53 * @{
<> 149:156823d33999 54 * @brief An internal module of @ref peer_manager. This module provides a simple buffer.
<> 149:156823d33999 55 */
<> 149:156823d33999 56
<> 149:156823d33999 57
<> 149:156823d33999 58 #define BUFFER_INVALID_ID 0xFF
<> 149:156823d33999 59
<> 149:156823d33999 60 #define PM_BUFFER_INIT(p_buffer, n_blocks, block_size, err_code) \
<> 149:156823d33999 61 do \
<> 149:156823d33999 62 { \
<> 149:156823d33999 63 static union { \
<> 149:156823d33999 64 uint8_t u8[(n_blocks) * (block_size)]; \
<> 149:156823d33999 65 uint32_t u32[1]; /*force allign to uint32_t*/ \
<> 149:156823d33999 66 } buffer_memory; \
<> 149:156823d33999 67 static uint8_t mutex_memory[MUTEX_STORAGE_SIZE(n_blocks)]; \
<> 149:156823d33999 68 err_code = pm_buffer_init((p_buffer), \
<> 149:156823d33999 69 buffer_memory.u8, \
<> 149:156823d33999 70 (n_blocks) * (block_size), \
<> 149:156823d33999 71 mutex_memory, \
<> 149:156823d33999 72 MUTEX_STORAGE_SIZE(n_blocks), \
<> 149:156823d33999 73 (n_blocks), \
<> 149:156823d33999 74 (block_size)); \
<> 149:156823d33999 75 } while(0)
<> 149:156823d33999 76
<> 149:156823d33999 77
<> 149:156823d33999 78 typedef struct
<> 149:156823d33999 79 {
<> 149:156823d33999 80 uint8_t * p_memory; /**< The storage for all buffer entries. The size of the buffer must be n_blocks*block_size. */
<> 149:156823d33999 81 uint8_t * p_mutex; /**< A mutex group with one mutex for each buffer entry. */
<> 149:156823d33999 82 uint32_t n_blocks; /**< The number of allocatable blocks in the buffer. */
<> 149:156823d33999 83 uint32_t block_size; /**< The size of each block in the buffer. */
<> 149:156823d33999 84 } pm_buffer_t;
<> 149:156823d33999 85
<> 149:156823d33999 86 /**@brief Function for initializing a buffer instance.
<> 149:156823d33999 87 *
<> 149:156823d33999 88 * @param[out] p_buffer The buffer instance to initialize.
<> 149:156823d33999 89 * @param[in] p_buffer_memory The memory this buffer will use.
<> 149:156823d33999 90 * @param[in] buffer_memory_size The size of p_buffer_memory. This must be at least
<> 149:156823d33999 91 * n_blocks*block_size.
<> 149:156823d33999 92 * @param[in] p_mutex_memory The memory for the mutexes. This must be at least
<> 149:156823d33999 93 * @ref MUTEX_STORAGE_SIZE(n_blocks).
<> 149:156823d33999 94 * @param[in] mutex_memory_size The size of p_mutex_memory.
<> 149:156823d33999 95 * @param[in] n_blocks The number of blocks in the buffer.
<> 149:156823d33999 96 * @param[in] block_size The size of each block.
<> 149:156823d33999 97 *
<> 149:156823d33999 98 * @retval NRF_SUCCESS Successfully initialized buffer instance.
<> 149:156823d33999 99 * @retval NRF_ERROR_INVALID_PARAM A parameter was 0 or NULL or a size was too small.
<> 149:156823d33999 100 */
<> 149:156823d33999 101 ret_code_t pm_buffer_init(pm_buffer_t * p_buffer,
<> 149:156823d33999 102 uint8_t * p_buffer_memory,
<> 149:156823d33999 103 uint32_t buffer_memory_size,
<> 149:156823d33999 104 uint8_t * p_mutex_memory,
<> 149:156823d33999 105 uint32_t mutex_memory_size,
<> 149:156823d33999 106 uint32_t n_blocks,
<> 149:156823d33999 107 uint32_t block_size);
<> 149:156823d33999 108
<> 149:156823d33999 109
<> 149:156823d33999 110 /**@brief Function for acquiring a buffer block in a buffer.
<> 149:156823d33999 111 *
<> 149:156823d33999 112 * @param[in] p_buffer The buffer instance acquire from.
<> 149:156823d33999 113 * @param[in] n_blocks The number of contiguous blocks to acquire.
<> 149:156823d33999 114 *
<> 149:156823d33999 115 * @return The id of the acquired block, if successful.
<> 149:156823d33999 116 * @retval BUFFER_INVALID_ID If unsuccessful.
<> 149:156823d33999 117 */
<> 149:156823d33999 118 uint8_t pm_buffer_block_acquire(pm_buffer_t * p_buffer, uint32_t n_blocks);
<> 149:156823d33999 119
<> 149:156823d33999 120
<> 149:156823d33999 121 /**@brief Function for getting a pointer to a specific buffer block.
<> 149:156823d33999 122 *
<> 149:156823d33999 123 * @param[in] p_buffer The buffer instance get from.
<> 149:156823d33999 124 * @param[in] id The id of the buffer to get the pointer for.
<> 149:156823d33999 125 *
<> 149:156823d33999 126 * @return A pointer to the buffer for the specified id, if the id is valid.
<> 149:156823d33999 127 * @retval NULL If the id is invalid.
<> 149:156823d33999 128 */
<> 149:156823d33999 129 uint8_t * pm_buffer_ptr_get(pm_buffer_t * p_buffer, uint8_t id);
<> 149:156823d33999 130
<> 149:156823d33999 131
<> 149:156823d33999 132 /**@brief Function for releasing a buffer block.
<> 149:156823d33999 133 *
<> 149:156823d33999 134 * @param[in] p_buffer The buffer instance containing the block to release.
<> 149:156823d33999 135 * @param[in] id The id of the block to release.
<> 149:156823d33999 136 */
<> 149:156823d33999 137 void pm_buffer_release(pm_buffer_t * p_buffer, uint8_t id);
<> 149:156823d33999 138
<> 149:156823d33999 139
<> 149:156823d33999 140 #endif // BUFFER_H__
<> 149:156823d33999 141
<> 149:156823d33999 142 /**
<> 149:156823d33999 143 * @}
<> 149:156823d33999 144 * @endcond
<> 149:156823d33999 145 */