More fixes to the AVRISP command timeout system so that it should no longer lock up while processing command no matter what the conditions.

pull/1469/head
Dean Camera 15 years ago
parent 12a01ed72d
commit e322f14620

@ -75,7 +75,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 */
while (Enter_ISP_Params.SynchLoops-- && (ResponseStatus == STATUS_CMD_FAILED))
while (Enter_ISP_Params.SynchLoops-- && (ResponseStatus == STATUS_CMD_FAILED) && TimeoutMSRemaining)
{
uint8_t ResponseBytes[4];
@ -518,4 +518,19 @@ void ISPProtocol_SPIMulti(void)
}
}
/** Blocking delay for a given number of milliseconds.
*
* \param[in] DelayMS Number of milliseconds to delay for
*/
void ISPProtocol_DelayMS(uint8_t DelayMS)
{
while (DelayMS-- && TimeoutMSRemaining)
{
if (TimeoutMSRemaining)
TimeoutMSRemaining--;
_delay_ms(1);
}
}
#endif

@ -66,17 +66,6 @@
#define PROG_MODE_PAGED_READYBUSY_MASK (1 << 6)
#define PROG_MODE_COMMIT_PAGE_MASK (1 << 7)
/* Inline Functions: */
/** Blocking delay for a given number of milliseconds.
*
* \param[in] DelayMS Number of milliseconds to delay for
*/
static inline void ISPProtocol_DelayMS(uint8_t DelayMS)
{
while (DelayMS--)
_delay_ms(1);
}
/* Function Prototypes: */
void ISPProtocol_EnterISPMode(void);
void ISPProtocol_LeaveISPMode(void);
@ -86,5 +75,5 @@
void ISPProtocol_ReadFuseLockSigOSCCAL(const uint8_t V2Command);
void ISPProtocol_WriteFuseLock(const uint8_t V2Command);
void ISPProtocol_SPIMulti(void);
void ISPProtocol_DelayMS(uint8_t DelayMS);
#endif

@ -112,7 +112,6 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
const uint8_t DelayMS, const uint8_t ReadMemCommand)
{
uint8_t ProgrammingStatus = STATUS_CMD_OK;
uint8_t TimeoutMSRemaining = 100;
/* Determine method of Programming Complete check */
switch (ProgrammingMode & ~(PROG_MODE_PAGED_WRITES_MASK | PROG_MODE_COMMIT_PAGE_MASK))
@ -148,6 +147,9 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
break;
}
if (ProgrammingStatus == STATUS_CMD_OK)
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return ProgrammingStatus;
}
@ -158,8 +160,6 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
*/
uint8_t ISPTarget_WaitWhileTargetBusy(void)
{
uint8_t TimeoutMSRemaining = 100;
do
{
/* Manage software timeout */
@ -175,7 +175,15 @@ uint8_t ISPTarget_WaitWhileTargetBusy(void)
}
while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);
return ((TimeoutMSRemaining) ? STATUS_CMD_OK : STATUS_RDY_BSY_TOUT);
if (TimeoutMSRemaining)
{
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return STATUS_CMD_OK;
}
else
{
return STATUS_RDY_BSY_TOUT;
}
}
/** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the

@ -42,8 +42,6 @@ uint32_t CurrentAddress;
/** Flag to indicate that the next read/write operation must update the device's current address */
bool MustSetAddress;
bool CommandTimedOut;
/** Initializes the hardware and software associated with the V2 protocol command handling. */
void V2Protocol_Init(void)
{
@ -70,7 +68,7 @@ void V2Protocol_ProcessCommand(void)
{
uint8_t V2Command = Endpoint_Read_Byte();
CommandTimedOut = false;
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
switch (V2Command)
{

@ -64,6 +64,12 @@
/** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */
#define PROGRAMMER_ID "AVRISP_MK2"
/** Timeout period for each issued command from the host before it is aborted */
#define COMMAND_TIMEOUT_MS 200
/** Command timeout counter register, GPIOR for speed */
#define TimeoutMSRemaining GPIOR0
/** MUX mask for the VTARGET ADC channel number */
#define VTARGET_ADC_CHANNEL_MASK _GETADCMUXMASK(ADC_CHANNEL, VTARGET_ADC_CHANNEL)

@ -77,13 +77,15 @@ static void TINYNVM_SendWriteNVMRegister(const uint8_t Address)
bool TINYNVM_WaitWhileNVMBusBusy(void)
{
/* Poll the STATUS register to check to see if NVM access has been enabled */
uint8_t TimeoutMSRemaining = 100;
while (TimeoutMSRemaining)
{
/* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */
XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);
if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)
return true;
{
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return true;
}
/* Manage software timeout */
if (TIFR0 & (1 << OCF0A))
@ -104,7 +106,6 @@ bool TINYNVM_WaitWhileNVMBusBusy(void)
bool TINYNVM_WaitWhileNVMControllerBusy(void)
{
/* Poll the STATUS register to check to see if NVM access has been enabled */
uint8_t TimeoutMSRemaining = 100;
while (TimeoutMSRemaining)
{
/* Send the SIN command to read the TPI STATUS register to see the NVM bus is busy */
@ -112,7 +113,10 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
/* Check to see if the BUSY flag is still set */
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))
return true;
{
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return true;
}
/* Manage software timeout */
if (TIFR0 & (1 << OCF0A))

@ -72,13 +72,15 @@ static void XMEGANVM_SendNVMRegAddress(const uint8_t Register)
bool XMEGANVM_WaitWhileNVMBusBusy(void)
{
/* Poll the STATUS register to check to see if NVM access has been enabled */
uint8_t TimeoutMSRemaining = 100;
while (TimeoutMSRemaining)
{
/* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */
XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);
if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)
return true;
{
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return true;
}
/* Manage software timeout */
if (TIFR0 & (1 << OCF0A))
@ -99,7 +101,6 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
bool XMEGANVM_WaitWhileNVMControllerBusy(void)
{
/* Poll the NVM STATUS register while the NVM controller is busy */
uint8_t TimeoutMSRemaining = 100;
while (TimeoutMSRemaining)
{
/* Send a LDS command to read the NVM STATUS register to check the BUSY flag */
@ -108,7 +109,10 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void)
/* Check to see if the BUSY flag is still set */
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))
return true;
{
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return true;
}
/* Manage software timeout */
if (TIFR0 & (1 << OCF0A))

@ -350,7 +350,6 @@ uint8_t XPROGTarget_ReceiveByte(void)
#if defined(XPROG_VIA_HARDWARE_USART)
/* Wait until a byte has been received before reading */
uint8_t TimeoutMSRemaining = 100;
while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining)
{
/* Manage software timeout */
@ -365,7 +364,6 @@ uint8_t XPROGTarget_ReceiveByte(void)
#else
/* Wait until a byte has been received before reading */
SoftUSART_BitCount = BITS_IN_USART_FRAME;
uint8_t TimeoutMSRemaining = 100;
while (SoftUSART_BitCount && TimeoutMSRemaining)
{
/* Manage software timeout */
@ -376,6 +374,9 @@ uint8_t XPROGTarget_ReceiveByte(void)
}
}
if (TimeoutMSRemaining)
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
/* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */
return (uint8_t)SoftUSART_Data;
#endif
@ -468,7 +469,6 @@ static void XPROGTarget_SetRxMode(void)
}
/* Wait until DATA line has been pulled up to idle by the target */
uint8_t TimeoutMSRemaining = 100;
while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK) && TimeoutMSRemaining)
{
/* Manage software timeout */
@ -480,6 +480,9 @@ static void XPROGTarget_SetRxMode(void)
}
#endif
if (TimeoutMSRemaining)
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
IsSending = false;
}

Loading…
Cancel
Save