mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-27 10:24:04 +00:00
Merge branch 'feature/multi_heap' into 'master'
Separate the heap implementation from FreeRTOS See merge request !731
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef _HEAP_REGIONS_H
|
||||
#define _HEAP_REGIONS_H
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
/* The maximum amount of tags in use */
|
||||
#define HEAPREGIONS_MAX_TAGCOUNT 16
|
||||
|
||||
/**
|
||||
* @brief Structure to define a memory region
|
||||
*/
|
||||
typedef struct HeapRegionTagged
|
||||
{
|
||||
uint8_t *pucStartAddress; ///< Start address of the region
|
||||
size_t xSizeInBytes; ///< Size of the region
|
||||
BaseType_t xTag; ///< Tag for the region
|
||||
uint32_t xExecAddr; ///< If non-zero, indicates the region also has an alias in IRAM.
|
||||
} HeapRegionTagged_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the heap allocator by feeding it the usable memory regions and their tags.
|
||||
*
|
||||
* This takes an array of heapRegionTagged_t structs, the last entry of which is a dummy entry
|
||||
* which has pucStartAddress set to NULL. It will initialize the heap allocator to serve memory
|
||||
* from these ranges.
|
||||
*
|
||||
* @param pxHeapRegions Array of region definitions
|
||||
*/
|
||||
|
||||
void vPortDefineHeapRegionsTagged( const HeapRegionTagged_t * const pxHeapRegions );
|
||||
|
||||
|
||||
/**
|
||||
* @brief Allocate memory from a region with a certain tag
|
||||
*
|
||||
* Like pvPortMalloc, this returns an allocated chunk of memory. This function,
|
||||
* however, forces the allocator to allocate from a region specified by a
|
||||
* specific tag.
|
||||
*
|
||||
* @param xWantedSize Size needed, in bytes
|
||||
* @param tag Tag of the memory region the allocation has to be from
|
||||
*
|
||||
* @return Pointer to allocated memory if succesful.
|
||||
* NULL if unsuccesful.
|
||||
*/
|
||||
void *pvPortMallocTagged( size_t xWantedSize, BaseType_t tag );
|
||||
|
||||
/**
|
||||
* @brief Free memory allocated with pvPortMallocTagged
|
||||
*
|
||||
* This is basically an implementation of free().
|
||||
*
|
||||
* @param pv Pointer to region allocated by pvPortMallocTagged
|
||||
*/
|
||||
void vPortFreeTagged( void *pv );
|
||||
|
||||
/**
|
||||
* @brief Get the lowest amount of memory free for a certain tag
|
||||
*
|
||||
* This function allows the user to see what the least amount of
|
||||
* free memory for a certain tag is.
|
||||
*
|
||||
* @param tag Tag of the memory region
|
||||
*
|
||||
* @return Minimum amount of free bytes available in the runtime of
|
||||
* the program
|
||||
*/
|
||||
size_t xPortGetMinimumEverFreeHeapSizeTagged( BaseType_t tag );
|
||||
|
||||
/**
|
||||
* @brief Get the amount of free bytes in a certain tagged region
|
||||
*
|
||||
* Works like xPortGetFreeHeapSize but allows the user to specify
|
||||
* a specific tag
|
||||
*
|
||||
* @param tag Tag of the memory region
|
||||
*
|
||||
* @return Remaining amount of free bytes in region
|
||||
*/
|
||||
size_t xPortGetFreeHeapSizeTagged( BaseType_t tag );
|
||||
|
||||
|
||||
#endif
|
@@ -1,79 +0,0 @@
|
||||
#ifndef _HEAP_REGION_DEBUG_H
|
||||
#define _HEAP_REGION_DEBUG_H
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
#if (configENABLE_MEMORY_DEBUG == 1)
|
||||
|
||||
#define DEBUG_DOG_VALUE 0x1a2b3c4d
|
||||
#define DEBUG_MAX_INFO_NUM 20
|
||||
#define DEBUG_TYPE_MALLOC 1
|
||||
#define DEBUG_TYPE_FREE 2
|
||||
|
||||
typedef struct {
|
||||
unsigned int dog;
|
||||
char task[4];
|
||||
unsigned int pc;
|
||||
}block_head_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int dog;
|
||||
}block_tail_t;
|
||||
|
||||
/* Please keep this definition same as BlockLink_t */
|
||||
typedef struct _os_block_t {
|
||||
struct _os_block_t *next; /*<< The next free block in the list. */
|
||||
int size: 24; /*<< The size of the free block. */
|
||||
int xtag: 7; /*<< Tag of this region */
|
||||
int xAllocated: 1; /*<< 1 if allocated */
|
||||
}os_block_t;
|
||||
|
||||
typedef struct {
|
||||
block_head_t head;
|
||||
os_block_t os_block;
|
||||
}debug_block_t;
|
||||
|
||||
typedef struct _mem_dbg_info{
|
||||
void *addr;
|
||||
char *task;
|
||||
uint32_t pc;
|
||||
uint32_t time;
|
||||
uint8_t type;
|
||||
}mem_dbg_info_t;
|
||||
|
||||
typedef struct _mem_dbg_ctl{
|
||||
mem_dbg_info_t info[DEBUG_MAX_INFO_NUM];
|
||||
uint32_t cnt;
|
||||
}mem_dbg_ctl_t;
|
||||
|
||||
#define BLOCK_HEAD_LEN sizeof(block_head_t)
|
||||
#define BLOCK_TAIL_LEN sizeof(block_tail_t)
|
||||
#define OS_BLOCK(_b) ((os_block_t*)((debug_block_t*)((char*)(_b) + BLOCK_HEAD_LEN)))
|
||||
#define DEBUG_BLOCK(_b) ((debug_block_t*)((char*)(_b) - BLOCK_HEAD_LEN))
|
||||
#define HEAD_DOG(_b) ((_b)->head.dog)
|
||||
#define TAIL_DOG(_b) (*(unsigned int*)((char*)(_b) + (((_b)->os_block.size ) - BLOCK_TAIL_LEN)))
|
||||
|
||||
#define DOG_ASSERT()\
|
||||
{\
|
||||
mem_debug_show();\
|
||||
abort();\
|
||||
}
|
||||
|
||||
extern void mem_check_block(void * data);
|
||||
extern void mem_init_dog(void *data);
|
||||
extern void mem_debug_init(size_t size, void *start, void *end, portMUX_TYPE *mutex);
|
||||
extern void mem_malloc_block(void *data);
|
||||
extern void mem_free_block(void *data);
|
||||
extern void mem_check_all(void* pv);
|
||||
|
||||
#else
|
||||
|
||||
#define mem_check_block(...)
|
||||
#define mem_init_dog(...)
|
||||
|
||||
#define BLOCK_HEAD_LEN 0
|
||||
#define BLOCK_TAIL_LEN 0
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -136,29 +136,12 @@ extern "C" {
|
||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
|
||||
#endif
|
||||
|
||||
/* Used by heap_5.c. */
|
||||
typedef struct HeapRegion
|
||||
{
|
||||
uint8_t *pucStartAddress;
|
||||
size_t xSizeInBytes;
|
||||
} HeapRegion_t;
|
||||
|
||||
/*
|
||||
* Used to define multiple heap regions for use by heap_5.c. This function
|
||||
* must be called before any calls to pvPortMalloc() - not creating a task,
|
||||
* queue, semaphore, mutex, software timer, event group, etc. will result in
|
||||
* pvPortMalloc being called.
|
||||
*
|
||||
* pxHeapRegions passes in an array of HeapRegion_t structures - each of which
|
||||
* defines a region of memory that can be used as the heap. The array is
|
||||
* terminated by a HeapRegions_t structure that has a size of 0. The region
|
||||
* with the lowest start address must appear first in the array.
|
||||
*/
|
||||
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions );
|
||||
|
||||
|
||||
/*
|
||||
* Map to the memory management routines required for the port.
|
||||
*
|
||||
* Note that libc standard malloc/free are also available for
|
||||
* non-FreeRTOS-specific code, and behave the same as
|
||||
* pvPortMalloc()/vPortFree().
|
||||
*/
|
||||
void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
|
||||
void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
|
||||
|
Reference in New Issue
Block a user