diff options
Diffstat (limited to 'Projects')
-rw-r--r-- | Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c | 17 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.h | 13 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c | 16 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/V2Protocol.c | 4 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/V2Protocol.h | 6 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c | 12 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c | 12 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c | 9 |
8 files changed, 58 insertions, 31 deletions
diff --git a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c index e0eb44107..85b31fbdb 100644 --- a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c +++ b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c @@ -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
\ No newline at end of file diff --git a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.h b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.h index 88e35348d..a9114e1e8 100644 --- a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.h +++ b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.h @@ -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
diff --git a/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c b/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c index 51ba1ec97..94f1c3d74 100644 --- a/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c +++ b/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c @@ -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
diff --git a/Projects/AVRISP-MKII/Lib/V2Protocol.c b/Projects/AVRISP-MKII/Lib/V2Protocol.c index f7e5e8102..3df8045aa 100644 --- a/Projects/AVRISP-MKII/Lib/V2Protocol.c +++ b/Projects/AVRISP-MKII/Lib/V2Protocol.c @@ -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)
{
diff --git a/Projects/AVRISP-MKII/Lib/V2Protocol.h b/Projects/AVRISP-MKII/Lib/V2Protocol.h index 97fea471b..26c42ab75 100644 --- a/Projects/AVRISP-MKII/Lib/V2Protocol.h +++ b/Projects/AVRISP-MKII/Lib/V2Protocol.h @@ -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)
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c index 428469df7..a894793c7 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c @@ -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))
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c index 6ef59db37..f63f13a97 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c @@ -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))
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c index 45c1d225d..7bef25e6e 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c @@ -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;
}
|