DSPRelated.com
Forums

C5509 MEM_alloc returns nothing after MEM_free

Started by amir...@imperial.ac.uk February 23, 2009
Hi all,

I know there are a lot of threads on this problem but I haven't found one that solves my problem. I am using the dsk5509a evaluation board, CCS v3.1 with DSP/BIOS config.

I have some variables that require dynamic allocation. Each is a maximum of 400 Bytes (7 of these = 2.8KB).

I had initially allocated a section of the SARAM for the heap but given that failed I allocated some different sections such that I have the following according to my .cmd file:

MEMORY {
DARAM: origin = 0x200, len = 0xfe00
SARAM: origin = 0x10000, len = 0x2a000
VECT: origin = 0x100, len = 0x100
SARAM0: origin = 0x3a000, len = 0x1f40
SARAM2: origin = 0x3e000, len = 0x1f40
SARAM1: origin = 0x3c000, len = 0x1f40
}

and I have segment IDs for each heap... such as SARAM0's heap is labelled _IDATA0 and is allocated as:

.SARAM0$heap: {
SARAM0$B = .;
_SARAM0_base = .;
SARAM0$L = 0x1f40;
_SARAM0_length = 0x1f40;
. += 0x1f40;
} > SARAM0

In my code I declare my segment and memory allocation in my main function:
extern Int IDATA0;

then later I use MEM_alloc():
h = MEM_alloc(IDATA0,n*sizeof(float),0);

This is done for all 7 variables and then after they are used I free them using MEM_free:

test &= MEM_free(IDATA0,h,n*sizeof(float));

and the Boolean test is there to confirm it is freed. It always returns 1 which I believe means success. When I next allocate my variable h using the same statement, 0x00000000 is returned, for all variables.

I've tried: malloc, moving where the variables are allocated (in the subfunctions and in the main), different heaps in the SARAM and DARAM and different variable sizes.

The only warnings I get are:

"C:/CCStudio_v3.1/c5500/bios/include/std.h", line 140: warning: typedef name has already been declared (with same type)"

because I include the following files in my code:

#include
#include
#include

because I need "mem.h" for MEM_alloc to work, and for some reason "std.h" for "mem.h" to work. If I don't include them it can't seem to use MEM_alloc.

Sorry for the long winded description, but I wanted to be as detailed as possible. Any help would be of very useful as I have no idea where to go from here.

Thanks and all the best,

Amir