Added const where possible to the source functions in the Projects directory.
authorDean Camera <dean@fourwalledcubicle.com>
Sat, 26 Dec 2009 04:13:55 +0000 (04:13 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sat, 26 Dec 2009 04:13:55 +0000 (04:13 +0000)
Added command timeout to the AVRISP project so that incorrectly connected targets no longer freeze the device.

Removed string descriptors from the TeensyHID bootloader to reduce its size.

20 files changed:
Bootloaders/TeensyHID/Descriptors.c
LUFA/ManPages/ChangeLog.txt
LUFA/ManPages/LUFAPoweredProjects.txt
Projects/AVRISP/AVRISP.c
Projects/AVRISP/Lib/ISP/ISPProtocol.h
Projects/AVRISP/Lib/ISP/ISPTarget.c
Projects/AVRISP/Lib/ISP/ISPTarget.h
Projects/AVRISP/Lib/V2Protocol.c
Projects/AVRISP/Lib/V2Protocol.h
Projects/AVRISP/Lib/V2ProtocolParams.c
Projects/AVRISP/Lib/V2ProtocolParams.h
Projects/AVRISP/Lib/XPROG/TINYNVM.c
Projects/AVRISP/Lib/XPROG/TINYNVM.h
Projects/AVRISP/Lib/XPROG/XMEGANVM.c
Projects/AVRISP/Lib/XPROG/XMEGANVM.h
Projects/AVRISP/Lib/XPROG/XPROGProtocol.c
Projects/AVRISP/Lib/XPROG/XPROGTarget.c
Projects/AVRISP/Lib/XPROG/XPROGTarget.h
Projects/MissileLauncher/MissileLauncher.c
Projects/MissileLauncher/MissileLauncher.h

index 791269c..65a8d11 100644 (file)
@@ -152,7 +152,7 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor =
  */\r
 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)\r
 {\r
  */\r
 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)\r
 {\r
-       const uint8_t  DescriptorType   = (wValue >> 8);\r
+       const uint8_t DescriptorType = (wValue >> 8);\r
 \r
        void*    Address = NULL;\r
        uint16_t Size    = NO_DESCRIPTOR;\r
 \r
        void*    Address = NULL;\r
        uint16_t Size    = NO_DESCRIPTOR;\r
index 17702b6..48361e3 100644 (file)
   *\r
   *  <b>New:</b>\r
   *  - Added TPI programming support for 6-pin ATTINY to the AVRISP programmer project\r
   *\r
   *  <b>New:</b>\r
   *  - Added TPI programming support for 6-pin ATTINY to the AVRISP programmer project\r
+  *  - Added command timeout counter to the AVRISP project so that the device no longer freezes when incorrectly connected\r
+  *    to a target\r
   *\r
   *  <b>Changed:</b>\r
   *\r
   *  <b>Changed:</b>\r
+  *  - Slowed down bit-banged PDI programming in the AVRISP project slightly to prevent transmission errors\r
   *\r
   *  <b>Fixed:</b>\r
   *\r
   *\r
   *  <b>Fixed:</b>\r
   *\r
index 9d95a6e..615e5c6 100644 (file)
@@ -37,7 +37,7 @@
  *  - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller: http://noisybox.net/electronics/wingdinger/\r
  *  - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master\r
  *  - Generic HID Device Creator : http://generichid.sourceforge.net/\r
  *  - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller: http://noisybox.net/electronics/wingdinger/\r
  *  - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master\r
  *  - Generic HID Device Creator : http://generichid.sourceforge.net/\r
- *  - Mobo 4.3, some sort of Audio related device: http://sites.google.com/site/lofturj/mobo4_3\r
+ *  - Mobo 4.3, a USB controlled all band (160-10m) HF SDR transceiver: http://sites.google.com/site/lofturj/mobo4_3\r
  *  - NES Controller USB modification: http://projects.peterpolidoro.net/video/NESUSB.htm\r
  *  - MakeTV Episode Dispenser: http://www.youtube.com/watch?v=BkWUi18hl3g\r
  *  - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/\r
  *  - NES Controller USB modification: http://projects.peterpolidoro.net/video/NESUSB.htm\r
  *  - MakeTV Episode Dispenser: http://www.youtube.com/watch?v=BkWUi18hl3g\r
  *  - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/\r
index c0572fc..7974f1c 100644 (file)
@@ -78,7 +78,7 @@ void SetupHardware(void)
        ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
        #endif\r
        \r
        ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
        #endif\r
        \r
-       /* Millisecond timer initialization for timeouts and delays */\r
+       /* Millisecond timer initialization for managing the command timeout counter */\r
        OCR0A  = ((F_CPU / 64) / 1000);\r
        TCCR0A = (1 << WGM01);\r
        TCCR0B = ((1 << CS01) | (1 << CS00));\r
        OCR0A  = ((F_CPU / 64) / 1000);\r
        TCCR0A = (1 << WGM01);\r
        TCCR0B = ((1 << CS01) | (1 << CS00));\r
index 43c25c4..abbbf56 100644 (file)
                 */\r
                static inline void ISPProtocol_DelayMS(uint8_t DelayMS)\r
                {\r
                 */\r
                static inline void ISPProtocol_DelayMS(uint8_t DelayMS)\r
                {\r
-                       TCNT0 = 0;\r
-                       TIFR0 = (1 << OCF1A);\r
+                       OCR2A  = ((F_CPU / 64) / 1000);\r
+                       TCCR2A = (1 << WGM01);\r
+                       TCCR2B = ((1 << CS01) | (1 << CS00));                   \r
 \r
                        while (DelayMS)\r
                        {\r
 \r
                        while (DelayMS)\r
                        {\r
-                               if (TIFR0 & (1 << OCF1A))\r
+                               if (TIFR2 & (1 << OCF2A))\r
                                {\r
                                {\r
-                                       TIFR0 = (1 << OCF1A);\r
+                                       TIFR2 = (1 << OCF2A);\r
                                        DelayMS--;\r
                                }\r
                        }\r
                                        DelayMS--;\r
                                }\r
                        }\r
+                       \r
+                       TCCR2B = 0;                     \r
                }\r
 \r
        /* Function Prototypes: */\r
                }\r
 \r
        /* Function Prototypes: */\r
index e99e3e5..29cb18e 100644 (file)
@@ -122,26 +122,15 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
                        break;\r
                case PROG_MODE_WORD_VALUE_MASK:\r
                case PROG_MODE_PAGED_VALUE_MASK:\r
                        break;\r
                case PROG_MODE_WORD_VALUE_MASK:\r
                case PROG_MODE_PAGED_VALUE_MASK:\r
-                       TCNT0 = 0;\r
-                       TIFR0 = (1 << OCF1A);\r
-                       \r
-                       uint8_t TimeoutMS = TARGET_BUSY_TIMEOUT_MS;\r
-\r
                        do\r
                        {\r
                                SPI_SendByte(ReadMemCommand);\r
                                SPI_SendByte(PollAddress >> 8);\r
                                SPI_SendByte(PollAddress & 0xFF);\r
                        do\r
                        {\r
                                SPI_SendByte(ReadMemCommand);\r
                                SPI_SendByte(PollAddress >> 8);\r
                                SPI_SendByte(PollAddress & 0xFF);\r
-\r
-                               if (TIFR0 & (1 << OCF1A))\r
-                               {\r
-                                       TIFR0 = (1 << OCF1A);\r
-                                       TimeoutMS--;\r
-                               }\r
                        }\r
                        }\r
-                       while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMS);\r
+                       while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMSRemaining);\r
 \r
 \r
-                       if (!(TimeoutMS))\r
+                       if (!(TimeoutMSRemaining))\r
                         ProgrammingStatus = STATUS_CMD_TOUT;\r
                        \r
                        break;          \r
                         ProgrammingStatus = STATUS_CMD_TOUT;\r
                        \r
                        break;          \r
@@ -161,27 +150,16 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
  */\r
 uint8_t ISPTarget_WaitWhileTargetBusy(void)\r
 {\r
  */\r
 uint8_t ISPTarget_WaitWhileTargetBusy(void)\r
 {\r
-       TCNT0 = 0;\r
-       TIFR0 = (1 << OCF1A);\r
-                       \r
-       uint8_t TimeoutMS = TARGET_BUSY_TIMEOUT_MS;\r
-       \r
        do\r
        {\r
                SPI_SendByte(0xF0);\r
                SPI_SendByte(0x00);\r
 \r
                SPI_SendByte(0x00);\r
        do\r
        {\r
                SPI_SendByte(0xF0);\r
                SPI_SendByte(0x00);\r
 \r
                SPI_SendByte(0x00);\r
-\r
-               if (TIFR0 & (1 << OCF1A))\r
-               {\r
-                       TIFR0 = (1 << OCF1A);\r
-                       TimeoutMS--;\r
-               }\r
        }\r
        }\r
-       while ((SPI_ReceiveByte() & 0x01) && TimeoutMS);\r
+       while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);\r
 \r
 \r
-       if (!(TimeoutMS))\r
+       if (!(TimeoutMSRemaining))\r
          return STATUS_RDY_BSY_TOUT;\r
        else\r
          return STATUS_CMD_OK;\r
          return STATUS_RDY_BSY_TOUT;\r
        else\r
          return STATUS_CMD_OK;\r
index 96f1a64..c856ddd 100644 (file)
        /* Macros: */\r
                /** Total number of allowable ISP programming speeds supported by the device */\r
                #define TOTAL_ISP_PROGRAMMING_SPEEDS  7\r
        /* Macros: */\r
                /** Total number of allowable ISP programming speeds supported by the device */\r
                #define TOTAL_ISP_PROGRAMMING_SPEEDS  7\r
-\r
-               /** Timeout in milliseconds of target busy-wait loops waiting for a command to complete */\r
-               #define TARGET_BUSY_TIMEOUT_MS        100\r
-\r
+               \r
        /* Function Prototypes: */\r
                uint8_t ISPTarget_GetSPIPrescalerMask(void);\r
                void    ISPTarget_ChangeTargetResetLine(const bool ResetTarget);\r
        /* Function Prototypes: */\r
                uint8_t ISPTarget_GetSPIPrescalerMask(void);\r
                void    ISPTarget_ChangeTargetResetLine(const bool ResetTarget);\r
index 4f7904a..4fcb5aa 100644 (file)
@@ -43,6 +43,13 @@ uint32_t CurrentAddress;
 bool MustSetAddress;\r
 \r
 \r
 bool MustSetAddress;\r
 \r
 \r
+/** ISR for the management of the command execution timeout counter */\r
+ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+{\r
+       if (TimeoutMSRemaining)\r
+         TimeoutMSRemaining--;\r
+}\r
+\r
 /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host.\r
  *  This routine decodes the issued command and passes off the handling of the command to the\r
  *  appropriate function.\r
 /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host.\r
  *  This routine decodes the issued command and passes off the handling of the command to the\r
  *  appropriate function.\r
@@ -51,6 +58,9 @@ void V2Protocol_ProcessCommand(void)
 {\r
        uint8_t V2Command = Endpoint_Read_Byte();\r
        \r
 {\r
        uint8_t V2Command = Endpoint_Read_Byte();\r
        \r
+       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+       TIMSK0 |= (1 << OCIE0A);\r
+\r
        switch (V2Command)\r
        {\r
                case CMD_SIGN_ON:\r
        switch (V2Command)\r
        {\r
                case CMD_SIGN_ON:\r
@@ -110,7 +120,9 @@ void V2Protocol_ProcessCommand(void)
                        V2Protocol_UnknownCommand(V2Command);\r
                        break;\r
        }\r
                        V2Protocol_UnknownCommand(V2Command);\r
                        break;\r
        }\r
-       \r
+               \r
+       TIMSK0 &= ~(1 << OCIE0A);\r
+\r
        Endpoint_WaitUntilReady();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);\r
 }\r
        Endpoint_WaitUntilReady();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);\r
 }\r
index db4d09f..76b08b0 100644 (file)
        /* Preprocessor Checks: */\r
                #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))\r
                        #undef ENABLE_ISP_PROTOCOL\r
        /* Preprocessor Checks: */\r
                #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))\r
                        #undef ENABLE_ISP_PROTOCOL\r
-                       #undef ENABLE_TPI_PROTOCOL\r
                        \r
                        \r
-                       #if !defined(ENABLE_PDI_PROTOCOL)\r
-                               #define ENABLE_PDI_PROTOCOL\r
+                       #if !defined(ENABLE_XPROG_PROTOCOL)\r
+                               #define ENABLE_XPROG_PROTOCOL\r
                        #endif\r
                #endif\r
 
        /* Macros: */\r
                /** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */
                #define PROGRAMMER_ID     "AVRISP_MK2"\r
                        #endif\r
                #endif\r
 
        /* Macros: */\r
                /** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */
                #define PROGRAMMER_ID     "AVRISP_MK2"\r
+               \r
+               /** Timeout period for each issued command from the host before it is aborted */\r
+               #define COMMAND_TIMEOUT_MS 200\r
+               \r
+               /** Command timeout counter register, GPIOR for speed */\r
+               #define TimeoutMSRemaining GPIOR1\r
 \r
        /* External Variables: */\r
                extern uint32_t CurrentAddress;\r
 \r
        /* External Variables: */\r
                extern uint32_t CurrentAddress;\r
index 6b7f84a..eacff03 100644 (file)
@@ -43,44 +43,44 @@ uint8_t EEMEM EEPROM_Rest_Polarity = 0x00;
 static ParameterItem_t ParameterTable[] = \r
        {\r
                { .ParamID          = PARAM_BUILD_NUMBER_LOW,\r
 static ParameterItem_t ParameterTable[] = \r
        {\r
                { .ParamID          = PARAM_BUILD_NUMBER_LOW,\r
-                 .ParamValue       = (LUFA_VERSION_INTEGER >> 8),\r
-                 .ParamPrivileges  = PARAM_PRIV_READ                    },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ,\r
+                 .ParamValue       = (LUFA_VERSION_INTEGER >> 8)        },\r
 \r
                { .ParamID          = PARAM_BUILD_NUMBER_HIGH,\r
 \r
                { .ParamID          = PARAM_BUILD_NUMBER_HIGH,\r
-                 .ParamValue       = (LUFA_VERSION_INTEGER & 0xFF),\r
-                 .ParamPrivileges  = PARAM_PRIV_READ                    },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ,\r
+                 .ParamValue       = (LUFA_VERSION_INTEGER & 0xFF),     },\r
 \r
                { .ParamID          = PARAM_HW_VER,\r
 \r
                { .ParamID          = PARAM_HW_VER,\r
-                 .ParamValue       = 0x00,\r
-                 .ParamPrivileges  = PARAM_PRIV_READ                    },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ,\r
+                 .ParamValue       = 0x00                               },\r
 \r
                { .ParamID          = PARAM_SW_MAJOR,\r
 \r
                { .ParamID          = PARAM_SW_MAJOR,\r
-                 .ParamValue       = 0x01,\r
-                 .ParamPrivileges  = PARAM_PRIV_READ                    },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ,\r
+                 .ParamValue       = 0x01                               },\r
 \r
                { .ParamID          = PARAM_SW_MINOR,\r
 \r
                { .ParamID          = PARAM_SW_MINOR,\r
-                 .ParamValue       = 0x0D,\r
-                 .ParamPrivileges  = PARAM_PRIV_READ                    },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ,\r
+                 .ParamValue       = 0x0D                               },\r
 \r
                { .ParamID          = PARAM_VTARGET,\r
 \r
                { .ParamID          = PARAM_VTARGET,\r
-                 .ParamValue       = 0x32,\r
-                 .ParamPrivileges  = PARAM_PRIV_READ                    },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ,\r
+                 .ParamValue       = 0x32                               },\r
 \r
                { .ParamID          = PARAM_SCK_DURATION,\r
 \r
                { .ParamID          = PARAM_SCK_DURATION,\r
-                 .ParamValue       = (TOTAL_ISP_PROGRAMMING_SPEEDS - 1),\r
-                 .ParamPrivileges  = PARAM_PRIV_READ | PARAM_PRIV_WRITE },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ | PARAM_PRIV_WRITE,\r
+                 .ParamValue       = (TOTAL_ISP_PROGRAMMING_SPEEDS - 1) },\r
 \r
                { .ParamID          = PARAM_RESET_POLARITY,\r
 \r
                { .ParamID          = PARAM_RESET_POLARITY,\r
-                 .ParamValue       = 0x00,\r
-                 .ParamPrivileges  = PARAM_PRIV_WRITE                   },\r
+                 .ParamPrivileges  = PARAM_PRIV_WRITE,\r
+                 .ParamValue       = 0x00                               },\r
 \r
                { .ParamID          = PARAM_STATUS_TGT_CONN,\r
 \r
                { .ParamID          = PARAM_STATUS_TGT_CONN,\r
-                 .ParamValue       = 0x00,\r
-                 .ParamPrivileges  = PARAM_PRIV_READ                    },\r
+                 .ParamPrivileges  = PARAM_PRIV_READ,\r
+                 .ParamValue       = 0x00                               },\r
 \r
                { .ParamID          = PARAM_DISCHARGEDELAY,\r
 \r
                { .ParamID          = PARAM_DISCHARGEDELAY,\r
-                 .ParamValue       = 0x00,\r
-                 .ParamPrivileges  = PARAM_PRIV_WRITE                   },\r
+                 .ParamPrivileges  = PARAM_PRIV_WRITE,\r
+                 .ParamValue       = 0x00                               },\r
        };\r
 \r
 \r
        };\r
 \r
 \r
index 14ff56c..28d57c8 100644 (file)
@@ -62,8 +62,8 @@
                typedef struct\r
                {\r
                        const uint8_t ParamID; /**< Parameter ID number to uniquely identify the parameter within the device */\r
                typedef struct\r
                {\r
                        const uint8_t ParamID; /**< Parameter ID number to uniquely identify the parameter within the device */\r
+                       const uint8_t ParamPrivileges;  /**< Parameter privileges to allow the host to read or write the parameter's value */\r
                        uint8_t ParamValue; /**< Current parameter's value within the device */\r
                        uint8_t ParamValue; /**< Current parameter's value within the device */\r
-                       uint8_t ParamPrivileges;  /**< Parameter privileges to allow the host to read or write the parameter's value */\r
                } ParameterItem_t;\r
 \r
        /* Function Prototypes: */\r
                } ParameterItem_t;\r
 \r
        /* Function Prototypes: */\r
index f4b90ff..3ddd2ed 100644 (file)
@@ -37,6 +37,7 @@
 #include "TINYNVM.h"\r
 \r
 #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)\r
 #include "TINYNVM.h"\r
 \r
 #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)\r
+#warning TPI Protocol support is currently incomplete and is not suitable for general use.\r
 \r
 /** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read.\r
  *\r
 \r
 /** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read.\r
  *\r
  */\r
 bool TINYNVM_WaitWhileNVMBusBusy(void)\r
 {\r
  */\r
 bool TINYNVM_WaitWhileNVMBusBusy(void)\r
 {\r
-       TCNT0 = 0;\r
-       TIFR0 = (1 << OCF1A);\r
-                       \r
-       uint8_t TimeoutMS = TINY_NVM_BUSY_TIMEOUT_MS;\r
-       \r
        /* Poll the STATUS register to check to see if NVM access has been enabled */\r
        /* Poll the STATUS register to check to see if NVM access has been enabled */\r
-       while (TimeoutMS)\r
+       while (TimeoutMSRemaining)\r
        {\r
                /* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)\r
                  return true;\r
        {\r
                /* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)\r
                  return true;\r
-\r
-               if (TIFR0 & (1 << OCF1A))\r
-               {\r
-                       TIFR0 = (1 << OCF1A);\r
-                       TimeoutMS--;\r
-               }\r
        }\r
        \r
        return false;\r
        }\r
        \r
        return false;\r
index ecf429e..75d1129 100644 (file)
                #endif\r
 \r
        /* Defines: */\r
                #endif\r
 \r
        /* Defines: */\r
-               #define TINY_NVM_BUSY_TIMEOUT_MS       100\r
+               #define TINY_NVM_REG_NVMCSR            0x32\r
+               #define TINY_NVM_REG_NVMCMD            0x33\r
+\r
+               #define TINY_NVM_CMD_NOOP              0x00\r
+               #define TINY_NVM_CMD_CHIPERASE         0x10\r
+               #define TINY_NVM_CMD_SECTIONERASE      0x14\r
+               #define TINY_NVM_CMD_WORDWRITE         0x1D\r
 \r
        /* Function Prototypes: */\r
                bool TINYNVM_WaitWhileNVMBusBusy(void);\r
 \r
        /* Function Prototypes: */\r
                bool TINYNVM_WaitWhileNVMBusBusy(void);\r
index 6280f60..c83ae01 100644 (file)
@@ -58,10 +58,10 @@ void XMEGANVM_SendNVMRegAddress(const uint8_t Register)
 void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)\r
 {\r
        /* Send the given 32-bit address to the target, LSB first */\r
 void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)\r
 {\r
        /* Send the given 32-bit address to the target, LSB first */\r
-       XPROGTarget_SendByte(AbsoluteAddress &  0xFF);\r
-       XPROGTarget_SendByte(AbsoluteAddress >> 8);\r
-       XPROGTarget_SendByte(AbsoluteAddress >> 16);\r
-       XPROGTarget_SendByte(AbsoluteAddress >> 24);\r
+       XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[0]);\r
+       XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[1]);\r
+       XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[2]);\r
+       XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[3]);\r
 }\r
 \r
 /** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read or CRC\r
 }\r
 \r
 /** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read or CRC\r
@@ -71,24 +71,13 @@ void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)
  */\r
 bool XMEGANVM_WaitWhileNVMBusBusy(void)\r
 {\r
  */\r
 bool XMEGANVM_WaitWhileNVMBusBusy(void)\r
 {\r
-       TCNT0 = 0;\r
-       TIFR0 = (1 << OCF1A);\r
-                       \r
-       uint8_t TimeoutMS = XMEGA_NVM_BUSY_TIMEOUT_MS;\r
-       \r
        /* Poll the STATUS register to check to see if NVM access has been enabled */\r
        /* Poll the STATUS register to check to see if NVM access has been enabled */\r
-       while (TimeoutMS)\r
+       while (TimeoutMSRemaining)\r
        {\r
                /* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)\r
                  return true;\r
        {\r
                /* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)\r
                  return true;\r
-\r
-               if (TIFR0 & (1 << OCF1A))\r
-               {\r
-                       TIFR0 = (1 << OCF1A);\r
-                       TimeoutMS--;\r
-               }\r
        }\r
        \r
        return false;\r
        }\r
        \r
        return false;\r
@@ -101,13 +90,8 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
  */\r
 bool XMEGANVM_WaitWhileNVMControllerBusy(void)\r
 {\r
  */\r
 bool XMEGANVM_WaitWhileNVMControllerBusy(void)\r
 {\r
-       TCNT0 = 0;\r
-       TIFR0 = (1 << OCF1A);\r
-                       \r
-       uint8_t TimeoutMS = XMEGA_NVM_BUSY_TIMEOUT_MS;\r
-       \r
        /* Poll the NVM STATUS register while the NVM controller is busy */\r
        /* Poll the NVM STATUS register while the NVM controller is busy */\r
-       while (TimeoutMS)\r
+       while (TimeoutMSRemaining)\r
        {\r
                /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */\r
                XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
        {\r
                /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */\r
                XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
@@ -116,12 +100,6 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void)
                /* Check to see if the BUSY flag is still set */\r
                if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
                  return true;\r
                /* Check to see if the BUSY flag is still set */\r
                if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
                  return true;\r
-\r
-               if (TIFR0 & (1 << OCF1A))\r
-               {\r
-                       TIFR0 = (1 << OCF1A);\r
-                       TimeoutMS--;\r
-               }\r
        }\r
        \r
        return false;\r
        }\r
        \r
        return false;\r
@@ -158,22 +136,24 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest)
        if (!(XMEGANVM_WaitWhileNVMControllerBusy()))\r
          return false;\r
        \r
        if (!(XMEGANVM_WaitWhileNVMControllerBusy()))\r
          return false;\r
        \r
-       *CRCDest = 0;\r
+       uint32_t MemoryCRC = 0;\r
        \r
        /* Read the first generated CRC byte value */\r
        XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
        XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0);\r
        \r
        /* Read the first generated CRC byte value */\r
        XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
        XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0);\r
-       *CRCDest  = XPROGTarget_ReceiveByte();\r
+       MemoryCRC  = XPROGTarget_ReceiveByte();\r
 \r
        /* Read the second generated CRC byte value */\r
        XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
        XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT1);\r
 \r
        /* Read the second generated CRC byte value */\r
        XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
        XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT1);\r
-       *CRCDest |= ((uint16_t)XPROGTarget_ReceiveByte() << 8);\r
+       MemoryCRC |= ((uint16_t)XPROGTarget_ReceiveByte() << 8);\r
 \r
        /* Read the third generated CRC byte value */\r
        XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
        XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT2);\r
 \r
        /* Read the third generated CRC byte value */\r
        XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));\r
        XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT2);\r
-       *CRCDest |= ((uint32_t)XPROGTarget_ReceiveByte() << 16);\r
+       MemoryCRC |= ((uint32_t)XPROGTarget_ReceiveByte() << 16);\r
+       \r
+       *CRCDest = MemoryCRC;\r
        \r
        return true;\r
 }\r
        \r
        return true;\r
 }\r
@@ -186,7 +166,7 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest)
  *\r
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
  *\r
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
-bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const uint16_t ReadSize)\r
+bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadSize)\r
 {\r
        /* Wait until the NVM controller is no longer busy */\r
        if (!(XMEGANVM_WaitWhileNVMControllerBusy()))\r
 {\r
        /* Wait until the NVM controller is no longer busy */\r
        if (!(XMEGANVM_WaitWhileNVMControllerBusy()))\r
@@ -207,7 +187,7 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const
                \r
        /* Send a LD command with indirect access and postincrement to read out the bytes */\r
        XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);\r
                \r
        /* Send a LD command with indirect access and postincrement to read out the bytes */\r
        XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);\r
-       for (uint16_t i = 0; i < ReadSize; i++)\r
+       while (ReadSize--)\r
          *(ReadBuffer++) = XPROGTarget_ReceiveByte();\r
        \r
        return true;\r
          *(ReadBuffer++) = XPROGTarget_ReceiveByte();\r
        \r
        return true;\r
@@ -253,8 +233,8 @@ bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAd
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
 bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand,\r
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
 bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand,\r
-                               const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,\r
-                               const uint8_t* WriteBuffer, const uint16_t WriteSize)\r
+                              const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,\r
+                              const uint8_t* WriteBuffer, uint16_t WriteSize)\r
 {\r
        if (PageMode & XPRG_PAGEMODE_ERASE)\r
        {\r
 {\r
        if (PageMode & XPRG_PAGEMODE_ERASE)\r
        {\r
@@ -294,7 +274,7 @@ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t Eras
                        \r
                /* Send a ST command with indirect access and postincrement to write the bytes */\r
                XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);\r
                        \r
                /* Send a ST command with indirect access and postincrement to write the bytes */\r
                XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);\r
-               for (uint16_t i = 0; i < WriteSize; i++)\r
+               while (WriteSize--)\r
                  XPROGTarget_SendByte(*(WriteBuffer++));\r
        }\r
        \r
                  XPROGTarget_SendByte(*(WriteBuffer++));\r
        }\r
        \r
index 6a4de1f..d1a14ab 100644 (file)
@@ -56,8 +56,6 @@
                #endif\r
 \r
        /* Defines: */\r
                #endif\r
 \r
        /* Defines: */\r
-               #define XMEGA_NVM_BUSY_TIMEOUT_MS            100\r
-               \r
                #define XMEGA_NVM_REG_ADDR0                  0x00\r
                #define XMEGA_NVM_REG_ADDR1                  0x01\r
                #define XMEGA_NVM_REG_ADDR2                  0x02\r
                #define XMEGA_NVM_REG_ADDR0                  0x00\r
                #define XMEGA_NVM_REG_ADDR1                  0x01\r
                #define XMEGA_NVM_REG_ADDR2                  0x02\r
                bool XMEGANVM_WaitWhileNVMBusBusy(void);\r
                bool XMEGANVM_WaitWhileNVMControllerBusy(void);\r
                bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest);\r
                bool XMEGANVM_WaitWhileNVMBusBusy(void);\r
                bool XMEGANVM_WaitWhileNVMControllerBusy(void);\r
                bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest);\r
-               bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const uint16_t ReadSize);\r
+               bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadSize);\r
                bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t* WriteBuffer);\r
                bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand,\r
                                              const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,\r
                bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t* WriteBuffer);\r
                bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand,\r
                                              const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,\r
-                                             const uint8_t* WriteBuffer, const uint16_t WriteSize);\r
+                                             const uint8_t* WriteBuffer, uint16_t WriteSize);\r
                bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address);\r
 \r
 #endif\r
                bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address);\r
 \r
 #endif\r
index edcc874..bccb96c 100644 (file)
@@ -38,7 +38,7 @@
 \r
 #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)\r
 /** Base absolute address for the target's NVM controller */\r
 \r
 #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)\r
 /** Base absolute address for the target's NVM controller */\r
-uint32_t XPROG_Param_NVMBase = 0x010001C0;\r
+uint32_t XPROG_Param_NVMBase    = 0x010001C0;\r
 \r
 /** Size in bytes of the target's EEPROM page */\r
 uint32_t XPROG_Param_EEPageSize;\r
 \r
 /** Size in bytes of the target's EEPROM page */\r
 uint32_t XPROG_Param_EEPageSize;\r
@@ -46,7 +46,6 @@ uint32_t XPROG_Param_EEPageSize;
 /** Currently selected XPROG programming protocol */\r
 uint8_t  XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI;\r
 \r
 /** Currently selected XPROG programming protocol */\r
 uint8_t  XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI;\r
 \r
-\r
 /** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI\r
  *  programming.\r
  */\r
 /** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI\r
  *  programming.\r
  */\r
index 708b237..59c85f3 100644 (file)
@@ -174,7 +174,7 @@ void XPROGTarget_EnableTargetTPI(void)
        BITBANG_TPIDATA_PORT |= BITBANG_TPIDATA_MASK;\r
 \r
        /* Fire timer capture ISR every 100 cycles to manage the software USART */\r
        BITBANG_TPIDATA_PORT |= BITBANG_TPIDATA_MASK;\r
 \r
        /* Fire timer capture ISR every 100 cycles to manage the software USART */\r
-       OCR1A   = 80;\r
+       OCR1A   = 100;\r
        TCCR1B  = (1 << WGM13) | (1 << WGM12) | (1 << CS10);\r
        TIMSK1  = (1 << ICIE1);\r
        \r
        TCCR1B  = (1 << WGM13) | (1 << WGM12) | (1 << CS10);\r
        TIMSK1  = (1 << ICIE1);\r
        \r
@@ -217,7 +217,7 @@ void XPROGTarget_EnableTargetPDI(void)
        asm volatile ("NOP"::);\r
 \r
        /* Fire timer compare ISR every 100 cycles to manage the software USART */\r
        asm volatile ("NOP"::);\r
 \r
        /* Fire timer compare ISR every 100 cycles to manage the software USART */\r
-       OCR1A   = 80;\r
+       OCR1A   = 100;\r
        TCCR1B  = (1 << WGM12) | (1 << CS10);\r
        TIMSK1  = (1 << OCIE1A);\r
        \r
        TCCR1B  = (1 << WGM12) | (1 << CS10);\r
        TIMSK1  = (1 << OCIE1A);\r
        \r
@@ -353,7 +353,7 @@ uint8_t XPROGTarget_ReceiveByte(void)
        }\r
 \r
        /* Wait until a byte has been received before reading */\r
        }\r
 \r
        /* Wait until a byte has been received before reading */\r
-       while (!(UCSR1A & (1 << RXC1)));\r
+       while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining);\r
        return UDR1;\r
 #else\r
        /* Switch to Rx mode if currently in Tx mode */\r
        return UDR1;\r
 #else\r
        /* Switch to Rx mode if currently in Tx mode */\r
@@ -369,8 +369,8 @@ uint8_t XPROGTarget_ReceiveByte(void)
 \r
        /* Wait until a byte has been received before reading */\r
        SoftUSART_BitCount = BITS_IN_USART_FRAME;\r
 \r
        /* Wait until a byte has been received before reading */\r
        SoftUSART_BitCount = BITS_IN_USART_FRAME;\r
-       while (SoftUSART_BitCount);\r
-       \r
+       while (SoftUSART_BitCount && TimeoutMSRemaining);\r
+\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
        /* 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
index 58c1caa..4460216 100644 (file)
@@ -42,6 +42,8 @@
                #include <stdbool.h>\r
                \r
                #include <LUFA/Common/Common.h>\r
                #include <stdbool.h>\r
                \r
                #include <LUFA/Common/Common.h>\r
+               \r
+               #include "../V2Protocol.h"\r
        \r
        /* Preprocessor Checks: */\r
                #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))\r
        \r
        /* Preprocessor Checks: */\r
                #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))\r
index 26dd077..29ebd45 100644 (file)
@@ -1,12 +1,4 @@
 /*\r
 /*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
          USB Missile Launcher Demo\r
         Copyright (C) Dave Fletcher, 2009.\r
          fletch at fletchtronics dot net\r
          USB Missile Launcher Demo\r
         Copyright (C) Dave Fletcher, 2009.\r
          fletch at fletchtronics dot net\r
@@ -158,7 +150,7 @@ void Read_Joystick_Status(void)
  *  \param[in] Report  Report data to send.\r
  *  \param[in] ReportSize  Report length in bytes.\r
  */\r
  *  \param[in] Report  Report data to send.\r
  *  \param[in] ReportSize  Report length in bytes.\r
  */\r
-void Send_Command_Report(uint8_t *Report, uint16_t ReportSize)\r
+void Send_Command_Report(uint8_t* const Report, const uint16_t ReportSize)\r
 {\r
        memcpy(CmdBuffer, Report, 8);\r
        WriteNextReport(CmdBuffer, ReportSize);\r
 {\r
        memcpy(CmdBuffer, Report, 8);\r
        WriteNextReport(CmdBuffer, ReportSize);\r
@@ -168,7 +160,7 @@ void Send_Command_Report(uint8_t *Report, uint16_t ReportSize)
  *\r
  *  \param[in] Command  One of the command constants.\r
  */\r
  *\r
  *  \param[in] Command  One of the command constants.\r
  */\r
-void Send_Command(uint8_t* Command)\r
+void Send_Command(uint8_t* const Command)\r
 {\r
        if ((CmdState == CMD_STOP && Command != CMD_STOP) ||\r
                (CmdState != CMD_STOP && Command == CMD_STOP))\r
 {\r
        if ((CmdState == CMD_STOP && Command != CMD_STOP) ||\r
                (CmdState != CMD_STOP && Command == CMD_STOP))\r
@@ -252,7 +244,7 @@ void DiscardNextReport(void)
  *  \param[in] ReportOUTData  Buffer containing the report to send to the device\r
  *  \param[in] ReportLength  Length of the report to send\r
  */\r
  *  \param[in] ReportOUTData  Buffer containing the report to send to the device\r
  *  \param[in] ReportLength  Length of the report to send\r
  */\r
-void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength)\r
+void WriteNextReport(uint8_t* const ReportOUTData, const uint16_t ReportLength)\r
 {\r
        /* Select and unfreeze HID data OUT pipe */\r
        Pipe_SelectPipe(HID_DATA_OUT_PIPE);\r
 {\r
        /* Select and unfreeze HID data OUT pipe */\r
        Pipe_SelectPipe(HID_DATA_OUT_PIPE);\r
index e92fe74..400ee26 100644 (file)
@@ -82,8 +82,8 @@
                void SetupHardware(void);\r
 \r
                void Read_Joystick_Status(void);\r
                void SetupHardware(void);\r
 \r
                void Read_Joystick_Status(void);\r
-        void Send_Command_Report(uint8_t* Report, uint16_t ReportSize);\r
-        void Send_Command(uint8_t* Command);\r
+        void Send_Command_Report(uint8_t* const Report, const uint16_t ReportSize);\r
+        void Send_Command(uint8_t* const Command);\r
 \r
                void HID_Host_Task(void);\r
 \r
 \r
                void HID_Host_Task(void);\r
 \r
@@ -94,6 +94,6 @@
                void EVENT_USB_Host_DeviceEnumerationComplete(void);\r
 \r
                void DiscardNextReport(void);\r
                void EVENT_USB_Host_DeviceEnumerationComplete(void);\r
 \r
                void DiscardNextReport(void);\r
-               void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength);\r
+               void WriteNextReport(uint8_t* const ReportOUTData, const uint16_t ReportLength);\r
                \r
 #endif\r
                \r
 #endif\r