Free (GPLv2) TCP/IP stack developed by TASS Belgium

Dependents:   lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pico_mm.h Source File

pico_mm.h

00001 /*********************************************************************
00002    PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
00003    See LICENSE and COPYING for usage.
00004 
00005    Authors: Gustav Janssens, Jonas Van Nieuwenberg, Sam Van Den Berge
00006  *********************************************************************/
00007 
00008 
00009 #ifndef _INCLUDE_PICO_MM
00010 #define _INCLUDE_PICO_MM
00011 
00012 #include "pico_config.h"
00013 
00014 /*
00015  * Memory init function, this will create a memory manager instance
00016  * A memory_manager page will be created, along with one page of memory
00017  * Memory can be asked for via the pico_mem_zalloc function
00018  * More memory will be allocated to the memory manager according to its needs
00019  * A maximum amount of memory of uint32_t memsize can be allocated
00020  */
00021 void pico_mem_init(uint32_t memsize);
00022 /*
00023  * Memory deinit function, this will free all memory occupied by the current
00024  * memory manager instance.
00025  */
00026 void pico_mem_deinit(void);
00027 /*
00028  * Zero-initialized malloc function, will reserve a memory segment of length uint32_t len
00029  * This memory will be quickly allocated in a slab of fixed size if possible
00030  * or less optimally in the heap for a small variable size
00031  * The fixed size of the slabs can be changed dynamically via a statistics engine
00032  */
00033 void*pico_mem_zalloc(size_t len);
00034 /*
00035  * Free function, free a block of memory pointed to by ptr.
00036  * Unused memory is only returned to the system's control by pico_mem_cleanup
00037  */
00038 void pico_mem_free(void*ptr);
00039 /*
00040  * This cleanup function will be provided by the memory manager
00041  * It can be called during processor downtime
00042  * This function will return unused pages to the system's control
00043  * Pages are unused if they no longer contain slabs or heap, and they have been idle for a longer time
00044  */
00045 void pico_mem_cleanup(uint32_t timestamp);
00046 
00047 
00048 
00049 #ifdef PICO_SUPPORT_MM_PROFILING
00050 /***********************************************************************************************************************
00051  ***********************************************************************************************************************
00052    MEMORY PROFILING FUNCTIONS
00053  ***********************************************************************************************************************
00054  ***********************************************************************************************************************/
00055 /* General info struct */
00056 struct profiling_data
00057 {
00058     uint32_t free_heap_space;
00059     uint32_t free_slab_space;
00060     uint32_t used_heap_space;
00061     uint32_t used_slab_space;
00062 };
00063 
00064 /*
00065  * This function fills up a struct with used and free slab and heap space in the memory manager
00066  * The user is responsible for resource managment
00067  */
00068 void pico_mem_profile_collect_data(struct profiling_data*profiling_page_struct);
00069 
00070 /*
00071  * This function prints the general structure of the memory manager
00072  * Printf in this function can be rerouted to send this data over a serial port, or to write it away to memory
00073  */
00074 void pico_mem_profile_scan_data(void);
00075 
00076 /*
00077  * This function returns the total size that the manager has received from the system
00078  * This can give an indication of the total system resource commitment, but keep in mind that
00079  * there can be many free blocks in this "used" size
00080  * Together with pico_mem_profile_collect_data, this can give a good estimation of the total
00081  * resource commitment
00082  */
00083 uint32_t pico_mem_profile_used_size(void);
00084 
00085 /*
00086  * This function returns a pointer to page 0, the main memory manager housekeeping (struct pico_mem_manager).
00087  * This can be used to collect data about the memory in user defined functions.
00088  * Use with care!
00089  */
00090 void*pico_mem_profile_manager(void);
00091 
00092 /*
00093  * paramter manager is a pointer to a struct pico_mem_manager
00094  */
00095 void pico_mem_init_profiling(void*manager, uint32_t memsize);
00096 #endif /* PICO_SUPPORT_MM_PROFILING */
00097 
00098 #endif /* _INCLUDE_PICO_MM */