My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions
sw_buddy.c File Reference
#include <sw_types.h>
#include <sw_debug.h>
#include <sw_list.h>
#include <sw_buddy.h>
#include <sw_mem_functions.h>

Classes

struct  taskid_hindex
 

Macros

#define NULL   ((void *)0)
 
#define _DEBUG   0
 
#define OTZ_DPRINTK(...)
 
#define IS_POW_TWO(x)   (x && !(x & (x - 1)))
 
#define get_current_task_id()   0
 Returnd the ID of the current task. More...
 

Functions

int buddy_init (int index, void *heap_start, unsigned int heap_size)
 Buddy allocator initialization. More...
 
void * sw_buddy_malloc (int index, unsigned int size)
 allocates memory at the requested heap index for size bytes More...
 
void * buddy_zalloc (unsigned int size)
 Allocates memory at the requested heap index for size bytes and initalizes it to zero. More...
 
void buddy_free (int index, void *ptr)
 Frees the allocated memory block at the given heap index and address ptr. More...
 
void sw_buddy_print_state (void)
 Prints the state of the heap allocations Whether heap is found for this task Heap size, no. of free and allocated blocks. More...
 
void buddy_print_hk_state (int index)
 Prints the status of house keeping region of heap memory No. of free and allocated nodes in the heap. More...
 
void * sw_malloc_private (int heap_id, u32 size)
 Allocates memory privately for size bytes at the memory related to heap_id passed. More...
 
void * sw_malloc (u32 size)
 Gets the task id and allocates memory in the heap memory corresponding to the task. More...
 
void sw_free_private (int heap_id, void *pointer)
 Frees the privately allocated memory pointing to the heap_id and the address pointer. More...
 
void sw_free (void *pointer)
 Gets the task_id and frees the heap memory corresponding to the task_id. More...
 
int sw_heap_init (int index, void *heap_start, unsigned int heap_size)
 Heap memory initialization. More...
 
int alloc_private_heap (int heap_id)
 Allocates heap memory initially during task creation for a particular heap_id Checks for already allocated heap matching the heap_id, If no memory was allocated earlier, memory is allocated for the passed heap_id. More...
 
int free_private_heap (int heap_id)
 Frees the private heap already allocated corresponding to the heap_id. More...
 
u32 get_ptr_size (void *ptr)
 Gets the pointer size of the allocated block of memory. More...
 

Macro Definition Documentation

#define _DEBUG   0
int get_current_task_id ( )    0

Returnd the ID of the current task.

Returns
Returns the current task ID
#define IS_POW_TWO (   x)    (x && !(x & (x - 1)))
#define NULL   ((void *)0)
#define OTZ_DPRINTK (   ...)

Function Documentation

int alloc_private_heap ( int  heap_id)

Allocates heap memory initially during task creation for a particular heap_id Checks for already allocated heap matching the heap_id, If no memory was allocated earlier, memory is allocated for the passed heap_id.

Parameters
heap_id
Returns
void buddy_free ( int  index,
void *  ptr 
)

Frees the allocated memory block at the given heap index and address ptr.

Parameters
index
ptr
int buddy_init ( int  index,
void *  heap_start,
unsigned int  heap_size 
)

Buddy allocator initialization.

Parameters
index
heap_start
heap_size
Returns
void buddy_print_hk_state ( int  index)

Prints the status of house keeping region of heap memory No. of free and allocated nodes in the heap.

void* buddy_zalloc ( unsigned int  size)

Allocates memory at the requested heap index for size bytes and initalizes it to zero.

Parameters
size
Returns
int free_private_heap ( int  heap_id)

Frees the private heap already allocated corresponding to the heap_id.

Parameters
heap_id
Returns
u32 get_ptr_size ( void *  ptr)

Gets the pointer size of the allocated block of memory.

function to get the size of a pointer. This is needed during realloc

Parameters
ptr
Returns
void* sw_buddy_malloc ( int  index,
unsigned int  size 
)

allocates memory at the requested heap index for size bytes

Parameters
index
size
Returns
void sw_buddy_print_state ( void  )

Prints the state of the heap allocations Whether heap is found for this task Heap size, no. of free and allocated blocks.

void sw_free ( void *  pointer)

Gets the task_id and frees the heap memory corresponding to the task_id.

Parameters
pointer
void sw_free_private ( int  heap_id,
void *  pointer 
)

Frees the privately allocated memory pointing to the heap_id and the address pointer.

Parameters
heap_id
pointer
int sw_heap_init ( int  index,
void *  heap_start,
unsigned int  heap_size 
)

Heap memory initialization.

Parameters
index
heap_start
heap_size
Returns
void* sw_malloc ( u32  size)

Gets the task id and allocates memory in the heap memory corresponding to the task.

Parameters
size
Returns
void* sw_malloc_private ( int  heap_id,
u32  size 
)

Allocates memory privately for size bytes at the memory related to heap_id passed.

Parameters
heap_id
size
Returns