/*
	XM_SEND.C

	XModem-CRC file transfer example using the SCC chip.

	One block of 128 characters is transferred from the SCC channel A to
	a remote device that supports XModem-CRC. Configure the remote device
	for 9600 bps at 8N1 without RTS/CTS flow control.

	Note that any port may be used by this program by changing from SCC
	channel A to the desired port. To use port z1, change aascscc.lib to
	aascz1.lib and then change the parameters in aascOpen() to reflect
	those used for the z1 port.
*/

#use vdriver.lib
#use aasc.lib
#use aascscc.lib

#define BUFSIZE 1024	// Circular buffer size
#define BAUDMULT 8	// x 1200 bits per second ( eg: 8 x 1200 = 9600 baud )

struct _Channel *aascChannel;
char circBufIn[BUFSIZE],circBufOut[BUFSIZE],aascBuffer[BUFSIZE];

int aascInit(void);

void main(void)
{
	// Initialize the aasc framework.
	
	if( !aascInit() ) exit(-1);

	strcpy( aascBuffer, "This is some xmodem data to transfer...");	
	// Process the data transfer.
	
	while(1) {

		hitwd();

		printf("Press any key to initiate Xmodem controller-to-PC transfer.\r");
		hitwd();

		if( kbhit() ) {

			printf("\nXmodem transfer initiated...\n\n");
			hitwd();

			// Setup XModem transfer to logical memory.

			aascXMWrInitLog( (unsigned) aascBuffer, 128);

			aascWriteXModem( aascChannel, 0, 1, aascWrCallBackLg );
		
			while( !aascWriteXModem( aascChannel, 0, 0, aascWrCallBackLg ) ) hitwd();

			printf("\nXmodem transfer finished...\n\n");
			hitwd();
		}
	}
}

int aascInit(void)
{
	// Initialize the virtual driver

	VdInit();
	
	// Open channel A of the SCC at 8N1
	
	aascChannel = aascOpen( DEV_SCC, 0,
                 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, circBufIn, sizeof( circBufIn));
	aascSetWriteBuf( aascChannel, circBufOut, sizeof( circBufOut));
}