libnds 1.3.5 / 1.3.8 FIFO problem

Post Reply
Copper
Posts: 7
Joined: Sun Dec 28, 2008 9:34 pm

libnds 1.3.5 / 1.3.8 FIFO problem

Post by Copper » Sun Sep 20, 2009 9:14 pm

Hi,

I have a little problem with the FIFO based arm9->arm7 communication in the last libnds...

Actually in my 'work in progress' emulator, after a while (some minutes), X / Y keys and stylus are not working anymore...

In my code I use only arm9 -> arm7 communication for sound, and when the problem occurs sound is still working... => FIFO ARM9 => ARM7 works

I've added a debug test arm7 -> arm9 communication => FIFO ARM7 => ARM9 stops after a while

Some informations about my homebrew :

- ARM7 and ARM9 are both compiled -marm & -O3 switchs
- problem does not occur when compiled with libnds 1.3.1 / 1.3.3 (but my HBL interrupt handler is not stable with those versions on DS)
- problem occurs both on hard & no$gba emulator
- FIFO doesn't work at all with libnds 1.3.4 (in my homebrew)
- I've added some visual debug informations and recompiled the lib :

/*static*/ void fifoInternalRecvInterrupt() {
REG_IE &= ~IRQ_FIFO_NOT_EMPTY;
REG_IME=1;

u32 data, block=FIFO_BUFFER_TERMINATE;

while( !(REG_IPC_FIFO_CR & IPC_FIFO_RECV_EMPTY) ) {
data = REG_IPC_FIFO_RX;

REG_IME=0;
block=fifo_allocBlock();
if (block != FIFO_BUFFER_TERMINATE ) {
FIFO_BUFFER_DATA(block)=data;
fifo_queueBlock(&fifo_receive_queue,block,block);
}
else {
#ifdef ARM9
#define BG_PALETTE ((u16*)0x05000000)/** \brief background palette memory*/
BG_PALETTE[0] = BG_PALETTE[0] + 1;
#endif

}
REG_IME=1;
}


- When the problem occurs screen is flashing so it's seems fifo_allocBlock() in fifoInternalRecvInterrupt() return FIFO_BUFFER_TERMINATE...

Edit: Tested with FIFO_BUFFER_ENTRIES 1024 on ARM9 part... Problem still occurs... But later

Copper
Posts: 7
Joined: Sun Dec 28, 2008 9:34 pm

Re: libnds 1.3.5 / 1.3.8 FIFO problem

Post by Copper » Sun Sep 27, 2009 7:29 pm

I think I found the bug (memory leak) :

The bug is in fifoInternalSend :

Current code in libnds 1.3.8 :

Code: Select all

	if (!firstwordsent) {
		u32 head = fifo_allocBlock();
		FIFO_BUFFER_DATA(head)=firstword;
		fifo_send_queue.head = fifo_send_queue.tail = head;
	}
If first word not sent and fifo_send_queue.head != FIFO_BUFFER_TERMINATE the elements in queue are lost and a memory leak occurs...

here a possible correction :

Code: Select all

	if (!firstwordsent) {
		u32 head = fifo_allocBlock();
		if(fifo_send_queue.head == FIFO_BUFFER_TERMINATE) {
			fifo_send_queue.head = head;
		} else {
			FIFO_BUFFER_SETNEXT(fifo_send_queue.tail,head);		
		}
		FIFO_BUFFER_DATA(head)=firstword;
		fifo_send_queue.tail = head;
	}
I hope it will be integrated in next version :mrgreen:

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest