Document the PDI programming routines implemented so far in the AVRISP project. Add...
[pub/USBasp.git] / Projects / AVRISP / Lib / PDITarget.c
index 57a1a29..d104206 100644 (file)
 #define  INCLUDE_FROM_PDITARGET_C\r
 #include "PDITarget.h"\r
 \r
+/** Writes a given byte to the attached XMEGA device, using a RS232 frame via software through the\r
+ *  PDI interface.\r
+ *\r
+ *  \param Byte  Byte to send to the attached device\r
+ */\r
 void PDITarget_SendByte(uint8_t Byte)\r
 {\r
-       PDIDATA_LINE_PORT  &= ~PDIDATA_LINE_MASK;\r
+       PDIDATA_LINE_PORT &= ~PDIDATA_LINE_MASK;\r
 \r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;       \r
+       TOGGLE_PDI_CLOCK;\r
 \r
        for (uint8_t i = 0; i < 8; i++)\r
        {\r
@@ -54,33 +58,28 @@ void PDITarget_SendByte(uint8_t Byte)
                  \r
                Byte >>= 1;\r
 \r
-               PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-               PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;       \r
+               TOGGLE_PDI_CLOCK;\r
        }\r
 \r
-       PDIDATA_LINE_PORT  |= PDIDATA_LINE_MASK;\r
+       PDIDATA_LINE_PORT |= PDIDATA_LINE_MASK;\r
 \r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+       TOGGLE_PDI_CLOCK;\r
+       TOGGLE_PDI_CLOCK;\r
 }\r
 \r
+/** Reads a given byte from the attached XMEGA device, encoded in a RS232 frame through the PDI interface.\r
+ *\r
+ *  \return Received byte from the attached device\r
+ */\r
 uint8_t PDITarget_ReceiveByte(void)\r
 {\r
        uint8_t ReceivedByte = 0;\r
 \r
-       PDIDATA_LINE_DDR   &= ~PDIDATA_LINE_MASK;\r
+       PDIDATA_LINE_DDR &= ~PDIDATA_LINE_MASK;\r
 \r
-       bool FoundStartBit;\r
-\r
-       do\r
-       {\r
-               PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-               PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-               FoundStartBit = !(PDIDATA_LINE_PIN & PDIDATA_LINE_MASK);\r
-       } while (!FoundStartBit);\r
-       \r
+       while (PDIDATA_LINE_PIN & PDIDATA_LINE_MASK);\r
+         TOGGLE_PDI_CLOCK;\r
+         \r
        for (uint8_t i = 0; i < 8; i++)\r
        {\r
                if (PDIDATA_LINE_PIN & PDIDATA_LINE_MASK)\r
@@ -88,16 +87,13 @@ uint8_t PDITarget_ReceiveByte(void)
 \r
                ReceivedByte <<= 1;\r
 \r
-               PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-               PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;       \r
+               TOGGLE_PDI_CLOCK;       \r
        }\r
 \r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
-       PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+       TOGGLE_PDI_CLOCK;\r
+       TOGGLE_PDI_CLOCK;\r
        \r
-       PDIDATA_LINE_DDR   |= PDIDATA_LINE_MASK;\r
+       PDIDATA_LINE_DDR |= PDIDATA_LINE_MASK;\r
        \r
        return ReceivedByte;\r
 }\r