/*
	SCCECHO.C

	Example program for using the aascscc.lib library.

	This program simply echoes text typed at an ascii terminal back to the
	terminal.

	Connect a controller that has an SCC through SCC port A to a PC or dumb
	terminal. If using a PC, MS-Windows "terminal.exe" can be used in "ANSI
	Terminal Emulation" with "Local Echo" disabled and "Flow Control" set to
	"None". If RTS/CTS handshaking is enabled by setting the macro SHAKE to
	non-zero, enable "Flow Control" within terminal.exe to "Hardware".

	This example program defaults to settings of "No Parity", "One Stop Bit" and
	"Eight Data Bits". Set your terminal accordingly.
	
	See further notes in the library file aascscc.lib.
*/

#use aasc.lib
#use aascscc.lib

#define BUFSIZE 684	// Circular buffer size
#define BAUDMULT 8	// x 1200 bits per second ( eg: 8 x 1200 = 9600 baud )
#define SHAKE 0		// Set to 1 for RTS/CTS handshaking

char readBuffer[BUFSIZE],writeBuffer[BUFSIZE],workBuffer[BUFSIZE],*pworkBuffer;
struct _Channel *aascChannel;

main()
{
	_GLOBAL_INIT(); // This must be the first action performed in main().

	// Open channel A of the SCC at 8N1
	
	aascChannel = aascOpen( DEV_SCC, SHAKE,
                 SCC_A | SCC_1STOP | SCC_NOPARITY | SCC_8DATA | SCC_1200*BAUDMULT,
                 NULL);

	if(aascChannel==NULL) {
		printf("SCC channel A not available.");
		return;
	}
	
   // Setup the circular buffers.
   
	aascSetReadBuf( aascChannel, readBuffer, sizeof( readBuffer));
	aascSetWriteBuf( aascChannel, writeBuffer, sizeof( writeBuffer));

	// Process the data transfer.
	
	while(1) {

		hitwd();

		// Perform data transfer.
		
		if( aascReadChar( aascChannel, workBuffer) ) {
			while( !aascWriteChar( aascChannel, workBuffer[0]) ) {
				hitwd();
			}
		}
	}
}