More speed and quality improvements to the software USART in the AVRISP project.
authorDean Camera <dean@fourwalledcubicle.com>
Wed, 16 Dec 2009 09:13:42 +0000 (09:13 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Wed, 16 Dec 2009 09:13:42 +0000 (09:13 +0000)
Projects/AVRISP/Lib/NVMTarget.c
Projects/AVRISP/Lib/NVMTarget.h
Projects/AVRISP/Lib/PDITarget.c
Projects/AVRISP/Lib/PDITarget.h
Projects/AVRISP/makefile

index 10a911f..c4de1d2 100644 (file)
@@ -48,23 +48,7 @@ void NVMTarget_SendNVMRegAddress(uint8_t Register)
        uint32_t Address = XPROG_Param_NVMBase | Register;\r
 \r
        /* Send the calculated 32-bit address to the target, LSB first */\r
-       PDITarget_SendByte(Address &  0xFF);\r
-       PDITarget_SendByte(Address >> 8);\r
-       PDITarget_SendByte(Address >> 16);\r
-       PDITarget_SendByte(Address >> 24);\r
-}\r
-\r
-/** Sends the given 32-bit absolute address to the target.\r
- *\r
- *  \param[in] AbsoluteAddress  Absolute address to send to the target\r
- */\r
-void NVMTarget_SendAddress(uint32_t AbsoluteAddress)\r
-{\r
-       /* Send the given 32-bit address to the target, LSB first */\r
-       PDITarget_SendByte(AbsoluteAddress &  0xFF);\r
-       PDITarget_SendByte(AbsoluteAddress >> 8);\r
-       PDITarget_SendByte(AbsoluteAddress >> 16);\r
-       PDITarget_SendByte(AbsoluteAddress >> 24);\r
+       NVMTarget_SendAddress(Address);\r
 }\r
 \r
 /** Waits while the target's NVM controller is busy performing an operation, exiting if the\r
index e9acd43..803ec3c 100644 (file)
                #define NVM_CMD_ERASEWRITEEEPROMPAGE   0x35\r
                #define NVM_CMD_READEEPROM             0x06\r
 \r
+       /* Inline Functions: */\r
+               /** Sends the given 32-bit absolute address to the target.\r
+                *\r
+                *  \param[in] AbsoluteAddress  Absolute address to send to the target\r
+                */\r
+               static inline void NVMTarget_SendAddress(uint32_t AbsoluteAddress)\r
+               {\r
+                       /* Send the given 32-bit address to the target, LSB first */\r
+                       PDITarget_SendByte(AbsoluteAddress &  0xFF);\r
+                       PDITarget_SendByte(AbsoluteAddress >> 8);\r
+                       PDITarget_SendByte(AbsoluteAddress >> 16);\r
+                       PDITarget_SendByte(AbsoluteAddress >> 24);\r
+               }\r
+\r
        /* Function Prototypes: */\r
                void NVMTarget_SendNVMRegAddress(uint8_t Register);\r
                void NVMTarget_SendAddress(uint32_t AbsoluteAddress);\r
index e21942a..afcf8b8 100644 (file)
@@ -196,19 +196,18 @@ void PDITarget_SendByte(uint8_t Byte)
                IsSending = true;\r
        }\r
 \r
-       bool    EvenParityBit = false;\r
-       uint8_t ParityData    = Byte;\r
+       /* Calculate the new USART frame data here while while we wait for a previous byte (if any) to finish sending */\r
+       uint16_t NewUSARTData = ((1 << 11) | (1 << 10) | (0 << 9) | ((uint16_t)Byte << 1) | (0 << 0));\r
 \r
        /* Compute Even parity - while a bit is still set, chop off lowest bit and toggle parity bit */\r
+       uint8_t ParityData    = Byte;\r
        while (ParityData)\r
        {\r
-               EvenParityBit ^= true;\r
-               ParityData    &= (ParityData - 1);\r
+               NewUSARTData ^= (1 << 9);\r
+               ParityData   &= (ParityData - 1);\r
        }\r
 \r
-       /* Calculate the new USART frame data here while while we wait for a previous byte (if any) to finish sending */\r
-       uint16_t NewUSARTData = ((1 << 11) | (1 << 10) | ((uint16_t)EvenParityBit << 9) | ((uint16_t)Byte << 1) | (0 << 0));\r
-\r
+       /* Wait until transmitter is idle before writing new data */\r
        while (SoftUSART_BitCount);\r
 \r
        /* Data shifted out LSB first, START DATA PARITY STOP STOP */\r
@@ -258,7 +257,7 @@ uint8_t PDITarget_ReceiveByte(void)
        SoftUSART_BitCount = BITS_IN_FRAME;\r
        while (SoftUSART_BitCount);\r
        \r
-       /* Throw away the start, parity and stop bits to leave only the data */\r
+       /* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */\r
        return (uint8_t)SoftUSART_Data;\r
 #endif\r
 }\r
@@ -280,7 +279,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_FRAME; i++)\r
        {\r
                /* Wait for a full cycle of the clock */\r
                while (PIND & (1 << 5));\r
index 2a704b3..03083fc 100644 (file)
 \r
        /* Defines: */\r
                #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))\r
-//                     #define PDI_VIA_HARDWARE_USART\r
-\r
-                       #define BITBANG_PDIDATA_PORT     PORTD\r
-                       #define BITBANG_PDIDATA_DDR      DDRD\r
-                       #define BITBANG_PDIDATA_PIN      PIND\r
-                       #define BITBANG_PDIDATA_MASK     (1 << 3)\r
-                       \r
-                       #define BITBANG_PDICLOCK_PORT    PORTD\r
-                       #define BITBANG_PDICLOCK_DDR     DDRD\r
-                       #define BITBANG_PDICLOCK_PIN     PIND\r
-                       #define BITBANG_PDICLOCK_MASK    (1 << 5)\r
+                       #define PDI_VIA_HARDWARE_USART\r
                #else\r
                        #define BITBANG_PDIDATA_PORT     PORTB\r
                        #define BITBANG_PDIDATA_DDR      DDRB\r
index 23e27c5..2b6a1e8 100644 (file)
@@ -66,7 +66,7 @@ MCU = at90usb1287
 # Target board (see library "Board Types" documentation, USER or blank for projects not requiring\r
 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called \r
 # "Board" inside the application directory.\r
-BOARD = XPLAIN\r
+BOARD = USBKEY\r
 \r
 \r
 # Processor frequency.\r