/*
LUFA Library
Copyright (C) Dean Camera, 2010.
-
+
dean [at] fourwalledcubicle [dot] com
- www.fourwalledcubicle.com
+ www.lufa-lib.org
*/
/*
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
- Permission to use, copy, modify, distribute, and sell this
+ Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
+ without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
/* Set Tx and XCK as outputs, Rx as input */
DDRD |= (1 << 5) | (1 << 3);
DDRD &= ~(1 << 2);
-
+
/* Set DATA line high for at least 90ns to disable /RESET functionality */
PORTD |= (1 << 3);
_delay_us(1);
-
+
/* Set up the synchronous USART for XMEGA communications - 8 data bits, even parity, 2 stop bits */
UBRR1 = (F_CPU / XPROG_HARDWARE_SPEED);
UCSR1B = (1 << TXEN1);
/* Set Tx and XCK as outputs, Rx as input */
DDRD |= (1 << 5) | (1 << 3);
DDRD &= ~(1 << 2);
-
+
/* Set up the synchronous USART for TINY communications - 8 data bits, even parity, 2 stop bits */
UBRR1 = (F_CPU / XPROG_HARDWARE_SPEED);
UCSR1B = (1 << TXEN1);
/* Switch to Tx mode if currently in Rx mode */
if (!(IsSending))
XPROGTarget_SetTxMode();
-
+
/* Wait until there is space in the hardware Tx buffer before writing */
while (!(UCSR1A & (1 << UDRE1)));
UCSR1A |= (1 << TXC1);
UDR1 = Byte;
-
- if (TimeoutMSRemaining)
- TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
}
/** Receives a byte via the software USART, blocking until data is received.
XPROGTarget_SetRxMode();
/* Wait until a byte has been received before reading */
- while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining);
-
- if (TimeoutMSRemaining)
- TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
+ while (!(UCSR1A & (1 << RXC1)) && TimeoutTicksRemaining);
return UDR1;
}
while (PIND & (1 << 5));
while (!(PIND & (1 << 5)));
}
-
- if (TimeoutMSRemaining)
- TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
}
static void XPROGTarget_SetTxMode(void)
UCSR1B &= ~(1 << RXEN1);
UCSR1B |= (1 << TXEN1);
-
- IsSending = true;
-
- if (TimeoutMSRemaining)
- TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
IsSending = true;
}
DDRD &= ~(1 << 3);
PORTD &= ~(1 << 3);
- if (TimeoutMSRemaining)
- TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
-
IsSending = false;
}
#endif
+