#include "../h/rci.h"
#include "shmemDemo.h"

extern startupFxn();
extern taskFxn();

#if VXWORKS_CFG
#define main shmemDemo_
#endif

main()
{
	RCI_DESC *td1, *td2;
	SMEM *smem1, *smem2;
	char ibuf[BUFSIZE];

	rciSetOptions (EXIT_ON_ERROR);

	td1 = rciCreate ("task1", 0x1);
	rciRate (td1, 1000, 500);
	rciScheduling (td1, ON_CLOCK, 0);
	rciControlFxns (td1, startupFxn, taskFxn, NULLF, 0);
	smem1 = (SMEM*)rciSharedMemory ("SMEM", sizeof(SMEM), td1);
	smem1->lmem = rciLocalMemory ("LMEM", sizeof(LMEM), td1);

	td2 = rciCreate ("task2", 0x3);
	rciRate (td2, 1000, 0);
	rciScheduling (td2, ON_CLOCK, 0);
	rciControlFxns (td2, startupFxn, taskFxn, NULLF, 0);
	smem2 = (SMEM*)rciSharedMemory ("SMEM", sizeof(SMEM), td2);
	smem2->lmem = rciLocalMemory ("LMEM", sizeof(LMEM), td2);

	rciGlobalMemory ("GMEM", sizeof(GMEM), ~0, TASKCPU(td1));

	rciStart(~0);

	while (1)
	 { gets (ibuf);
	   strcpy (smem1->buf, ibuf);
	   smem1->ready = 1;
	   while (!smem2->ready)
	      ;
	   printf ("%s\n", smem2->buf);
	   smem2->ready = 0;
	 }
}
