From d1608d4af321529f0ddef9defcd97669ae9018c3 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sat, 26 Dec 2009 04:13:55 +0000 Subject: Added const where possible to the source functions in the Projects directory. Added command timeout to the AVRISP project so that incorrectly connected targets no longer freeze the device. Removed string descriptors from the TeensyHID bootloader to reduce its size. --- Projects/AVRISP/Lib/ISP/ISPProtocol.h | 11 +++++++---- Projects/AVRISP/Lib/ISP/ISPTarget.c | 30 ++++-------------------------- Projects/AVRISP/Lib/ISP/ISPTarget.h | 5 +---- 3 files changed, 12 insertions(+), 34 deletions(-) (limited to 'Projects/AVRISP/Lib/ISP') diff --git a/Projects/AVRISP/Lib/ISP/ISPProtocol.h b/Projects/AVRISP/Lib/ISP/ISPProtocol.h index 43c25c4fa..abbbf569d 100644 --- a/Projects/AVRISP/Lib/ISP/ISPProtocol.h +++ b/Projects/AVRISP/Lib/ISP/ISPProtocol.h @@ -72,17 +72,20 @@ */ static inline void ISPProtocol_DelayMS(uint8_t DelayMS) { - TCNT0 = 0; - TIFR0 = (1 << OCF1A); + OCR2A = ((F_CPU / 64) / 1000); + TCCR2A = (1 << WGM01); + TCCR2B = ((1 << CS01) | (1 << CS00)); while (DelayMS) { - if (TIFR0 & (1 << OCF1A)) + if (TIFR2 & (1 << OCF2A)) { - TIFR0 = (1 << OCF1A); + TIFR2 = (1 << OCF2A); DelayMS--; } } + + TCCR2B = 0; } /* Function Prototypes: */ diff --git a/Projects/AVRISP/Lib/ISP/ISPTarget.c b/Projects/AVRISP/Lib/ISP/ISPTarget.c index e99e3e53c..29cb18e62 100644 --- a/Projects/AVRISP/Lib/ISP/ISPTarget.c +++ b/Projects/AVRISP/Lib/ISP/ISPTarget.c @@ -122,26 +122,15 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1 break; 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); - - if (TIFR0 & (1 << OCF1A)) - { - TIFR0 = (1 << OCF1A); - TimeoutMS--; - } } - while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMS); + while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMSRemaining); - if (!(TimeoutMS)) + if (!(TimeoutMSRemaining)) ProgrammingStatus = STATUS_CMD_TOUT; break; @@ -161,27 +150,16 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1 */ uint8_t ISPTarget_WaitWhileTargetBusy(void) { - TCNT0 = 0; - TIFR0 = (1 << OCF1A); - - uint8_t TimeoutMS = TARGET_BUSY_TIMEOUT_MS; - do { SPI_SendByte(0xF0); SPI_SendByte(0x00); SPI_SendByte(0x00); - - if (TIFR0 & (1 << OCF1A)) - { - TIFR0 = (1 << OCF1A); - TimeoutMS--; - } } - while ((SPI_ReceiveByte() & 0x01) && TimeoutMS); + while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining); - if (!(TimeoutMS)) + if (!(TimeoutMSRemaining)) return STATUS_RDY_BSY_TOUT; else return STATUS_CMD_OK; diff --git a/Projects/AVRISP/Lib/ISP/ISPTarget.h b/Projects/AVRISP/Lib/ISP/ISPTarget.h index 96f1a6476..c856ddde1 100644 --- a/Projects/AVRISP/Lib/ISP/ISPTarget.h +++ b/Projects/AVRISP/Lib/ISP/ISPTarget.h @@ -57,10 +57,7 @@ /* Macros: */ /** Total number of allowable ISP programming speeds supported by the device */ #define TOTAL_ISP_PROGRAMMING_SPEEDS 7 - - /** Timeout in milliseconds of target busy-wait loops waiting for a command to complete */ - #define TARGET_BUSY_TIMEOUT_MS 100 - + /* Function Prototypes: */ uint8_t ISPTarget_GetSPIPrescalerMask(void); void ISPTarget_ChangeTargetResetLine(const bool ResetTarget); -- cgit v1.2.3