Start of implementation of the low level TPI programming protocol in the AVRISP project.
[pub/USBasp.git] / Projects / AVRISP / Lib / PDITarget.c
index 29bb339..2c6ffd9 100644 (file)
@@ -67,13 +67,13 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
                  return;\r
                  \r
                /* Wait for the start bit when receiving */\r
-               if ((SoftUSART_BitCount == BITS_IN_FRAME) && (BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK))\r
+               if ((SoftUSART_BitCount == BITS_IN_PDI_FRAME) && (BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK))\r
                  return;\r
        \r
                /* Shift in the bit one less than the frame size in position, so that the start bit will eventually\r
                 * be discarded leaving the data to be byte-aligned for quick access */\r
                if (BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK)\r
-                 SoftUSART_Data |= (1 << (BITS_IN_FRAME - 1));\r
+                 SoftUSART_Data |= (1 << (BITS_IN_PDI_FRAME - 1));\r
 \r
                SoftUSART_Data >>= 1;\r
                SoftUSART_BitCount--;\r
@@ -133,6 +133,7 @@ void PDITarget_EnableTargetPDI(void)
        TCCR1B  = (1 << WGM12) | (1 << CS10);\r
        TIMSK1  = (1 << OCIE1A);\r
        \r
+       /* Send two BREAKs of 12 bits each to enable TPI interface (need at least 16 idle bits) */\r
        PDITarget_SendBreak();\r
        PDITarget_SendBreak();\r
 #endif\r
@@ -158,8 +159,6 @@ void PDITarget_DisableTargetPDI(void)
        /* Tristate DATA and CLOCK lines */\r
        BITBANG_PDIDATA_PORT  &= ~BITBANG_PDIDATA_MASK;\r
        BITBANG_PDICLOCK_PORT &= ~BITBANG_PDICLOCK_MASK;\r
-\r
-       TCCR0B  = 0;\r
 #endif\r
 }\r
 \r
@@ -212,7 +211,7 @@ void PDITarget_SendByte(const uint8_t Byte)
 \r
        /* Data shifted out LSB first, START DATA PARITY STOP STOP */\r
        SoftUSART_Data     = NewUSARTData;\r
-       SoftUSART_BitCount = BITS_IN_FRAME;\r
+       SoftUSART_BitCount = BITS_IN_PDI_FRAME;\r
 #endif\r
 }\r
 \r
@@ -254,7 +253,7 @@ uint8_t PDITarget_ReceiveByte(void)
        }\r
 \r
        /* Wait until a byte has been received before reading */\r
-       SoftUSART_BitCount = BITS_IN_FRAME;\r
+       SoftUSART_BitCount = BITS_IN_PDI_FRAME;\r
        while (SoftUSART_BitCount);\r
        \r
        /* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */\r
@@ -279,7 +278,7 @@ void PDITarget_SendBreak(void)
        }\r
 \r
        /* Need to do nothing for a full frame to send a BREAK */\r
-       for (uint8_t i = 0; i < BITS_IN_FRAME; i++)\r
+       for (uint8_t i = 0; i < BITS_IN_PDI_FRAME; i++)\r
        {\r
                /* Wait for a full cycle of the clock */\r
                while (PIND & (1 << 5));\r
@@ -299,7 +298,7 @@ void PDITarget_SendBreak(void)
 \r
        /* Need to do nothing for a full frame to send a BREAK */\r
        SoftUSART_Data     = 0x0FFF;\r
-       SoftUSART_BitCount = BITS_IN_FRAME;\r
+       SoftUSART_BitCount = BITS_IN_PDI_FRAME;\r
 #endif\r
 }\r
 \r