Reputation: 75
I'm using an MSP430G2553 microcontroller (500 bytes of SRAM and 16kB of flash). I have 4 ring buffers allocating memory at the initialization of my code (using malloc)
typedef struct
{
unsigned char Head;
unsigned char Tail;
unsigned char Size;
unsigned char *Buffer;
} RingBuffer;
void RB_Init(RingBuffer *RB)
{
RB->Size = 32;
RB->Tail = 0;
RB->Head = 0;
RB->Buffer = (unsigned char*) malloc(RB->Size);
}
Basically I'm calling RB_Init four times to create those ring buffers. When the size (capacity of the ring buffer) is 16 everything is fine and I check all four and they each have a memory address. When I change the size to 32 only 2 get memory addresses, the last two aren't getting memory allocated.
Based on the memory map I get from code composer studio (shown below) it looks like I still have a lot of space (under RAM and FLASH). Why aren't the last two buffer arrays getting addresses when I have the sizes at 32 bytes (Why does it seem I hit my limit at 64 bytes?)
******************************************************************************
MSP430 Linker PC v4.1.5
******************************************************************************
>> Linked Fri Dec 27 22:53:28 2013
OUTPUT FILE NAME: <xxx.out>
ENTRY POINT SYMBOL: "_c_int00" address: 0000c672
MEMORY CONFIGURATION
name origin length used unused attr fill
---------------------- -------- --------- -------- -------- ---- --------
SFR 00000000 00000010 00000000 00000010 RWIX
PERIPHERALS_8BIT 00000010 000000f0 00000000 000000f0 RWIX
PERIPHERALS_16BIT 00000100 00000100 00000000 00000100 RWIX
RAM 00000200 00000200 000000cf 00000131 RWIX
INFOD 00001000 00000040 00000000 00000040 RWIX
INFOC 00001040 00000040 00000000 00000040 RWIX
INFOB 00001080 00000040 00000000 00000040 RWIX
INFOA 000010c0 00000040 00000000 00000040 RWIX
FLASH 0000c000 00003fe0 00000802 000037de RWIX
INT00 0000ffe0 00000002 00000000 00000002 RWIX
INT01 0000ffe2 00000002 00000000 00000002 RWIX
INT02 0000ffe4 00000002 00000002 00000000 RWIX
INT03 0000ffe6 00000002 00000002 00000000 RWIX
INT04 0000ffe8 00000002 00000000 00000002 RWIX
INT05 0000ffea 00000002 00000000 00000002 RWIX
INT06 0000ffec 00000002 00000002 00000000 RWIX
INT07 0000ffee 00000002 00000002 00000000 RWIX
INT08 0000fff0 00000002 00000000 00000002 RWIX
INT09 0000fff2 00000002 00000002 00000000 RWIX
INT10 0000fff4 00000002 00000000 00000002 RWIX
INT11 0000fff6 00000002 00000000 00000002 RWIX
INT12 0000fff8 00000002 00000000 00000002 RWIX
INT13 0000fffa 00000002 00000000 00000002 RWIX
INT14 0000fffc 00000002 00000000 00000002 RWIX
RESET 0000fffe 00000002 00000002 00000000 RWIX
Upvotes: 1
Views: 1738
Reputation: 82390
It's unimportant how much RAM your system has, in your case the configured heap size is too small.
But if you always need 4 ringbuffers with a fixed size, it makes no sense to allocate them via malloc.
You could better define static variables, so you will know at link time if your RAM is enough.
#define RING_BUF_SIZE 32
typedef struct
{
unsigned char Head;
unsigned char Tail;
unsigned char buffer[RING_BUF_SIZE];
} RingBuffer;
static RingBuffer myRingbuffer[4];
void RB_Init(RingBuffer *RB)
{
memset(RB, 0, sizeof(RingBuffer) );
}
It's important to initialize them, as the code composer is not ANSI-C compliant here and the startup code will not zero all variables at startup.
Upvotes: 4