#include "../h/rci.h"
#include "memDemo.h"

taskFxn(td, arg)
RCI_DESC *td;
int arg;
{
	
	KEYBUF *keybuf;
	char *buf1;
	char *buf2;
	char *buf3;
	char tempbuf[BUFSIZE];

	keybuf = (KEYBUF*)getMemByName("KEYBUF");

	if (strcmp(rciTaskName(td), "task1") == 0)
	 {
	   buf1 = (char*)getMemByAddr(keybuf->bufaddr1);
	   buf2 = (char*)getMemByAddr(keybuf->bufaddr2);

	   if (keybuf->ready1)
	    { readMem (buf1, tempbuf);
	      writeMem (buf2, tempbuf);
	      keybuf->ready2 = 1;
	      keybuf->ready1 = 0;
	    }
	 }
	else
	 {
	   buf2 = (char*)getMemByAddr(keybuf->bufaddr2);
	   buf3 = (char*)getMemByAddr(keybuf->bufaddr3);

	   if (keybuf->ready2)
	    { readMem (buf2, tempbuf);
	      writeMem (buf3, tempbuf);
	      keybuf->ready3 = 2;
	      keybuf->ready2 = 0;
	    }
	 }
}
