mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-10 08:07:46 -04:00
Made a review
My implementation is now compiling and running. I've made a test with the WIN32-MSVC demo.
This commit is contained in:
parent
0a61cf54e7
commit
e473cf6caa
10 changed files with 66 additions and 85 deletions
|
@ -10,7 +10,7 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include "heap_private.h"
|
||||
#include "block_map.h"
|
||||
#include "parent_group.h"
|
||||
|
||||
|
||||
|
@ -37,6 +37,8 @@ return block_map_parent_group_get_item((block_map_parent_group_t*)group, size);
|
|||
|
||||
size_t block_map_group_get_last_size(block_map_group_t* group)
|
||||
{
|
||||
if(group==NULL)
|
||||
return 0;
|
||||
if(cluster_group_get_level(group)==0)
|
||||
return block_map_item_group_get_last_size((block_map_item_group_t*)group);
|
||||
return ((block_map_parent_group_t*)group)->last_size;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include "heap_internal.h"
|
||||
#include "heap.h"
|
||||
|
||||
|
||||
//=======
|
||||
|
@ -61,7 +61,7 @@ static inline uint16_t cluster_group_get_child_count(cluster_group_t* group)
|
|||
{
|
||||
cluster_group_t get;
|
||||
get.value=group->value;
|
||||
return get.child_count;
|
||||
return (uint16_t)get.child_count;
|
||||
}
|
||||
|
||||
size_t cluster_group_get_item_count(cluster_group_t* group);
|
||||
|
@ -70,21 +70,21 @@ static inline uint16_t cluster_group_get_level(cluster_group_t* group)
|
|||
{
|
||||
cluster_group_t get;
|
||||
get.value=group->value;
|
||||
return get.level;
|
||||
return (uint16_t)get.level;
|
||||
}
|
||||
|
||||
static inline bool cluster_group_is_dirty(cluster_group_t* group)
|
||||
{
|
||||
cluster_group_t get;
|
||||
get.value=group->value;
|
||||
return get.dirty;
|
||||
return (uint16_t)get.dirty;
|
||||
}
|
||||
|
||||
static inline bool cluster_group_is_locked(cluster_group_t* group)
|
||||
{
|
||||
cluster_group_t get;
|
||||
get.value=group->value;
|
||||
return get.locked;
|
||||
return (uint16_t)get.locked;
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,7 +112,7 @@ static inline void cluster_group_set_locked(cluster_group_t* group, bool lock)
|
|||
{
|
||||
cluster_group_t set;
|
||||
set.value=group->value;
|
||||
assert(set.locked!=lock);
|
||||
configASSERT((bool)set.locked!=lock);
|
||||
set.locked=lock;
|
||||
group->value=set.value;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include "heap.h"
|
||||
#include "block_map.h"
|
||||
#include "semphr.h"
|
||||
|
||||
|
||||
|
@ -35,9 +35,6 @@
|
|||
#error Not supported with heap_6
|
||||
#endif
|
||||
|
||||
/* Max value that fits in a size_t type. */
|
||||
#define SIZE_MAX (~(( size_t)0))
|
||||
|
||||
/* Check if multiplying a and b will result in overflow. */
|
||||
#define MULTIPLY_WILL_OVERFLOW(a, b) (((a)>0)&&((b)>(SIZE_MAX/(a))))
|
||||
|
||||
|
@ -114,13 +111,12 @@ heap->used=sizeof(heap_t);
|
|||
heap->size=size;
|
||||
heap->free_block=0;
|
||||
heap->next_heap=0;
|
||||
block_map_init(&heap->map_free);
|
||||
block_map_init((block_map_t*)&heap->map_free);
|
||||
if(prev_heap)
|
||||
prev_heap->next_heap=(size_t)heap;
|
||||
xFreeBlocks++;
|
||||
xFreeBytes+=available;
|
||||
xLargestFreeBlock=max(xLargestFreeBlock, available);
|
||||
xMinimumFreeBytes=xFreeBytesAvailable;
|
||||
xMinimumFreeBytes=xFreeBytes;
|
||||
return heap;
|
||||
}
|
||||
|
||||
|
@ -183,7 +179,7 @@ return heap_block_init(heap, &info);
|
|||
void* heap_alloc_from_map(heap_handle_t heap, size_t size)
|
||||
{
|
||||
heap_block_info_t info;
|
||||
if(!block_map_get_block(heap, &heap->map_free, size, &info))
|
||||
if(!block_map_get_block(heap, (block_map_t*)&heap->map_free, size, &info))
|
||||
return NULL;
|
||||
heap->free-=info.size;
|
||||
heap_reduce_free_bytes(info.size);
|
||||
|
@ -245,7 +241,7 @@ if(info.previous.free)
|
|||
{
|
||||
offset=info.previous.offset;
|
||||
size+=info.previous.size;
|
||||
block_map_remove_block(heap, &heap->map_free, &info.previous);
|
||||
block_map_remove_block(heap, (block_map_t*)&heap->map_free, &info.previous);
|
||||
heap->free-=info.previous.size;
|
||||
xFreeBlocks--;
|
||||
xFreeBytes-=info.previous.size;
|
||||
|
@ -260,7 +256,7 @@ if(!info.next.offset)
|
|||
if(info.next.free)
|
||||
{
|
||||
size+=info.next.size;
|
||||
block_map_remove_block(heap, &heap->map_free, &info.next);
|
||||
block_map_remove_block(heap, (block_map_t*)&heap->map_free, &info.next);
|
||||
heap->free-=info.next.size;
|
||||
xFreeBlocks--;
|
||||
xFreeBytes-=info.next.size;
|
||||
|
@ -272,7 +268,7 @@ info.current.offset=offset;
|
|||
info.current.size=size;
|
||||
info.current.free=true;
|
||||
heap_block_init(heap, &info.current);
|
||||
block_map_add_block(heap, &heap->map_free, &info.current);
|
||||
block_map_add_block(heap, (block_map_t*)&heap->map_free, &info.current);
|
||||
}
|
||||
|
||||
|
||||
|
@ -283,7 +279,7 @@ block_map_add_block(heap, &heap->map_free, &info.current);
|
|||
size_t heap_get_largest_free_block(heap_handle_t heap)
|
||||
{
|
||||
size_t largest=0;
|
||||
largest=block_map_get_last_size(heap->map_free);
|
||||
largest=block_map_get_last_size((block_map_t*)&heap->map_free);
|
||||
largest=max(largest, heap->size-heap->used);
|
||||
return largest;
|
||||
}
|
||||
|
@ -302,7 +298,7 @@ if(MULTIPLY_WILL_OVERFLOW(xNum, xSize)==0)
|
|||
if(buf!=NULL)
|
||||
memset(buf, 0, xNum*xSize);
|
||||
}
|
||||
return pv;
|
||||
return buf;
|
||||
}
|
||||
|
||||
void* pvPortMalloc(size_t xWantedSize)
|
||||
|
@ -328,7 +324,6 @@ void vPortDefineHeapRegions(HeapRegion_t const* pxHeapRegions)PRIVILEGED_FUNCTIO
|
|||
{
|
||||
configASSERT(first_heap==NULL);
|
||||
configASSERT(pxHeapRegions!=NULL);
|
||||
BaseType_t heap_count=0;
|
||||
HeapRegion_t const* region=pxHeapRegions;
|
||||
while(region->xSizeInBytes>0)
|
||||
{
|
||||
|
@ -341,7 +336,9 @@ while(region->xSizeInBytes>0)
|
|||
last_heap=heap;
|
||||
region++;
|
||||
}
|
||||
#if(configUSE_HEAP_IN_ISR==0)
|
||||
heap_mutex=xSemaphoreCreateMutexStatic(&heap_mutex_buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vPortFree(void* pv)
|
||||
|
@ -395,8 +392,10 @@ heap_unlock(locked);
|
|||
|
||||
void vPortHeapResetState(void)
|
||||
{
|
||||
#if(configUSE_HEAP_IN_ISR==0)
|
||||
vSemaphoreDelete(heap_mutex);
|
||||
heap_mutex=NULL;
|
||||
#endif
|
||||
first_heap=NULL;
|
||||
last_heap=NULL;
|
||||
xFreeBlocks=0;
|
||||
|
|
|
@ -17,8 +17,46 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include "block_map.h"
|
||||
#include "offset_index.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
|
||||
//==========
|
||||
// Settings
|
||||
//==========
|
||||
|
||||
#define configUSE_HEAP_IN_ISR 1
|
||||
|
||||
#define CLUSTER_GROUP_SIZE 10
|
||||
|
||||
|
||||
//===========
|
||||
// Alignment
|
||||
//===========
|
||||
|
||||
#define SIZE_BITS (sizeof(size_t)*8)
|
||||
#define SIZE_BYTES sizeof(size_t)
|
||||
|
||||
#define BLOCK_SIZE_MIN (4*SIZE_BYTES)
|
||||
|
||||
static inline size_t align_down(size_t value, size_t align)
|
||||
{
|
||||
return value&~(align-1);
|
||||
}
|
||||
|
||||
static inline size_t align_up(size_t value, size_t align)
|
||||
{
|
||||
return value+(align-value%align)%align;
|
||||
}
|
||||
|
||||
|
||||
//======
|
||||
|
@ -32,7 +70,7 @@ size_t used;
|
|||
size_t size;
|
||||
size_t free_block;
|
||||
size_t next_heap;
|
||||
block_map_t map_free;
|
||||
size_t map_free;
|
||||
}heap_t;
|
||||
|
||||
typedef heap_t* heap_handle_t;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include "heap.h"
|
||||
#include "heap_block.h"
|
||||
|
||||
|
||||
//==================
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include "heap_internal.h"
|
||||
#include "heap.h"
|
||||
|
||||
|
||||
//======
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
//=================
|
||||
// heap_internal.h
|
||||
//=================
|
||||
|
||||
// Copyright 2024, Sven Bieg (svenbieg@web.de)
|
||||
// http://github.com/svenbieg/Heap
|
||||
|
||||
#ifndef _HEAP_INTERNAL_H
|
||||
#define _HEAP_INTERNAL_H
|
||||
|
||||
|
||||
//=======
|
||||
// Using
|
||||
//=======
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
|
||||
//==========
|
||||
// Settings
|
||||
//==========
|
||||
|
||||
#define configUSE_HEAP_IN_ISR 1
|
||||
|
||||
#define CLUSTER_GROUP_SIZE 10
|
||||
|
||||
|
||||
//===========
|
||||
// Alignment
|
||||
//===========
|
||||
|
||||
#define SIZE_BITS (sizeof(size_t)*8)
|
||||
#define SIZE_BYTES sizeof(size_t)
|
||||
|
||||
#define BLOCK_SIZE_MIN (4*SIZE_BYTES)
|
||||
|
||||
static inline size_t align_down(size_t value, size_t align)
|
||||
{
|
||||
return value&~(align-1);
|
||||
}
|
||||
|
||||
static inline size_t align_up(size_t value, size_t align)
|
||||
{
|
||||
return value+(align-value%align)%align;
|
||||
}
|
||||
|
||||
#endif // _HEAP_INTERNAL_H
|
|
@ -11,6 +11,7 @@
|
|||
//=======
|
||||
|
||||
#include "heap.h"
|
||||
#include "offset_index.h"
|
||||
#include "parent_group.h"
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include "heap_private.h"
|
||||
#include "parent_group.h"
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
// Using
|
||||
//=======
|
||||
|
||||
#include <heap.h>
|
||||
#include "cluster_group.h"
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue