/*
	UARTECHO.C

	This program demonstrates how to use the XP87xx expansion card
	(previously known as the EXP-232 or UART card) with the aasc...
	drivers.	For details of the non device specific functions, please
	refer to stdecho.c
*/

#use aascuart.lib						//	the device driver

main() {
	char rBuf[0x400];
	char wBuf[0x400];
	auto char localBuf[0x400];
	auto unsigned count;
	auto struct _Channel *chan;
	auto char *pCur;
	auto unsigned remaining;

	_GLOBAL_INIT();	
	chan = aascOpen(DEV_UART,
		0,
		UART_PARAM_8N1+UART_PARAM_1200*16+3,	//	board 3 at 19200bps
		NULL);
	aascSetReadBuf(chan,rBuf,sizeof(rBuf));
	aascSetWriteBuf(chan,wBuf,sizeof(wBuf));
	aascTxSwitch(chan,1);
	aascRxSwitch(chan,1);
	
	while (1) {
		hitwd();
		remaining = aascReadBlk(chan,localBuf,sizeof(localBuf),0);
		pCur = localBuf;
		while (remaining) {
			count = aascWriteBlk(chan, pCur, remaining, 1);
			pCur += count;
			remaining -= count;
			hitwd();
		}
	}
}
