aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/AVRISP/Lib/PDITarget.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-12-11 04:04:34 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-12-11 04:04:34 +0000
commit66201a05e9d5793880b27519affff7132f6630ea (patch)
tree3e93502cd9169a4c3b66190d0ff9a805c4d46863 /Projects/AVRISP/Lib/PDITarget.c
parent7e5966c1a88bf670c2f4962e8a52fcfc3528e82a (diff)
downloadlufa-66201a05e9d5793880b27519affff7132f6630ea.tar.gz
lufa-66201a05e9d5793880b27519affff7132f6630ea.tar.bz2
lufa-66201a05e9d5793880b27519affff7132f6630ea.zip
Fix PDI code - must send NVM enable key least significant byte first, need to make sure Tx and Rx is switched correctly including disabling the output on the Tx line when receiving.
Diffstat (limited to 'Projects/AVRISP/Lib/PDITarget.c')
-rw-r--r--Projects/AVRISP/Lib/PDITarget.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/Projects/AVRISP/Lib/PDITarget.c b/Projects/AVRISP/Lib/PDITarget.c
index d012a1beb..22a4d019a 100644
--- a/Projects/AVRISP/Lib/PDITarget.c
+++ b/Projects/AVRISP/Lib/PDITarget.c
@@ -38,8 +38,9 @@
#define INCLUDE_FROM_PDITARGET_C
#include "PDITarget.h"
-#if !defined(PDI_VIA_HARDWARE_USART)
volatile bool IsSending;
+
+#if !defined(PDI_VIA_HARDWARE_USART)
volatile uint16_t DataBits;
volatile uint8_t BitCount;
@@ -192,31 +193,60 @@ void PDITarget_DisableTargetPDI(void)
void PDITarget_SendByte(uint8_t Byte)
{
- UCSR1B &= ~(1 << RXEN1);
- UCSR1B |= (1 << TXEN1);
+ /* Switch to Tx mode if currently in Rx mode */
+ if (!(IsSending))
+ {
+ PORTD |= (1 << 3);
+ DDRD |= (1 << 3);
+ UCSR1B &= ~(1 << RXEN1);
+ UCSR1B |= (1 << TXEN1);
+
+ IsSending = true;
+ }
+
+ /* Wait until there is space in the hardware Tx buffer before writing */
+ while (!(UCSR1A & (1 << UDRE1)));
UDR1 = Byte;
-
- while (!(UCSR1A & (1 << TXC1)));
- UCSR1A |= (1 << TXC1);
}
uint8_t PDITarget_ReceiveByte(void)
{
- UCSR1B &= ~(1 << TXEN1);
- UCSR1B |= (1 << RXEN1);
+ /* Switch to Rx mode if currently in Tx mode */
+ if (IsSending)
+ {
+ while (!(UCSR1A & (1 << TXC1)));
+ UCSR1A |= (1 << TXC1);
+ UCSR1B &= ~(1 << TXEN1);
+ UCSR1B |= (1 << RXEN1);
+
+ DDRD &= ~(1 << 3);
+ PORTD &= ~(1 << 3);
+
+ IsSending = false;
+ }
+
+ /* Wait until a byte has been received before reading */
while (!(UCSR1A & (1 << RXC1)));
- UCSR1A |= (1 << RXC1);
-
return UDR1;
}
void PDITarget_SendBreak(void)
{
- UCSR1B &= ~(1 << RXEN1);
- UCSR1B |= (1 << TXEN1);
+ /* Switch to Tx mode if currently in Rx mode */
+ if (!(IsSending))
+ {
+ PORTD |= (1 << 3);
+ DDRD |= (1 << 3);
+
+ UCSR1B &= ~(1 << RXEN1);
+ UCSR1B |= (1 << TXEN1);
+
+ IsSending = true;
+ }
+ /* Need to do nothing for a full frame to send a BREAK */
for (uint8_t i = 0; i <= BITS_IN_FRAME; i++)
{
/* Wait for rising edge of clock */