Speed up Webserver demo data rate by not sending a full ethernet frame each time...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / ISP / ISPTarget.c
index 1bd6887..267e518 100644 (file)
@@ -1,13 +1,13 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
@@ -53,14 +53,14 @@ uint8_t ISPTarget_GetSPIPrescalerMask(void)
                SPI_SPEED_FCPU_DIV_8,    // AVRStudio =   1MHz SPI, Actual =   1MHz SPI\r
                SPI_SPEED_FCPU_DIV_16,   // AVRStudio = 500KHz SPI, Actual = 500KHz SPI\r
                SPI_SPEED_FCPU_DIV_32,   // AVRStudio = 250KHz SPI, Actual = 250KHz SPI\r
                SPI_SPEED_FCPU_DIV_8,    // AVRStudio =   1MHz SPI, Actual =   1MHz SPI\r
                SPI_SPEED_FCPU_DIV_16,   // AVRStudio = 500KHz SPI, Actual = 500KHz SPI\r
                SPI_SPEED_FCPU_DIV_32,   // AVRStudio = 250KHz SPI, Actual = 250KHz SPI\r
-               SPI_SPEED_FCPU_DIV_64    // AVRStudio = 125KHz SPI, Actual = 125KHz SPI \r
+               SPI_SPEED_FCPU_DIV_64,   // AVRStudio = 125KHz SPI, Actual = 125KHz SPI\r
        #elif (F_CPU == 16000000)\r
                SPI_SPEED_FCPU_DIV_2,    // AVRStudio =   8MHz SPI, Actual =   8MHz SPI\r
                SPI_SPEED_FCPU_DIV_4,    // AVRStudio =   4MHz SPI, Actual =   4MHz SPI\r
                SPI_SPEED_FCPU_DIV_8,    // AVRStudio =   2MHz SPI, Actual =   2MHz SPI\r
                SPI_SPEED_FCPU_DIV_16,   // AVRStudio =   1MHz SPI, Actual =   1MHz SPI\r
                SPI_SPEED_FCPU_DIV_32,   // AVRStudio = 500KHz SPI, Actual = 500KHz SPI\r
        #elif (F_CPU == 16000000)\r
                SPI_SPEED_FCPU_DIV_2,    // AVRStudio =   8MHz SPI, Actual =   8MHz SPI\r
                SPI_SPEED_FCPU_DIV_4,    // AVRStudio =   4MHz SPI, Actual =   4MHz SPI\r
                SPI_SPEED_FCPU_DIV_8,    // AVRStudio =   2MHz SPI, Actual =   2MHz SPI\r
                SPI_SPEED_FCPU_DIV_16,   // AVRStudio =   1MHz SPI, Actual =   1MHz SPI\r
                SPI_SPEED_FCPU_DIV_32,   // AVRStudio = 500KHz SPI, Actual = 500KHz SPI\r
-               SPI_SPEED_FCPU_DIV_64,   // AVRStudio = 250KHz SPI, Actual = 250KHz SPI         \r
+               SPI_SPEED_FCPU_DIV_64,   // AVRStudio = 250KHz SPI, Actual = 250KHz SPI\r
                SPI_SPEED_FCPU_DIV_128   // AVRStudio = 125KHz SPI, Actual = 125KHz SPI\r
        #else\r
                #error No SPI prescaler masks for chosen F_CPU speed.\r
                SPI_SPEED_FCPU_DIV_128   // AVRStudio = 125KHz SPI, Actual = 125KHz SPI\r
        #else\r
                #error No SPI prescaler masks for chosen F_CPU speed.\r
@@ -128,7 +128,7 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
                                SPI_SendByte(PollAddress >> 8);\r
                                SPI_SendByte(PollAddress & 0xFF);\r
                        }\r
                                SPI_SendByte(PollAddress >> 8);\r
                                SPI_SendByte(PollAddress & 0xFF);\r
                        }\r
-                       while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMSRemaining);\r
+                       while ((SPI_TransferByte(0x00) == PollValue) && TimeoutMSRemaining);\r
 \r
                        if (!(TimeoutMSRemaining))\r
                         ProgrammingStatus = STATUS_CMD_TOUT;\r
 \r
                        if (!(TimeoutMSRemaining))\r
                         ProgrammingStatus = STATUS_CMD_TOUT;\r
@@ -139,6 +139,9 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
                        ProgrammingStatus = ISPTarget_WaitWhileTargetBusy();\r
                        break;\r
        }\r
                        ProgrammingStatus = ISPTarget_WaitWhileTargetBusy();\r
                        break;\r
        }\r
+       \r
+       if (ProgrammingStatus == STATUS_CMD_OK)\r
+         TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
 \r
        return ProgrammingStatus;\r
 }\r
 \r
        return ProgrammingStatus;\r
 }\r
@@ -159,10 +162,7 @@ uint8_t ISPTarget_WaitWhileTargetBusy(void)
        }\r
        while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);\r
 \r
        }\r
        while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);\r
 \r
-       if (!(TimeoutMSRemaining))\r
-         return STATUS_RDY_BSY_TOUT;\r
-       else\r
-         return STATUS_CMD_OK;\r
+       return ((TimeoutMSRemaining) ? STATUS_CMD_OK : STATUS_RDY_BSY_TOUT);\r
 }\r
 \r
 /** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the\r
 }\r
 \r
 /** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the\r
@@ -171,7 +171,7 @@ uint8_t ISPTarget_WaitWhileTargetBusy(void)
  */\r
 void ISPTarget_LoadExtendedAddress(void)\r
 {\r
  */\r
 void ISPTarget_LoadExtendedAddress(void)\r
 {\r
-       SPI_SendByte(0x4D);\r
+       SPI_SendByte(LOAD_EXTENDED_ADDRESS_CMD);\r
        SPI_SendByte(0x00);\r
        SPI_SendByte((CurrentAddress & 0x00FF0000) >> 16);\r
        SPI_SendByte(0x00);     \r
        SPI_SendByte(0x00);\r
        SPI_SendByte((CurrentAddress & 0x00FF0000) >> 16);\r
        SPI_SendByte(0x00);     \r