tags:

views:

170

answers:

3

I am writing a C program for a 8051 architecture chip and the SDCC compiler.

I have a structure called FilterStructure;

my code looks like this...

#define NAME_SIZE 8

typedef struct {
char Name[NAME_SIZE];
} FilterStructure;

void ReadFilterName(U8 WheelID, U8 Filter, FilterStructure* NameStructure);

int main (void)
{
    FilterStructure testStruct;
    ReadFilterName('A', 3, &testFilter);     
    ...
    ...
    return 0;
}

void ReadFilterName(U8 WheelID, U8 Filter, FilterStructure* NameStructure)
{    
    int StartOfName = 0;
    int i = 0;
    ///... do some stuff...
    for(i = 0; i < 8; i++)
    {
        NameStructure->Name[i] = FLASH_ByteRead(StartOfName + i);
    }
    return;
}

For some reason I get a link error "?ASlink-Error-Could not get 29 consecutive bytes in internal RAM for area DSEG"

If I comment out the line that says FilterStructure testStruct; the error goes away.

What does this error mean? Do I need to discard the structure when I am done with it?

+1  A: 

you've run out of memory....by the looks of it.

try moving it out as a global variable, see if that makes it better.

Keith Nicholas
+1  A: 

The message means that your local variable testStruct couldn't be allocated in RAM (or DSEG that should be DATA SEGMENT of your binary), since your memory manager couldn't find 29 consecutive bytes to allocate it.

This is strange since your struct should be 8 bytes long.. but btw it's nothing to do with discarding the structure, this seems a memory management problem.. I don't know 8051 specs so well but it should be quite limited right?

EDIT: looking at 8051 specs it seems it just has 128 bytes of RAM. This can cause the problem because the variable, declared as a local, is allocated in internal RAM while you should try to allocate it on an external RAM chip if it's possible (using the address/data bus of the chip), but I'm not sure since this kind of microcontroller shouldn't be used to do these things.

Jack
i changed the declaration of my struct to xdata FilterStructure testStruct; and it seems to have fixed the problem.
Jordan S
+1  A: 

Just a guess: 8051 has only 128 or 256 bytes of "internal RAM". Not so much... It can use part of it as stack and part for registers. Maybe your "large" (8 bytes!!!) structure on the stack forces the compiler to reserve too much stack space inside the internal memory. I suggest to have a look into the linker map file, maybe you can "rearrange" the memory partition. The massage says "consecutive bytes", so perhaps there is still enough space availabe, but it's fragmented.

Bye

Giuseppe Guerrini