salmanliaquat
Full Member level 2
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:
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:
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.
Thanks for reading and advance thanks for helpful replies.
Regards,
Salman.
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];
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.