Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] LPC2138 : problem having large buffers in ram

Status
Not open for further replies.

salmanliaquat

Full Member level 2
Joined
Feb 21, 2011
Messages
128
Helped
38
Reputation
76
Reaction score
38
Trophy points
1,318
Location
Pakistan
Activity points
1,908
MCU = LPC2138 (32-bit by nxp)
IDE = Keil uVision4 (MDK-arm 4.21)

Hi All,
After so much effort to try to find out and debug the problem, i finally decided to post here on the forum all my observations related to the issue.
Here's an overview of code:

Code:
struct queue{
   char *buffer;
   int wp;
   in rp;
 };
char j =0 ;
char buffer1[6000];
char buffer2[1000];
char buffer3[600];
char uartBuffer[100];
struct queue myQueues;

void initQueue(char* bufferQueue, int size) {
    myQueue.buffer = bufferQueue;
    myQueue.wp = 0;
    myQueue.rp = 0;
}

void enqueue(char *data) {
  unsigned int i = 0;
  q = &myQueues;
  while(data[i] != '\0') {
        q->buffer[q->wp++] = data[i++];
        if (q->wp >= q->size)
                q->wp = 0;
        }
        q->buffer[q->wp++] = 0;
        if (q->wp >= q->size)
                q->wp = 0;
}

int main () {
  char str[50];
  UART0_init(9600);
  UART0_interrupt_init();
  initQueue(buffer3, 600);

  while(1) {
     sprintf(str, "wp: %d    rp: %d", myQueues.wp, myQueues.rp);
     UART0_sendstring(str);
  }
}

void UART0Isr() {
     uartBuffer[j++] = UART0_getbyte(); // get data until sequence completed 
       
     if(/*sequence complete condition*/) {
            uartBuffer[j] = '\0';                //NULL appended
            j = 0;
            enqueue(uartBuffer);
     }
}

Now, the problem is that the controller hangs after "enqueuing" 8 sequences(all sequences are same). and the number 8 decreases if i increase the size of sequence.

if i reduce the buffer3 size to 500 or less, code works perfectly fine.
for buffer3 size > 500 ----> code hangs

if i interchange the declaration sequence of global variables like:
Code:
char buffer3[600];
char buffer1[6000];
char buffer2[1000];
declaring buffer3 first and then other large buffers. it gets ok. Atleast for 1000 sequences.

Also changing size of other large buffers make some impact on the total number of sequences it will enqueue before it hangs.

if i disable all interrupts and use enqueue in main in a while loop, its runs fine.
Code:
void main() {
char sequence = "ABCDEFGHIJK";
while(1) {
  enqueue(sequence);    //keep enqueuing again and again
}
}

Thanks for reading and advance thanks for helpful replies.

Regards,
Salman.
 

Hai.. It is just a suggestion. Why don't you allocate the memory dynamically instead of using array?
 

Hai.. It is just a suggestion. Why don't you allocate the memory dynamically instead of using array?

well dynamic memory allocation requires real time library to be included and i am not using it. Its not that much of a requirement since i have much space available
in ram. But i will certainly turn to it when i will be writing more memory efficient codes.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top