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.
NanostackMemoryManager.h
00001 /* Copyright (c) 2017 ARM Limited 00002 * 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 */ 00015 00016 #ifndef NANOSTACK_MEMORY_MANAGER_H 00017 #define NANOSTACK_MEMORY_MANAGER_H 00018 00019 #include "EMACMemoryManager.h" 00020 00021 class NanostackMemoryManager : public EMACMemoryManager { 00022 public: 00023 00024 /** 00025 * Allocates memory buffer from the heap 00026 * 00027 * Memory buffer allocated from heap is always contiguous and can be arbitrary size. 00028 * 00029 * @param size Size of the memory to allocate in bytes 00030 * @param align Memory alignment requirement in bytes 00031 * @return Allocated memory buffer, or NULL in case of error 00032 */ 00033 virtual emac_mem_buf_t *alloc_heap(uint32_t size, uint32_t align); 00034 00035 /** 00036 * Allocates memory buffer chain from a pool 00037 * 00038 * Memory allocated from pool is contiguous if size is equal or less than 00039 * (aligned) allocation unit, otherwise may be chained. Will typically come from 00040 * fixed-size packet pool memory. 00041 * 00042 * @param size Total size of the memory to allocate in bytes 00043 * @param align Memory alignment requirement for each buffer in bytes 00044 * @return Allocated memory buffer chain, or NULL in case of error 00045 */ 00046 virtual emac_mem_buf_t *alloc_pool(uint32_t size, uint32_t align); 00047 00048 /** 00049 * Get memory buffer pool allocation unit 00050 * 00051 * Returns the maximum size of contiguous memory that can be allocated from a pool. 00052 * 00053 * @param align Memory alignment requirement in bytes 00054 * @return Contiguous memory size 00055 */ 00056 virtual uint32_t get_pool_alloc_unit(uint32_t align) const; 00057 00058 /** 00059 * Free memory buffer chain 00060 * 00061 * If memory buffer is chained must point to the start of the chain. Frees all buffers 00062 * from the chained list. 00063 * 00064 * @param buf Memory buffer chain to be freed. 00065 */ 00066 virtual void free(emac_mem_buf_t *buf); 00067 00068 /** 00069 * Return total length of a memory buffer chain 00070 * 00071 * Returns a total length of this buffer and any following buffers in the chain. 00072 * 00073 * @param buf Memory buffer chain 00074 * @return Total length in bytes 00075 */ 00076 virtual uint32_t get_total_len(const emac_mem_buf_t *buf) const; 00077 00078 virtual void set_align_preference(uint32_t align) { } 00079 00080 /** 00081 * Copy a memory buffer chain 00082 * 00083 * Copies data from one buffer chain to another. Copy operation does not adjust the lengths 00084 * of the copied-to memory buffer chain, so chain total lengths must be the same. 00085 * 00086 * @param to_buf Memory buffer chain to copy to 00087 * @param from_buf Memory buffer chain to copy from 00088 */ 00089 virtual void copy(emac_mem_buf_t *to_buf, const emac_mem_buf_t *from_buf); 00090 00091 00092 00093 /** 00094 * Concatenate two memory buffer chains 00095 * 00096 * Concatenates buffer chain to end of the other buffer chain. Concatenated-to buffer total length 00097 * is adjusted accordingly. cat_buf must point to the start of a the chain. After concatenation 00098 * to_buf's chain now owns those buffers, and they will be freed when the to_buf chain is freed. 00099 * 00100 * @param to_buf Memory buffer chain to concatenate to 00101 * @param cat_buf Memory buffer chain to concatenate 00102 */ 00103 virtual void cat(emac_mem_buf_t *to_buf, emac_mem_buf_t *cat_buf); 00104 00105 /** 00106 * Returns the next buffer 00107 * 00108 * Returns the next buffer from the memory buffer chain. 00109 * 00110 * @param buf Memory buffer 00111 * @return The next memory buffer, or NULL if last 00112 */ 00113 virtual emac_mem_buf_t *get_next(const emac_mem_buf_t *buf) const; 00114 00115 /** 00116 * Return pointer to the payload of the buffer 00117 * 00118 * @param buf Memory buffer 00119 * @return Pointer to the payload 00120 */ 00121 virtual void *get_ptr(const emac_mem_buf_t *buf) const; 00122 00123 /** 00124 * Return payload size of the buffer 00125 * 00126 * @param buf Memory buffer 00127 * @return Size in bytes 00128 */ 00129 virtual uint32_t get_len(const emac_mem_buf_t *buf) const; 00130 00131 /** 00132 * Sets the payload size of the buffer 00133 * 00134 * The allocated payload size will not change. It is not permitted 00135 * to change the length of a buffer that is not the first (or only) in a chain. 00136 * 00137 * @param buf Memory buffer 00138 * @param len Payload size, must be less or equal allocated size 00139 */ 00140 virtual void set_len(emac_mem_buf_t *buf, uint32_t len); 00141 }; 00142 00143 #endif /* NANOSTACK_MEMORY_MANAGER_H */
Generated on Tue Jul 12 2022 12:45:35 by
