Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nrf51-sdk by
pm_buffer.h
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 00034 #ifndef BUFFER_H__ 00035 #define BUFFER_H__ 00036 00037 #include <stdint.h> 00038 #include "sdk_errors.h " 00039 #include "pm_mutex.h" 00040 00041 00042 /** 00043 * @defgroup pm_buffer Buffer 00044 * @ingroup peer_manager 00045 * @{ 00046 * @brief An internal module of @ref peer_manager. This module provides a simple buffer. 00047 */ 00048 00049 00050 #define BUFFER_INVALID_ID 0xFF 00051 00052 #define PM_BUFFER_INIT(p_buffer, n_blocks, block_size, err_code) \ 00053 do \ 00054 { \ 00055 static uint8_t buffer_memory[(n_blocks) * (block_size)]; \ 00056 static uint8_t mutex_memory[MUTEX_STORAGE_SIZE(n_blocks)]; \ 00057 err_code = pm_buffer_init((p_buffer), \ 00058 buffer_memory, \ 00059 (n_blocks) * (block_size), \ 00060 mutex_memory, \ 00061 MUTEX_STORAGE_SIZE(n_blocks), \ 00062 (n_blocks), \ 00063 (block_size)); \ 00064 } while(0) 00065 00066 00067 typedef struct 00068 { 00069 uint8_t * p_memory; /**< The storage for all buffer entries. The size of the buffer must be n_blocks*block_size. */ 00070 uint8_t * p_mutex; /**< A mutex group with one mutex for each buffer entry. */ 00071 uint32_t n_blocks; /**< The number of allocatable blocks in the buffer. */ 00072 uint32_t block_size; /**< The size of each block in the buffer. */ 00073 } pm_buffer_t; 00074 00075 /**@brief Function for initializing a buffer instance. 00076 * 00077 * @param[out] p_buffer The buffer instance to initialize. 00078 * @param[in] p_buffer_memory The memory this buffer will use. 00079 * @param[in] buffer_memory_size The size of p_buffer_memory. This must be at least 00080 * n_blocks*block_size. 00081 * @param[in] p_mutex_memory The memory for the mutexes. This must be at least 00082 * @ref MUTEX_STORAGE_SIZE(n_blocks). 00083 * @param[in] mutex_memory_size The size of p_mutex_memory. 00084 * @param[in] n_blocks The number of blocks in the buffer. 00085 * @param[in] block_size The size of each block. 00086 * 00087 * @retval NRF_SUCCESS Successfully initialized buffer instance. 00088 * @retval NRF_ERROR_INVALID_PARAM A parameter was 0 or NULL or a size was too small. 00089 */ 00090 ret_code_t pm_buffer_init(pm_buffer_t * p_buffer, 00091 uint8_t * p_buffer_memory, 00092 uint32_t buffer_memory_size, 00093 uint8_t * p_mutex_memory, 00094 uint32_t mutex_memory_size, 00095 uint32_t n_blocks, 00096 uint32_t block_size); 00097 00098 00099 /**@brief Function for acquiring a buffer block in a buffer. 00100 * 00101 * @param[in] p_buffer The buffer instance acquire from. 00102 * @param[in] n_blocks The number of contiguous blocks to acquire. 00103 * 00104 * @return The id of the acquired block, if successful. 00105 * @retval BUFFER_INVALID_ID If unsuccessful. 00106 */ 00107 uint8_t pm_buffer_block_acquire(pm_buffer_t * p_buffer, uint32_t n_blocks); 00108 00109 00110 /**@brief Function for getting a pointer to a specific buffer block. 00111 * 00112 * @param[in] p_buffer The buffer instance get from. 00113 * @param[in] id The id of the buffer to get the pointer for. 00114 * 00115 * @return A pointer to the buffer for the specified id, if the id is valid. 00116 * @retval NULL If the id is invalid. 00117 */ 00118 uint8_t * pm_buffer_ptr_get(pm_buffer_t * p_buffer, uint8_t id); 00119 00120 00121 /**@brief Function for releasing a buffer block. 00122 * 00123 * @param[in] p_buffer The buffer instance containing the block to release. 00124 * @param[in] id The id of the block to release. 00125 */ 00126 void pm_buffer_release(pm_buffer_t * p_buffer, uint8_t id); 00127 00128 00129 #endif // BUFFER_H__ 00130 00131 /** 00132 * @} 00133 */
Generated on Tue Jul 12 2022 14:11:20 by
