FreeBSD/sys/boot/arm/at91/libat91/xmodem.c
/*
 * int xmodem_rx(char *)
 *  This global function receives a x-modem transmission consisting of
 * (potentially) several blocks.  Returns the number of bytes received or
 * -1 on error.
 */
int xmodem_rx(char *)
This global function receives a x-modem transmission consisting of
(potentially) several blocks.  Returns the number of bytes received or
-1 on error.
int xmodem_rx ( char * ) This global function receives a x - modem transmission consisting of ( potentially ) several blocks . Returns the number of bytes received or - 1 on error .
int
xmodem_rx(char *dest)
{
	int		starting, ch;
	char		packetNumber, *startAddress = dest;
	packetNumber = 1;
	starting = 1;
	while (1) {
		if (starting)
			putchar('C');
		if (((ch = getc(1)) == -1) || (ch != SOH && ch != EOT))
			continue;
		if (ch == EOT) {
			putchar(ACK);
			return (dest - startAddress);
		}
		starting = 0;
		if (!GetRecord(packetNumber, dest))
			return (-1);
		dest += PACKET_SIZE;
		packetNumber++;
	}
	return (-1);
}
int xmodem_rx ( char * dest ) { int starting , ch ; char packetNumber , * startAddress = dest ; packetNumber = 1 ; starting = 1 ; while ( 1 ) { if ( starting ) putchar ( ' ' ) ; if ( ( ( ch = getc ( 1 ) ) == -1 ) || ( ch != SOH && ch != EOT ) ) continue ; if ( ch == EOT ) { putchar ( ACK ) ; return ( dest - startAddress ) ; } starting = 0 ; if ( ! GetRecord ( packetNumber , dest ) ) return ( -1 ) ; dest += PACKET_SIZE ; packetNumber ++ ; } return ( -1 ) ; }
int xmodem_rx(char *)
  This global function receives a x-modem transmission consisting of
 (potentially) several blocks.
int xmodem_rx ( char * ) This global function receives a x - modem transmission consisting of ( potentially ) several blocks .
// Xmodem packets: SOH PKT# ~PKT# 128-bytes CRC16 // the loop above should return in all cases