Increase AVRISP command timeout to 240ms up from 150ms to prevent some ISP commands...
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 28 Aug 2009 08:24:50 +0000 (08:24 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 28 Aug 2009 08:24:50 +0000 (08:24 +0000)
Add check to the PROGRAM FLASH ISP and PROGRAM EEPROM ISP handler to return an explicit error when the host attempts to write more data than the device is able to buffer.

Projects/AVRISP/Lib/V2Protocol.c
Projects/AVRISP/Lib/V2ProtocolTarget.c
Projects/AVRISP/Lib/V2ProtocolTarget.h

index 3a1b78e..3aa2d89 100644 (file)
@@ -308,6 +308,18 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
 \r
        Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData));\r
        Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
 \r
        Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData));\r
        Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
+       \r
+       if (Write_Memory_Params.BytesToWrite > sizeof(Write_Memory_Params.ProgData))\r
+       {\r
+               Endpoint_ClearOUT();\r
+               Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
+\r
+               Endpoint_Write_Byte(V2Command);\r
+               Endpoint_Write_Byte(STATUS_CMD_FAILED);\r
+               Endpoint_ClearIN();\r
+               return;\r
+       }\r
+       \r
        Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite);\r
 \r
        Endpoint_ClearOUT();\r
        Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite);\r
 \r
        Endpoint_ClearOUT();\r
@@ -407,7 +419,6 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
 \r
        Endpoint_Write_Byte(V2Command);\r
        Endpoint_Write_Byte(ProgrammingStatus);\r
 \r
        Endpoint_Write_Byte(V2Command);\r
        Endpoint_Write_Byte(ProgrammingStatus);\r
-       \r
        Endpoint_ClearIN();\r
 }\r
 \r
        Endpoint_ClearIN();\r
 }\r
 \r
index 9c6ccf4..24cd941 100644 (file)
@@ -155,13 +155,15 @@ uint8_t V2Protocol_WaitWhileTargetBusy(void)
 {\r
        TCNT0 = 0;\r
        \r
 {\r
        TCNT0 = 0;\r
        \r
+       bool DeviceBusy;\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
-               bool DeviceBusy = (SPI_ReceiveByte() & 0x01);\r
+               DeviceBusy = (SPI_ReceiveByte() & 0x01);\r
        }\r
        while (DeviceBusy && (TCNT0 < TARGET_BUSY_TIMEOUT_MS));\r
 \r
        }\r
        while (DeviceBusy && (TCNT0 < TARGET_BUSY_TIMEOUT_MS));\r
 \r
index 1e0364d..6322b9f 100644 (file)
@@ -52,7 +52,7 @@
                #define TOTAL_PROGRAMMING_SPEEDS  7\r
 \r
                /** Timeout in milliseconds of target busy-wait loops waiting for a command to complete */\r
                #define TOTAL_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    150\r
+               #define TARGET_BUSY_TIMEOUT_MS    240\r
                \r
        /* External Variables: */\r
                extern uint32_t CurrentAddress;\r
                \r
        /* External Variables: */\r
                extern uint32_t CurrentAddress;\r