Reverted AVRISP-MKII clone project watchdog based command timeout patch in favour...
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 1 Apr 2012 13:39:04 +0000 (13:39 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 1 Apr 2012 13:39:04 +0000 (13:39 +0000)
LUFA/DoxygenPages/ChangeLog.txt
Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c
Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c
Projects/AVRISP-MKII/Lib/V2Protocol.c
Projects/AVRISP-MKII/Lib/V2Protocol.h
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c

index 48dec12..3cab967 100644 (file)
@@ -22,6 +22,7 @@
   *  - Library Applications:
   *   - Raised the guard bits in the AVRISP-MKII clone project when in PDI and TPI to 32, to prevent communication errors on low quality connections to a target
   *   - Added additional bootloader API data to expose the bootloader start address and class to the DFU and CDC class bootloaders
   *  - Library Applications:
   *   - Raised the guard bits in the AVRISP-MKII clone project when in PDI and TPI to 32, to prevent communication errors on low quality connections to a target
   *   - Added additional bootloader API data to expose the bootloader start address and class to the DFU and CDC class bootloaders
+  *   - Reverted AVRISP-MKII clone project watchdog based command timeout patch in favour of a hardware timer, to allow for use in devices with WDTRST fuse programmed
   *
   *  <b>Fixed:</b>
   *  - Core:
   *
   *  <b>Fixed:</b>
   *  - Core:
index ada9541..f757ac1 100644 (file)
@@ -73,7 +73,7 @@ void ISPProtocol_EnterISPMode(void)
 
        /* Continuously attempt to synchronize with the target until either the number of attempts specified
         * by the host has exceeded, or the the device sends back the expected response values */
 
        /* Continuously attempt to synchronize with the target until either the number of attempts specified
         * by the host has exceeded, or the the device sends back the expected response values */
-       while (Enter_ISP_Params.SynchLoops-- && !(TimeoutExpired))
+       while (Enter_ISP_Params.SynchLoops-- && TimeoutTicksRemaining)
        {
                uint8_t ResponseBytes[4];
 
        {
                uint8_t ResponseBytes[4];
 
@@ -523,7 +523,7 @@ void ISPProtocol_SPIMulti(void)
  */
 void ISPProtocol_DelayMS(uint8_t DelayMS)
 {
  */
 void ISPProtocol_DelayMS(uint8_t DelayMS)
 {
-       while (DelayMS-- && !(TimeoutExpired))
+       while (DelayMS-- && TimeoutTicksRemaining)
          Delay_MS(1);
 }
 
          Delay_MS(1);
 }
 
index e2b2301..b77c180 100644 (file)
@@ -254,7 +254,7 @@ uint8_t ISPTarget_TransferSoftSPIByte(const uint8_t Byte)
 
        TCNT1  = 0;
        TCCR1B = ((1 << WGM12) | (1 << CS11));
 
        TCNT1  = 0;
        TCCR1B = ((1 << WGM12) | (1 << CS11));
-       while (SoftSPI_BitsRemaining && !(TimeoutExpired));
+       while (SoftSPI_BitsRemaining && TimeoutTicksRemaining);
        TCCR1B = 0;
 
        return SoftSPI_Data;
        TCCR1B = 0;
 
        return SoftSPI_Data;
@@ -296,9 +296,9 @@ uint8_t ISPTarget_WaitWhileTargetBusy(void)
                ISPTarget_SendByte(0x00);
                ISPTarget_SendByte(0x00);
        }
                ISPTarget_SendByte(0x00);
                ISPTarget_SendByte(0x00);
        }
-       while ((ISPTarget_ReceiveByte() & 0x01) && !(TimeoutExpired));
+       while ((ISPTarget_ReceiveByte() & 0x01) && TimeoutTicksRemaining);
 
 
-       return (TimeoutExpired) ? STATUS_RDY_BSY_TOUT : STATUS_CMD_OK;
+       return (TimeoutTicksRemaining > 0) ? STATUS_CMD_OK : STATUS_RDY_BSY_TOUT;
 }
 
 /** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the
 }
 
 /** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the
@@ -348,10 +348,10 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode,
                                ISPTarget_SendByte(PollAddress >> 8);
                                ISPTarget_SendByte(PollAddress & 0xFF);
                        }
                                ISPTarget_SendByte(PollAddress >> 8);
                                ISPTarget_SendByte(PollAddress & 0xFF);
                        }
-                       while ((ISPTarget_TransferByte(0x00) == PollValue) && !(TimeoutExpired));
+                       while ((ISPTarget_TransferByte(0x00) == PollValue) && TimeoutTicksRemaining);
 
 
-                       if (TimeoutExpired)
-                        ProgrammingStatus = STATUS_CMD_TOUT;
+                       if (!(TimeoutTicksRemaining))
+                         ProgrammingStatus = STATUS_CMD_TOUT;
 
                        break;
                case PROG_MODE_WORD_READYBUSY_MASK:
 
                        break;
                case PROG_MODE_WORD_READYBUSY_MASK:
index 780c48a..f485810 100644 (file)
@@ -44,10 +44,12 @@ bool MustLoadExtendedAddress;
 
 
 /** ISR to manage timeouts whilst processing a V2Protocol command */
 
 
 /** ISR to manage timeouts whilst processing a V2Protocol command */
-ISR(WDT_vect, ISR_BLOCK)
+ISR(TIMER0_COMPA_vect, ISR_NOBLOCK)
 {
 {
-       TimeoutExpired = true;
-       wdt_disable();
+       if (TimeoutTicksRemaining)
+         TimeoutTicksRemaining--;
+       else
+         TCCR0B = 0;
 }
 
 /** Initializes the hardware and software associated with the V2 protocol command handling. */
 }
 
 /** Initializes the hardware and software associated with the V2 protocol command handling. */
@@ -60,6 +62,11 @@ void V2Protocol_Init(void)
        ADC_StartReading(VTARGET_REF_MASK | ADC_RIGHT_ADJUSTED | VTARGET_ADC_CHANNEL_MASK);
        #endif
 
        ADC_StartReading(VTARGET_REF_MASK | ADC_RIGHT_ADJUSTED | VTARGET_ADC_CHANNEL_MASK);
        #endif
 
+       /* Timeout timer initialization (~10ms period) */
+       OCR0A  = (((F_CPU / 1024) / 100) - 1);
+       TCCR0A = (1 << WGM01);
+       TIMSK0 = (1 << OCIE0A);
+
        V2Params_LoadNonVolatileParamValues();
 
        #if defined(ENABLE_ISP_PROTOCOL)
        V2Params_LoadNonVolatileParamValues();
 
        #if defined(ENABLE_ISP_PROTOCOL)
@@ -75,10 +82,9 @@ void V2Protocol_ProcessCommand(void)
 {
        uint8_t V2Command = Endpoint_Read_8();
 
 {
        uint8_t V2Command = Endpoint_Read_8();
 
-       /* Start the watchdog with timeout interrupt enabled to manage the timeout */
-       TimeoutExpired = false;
-       wdt_enable(WDTO_1S);
-       WDTCSR |= (1 << WDIE);
+       /* Reset timeout counter duration and start the timer */
+       TimeoutTicksRemaining = COMMAND_TIMEOUT_TICKS;
+       TCCR0B = ((1 << CS02) | (1 << CS00));   
 
        switch (V2Command)
        {
 
        switch (V2Command)
        {
@@ -140,8 +146,8 @@ void V2Protocol_ProcessCommand(void)
                        break;
        }
 
                        break;
        }
 
-       /* Disable the timeout management watchdog timer */
-       wdt_disable();
+       /* Disable the timeout management timer */
+       TCCR0B = 0;
 
        Endpoint_WaitUntilReady();
        Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPNUM);
 
        Endpoint_WaitUntilReady();
        Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPNUM);
index 59d61b4..dca97cb 100644 (file)
@@ -78,8 +78,8 @@
                /** Timeout period for each issued command from the host before it is aborted (in 10ms ticks). */
                #define COMMAND_TIMEOUT_TICKS      100
 
                /** Timeout period for each issued command from the host before it is aborted (in 10ms ticks). */
                #define COMMAND_TIMEOUT_TICKS      100
 
-               /** Command timeout expiration flag, GPIOR for speed. */
-               #define TimeoutExpired             GPIOR1
+               /** Command timeout ticks remaining counter, GPIOR for speed. */
+               #define TimeoutTicksRemaining      GPIOR1
 
                /** MUX mask for the VTARGET ADC channel number. */
                #define VTARGET_ADC_CHANNEL_MASK   ADC_GET_CHANNEL_MASK(VTARGET_ADC_CHANNEL)
 
                /** MUX mask for the VTARGET ADC channel number. */
                #define VTARGET_ADC_CHANNEL_MASK   ADC_GET_CHANNEL_MASK(VTARGET_ADC_CHANNEL)
index b883237..df0374d 100644 (file)
@@ -85,7 +85,7 @@ bool TINYNVM_WaitWhileNVMBusBusy(void)
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
-               if (TimeoutExpired)
+               if (!(TimeoutTicksRemaining))
                  return false;
 
                /* Check the status register read response to see if the NVM bus is enabled */
                  return false;
 
                /* Check the status register read response to see if the NVM bus is enabled */
@@ -110,7 +110,7 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
-               if (TimeoutExpired)
+               if (!(TimeoutTicksRemaining))
                  return false;
 
                /* Check to see if the BUSY flag is still set */
                  return false;
 
                /* Check to see if the BUSY flag is still set */
@@ -182,14 +182,14 @@ bool TINYNVM_ReadMemory(const uint16_t ReadAddress,
        /* Send the address of the location to read from */
        TINYNVM_SendPointerAddress(ReadAddress);
 
        /* Send the address of the location to read from */
        TINYNVM_SendPointerAddress(ReadAddress);
 
-       while (ReadSize-- && !(TimeoutExpired))
+       while (ReadSize-- && TimeoutTicksRemaining)
        {
                /* Read the byte of data from the target */
                XPROGTarget_SendByte(TPI_CMD_SLD | TPI_POINTER_INDIRECT_PI);
                *(ReadBuffer++) = XPROGTarget_ReceiveByte();
        }
 
        {
                /* Read the byte of data from the target */
                XPROGTarget_SendByte(TPI_CMD_SLD | TPI_POINTER_INDIRECT_PI);
                *(ReadBuffer++) = XPROGTarget_ReceiveByte();
        }
 
-       return (TimeoutExpired == false);
+       return (TimeoutTicksRemaining > 0);
 }
 
 /** Writes word addressed memory to the target's memory spaces.
 }
 
 /** Writes word addressed memory to the target's memory spaces.
index e1169d5..97154ea 100644 (file)
@@ -80,7 +80,7 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
-               if (TimeoutExpired)
+               if (!(TimeoutTicksRemaining))
                  return false;
 
                /* Check the status register read response to see if the NVM bus is enabled */
                  return false;
 
                /* Check the status register read response to see if the NVM bus is enabled */
@@ -109,7 +109,7 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void)
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
                uint8_t StatusRegister = XPROGTarget_ReceiveByte();
 
                /* We might have timed out waiting for the status register read response, check here */
-               if (TimeoutExpired)
+               if (!(TimeoutTicksRemaining))
                  return false;
 
                /* Check to see if the BUSY flag is still set */
                  return false;
 
                /* Check to see if the BUSY flag is still set */
@@ -209,7 +209,7 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest)
        for (uint8_t i = 0; i < XMEGA_CRC_LENGTH_BYTES; i++)
          ((uint8_t*)CRCDest)[i] = XPROGTarget_ReceiveByte();
 
        for (uint8_t i = 0; i < XMEGA_CRC_LENGTH_BYTES; i++)
          ((uint8_t*)CRCDest)[i] = XPROGTarget_ReceiveByte();
 
-       return (TimeoutExpired == false);
+       return (TimeoutTicksRemaining > 0);
 }
 
 /** Reads memory from the target's memory spaces.
 }
 
 /** Reads memory from the target's memory spaces.
@@ -241,10 +241,10 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16
 
        /* Send a LD command with indirect access and post-increment to read out the bytes */
        XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);
 
        /* Send a LD command with indirect access and post-increment to read out the bytes */
        XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);
-       while (ReadSize-- && !(TimeoutExpired))
+       while (ReadSize-- && TimeoutTicksRemaining)
          *(ReadBuffer++) = XPROGTarget_ReceiveByte();
 
          *(ReadBuffer++) = XPROGTarget_ReceiveByte();
 
-       return (TimeoutExpired == false);
+       return (TimeoutTicksRemaining > 0);
 }
 
 /** Writes byte addressed memory to the target's memory spaces.
 }
 
 /** Writes byte addressed memory to the target's memory spaces.
index b50ffbd..b2f5552 100644 (file)
@@ -153,7 +153,7 @@ uint8_t XPROGTarget_ReceiveByte(void)
          XPROGTarget_SetRxMode();
 
        /* Wait until a byte has been received before reading */
          XPROGTarget_SetRxMode();
 
        /* Wait until a byte has been received before reading */
-       while (!(UCSR1A & (1 << RXC1)) && !(TimeoutExpired));
+       while (!(UCSR1A & (1 << RXC1)) && TimeoutTicksRemaining);
 
        return UDR1;
 }
 
        return UDR1;
 }