/**********************************************************
	simple3wire.c
   Z-World, 2003

	This program is used with RCM3700 series controllers
	with prototyping boards.

	Description
	===========
	This program demonstrates basic initialization for a
	simple RS232 3-wire loopback displayed in STDIO window.

	Normally we would connect to another controller,

		Tx  <---> Rx
		Rx  <---> Tx
		Gnd <---> Gnd

	However, for this simple demonstration, make the
	following connections:

	Proto-board Connections
	=======================

		TxD <---> RxC
		RxD <---> TxC

	Instructions
	============
	1.  Compile and run this program.
	2.  Lower case characters are sent by TxC. RxD receives
	    the character.  TxD sends the converted uppercase
	    character to RxC and displays in STDIO.

**********************************************************/
#class auto

///////
// change serial buffer name and size here
// for example:  CINBUFSIZE to EINBUFSIZE
///////
#define CINBUFSIZE  15
#define COUTBUFSIZE 15

#define DINBUFSIZE  15
#define DOUTBUFSIZE 15

///////
// change serial baud rate here
///////
#ifndef _232BAUD
#define _232BAUD 115200
#endif


main()
{
	auto int nIn1, nIn2;
	auto char cOut;

	brdInit();				//initialize board for this demo

   BitWrPortI(PEDR, &PEDRShadow, 0, 5);	//set low to enable rs232 device

	serCopen(_232BAUD);
	serDopen(_232BAUD);
	serCwrFlush();
	serCrdFlush();
	serDwrFlush();
	serDrdFlush();

	while (1)
	{
		for (cOut='a';cOut<='z';++cOut)
		{
			serCputc (cOut);								//	Send lowercase byte
			while ((nIn1=serDgetc()) == -1);			// Wait for echo
			serDputc (toupper(nIn1));					//	Send the converted upper case byte
			while ((nIn2=serCgetc()) == -1);			// Wait for echo
			printf ("Serial C sent %c, serial D sent %c, serial C received %c\n",
						cOut, toupper(nIn1), nIn2);
		}
	}
}

