From d1608d4af321529f0ddef9defcd97669ae9018c3 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sat, 26 Dec 2009 04:13:55 +0000 Subject: [PATCH] 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. --- Bootloaders/TeensyHID/Descriptors.c | 2 +- LUFA/ManPages/ChangeLog.txt | 3 ++ LUFA/ManPages/LUFAPoweredProjects.txt | 2 +- Projects/AVRISP/AVRISP.c | 2 +- Projects/AVRISP/Lib/ISP/ISPProtocol.h | 11 +++-- Projects/AVRISP/Lib/ISP/ISPTarget.c | 30 ++---------- Projects/AVRISP/Lib/ISP/ISPTarget.h | 5 +- Projects/AVRISP/Lib/V2Protocol.c | 14 +++++- Projects/AVRISP/Lib/V2Protocol.h | 11 +++-- Projects/AVRISP/Lib/V2ProtocolParams.c | 40 ++++++++-------- Projects/AVRISP/Lib/V2ProtocolParams.h | 2 +- Projects/AVRISP/Lib/XPROG/TINYNVM.c | 14 +----- Projects/AVRISP/Lib/XPROG/TINYNVM.h | 8 +++- Projects/AVRISP/Lib/XPROG/XMEGANVM.c | 54 +++++++--------------- Projects/AVRISP/Lib/XPROG/XMEGANVM.h | 6 +-- Projects/AVRISP/Lib/XPROG/XPROGProtocol.c | 3 +- Projects/AVRISP/Lib/XPROG/XPROGTarget.c | 10 ++-- Projects/AVRISP/Lib/XPROG/XPROGTarget.h | 2 + Projects/MissileLauncher/MissileLauncher.c | 14 ++---- Projects/MissileLauncher/MissileLauncher.h | 6 +-- 20 files changed, 102 insertions(+), 137 deletions(-) diff --git a/Bootloaders/TeensyHID/Descriptors.c b/Bootloaders/TeensyHID/Descriptors.c index 791269cbca..65a8d11b61 100644 --- a/Bootloaders/TeensyHID/Descriptors.c +++ b/Bootloaders/TeensyHID/Descriptors.c @@ -152,7 +152,7 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor = */ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) { - const uint8_t DescriptorType = (wValue >> 8); + const uint8_t DescriptorType = (wValue >> 8); void* Address = NULL; uint16_t Size = NO_DESCRIPTOR; diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index 17702b663b..48361e3075 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -10,8 +10,11 @@ * * New: * - Added TPI programming support for 6-pin ATTINY to the AVRISP programmer project + * - Added command timeout counter to the AVRISP project so that the device no longer freezes when incorrectly connected + * to a target * * Changed: + * - Slowed down bit-banged PDI programming in the AVRISP project slightly to prevent transmission errors * * Fixed: * diff --git a/LUFA/ManPages/LUFAPoweredProjects.txt b/LUFA/ManPages/LUFAPoweredProjects.txt index 9d95a6ea0b..615e5c6abf 100644 --- a/LUFA/ManPages/LUFAPoweredProjects.txt +++ b/LUFA/ManPages/LUFAPoweredProjects.txt @@ -37,7 +37,7 @@ * - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller: http://noisybox.net/electronics/wingdinger/ * - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master * - Generic HID Device Creator : http://generichid.sourceforge.net/ - * - Mobo 4.3, some sort of Audio related device: http://sites.google.com/site/lofturj/mobo4_3 + * - Mobo 4.3, a USB controlled all band (160-10m) HF SDR transceiver: http://sites.google.com/site/lofturj/mobo4_3 * - NES Controller USB modification: http://projects.peterpolidoro.net/video/NESUSB.htm * - MakeTV Episode Dispenser: http://www.youtube.com/watch?v=BkWUi18hl3g * - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/ diff --git a/Projects/AVRISP/AVRISP.c b/Projects/AVRISP/AVRISP.c index c0572fca2f..7974f1ca98 100644 --- a/Projects/AVRISP/AVRISP.c +++ b/Projects/AVRISP/AVRISP.c @@ -78,7 +78,7 @@ void SetupHardware(void) ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC); #endif - /* Millisecond timer initialization for timeouts and delays */ + /* Millisecond timer initialization for managing the command timeout counter */ OCR0A = ((F_CPU / 64) / 1000); TCCR0A = (1 << WGM01); TCCR0B = ((1 << CS01) | (1 << CS00)); diff --git a/Projects/AVRISP/Lib/ISP/ISPProtocol.h b/Projects/AVRISP/Lib/ISP/ISPProtocol.h index 43c25c4fa3..abbbf569d6 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 e99e3e53c9..29cb18e620 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 96f1a6476e..c856ddde14 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); diff --git a/Projects/AVRISP/Lib/V2Protocol.c b/Projects/AVRISP/Lib/V2Protocol.c index 4f7904a217..4fcb5aa005 100644 --- a/Projects/AVRISP/Lib/V2Protocol.c +++ b/Projects/AVRISP/Lib/V2Protocol.c @@ -43,6 +43,13 @@ uint32_t CurrentAddress; bool MustSetAddress; +/** ISR for the management of the command execution timeout counter */ +ISR(TIMER0_COMPA_vect, ISR_BLOCK) +{ + if (TimeoutMSRemaining) + TimeoutMSRemaining--; +} + /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host. * This routine decodes the issued command and passes off the handling of the command to the * appropriate function. @@ -51,6 +58,9 @@ void V2Protocol_ProcessCommand(void) { uint8_t V2Command = Endpoint_Read_Byte(); + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + TIMSK0 |= (1 << OCIE0A); + switch (V2Command) { case CMD_SIGN_ON: @@ -110,7 +120,9 @@ void V2Protocol_ProcessCommand(void) V2Protocol_UnknownCommand(V2Command); break; } - + + TIMSK0 &= ~(1 << OCIE0A); + Endpoint_WaitUntilReady(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); } diff --git a/Projects/AVRISP/Lib/V2Protocol.h b/Projects/AVRISP/Lib/V2Protocol.h index db4d09f0a1..76b08b022a 100644 --- a/Projects/AVRISP/Lib/V2Protocol.h +++ b/Projects/AVRISP/Lib/V2Protocol.h @@ -49,16 +49,21 @@ /* Preprocessor Checks: */ #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #undef ENABLE_ISP_PROTOCOL - #undef ENABLE_TPI_PROTOCOL - #if !defined(ENABLE_PDI_PROTOCOL) - #define ENABLE_PDI_PROTOCOL + #if !defined(ENABLE_XPROG_PROTOCOL) + #define ENABLE_XPROG_PROTOCOL #endif #endif /* Macros: */ /** 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 GPIOR1 /* External Variables: */ extern uint32_t CurrentAddress; diff --git a/Projects/AVRISP/Lib/V2ProtocolParams.c b/Projects/AVRISP/Lib/V2ProtocolParams.c index 6b7f84aa34..eacff03944 100644 --- a/Projects/AVRISP/Lib/V2ProtocolParams.c +++ b/Projects/AVRISP/Lib/V2ProtocolParams.c @@ -43,44 +43,44 @@ uint8_t EEMEM EEPROM_Rest_Polarity = 0x00; static ParameterItem_t ParameterTable[] = { { .ParamID = PARAM_BUILD_NUMBER_LOW, - .ParamValue = (LUFA_VERSION_INTEGER >> 8), - .ParamPrivileges = PARAM_PRIV_READ }, + .ParamPrivileges = PARAM_PRIV_READ, + .ParamValue = (LUFA_VERSION_INTEGER >> 8) }, { .ParamID = PARAM_BUILD_NUMBER_HIGH, - .ParamValue = (LUFA_VERSION_INTEGER & 0xFF), - .ParamPrivileges = PARAM_PRIV_READ }, + .ParamPrivileges = PARAM_PRIV_READ, + .ParamValue = (LUFA_VERSION_INTEGER & 0xFF), }, { .ParamID = PARAM_HW_VER, - .ParamValue = 0x00, - .ParamPrivileges = PARAM_PRIV_READ }, + .ParamPrivileges = PARAM_PRIV_READ, + .ParamValue = 0x00 }, { .ParamID = PARAM_SW_MAJOR, - .ParamValue = 0x01, - .ParamPrivileges = PARAM_PRIV_READ }, + .ParamPrivileges = PARAM_PRIV_READ, + .ParamValue = 0x01 }, { .ParamID = PARAM_SW_MINOR, - .ParamValue = 0x0D, - .ParamPrivileges = PARAM_PRIV_READ }, + .ParamPrivileges = PARAM_PRIV_READ, + .ParamValue = 0x0D }, { .ParamID = PARAM_VTARGET, - .ParamValue = 0x32, - .ParamPrivileges = PARAM_PRIV_READ }, + .ParamPrivileges = PARAM_PRIV_READ, + .ParamValue = 0x32 }, { .ParamID = PARAM_SCK_DURATION, - .ParamValue = (TOTAL_ISP_PROGRAMMING_SPEEDS - 1), - .ParamPrivileges = PARAM_PRIV_READ | PARAM_PRIV_WRITE }, + .ParamPrivileges = PARAM_PRIV_READ | PARAM_PRIV_WRITE, + .ParamValue = (TOTAL_ISP_PROGRAMMING_SPEEDS - 1) }, { .ParamID = PARAM_RESET_POLARITY, - .ParamValue = 0x00, - .ParamPrivileges = PARAM_PRIV_WRITE }, + .ParamPrivileges = PARAM_PRIV_WRITE, + .ParamValue = 0x00 }, { .ParamID = PARAM_STATUS_TGT_CONN, - .ParamValue = 0x00, - .ParamPrivileges = PARAM_PRIV_READ }, + .ParamPrivileges = PARAM_PRIV_READ, + .ParamValue = 0x00 }, { .ParamID = PARAM_DISCHARGEDELAY, - .ParamValue = 0x00, - .ParamPrivileges = PARAM_PRIV_WRITE }, + .ParamPrivileges = PARAM_PRIV_WRITE, + .ParamValue = 0x00 }, }; diff --git a/Projects/AVRISP/Lib/V2ProtocolParams.h b/Projects/AVRISP/Lib/V2ProtocolParams.h index 14ff56c71a..28d57c80bb 100644 --- a/Projects/AVRISP/Lib/V2ProtocolParams.h +++ b/Projects/AVRISP/Lib/V2ProtocolParams.h @@ -62,8 +62,8 @@ typedef struct { const uint8_t ParamID; /**< Parameter ID number to uniquely identify the parameter within the device */ + const uint8_t ParamPrivileges; /**< Parameter privileges to allow the host to read or write the parameter's value */ uint8_t ParamValue; /**< Current parameter's value within the device */ - uint8_t ParamPrivileges; /**< Parameter privileges to allow the host to read or write the parameter's value */ } ParameterItem_t; /* Function Prototypes: */ diff --git a/Projects/AVRISP/Lib/XPROG/TINYNVM.c b/Projects/AVRISP/Lib/XPROG/TINYNVM.c index f4b90ffa58..3ddd2eda01 100644 --- a/Projects/AVRISP/Lib/XPROG/TINYNVM.c +++ b/Projects/AVRISP/Lib/XPROG/TINYNVM.c @@ -37,6 +37,7 @@ #include "TINYNVM.h" #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__) +#warning TPI Protocol support is currently incomplete and is not suitable for general use. /** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read. * @@ -44,24 +45,13 @@ */ bool TINYNVM_WaitWhileNVMBusBusy(void) { - TCNT0 = 0; - TIFR0 = (1 << OCF1A); - - uint8_t TimeoutMS = TINY_NVM_BUSY_TIMEOUT_MS; - /* Poll the STATUS register to check to see if NVM access has been enabled */ - while (TimeoutMS) + 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; - - if (TIFR0 & (1 << OCF1A)) - { - TIFR0 = (1 << OCF1A); - TimeoutMS--; - } } return false; diff --git a/Projects/AVRISP/Lib/XPROG/TINYNVM.h b/Projects/AVRISP/Lib/XPROG/TINYNVM.h index ecf429e774..75d11293d5 100644 --- a/Projects/AVRISP/Lib/XPROG/TINYNVM.h +++ b/Projects/AVRISP/Lib/XPROG/TINYNVM.h @@ -56,7 +56,13 @@ #endif /* Defines: */ - #define TINY_NVM_BUSY_TIMEOUT_MS 100 + #define TINY_NVM_REG_NVMCSR 0x32 + #define TINY_NVM_REG_NVMCMD 0x33 + + #define TINY_NVM_CMD_NOOP 0x00 + #define TINY_NVM_CMD_CHIPERASE 0x10 + #define TINY_NVM_CMD_SECTIONERASE 0x14 + #define TINY_NVM_CMD_WORDWRITE 0x1D /* Function Prototypes: */ bool TINYNVM_WaitWhileNVMBusBusy(void); diff --git a/Projects/AVRISP/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP/Lib/XPROG/XMEGANVM.c index 6280f60fbb..c83ae0115b 100644 --- a/Projects/AVRISP/Lib/XPROG/XMEGANVM.c +++ b/Projects/AVRISP/Lib/XPROG/XMEGANVM.c @@ -58,10 +58,10 @@ void XMEGANVM_SendNVMRegAddress(const uint8_t Register) void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress) { /* Send the given 32-bit address to the target, LSB first */ - XPROGTarget_SendByte(AbsoluteAddress & 0xFF); - XPROGTarget_SendByte(AbsoluteAddress >> 8); - XPROGTarget_SendByte(AbsoluteAddress >> 16); - XPROGTarget_SendByte(AbsoluteAddress >> 24); + XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[0]); + XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[1]); + XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[2]); + XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[3]); } /** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read or CRC @@ -71,24 +71,13 @@ void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress) */ bool XMEGANVM_WaitWhileNVMBusBusy(void) { - TCNT0 = 0; - TIFR0 = (1 << OCF1A); - - uint8_t TimeoutMS = XMEGA_NVM_BUSY_TIMEOUT_MS; - /* Poll the STATUS register to check to see if NVM access has been enabled */ - while (TimeoutMS) + 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; - - if (TIFR0 & (1 << OCF1A)) - { - TIFR0 = (1 << OCF1A); - TimeoutMS--; - } } return false; @@ -101,13 +90,8 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void) */ bool XMEGANVM_WaitWhileNVMControllerBusy(void) { - TCNT0 = 0; - TIFR0 = (1 << OCF1A); - - uint8_t TimeoutMS = XMEGA_NVM_BUSY_TIMEOUT_MS; - /* Poll the NVM STATUS register while the NVM controller is busy */ - while (TimeoutMS) + while (TimeoutMSRemaining) { /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */ XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); @@ -116,12 +100,6 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void) /* Check to see if the BUSY flag is still set */ if (!(XPROGTarget_ReceiveByte() & (1 << 7))) return true; - - if (TIFR0 & (1 << OCF1A)) - { - TIFR0 = (1 << OCF1A); - TimeoutMS--; - } } return false; @@ -158,22 +136,24 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest) if (!(XMEGANVM_WaitWhileNVMControllerBusy())) return false; - *CRCDest = 0; + uint32_t MemoryCRC = 0; /* Read the first generated CRC byte value */ XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0); - *CRCDest = XPROGTarget_ReceiveByte(); + MemoryCRC = XPROGTarget_ReceiveByte(); /* Read the second generated CRC byte value */ XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT1); - *CRCDest |= ((uint16_t)XPROGTarget_ReceiveByte() << 8); + MemoryCRC |= ((uint16_t)XPROGTarget_ReceiveByte() << 8); /* Read the third generated CRC byte value */ XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT2); - *CRCDest |= ((uint32_t)XPROGTarget_ReceiveByte() << 16); + MemoryCRC |= ((uint32_t)XPROGTarget_ReceiveByte() << 16); + + *CRCDest = MemoryCRC; return true; } @@ -186,7 +166,7 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest) * * \return Boolean true if the command sequence complete successfully */ -bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const uint16_t ReadSize) +bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadSize) { /* Wait until the NVM controller is no longer busy */ if (!(XMEGANVM_WaitWhileNVMControllerBusy())) @@ -207,7 +187,7 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const /* Send a LD command with indirect access and postincrement to read out the bytes */ XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE); - for (uint16_t i = 0; i < ReadSize; i++) + while (ReadSize--) *(ReadBuffer++) = XPROGTarget_ReceiveByte(); return true; @@ -253,8 +233,8 @@ bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAd * \return Boolean true if the command sequence complete successfully */ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand, - const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress, - const uint8_t* WriteBuffer, const uint16_t WriteSize) + const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress, + const uint8_t* WriteBuffer, uint16_t WriteSize) { if (PageMode & XPRG_PAGEMODE_ERASE) { @@ -294,7 +274,7 @@ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t Eras /* Send a ST command with indirect access and postincrement to write the bytes */ XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE); - for (uint16_t i = 0; i < WriteSize; i++) + while (WriteSize--) XPROGTarget_SendByte(*(WriteBuffer++)); } diff --git a/Projects/AVRISP/Lib/XPROG/XMEGANVM.h b/Projects/AVRISP/Lib/XPROG/XMEGANVM.h index 6a4de1fb12..d1a14abda7 100644 --- a/Projects/AVRISP/Lib/XPROG/XMEGANVM.h +++ b/Projects/AVRISP/Lib/XPROG/XMEGANVM.h @@ -56,8 +56,6 @@ #endif /* Defines: */ - #define XMEGA_NVM_BUSY_TIMEOUT_MS 100 - #define XMEGA_NVM_REG_ADDR0 0x00 #define XMEGA_NVM_REG_ADDR1 0x01 #define XMEGA_NVM_REG_ADDR2 0x02 @@ -111,11 +109,11 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void); bool XMEGANVM_WaitWhileNVMControllerBusy(void); bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest); - bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const uint16_t ReadSize); + bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadSize); bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t* WriteBuffer); bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand, const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress, - const uint8_t* WriteBuffer, const uint16_t WriteSize); + const uint8_t* WriteBuffer, uint16_t WriteSize); bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address); #endif diff --git a/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c index edcc874d74..bccb96c2c1 100644 --- a/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c @@ -38,7 +38,7 @@ #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__) /** Base absolute address for the target's NVM controller */ -uint32_t XPROG_Param_NVMBase = 0x010001C0; +uint32_t XPROG_Param_NVMBase = 0x010001C0; /** Size in bytes of the target's EEPROM page */ uint32_t XPROG_Param_EEPageSize; @@ -46,7 +46,6 @@ uint32_t XPROG_Param_EEPageSize; /** Currently selected XPROG programming protocol */ uint8_t XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI; - /** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI * programming. */ diff --git a/Projects/AVRISP/Lib/XPROG/XPROGTarget.c b/Projects/AVRISP/Lib/XPROG/XPROGTarget.c index 708b237efb..59c85f382c 100644 --- a/Projects/AVRISP/Lib/XPROG/XPROGTarget.c +++ b/Projects/AVRISP/Lib/XPROG/XPROGTarget.c @@ -174,7 +174,7 @@ void XPROGTarget_EnableTargetTPI(void) BITBANG_TPIDATA_PORT |= BITBANG_TPIDATA_MASK; /* Fire timer capture ISR every 100 cycles to manage the software USART */ - OCR1A = 80; + OCR1A = 100; TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10); TIMSK1 = (1 << ICIE1); @@ -217,7 +217,7 @@ void XPROGTarget_EnableTargetPDI(void) asm volatile ("NOP"::); /* Fire timer compare ISR every 100 cycles to manage the software USART */ - OCR1A = 80; + OCR1A = 100; TCCR1B = (1 << WGM12) | (1 << CS10); TIMSK1 = (1 << OCIE1A); @@ -353,7 +353,7 @@ uint8_t XPROGTarget_ReceiveByte(void) } /* Wait until a byte has been received before reading */ - while (!(UCSR1A & (1 << RXC1))); + while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining); return UDR1; #else /* Switch to Rx mode if currently in Tx mode */ @@ -369,8 +369,8 @@ uint8_t XPROGTarget_ReceiveByte(void) /* Wait until a byte has been received before reading */ SoftUSART_BitCount = BITS_IN_USART_FRAME; - while (SoftUSART_BitCount); - + while (SoftUSART_BitCount && TimeoutMSRemaining); + /* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */ return (uint8_t)SoftUSART_Data; #endif diff --git a/Projects/AVRISP/Lib/XPROG/XPROGTarget.h b/Projects/AVRISP/Lib/XPROG/XPROGTarget.h index 58c1caa377..44602164ee 100644 --- a/Projects/AVRISP/Lib/XPROG/XPROGTarget.h +++ b/Projects/AVRISP/Lib/XPROG/XPROGTarget.h @@ -42,6 +42,8 @@ #include #include + + #include "../V2Protocol.h" /* Preprocessor Checks: */ #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) diff --git a/Projects/MissileLauncher/MissileLauncher.c b/Projects/MissileLauncher/MissileLauncher.c index 26dd077cd7..29ebd458a2 100644 --- a/Projects/MissileLauncher/MissileLauncher.c +++ b/Projects/MissileLauncher/MissileLauncher.c @@ -1,11 +1,3 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - /* USB Missile Launcher Demo Copyright (C) Dave Fletcher, 2009. @@ -158,7 +150,7 @@ void Read_Joystick_Status(void) * \param[in] Report Report data to send. * \param[in] ReportSize Report length in bytes. */ -void Send_Command_Report(uint8_t *Report, uint16_t ReportSize) +void Send_Command_Report(uint8_t* const Report, const uint16_t ReportSize) { memcpy(CmdBuffer, Report, 8); WriteNextReport(CmdBuffer, ReportSize); @@ -168,7 +160,7 @@ void Send_Command_Report(uint8_t *Report, uint16_t ReportSize) * * \param[in] Command One of the command constants. */ -void Send_Command(uint8_t* Command) +void Send_Command(uint8_t* const Command) { if ((CmdState == CMD_STOP && Command != CMD_STOP) || (CmdState != CMD_STOP && Command == CMD_STOP)) @@ -252,7 +244,7 @@ void DiscardNextReport(void) * \param[in] ReportOUTData Buffer containing the report to send to the device * \param[in] ReportLength Length of the report to send */ -void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength) +void WriteNextReport(uint8_t* const ReportOUTData, const uint16_t ReportLength) { /* Select and unfreeze HID data OUT pipe */ Pipe_SelectPipe(HID_DATA_OUT_PIPE); diff --git a/Projects/MissileLauncher/MissileLauncher.h b/Projects/MissileLauncher/MissileLauncher.h index e92fe743cf..400ee26bb7 100644 --- a/Projects/MissileLauncher/MissileLauncher.h +++ b/Projects/MissileLauncher/MissileLauncher.h @@ -82,8 +82,8 @@ void SetupHardware(void); void Read_Joystick_Status(void); - void Send_Command_Report(uint8_t* Report, uint16_t ReportSize); - void Send_Command(uint8_t* Command); + void Send_Command_Report(uint8_t* const Report, const uint16_t ReportSize); + void Send_Command(uint8_t* const Command); void HID_Host_Task(void); @@ -94,6 +94,6 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void); void DiscardNextReport(void); - void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength); + void WriteNextReport(uint8_t* const ReportOUTData, const uint16_t ReportLength); #endif