Hi, I'm using P89LPC932 chip and I have the following question: how can I access to on-chip ram? I've check the checkbox "Use on-chip ram" of menu: Options for Target --> Target in uvision3 IDE and I've written the following code
#include <stdlib.h> #include <absacc.h> char *BuffTX; char Var = 0x00; main { //Reserve memory init_mempool (&XBYTE [0x0], 0x200); BuffTX = calloc (10, sizeof (char)); if (BuffTX == NULL) { //Allocating failed ... } else { *BuffTX = 0x01; Var = *BuffTX; }
"I've check the checkbox 'Use on-chip ram'" All that does is to provide information to the tools - it does nothing to enable XRAM on the actual hardware. If the chip requires XRAM to be enabled (check the datasheet) you need to write the code to do it.
init_mempool (&XBYTE [0x0], 0x200);
Hi Andrew, what do you suggest to me if I have to use dynamic memory allocation? I must "size" on the fly some arrays: if you have any better method I'm glad to know about it Thank you
What exactly are you trying to do? Why do you feel the need for dynamic sizing?
well, I've to send an array on the serial port but the matter is that this array has different size in response of the different message send Any suggestion to code this behaviour?
what is the problem, allocate the max size. Erik
"I've to send an array on the serial port but the matter is that this array has different size in response of the different message send" As Erik says, just make the array big enough for the largest message. This is perfectly standard practice. You're always going to have to have space for the biggest possible message, so you lose nothing by this! Conversely, using dynamic allocation you suffer overheads in memory usage, code size and execution speed.
Hi, the question is that maximum size is 256 and I have two buffers of this size, so there is not room for any other variables...
"maximum size is 256 and I have two buffers of this size" So how would dynamic allocation help you?? It cannot magically create memory from nowhere! Why do you have two buffers? Can you actually have two messages buffered at the same time? If you can have two messages buffered at the same time, can you be absolutely 101% totally sure that they cannot possibly both be maximum-length messages?
the question is that maximum size is 256 Say what? from the datasheet: "256-byte RAM data memory, 512-byte auxiliary on-chip RAM." when I went to school, that added up to 768 Erik