X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/258a6a01777afadbf6913246f12a7106b421b795..24f730fce3f2022762011d795c3feada5ef874b3:/Projects/AVRISP/Lib/ISPTarget.c diff --git a/Projects/AVRISP/Lib/ISPTarget.c b/Projects/AVRISP/Lib/ISPTarget.c index f2b57343f..ce364c6cc 100644 --- a/Projects/AVRISP/Lib/ISPTarget.c +++ b/Projects/AVRISP/Lib/ISPTarget.c @@ -28,8 +28,6 @@ this software. */ -#if defined(ENABLE_ISP_PROTOCOL) - /** \file * * Target-related functions for the ISP Protocol decoder. @@ -37,6 +35,8 @@ #include "ISPTarget.h" +#if defined(ENABLE_ISP_PROTOCOL) || defined(__DOXYGEN__) + /** Converts the given AVR Studio SCK duration parameter (set by a SET PARAM command from the host) to the nearest * possible SPI clock prescaler mask for passing to the SPI_Init() routine. * @@ -80,7 +80,7 @@ uint8_t ISPTarget_GetSPIPrescalerMask(void) * * \param[in] ResetTarget Boolean true when the target should be held in reset, false otherwise */ -void ISPTarget_ChangeTargetResetLine(bool ResetTarget) +void ISPTarget_ChangeTargetResetLine(const bool ResetTarget) { if (ResetTarget) { @@ -108,8 +108,8 @@ void ISPTarget_ChangeTargetResetLine(bool ResetTarget) * \return V2 Protocol status \ref STATUS_CMD_OK if the no timeout occurred, \ref STATUS_RDY_BSY_TOUT or * \ref STATUS_CMD_TOUT otherwise */ -uint8_t ISPTarget_WaitForProgComplete(uint8_t ProgrammingMode, uint16_t PollAddress, uint8_t PollValue, - uint8_t DelayMS, uint8_t ReadMemCommand) +uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint16_t PollAddress, const uint8_t PollValue, + const uint8_t DelayMS, const uint8_t ReadMemCommand) { uint8_t ProgrammingStatus = STATUS_CMD_OK; @@ -123,16 +123,25 @@ uint8_t ISPTarget_WaitForProgComplete(uint8_t ProgrammingMode, uint16_t PollAddr case PROG_MODE_WORD_VALUE_MASK: case PROG_MODE_PAGED_VALUE_MASK: TCNT0 = 0; + TIFR0 = (1 << OCF1A); + + uint8_t TimeoutMS = TARGET_BUSY_TIMEOUT_MS; do { SPI_SendByte(ReadMemCommand); SPI_SendByte(PollAddress >> 8); - SPI_SendByte(PollAddress & 0xFF); + SPI_SendByte(PollAddress & 0xFF); + + if (TIFR0 & (1 << OCF1A)) + { + TIFR0 = (1 << OCF1A); + TimeoutMS--; + } } - while ((SPI_TransferByte(0x00) != PollValue) && (TCNT0 < TARGET_BUSY_TIMEOUT_MS)); + while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMS); - if (TCNT0 >= TARGET_BUSY_TIMEOUT_MS) + if (!(TimeoutMS)) ProgrammingStatus = STATUS_CMD_TOUT; break; @@ -153,6 +162,9 @@ uint8_t ISPTarget_WaitForProgComplete(uint8_t ProgrammingMode, uint16_t PollAddr uint8_t ISPTarget_WaitWhileTargetBusy(void) { TCNT0 = 0; + TIFR0 = (1 << OCF1A); + + uint8_t TimeoutMS = TARGET_BUSY_TIMEOUT_MS; do { @@ -160,10 +172,16 @@ uint8_t ISPTarget_WaitWhileTargetBusy(void) SPI_SendByte(0x00); SPI_SendByte(0x00); + + if (TIFR0 & (1 << OCF1A)) + { + TIFR0 = (1 << OCF1A); + TimeoutMS--; + } } - while ((SPI_ReceiveByte() & 0x01) && (TCNT0 < TARGET_BUSY_TIMEOUT_MS)); + while ((SPI_ReceiveByte() & 0x01) && TimeoutMS); - if (TCNT0 >= TARGET_BUSY_TIMEOUT_MS) + if (!(TimeoutMS)) return STATUS_RDY_BSY_TOUT; else return STATUS_CMD_OK;