From 4f74075fad7f1e7a35d04ff534d9d6a57d2b97fc Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Tue, 15 Dec 2009 11:12:38 +0000 Subject: Speed up bit-banged USART code in the AVRISP project. Fix project text files to refer to "project" instead of "demo". --- Projects/AVRISP/AVRISP.txt | 16 ++++++++-------- Projects/AVRISP/Lib/NVMTarget.c | 1 - Projects/AVRISP/Lib/PDITarget.c | 41 +++++++++++++++++++++++------------------ Projects/AVRISP/makefile | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) (limited to 'Projects/AVRISP') diff --git a/Projects/AVRISP/AVRISP.txt b/Projects/AVRISP/AVRISP.txt index 2de8dd2e7..35cf93770 100644 --- a/Projects/AVRISP/AVRISP.txt +++ b/Projects/AVRISP/AVRISP.txt @@ -6,9 +6,9 @@ /** \mainpage AVRISP MKII Programmer Project * - * \section SSec_Compat Demo Compatibility: + * \section SSec_Compat Project Compatibility: * - * The following list indicates what microcontrollers are compatible with this demo. + * The following list indicates what microcontrollers are compatible with this project. * * - Series 7 USB AVRs * - Series 6 USB AVRs @@ -17,7 +17,7 @@ * * \section SSec_Info USB Information: * - * The following table gives a rundown of the USB utilization of this demo. + * The following table gives a rundown of the USB utilization of this project. * * * @@ -67,7 +67,7 @@ * While this application can be compiled for USB AVRs with as little as 8KB of FLASH, for full functionality 16KB or more * of FLASH is required. On 8KB devices, either ISP or PDI programming support can be disabled to reduce program size. * - * + * \section Sec_ISP ISP Connections * Connections to the device for SPI programming (when enabled): * *
@@ -111,7 +111,7 @@ * 1Optional, see \ref SSec_Options section - for USB AVRs with ADC modules only \n * 2See \ref SSec_Options section * - * + * \section Sec_PDI PDI Connections * Connections to the device for PDI programming1 (when enabled): * *
@@ -152,12 +152,12 @@ * *
* - * 1 When PDI_VIA_HARDWARE_USART is set, the AVR's Tx and Rx become the DATA line when connected together - * via a pair of 300 ohm resistors, and the AVR's XCK pin becomes CLOCK. + * 1 When PDI_VIA_HARDWARE_USART is set, the AVR's Tx and Rx become the DATA line when connected together + * via a pair of 300 ohm resistors, and the AVR's XCK pin becomes CLOCK. * * \section SSec_Options Project Options * - * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. + * The following defines can be found in this project, which can control the project behaviour when defined, or changed in value. * * * diff --git a/Projects/AVRISP/Lib/NVMTarget.c b/Projects/AVRISP/Lib/NVMTarget.c index 9402b2b8a..10a911ff3 100644 --- a/Projects/AVRISP/Lib/NVMTarget.c +++ b/Projects/AVRISP/Lib/NVMTarget.c @@ -182,7 +182,6 @@ bool NVMTarget_ReadMemory(uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t Re * \param[in] WriteCommand Command to send to the device to write each memory byte * \param[in] WriteAddress Start address to write to within the target's address space * \param[in] WriteBuffer Buffer to source data from - * \param[in] WriteSize Number of bytes to write * * \return Boolean true if the command sequence complete successfully */ diff --git a/Projects/AVRISP/Lib/PDITarget.c b/Projects/AVRISP/Lib/PDITarget.c index 28df55021..1bbb4d577 100644 --- a/Projects/AVRISP/Lib/PDITarget.c +++ b/Projects/AVRISP/Lib/PDITarget.c @@ -45,9 +45,8 @@ volatile bool IsSending; /** Software USART raw frame bits for transmission/reception. */ volatile uint16_t SoftUSART_Data; -/** Bits remaining to be sent or received via the software USART. */ -volatile uint8_t SoftUSART_BitCount; - +/** Bits remaining to be sent or received via the software USART - set as a GPIOR for speed. */ +#define SoftUSART_BitCount GPIOR2 /** ISR to manage the software USART when bit-banged USART mode is selected. */ ISR(TIMER1_COMPA_vect, ISR_BLOCK) @@ -59,21 +58,13 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK) if (!(SoftUSART_BitCount)) return; - /* Check to see if the current clock state is on the rising or falling edge */ - bool IsRisingEdge = (BITBANG_PDICLOCK_PORT & BITBANG_PDICLOCK_MASK); - - if (IsSending && !IsRisingEdge) - { - if (SoftUSART_Data & 0x01) - BITBANG_PDIDATA_PORT |= BITBANG_PDIDATA_MASK; - else - BITBANG_PDIDATA_PORT &= ~BITBANG_PDIDATA_MASK; - - SoftUSART_Data >>= 1; - SoftUSART_BitCount--; - } - else if (!IsSending && IsRisingEdge) + /* Check to see if we are at a rising or falling edge of the clock */ + if (BITBANG_PDICLOCK_PORT & BITBANG_PDICLOCK_MASK) { + /* If at rising clock edge and we are in send mode, abort */ + if (IsSending) + return; + /* Wait for the start bit when receiving */ if ((SoftUSART_BitCount == BITS_IN_FRAME) && (BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK)) return; @@ -84,6 +75,20 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK) SoftUSART_Data >>= 1; SoftUSART_BitCount--; } + else + { + /* If at falling clock edge and we are in receive mode, abort */ + if (!IsSending) + return; + + if (SoftUSART_Data & 0x01) + BITBANG_PDIDATA_PORT |= BITBANG_PDIDATA_MASK; + else + BITBANG_PDIDATA_PORT &= ~BITBANG_PDIDATA_MASK; + + SoftUSART_Data >>= 1; + SoftUSART_BitCount--; + } } #endif @@ -120,7 +125,7 @@ void PDITarget_EnableTargetPDI(void) asm volatile ("NOP"::); /* Fire timer compare ISR every 100 cycles to manage the software USART */ - OCR1A = 100; + OCR1A = 80; TCCR1B = (1 << WGM12) | (1 << CS10); TIMSK1 = (1 << OCIE1A); diff --git a/Projects/AVRISP/makefile b/Projects/AVRISP/makefile index 23e27c52d..2b6a1e858 100644 --- a/Projects/AVRISP/makefile +++ b/Projects/AVRISP/makefile @@ -66,7 +66,7 @@ MCU = at90usb1287 # Target board (see library "Board Types" documentation, USER or blank for projects not requiring # LUFA board drivers). If USER is selected, put custom board drivers in a directory called # "Board" inside the application directory. -BOARD = XPLAIN +BOARD = USBKEY # Processor frequency. -- cgit v1.2.3