Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fnet_mempool.h Source File

fnet_mempool.h

00001 /**************************************************************************
00002 *
00003 * Copyright 2011-2016 by Andrey Butok. FNET Community.
00004 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
00005 *
00006 ***************************************************************************
00007 *
00008 *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00009 *  not use this file except in compliance with the License.
00010 *  You may obtain a copy of the License at
00011 *
00012 *  http://www.apache.org/licenses/LICENSE-2.0
00013 *
00014 *  Unless required by applicable law or agreed to in writing, software
00015 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00016 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017 *  See the License for the specific language governing permissions and
00018 *  limitations under the License.
00019 *
00020 **********************************************************************/
00021 /*!
00022 * @brief FNET memory pools API.
00023 *
00024 ***************************************************************************/
00025 
00026 #ifndef _FNET_MEMPOOL_H_
00027 
00028 #define _FNET_MEMPOOL_H_
00029 
00030 /**************************************************************************/ /*!
00031  * @internal
00032  * @brief Memory pool descriptor.
00033  * @see fnet_mempool_init()
00034  ******************************************************************************/
00035 typedef fnet_int32_t fnet_mempool_desc_t;
00036 
00037 /* Memory pool unit header.*/
00038 FNET_COMP_PACKED_BEGIN
00039 typedef struct fnet_mempool_unit_header
00040 {
00041     fnet_size_t                         size FNET_COMP_PACKED;                     /* Unit size. */
00042     struct fnet_mempool_unit_header     *ptr FNET_COMP_PACKED;   /* Pointer to the next free block. */
00043 }
00044 fnet_mempool_unit_header_t;
00045 FNET_COMP_PACKED_END
00046 
00047 typedef enum
00048 {
00049     FNET_MEMPOOL_ALIGN_8 = (0x7u),       /* Evenly divisible by 8.*/
00050     FNET_MEMPOOL_ALIGN_16 = (0xFu),      /* Evenly divisible by 16.*/
00051     FNET_MEMPOOL_ALIGN_32 = (0x1Fu),     /* Evenly divisible by 32.*/
00052     FNET_MEMPOOL_ALIGN_64 = (0x3Fu)      /* Evenly divisible by 64.*/
00053 }
00054 fnet_mempool_align_t;
00055 
00056 #if defined(__cplusplus)
00057 extern "C" {
00058 #endif
00059 
00060 fnet_mempool_desc_t fnet_mempool_init( void *pool_ptr, fnet_size_t pool_size, fnet_mempool_align_t alignment );
00061 void fnet_mempool_release( fnet_mempool_desc_t mpool );
00062 void fnet_mempool_free( fnet_mempool_desc_t mpool, void *ap );
00063 void *fnet_mempool_malloc(fnet_mempool_desc_t mpool, fnet_size_t nbytes );
00064 fnet_size_t fnet_mempool_free_mem_status( fnet_mempool_desc_t mpool);
00065 fnet_size_t fnet_mempool_malloc_max( fnet_mempool_desc_t mpool );
00066 
00067 #if 0 /* For Debug needs.*/
00068 fnet_return_t fnet_mempool_check( fnet_mempool_desc_t mpool );
00069 #endif
00070 
00071 #if defined(__cplusplus)
00072 }
00073 #endif
00074 
00075 #endif