\r
/* Continuously attempt to synchronize with the target until either the number of attempts specified\r
* by the host has exceeded, or the the device sends back the expected response values */\r
- while (Enter_ISP_Params.SynchLoops-- && (ResponseStatus == STATUS_CMD_FAILED))\r
+ while (Enter_ISP_Params.SynchLoops-- && (ResponseStatus == STATUS_CMD_FAILED) && TimeoutMSRemaining)\r
{\r
uint8_t ResponseBytes[4];\r
\r
}\r
}\r
\r
+/** Blocking delay for a given number of milliseconds.\r
+ *\r
+ * \param[in] DelayMS Number of milliseconds to delay for\r
+ */\r
+void ISPProtocol_DelayMS(uint8_t DelayMS)\r
+{\r
+ while (DelayMS-- && TimeoutMSRemaining)\r
+ {\r
+ if (TimeoutMSRemaining)\r
+ TimeoutMSRemaining--;\r
+ \r
+ _delay_ms(1);\r
+ }\r
+}\r
+\r
#endif
\ No newline at end of file
#define PROG_MODE_PAGED_READYBUSY_MASK (1 << 6)\r
#define PROG_MODE_COMMIT_PAGE_MASK (1 << 7)\r
\r
- /* Inline Functions: */\r
- /** Blocking delay for a given number of milliseconds.\r
- *\r
- * \param[in] DelayMS Number of milliseconds to delay for\r
- */\r
- static inline void ISPProtocol_DelayMS(uint8_t DelayMS)\r
- {\r
- while (DelayMS--)\r
- _delay_ms(1);\r
- }\r
-\r
/* Function Prototypes: */\r
void ISPProtocol_EnterISPMode(void);\r
void ISPProtocol_LeaveISPMode(void);\r
void ISPProtocol_ReadFuseLockSigOSCCAL(const uint8_t V2Command);\r
void ISPProtocol_WriteFuseLock(const uint8_t V2Command);\r
void ISPProtocol_SPIMulti(void);\r
-\r
+ void ISPProtocol_DelayMS(uint8_t DelayMS);\r
#endif\r
const uint8_t DelayMS, const uint8_t ReadMemCommand)\r
{\r
uint8_t ProgrammingStatus = STATUS_CMD_OK;\r
- uint8_t TimeoutMSRemaining = 100;\r
\r
/* Determine method of Programming Complete check */\r
switch (ProgrammingMode & ~(PROG_MODE_PAGED_WRITES_MASK | PROG_MODE_COMMIT_PAGE_MASK))\r
break;\r
}\r
\r
+ if (ProgrammingStatus == STATUS_CMD_OK)\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+\r
return ProgrammingStatus;\r
}\r
\r
*/\r
uint8_t ISPTarget_WaitWhileTargetBusy(void)\r
{\r
- uint8_t TimeoutMSRemaining = 100;\r
-\r
do\r
{\r
/* Manage software timeout */\r
}\r
while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);\r
\r
- return ((TimeoutMSRemaining) ? STATUS_CMD_OK : STATUS_RDY_BSY_TOUT);\r
+ if (TimeoutMSRemaining)\r
+ {\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+ return STATUS_CMD_OK;\r
+ }\r
+ else\r
+ {\r
+ return STATUS_RDY_BSY_TOUT;\r
+ }\r
}\r
\r
/** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the\r
/** Flag to indicate that the next read/write operation must update the device's current address */\r
bool MustSetAddress;\r
\r
-bool CommandTimedOut;\r
-\r
/** Initializes the hardware and software associated with the V2 protocol command handling. */\r
void V2Protocol_Init(void)\r
{\r
{\r
uint8_t V2Command = Endpoint_Read_Byte();\r
\r
- CommandTimedOut = false;\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
\r
switch (V2Command)\r
{\r
/** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */\r
#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 GPIOR0\r
+\r
/** MUX mask for the VTARGET ADC channel number */\r
#define VTARGET_ADC_CHANNEL_MASK _GETADCMUXMASK(ADC_CHANNEL, VTARGET_ADC_CHANNEL)\r
\r
bool TINYNVM_WaitWhileNVMBusBusy(void)\r
{\r
/* Poll the STATUS register to check to see if NVM access has been enabled */\r
- uint8_t TimeoutMSRemaining = 100;\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
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+ return true;\r
+ }\r
\r
/* Manage software timeout */\r
if (TIFR0 & (1 << OCF0A))\r
bool TINYNVM_WaitWhileNVMControllerBusy(void)\r
{\r
/* Poll the STATUS register to check to see if NVM access has been enabled */\r
- uint8_t TimeoutMSRemaining = 100;\r
while (TimeoutMSRemaining)\r
{\r
/* Send the SIN command to read the TPI STATUS register to see the NVM bus is busy */\r
\r
/* Check to see if the BUSY flag is still set */\r
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
- return true;\r
+ {\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+ return true;\r
+ }\r
\r
/* Manage software timeout */\r
if (TIFR0 & (1 << OCF0A))\r
bool XMEGANVM_WaitWhileNVMBusBusy(void)\r
{\r
/* Poll the STATUS register to check to see if NVM access has been enabled */\r
- uint8_t TimeoutMSRemaining = 100;\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
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+ return true;\r
+ }\r
\r
/* Manage software timeout */\r
if (TIFR0 & (1 << OCF0A))\r
bool XMEGANVM_WaitWhileNVMControllerBusy(void)\r
{\r
/* Poll the NVM STATUS register while the NVM controller is busy */\r
- uint8_t TimeoutMSRemaining = 100;\r
while (TimeoutMSRemaining)\r
{\r
/* Send a LDS command to read the NVM STATUS register to check the BUSY flag */\r
\r
/* Check to see if the BUSY flag is still set */\r
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
- return true;\r
+ {\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+ return true;\r
+ }\r
\r
/* Manage software timeout */\r
if (TIFR0 & (1 << OCF0A))\r
\r
#if defined(XPROG_VIA_HARDWARE_USART)\r
/* Wait until a byte has been received before reading */\r
- uint8_t TimeoutMSRemaining = 100;\r
while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining)\r
{\r
/* Manage software timeout */\r
#else\r
/* Wait until a byte has been received before reading */\r
SoftUSART_BitCount = BITS_IN_USART_FRAME;\r
- uint8_t TimeoutMSRemaining = 100;\r
while (SoftUSART_BitCount && TimeoutMSRemaining)\r
{\r
/* Manage software timeout */\r
}\r
}\r
\r
+ if (TimeoutMSRemaining)\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\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
}\r
\r
/* Wait until DATA line has been pulled up to idle by the target */\r
- uint8_t TimeoutMSRemaining = 100;\r
while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK) && TimeoutMSRemaining)\r
{\r
/* Manage software timeout */\r
} \r
#endif\r
\r
+ if (TimeoutMSRemaining)\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+\r
IsSending = false;\r
}\r
\r