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

extern taskFxn();

#if VXWORKS_CFG
#define main memDemo_
#endif

main()
{
	RCI_DESC *td1, *td2;
	KEYBUF *keybuf;
	char ibuf[BUFSIZE];

	rciSetOptions (EXIT_ON_ERROR);

	td1 = rciCreate ("task1", 0x1);
	rciRate (td1, 1000, 500);
	rciScheduling (td1, ON_CLOCK, 0);
	rciControlFxns (td1, NULLF, taskFxn, NULLF, 0);

	td2 = rciCreate ("task2", 0x3);
	rciRate (td2, 1000, 0);
	rciScheduling (td2, ON_CLOCK, 0);
	rciControlFxns (td2, NULLF, taskFxn, NULLF, 0);

	keybuf = (KEYBUF*)allocMem("KEYBUF", sizeof(KEYBUF), 0);
	keybuf->bufaddr1 = allocMem(NULL, BUFSIZE, TASKCPU(td1));
	keybuf->bufaddr2 = allocMem(NULL, BUFSIZE, TASKCPU(td1));
	keybuf->bufaddr3 = allocMem(NULL, BUFSIZE, TASKCPU(td2));

	rciStart(~0);

	while (1)
	 { gets (ibuf);
	   writeMem (keybuf->bufaddr1, ibuf);
	   keybuf->ready1 = 1;
	   while (!keybuf->ready3)
	      ;
	   readMem (keybuf->bufaddr3, ibuf);
	   printf ("%s\n", ibuf);
	   keybuf->ready3 = 0;
	 }
}
