Nordic stack and drivers for the mbed BLE API

Dependents:   BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate writable_gatt ... more

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

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